Mercurial > hg > ismi-richfaces
diff 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 |
line wrap: on
line diff
--- a/src/main/java/de/mpiwg/itgroup/ismi/entry/beans/AbstractISMIBean.java Wed Oct 12 15:34:49 2016 +0200 +++ b/src/main/java/de/mpiwg/itgroup/ismi/entry/beans/AbstractISMIBean.java Wed Oct 12 20:50:30 2016 +0200 @@ -23,6 +23,7 @@ import de.mpiwg.itgroup.ismi.auxObjects.ListenerObject; import de.mpiwg.itgroup.ismi.entry.dataBeans.SimpleSearchCache; +import de.mpiwg.itgroup.ismi.util.guiComponents.Calendar; import de.mpiwg.itgroup.ismi.util.guiComponents.Reference; import de.mpiwg.itgroup.ismi.util.guiComponents.ReferenceTable; import de.mpiwg.itgroup.ismi.util.guiComponents.StatusChecker; @@ -93,7 +94,7 @@ protected boolean selectedSaveAsNew = false; - private HashSet<StatusChecker> statusChecker = new HashSet<StatusChecker>(); + private HashSet<StatusChecker> statusCheckers = new HashSet<StatusChecker>(); private boolean warning = false; private String warningMessage = ""; private boolean displayWarning = false; @@ -119,12 +120,22 @@ protected long start; + /** + * Save current entity. + * + * @return + */ public String save(){ logger.info("*************** START Saving "+ this.defObjectClass + " [ID=" + entity.getId() +", user"+ getUserName() +"] *********************"); this.start = System.currentTimeMillis(); return null; } + /** + * End saving current entity. + * + * To be called at the end of save(). + */ protected void saveEnd(){ logger.info("*************** END Saving "+ this.defObjectClass + " [ID=" + entity.getId() +", user"+ getUserName() +"] *********************\n"); } @@ -139,7 +150,10 @@ return entity; } - protected void printSuccessSavingEntity(){ + /** + * Add save confirmation to message. + */ + protected void printSuccessSavingEntity() { this.addGeneralMsg("The entity was successfully saved!"); this.addGeneralMsg("Its ID is " + this.entity.getId()); } @@ -254,14 +268,18 @@ } + /** + * Save references and set relations. + * + * @throws Exception + */ protected void prepareEndNoteRefs2Save() throws Exception{ //REFERENCE -> is_reference_of -> WITNESS this.entity.removeAllTargetRelationsByName(rel_is_reference_of); - for(SelectableObject<Reference> so : this.endNoteRefTable.list){ + for (SelectableObject<Reference> so : this.endNoteRefTable.list) { Reference ref = so.getObj(); - Entity entRef = ref.getEnt(); - getWrapper().saveAssertion(entRef, getUserName()); + getWrapper().saveEntity(entRef, getUserName()); //entity can be no persistent, therefore the assignment of the relation should be done after the save entRef.addSourceRelation(rel_is_reference_of, entity); //new Relation(entRef, entity, rel_is_reference_of); @@ -269,12 +287,12 @@ } - public static de.mpiwg.itgroup.ismi.util.guiComponents.Calendar updateCalendar(Attribute att){ - de.mpiwg.itgroup.ismi.util.guiComponents.Calendar calendar = null; + public static Calendar updateCalendar(Attribute att){ + Calendar calendar = null; if(att != null && StringUtils.isNotEmpty(att.getOwnValue())){ - calendar = new de.mpiwg.itgroup.ismi.util.guiComponents.Calendar(att.getOwnValue()); + calendar = new Calendar(att.getOwnValue()); }else{ - calendar = new de.mpiwg.itgroup.ismi.util.guiComponents.Calendar(); + calendar = new Calendar(); } return calendar; } @@ -314,40 +332,38 @@ } /** - * <p> - * "Entity -> CurrentEntity" - * </p> - * <p> - * This method updates the attributes of the given entity with the + * Update the defined attributes of the given entity with the * attributes of the attributes Map<String, String>. - * </p> * - * @return the input's entity with updated attributes. + * @return the entity with updated attributes. */ - public Entity updateEntityAttributes(Entity entity) { - if (entity == null) { - entity = new Entity(Node.TYPE_ABOX, false); - //entity.setObjectClass(getDefinition().getOwnValue()); - entity.setObjectClass(this.defObjectClass); - } - //for (Attribute defAtt : getDefinition(entity).getAttributes()) { - for (Attribute defAtt : getWrapper().getDefAttributes(this.defObjectClass)) { - Attribute att = entity.getAttributeByName(defAtt.getOwnValue()); - if (StringUtils.isNotEmpty(this.attributes - .get(defAtt.getOwnValue()))) { - if (att == null) { - att = new Attribute(defAtt); - entity.addAttribute(att); - } - att.setOwnValue(this.attributes.get(defAtt.getOwnValue())); - att.setObjectClass(defAtt.getOwnValue()); - } else if (att != null) { - // the attribute must be deleted. - entity.getAttributes().remove(att); - } - } - return entity; - } + public Entity updateEntityAttributes(Entity entity) { + // create entity if it doesn't exist + if (entity == null) { + entity = new Entity(Node.TYPE_ABOX, false); + entity.setObjectClass(this.defObjectClass); + } + // update all defined attributes + for (Attribute defAtt : getWrapper().getDefAttributes(this.defObjectClass)) { + String attName = defAtt.getOwnValue(); + Attribute att = entity.getAttributeByName(attName); + if (StringUtils.isNotEmpty(this.attributes.get(attName))) { + // there is an attribute to update + if (att == null) { + // attribute is new + att = new Attribute(defAtt); + entity.addAttribute(att); + } + // update value + att.setOwnValue(this.attributes.get(attName)); + att.setObjectClass(attName); + } else if (att != null) { + // there is no attribute to update - delete attribute + entity.getAttributes().remove(att); + } + } + return entity; + } protected List<SelectItem> updateSuggestedPersonByRole(String searchWord, String objClass, String attName, String role){ List<Attribute> attList = getWrapper().getAttributesByDefByAttName(objClass, attName, searchWord.toString(), -1); @@ -637,7 +653,7 @@ } public void registerChecker(StatusChecker sc) { - statusChecker.add(sc); + statusCheckers.add(sc); } public void registerChecker(ListenerObject lo, String message) { @@ -647,7 +663,7 @@ public void registerChecker(StatusChecker sc, String message) { sc.setMessage(message); - statusChecker.add(sc); + statusCheckers.add(sc); } class CheckResults { @@ -658,10 +674,15 @@ } + /** + * Get the result from all StatusCheckers. + * + * @return + */ public CheckResults getCheckResults() { CheckResults cr = new CheckResults(); - for (StatusChecker sc : statusChecker) { + for (StatusChecker sc : statusCheckers) { if (sc.getStatus().equals("false")) { cr.hasErrors = true; cr.errors.add(sc.getMessage()); @@ -842,41 +863,40 @@ return lo; } - protected void generateSecundaryOW(Entity entity, String user) throws Exception{ - List<Entity> nodeList = new ArrayList<Entity>(); - - long start = System.currentTimeMillis(); - if(entity.getObjectClass().equals(PLACE)){ - this.generateOW4City(entity, nodeList, user); - long medium = System.currentTimeMillis(); - System.out.println("nodeList.size(): " + nodeList.size() + " time: " + (medium - start)); - getWrapper().saveEntityListAsNodeWithoutContent(nodeList, user); - System.out.println("Save time: " + (System.currentTimeMillis() - medium)); - }else if(entity.getObjectClass().equals(REPOSITORY)){ - this.generateOW4Repository(entity, nodeList, new HashMap<String, String>(), user); - long medium = System.currentTimeMillis(); - System.out.println("nodeList.size(): " + nodeList.size() + " time: " + (medium - start)); - getWrapper().saveEntityListAsNodeWithoutContent(nodeList, user); - System.out.println("Save time: " + (System.currentTimeMillis() - medium)); - }else if(entity.getObjectClass().equals(COLLECTION)){ - this.generateOW4Collection(entity, nodeList, new HashMap<String, String>(), user); - long medium = System.currentTimeMillis(); - System.out.println("nodeList.size(): " + nodeList.size() + " time: " + (medium - start)); - getWrapper().saveEntityListAsNodeWithoutContent(nodeList, user); - System.out.println("Save time: " + (System.currentTimeMillis() - medium)); - }else if(entity.getObjectClass().equals(CODEX)){ - this.generateOW4Codex(entity, nodeList, new HashMap<String, String>(), user); - long medium = System.currentTimeMillis(); - System.out.println("nodeList.size(): " + nodeList.size() + " time: " + (medium - start)); - getWrapper().saveEntityListAsNodeWithoutContent(nodeList, user); - System.out.println("Save time: " + (System.currentTimeMillis() - medium)); - }else if(entity.getObjectClass().equals(TEXT)){ - generateOW4Text(entity, user); - long medium = System.currentTimeMillis(); - System.out.println("Saving witnessList time: " + (medium - start)); - } - //TODO PERSON and TEXT - } + /** + * Update the ownvalues of entities that are related to the given entity. + * + * @param entity + * @param user + * @throws Exception + */ + protected void updateRelatedOW(Entity entity, String user) throws Exception { + List<Entity> nodeList = new ArrayList<Entity>(); + + /* + * run updates depending on type + */ + if (entity.getObjectClass().equals(PLACE)) { + this.generateOW4City(entity, nodeList, user); + getWrapper().saveEntityListAsNodeWithoutContent(nodeList, user); + + } else if (entity.getObjectClass().equals(REPOSITORY)) { + this.generateOW4Repository(entity, nodeList, new HashMap<String, String>(), user); + getWrapper().saveEntityListAsNodeWithoutContent(nodeList, user); + + } else if (entity.getObjectClass().equals(COLLECTION)) { + this.generateOW4Collection(entity, nodeList, new HashMap<String, String>(), user); + getWrapper().saveEntityListAsNodeWithoutContent(nodeList, user); + + } else if (entity.getObjectClass().equals(CODEX)) { + this.generateOW4Codex(entity, nodeList, new HashMap<String, String>(), user); + getWrapper().saveEntityListAsNodeWithoutContent(nodeList, user); + + } else if (entity.getObjectClass().equals(TEXT)) { + generateOW4Text(entity, user); + } + // TODO PERSON and TEXT + } private void generateOW4City(Entity city, List<Entity> nodeList, String user){ Map<String, String> map = new HashMap<String, String>();