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