View Javadoc
1   /*
2    * Copyright 2011 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.ole.select.businessobject.inquiry;
17  
18  
19  import org.apache.commons.lang.StringUtils;
20  import org.kuali.ole.select.businessobject.OlePersonRequestor;
21  import org.kuali.ole.sys.businessobject.inquiry.KfsInquirableImpl;
22  import org.kuali.rice.kns.lookup.HtmlData;
23  import org.kuali.rice.kns.lookup.HtmlData.AnchorHtmlData;
24  import org.kuali.rice.krad.bo.BusinessObject;
25  import org.kuali.rice.krad.util.KRADConstants;
26  import org.kuali.rice.krad.util.ObjectUtils;
27  import org.kuali.rice.krad.util.UrlFactory;
28  
29  import java.util.*;
30  
31  
32  /**
33   * This class adds in some new sections for {@link Org} inquiries, specifically Org Hierarchy Org Review Hierarchy
34   */
35  public class OlePersonRequestorInquirableImpl extends KfsInquirableImpl {
36  
37      /**
38       * Overrides the helper method to build an inquiry url for a result field.
39       * For the Vendor URL field, returns the url address as the inquiry URL, so that Vendor URL functions as a hyperlink.
40       *
41       * @param bo           the business object instance to build the urls for
42       * @param propertyName the property which links to an inquirable
43       * @return String url to inquiry
44       */
45      @Override
46      public HtmlData getInquiryUrl(BusinessObject businessObject, String attributeName, boolean forceInquiry) {
47          if (businessObject instanceof OlePersonRequestor && attributeName.equalsIgnoreCase("id")) {
48              List<String> primaryKeys = new ArrayList<String>();
49              primaryKeys.add("id");
50              String href = (getInquiryUrlForPrimaryKeys(OlePersonRequestor.class, businessObject, primaryKeys, null)).getHref();
51              href = "kr/" + href;
52              AnchorHtmlData htmlData = new AnchorHtmlData();
53              htmlData.setHref(href);
54              return htmlData;
55          }
56  
57          return super.getInquiryUrl(businessObject, attributeName, forceInquiry);
58      }
59  
60      @Override
61      public AnchorHtmlData getInquiryUrlForPrimaryKeys(
62              Class clazz, Object businessObject, List<String> primaryKeys, String displayText) {
63          Map<String, String> fieldList = new HashMap<String, String>();
64          if (businessObject == null) {
65              return new AnchorHtmlData(KRADConstants.EMPTY_STRING, KRADConstants.EMPTY_STRING);
66          }
67  
68          Properties parameters = new Properties();
69          parameters.put(KRADConstants.DISPATCH_REQUEST_PARAMETER, KRADConstants.START_METHOD);
70          OlePersonRequestor olePersonRequestor = (OlePersonRequestor) businessObject;
71          if (olePersonRequestor.getInternalRequestorId() != null) {
72              parameters.put(KRADConstants.BUSINESS_OBJECT_CLASS_ATTRIBUTE, "org.kuali.rice.kim.api.identity.Person");
73              parameters.put("principalId", olePersonRequestor.getInternalRequestorId());
74              fieldList.put("principalId", olePersonRequestor.getInternalRequestorId());
75          } else if (olePersonRequestor.getExternalRequestorId() != null) {
76              parameters.put(KRADConstants.BUSINESS_OBJECT_CLASS_ATTRIBUTE, "org.kuali.ole.select.businessobject.OleRequestor");
77              parameters.put("requestorId", olePersonRequestor.getExternalRequestorId());
78              fieldList.put("requestorId", olePersonRequestor.getExternalRequestorId());
79          } else {
80              parameters.put(KRADConstants.BUSINESS_OBJECT_CLASS_ATTRIBUTE, clazz.getClass());
81              String titleAttributeValue;
82              for (String primaryKey : primaryKeys) {
83                  titleAttributeValue = ObjectUtils.getPropertyValue(businessObject, primaryKey).toString();
84                  parameters.put(primaryKey, titleAttributeValue);
85                  fieldList.put(primaryKey, titleAttributeValue);
86              }
87          }
88          if (StringUtils.isEmpty(displayText)) {
89              return getHyperLink(clazz, fieldList, UrlFactory.parameterizeUrl(KRADConstants.INQUIRY_ACTION, parameters));
90          } else {
91              return getHyperLink(clazz, fieldList, UrlFactory.parameterizeUrl(KRADConstants.INQUIRY_ACTION, parameters), displayText);
92          }
93      }
94  
95  }