Mercurial > hg > ismi-richfaces
annotate src/main/java/de/mpiwg/itgroup/ismi/entry/beans/AbstractISMIBean.java @ 111:22a18bfc66b0
new completion that uses ALIASes: AbstractListenerObject. was_copied_in in WITNESS form can use PLACE aliases now. some cleanup.
author | casties |
---|---|
date | Fri, 09 Dec 2016 21:18:27 +0100 |
parents | e27603a39e70 |
children | 59f26a5ef2b3 |
rev | line source |
---|---|
1 | 1 package de.mpiwg.itgroup.ismi.entry.beans; |
2 | |
3 import java.io.Serializable; | |
4 import java.util.ArrayList; | |
5 import java.util.HashMap; | |
6 import java.util.HashSet; | |
7 import java.util.List; | |
8 import java.util.Map; | |
9 | |
10 import javax.faces.context.FacesContext; | |
11 import javax.faces.event.ValueChangeEvent; | |
12 import javax.faces.model.SelectItem; | |
13 | |
14 import org.apache.commons.lang.StringUtils; | |
15 import org.apache.log4j.Logger; | |
16 import org.mpi.openmind.cache.WrapperService; | |
17 import org.mpi.openmind.repository.bo.Attribute; | |
18 import org.mpi.openmind.repository.bo.Entity; | |
19 import org.mpi.openmind.repository.bo.Node; | |
20 import org.mpi.openmind.repository.bo.Relation; | |
95 | 21 import org.mpi.openmind.repository.services.PersistenceService; |
1 | 22 import org.mpi.openmind.security.SecurityService; |
23 import org.mpi.openmind.security.bo.User; | |
24 | |
25 import de.mpiwg.itgroup.ismi.auxObjects.ListenerObject; | |
26 import de.mpiwg.itgroup.ismi.entry.dataBeans.SimpleSearchCache; | |
91 | 27 import de.mpiwg.itgroup.ismi.util.guiComponents.Calendar; |
1 | 28 import de.mpiwg.itgroup.ismi.util.guiComponents.Reference; |
29 import de.mpiwg.itgroup.ismi.util.guiComponents.ReferenceTable; | |
30 import de.mpiwg.itgroup.ismi.util.guiComponents.StatusChecker; | |
31 import de.mpiwg.itgroup.ismi.util.guiComponents.StatusImage; | |
32 import de.mpiwg.itgroup.ismi.utils.SelectableObject; | |
33 | |
34 /** | |
35 * | |
36 * @author jurzua | |
37 */ | |
38 public class AbstractISMIBean extends AbstractBean implements Serializable{ | |
39 | |
40 private static final long serialVersionUID = 9193140306343947209L; | |
41 | |
42 private static Logger logger = Logger.getLogger(AbstractISMIBean.class); | |
95 | 43 private static Logger txLog = Logger.getLogger(PersistenceService.TRANSACTION_LOGGER); |
1 | 44 |
45 public static String WITNESS = "WITNESS"; | |
46 public static String TEXT = "TEXT"; | |
47 public static String PERSON = "PERSON"; | |
48 public static String COLLECTION = "COLLECTION"; | |
49 public static String CODEX = "CODEX"; | |
50 public static String REPOSITORY = "REPOSITORY"; | |
51 public static String ALIAS = "ALIAS"; | |
52 public static String PLACE = "PLACE"; | |
53 public static String SUBJECT = "SUBJECT"; | |
54 public static String REFERENCE = "REFERENCE"; | |
55 public static String ROLE = "ROLE"; | |
56 public static String DIGITALIZATION = "DIGITALIZATION"; | |
57 public static String FLORUIT_DATE = "FLORUIT_DATE"; | |
58 | |
59 public static String is_digitalization_of = "is_digitalization_of"; | |
60 public static String is_part_of = "is_part_of"; | |
61 public static String is_in = "is_in"; | |
62 public static String has_subject = "has_subject"; | |
63 public static String misattributed_to = "misattributed_to"; | |
64 public static String lived_in = "lived_in"; | |
65 public static String owned_by = "owned_by"; | |
66 public static String has_role = "has_role"; | |
67 public static String was_student_of = "was_student_of"; | |
68 public static String is_alias_name_of = "is_alias_name_of"; | |
69 public static String is_prime_alias_name_of = "is_prime_alias_name_of"; | |
70 public static String is_alias_title_of = "is_alias_title_of"; | |
71 public static String is_prime_alias_title_of = "is_prime_alias_title_of"; | |
72 public static String alias = "alias"; | |
73 public static String has_floruit_date = "has_floruit_date"; | |
74 | |
75 public static String rel_was_created_by = "was_created_by"; | |
76 public static String rel_was_copied_by = "was_copied_by"; | |
77 public static String is_exemplar_of = "is_exemplar_of"; | |
78 public static String is_possible_exemplar_of = "is_possible_exemplar_of"; | |
79 public static String rel_had_patron = "had_patron"; | |
80 public static String rel_has_title_written_as = "has_title_written_as"; | |
81 public static String rel_has_author_written_as = "has_author_written_as"; | |
82 public static String rel_is_reference_of = "is_reference_of"; | |
83 | |
84 public static String rel_was_studied_by = "was_studied_by"; | |
85 | |
86 public static String PAGE_EDITOR = "entry_edit_entity"; | |
87 public static String PAGE_SIMPLE_SEARCH = "simple_search"; | |
88 public static String PAGE_MERGE = "general_merge"; | |
89 | |
90 //some attributes names | |
91 public static String name = "name"; | |
92 public static String name_translit = "name_translit"; | |
93 public static String full_title_translit = "full_title_translit"; | |
94 | |
95 public static int MAX_SUGGEST = 25; | |
96 | |
97 protected boolean selectedSaveAsNew = false; | |
98 | |
91 | 99 private HashSet<StatusChecker> statusCheckers = new HashSet<StatusChecker>(); |
1 | 100 private boolean warning = false; |
101 private String warningMessage = ""; | |
102 private boolean displayWarning = false; | |
103 | |
104 //private PanelPopup popup = new PanelPopup(); | |
105 //private String popupText = ""; | |
106 | |
107 private String currentId; | |
108 private String currentIdMsg; | |
109 | |
110 // used in the new version | |
111 private Boolean create_error = false; | |
112 private String selectedWitnessID = "0"; | |
113 private boolean showWitness; | |
114 private boolean showTitle = false; | |
115 | |
116 private Map<String, String> attributes = new HashMap<String, String>(); | |
117 protected String defObjectClass = null; | |
118 | |
119 protected String displayUrl; | |
120 | |
121 protected Entity entity; | |
122 | |
123 protected long start; | |
124 | |
91 | 125 /** |
126 * Save current entity. | |
127 * | |
128 * @return | |
129 */ | |
1 | 130 public String save(){ |
131 logger.info("*************** START Saving "+ this.defObjectClass + " [ID=" + entity.getId() +", user"+ getUserName() +"] *********************"); | |
95 | 132 txLog.debug("*** START Saving "+ this.defObjectClass + " id=" + entity.getId() +" user="+getUserName()); |
1 | 133 this.start = System.currentTimeMillis(); |
134 return null; | |
135 } | |
136 | |
91 | 137 /** |
138 * End saving current entity. | |
139 * | |
140 * To be called at the end of save(). | |
141 */ | |
1 | 142 protected void saveEnd(){ |
143 logger.info("*************** END Saving "+ this.defObjectClass + " [ID=" + entity.getId() +", user"+ getUserName() +"] *********************\n"); | |
95 | 144 txLog.debug("*** END Saving "+ this.defObjectClass + " id=" + entity.getId() +" user="+getUserName()); |
1 | 145 } |
146 | |
147 public Entity getEntity() { | |
148 if (this.entity == null) { | |
149 this.entity = new Entity(); | |
150 this.entity.setObjectClass(defObjectClass); | |
151 this.entity.setLightweight(false); | |
152 this.loadAttributes(this.entity); | |
153 } | |
154 return entity; | |
155 } | |
156 | |
91 | 157 /** |
158 * Add save confirmation to message. | |
159 */ | |
160 protected void printSuccessSavingEntity() { | |
1 | 161 this.addGeneralMsg("The entity was successfully saved!"); |
162 this.addGeneralMsg("Its ID is " + this.entity.getId()); | |
163 } | |
164 | |
105 | 165 /** |
166 * Set the current Entity and parse data for the form. | |
167 * | |
168 * @param entity | |
169 */ | |
1 | 170 public void setEntity(Entity entity) { |
171 this.entity = entity; | |
172 } | |
173 | |
174 public String getSaveButtonLabel(){ | |
175 if(entity.isPersistent()) | |
176 return "Save"; | |
177 return "Create"; | |
178 } | |
179 | |
180 public boolean isRenderSaveButton(){ | |
181 //#{(CurrentText.entity.id == null and Session.canCreate) || (CurrentText.entity.id != null and Session.canEdit)} | |
182 if((!entity.isPersistent() && getSessionBean().isCanCreate()) || | |
183 entity.isPersistent() && getSessionBean().isCanEdit()) | |
184 return true; | |
185 return false; | |
186 } | |
187 | |
92 | 188 /** |
189 * Clear the bean by setting a new empty entity. | |
190 * @return | |
191 */ | |
1 | 192 public String clearAction(){ |
193 System.out.println("clearAction"); | |
194 this.entity = new Entity(Node.TYPE_ABOX, this.defObjectClass, false); | |
195 this.setEntity(this.entity); | |
196 return PAGE_EDITOR; | |
197 } | |
198 | |
92 | 199 /** |
200 * Reload the bean using the entity with currentId. | |
201 * @return | |
202 */ | |
90 | 203 public String actionReloadEntity() { |
1 | 204 Long id = null; |
90 | 205 try { |
1 | 206 id = new Long(this.getCurrentId()); |
90 | 207 } catch (Exception e) {} |
1 | 208 |
90 | 209 if (id != null) { |
210 Entity newEnt = getWrapper().getEntityById(id); | |
211 if (newEnt != null && newEnt.getObjectClass().equals(this.defObjectClass)) { | |
212 this.setEntity(newEnt); | |
213 } else { | |
1 | 214 this.setCurrentIdMsg("Entity no found!"); |
215 } | |
90 | 216 } else { |
1 | 217 this.setCurrentIdMsg("ID is not valid!"); |
218 } | |
219 return PAGE_EDITOR; | |
220 } | |
221 | |
222 public String getDisplayUrl() { | |
223 return displayUrl; | |
224 } | |
225 | |
226 public void setDisplayUrl(String displayUrl) { | |
227 this.displayUrl = displayUrl; | |
228 } | |
229 | |
230 public static String generateDisplayUrl(Entity author, Entity title, Entity witness, String rootUrl){ | |
231 //example: ?personId=414996&textId=36650&witnessId=66802#witnesses | |
232 StringBuilder sb = new StringBuilder(); | |
233 if(author != null && author.isPersistent()){ | |
234 sb.append(rootUrl + "/search/displayAuthor.xhtml?"); | |
235 sb.append("personId=" + author.getId()); | |
236 if(title != null && title.isPersistent()){ | |
237 sb.append("&textId=" + title.getId()); | |
238 if(witness != null && witness.isPersistent()){ | |
239 sb.append("&witness=" + witness.getId()); | |
240 sb.append("#witnesses"); | |
241 }else{ | |
242 sb.append("#titles"); | |
243 } | |
244 } | |
245 }else if(title != null && title.isPersistent()){ | |
246 sb.append(rootUrl + "/search/displayTitle.xhtml?"); | |
247 sb.append("&textId=" + title.getId()); | |
248 if(witness != null && witness.isPersistent()){ | |
249 sb.append("&witness=" + witness.getId()); | |
250 sb.append("#witnesses"); | |
251 }else{ | |
252 sb.append("#titles"); | |
253 } | |
254 | |
255 } | |
256 return sb.toString(); | |
257 } | |
258 | |
259 //******************************** | |
260 //**** PUBLICATIONS END NOTE ***** | |
261 //******************************** | |
262 | |
263 private ReferenceTable endNoteRefTable = new ReferenceTable(); | |
264 | |
265 protected void loadEndNoteRefs(){ | |
266 this.endNoteRefTable.loadRefs(getEntRefs()); | |
267 } | |
268 | |
269 public ReferenceTable getEndNoteRefTable() { | |
270 return endNoteRefTable; | |
271 } | |
272 | |
273 public void setEndNoteRefTable(ReferenceTable endNoteRefTable) { | |
274 this.endNoteRefTable = endNoteRefTable; | |
275 } | |
276 | |
277 private List<Entity> getEntRefs(){ | |
278 List<Entity> rs = new ArrayList<Entity>(); | |
279 for (Relation rel : this.entity.getTargetRelations()) { | |
280 if (rel.getOwnValue().equals(rel_is_reference_of)) { | |
281 rs.add(getWrapper().getEntityByIdWithContent(rel.getSourceId())); | |
282 } | |
283 } | |
284 return rs; | |
285 } | |
286 | |
287 | |
91 | 288 /** |
289 * Save references and set relations. | |
290 * | |
291 * @throws Exception | |
292 */ | |
1 | 293 protected void prepareEndNoteRefs2Save() throws Exception{ |
294 //REFERENCE -> is_reference_of -> WITNESS | |
295 this.entity.removeAllTargetRelationsByName(rel_is_reference_of); | |
91 | 296 for (SelectableObject<Reference> so : this.endNoteRefTable.list) { |
1 | 297 Reference ref = so.getObj(); |
298 Entity entRef = ref.getEnt(); | |
91 | 299 getWrapper().saveEntity(entRef, getUserName()); |
1 | 300 //entity can be no persistent, therefore the assignment of the relation should be done after the save |
301 entRef.addSourceRelation(rel_is_reference_of, entity); | |
302 //new Relation(entRef, entity, rel_is_reference_of); | |
303 } | |
304 } | |
305 | |
306 | |
91 | 307 public static Calendar updateCalendar(Attribute att){ |
308 Calendar calendar = null; | |
1 | 309 if(att != null && StringUtils.isNotEmpty(att.getOwnValue())){ |
91 | 310 calendar = new Calendar(att.getOwnValue()); |
1 | 311 }else{ |
91 | 312 calendar = new Calendar(); |
1 | 313 } |
314 return calendar; | |
315 } | |
316 | |
92 | 317 /** |
318 * Load all (defined) attributes of the entity into this.attributes. | |
319 * | |
320 * Creates new empty attributes if entity=null. | |
321 * | |
322 * @param entity | |
323 */ | |
324 protected void loadAttributes(Entity entity) { | |
325 attributes = new HashMap<String, String>(); | |
326 if (entity != null) { | |
327 for (Attribute defAtt : getWrapper().getDefAttributes(this.defObjectClass)) { | |
328 Attribute originalAtt = entity.getAttributeByName(defAtt.getOwnValue()); | |
329 String attValue = (originalAtt != null) ? originalAtt.getOwnValue() : ""; | |
330 attributes.put(defAtt.getOwnValue(), attValue); | |
331 } | |
332 } else { | |
333 for (Attribute defAtt : getWrapper().getDefAttributes(this.defObjectClass)) { | |
334 attributes.put(defAtt.getOwnValue(), ""); | |
335 } | |
336 } | |
337 } | |
1 | 338 |
105 | 339 /** |
340 * Clear some selected options. | |
341 */ | |
1 | 342 public void reset(){ |
343 this.setSelectedSaveAsNew(false); | |
344 this.setCurrentId(""); | |
345 this.setCurrentIdMsg(""); | |
346 this.setAttributes(new HashMap<String, String>()); | |
347 this.displayUrl = null; | |
348 this.endNoteRefTable = new ReferenceTable(); | |
349 } | |
350 | |
351 public boolean isSelectedSaveAsNew() { | |
352 return selectedSaveAsNew; | |
353 } | |
354 | |
355 public void setSelectedSaveAsNew(boolean selectedSaveAsNew) { | |
356 this.selectedSaveAsNew = selectedSaveAsNew; | |
357 } | |
358 | |
359 /** | |
91 | 360 * Update the defined attributes of the given entity with the |
1 | 361 * attributes of the attributes Map<String, String>. |
362 * | |
91 | 363 * @return the entity with updated attributes. |
1 | 364 */ |
91 | 365 public Entity updateEntityAttributes(Entity entity) { |
366 // create entity if it doesn't exist | |
367 if (entity == null) { | |
368 entity = new Entity(Node.TYPE_ABOX, false); | |
369 entity.setObjectClass(this.defObjectClass); | |
370 } | |
371 // update all defined attributes | |
372 for (Attribute defAtt : getWrapper().getDefAttributes(this.defObjectClass)) { | |
373 String attName = defAtt.getOwnValue(); | |
374 Attribute att = entity.getAttributeByName(attName); | |
375 if (StringUtils.isNotEmpty(this.attributes.get(attName))) { | |
376 // there is an attribute to update | |
377 if (att == null) { | |
378 // attribute is new | |
379 att = new Attribute(defAtt); | |
380 entity.addAttribute(att); | |
381 } | |
382 // update value | |
383 att.setOwnValue(this.attributes.get(attName)); | |
384 att.setObjectClass(attName); | |
385 } else if (att != null) { | |
386 // there is no attribute to update - delete attribute | |
387 entity.getAttributes().remove(att); | |
388 } | |
389 } | |
390 return entity; | |
391 } | |
1 | 392 |
393 protected List<SelectItem> updateSuggestedPersonByRole(String searchWord, String objClass, String attName, String role){ | |
394 List<Attribute> attList = getWrapper().getAttributesByDefByAttName(objClass, attName, searchWord.toString(), -1); | |
395 | |
396 List<SelectItem> suggestedItems = new ArrayList<SelectItem>(); | |
397 if (attList == null) | |
398 return suggestedItems; | |
399 | |
400 int count = 0; | |
401 for (Attribute att : attList) { | |
402 if(getCache().roleContainsPersonId(role, att.getSourceId())){ | |
403 SelectItem item = new SelectItem(att, att.getOwnValue() + " [" + att.getSourceId() + "]","description: " + att); | |
404 suggestedItems.add(item); | |
405 count++; | |
406 if(count == MAX_SUGGEST) | |
407 break; | |
408 } | |
409 } | |
410 return suggestedItems; | |
411 } | |
412 | |
413 protected List<SelectItem> updateSuggestedItems(ValueChangeEvent event, | |
414 String objClass, String attName) { | |
415 return updateSuggestedItems((String) event.getNewValue(), objClass, | |
416 attName); | |
417 } | |
418 | |
419 protected List<SelectItem> updateSuggestedItems(String searchWord, | |
420 String objClass, String attName) { | |
421 | |
422 List<Attribute> attList = getWrapper().getAttributesByDefByAttName(objClass, attName, searchWord.toString(), MAX_SUGGEST); | |
423 | |
424 List<SelectItem> suggestedItems = new ArrayList<SelectItem>(); | |
425 if (attList == null) | |
426 return suggestedItems; | |
427 | |
428 for (Attribute att : attList) { | |
429 SelectItem item = new SelectItem(att, att.getOwnValue() + " [" + att.getSourceId() + "]", | |
430 "description: " + att); | |
431 suggestedItems.add(item); | |
432 } | |
433 return suggestedItems; | |
434 } | |
435 | |
436 protected SimpleSearchCache getCache(){ | |
437 return getAppBean().getSimpleSearchCache(); | |
438 } | |
439 | |
440 protected List<SelectItem> updateSuggestedItems(String objClass, | |
441 String firstName, String firstValue, String secondName, | |
442 String secondValue) { | |
443 | |
444 List<Attribute> attList = | |
445 getWrapper(). | |
446 searchAttribute(firstName, firstValue, secondName, secondValue, objClass, MAX_SUGGEST); | |
447 | |
448 List<SelectItem> suggestedItems = new ArrayList<SelectItem>(); | |
449 if (attList == null) | |
450 return suggestedItems; | |
451 | |
452 for (Attribute att : attList) { | |
453 SelectItem item = new SelectItem(att, att.getOwnValue() + " [" + att.getSourceId() + "]"); | |
454 suggestedItems.add(item); | |
455 } | |
456 return suggestedItems; | |
457 } | |
458 | |
459 public Map<String, String> getAttributes() { | |
460 return attributes; | |
461 } | |
462 | |
463 public void setAttributes(Map<String, String> attributes) { | |
464 this.attributes = attributes; | |
465 } | |
466 | |
467 /** | |
468 * <p> | |
469 * This method plays the role of a small cache to get quickly the | |
470 * definitions. | |
471 * </p> | |
472 * TODO this method must be implemented into a bean in session context and | |
473 * research by every beans. | |
474 * | |
475 * @param assertion | |
476 * @return | |
477 */ | |
478 public Entity getLWDefinition(Entity assertion) { | |
479 return getWrapper().getDefinition(assertion.getObjectClass()); | |
480 } | |
481 | |
482 public Entity getLWDefinition(String objClass) { | |
483 return getWrapper().getDefinition(objClass); | |
484 } | |
485 | |
486 /** | |
487 * <p> | |
488 * Returns the target's entity of a relation. The returned target is no | |
489 * light weight. | |
490 * <p> | |
491 * | |
492 * @param rel | |
493 * @param target | |
494 * @return | |
495 */ | |
496 protected Entity getTargetRelation(Relation rel) { | |
497 Entity target = rel.getTarget(); | |
498 if (target == null) { | |
499 target = getWrapper().getEntityById(rel.getTargetId()); | |
500 rel.setTarget(target); | |
501 } else if (target.isLightweight()) { | |
502 target = getWrapper().getEntityContent(target); | |
503 } | |
504 return target; | |
505 } | |
506 | |
507 protected Attribute getTargetAttribute(Entity target, String name) { | |
508 Attribute att = getWrapper().getAttributeByName(target.getId(), name); | |
509 | |
510 if (att == null) { | |
511 att = new Attribute(); | |
512 att.setOwnValue(target.getOwnValue()); | |
513 } | |
514 return att; | |
515 } | |
516 | |
517 protected WrapperService getWrapper() { | |
518 return getAppBean().getWrapper(); | |
519 } | |
520 | |
521 /** | |
522 * <p> | |
523 * Return the <code>FacesContext</code> instance for the current request. | |
524 */ | |
525 protected FacesContext context() { | |
526 return (FacesContext.getCurrentInstance()); | |
527 } | |
528 | |
529 public void setCreate_error(Boolean create_error) { | |
530 this.create_error = create_error; | |
531 } | |
532 | |
533 public Boolean getCreate_error() { | |
534 return create_error; | |
535 } | |
536 | |
537 /** | |
538 * Eine Liste <code>toBeRestricted</code> wird so eingeschraenkt, dass nur | |
539 * noch die jenigen uebrig bleiben, die �ber die Relation | |
540 * <code>relation</code> mit einem der Elemente aus | |
541 * <code>contraintIds</code> verbunden sind. | |
542 * | |
543 * @param toBeRestricted | |
544 * @param constraintIds | |
545 * @param relation | |
546 * @param mode | |
547 * @return | |
548 */ | |
549 protected List<SelectItem> restrictList(List<SelectItem> toBeRestricted, | |
550 List<String> constraintIds, String relation, String mode) { | |
551 | |
552 List<SelectItem> newList = new ArrayList<SelectItem>(); | |
553 | |
554 for (SelectItem s : toBeRestricted) { | |
555 Entity ent = getWrapper().getEntityById( | |
556 Long.valueOf((String) s.getValue())); | |
557 if (s.getValue().equals("0")) { | |
558 newList.add(s); | |
559 continue; | |
560 } | |
561 | |
562 List<Relation> rels; | |
563 if (mode.equals("target")) { | |
564 rels = ent.getTargetRelations(); | |
565 } else if (mode.equals("source")) { | |
566 rels = ent.getSourceRelations(); | |
567 } else { | |
568 System.err.println("restrict List - mode not defined:" + mode); | |
569 return null; | |
570 } | |
571 | |
572 for (Relation r : rels) { | |
573 if (r.getObjectClass().equals(relation)) { | |
574 Long id; | |
575 if (mode.equals("target")) { | |
576 id = r.getSource().getId(); | |
577 } else if (mode.equals("source")) { | |
578 id = r.getTarget().getId(); | |
579 } else { | |
580 System.err.println("restrict List - mode not defined:" | |
581 + mode); | |
582 return null; | |
583 } | |
584 if (constraintIds.contains(String.valueOf(id))) { | |
585 newList.add(s); | |
586 } | |
587 } | |
588 } | |
589 } | |
590 | |
591 return newList; | |
592 } | |
593 | |
594 public String getSelectedWitnessID() { | |
595 return selectedWitnessID; | |
596 } | |
597 | |
598 public void setShowWitness(boolean showWitness) { | |
599 this.showWitness = showWitness; | |
600 } | |
601 | |
602 public boolean isShowWitness() { | |
603 return showWitness; | |
604 } | |
605 | |
606 public void setShowTitle(boolean showTitle) { | |
607 this.showTitle = showTitle; | |
608 } | |
609 | |
610 public boolean isShowTitle() { | |
611 return showTitle; | |
612 } | |
613 /* | |
614 public PanelPopup getPopup() { | |
615 return popup; | |
616 } | |
617 | |
618 public void setPopup(PanelPopup popup) { | |
619 this.popup = popup; | |
620 } | |
621 | |
622 public String getPopupText() { | |
623 return popupText; | |
624 } | |
625 | |
626 public void setPopupText(String popupText) { | |
627 this.popupText = popupText; | |
628 }*/ | |
629 | |
630 | |
631 public String getUserName(){ | |
632 User user = getSessionUser(); | |
633 if(user == null) | |
634 return ""; | |
635 else | |
636 return user.getEmail(); | |
637 } | |
638 | |
639 public User getSessionUser() { | |
640 SessionBean bean = getSessionBean(); | |
641 if(bean != null){ | |
642 return bean.getUser(); | |
643 }else{ | |
644 return null; | |
645 } | |
646 } | |
647 | |
648 public void fillList(List<SelectItem> list, String[] array) { | |
649 list.add(new SelectItem("")); | |
650 for (int i = 0; i < array.length; i++) { | |
651 list.add(new SelectItem(array[i])); | |
652 } | |
653 | |
654 } | |
655 | |
656 public boolean isWarning() { | |
657 return warning; | |
658 } | |
659 | |
660 public void setWarning(boolean warning) { | |
661 this.warning = warning; | |
662 } | |
663 | |
664 public void setWarningMessage(String warningMessage) { | |
665 this.warningMessage = warningMessage; | |
666 } | |
667 | |
668 public String getWarningMessage() { | |
669 return warningMessage; | |
670 } | |
671 | |
672 public void setDisplayWarning(boolean displayWarning) { | |
673 this.displayWarning = displayWarning; | |
674 } | |
675 | |
676 public boolean isDisplayWarning() { | |
677 return displayWarning; | |
678 } | |
679 | |
680 public void registerChecker(StatusChecker sc) { | |
91 | 681 statusCheckers.add(sc); |
1 | 682 } |
683 | |
684 public void registerChecker(ListenerObject lo, String message) { | |
685 registerChecker(lo.statusImage, message); | |
686 | |
687 } | |
688 | |
689 public void registerChecker(StatusChecker sc, String message) { | |
690 sc.setMessage(message); | |
91 | 691 statusCheckers.add(sc); |
1 | 692 } |
693 | |
694 class CheckResults { | |
695 List<String> errors = new ArrayList<String>(); | |
696 List<String> warnings = new ArrayList<String>(); | |
697 public boolean hasErrors = false; | |
698 public boolean hasWarnings = false; | |
699 | |
700 } | |
701 | |
91 | 702 /** |
703 * Get the result from all StatusCheckers. | |
704 * | |
705 * @return | |
706 */ | |
1 | 707 public CheckResults getCheckResults() { |
708 CheckResults cr = new CheckResults(); | |
709 | |
91 | 710 for (StatusChecker sc : statusCheckers) { |
1 | 711 if (sc.getStatus().equals("false")) { |
712 cr.hasErrors = true; | |
713 cr.errors.add(sc.getMessage()); | |
714 } else if (sc.getStatus().equals("unset")) { | |
715 cr.hasWarnings = true; | |
716 cr.warnings.add(sc.getMessage()); | |
717 } | |
718 } | |
719 return cr; | |
720 } | |
721 | |
722 protected ListenerObject changeValue(String ownvalue, ListenerObject lo, String suggestType, String suggestAttributeName, | |
723 List<SelectItem> restrictedItems) { | |
724 if (restrictedItems != null) { | |
725 lo.suggestedItems = restrictedItems;} | |
726 | |
727 if (ownvalue == null || ownvalue.equals("")) | |
728 lo.statusImage.setStatus("unset"); | |
729 else | |
730 lo.statusImage.setStatus("false"); | |
731 lo.entity = null; | |
732 // setze erst mal den Eigenwert auf das eingebene. | |
733 Attribute at = new Attribute(); | |
734 at.setOwnValue(ownvalue); | |
735 lo.attribute = at; | |
736 Entity element = null; | |
737 if (lo.suggestedItems != null) // schaue in der liste der vorgebenen Ereignisse nach. | |
738 for (SelectItem item : lo.suggestedItems) { | |
739 if (item.getLabel().equals(ownvalue)) { | |
740 if (Attribute.class.isInstance(item.getValue())){ // entweder es ist schon ein attribute | |
741 lo.attribute = (Attribute) item.getValue(); | |
742 element = getWrapper().getEntityById( | |
743 lo.attribute.getSourceId()); | |
744 }else{ //oder ein paar wert / id// = (Attribute) item.getValue(); | |
745 element = getWrapper().getEntityById(Long.valueOf((String) item.getValue())); | |
111
22a18bfc66b0
new completion that uses ALIASes: AbstractListenerObject. was_copied_in in WITNESS form can use PLACE aliases now. some cleanup.
casties
parents:
105
diff
changeset
|
746 lo.setEntityAndAttributeName(element, suggestAttributeName); |
1 | 747 } |
748 if (element != null) { | |
749 if(element.isLightweight()){ | |
750 element = getWrapper().getEntityByIdWithContent(element.getId()); | |
751 } | |
752 lo.entity = element; | |
753 lo.statusImage.setStatus("ok"); | |
754 } | |
755 break; | |
756 } | |
757 | |
758 } else { | |
759 //juc *** List<Entity> ents = getWrapper().getLightweightConceptsByAttribute(null, suggestType, suggestAttributeName, ownvalue, 1, false); | |
760 List<Entity> ents = getWrapper().getEntitiesByAtt(suggestType, suggestAttributeName, ownvalue, 1, false); | |
761 if (ents.size()==1){ | |
111
22a18bfc66b0
new completion that uses ALIASes: AbstractListenerObject. was_copied_in in WITNESS form can use PLACE aliases now. some cleanup.
casties
parents:
105
diff
changeset
|
762 lo.setEntityAndAttributeName(ents.get(0),suggestAttributeName); |
1 | 763 lo.statusImage.setStatus("ok"); |
764 } | |
765 | |
766 } | |
767 return lo; | |
768 | |
769 } | |
770 | |
771 | |
772 | |
773 protected ListenerObject changeValuePersonByRole(ValueChangeEvent event, ListenerObject lo, String role){ | |
774 if (event.getNewValue() == null) { | |
775 return lo; | |
776 }else if(StringUtils.isEmpty(event.getNewValue().toString()) && (event.getOldValue() == null || StringUtils.isEmpty(event.getOldValue().toString()))){ | |
777 //if the old and new value are empty, then return | |
778 return lo; | |
779 } | |
780 if (event.getNewValue().equals(event.getOldValue())) { | |
781 return lo; | |
782 } | |
783 | |
784 String ownValue = (String) event.getNewValue(); | |
785 | |
786 if(StringUtils.isEmpty(ownValue)) | |
787 lo.statusImage.setStatus("unset"); | |
788 else | |
789 lo.statusImage.setStatus("false"); | |
790 | |
791 lo.entity = null; | |
792 // setze erst mal den Eigenwert auf das eingebene. | |
793 Attribute at = new Attribute(); | |
794 at.setOwnValue(ownValue); | |
795 lo.attribute = at; | |
796 for (SelectItem item : lo.suggestedItems) { | |
797 if (StringUtils.isNotEmpty(item.getLabel()) && | |
798 item.getLabel().equals(ownValue)) { | |
799 //System.out.println("item.getValue()= " + item.getValue()); | |
800 lo.attribute = (Attribute) item.getValue(); | |
801 Entity element = getWrapper().getEntityById( | |
802 lo.attribute.getSourceId()); | |
803 | |
804 if (element != null) { | |
805 if(element.isLightweight()){ | |
806 element = getWrapper().getEntityByIdWithContent(element.getId()); | |
807 } | |
808 lo.entity = element; | |
809 lo.statusImage.setStatus(StatusImage.STATUS_OK); | |
810 } | |
811 break; | |
812 } | |
813 | |
814 } | |
815 | |
816 //juc lo.suggestedItems = updateSuggestedPersonByRole(ownValue, PERSON, "name", role); | |
817 lo.suggestedItems = updateSuggestedPersonByRole(ownValue, PERSON, "name_translit", role); | |
818 | |
819 | |
820 return lo; | |
821 } | |
822 | |
823 protected ListenerObject changeValue(String ownvalue, ListenerObject lo, | |
824 String suggestType, String suggestAttributeName) { | |
825 | |
826 return changeValue(ownvalue, lo, suggestType, suggestAttributeName, | |
827 null); | |
828 } | |
829 | |
830 protected ListenerObject changeListener(ValueChangeEvent event, | |
831 ListenerObject lo, String suggestType, String suggestAttributeName, | |
832 String restrictingAttributeName, String restrictingAttributeValue) { | |
833 try { | |
834 if (event.getNewValue() == null) { | |
835 return lo; | |
836 }else if(StringUtils.isEmpty(event.getNewValue().toString()) && (event.getOldValue() == null || StringUtils.isEmpty(event.getOldValue().toString()))){ | |
837 //if the old and new value are empty, then return | |
838 return lo; | |
839 } | |
840 if (event.getNewValue().equals(event.getOldValue())) { | |
841 return lo; | |
842 } | |
843 | |
844 String ownvalue = (String) event.getNewValue(); | |
845 | |
846 if(StringUtils.isEmpty(ownvalue)) | |
847 lo.statusImage.setStatus(StatusImage.STATUS_UNSET); | |
848 else | |
849 lo.statusImage.setStatus(StatusImage.STATUS_FALSE); | |
850 | |
851 lo.entity = null; | |
852 // setze erst mal den Eigenwert auf das eingebene. | |
853 Attribute at = new Attribute(); | |
854 at.setOwnValue(ownvalue); | |
855 lo.attribute = at; | |
856 for (SelectItem item : lo.suggestedItems) { | |
857 if (StringUtils.isNotEmpty(item.getLabel()) && | |
858 item.getLabel().equals(ownvalue)) { | |
859 //System.out.println("item.getValue()= " + item.getValue()); | |
860 lo.attribute = (Attribute) item.getValue(); | |
861 Entity element = getWrapper().getEntityById( | |
862 lo.attribute.getSourceId()); | |
863 | |
864 if (element != null) { | |
865 if(element.isLightweight()){ | |
866 element = getWrapper().getEntityByIdWithContent(element.getId()); | |
867 } | |
868 lo.entity = element; | |
869 lo.statusImage.setStatus(StatusImage.STATUS_OK); | |
870 } | |
871 break; | |
872 } | |
873 | |
874 } | |
875 | |
876 if (restrictingAttributeName == null) { | |
877 lo.suggestedItems = this.updateSuggestedItems(event, | |
878 suggestType, suggestAttributeName); | |
879 } else { | |
880 lo.suggestedItems = this.updateSuggestedItems(suggestType, | |
881 suggestAttributeName, event.getNewValue().toString(), | |
882 restrictingAttributeName, restrictingAttributeValue); | |
883 } | |
884 | |
885 } catch (Exception e) { | |
886 e.printStackTrace(); | |
887 } | |
888 return lo; | |
889 } | |
890 | |
91 | 891 /** |
892 * Update the ownvalues of entities that are related to the given entity. | |
893 * | |
894 * @param entity | |
895 * @param user | |
896 * @throws Exception | |
897 */ | |
898 protected void updateRelatedOW(Entity entity, String user) throws Exception { | |
899 List<Entity> nodeList = new ArrayList<Entity>(); | |
900 | |
901 /* | |
902 * run updates depending on type | |
903 */ | |
904 if (entity.getObjectClass().equals(PLACE)) { | |
905 this.generateOW4City(entity, nodeList, user); | |
906 getWrapper().saveEntityListAsNodeWithoutContent(nodeList, user); | |
907 | |
908 } else if (entity.getObjectClass().equals(REPOSITORY)) { | |
909 this.generateOW4Repository(entity, nodeList, new HashMap<String, String>(), user); | |
910 getWrapper().saveEntityListAsNodeWithoutContent(nodeList, user); | |
911 | |
912 } else if (entity.getObjectClass().equals(COLLECTION)) { | |
913 this.generateOW4Collection(entity, nodeList, new HashMap<String, String>(), user); | |
914 getWrapper().saveEntityListAsNodeWithoutContent(nodeList, user); | |
915 | |
916 } else if (entity.getObjectClass().equals(CODEX)) { | |
917 this.generateOW4Codex(entity, nodeList, new HashMap<String, String>(), user); | |
918 getWrapper().saveEntityListAsNodeWithoutContent(nodeList, user); | |
919 | |
920 } else if (entity.getObjectClass().equals(TEXT)) { | |
921 generateOW4Text(entity, user); | |
922 } | |
923 // TODO PERSON and TEXT | |
924 } | |
1 | 925 |
926 private void generateOW4City(Entity city, List<Entity> nodeList, String user){ | |
927 Map<String, String> map = new HashMap<String, String>(); | |
928 map.put(PLACE, city.getOwnValue()); | |
929 | |
930 List<Entity> repoList = getWrapper().getSourcesForTargetRelation(city, is_in, REPOSITORY, -1); | |
931 for(Entity repo : repoList){ | |
932 this.generateOW4Repository(repo, nodeList, map, user); | |
933 } | |
934 } | |
935 | |
936 private void generateOW4Repository(Entity repository, List<Entity> nodeList, Map<String, String> map, String user){ | |
937 if(map.size() == 0){ | |
938 List<Entity> placeList = getWrapper().getTargetsForSourceRelation(repository, is_in, PLACE, 1); | |
939 map.put(PLACE, ((placeList.size() > 0) ? placeList.get(0).getOwnValue() : "")); | |
940 } | |
941 | |
942 map.put(REPOSITORY, repository.getOwnValue()); | |
943 List<Entity> collectionList = getWrapper().getSourcesForTargetRelation(repository, is_part_of, COLLECTION, -1); | |
944 for(Entity collection : collectionList){ | |
945 this.generateOW4Collection(collection, nodeList, map, user); | |
946 } | |
947 } | |
948 | |
949 private void generateOW4Collection(Entity collection, List<Entity> nodeList, Map<String, String> map, String user){ | |
950 if(map.size() == 0){ | |
951 List<Entity> repoList = getWrapper().getTargetsForSourceRelation(collection, is_part_of, REPOSITORY, 1); | |
952 map.put(REPOSITORY, (repoList.size() > 0) ? repoList.get(0).getOwnValue() : ""); | |
953 if(repoList.size() > 0){ | |
954 Entity repository = repoList.get(0); | |
955 List<Entity> placeList = getWrapper().getTargetsForSourceRelation(repository, is_in, PLACE, 1); | |
956 map.put(PLACE, (placeList.size() > 0) ? placeList.get(0).getOwnValue() : ""); | |
957 }else{ | |
958 map.put(REPOSITORY, ""); | |
959 map.put(PLACE, ""); | |
960 } | |
961 } | |
962 | |
963 map.put(COLLECTION, collection.getOwnValue()); | |
964 List<Entity> list = getWrapper().getSourcesForTargetRelation(collection, is_part_of, CODEX, -1); | |
965 for(Entity codex : list){ | |
966 //update ow codex | |
967 Attribute att = getWrapper().getAttributeByName(codex.getId(), "identifier"); | |
968 if(att != null){ | |
969 codex.setOwnValue(collection.getOwnValue() + "_" + att.getOwnValue()); | |
970 nodeList.add(codex); | |
971 } | |
972 this.generateOW4Codex(codex, nodeList, map, user); | |
973 } | |
974 } | |
975 | |
976 private void generateOW4Codex(Entity codex, List<Entity> nodeList, Map<String, String> map, String user){ | |
977 if(map.size() == 0){ | |
978 List<Entity> collList = getWrapper().getTargetsForSourceRelation(codex, is_part_of, COLLECTION, 1); | |
979 map.put(COLLECTION, (collList.size() > 0 ) ? collList.get(0).getOwnValue() : ""); | |
980 if(collList.size() > 0){ | |
981 Entity collection = collList.get(0); | |
982 List<Entity> repoList = getWrapper().getTargetsForSourceRelation(collection, is_part_of, REPOSITORY, 1); | |
983 map.put(REPOSITORY, (repoList.size() > 0) ? repoList.get(0).getOwnValue() : ""); | |
984 if(repoList.size() > 0){ | |
985 Entity repository = repoList.get(0); | |
986 List<Entity> placeList = getWrapper().getTargetsForSourceRelation(repository, is_in, PLACE, 1); | |
987 map.put(PLACE, (placeList.size() > 0) ? placeList.get(0).getOwnValue() : ""); | |
988 }else{ | |
989 map.put(PLACE, ""); | |
990 } | |
991 }else{ | |
992 map.put(COLLECTION, ""); | |
993 map.put(REPOSITORY, ""); | |
994 map.put(PLACE, ""); | |
995 } | |
996 } | |
997 List<Entity> list = getWrapper().getSourcesForTargetRelation(codex, is_part_of, WITNESS, -1); | |
998 String placeText = (StringUtils.isNotEmpty(map.get(PLACE))) ? "_" + map.get(PLACE) : ""; | |
999 String repoText = (StringUtils.isNotEmpty(map.get(REPOSITORY))) ? "_" + map.get(REPOSITORY) : ""; | |
1000 String codexText = (codex != null) ? "_" + codex.getOwnValue() : ""; | |
1001 | |
1002 for(Entity witness : list){ | |
1003 List<Entity> textList = getWrapper().getTargetsForSourceRelation(witness, "is_exemplar_of", TEXT, -1); | |
1004 String textName = (textList.size() > 0) ? textList.get(0).getOwnValue() : ""; | |
1005 witness.setOwnValue(textName + placeText + repoText + codexText); | |
1006 nodeList.add(witness); | |
1007 } | |
1008 } | |
1009 | |
1010 private void generateOW4Text(Entity text, String user) throws Exception{ | |
1011 List<Entity> witnessList = getWrapper().getSourcesForTargetRelation(text, "is_exemplar_of", WITNESS, -1); | |
1012 List<Entity> listToSave = new ArrayList<Entity>(); | |
1013 for(Entity witness : witnessList){ | |
1014 List<Entity> list = getWrapper().getTargetsForSourceRelation(witness, "is_part_of", "CODEX", 1); | |
1015 if(list.size() > 0){ | |
1016 Entity codex = list.get(0); | |
1017 list = getWrapper().getTargetsForSourceRelation(codex, "is_part_of", "COLLECTION", 1); | |
1018 if(list.size() > 0){ | |
1019 Entity collection = list.get(0); | |
1020 list = getWrapper().getTargetsForSourceRelation(collection, "is_part_of", "REPOSITORY", 1); | |
1021 if(list.size() > 0){ | |
1022 Entity repository = list.get(0); | |
1023 list = getWrapper().getTargetsForSourceRelation(repository, "is_in", "PLACE", 1); | |
1024 if(list.size() > 0){ | |
1025 Entity city = list.get(0); | |
1026 witness.setOwnValue(text.getOwnValue() + "_" + city.getOwnValue() + "_" + repository.getOwnValue() + "_" + codex.getOwnValue()); | |
1027 listToSave.add(witness); | |
1028 } | |
1029 } | |
1030 } | |
1031 } | |
1032 getWrapper().saveEntityListAsNodeWithoutContent(listToSave, user); | |
1033 } | |
1034 } | |
1035 | |
1036 protected SecurityService getSecurityService() { | |
1037 return getAppBean().getSecurityService(); | |
1038 } | |
1039 | |
1040 protected ListenerObject changeListener(ValueChangeEvent event, | |
1041 ListenerObject lo, String suggestType, String suggestAttributeName) { | |
1042 | |
1043 return changeListener(event, lo, suggestType, suggestAttributeName, | |
1044 null, null); | |
1045 } | |
1046 | |
1047 public String getCurrentId() { | |
1048 return currentId; | |
1049 } | |
1050 | |
1051 public void setCurrentId(String currentId) { | |
1052 this.currentId = currentId; | |
1053 } | |
1054 | |
1055 public String getCurrentIdMsg() { | |
1056 return currentIdMsg; | |
1057 } | |
1058 | |
1059 public void setCurrentIdMsg(String currentIdMsg) { | |
1060 this.currentIdMsg = currentIdMsg; | |
1061 } | |
1062 | |
1063 public String getDefObjectClass() { | |
1064 return defObjectClass; | |
1065 } | |
1066 | |
1067 public void setDefObjectClass(String defObjectClass) { | |
1068 this.defObjectClass = defObjectClass; | |
1069 } | |
1070 } |