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