package de.terrestris.shogun2.model.wps;

import java.util.HashMap;
import java.util.Map;

import javax.persistence.CollectionTable;
import javax.persistence.ElementCollection;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.MapKeyColumn;
import javax.persistence.Table;

import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;

/**
 *
 */
@Entity
@Table
public class WpsProcessExecute extends WpsReference {

	/**
	 *
	 */
	private static final long serialVersionUID = 1L;

	/**
	 *
	 */
	private String identifier;

	/**
	 *
	 */
	private String displayName;

	/**
	 *
	 */
	@ElementCollection
	@MapKeyColumn(name = "INPUT_IDENTIFIER")
	@CollectionTable(
		name = "WPSPROCESSEXECUTE_INPUTS",
		joinColumns = @JoinColumn(name = "WPSPROCESSEXECUTE_ID")
	)
	private Map<String, WpsParameter> input = new HashMap<>();

	/**
	 * Constructor
	 */
	public WpsProcessExecute() {
	}


	/**
	 * @return the identifier
	 */
	public String getIdentifier() {
		return identifier;
	}


	/**
	 * @param identifier the identifier to set
	 */
	public void setIdentifier(String identifier) {
		this.identifier = identifier;
	}


	/**
	 * @return the displayName
	 */
	public String getDisplayName() {
		return displayName;
	}


	/**
	 * @param displayName the displayName to set
	 */
	public void setDisplayName(String displayName) {
		this.displayName = displayName;
	}


	/**
	 * @return the input
	 */
	public Map<String, WpsParameter> getInput() {
		return input;
	}


	/**
	 * @param input the input to set
	 */
	public void setInput(Map<String, WpsParameter> input) {
		this.input = input;
	}


	/**
	 * @see java.lang.Object#hashCode()
	 *
	 * According to
	 * http://stackoverflow.com/questions/27581/overriding-equals-and-hashcode-in-java
	 * it is recommended only to use getter-methods when using ORM like Hibernate
	 */
	@Override
	public int hashCode() {
		return new HashCodeBuilder(47, 23) // two randomly chosen prime numbers
			.appendSuper(super.hashCode())
			.append(getIdentifier())
			.append(getDisplayName())
			.toHashCode();
	}

	/**
	 * @see java.lang.Object#equals(java.lang.Object)
	 *
	 * According to
	 * http://stackoverflow.com/questions/27581/overriding-equals-and-hashcode-in-java
	 * it is recommended only to use getter-methods when using ORM like Hibernate
	 */
	@Override
	public boolean equals(Object obj) {
		if (!(obj instanceof WpsProcessExecute))
			return false;
		WpsProcessExecute other = (WpsProcessExecute) obj;

		return new EqualsBuilder()
			.appendSuper(super.equals(other))
			.append(getIdentifier(), other.getIdentifier())
			.append(getDisplayName(), other.getDisplayName())
			.isEquals();
	}

	/**
	 *
	 */
	@Override
	public String toString(){
		return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
			.appendSuper(super.toString())
			.append("identifier", identifier)
			.append("displayName", displayName)
			.toString();
	}
}

@@ -109,31 +109,22 @@
 istence.
-CollectionTable
+Entity
 ;%0Aimport
@@ -142,32 +142,25 @@
 istence.
-ElementCollectio
+JoinColum
 n;%0Aimpor
@@ -171,38 +171,41 @@
 vax.persistence.
-Entity
+JoinTable
 ;%0Aimport javax.p
@@ -211,34 +211,34 @@
 persistence.
-JoinColumn
+ManyToMany
 ;%0Aimport jav
@@ -777,87 +777,32 @@
 /%0A%09@
-ElementCollection%0A%09@MapKeyColumn(name = %22INPUT_IDENTIFIER%22)%0A%09@Collectio
+ManyToMany%0A%09@Joi
 nTable(%0A
 %09%09na
@@ -797,16 +797,17 @@
 nTable(%0A
+%09
 %09%09name =
@@ -825,16 +825,17 @@
 SEXECUTE
+S
 _INPUTS%22
@@ -838,16 +838,17 @@
 UTS%22,%0A%09%09
+%09
 joinColu
@@ -852,16 +852,18 @@
 olumns =
+ %7B
  @JoinCo
@@ -882,29 +882,133 @@
 %22WPS
-PROCESSEXECU
+EXECUTEPROCESS_ID%22) %7D,%0A%09%09%09inverseJoinColumns = %7B @JoinColumn(name = %22WPSPARAME
 TE
+R
 _ID%22)
-%0A%09
+ %7D%0A%09%09)%0A%09@MapKeyColumn(name=%22IDENTIFIER%22
 )%0A%09p

Use ManyToMany instead of ElementCollection