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