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