View Javadoc
1   package org.kuali.kpme.edo.group;
2   
3   import com.google.gson.Gson;
4   import com.google.gson.reflect.TypeToken;
5   import org.apache.log4j.Logger;
6   import org.kuali.kpme.edo.util.EdoConstants;
7   import org.kuali.rice.kim.api.group.Group;
8   import org.kuali.rice.kim.api.services.KimApiServiceLocator;
9   import org.kuali.rice.kim.api.type.KimType;
10  
11  import java.lang.reflect.Type;
12  import java.util.ArrayList;
13  import java.util.HashMap;
14  import java.util.List;
15  import java.util.Map;
16  
17  /**
18   * $HeadURL$
19   * $Revision$
20   * Created with IntelliJ IDEA.
21   * User: bradleyt
22   * Date: 12/11/13
23   * Time: 2:43 PM
24   */
25  public class EdoGroup {
26      private static final Logger LOG = Logger.getLogger(EdoGroup.class);
27  
28      private String groupName;
29      private String kimTypeName;
30      private String kimGroupId;
31      private String kimRoleName;
32      private Map<String, String> grpAttributes;
33  
34      public EdoGroup() {
35          grpAttributes = new HashMap<String, String>();
36      }
37  
38      public String getGroupName() {
39          return groupName;
40      }
41  
42      public void setGroupName(String groupName) {
43          this.groupName = groupName;
44      }
45  
46      public String getKimTypeName() {
47          return kimTypeName;
48      }
49  
50      public void setKimTypeName(String kimTypeName) {
51          this.kimTypeName = kimTypeName;
52      }
53  
54      public String getKimGroupId() {
55          return kimGroupId;
56      }
57  
58      public void setKimGroupId(String kimGroupId) {
59          this.kimGroupId = kimGroupId;
60      }
61  
62      public String getKimRoleName() {
63          return kimRoleName;
64      }
65  
66      public void setKimRoleName(String kimRoleName) {
67          this.kimRoleName = kimRoleName;
68      }
69  
70      public Map<String, String> getGrpAttributes() {
71          return grpAttributes;
72      }
73  
74      public void setGrpAttributes(Map<String, String> grpAttributes) {
75          this.grpAttributes = grpAttributes;
76      }
77  
78      public boolean isEmpty() {
79          boolean flag = false;
80          if (this.groupName == null) {
81              flag = true;
82          }
83          return flag;
84      }
85  
86      public Group addGroup() {
87  
88          KimType kimType = KimApiServiceLocator.getKimTypeInfoService().findKimTypeByNameAndNamespace(EdoConstants.EDO_NAME_SPACE, this.kimTypeName);
89          Group.Builder groupInfo = Group.Builder.create(EdoConstants.EDO_NAME_SPACE, this.groupName, kimType.getId());
90          groupInfo.setActive(true);
91          groupInfo.setAttributes(this.grpAttributes);
92  
93          Group grp = KimApiServiceLocator.getGroupService().createGroup(groupInfo.build());
94          this.setKimGroupId(grp.getId());
95  
96          return grp;
97      }
98  
99      public Group disableGroup() {
100 
101         //Group grp = KimApiServiceLocator.getGroupService().getGroupByNamespaceCodeAndName(EdoConstants.EDO_NAME_SPACE, this.groupName);
102         KimType kimType = KimApiServiceLocator.getKimTypeInfoService().findKimTypeByNameAndNamespace(EdoConstants.EDO_NAME_SPACE, this.kimTypeName);
103         Group.Builder groupInfo = Group.Builder.create(EdoConstants.EDO_NAME_SPACE, this.groupName, kimType.getId());
104         groupInfo.setActive(false);
105 
106         Group grp = KimApiServiceLocator.getGroupService().updateGroup(groupInfo.build());
107 
108         return grp;
109     }
110 
111     public void addGroupAttribute(String grpAttributeName, String grpAttributeValue) {
112 
113         this.grpAttributes.put(grpAttributeName, grpAttributeValue);
114 
115         return;
116     }
117 
118     public String getEdoGroupJSONString() {
119         ArrayList<String> tmp = new ArrayList<String>();
120         Type tmpType = new TypeToken<List<String>>() {}.getType();
121         Gson gson = new Gson();
122 
123         tmp.add(this.getGroupName());
124         tmp.add(this.getKimRoleName());
125         tmp.add(this.getKimGroupId());
126         tmp.add(this.getKimTypeName());
127 
128         return gson.toJson(tmp, tmpType).toString();
129     }
130 
131 }