View Javadoc
1   /**
2    * Copyright 2004-2014 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.kpme.pm.position;
17  
18  import java.math.BigDecimal;
19  import java.util.ArrayList;
20  import java.util.Date;
21  import java.util.LinkedList;
22  import java.util.List;
23  
24  import org.apache.commons.collections.CollectionUtils;
25  import org.apache.commons.lang.StringUtils;
26  import org.joda.time.DateTime;
27  import org.kuali.kpme.core.api.position.PositionBaseContract;
28  import org.kuali.kpme.core.departmentaffiliation.DepartmentAffiliationBo;
29  import org.kuali.kpme.core.groupkey.HrGroupKeyBo;
30  import org.kuali.kpme.core.position.PositionBaseBo;
31  import org.kuali.kpme.pm.api.classification.ClassificationContract;
32  import org.kuali.kpme.pm.api.classification.duty.ClassificationDutyContract;
33  import org.kuali.kpme.pm.api.classification.flag.ClassificationFlagContract;
34  import org.kuali.kpme.pm.api.position.Position;
35  import org.kuali.kpme.pm.api.position.PositionContract;
36  import org.kuali.kpme.pm.api.position.funding.PositionFunding;
37  import org.kuali.kpme.pm.classification.qual.ClassificationQualificationBo;
38  import org.kuali.kpme.pm.position.funding.PositionFundingBo;
39  import org.kuali.kpme.pm.positiondepartment.PositionDepartmentBo;
40  import org.kuali.kpme.pm.positionresponsibility.PositionResponsibilityBo;
41  import org.kuali.kpme.pm.service.base.PmServiceLocator;
42  import org.kuali.rice.core.api.config.property.ConfigContext;
43  import org.kuali.rice.core.api.mo.ModelObjectUtils;
44  import org.kuali.rice.core.api.util.Truth;
45  
46  import com.google.common.collect.ImmutableList;
47  
48  public class PositionBo extends PositionBaseBo implements PositionContract {
49  	private static final long serialVersionUID = 1L;
50  	
51      public static final ImmutableList<String> CACHE_FLUSH = new ImmutableList.Builder<String>()
52              .add(PositionBaseContract.CACHE_NAME)
53              .add(PositionContract.CACHE_NAME)
54              .build();
55  
56      public static final ImmutableList<String> BUSINESS_KEYS = new ImmutableList.Builder<String>()
57              .add(KeyFields.POSITION_NUMBER)
58              .build();
59  
60  	private List<PositionQualificationBo> qualificationList = new LinkedList<PositionQualificationBo>();
61      private List<PositionDutyBo> dutyList = new LinkedList<PositionDutyBo>();
62      private List<PstnFlagBo> flagList = new LinkedList<PstnFlagBo>();
63      private List<PositionResponsibilityBo> positionResponsibilityList = new LinkedList<PositionResponsibilityBo>();
64      private List<PositionFundingBo> fundingList = new ArrayList<PositionFundingBo>();
65      private List<PositionDepartmentBo> departmentList = new ArrayList<PositionDepartmentBo>();
66  
67      private String salaryGroup;
68      private String pmPositionClassId;
69      private transient String positionClass;
70      private String classificationTitle;
71  
72      private BigDecimal percentTime;
73      private int workMonths;
74      private String benefitsEligible;
75      private String leaveEligible;
76      private String leavePlan;
77      private String positionReportGroup;
78      private String positionType;
79      private String poolEligible;
80      private int maxPoolHeadCount;
81      private String tenureEligible;
82       
83      private String process;
84      private String positionStatus;
85      private String primaryDepartment;
86      private String appointmentType;
87      private String reportsToPositionId;
88      private String reportsToPrincipalId;
89      private Date expectedEndDate;
90      private String renewEligible;
91      private String temporary;
92      private String contract;
93      private String contractType;
94      private String payGrade;
95      private String payStep;
96      
97      private String category;		// used to determine what fields should show when editing an existing maint doc
98      
99      private String reportsToWorkingTitle; // KPME-3269
100     
101     private List<ClassificationQualificationBo> requiredQualList = new ArrayList<ClassificationQualificationBo>(); 	// read only required qualifications that comes from assiciated Classification
102     /*private transient boolean displayQualifications;
103     private transient boolean displayDuties;
104     private transient boolean displayFlags;
105     private transient boolean displayResponsibility;
106     private transient boolean displayFunding;
107     private transient boolean displayAdHocRecipients;*/
108 
109     @Override
110     public List<PositionDutyBo> getDutyList() {
111     	if(CollectionUtils.isEmpty(dutyList) && StringUtils.isNotEmpty(this.getPmPositionClassId())) {
112     		List<? extends ClassificationDutyContract> aList = PmServiceLocator.getClassificationDutyService().getDutyListForClassification(this.getPmPositionClassId());
113     		if(CollectionUtils.isNotEmpty(aList)) {
114     			List<PositionDutyBo> pDutyList = new ArrayList<PositionDutyBo>();
115     			// copy basic information from classificaton duty list
116     			for(ClassificationDutyContract aDuty : aList) {
117     				PositionDutyBo pDuty = new PositionDutyBo();
118     				pDuty.setName(aDuty.getName());
119     				pDuty.setDescription(aDuty.getDescription());
120     				pDuty.setPercentage(aDuty.getPercentage());
121     				pDuty.setPmDutyId(null);
122     				pDuty.setHrPositionId(this.getHrPositionId());
123     				pDutyList.add(pDuty);
124     			}
125     			this.setDutyList(pDutyList);
126     		}
127     	}
128 		return dutyList;
129 	}
130 
131     @Override
132 	public List<PositionResponsibilityBo> getPositionResponsibilityList() {
133 		return positionResponsibilityList;
134 	}
135 
136 	public void setPositionResponsibilityList(
137 			List<PositionResponsibilityBo> positionResponsibilityList) {
138 		this.positionResponsibilityList = positionResponsibilityList;
139 	}
140 	public void setDutyList(List<PositionDutyBo> dutyList) {
141 		this.dutyList = dutyList;
142 	}
143 
144     @Override
145 	public List<PositionQualificationBo> getQualificationList() {
146 		return qualificationList;
147 	}
148 
149 	public void setQualificationList(List<PositionQualificationBo> qualificationList) {
150 		this.qualificationList = qualificationList;
151 	}
152 
153     @Override
154 	public List<PstnFlagBo> getFlagList() {
155 		if(CollectionUtils.isEmpty(flagList) && StringUtils.isNotEmpty(this.getPmPositionClassId())) {
156     		List<? extends ClassificationFlagContract> aList = PmServiceLocator.getClassificationFlagService().getFlagListForClassification(this.getPmPositionClassId());
157     		if(CollectionUtils.isNotEmpty(aList)) {
158     			List<PstnFlagBo> pFlagList = new ArrayList<PstnFlagBo>();
159     			// copy basic information from classificaton flag list
160     			for(ClassificationFlagContract aFlag : aList) {
161     				PstnFlagBo pFlag = new PstnFlagBo();
162     				pFlag.setCategory(aFlag.getCategory());
163     				pFlag.setNames(aFlag.getNames());
164     				pFlag.setPmFlagId(null);
165     				pFlag.setHrPositionId(this.getHrPositionId());
166     				pFlagList.add(pFlag);
167     			}
168     			this.setFlagList(pFlagList);
169     		}
170 		}
171 		return flagList;
172 	}
173 
174 	public void setFlagList(List<PstnFlagBo> flagList) {
175 		this.flagList = flagList;
176 	}
177 
178     @Override
179 	public String getPmPositionClassId() {
180 		return pmPositionClassId;
181 	}
182 
183 	public void setPmPositionClassId(String id) {
184 		this.pmPositionClassId = id;
185 	}
186 
187     @Override
188     public String getPositionClass() {
189         if (StringUtils.isBlank(positionClass) && StringUtils.isNotBlank(pmPositionClassId)) {
190             ClassificationContract classification = PmServiceLocator.getClassificationService().getClassificationById(this.pmPositionClassId);
191             positionClass = classification != null ? classification.getPositionClass() : null;
192         }
193 
194         return positionClass;
195     }
196 
197     public void setPositionClass(String positionClass) {
198         this.positionClass = positionClass;
199     }
200 
201     @SuppressWarnings("unchecked")
202     @Override
203 	public List<ClassificationQualificationBo> getRequiredQualList() {
204 		if(StringUtils.isNotEmpty(this.getPmPositionClassId())) {
205 			// when Position Classification Id is changed, change the requiredQualList with it
206 			if(CollectionUtils.isEmpty(requiredQualList) ||
207 					(CollectionUtils.isNotEmpty(requiredQualList) 
208 							&& !requiredQualList.get(0).getPmPositionClassId().equals(this.getPmPositionClassId()))) {
209 				List<ClassificationQualificationBo> aList = (List<ClassificationQualificationBo>)PmServiceLocator.getClassificationQualService()
210 						.getQualListForClassification(this.getPmPositionClassId());
211 				if(CollectionUtils.isNotEmpty(aList))
212 					this.setRequiredQualList(aList);
213 			} else {
214 				
215 			}
216 		}
217  		return requiredQualList;
218 	}
219 	
220 	public void setRequiredQualList(List<ClassificationQualificationBo> aList) {
221 			requiredQualList = aList;
222 	}
223 
224     @Override
225 	public List<PositionFundingBo> getFundingList() {
226 		return fundingList;
227 	}
228 
229 	public void setFundingList(List<PositionFundingBo> fundingList) {
230 		this.fundingList = fundingList;
231 	}
232 
233     @Override
234 	public String getCategory() {
235 		return category;
236 	}
237 
238 	public void setCategory(String category) {
239 		this.category = category;
240 	}
241 
242     @Override
243     public String getSalaryGroup() {
244         return salaryGroup;
245     }
246 
247     public void setSalaryGroup(String salaryGroup) {
248         this.salaryGroup = salaryGroup;
249     }
250 
251     @Override
252     public String getClassificationTitle() {
253         return classificationTitle;
254     }
255 
256     public void setClassificationTitle(String classificationTitle) {
257         this.classificationTitle = classificationTitle;
258     }
259 
260 
261     @Override
262     public BigDecimal getPercentTime() {
263         return percentTime;
264     }
265 
266     public void setPercentTime(BigDecimal percentTime) {
267         this.percentTime = percentTime;
268     }
269 
270     @Override
271     public String getBenefitsEligible() {
272         return benefitsEligible;
273     }
274 
275     public void setBenefitsEligible(String benefitsEligible) {
276         this.benefitsEligible = benefitsEligible;
277     }
278 
279     @Override
280     public String getLeaveEligible() {
281         return leaveEligible;
282     }
283 
284     public void setLeaveEligible(String leaveEligible) {
285         this.leaveEligible = leaveEligible;
286     }
287 
288     @Override
289     public String getLeavePlan() {
290         return leavePlan;
291     }
292 
293     public void setLeavePlan(String leavePlan) {
294         this.leavePlan = leavePlan;
295     }
296 
297     @Override
298     public String getPositionReportGroup() {
299         return positionReportGroup;
300     }
301 
302     public void setPositionReportGroup(String positionReportGroup) {
303         this.positionReportGroup = positionReportGroup;
304     }
305 
306     @Override
307     public String getPositionType() {
308         return positionType;
309     }
310 
311     public void setPositionType(String positionType) {
312         this.positionType = positionType;
313     }
314 
315     @Override
316     public String getPoolEligible() {
317         return poolEligible;
318     }
319 
320     public void setPoolEligible(String poolEligible) {
321         this.poolEligible = poolEligible;
322     }
323 
324     @Override
325     public int getMaxPoolHeadCount() {
326         return maxPoolHeadCount;
327     }
328 
329     public void setMaxPoolHeadCount(int maxPoolHeadCount) {
330         this.maxPoolHeadCount = maxPoolHeadCount;
331     }
332 
333     @Override
334     public String getTenureEligible() {
335         return tenureEligible;
336     }
337 
338     public void setTenureEligible(String tenureEligible) {
339         this.tenureEligible = tenureEligible;
340     }
341 
342     @Override
343     public int getWorkMonths() {
344         return workMonths;
345     }
346 
347     public void setWorkMonths(int workMonths) {
348         this.workMonths = workMonths;
349     }
350 
351     @Override
352     public List<PositionDepartmentBo> getDepartmentList() {
353         return departmentList;
354     }
355 
356     public void setDepartmentList(List<PositionDepartmentBo> departmentList) {
357         this.departmentList = departmentList;
358     }
359 
360     @Override
361 	public String getProcess() {
362 		return process;
363 	}
364 
365 	public void setProcess(String process) {
366 		this.process = process;
367 	}
368 
369     @Override
370 	public String getPositionStatus() {
371 		return positionStatus;
372 	}
373 
374 	public void setPositionStatus(String positionStatus) {
375 		this.positionStatus = positionStatus;
376 	}
377 
378     @Override
379 	public String getPrimaryDepartment() {
380 
381 		if (this.primaryDepartment == null && this.departmentList != null && this.departmentList.size() > 0) {
382 			for (PositionDepartmentBo department: this.departmentList) {
383 				DepartmentAffiliationBo pda = department.getDeptAfflObj();
384 				if (pda.isPrimaryIndicator()) {
385 					primaryDepartment = department.getDepartment();
386 					break;
387 				} 
388 			}
389 		}
390 		
391 		return primaryDepartment;
392 	}
393 
394     public void setPrimaryDepartment (String primaryDepartment) {
395         this.primaryDepartment = primaryDepartment;
396     }
397 
398     @Override
399 	public String getReportsToPositionId() {
400 		return reportsToPositionId;
401 	}
402 
403 	public void setReportsToPositionId(String reportsToPositionId) {
404 		this.reportsToPositionId = reportsToPositionId;
405 	}
406 
407     @Override
408 	public String getReportsToPrincipalId() {
409 		return reportsToPrincipalId;
410 	}
411 
412 	public void setReportsToPrincipalId(String reportsToPrincipalId) {
413 		this.reportsToPrincipalId = reportsToPrincipalId;
414 	}
415 
416 	public Date getExpectedEndDate() {
417 		return expectedEndDate;
418 	}
419 
420 	public void setExpectedEndDate(Date expectedEndDate) {
421 		this.expectedEndDate = expectedEndDate;
422 	}
423 
424     @Override
425 	public String getRenewEligible() {
426 		return renewEligible;
427 	}
428 
429 	public void setRenewEligible(String renewEligible) {
430 		this.renewEligible = renewEligible;
431 	}
432 
433     @Override
434 	public String getTemporary() {
435 		return temporary;
436 	}
437 
438 	public void setTemporary(String temporary) {
439 		this.temporary = temporary;
440 	}
441 
442     @Override
443 	public String getContract() {
444 		return contract;
445 	}
446 
447 	public void setContract(String contract) {
448 		this.contract = contract;
449 	}
450 
451     @Override
452 	public String getContractType() {
453 		return contractType;
454 	}
455 
456 	public void setContractType(String contractType) {
457 		this.contractType = contractType;
458 	}
459 
460     @Override
461 	public String getAppointmentType() {
462 		return appointmentType;
463 	}
464 
465 	public void setAppointmentType(String appointmentType) {
466 		this.appointmentType = appointmentType;
467 	}
468 
469     @Override
470 	public String getPayGrade() {
471 		return payGrade;
472 	}
473 
474 	public void setPayGrade(String payGrade) {
475 		this.payGrade = payGrade;
476 	}
477 
478     @Override
479 	public String getPayStep() {
480 		return payStep;
481 	}
482 
483 	public void setPayStep(String payStep) {
484 		this.payStep = payStep;
485 	}
486 
487     @Override
488 	public String getReportsToWorkingTitle() {
489 		return reportsToWorkingTitle;
490 	}
491 
492 	public void setReportsToWorkingTitle(String reportsToWorkingTitle) {
493 		this.reportsToWorkingTitle = reportsToWorkingTitle;
494 	}
495 
496 	public boolean isDisplayQualifications() {
497         String status = ConfigContext.getCurrentContextConfig().getProperty("kpme.pm.position.display.qualifications");
498         return Truth.strToBooleanIgnoreCase(status, Boolean.FALSE);
499 	}
500 
501 
502 	public boolean isDisplayDuties() {
503         String status = ConfigContext.getCurrentContextConfig().getProperty("kpme.pm.position.display.duties");
504         return Truth.strToBooleanIgnoreCase(status, Boolean.FALSE);
505 	}
506 
507 	public boolean isDisplayFlags() {
508         String status = ConfigContext.getCurrentContextConfig().getProperty("kpme.pm.position.display.flags");
509         return Truth.strToBooleanIgnoreCase(status, Boolean.FALSE);
510 	}
511 
512 
513 	public boolean isDisplayResponsibility() {
514         String status = ConfigContext.getCurrentContextConfig().getProperty("kpme.pm.position.display.responsibility");
515         return Truth.strToBooleanIgnoreCase(status, Boolean.FALSE);
516 	}
517 
518 	public boolean isDisplayFunding() {
519         String status = ConfigContext.getCurrentContextConfig().getProperty("kpme.pm.position.display.funding");
520         return Truth.strToBooleanIgnoreCase(status, Boolean.FALSE);
521 	}
522 
523 
524 	public boolean isDisplayAdHocRecipients() {
525         String status = ConfigContext.getCurrentContextConfig().getProperty("kpme.pm.position.display.adhocrecipients");
526         return Truth.strToBooleanIgnoreCase(status, Boolean.FALSE);
527 	}
528 
529 	@Override
530 	public DateTime getExpectedEndDateTime() {
531 		DateTime retVal = null;
532 		if(getExpectedEndDate() != null) {
533 			retVal = new DateTime(getExpectedEndDate());
534 		}
535 		return retVal;
536 	}
537 	
538 	public static PositionBo from(Position im) {
539 				if (im == null) {
540 					return null;
541 				}
542 				PositionBo retVal = new PositionBo();
543 		
544 				retVal.setHrPositionId(im.getHrPositionId());
545 				retVal.setPositionNumber(im.getPositionNumber());
546 				retVal.setGroupKey(HrGroupKeyBo.from(im.getGroupKey()));
547 				retVal.setGroupKeyCode(im.getGroupKeyCode());
548 				copyCommonFields(retVal, im);
549 				
550 				retVal.setBenefitsEligible(im.getBenefitsEligible());
551 				retVal.setPercentTime(im.getPercentTime());
552 				retVal.setClassificationTitle(im.getClassificationTitle());
553 				retVal.setSalaryGroup(im.getSalaryGroup());
554 				
555 				List<PositionQualificationBo> qualifications= ModelObjectUtils.transform(im.getQualificationList(), PositionQualificationBo.toBo);
556 				PositionQualificationBo.setOwnerOfDerivedCollection(retVal, qualifications);
557 				retVal.setQualificationList(qualifications);
558 				
559 				retVal.setReportsToPrincipalId(im.getReportsToPrincipalId());
560 				retVal.setLeaveEligible(im.getLeaveEligible());
561 				retVal.setPositionReportGroup(im.getPositionReportGroup());
562 				retVal.setPositionType(im.getPositionType());
563 				retVal.setPoolEligible(im.getPoolEligible());
564 				retVal.setMaxPoolHeadCount(im.getMaxPoolHeadCount());
565 				retVal.setTenureEligible(im.getTenureEligible());
566                 retVal.setPositionClass(im.getPositionClass());
567                 retVal.setAppointmentType(im.getAppointmentType());
568                 retVal.setReportsToWorkingTitle(im.getReportsToWorkingTitle());
569                 retVal.setPrimaryDepartment(im.getPrimaryDepartment());
570                 retVal.setProcess(im.getProcess());
571 
572 				List<PositionDepartmentBo> departments = ModelObjectUtils.transform(im.getDepartmentList(), PositionDepartmentBo.toBo);
573 				PositionDepartmentBo.setOwnerOfDerivedCollection(retVal, departments);
574 				retVal.setDepartmentList(departments);
575 				
576 				retVal.setPositionStatus(im.getPositionStatus());
577 				retVal.setContractType(im.getContractType());
578 				retVal.setRenewEligible(im.getRenewEligible());
579 				retVal.setReportsToPositionId(im.getReportsToPositionId());
580 				
581 				retVal.setRequiredQualList(ModelObjectUtils.transform(im.getRequiredQualList(), ClassificationQualificationBo.toBo));
582 				
583 				List<PositionResponsibilityBo> responsibilities = ModelObjectUtils.transform(im.getPositionResponsibilityList(),PositionResponsibilityBo.toBo);
584 				PositionResponsibilityBo.setOwnerOfDerivedCollection(retVal, responsibilities);
585 				retVal.setPositionResponsibilityList(responsibilities);
586 				
587 				retVal.setPmPositionClassId(im.getPmPositionClassId());
588 				
589 				List<PositionFundingBo> fundings = ModelObjectUtils.transform(im.getFundingList(),PositionFundingBo.toBo);
590 				PositionFundingBo.setOwnerOfDerivedCollection(retVal, fundings);
591 				retVal.setFundingList(fundings);
592 				
593 				retVal.setWorkMonths(im.getWorkMonths());
594 				retVal.setTemporary(im.getTemporary());
595 				retVal.setCategory(im.getCategory());
596 				retVal.setLeavePlan(im.getLeavePlan());
597 				
598 				List<PstnFlagBo> flags = ModelObjectUtils.transform(im.getFlagList(), PstnFlagBo.toBo);
599 				PstnFlagBo.setOwnerOfDerivedCollection(retVal, flags);
600 				retVal.setFlagList(flags);
601 				
602 				retVal.setPayStep(im.getPayStep());
603 				retVal.setPayGrade(im.getPayGrade());
604 				
605 				List<PositionDutyBo> duties = ModelObjectUtils.transform(im.getDutyList(), PositionDutyBo.toBo);
606 				PositionDutyBo.setOwnerOfDerivedCollection(retVal, duties);
607 				retVal.setDutyList(duties);
608 				
609 				retVal.setContract(im.getContract());
610 				retVal.setDescription(im.getDescription());
611 				retVal.setId(im.getId());
612 				retVal.setEffectiveLocalDate(im.getEffectiveLocalDate());
613 				return retVal;
614 			}
615 		
616 			public static Position to(PositionBo bo) {
617 				if (bo == null) {
618 					return null;
619 				}
620 				return Position.Builder.create(bo).build();
621 			}
622 		
623 			public static final ModelObjectUtils.Transformer<PositionBo, Position> toImmutable = new ModelObjectUtils.Transformer<PositionBo, Position>() {
624 				public Position transform(PositionBo input) {
625 					return PositionBo.to(input);
626 				};
627 			};
628 		
629 			public static final ModelObjectUtils.Transformer<Position, PositionBo> toBo = new ModelObjectUtils.Transformer<Position, PositionBo>() {
630 				public PositionBo transform(Position input) {
631 					return PositionBo.from(input);
632 				};
633 			};
634 	
635 }