changeset 143:1c09041f1182

110: The title-as-written-on-manuscript in the witness form does not save Task-Url: https://it-dev.mpiwg-berlin.mpg.de/tracs/ismi/ticket/110
author Robert Casties <casties@mpiwg-berlin.mpg.de>
date Fri, 23 Jun 2017 20:40:18 +0200
parents 13fb56030fe8
children 6911b522c6e2
files src/main/java/de/mpiwg/itgroup/ismi/entry/beans/CurrentWitnessBean.java src/main/webapp/entry/text.xhtml src/main/webapp/entry/witness.xhtml
diffstat 3 files changed, 131 insertions(+), 51 deletions(-) [+]
line wrap: on
line diff
--- a/src/main/java/de/mpiwg/itgroup/ismi/entry/beans/CurrentWitnessBean.java	Fri Jun 16 20:16:30 2017 +0200
+++ b/src/main/java/de/mpiwg/itgroup/ismi/entry/beans/CurrentWitnessBean.java	Fri Jun 23 20:40:18 2017 +0200
@@ -111,7 +111,8 @@
 					"notes_on_ownership", "source_of_information"},
 			// source relations
 			new String[] {"is_exemplar_of", "is_part_of", "has_author_misidentification", "was_copied_by",
-					"was_copied_in", "was_copied_in_as", "had_patron", "was_studied_by"},
+					"was_copied_in", "was_copied_in_as", "had_patron", "was_studied_by",
+					"has_author_written_as", "has_title_written_as"},
 			// target relations
 			new String[] {"is_reference_of"});
 
@@ -255,8 +256,9 @@
 			
 			// 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);
+			
+			// update title/author_written_as relations
+			this.updateWrittenAliases();
 			
 			// WITNESS -> is_part_of_codex 
 			if(this.isSelectedSaveAsNew()){
@@ -283,6 +285,85 @@
 		return PAGE_EDITOR;
 	}
 
