001/** 002 * Copyright 2004-2014 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 */ 016package org.kuali.kpme.core.paystep; 017 018import java.math.BigDecimal; 019 020import org.apache.commons.lang.StringUtils; 021import org.apache.log4j.Logger; 022import org.kuali.kpme.core.api.paystep.PayStep; 023import org.kuali.kpme.core.api.paystep.PayStepContract; 024import org.kuali.kpme.core.bo.HrBusinessObject; 025import org.kuali.kpme.core.util.HrConstants; 026import org.kuali.rice.core.api.mo.ModelObjectUtils; 027 028import com.google.common.collect.ImmutableList; 029import com.google.common.collect.ImmutableMap; 030 031public class PayStepBo extends HrBusinessObject implements Comparable, PayStepContract { 032 033 static class KeyFields { 034 private static final String PAY_STEP = "payStep"; 035 } 036 037 /* 038 * convert bo to immutable 039 * 040 * Can be used with ModelObjectUtils: 041 * 042 * org.kuali.rice.core.api.mo.ModelObjectUtils.transform(listOfPayStepBo, PayStepBo.toImmutable); 043 */ 044 public static final ModelObjectUtils.Transformer<PayStepBo, PayStep> toImmutable = 045 new ModelObjectUtils.Transformer<PayStepBo, PayStep>() { 046 public PayStep transform(PayStepBo input) { 047 return PayStepBo.to(input); 048 }; 049 }; 050 051 /* 052 * convert immutable to bo 053 * 054 * Can be used with ModelObjectUtils: 055 * 056 * org.kuali.rice.core.api.mo.ModelObjectUtils.transform(listOfPayStep, PayStepBo.toBo); 057 */ 058 public static final ModelObjectUtils.Transformer<PayStep, PayStepBo> toBo = 059 new ModelObjectUtils.Transformer<PayStep, PayStepBo>() { 060 public PayStepBo transform(PayStep input) { 061 return PayStepBo.from(input); 062 }; 063 }; 064 065 private static final Logger LOG = Logger.getLogger(PayStepBo.class); 066 //KPME-2273/1965 Primary Business Keys List. 067 public static final ImmutableList<String> BUSINESS_KEYS = new ImmutableList.Builder<String>() 068 .add(KeyFields.PAY_STEP) 069 .build(); 070 071 private static final long serialVersionUID = 1L; 072 073 private String pmPayStepId; 074 private String payStep; 075 private String salaryGroup; 076 private String payGrade; 077 private int stepNumber; 078 private BigDecimal compRate; 079 private int serviceAmount; 080 private String serviceUnit; 081 082 @Override 083 public ImmutableMap<String, Object> getBusinessKeyValuesMap() { 084 return new ImmutableMap.Builder<String, Object>() 085 .put(KeyFields.PAY_STEP, this.getPayStep()) 086 .build(); 087 } 088 089 @Override 090 public boolean isActive() { 091 return super.isActive(); 092 } 093 094 @Override 095 public void setActive(boolean active) { 096 super.setActive(active); 097 } 098 099 @Override 100 public String getObjectId() { 101 return super.getObjectId(); 102 } 103 104 @Override 105 public Long getVersionNumber() { 106 return super.getVersionNumber(); 107 } 108 109 @Override 110 public int compareTo(Object o) { 111 if(o instanceof PayStepBo) { 112 PayStepBo s = (PayStepBo) o; 113 if(StringUtils.equals(s.salaryGroup,salaryGroup) 114 && StringUtils.equals(s.payGrade,payGrade)) { 115 116 Integer otherServiceTime = 0; 117 if(StringUtils.equals(s.serviceUnit,HrConstants.SERVICE_TIME_YEAR)) 118 otherServiceTime = s.getServiceAmount() * 12; 119 else 120 otherServiceTime = s.getServiceAmount(); 121 122 Integer thisServiceTime = 0; 123 if(StringUtils.equals(serviceUnit, HrConstants.SERVICE_TIME_YEAR)) 124 thisServiceTime = serviceAmount * 12; 125 else 126 thisServiceTime = serviceAmount; 127 128 return otherServiceTime.compareTo(thisServiceTime); 129 } 130 else 131 // throw new IllegalArgumentException("pay step must be within the same salary group and pay grade"); 132 LOG.error("pay step must be within the same salary group and pay grade"); 133 } 134 135 return 0; 136 } 137 138 public String getPayStep() { 139 return payStep; 140 } 141 142 public void setPayStep(String payStep) { 143 this.payStep = payStep; 144 } 145 146 public String getSalaryGroup() { 147 return salaryGroup; 148 } 149 150 public void setSalaryGroup(String salaryGroup) { 151 this.salaryGroup = salaryGroup; 152 } 153 154 public String getPayGrade() { 155 return payGrade; 156 } 157 158 public void setPayGrade(String payGrade) { 159 this.payGrade = payGrade; 160 } 161 162 public int getStepNumber() { 163 return stepNumber; 164 } 165 166 public void setStepNumber(int stepNumber) { 167 this.stepNumber = stepNumber; 168 } 169 170 public BigDecimal getCompRate() { 171 return compRate; 172 } 173 174 public void setCompRate(BigDecimal compRate) { 175 this.compRate = compRate; 176 } 177 178 public int getServiceAmount() { 179 return serviceAmount; 180 } 181 182 public void setServiceAmount(int serviceInterval) { 183 this.serviceAmount = serviceInterval; 184 } 185 186 public String getServiceUnit() { 187 return serviceUnit; 188 } 189 190 public void setServiceUnit(String serviceUnit) { 191 this.serviceUnit = serviceUnit; 192 } 193 194 @Override 195 public String getId() { 196 return pmPayStepId; 197 } 198 199 @Override 200 public void setId(String id) { 201 pmPayStepId = id; 202 } 203 204 @Override 205 protected String getUniqueKey() { 206 return getPmPayStepId(); 207 } 208 209 public String getPmPayStepId() { 210 return pmPayStepId; 211 } 212 213 public void setPmPayStepId(String pmPayStepId) { 214 this.pmPayStepId = pmPayStepId; 215 } 216 217 public static PayStepBo from(PayStep im) { 218 if (im == null) { 219 return null; 220 } 221 PayStepBo ps = new PayStepBo(); 222 ps.setPmPayStepId(im.getPmPayStepId()); 223 ps.setPayStep(im.getPayStep()); 224 ps.setSalaryGroup(im.getSalaryGroup()); 225 ps.setPayGrade(im.getPayGrade()); 226 ps.setStepNumber(im.getStepNumber()); 227 ps.setCompRate(im.getCompRate()); 228 ps.setServiceAmount(im.getServiceAmount()); 229 ps.setServiceUnit(im.getServiceUnit()); 230 231 // finally copy over the common fields into ps from im 232 copyCommonFields(ps, im); 233 234 return ps; 235 } 236 237 public static PayStep to(PayStepBo bo) { 238 if (bo == null) { 239 return null; 240 } 241 return PayStep.Builder.create(bo).build(); 242 } 243}