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.earngroup.service;
017    
018    import org.kuali.hr.time.HrBusinessObject;
019    import org.kuali.hr.time.earngroup.EarnGroup;
020    import org.kuali.hr.time.earngroup.EarnGroupDefinition;
021    import org.kuali.hr.time.service.base.TkServiceLocator;
022    import org.kuali.hr.time.util.HrBusinessObjectMaintainableImpl;
023    import org.kuali.hr.time.util.ValidationUtils;
024    import org.kuali.rice.kns.document.MaintenanceDocument;
025    import org.kuali.rice.krad.util.GlobalVariables;
026    import org.kuali.rice.krad.util.KRADConstants;
027    
028    import java.util.HashSet;
029    import java.util.Map;
030    import java.util.Set;
031    
032    public class EarnGroupMaintainableImpl 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("earnGroups")) {
041                    EarnGroupDefinition definition = (EarnGroupDefinition)newCollectionLines.get(collectionName );
042                if ( definition != null ) {
043                    EarnGroup earnGroup = (EarnGroup)this.getBusinessObject();
044                    Set<String> earnCodes = new HashSet<String>();
045                    for(EarnGroupDefinition earnGroupDef : earnGroup.getEarnGroups()){
046                            earnCodes.add(earnGroupDef.getEarnCode());
047                    }
048                    if(earnCodes.contains(definition.getEarnCode())){
049                            GlobalVariables.getMessageMap().putErrorWithoutFullErrorPath(KRADConstants.MAINTENANCE_NEW_MAINTAINABLE +"earnGroups",
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 +"earnGroups",
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                    EarnGroup earnGroup = (EarnGroup)this.getBusinessObject();
066                    int count = TkServiceLocator.getEarnGroupService().getNewerEarnGroupCount(earnGroup.getEarnGroup(), 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.getEarnGroupService().getEarnGroup(id);
076            } 
077            
078    }