diff src/main/java/de/mpiwg/itgroup/ismi/entry/beans/CurrentWitnessBean.java @ 111:22a18bfc66b0

new completion that uses ALIASes: AbstractListenerObject. was_copied_in in WITNESS form can use PLACE aliases now. some cleanup.
author casties
date Fri, 09 Dec 2016 21:18:27 +0100
parents 2e911857a759
children 59f26a5ef2b3
line wrap: on
line diff
--- a/src/main/java/de/mpiwg/itgroup/ismi/entry/beans/CurrentWitnessBean.java	Thu Dec 08 16:05:18 2016 +0100
+++ b/src/main/java/de/mpiwg/itgroup/ismi/entry/beans/CurrentWitnessBean.java	Fri Dec 09 21:18:27 2016 +0100
@@ -17,6 +17,7 @@
 import org.mpi.openmind.repository.bo.Relation;
 import org.mpi.openmind.security.bo.User;
 
+import de.mpiwg.itgroup.ismi.auxObjects.AliasListenerObject;
 import de.mpiwg.itgroup.ismi.auxObjects.ListenerObject;
 import de.mpiwg.itgroup.ismi.auxObjects.lo.WitnessAuthorLO;
 import de.mpiwg.itgroup.ismi.auxObjects.lo.WitnessTextLO;
@@ -71,7 +72,7 @@
 	private ListenerObject copyistLo = new ListenerObject(PERSON, name_translit);
 
 	// WITENSS -> was_copied_at -> PLACE
-	private ListenerObject copyPlaceLo = new ListenerObject(PLACE, name);
+	private ListenerObject copyPlaceLo = new AliasListenerObject(PLACE, name, "is_alias_name_of");
 
 	// WITNESS -> xx -> PERSON
 	private ListenerObject patronageLo = new ListenerObject(PERSON, name_translit);
@@ -209,8 +210,21 @@
 			// WITENSS -> was_copied_by -> PERSON
 			this.entity.replaceSourceRelation(this.copyistLo.entity, PERSON, rel_was_copied_by);
 			
-			//WITENSS -> was_copied_in -> PLACE
-			this.entity.replaceSourceRelation(this.copyPlaceLo.entity, PLACE, "was_copied_in");
+			// WITNESS -> was_copied_in -> PLACE
+			Entity copyPlace = this.copyPlaceLo.entity;
+			if (copyPlace != null && copyPlace.getObjectClass().equals(PLACE)) {
+			    // regular PLACE
+	            this.entity.replaceSourceRelation(copyPlace, PLACE, "was_copied_in");
+			} else if (copyPlace != null && copyPlace.getObjectClass().equals("ALIAS")) {
+                // WITNESS -> was_copied_in_as -> ALIAS
+                this.entity.replaceSourceRelation(copyPlace, "ALIAS", "was_copied_in_as");
+                // ALIAS -> is_alias_name_of -> PLACE
+                List<Entity> places = getWrapper().getTargetsForSourceRelation(copyPlace, "is_alias_name_of", "PLACE", 1);
+                if (! places.isEmpty()) {
+                    // WITNESS -> was_copied_in -> PLACE
+                    this.entity.replaceSourceRelation(places.get(0), PLACE, "was_copied_in");
+                }
+            } 
 			
 			//REFERENCE -> is_reference_of -> WITNESS
 			//this.entity = this.prepareReferencesToSave(this.entity);
