Skip to content

Commit

Permalink
remove get task resource endpoint if no user tasks is defined in the …
Browse files Browse the repository at this point in the history
…workflow
  • Loading branch information
mswiderski committed Sep 21, 2024
1 parent 1abb4f4 commit 30cc17f
Showing 1 changed file with 28 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ public CompilationUnit generateCompilationUnit() {
});
});

if (userTasks != null) {
if (userTasks != null && !userTasks.isEmpty()) {

CompilationUnit userTaskClazz = parse(this.getClass().getResourceAsStream(getUserTaskResourceTemplate()));

Expand Down Expand Up @@ -394,11 +394,6 @@ public CompilationUnit generateCompilationUnit() {
}

}
} else {
// no user tasks remove the list tasks method
Optional<MethodDeclaration> createResourceMethod = template.findAll(MethodDeclaration.class).stream()
.filter(md -> md.getNameAsString().equals("getTasks_" + processName)).findFirst();
createResourceMethod.ifPresent(template::remove);
}

template.findAll(StringLiteralExpr.class).forEach(this::interpolateStrings);
Expand Down Expand Up @@ -528,6 +523,16 @@ public int compare(Parameter o1, Parameter o2) {

enableValidation(template);
securityAnnotated(template);

if (!hasUserTask(this)) {

// no user tasks remove the list tasks method
Optional<MethodDeclaration> getTasksResourceMethod = template.findAll(MethodDeclaration.class).stream()
.filter(md -> md.getNameAsString().equals("getTasks_" + processName)).findFirst();
getTasksResourceMethod.ifPresent(template::remove);

}

try {
template.getMembers().sort(new BodyDeclarationComparator());
} catch (IllegalArgumentException e) {
Expand All @@ -537,6 +542,23 @@ public int compare(Parameter o1, Parameter o2) {
return clazz;
}

protected boolean hasUserTask(AbstractResourceGenerator genarator) {
boolean hasUserTasks = genarator.userTasks != null && !genarator.userTasks.isEmpty();
if (hasUserTasks) {
return true;
}
if (!genarator.subprocesses.isEmpty()) {
for (AbstractResourceGenerator subgenarator : genarator.subprocesses) {
boolean subHasUserTask = hasUserTask(subgenarator);
if (subHasUserTask) {
return true;
}
}
}

return hasUserTasks;
}

protected void addDefinedError(Collection<FaultNode> errors, MethodDeclaration cloned) {
NormalAnnotationExpr apiResponses = (NormalAnnotationExpr) cloned.getAnnotationByName("APIResponses")
.orElse(null);
Expand Down

0 comments on commit 30cc17f

Please sign in to comment.