changeset 136:502ae5b1a07d

fixing bugs from re-use efforts. misc cleanups.
author casties
date Thu, 02 Mar 2017 19:48:58 +0100
parents 0183b8a09717
children 3c585df9f874
files src/main/java/de/mpiwg/itgroup/ismi/entry/beans/AbstractISMIBean.java src/main/java/de/mpiwg/itgroup/ismi/entry/beans/CurrentCityBean.java src/main/java/de/mpiwg/itgroup/ismi/entry/beans/CurrentCodexBean.java src/main/java/de/mpiwg/itgroup/ismi/entry/beans/CurrentCollectionBean.java src/main/java/de/mpiwg/itgroup/ismi/entry/beans/CurrentPersonBean.java src/main/java/de/mpiwg/itgroup/ismi/entry/beans/CurrentRepositoryBean.java src/main/java/de/mpiwg/itgroup/ismi/entry/beans/CurrentTextBean.java src/main/java/de/mpiwg/itgroup/ismi/entry/beans/CurrentWitnessBean.java src/main/java/de/mpiwg/itgroup/ismi/util/guiComponents/Misattribution.java src/main/java/de/mpiwg/itgroup/ismi/util/guiComponents/MisattributionTable.java src/main/java/de/mpiwg/itgroup/ismi/util/guiComponents/Misidentification.java src/main/java/de/mpiwg/itgroup/ismi/util/guiComponents/MisidentificationTable.java src/main/webapp/entry/components/misattribution.xhtml
diffstat 13 files changed, 99 insertions(+), 83 deletions(-) [+]
line wrap: on
line diff
--- a/src/main/java/de/mpiwg/itgroup/ismi/entry/beans/AbstractISMIBean.java	Fri Feb 24 20:27:44 2017 +0100
+++ b/src/main/java/de/mpiwg/itgroup/ismi/entry/beans/AbstractISMIBean.java	Thu Mar 02 19:48:58 2017 +0100
@@ -290,21 +290,18 @@
 		
 	
 	/**
-	 * Save references and set relations.
+	 * Save references from this.endNoteRefTable and update relations.
 	 *  
 	 * @throws Exception
 	 */
-	protected void prepareEndNoteRefs2Save() throws Exception {
+	protected void saveReferences() throws Exception {
 		//REFERENCE -> is_reference_of -> WITNESS
 		List<Entity> refs = new ArrayList<Entity>();
-		this.entity.removeAllTargetRelationsByName(rel_is_reference_of);
 		for (SelectableObject<Reference> so : this.endNoteRefTable.list) {
 			Reference ref = so.getObj();
 			Entity ent = ref.getEnt();
-			if (!ent.isPersistent()) {
-				// persist reference Entity
-				getWrapper().saveEntity(ent, getUserName(), Reference.editReferenceIntent);
-			}
+			// save reference Entity
+			getWrapper().saveEntity(ent, getUserName(), Reference.editReferenceIntent);
 			refs.add(ent);
 		}
 		// update relations
@@ -1090,7 +1087,7 @@
      * @param relName
      * @param aliasRelName
      */
-    protected void replaceUniqueAliasSourceRelation(Entity ent, AliasListenerObject lo, String targetClass, String relName, String aliasRelName) {
+    public void replaceUniqueAliasSourceRelation(Entity ent, AliasListenerObject lo, String targetClass, String relName, String aliasRelName) {
         Entity target = lo.entity;
         if (target == null || target.getObjectClass() == null) {
             return;
@@ -1098,6 +1095,7 @@
         if (target.getObjectClass().equals(targetClass)) {
             // regular target entity e.g. PLACE
             ent.replaceUniqueSourceRelation(target, targetClass, relName);
+            // should not have alias relation
             ent.removeAllSourceRelationsByName(aliasRelName);
         } else if (target.getObjectClass().equals(ALIAS)) {
             // e.g. WITNESS -> was_created_in_as -> ALIAS
@@ -1154,7 +1152,7 @@
 				// this should not happen
 				logger.error("Old relation to new target ID:"+oldRel);
 			} else {
-				ent.removeSourceRelation(relName, oldRel.getTargetId());
+				ent.removeSourceRelation(relName, tarId);
 			}
 		}
 	}
@@ -1202,7 +1200,7 @@
 				// this should not happen
 				logger.error("Old relation to new source ID:"+oldRel);
 			} else {
-				ent.removeTargetRelation(relName, oldRel.getTargetId());
+				ent.removeTargetRelation(relName, srcId);
 			}
 		}
 	}
