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.ElectronicInvoiceRejectDocument;
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.rice.kim.bo.Person;
027    import org.kuali.rice.kim.util.KimConstants;
028    import org.kuali.rice.kns.bo.BusinessObject;
029    import org.kuali.rice.kns.document.Document;
030    import org.kuali.rice.kns.document.authorization.TransactionalDocumentAuthorizerBase;
031    import org.kuali.rice.kns.util.KNSConstants;
032    
033    public class ElectronicInvoiceRejectDocumentAuthorizer extends TransactionalDocumentAuthorizerBase {
034    
035        @Override
036        protected void addRoleQualification(BusinessObject businessObject, Map<String, String> attributes) {
037            super.addRoleQualification(businessObject, attributes);
038            attributes.put(PurapKimAttributes.DOCUMENT_SENSITIVE, "false");
039            ElectronicInvoiceRejectDocument purapDoc = (ElectronicInvoiceRejectDocument) businessObject;
040            if (purapDoc.getAccountsPayablePurchasingDocumentLinkIdentifier() != null) {
041                List<SensitiveData> sensitiveDataList = SpringContext.getBean(SensitiveDataService.class).getSensitiveDatasAssignedByRelatedDocId(purapDoc.getAccountsPayablePurchasingDocumentLinkIdentifier());
042                StringBuffer sensitiveDataCodes = new StringBuffer();
043                for (SensitiveData sensitiveData : sensitiveDataList) {
044                    sensitiveDataCodes.append(sensitiveData.getSensitiveDataCode()).append(";");
045                }
046                if (sensitiveDataCodes.length() > 0) {
047                    attributes.put(PurapKimAttributes.DOCUMENT_SENSITIVE, "true");
048                    attributes.put(PurapKimAttributes.SENSITIVE_DATA_CODE, sensitiveDataCodes.toString().substring(0, sensitiveDataCodes.length() - 1));
049                    attributes.put(PurapKimAttributes.ACCOUNTS_PAYABLE_PURCHASING_DOCUMENT_LINK_IDENTIFIER, purapDoc.getAccountsPayablePurchasingDocumentLinkIdentifier().toString());
050                }
051            }
052        }
053        
054        @Override
055        public boolean canEditDocumentOverview(Document document, Person user) {
056            return isAuthorizedByTemplate(document,
057                    KNSConstants.KNS_NAMESPACE,
058                    KimConstants.PermissionTemplateNames.EDIT_DOCUMENT,
059                    user.getPrincipalId());
060        }
061    
062    }