1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.hr.job.service;
17
18 import java.util.Map;
19
20 import org.apache.commons.lang.StringUtils;
21 import org.kuali.hr.job.Job;
22 import org.kuali.hr.time.HrBusinessObject;
23 import org.kuali.hr.time.service.base.TkServiceLocator;
24 import org.kuali.hr.time.util.HrBusinessObjectMaintainableImpl;
25 import org.kuali.rice.kim.api.identity.Person;
26 import org.kuali.rice.kim.api.services.KimApiServiceLocator;
27 import org.kuali.rice.kns.document.MaintenanceDocument;
28
29
30
31
32
33
34 public class JobMaintainableImpl extends HrBusinessObjectMaintainableImpl {
35
36
37
38
39 private static final long serialVersionUID = 1L;
40
41
42 public void setJobNumber(Job job) {
43 Long jobNumber = new Long("0");
44 Job maxJob = TkServiceLocator.getJobService().getMaxJob(job.getPrincipalId());
45
46 if(maxJob != null) {
47
48 jobNumber = maxJob.getJobNumber() +1;
49 }
50 job.setJobNumber(jobNumber);
51 }
52
53
54
55 @SuppressWarnings("rawtypes")
56 @Override
57 public Map populateBusinessObject(Map<String, String> fieldValues,
58 MaintenanceDocument maintenanceDocument, String methodToCall) {
59 if (fieldValues.containsKey("principalId")
60 && StringUtils.isNotEmpty(fieldValues.get("principalId"))) {
61 Person p = KimApiServiceLocator.getPersonService().getPerson(
62 fieldValues.get("principalId"));
63 if (p != null) {
64 fieldValues.put("name", p.getName());
65 }else{
66 fieldValues.put("name", "");
67 }
68 }
69 if(StringUtils.equals(getMaintenanceAction(),"New")){
70 if (!fieldValues.containsKey("jobNumber") || StringUtils.isEmpty(fieldValues.get("jobNumber"))) {
71 if (fieldValues.containsKey("principalId") && StringUtils.isNotEmpty(fieldValues.get("principalId"))) {
72 Job maxJob = TkServiceLocator.getJobService().getMaxJob(fieldValues.get("principalId"));
73 if(maxJob != null) {
74 fieldValues.put("jobNumber", Long.toString(maxJob.getJobNumber() +1));
75 } else {
76 fieldValues.put("jobNumber", "0");
77 }
78 }
79 }
80 }
81
82 return super.populateBusinessObject(fieldValues, maintenanceDocument,
83 methodToCall);
84 }
85
86 @Override
87 public HrBusinessObject getObjectById(String id) {
88 return (HrBusinessObject)TkServiceLocator.getJobService().getJob(id);
89 }
90
91 @Override
92 public void customSaveLogic(HrBusinessObject hrObj) {
93 if(StringUtils.equals(getMaintenanceAction(),"New")){
94 Job job = (Job)hrObj;
95 this.setJobNumber(job);
96 }
97 }
98
99
100 }