--- a/src/main/java/de/mpiwg/itgroup/ismi/entry/beans/CurrentCityBean.java	Fri Feb 24 20:27:44 2017 +0100
+++ b/src/main/java/de/mpiwg/itgroup/ismi/entry/beans/CurrentCityBean.java	Thu Mar 02 19:48:58 2017 +0100
@@ -176,7 +176,7 @@
 			replaceMultipleTargetRelations(entity, aliasList.getEntities(), ALIAS, is_alias_name_of);
             
 			//REFERENCE -> is_reference_of -> THIS
-			this.prepareEndNoteRefs2Save();		
+			this.saveReferences();		
 			
 			// save this entity
 			this.entity = getWrapper().saveEntity(this.entity, getSessionUser().getEmail(), editPlaceIntent);
--- a/src/main/java/de/mpiwg/itgroup/ismi/entry/beans/CurrentCodexBean.java	Fri Feb 24 20:27:44 2017 +0100
+++ b/src/main/java/de/mpiwg/itgroup/ismi/entry/beans/CurrentCodexBean.java	Thu Mar 02 19:48:58 2017 +0100
@@ -252,7 +252,7 @@
 			
 			//REFERENCE -> is_reference_of -> THIS
 			//this.entity = this.prepareReferencesToSave(this.entity);
-			this.prepareEndNoteRefs2Save();		
+			this.saveReferences();		
 
 			// CODEX -> owned_by -> PERSON
 			replaceMultipleSourceRelations(entity, ownedByPeople.getEntities(), PERSON, owned_by);
--- a/src/main/java/de/mpiwg/itgroup/ismi/entry/beans/CurrentCollectionBean.java	Fri Feb 24 20:27:44 2017 +0100
+++ b/src/main/java/de/mpiwg/itgroup/ismi/entry/beans/CurrentCollectionBean.java	Thu Mar 02 19:48:58 2017 +0100
@@ -138,7 +138,7 @@
 			this.entity.replaceUniqueSourceRelation(this.getRepositoryLo().entity, REPOSITORY, is_part_of);
 
 			// REFERENCE -> is_reference_of -> THIS
