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.module.purap.document.authorization;
17  
18  import org.kuali.ole.module.purap.businessobject.SensitiveData;
19  import org.kuali.ole.module.purap.document.ReceivingDocument;
20  import org.kuali.ole.module.purap.identity.PurapKimAttributes;
21  import org.kuali.ole.module.purap.service.SensitiveDataService;
22  import org.kuali.ole.sys.context.SpringContext;
23  import org.kuali.rice.kim.api.KimConstants;
24  import org.kuali.rice.kim.api.identity.Person;
25  import org.kuali.rice.kns.document.authorization.TransactionalDocumentAuthorizerBase;
26  import org.kuali.rice.krad.document.Document;
27  import org.kuali.rice.krad.util.KRADConstants;
28  
29  import java.util.List;
30  import java.util.Map;
31  
32  public class ReceivingDocumentAuthorizerBase extends TransactionalDocumentAuthorizerBase {
33  
34      @Override
35      protected void addRoleQualification(Object businessObject, Map<String, String> attributes) {
36          super.addRoleQualification(businessObject, attributes);
37          attributes.put(PurapKimAttributes.DOCUMENT_SENSITIVE, "false");
38          ReceivingDocument purapDoc = (ReceivingDocument) businessObject;
39          if (purapDoc.getAccountsPayablePurchasingDocumentLinkIdentifier() != null) {
40              List<SensitiveData> sensitiveDataList = SpringContext.getBean(SensitiveDataService.class).getSensitiveDatasAssignedByRelatedDocId(purapDoc.getAccountsPayablePurchasingDocumentLinkIdentifier());
41              StringBuffer sensitiveDataCodes = new StringBuffer();
42              for (SensitiveData sensitiveData : sensitiveDataList) {
43                  sensitiveDataCodes.append(sensitiveData.getSensitiveDataCode()).append(";");
44              }
45              if (sensitiveDataCodes.length() > 0) {
46                  attributes.put(PurapKimAttributes.DOCUMENT_SENSITIVE, "true");
47                  attributes.put(PurapKimAttributes.SENSITIVE_DATA_CODE, sensitiveDataCodes.toString().substring(0, sensitiveDataCodes.length() - 1));
48                  attributes.put(PurapKimAttributes.ACCOUNTS_PAYABLE_PURCHASING_DOCUMENT_LINK_IDENTIFIER, purapDoc.getAccountsPayablePurchasingDocumentLinkIdentifier().toString());
49              }
50          }
51      }
52  
53      @Override
54      public boolean canEditDocumentOverview(Document document, Person user) {
55          return isAuthorizedByTemplate(document,
56                  KRADConstants.KNS_NAMESPACE,
57                  KimConstants.PermissionTemplateNames.EDIT_DOCUMENT,
58                  user.getPrincipalId());
59      }
60  
61  }