Search in sources :

Example 1 with SystemException

use of pro.taskana.common.api.exceptions.SystemException in project taskana by Taskana.

the class TaskHistoryEventRepresentationModelAssembler method toModel.

@NonNull
@Override
public TaskHistoryEventRepresentationModel toModel(@NonNull TaskHistoryEvent historyEvent) {
    TaskHistoryEventRepresentationModel repModel = new TaskHistoryEventRepresentationModel();
    repModel.setTaskHistoryId(historyEvent.getId());
    repModel.setBusinessProcessId(historyEvent.getBusinessProcessId());
    repModel.setParentBusinessProcessId(historyEvent.getParentBusinessProcessId());
    repModel.setTaskId(historyEvent.getTaskId());
    repModel.setEventType(historyEvent.getEventType());
    repModel.setCreated(historyEvent.getCreated());
    repModel.setUserId(historyEvent.getUserId());
    repModel.setUserLongName(historyEvent.getUserLongName());
    repModel.setDomain(historyEvent.getDomain());
    repModel.setWorkbasketKey(historyEvent.getWorkbasketKey());
    repModel.setPorCompany(historyEvent.getPorCompany());
    repModel.setPorType(historyEvent.getPorType());
    repModel.setPorInstance(historyEvent.getPorInstance());
    repModel.setPorSystem(historyEvent.getPorSystem());
    repModel.setPorValue(historyEvent.getPorValue());
    repModel.setTaskOwnerLongName(historyEvent.getTaskOwnerLongName());
    repModel.setTaskClassificationKey(historyEvent.getTaskClassificationKey());
    repModel.setTaskClassificationCategory(historyEvent.getTaskClassificationCategory());
    repModel.setAttachmentClassificationKey(historyEvent.getAttachmentClassificationKey());
    repModel.setOldValue(historyEvent.getOldValue());
    repModel.setNewValue(historyEvent.getNewValue());
    repModel.setCustom1(historyEvent.getCustomAttribute(TaskHistoryCustomField.CUSTOM_1));
    repModel.setCustom2(historyEvent.getCustomAttribute(TaskHistoryCustomField.CUSTOM_2));
    repModel.setCustom3(historyEvent.getCustomAttribute(TaskHistoryCustomField.CUSTOM_3));
    repModel.setCustom4(historyEvent.getCustomAttribute(TaskHistoryCustomField.CUSTOM_4));
    repModel.setDetails(historyEvent.getDetails());
    try {
        repModel.add(linkTo(methodOn(TaskHistoryEventController.class).getTaskHistoryEvent(historyEvent.getId())).withSelfRel());
    } catch (Exception e) {
        throw new SystemException("caught unexpected Exception", e);
    }
    return repModel;
}
Also used : SystemException(pro.taskana.common.api.exceptions.SystemException) TaskHistoryEventRepresentationModel(pro.taskana.simplehistory.rest.models.TaskHistoryEventRepresentationModel) SystemException(pro.taskana.common.api.exceptions.SystemException) NonNull(org.springframework.lang.NonNull)

Example 2 with SystemException

use of pro.taskana.common.api.exceptions.SystemException in project taskana by Taskana.

the class ClassificationQueryImpl method list.

@Override
public List<ClassificationSummary> list(int offset, int limit) {
    List<ClassificationSummary> result = new ArrayList<>();
    try {
        taskanaEngine.openConnection();
        RowBounds rowBounds = new RowBounds(offset, limit);
        result = taskanaEngine.getSqlSession().selectList(LINK_TO_SUMMARYMAPPER, this, rowBounds);
        return result;
    } catch (PersistenceException e) {
        if (e.getMessage().contains("ERRORCODE=-4470")) {
            TaskanaRuntimeException ex = new SystemException("The offset beginning was set over the amount of result-rows.", e.getCause());
            ex.setStackTrace(e.getStackTrace());
            throw ex;
        }
        throw e;
    } finally {
        taskanaEngine.returnConnection();
    }
}
Also used : SystemException(pro.taskana.common.api.exceptions.SystemException) ClassificationSummary(pro.taskana.classification.api.models.ClassificationSummary) ArrayList(java.util.ArrayList) PersistenceException(org.apache.ibatis.exceptions.PersistenceException) RowBounds(org.apache.ibatis.session.RowBounds) TaskanaRuntimeException(pro.taskana.common.api.exceptions.TaskanaRuntimeException)

