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.earngroup.service;
17  
18  import org.kuali.hr.time.HrBusinessObject;
19  import org.kuali.hr.time.earngroup.EarnGroup;
20  import org.kuali.hr.time.earngroup.EarnGroupDefinition;
21  import org.kuali.hr.time.service.base.TkServiceLocator;
22  import org.kuali.hr.time.util.HrBusinessObjectMaintainableImpl;
23  import org.kuali.hr.time.util.ValidationUtils;
24  import org.kuali.rice.kns.document.MaintenanceDocument;
25  import org.kuali.rice.krad.util.GlobalVariables;
26  import org.kuali.rice.krad.util.KRADConstants;
27  
28  import java.util.HashSet;
29  import java.util.Map;
30  import java.util.Set;
31  
32  public class EarnGroupMaintainableImpl 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("earnGroups")) {
41          	EarnGroupDefinition definition = (EarnGroupDefinition)newCollectionLines.get(collectionName );
42              if ( definition != null ) {
43              	EarnGroup earnGroup = (EarnGroup)this.getBusinessObject();
44              	Set<String> earnCodes = new HashSet<String>();
45              	for(EarnGroupDefinition earnGroupDef : earnGroup.getEarnGroups()){
46              		earnCodes.add(earnGroupDef.getEarnCode());
47              	}
48              	if(earnCodes.contains(definition.getEarnCode())){
49              		GlobalVariables.getMessageMap().putErrorWithoutFullErrorPath(KRADConstants.MAINTENANCE_NEW_MAINTAINABLE +"earnGroups",
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 +"earnGroups",
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  		EarnGroup earnGroup = (EarnGroup)this.getBusinessObject();
66  		int count = TkServiceLocator.getEarnGroupService().getNewerEarnGroupCount(earnGroup.getEarnGroup(), 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.getEarnGroupService().getEarnGroup(id);
76  	} 
77  	
78  }