1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.syncope.core.provisioning.java.job;
20
21 import org.apache.syncope.core.persistence.api.dao.JobStatusDAO;
22 import org.apache.syncope.core.persistence.api.entity.EntityFactory;
23 import org.apache.syncope.core.persistence.api.entity.JobStatus;
24 import org.apache.syncope.core.provisioning.api.event.JobStatusEvent;
25 import org.slf4j.Logger;
26 import org.slf4j.LoggerFactory;
27 import org.springframework.context.event.EventListener;
28 import org.springframework.scheduling.annotation.Async;
29
30 public class JobStatusUpdater {
31
32 protected static final Logger LOG = LoggerFactory.getLogger(JobStatusUpdater.class);
33
34 protected final JobStatusDAO jobStatusDAO;
35
36 protected final EntityFactory entityFactory;
37
38 public JobStatusUpdater(final JobStatusDAO jobStatusDAO, final EntityFactory entityFactory) {
39 this.jobStatusDAO = jobStatusDAO;
40 this.entityFactory = entityFactory;
41 }
42
43
44
45
46
47
48
49
50
51
52
53 @Async("jobStatusUpdaterThreadExecutor")
54 @EventListener
55 public void update(final JobStatusEvent event) {
56 if (event.getJobStatus() == null) {
57 LOG.debug("Deleting status for job '{}'", event.getJobRefDesc());
58 jobStatusDAO.delete(event.getJobRefDesc());
59 } else {
60 LOG.debug("Updating job '{}' with status '{}'", event.getJobRefDesc(), event.getJobStatus());
61 JobStatus jobStatus = entityFactory.newEntity(JobStatus.class);
62 jobStatus.setKey(event.getJobRefDesc());
63 jobStatus.setStatus(event.getJobStatus());
64 jobStatusDAO.save(jobStatus);
65 }
66 }
67 }