Example 3 with SystemException

use of pro.taskana.common.api.exceptions.SystemException in project taskana by Taskana.

the class WorkbasketRepresentationModelAssembler method toModel.

@NonNull
@Override
public WorkbasketRepresentationModel toModel(@NonNull Workbasket workbasket) {
    WorkbasketRepresentationModel repModel = new WorkbasketRepresentationModel();
    repModel.setWorkbasketId(workbasket.getId());
    repModel.setKey(workbasket.getKey());
    repModel.setName(workbasket.getName());
    repModel.setDomain(workbasket.getDomain());
    repModel.setType(workbasket.getType());
    repModel.setDescription(workbasket.getDescription());
    repModel.setOwner(workbasket.getOwner());
    repModel.setMarkedForDeletion(workbasket.isMarkedForDeletion());
    repModel.setCustom1(workbasket.getCustomField(WorkbasketCustomField.CUSTOM_1));
    repModel.setCustom2(workbasket.getCustomField(WorkbasketCustomField.CUSTOM_2));
    repModel.setCustom3(workbasket.getCustomField(WorkbasketCustomField.CUSTOM_3));
    repModel.setCustom4(workbasket.getCustomField(WorkbasketCustomField.CUSTOM_4));
    repModel.setOrgLevel1(workbasket.getOrgLevel1());
    repModel.setOrgLevel2(workbasket.getOrgLevel2());
    repModel.setOrgLevel3(workbasket.getOrgLevel3());
    repModel.setOrgLevel4(workbasket.getOrgLevel4());
    repModel.setCreated(workbasket.getCreated());
    repModel.setModified(workbasket.getModified());
    try {
        return addLinks(repModel, workbasket);
    } catch (Exception e) {
        throw new SystemException("caught unexpected Exception.", e.getCause());
    }
}
Also used : WorkbasketRepresentationModel(pro.taskana.workbasket.rest.models.WorkbasketRepresentationModel) SystemException(pro.taskana.common.api.exceptions.SystemException) NotAuthorizedException(pro.taskana.common.api.exceptions.NotAuthorizedException) WorkbasketNotFoundException(pro.taskana.workbasket.api.exceptions.WorkbasketNotFoundException) SystemException(pro.taskana.common.api.exceptions.SystemException) NonNull(org.springframework.lang.NonNull)

Example 4 with SystemException

use of pro.taskana.common.api.exceptions.SystemException in project taskana by Taskana.

the class JobRunnerAccTest method should_onlyExecuteJobOnce_When_MultipleThreadsTryToRunJobsAtTheSameTime.

