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