001: /*
002: * Copyright 2007 The Kuali Foundation.
003: *
004: * Licensed under the Educational Community License, Version 1.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.opensource.org/licenses/ecl1.php
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: package org.kuali.module.vendor.document.authorization;
017:
018: import java.util.List;
019: import java.util.Map;
020:
021: import org.kuali.core.bo.user.UniversalUser;
022: import org.kuali.core.document.Document;
023: import org.kuali.core.document.MaintenanceDocument;
024: import org.kuali.core.document.authorization.DocumentActionFlags;
025: import org.kuali.core.document.authorization.MaintenanceDocumentActionFlags;
026: import org.kuali.core.document.authorization.MaintenanceDocumentAuthorizations;
027: import org.kuali.core.document.authorization.MaintenanceDocumentAuthorizerBase;
028: import org.kuali.core.util.ObjectUtils;
029: import org.kuali.kfs.context.SpringContext;
030: import org.kuali.kfs.service.ParameterService;
031: import org.kuali.kfs.service.impl.ParameterConstants;
032: import org.kuali.module.vendor.VendorAuthorizationConstants;
033: import org.kuali.module.vendor.VendorConstants;
034: import org.kuali.module.vendor.VendorPropertyConstants;
035: import org.kuali.module.vendor.bo.VendorContract;
036: import org.kuali.module.vendor.bo.VendorContractOrganization;
037: import org.kuali.module.vendor.bo.VendorDetail;
038: import org.kuali.module.vendor.bo.VendorHeader;
039: import org.kuali.module.vendor.bo.VendorSupplierDiversity;
040: import org.kuali.module.vendor.util.VendorUtils;
041:
042: /**
043: * Authorizer class for Vendor maintenance document
044: */
045: public class VendorDocumentAuthorizer extends
046: MaintenanceDocumentAuthorizerBase {
047:
048: /**
049: * By default, there are no restrictions for the fields in the superclass. This method is overridden here to makes all the
050: * fields in Vendor Header readOnly if the vendor is not a parent. If the vendor is not a new vendor, if it is a parent, if
051: * vendor header and vendor type is not null and if the vendor type's changed allowed is set to N in the vendor type maintenance
052: * table, then we have to set the vendor type as readOnly field.
053: *
054: * @see org.kuali.core.document.authorization.MaintenanceDocumentAuthorizer#getFieldAuthorizations(org.kuali.core.document.MaintenanceDocument,
055: * org.kuali.core.bo.user.UniversalUser)
056: */
057: @Override
058: public MaintenanceDocumentAuthorizations getFieldAuthorizations(
059: MaintenanceDocument document, UniversalUser user) {
060: MaintenanceDocumentAuthorizations auths = new MaintenanceDocumentAuthorizations();
061: VendorDetail vendor = (VendorDetail) document
062: .getNewMaintainableObject().getBusinessObject();
063: VendorDetail oldVendor = (VendorDetail) document
064: .getOldMaintainableObject().getBusinessObject();
065: VendorHeader vendorHeader = vendor.getVendorHeader();
066: VendorHeader oldVendorHeader = oldVendor.getVendorHeader();
067:
068: // If the vendor is not a parent, there are certain fields that should be readOnly
069: if (!vendor.isVendorParentIndicator()) {
070: // All the fields in VendorHeader should be readOnly if the vendor is not a parent.
071:
072: auths
073: .addReadonlyAuthField(VendorPropertyConstants.VENDOR_TYPE_CODE);
074: auths
075: .addReadonlyAuthField(VendorPropertyConstants.VENDOR_TAX_NUMBER);
076: auths
077: .addReadonlyAuthField(VendorPropertyConstants.VENDOR_TAX_TYPE_CODE);
078: auths
079: .addReadonlyAuthField(VendorPropertyConstants.VENDOR_OWNERSHIP_CODE);
080: auths
081: .addReadonlyAuthField(VendorPropertyConstants.VENDOR_OWNERSHIP_CATEGORY_CODE);
082: auths
083: .addReadonlyAuthField(VendorPropertyConstants.VENDOR_FEDERAL_WITHOLDING_TAX_BEGINNING_DATE);
084: auths
085: .addReadonlyAuthField(VendorPropertyConstants.VENDOR_FEDERAL_WITHOLDING_TAX_END_DATE);
086: auths
087: .addReadonlyAuthField(VendorPropertyConstants.VENDOR_W9_RECEIVED_INDICATOR);
088: auths
089: .addReadonlyAuthField(VendorPropertyConstants.VENDOR_W8_BEN_RECEIVED_INDICATOR);
090: auths
091: .addReadonlyAuthField(VendorPropertyConstants.VENDOR_DEBARRED_INDICATOR);
092: auths
093: .addReadonlyAuthField(VendorPropertyConstants.VENDOR_FOREIGN_INDICATOR);
094: // Supplier Diversities drop down menu is readOnly if the vendor is not a parent.
095: List<VendorSupplierDiversity> supplierDivs = vendor
096: .getVendorHeader().getVendorSupplierDiversities();
097: if (ObjectUtils.isNotNull(supplierDivs)) {
098: for (int div = 0; div < supplierDivs.size(); div++) {
099: VendorSupplierDiversity vsd = supplierDivs.get(div);
100: auths
101: .addReadonlyAuthField(VendorUtils
102: .assembleWithPosition(
103: VendorPropertyConstants.VENDOR_HEADER_PREFIX
104: + VendorPropertyConstants.VENDOR_SUPPLIER_DIVERSITY_CODE,
105: VendorPropertyConstants.VENDOR_SUPPLIER_DIVERSITIES,
106: div));
107: auths
108: .addReadonlyAuthField(VendorUtils
109: .assembleWithPosition(
110: VendorPropertyConstants.VENDOR_HEADER_PREFIX
111: + VendorPropertyConstants.VENDOR_SUPPLIER_DIVERSITY_ACTIVE,
112: VendorPropertyConstants.VENDOR_SUPPLIER_DIVERSITIES,
113: div));
114: }
115: }
116: }
117: // Else if the vendor is not a new vendor, if it is a parent, if vendor header and vendor type is not null
118: // and if the vendor type's changed allowed is set to
119: // N in the vendor type maintenance table, then we have to set the vendor type as readOnly field.
120: else if (ObjectUtils.isNotNull(vendor
121: .getVendorHeaderGeneratedIdentifier())
122: && ObjectUtils.isNotNull(vendorHeader)
123: && ObjectUtils.isNotNull(oldVendorHeader
124: .getVendorType())
125: && !oldVendorHeader.getVendorType()
126: .isVendorTypeChangeAllowedIndicator()) {
127: auths
128: .addReadonlyAuthField(VendorPropertyConstants.VENDOR_TYPE_CODE);
129: }
130: setVendorContractFieldsAuthorization(vendor, auths, user);
131:
132: return auths;
133: }
134:
135: /**
136: * If the current user is a member of TAXNBR_ACCESSIBLE_GROUP then user is allowed to edit tax number.
137: *
138: * @see org.kuali.core.document.MaintenanceDocumentAuthorizerBase#getEditMode(org.kuali.core.document.Document,
139: * org.kuali.core.bo.user.KualiUser)
140: */
141: @Override
142: public Map getEditMode(Document document, UniversalUser user) {
143: Map editMode = super .getEditMode(document, user);
144: VendorDetail vendor = (VendorDetail) ((MaintenanceDocument) document)
145: .getNewMaintainableObject().getBusinessObject();
146: String taxNbrAccessibleWorkgroup = SpringContext.getBean(
147: ParameterService.class).getParameterValue(
148: VendorDetail.class,
149: VendorConstants.Workgroups.WORKGROUP_TAXNBR_ACCESSIBLE);
150:
151: if (user.isMember(taxNbrAccessibleWorkgroup)) {
152: editMode
153: .put(
154: VendorAuthorizationConstants.VendorEditMode.TAX_ENTRY,
155: "TRUE");
156: }
157:
158: return editMode;
159: }
160:
161: /**
162: * Disables blanket approve for Vendor maintenance document
163: *
164: * @see org.kuali.core.document.authorization.DocumentAuthorizer#getDocumentActionFlags(org.kuali.core.document.Document,
165: * org.kuali.core.bo.user.UniversalUser)
166: */
167: @Override
168: public DocumentActionFlags getDocumentActionFlags(
169: Document document, UniversalUser user) {
170: MaintenanceDocumentActionFlags docActionFlags = new MaintenanceDocumentActionFlags(
171: super .getDocumentActionFlags(document, user));
172: docActionFlags.setCanBlanketApprove(false);
173: return docActionFlags;
174: }
175:
176: /**
177: * Sets the vendor contract and vendor contract organization fields to be read only if the current user is not a member of
178: * purchasing workgroup.
179: *
180: * @param vendor an instance of VendorDetail document
181: * @param auths an instance of MaintenanceDocumentAuthorizations which is used to define the read only fields
182: * @param user current logged-in user
183: */
184: private void setVendorContractFieldsAuthorization(
185: VendorDetail vendor,
186: MaintenanceDocumentAuthorizations auths, UniversalUser user) {
187: String purchasingWorkgroup = SpringContext.getBean(
188: ParameterService.class).getParameterValue(
189: ParameterConstants.PURCHASING_DOCUMENT.class,
190: VendorConstants.Workgroups.WORKGROUP_PURCHASING);
191: if (!user.isMember(purchasingWorkgroup)) {
192: List<VendorContract> contracts = vendor
193: .getVendorContracts();
194: int i = 0;
195: for (VendorContract contract : contracts) {
196: // contract fields
197: auths.addReadonlyAuthField("vendorContracts[" + i
198: + "].vendorContractName");
199: auths.addReadonlyAuthField("vendorContracts[" + i
200: + "].vendorContractDescription");
201: auths.addReadonlyAuthField("vendorContracts[" + i
202: + "].vendorCampusCode");
203: auths.addReadonlyAuthField("vendorContracts[" + i
204: + "].vendorContractBeginningDate");
205: auths.addReadonlyAuthField("vendorContracts[" + i
206: + "].vendorContractEndDate");
207: auths.addReadonlyAuthField("vendorContracts[" + i
208: + "].contractManagerCode");
209: auths.addReadonlyAuthField("vendorContracts[" + i
210: + "].vendorB2bIndicator");
211: auths.addReadonlyAuthField("vendorContracts[" + i
212: + "].purchaseOrderCostSourceCode");
213: auths.addReadonlyAuthField("vendorContracts[" + i
214: + "].vendorPaymentTermsCode");
215: auths.addReadonlyAuthField("vendorContracts[" + i
216: + "].vendorShippingPaymentTermsCode");
217: auths.addReadonlyAuthField("vendorContracts[" + i
218: + "].vendorShippingTitleCode");
219: auths.addReadonlyAuthField("vendorContracts[" + i
220: + "].vendorContractExtensionDate");
221: auths.addReadonlyAuthField("vendorContracts[" + i
222: + "].organizationAutomaticPurchaseOrderLimit");
223: auths.addReadonlyAuthField("vendorContracts[" + i
224: + "].active");
225:
226: // contract organization sub collection fields
227: int j = 0;
228: List<VendorContractOrganization> vendorContractOrganizations = contract
229: .getVendorContractOrganizations();
230: for (VendorContractOrganization org : vendorContractOrganizations) {
231: auths.addReadonlyAuthField("vendorContracts[" + i
232: + "].vendorContractOrganizations[" + j
233: + "].chartOfAccountsCode");
234: auths.addReadonlyAuthField("vendorContracts[" + i
235: + "].vendorContractOrganizations[" + j
236: + "].organizationCode");
237: auths
238: .addReadonlyAuthField("vendorContracts["
239: + i
240: + "].vendorContractOrganizations["
241: + j
242: + "].vendorContractPurchaseOrderLimitAmount");
243: auths.addReadonlyAuthField("vendorContracts[" + i
244: + "].vendorContractOrganizations[" + j
245: + "].vendorContractExcludeIndicator");
246: auths.addReadonlyAuthField("vendorContracts[" + i
247: + "].vendorContractOrganizations[" + j
248: + "].active");
249: j++;
250: }
251: i++;
252: }
253: }
254: }
255: }
|