/*
 * 
 */
package com.fp.bpmlib.query.inbox;

import java.util.Map;

import com.fp.bpmlib.task.client.TaskUtil;
import com.fp.dto.Response;
import com.fp.dto.query.QueryRequest;
import com.fp.dto.rules.QueryRule;

// TODO: Auto-generated Javadoc
/**
 * Class TaskDetail encargada de mostrar el detalle de una tarea.
 * 
 * @author gfiallos
 */
public class TaskDetail extends QueryRule {

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

    /**
     * Process.
     * 
     * @param pQueryRequest the query request
     * @return query request
     * @throws Exception la exception
     */
    @Override
    public QueryRequest process(QueryRequest pQueryRequest) throws Exception {
        long tid = pQueryRequest.getLong(TaskUtil.BPM_TID);
        TaskUtil tu = new TaskUtil(tid);
        try {
            pQueryRequest.getResponse().put("detail", tu.getDetail(pQueryRequest.getLanguage()));
            pQueryRequest.getResponse().put("param", tu.getDestinyData());
            pQueryRequest.getResponse().put("k", tu.getTaskInfo().getKind());
            pQueryRequest.getResponse().put("s", tu.getStatus());
        } finally {
            tu.close();
        }
        return pQueryRequest;
    }

    public static void addTaskDetail(Map<String, Object> mtask, TaskUtil taskUtil, String language) throws Exception {
        Response resp = new Response(Response.RESPONSE_OK, "");
        resp.put("detail", taskUtil.getDetail(language));
        resp.put("param", taskUtil.getDestinyData());
        resp.put("k", taskUtil.getTaskInfo().getKind());
        resp.put("s", taskUtil.getStatus());

        Map<String, Object> param = (Map<String, Object>) resp.get("param");
        param.put("TID", taskUtil.getTid());
        param.put("KIND", resp.get("k"));

        mtask.put("taskDetail", resp);
    }
}
