001 /*
002 * Copyright 2011 The Kuali Foundation.
003 *
004 * Licensed under the Educational Community License, Version 2.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/ecl2.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.kfs.module.purap.document.authorization;
017
018 import java.util.List;
019 import java.util.Map;
020
021 import org.kuali.kfs.module.purap.businessobject.SensitiveData;
022 import org.kuali.kfs.module.purap.document.PurchasingAccountsPayableDocument;
023 import org.kuali.kfs.module.purap.identity.PurapKimAttributes;
024 import org.kuali.kfs.module.purap.service.SensitiveDataService;
025 import org.kuali.kfs.sys.context.SpringContext;
026 import org.kuali.kfs.sys.document.authorization.AccountingDocumentAuthorizerBase;
027 import org.kuali.rice.kim.bo.Person;
028 import org.kuali.rice.kim.util.KimConstants;
029 import org.kuali.rice.kns.bo.BusinessObject;
030 import org.kuali.rice.kns.document.Document;
031 import org.kuali.rice.kns.util.KNSConstants;
032 import org.kuali.rice.kns.util.ObjectUtils;
033
034 public class PurchasingAccountsPayableTransactionalDocumentAuthorizerBase extends AccountingDocumentAuthorizerBase {
035
036 @Override
037 protected void addRoleQualification(BusinessObject businessObject, Map<String, String> attributes) {
038 super.addRoleQualification(businessObject, attributes);
039 attributes.put(PurapKimAttributes.DOCUMENT_SENSITIVE, "false");
040 PurchasingAccountsPayableDocument purapDoc = (PurchasingAccountsPayableDocument) businessObject;
041 if (purapDoc.getAccountsPayablePurchasingDocumentLinkIdentifier() != null) {
042 List<SensitiveData> sensitiveDataList = SpringContext.getBean(SensitiveDataService.class).getSensitiveDatasAssignedByRelatedDocId(purapDoc.getAccountsPayablePurchasingDocumentLinkIdentifier());
043 if (ObjectUtils.isNotNull(sensitiveDataList) && !sensitiveDataList.isEmpty()) {
044 StringBuffer sensitiveDataCodes = new StringBuffer();
045 for (SensitiveData sensitiveData : sensitiveDataList) {
046 if (ObjectUtils.isNotNull(sensitiveData)) {
047 sensitiveDataCodes.append(sensitiveData.getSensitiveDataCode()).append(";");
048 }
049 }
050 if (sensitiveDataCodes.length() > 0) {
051 attributes.put(PurapKimAttributes.DOCUMENT_SENSITIVE, "true");
052 attributes.put(PurapKimAttributes.SENSITIVE_DATA_CODE, sensitiveDataCodes.toString().substring(0, sensitiveDataCodes.length() - 1));
053 attributes.put(PurapKimAttributes.ACCOUNTS_PAYABLE_PURCHASING_DOCUMENT_LINK_IDENTIFIER, purapDoc.getAccountsPayablePurchasingDocumentLinkIdentifier().toString());
054 }
055 }
056 }
057 }
058
059 @Override
060 public boolean canEditDocumentOverview(Document document, Person user) {
061 return isAuthorizedByTemplate(document,
062 KNSConstants.KNS_NAMESPACE,
063 KimConstants.PermissionTemplateNames.EDIT_DOCUMENT,
064 user.getPrincipalId());
065 }
066
067 }