View Javadoc
1   /**
2    * Copyright 2005-2014 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.rice.krad.uif.service.impl;
17  
18  import org.kuali.rice.krad.bo.AdHocRoutePerson;
19  import org.kuali.rice.krad.bo.AdHocRouteWorkgroup;
20  import org.kuali.rice.krad.rules.rule.event.AddAdHocRoutePersonEvent;
21  import org.kuali.rice.krad.rules.rule.event.AddAdHocRouteWorkgroupEvent;
22  import org.kuali.rice.krad.service.KRADServiceLocatorWeb;
23  import org.kuali.rice.krad.service.KualiRuleService;
24  import org.kuali.rice.krad.uif.view.ViewModel;
25  import org.kuali.rice.krad.web.form.DocumentFormBase;
26  
27  /**
28   * View helper extension for document views.
29   *
30   * @author Kuali Rice Team (rice.collab@kuali.org)
31   */
32  public class DocumentViewHelperServiceImpl extends ViewHelperServiceImpl {
33      private static final long serialVersionUID = 5311653907592800785L;
34  
35      private transient KualiRuleService kualiRuleService;
36  
37      /**
38       * Performs validation on the new collection line before it is added to the corresponding collection.
39       *
40       * @param addLine new line instance to validate
41       * @param model object instance that contains the views data
42       * @return true if the line is valid and it should be added to the
43       * collection, false if it was not valid and should not be added to
44       * the collection
45       */
46      @Override
47      protected boolean performAddLineValidation(ViewModel model, Object addLine, String collectionId,
48              String collectionPath) {
49          boolean isValidLine = super.performAddLineValidation(model, addLine, collectionId, collectionPath);
50  
51          if (model instanceof DocumentFormBase && addLine instanceof AdHocRoutePerson) {
52              DocumentFormBase form = (DocumentFormBase) model;
53              isValidLine &= getKualiRuleService().applyRules(new AddAdHocRoutePersonEvent(form.getDocument(),
54                      (AdHocRoutePerson) addLine));
55          } else if (model instanceof DocumentFormBase && addLine instanceof AdHocRouteWorkgroup) {
56              DocumentFormBase form = (DocumentFormBase) model;
57              isValidLine &= getKualiRuleService().applyRules(new AddAdHocRouteWorkgroupEvent(form.getDocument(),
58                      (AdHocRouteWorkgroup) addLine));
59          }
60  
61          return isValidLine;
62      }
63  
64      /**
65       * Retrieves an instance of the rule service.
66       *
67       * @return Kuali rule service
68       */
69      protected KualiRuleService getKualiRuleService() {
70          if (kualiRuleService == null) {
71              kualiRuleService = KRADServiceLocatorWeb.getKualiRuleService();
72          }
73  
74          return this.kualiRuleService;
75      }
76  }