Tasks
Creating tasks
The following sample creates a task record. Prerequisite to working with task records, you must also get the unique key value for an existing TeamConnect user record to add as a task assignee.
Code Snippet
protected TaskRepository taskRepository; private String createTask() throws Exception { Date date = new Date(); TaskAssigneeCreate taskAssignee = new TaskAssigneeCreate(); taskAssignee.setUserUniqueKey("user_1003"); taskAssignee.setAssignedOn(date); TaskCreate task = new TaskCreate(); //the shortDescription field is required task.setShortDescription("subject"); task.setActualHours(new BigDecimal("8.00")); task.setCurrentAssignee(taskAssignee); task.setPriority(TaskPriority.HIGH); task.setEstimatedHours(new BigDecimal("9.00")); task.setStartDate(date); task.setNote("A_task_note_" + date.getTime()); task.setRateAmount(new BigDecimal("50")); return taskRepository.insertTask(task); }
Updating tasks
The following sample updates a task record with the actual hours to complete the task, a newly calculated total amount, the date the task was completed, and percent completion value.
Code Snippet
//for this sample, it is assumed that a task record already exists with a unique key String equal to uniqueKey protected TaskRepository taskRepository; public void test_updateTask() throws Exception { Date date = new Date(); TaskUpdate taskUpdate = new TaskUpdate(); //use the setUniqueKey method to identify the target task record to update by its unique key taskUpdate.setUniqueKey(uniqueKey); taskUpdate.setActualHours(new BigDecimal("15.00")); taskUpdate.setRateAmount(new BigDecimal("50")); taskUpdate.setCompletedDate(date); taskUpdate.setCompletedPercent(100.00); taskRepository.updateTask(taskUpdate); }
Reading tasks
The following sample reads a task record and returns the specified property values.
Code Snippet
protected TaskRepository taskRepository; private List<String> getPropertiesToRead() { List<String> props = new List<String>(); //the list of all available properties displays below but to increase efficiency in your searches, you can omit unnecessary properties from your application and those values will not be returned props.add("shortDescription"); props.add("uniqueKey"); props.add("currentAssignee"); props.add("categories"); props.add("createdOn"); props.add("modifiedBy"); props.add("version"); props.add("modifiedOn"); props.add("contact"); props.add("project"); props.add("activityItem"); props.add("priority"); props.add("workStatus"); props.add("postingStatus"); props.add("dueDate"); props.add("startDate"); props.add("completedDate"); props.add("completedPercent"); props.add("actualHours"); props.add("estimatedHours"); props.add("rateAmount"); props.add("totalAmount"); props.add("note"); return props; } private Task readTask() throws Exception { Task readTask = taskRepository.readTask(uniqueKey, getPropertiesToRead()); return readTask; }
Searching tasks
The following sample searches for one or more task records and returns the specified property values. For this sample, it is assumed there is one or more tasks already existing with a subject String field value equal to subject.
Code Snippet
protected TaskRepository taskRepository; private List<Task> test_readTasksByCriteria() throws Exception { // Criterion for task searching StringFieldCriterion fieldCriterion = new StringFieldCriterion(); fieldCriterion.setComparator(StringComparator.EQUALS_ENFORCE_CASE); LegacySearchFieldPathExpression fieldPathExpression = new LegacySearchFieldPathExpression(); fieldPathExpression.setSearchKeyPath("shortDescription"); fieldCriterion.setFieldPath(fieldPathExpression); fieldCriterion.getValue().add(subject); FieldSearchClause searchCriteria = new FieldSearchClause(); searchCriteria.setOperator(LogicOperator.AND); searchCriteria.getCriteria().add(fieldCriterion); tasks = taskRepository.readTasksByCriteria(searchCriteria, 100, getPropertiesToRead()); } private List<String> getPropertiesToRead() { List<String> props = new List<String>(); //the list of all available properties displays below but to increase efficiency in your searches, you can omit unnecessary properties from your application and those values will not be returned props.add("shortDescription"); props.add("uniqueKey"); props.add("currentAssignee"); props.add("categories"); props.add("createdOn"); props.add("modifiedBy"); props.add("version"); props.add("modifiedOn"); props.add("contact"); props.add("project"); props.add("activityItem"); props.add("priority"); props.add("workStatus"); props.add("postingStatus"); props.add("dueDate"); props.add("startDate"); props.add("completedDate"); props.add("completedPercent"); props.add("actualHours"); props.add("estimatedHours"); props.add("rateAmount"); props.add("totalAmount"); props.add("note"); return props; }
Posting tasks
The following sample posts a task with given unique key.
Code Snippet
String taskUniqueKey = "TASK_1001"; protected TaskRepository taskRepository; taskRepository.postTask(taskUniqueKey);
Voiding tasks
The following sample voids a task with given unique key.
Code Snippet
String taskUniqueKey = "TASK_1001"; protected TaskRepository taskRepository; taskRepository.voidTask(taskUniqueKey);
Reassigning tasks
The following sample reassigns a task from a current assignee (user) to a different assignee.
Code Snippet
//for this sample, it is assumed that a task record already exists with a unique key String equal to uniqueKey protected TaskRepository taskRepository; private test_reassign() throws Exception { //reassign a task identified by its unique key to a new assignee, identified by his corresponding user unique key ("user_1005") taskRepository.reassign(uniqueKey, "user_1005"); }
Deleting tasks
The following sample deletes an existing task.
Code Snippet
//for this sample it is assumed that a task record exists with a unique key String equal to uniqueKey protected TaskRepository taskRepository; public void test_deleteTask() throws Exception { taskRepository.deleteTask(uniqueKey); }