<commit_before>/*
 * Copyright 2011 The Kuali Foundation Licensed under the Educational Community
 * License, Version 1.0 (the "License"); you may not use this file except in
 * compliance with the License. You may obtain a copy of the License at
 * http://www.opensource.org/licenses/ecl1.php Unless required by applicable law
 * or agreed to in writing, software distributed under the License is
 * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied. See the License for the specific language
 * governing permissions and limitations under the License.
 */
package org.kuali.rice.krad.uif.service.impl;

import org.kuali.rice.krad.bo.AdHocRoutePerson;
import org.kuali.rice.krad.bo.AdHocRouteWorkgroup;
import org.kuali.rice.krad.rule.event.AddAdHocRoutePersonEvent;
import org.kuali.rice.krad.rule.event.AddAdHocRouteWorkgroupEvent;
import org.kuali.rice.krad.service.KRADServiceLocatorWeb;
import org.kuali.rice.krad.service.KualiRuleService;
import org.kuali.rice.krad.uif.container.CollectionGroup;
import org.kuali.rice.krad.uif.container.View;
import org.kuali.rice.krad.web.spring.form.MaintenanceForm;

/**
 * @author <NAME> (<EMAIL>)
 */
public class DocumentViewHelperServiceImpl extends ViewHelperServiceImpl {

    private KualiRuleService kualiRuleService;

    /**
     * Performs validation on the new collection line before it is added to the
     * corresponding collection
     *
     * @param view
     *            - view instance that the action was taken on
     * @param collectionGroup
     *            - collection group component for the collection
     * @param addLine
     *            - new line instance to validate
     * @param model
     *            - object instance that contain's the views data
     * @return boolean true if the line is valid and it should be added to the
     *         collection, false if it was not valid and should not be added to
     *         the collection
     */
    @Override
    protected boolean performAddLineValidation(View view, CollectionGroup collectionGroup, Object model, Object addLine) {
        boolean isValidLine = true;

        if (model.getClass().equals(MaintenanceForm.class) && addLine.getClass().equals(AdHocRoutePerson.class)) {
            MaintenanceForm form = (MaintenanceForm) model;
            isValidLine = getKualiRuleService().applyRules(new AddAdHocRoutePersonEvent(form.getDocument(), (AdHocRoutePerson)addLine));
        }
        else if (model.getClass().equals(MaintenanceForm.class) && addLine.getClass().equals(AdHocRouteWorkgroup.class)) {
            MaintenanceForm form = (MaintenanceForm) model;
            isValidLine = getKualiRuleService().applyRules(new AddAdHocRouteWorkgroupEvent(form.getDocument(), (AdHocRouteWorkgroup)addLine));
        }

        return isValidLine;
    }

    protected KualiRuleService getKualiRuleService() {
        if (kualiRuleService == null) {
            kualiRuleService = KRADServiceLocatorWeb.getKualiRuleService();
        }
        return this.kualiRuleService;<commit_msg>KULRICE-5153 - Minor adjustments to look at document form, not just maintenance form.<commit_after>/*
 * Copyright 2011 The Kuali Foundation Licensed under the Educational Community
 * License, Version 1.0 (the "License"); you may not use this file except in
 * compliance with the License. You may obtain a copy of the License at
 * http://www.opensource.org/licenses/ecl1.php Unless required by applicable law
 * or agreed to in writing, software distributed under the License is
 * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied. See the License for the specific language
 * governing permissions and limitations under the License.
 */
package org.kuali.rice.krad.uif.service.impl;

import org.kuali.rice.krad.bo.AdHocRoutePerson;
import org.kuali.rice.krad.bo.AdHocRouteWorkgroup;
import org.kuali.rice.krad.rule.event.AddAdHocRoutePersonEvent;
import org.kuali.rice.krad.rule.event.AddAdHocRouteWorkgroupEvent;
import org.kuali.rice.krad.service.KRADServiceLocatorWeb;
import org.kuali.rice.krad.service.KualiRuleService;
import org.kuali.rice.krad.uif.container.CollectionGroup;
import org.kuali.rice.krad.uif.container.View;
import org.kuali.rice.krad.web.spring.form.DocumentFormBase;

/**
 * @author <NAME> (<EMAIL>)
 */
public class DocumentViewHelperServiceImpl extends ViewHelperServiceImpl {

    private KualiRuleService kualiRuleService;

    /**
     * Performs validation on the new collection line before it is added to the
     * corresponding collection
     *
     * @param view
     *            - view instance that the action was taken on
     * @param collectionGroup
     *            - collection group component for the collection
     * @param addLine
     *            - new line instance to validate
     * @param model
     *            - object instance that contain's the views data
     * @return boolean true if the line is valid and it should be added to the
     *         collection, false if it was not valid and should not be added to
     *         the collection
     */
    @Override
    protected boolean performAddLineValidation(View view, CollectionGroup collectionGroup, Object model, Object addLine) {
        boolean isValidLine = true;

        if (model instanceof DocumentFormBase && addLine instanceof AdHocRoutePerson) {
            DocumentFormBase form = (DocumentFormBase) model;
            isValidLine = getKualiRuleService().applyRules(new AddAdHocRoutePersonEvent(form.getDocument(), (AdHocRoutePerson)addLine));
        }
        else if (model instanceof DocumentFormBase && addLine instanceof AdHocRouteWorkgroup) {
            DocumentFormBase form = (DocumentFormBase) model;
            isValidLine = getKualiRuleService().applyRules(new AddAdHocRouteWorkgroupEvent(form.getDocument(), (AdHocRouteWorkgroup)addLine));
        }

        return isValidLine;
    }

    protected KualiRuleService getKualiRuleService() {
        if (kualiRuleService == null) {
            kualiRuleService = KRADServiceLocatorWeb.getKualiRuleService();
        }
        return this.kualiRuleService;
{'fraction_non_alphanumeric': 0.07839974189385385, 'fraction_numerical': 0.002903694144216809, 'mean_word_length': 3.397163120567376, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1897027', 'n_tokens_mistral': 1731, 'n_tokens_neox': 1698, 'n_words': 506}