diff src/main/java/org/mpi/openmind/repository/services/utils/EditIntent.java @ 66:3e4b05a6cb47

new EditIntent for saveEntity().
author casties
date Mon, 30 Jan 2017 20:32:26 +0100
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/java/org/mpi/openmind/repository/services/utils/EditIntent.java	Mon Jan 30 20:32:26 2017 +0100
@@ -0,0 +1,102 @@
+package org.mpi.openmind.repository.services.utils;
+
+import java.util.HashSet;
+import java.util.Set;
+
+/**
+ * Class documenting the parts (attributes, relations) if an Entity that may be
+ * edited.
+ * 
+ * @author casties
+ *
+ */
+public class EditIntent {
+	String modifiedEntity;
+	Set<String> modifiedAttributes;
+	Set<String> modifiedSourceRelations;
+	Set<String> modifiedTargetRelations;
+
+	/**
+	 * Creates an EditIntent with the given attribute and relation names.
+	 * 
+	 * @param modifiedEntity
+	 * @param modifiedAttributes
+	 * @param modifiedSourceRelations
+	 * @param modifiedTargetRelations
+	 */
+	public EditIntent(String modifiedEntity, Set<String> modifiedAttributes, Set<String> modifiedSourceRelations,
+			Set<String> modifiedTargetRelations) {
+		super();
+		this.modifiedEntity = modifiedEntity;
+		this.modifiedAttributes = modifiedAttributes;
+		this.modifiedSourceRelations = modifiedSourceRelations;
+		this.modifiedTargetRelations = modifiedTargetRelations;
+	}
+
+	/**
+	 * Creates an EditIntent with the given attribute and relation names.
+	 * 
+	 * @param modifiedEntity
+	 * @param modifiedAttributes
+	 * @param modifiedSourceRelations
+	 * @param modifiedTargetRelations
+	 */
+	public EditIntent(String modifiedEntity, String[] modifiedAttributes, String[] modifiedSourceRelations, String[] modifiedTargetRelations) {
+		super();
+		this.modifiedEntity = modifiedEntity;
+		this.modifiedAttributes = new HashSet<String>();
+		for (String s : modifiedAttributes) {
+			this.modifiedAttributes.add(s);
+		}
+		
+		this.modifiedSourceRelations = new HashSet<String>();
+		for (String s : modifiedSourceRelations) {
+			this.modifiedSourceRelations.add(s);
+		}
+
+		this.modifiedTargetRelations = new HashSet<String>();
+		for (String s : modifiedTargetRelations) {
+			this.modifiedTargetRelations.add(s);
+		}
+	}
+	
+	/**
+	 * Returns if the modification of the Entity with the given name is intended.
+	 * 
+	 * @param name
+	 * @return
+	 */
+	public boolean isEntModificationIntended(String name) {
+		return modifiedEntity.equals(name);
+	}
+	
+	/**
+	 * Returns if the modification of the Attribute with the given name is intended.
+	 * 
+	 * @param name
+	 * @return
+	 */
+	public boolean isAttModificationIntended(String name) {
+		return modifiedAttributes.contains(name);
+	}
+
+	/**
+	 * Returns if the modification of the Relation with the given name is intended.
+	 * 
+	 * @param name
+	 * @return
+	 */
+	public boolean isSrcRelModificationIntended(String name) {
+		return modifiedSourceRelations.contains(name);
+	}
+
+	/**
+	 * Returns if the modification of the Relation with the given name is intended.
+	 * 
+	 * @param name
+	 * @return
+	 */
+	public boolean isTarRelModificationIntended(String name) {
+		return modifiedTargetRelations.contains(name);
+	}
+}