001    /**
002     * Copyright 2005-2012 The Kuali Foundation
003     *
004     * Licensed under the Educational Community License, Version 2.0 (the "License");
005     * you may not use this file except in compliance with the License.
006     * You may obtain a copy of the License at
007     *
008     * http://www.opensource.org/licenses/ecl2.php
009     *
010     * Unless required by applicable law or agreed to in writing, software
011     * distributed under the License is distributed on an "AS IS" BASIS,
012     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013     * See the License for the specific language governing permissions and
014     * limitations under the License.
015     */
016    package org.kuali.rice.krad.uif.service.impl;
017    
018    import org.kuali.rice.krad.bo.AdHocRoutePerson;
019    import org.kuali.rice.krad.bo.AdHocRouteWorkgroup;
020    import org.kuali.rice.krad.rules.rule.event.AddAdHocRoutePersonEvent;
021    import org.kuali.rice.krad.rules.rule.event.AddAdHocRouteWorkgroupEvent;
022    import org.kuali.rice.krad.service.KRADServiceLocatorWeb;
023    import org.kuali.rice.krad.service.KualiRuleService;
024    import org.kuali.rice.krad.uif.container.CollectionGroup;
025    import org.kuali.rice.krad.uif.view.View;
026    import org.kuali.rice.krad.web.form.DocumentFormBase;
027    
028    /**
029     * @author Kuali Rice Team (rice.collab@kuali.org)
030     */
031    public class DocumentViewHelperServiceImpl extends ViewHelperServiceImpl {
032    
033        private KualiRuleService kualiRuleService;
034    
035        /**
036         * Performs validation on the new collection line before it is added to the
037         * corresponding collection
038         *
039         * @param view - view instance that the action was taken on
040         * @param collectionGroup - collection group component for the collection
041         * @param addLine - new line instance to validate
042         * @param model - object instance that contains the views data
043         * @return boolean true if the line is valid and it should be added to the
044         *         collection, false if it was not valid and should not be added to
045         *         the collection
046         */
047        @Override
048        protected boolean performAddLineValidation(View view, CollectionGroup collectionGroup, Object model,
049                Object addLine) {
050            boolean isValidLine = true;
051    
052            if (model instanceof DocumentFormBase && addLine instanceof AdHocRoutePerson) {
053                DocumentFormBase form = (DocumentFormBase) model;
054                isValidLine = getKualiRuleService()
055                        .applyRules(new AddAdHocRoutePersonEvent(form.getDocument(), (AdHocRoutePerson) addLine));
056            } else if (model instanceof DocumentFormBase && addLine instanceof AdHocRouteWorkgroup) {
057                DocumentFormBase form = (DocumentFormBase) model;
058                isValidLine = getKualiRuleService()
059                        .applyRules(new AddAdHocRouteWorkgroupEvent(form.getDocument(), (AdHocRouteWorkgroup) addLine));
060            }
061    
062            return isValidLine;
063        }
064    
065        /**
066         * Gets the Kuali rule service
067         *
068         * @return KualiRuleService Kuali rule service
069         */
070        protected KualiRuleService getKualiRuleService() {
071            if (kualiRuleService == null) {
072                kualiRuleService = KRADServiceLocatorWeb.getKualiRuleService();
073            }
074            return this.kualiRuleService;
075        }
076    }