TSK-1064: refactored / simplified streams and boolean expressions

This commit is contained in:
Mustapha Zorgati 2020-01-29 21:05:32 +01:00
parent 811f26c206
commit 6c73ed18f2
1 changed files with 25 additions and 41 deletions

View File

@ -3,7 +3,7 @@ package pro.taskana.task.internal;
import java.time.Duration; import java.time.Duration;
import java.time.Instant; import java.time.Instant;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Collections;
import java.util.HashSet; import java.util.HashSet;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
@ -389,7 +389,7 @@ public class TaskServiceImpl implements TaskService {
String userId = CurrentUserContext.getUserid(); String userId = CurrentUserContext.getUserid();
LOGGER.debug("entry to updateTask(task = {}, userId = {})", task, userId); LOGGER.debug("entry to updateTask(task = {}, userId = {})", task, userId);
TaskImpl newTaskImpl = (TaskImpl) task; TaskImpl newTaskImpl = (TaskImpl) task;
TaskImpl oldTaskImpl = null; TaskImpl oldTaskImpl;
try { try {
taskanaEngine.openConnection(); taskanaEngine.openConnection();
oldTaskImpl = (TaskImpl) getTask(newTaskImpl.getId()); oldTaskImpl = (TaskImpl) getTask(newTaskImpl.getId());
@ -649,7 +649,7 @@ public class TaskServiceImpl implements TaskService {
public void refreshPriorityAndDueDate(String taskId) throws ClassificationNotFoundException { public void refreshPriorityAndDueDate(String taskId) throws ClassificationNotFoundException {
LOGGER.debug("entry to refreshPriorityAndDueDate(taskId = {})", taskId); LOGGER.debug("entry to refreshPriorityAndDueDate(taskId = {})", taskId);
TaskImpl task = null; TaskImpl task;
BulkOperationResults<String, Exception> bulkLog = new BulkOperationResults<>(); BulkOperationResults<String, Exception> bulkLog = new BulkOperationResults<>();
try { try {
taskanaEngine.openConnection(); taskanaEngine.openConnection();
@ -734,9 +734,8 @@ public class TaskServiceImpl implements TaskService {
return result; return result;
} }
Set<String> taskIdSet = String[] taskIdArray =
taskSummaries.stream().map(TaskSummaryImpl::getId).collect(Collectors.toSet()); taskSummaries.stream().map(TaskSummaryImpl::getId).distinct().toArray(String[]::new);
String[] taskIdArray = taskIdSet.toArray(new String[0]);
LOGGER.debug( LOGGER.debug(
"augmentTaskSummariesByContainedSummaries() about to query for attachmentSummaries "); "augmentTaskSummariesByContainedSummaries() about to query for attachmentSummaries ");
@ -760,7 +759,7 @@ public class TaskServiceImpl implements TaskService {
String userId = CurrentUserContext.getUserid(); String userId = CurrentUserContext.getUserid();
LOGGER.debug( LOGGER.debug(
"entry to claim(id = {}, userId = {}, forceClaim = {})", taskId, userId, forceClaim); "entry to claim(id = {}, userId = {}, forceClaim = {})", taskId, userId, forceClaim);
TaskImpl task = null; TaskImpl task;
try { try {
taskanaEngine.openConnection(); taskanaEngine.openConnection();
task = (TaskImpl) getTask(taskId); task = (TaskImpl) getTask(taskId);
@ -799,7 +798,7 @@ public class TaskServiceImpl implements TaskService {
taskId, taskId,
userId, userId,
forceUnclaim); forceUnclaim);
TaskImpl task = null; TaskImpl task;
try { try {
taskanaEngine.openConnection(); taskanaEngine.openConnection();
task = (TaskImpl) getTask(taskId); task = (TaskImpl) getTask(taskId);
@ -835,7 +834,7 @@ public class TaskServiceImpl implements TaskService {
String userId = CurrentUserContext.getUserid(); String userId = CurrentUserContext.getUserid();
LOGGER.debug( LOGGER.debug(
"entry to completeTask(id = {}, userId = {}, isForced = {})", taskId, userId, isForced); "entry to completeTask(id = {}, userId = {}, isForced = {})", taskId, userId, isForced);
TaskImpl task = null; TaskImpl task;
try { try {
taskanaEngine.openConnection(); taskanaEngine.openConnection();
task = (TaskImpl) this.getTask(taskId); task = (TaskImpl) this.getTask(taskId);
@ -884,7 +883,7 @@ public class TaskServiceImpl implements TaskService {
throws TaskNotFoundException, InvalidStateException, NotAuthorizedException { throws TaskNotFoundException, InvalidStateException, NotAuthorizedException {
LOGGER.debug("entry to deleteTask(taskId = {} , forceDelete = {})", taskId, forceDelete); LOGGER.debug("entry to deleteTask(taskId = {} , forceDelete = {})", taskId, forceDelete);
taskanaEngine.getEngine().checkRoleMembership(TaskanaRole.ADMIN); taskanaEngine.getEngine().checkRoleMembership(TaskanaRole.ADMIN);
TaskImpl task = null; TaskImpl task;
try { try {
taskanaEngine.openConnection(); taskanaEngine.openConnection();
task = (TaskImpl) getTask(taskId); task = (TaskImpl) getTask(taskId);
@ -983,26 +982,17 @@ public class TaskServiceImpl implements TaskService {
switch (desiredCallbackState) { switch (desiredCallbackState) {
case CALLBACK_PROCESSING_COMPLETED: case CALLBACK_PROCESSING_COMPLETED:
if (!(currentTaskState.equals(TaskState.COMPLETED))) { return currentTaskState.equals(TaskState.COMPLETED);
return false;
}
return true;
case CLAIMED: case CLAIMED:
if (!currentTaskState.equals(TaskState.CLAIMED)) { if (!currentTaskState.equals(TaskState.CLAIMED)) {
return false; return false;
} else if (!currentTaskCallbackState.equals(CallbackState.CALLBACK_PROCESSING_REQUIRED)) { } else {
return false; return currentTaskCallbackState.equals(CallbackState.CALLBACK_PROCESSING_REQUIRED);
} }
return true;
case CALLBACK_PROCESSING_REQUIRED: case CALLBACK_PROCESSING_REQUIRED:
if (currentTaskCallbackState.equals(CallbackState.CALLBACK_PROCESSING_COMPLETED)) { return !currentTaskCallbackState.equals(CallbackState.CALLBACK_PROCESSING_COMPLETED);
return false;
}
return true;
case NONE:
return false;
default: default:
return false; return false;
@ -1240,7 +1230,7 @@ public class TaskServiceImpl implements TaskService {
TaskImpl task, List<AttachmentImpl> attachmentImpls) { TaskImpl task, List<AttachmentImpl> attachmentImpls) {
LOGGER.debug("entry to transferBulk()"); LOGGER.debug("entry to transferBulk()");
Set<String> classificationIdSet = Set<String> classificationIdSet =
new HashSet<>(Arrays.asList(task.getClassificationSummary().getId())); new HashSet<>(Collections.singletonList(task.getClassificationSummary().getId()));
if (attachmentImpls != null && !attachmentImpls.isEmpty()) { if (attachmentImpls != null && !attachmentImpls.isEmpty()) {
for (AttachmentImpl att : attachmentImpls) { for (AttachmentImpl att : attachmentImpls) {
classificationIdSet.add(att.getClassificationSummary().getId()); classificationIdSet.add(att.getClassificationSummary().getId());
@ -1270,11 +1260,11 @@ public class TaskServiceImpl implements TaskService {
return; return;
} }
// calculate parameters for workbasket query: workbasket keys // calculate parameters for workbasket query: workbasket keys
Set<String> workbasketIdSet = String[] workbasketIdArray =
taskSummaries.stream() taskSummaries.stream()
.map(t -> t.getWorkbasketSummary().getId()) .map(t -> t.getWorkbasketSummary().getId())
.collect(Collectors.toSet()); .distinct()
String[] workbasketIdArray = workbasketIdSet.toArray(new String[0]); .toArray(String[]::new);
LOGGER.debug("addWorkbasketSummariesToTaskSummaries() about to query workbaskets"); LOGGER.debug("addWorkbasketSummariesToTaskSummaries() about to query workbaskets");
WorkbasketQueryImpl query = (WorkbasketQueryImpl) workbasketService.createWorkbasketQuery(); WorkbasketQueryImpl query = (WorkbasketQueryImpl) workbasketService.createWorkbasketQuery();
query.setUsedToAugmentTasks(true); query.setUsedToAugmentTasks(true);
@ -1430,7 +1420,7 @@ public class TaskServiceImpl implements TaskService {
throws InvalidArgumentException { throws InvalidArgumentException {
if (LOGGER.isDebugEnabled()) { if (LOGGER.isDebugEnabled()) {
LOGGER.debug( LOGGER.debug(
"entry to validateCustomFields(customFieldsToUpdate = {}, taskIds = {})", "entry to validateCustomFields(customFieldsToUpdate = {})",
LoggerUtils.mapToString(customFieldsToUpdate)); LoggerUtils.mapToString(customFieldsToUpdate));
} }
@ -1450,7 +1440,7 @@ public class TaskServiceImpl implements TaskService {
} }
private List<TaskSummary> getTasksToChange(List<String> taskIds) { private List<TaskSummary> getTasksToChange(List<String> taskIds) {
return createTaskQuery().idIn(taskIds.toArray(new String[taskIds.size()])).list(); return createTaskQuery().idIn(taskIds.toArray(new String[0])).list();
} }
private List<TaskSummary> getTasksToChange(ObjectReference selectionCriteria) { private List<TaskSummary> getTasksToChange(ObjectReference selectionCriteria) {
@ -1937,14 +1927,14 @@ public class TaskServiceImpl implements TaskService {
if (attachmentImpls == null || attachmentImpls.isEmpty()) { if (attachmentImpls == null || attachmentImpls.isEmpty()) {
return result; return result;
} }
Set<String> classificationIds =
attachmentImpls.stream()
.map(t -> t.getClassificationSummary().getId())
.collect(Collectors.toSet());
List<ClassificationSummary> classifications = List<ClassificationSummary> classifications =
classificationService classificationService
.createClassificationQuery() .createClassificationQuery()
.idIn(classificationIds.toArray(new String[0])) .idIn(
attachmentImpls.stream()
.map(t -> t.getClassificationSummary().getId())
.distinct()
.toArray(String[]::new))
.list(); .list();
for (AttachmentImpl att : attachmentImpls) { for (AttachmentImpl att : attachmentImpls) {
ClassificationSummary classificationSummary = ClassificationSummary classificationSummary =
@ -1973,8 +1963,7 @@ public class TaskServiceImpl implements TaskService {
} }
private void createTasksCompletedEvents(List<TaskSummary> taskSummaries) { private void createTasksCompletedEvents(List<TaskSummary> taskSummaries) {
taskSummaries.stream() taskSummaries.forEach(task -> historyEventProducer.createEvent(new CompletedEvent(task)));
.forEach(task -> historyEventProducer.createEvent(new CompletedEvent(task)));
} }
/** /**
@ -1989,7 +1978,6 @@ public class TaskServiceImpl implements TaskService {
private int prio; private int prio;
PrioDurationHolder(Duration duration, int prio) { PrioDurationHolder(Duration duration, int prio) {
super();
this.duration = duration; this.duration = duration;
this.prio = prio; this.prio = prio;
} }
@ -2006,10 +1994,6 @@ public class TaskServiceImpl implements TaskService {
return prio; return prio;
} }
public void setPrio(int prio) {
this.prio = prio;
}
@Override @Override
public String toString() { public String toString() {
return "PrioDurationHolder [duration=" + duration + ", prio=" + prio + "]"; return "PrioDurationHolder [duration=" + duration + ", prio=" + prio + "]";