| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
package org.kuali.rice.kim.inquiry; |
| 17 | |
|
| 18 | |
import org.apache.commons.beanutils.PropertyUtils; |
| 19 | |
import org.kuali.rice.core.impl.namespace.NamespaceBo; |
| 20 | |
import org.kuali.rice.kim.bo.impl.ResponsibilityImpl; |
| 21 | |
import org.kuali.rice.kim.bo.impl.RoleImpl; |
| 22 | |
import org.kuali.rice.kim.bo.role.dto.KimRoleInfo; |
| 23 | |
import org.kuali.rice.kim.bo.role.impl.KimResponsibilityImpl; |
| 24 | |
import org.kuali.rice.kim.bo.role.impl.ResponsibilityAttributeDataImpl; |
| 25 | |
import org.kuali.rice.kim.bo.role.impl.RoleResponsibilityImpl; |
| 26 | |
import org.kuali.rice.kim.lookup.RoleLookupableHelperServiceImpl; |
| 27 | |
import org.kuali.rice.kim.service.KIMServiceLocator; |
| 28 | |
import org.kuali.rice.kim.service.ResponsibilityService; |
| 29 | |
import org.kuali.rice.kim.service.RoleService; |
| 30 | |
import org.kuali.rice.kim.util.KimConstants; |
| 31 | |
import org.kuali.rice.kns.bo.BusinessObject; |
| 32 | |
import org.kuali.rice.kns.lookup.HtmlData; |
| 33 | |
import org.kuali.rice.kns.lookup.HtmlData.AnchorHtmlData; |
| 34 | |
import org.kuali.rice.kns.lookup.HtmlData.MultipleAnchorHtmlData; |
| 35 | |
import org.kuali.rice.kns.service.KNSServiceLocator; |
| 36 | |
import org.kuali.rice.kns.util.ObjectUtils; |
| 37 | |
|
| 38 | |
import java.util.*; |
| 39 | |
|
| 40 | |
|
| 41 | |
|
| 42 | |
|
| 43 | |
|
| 44 | |
|
| 45 | |
|
| 46 | 0 | public class ResponsibilityInquirableImpl extends RoleMemberInquirableImpl { |
| 47 | |
|
| 48 | 0 | protected final String KIM_RESPONSIBILITY_REQUIRED_ATTRIBUTE_ID = "kimResponsibilityRequiredAttributeId"; |
| 49 | 0 | protected final String RESPONSIBILITY_ID = "responsibilityId"; |
| 50 | |
transient private static ResponsibilityService responsibilityService; |
| 51 | |
|
| 52 | |
@Override |
| 53 | |
public HtmlData getInquiryUrl(BusinessObject businessObject, String attributeName, boolean forceInquiry) { |
| 54 | |
|
| 55 | |
|
| 56 | |
|
| 57 | |
|
| 58 | |
|
| 59 | 0 | if(NAME.equals(attributeName) || NAME_TO_DISPLAY.equals(attributeName)){ |
| 60 | 0 | List<String> primaryKeys = new ArrayList<String>(); |
| 61 | 0 | primaryKeys.add(RESPONSIBILITY_ID); |
| 62 | 0 | return getInquiryUrlForPrimaryKeys(ResponsibilityImpl.class, businessObject, primaryKeys, null); |
| 63 | 0 | } else if(NAMESPACE_CODE.equals(attributeName) || TEMPLATE_NAMESPACE_CODE.equals(attributeName)){ |
| 64 | 0 | List<String> primaryKeys = new ArrayList<String>(); |
| 65 | 0 | primaryKeys.add("code"); |
| 66 | 0 | NamespaceBo parameterNamespace = new NamespaceBo(); |
| 67 | 0 | parameterNamespace.setCode((String)ObjectUtils.getPropertyValue(businessObject, attributeName)); |
| 68 | 0 | return getInquiryUrlForPrimaryKeys(NamespaceBo.class, parameterNamespace, primaryKeys, null); |
| 69 | 0 | } else if(DETAIL_OBJECTS.equals(attributeName)){ |
| 70 | |
|
| 71 | 0 | } else if(ASSIGNED_TO_ROLES.equals(attributeName)){ |
| 72 | 0 | return getAssignedRoleInquiryUrl(businessObject); |
| 73 | |
} |
| 74 | |
|
| 75 | 0 | return super.getInquiryUrl(businessObject, attributeName, forceInquiry); |
| 76 | |
} |
| 77 | |
|
| 78 | |
@SuppressWarnings("unchecked") |
| 79 | |
protected HtmlData getAttributesInquiryUrl(BusinessObject businessObject, String attributeName){ |
| 80 | 0 | List<ResponsibilityAttributeDataImpl> responsibilityAttributeData = |
| 81 | |
(List<ResponsibilityAttributeDataImpl>)ObjectUtils.getPropertyValue(businessObject, attributeName); |
| 82 | 0 | List<AnchorHtmlData> htmlData = new ArrayList<AnchorHtmlData>(); |
| 83 | 0 | List<String> primaryKeys = new ArrayList<String>(); |
| 84 | 0 | primaryKeys.add(ATTRIBUTE_DATA_ID); |
| 85 | 0 | for(ResponsibilityAttributeDataImpl responsibilityAttributeDataImpl: responsibilityAttributeData){ |
| 86 | 0 | htmlData.add(getInquiryUrlForPrimaryKeys(ResponsibilityAttributeDataImpl.class, responsibilityAttributeDataImpl, primaryKeys, |
| 87 | |
getKimAttributeLabelFromDD(responsibilityAttributeDataImpl.getKimAttribute().getAttributeName())+KimConstants.KimUIConstants.NAME_VALUE_SEPARATOR+ |
| 88 | |
responsibilityAttributeDataImpl.getAttributeValue())); |
| 89 | |
} |
| 90 | 0 | return new MultipleAnchorHtmlData(htmlData); |
| 91 | |
} |
| 92 | |
|
| 93 | |
@SuppressWarnings("unchecked") |
| 94 | |
protected HtmlData getAssignedRoleInquiryUrl(BusinessObject businessObject){ |
| 95 | 0 | ResponsibilityImpl responsibility = (ResponsibilityImpl)businessObject; |
| 96 | 0 | List<RoleImpl> assignedToRoles = responsibility.getAssignedToRoles(); |
| 97 | 0 | List<AnchorHtmlData> htmlData = new ArrayList<AnchorHtmlData>(); |
| 98 | 0 | if(assignedToRoles!=null && !assignedToRoles.isEmpty()){ |
| 99 | 0 | List<String> primaryKeys = Collections.singletonList(ROLE_ID); |
| 100 | 0 | RoleService roleService = KIMServiceLocator.getRoleService(); |
| 101 | 0 | for(RoleImpl roleImpl: assignedToRoles){ |
| 102 | 0 | KimRoleInfo roleInfo = roleService.getRole(roleImpl.getRoleId()); |
| 103 | 0 | AnchorHtmlData inquiryHtmlData = getInquiryUrlForPrimaryKeys(RoleImpl.class, roleInfo, primaryKeys, |
| 104 | |
roleInfo.getNamespaceCode()+" "+ |
| 105 | |
roleInfo.getRoleName()); |
| 106 | 0 | inquiryHtmlData.setHref(RoleLookupableHelperServiceImpl.getCustomRoleInquiryHref(inquiryHtmlData.getHref())); |
| 107 | 0 | htmlData.add(inquiryHtmlData); |
| 108 | 0 | } |
| 109 | |
} |
| 110 | 0 | return new MultipleAnchorHtmlData(htmlData); |
| 111 | |
} |
| 112 | |
|
| 113 | |
|
| 114 | |
|
| 115 | |
|
| 116 | |
|
| 117 | |
|
| 118 | |
@SuppressWarnings("unchecked") |
| 119 | |
@Override |
| 120 | |
public BusinessObject getBusinessObject(Map fieldValues) { |
| 121 | 0 | Map<String, String> criteria = new HashMap<String, String>(); |
| 122 | 0 | criteria.put("responsibilityId", fieldValues.get("responsibilityId").toString()); |
| 123 | 0 | KimResponsibilityImpl responsibilityImpl = (KimResponsibilityImpl) KNSServiceLocator.getBusinessObjectService().findByPrimaryKey(KimResponsibilityImpl.class, criteria); |
| 124 | 0 | return getResponsibilitiesSearchResultsCopy(responsibilityImpl); |
| 125 | |
} |
| 126 | |
|
| 127 | |
public ResponsibilityService getResponsibilityService() { |
| 128 | 0 | if (responsibilityService == null ) { |
| 129 | 0 | responsibilityService = KIMServiceLocator.getResponsibilityService(); |
| 130 | |
} |
| 131 | 0 | return responsibilityService; |
| 132 | |
} |
| 133 | |
|
| 134 | |
@SuppressWarnings("unchecked") |
| 135 | |
private ResponsibilityImpl getResponsibilitiesSearchResultsCopy(KimResponsibilityImpl responsibilitySearchResult){ |
| 136 | 0 | ResponsibilityImpl responsibilitySearchResultCopy = new ResponsibilityImpl(); |
| 137 | |
try{ |
| 138 | 0 | PropertyUtils.copyProperties(responsibilitySearchResultCopy, responsibilitySearchResult); |
| 139 | 0 | } catch(Exception ex){ |
| 140 | |
|
| 141 | 0 | ex.printStackTrace(); |
| 142 | 0 | } |
| 143 | 0 | Map<String, String> criteria = new HashMap<String, String>(); |
| 144 | 0 | criteria.put("responsibilityId", responsibilitySearchResultCopy.getResponsibilityId()); |
| 145 | 0 | List<RoleResponsibilityImpl> roleResponsibilitys = |
| 146 | |
(List<RoleResponsibilityImpl>) KNSServiceLocator.getBusinessObjectService().findMatching(RoleResponsibilityImpl.class, criteria); |
| 147 | 0 | List<RoleImpl> assignedToRoles = new ArrayList<RoleImpl>(); |
| 148 | 0 | for(RoleResponsibilityImpl roleResponsibilityImpl: roleResponsibilitys){ |
| 149 | 0 | assignedToRoles.add(getRoleImpl(roleResponsibilityImpl.getRoleId())); |
| 150 | |
} |
| 151 | 0 | responsibilitySearchResultCopy.setAssignedToRoles(assignedToRoles); |
| 152 | 0 | return responsibilitySearchResultCopy; |
| 153 | |
} |
| 154 | |
|
| 155 | |
} |