1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
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
45
46
47
48
49
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 }