<commit_before>/*
 * Copyright 2005-2010 The Kuali Foundation
 * 
 * Licensed under the Educational Community License, Version 2.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.kra.personmasschange.service.impl;

import java.util.List;

import org.apache.commons.lang.ObjectUtils;
import org.apache.commons.lang.StringUtils;
import org.kuali.kra.bo.AbstractProjectPerson;
import org.kuali.kra.document.ResearchDocumentBase;
import org.kuali.kra.infrastructure.KeyConstants;
import org.kuali.kra.personmasschange.bo.PersonMassChange;
import org.kuali.kra.rules.ErrorReporter;
import org.kuali.kra.service.KcPersonService;
import org.kuali.kra.service.RolodexService;
import org.kuali.rice.krad.bo.PersistableBusinessObject;
import org.kuali.rice.krad.service.BusinessObjectService;

public abstract class MassPersonChangeServiceBase {
    
    protected static final String PMC_LOCKED_FIELD = "personMassChangeDocumentLocked";

    protected final ErrorReporter errorReporter = new ErrorReporter();
    
    private BusinessObjectService businessObjectService;
    private KcPersonService kcPersonService;
    private RolodexService rolodexService;

    protected boolean isReplacerValidPersonChangeCandidate(PersonMassChange personMassChange, List<? extends AbstractProjectPerson> persons) {
        boolean isValid = true;
        for (AbstractProjectPerson person : persons) {
            if ((personMassChange.getReplacerPersonId() != null 
                        && StringUtils.equals(personMassChange.getReplacerPersonId(), person.getPersonId()))
                    || (personMassChange.getReplacerRolodexId() != null 
                        && ObjectUtils.equals(personMassChange.getReplaceeRolodexId(), person.getRolodexId()))) {
                reportReplacerExists(person);
                isValid = false;
            }
        }
        return isValid;
    }
    
    protected boolean isPersonChangeCandidate(PersonMassChange personMassChange, List<? extends AbstractProjectPerson> persons, String... personRoles) {
        boolean isPersonChangeCandidate = false;
        
        for (AbstractProjectPerson person : persons) {
            if (isPersonInRole(person, personRoles)) {
                if (isPersonIdMassChange(personMassChange, person.getPersonId()) || isRolodexIdMassChange(personMassChange, person.getRolodexId())) {
                    isPersonChangeCandidate = true;
                    break;<commit_msg>KCINFR-618 : Fix typo in the check for a duplicate person.<commit_after>/*
 * Copyright 2005-2010 The Kuali Foundation
 * 
 * Licensed under the Educational Community License, Version 2.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.kra.personmasschange.service.impl;

import java.util.List;

import org.apache.commons.lang.ObjectUtils;
import org.apache.commons.lang.StringUtils;
import org.kuali.kra.bo.AbstractProjectPerson;
import org.kuali.kra.document.ResearchDocumentBase;
import org.kuali.kra.infrastructure.KeyConstants;
import org.kuali.kra.personmasschange.bo.PersonMassChange;
import org.kuali.kra.rules.ErrorReporter;
import org.kuali.kra.service.KcPersonService;
import org.kuali.kra.service.RolodexService;
import org.kuali.rice.krad.bo.PersistableBusinessObject;
import org.kuali.rice.krad.service.BusinessObjectService;

public abstract class MassPersonChangeServiceBase {
    
    protected static final String PMC_LOCKED_FIELD = "personMassChangeDocumentLocked";

    protected final ErrorReporter errorReporter = new ErrorReporter();
    
    private BusinessObjectService businessObjectService;
    private KcPersonService kcPersonService;
    private RolodexService rolodexService;

    protected boolean isReplacerValidPersonChangeCandidate(PersonMassChange personMassChange, List<? extends AbstractProjectPerson> persons) {
        boolean isValid = true;
        for (AbstractProjectPerson person : persons) {
            if ((personMassChange.getReplacerPersonId() != null 
                        && StringUtils.equals(personMassChange.getReplacerPersonId(), person.getPersonId()))
                    || (personMassChange.getReplacerRolodexId() != null 
                        && ObjectUtils.equals(personMassChange.getReplacerRolodexId(), person.getRolodexId()))) {
                reportReplacerExists(person);
                isValid = false;
            }
        }
        return isValid;
    }
    
    protected boolean isPersonChangeCandidate(PersonMassChange personMassChange, List<? extends AbstractProjectPerson> persons, String... personRoles) {
        boolean isPersonChangeCandidate = false;
        
        for (AbstractProjectPerson person : persons) {
            if (isPersonInRole(person, personRoles)) {
                if (isPersonIdMassChange(personMassChange, person.getPersonId()) || isRolodexIdMassChange(personMassChange, person.getRolodexId())) {
                    isPersonChangeCandidate = true;
                    break;
{'fraction_non_alphanumeric': 0.0790413054563998, 'fraction_numerical': 0.004249532551419344, 'mean_word_length': 3.6076742364917775, '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': '6725103', 'n_tokens_mistral': 1620, 'n_tokens_neox': 1549, 'n_words': 394}