Coverage Report - pt.digitalis.dif.controller.security.objects.DIFGroupImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
DIFGroupImpl
0%
0/56
0%
0/16
1,7
 
 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  0
 public class DIFGroupImpl implements IDIFGroup {
 23  
 
 24  
     /** The identity manager implementation */
 25  0
     static private IIdentityManager identityManager = DIFIoCRegistry.getRegistry().getImplementation(
 26  0
             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  0
     public DIFGroupImpl()
 47  0
     {}
 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  0
     public DIFGroupImpl(IDIFGroup group)
 56  
     {
 57  0
         this.groupID = group.getID();
 58  0
         this.groupName = group.getName();
 59  0
         this.groupDescription = group.getDescription();
 60  0
         this.parentGroup = group.getParentGroupID();
 61  0
     }
 62  
 
 63  
     /**
 64  
      * @see java.lang.Object#clone()
 65  
      */
 66  
     @Override
 67  
     protected Object clone() throws CloneNotSupportedException
 68  
     {
 69  0
         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  0
             return (IDIFGroup) this.clone();
 80  
         }
 81  0
         catch (CloneNotSupportedException e)
 82  
         {
 83  0
             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  0
         if (this == obj)
 94  0
             return true;
 95  0
         if (obj == null)
 96  0
             return false;
 97  0
         if (getClass() != obj.getClass())
 98  0
             return false;
 99  0
         DIFGroupImpl other = (DIFGroupImpl) obj;
 100  0
         if (groupID == null)
 101  
         {
 102  0
             if (other.groupID != null)
 103  0
                 return false;
 104  
         }
 105  0
         else if (!groupID.equals(other.groupID))
 106  0
             return false;
 107  0
         return true;
 108  
     }
 109  
 
 110  
     /** @see pt.digitalis.dif.controller.security.objects.IDIFGroup#getDescription() */
 111  
     public String getDescription()
 112  
     {
 113  0
         return this.groupDescription;
 114  
     }
 115  
 
 116  
     /** @see pt.digitalis.dif.controller.security.objects.IDIFGroup#getID() */
 117  
     public String getID()
 118  
     {
 119  0
         return this.groupID;
 120  
     }
 121  
 
 122  
     /** @see pt.digitalis.dif.controller.security.objects.IDIFGroup#getName() */
 123  
     public String getName()
 124  
     {
 125  0
         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  0
         return DIFGroupImpl.identityManager.getGroup(this.getParentGroupID());
 134  
     }
 135  
 
 136  
     /** @see pt.digitalis.dif.controller.security.objects.IDIFGroup#getParentGroupID() */
 137  
     public String getParentGroupID()
 138  
     {
 139  0
         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  0
         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  0
         return identityManager.getGroupUsers(groupID);
 156  
     }
 157  
 
 158  
     /**
 159  
      * @see java.lang.Object#hashCode()
 160  
      */
 161  
     @Override
 162  
     public int hashCode()
 163  
     {
 164  0
         final int prime = 31;
 165  0
         int result = 1;
 166  0
         result = prime * result + ((groupID == null) ? 0 : groupID.hashCode());
 167  0
         return result;
 168  
     }
 169  
 
 170  
     /**
 171  
      * @see pt.digitalis.dif.controller.security.objects.IDIFGroup#isDefault()
 172  
      */
 173  
     public boolean isDefault()
 174  
     {
 175  0
         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  0
         this.isDefault = isDefault;
 184  0
     }
 185  
 
 186  
     /** @see pt.digitalis.dif.controller.security.objects.IDIFGroup#setDescription(String) */
 187  
     public void setDescription(String newDescription)
 188  
     {
 189  0
         this.groupDescription = newDescription;
 190  0
     }
 191  
 
 192  
     /** @see pt.digitalis.dif.controller.security.objects.IDIFGroup#setID(String) */
 193  
     public void setID(String newGroupId)
 194  
     {
 195  0
         this.groupID = newGroupId;
 196  0
     }
 197  
 
 198  
     /** @see pt.digitalis.dif.controller.security.objects.IDIFGroup#setName(String) */
 199  
     public void setName(String newName)
 200  
     {
 201  0
         this.groupName = newName;
 202  0
     }
 203  
 
 204  
     /** @see pt.digitalis.dif.controller.security.objects.IDIFGroup#setParentGroupID(String) */
 205  
     public void setParentGroupID(String newParent)
 206  
     {
 207  0
         this.parentGroup = newParent;
 208  0
     }
 209  
 
 210  
     /**
 211  
      * @see java.lang.Object#toString()
 212  
      */
 213  
     @Override
 214  
     public String toString()
 215  
     {
 216  0
         ObjectFormatter formatter = new ObjectFormatter();
 217  
 
 218  0
         formatter.addItem("ID", getID());
 219  0
         formatter.addItemIfNotNull("Name", getName());
 220  0
         formatter.addItemIfNotNull("Description", getDescription());
 221  0
         formatter.addItemIfNotNull("Parent Group", getParentGroupID());
 222  
 
 223  0
         return formatter.getFormatedObject();
 224  
     }
 225  
 }