View Javadoc

1   /**
2    * 2007, Digitalis Informatica. All rights reserved. Distribuicao e Gestao de Informatica, Lda. Estrada de Paco de Arcos
3    * num.9 - Piso -1 2780-666 Paco de Arcos Telefone: (351) 21 4408990 Fax: (351) 21 4408999 http://www.digitalis.pt
4    */
5   
6   package pt.digitalis.dif.controller.security.objects;
7   
8   import java.util.Map;
9   import java.util.Set;
10  
11  import pt.digitalis.dif.controller.security.managers.IIdentityManager;
12  import pt.digitalis.dif.exception.security.IdentityManagerException;
13  import pt.digitalis.dif.ioc.DIFIoCRegistry;
14  import pt.digitalis.dif.utils.ObjectFormatter;
15  
16  /**
17   * Default implementation for DIF group.
18   * 
19   * @author Rodrigo Gonçalves <a href="mailto:rgoncalves@digitalis.pt">rgoncalves@digitalis.pt</a><br/>
20   * @created 2007/12/04
21   */
22  public class DIFGroupImpl implements IDIFGroup {
23  
24      /** The identity manager implementation */
25      static private IIdentityManager identityManager = DIFIoCRegistry.getRegistry().getImplementation(
26              IIdentityManager.class);
27  
28      /** The group description. */
29      private String groupDescription;
30  
31      /** The group id. */
32      private String groupID;
33  
34      /** The group name. */
35      private String groupName;
36  
37      /** Is "default group"? */
38      private boolean isDefault;
39  
40      /** The parent group. */
41      private String parentGroup;
42  
43      /**
44       * Default constructor.
45       */
46      public DIFGroupImpl()
47      {}
48  
49      /**
50       * Creates a new group based on a given one
51       * 
52       * @param group
53       *            the group to copy data from
54       */
55      public DIFGroupImpl(IDIFGroup group)
56      {
57          this.groupID = group.getID();
58          this.groupName = group.getName();
59          this.groupDescription = group.getDescription();
60          this.parentGroup = group.getParentGroupID();
61      }
62  
63      /**
64       * @see java.lang.Object#clone()
65       */
66      @Override
67      protected Object clone() throws CloneNotSupportedException
68      {
69          return new DIFGroupImpl(this);
70      }
71  
72      /**
73       * @see pt.digitalis.dif.controller.security.objects.IDIFGroup#cloneGroup()
74       */
75      public IDIFGroup cloneGroup()
76      {
77          try
78          {
79              return (IDIFGroup) this.clone();
80          }
81          catch (CloneNotSupportedException e)
82          {
83              return null;
84          }
85      }
86  
87      /**
88       * @see java.lang.Object#equals(java.lang.Object)
89       */
90      @Override
91      public boolean equals(Object obj)
92      {
93          if (this == obj)
94              return true;
95          if (obj == null)
96              return false;
97          if (getClass() != obj.getClass())
98              return false;
99          DIFGroupImpl other = (DIFGroupImpl) obj;
100         if (groupID == null)
101         {
102             if (other.groupID != null)
103                 return false;
104         }
105         else if (!groupID.equals(other.groupID))
106             return false;
107         return true;
108     }
109 
110     /** @see pt.digitalis.dif.controller.security.objects.IDIFGroup#getDescription() */
111     public String getDescription()
112     {
113         return this.groupDescription;
114     }
115 
116     /** @see pt.digitalis.dif.controller.security.objects.IDIFGroup#getID() */
117     public String getID()
118     {
119         return this.groupID;
120     }
121 
122     /** @see pt.digitalis.dif.controller.security.objects.IDIFGroup#getName() */
123     public String getName()
124     {
125         return this.groupName;
126     }
127 
128     /**
129      * @see pt.digitalis.dif.controller.security.objects.IDIFGroup#getParentGroup()
130      */
131     public IDIFGroup getParentGroup() throws IdentityManagerException
132     {
133         return DIFGroupImpl.identityManager.getGroup(this.getParentGroupID());
134     }
135 
136     /** @see pt.digitalis.dif.controller.security.objects.IDIFGroup#getParentGroupID() */
137     public String getParentGroupID()
138     {
139         return this.parentGroup;
140     }
141 
142     /**
143      * @see pt.digitalis.dif.controller.security.objects.IDIFGroup#getUserIDs()
144      */
145     public Set<String> getUserIDs() throws IdentityManagerException
146     {
147         return identityManager.getUserIDsInGroup(groupID);
148     }
149 
150     /**
151      * @see pt.digitalis.dif.controller.security.objects.IDIFGroup#getUsers()
152      */
153     public Map<String, IDIFUser> getUsers() throws IdentityManagerException
154     {
155         return identityManager.getGroupUsers(groupID);
156     }
157 
158     /**
159      * @see java.lang.Object#hashCode()
160      */
161     @Override
162     public int hashCode()
163     {
164         final int prime = 31;
165         int result = 1;
166         result = prime * result + ((groupID == null) ? 0 : groupID.hashCode());
167         return result;
168     }
169 
170     /**
171      * @see pt.digitalis.dif.controller.security.objects.IDIFGroup#isDefault()
172      */
173     public boolean isDefault()
174     {
175         return this.isDefault;
176     }
177 
178     /**
179      * @see pt.digitalis.dif.controller.security.objects.IDIFGroup#setDefault(boolean)
180      */
181     public void setDefault(boolean isDefault)
182     {
183         this.isDefault = isDefault;
184     }
185 
186     /** @see pt.digitalis.dif.controller.security.objects.IDIFGroup#setDescription(String) */
187     public void setDescription(String newDescription)
188     {
189         this.groupDescription = newDescription;
190     }
191 
192     /** @see pt.digitalis.dif.controller.security.objects.IDIFGroup#setID(String) */
193     public void setID(String newGroupId)
194     {
195         this.groupID = newGroupId;
196     }
197 
198     /** @see pt.digitalis.dif.controller.security.objects.IDIFGroup#setName(String) */
199     public void setName(String newName)
200     {
201         this.groupName = newName;
202     }
203 
204     /** @see pt.digitalis.dif.controller.security.objects.IDIFGroup#setParentGroupID(String) */
205     public void setParentGroupID(String newParent)
206     {
207         this.parentGroup = newParent;
208     }
209 
210     /**
211      * @see java.lang.Object#toString()
212      */
213     @Override
214     public String toString()
215     {
216         ObjectFormatter formatter = new ObjectFormatter();
217 
218         formatter.addItem("ID", getID());
219         formatter.addItemIfNotNull("Name", getName());
220         formatter.addItemIfNotNull("Description", getDescription());
221         formatter.addItemIfNotNull("Parent Group", getParentGroupID());
222 
223         return formatter.getFormatedObject();
224     }
225 }