Skip to content

Commit

Permalink
only add task if it does not exist check
Browse files Browse the repository at this point in the history
checks on task's for_entity, jurisdiction, planIdentifier and code
  • Loading branch information
LZRS committed May 24, 2021
1 parent 9b9b4d8 commit f817377
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions src/main/java/org/opensrp/service/TaskService.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,31 @@ public void addOrUpdateTask(Task task) {
addTask(task);
}
}

public boolean taskExists(Task task){
String taskIdentifier = task.getIdentifier();
String entityId = task.getForEntity();
String jurisdiction = task.getGroupIdentifier();
String planIdentifier = task.getPlanIdentifier();
String taskCode = task.getCode();

return (StringUtils.isNotBlank(taskIdentifier) && taskRepository.checkIfTaskExists(entityId, jurisdiction, planIdentifier, taskCode));
}

public boolean taskNotExists(Task task){
return !taskExists(task);
}

public Task addTask(Task task) {
if (StringUtils.isBlank(task.getIdentifier()))
throw new IllegalArgumentException("Identifier not specified");
task.setAuthoredOn(new DateTime());
task.setLastModified(new DateTime());
taskRepository.add(task);
if (taskNotExists(task)) {
task.setAuthoredOn(new DateTime());
task.setLastModified(new DateTime());
taskRepository.add(task);
}

return task;

}

public Task updateTask(Task task) {
Expand Down

0 comments on commit f817377

Please sign in to comment.