View Javadoc
1   /*
2    * Copyright 2011 The Kuali Foundation.
3    *
4    * Licensed under the Educational Community License, Version 1.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/ecl1.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.sys.document.validation;
17  
18  import java.util.ArrayList;
19  import java.util.Collection;
20  import java.util.List;
21  
22  import org.kuali.ole.sys.document.validation.event.AttributedDocumentEvent;
23  import org.kuali.rice.kew.api.WorkflowDocument;
24  
25  /**
26   * An abstract class that creates an easy way to do routeNode validations.  Basically,
27   * extenders set a validRouteNodeNames - a list of all valid route nodes to perform the validation.
28   */
29  public abstract class RouteNodeValidation extends GenericValidation {
30      private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(RouteNodeValidation.class);
31  
32      protected List<String> validRouteNodeNames;
33  
34      @Override
35      public boolean stageValidation(AttributedDocumentEvent event) {
36          boolean valid = true;
37          if (LOG.isDebugEnabled()) {
38              LOG.debug("Staging validation for: "+getClass().getName()+" for event "+event.getClass().getName());
39          }
40          populateParametersFromEvent(event);
41  
42          Collection<String> currentRouteLevels = new ArrayList<String>();
43          try {
44              WorkflowDocument workflowDoc = event.getDocument().getDocumentHeader().getWorkflowDocument();
45              currentRouteLevels = workflowDoc.getNodeNames();
46              for(String nodeName : validRouteNodeNames) {
47                  if (currentRouteLevels.contains(nodeName) && workflowDoc.isApprovalRequested()) {
48                      return validate(event);
49                  }
50              }
51  
52          }
53          catch (Exception e) {
54              throw new RuntimeException(e);
55          }
56  
57          return valid;
58  
59  
60      }
61  
62  
63  
64  
65  
66      public void setValidRouteNodeNames(List<String> validRouteNodeNames) {
67          this.validRouteNodeNames = validRouteNodeNames;
68      }
69  
70      /**
71       * @return list of valid route node names
72       */
73      public List<String> getValidRouteNodeNames() {
74          return validRouteNodeNames;
75      }
76  
77  
78  
79  
80  
81  }