package de.terrestris.shogun2.model;

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

import javax.persistence.MappedSuperclass;
import javax.persistence.OneToMany;

import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.CascadeType;

import com.fasterxml.jackson.annotation.JsonIgnore;

import de.terrestris.shogun2.model.security.PermissionCollection;

/**
 * This class represents the abstract superclass for all entities that may be
 * secured in the sense of a restriction to certain users or groups.
 *
 * @author Nils Bühner
 *
 */
@MappedSuperclass
public abstract class SecuredPersistentObject extends PersistentObject {

	private static final long serialVersionUID = 1L;

	@OneToMany
	@Cascade(CascadeType.ALL)
	@JsonIgnore
	private Map<User, PermissionCollection> userPermissions = new HashMap<User, PermissionCollection>();

	@OneToMany
	@Cascade(CascadeType.ALL)
	@JsonIgnore
	private Map<UserGroup, PermissionCollection> groupPermissions = new HashMap<UserGroup, PermissionCollection>();

	/**
	 * @return the userPermissions
	 */
	public Map<User, PermissionCollection> getUserPermissions() {
		return userPermissions;
	}

	/**
	 * @param userPermissions the userPermissions to set
	 */
	public void setUserPermissions(Map<User, PermissionCollection> userPermissions) {
		this.userPermissions = userPermissions;
	}

	/**
	 * @return the groupPermissions
	 */
	public Map<UserGroup, PermissionCollection> getGroupPermissions() {
		return groupPermissions;
	}

	/**
	 * @param groupPermissions the groupPermissions to set
	 */
	public void setGroupPermissions(
			Map<UserGroup, PermissionCollection> groupPermissions) {
		this.groupPermissions = groupPermissions;
	}

}

@@ -160,16 +160,185 @@
 oMany;%0A%0A
+import org.apache.commons.lang3.builder.EqualsBuilder;%0Aimport org.apache.commons.lang3.builder.HashCodeBuilder;%0Aimport org.apache.commons.lang3.builder.ToStringBuilder;%0A
 import o
@@ -1865,10 +1865,1809 @@
 ns;%0A%09%7D%0A%0A
+%09/**%0A%09 * @see java.lang.Object#hashCode()%0A%09 *%0A%09 *      According to%0A%09 *      http://stackoverflow.com/questions/27581/overriding-equals%0A%09 *      -and-hashcode-in-java it is recommended only to use getter-methods%0A%09 *      when using ORM like Hibernate%0A%09 */%0A%09@Override%0A%09public int hashCode() %7B%0A%09%09// do not use the permission maps here to avoid performance problems%0A%09%09// (as we are loading everything lazily). Subclasses should%0A%09%09// overwrite/implement this method instead and use their basic%0A%09%09// properties for calculation%0A%0A%09%09// two randomly chosen prime numbers%0A%09%09return new HashCodeBuilder(13, 23).%0A%09%09%09%09appendSuper(super.hashCode()).%0A%09%09%09%09toHashCode();%0A%09%7D%0A%0A%09/**%0A%09 * @see java.lang.Object#equals(java.lang.Object)%0A%09 *%0A%09 *      According to%0A%09 *      http://stackoverflow.com/questions/27581/overriding-equals%0A%09 *      -and-hashcode-in-java it is recommended only to use getter-methods%0A%09 *      when using ORM like Hibernate%0A%09 */%0A%09@Override%0A%09public boolean equals(Object obj) %7B%0A%09%09// do not use the permission maps here to avoid performance problems%0A%09%09// (as we are loading everything lazily). Subclasses should%0A%09%09// overwrite/implement this method instead and use their basic%0A%09%09// properties for calculation%0A%0A%09%09if (!(obj instanceof SecuredPersistentObject))%0A%09%09%09return false;%0A%09%09SecuredPersistentObject other = (SecuredPersistentObject) obj;%0A%0A%09%09return new EqualsBuilder().%0A%09%09%09%09appendSuper(super.equals(other)).%0A%09%09%09%09isEquals();%0A%09%7D%0A%0A%09/**%0A%09 *%0A%09 */%0A%09@Override%0A%09public String toString() %7B%0A%09%09// do not use the permission maps here to avoid performance problems%0A%09%09// (as we are loading everything lazily). Subclasses should%0A%09%09// overwrite/implement this method instead and use their basic%0A%09%09// properties for calculation%0A%0A%09%09return new ToStringBuilder(this)%0A%09%09%09.appendSuper(super.toString())%0A%09%09%09.toString();%0A%09%7D%0A%0A
 %7D%0A

Add hashCode/equals/toString methods