View Javadoc
1   /*
2    * Copyright 2008 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.validation.impl;
17  
18  import org.apache.commons.lang.StringUtils;
19  import org.kuali.ole.module.purap.PurapConstants;
20  import org.kuali.ole.module.purap.PurapKeyConstants;
21  import org.kuali.ole.module.purap.businessobject.SensitiveData;
22  import org.kuali.ole.module.purap.document.PurchaseOrderDocument;
23  import org.kuali.ole.sys.document.validation.GenericValidation;
24  import org.kuali.ole.sys.document.validation.event.AttributedDocumentEvent;
25  import org.kuali.rice.krad.util.GlobalVariables;
26  
27  import java.util.HashSet;
28  import java.util.List;
29  
30  /**
31   * A validation that checks whether the given accounting line is accessible to the given user or not
32   */
33  public class PurchaseOrderAssignSensitiveDataValidation extends GenericValidation {
34  
35      private PurchaseOrderDocument accountingDocumentForValidation;
36      private String sensitiveDataAssignmentReason;
37      private List<SensitiveData> sensitiveDatasAssigned;
38  
39      /**
40       * Applies rules for validation of sensitive data assignment to the PurchaseOrder document:
41       * The assignment reason must not be empty;
42       * The assigned sensitive data entries must be active and not redundant.
43       *
44       * @param document A PurchaseOrderDocument (or one of its children)
45       * @return True if all relevant validation rules are passed.
46       */
47      public boolean validate(AttributedDocumentEvent event) {
48          boolean valid = true;
49          GlobalVariables.getMessageMap().clearErrorPath();
50          HashSet<String> sdset = new HashSet<String>();
51  
52          if (StringUtils.isEmpty(sensitiveDataAssignmentReason)) {
53              GlobalVariables.getMessageMap().putError(PurapConstants.ASSIGN_SENSITIVE_DATA_TAB_ERRORS, PurapKeyConstants.ERROR_ASSIGN_SENSITIVE_DATA_REASON_EMPTY);
54              valid = false;
55          }
56  
57          for (Object sdobj : sensitiveDatasAssigned) {
58              SensitiveData sd = (SensitiveData) sdobj;
59              if (!sd.isActive()) {
60                  GlobalVariables.getMessageMap().putError(PurapConstants.ASSIGN_SENSITIVE_DATA_TAB_ERRORS, PurapKeyConstants.ERROR_ASSIGN_SENSITIVE_DATA_INACTIVE, sd.getSensitiveDataDescription());
61                  valid = false;
62              } else if (!sdset.add(sd.getSensitiveDataCode())) {
63                  GlobalVariables.getMessageMap().putError(PurapConstants.ASSIGN_SENSITIVE_DATA_TAB_ERRORS, PurapKeyConstants.ERROR_ASSIGN_SENSITIVE_DATA_REDUNDANT, sd.getSensitiveDataDescription());
64                  valid = false;
65              }
66          }
67  
68          GlobalVariables.getMessageMap().clearErrorPath();
69          return valid;
70      }
71  
72      public PurchaseOrderDocument getAccountingDocumentForValidation() {
73          return accountingDocumentForValidation;
74      }
75  
76      public void setAccountingDocumentForValidation(PurchaseOrderDocument accountingDocumentForValidation) {
77          this.accountingDocumentForValidation = accountingDocumentForValidation;
78      }
79  
80      public String getSensitiveDataAssignmentReason() {
81          return sensitiveDataAssignmentReason;
82      }
83  
84      public void setSensitiveDataAssignmentReason(String sensitiveDataAssignmentReason) {
85          this.sensitiveDataAssignmentReason = sensitiveDataAssignmentReason;
86      }
87  
88      public List<SensitiveData> getSensitiveDatasAssigned() {
89          return sensitiveDatasAssigned;
90      }
91  
92      public void setSensitiveDatasAssigned(List<SensitiveData> sensitiveDatasAssigned) {
93          this.sensitiveDatasAssigned = sensitiveDatasAssigned;
94      }
95  
96  }
97