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

import java.util.HashMap;

import com.fp.bpmlib.BPMException;
import com.fp.bpmlib.task.client.TaskUtil;
import com.fp.common.helper.BeanManager;
import com.fp.dto.query.QueryRequest;
import com.fp.dto.rules.QueryRule;
import com.fp.simple.dto.Responses;

// TODO: Auto-generated Javadoc
/**
 * Class CompleteTask encargada de.
 * 
 * @author gfiallos
 */
public class CompleteTask 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 = BeanManager.convertObject(pQueryRequest.get("TID"), Long.class);
        if (tid == null) {
            throw new BPMException("BPM-0008", "NO SE HA ENCONTRADO LA TAREA {0}", tid);
        }
        TaskUtil task = new TaskUtil(tid);
        try {
            task.complete(pQueryRequest.getJournalId(), new HashMap<String, Object>(), Responses.OK, "AA");
        } finally {
            task.close();
        }
        return pQueryRequest;
    }

}
