1
|
1 package de.mpiwg.itgroup.ismi.entry.beans;
|
|
2
|
|
3 import java.io.Serializable;
|
|
4
|
|
5 import org.apache.commons.lang.StringUtils;
|
|
6 import org.apache.log4j.Logger;
|
|
7 import org.mpi.openmind.repository.bo.Attribute;
|
|
8 import org.mpi.openmind.repository.bo.Entity;
|
|
9 import org.mpi.openmind.repository.bo.Node;
|
125
|
10 import org.mpi.openmind.repository.services.utils.EditIntent;
|
1
|
11
|
|
12 public class CurrentCollectionBean extends CodexEditorTemplate implements
|
|
13 Serializable {
|
|
14 private static final long serialVersionUID = 5723693904746973203L;
|
|
15
|
|
16 public static int MAX_PLACES = 100;
|
|
17 public static int MAX_REPOSITORIES = 100;
|
|
18 private static Logger logger = Logger
|
|
19 .getLogger(CurrentCollectionBean.class);
|
|
20
|
|
21 protected Boolean restrictCities = true;
|
|
22 private Boolean restrictRepositories = true;
|
|
23
|
125
|
24 /** intent to edit all attributes and relations in the form */
|
|
25 public static EditIntent editCollectionIntent = new EditIntent(
|
|
26 AbstractISMIBean.COLLECTION,
|
|
27 // attributes
|
|
28 new String[]{"name"},
|
|
29 // source relations
|
|
30 new String[]{"is_part_of"},
|
|
31 // target relations
|
|
32 new String[]{"is_reference_of"});
|
|
33
|
1
|
34
|
|
35 @Override
|
|
36 public void reset() {
|
|
37 super.reset();
|
|
38 this.entity = new Entity(Node.TYPE_ABOX, COLLECTION, false);
|
|
39
|
|
40 this.restrictCities = true;
|
|
41 this.restrictRepositories = true;
|
|
42
|
|
43 this.entity = new Entity(Node.TYPE_ABOX, COLLECTION, false);
|
|
44 }
|
|
45
|
|
46 public CurrentCollectionBean() {
|
|
47 this.reset();
|
|
48 // setDefinition(getDefinition("COLLECTION"));
|
|
49 setDefObjectClass(COLLECTION);
|
|
50 registerChecker(getCityLo(), "City is not valid!");
|
|
51 registerChecker(getCountryLo(), "Country is not valid!");
|
|
52 registerChecker(getRepositoryLo(), "Repository is not valid!");
|
|
53 }
|
|
54
|
|
55 public Boolean getRestrictCities() {
|
|
56 return restrictCities;
|
|
57 }
|
|
58
|
|
59 public void setRestrictCities(Boolean restrictCities) {
|
|
60 this.restrictCities = restrictCities;
|
|
61 }
|
|
62
|
|
63 public Boolean getRestrictRepositories() {
|
|
64 return restrictRepositories;
|
|
65 }
|
|
66
|
|
67 public void setRestrictRepositories(Boolean restrictRepositories) {
|
|
68 this.restrictRepositories = restrictRepositories;
|
|
69 }
|
|
70
|
|
71 public void setEntity(Entity collection) {
|
|
72 this.reset();
|
|
73 this.entity = collection;
|
|
74
|
|
75 if (this.entity != null && this.entity.isPersistent()) {
|
|
76 if (this.entity.isLightweight()) {
|
|
77 this.entity = getWrapper().getEntityContent(this.entity);
|
|
78 }
|
|
79
|
|
80 this.loadAttributes(this.entity);
|
|
81
|
|
82 for (Entity target : getWrapper().getTargetsForSourceRelation(
|
|
83 collection, "is_part_of", REPOSITORY, 1)) {
|
|
84 setRepository(target);
|
|
85 }
|
|
86
|
|
87 // this.loadReferences(this.entity);
|
|
88 this.loadEndNoteRefs();
|
|
89
|
|
90 this.setCurrentId(this.entity.getId().toString());
|
|
91 this.checkConsistencyFromCountryToCodex();
|
|
92 }
|
|
93 }
|
|
94
|
|
95 public String saveAsNewEntity() {
|
|
96 this.setSelectedSaveAsNew(true);
|
|
97 return save();
|
|
98 }
|
|
99
|
|
100 @Override
|
|
101 public String save() {
|
|
102 super.save();
|
|
103 try {
|
|
104
|
|
105 CheckResults cr = getCheckResults();
|
|
106 if (cr.hasErrors) {
|
|
107 getSessionBean().setErrorMessages(cr);
|
|
108 getSessionBean().setDisplayError(true);
|
|
109 this.setSelectedSaveAsNew(false);
|
|
110 return "";
|
|
111 }
|
|
112
|
|
113 this.entity = this.updateEntityAttributes(this.entity);
|
|
114 // checking is the identifier is unique for the selected collecion
|
|
115 Attribute attName = this.entity.getAttributeByName("name");
|
|
116 String collectionName = (attName == null) ? null : attName
|
|
117 .getValue();
|
|
118 if (StringUtils.isNotEmpty(collectionName)) {
|
|
119 if (!checkUnityCollection(collectionName,
|
|
120 (isSelectedSaveAsNew()) ? null : this.entity.getId(),
|
|
121 this.getRepositoryLo().entity)) {
|
|
122 this.renderUnityCheckerDialog();
|
|
123 this.setSelectedSaveAsNew(false);
|
|
124 return "";
|
|
125 }
|
|
126 } else {
|
|
127 this.addErrorMsg("Ths entity has not been saved, because its name was empty.");
|
|
128 this.addErrorMsg("You must enter a name.");
|
|
129 return "";
|
|
130 }
|
|
131
|
|
132 if (!isCollectionConsistentBeforeSave()) {
|
|
133 return "";
|
|
134 }
|
|
135
|
|
136 if (this.getRepositoryLo().entity != null
|
|
137 && this.getRepositoryLo().entity.isLightweight()) {
|
|
138 this.getRepositoryLo().entity = getWrapper()
|
|
139 .getEntityByIdWithContent(
|
|
140 this.getRepositoryLo().entity.getId());
|
|
141 }
|
|
142 this.entity.replaceSourceRelation(this.getRepositoryLo().entity,
|
|
143 REPOSITORY, is_part_of);
|
|
144
|
|
145 // REFERENCE -> is_reference_of -> THIS
|
|
146 this.prepareEndNoteRefs2Save();
|
|
147
|
|
148 if (isSelectedSaveAsNew()) {
|
125
|
149 //this.entity.removeAllTargetRelations(is_part_of, CODEX);
|
|
150 //this.entity = getWrapper().saveEntityAsNew(this.entity,
|
|
151 // getSessionUser().getEmail());
|
1
|
152 } else {
|
125
|
153 this.entity = getWrapper().saveEntity(this.entity, getSessionUser().getEmail(), editCollectionIntent);
|
1
|
154 }
|
|
155
|
91
|
156 this.updateRelatedOW(this.entity, getSessionUser().getEmail());
|
1
|
157 this.setCurrentId(this.entity.getId().toString());
|
|
158
|
|
159 logger.info("Entity saved - Time = "
|
|
160 + (System.currentTimeMillis() - start) + ", " + entity);
|
|
161 this.printSuccessSavingEntity();
|
|
162
|
|
163 this.setSelectedSaveAsNew(false);
|
|
164
|
|
165 } catch (Exception e) {
|
|
166 logger.error(e.getMessage(), e);
|
|
167 e.printStackTrace();
|
|
168 this.printInternalError(e);
|
|
169 }
|
|
170 saveEnd();
|
|
171
|
|
172 return PAGE_EDITOR;
|
|
173 }
|
|
174
|
|
175 /**
|
|
176 * <p>
|
|
177 * This method saves the collection without the loading of its contain when
|
|
178 * it is not necessary. LW means that the collection keeps light weight or
|
|
179 * without attributes and relation.
|
|
180 * </p>
|
|
181 * <p>
|
|
182 * It is normally used by classes (like: CurrentCodex, CurrentWitness) which
|
|
183 * inherit of this class.
|
|
184 * </p>
|
|
185 *
|
|
186 * @param collection
|
|
187 */
|
|
188 public void setLWCollection(Entity collection) {
|
|
189 this.entity = collection;
|
|
190 }
|
|
191 }
|