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 org.apache.commons.lang.StringUtils;
 19  
 import org.kuali.rice.kim.api.role.Role;
 20  
 import org.kuali.rice.kim.api.role.RoleService;
 21  
 import org.kuali.rice.kim.api.services.KimApiServiceLocator;
 22  
 import org.kuali.rice.kim.api.type.KimType;
 23  
 import org.kuali.rice.kim.api.type.KimTypeInfoService;
 24  
 import org.kuali.rice.kim.bo.ui.KimDocumentRoleMember;
 25  
 import org.kuali.rice.kim.bo.ui.KimDocumentRoleQualifier;
 26  
 import org.kuali.rice.kim.document.IdentityManagementRoleDocument;
 27  
 import org.kuali.rice.kim.impl.type.KimTypeAttributesHelper;
 28  
 import org.kuali.rice.kim.service.KIMServiceLocatorInternal;
 29  
 import org.kuali.rice.kim.service.UiDocumentService;
 30  
 import org.kuali.rice.kim.util.KIMPropertyConstants;
 31  
 import org.kuali.rice.kim.util.KimCommonUtilsInternal;
 32  
 import org.kuali.rice.kim.util.KimConstants;
 33  
 import org.kuali.rice.kns.lookup.KualiLookupableHelperServiceImpl;
 34  
 import org.kuali.rice.krad.bo.BusinessObject;
 35  
 import org.kuali.rice.krad.datadictionary.AttributeDefinition;
 36  
 import org.kuali.rice.krad.util.GlobalVariables;
 37  
 
 38  
 import java.util.ArrayList;
 39  
 import java.util.List;
 40  
 import java.util.Map;
 41  
 
 42  
 /**
 43  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 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  
         }
 84  0
         return searchResults;
 85  
     }
 86  
 
 87  
     public String getQualifiersToDisplay(KimDocumentRoleMember roleMember) {
 88  0
         if (roleMember != null && StringUtils.isNotEmpty(roleMember.getRoleId()) &&
 89  
                 roleMember.getQualifiers() != null && !roleMember.getQualifiers().isEmpty()) {
 90  0
             Role role = getRoleService().getRole(roleMember.getRoleId());
 91  0
             KimType kimType = null;
 92  0
             if (role != null) {
 93  0
                 kimType = getKimTypeInfoService().getKimType(role.getKimTypeId());
 94  
             }
 95  0
             if (kimType != null) {
 96  0
                 KimTypeAttributesHelper attributesHelper = new KimTypeAttributesHelper(kimType);
 97  0
                 StringBuffer attributesToDisplay = new StringBuffer();
 98  
                 AttributeDefinition attribDefn;
 99  0
                 for (KimDocumentRoleQualifier attribute : roleMember.getQualifiers()) {
 100  0
                     if (attribute.getKimAttribute() != null) {
 101  0
                         attribDefn = attributesHelper.getAttributeDefinition(attribute.getKimAttribute().getAttributeName());
 102  0
                         attributesToDisplay.append(attribDefn != null ? attribDefn.getLabel() : "");
 103  0
                         attributesToDisplay.append(KimConstants.KimUIConstants.NAME_VALUE_SEPARATOR);
 104  0
                         attributesToDisplay.append(attribute.getAttrVal());
 105  0
                         attributesToDisplay.append(KimConstants.KimUIConstants.COMMA_SEPARATOR);
 106  
                     }
 107  
                 }
 108  0
                 return KimCommonUtilsInternal.stripEnd(attributesToDisplay.toString(), KimConstants.KimUIConstants.COMMA_SEPARATOR);
 109  
             }
 110  
         }
 111  0
         return "";
 112  
     }
 113  
 
 114  
     public RoleService getRoleService() {
 115  0
         if (roleService == null) {
 116  0
             roleService = KimApiServiceLocator.getRoleService();
 117  
         }
 118  0
         return roleService;
 119  
     }
 120  
 
 121  
     public KimTypeInfoService getKimTypeInfoService() {
 122  0
         if (kimTypeInfoService == null) {
 123  0
             kimTypeInfoService = KimApiServiceLocator.getKimTypeInfoService();
 124  
         }
 125  0
         return kimTypeInfoService;
 126  
     }
 127  
 
 128  
     public UiDocumentService getUiDocumentService() {
 129  0
         if (uiDocumentService == null) {
 130  0
             uiDocumentService = KIMServiceLocatorInternal.getUiDocumentService();
 131  
         }
 132  0
         return uiDocumentService;
 133  
     }
 134  
 }