--- /dev/null
+/*****************************************************************************
+ * Copyright Igor Barma, Eric Brun, Alexandre Desoubeaux, Christian Martel,
+ * (2 décembre 2008)
+ *
+ * Ce logiciel est un programme informatique servant à l'évaluation des
+ * compétences.
+ *
+ * Ce logiciel est régi par la licence CeCILL soumise au droit français et
+ * respectant les principes de diffusion des logiciels libres. Vous pouvez
+ * utiliser, modifier et/ou redistribuer ce programme sous les conditions
+ * de la licence CeCILL telle que diffusée par le CEA, le CNRS et l'INRIA
+ * sur le site "http://www.cecill.info".
+ *
+ * En contrepartie de l'accessibilité au code source et des droits de copie,
+ * de modification et de redistribution accordés par cette licence, il n'est
+ * offert aux utilisateurs qu'une garantie limitée. Pour les mêmes raisons,
+ * seule une responsabilité restreinte pèse sur l'auteur du programme, le
+ * titulaire des droits patrimoniaux et les concédants successifs.
+ *
+ * A cet égard l'attention de l'utilisateur est attirée sur les risques
+ * associés au chargement, à l'utilisation, à la modification et/ou au
+ * développement et à la reproduction du logiciel par l'utilisateur étant
+ * donné sa spécificité de logiciel libre, qui peut le rendre complexe à
+ * manipuler et qui le réserve donc à des développeurs et des professionnels
+ * avertis possédant des connaissances informatiques approfondies. Les
+ * utilisateurs sont donc invités à charger et tester l'adéquation du
+ * logiciel à leurs besoins dans des conditions permettant d'assurer la
+ * sécurité de leurs systèmes et ou de leurs données et, plus généralement,
+ * à l'utiliser et l'exploiter dans les mêmes conditions de sécurité.
+ *
+ * Le fait que vous puissiez accéder à cet en-tête signifie que vous avez
+ * pris connaissance de la licence CeCILL, et que vous en avez accepté les
+ * termes.
+ *******************************************************************************/
+package com.pentila.evalcomp.domain;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import net.sf.gilead.annotations.ServerOnly;
+
+import com.pentila.evalcomp.domain.definition.EntityDefinitionAbstract;
+import com.pentila.evalcomp.domain.definition.EvaluationObject;
+
+// TODO: Auto-generated Javadoc
+/**
+ * The Class Entity.
+ */
+public abstract class Entity extends EObject {
+
+ /** The roles. */
+ Set<Role> roles;
+
+ /*
+ * public Entity(){ this.getRoles(); }
+ */
+
+ /** The affectations. */
+ @ServerOnly
+ Set<Affectation> affectations;
+
+ /** The entity definitions. */
+ Set<EntityDefinitionAbstract> entityDefinitions;
+
+ /** The id of the entity. */
+ Long id;
+
+ /** The modify time stamp. */
+ String modifyTimeStamp;
+
+ /** The status. */
+ int status = 0;
+
+
+
+ /** The Constant DELETED. */
+ public static final int DELETED = 2;
+
+ /** The Constant EXTERN. */
+ public static final String EXTERN = "E";
+
+ /** The Constant INTERN. */
+ public static final String INTERN = "I";
+
+ /** The Constant DELETED. */
+ public static final int NOTHERE = 3;
+
+ /** The Constant OBSOLETE. */
+ public static final int OBSOLETE = 1;
+
+ /** The Constant VALID. */
+ public static final int VALID = 0;
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.Object#equals(java.lang.Object)
+ */
+ @Override
+ public boolean equals(Object o) {
+ boolean ret = false;
+ if ((o instanceof Entity)
+ && (this.getUid().equals(((Entity) o).getUid()))) {
+ if ((o instanceof User && this instanceof User)
+ || (o instanceof Group && this instanceof Group)) {
+ ret = true;
+ }
+ }
+ return ret;
+ }
+
+ /**
+ * Gets the affectations.
+ *
+ * @return the affectations
+ */
+ public Set<Affectation> getAffectations() {
+ return affectations;
+ }
+
+ /**
+ * Gets the entity definitions.
+ *
+ * @return the entity definitions
+ */
+ public Set<EntityDefinitionAbstract> getEntityDefinitions() {
+ return entityDefinitions;
+ }
+
+ /**
+ * Gets the id.
+ *
+ * @return the id
+ */
+ public Long getId() {
+ return id;
+ }
+
+ /**
+ * Gets the modify time stamp.
+ *
+ * @return the modify time stamp
+ */
+ public String getModifyTimeStamp() {
+ return modifyTimeStamp;
+ }
+
+ /**
+ * Gets the roles.
+ *
+ * @return the roles
+ */
+ public Set<Role> getRoles() {
+ // return roles;
+
+ if (roles == null || roles.isEmpty()) {
+
+ Set<Role> sr = new HashSet<Role>();
+ try {
+ if (affectations != null) {
+ for (Affectation a : affectations) {
+ sr.add(a.getRole());
+ }
+ }
+ roles = sr;
+
+ } catch (Exception e) {
+
+ }
+ }
+ return roles;
+ }
+
+ /**
+ * Gets the status.
+ *
+ * @return the status
+ */
+ public int getStatus() {
+ return status;
+ }
+
+ /**
+ * Gets the uid.
+ *
+ * @return the uid
+ */
+ public String getUid() {
+ return "";
+ }
+
+ /**
+ * Gets the users in the entity.
+ *
+ * @return the users
+ */
+ public abstract Set<User> getUsers();/* {
+ return null;
+ }
+ */
+ /**
+ * Checks for eo by role.
+ *
+ * @param role
+ * the role
+ * @param EO
+ * the eO
+ *
+ * @return true, if successful
+ */
+ public boolean hasEOByRole(String role, EvaluationObject EO) {
+
+ for (Affectation a : affectations) {
+
+ if (a.getEvaluationObject() != null) {
+ if (a.getRole().getName().equals(role)
+ && a.getEvaluationObject().getId().equals(EO.getId())) {
+
+ return true;
+ }
+ }
+ }
+
+ return false;
+ }
+
+ /**
+ * Checks for role.
+ *
+ * @param role
+ * the role
+ *
+ * @return true, if successful
+ */
+ public boolean hasRole(String role) {
+
+ for (Role r : getRoles()) {
+ if (r.getName().equals(role)) {
+ return true;
+ }
+ }
+
+ /*
+ * for (Affectation a : affectations) { if
+ * (a.getRole().getName().equals(role)) { return true; } }
+ */
+ return false;
+
+ }
+
+ /**
+ * Sets the affectations.
+ *
+ * @param affectations
+ * the new affectations
+ */
+ public void setAffectations(Set<Affectation> affectations) {
+ this.affectations = affectations;
+ }
+
+ /**
+ * Sets the entity definitions.
+ *
+ * @param entityDefinitions
+ * the new entity definitions
+ */
+ public void setEntityDefinitions(Set<EntityDefinitionAbstract> entityDefinitions) {
+ this.entityDefinitions = entityDefinitions;
+ }
+
+ /**
+ * Sets the id.
+ *
+ * @param id
+ * the new id
+ */
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+ /**
+ * Sets the modify time stamp.
+ *
+ * @param modifyTimeStamp
+ * the new modify time stamp
+ */
+ public void setModifyTimeStamp(String modifyTimeStamp) {
+ this.modifyTimeStamp = modifyTimeStamp;
+ }
+
+ /**
+ * Sets the status.
+ *
+ * @param status
+ * the new status
+ */
+ public void setStatus(int status) {
+ this.status = status;
+ }
+
+ /**
+ * Sets the roles.
+ *
+ * @param roles the new roles
+ */
+ public void setRoles(Set<Role> roles) {
+ this.roles = roles;
+ }
+
+}