Search in sources :

Example 26 with InvalidArgumentException

use of pro.taskana.exceptions.InvalidArgumentException in project taskana by Taskana.

the class TaskMonitorServiceImpl method getCustomFieldValueReport.

@Override
public CustomFieldValueReport getCustomFieldValueReport(List<String> workbasketIds, List<TaskState> states, List<String> categories, List<String> domains, CustomField customField, List<String> customFieldValues, List<TimeIntervalColumnHeader> columnHeaders, boolean inWorkingDays) throws InvalidArgumentException {
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("entry to getCustomFieldValueReport(workbasketIds = {}, states = {}, categories = {}, " + "domains = {}, customField = {}, customFieldValues = {}, columnHeaders = {}, " + "inWorkingDays = {})", LoggerUtils.listToString(workbasketIds), LoggerUtils.listToString(states), LoggerUtils.listToString(categories), LoggerUtils.listToString(domains), customField, LoggerUtils.listToString(customFieldValues), LoggerUtils.listToString(columnHeaders), inWorkingDays);
    }
    try {
        taskanaEngineImpl.openConnection();
        if (customField == null) {
            throw new InvalidArgumentException("CustomField can´t be used as NULL-Parameter");
        }
        configureDaysToWorkingDaysConverter();
        CustomFieldValueReport report = new CustomFieldValueReport(columnHeaders);
        List<MonitorQueryItem> monitorQueryItems = taskMonitorMapper.getTaskCountOfCustomFieldValues(workbasketIds, states, categories, domains, customField, customFieldValues);
        report.addItems(monitorQueryItems, new DaysToWorkingDaysPreProcessor<>(columnHeaders, inWorkingDays));
        return report;
    } finally {
        taskanaEngineImpl.returnConnection();
        LOGGER.debug("exit from getCustomFieldValueReport().");
    }
}
Also used : InvalidArgumentException(pro.taskana.exceptions.InvalidArgumentException) CustomFieldValueReport(pro.taskana.impl.report.impl.CustomFieldValueReport) MonitorQueryItem(pro.taskana.impl.report.impl.MonitorQueryItem) DetailedMonitorQueryItem(pro.taskana.impl.report.impl.DetailedMonitorQueryItem)

Example 27 with InvalidArgumentException

use of pro.taskana.exceptions.InvalidArgumentException in project taskana by Taskana.

the class TaskServiceImpl method completeTasks.

