1
2
3
4
5
6
7
8
9
10
11
12
13
14
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 }