-			this.prepareEndNoteRefs2Save();
+			this.saveReferences();
 
 			if (isSelectedSaveAsNew()) {
 				// this.entity.removeAllTargetRelations(is_part_of, CODEX);
--- a/src/main/java/de/mpiwg/itgroup/ismi/entry/beans/CurrentPersonBean.java	Fri Feb 24 20:27:44 2017 +0100
+++ b/src/main/java/de/mpiwg/itgroup/ismi/entry/beans/CurrentPersonBean.java	Thu Mar 02 19:48:58 2017 +0100
@@ -271,10 +271,9 @@
             // PERSON -> was_died_in -> PLACE
             replaceUniqueAliasSourceRelation(this.entity, deathPlaceLo, PLACE, "died_in", "died_in_as");            
 
-			// ALIAS -> is_alias_name_of -> PERSON
-			replaceMultipleTargetRelations(entity, aliasList.getEntities(), ALIAS, is_alias_name_of);
-			
             // ALIAS -> is_prime_alias_name_of/is_alias_name_of -> PERSON
+			ArrayList<Entity> aliasNames = new ArrayList<Entity>(aliasList.getEntities());
+			// replace prime_alias_name with alias_name  
 			this.entity.removeAllTargetRelationsByName(is_prime_alias_name_of);
 			if (shortNameAlias != null) {
 				if (shortNameAlias.getAttributeByName(alias) == null) {
@@ -285,8 +284,10 @@
 				}
 				shortNameAlias = getWrapper().saveEntity(shortNameAlias, getSessionUser().getEmail(), null);
 				// save as is_alias_name_of
-				entity.replaceUniqueTargetRelation(shortNameAlias, ALIAS, is_alias_name_of);
+				aliasNames.add(shortNameAlias);
 			}
+			// set alias names
+			replaceMultipleTargetRelations(entity, aliasNames, ALIAS, is_alias_name_of);
 			
 			// PERSON -> lived_in -> PLACE (manyToMany)
 			this.entity.removeAllSourceRelationsByName(lived_in);
@@ -343,7 +344,7 @@
 			replaceMultipleSourceRelations(entity, roleList.getEntities(), ROLE, has_role);
 			
 			//REFERENCE -> is_reference_of -> THIS
-			this.prepareEndNoteRefs2Save();
+			this.saveReferences();
 			
 			// save entity
 			this.entity = getWrapper().saveEntity(this.entity, getSessionUser().getEmail(), editPersonIntent);
--- a/src/main/java/de/mpiwg/itgroup/ismi/entry/beans/CurrentRepositoryBean.java	Fri Feb 24 20:27:44 2017 +0100
+++ b/src/main/java/de/mpiwg/itgroup/ismi/entry/beans/CurrentRepositoryBean.java	Thu Mar 02 19:48:58 2017 +0100
@@ -104,7 +104,7 @@
 			this.entity.replaceUniqueSourceRelation(this.getCityLo().getEntity(), PLACE, is_in);
 			
 			//REFERENCE -> is_reference_of -> THIS
-			this.prepareEndNoteRefs2Save();
+			this.saveReferences();
 			
 			if(isSelectedSaveAsNew()){
 				//this.entity.removeAllTargetRelations(is_part_of, COLLECTION);
--- a/src/main/java/de/mpiwg/itgroup/ismi/entry/beans/CurrentTextBean.java	Fri Feb 24 20:27:44 2017 +0100
+++ b/src/main/java/de/mpiwg/itgroup/ismi/entry/beans/CurrentTextBean.java	Thu Mar 02 19:48:58 2017 +0100
@@ -27,7 +27,6 @@
 import de.mpiwg.itgroup.ismi.auxObjects.ListenerObject;
 import de.mpiwg.itgroup.ismi.util.guiComponents.Calendar;
 import de.mpiwg.itgroup.ismi.util.guiComponents.EntityList;
-import de.mpiwg.itgroup.ismi.util.guiComponents.Misattribution;
 import de.mpiwg.itgroup.ismi.util.guiComponents.MisattributionTable;
 
 public class CurrentTextBean extends AbstractISMIBean implements Serializable{
@@ -609,13 +608,13 @@
 			replaceMultipleTargetRelations(entity, explicitAliasList.getEntities(), ALIAS, "is_alias_explicit_of");
 			
 			// set references
-			this.prepareEndNoteRefs2Save();
+			this.saveReferences();
 			
 			/*
-			 * set misattribution
+			 * save misattributions
 			 */
-			this.entity.removeAllSourceRelations(Misattribution.HAS_AUTHOR_MISATT, Misattribution.MISATT);
-			
+			this.entity = this.misattTable.saveMisattributions(this.entity);
+						
 			/*
 			 * save entity
 			 */
@@ -623,11 +622,6 @@
 			this.getAppBean().setAllTextsAsDirty();
 			getAppBean().getSimpleSearchCache().setMapDirty(true);
 			
-			/*
-			 * save misattributions
-			 */
-			this.entity = this.misattTable.saveMisattributions(this.entity);
-			
 			// re-set entity
 			this.setEntity(this.entity);
 			
--- a/src/main/java/de/mpiwg/itgroup/ismi/entry/beans/CurrentWitnessBean.java	Fri Feb 24 20:27:44 2017 +0100
+++ b/src/main/java/de/mpiwg/itgroup/ismi/entry/beans/CurrentWitnessBean.java	Thu Mar 02 19:48:58 2017 +0100
@@ -236,7 +236,7 @@
 			replaceUniqueAliasSourceRelation(this.entity, this.copyPlaceLo, PLACE, rel_was_copied_in, rel_was_copied_in_as);
 			
 			//REFERENCE -> is_reference_of -> WITNESS
-			this.prepareEndNoteRefs2Save();
+			this.saveReferences();
 			
 			//WITNESS -> was studied by manyToMany -> PERSON
 			replaceMultipleSourceRelations(entity, studiedByList.getEntities(), PERSON, rel_was_studied_by);
@@ -262,7 +262,9 @@
 			if(this.isSelectedSaveAsNew()){
 				//this.entity = getWrapper().saveEntityAsNew(this.entity, user.getEmail());
 			}else{
-				// save this entity
+				/*
+				 * save this entity
+				 */
 				this.entity = getWrapper().saveEntity(this.entity, user.getEmail(), editWitnessIntent);
 			}
 			// re-set form
--- a/src/main/java/de/mpiwg/itgroup/ismi/util/guiComponents/Misattribution.java	Fri Feb 24 20:27:44 2017 +0100
+++ b/src/main/java/de/mpiwg/itgroup/ismi/util/guiComponents/Misattribution.java	Thu Mar 02 19:48:58 2017 +0100
@@ -3,10 +3,10 @@
 import java.io.Serializable;
 import java.util.List;
 
+import org.apache.commons.lang.StringUtils;
 import org.mpi.openmind.cache.WrapperService;
 import org.mpi.openmind.repository.bo.Entity;
 import org.mpi.openmind.repository.bo.Node;
-import org.mpi.openmind.repository.bo.Relation;
 
 public class Misattribution implements Serializable {
 	private static final long serialVersionUID = -1840193000833171154L;
@@ -27,7 +27,15 @@
 		this.userName = userName;
 	}
 	
-	public Entity saveAndGetMisattribution(Entity text) throws Exception{
+	/**
+	 * Save the MISATTRIBUTION Entity represented by this Misattribution object as
+	 * a misattribution of the given TEXT.
+	 *  
+	 * @param text
+	 * @return
+	 * @throws Exception
+	 */
+	public Entity saveMisattribution(Entity text) throws Exception{
 
 	    // create misattribution if necessary
 		if(misatt == null){
@@ -36,19 +44,23 @@
 		
 		// save reference
 		Entity entityRef = this.ref.getEnt();
-		ot.saveEntity(entityRef, userName, null);
-
-		// set person relation to misattribution
-		this.misatt.removeAllSourceRelations(MISATTRIBUTED_TO, "PERSON");
-		new Relation(misatt, person, MISATTRIBUTED_TO);
+		if (StringUtils.isEmpty(entityRef.getAttributeByName("endnote-id").getOwnValue())) {
+			entityRef = null;
+		} else {
+			ot.saveEntity(entityRef, userName, null);
+		}
 		
 		// set reference relation to misattribution
-		this.misatt.removeAllTargetRelations(IS_REFERENCE_OF, "REFERENCE");
-		new Relation(entityRef, misatt, IS_REFERENCE_OF);
+		this.misatt.replaceUniqueTargetRelation(entityRef, "REFERENCE", IS_REFERENCE_OF);			
+
+		// set person relation to misattribution
+		if (person.isLightweight()) {
+			person = ot.getEntityContent(person);
+		}
+		this.misatt.replaceUniqueSourceRelation(person, "PERSON", MISATTRIBUTED_TO);
 		
 		// set text relation to misattribution
-		this.misatt.removeAllTargetRelations(HAS_AUTHOR_MISATT, "TEXT");
-		new Relation(text, misatt, HAS_AUTHOR_MISATT);
+		this.misatt.replaceUniqueTargetRelation(text, "TEXT", HAS_AUTHOR_MISATT);
 		
 		// save misattribution
 		ot.saveEntity(misatt, userName, null);
@@ -82,12 +94,16 @@
 		
 		tmpList = ot.getSourcesForTargetRelation(misatt, IS_REFERENCE_OF, "REFERENCE", -1);
 		if(tmpList.size() > 0){
+			// take first reference
 			Entity ref = tmpList.get(0);
 			if(ref.isLightweight()){
 				ref = ot.getEntityByIdWithContent(ref.getId());
 			}
 			obj.setRef(new Reference(ref));
-		}		
+		} else {
+			// create empty reference
+			obj.setRef(new Reference(null));
+		}
 		
 		//this.person = person;
 		//this.ref = new Reference(ref);
--- a/src/main/java/de/mpiwg/itgroup/ismi/util/guiComponents/MisattributionTable.java	Fri Feb 24 20:27:44 2017 +0100
+++ b/src/main/java/de/mpiwg/itgroup/ismi/util/guiComponents/MisattributionTable.java	Thu Mar 02 19:48:58 2017 +0100
@@ -101,7 +101,7 @@
 	}
 	
 	/**
-	 * Save all misattributions.
+	 * Save all misattributions on this text.
 	 * 
 	 * Deletes removed misattributions.
 	 * 
@@ -112,26 +112,27 @@
 	public Entity saveMisattributions(Entity text) throws Exception {
 		// remember old misattributions
 		List<Relation> oldRels = text.getSourceRelations(Misattribution.HAS_AUTHOR_MISATT, Misattribution.MISATT);
-		// delete old relations
-		text.removeAllSourceRelationsByName(Misattribution.HAS_AUTHOR_MISATT);
-		// create new misattributions
+		List<Entity> misatts = new ArrayList<Entity>();
+		// save new misattributions
 		for (Misattribution misatt : this.getMisattList()) {
-			text = misatt.saveAndGetMisattribution(text);
+			misatt.saveMisattribution(text);
+			misatts.add(misatt.getMisatt());
 		}
+		// update relations
+		this.replaceMultipleSourceRelations(text, misatts, Misattribution.MISATT, Misattribution.HAS_AUTHOR_MISATT);
 		// check for orphaned old misattributions
 		for (Relation rel : oldRels) {
-			boolean match = false;
-			for (Misattribution mi : this.getMisattList()) {
-				Entity miEnt = mi.getMisatt();
+			boolean found = false;
+			for (Entity miEnt : misatts) {
 				if (miEnt != null && rel.getTargetId() == miEnt.getId()) {
-					match = true;
+					found = true;
 					break;
 				}
 			}
-			if (!match) {
-				Entity ent = getWrapper().getEntityById(rel.getTargetId());
-				logger.warn("Orphaned MISATTRIBUTION will be deleted: " + ent);
-				getWrapper().removeCurrentVersionEntity(ent, getUserName());
+			if (!found) {
+				Entity miEnt = getWrapper().getEntityById(rel.getTargetId());
+				logger.warn("Orphaned MISATTRIBUTION will be deleted: " + miEnt);
+				getWrapper().removeCurrentVersionEntity(miEnt, getUserName());
 			}
 		}
 		return text;
--- a/src/main/java/de/mpiwg/itgroup/ismi/util/guiComponents/Misidentification.java	Fri Feb 24 20:27:44 2017 +0100
+++ b/src/main/java/de/mpiwg/itgroup/ismi/util/guiComponents/Misidentification.java	Thu Mar 02 19:48:58 2017 +0100
@@ -3,11 +3,11 @@
 import java.io.Serializable;
 import java.util.List;
 
+import org.apache.commons.lang.StringUtils;
 import org.mpi.openmind.cache.WrapperService;
 import org.mpi.openmind.repository.bo.Attribute;
 import org.mpi.openmind.repository.bo.Entity;
 import org.mpi.openmind.repository.bo.Node;
-import org.mpi.openmind.repository.bo.Relation;
 
 public class Misidentification implements Serializable {
 	private static final long serialVersionUID = -1840193000833171153L;
@@ -32,7 +32,7 @@
 		this.userName = userName;
 	}
 
-	public Entity saveAndGetMisidentification(Entity witness) throws Exception {
+	public Entity saveMisidentification(Entity witness) throws Exception {
 
 		// create misidentification if necessary
 		if (misident == null) {
@@ -53,25 +53,25 @@
 
 		// save reference
 		Entity entityRef = this.ref.getEnt();
-		ot.saveEntity(entityRef, userName, null);
+		if (StringUtils.isEmpty(entityRef.getAttributeByName("endnote-id").getOwnValue())) {
+			entityRef = null;
+		} else {
+			ot.saveEntity(entityRef, userName, null);
+		}
+
+		// set reference relation to misidentification
+		misident.replaceUniqueTargetRelation(entityRef, "REFERENCE", IS_REFERENCE_OF);
 
 		// set person relation to misidentification
-		this.misident.removeAllSourceRelations(MISATTRIBUTED_TO, "PERSON");
 		if (person.isLightweight()) {
 			person = ot.getEntityContent(person);
 		}
-		new Relation(misident, person, MISATTRIBUTED_TO);
-
-		// set reference relation to misidentification
-		this.misident.removeAllTargetRelations(IS_REFERENCE_OF, "REFERENCE");
-		new Relation(entityRef, misident, IS_REFERENCE_OF);
+		misident.replaceUniqueSourceRelation(person, "PERSON", MISATTRIBUTED_TO);
 
 		// set text relation to misidentification
-		this.misident.removeAllTargetRelations(HAS_MISIDENT, "WITNESS");
-		new Relation(witness, misident, HAS_MISIDENT);
+		misident.replaceUniqueTargetRelation(witness, "WITNESS", HAS_MISIDENT);
 
 		// save misidentification 
-		// FIXME: really save here?
 		ot.saveEntity(misident, userName, null);
 
 		return witness;
@@ -124,6 +124,9 @@
 				ref = ot.getEntityByIdWithContent(ref.getId());
 			}
 			obj.setRef(new Reference(ref));
+		} else {
+			// create empty reference
+			obj.setRef(new Reference(null));
 		}
 
 		// this.person = person;
--- a/src/main/java/de/mpiwg/itgroup/ismi/util/guiComponents/MisidentificationTable.java	Fri Feb 24 20:27:44 2017 +0100
+++ b/src/main/java/de/mpiwg/itgroup/ismi/util/guiComponents/MisidentificationTable.java	Thu Mar 02 19:48:58 2017 +0100
@@ -111,26 +111,27 @@
 	public Entity saveMisidentifications(Entity witness) throws Exception {
 		// remember old misidentifications
 		List<Relation> oldRels = witness.getSourceRelations(Misidentification.HAS_MISIDENT, Misidentification.MISIDENT);
-		// delete old relations
-		witness.removeAllSourceRelationsByName(Misidentification.HAS_MISIDENT);
-		// create new misidentifications
+		List<Entity> misidents = new ArrayList<Entity>();
+		// save new misidentifications
 		for (Misidentification misident : this.getMisidentList()) {
-			witness = misident.saveAndGetMisidentification(witness);
+			misident.saveMisidentification(witness);
+			misidents.add(misident.getMisident());			
 		}
+		// update relations
+		this.replaceMultipleSourceRelations(witness, misidents, Misidentification.MISIDENT, Misidentification.HAS_MISIDENT);
 		// check for orphaned old misidentifications
 		for (Relation rel : oldRels) {
-			boolean match = false;
-			for (Misidentification mi : this.getMisidentList()) {
-				Entity miEnt = mi.getMisident();
+			boolean found = false;
+			for (Entity miEnt : misidents) {
 				if (miEnt != null && rel.getTargetId() == miEnt.getId()) {
-					match = true;
+					found = true;
 					break;
 				}
 			}
-			if (!match) {
-				Entity ent = getWrapper().getEntityById(rel.getTargetId());
-				logger.warn("Orphaned MISIDENTIFICATION will be deleted: "+ent);
-				getWrapper().removeCurrentVersionEntity(ent, getUserName());
+			if (!found) {
+				Entity miEnt = getWrapper().getEntityById(rel.getTargetId());
+				logger.warn("Orphaned MISIDENTIFICATION will be deleted: "+miEnt);
+				getWrapper().removeCurrentVersionEntity(miEnt, getUserName());
 			}
 		}
 		return witness;
--- a/src/main/webapp/entry/components/misattribution.xhtml	Fri Feb 24 20:27:44 2017 +0100
+++ b/src/main/webapp/entry/components/misattribution.xhtml	Thu Mar 02 19:48:58 2017 +0100
@@ -36,18 +36,18 @@
 								<h:panelGrid columns="2">
 
 									<h:outputLabel value="EndNote Id" />
-									<h:inputText
+									<h:inputText size="80"
 										value="#{CurrentText.misattTable.misatt.ref.endNoteId}" />
 
 									<h:outputLabel value="EndNote Content" />
 									<h:inputTextarea
 										value="#{CurrentText.misattTable.misatt.ref.endNoteContent}"
-										rows="10" cols="200" />
+										rows="10" cols="80" />
 
 									<h:outputLabel value="Additional Information" />
 									<h:inputTextarea
 										value="#{CurrentText.misattTable.misatt.ref.addInformation}"
-										rows="3" cols="200" />
+										rows="3" cols="80" />
 
 								</h:panelGrid>
 								<a4j:commandButton value="OK"