<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.kfs.module.tem.document.validation.impl;

import org.kuali.kfs.module.tem.TemKeyConstants;
import org.kuali.kfs.module.tem.TemPropertyConstants.ArrangerFields;
import org.kuali.kfs.module.tem.document.TravelArrangerDocument;
import org.kuali.kfs.sys.context.SpringContext;
import org.kuali.kfs.sys.document.validation.GenericValidation;
import org.kuali.kfs.sys.document.validation.event.AttributedDocumentEvent;
import org.kuali.rice.kim.api.identity.Person;
import org.kuali.rice.kim.api.identity.PersonService;
import org.kuali.rice.krad.util.GlobalVariables;
import org.kuali.rice.krad.util.ObjectUtils;

public class TravelArrangerUniqueTravelerArrangerValidation extends GenericValidation {

    @Override
    public boolean validate(AttributedDocumentEvent event) {
        boolean success = true;
        TravelArrangerDocument document = (TravelArrangerDocument)event.getDocument();
        Integer profileId = document.getProfileId();
        String arrangerId = document.getArrangerId();
        Person arranger = null;

        if(ObjectUtils.isNotNull(profileId)) {
            document.refreshReferenceObject("profile");
        }

        if (ObjectUtils.isNull(document.getProfile())) {
            /** Route document does a validation of the DD and already put the error message on in the message map so we do not need to put another on the stack.
            * If we do not return here, we'll get a NPE down below.
            */
            return false;
        }
        if(ObjectUtils.isNotNull(arrangerId)) {
            arranger = SpringContext.getBean(PersonService.class).getPerson(arrangerId);
        }

        if(document.getProfile().getPrincipalId().equals(arrangerId)) {
            GlobalVariables.getMessageMap().putError(ArrangerFields.TRAVELER_NAME, TemKeyConstants.ERROR_TTA_ARRGR_TRVLR_SAME);<commit_msg>KFSMI-9891 fixing NPE when non KIM TEM profile is used.<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.kfs.module.tem.document.validation.impl;

import org.kuali.kfs.module.tem.TemKeyConstants;
import org.kuali.kfs.module.tem.TemPropertyConstants.ArrangerFields;
import org.kuali.kfs.module.tem.document.TravelArrangerDocument;
import org.kuali.kfs.sys.document.validation.GenericValidation;
import org.kuali.kfs.sys.document.validation.event.AttributedDocumentEvent;
import org.kuali.rice.krad.util.GlobalVariables;
import org.kuali.rice.krad.util.ObjectUtils;

public class TravelArrangerUniqueTravelerArrangerValidation extends GenericValidation {

    @Override
    public boolean validate(AttributedDocumentEvent event) {
        boolean success = true;
        TravelArrangerDocument document = (TravelArrangerDocument)event.getDocument();
        Integer profileId = document.getProfileId();
        String arrangerId = document.getArrangerId();

        if(ObjectUtils.isNotNull(profileId)) {
            document.refreshReferenceObject("profile");
        }

        if (ObjectUtils.isNull(document.getProfile()) ) {
            /** Route document does a validation of the DD and already put the error message on in the message map so we do not need to put another on the stack.
            * If we do not return here, we'll get a NPE down below.
            */
            return false;
        }

        if (ObjectUtils.isNull(document.getProfile().getPrincipalId())) {
            //Non KIM TEM profile
            return true;
        }

        if(document.getProfile().getPrincipalId().equals(arrangerId)) {
            GlobalVariables.getMessageMap().putError(ArrangerFields.TRAVELER_NAME, TemKeyConstants.ERROR_TTA_ARRGR_TRVLR_SAME);
{'fraction_non_alphanumeric': 0.08544891640866874, 'fraction_numerical': 0.0037151702786377707, 'mean_word_length': 3.632887189292543, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '5716640', 'n_tokens_mistral': 1352, 'n_tokens_neox': 1303, 'n_words': 376}