Skip to content

Commit

Permalink
Do not crash tests with orphaned task objects
Browse files Browse the repository at this point in the history
  • Loading branch information
matthias-ronge committed Oct 30, 2024
1 parent b336639 commit c052fc4
Showing 1 changed file with 18 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ public Keyworder(Process process) {

public Keyworder(Task task) {
if (Objects.nonNull(task.getProcess())) {
// ordinary task as part of a process
this.titleKeywords = initTitleKeywords(task.getProcess().getTitle());
this.projectKeywords = initProjectKeywords(task.getProcess().getProject().getTitle());
this.batchKeywords = initBatchKeywords(task.getProcess().getBatches());
Expand All @@ -113,7 +114,8 @@ public Keyworder(Task task) {
comment.getCurrentTask(), task) || Objects.equals(comment.getCorrectionTask(), task)).collect(Collectors
.toList());
this.commentKeywords = initCommentKeywords(commentsOfTask);
} else {
} else if (Objects.nonNull(task.getTemplate())) {
// template task as part of a production template
this.titleKeywords = initTitleKeywords(task.getTemplate().getTitle());
Set<String> projectKeywords = new HashSet<>();
for (Project project : task.getTemplate().getProjects()) {
Expand All @@ -128,6 +130,18 @@ public Keyworder(Task task) {
this.metadataPseudoKeywords = Collections.emptySet();
this.processId = task.getTemplate().getId().toString();
this.commentKeywords = Collections.emptySet();
} else {
// orphaned task (in a few tests)
this.titleKeywords = Collections.emptySet();
this.projectKeywords = Collections.emptySet();
this.batchKeywords = Collections.emptySet();
var taskKeywords = initTaskKeywords(Collections.singleton(task));
this.taskKeywords = taskKeywords.getLeft();
this.taskPseudoKeywords = taskKeywords.getRight();
this.metadataKeywords = Collections.emptySet();
this.metadataPseudoKeywords = Collections.emptySet();
this.processId = null;
this.commentKeywords = Collections.emptySet();
}
}

Expand Down Expand Up @@ -388,7 +402,9 @@ public String getSearch() {
freeKeywords.addAll(batchKeywords);
freeKeywords.addAll(taskKeywords);
freeKeywords.addAll(metadataKeywords);
freeKeywords.add(processId);
if (Objects.nonNull(processId)) {
freeKeywords.add(processId);
}
freeKeywords.addAll(commentKeywords);
return String.join(" ", freeKeywords);
}
Expand Down

0 comments on commit c052fc4

Please sign in to comment.