View Javadoc

1   /*
2    * Copyright 2011 The Kuali Foundation Licensed under the Educational Community
3    * License, Version 1.0 (the "License"); you may not use this file except in
4    * compliance with the License. You may obtain a copy of the License at
5    * http://www.opensource.org/licenses/ecl1.php Unless required by applicable law
6    * or agreed to in writing, software distributed under the License is
7    * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
8    * KIND, either express or implied. See the License for the specific language
9    * governing permissions and limitations under the License.
10   */
11  package org.kuali.rice.krad.uif.service.impl;
12  
13  import org.kuali.rice.krad.bo.AdHocRoutePerson;
14  import org.kuali.rice.krad.bo.AdHocRouteWorkgroup;
15  import org.kuali.rice.krad.rule.event.AddAdHocRoutePersonEvent;
16  import org.kuali.rice.krad.rule.event.AddAdHocRouteWorkgroupEvent;
17  import org.kuali.rice.krad.service.KRADServiceLocatorWeb;
18  import org.kuali.rice.krad.service.KualiRuleService;
19  import org.kuali.rice.krad.uif.container.CollectionGroup;
20  import org.kuali.rice.krad.uif.view.View;
21  import org.kuali.rice.krad.web.form.DocumentFormBase;
22  
23  /**
24   * @author Kuali Rice Team (rice.collab@kuali.org)
25   */
26  public class DocumentViewHelperServiceImpl extends ViewHelperServiceImpl {
27  
28      private KualiRuleService kualiRuleService;
29  
30      /**
31       * Performs validation on the new collection line before it is added to the
32       * corresponding collection
33       *
34       * @param view - view instance that the action was taken on
35       * @param collectionGroup - collection group component for the collection
36       * @param addLine - new line instance to validate
37       * @param model - object instance that contains the views data
38       * @return boolean true if the line is valid and it should be added to the
39       *         collection, false if it was not valid and should not be added to
40       *         the collection
41       */
42      @Override
43      protected boolean performAddLineValidation(View view, CollectionGroup collectionGroup, Object model,
44              Object addLine) {
45          boolean isValidLine = true;
46  
47          if (model instanceof DocumentFormBase && addLine instanceof AdHocRoutePerson) {
48              DocumentFormBase form = (DocumentFormBase) model;
49              isValidLine = getKualiRuleService()
50                      .applyRules(new AddAdHocRoutePersonEvent(form.getDocument(), (AdHocRoutePerson) addLine));
51          } else if (model instanceof DocumentFormBase && addLine instanceof AdHocRouteWorkgroup) {
52              DocumentFormBase form = (DocumentFormBase) model;
53              isValidLine = getKualiRuleService()
54                      .applyRules(new AddAdHocRouteWorkgroupEvent(form.getDocument(), (AdHocRouteWorkgroup) addLine));
55          }
56  
57          return isValidLine;
58      }
59  
60      protected KualiRuleService getKualiRuleService() {
61          if (kualiRuleService == null) {
62              kualiRuleService = KRADServiceLocatorWeb.getKualiRuleService();
63          }
64          return this.kualiRuleService;
65      }
66  }