Mercurial > hg > ismi-richfaces
changeset 105:e27603a39e70
small cleanups.
author | casties |
---|---|
date | Fri, 04 Nov 2016 18:10:40 +0100 |
parents | 42d0169904f3 |
children | 71efad4fe975 |
files | src/main/java/de/mpiwg/itgroup/ismi/entry/beans/AbstractISMIBean.java src/main/java/de/mpiwg/itgroup/ismi/entry/beans/CodexEditorTemplate.java src/main/java/de/mpiwg/itgroup/ismi/entry/beans/CurrentCityBean.java |
diffstat | 3 files changed, 91 insertions(+), 73 deletions(-) [+] |
line wrap: on
line diff
--- a/src/main/java/de/mpiwg/itgroup/ismi/entry/beans/AbstractISMIBean.java Fri Nov 04 18:10:07 2016 +0100 +++ b/src/main/java/de/mpiwg/itgroup/ismi/entry/beans/AbstractISMIBean.java Fri Nov 04 18:10:40 2016 +0100 @@ -162,6 +162,11 @@ this.addGeneralMsg("Its ID is " + this.entity.getId()); } + /** + * Set the current Entity and parse data for the form. + * + * @param entity + */ public void setEntity(Entity entity) { this.entity = entity; } @@ -331,6 +336,9 @@ } } + /** + * Clear some selected options. + */ public void reset(){ this.setSelectedSaveAsNew(false); this.setCurrentId("");
--- a/src/main/java/de/mpiwg/itgroup/ismi/entry/beans/CodexEditorTemplate.java Fri Nov 04 18:10:07 2016 +0100 +++ b/src/main/java/de/mpiwg/itgroup/ismi/entry/beans/CodexEditorTemplate.java Fri Nov 04 18:10:40 2016 +0100 @@ -78,6 +78,10 @@ this.thereExistMoreCodices = false; } + /** + * Set this.countryLo and restrict by country type(?). + * @param country + */ public void setCountry(Entity country){ this.getCountryLo().setEntityAndAttribute0(country); this.restrictByCountry(country); @@ -356,8 +360,8 @@ } /** - * Restrict all list for the select menu, to the place selected - * TODO @Dirk this method seeks relations, which does not exist more, it implicates a bad performance. + * Restrict the list for the select menu, to the place selected + * * @param country */ protected void restrictByCountry(Entity country) { @@ -423,30 +427,35 @@ * ######################## */ - public void checkConsistencyFromCountryToCodex(){ - boolean consistent = false; - - Entity country = this.getCountryLo().entity; - if(country != null && country.isPersistent() && getCountryLo().getAttribute() != null &&StringUtils.isNotEmpty(getCountryLo().getAttribute().getValue())){ - - Attribute att = getWrapper().getAttributeByName(country.getId(), "name"); - - if(att != null && getCountryLo().getAttribute().getValue().equals(att.getValue())){ - this.getCountryLo().statusImage.setStatus(StatusImage.STATUS_OK); - consistent = true; - }else{ - this.getCountryLo().statusImage.setStatus(StatusImage.STATUS_FALSE); - } - }else{ - this.getCountryLo().statusImage.setStatus(StatusImage.STATUS_UNSET); - } - - if(consistent){ - this.checkConsistencyFromCityToCodex(country); - }else{ - this.labelStatesAsFalseOrUnset(true, true, true, true, false); - } - } + /** + * Returns if country (this.countryLo) has a proper name and continues checking + * city, repository, collection and codex. + */ + public void checkConsistencyFromCountryToCodex() { + boolean consistent = false; + + Entity country = this.getCountryLo().entity; + if (country != null && country.isPersistent() && getCountryLo().getAttribute() != null + && StringUtils.isNotEmpty(getCountryLo().getAttribute().getValue())) { + + Attribute att = getWrapper().getAttributeByName(country.getId(), "name"); + + if (att != null && getCountryLo().getAttribute().getValue().equals(att.getValue())) { + this.getCountryLo().statusImage.setStatus(StatusImage.STATUS_OK); + consistent = true; + } else { + this.getCountryLo().statusImage.setStatus(StatusImage.STATUS_FALSE); + } + } else { + this.getCountryLo().statusImage.setStatus(StatusImage.STATUS_UNSET); + } + + if (consistent) { + this.checkConsistencyFromCityToCodex(country); + } else { + this.labelStatesAsFalseOrUnset(true, true, true, true, false); + } + } private void checkConsistencyFromCityToCodex(Entity country){ boolean consistent = false;
--- a/src/main/java/de/mpiwg/itgroup/ismi/entry/beans/CurrentCityBean.java Fri Nov 04 18:10:07 2016 +0100 +++ b/src/main/java/de/mpiwg/itgroup/ismi/entry/beans/CurrentCityBean.java Fri Nov 04 18:10:40 2016 +0100 @@ -56,46 +56,50 @@ } @Override - public void setEntity(Entity city) { - this.reset(); - this.entity = city; - - if(this.entity.isPersistent()){ - if(city.isLightweight()){ - this.entity = getWrapper().getEntityContent(this.entity); - } - - this.loadAttributes(this.entity); - - List<Entity> list = getWrapper().getTargetsForSourceRelation(city, is_part_of, PLACE, -1); - if(list.size() > 0){ - this.setCountry(list.get(0)); - if(list.size() > 1){ - addErrorMsg("Ontological inconsistency. This place 'is part of' " + list.size() + " other places."); - addErrorMsg("List:"); - for(Entity place : list){ - addErrorMsg(place.getOwnValue() + " [" + place.getId() + "]"); - } - } - } - - for(Entity place : getWrapper().getSourcesForTargetRelation(city, is_part_of, PLACE, -1)){ - String label = place.getOwnValue() + " [" + place.getId() + "]"; - this.placesPartOfThis.add(new SelectableObject<Entity>(place, label)); - } - - for(Entity person : getWrapper().getSourcesForTargetRelation(city, lived_in, PERSON, -1)){ - String label = person.getOwnValue() + " [" + person.getId() + "]"; - this.peopleLivedIn.add(new SelectableObject<Entity>(person, label)); - } - - //this.loadReferences(this.entity); - this.loadEndNoteRefs(); - - this.setCurrentId(this.entity.getId().toString()); - this.checkConsistencyFromCountryToCodex(); - } - } + public void setEntity(Entity city) { + this.reset(); + this.entity = city; + + if (this.entity.isPersistent()) { + // load attributes and relations of Entity + if (city.isLightweight()) { + this.entity = getWrapper().getEntityContent(this.entity); + } + // load entity attributes into bean + this.loadAttributes(this.entity); + + /* + * create list of places this place is part_of + */ + List<Entity> list = getWrapper().getTargetsForSourceRelation(city, is_part_of, PLACE, -1); + if (list.size() > 0) { + this.setCountry(list.get(0)); + // part_of more than one place + if (list.size() > 1) { + addErrorMsg("Ontological inconsistency. This place 'is part of' " + list.size() + " other places."); + addErrorMsg("List:"); + for (Entity place : list) { + addErrorMsg(place.getOwnValue() + " [" + place.getId() + "]"); + } + } + } + + /* + * create list of places that are part of this place + */ + for (Entity place : getWrapper().getSourcesForTargetRelation(city, is_part_of, PLACE, -1)) { + String label = place.getOwnValue() + " [" + place.getId() + "]"; + this.placesPartOfThis.add(new SelectableObject<Entity>(place, label)); + } + + // load references + this.loadEndNoteRefs(); + + this.setCurrentId(this.entity.getId().toString()); + // check consistency and set checkmark(s) + this.checkConsistencyFromCountryToCodex(); + } + } @Override public String save(){ @@ -120,19 +124,17 @@ return "SAVE_ERROR"; } }else{ - this.addErrorMsg("Ths entity has not been saved, because its name was empty."); - this.addErrorMsg("You must enter a name."); + this.addErrorMsg("This place has not been saved, because its name was empty."); + this.addErrorMsg("You have to enter a name."); return "SAVE_ERROR"; } - //this.entity.removeSourceRelation("is_part_of", this.getCountryLo().entity); - //replaceSourceRelation(this.entity, this.getCountryLo().entity, "PLACE", "is_part_of"); this.entity.replaceSourceRelation(this.getCountryLo().entity, PLACE, is_part_of); this.entity.removeAllTargetRelationsByName(is_part_of); for(SelectableObject<Entity> so : this.placesPartOfThis){ Entity place = getWrapper().getEntityByIdWithContent(so.getObj().getId()); - Relation isPartOf = new Relation(place, this.entity, is_part_of); + new Relation(place, this.entity, is_part_of); } /* @@ -161,14 +163,13 @@ this.updateRelatedOW(this.entity, getSessionUser().getEmail()); this.setCurrentId(this.entity.getId().toString()); - logger.info("Entity saved - Time = " + (System.currentTimeMillis() - start) + ", " + entity); + logger.debug("Place saved - Time = " + (System.currentTimeMillis() - start) + ", " + entity); this.printSuccessSavingEntity(); this.setSelectedSaveAsNew(false); } catch (Exception e) { logger.error(e.getMessage(), e); - e.printStackTrace(); this.printInternalError(e); } saveEnd();