View Javadoc
1   /*
2    * The Kuali Financial System, a comprehensive financial management system for higher education.
3    * 
4    * Copyright 2005-2014 The Kuali Foundation
5    * 
6    * This program is free software: you can redistribute it and/or modify
7    * it under the terms of the GNU Affero General Public License as
8    * published by the Free Software Foundation, either version 3 of the
9    * License, or (at your option) any later version.
10   * 
11   * This program is distributed in the hope that it will be useful,
12   * but WITHOUT ANY WARRANTY; without even the implied warranty of
13   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   * GNU Affero General Public License for more details.
15   * 
16   * You should have received a copy of the GNU Affero General Public License
17   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18   */
19  package org.kuali.kfs.sec.businessobject;
20  
21  import java.sql.Timestamp;
22  
23  import org.apache.commons.lang.StringUtils;
24  import org.kuali.kfs.sys.context.SpringContext;
25  import org.kuali.rice.core.api.membership.MemberType;
26  import org.kuali.rice.core.api.util.type.KualiInteger;
27  import org.kuali.rice.kim.api.group.Group;
28  import org.kuali.rice.kim.api.group.GroupService;
29  import org.kuali.rice.kim.api.identity.Person;
30  import org.kuali.rice.kim.api.identity.PersonService;
31  import org.kuali.rice.kim.api.role.Role;
32  import org.kuali.rice.kim.api.services.KimApiServiceLocator;
33  import org.kuali.rice.krad.bo.PersistableBusinessObjectBase;
34  
35  
36  /**
37   * Associates a member (principal, role, or group) to a model. These become the members of the model role created in KIM
38   */
39  public class SecurityModelMember extends PersistableBusinessObjectBase {
40      protected KualiInteger modelId;
41      protected String memberId;
42      protected String memberTypeCode;
43      protected Timestamp activeFromDate;
44      protected Timestamp activeToDate;
45  
46      protected SecurityModel securityModel;
47  
48      // non db
49      protected String memberName = "";
50  
51      protected ModelMember modelMember;
52  
53      /**
54       * Gets the modelId attribute.
55       *
56       * @return Returns the modelId.
57       */
58      public KualiInteger getModelId() {
59          return modelId;
60      }
61  
62  
63      /**
64       * Sets the modelId attribute value.
65       *
66       * @param modelId The modelId to set.
67       */
68      public void setModelId(KualiInteger modelId) {
69          this.modelId = modelId;
70      }
71  
72  
73      /**
74       * Gets the memberId attribute.
75       *
76       * @return Returns the memberId.
77       */
78      public String getMemberId() {
79          return memberId;
80      }
81  
82  
83      /**
84       * Sets the memberId attribute value.
85       *
86       * @param memberId The memberId to set.
87       */
88      public void setMemberId(String memberId) {
89          this.memberId = memberId;
90          memberName = "";
91      }
92  
93  
94      /**
95       * Gets the memberTypeCode attribute.
96       *
97       * @return Returns the memberTypeCode.
98       */
99      public String getMemberTypeCode() {
100         return memberTypeCode;
101     }
102 
103 
104     /**
105      * Sets the memberTypeCode attribute value.
106      *
107      * @param memberTypeCode The memberTypeCode to set.
108      */
109     public void setMemberTypeCode(String memberTypeCode) {
110         this.memberTypeCode = memberTypeCode;
111         memberName = "";
112     }
113 
114 
115     /**
116      * Gets the activeFromDate attribute.
117      *
118      * @return Returns the activeFromDate.
119      */
120     public Timestamp getActiveFromDate() {
121         return activeFromDate;
122     }
123 
124 
125     /**
126      * Sets the activeFromDate attribute value.
127      *
128      * @param activeFromDate The activeFromDate to set.
129      */
130     public void setActiveFromDate(Timestamp activeFromDate) {
131         this.activeFromDate = activeFromDate;
132     }
133 
134 
135     /**
136      * Gets the activeToDate attribute.
137      *
138      * @return Returns the activeToDate.
139      */
140     public Timestamp getActiveToDate() {
141         return activeToDate;
142     }
143 
144 
145     /**
146      * Sets the activeToDate attribute value.
147      *
148      * @param activeToDate The activeToDate to set.
149      */
150     public void setActiveToDate(Timestamp activeToDate) {
151         this.activeToDate = activeToDate;
152     }
153 
154 
155     /**
156      * Gets the memberName attribute.
157      *
158      * @return Returns the memberName.
159      */
160     public String getMemberName() {
161         if ( StringUtils.isBlank(memberName) ) {
162             if (StringUtils.isNotBlank(memberTypeCode) && StringUtils.isNotBlank(memberId)) {
163                 if (MemberType.PRINCIPAL.getCode().equals(memberTypeCode)) {
164                     Person person = SpringContext.getBean(PersonService.class).getPerson(memberId);
165                     if (person != null) {
166                         memberName = person.getName();
167                     }
168                 } else if (MemberType.ROLE.getCode().equals(memberTypeCode)) {
169                     Role roleInfo = KimApiServiceLocator.getRoleService().getRole(memberId);
170                     if (roleInfo != null) {
171                         memberName = roleInfo.getName();
172                     }
173                 } else if (MemberType.GROUP.getCode().equals(memberTypeCode)) {
174                     Group groupInfo = KimApiServiceLocator.getGroupService().getGroup(memberId);
175                     if (groupInfo != null) {
176                         memberName = groupInfo.getName();
177                     }
178                 }
179             }
180         }
181 
182         return memberName;
183     }
184 
185 
186     /**
187      * Sets the memberName attribute value.
188      *
189      * @param memberName The memberName to set.
190      */
191     public void setMemberName(String memberName) {
192         this.memberName = memberName;
193     }
194 
195 
196     /**
197      * Gets the securityModel attribute.
198      *
199      * @return Returns the securityModel.
200      */
201     public SecurityModel getSecurityModel() {
202         return securityModel;
203     }
204 
205 
206     /**
207      * Sets the securityModel attribute value.
208      *
209      * @param securityModel The securityModel to set.
210      */
211     public void setSecurityModel(SecurityModel securityModel) {
212         this.securityModel = securityModel;
213     }
214 
215 
216     /**
217      * Gets the modelMember attribute.
218      *
219      * @return Returns the modelMember.
220      */
221     public ModelMember getModelMember() {
222         return modelMember;
223     }
224 
225 
226     /**
227      * Sets the modelMember attribute value.
228      *
229      * @param modelMember The modelMember to set.
230      */
231     public void setModelMember(ModelMember modelMember) {
232         this.modelMember = modelMember;
233     }
234 
235     /**
236      * Builds a string representation of the model definition assignmentss
237      *
238      * @return String
239      */
240     public String getModelDefinitionSummary() {
241         String summary = "";
242 
243         for (SecurityModelDefinition modelDefinition : securityModel.getModelDefinitions()) {
244             summary += "Definition Name: " + modelDefinition.getSecurityDefinition().getName();
245             summary += ", Constraint Code: " + modelDefinition.getConstraintCode();
246             summary += ", Operator Code: " + modelDefinition.getOperatorCode();
247             summary += ", Value: " + modelDefinition.getAttributeValue();
248             summary += "; ";
249         }
250 
251         return summary;
252     }
253 
254 
255     @Override
256     public String toString() {
257         StringBuilder builder = new StringBuilder();
258         builder.append("SecurityModelMember [");
259         if (modelId != null) {
260             builder.append("modelId=");
261             builder.append(modelId);
262             builder.append(", ");
263         }
264         if (memberId != null) {
265             builder.append("memberId=");
266             builder.append(memberId);
267             builder.append(", ");
268         }
269         if (memberTypeCode != null) {
270             builder.append("memberTypeCode=");
271             builder.append(memberTypeCode);
272             builder.append(", ");
273         }
274         if (activeFromDate != null) {
275             builder.append("activeFromDate=");
276             builder.append(activeFromDate);
277             builder.append(", ");
278         }
279         if (activeToDate != null) {
280             builder.append("activeToDate=");
281             builder.append(activeToDate);
282             builder.append(", ");
283         }
284         if (getMemberName() != null) {
285             builder.append("getMemberName()=");
286             builder.append(getMemberName());
287             builder.append(", ");
288         }
289         if (getModelDefinitionSummary() != null) {
290             builder.append("getModelDefinitionSummary()=");
291             builder.append(getModelDefinitionSummary());
292         }
293         builder.append("]");
294         return builder.toString();
295     }
296 
297 
298 }