@Test
void should_onlyExecuteJobOnce_When_MultipleThreadsTryToRunJobsAtTheSameTime() throws Exception {
    // for some reason clearing the job table is not enough..
    resetDb(true);
    assertThat(jobService.findJobsToRun()).isEmpty();
    ScheduledJob job = createJob(Instant.now().minus(5, ChronoUnit.MINUTES));
    assertThat(jobService.findJobsToRun()).containsExactly(job);
    ParallelThreadHelper.runInThread(() -> {
        try {
            TaskanaEngine taskanaEngine = taskanaEngineConfiguration.buildTaskanaEngine(ConnectionManagementMode.AUTOCOMMIT);
            DataSource dataSource = DataSourceGenerator.getDataSource();
            // We have to slow down the transaction.
            // This is necessary to guarantee the execution of
            // both test threads and therefore test the database lock.
            // Without the slow down the test threads would execute too fast and
            // would not request executable jobs from the database at the same time.
            // TODO: please fix this. With the slowdown the test suite fails often
            // dataSource = slowDownDatabaseTransaction(dataSource);
            PlainJavaTransactionProvider transactionProvider = new PlainJavaTransactionProvider(taskanaEngine, dataSource);
            JobRunner runner = new JobRunner(taskanaEngine);
            runner.registerTransactionProvider(transactionProvider);
            runner.runJobs();
        } catch (Exception e) {
            throw new SystemException("Caught Exception", e);
        }
    }, 2);
    // runEvery is set to P1D Therefore we need to check which jobs run tomorrow.
    // Just to be sure the jobs are found we will look for any job scheduled in the next 2 days.
    List<ScheduledJob> jobsToRun = getJobMapper().findJobsToRun(Instant.now().plus(2, ChronoUnit.DAYS));
    assertThat(jobsToRun).hasSize(1).doesNotContain(job);
}
Also used : JobRunner(pro.taskana.common.internal.jobs.JobRunner) TaskanaEngine(pro.taskana.common.api.TaskanaEngine) PlainJavaTransactionProvider(pro.taskana.common.internal.jobs.PlainJavaTransactionProvider) SystemException(pro.taskana.common.api.exceptions.SystemException) ScheduledJob(pro.taskana.common.api.ScheduledJob) SystemException(pro.taskana.common.api.exceptions.SystemException) DataSource(javax.sql.DataSource) AbstractAccTest(acceptance.AbstractAccTest) Test(org.junit.jupiter.api.Test)

Example 5 with SystemException

use of pro.taskana.common.api.exceptions.SystemException in project taskana by Taskana.

the class WorkbasketCleanupJob method execute.

@Override
public void execute() throws TaskanaException {
    LOGGER.info("Running job to delete all workbaskets marked for deletion");
    try {
        List<String> workbasketsMarkedForDeletion = getWorkbasketsMarkedForDeletion();
        int totalNumberOfWorkbasketDeleted = CollectionUtil.partitionBasedOnSize(workbasketsMarkedForDeletion, batchSize).stream().mapToInt(this::deleteWorkbasketsTransactionally).sum();
        LOGGER.info("Job ended successfully. {} workbaskets deleted.", totalNumberOfWorkbasketDeleted);
    } catch (Exception e) {
        throw new SystemException("Error while processing WorkbasketCleanupJob.", e);
    }
}
Also used : SystemException(pro.taskana.common.api.exceptions.SystemException) TaskanaException(pro.taskana.common.api.exceptions.TaskanaException) NotAuthorizedException(pro.taskana.common.api.exceptions.NotAuthorizedException) InvalidArgumentException(pro.taskana.common.api.exceptions.InvalidArgumentException) SystemException(pro.taskana.common.api.exceptions.SystemException)

Aggregations

SystemException (pro.taskana.common.api.exceptions.SystemException)44 ArrayList (java.util.ArrayList)6 PersistenceException (org.apache.ibatis.exceptions.PersistenceException)6 RowBounds (org.apache.ibatis.session.RowBounds)6 NotAuthorizedException (pro.taskana.common.api.exceptions.NotAuthorizedException)6 List (java.util.List)5 Collectors (java.util.stream.Collectors)5 NonNull (org.springframework.lang.NonNull)5 TaskanaRuntimeException (pro.taskana.common.api.exceptions.TaskanaRuntimeException)5 Instant (java.time.Instant)4 Map (java.util.Map)4 Optional (java.util.Optional)4 Method (java.lang.reflect.Method)3 Connection (java.sql.Connection)3 SQLException (java.sql.SQLException)3 Arrays (java.util.Arrays)3 HashMap (java.util.HashMap)3 Predicate.not (java.util.function.Predicate.not)3 ClassificationSummary (pro.taskana.classification.api.models.ClassificationSummary)3 InvalidArgumentException (pro.taskana.common.api.exceptions.InvalidArgumentException)3