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