/** See the file "LICENSE" for the full license governing this code. */
package au.org.ands.vocabs.toolkit.restlet;

import java.lang.invoke.MethodHandles;
import java.util.HashMap;

import javax.servlet.ServletContext;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import au.org.ands.vocabs.toolkit.tasks.TaskInfo;
import au.org.ands.vocabs.toolkit.tasks.TaskRunner;
import au.org.ands.vocabs.toolkit.tasks.TaskStatus;
import au.org.ands.vocabs.toolkit.utils.ToolkitFileUtils;

/** Restlets for running a Toolkit supported tasks. */
@Path("runTask")
public class RunTask {

    /** Logger for this class. */
    private Logger logger = LoggerFactory.getLogger(
            MethodHandles.lookup().lookupClass());

    /** Injected servlet context. */
    @Context
    private ServletContext context;

    /** Get the list of PoolParty projects.
     * @param taskId The task id.
     * @return The list of PoolParty projects, in JSON format,
     * as returned by PoolParty. */
    @Path("{taskId}")
    @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
    @GET
    public final HashMap<String, String> runTask(
            @PathParam("taskId") final int taskId) {
        logger.debug("called runTask, taskid = " + taskId);
        // Initialize these to null/empty values. On success of
        // the try, taskInfo will be non-null, and throwableText
        // will remain empty. On failure, taskInfo will remain null,
        // and throwableText will be non-empty.
        TaskInfo taskInfo = null;
        String throwableText = "";
        try {
            taskInfo = ToolkitFileUtils.getTaskInfo(taskId);
        } catch (Throwable e) {
            throwableText = "; caught exception: " + e.getMessage();
            logger.error("Caught an exception getting TaskInfo for task id: "
                    + taskId, e);
        }
        if (taskInfo == null) {
            // Either an exception getting the data from the database,
            // or an error generated by the validity checks in getTaskInfo().
            HashMap<String, String> response =
                    new HashMap<String, String>();
            response.put("status", TaskStatus.ERROR);
            response.put("runTask", "Unable to get all task details for"
                    + " task with id " + taskId + throwableText);
            return response;
        } else {
            TaskRunner runner = new TaskRunner(taskInfo);
            runner.runTask();
            return runner.getResults();
        }
    }

}

@@ -686,18 +686,16 @@
 running 
-a 
 Toolkit 
@@ -993,42 +993,18 @@
 /** 
-Get the list of PoolParty projects
+Run a task
 .%0A  
@@ -1038,104 +1038,149 @@
  id.
-%0A     * @return The list of PoolParty projects, in JSON
+ The id of the task%0A     *      in the task database table.%0A     * @return The result of running the task, either in JSON or XML
  format
-,
+.
 %0A    
- * as returned by PoolParty.
  */%0A

Fix Javadoc comments for RunTask