View Javadoc
1   /**
2    * Copyright 2004-2014 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.kpme.pm.position;
17  
18  import org.apache.commons.collections.CollectionUtils;
19  import org.apache.commons.lang.StringUtils;
20  import org.joda.time.DateTime;
21  import org.joda.time.LocalDate;
22  import org.kuali.kpme.core.api.KPMEConstants;
23  import org.kuali.kpme.core.api.groupkey.HrGroupKey;
24  import org.kuali.kpme.core.api.namespace.KPMENamespace;
25  import org.kuali.kpme.core.bo.HrBusinessObject;
26  import org.kuali.kpme.core.role.KPMERole;
27  import org.kuali.kpme.core.service.HrServiceLocator;
28  import org.kuali.kpme.core.service.role.KPMERoleService;
29  import org.kuali.kpme.core.util.GroupKeyInputField;
30  import org.kuali.kpme.core.util.TKUtils;
31  import org.kuali.rice.core.api.membership.MemberType;
32  import org.kuali.rice.core.api.util.ConcreteKeyValue;
33  import org.kuali.rice.core.api.util.KeyValue;
34  import org.kuali.rice.kim.api.role.RoleMember;
35  import org.kuali.rice.krad.uif.control.UifKeyValuesFinderBase;
36  import org.kuali.rice.krad.uif.view.ViewModel;
37  import org.kuali.rice.krad.util.GlobalVariables;
38  import org.kuali.rice.krad.valuefinder.ValueFinder;
39  import org.kuali.rice.krad.web.form.MaintenanceDocumentForm;
40  
41  import java.util.ArrayList;
42  import java.util.HashMap;
43  import java.util.List;
44  import java.util.Map;
45  
46  /**
47   * Created by mlemons on 7/18/14.
48   */
49  
50  public class PositionGroupKeyValueFinder extends org.kuali.kpme.core.util.GroupKeyValueFinder {
51  
52      @Override
53      public List<KeyValue> getKeyValues(ViewModel model) {
54          String principalId = GlobalVariables.getUserSession().getPrincipalId();
55  
56          KPMERoleService rs = HrServiceLocator.getKPMERoleService();
57  
58          List<Map<String, String>> roles = new ArrayList<Map<String, String>>();
59  
60          Map<String, String> role1 = new HashMap<String, String>();
61          role1.put((String)"NameSpace" , KPMENamespace.KPME_HR.getNamespaceCode());
62          role1.put((String)"Role", KPMERole.DEPARTMENT_APPROVER.getRoleName());
63  
64          Map<String, String> role2 = new HashMap<String, String>();
65          role2.put((String)"NameSpace", KPMENamespace.KPME_HR.getNamespaceCode());
66          role2.put((String)"Role", KPMERole.HR_DEPARTMENT_ADMINISTRATOR.getRoleName());
67  
68          roles.add(role1);
69          roles.add(role2);
70  
71          for (Map<String, String> role : roles)
72          {
73              List<RoleMember> rms = rs.getRoleMembers(role.get("NameSpace"), role.get("Role"), new HashMap<String, String>(), DateTime.now(), true);
74              if (!rms.isEmpty())
75              {
76                  for (RoleMember rm: rms)
77                  {
78                      if ( ( rm.getType() == MemberType.PRINCIPAL) && (StringUtils.equals(rm.getMemberId(), principalId)) )
79                      {
80                          if (rm.getAttributes().containsKey(KPMEConstants.CommonElements.GROUP_KEY_CODE))
81                          {
82                              List<KeyValue> keyValues = new ArrayList<KeyValue>();
83                              keyValues.add(new ConcreteKeyValue(rm.getAttributes().get(KPMEConstants.CommonElements.GROUP_KEY_CODE), rm.getAttributes().get(KPMEConstants.CommonElements.GROUP_KEY_CODE) ));
84                              return keyValues;
85                          }
86                      }
87                  }
88              }
89          }
90  
91          return super.getKeyValues(model);
92      }
93  }