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.HrDataObjectMaintainableImpl;
24 import org.kuali.kpme.core.cache.CacheUtils;
25 import org.kuali.kpme.core.job.JobBo;
26 import org.kuali.kpme.core.service.HrServiceLocator;
27 import org.kuali.rice.kim.api.identity.name.EntityName;
28 import org.kuali.rice.kim.api.identity.principal.EntityNamePrincipalName;
29 import org.kuali.rice.kim.api.services.KimApiServiceLocator;
30 import org.kuali.rice.krad.maintenance.MaintenanceDocument;
31
32
33
34
35
36
37 public class JobMaintainableImpl extends HrDataObjectMaintainableImpl {
38
39
40
41
42 private static final long serialVersionUID = 1L;
43
44 @Override
45 public void saveDataObject() {
46 super.saveDataObject();
47 String cacheName = JobContract.CACHE_NAME;
48 CacheUtils.flushCache(cacheName);
49 }
50
51 @Override
52 public void processAfterCopy(MaintenanceDocument document,
53 Map<String, String[]> parameters) {
54 super.processAfterCopy(document, parameters);
55 JobBo job = (JobBo) document.getNewMaintainableObject().getDataObject();
56 job.setPrincipalId(null);
57 job.setJobNumber(null);
58 }
59
60 @Override
61 public HrBusinessObject getObjectById(String id) {
62 return JobBo.from(HrServiceLocator.getJobService().getJob(id));
63 }
64
65
66 public EntityName getName(String principalId) {
67 return KimApiServiceLocator.getIdentityService().getDefaultNamesForPrincipalId(principalId).getDefaultName();
68 }
69
70
71 public JobBo getNameAndJob(String principalId) {
72 JobBo aJob = new JobBo();
73
74 EntityNamePrincipalName p = KimApiServiceLocator.getIdentityService().getDefaultNamesForPrincipalId(principalId);
75 if (p != null && p.getDefaultName() != null) {
76 aJob.setPrincipalName(p.getDefaultName().getCompositeName());
77 }else{
78 aJob.setPrincipalName("");
79 }
80
81 JobContract maxJob = HrServiceLocator.getJobService().getMaxJob(principalId);
82 if(maxJob != null) {
83 aJob.setJobNumber(maxJob.getJobNumber() +1);
84 } else {
85 aJob.setJobNumber(0L);
86 }
87
88 return aJob;
89 }
90
91 @Override
92 public void prepareForSave() {
93 JobBo aJob = (JobBo) this.getDataObject();
94
95
96 if ((StringUtils.equals(getMaintenanceAction(), "New") || StringUtils.equals(getMaintenanceAction(), "Copy")) && aJob.getJobNumber()==null) {
97
98 JobContract maxJob = HrServiceLocator.getJobService().getMaxJob(aJob.getPrincipalId());
99
100 if(maxJob != null) {
101 aJob.setJobNumber(maxJob.getJobNumber() +1);
102 } else {
103 aJob.setJobNumber(0L);
104 }
105
106 }
107
108 super.prepareForSave();
109 }
110
111 }