@@ -356,7 +370,7 @@
 			
 			List<Entity> targets = getWrapper().getTargetsForSourceRelation(titleLo.getEntity(), rel_was_created_by, PERSON, 1);
 			if(targets.size() > 0){
-				this.authorLo.setEntityAndAttribute0(targets.get(0));
+				this.authorLo.setEntityAndAttribute(targets.get(0));
 				
 			}else{
 				this.authorLo.reset();
@@ -453,12 +467,10 @@
 			for (Relation rel : witness.getSourceRelations()) {
 				Entity target = null;
 				if (rel.getOwnValue().equals(is_exemplar_of)) {
-
 					// WITNESS -> is_exemplar_of -> TEXT
 					target = getTargetRelation(rel);
-					titleLo.setEntityAndAttribute0(target);
+					titleLo.setEntityAndAttribute(target);
 					this.updateTitle();
-				
 				} else if (rel.getOwnValue().equals(is_possible_exemplar_of)) {
 					// WITNESS -> is_possible_exemplar_of -> TEXT
 					target = getTargetRelation(rel);
@@ -469,18 +481,25 @@
 				} else if (rel.getOwnValue().equals(rel_was_copied_by)) {
 					// WITENSS -> was_copied_by -> PERSON
 					target = getTargetRelation(rel);
-					copyistLo.setEntityAndAttribute0(target);
+					copyistLo.setEntityAndAttribute(target);
 				} else if (rel.getOwnValue().equals("was_copied_in")) {
 					// WITENSS -> was_copied_in -> PLACE
 					target = getTargetRelation(rel);
-					copyPlaceLo.setEntityAndAttribute0(target);
+					// don't use place if there is an alias
+					if (copyPlaceLo.getEntity().getObjectClass() == null) {
+					    copyPlaceLo.setEntityAndAttribute(target);
+					}
+                } else if (rel.getOwnValue().equals("was_copied_in_as")) {
+                    // WITENSS -> was_copied_in_as -> ALIAS
+                    target = getTargetRelation(rel);
+                    copyPlaceLo.setEntityAndAttribute(target);
 				} else if (rel.getOwnValue().equals(rel_had_patron)) {
 					// WITNESS -> had_patron -> PERSON
 					target = getTargetRelation(rel);
-					patronageLo.setEntityAndAttribute(target, name_translit);
+					patronageLo.setEntityAndAttributeName(target, name_translit);
 				} else if (rel.getOwnValue().equals(is_part_of)) {
-					// WITNESS -> had_patron -> PERSON		
-					if(rel.getTargetObjectClass().equals(CODEX)){
+					// WITNESS -> is_part_of -> CODEX
+					if (rel.getTargetObjectClass().equals(CODEX)) {
 						target = getTargetRelation(rel);
 						this.setCodex(target);
 					}
@@ -514,7 +533,7 @@
 	 * @param codex
 	 */
 	public void setCodex(Entity codex){
-		this.getCodexLo().setEntityAndAttribute(codex, "identifier");
+		this.getCodexLo().setEntityAndAttributeName(codex, "identifier");
 		
 		if(this.getCodexLo().entity != null && this.getCodexLo().entity.isPersistent()){
 			
@@ -684,7 +703,7 @@
 		if(this.selectedTitleId != null){
 			Entity title = getWrapper().getEntityById(this.selectedTitleId);
 			if(title != null){
-				this.titleLo.setEntityAndAttribute0(title);
+				this.titleLo.setEntityAndAttribute(title);
 				this.updateTitle();
 				setSelectTitleRendered(false);
 			}
@@ -771,11 +790,11 @@
 			Entity selectedPerson = getWrapper().getEntityByIdWithContent(selectedPersonId);
 			if(selectedPerson != null){
 				if (role.equals("Copyist")) {
-					copyistLo.setEntityAndAttribute0(selectedPerson);
+					copyistLo.setEntityAndAttribute(selectedPerson);
 				} else if (role.equals("Patron")) {
-					patronageLo.setEntityAndAttribute0(selectedPerson);
+					patronageLo.setEntityAndAttribute(selectedPerson);
 				} else if (role.equals("Author")) {
-					authorLo.setEntityAndAttribute0(selectedPerson);
+					authorLo.setEntityAndAttribute(selectedPerson);
 					this.updateAuthor();
 				}
 				setSelectPersonRendered(false);						
@@ -879,7 +898,7 @@
 						//juc Attribute att = getWrapper().getAttributeByName(possibleCodex, "identifier");
 						Attribute att = getWrapper().getAttributeByName(possibleCodex.getId(), "identifier");
 						if(att != null && identifier.equals(att.getValue())){
-							getCodexLo().setEntityAndAttribute(possibleCodex, "identifier");
+							getCodexLo().setEntityAndAttributeName(possibleCodex, "identifier");
 							return true;
 						}
 					}
@@ -892,7 +911,7 @@
 			getWrapper().saveEntity(newCodex, user);
 			Relation isPartOf = new Relation(newCodex, getCollectionLo().getEntity(), is_part_of);
 			getWrapper().saveRelationAsNode(isPartOf, user);
-			getCodexLo().setEntityAndAttribute(newCodex, "identifier");
+			getCodexLo().setEntityAndAttributeName(newCodex, "identifier");
 			
 		} catch (Exception e) {
 			logger.error(e.getMessage(), e);