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