diff src/main/java/de/mpiwg/itgroup/ismi/entry/beans/CurrentWitnessBean.java @ 134:25bfcc9d757c

effort to re-use more relations when saving entities. new replaceMultipleSourceRelations() and changes to use it. changes for renamed replaceUniqueSourceRelation().
author casties
date Fri, 24 Feb 2017 20:25:33 +0100
parents 5ccd6e709f95
children 502ae5b1a07d
line wrap: on
line diff
--- a/src/main/java/de/mpiwg/itgroup/ismi/entry/beans/CurrentWitnessBean.java	Thu Feb 23 19:25:37 2017 +0100
+++ b/src/main/java/de/mpiwg/itgroup/ismi/entry/beans/CurrentWitnessBean.java	Fri Feb 24 20:25:33 2017 +0100
@@ -224,30 +224,25 @@
 			this.entity = this.updateEntityAttributes(this.entity);
 
 			// WITNESS -> is_part_of -> CODEX
-			this.entity.replaceSourceRelation(getCodexLo().entity, CODEX, is_part_of);
+			this.entity.replaceUniqueSourceRelation(getCodexLo().entity, CODEX, is_part_of);
 			
 			// WITNESS -> is_exemplar_of -> TEXT -> was_created_by -> PERSON
 			//replaceSourceRelation(this.entity, this.author, PERSON, was_created_by);
 
 			// WITENSS -> was_copied_by -> PERSON
-			this.entity.replaceSourceRelation(this.copyistLo.entity, PERSON, rel_was_copied_by);
+			this.entity.replaceUniqueSourceRelation(this.copyistLo.entity, PERSON, rel_was_copied_by);
 			
 			// WITNESS -> was_copied_in -> PLACE
-			replaceAliasSourceRelation(this.entity, this.copyPlaceLo, PLACE, "was_copied_in", "was_copied_in_as");
+			replaceUniqueAliasSourceRelation(this.entity, this.copyPlaceLo, PLACE, rel_was_copied_in, rel_was_copied_in_as);
 			
 			//REFERENCE -> is_reference_of -> WITNESS
-			//this.entity = this.prepareReferencesToSave(this.entity);
 			this.prepareEndNoteRefs2Save();
 			
 			//WITNESS -> was studied by manyToMany -> PERSON
-			this.entity.removeAllSourceRelationsByName(rel_was_studied_by);
-			for(Entity target : this.studiedByList.getEntities()){
-				Entity target0 = getWrapper().getEntityByIdWithContent(target.getId());
-				new Relation(this.entity, target0, rel_was_studied_by);
-			}
+			replaceMultipleSourceRelations(entity, studiedByList.getEntities(), PERSON, rel_was_studied_by);
 
 			// WITNESS -> had_patron -> PERSON