@Override
public BulkOperationResults<String, TaskanaException> completeTasks(List<String> taskIds) throws InvalidArgumentException {
    try {
        LOGGER.debug("entry to completeTasks(taskIds = {})", taskIds);
        taskanaEngine.openConnection();
        // Check pre-conditions with throwing Exceptions
        if (taskIds == null) {
            throw new InvalidArgumentException("TaskIds can´t be used as NULL-Parameter.");
        }
        // process bulk-complete
        BulkOperationResults<String, TaskanaException> bulkLog = new BulkOperationResults<>();
        if (!taskIds.isEmpty()) {
            // remove null/empty taskIds with message
            Iterator<String> taskIdIterator = taskIds.iterator();
            while (taskIdIterator.hasNext()) {
                String currentTaskId = taskIdIterator.next();
                if (currentTaskId == null || currentTaskId.isEmpty()) {
                    bulkLog.addError("", new InvalidArgumentException("IDs with EMPTY or NULL value are not allowed and invalid."));
                    taskIdIterator.remove();
                }
            }
            // query for existing tasks, modify values and LOG missing ones.
            List<TaskSummary> taskSummaries = this.createTaskQuery().idIn(taskIds.toArray(new String[0])).list();
            Instant now = Instant.now();
            taskIdIterator = taskIds.iterator();
            while (taskIdIterator.hasNext()) {
                String currentTaskId = taskIdIterator.next();
                TaskSummaryImpl taskSummary = (TaskSummaryImpl) taskSummaries.stream().filter(ts -> currentTaskId.equals(ts.getTaskId())).findFirst().orElse(null);
                if (taskSummary == null) {
                    bulkLog.addError(currentTaskId, new TaskNotFoundException(currentTaskId, "task with id " + currentTaskId + " was not found."));
                    taskIdIterator.remove();
                } else if (taskSummary.getClaimed() == null || taskSummary.getState() != TaskState.CLAIMED) {
                    bulkLog.addError(currentTaskId, new InvalidStateException(currentTaskId));
                    taskIdIterator.remove();
                } else if (!CurrentUserContext.getAccessIds().contains(taskSummary.getOwner())) {
                    bulkLog.addError(currentTaskId, new InvalidOwnerException("TaskOwner is" + taskSummary.getOwner() + ", but current User is " + CurrentUserContext.getUserid()));
                    taskIdIterator.remove();
                } else {
                    taskSummary.setCompleted(now);
                    taskSummary.setModified(now);
                    taskSummary.setState(TaskState.COMPLETED);
                }
            }
            if (!taskIds.isEmpty() && !taskSummaries.isEmpty()) {
                taskMapper.updateCompleted(taskIds, (TaskSummaryImpl) taskSummaries.get(0));
            }
        }
        return bulkLog;
    } finally {
        taskanaEngine.returnConnection();
        LOGGER.debug("exit from to completeTasks(taskIds = {})", taskIds);
    }
}
Also used : Arrays(java.util.Arrays) PersistenceException(org.apache.ibatis.exceptions.PersistenceException) IdGenerator(pro.taskana.impl.util.IdGenerator) LoggerFactory(org.slf4j.LoggerFactory) WorkbasketService(pro.taskana.WorkbasketService) ArrayList(java.util.ArrayList) CurrentUserContext(pro.taskana.security.CurrentUserContext) HashSet(java.util.HashSet) WorkbasketNotFoundException(pro.taskana.exceptions.WorkbasketNotFoundException) SystemException(pro.taskana.exceptions.SystemException) CustomPropertySelector(pro.taskana.mappings.CustomPropertySelector) Task(pro.taskana.Task) InvalidStateException(pro.taskana.exceptions.InvalidStateException) Duration(java.time.Duration) Map(java.util.Map) TaskState(pro.taskana.TaskState) WorkbasketPermission(pro.taskana.WorkbasketPermission) WorkbasketSummary(pro.taskana.WorkbasketSummary) TimeIntervalColumnHeader(pro.taskana.impl.report.impl.TimeIntervalColumnHeader) ClassificationSummary(pro.taskana.ClassificationSummary) TaskNotFoundException(pro.taskana.exceptions.TaskNotFoundException) TaskanaEngine(pro.taskana.TaskanaEngine) Attachment(pro.taskana.Attachment) TaskAlreadyExistException(pro.taskana.exceptions.TaskAlreadyExistException) TaskSummary(pro.taskana.TaskSummary) ClassificationNotFoundException(pro.taskana.exceptions.ClassificationNotFoundException) ConcurrencyException(pro.taskana.exceptions.ConcurrencyException) Logger(org.slf4j.Logger) InvalidOwnerException(pro.taskana.exceptions.InvalidOwnerException) Iterator(java.util.Iterator) Set(java.util.Set) InvalidWorkbasketException(pro.taskana.exceptions.InvalidWorkbasketException) AttachmentMapper(pro.taskana.mappings.AttachmentMapper) Classification(pro.taskana.Classification) LoggerUtils(pro.taskana.impl.util.LoggerUtils) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) AttachmentPersistenceException(pro.taskana.exceptions.AttachmentPersistenceException) InvalidArgumentException(pro.taskana.exceptions.InvalidArgumentException) TaskService(pro.taskana.TaskService) TaskMapper(pro.taskana.mappings.TaskMapper) List(java.util.List) Workbasket(pro.taskana.Workbasket) TaskanaRole(pro.taskana.TaskanaRole) NotAuthorizedException(pro.taskana.exceptions.NotAuthorizedException) TaskanaException(pro.taskana.exceptions.TaskanaException) TaskQuery(pro.taskana.TaskQuery) Collections(java.util.Collections) Instant(java.time.Instant) InvalidStateException(pro.taskana.exceptions.InvalidStateException) TaskanaException(pro.taskana.exceptions.TaskanaException) InvalidArgumentException(pro.taskana.exceptions.InvalidArgumentException) TaskNotFoundException(pro.taskana.exceptions.TaskNotFoundException) TaskSummary(pro.taskana.TaskSummary) InvalidOwnerException(pro.taskana.exceptions.InvalidOwnerException)

Example 28 with InvalidArgumentException

use of pro.taskana.exceptions.InvalidArgumentException in project taskana by Taskana.

the class UpdateTaskAccTest method testThrowsExceptionIfMandatoryPrimaryObjectReferenceIsNotSetOrIncomplete.

