001/* 002 * Copyright 2011 The Kuali Foundation. 003 * 004 * Licensed under the Educational Community License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.opensource.org/licenses/ecl2.php 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.kuali.ole.select.businessobject.defaultvalue; 017 018import org.kuali.ole.select.OleSelectConstant; 019import org.kuali.rice.core.api.membership.MemberType; 020import org.kuali.rice.kim.api.services.KimApiServiceLocator; 021import org.kuali.rice.krad.util.GlobalVariables; 022import org.kuali.rice.krad.valuefinder.ValueFinder; 023 024import java.util.ArrayList; 025import java.util.Iterator; 026import java.util.List; 027 028//import org.kuali.rice.kim.impl.role.RoleBo; 029 030public class DefaultValueLoggedInUser implements ValueFinder { 031 032 @Override 033 public String getValue() { 034 // TODO Auto-generated method stub 035 boolean flag = false; 036 String role = getRole(); 037 String principalName = null; 038 List<String> roleImpl = getRolesForPrincipal(GlobalVariables.getUserSession().getPrincipalId()); 039 Iterator itr = roleImpl.iterator(); 040 while (itr.hasNext()) { 041 String kimrole = itr.next().toString(); 042 if (KimApiServiceLocator.getRoleService().getRole(kimrole) != null) { 043 if (KimApiServiceLocator.getRoleService().getRole(kimrole).getName().equalsIgnoreCase(role)) { 044 flag = true; 045 principalName = null; 046 } 047 } 048 } 049 if (!flag) { 050 principalName = GlobalVariables.getUserSession().getPrincipalId(); 051 } 052 return principalName; 053 } 054 055 @SuppressWarnings("unchecked") 056 private List<String> getRolesForPrincipal(String principalId) { 057 if (principalId == null) { 058 return new ArrayList<String>(); 059 } 060 /*Map<String,String> criteria = new HashMap<String,String>( 2 ); 061 criteria.put("members.memberId", principalId); 062 criteria.put("members.memberTypeCode", MemberType.PRINCIPAL.getCode()); 063 return (List<RoleBo>)SpringContext.getBean(BusinessObjectService.class).findMatching(RoleBo.class, criteria);*/ 064 return (List<String>) KimApiServiceLocator.getRoleService().getMemberParentRoleIds(MemberType.PRINCIPAL.getCode(), principalId); 065 } 066 067 public String getRole() { 068 return OleSelectConstant.SYSTEM_USER_ROLE_NAME; 069 } 070 071}