/*
 * 
 */
package com.fp.bpmlib.transaction.task;

import com.fp.base.persistence.util.job.ServiceManager;
import com.fp.dto.rules.TransactionRule;
import com.fp.dto.save.SaveRequest;

// TODO: Auto-generated Javadoc
/**
 * Clase ServerManager encargada de iniciar o detener el Servidor de Tareas.
 * 
 * @author gfiallos
 */
public class ServerManager extends TransactionRule {

    /** serialVersionUID. */
    private static final long serialVersionUID = 1L;

    /**
     * Normal process.
     * 
     * @param pSaveRequest the save request
     * @return save request
     * @throws Exception la exception
     */
    @Override
    public SaveRequest normalProcess(SaveRequest pSaveRequest) throws Exception {
        String status = (String) pSaveRequest.get("status");
        String code = (String) pSaveRequest.get("code");
        ServiceManager sm = new ServiceManager();
        if ("I".equals(status)) {
            sm.startService(code);
        } else {
            sm.stopService(code);
        }
        pSaveRequest.getResponse().put("TSStatus", sm.isRunning(code));
        return pSaveRequest;
    }

    /**
     * Reverse process.
     * 
     * @param pSaveRequest the save request
     * @return save request
     * @throws Exception la exception
     */
    @Override
    public SaveRequest reverseProcess(SaveRequest pSaveRequest) throws Exception {
        return pSaveRequest;
    }

}