@WithAccessId(userName = "user_1_1", groupNames = { "group_1" })
@Test
public void testThrowsExceptionIfMandatoryPrimaryObjectReferenceIsNotSetOrIncomplete() throws SQLException, NotAuthorizedException, InvalidArgumentException, ClassificationNotFoundException, WorkbasketNotFoundException, TaskAlreadyExistException, InvalidWorkbasketException, TaskNotFoundException, ConcurrencyException, AttachmentPersistenceException {
    TaskService taskService = taskanaEngine.getTaskService();
    Task task = taskService.getTask("TKI:000000000000000000000000000000000000");
    task.setPrimaryObjRef(null);
    try {
        taskService.updateTask(task);
        fail("update() should have thrown InvalidArgumentException.");
    } catch (InvalidArgumentException ex) {
    // nothing to do
    }
    task.setPrimaryObjRef(createObjectReference("COMPANY_A", "SYSTEM_A", "INSTANCE_A", "VNR", null));
    try {
        taskService.updateTask(task);
        fail("update() should have thrown InvalidArgumentException.");
    } catch (InvalidArgumentException ex) {
    // nothing to do
    }
    task.setPrimaryObjRef(createObjectReference("COMPANY_A", "SYSTEM_A", "INSTANCE_A", null, "1234567"));
    try {
        taskService.updateTask(task);
        fail("update() should have thrown InvalidArgumentException.");
    } catch (InvalidArgumentException ex) {
    // nothing to do
    }
    task.setPrimaryObjRef(createObjectReference("COMPANY_A", "SYSTEM_A", null, "VNR", "1234567"));
    try {
        taskService.updateTask(task);
        fail("update() should have thrown InvalidArgumentException.");
    } catch (InvalidArgumentException ex) {
    // nothing to do
    }
    task.setPrimaryObjRef(createObjectReference("COMPANY_A", null, "INSTANCE_A", "VNR", "1234567"));
    try {
        taskService.updateTask(task);
        fail("update() should have thrown InvalidArgumentException.");
    } catch (InvalidArgumentException ex) {
    // nothing to do
    }
    task.setPrimaryObjRef(createObjectReference(null, "SYSTEM_A", "INSTANCE_A", "VNR", "1234567"));
    try {
        taskService.updateTask(task);
        fail("update() should have thrown InvalidArgumentException.");
    } catch (InvalidArgumentException ex) {
    // nothing to do
    }
}
Also used : Task(pro.taskana.Task) InvalidArgumentException(pro.taskana.exceptions.InvalidArgumentException) TaskService(pro.taskana.TaskService) AbstractAccTest(acceptance.AbstractAccTest) Test(org.junit.Test) WithAccessId(pro.taskana.security.WithAccessId)

Example 29 with InvalidArgumentException

use of pro.taskana.exceptions.InvalidArgumentException in project taskana by Taskana.

the class DeleteWorkbasketAccTest method testCreateAndDeleteWorkbasket.

