gt:         if (CollectionUtils.isNotEmpty(budgetPersonSequences)) {
context: /*
   * Kuali Coeus, a comprehensive research administration system for higher education.
   * 
   * Copyright 2005-2015 Kuali, Inc.
   * 
   * This program is free software: you can redistribute it and/or modify
   * it under the terms of the GNU Affero General Public License as
   * published by the Free Software Foundation, either version 3 of the
   * License, or (at your option) any later version.
   * 
   * This program is distributed in the hope that it will be useful,
   * but WITHOUT ANY WARRANTY; without even the implied warranty of
   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   * GNU Affero General Public License for more details.
   * 
   * You should have received a copy of the GNU Affero General Public License
   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
   */
  package org.kuali.coeus.common.budget.impl.personnel;
  
  import org.apache.commons.collections4.CollectionUtils;
  import org.apache.commons.lang3.StringUtils;
  import org.kuali.coeus.sys.api.model.ScaleTwoDecimal;
  import org.kuali.coeus.common.budget.framework.core.Budget;
  import org.kuali.coeus.common.budget.framework.core.BudgetParent;
  import org.kuali.coeus.common.budget.framework.core.BudgetSaveEvent;
  import org.kuali.coeus.common.budget.framework.core.SaveBudgetEvent;
  import org.kuali.coeus.common.budget.framework.nonpersonnel.ApplyToPeriodsBudgetEvent;
  import org.kuali.coeus.common.budget.framework.nonpersonnel.BudgetLineItem;
  import org.kuali.coeus.common.budget.framework.period.BudgetPeriod;
  import org.kuali.coeus.common.budget.framework.personnel.AddPersonnelBudgetEvent;
  import org.kuali.coeus.common.budget.framework.personnel.BudgetPerson;
  import org.kuali.coeus.common.budget.framework.personnel.BudgetPersonService;
  import org.kuali.coeus.common.budget.framework.personnel.BudgetPersonnelDetails;
  import org.kuali.coeus.common.budget.framework.personnel.BudgetSavePersonnelEvent;
  import org.kuali.coeus.common.budget.framework.personnel.BudgetSaveProjectPersonnelEvent;
  import org.kuali.coeus.common.budget.framework.personnel.DeleteBudgetPersonEvent;
  import org.kuali.coeus.common.budget.framework.personnel.JobCode;
  import org.kuali.coeus.common.budget.framework.personnel.JobCodeService;
  import org.kuali.coeus.common.budget.framework.personnel.ValidCeJobCode;
  import org.kuali.coeus.common.framework.ruleengine.KcBusinessRule;
  import org.kuali.coeus.common.framework.ruleengine.KcEventMethod;
  import org.kuali.coeus.common.framework.ruleengine.KcEventResult;
  import org.kuali.kra.infrastructure.Constants;
  import org.kuali.kra.infrastructure.KeyConstants;
  import org.kuali.coeus.propdev.impl.core.DevelopmentProposal;
  import org.kuali.rice.core.api.util.RiceKeyConstants;
  import org.kuali.rice.coreservice.framework.parameter.ParameterService;
  import org.kuali.rice.krad.data.CompoundKey;
  import org.kuali.rice.krad.data.DataObjectService;
  import org.kuali.rice.krad.service.BusinessObjectService;
  import org.kuali.rice.krad.service.DictionaryValidationService;
  import org.kuali.rice.krad.util.GlobalVariables;
  import org.kuali.rice.krad.util.MessageMap;
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.beans.factory.annotation.Qualifier;
  
  import java.util.*;
  
  @KcBusinessRule("budgetPersonnelRule")
  public class BudgetPersonnelRule {
  
      private static final String BUDGET_PERSONS_FIELD_NAME_START = "budgetPersons[";
      private static final String BUDGET_PERSONS_FIELD_NAME_JOBCODE = "].jobCode";
      private static final String BUDGET_PERSONS_FIELD_NAME_PERSON_NUMBER = "].personNumber";
      private static final String BUDGET_PERSONS_FIELD_NAME_CALC_BASE = "].calculationBase";
      
      @Autowired
      @Qualifier("businessObjectService")
      private BusinessObjectService boService;
      
      @Autowired
      @Qualifier("parameterService")
      private ParameterService paramService;
      
      @Autowired
      @Qualifier("budgetPersonService")
      private  BudgetPersonService budgetPersonService;
      
      @Autowired
      @Qualifier("dictionaryValidationService")
      private DictionaryValidationService dictionaryValidationService;
      
  	@Autowired
  	@Qualifier("dataObjectService")
  	private DataObjectService dataObjectService;
  	
  	@Autowired
  	@Qualifier("jobCodeService")
  	private JobCodeService jobCodeService;
  	
      /**
       * 
       * This method to check the 'selected' person to delete is not associate with budget personnel details
       * @param budgetDocument
       * @param budgetPerson
       * @return
       */
      @KcEventMethod
      public boolean processCheckExistBudgetPersonnelDetailsBusinessRules(DeleteBudgetPersonEvent event) {
          boolean valid = true;
          String errorPath = event.getErrorPath();
          // User  may delete person before the deleted detail is persisted
          if (isPersonDetailsFound (event.getBudget(), event.getBudgetPerson())) {
                  final MessageMap messageMap = GlobalVariables.getMessageMap();
                  messageMap.putError(errorPath, KeyConstants.ERROR_DELETE_PERSON_WITH_PERSONNEL_DETAIL, event.getBudgetPerson().getPersonName());
                  valid = false;
          }
          return valid;
      }
      
      /*
       * Check if this budget person has any budgetdetail set.  This is called before checking whether
       * this person can be deleted.  If retrieve from DB, then it might not be correct because
       * the deleted detail may have not been persisted before delete person is called.
       */
      private boolean isPersonDetailsFound (Budget budget, BudgetPerson budgetPerson) {
          for (BudgetPeriod budgetPeriod : budget.getBudgetPeriods()) {
              for (BudgetLineItem lineItem : budgetPeriod.getBudgetLineItems()) {
                  for (BudgetPersonnelDetails budgetPersonnelDetail : lineItem.getBudgetPersonnelDetailsList()) {
                      if (budgetPersonnelDetail.getPersonSequenceNumber().equals(budgetPerson.getPersonSequenceNumber())) {
                          return true;
                      }
                  }
              }
          }
          return false;
      }
  
      @KcEventMethod
      public boolean processCheckBaseSalaryFormat(BudgetSaveEvent event) {
          boolean valid = true;
          
          MessageMap messageMap = GlobalVariables.getMessageMap();
          int i = 0;
          List<BudgetPerson> budgetPersons = event.getBudget().getBudgetPersons();
          for (BudgetPerson budgetPerson : budgetPersons) {
              if (budgetPerson.getCalculationBase() == null) {
                  messageMap.putError(BUDGET_PERSONS_FIELD_NAME_START + i + BUDGET_PERSONS_FIELD_NAME_CALC_BASE,
                      RiceKeyConstants.ERROR_REQUIRED, new String[] {"Base Salary"});
                      valid = false;
              } else if (budgetPerson.getCalculationBase().isNegative()) {
                  messageMap.putError(BUDGET_PERSONS_FIELD_NAME_START + i + BUDGET_PERSONS_FIELD_NAME_CALC_BASE,
                      KeyConstants.ERROR_NEGATIVE_AMOUNT, new String[] {"Base Salary"});
                  valid = false;
              }
              i++;
          }
                      
          return valid;
      }
  
      private Collection<ValidCeJobCode> getMappedCostElements(BudgetPerson person) {
          return budgetPersonService.getApplicableCostElements(person.getBudget(), 
                  person.getPersonSequenceNumber().toString());
      }
      
      @KcEventMethod
      public boolean processBudgetPersonnelBusinessRules(BudgetSaveEvent event) {
          boolean valid = true;
          
          MessageMap messageMap = GlobalVariables.getMessageMap();
          
          List<BudgetPerson> budgetPersons = event.getBudget().getBudgetPersons();
          for (int i = 0; i < budgetPersons.size(); i++) {
              BudgetPerson budgetPerson = budgetPersons.get(i);
              for (int j = i + 1; j < budgetPersons.size(); j++) {
                  BudgetPerson budgetPersonCompare = budgetPersons.get(j);
                  if (budgetPerson.isDuplicatePerson(budgetPersonCompare)) {
                      BudgetParent budgetParent = event.getBudget().getBudgetParent().getDocument().getBudgetParent();
                      if (budgetParent instanceof DevelopmentProposal && ((DevelopmentProposal)budgetParent).isParent()) {
                          // not an error - ProposalHierarchy parents are allowed to have duplicate BudgetPersons
                      }
                      else {
                          messageMap.putError("budgetPersons[" + j + "].personName", KeyConstants.ERROR_DUPLICATE_BUDGET_PERSON, budgetPerson.getPersonName());
                          valid = false;
                      }
                  }
  
              }
              
          }
          
          return valid;
      }
  
      /**
       * This method executes the job code change validation rules against the budget document
       * for a specific budget period.
       * @param budgetDocument the budget document
       * @param viewBudgetPeriod the budget period number.
       * @return true is valid false if not valid
       * @throws NullPointerException if the budgetDocument is null
       * @throws IllegalArgumentException if the viewBudgetPeriod < 1
       */
      @KcEventMethod
      public boolean processCheckForJobCodeChange(BudgetSavePersonnelEvent event) {
          if (event.getBudget() == null) {
              throw new NullPointerException("the budgetDocument is null");
          }
          
          if (event.getCurrentBudgetPeriod() == null) {
              throw new NullPointerException("the currentBudgetPeriod is invalid");
          }
          
          boolean valid = true;
          
          GlobalVariables.getMessageMap().addToErrorPath("document");
  
          final BudgetPeriod selectedBudgetPeriod = event.getCurrentBudgetPeriod();
          
          final Collection<Integer> budgetPersonSequences
              = this.getBudgetPersonSequencesFromPersonnelDetails(selectedBudgetPeriod.getBudgetLineItems());
          
  