View Javadoc

1   /**
2    * Copyright 2004-2013 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.hr.time.earncodegroup.service;
17  
18  import java.util.HashSet;
19  import java.util.Map;
20  import java.util.Set;
21  
22  import org.kuali.hr.time.HrBusinessObject;
23  import org.kuali.hr.time.earncodegroup.EarnCodeGroup;
24  import org.kuali.hr.time.earncodegroup.EarnCodeGroupDefinition;
25  import org.kuali.hr.time.service.base.TkServiceLocator;
26  import org.kuali.hr.time.util.HrBusinessObjectMaintainableImpl;
27  import org.kuali.hr.time.util.ValidationUtils;
28  import org.kuali.rice.kns.document.MaintenanceDocument;
29  import org.kuali.rice.krad.util.GlobalVariables;
30  import org.kuali.rice.krad.util.KRADConstants;
31  
32  public class EarnCodeGroupMaintainableImpl extends HrBusinessObjectMaintainableImpl{
33  	/**
34  	 * 
35  	 */
36  	private static final long serialVersionUID = 1L;
37  	
38  	@Override
39      public void addNewLineToCollection(String collectionName) {
40          if (collectionName.equals("earnCodeGroups")) {
41          	EarnCodeGroupDefinition definition = (EarnCodeGroupDefinition)newCollectionLines.get(collectionName );
42              if ( definition != null ) {
43              	EarnCodeGroup earnGroup = (EarnCodeGroup)this.getBusinessObject();
44              	Set<String> earnCodes = new HashSet<String>();
45              	for(EarnCodeGroupDefinition earnGroupDef : earnGroup.getEarnCodeGroups()){
46              		earnCodes.add(earnGroupDef.getEarnCode());
47              	}
48              	if(earnCodes.contains(definition.getEarnCode())){
49              		GlobalVariables.getMessageMap().putErrorWithoutFullErrorPath(KRADConstants.MAINTENANCE_NEW_MAINTAINABLE +"earnCodeGroups", 
50              				"earngroup.duplicate.earncode",definition.getEarnCode());
51              		return;
52      			} 
53              	if (!ValidationUtils.validateEarnCode(definition.getEarnCode().toUpperCase(), earnGroup.getEffectiveDate())) {
54      				GlobalVariables.getMessageMap().putErrorWithoutFullErrorPath(KRADConstants.MAINTENANCE_NEW_MAINTAINABLE +"earnCodeGroups", 
55      							"error.existence", "Earncode '" + definition.getEarnCode()+ "'");
56      				return;
57      			} 
58              }
59          }
60         super.addNewLineToCollection(collectionName);
61      }
62  	
63  	@Override
64      public void processAfterEdit( MaintenanceDocument document, Map<String,String[]> parameters ) {
65  		EarnCodeGroup earnGroup = (EarnCodeGroup)this.getBusinessObject();
66  		int count = TkServiceLocator.getEarnCodeGroupService().getNewerEarnCodeGroupCount(earnGroup.getEarnCodeGroup(), earnGroup.getEffectiveDate());
67  		if(count > 0) {
68  			GlobalVariables.getMessageMap().putWarningWithoutFullErrorPath(KRADConstants.MAINTENANCE_NEW_MAINTAINABLE + "effectiveDate", 
69  					"earngroup.effectiveDate.newr.exists");
70  		}
71  	}
72  
73  	@Override
74  	public HrBusinessObject getObjectById(String id) {
75  		return TkServiceLocator.getEarnCodeGroupService().getEarnCodeGroup(id);
76  	} 
77  
78      @Override
79      public void customSaveLogic(HrBusinessObject hrObj){
80          EarnCodeGroup ecg = (EarnCodeGroup)hrObj;
81          for (EarnCodeGroupDefinition definition : ecg.getEarnCodeGroups()) {
82              definition.setHrEarnCodeGroupDefId(null);
83              definition.setHrEarnCodeGroupId(ecg.getHrEarnCodeGroupId());
84          }
85      }
86  }