1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.kpme.core.job.web;
17
18 import java.util.Map;
19
20 import org.apache.commons.lang.StringUtils;
21 import org.kuali.kpme.core.api.job.JobContract;
22 import org.kuali.kpme.core.bo.HrBusinessObject;
23 import org.kuali.kpme.core.bo.HrBusinessObjectMaintainableImpl;
24 import org.kuali.kpme.core.job.JobBo;
25 import org.kuali.kpme.core.service.HrServiceLocator;
26 import org.kuali.rice.kim.api.identity.name.EntityName;
27 import org.kuali.rice.kim.api.identity.principal.EntityNamePrincipalName;
28 import org.kuali.rice.kim.api.services.KimApiServiceLocator;
29 import org.kuali.rice.krad.maintenance.MaintenanceDocument;
30
31
32
33
34
35
36 public class JobMaintainableImpl extends HrBusinessObjectMaintainableImpl {
37
38
39
40
41 private static final long serialVersionUID = 1L;
42
43 @Override
44 public void processAfterCopy(MaintenanceDocument document,
45 Map<String, String[]> parameters) {
46 super.processAfterCopy(document, parameters);
47 JobBo job = (JobBo) document.getNewMaintainableObject().getDataObject();
48 job.setPrincipalId(null);
49 job.setJobNumber(null);
50 }
51
52 @Override
53 public HrBusinessObject getObjectById(String id) {
54 return JobBo.from(HrServiceLocator.getJobService().getJob(id));
55 }
56
57
58 public EntityName getName(String principalId) {
59 return KimApiServiceLocator.getIdentityService().getDefaultNamesForPrincipalId(principalId).getDefaultName();
60 }
61
62
63 public JobBo getNameAndJob(String principalId) {
64 JobBo aJob = new JobBo();
65
66 EntityNamePrincipalName p = KimApiServiceLocator.getIdentityService().getDefaultNamesForPrincipalId(principalId);
67 if (p != null && p.getDefaultName() != null) {
68 aJob.setPrincipalName(p.getDefaultName().getCompositeName());
69 }else{
70 aJob.setPrincipalName("");
71 }
72
73 JobContract maxJob = HrServiceLocator.getJobService().getMaxJob(principalId);
74 if(maxJob != null) {
75 aJob.setJobNumber(maxJob.getJobNumber() +1);
76 } else {
77 aJob.setJobNumber(0L);
78 }
79
80 return aJob;
81 }
82
83 @Override
84 public void prepareForSave() {
85 JobBo aJob = (JobBo) this.getDataObject();
86
87
88 if ((StringUtils.equals(getMaintenanceAction(), "New") || StringUtils.equals(getMaintenanceAction(), "Copy")) && aJob.getJobNumber()==null) {
89
90 JobContract maxJob = HrServiceLocator.getJobService().getMaxJob(aJob.getPrincipalId());
91
92 if(maxJob != null) {
93 aJob.setJobNumber(maxJob.getJobNumber() +1);
94 } else {
95 aJob.setJobNumber(0L);
96 }
97
98 }
99
100 super.prepareForSave();
101 }
102
103 }