All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.hypertrack.factory.TaskFactory Maven / Gradle / Ivy

There is a newer version: 1.0.1
Show newest version
package io.hypertrack.factory;

import io.hypertrack.model.Task;
import io.hypertrack.net.HyperTrackClient;
import io.hypertrack.net.HyperTrackException;

import java.util.Map;

/**
 * Factory class for Task model.
 */
public class TaskFactory extends HyperTrackFactory {
    private static String modelUrl = "tasks/";

    public TaskFactory(HyperTrackClient client) {
        super(client);
    }

    @Override
    protected Task makeNew(Map params) {
        return new Task(params);
    }

    @Override
    protected String getModelUrl() {
        return modelUrl;
    }

    /**
     * Returns tracking url of the task.
     *
     * @param   task    task object
     * @return          tracking url of the task
     */
    public String getTrackingUrl(Task task) {
        String taskId = task.getId();
        return this.getTrackingUrl(taskId);
    }

    /**
     * Returns tracking url of the task.
     *
     * @param   taskId  id of the task
     * @return          tracking url of the task
     */
    public String getTrackingUrl(String taskId) {
        try {
            String response = getClient().request(getInstanceUrl(taskId) + "tracking_url/",
                    "GET", null);
            Map responseMap = getMapFromResponse(response);
            return (String)responseMap.get("tracking_url");
        } catch (final HyperTrackException e) {
            e.printStackTrace();
            throw new IllegalArgumentException("Could not fetch tracking uri", e);
        }
    }

    /**
     * Mark task as completed.
     *
     * @param   task    task object
     * @param   params  params to be passed as POST body
     */
    public void markCompleted(Task task, Map params) {
        String taskId = task.getId();

        try {
            String response = getClient().request(getInstanceUrl(taskId) + "completed/",
                    "POST", params);
            Map responseMap = getMapFromResponse(response);
            updateFromParams(task, responseMap);
        } catch (final HyperTrackException e) {
            e.printStackTrace();
            throw new IllegalArgumentException("Could not complete task", e);
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy