Working with tasks

Previous: Dealing with processes ] [ Top:  ] [ Next: Working with requests ]



task: Show a task, including data requirements
 
if (argsleft < 2) {
   printf ("wftk task: dsrep and process ID required (use . for default repository)\n");
   exit (1);
}

datasheet = wftk_process_load (session, PERIOD_TO_NULL (argv[argp]), argv[argp+1]); argp++; argp++;
if (datasheet) {
   if (argsleft < 1) {
      task = wftk_task_retrieve (session, datasheet);
   } else {
      task = xml_create ("task");
      xml_set (task, "id", argv[argp++]);
      xml_set (task, "dsrep", xml_attrval (datasheet, "repository"));
      xml_set (task, "process", xml_attrval (datasheet, "id"));
      wftk_task_retrieve (session, task);
   }

   if (!strcmp (xml_attrval (task, "status"), "none")) {
      printf ("No task found.\n");
   } else {
      printf ("Task '%s'\n", *xml_attrval (task, "label") ? xml_attrval (task, "label") : xml_attrval (task, "id"));
      if (*xml_attrval (task, "role")) printf ("Role: %s\n", xml_attrval (task, "role"));
      if (*xml_attrval (task, "user")) printf ("Assigned to %s\n", xml_attrval (task, "user"));
      mark = xml_firstelem (task);
      while (mark) {
         if (xml_is (mark, "field")) {
            value = wftk_value_get (session, task, xml_attrval (mark, "id"));
            printf (" %c %s: %s\n", strcmp (xml_attrval (mark, "mode"), "input") ? ' ' : '*',
                                    xml_attrval (mark, "id"), value);
            if (value) free (value);
         }
         mark = xml_nextelem (mark);
      }
   }
}


tasks: List tasks
This task list is simply a list of tasks active in a given process. The list is obtained from the datasheet directly.
 
if (argsleft < 2) {
   printf ("wftk task: dsrep and process ID required (use . for default repository)\n");
   exit (1);
}

list = xml_create ("list");
if (strcmp (argv[argp++], ".")) xml_set (list, "dsrep", argv[argp-1]);
xml_set (list, "process", argv[argp++]);
wftk_task_list (session, list, NULL);
mark = xml_firstelem (list);
if (!mark) {
   printf ("No tasks found.\n");
} else {
   while (mark) {
      printf ("%s: %s", xml_attrval (mark, "id"), xml_attrval (mark, "label"));
      if (*xml_attrval (mark, "role")) printf (" [%s]", xml_attrval (mark, "role"));
      if (*xml_attrval (mark, "user")) printf (" (%s)", xml_attrval (mark, "user"));
      printf ("\n");
      mark = xml_nextelem (mark);
   }
}


todo: List indexed tasks
This list of tasks is obtained from the task index (the active task database). At some point it'll screen for specific users or roles; for the time being it will demonstrate working with task list returns (which are done in exactly the same way as above, of course.)
 
list = xml_create ("list");
if (argsleft > 0) xml_set (list, "user", argv[argp++]);
xml_set (list, "status", "active");
wftk_task_list (session, list, NULL);
mark = xml_firstelem (list);
if (!mark) {
   printf ("No tasks found.\n");
} else {
   while (mark) {
      printf ("%s > %s: %s", xml_attrval (mark, "process"), xml_attrval (mark, "id"), xml_attrval (mark, "label"));
      if (*xml_attrval (mark, "role")) printf (" [%s]", xml_attrval (mark, "role"));
      if (argc == 2 && *xml_attrval (mark, "user")) printf (" (%s)", xml_attrval (mark, "user"));
      printf ("\n");
      mark = xml_nextelem (mark);
   }
}


complete: Complete a task (or start the process)
 
if (argsleft < 2) {
   printf ("wftk task: dsrep and process ID required (use . for default repository)\n");
   exit (1);
}

