View Javadoc
1   /*
2    * Copyright 2011 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.ole.select.businessobject.defaultvalue;
17  
18  import org.kuali.ole.select.OleSelectConstant;
19  import org.kuali.rice.core.api.membership.MemberType;
20  import org.kuali.rice.kim.api.services.KimApiServiceLocator;
21  import org.kuali.rice.krad.util.GlobalVariables;
22  import org.kuali.rice.krad.valuefinder.ValueFinder;
23  
24  import java.util.ArrayList;
25  import java.util.Iterator;
26  import java.util.List;
27  
28  //import org.kuali.rice.kim.impl.role.RoleBo;
29  
30  public class DefaultValueLoggedInUser implements ValueFinder {
31  
32      @Override
33      public String getValue() {
34          // TODO Auto-generated method stub
35          boolean flag = false;
36          String role = getRole();
37          String principalName = null;
38          List<String> roleImpl = getRolesForPrincipal(GlobalVariables.getUserSession().getPrincipalId());
39          Iterator itr = roleImpl.iterator();
40          while (itr.hasNext()) {
41              String kimrole = itr.next().toString();
42              if (KimApiServiceLocator.getRoleService().getRole(kimrole) != null) {
43                  if (KimApiServiceLocator.getRoleService().getRole(kimrole).getName().equalsIgnoreCase(role)) {
44                      flag = true;
45                      principalName = null;
46                  }
47              }
48          }
49          if (!flag) {
50              principalName = GlobalVariables.getUserSession().getPrincipalId();
51          }
52          return principalName;
53      }
54  
55      @SuppressWarnings("unchecked")
56      private List<String> getRolesForPrincipal(String principalId) {
57          if (principalId == null) {
58              return new ArrayList<String>();
59          }
60          /*Map<String,String> criteria = new HashMap<String,String>( 2 );
61          criteria.put("members.memberId", principalId);
62          criteria.put("members.memberTypeCode", MemberType.PRINCIPAL.getCode());
63          return (List<RoleBo>)SpringContext.getBean(BusinessObjectService.class).findMatching(RoleBo.class, criteria);*/
64          return (List<String>) KimApiServiceLocator.getRoleService().getMemberParentRoleIds(MemberType.PRINCIPAL.getCode(), principalId);
65      }
66  
67      public String getRole() {
68          return OleSelectConstant.SYSTEM_USER_ROLE_NAME;
69      }
70  
71  }