View Javadoc
1   /*
2    * Copyright 2009 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.vnd.document.authorization;
17  
18  import java.util.Collections;
19  import java.util.HashMap;
20  import java.util.Map;
21  import java.util.Set;
22  
23  import org.kuali.ole.sys.OLEConstants;
24  import org.kuali.ole.sys.context.SpringContext;
25  import org.kuali.ole.sys.document.authorization.FinancialSystemMaintenanceDocumentPresentationControllerBase;
26  import org.kuali.ole.vnd.VendorPropertyConstants;
27  import org.kuali.ole.vnd.businessobject.VendorDetail;
28  import org.kuali.rice.kim.api.KimConstants;
29  import org.kuali.rice.kim.api.services.KimApiServiceLocator;
30  import org.kuali.rice.kns.document.MaintenanceDocument;
31  import org.kuali.rice.kns.service.DocumentHelperService;
32  import org.kuali.rice.krad.bo.BusinessObject;
33  import org.kuali.rice.krad.document.Document;
34  import org.kuali.rice.krad.util.GlobalVariables;
35  import org.kuali.rice.krad.util.ObjectUtils;
36  
37  public class VendorDocumentPresentationController extends FinancialSystemMaintenanceDocumentPresentationControllerBase {
38  
39      @Override
40      public Set<String> getConditionallyReadOnlySectionIds(MaintenanceDocument document) {
41          Set<String> conditionallyReadOnlySectionIds = super.getConditionallyReadOnlySectionIds(document);
42          VendorDetail vendor = (VendorDetail)document.getNewMaintainableObject().getDataObject();
43  
44          if (!vendor.isVendorParentIndicator()) {
45              // make some sections read only, e.g. supplier diversity cause they're on the header
46              conditionallyReadOnlySectionIds.add(VendorPropertyConstants.VENDOR_SUPPLIER_DIVERSITIES);
47          }
48  
49          return conditionallyReadOnlySectionIds;
50      }
51  
52      @Override
53      public Set<String> getConditionallyReadOnlyPropertyNames(MaintenanceDocument document) {
54          Set<String> conditionallyReadonlyPropertyNames = super.getConditionallyReadOnlyPropertyNames(document);
55          VendorDetail vendor = (VendorDetail)document.getNewMaintainableObject().getDataObject();
56          VendorDocumentAuthorizer documentAuthorizer = (VendorDocumentAuthorizer) SpringContext.getBean(DocumentHelperService.class).getDocumentAuthorizer(document);
57          boolean isAuthorized = documentAuthorizer.isAuthorized(document, VendorPropertyConstants.OLE_VND, VendorPropertyConstants.PERMISSION_NAME_INACTIVATE_VENDOR, GlobalVariables.getUserSession().getPerson().getPrincipalId());
58  
59          String nameSpaceCode = OLEConstants.Vendor.VENDOR_NAMESPACE;
60  
61          boolean hasPermission = KimApiServiceLocator.getPermissionService().hasPermission(
62                  GlobalVariables.getUserSession().getPerson().getPrincipalId(), nameSpaceCode,
63                  OLEConstants.Vendor.DEACTIVATE_VENDOR);
64          boolean hasPermissionVendorFlag = KimApiServiceLocator.getPermissionService().hasPermission(
65                  GlobalVariables.getUserSession().getPerson().getPrincipalId(), nameSpaceCode,
66                  OLEConstants.Vendor.EDIT_VENDOR_LINKING_NUM);
67  
68          if (!isAuthorized) {
69              if (!hasPermission) {
70          conditionallyReadonlyPropertyNames.add(VendorPropertyConstants.VENDOR_ACTIVE_INDICATOR);
71          conditionallyReadonlyPropertyNames.add(VendorPropertyConstants.VENDOR_INACTIVE_REASON);
72          }
73              if (!hasPermissionVendorFlag) {
74                  conditionallyReadonlyPropertyNames.add(VendorPropertyConstants.VENDOR_LINKING_NUMBER);
75              }
76          }
77          if (vendor.isVendorParentIndicator()) {
78              // Vendor Parent Indicator should be readOnly if the vendor is a parent.
79              conditionallyReadonlyPropertyNames.add(VendorPropertyConstants.VENDOR_PARENT_INDICATOR);
80  
81              // For existing vendors, don't allow vendor type code to be changed if maint table indicates it shouldn't be changed
82              if (ObjectUtils.isNotNull(vendor.getVendorHeaderGeneratedIdentifier()) && !vendor.getVendorHeader().getVendorType().isVendorTypeChangeAllowedIndicator()) {
83                  conditionallyReadonlyPropertyNames.add(VendorPropertyConstants.VENDOR_TYPE_CODE);
84              }
85          }
86  
87          // If the vendor is not a parent, there are certain fields that should be readOnly
88          else {
89              // All the fields in VendorHeader should be readOnly if the vendor is not a parent.
90              conditionallyReadonlyPropertyNames.add(VendorPropertyConstants.VENDOR_TYPE_CODE);
91              conditionallyReadonlyPropertyNames.add(VendorPropertyConstants.VENDOR_TAX_NUMBER);
92              conditionallyReadonlyPropertyNames.add(VendorPropertyConstants.VENDOR_TAX_TYPE_CODE);
93              conditionallyReadonlyPropertyNames.add(VendorPropertyConstants.VENDOR_OWNERSHIP_CODE);
94              conditionallyReadonlyPropertyNames.add(VendorPropertyConstants.VENDOR_OWNERSHIP_CATEGORY_CODE);
95              conditionallyReadonlyPropertyNames.add(VendorPropertyConstants.VENDOR_FEDERAL_WITHOLDING_TAX_BEGINNING_DATE);
96              conditionallyReadonlyPropertyNames.add(VendorPropertyConstants.VENDOR_FEDERAL_WITHOLDING_TAX_END_DATE);
97              conditionallyReadonlyPropertyNames.add(VendorPropertyConstants.VENDOR_W9_RECEIVED_INDICATOR);
98              conditionallyReadonlyPropertyNames.add(VendorPropertyConstants.VENDOR_W8_BEN_RECEIVED_INDICATOR);
99              conditionallyReadonlyPropertyNames.add(VendorPropertyConstants.VENDOR_DEBARRED_INDICATOR);
100             conditionallyReadonlyPropertyNames.add(VendorPropertyConstants.VENDOR_FOREIGN_INDICATOR);
101         }
102 
103         return conditionallyReadonlyPropertyNames;
104     }
105 
106     @Override
107     public Set<String> getConditionallyHiddenPropertyNames(BusinessObject businessObject) {
108         Set<String> conditionallyHiddenPropertyNames = super.getConditionallyHiddenPropertyNames(businessObject);
109         MaintenanceDocument document = (MaintenanceDocument) businessObject;
110         VendorDetail vendor = (VendorDetail)document.getNewMaintainableObject().getDataObject();
111         // If the vendor is a parent then the vendor parent name should be hidden.
112         if (vendor.isVendorParentIndicator()) {
113             conditionallyHiddenPropertyNames.add(VendorPropertyConstants.VENDOR_PARENT_NAME);
114         }
115 
116         return conditionallyHiddenPropertyNames;
117     }
118 
119     @Override
120     public boolean canBlanketApprove(Document document) {
121 
122         String documentTypeName = OLEConstants.Vendor.DOCUMENT_TYPE;
123         String nameSpaceCode = OLEConstants.Vendor.VENDOR_NAMESPACE;
124         Map<String,String> permissionDetails = new HashMap<String, String>();
125         permissionDetails.put(KimConstants.AttributeConstants.DOCUMENT_TYPE_NAME,documentTypeName);
126         boolean hasPermission = false;
127         /*hasPermission = KimApiServiceLocator.getPermissionService().isAuthorizedByTemplate(
128                 GlobalVariables.getUserSession().getPerson().getPrincipalId(), nameSpaceCode,
129                 OLEConstants.Vendor.BLANKET_APPROVE, permissionDetails, new HashMap<String, String>());*/
130         if (!document.getDocumentHeader().getWorkflowDocument().getStatus().getCode().equalsIgnoreCase(OLEConstants.FINAL_STATUS)) {
131             hasPermission = KimApiServiceLocator.getPermissionService().hasPermission(
132                     GlobalVariables.getUserSession().getPerson().getPrincipalId(), nameSpaceCode,
133                     OLEConstants.Vendor.BLANKET_APPROVE_VENDOR_DOCUMENT);
134         }
135 
136         Map<String,String> roleQualifiers = new HashMap<String,String>();
137 
138       /*  hasPermission = KimApiServiceLocator.getPermissionService().isAuthorized(
139                 GlobalVariables.getUserSession().getPerson().getPrincipalId(), nameSpaceCode,
140                 OLEConstants.Vendor.BLANKET_APPROVE_VENDOR_DOCUMENT, new HashMap<String, String>());
141       */
142       if(!hasPermission) {
143             permissionDetails.put(KimConstants.AttributeConstants.REQUIRED,"FALSE");
144             permissionDetails.put(KimConstants.AttributeConstants.ACTION_DETAILS_AT_ROLE_MEMBER_LEVEL,"FALSE");
145             permissionDetails.put(KimConstants.AttributeConstants.ROUTE_NODE_NAME,OLEConstants.Vendor.VENDOR_MANAGEMENT);
146            /* hasPermission = KimApiServiceLocator.getResponsibilityService().hasResponsibilityByTemplate(
147                     GlobalVariables.getUserSession().getPerson().getPrincipalId(),
148                     OLEConstants.CoreModuleNamespaces.VENDOR, OLEConstants.Vendor.VENDOR_REVIEW,
149                     new HashMap<String, String>(), permissionDetails);*/
150            // hasPermission = KimApiServiceLocator.getResponsibilityService().hasResponsibility(GlobalVariables.getUserSession().getPerson().getPrincipalId(), OLEConstants.Vendor.VENDOR_REVIEW, null);
151 
152             hasPermission = KimApiServiceLocator.getResponsibilityService().hasResponsibility(GlobalVariables.getUserSession().getPerson().getPrincipalId(),OLEConstants.CoreModuleNamespaces.VENDOR, OLEConstants.Vendor.VENDOR_REVIEW_DOCUMENT, Collections.<String, String>emptyMap());
153 
154 
155        }
156 
157        return hasPermission;
158     }
159 
160   }