@WithAccessId(userName = "user_1_2", groupNames = { "businessadmin" })
@Test
public void testCreateAndDeleteWorkbasket() throws SQLException, NotAuthorizedException, InvalidArgumentException, WorkbasketNotFoundException, InvalidWorkbasketException, WorkbasketAlreadyExistException, DomainNotFoundException {
    WorkbasketService workbasketService = taskanaEngine.getWorkbasketService();
    int before = workbasketService.createWorkbasketQuery().domainIn("DOMAIN_A").list().size();
    Workbasket workbasket = workbasketService.newWorkbasket("NT1234", "DOMAIN_A");
    workbasket.setName("TheUltimate");
    workbasket.setType(WorkbasketType.GROUP);
    workbasket.setOrgLevel1("company");
    workbasket = workbasketService.createWorkbasket(workbasket);
    try {
        workbasketService.deleteWorkbasket(workbasket.getId());
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
Also used : WorkbasketService(pro.taskana.WorkbasketService) Workbasket(pro.taskana.Workbasket) WorkbasketAlreadyExistException(pro.taskana.exceptions.WorkbasketAlreadyExistException) WorkbasketInUseException(pro.taskana.exceptions.WorkbasketInUseException) DomainNotFoundException(pro.taskana.exceptions.DomainNotFoundException) InvalidWorkbasketException(pro.taskana.exceptions.InvalidWorkbasketException) InvalidArgumentException(pro.taskana.exceptions.InvalidArgumentException) WorkbasketNotFoundException(pro.taskana.exceptions.WorkbasketNotFoundException) SQLException(java.sql.SQLException) NotAuthorizedException(pro.taskana.exceptions.NotAuthorizedException) AbstractAccTest(acceptance.AbstractAccTest) Test(org.junit.Test) WithAccessId(pro.taskana.security.WithAccessId)

Example 30 with InvalidArgumentException

use of pro.taskana.exceptions.InvalidArgumentException in project taskana by Taskana.

the class CreateTaskAccTest method testThrowsExceptionIfAttachmentIsInvalid.

@WithAccessId(userName = "user_1_1", groupNames = { "group_1" })
@Test
public void testThrowsExceptionIfAttachmentIsInvalid() throws SQLException, NotAuthorizedException, InvalidArgumentException, ClassificationNotFoundException, WorkbasketNotFoundException, TaskAlreadyExistException, InvalidWorkbasketException {
    TaskService taskService = taskanaEngine.getTaskService();
    Task newTask = makeNewTask(taskService);
    newTask.addAttachment(createAttachment("DOCTYPE_DEFAULT", null, "E-MAIL", "2018-01-15", createSimpleCustomProperties(3)));
    try {
        taskService.createTask(newTask);
        fail("Should have thrown an InvalidArgumentException, becasue Attachment-ObjRef is null.");
    } catch (InvalidArgumentException ex) {
    // nothing to do
    }
    newTask = makeNewTask(taskService);
    newTask.addAttachment(createAttachment("DOCTYPE_DEFAULT", createObjectReference("COMPANY_A", "SYSTEM_B", "INSTANCE_B", "ArchiveId", null), "E-MAIL", "2018-01-15", createSimpleCustomProperties(3)));
    try {
        taskService.createTask(newTask);
        fail("Should have thrown an InvalidArgumentException, becasue ObjRef-Value is null.");
    } catch (InvalidArgumentException ex) {
    // nothing to do
    }
    newTask = makeNewTask(taskService);
    newTask.addAttachment(createAttachment("DOCTYPE_DEFAULT", createObjectReference("COMPANY_A", "SYSTEM_B", "INSTANCE_B", null, "12345678901234567890123456789012345678901234567890"), "E-MAIL", "2018-01-15", createSimpleCustomProperties(3)));
    try {
        taskService.createTask(newTask);
        fail("Should have thrown an InvalidArgumentException, becasue ObjRef-Type is null.");
    } catch (InvalidArgumentException ex) {
    // nothing to do
    }
    newTask = makeNewTask(taskService);
    newTask.addAttachment(createAttachment("DOCTYPE_DEFAULT", createObjectReference("COMPANY_A", "SYSTEM_B", null, "ArchiveId", "12345678901234567890123456789012345678901234567890"), "E-MAIL", "2018-01-15", createSimpleCustomProperties(3)));
    try {
        taskService.createTask(newTask);
        fail("Should have thrown an InvalidArgumentException, becasue ObjRef-SystemInstance is null.");
    } catch (InvalidArgumentException ex) {
    // nothing to do
    }
    newTask = makeNewTask(taskService);
    newTask.addAttachment(createAttachment("DOCTYPE_DEFAULT", createObjectReference("COMPANY_A", null, "INSTANCE_B", "ArchiveId", "12345678901234567890123456789012345678901234567890"), "E-MAIL", "2018-01-15", createSimpleCustomProperties(3)));
    try {
        taskService.createTask(newTask);
        fail("Should have thrown an InvalidArgumentException, becasue ObjRef-System is null.");
    } catch (InvalidArgumentException ex) {
    // nothing to do
    }
    newTask = makeNewTask(taskService);
    newTask.addAttachment(createAttachment("DOCTYPE_DEFAULT", createObjectReference(null, "SYSTEM_B", "INSTANCE_B", "ArchiveId", "12345678901234567890123456789012345678901234567890"), "E-MAIL", "2018-01-15", createSimpleCustomProperties(3)));
    try {
        taskService.createTask(newTask);
        fail("Should have thrown an InvalidArgumentException, becasue ObjRef-Company is null.");
    } catch (InvalidArgumentException ex) {
    // nothing to do
    }
}
Also used : Task(pro.taskana.Task) InvalidArgumentException(pro.taskana.exceptions.InvalidArgumentException) TaskService(pro.taskana.TaskService) TaskanaEngineProxyForTest(pro.taskana.impl.TaskanaEngineProxyForTest) AbstractAccTest(acceptance.AbstractAccTest) Test(org.junit.Test) WithAccessId(pro.taskana.security.WithAccessId)

Aggregations

InvalidArgumentException (pro.taskana.exceptions.InvalidArgumentException)41 Test (org.junit.Test)24 AbstractAccTest (acceptance.AbstractAccTest)21 WithAccessId (pro.taskana.security.WithAccessId)19 TaskService (pro.taskana.TaskService)18 TaskSummary (pro.taskana.TaskSummary)16 TaskanaEngineProxyForTest (pro.taskana.impl.TaskanaEngineProxyForTest)12 NotAuthorizedException (pro.taskana.exceptions.NotAuthorizedException)11 ArrayList (java.util.ArrayList)7 List (java.util.List)7 Task (pro.taskana.Task)7 Workbasket (pro.taskana.Workbasket)7 Classification (pro.taskana.Classification)6 ClassificationNotFoundException (pro.taskana.exceptions.ClassificationNotFoundException)6 SQLException (java.sql.SQLException)5 ClassificationSummary (pro.taskana.ClassificationSummary)5 WorkbasketAccessItem (pro.taskana.WorkbasketAccessItem)5 WorkbasketService (pro.taskana.WorkbasketService)5 Instant (java.time.Instant)4 Collectors (java.util.stream.Collectors)4