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 org.apache.commons.lang.StringUtils;
19 import org.kuali.hr.job.Job;
20 import org.kuali.hr.time.HrBusinessObject;
21 import org.kuali.hr.time.service.base.TkServiceLocator;
22 import org.kuali.hr.time.util.HrBusinessObjectMaintainableImpl;
23 import org.kuali.rice.kim.api.identity.principal.EntityNamePrincipalName;
24 import org.kuali.rice.kim.api.services.KimApiServiceLocator;
25 import org.kuali.rice.kns.document.MaintenanceDocument;
26
27 import java.util.Map;
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 EntityNamePrincipalName p = KimApiServiceLocator.getIdentityService().getDefaultNamesForPrincipalId(fieldValues.get("principalId"));
62 if (p != null && p.getDefaultName() != null) {
63 fieldValues.put("name", p.getDefaultName().getCompositeName());
64 }else{
65 fieldValues.put("name", "");
66 }
67 }
68 if(StringUtils.equals(getMaintenanceAction(),"New")){
69 if (!fieldValues.containsKey("jobNumber") || StringUtils.isEmpty(fieldValues.get("jobNumber"))) {
70 if (fieldValues.containsKey("principalId") && StringUtils.isNotEmpty(fieldValues.get("principalId"))) {
71 Job maxJob = TkServiceLocator.getJobService().getMaxJob(fieldValues.get("principalId"));
72 if(maxJob != null) {
73 fieldValues.put("jobNumber", Long.toString(maxJob.getJobNumber() +1));
74 } else {
75 fieldValues.put("jobNumber", "0");
76 }
77 }
78 }
79 }
80
81 return super.populateBusinessObject(fieldValues, maintenanceDocument,
82 methodToCall);
83 }
84
85 @Override
86 public HrBusinessObject getObjectById(String id) {
87 return (HrBusinessObject)TkServiceLocator.getJobService().getJob(id);
88 }
89
90 @Override
91 public void customSaveLogic(HrBusinessObject hrObj) {
92 if(StringUtils.equals(getMaintenanceAction(),"New")){
93 Job job = (Job)hrObj;
94 this.setJobNumber(job);
95 }
96 }
97
98
99 }