-			this.entity.replaceSourceRelation(this.patronageLo.entity, PERSON, rel_had_patron);
+			this.entity.replaceUniqueSourceRelation(this.patronageLo.entity, PERSON, rel_had_patron);
 			
 			
 			/*
@@ -256,27 +251,21 @@
 			this.entity = this.misidentTable.saveMisidentifications(this.entity);
 			
 			// WITNESS -> is_exemplar_of -> TEXT
-			this.entity.replaceSourceRelation(this.titleLo.entity, TEXT, is_exemplar_of);
+			this.entity.replaceUniqueSourceRelation(this.titleLo.entity, TEXT, is_exemplar_of);
+			
 			// legacy relations(?)
 			this.entity.removeAllSourceRelationsByName(is_possible_exemplar_of);
 			this.entity.removeAllSourceRelations(rel_has_title_written_as, ALIAS);
 			this.entity.removeAllSourceRelations(rel_has_author_written_as, ALIAS);
 			
-			if(textUnknown){
-				for(Entity target : this.possibleExamplerOfList.getEntities()){
-					Entity target0 = getWrapper().getEntityByIdWithContent(target.getId());
-					new Relation(this.entity, target0, is_possible_exemplar_of);
-				}
-			}else{
-				this.saveIndirectedAliases();
-			}
-			
 			// WITNESS -> is_part_of_codex 
 			if(this.isSelectedSaveAsNew()){
 				//this.entity = getWrapper().saveEntityAsNew(this.entity, user.getEmail());
 			}else{
+				// save this entity
 				this.entity = getWrapper().saveEntity(this.entity, user.getEmail(), editWitnessIntent);
 			}
+			// re-set form
 			this.setEntity(this.entity);
 			
 			logger.info("Entity saved - Time = " + (System.currentTimeMillis() - start) + ", " + entity);
@@ -292,89 +281,11 @@
 		return PAGE_EDITOR;
 	}
 
-	private void saveIndirectedAliases() throws Exception{
-		
-		User user = getSessionUser();
-		
-		//WITNESS -> has_title_written_as -> ALIAS
-		if(StringUtils.isNotEmpty(valueTextWritten)){
-			Entity alias = null;
-			if(this.suggestedTitlesWritten != null){
-				for(SelectItem item : this.suggestedTitlesWritten){
-					Long id = (Long)item.getValue();
-					if(id != null){
-						Entity candidate = getWrapper().getEntityById(id);
-						if(candidate != null && valueTextWritten.equals(candidate.getOwnValue())){
-							alias = candidate;
-							break;
-						}
-					}
-				}
-			}
-			
-			if(alias == null){
-				alias = new Entity(Node.TYPE_ABOX, ALIAS, false);
-				alias.addAttribute(new Attribute(ALIAS, "text", valueTextWritten));
-				alias = getWrapper().saveEntity(alias, user.getEmail(), null);
-				new Relation(alias, this.titleLo.getEntity(), "is_alias_title_of");
-				alias = getWrapper().saveEntity(alias, user.getEmail(), null);
-			}			
-			if(alias.isLightweight()){
-				alias = getWrapper().getEntityByIdWithContent(alias.getId());
-			}
-			this.entity.replaceSourceRelation(alias, ALIAS, rel_has_title_written_as);
-		}
-				
-		
-		if(StringUtils.isNotEmpty(this.valueAuthorWritten)){
-			Entity alias = null;
-			if(suggestedAuthorsWritten != null){
-				for(SelectItem item : this.suggestedAuthorsWritten){
-					Long id = (Long)item.getValue();
-					if(id != null){
-						Entity candidate = getWrapper().getEntityById(id);
-						if(candidate != null && valueAuthorWritten.equals(candidate.getOwnValue())){
-							alias = candidate;
-							break;
-						}
-					}
-				}
-			}
-			
-			if(alias == null){
-				alias = new Entity(Node.TYPE_ABOX, ALIAS, false);
-				alias.addAttribute(new Attribute(ALIAS, "text", valueAuthorWritten));
-				alias = getWrapper().saveEntity(alias, user.getEmail(), null);
-				new Relation(alias, this.authorLo.getEntity(), "is_alias_name_of");
-				alias = getWrapper().saveEntity(alias, user.getEmail(), null);
-			}
-			if(alias.isLightweight()){
-				alias = getWrapper().getEntityByIdWithContent(alias.getId());
-			}
-			this.entity.replaceSourceRelation(alias, ALIAS, rel_has_author_written_as);
-		}
-	}
-	
 	public String saveAsNewEntity() {
 		this.setSelectedSaveAsNew(true);
 		return save();
 	}
 
-	/* rich
-	public void patronageChangeListener(ValueChangeEvent event) {
-		//patronageLo = changeListener(event, patronageLo, PERSON, "name");
-		patronageLo = changeValuePersonByRole(event, patronageLo, "Patron");
-	
-	}
-	
-	public void copyistChangeListener(ValueChangeEvent event) {
-		copyistLo = changeValuePersonByRole(event, copyistLo, "Copyist");	
-	}
-
-	public void copyPlacesChangeListener(ValueChangeEvent event) {
-		copyPlaceLo = changeListener(event, copyPlaceLo,"PLACE", "name");
-	}*/
-	
 	public void updateTitle(){
 		
 		if(titleLo.entity != null && titleLo.entity.isPersistent()){