Mercurial > hg > ismi-richfaces
diff src/main/java/de/mpiwg/itgroup/ismi/entry/beans/CurrentTextBean.java @ 91:d172201d24ad
more comments and refactorings.
author | casties |
---|---|
date | Wed, 12 Oct 2016 20:50:30 +0200 |
parents | 72b877076f43 |
children | 9adcab5143a3 |
line wrap: on
line diff
--- a/src/main/java/de/mpiwg/itgroup/ismi/entry/beans/CurrentTextBean.java Wed Oct 12 15:34:49 2016 +0200 +++ b/src/main/java/de/mpiwg/itgroup/ismi/entry/beans/CurrentTextBean.java Wed Oct 12 20:50:30 2016 +0200 @@ -24,8 +24,8 @@ import de.mpiwg.itgroup.ismi.auxObjects.ListenerObject; import de.mpiwg.itgroup.ismi.util.guiComponents.Calendar; -import de.mpiwg.itgroup.ismi.util.guiComponents.EndNoteMisattribution; -import de.mpiwg.itgroup.ismi.util.guiComponents.EndNoteMisattributionTable; +import de.mpiwg.itgroup.ismi.util.guiComponents.Misattribution; +import de.mpiwg.itgroup.ismi.util.guiComponents.MisattributionTable; import de.mpiwg.itgroup.ismi.util.guiComponents.EntityList; public class CurrentTextBean extends AbstractISMIBean implements Serializable{ @@ -106,7 +106,7 @@ private EntityList explicitAliasList; //private MisattributionDataTable misattDataTable; - private transient EndNoteMisattributionTable misattTable; + private transient MisattributionTable misattTable; public CurrentTextBean() { this.reset(); @@ -122,7 +122,7 @@ this.incipitAliasList = new EntityList(ALIAS, "alias", getWrapper(), getUserName()); this.explicitAliasList = new EntityList(ALIAS, "alias", getWrapper(), getUserName()); //this.misattDataTable = new MisattributionDataTable(PERSON, "name_translit"); - this.misattTable = new EndNoteMisattributionTable(); + this.misattTable = new MisattributionTable(); this.selectPersonRendered = false; this.selectedPersonId = null; @@ -198,13 +198,20 @@ } /** - * Source's Relations # TEXT is_commentary_on TEXT # TEXT is_translation_of - * TEXT # TEXT is_version_of TEXT # TEXT was_created_by PERSON # TEXT - * was_created_in PLACE # TEXT was_dedicated_to PERSON # TEXT has_subject - * SUBJECT + * Set entity and process attributes and relations. * - * Target's Relations # ALIAS is_alias_title_of TEXT # ALIAS - * is_alias_incipit_of TEXT + * Source Relations: + * TEXT is_commentary_on TEXT, + * TEXT is_translation_of TEXT, + * TEXT is_version_of TEXT, + * TEXT was_created_by PERSON, + * TEXT was_created_in PLACE, + * TEXT was_dedicated_to PERSON, + * TEXT has_subject SUBJECT + * + * Target Relations: + * ALIAS is_alias_title_of TEXT, + * ALIAS is_alias_incipit_of TEXT * * @param text */ @@ -212,120 +219,105 @@ public void setEntity(Entity text) { this.reset(); this.entity = text; - if(this.entity.isPersistent()){ + if (this.entity.isPersistent()) { + // set id setCurrentId(this.entity.getId().toString()); + + // load content if (text.isLightweight()) { this.entity = getWrapper().getEntityContent(this.entity); this.entity.setLightweight(false); } + // set creation date Attribute attCreationDate = this.entity.getAttributeByName("creation_date"); - if(attCreationDate != null && StringUtils.isNotEmpty(attCreationDate.getOwnValue())){ + if(attCreationDate != null && StringUtils.isNotEmpty(attCreationDate.getOwnValue())) { this.creationDate = new Calendar(attCreationDate.getOwnValue()); - }else{ + } else { this.creationDate = new Calendar(); } + /* + * set attributes + */ this.loadAttributes(this.entity);//, getDefinition(this.entity)); + /* + * set source relations + */ for (Relation rel : text.getSourceRelations()) { Entity target = null; - if( rel.getOwnValue().equals(has_subject)){ + String relName = rel.getOwnValue(); + if(relName.equals(has_subject)) { this.subject = getTargetRelation(rel); this.idSubject = subject.getId(); - } else if (rel.getOwnValue().equals("is_commentary_on")) { + + } else if (relName.equals("is_commentary_on")) { target = getTargetRelation(rel); this.commentaryLo.setEntityAndAttribute0(target); - } else if (rel.getOwnValue().equals("is_translation_of")) { + + } else if (relName.equals("is_translation_of")) { target = getTargetRelation(rel); this.translationLo.setEntityAndAttribute0(target); - } else if (rel.getOwnValue().equals("is_version_of")) { + + } else if (relName.equals("is_version_of")) { target = getTargetRelation(rel); this.versionLo.setEntityAndAttribute0(target); - } else if (rel.getOwnValue().equals("was_created_by")) { + + } else if (relName.equals("was_created_by")) { target = getTargetRelation(rel); this.authorLo.setEntityAndAttribute0(target); - if(this.authorLo.attribute != null){ + if (this.authorLo.attribute != null) { this.textAuthorNameTranslit = this.authorLo.attribute.getValue(); } - } else if (rel.getOwnValue().equals("was_dedicated_to")) { + } else if (relName.equals("was_dedicated_to")) { target = getTargetRelation(rel); this.dedicatedPersonLo.setEntityAndAttribute0(target); - } else if (rel.getOwnValue().equals("was_created_in")) { + } else if (relName.equals("was_created_in")) { target = getTargetRelation(rel); - //rich this.placeLo.setEntityAndAttribute(target, "name"); this.placeLo.setEntityAndAttribute0(target); - //} else if (rel.getOwnValue().equals(misattributed_to)) { - } else if (rel.getOwnValue().equals("has_author_misattribution")) { + + } else if (relName.equals("has_author_misattribution")) { target = getTargetRelation(rel); - //String refId = (rel.getAttributeByName("reference_id") != null) ? rel.getAttributeByName("reference_id").getValue() : null; - //String notes = (rel.getAttributeByName("notes") != null) ? rel.getAttributeByName("notes").getValue() : null; - //target=person - //this.misattDataTable.add(target, refId, notes); - //this.misattTable.add(target, ref, rel); this.misattTable.load(target); } - } + + /* + * set target relations + */ for (Relation rel : text.getTargetRelations()) { - - if (rel.getOwnValue().equals("is_alias_title_of")) { + String relName = rel.getOwnValue(); + if (relName.equals("is_alias_title_of")) { Entity alias = getWrapper().getEntityByIdWithContent(rel.getSourceId()); - this.aliasList.add(alias); - } else if (rel.getOwnValue().equals("is_alias_incipit_of")) { + this.aliasList.add(alias); + + } else if (relName.equals("is_alias_incipit_of")) { Entity alias = getWrapper().getEntityByIdWithContent(rel.getSourceId()); this.incipitAliasList.add(alias); - } else if (rel.getOwnValue().equals("is_alias_explicit_of")) { + + } else if (relName.equals("is_alias_explicit_of")) { Entity alias = getWrapper().getEntityByIdWithContent(rel.getSourceId()); this.explicitAliasList.add(alias); - } else if (rel.getOwnValue().equals("is_prime_alias_title_of")) { + + } else if (relName.equals("is_prime_alias_title_of")) { Entity alias = getWrapper().getEntityByIdWithContent(rel.getSourceId()); this.shortTitleAlias = alias; this.valueShortTitle = alias.getAttributeByName("alias").getValue(); } } + /* + * set references + */ this.loadEndNoteRefs(); this.displayUrl = generateDisplayUrl(authorLo.entity, text, null, getAppBean().getRoot()); } } - /** - * Added by DW it is no used anymore - * - * @param event - */ - public void translitTitleChangeListener(ValueChangeEvent event) { - try { - if (event.getNewValue() == null) { - return; - } - if (event.getNewValue().equals(event.getOldValue())) { - return; - } - - String newName = (String) event.getNewValue(); - - if (translitTitleAlias == null) { - translitTitleAlias = new Entity(Node.TYPE_ABOX, "ALIAS", false); - } - - Attribute attr = this.translitTitleAlias - .getAttributeByName("alias"); - if (attr == null) { - this.translitTitleAlias.addAttribute(new Attribute("alias", - TEXT, newName)); - } else - attr.setValue(newName); - - } catch (Exception e) { - e.printStackTrace(); - } - } - public String translitTitleAction() { String pn = getAttributes().get("full_title"); @@ -501,6 +493,13 @@ this.setSelectPersonRendered(false); } + /** + * Check mandatory parts. + * + * In this case the author has to be set. + * + * @return + */ public boolean mandatoryEntriesOK(){ boolean ok = true; if(this.authorLo.entity == null || !this.authorLo.entity.isPersistent()){ @@ -510,18 +509,21 @@ return ok; } + /* (non-Javadoc) + * @see de.mpiwg.itgroup.ismi.entry.beans.AbstractISMIBean#save() + */ @Override public String save() { super.save(); try { - if(!mandatoryEntriesOK()){ + /* + * check input + */ + if (!mandatoryEntriesOK()) { addGeneralMsg("The entity could not be saved."); return PAGE_EDITOR; - } - - User user = getSessionUser(); - + } CheckResults cr = getCheckResults(); if (cr.hasErrors) { getSessionBean().setErrorMessages(cr); @@ -529,12 +531,17 @@ return PAGE_EDITOR; } + User user = getSessionUser(); - + // add creation date getAttributes().put("creation_date", this.creationDate.toJSONString()); + // update all attributes this.entity = updateEntityAttributes(this.entity); + /* + * set relations + */ this.entity.replaceSourceRelation(commentaryLo.entity, TEXT, "is_commentary_on"); this.entity.replaceSourceRelation(translationLo.entity, TEXT, "is_translation_of"); @@ -548,103 +555,97 @@ this.entity.replaceSourceRelation(placeLo.entity, PLACE, "was_created_in"); this.entity.removeAllSourceRelations(has_subject, SUBJECT); - if(getIdSubject() != null){ + if (getIdSubject() != null) { this.subject = getWrapper().getEntityByIdWithContent(getIdSubject()); this.entity.replaceSourceRelation(subject, SUBJECT, has_subject); } - - //is_prime_alias_title_of - if(!StringUtils.isEmpty(valueShortTitle)){ + /* + * set short title (is_prime_alias_title_of) + */ + if (!StringUtils.isEmpty(valueShortTitle)) { this.entity.removeAllTargetRelations("is_prime_alias_title_of", ALIAS); - if(this.shortTitleAlias == null){ + if (this.shortTitleAlias == null) { //1)create alias, 2) update value of alias3) save alias, and 4) add to this text. shortTitleAlias = new Entity(Node.TYPE_ABOX, ALIAS, false); shortTitleAlias.addAttribute(new Attribute("alias", "text", this.valueShortTitle)); getWrapper().saveEntity(shortTitleAlias, getUserName()); - }else{ + } else { //1) update value, 2) re-save alias this.shortTitleAlias.getAttributeByName("alias").setOwnValue(this.valueShortTitle); this.shortTitleAlias.removeAllSourceRelations("is_prime_alias_title_of", TEXT); getWrapper().saveEntity(shortTitleAlias, getUserName()); } - Relation aliasRel = new Relation(shortTitleAlias, this.entity, "is_prime_alias_title_of"); + new Relation(shortTitleAlias, this.entity, "is_prime_alias_title_of"); } /* - if (this.shortTitleAlias == null - || (shortTitleAlias.getAttributeByName("alias") != null && StringUtils - .isEmpty(shortTitleAlias - .getAttributeByName("alias").getOwnValue()))) { - this.entity.removeAllTargetRelations("is_prime_alias_title_of", - ALIAS); - } else if (this.shortTitleAlias != null) { - shortTitleAlias = getWrapper().saveEntity(shortTitleAlias, user.getEmail()); - this.entity.setAsUniqueTargetRelation("is_prime_alias_title_of", - this.shortTitleAlias); - } - */ - - //ALIAS -> is_alias_title_of -> TEXT + * set alias title (ALIAS -> is_alias_title_of -> TEXT) + */ this.entity.removeAllTargetRelationsByName("is_alias_title_of"); for(Entity alias : this.aliasList.getEntities()){ Entity alias0 = getWrapper().getEntityByIdWithContent(alias.getId()); - Relation aliasRel = new Relation(alias0, this.entity, "is_alias_title_of"); + new Relation(alias0, this.entity, "is_alias_title_of"); } - //saveAliases2(incipitAliases, deletedIncipitAliases, - // "is_alias_incipit_of"); - //deletedIncipitAliases = refreshAliasMap(incipitAliases, deletedIncipitAliases); + /* + * set alias incipit + */ this.entity.removeAllTargetRelationsByName("is_alias_incipit_of"); for(Entity alias : this.incipitAliasList.getEntities()){ Entity alias0 = getWrapper().getEntityByIdWithContent(alias.getId()); - Relation aliasRel = new Relation(alias0, this.entity, "is_alias_incipit_of"); + new Relation(alias0, this.entity, "is_alias_incipit_of"); } /* - saveAliases2(explicitAliases, deletedExplicitAliases, - "is_alias_explicit_of"); - deletedExplicitAliases = refreshAliasMap(explicitAliases, deletedExplicitAliases); - */ + * save alias explicit + */ this.entity.removeAllTargetRelationsByName("is_alias_explicit_of"); for(Entity alias : this.explicitAliasList.getEntities()){ Entity alias0 = getWrapper().getEntityByIdWithContent(alias.getId()); - Relation aliasRel = new Relation(alias0, this.entity, "is_alias_explicit_of"); + new Relation(alias0, this.entity, "is_alias_explicit_of"); } - //String lastAction = ""; - - //REFERENCE -> is_reference_of -> THIS - //this.entity = this.prepareReferencesToSave(this.entity); + // set references this.prepareEndNoteRefs2Save(); - this.entity.removeAllSourceRelations(EndNoteMisattribution.HAS_AUTHOR_MISATT, EndNoteMisattribution.MISATT); + /* + * set misattribution + */ + this.entity.removeAllSourceRelations(Misattribution.HAS_AUTHOR_MISATT, Misattribution.MISATT); + /* + * save entity + */ this.entity = getWrapper().saveEntity(this.entity, user.getEmail()); this.getAppBean().setAllTextsAsDirty(); getAppBean().getSimpleSearchCache().setMapDirty(true); + /* + * save misattributions + */ this.entity = this.misattTable.saveMisattributions(this.entity); + // re-set entity this.setEntity(this.entity); - //lastAction = "save text"; - - - this.generateSecundaryOW(this.entity, getSessionUser().getEmail()); + + // update related own values + this.updateRelatedOW(this.entity, getSessionUser().getEmail()); logger.info("Entity saved - Time = " + (System.currentTimeMillis() - start) + ", " + entity); + + // print success this.printSuccessSavingEntity(); - //setActionInfo(lastAction); - - } catch (Exception e) { logger.error(e.getMessage(), e); - e.printStackTrace(); this.printInternalError(e); } + + // end saving saveEnd(); + // stay on edit page return PAGE_EDITOR; } @@ -656,105 +657,6 @@ this.incipitAliasList = incipitAliasList; } - /** - * This method saves the text as new entity, and its related alias and - * witness. - * - * @return - */ - public String saveAsNewEntity() { - - try { - User user = getSessionUser(); - - CheckResults cr = getCheckResults(); - if (cr.hasErrors) { - getSessionBean().setErrorMessages(cr); - getSessionBean().setDisplayError(true); - return "SAVE_ERROR"; - } - - - this.entity = updateEntityAttributes(this.entity); - //text.setOwnValue(createOwnValue()); - - //text.removeSourceRelation("is_commentary_of", commentaryLo.entity); - //replaceSourceRelation(text, commentaryLo.entity, TEXT, "is_commentary_on"); - this.entity.replaceSourceRelation(commentaryLo.entity, TEXT, "is_commentary_on"); - - //text.removeSourceRelation("is_translation_of", translationLo.entity); - //replaceSourceRelation(text, translationLo.entity, TEXT, "is_translation_of"); - this.entity.replaceSourceRelation(translationLo.entity, TEXT, "is_translation_of"); - - //text.removeSourceRelation("is_version_of", versionLo.entity); - //replaceSourceRelation(text, versionLo.entity, TEXT, "is_version_of"); - this.entity.replaceSourceRelation(versionLo.entity, TEXT, "is_version_of"); - - //text.removeSourceRelation("was_created_by", authorLo.entity); - //replaceSourceRelation(text, authorLo.entity, PERSON, "was_created_by"); - this.entity.replaceSourceRelation(authorLo.entity, PERSON, "was_created_by"); - - //text.removeSourceRelation("was_dedicated_to", dedicatedPersonLo.entity); - //replaceSourceRelation(text, dedicatedPersonLo.entity, PERSON, - // "was_dedicated_to"); - this.entity.replaceSourceRelation(dedicatedPersonLo.entity, PERSON, "was_dedicated_to"); - - //text.removeSourceRelation("was_created_in", placeLo.entity); - //replaceSourceRelation(text, placeLo.entity, PLACE, "was_created_in"); - this.entity.replaceSourceRelation(placeLo.entity, PLACE, "was_created_in"); - - //String lastAction = ""; - - // removing transiently the target relation, - // because they should not be saved as new - this.entity.removeAllTargetRelations("is_exemplar_of", "WITNESS"); - this.entity.removeAllTargetRelations("is_prime_alias_title_of", "ALIAS"); - this.entity.removeAllTargetRelations("is_alias_title_of", "ALIAS"); - this.entity.removeAllTargetRelations("is_alias_incipit_of", "ALIAS"); - this.entity.removeAllTargetRelations("is_alias_explicit_of", "ALIAS"); - - - this.entity = getWrapper().saveEntityAsNew(this.entity, user.getEmail()); - //((AllTextsBean) this.getSessionBean("AllTexts")).setAllTextsAsDirty(); - this.getAppBean().setAllTextsAsDirty(); - getAppBean().getSimpleSearchCache().setMapDirty(true); - - //lastAction = "save text as new entity"; - getSessionBean().setEditFormCurrentEntId(this.entity.getId()); - - logger.info("The entity was saved successfully!!!" + this.entity); - //this.saveAsNew = false; - - //setActionInfo(lastAction); - - - } catch (Exception e) { - logger.error(e.getMessage(), e); - e.printStackTrace(); - this.printInternalError(e); - } - return PAGE_EDITOR; - } - - /** - * Refresh aliasMap: delete the tuples, which are ticked to be deleted. - * - * @param map - * @return - */ - private Map<Long, Boolean> refreshAliasMap(List<Entity> list, Map<Long, Boolean> aliasesMap){ - for(Long id : aliasesMap.keySet()){ - if(aliasesMap.get(id)){ - aliasesMap.remove(id); - Entity alias = getEntityById(list, id); - if(alias != null){ - list.remove(alias); - } - } - } - return aliasesMap; - } - public Attribute getAttTitleAlias() { return attTitleAlias; } @@ -819,82 +721,6 @@ return newTitleAlias; } - /** - * <p>This method saves transiently the aliases as new Entities, which are not marked to be deleted - * in aliasesMap.</p> - * - * @param aliases list of aliases showing in the interface. - * @param aliasesMap map id - boolean, which indicates if the alias[id] should be deleted(true). - * @param aliasRelationName name of the relation which links this text whith the given alias list. - * @param user - */ - /* - private void saveAliasesAsNew(List<Entity> aliases, - Map<Long, Boolean> aliasesMap, String aliasRelationName, String user) { - - //first step: save the alias, if it is ticked as 'no delete' - for(Long aliasId : aliasesMap.keySet()){ - if(!aliasesMap.get(aliasId)){ - Entity alias = getEntityById(aliases, new Long(aliasId)); - if(alias != null){ - alias.removeAllSourceRelations(aliasRelationName, TEXT); - Relation rel = new Relation(alias, this.entity, aliasRelationName); - getWrapper().saveEntityAsNew(alias, user); - } - } - } - }*/ - - /** - * <p>This method removes transiently the aliases, which are marked to be deleted - * and insert to the text the alias, which are not yet contained.</p> - * - * @param aliases list of aliases showing in the interface. - * @param aliasesMap map id - boolean, which indicates if the alias[id] should be deleted(true). - * @param aliasRelationName name of the relation which links this text whith the given alias list. - */ - /* - private void saveAliases2(List<Entity> aliases, - Map<Long, Boolean> aliasesMap, String aliasRelationName) { - - List<Relation> aliasRelList = this.entity.getTargetRelations(aliasRelationName, "ALIAS"); - - //first step: delete aliases, which are ticked to be deleted and are contained by the current text - for(Relation aliasRel : aliasRelList){ - //if the alias Map does not contain the 'relation source' or it is marked to be deleted, - //the relation should be removed from the text - if(!aliasesMap.containsKey(aliasRel.getSourceId()) || aliasesMap.get(aliasRel.getSourceId())){ - text.removeTargetRelation(aliasRel); - } - } - - //second step: insert alias (as relation) to the text, - //if the alias is not contained by the text - for(Long aliasId : aliasesMap.keySet()){ - if(!aliasesMap.get(aliasId)){ - if(!text.containsTargetRelation(aliasRelationName, new Long(aliasId))){ - Entity alias = getEntityById(aliases, new Long(aliasId)); - if(alias != null){ - Relation rel = new Relation(alias, this.entity, aliasRelationName); - } - } - } - } - }*/ - - /** - * TODO move this method to some util's package - * @return - */ - private Entity getEntityById(List<Entity> list, Long id){ - for(Entity e : list){ - if(e.getId().compareTo(id) == 0){ - return e; - } - } - return null; - } - public Map<Long, Boolean> getDeletedIncipitAliases() { return deletedIncipitAliases; } @@ -1097,11 +923,11 @@ this.selectedPersonId = selectedPersonId; } - public EndNoteMisattributionTable getMisattTable() { + public MisattributionTable getMisattTable() { return misattTable; } - public void setMisattTable(EndNoteMisattributionTable misattTable) { + public void setMisattTable(MisattributionTable misattTable) { this.misattTable = misattTable; }