use of pro.taskana.exceptions.InvalidArgumentException in project taskana by Taskana.
the class TaskServiceImpl method transferTasks.
@Override
public BulkOperationResults<String, TaskanaException> transferTasks(String destinationWorkbasketId, List<String> taskIds) throws NotAuthorizedException, InvalidArgumentException, WorkbasketNotFoundException {
try {
taskanaEngine.openConnection();
LOGGER.debug("entry to transferBulk(targetWbId = {}, taskIds = {})", destinationWorkbasketId, taskIds);
// Check pre-conditions with trowing Exceptions
if (destinationWorkbasketId == null || taskIds == null) {
throw new InvalidArgumentException("DestinationWorkbasketId or TaskIds can´t be used as NULL-Parameter.");
}
Workbasket destinationWorkbasket = workbasketService.getWorkbasket(destinationWorkbasketId);
return transferTasks(taskIds, destinationWorkbasket);
} finally {
LOGGER.debug("exit from transferBulk(targetWbKey = {}, taskIds = {})", destinationWorkbasketId, taskIds);
taskanaEngine.returnConnection();
}
}
use of pro.taskana.exceptions.InvalidArgumentException in project taskana by Taskana.
the class TaskServiceImpl method transferTasks.
private BulkOperationResults<String, TaskanaException> transferTasks(List<String> taskIds, Workbasket destinationWorkbasket) throws InvalidArgumentException {
BulkOperationResults<String, TaskanaException> bulkLog = new BulkOperationResults<>();
// check tasks Ids exist and not empty - log and remove
Iterator<String> taskIdIterator = taskIds.iterator();
while (taskIdIterator.hasNext()) {
String currentTaskId = taskIdIterator.next();
if (currentTaskId == null || currentTaskId.equals("")) {
bulkLog.addError("", new InvalidArgumentException("IDs with EMPTY or NULL value are not allowed."));
taskIdIterator.remove();
}
}
// query for existing tasks. use taskMapper.findExistingTasks because this method
// returns only the required information.
List<MinimalTaskSummary> taskSummaries = taskMapper.findExistingTasks(taskIds);
// check source WB (read)+transfer
Set<String> workbasketIds = new HashSet<>();
taskSummaries.stream().forEach(t -> workbasketIds.add(t.getWorkbasketId()));
WorkbasketQueryImpl query = (WorkbasketQueryImpl) workbasketService.createWorkbasketQuery();
query.setUsedToAugmentTasks(true);
List<WorkbasketSummary> sourceWorkbaskets = query.callerHasPermission(WorkbasketPermission.TRANSFER).idIn(workbasketIds.toArray(new String[0])).list();
taskIdIterator = taskIds.iterator();
while (taskIdIterator.hasNext()) {
String currentTaskId = taskIdIterator.next();
MinimalTaskSummary taskSummary = taskSummaries.stream().filter(t -> currentTaskId.equals(t.getTaskId())).findFirst().orElse(null);
if (taskSummary == null) {
bulkLog.addError(currentTaskId, new TaskNotFoundException(currentTaskId, "Task with id " + currentTaskId + " was not found."));
taskIdIterator.remove();
} else if (!sourceWorkbaskets.stream().anyMatch(wb -> taskSummary.getWorkbasketId().equals(wb.getId()))) {
bulkLog.addError(currentTaskId, new NotAuthorizedException("The workbasket of this task got not TRANSFER permissions. TaskId=" + currentTaskId));
taskIdIterator.remove();
}
}
// filter taskSummaries and update values
taskSummaries = taskSummaries.stream().filter(ts -> taskIds.contains(ts.getTaskId())).collect(Collectors.toList());
if (!taskSummaries.isEmpty()) {
Instant now = Instant.now();
TaskSummaryImpl updateObject = new TaskSummaryImpl();
updateObject.setRead(false);
updateObject.setTransferred(true);
updateObject.setWorkbasketSummary(destinationWorkbasket.asSummary());
updateObject.setDomain(destinationWorkbasket.getDomain());
updateObject.setModified(now);
updateObject.setState(TaskState.READY);
updateObject.setOwner(null);
taskMapper.updateTransfered(taskIds, updateObject);
}
return bulkLog;
}
use of pro.taskana.exceptions.InvalidArgumentException in project taskana by Taskana.
the class TaskServiceImpl method createTask.
@Override
public Task createTask(Task taskToCreate) throws NotAuthorizedException, WorkbasketNotFoundException, ClassificationNotFoundException, TaskAlreadyExistException, InvalidArgumentException {
LOGGER.debug("entry to createTask(task = {})", taskToCreate);
TaskImpl task = (TaskImpl) taskToCreate;
try {
taskanaEngine.openConnection();
if (task.getId() != "" && task.getId() != null) {
throw new TaskAlreadyExistException(task.getId());
} else {
LOGGER.debug("Task {} cannot be be found, so it can be created.", task.getId());
Workbasket workbasket;
if (task.getWorkbasketSummary().getId() != null) {
workbasket = workbasketService.getWorkbasket(task.getWorkbasketSummary().getId());
} else if (task.getWorkbasketKey() != null) {
workbasket = workbasketService.getWorkbasket(task.getWorkbasketKey(), task.getDomain());
} else {
throw new InvalidArgumentException("Cannot create a task outside a workbasket");
}
task.setWorkbasketSummary(workbasket.asSummary());
task.setDomain(workbasket.getDomain());
workbasketService.checkAuthorization(task.getWorkbasketSummary().getId(), WorkbasketPermission.APPEND);
String classificationKey = task.getClassificationKey();
if (classificationKey == null || classificationKey.length() == 0) {
throw new InvalidArgumentException("classificationKey of task must not be empty");
}
Classification classification = this.classificationService.getClassification(classificationKey, workbasket.getDomain());
task.setClassificationSummary(classification.asSummary());
validateObjectReference(task.getPrimaryObjRef(), "primary ObjectReference", "Task");
PrioDurationHolder prioDurationFromAttachments = handleAttachments(task);
standardSettings(task, classification, prioDurationFromAttachments);
this.taskMapper.insert(task);
LOGGER.debug("Method createTask() created Task '{}'.", task.getId());
}
return task;
} finally {
taskanaEngine.returnConnection();
LOGGER.debug("exit from createTask(task = {})", task);
}
}
use of pro.taskana.exceptions.InvalidArgumentException in project taskana by Taskana.
the class TaskServiceImpl method updateTasks.
@Override
public List<String> updateTasks(ObjectReference selectionCriteria, Map<String, String> customFieldsToUpdate) throws InvalidArgumentException {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("entry to updateTasks(selectionCriteria = {}, customFieldsToUpdate = {})", selectionCriteria, customFieldsToUpdate);
}
if (customFieldsToUpdate == null || customFieldsToUpdate.isEmpty()) {
LOGGER.warn("The customFieldsToUpdate argument to updateTasks must not be empty. Throwing InvalidArgumentException.");
throw new InvalidArgumentException("The customFieldsToUpdate argument to updateTasks must not be empty.");
}
validateObjectReference(selectionCriteria, "ObjectReference", "updateTasks call");
Set<String> allowedKeys = new HashSet<>(Arrays.asList("1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16"));
try {
taskanaEngine.openConnection();
CustomPropertySelector fieldSelector = new CustomPropertySelector();
TaskImpl newTask = new TaskImpl();
newTask.setModified(Instant.now());
for (Map.Entry<String, String> entry : customFieldsToUpdate.entrySet()) {
String key = entry.getKey();
if (!allowedKeys.contains(key)) {
LOGGER.warn("The customFieldsToUpdate argument to updateTasks contains invalid key {}.", key);
throw new InvalidArgumentException("The customFieldsToUpdate argument to updateTasks contains invalid key " + key);
} else {
fieldSelector.setCustomProperty(key, true);
newTask.setCustomAttribute(key, entry.getValue());
}
}
// use query in order to find only those tasks that are visible to the current user
List<TaskSummary> taskSummaries = createTaskQuery().primaryObjectReferenceCompanyIn(selectionCriteria.getCompany()).primaryObjectReferenceSystemIn(selectionCriteria.getSystem()).primaryObjectReferenceSystemInstanceIn(selectionCriteria.getSystemInstance()).primaryObjectReferenceTypeIn(selectionCriteria.getType()).primaryObjectReferenceValueIn(selectionCriteria.getValue()).list();
List<String> taskIds = new ArrayList<>();
if (!taskSummaries.isEmpty()) {
taskIds = taskSummaries.stream().map(TaskSummary::getTaskId).collect(Collectors.toList());
taskMapper.updateTasks(taskIds, newTask, fieldSelector);
LOGGER.debug("updateTasks() updated the following tasks: {} ", LoggerUtils.listToString(taskIds));
} else {
LOGGER.debug("updateTasks() found no tasks for update ");
}
return taskIds;
} finally {
LOGGER.debug("exit from deleteTasks().");
taskanaEngine.returnConnection();
}
}
use of pro.taskana.exceptions.InvalidArgumentException in project taskana by Taskana.
the class TaskServiceImpl method deleteTasks.
@Override
public BulkOperationResults<String, TaskanaException> deleteTasks(List<String> taskIds) throws InvalidArgumentException {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("entry to deleteTasks(tasks = {})", LoggerUtils.listToString(taskIds));
}
try {
taskanaEngine.openConnection();
if (taskIds == null) {
throw new InvalidArgumentException("TaskIds can´t be NULL as parameter for deleteTasks().");
}
BulkOperationResults<String, TaskanaException> bulkLog = new BulkOperationResults<>();
List<MinimalTaskSummary> taskSummaries = taskMapper.findExistingTasks(taskIds);
Iterator<String> taskIdIterator = taskIds.iterator();
while (taskIdIterator.hasNext()) {
String currentTaskId = taskIdIterator.next();
if (currentTaskId == null || currentTaskId.equals("")) {
bulkLog.addError("", new InvalidArgumentException("IDs with EMPTY or NULL value are not allowed."));
taskIdIterator.remove();
} else {
MinimalTaskSummary foundSummary = taskSummaries.stream().filter(taskState -> currentTaskId.equals(taskState.getTaskId())).findFirst().orElse(null);
if (foundSummary == null) {
bulkLog.addError(currentTaskId, new TaskNotFoundException(currentTaskId, "Task with id " + currentTaskId + " was not found."));
taskIdIterator.remove();
} else {
if (!TaskState.COMPLETED.equals(foundSummary.getTaskState())) {
bulkLog.addError(currentTaskId, new InvalidStateException(currentTaskId));
taskIdIterator.remove();
}
}
}
}
if (!taskIds.isEmpty()) {
taskMapper.deleteMultiple(taskIds);
}
return bulkLog;
} finally {
LOGGER.debug("exit from deleteTasks()");
taskanaEngine.returnConnection();
}
}
Aggregations