Coverage Report - org.kuali.rice.kim.lookup.KimDocumentRoleMemberLookupableHelperServiceImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
KimDocumentRoleMemberLookupableHelperServiceImpl
0%
0/47
0%
0/72
8.4
 
 1  
 /*
 2  
  * Copyright 2007-2009 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.rice.kim.lookup;
 17  
 
 18  
 import java.util.ArrayList;
 19  
 import java.util.List;
 20  
 import java.util.Map;
 21  
 
 22  
 import org.apache.commons.lang.StringUtils;
 23  
 import org.kuali.rice.kim.bo.role.dto.KimRoleInfo;
 24  
 import org.kuali.rice.kim.bo.types.dto.KimTypeInfo;
 25  
 import org.kuali.rice.kim.bo.ui.KimDocumentRoleMember;
 26  
 import org.kuali.rice.kim.bo.ui.KimDocumentRoleQualifier;
 27  
 import org.kuali.rice.kim.document.IdentityManagementRoleDocument;
 28  
 import org.kuali.rice.kim.document.KimTypeAttributesHelper;
 29  
 import org.kuali.rice.kim.service.KIMServiceLocator;
 30  
 import org.kuali.rice.kim.service.KimTypeInfoService;
 31  
 import org.kuali.rice.kim.service.RoleService;
 32  
 import org.kuali.rice.kim.service.UiDocumentService;
 33  
 import org.kuali.rice.kim.util.KIMPropertyConstants;
 34  
 import org.kuali.rice.kim.util.KimCommonUtils;
 35  
 import org.kuali.rice.kim.util.KimConstants;
 36  
 import org.kuali.rice.kns.bo.BusinessObject;
 37  
 import org.kuali.rice.kns.datadictionary.AttributeDefinition;
 38  
 import org.kuali.rice.kns.lookup.KualiLookupableHelperServiceImpl;
 39  
 import org.kuali.rice.kns.util.GlobalVariables;
 40  
 
 41  
 /**
 42  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 43  
  *
 44  
  */
 45  0
 public class KimDocumentRoleMemberLookupableHelperServiceImpl extends KualiLookupableHelperServiceImpl {
 46  
 
 47  
         private static final long serialVersionUID = 1L;
 48  
         private transient UiDocumentService uiDocumentService;
 49  
         private transient RoleService roleService;
 50  
         private transient KimTypeInfoService kimTypeInfoService;
 51  
         
 52  
         @SuppressWarnings("unchecked")
 53  
         protected List<? extends BusinessObject> getSearchResultsHelper(Map<String, String> fieldValues, boolean unbounded) {
 54  0
                 List<KimDocumentRoleMember> searchResults = new ArrayList<KimDocumentRoleMember>();
 55  0
                 IdentityManagementRoleDocument roleDocument = (IdentityManagementRoleDocument)GlobalVariables.getUserSession().retrieveObject(KimConstants.KimUIConstants.KIM_ROLE_DOCUMENT_SHORT_KEY);
 56  0
                 if(roleDocument!=null){
 57  0
                         String memberId = fieldValues.get(KimConstants.PrimaryKeyConstants.MEMBER_ID);
 58  0
                         String memberTypeCode = fieldValues.get(KIMPropertyConstants.KimMember.MEMBER_TYPE_CODE);
 59  0
                         String memberName = fieldValues.get(KimConstants.KimUIConstants.MEMBER_NAME);
 60  0
                         String memberNamespaceCode = fieldValues.get(KimConstants.KimUIConstants.MEMBER_NAMESPACE_CODE);
 61  0
                         String activeFromDate = fieldValues.get(KIMPropertyConstants.KimMember.ACTIVE_FROM_DATE);
 62  0
                         String activeToDate = fieldValues.get(KIMPropertyConstants.KimMember.ACTIVE_TO_DATE);
 63  0
                         List<KimDocumentRoleMember> currentRoleMembers = roleDocument.getMembers();
 64  0
                         if(currentRoleMembers!=null && !currentRoleMembers.isEmpty()){
 65  0
                                 for(KimDocumentRoleMember currentRoleMember: currentRoleMembers){
 66  0
                                         if((StringUtils.isEmpty(memberId) || (StringUtils.isNotEmpty(memberId) && memberId.equals(currentRoleMember.getMemberId())))
 67  
                                                         && (StringUtils.isEmpty(memberTypeCode) || (StringUtils.isNotEmpty(memberTypeCode) && memberTypeCode.equals(currentRoleMember.getMemberTypeCode())))
 68  
                                                         && (StringUtils.isEmpty(memberName) || (StringUtils.isNotEmpty(memberName) && memberName.equals(currentRoleMember.getMemberName())))
 69  
                                                         && (StringUtils.isEmpty(memberNamespaceCode) || (StringUtils.isNotEmpty(memberNamespaceCode) && memberNamespaceCode.equals(currentRoleMember.getMemberNamespaceCode())))
 70  
                                                         && (StringUtils.isEmpty(activeFromDate) || (StringUtils.isNotEmpty(activeFromDate) && activeFromDate.equals(currentRoleMember.getActiveFromDate())))
 71  
                                                         && (StringUtils.isEmpty(activeToDate) || (StringUtils.isNotEmpty(activeToDate) && activeToDate.equals(currentRoleMember.getActiveToDate())))){
 72  0
                                                 searchResults.add(currentRoleMember);
 73  
                                         }
 74  
                                 }
 75  
                         }
 76  0
                 } else{
 77  0
                         searchResults = getUiDocumentService().getRoleMembers(fieldValues);
 78  
                 }
 79  0
                 if(searchResults!=null){
 80  0
                         for(KimDocumentRoleMember roleMember: searchResults)
 81  0
                                 roleMember.setQualifiersToDisplay(getQualifiersToDisplay(roleMember));
 82  
                 }
 83  0
                 return searchResults;
 84  
         }
 85  
 
 86  
         public String getQualifiersToDisplay(KimDocumentRoleMember roleMember) {
 87  0
                 if(roleMember!=null && StringUtils.isNotEmpty(roleMember.getRoleId()) && 
 88  
                                 roleMember.getQualifiers()!=null && !roleMember.getQualifiers().isEmpty()){
 89  0
                         KimRoleInfo roleInfo = getRoleService().getRole(roleMember.getRoleId());
 90  0
                         KimTypeInfo kimType = null;
 91  0
                         if(roleInfo!=null)
 92  0
                                 kimType = getKimTypeInfoService().getKimType(roleInfo.getKimTypeId());
 93  0
                         if(kimType!=null){
 94  0
                                 KimTypeAttributesHelper attributesHelper = new KimTypeAttributesHelper(kimType);
 95  0
                                 StringBuffer attributesToDisplay = new StringBuffer();
 96  
                                 AttributeDefinition attribDefn;
 97  0
                                 for(KimDocumentRoleQualifier attribute: roleMember.getQualifiers()){
 98  0
                                         if(attribute.getKimAttribute()!=null){
 99  0
                                                 attribDefn = attributesHelper.getAttributeDefinition(attribute.getKimAttribute().getAttributeName());
 100  0
                                                 attributesToDisplay.append(attribDefn!=null?attribDefn.getLabel():"");
 101  0
                                                 attributesToDisplay.append(KimConstants.KimUIConstants.NAME_VALUE_SEPARATOR );
 102  0
                                                 attributesToDisplay.append(attribute.getAttrVal());
 103  0
                                                 attributesToDisplay.append(KimConstants.KimUIConstants.COMMA_SEPARATOR);
 104  
                                         }
 105  
                                 }
 106  0
                                 return KimCommonUtils.stripEnd(attributesToDisplay.toString(), KimConstants.KimUIConstants.COMMA_SEPARATOR);
 107  
                         }
 108  
                 }
 109  0
                 return "";
 110  
         }
 111  
 
 112  
         public RoleService getRoleService() {
 113  0
                 if ( roleService == null ) {
 114  0
                         roleService = KIMServiceLocator.getRoleService();
 115  
                 }
 116  0
                 return roleService;
 117  
         }
 118  
 
 119  
         public KimTypeInfoService getKimTypeInfoService() {
 120  0
                 if ( kimTypeInfoService == null ) {
 121  0
                         kimTypeInfoService = KIMServiceLocator.getTypeInfoService();
 122  
                 }
 123  0
                 return kimTypeInfoService;
 124  
         }
 125  
         
 126  
         public UiDocumentService getUiDocumentService() {
 127  0
                 if ( uiDocumentService == null ) {
 128  0
                         uiDocumentService = KIMServiceLocator.getUiDocumentService();
 129  
                 }
 130  0
                 return uiDocumentService;
 131  
         }
 132  
 }