Subversion Repositories bacoAlunos

Rev

Rev 995 | Blame | Compare with Previous | Last modification | View Log | RSS feed

package pt.estgp.estgweb.domain;

import org.apache.log4j.Logger;
import pt.estgp.estgweb.services.jobs.JobHandler;
import pt.estgp.estgweb.services.jobs.ServiceJob;

import java.io.Serializable;

/**
 * @author Jorge Machado
 * @date 2/Mar/2008
 * @time 10:27:25
 * @see pt.estgp.estgweb.domain
 */

public class JobServiceTaskImpl extends JobServiceTask implements JobHandler
{
    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);

    public 1.5.0/docs/api/java/io/Serializable.html">Serializable getSerializable()
    {
        return getId();
    }

    @1.5.0/docs/api/java/lang/Override.html">Override
    public void runJob()
    {
        try {
            ServiceJob job = (ServiceJob) 1.5.0/docs/api/java/lang/Class.html">Class.forName(getTargetService()).newInstance();
            job.setParameters(getServiceTaskParameters());
            job.setJobServiceTask(this);
            job.runJob();
        } catch (1.5.0/docs/api/java/lang/InstantiationException.html">InstantiationException e) {
            logger.error(e,e);
        } catch (1.5.0/docs/api/java/lang/IllegalAccessException.html">IllegalAccessException e) {
            logger.error(e,e);
        } catch (1.5.0/docs/api/java/lang/ClassNotFoundException.html">ClassNotFoundException e) {
            logger.error(e, e);
        }
    }

    public static enum JobStatus
    {
        PENDING,
        STARTED,
        FINISHED,
        FINISHED_ERRORS,
        FINISHED_WARNINGS,
        FAILED,
        UNKNOWN_ERROR;

        public static JobStatus parse(1.5.0/docs/api/java/lang/String.html">String status)
        {
            if(status == null)
                return PENDING;
            if(status.equals(PENDING.name()))
                return PENDING;
            if(status.equals(STARTED.name()))
                return STARTED;
            if(status.equals(FINISHED.name()))
                return FINISHED;
            if(status.equals(FAILED.name()))
                return FAILED;
            return UNKNOWN_ERROR;
        }
    }

    public JobStatus getStatusEnum()
    {
        return JobStatus.parse(getStatus());
    }

    public void setStatusEnum(JobStatus statusEnum)
    {
        if(statusEnum == null)
            setStatus(JobStatus.UNKNOWN_ERROR.name());
        setStatus(statusEnum.name());
    }

}