View Javadoc
1   /*
2    * Copyright 2010 The Kuali Foundation.
3    *
4    * Licensed under the Educational Community License, Version 1.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/ecl1.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.coa.identity;
17  
18  import java.util.Collections;
19  import java.util.Map;
20  import java.util.Properties;
21  
22  import org.apache.commons.lang.StringUtils;
23  import org.kuali.ole.coa.service.OrgReviewRoleService;
24  import org.kuali.ole.sys.OLEConstants;
25  import org.kuali.ole.sys.businessobject.inquiry.KfsInquirableImpl;
26  import org.kuali.ole.sys.context.SpringContext;
27  import org.kuali.rice.kns.lookup.HtmlData;
28  import org.kuali.rice.krad.bo.BusinessObject;
29  import org.kuali.rice.krad.util.KRADConstants;
30  import org.kuali.rice.krad.util.UrlFactory;
31  
32  public class OrgReviewRoleInquirableImpl extends KfsInquirableImpl {
33  
34      protected static final String ORG_REVIEW_ROLE_INQUIRY_TITLE = "orgReviewRoleInquiryTitle";
35      protected static final String ORG_REVIEW_ROLE_MEMBER_ID = "orgReviewRoleMemberId";
36  
37      private static OrgReviewRoleService orgReviewRoleService;
38  
39      @Override
40      public BusinessObject getBusinessObject(Map fieldValues) {
41          OrgReviewRole orr = new OrgReviewRole();
42          String roleMemberId = (String) fieldValues.get(ORG_REVIEW_ROLE_MEMBER_ID);
43          if ( StringUtils.isNotBlank( roleMemberId ) ) {
44              if ( Boolean.valueOf( (String)fieldValues.get(OrgReviewRole.DELEGATE_FIELD_NAME) ) ) {
45                  getOrgReviewRoleService().populateOrgReviewRoleFromDelegationMember(orr, null, roleMemberId );
46              } else {
47                  getOrgReviewRoleService().populateOrgReviewRoleFromRoleMember(orr, roleMemberId );
48              }
49          }
50          return orr;
51      }
52  
53      @Override
54      public HtmlData getInquiryUrl(BusinessObject businessObject, String attributeName, boolean forceInquiry) {
55          if ( StringUtils.equals( attributeName, ORG_REVIEW_ROLE_INQUIRY_TITLE) ) {
56              Properties parameters = new Properties();
57              parameters.put(KRADConstants.DISPATCH_REQUEST_PARAMETER, OLEConstants.START_METHOD);
58              parameters.put(KRADConstants.BUSINESS_OBJECT_CLASS_ATTRIBUTE, OrgReviewRole.class.getName());
59              if ( StringUtils.isNotBlank(((OrgReviewRole)businessObject).getDelegationMemberId()) ) {
60                  parameters.put(ORG_REVIEW_ROLE_MEMBER_ID, ((OrgReviewRole)businessObject).getDelegationMemberId() );
61                  parameters.put(OrgReviewRole.DELEGATE_FIELD_NAME, "true" );
62              } else if ( StringUtils.isNotBlank(((OrgReviewRole)businessObject).getRoleMemberId()) ) {
63                  parameters.put(ORG_REVIEW_ROLE_MEMBER_ID, ((OrgReviewRole)businessObject).getRoleMemberId() );
64                  parameters.put(OrgReviewRole.DELEGATE_FIELD_NAME, "false" );
65              }
66              return getHyperLink(OrgReviewRole.class, Collections.EMPTY_MAP, UrlFactory.parameterizeUrl(KRADConstants.INQUIRY_ACTION, parameters));
67          } else {
68              return super.getInquiryUrl(businessObject, attributeName, forceInquiry);
69          }
70      }
71  
72      protected OrgReviewRoleService getOrgReviewRoleService() {
73          if ( orgReviewRoleService == null ) {
74              orgReviewRoleService = SpringContext.getBean( OrgReviewRoleService.class );
75          }
76          return orgReviewRoleService;
77      }
78  }