datasheet = wftk_process_load (session, PERIOD_TO_NULL (argv[argp]), argv[argp+1]); argp++; argp++;
if (datasheet) {
   if (argsleft < 1) {
      task = wftk_task_retrieve (session, datasheet);
   } else {
      task = xml_create ("task");
      xml_set (task, "id", argv[argp++]);
      xml_set (task, "dsrep", xml_attrval (datasheet, "repository"));
      xml_set (task, "process", xml_attrval (datasheet, "id"));
      wftk_task_retrieve (session, task);
   }

   if (wftk_task_complete (session, task)) {
      printf ("Completed.\n");
   } else {
      printf ("Not completed.\n");
   }
}


reject: Reject a task
 
if (argsleft < 3) {
   printf ("wftk reject: dsrep, process ID, and task ID required (use . for default repository)\n");
   exit (1);
}

datasheet = wftk_process_load (session, PERIOD_TO_NULL (argv[argp]), argv[argp+1]); argp++; argp++;
if (!datasheet) {
   printf ("Datasheet repository %s can't find datasheet %s", argv[argp-2], argv[argp-1]);
} else {
   task = xml_create ("task");
   xml_set (task, "id", argv[argp++]);
   xml_set (task, "dsrep", xml_attrval (datasheet, "repository"));
   xml_set (task, "process", xml_attrval (datasheet, "id"));
   wftk_task_retrieve (session, task);

   if (wftk_task_reject (session, task)) {
      printf ("Rejected.\n");
   } else {
      printf ("No action taken.\n");
   }
}


newtask: Create an ad-hoc task
This interface to wftk_task_new is somewhat weak, as it doesn't allow the user to specify data requirements for an ad-hoc task. The library itself has no such limitation.
 
if (argsleft < 3) {
   printf ("wftk task: dsrep, process ID and task ID required (use . for default repository)\n");
   exit (1);
}

task = xml_create ("task");
if (strcmp (argv[argp++], ".")) xml_set (task, "dsrep", argv[argp-1]);
xml_set (task, "process", argv[argp++]);
xml_set (task, "id", argv[argp++]);
if (argsleft > 0) xml_set (task, "label", argv[argp++]);

if (wftk_task_new (session, task)) {
   printf ("Task added.\n");
} else {
   printf ("No task added.\n");
}
Now that's easy.

rescind: Delete an ad-hoc task
 
if (argsleft < 3) {
   printf ("wftk task: dsrep, process ID and task ID required (use . for default repository)\n");
   exit (1);
}

task = xml_create ("task");
if (strcmp (argv[argp++], ".")) xml_set (task, "dsrep", argv[argp-1]);
xml_set (task, "process", argv[argp++]);
xml_set (task, "id", argv[argp++]);

if (wftk_task_rescind (session, task)) {
   printf ("Task rescinded.\n");
} else {
   printf ("No task rescinded.\n");
}
Now that's even easier.

assign: Attach a user to a task
If the user is omitted from this command, it has the effect of de-assigning the task.
 
if (argsleft < 3) {
   printf ("wftk assign: dsrep, process ID and task ID required (use . for default repository)\n");
   exit (1);
}

task = xml_create("task");
xml_set (task, "dsrep", PERIOD_TO_NULL (argv[argp]) ? argv[argp] : ""); argp++;
xml_set (task, "process", argv[argp++]);
xml_set (task, "id", argv[argp++]);
   
if (!wftk_task_retrieve (session, task)) {
   printf ("Task %s is not active", argv[argp-1]);
} else {
   if (argsleft > 0) {
      xml_set (task, "user", argv[argp++]);
   } else {
      xml_set (task, "user", "");
   }
   wftk_task_update (session, task);
}
Note that this function can't assign a task to a role, or assign a role to a user. These will come later.
Previous: Dealing with processes ] [ Top:  ] [ Next: Working with requests ]


This code and documentation are released under the terms of the GNU license. They are additionally copyright (c) 2000, Vivtek. All rights reserved except those explicitly granted under the terms of the GNU license.