Mercurial > hg > ismi-richfaces
annotate src/main/java/de/mpiwg/itgroup/ismi/entry/beans/CurrentCodexBean.java @ 133:5ccd6e709f95
fix attribute name in EditIntent.
author | casties |
---|---|
date | Thu, 23 Feb 2017 19:25:37 +0100 |
parents | eee2e0ca4032 |
children | 25bfcc9d757c |
rev | line source |
---|---|
1 | 1 package de.mpiwg.itgroup.ismi.entry.beans; |
2 | |
3 import java.io.Serializable; | |
4 | |
5 import java.util.ArrayList; | |
6 import java.util.List; | |
7 | |
8 import javax.faces.event.ActionEvent; | |
9 import javax.faces.model.SelectItem; | |
10 | |
11 import org.apache.commons.lang.StringUtils; | |
12 import org.apache.log4j.Logger; | |
13 import org.mpi.openmind.repository.bo.Attribute; | |
14 import org.mpi.openmind.repository.bo.Entity; | |
15 import org.mpi.openmind.repository.bo.Node; | |
16 import org.mpi.openmind.repository.bo.Relation; | |
125 | 17 import org.mpi.openmind.repository.services.utils.EditIntent; |
1 | 18 |
19 import de.mpiwg.itgroup.ismi.util.guiComponents.Calendar; | |
20 import de.mpiwg.itgroup.ismi.util.guiComponents.EntityList; | |
21 | |
22 /** | |
23 * @author jurzua | |
24 * | |
25 */ | |
26 public class CurrentCodexBean extends CodexEditorTemplate implements Serializable{ | |
27 private static final long serialVersionUID = -4242977362183330958L; | |
28 | |
29 private static Logger logger = Logger.getLogger(CurrentCodexBean.class); | |
30 | |
31 //private Entity codex; | |
32 | |
33 private List<Entity> witnessInCurrentCodex; | |
34 private boolean showWitnessInCurrentCodex; | |
35 | |
36 private EntityList ownedByPeople; | |
37 private EntityList readByPeople; | |
38 | |
39 private List<SelectItem> suggestedBindingList = new ArrayList<SelectItem>(); | |
40 | |
41 private CodexEditorTemplate referencedCodexTemplate; | |
42 private Boolean isAlias; | |
43 | |
125 | 44 /** intent to edit all attributes and relations in the form */ |
45 public static EditIntent editCodexIntent = new EditIntent( | |
46 AbstractISMIBean.CODEX, | |
47 // attributes | |
48 new String[]{"identifier", "is_alias", "public", "url_digitized_codex", "mpiwg_id", "indexmeta_folder", | |
49 "number_of_folios", "dimensions", "binding", "distinguishing_features", "notes", "notes_old", | |
50 "notes_on_ownership"}, | |
51 // source relations | |
52 new String[]{"is_part_of", "is_alias_of", "owned_by", "read_by"}, | |
53 // target relations | |
54 new String[]{"is_alias_of", "is_reference_of"}); | |
55 | |
1 | 56 |
57 public CurrentCodexBean() { | |
58 this.entity = new Entity(Node.TYPE_ABOX, CODEX, false); | |
59 setDefObjectClass(CODEX); | |
60 registerChecker(getCityLo(), "city is not valid"); | |
61 registerChecker(getCountryLo(), "country is not valid"); | |
62 registerChecker(getRepositoryLo(), "repository is not valid"); | |
63 registerChecker(getCollectionLo(), "collection is not valid"); | |
64 | |
65 this.refreshBindingList(); | |
66 } | |
67 | |
68 @Override | |
69 public void reset(){ | |
70 super.reset(); | |
71 this.entity = new Entity(Node.TYPE_ABOX, CODEX, false); | |
72 | |
73 this.ownedByPeople = new EntityList(PERSON, "name_translit", true); | |
74 this.readByPeople = new EntityList(PERSON, "name_translit", true); | |
75 | |
76 this.witnessInCurrentCodex = new ArrayList<Entity>(); | |
77 this.showWitnessInCurrentCodex = false; | |
78 this.isAlias = false; | |
79 this.referencedCodexTemplate = new CodexEditorTemplate(); | |
80 this.refreshBindingList(); | |
81 } | |
82 | |
83 public void listenerRefreshBindingList(ActionEvent event){ | |
84 this.refreshBindingList(); | |
85 } | |
86 | |
87 public void listenerEditCalendarOwnedBy(ActionEvent event){ | |
88 Entity entity = (Entity)getRequestBean("item"); | |
89 if(entity != null){ | |
90 Calendar cal = this.ownedByPeople.getCalendar(entity.getId()); | |
91 getSessionBean().editCalendar(cal, ownedByPeople, entity.getId()); | |
92 } | |
93 } | |
94 | |
95 public void listenerEditCalendarReadBy(ActionEvent event){ | |
96 Entity entity = (Entity)getRequestBean("item"); | |
97 if(entity != null){ | |
98 Calendar cal = this.readByPeople.getCalendar(entity.getId()); | |
99 getSessionBean().editCalendar(cal, readByPeople, entity.getId()); | |
100 } | |
101 } | |
102 | |
103 private void refreshBindingList(){ | |
104 this.suggestedBindingList = new ArrayList<SelectItem>(); | |
105 suggestedBindingList.add(new SelectItem("", "--choose--")); | |
106 Attribute binding = getWrapper().getDefAttributeByOwnValue(this.entity.getObjectClass(), "binding"); | |
107 if(binding != null){ | |
108 for(String s : binding.getPossibleValuesList()){ | |
109 this.suggestedBindingList.add(new SelectItem(s)); | |
110 } | |
111 } | |
112 } | |
113 | |
114 public String createCollectionAction() { | |
115 getSessionBean().setSelectedTab(SessionBean.COLLECTION_TAB); | |
116 return "edit"; | |
117 } | |
118 | |
119 @Override | |
120 public void setEntity(Entity codex) { | |
121 this.reset(); | |
122 this.entity = codex; | |
123 logger.info("Set Codex " + this.entity); | |
124 try { | |
125 if(this.entity != null && this.entity.isPersistent()){ | |
126 if(this.entity.isLightweight()){ | |
127 this.entity = getWrapper().getEntityContent(this.entity); | |
128 } | |
129 | |
130 this.loadAttributes(this.entity); | |
131 | |
132 Attribute isAliasAtt = getWrapper().getAttributeByName(this.entity.getId(), "is_alias"); | |
133 if(isAlias != null){ | |
134 try{ | |
135 this.isAlias = new Boolean(isAliasAtt.getOwnValue()); | |
136 }catch(Exception ex){ | |
137 this.isAlias = false; | |
138 } | |
139 }else{ | |
140 this.isAlias = false; | |
141 } | |
142 | |
143 for(Relation rel : getWrapper().getSourceRelations(codex, owned_by, PERSON, -1)) { | |
144 this.ownedByPeople.add(getWrapper().getEntityById(rel.getTargetId()), rel.getAttributeByName("date")); | |
145 } | |
146 | |
147 for(Relation rel : getWrapper().getSourceRelations(codex, "read_by", PERSON, -1)) { | |
148 this.readByPeople.add(getWrapper().getEntityById(rel.getTargetId()), rel.getAttributeByName("date")); | |
149 } | |
150 | |
151 for (Entity target : getWrapper() | |
152 .getTargetsForSourceRelation(codex, is_part_of, COLLECTION, 1)) { | |
153 String ct = target.getObjectClass(); | |
154 | |
155 if (ct.equals(COLLECTION)) { | |
156 this.setCollection(target); | |
157 } | |
158 } | |
159 | |
160 List<Entity> list = getWrapper().getTargetsForSourceRelation(codex, "is_alias_of", CODEX, 1); | |
161 if(!list.isEmpty()){ | |
162 this.setReferencedCodex(list.get(0)); | |
163 //this.referencedCodexTemplate.setCodexLo(codexLo); | |
164 //this.referencedCodexLO.setEntityAndAttribute(list.get(0), "identifier"); | |
165 } | |
166 | |
167 | |
168 //this.loadReferences(this.entity); | |
169 this.loadEndNoteRefs(); | |
170 | |
171 this.setCurrentId(this.entity.getId().toString()); | |
172 this.checkConsistencyFromCountryToCodex(); | |
173 } | |
174 } catch (Exception e) { | |
175 logger.info(e.getMessage(), e); | |
176 printInternalError(e); | |
177 } | |
178 } | |
179 | |
180 public void setReferencedCodex(Entity codex){ | |
111
22a18bfc66b0
new completion that uses ALIASes: AbstractListenerObject. was_copied_in in WITNESS form can use PLACE aliases now. some cleanup.
casties
parents:
91
diff
changeset
|
181 this.referencedCodexTemplate.getCodexLo().setEntityAndAttributeName(codex, "identifier"); |
1 | 182 |
183 if(this.referencedCodexTemplate.getCodexLo().entity != null && | |
184 this.referencedCodexTemplate.getCodexLo().entity.isPersistent()){ | |
185 | |
186 List<Entity> list = getWrapper().getTargetsForSourceRelation(codex, is_part_of, COLLECTION, 1); | |
187 if(list.size() > 0){ | |
188 this.referencedCodexTemplate.setCollection(list.get(0)); | |
189 } | |
190 } | |
191 } | |
192 | |
193 @Override | |
194 public String save() { | |
195 super.save(); | |
196 try { | |
197 CheckResults cr = getCheckResults(); | |
198 if (cr.hasErrors) { | |
199 getSessionBean().setErrorMessages(cr); | |
200 getSessionBean().setDisplayError(true); | |
201 this.setSelectedSaveAsNew(false); | |
202 return PAGE_EDITOR; | |
203 } | |
204 | |
205 if (this.entity == null) { | |
206 this.entity = new Entity(); | |
207 this.entity.setObjectClass("CODEX"); | |
208 } | |
209 | |
210 this.entity = this.updateEntityAttributes(this.entity); | |
211 | |
212 if(this.entity.getAttributeByName("is_alias") != null){ | |
213 this.entity.getAttributeByName("is_alias").setOwnValue(this.isAlias.toString()); | |
214 }else{ | |
215 this.entity.addAttribute(new Attribute("is_alias", "boolean", this.isAlias.toString())); | |
216 } | |
217 | |
218 if(this.isAlias){ | |
219 if(referencedCodexTemplate.getCodexLo().entity != null){ | |
220 // CODEX -> is_part_of -> CODEX | |
221 this.entity.replaceSourceRelation(referencedCodexTemplate.getCodexLo().entity, CODEX, "is_alias_of"); | |
222 }else{ | |
223 this.entity.removeAllSourceRelations("is_alias_of", CODEX); | |
224 } | |
225 } | |
226 | |
227 //checking is the identifier is unique for the selected collecion | |
228 String identifier = (this.entity.getAttributeByName("identifier") != null) ? this.entity.getAttributeByName("identifier").getValue() : ""; | |
229 if(StringUtils.isNotEmpty(identifier)){ | |
230 if(!checkUnityCodex(identifier, (isSelectedSaveAsNew()) ? null : this.entity.getId(), this.getCollectionLo().entity)){ | |
231 this.renderUnityCheckerDialog(); | |
232 this.setSelectedSaveAsNew(false); | |
233 return PAGE_EDITOR; | |
234 } | |
235 }else{ | |
236 this.addErrorMsg("This entity has not been saved, because its identifier was empty."); | |
237 this.addErrorMsg("You must enter an identifier."); | |
238 return PAGE_EDITOR; | |
239 } | |
240 | |
241 if(!isCodexConsistentBeforeSave()){ | |
242 return PAGE_EDITOR; | |
243 } | |
244 | |
245 this.entity.replaceSourceRelation(this.getCollectionLo().entity, COLLECTION, is_part_of); | |
246 | |
247 // CODEX -> owner_by (manyToMany) -> PERSON | |
248 this.entity.removeAllSourceRelationsByName(owned_by); | |
249 | |
250 // CODEX -> read_by (manyToMany) -> PERSON | |
251 this.entity.removeAllSourceRelationsByName("read_by"); | |
252 | |
253 //REFERENCE -> is_reference_of -> THIS | |
254 //this.entity = this.prepareReferencesToSave(this.entity); | |
255 this.prepareEndNoteRefs2Save(); | |
256 | |
257 if (this.isSelectedSaveAsNew()) { | |
125 | 258 //this.entity = getWrapper().saveEntityAsNew(this.entity,getSessionUser().getEmail()); |
1 | 259 this.setSelectedSaveAsNew(false); |
260 } else { | |
125 | 261 for (Entity owner : this.ownedByPeople.getEntities()) { |
262 if (owner.isLightweight()) { | |
1 | 263 owner = getWrapper().getEntityByIdWithContent(owner.getId()); |
264 } | |
265 Relation ownerBy = new Relation(this.entity, owner, owned_by); | |
266 Calendar cal = ownedByPeople.getCalendar(owner.getId()); | |
125 | 267 if (cal != null) { |
1 | 268 ownerBy.addAttribute(new Attribute("date", "date", cal.toJSONString())); |
269 } | |
270 } | |
125 | 271 for (Entity reader : this.readByPeople.getEntities()) { |
1 | 272 Relation readBy = new Relation(this.entity, reader, "read_by"); |
273 Calendar cal = readByPeople.getCalendar(reader.getId()); | |
125 | 274 if (cal != null) { |
1 | 275 readBy.addAttribute(new Attribute("date", "date", cal.toJSONString())); |
276 } | |
277 } | |
125 | 278 |
279 this.entity = getWrapper().saveEntity(this.entity, getSessionUser().getEmail(), editCodexIntent); | |
1 | 280 } |
281 | |
91 | 282 this.updateRelatedOW(this.entity, getSessionUser().getEmail()); |
1 | 283 getSessionBean().setEditFormCurrentEntId(this.entity.getId()); |
284 | |
285 logger.info("Entity saved - Time = " + (System.currentTimeMillis() - start) + ", " + entity); | |
286 this.printSuccessSavingEntity(); | |
287 | |
288 this.setSelectedSaveAsNew(false); | |
289 | |
290 } catch (Exception e) { | |
291 logger.error(e.getMessage(), e); | |
292 e.printStackTrace(); | |
293 this.printInternalError(e); | |
294 } | |
295 | |
296 saveEnd(); | |
297 return PAGE_EDITOR; | |
298 } | |
299 | |
300 public String saveAsNewEntity() { | |
301 this.setSelectedSaveAsNew(true); | |
302 return save(); | |
303 } | |
304 | |
305 public void setLWCodex(Entity codex) { | |
306 this.entity = codex; | |
307 } | |
308 | |
309 public void actionShowWitnessDialog(ActionEvent event){ | |
310 if(this.witnessInCurrentCodex.size() == 0 && this.entity.isPersistent()){ | |
311 this.witnessInCurrentCodex = | |
312 getWrapper().getSourcesForTargetRelation(this.entity, "is_part_of", "WITNESS", 50); | |
313 } | |
314 this.setShowWitnessInCurrentCodex(true); | |
315 } | |
316 | |
317 public void actionCloseWitnessDialog(ActionEvent event){ | |
318 this.setShowWitnessInCurrentCodex(false); | |
319 } | |
320 | |
321 public void actionEditThisWitness(ActionEvent event){ | |
322 this.setShowWitnessInCurrentCodex(false); | |
323 Entity currentWitness = (Entity)getRequestBean("witness"); | |
324 if(currentWitness != null && currentWitness.isPersistent()){ | |
325 getSessionBean().editEntity(currentWitness); | |
326 } | |
327 } | |
328 | |
329 public List<Entity> getWitnessInCurrentCodex() { | |
330 return witnessInCurrentCodex; | |
331 } | |
332 | |
333 public void setWitnessInCurrentCodex(List<Entity> witnessInCurrentCodex) { | |
334 this.witnessInCurrentCodex = witnessInCurrentCodex; | |
335 } | |
336 | |
337 public boolean isShowWitnessInCurrentCodex() { | |
338 if(this.entity == null || !this.entity.isPersistent()){ | |
339 return false; | |
340 } | |
341 return showWitnessInCurrentCodex; | |
342 } | |
343 | |
344 public void setShowWitnessInCurrentCodex(boolean showWitnessInCurrentCodex) { | |
345 this.showWitnessInCurrentCodex = showWitnessInCurrentCodex; | |
346 } | |
347 | |
348 public void actionEditThisCollection(ActionEvent event){ | |
349 if(this.getCollectionLo().entity != null && getCollectionLo().entity.isPersistent()){ | |
350 getSessionBean().editEntity(this.getCollectionLo().entity); | |
351 } | |
352 } | |
353 | |
354 public EntityList getOwnedByPeople() { | |
355 return ownedByPeople; | |
356 } | |
357 | |
358 public void setOwnedByPeople(EntityList ownedByPeople) { | |
359 this.ownedByPeople = ownedByPeople; | |
360 } | |
361 | |
362 public List<SelectItem> getSuggestedBindingList() { | |
363 return suggestedBindingList; | |
364 } | |
365 | |
366 public void setSuggestedBindingList(List<SelectItem> suggestedBindingList) { | |
367 this.suggestedBindingList = suggestedBindingList; | |
368 } | |
369 | |
370 public CodexEditorTemplate getReferencedCodexTemplate() { | |
371 return referencedCodexTemplate; | |
372 } | |
373 | |
374 public void setReferencedCodexTemplate( | |
375 CodexEditorTemplate referencedCodexTemplate) { | |
376 this.referencedCodexTemplate = referencedCodexTemplate; | |
377 } | |
378 | |
379 public Boolean getIsAlias() { | |
380 return isAlias; | |
381 } | |
382 | |
383 public void setIsAlias(Boolean isAlias) { | |
384 this.isAlias = isAlias; | |
385 } | |
386 | |
387 public EntityList getReadByPeople() { | |
388 return readByPeople; | |
389 } | |
390 | |
391 public void setReadByPeople(EntityList readByPeople) { | |
392 this.readByPeople = readByPeople; | |
393 } | |
394 | |
395 } |