Mercurial > hg > ismi-richfaces
comparison src/main/java/de/mpiwg/itgroup/ismi/entry/beans/AbstractISMIBean.java @ 91:d172201d24ad
more comments and refactorings.
author | casties |
---|---|
date | Wed, 12 Oct 2016 20:50:30 +0200 |
parents | 72b877076f43 |
children | be377d5f9cc4 |
comparison
equal
deleted
inserted
replaced
90:72b877076f43 | 91:d172201d24ad |
---|---|
21 import org.mpi.openmind.security.SecurityService; | 21 import org.mpi.openmind.security.SecurityService; |
22 import org.mpi.openmind.security.bo.User; | 22 import org.mpi.openmind.security.bo.User; |
23 | 23 |
24 import de.mpiwg.itgroup.ismi.auxObjects.ListenerObject; | 24 import de.mpiwg.itgroup.ismi.auxObjects.ListenerObject; |
25 import de.mpiwg.itgroup.ismi.entry.dataBeans.SimpleSearchCache; | 25 import de.mpiwg.itgroup.ismi.entry.dataBeans.SimpleSearchCache; |
26 import de.mpiwg.itgroup.ismi.util.guiComponents.Calendar; | |
26 import de.mpiwg.itgroup.ismi.util.guiComponents.Reference; | 27 import de.mpiwg.itgroup.ismi.util.guiComponents.Reference; |
27 import de.mpiwg.itgroup.ismi.util.guiComponents.ReferenceTable; | 28 import de.mpiwg.itgroup.ismi.util.guiComponents.ReferenceTable; |
28 import de.mpiwg.itgroup.ismi.util.guiComponents.StatusChecker; | 29 import de.mpiwg.itgroup.ismi.util.guiComponents.StatusChecker; |
29 import de.mpiwg.itgroup.ismi.util.guiComponents.StatusImage; | 30 import de.mpiwg.itgroup.ismi.util.guiComponents.StatusImage; |
30 import de.mpiwg.itgroup.ismi.utils.SelectableObject; | 31 import de.mpiwg.itgroup.ismi.utils.SelectableObject; |
91 | 92 |
92 public static int MAX_SUGGEST = 25; | 93 public static int MAX_SUGGEST = 25; |
93 | 94 |
94 protected boolean selectedSaveAsNew = false; | 95 protected boolean selectedSaveAsNew = false; |
95 | 96 |
96 private HashSet<StatusChecker> statusChecker = new HashSet<StatusChecker>(); | 97 private HashSet<StatusChecker> statusCheckers = new HashSet<StatusChecker>(); |
97 private boolean warning = false; | 98 private boolean warning = false; |
98 private String warningMessage = ""; | 99 private String warningMessage = ""; |
99 private boolean displayWarning = false; | 100 private boolean displayWarning = false; |
100 | 101 |
101 //private PanelPopup popup = new PanelPopup(); | 102 //private PanelPopup popup = new PanelPopup(); |
117 | 118 |
118 protected Entity entity; | 119 protected Entity entity; |
119 | 120 |
120 protected long start; | 121 protected long start; |
121 | 122 |
123 /** | |
124 * Save current entity. | |
125 * | |
126 * @return | |
127 */ | |
122 public String save(){ | 128 public String save(){ |
123 logger.info("*************** START Saving "+ this.defObjectClass + " [ID=" + entity.getId() +", user"+ getUserName() +"] *********************"); | 129 logger.info("*************** START Saving "+ this.defObjectClass + " [ID=" + entity.getId() +", user"+ getUserName() +"] *********************"); |
124 this.start = System.currentTimeMillis(); | 130 this.start = System.currentTimeMillis(); |
125 return null; | 131 return null; |
126 } | 132 } |
127 | 133 |
134 /** | |
135 * End saving current entity. | |
136 * | |
137 * To be called at the end of save(). | |
138 */ | |
128 protected void saveEnd(){ | 139 protected void saveEnd(){ |
129 logger.info("*************** END Saving "+ this.defObjectClass + " [ID=" + entity.getId() +", user"+ getUserName() +"] *********************\n"); | 140 logger.info("*************** END Saving "+ this.defObjectClass + " [ID=" + entity.getId() +", user"+ getUserName() +"] *********************\n"); |
130 } | 141 } |
131 | 142 |
132 public Entity getEntity() { | 143 public Entity getEntity() { |
137 this.loadAttributes(this.entity); | 148 this.loadAttributes(this.entity); |
138 } | 149 } |
139 return entity; | 150 return entity; |
140 } | 151 } |
141 | 152 |
142 protected void printSuccessSavingEntity(){ | 153 /** |
154 * Add save confirmation to message. | |
155 */ | |
156 protected void printSuccessSavingEntity() { | |
143 this.addGeneralMsg("The entity was successfully saved!"); | 157 this.addGeneralMsg("The entity was successfully saved!"); |
144 this.addGeneralMsg("Its ID is " + this.entity.getId()); | 158 this.addGeneralMsg("Its ID is " + this.entity.getId()); |
145 } | 159 } |
146 | 160 |
147 public void setEntity(Entity entity) { | 161 public void setEntity(Entity entity) { |
252 } | 266 } |
253 return rs; | 267 return rs; |
254 } | 268 } |
255 | 269 |
256 | 270 |
271 /** | |
272 * Save references and set relations. | |
273 * | |
274 * @throws Exception | |
275 */ | |
257 protected void prepareEndNoteRefs2Save() throws Exception{ | 276 protected void prepareEndNoteRefs2Save() throws Exception{ |
258 //REFERENCE -> is_reference_of -> WITNESS | 277 //REFERENCE -> is_reference_of -> WITNESS |
259 this.entity.removeAllTargetRelationsByName(rel_is_reference_of); | 278 this.entity.removeAllTargetRelationsByName(rel_is_reference_of); |
260 for(SelectableObject<Reference> so : this.endNoteRefTable.list){ | 279 for (SelectableObject<Reference> so : this.endNoteRefTable.list) { |
261 Reference ref = so.getObj(); | 280 Reference ref = so.getObj(); |
262 | |
263 Entity entRef = ref.getEnt(); | 281 Entity entRef = ref.getEnt(); |
264 getWrapper().saveAssertion(entRef, getUserName()); | 282 getWrapper().saveEntity(entRef, getUserName()); |
265 //entity can be no persistent, therefore the assignment of the relation should be done after the save | 283 //entity can be no persistent, therefore the assignment of the relation should be done after the save |
266 entRef.addSourceRelation(rel_is_reference_of, entity); | 284 entRef.addSourceRelation(rel_is_reference_of, entity); |
267 //new Relation(entRef, entity, rel_is_reference_of); | 285 //new Relation(entRef, entity, rel_is_reference_of); |
268 } | 286 } |
269 } | 287 } |
270 | 288 |
271 | 289 |
272 public static de.mpiwg.itgroup.ismi.util.guiComponents.Calendar updateCalendar(Attribute att){ | 290 public static Calendar updateCalendar(Attribute att){ |
273 de.mpiwg.itgroup.ismi.util.guiComponents.Calendar calendar = null; | 291 Calendar calendar = null; |
274 if(att != null && StringUtils.isNotEmpty(att.getOwnValue())){ | 292 if(att != null && StringUtils.isNotEmpty(att.getOwnValue())){ |
275 calendar = new de.mpiwg.itgroup.ismi.util.guiComponents.Calendar(att.getOwnValue()); | 293 calendar = new Calendar(att.getOwnValue()); |
276 }else{ | 294 }else{ |
277 calendar = new de.mpiwg.itgroup.ismi.util.guiComponents.Calendar(); | 295 calendar = new Calendar(); |
278 } | 296 } |
279 return calendar; | 297 return calendar; |
280 } | 298 } |
281 | 299 |
282 protected void loadAttributes(Entity entity) { | 300 protected void loadAttributes(Entity entity) { |
312 public void setSelectedSaveAsNew(boolean selectedSaveAsNew) { | 330 public void setSelectedSaveAsNew(boolean selectedSaveAsNew) { |
313 this.selectedSaveAsNew = selectedSaveAsNew; | 331 this.selectedSaveAsNew = selectedSaveAsNew; |
314 } | 332 } |
315 | 333 |
316 /** | 334 /** |
317 * <p> | 335 * Update the defined attributes of the given entity with the |
318 * "Entity -> CurrentEntity" | |
319 * </p> | |
320 * <p> | |
321 * This method updates the attributes of the given entity with the | |
322 * attributes of the attributes Map<String, String>. | 336 * attributes of the attributes Map<String, String>. |
323 * </p> | |
324 * | 337 * |
325 * @return the input's entity with updated attributes. | 338 * @return the entity with updated attributes. |
326 */ | 339 */ |
327 public Entity updateEntityAttributes(Entity entity) { | 340 public Entity updateEntityAttributes(Entity entity) { |
328 if (entity == null) { | 341 // create entity if it doesn't exist |
329 entity = new Entity(Node.TYPE_ABOX, false); | 342 if (entity == null) { |
330 //entity.setObjectClass(getDefinition().getOwnValue()); | 343 entity = new Entity(Node.TYPE_ABOX, false); |
331 entity.setObjectClass(this.defObjectClass); | 344 entity.setObjectClass(this.defObjectClass); |
332 } | 345 } |
333 //for (Attribute defAtt : getDefinition(entity).getAttributes()) { | 346 // update all defined attributes |
334 for (Attribute defAtt : getWrapper().getDefAttributes(this.defObjectClass)) { | 347 for (Attribute defAtt : getWrapper().getDefAttributes(this.defObjectClass)) { |
335 Attribute att = entity.getAttributeByName(defAtt.getOwnValue()); | 348 String attName = defAtt.getOwnValue(); |
336 if (StringUtils.isNotEmpty(this.attributes | 349 Attribute att = entity.getAttributeByName(attName); |
337 .get(defAtt.getOwnValue()))) { | 350 if (StringUtils.isNotEmpty(this.attributes.get(attName))) { |
338 if (att == null) { | 351 // there is an attribute to update |
339 att = new Attribute(defAtt); | 352 if (att == null) { |
340 entity.addAttribute(att); | 353 // attribute is new |
341 } | 354 att = new Attribute(defAtt); |
342 att.setOwnValue(this.attributes.get(defAtt.getOwnValue())); | 355 entity.addAttribute(att); |
343 att.setObjectClass(defAtt.getOwnValue()); | 356 } |
344 } else if (att != null) { | 357 // update value |
345 // the attribute must be deleted. | 358 att.setOwnValue(this.attributes.get(attName)); |
346 entity.getAttributes().remove(att); | 359 att.setObjectClass(attName); |
347 } | 360 } else if (att != null) { |
348 } | 361 // there is no attribute to update - delete attribute |
349 return entity; | 362 entity.getAttributes().remove(att); |
350 } | 363 } |
364 } | |
365 return entity; | |
366 } | |
351 | 367 |
352 protected List<SelectItem> updateSuggestedPersonByRole(String searchWord, String objClass, String attName, String role){ | 368 protected List<SelectItem> updateSuggestedPersonByRole(String searchWord, String objClass, String attName, String role){ |
353 List<Attribute> attList = getWrapper().getAttributesByDefByAttName(objClass, attName, searchWord.toString(), -1); | 369 List<Attribute> attList = getWrapper().getAttributesByDefByAttName(objClass, attName, searchWord.toString(), -1); |
354 | 370 |
355 List<SelectItem> suggestedItems = new ArrayList<SelectItem>(); | 371 List<SelectItem> suggestedItems = new ArrayList<SelectItem>(); |
635 public boolean isDisplayWarning() { | 651 public boolean isDisplayWarning() { |
636 return displayWarning; | 652 return displayWarning; |
637 } | 653 } |
638 | 654 |
639 public void registerChecker(StatusChecker sc) { | 655 public void registerChecker(StatusChecker sc) { |
640 statusChecker.add(sc); | 656 statusCheckers.add(sc); |
641 } | 657 } |
642 | 658 |
643 public void registerChecker(ListenerObject lo, String message) { | 659 public void registerChecker(ListenerObject lo, String message) { |
644 registerChecker(lo.statusImage, message); | 660 registerChecker(lo.statusImage, message); |
645 | 661 |
646 } | 662 } |
647 | 663 |
648 public void registerChecker(StatusChecker sc, String message) { | 664 public void registerChecker(StatusChecker sc, String message) { |
649 sc.setMessage(message); | 665 sc.setMessage(message); |
650 statusChecker.add(sc); | 666 statusCheckers.add(sc); |
651 } | 667 } |
652 | 668 |
653 class CheckResults { | 669 class CheckResults { |
654 List<String> errors = new ArrayList<String>(); | 670 List<String> errors = new ArrayList<String>(); |
655 List<String> warnings = new ArrayList<String>(); | 671 List<String> warnings = new ArrayList<String>(); |
656 public boolean hasErrors = false; | 672 public boolean hasErrors = false; |
657 public boolean hasWarnings = false; | 673 public boolean hasWarnings = false; |
658 | 674 |
659 } | 675 } |
660 | 676 |
677 /** | |
678 * Get the result from all StatusCheckers. | |
679 * | |
680 * @return | |
681 */ | |
661 public CheckResults getCheckResults() { | 682 public CheckResults getCheckResults() { |
662 CheckResults cr = new CheckResults(); | 683 CheckResults cr = new CheckResults(); |
663 | 684 |
664 for (StatusChecker sc : statusChecker) { | 685 for (StatusChecker sc : statusCheckers) { |
665 if (sc.getStatus().equals("false")) { | 686 if (sc.getStatus().equals("false")) { |
666 cr.hasErrors = true; | 687 cr.hasErrors = true; |
667 cr.errors.add(sc.getMessage()); | 688 cr.errors.add(sc.getMessage()); |
668 } else if (sc.getStatus().equals("unset")) { | 689 } else if (sc.getStatus().equals("unset")) { |
669 cr.hasWarnings = true; | 690 cr.hasWarnings = true; |
840 e.printStackTrace(); | 861 e.printStackTrace(); |
841 } | 862 } |
842 return lo; | 863 return lo; |
843 } | 864 } |
844 | 865 |
845 protected void generateSecundaryOW(Entity entity, String user) throws Exception{ | 866 /** |
846 List<Entity> nodeList = new ArrayList<Entity>(); | 867 * Update the ownvalues of entities that are related to the given entity. |
847 | 868 * |
848 long start = System.currentTimeMillis(); | 869 * @param entity |
849 if(entity.getObjectClass().equals(PLACE)){ | 870 * @param user |
850 this.generateOW4City(entity, nodeList, user); | 871 * @throws Exception |
851 long medium = System.currentTimeMillis(); | 872 */ |
852 System.out.println("nodeList.size(): " + nodeList.size() + " time: " + (medium - start)); | 873 protected void updateRelatedOW(Entity entity, String user) throws Exception { |
853 getWrapper().saveEntityListAsNodeWithoutContent(nodeList, user); | 874 List<Entity> nodeList = new ArrayList<Entity>(); |
854 System.out.println("Save time: " + (System.currentTimeMillis() - medium)); | 875 |
855 }else if(entity.getObjectClass().equals(REPOSITORY)){ | 876 /* |
856 this.generateOW4Repository(entity, nodeList, new HashMap<String, String>(), user); | 877 * run updates depending on type |
857 long medium = System.currentTimeMillis(); | 878 */ |
858 System.out.println("nodeList.size(): " + nodeList.size() + " time: " + (medium - start)); | 879 if (entity.getObjectClass().equals(PLACE)) { |
859 getWrapper().saveEntityListAsNodeWithoutContent(nodeList, user); | 880 this.generateOW4City(entity, nodeList, user); |
860 System.out.println("Save time: " + (System.currentTimeMillis() - medium)); | 881 getWrapper().saveEntityListAsNodeWithoutContent(nodeList, user); |
861 }else if(entity.getObjectClass().equals(COLLECTION)){ | 882 |
862 this.generateOW4Collection(entity, nodeList, new HashMap<String, String>(), user); | 883 } else if (entity.getObjectClass().equals(REPOSITORY)) { |
863 long medium = System.currentTimeMillis(); | 884 this.generateOW4Repository(entity, nodeList, new HashMap<String, String>(), user); |
864 System.out.println("nodeList.size(): " + nodeList.size() + " time: " + (medium - start)); | 885 getWrapper().saveEntityListAsNodeWithoutContent(nodeList, user); |
865 getWrapper().saveEntityListAsNodeWithoutContent(nodeList, user); | 886 |
866 System.out.println("Save time: " + (System.currentTimeMillis() - medium)); | 887 } else if (entity.getObjectClass().equals(COLLECTION)) { |
867 }else if(entity.getObjectClass().equals(CODEX)){ | 888 this.generateOW4Collection(entity, nodeList, new HashMap<String, String>(), user); |
868 this.generateOW4Codex(entity, nodeList, new HashMap<String, String>(), user); | 889 getWrapper().saveEntityListAsNodeWithoutContent(nodeList, user); |
869 long medium = System.currentTimeMillis(); | 890 |
870 System.out.println("nodeList.size(): " + nodeList.size() + " time: " + (medium - start)); | 891 } else if (entity.getObjectClass().equals(CODEX)) { |
871 getWrapper().saveEntityListAsNodeWithoutContent(nodeList, user); | 892 this.generateOW4Codex(entity, nodeList, new HashMap<String, String>(), user); |
872 System.out.println("Save time: " + (System.currentTimeMillis() - medium)); | 893 getWrapper().saveEntityListAsNodeWithoutContent(nodeList, user); |
873 }else if(entity.getObjectClass().equals(TEXT)){ | 894 |
874 generateOW4Text(entity, user); | 895 } else if (entity.getObjectClass().equals(TEXT)) { |
875 long medium = System.currentTimeMillis(); | 896 generateOW4Text(entity, user); |
876 System.out.println("Saving witnessList time: " + (medium - start)); | 897 } |
877 } | 898 // TODO PERSON and TEXT |
878 //TODO PERSON and TEXT | 899 } |
879 } | |
880 | 900 |
881 private void generateOW4City(Entity city, List<Entity> nodeList, String user){ | 901 private void generateOW4City(Entity city, List<Entity> nodeList, String user){ |
882 Map<String, String> map = new HashMap<String, String>(); | 902 Map<String, String> map = new HashMap<String, String>(); |
883 map.put(PLACE, city.getOwnValue()); | 903 map.put(PLACE, city.getOwnValue()); |
884 | 904 |