001 /** 002 * Copyright 2004-2013 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.hr.time.earncodegroup.service; 017 018 import java.util.HashSet; 019 import java.util.Map; 020 import java.util.Set; 021 022 import org.kuali.hr.time.HrBusinessObject; 023 import org.kuali.hr.time.earncodegroup.EarnCodeGroup; 024 import org.kuali.hr.time.earncodegroup.EarnCodeGroupDefinition; 025 import org.kuali.hr.time.service.base.TkServiceLocator; 026 import org.kuali.hr.time.util.HrBusinessObjectMaintainableImpl; 027 import org.kuali.hr.time.util.ValidationUtils; 028 import org.kuali.rice.kns.document.MaintenanceDocument; 029 import org.kuali.rice.krad.util.GlobalVariables; 030 import org.kuali.rice.krad.util.KRADConstants; 031 032 public class EarnCodeGroupMaintainableImpl extends HrBusinessObjectMaintainableImpl{ 033 /** 034 * 035 */ 036 private static final long serialVersionUID = 1L; 037 038 @Override 039 public void addNewLineToCollection(String collectionName) { 040 if (collectionName.equals("earnCodeGroups")) { 041 EarnCodeGroupDefinition definition = (EarnCodeGroupDefinition)newCollectionLines.get(collectionName ); 042 if ( definition != null ) { 043 EarnCodeGroup earnGroup = (EarnCodeGroup)this.getBusinessObject(); 044 Set<String> earnCodes = new HashSet<String>(); 045 for(EarnCodeGroupDefinition earnGroupDef : earnGroup.getEarnCodeGroups()){ 046 earnCodes.add(earnGroupDef.getEarnCode()); 047 } 048 if(earnCodes.contains(definition.getEarnCode())){ 049 GlobalVariables.getMessageMap().putErrorWithoutFullErrorPath(KRADConstants.MAINTENANCE_NEW_MAINTAINABLE +"earnCodeGroups", 050 "earngroup.duplicate.earncode",definition.getEarnCode()); 051 return; 052 } 053 if (!ValidationUtils.validateEarnCode(definition.getEarnCode().toUpperCase(), earnGroup.getEffectiveDate())) { 054 GlobalVariables.getMessageMap().putErrorWithoutFullErrorPath(KRADConstants.MAINTENANCE_NEW_MAINTAINABLE +"earnCodeGroups", 055 "error.existence", "Earncode '" + definition.getEarnCode()+ "'"); 056 return; 057 } 058 } 059 } 060 super.addNewLineToCollection(collectionName); 061 } 062 063 @Override 064 public void processAfterEdit( MaintenanceDocument document, Map<String,String[]> parameters ) { 065 EarnCodeGroup earnGroup = (EarnCodeGroup)this.getBusinessObject(); 066 int count = TkServiceLocator.getEarnCodeGroupService().getNewerEarnCodeGroupCount(earnGroup.getEarnCodeGroup(), earnGroup.getEffectiveDate()); 067 if(count > 0) { 068 GlobalVariables.getMessageMap().putWarningWithoutFullErrorPath(KRADConstants.MAINTENANCE_NEW_MAINTAINABLE + "effectiveDate", 069 "earngroup.effectiveDate.newr.exists"); 070 } 071 } 072 073 @Override 074 public HrBusinessObject getObjectById(String id) { 075 return TkServiceLocator.getEarnCodeGroupService().getEarnCodeGroup(id); 076 } 077 078 @Override 079 public void customSaveLogic(HrBusinessObject hrObj){ 080 EarnCodeGroup ecg = (EarnCodeGroup)hrObj; 081 for (EarnCodeGroupDefinition definition : ecg.getEarnCodeGroups()) { 082 definition.setHrEarnCodeGroupDefId(null); 083 definition.setHrEarnCodeGroupId(ecg.getHrEarnCodeGroupId()); 084 } 085 } 086 }