+	private void updateWrittenAliases() throws Exception {
+
+		User user = getSessionUser();
+
+		/*
+		 * WITNESS -> has_title_written_as -> ALIAS
+		 */
+		if (StringUtils.isNotEmpty(valueTextWritten)) {
+			// check if text is already an alias
+			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) {
+				// create new alias
+				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());
+			}
+			// update relation
+			this.entity.replaceUniqueSourceRelation(alias, ALIAS, rel_has_title_written_as);
+		} else {
+			// remove relation
+			this.entity.removeAllSourceRelations(rel_has_title_written_as, ALIAS);
+		}
+
+		/*
+		 * WITNESS -> has_author_written_as -> ALIAS
+		 */
+		if (StringUtils.isNotEmpty(this.valueAuthorWritten)) {
+			// check if text is already an alias
+			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) {
+				// create new alias
+				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());
+			}
+			// update relation 
+			this.entity.replaceUniqueSourceRelation(alias, ALIAS, rel_has_author_written_as);
+		} else {
+			// remove relation
+			this.entity.removeAllSourceRelations(rel_has_author_written_as, ALIAS);
+		}
+	}
+	
 	public String saveAsNewEntity() {
 		this.setSelectedSaveAsNew(true);
 		return save();
@@ -333,7 +414,7 @@
 
 	private List<SelectItem> getTitleAliases(Entity title) {
 		List<SelectItem> items = new ArrayList<SelectItem>();
-		this.valueTextWritten = null;
+		// I don't think so: this.valueTextWritten = null;
 		if(title != null && title.isPersistent()){
 			items.add(new SelectItem(new Long(-1), "-- choose --"));
 			List<Entity> aliasTitleList = getWrapper().getSourcesForTargetRelation(title, is_alias_title_of, ALIAS, -1);
@@ -351,9 +432,9 @@
 	}
 	private List<SelectItem> getAuthorAliases(Entity author) {
 		List<SelectItem> items = new ArrayList<SelectItem>();
-		this.valueAuthorWritten = null;
+		// I don't think so: this.valueAuthorWritten = null;
 		if(author != null && author.isPersistent()){
-			//items.add(new SelectItem(null, "-- choose --"));
+			items.add(new SelectItem(new Long(-1), "-- choose --"));
 			List<Entity> aliasAuthorList = getWrapper().getSourcesForTargetRelation(author, is_alias_name_of, ALIAS, -1);
 			for(Entity alias : aliasAuthorList){
 				items.add(new SelectItem(alias.getId(), alias.getOwnValue()));
@@ -391,57 +472,56 @@
 			// Loading the relations
 			// TODO loading target's relations
 			for (Relation rel : witness.getSourceRelations()) {
-				Entity target = null;
 				String relName = rel.getOwnValue();
 				if (relName.equals(is_exemplar_of)) {
 					// WITNESS -> is_exemplar_of -> TEXT
-					target = getTargetRelation(rel);
+					Entity target = getTargetRelation(rel);
 					titleLo.setEntityAndAttribute(target);
 					this.updateTitle();
 				} else if (relName.equals(is_possible_exemplar_of)) {
 					// WITNESS -> is_possible_exemplar_of -> TEXT
-					target = getTargetRelation(rel);
+					Entity target = getTargetRelation(rel);
 					possibleExamplerOfList.add(target);					
 				} else if (relName.equals(rel_was_studied_by)) {
-					target = getTargetRelation(rel);
+					Entity target = getTargetRelation(rel);
 					studiedByList.add(target);
 				} else if (relName.equals(rel_was_copied_by)) {
 					// WITENSS -> was_copied_by -> PERSON
-					target = getTargetRelation(rel);
+					Entity target = getTargetRelation(rel);
 					copyistLo.setEntityAndAttribute(target);
 				} else if (relName.equals("was_copied_in")) {
 					// WITENSS -> was_copied_in -> PLACE
-					target = getTargetRelation(rel);
+					Entity target = getTargetRelation(rel);
 					// don't use place if there is an alias
 					copyPlaceLo.setEntityAndAttributeIfEmpty(target);
                 } else if (relName.equals("was_copied_in_as")) {
                     // WITENSS -> was_copied_in_as -> ALIAS
-                    target = getTargetRelation(rel);
+                	Entity target = getTargetRelation(rel);
                     copyPlaceLo.setEntityAndAttribute(target);
 				} else if (relName.equals(rel_had_patron)) {
 					// WITNESS -> had_patron -> PERSON
-					target = getTargetRelation(rel);
+					Entity target = getTargetRelation(rel);
 					patronageLo.setEntityAndAttributeName(target, name_translit);
 				} else if (relName.equals(is_part_of)) {
 					// WITNESS -> is_part_of -> CODEX
 					if (rel.getTargetObjectClass().equals(CODEX)) {
-						target = getTargetRelation(rel);
+						Entity target = getTargetRelation(rel);
 						this.setCodex(target);
 					}
 				} else if (relName.equals(Misidentification.HAS_MISIDENT)) {
 					// WITNESS -> has_misidentification -> MISIDENTIFICATION
-					target = getTargetRelation(rel);
+					Entity target = getTargetRelation(rel);
 					this.misidentTable.load(target);
 					
 				} else if (relName.equals(rel_has_author_written_as)) {
 					//TODO this relation is no in the definitions
-					Entity target2 = getTargetRelation(rel);
-					Attribute alias = getTargetAttribute(target2, "alias");
+					Entity target = getTargetRelation(rel);
+					Attribute alias = getTargetAttribute(target, "alias");
 					this.valueAuthorWritten = (alias != null) ? alias.getValue() : null;
 								
 				} else if (relName.equals(rel_has_title_written_as)) {
 					//TODO this relation is no in the definitions
-					target = getTargetRelation(rel);
+					Entity target = getTargetRelation(rel);
 					//this.textWritten = target;
 					Attribute alias  = getTargetAttribute(target, "alias");
 					this.valueTextWritten = (alias != null) ? alias.getValue() : null;
@@ -519,7 +599,7 @@
 			Long aliasId = (Long) event.getNewValue();
 			if(aliasId != null){
 				if(aliasId.equals(-1)){
-					this.valueTextWritten = null;
+					//I don't think so: this.valueTextWritten = null;
 				}else{
 					Entity alias = getWrapper().getEntityByIdWithContent(aliasId);
 					if(alias != null){
@@ -539,7 +619,7 @@
 			Long aliasId = (Long) event.getNewValue();
 			if(aliasId != null){
 				if(aliasId.equals(-1)){
-					this.valueAuthorWritten = null;
+					//I don't think so: this.valueAuthorWritten = null;
 				}else{
 					Entity alias = getWrapper().getEntityByIdWithContent(aliasId);
 					if(alias != null){
--- a/src/main/webapp/entry/text.xhtml	Fri Jun 16 20:16:30 2017 +0200
+++ b/src/main/webapp/entry/text.xhtml	Fri Jun 23 20:40:18 2017 +0200
@@ -61,6 +61,31 @@
 			</h:panelGrid>
 			<h:outputText />
 
+            <h:outputText value="Aliases for Title" />
+            <h:panelGrid columns="1" border="1">
+                <h:panelGrid columns="2">
+                    <h:dataTable value="#{CurrentText.aliasList.entities}" var="item">
+                        <h:column>
+                            <h:outputText value="#{item.ownValue}" />
+                        </h:column>
+                        <h:column>
+                            <h:selectBooleanCheckbox
+                                value="#{CurrentText.aliasList.selections[item.id]}" />
+                        </h:column>
+                    </h:dataTable>
+                    <h:commandButton value="Remove Selection"
+                        actionListener="#{CurrentText.aliasList.listenerRemoveSelection}" />
+                </h:panelGrid>
+
+                <h:panelGrid columns="2">
+                    <h:inputText value="#{CurrentText.aliasList.input}"
+                        style="width:500px;" />
+                    <h:commandButton value="CREATE"
+                        actionListener="#{CurrentText.aliasList.listenerCreate}" />
+                </h:panelGrid>
+            </h:panelGrid>
+            <h:outputText />
+
 			<h:outputText value="Language" />
 			<h:selectOneMenu partialSubmit="true"
 				value="#{CurrentText.attributes['language']}">
@@ -161,31 +186,6 @@
 			<ismi:autocomplete lo="#{CurrentText.versionLo}" />
 			<h:outputText/>
 
-			<h:outputText value="Aliases for Title" />
-			<h:panelGrid columns="1" border="1">
-				<h:panelGrid columns="2">
-					<h:dataTable value="#{CurrentText.aliasList.entities}" var="item">
-						<h:column>
-							<h:outputText value="#{item.ownValue}" />
-						</h:column>
-						<h:column>
-							<h:selectBooleanCheckbox
-								value="#{CurrentText.aliasList.selections[item.id]}" />
-						</h:column>
-					</h:dataTable>
-					<h:commandButton value="Remove Selection"
-						actionListener="#{CurrentText.aliasList.listenerRemoveSelection}" />
-				</h:panelGrid>
-
-				<h:panelGrid columns="2">
-					<h:inputText value="#{CurrentText.aliasList.input}"
-						style="width:500px;" />
-					<h:commandButton value="CREATE"
-						actionListener="#{CurrentText.aliasList.listenerCreate}" />
-				</h:panelGrid>
-			</h:panelGrid>
-			<h:outputText />
-
 			<h:outputText value="Aliases for Explicit" />
 			<h:panelGrid columns="1" border="1">
 				<h:panelGrid columns="2">
--- a/src/main/webapp/entry/witness.xhtml	Fri Jun 16 20:16:30 2017 +0200
+++ b/src/main/webapp/entry/witness.xhtml	Fri Jun 23 20:40:18 2017 +0200
@@ -82,9 +82,9 @@
 				<h:panelGrid columns="1">
 					<h:inputText value="#{CurrentWitness.valueTextWritten}"
 						valueChangeListener="#{CurrentWitness.listenerCreateTitleAlias}"
-						size="100" style="direction: rtl;" />
+						size="100" style="direction:rtl;" />
 					<h:selectOneListbox partialSubmit="true"
-						style="direction: rtl;width: 500px;" size="5"
+						style="direction:rtl; width:500px;" size="5"
 						rendered="#{!empty CurrentWitness.suggestedTitlesWritten}"
 						valueChangeListener="#{CurrentWitness.listenerChooseTitleAlias}"
 						value="#{CurrentWitness.valueTitleSelectedId}">
@@ -101,8 +101,8 @@
 				<h:panelGrid columns="1">
 					<h:inputText value="#{CurrentWitness.valueAuthorWritten}"
 						valueChangeListener="#{CurrentWitness.listenerCreateAuthorAlias}"
-						size="100" style="direction: rtl;" />
-					<h:selectOneListbox style="direction: rtl;width: 500px;" size="5"
+						size="100" style="direction:rtl;" />
+					<h:selectOneListbox style="direction:rtl; width:500px;" size="5"
 						rendered="#{!empty CurrentWitness.suggestedAuthorsWritten}"
 						valueChangeListener="#{CurrentWitness.listenerChooseAuthorAlias}"
 						value="#{CurrentWitness.valueAuthorSelectedId}">
@@ -375,7 +375,7 @@
 		<h:panelGrid columns="4">
 			<h:outputText value="ID of the Witness" />
 			<h:inputText value="#{CurrentWitness.currentId}" />
-			<h:commandButton value="Load Witness By ID"
+			<a4j:commandButton value="Load Witness By ID"
 				action="#{CurrentWitness.actionReloadEntity}"
 				onclick="confirm('Do you really want to reload the entity?');" />
 			<h:outputText value="#{CurrentWitness.currentIdMsg}"