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.OleLoadSumRecords;
21  import org.kuali.ole.sys.OLEConstants;
22  import org.kuali.ole.sys.businessobject.inquiry.KfsInquirableImpl;
23  import org.kuali.ole.sys.context.SpringContext;
24  import org.kuali.rice.kim.api.services.IdentityManagementService;
25  import org.kuali.rice.kns.lookup.HtmlData;
26  import org.kuali.rice.kns.lookup.HtmlData.AnchorHtmlData;
27  import org.kuali.rice.krad.bo.BusinessObject;
28  import org.kuali.rice.krad.exception.DocumentAuthorizationException;
29  import org.kuali.rice.krad.util.GlobalVariables;
30  import org.kuali.rice.krad.util.KRADConstants;
31  import org.kuali.rice.krad.util.UrlFactory;
32  
33  import java.util.*;
34  
35  
36  /**
37   * This class adds in some new sections for {@link Org} inquiries, specifically Org Hierarchy Org Review Hierarchy
38   */
39  public class OleLoadSummaryInquirable extends KfsInquirableImpl {
40  
41      private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(OleLoadSummaryInquirable.class);
42  
43      /**
44       * Overrides the helper method to build an inquiry url for a result field.
45       * For the Vendor URL field, returns the url address as the inquiry URL, so that Vendor URL functions as a hyperlink.
46       *
47       * @param bo           the business object instance to build the urls for
48       * @param propertyName the property which links to an inquirable
49       * @return String url to inquiry
50       */
51      @Override
52      public HtmlData getInquiryUrl(BusinessObject businessObject, String attributeName, boolean forceInquiry) {
53  
54          boolean hasPermission = false;
55          String documentTypeName = OLEConstants.OleLoadSummary.LOAD_SUMMARY;
56          String nameSpaceCode = OLEConstants.OleLoadSummary.LOAD_SUMMARY_NAMESPACE;
57          if (LOG.isDebugEnabled()) {
58              LOG.debug("Inside getInquiryUrl documentTypeName   >>>>>>>>>>>>>>>>>" + documentTypeName);
59              LOG.debug("Inside getInquiryUrl nameSpaceCode  >>>>>>>>>>>>>>>>>" + nameSpaceCode);
60          }
61          hasPermission = SpringContext.getBean(IdentityManagementService.class).hasPermission(GlobalVariables.getUserSession().getPerson().getPrincipalId(), nameSpaceCode,
62                  OLEConstants.OleLoadSummary.CAN_SEARCH_LOAD_SUMMARY);
63  
64          if (!hasPermission) {
65              if (LOG.isDebugEnabled()) {
66                  LOG.debug("Inside getInquiryUrl hasPermission   if>>>>>>>>>>>>>>>>>" + hasPermission);
67              }
68              throw new DocumentAuthorizationException(GlobalVariables.getUserSession().getPerson().getPrincipalName(), " to edit reuisition document ", "dfsf");
69          } else {
70              if (businessObject instanceof OleLoadSumRecords && attributeName.equalsIgnoreCase("documentNumber")) {
71                  List<String> primaryKeys = new ArrayList<String>();
72                  primaryKeys.add("documentNumber");
73                  String href = (getInquiryUrlForPrimaryKeys(OleLoadSumRecords.class, businessObject, primaryKeys, null)).getHref();
74                  AnchorHtmlData htmlData = new AnchorHtmlData();
75                  htmlData.setHref(href);
76                  return htmlData;
77              }
78  
79              return super.getInquiryUrl(businessObject, attributeName, forceInquiry);
80          }
81      }
82  
83      @Override
84      public AnchorHtmlData getInquiryUrlForPrimaryKeys(
85              Class clazz, Object businessObject, List<String> primaryKeys, String displayText) {
86          if (businessObject == null) {
87              return new AnchorHtmlData(KRADConstants.EMPTY_STRING, KRADConstants.EMPTY_STRING);
88          }
89  
90          OleLoadSumRecords oleLoadSumRecords = (OleLoadSumRecords) businessObject;
91          Properties parameters = new Properties();
92          Map<String, String> fieldList = new HashMap<String, String>();
93          parameters.put(KRADConstants.DISPATCH_REQUEST_PARAMETER, "docHandler");
94          parameters.put(OLEConstants.DOCUMENT_TYPE_NAME, "OLE_ACQBTHUPLOAD");
95          parameters.put(OLEConstants.PARAMETER_COMMAND, "displayDocSearchView");
96          parameters.put("docId", oleLoadSumRecords.getDocumentNumber().toString());
97          fieldList.put("docId", oleLoadSumRecords.getDocumentNumber().toString());
98          if (StringUtils.isEmpty(displayText)) {
99              return getHyperLink(clazz, fieldList, UrlFactory.parameterizeUrl(OLEConstants.BATCH_UPLOAD_ACTION_PATH, parameters));
100         } else {
101             return getHyperLink(clazz, fieldList, UrlFactory.parameterizeUrl(OLEConstants.BATCH_UPLOAD_ACTION_PATH, parameters), displayText);
102         }
103     }
104 
105 }