Rev 1310 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
995 | jmachado | 1 | package pt.estgp.estgweb.domain; |
2 | |||
3 | import org.apache.log4j.Logger; |
||
4 | import pt.estgp.estgweb.services.jobs.JobHandler; |
||
5 | import pt.estgp.estgweb.services.jobs.ServiceJob; |
||
6 | |||
7 | import java.io.Serializable; |
||
8 | |||
9 | /** |
||
10 | * @author Jorge Machado |
||
11 | * @date 2/Mar/2008 |
||
12 | * @time 10:27:25 |
||
13 | * @see pt.estgp.estgweb.domain |
||
14 | */ |
||
15 | public class JobServiceTaskImpl extends JobServiceTask implements JobHandler |
||
16 | { |
||
17 | private static final 1.5.0/docs/api/java/util/logging/Logger.html">Logger logger = 1.5.0/docs/api/java/util/logging/Logger.html">Logger.getLogger(JobServiceTaskImpl.class); |
||
18 | |||
19 | public 1.5.0/docs/api/java/io/Serializable.html">Serializable getSerializable() |
||
20 | { |
||
21 | return getId(); |
||
22 | } |
||
23 | |||
24 | @1.5.0/docs/api/java/lang/Override.html">Override |
||
25 | public void runJob() |
||
26 | { |
||
27 | try { |
||
28 | ServiceJob job = (ServiceJob) 1.5.0/docs/api/java/lang/Class.html">Class.forName(getTargetService()).newInstance(); |
||
29 | job.setParameters(getServiceTaskParameters()); |
||
30 | job.setJobServiceTask(this); |
||
31 | job.runJob(); |
||
32 | } catch (1.5.0/docs/api/java/lang/InstantiationException.html">InstantiationException e) { |
||
33 | logger.error(e,e); |
||
34 | } catch (1.5.0/docs/api/java/lang/IllegalAccessException.html">IllegalAccessException e) { |
||
35 | logger.error(e,e); |
||
36 | } catch (1.5.0/docs/api/java/lang/ClassNotFoundException.html">ClassNotFoundException e) { |
||
37 | logger.error(e, e); |
||
38 | } |
||
39 | } |
||
40 | |||
41 | public static enum JobStatus |
||
42 | { |
||
43 | PENDING, |
||
44 | STARTED, |
||
45 | FINISHED, |
||
1070 | jmachado | 46 | FINISHED_ERRORS, |
47 | FINISHED_WARNINGS, |
||
995 | jmachado | 48 | FAILED, |
49 | UNKNOWN_ERROR; |
||
50 | |||
51 | public static JobStatus parse(1.5.0/docs/api/java/lang/String.html">String status) |
||
52 | { |
||
53 | if(status == null) |
||
54 | return PENDING; |
||
55 | if(status.equals(PENDING.name())) |
||
56 | return PENDING; |
||
57 | if(status.equals(STARTED.name())) |
||
58 | return STARTED; |
||
59 | if(status.equals(FINISHED.name())) |
||
60 | return FINISHED; |
||
1076 | jmachado | 61 | if(status.equals(FINISHED_ERRORS.name())) |
62 | return FINISHED_ERRORS; |
||
63 | if(status.equals(FINISHED_WARNINGS.name())) |
||
64 | return FINISHED_WARNINGS; |
||
995 | jmachado | 65 | if(status.equals(FAILED.name())) |
66 | return FAILED; |
||
67 | return UNKNOWN_ERROR; |
||
68 | } |
||
69 | } |
||
70 | |||
71 | public JobStatus getStatusEnum() |
||
72 | { |
||
73 | return JobStatus.parse(getStatus()); |
||
74 | } |
||
75 | |||
76 | public void setStatusEnum(JobStatus statusEnum) |
||
77 | { |
||
78 | if(statusEnum == null) |
||
79 | setStatus(JobStatus.UNKNOWN_ERROR.name()); |
||
80 | setStatus(statusEnum.name()); |
||
81 | } |
||
82 | |||
1076 | jmachado | 83 | public 1.5.0/docs/api/java/lang/String.html">String getServiceLastUpdateDateFormated() { |
84 | if(getServiceLastUpdateDate() == null) |
||
85 | return ""; |
||
86 | return pt.estgp.estgweb.web.utils.DatesUtils.getStringFromDateWithMinutesAndSeconds(getServiceLastUpdateDate()); |
||
87 | } |
||
88 | |||
89 | public 1.5.0/docs/api/java/lang/String.html">String getServiceFinishDateFormated() { |
||
90 | if(getServiceFinishDate() == null) |
||
91 | return ""; |
||
92 | return pt.estgp.estgweb.web.utils.DatesUtils.getStringFromDateWithMinutesAndSeconds(getServiceFinishDate()); |
||
93 | } |
||
94 | |||
95 | public 1.5.0/docs/api/java/lang/String.html">String getServiceStartDateFormated() { |
||
96 | if(getServiceStartDate() == null) |
||
97 | return ""; |
||
98 | return pt.estgp.estgweb.web.utils.DatesUtils.getStringFromDateWithMinutesAndSeconds(getServiceStartDate()); |
||
99 | } |
||
1328 | jmachado | 100 | |
101 | public JobServiceTaskParameter getParameter(1.5.0/docs/api/java/lang/String.html">String name) |
||
102 | { |
||
103 | if(getServiceTaskParameters() != null) |
||
104 | for(JobServiceTaskParameter param: getServiceTaskParameters()) |
||
105 | if(param.getName().equals(name)) |
||
106 | return param; |
||
107 | return null; |
||
108 | } |
||
109 | |||
995 | jmachado | 110 | } |