How to Set Task Deadline by Priority

This Create Task/Before trigger sets the field “Deadline” depending upon the assigned priority. In this example, working days and holidays are not taken into account. For the purpose of taking them into consideration, fields of class Calendar have to come into play.

package scripts.before_create_task;

import com.trackstudio.exception.GranException;
import com.trackstudio.external.TaskTrigger;
import com.trackstudio.secured.SecuredTaskTriggerBean;

import java.util.Calendar;
import java.util.HashMap;
import java.util.Map;

 * The script sets the deadline of the task depending upon the selected priority */

public class SetDeadlineByPriority implements TaskTrigger {

    public SecuredTaskTriggerBean execute(SecuredTaskTriggerBean task) throws GranException {
        if (task.getPriority().getName().equals("Normal")) {
            Calendar now = Calendar.getInstance();
            // 8 days are added
            now.add(Calendar.DAY_OF_YEAR, 8);
        } else if (task.getPriority().getName().equals("Key")) {
            Calendar now = Calendar.getInstance();
            // 3 days are added
            now.add(Calendar.DAY_OF_YEAR, 3);
        } else if (task.getPriority().getName().equals("Optative")) {
            Calendar now = Calendar.getInstance();
            // 14 days are added
            now.add(Calendar.DAY_OF_YEAR, 14);
        return task;