Subversion Repositories bacoAlunos

Rev

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