Search in sources :

Example 6 with SystemException

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

the class TaskServiceImpl method standardSettings.

private void standardSettings(TaskImpl task, Classification classification, PrioDurationHolder prioDurationFromAttachments) {
    Instant now = Instant.now();
    task.setId(IdGenerator.generateWithPrefix(ID_PREFIX_TASK));
    task.setState(TaskState.READY);
    task.setCreated(now);
    task.setModified(now);
    task.setRead(false);
    task.setTransferred(false);
    String creator = CurrentUserContext.getUserid();
    if (taskanaEngine.getConfiguration().isSecurityEnabled()) {
        if (creator == null) {
            throw new SystemException("TaskanaSecurity is enabled, but the current UserId is NULL while creating a Task.");
        }
    }
    task.setCreator(creator);
    if (task.getPlanned() == null) {
        task.setPlanned(now);
    }
    // if no business process id is provided, a unique id is created.
    if (task.getBusinessProcessId() == null) {
        task.setBusinessProcessId(IdGenerator.generateWithPrefix(ID_PREFIX_BUSINESS_PROCESS));
    }
    if (classification != null) {
        PrioDurationHolder finalPrioDuration = getNewPrioDuration(prioDurationFromAttachments.getPrio(), prioDurationFromAttachments.getDuration(), classification.getPriority(), classification.getServiceLevel());
        Duration finalDuration = finalPrioDuration.getDuration();
        if (finalDuration != null && !MAX_DURATION.equals(finalDuration)) {
            long days = converter.convertWorkingDaysToDays(task.getPlanned(), finalDuration.toDays());
            Instant due = task.getPlanned().plus(Duration.ofDays(days));
            task.setDue(due);
        }
        task.setPriority(finalPrioDuration.getPrio());
    }
    if (task.getName() == null) {
        task.setName(classification.getName());
    }
    if (task.getDescription() == null) {
        task.setDescription(classification.getDescription());
    }
    // insert Attachments if needed
    List<Attachment> attachments = task.getAttachments();
    if (attachments != null) {
        for (Attachment attachment : attachments) {
            AttachmentImpl attachmentImpl = (AttachmentImpl) attachment;
            attachmentImpl.setId(IdGenerator.generateWithPrefix(ID_PREFIX_ATTACHMENT));
            attachmentImpl.setTaskId(task.getId());
            attachmentImpl.setCreated(now);
            attachmentImpl.setModified(now);
            attachmentMapper.insert(attachmentImpl);
        }
    }
}
Also used : SystemException(pro.taskana.exceptions.SystemException) Instant(java.time.Instant) Duration(java.time.Duration) Attachment(pro.taskana.Attachment)

Example 7 with SystemException

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

the class TaskServiceImpl method addClassificationSummariesToTaskSummaries.

private void addClassificationSummariesToTaskSummaries(List<TaskSummaryImpl> tasks, List<ClassificationSummary> classifications) {
    if (tasks == null || tasks.isEmpty()) {
        return;
    }
    // assign query results to appropriate tasks.
    for (TaskSummaryImpl task : tasks) {
        String classificationId = task.getClassificationSummary().getId();
        ClassificationSummary aClassification = classifications.stream().filter(c -> c.getId().equals(classificationId)).findFirst().orElse(null);
        if (aClassification == null) {
            LOGGER.error("Didnt find a Classification for task ");
            throw new SystemException("Did not find a Classification for task (Id=" + task.getTaskId() + ",classification=" + task.getClassificationSummary().getId() + ")");
        }
        // set the classification on the task object
        task.setClassificationSummary(aClassification);
    }
}
Also used : SystemException(pro.taskana.exceptions.SystemException) ClassificationSummary(pro.taskana.ClassificationSummary)

Example 8 with SystemException

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

the class TaskServiceImpl method addClassificationSummariesToAttachments.

private List<Attachment> addClassificationSummariesToAttachments(TaskImpl task, List<AttachmentImpl> attachmentImpls, List<ClassificationSummary> classifications) {
    if (attachmentImpls == null || attachmentImpls.isEmpty()) {
        return new ArrayList<>();
    }
    List<Attachment> result = new ArrayList<>();
    for (AttachmentImpl att : attachmentImpls) {
        // find the associated task to use the correct domain
        ClassificationSummary aClassification = classifications.stream().filter(c -> c != null & c.getId().equals(att.getClassificationSummary().getId())).findFirst().orElse(null);
        if (aClassification == null) {
            LOGGER.error("Could not find a Classification for attachment {}.", att);
            throw new SystemException("Could not find a Classification for attachment " + att);
        }
        att.setClassificationSummary(aClassification);
        result.add(att);
    }
    return result;
}
Also used : SystemException(pro.taskana.exceptions.SystemException) ClassificationSummary(pro.taskana.ClassificationSummary) ArrayList(java.util.ArrayList) Attachment(pro.taskana.Attachment)

Example 9 with SystemException

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

the class TaskanaEngineConfiguration method readPropertiesFromFile.

private Properties readPropertiesFromFile(String propertiesFile) {
    Properties props = new Properties();
    boolean loadFromClasspath = loadFromClasspath(propertiesFile);
    try {
        if (loadFromClasspath) {
            InputStream inputStream = this.getClass().getResourceAsStream(propertiesFile);
            if (inputStream == null) {
                LOGGER.error("taskana properties file {} was not found on classpath.", propertiesFile);
            } else {
                props.load(new InputStreamReader(inputStream));
                LOGGER.debug("Role properties were loaded from file {} from classpath.", propertiesFile);
            }
        } else {
            props.load(new FileInputStream(propertiesFile));
            LOGGER.debug("Role properties were loaded from file {}.", propertiesFile);
        }
    } catch (IOException e) {
        LOGGER.error("caught IOException when processing properties file {}.", propertiesFile);
        throw new SystemException("internal System error when processing properties file " + propertiesFile);
    }
    return props;
}
Also used : InputStreamReader(java.io.InputStreamReader) SystemException(pro.taskana.exceptions.SystemException) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) IOException(java.io.IOException) Properties(java.util.Properties) FileInputStream(java.io.FileInputStream)

Example 10 with SystemException

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

the class TaskanaEngineImpl method createSqlSessionManager.

/**
 * This method creates the sqlSessionManager of myBatis. It integrates all the SQL mappers and sets the databaseId
 * attribute.
 *
 * @return a {@link SqlSessionFactory}
 */
protected SqlSessionManager createSqlSessionManager() {
    Environment environment = new Environment(DEFAULT, this.transactionFactory, taskanaEngineConfiguration.getDatasource());
    Configuration configuration = new Configuration(environment);
    // set databaseId
    String databaseProductName;
    try (Connection con = taskanaEngineConfiguration.getDatasource().getConnection()) {
        databaseProductName = con.getMetaData().getDatabaseProductName();
        if (databaseProductName.contains("DB2")) {
            configuration.setDatabaseId("db2");
        } else if (databaseProductName.contains("H2")) {
            configuration.setDatabaseId("h2");
        } else {
            LOGGER.error("Method createSqlSessionManager() didn't find database with name {}. Throwing UnsupportedDatabaseException", databaseProductName);
            throw new UnsupportedDatabaseException(databaseProductName);
        }
    } catch (SQLException e) {
        LOGGER.error("Method createSqlSessionManager() could not open a connection to the database. No databaseId has been set.", e);
        throw new SystemException("Method createSqlSessionManager() could not open a connection to the database. No databaseId has been set.");
    }
    // add mappers
    configuration.addMapper(TaskMapper.class);
    configuration.addMapper(TaskMonitorMapper.class);
    configuration.addMapper(WorkbasketMapper.class);
    configuration.addMapper(DistributionTargetMapper.class);
    configuration.addMapper(ClassificationMapper.class);
    configuration.addMapper(WorkbasketAccessMapper.class);
    configuration.addMapper(ObjectReferenceMapper.class);
    configuration.addMapper(QueryMapper.class);
    configuration.addMapper(AttachmentMapper.class);
    configuration.addMapper(JobMapper.class);
    configuration.getTypeHandlerRegistry().register(MapTypeHandler.class);
    SqlSessionFactory localSessionFactory = new SqlSessionFactoryBuilder().build(configuration);
    return SqlSessionManager.newInstance(localSessionFactory);
}
Also used : UnsupportedDatabaseException(pro.taskana.exceptions.UnsupportedDatabaseException) TaskanaEngineConfiguration(pro.taskana.configuration.TaskanaEngineConfiguration) Configuration(org.apache.ibatis.session.Configuration) SystemException(pro.taskana.exceptions.SystemException) SQLException(java.sql.SQLException) Connection(java.sql.Connection) SqlSessionFactory(org.apache.ibatis.session.SqlSessionFactory) Environment(org.apache.ibatis.mapping.Environment) SqlSessionFactoryBuilder(org.apache.ibatis.session.SqlSessionFactoryBuilder)

Aggregations

SystemException (pro.taskana.exceptions.SystemException)10 ClassificationSummary (pro.taskana.ClassificationSummary)4 Attachment (pro.taskana.Attachment)3 NotAuthorizedException (pro.taskana.exceptions.NotAuthorizedException)2 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1 Connection (java.sql.Connection)1 SQLException (java.sql.SQLException)1 Duration (java.time.Duration)1 Instant (java.time.Instant)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 Properties (java.util.Properties)1 StringTokenizer (java.util.StringTokenizer)1 Environment (org.apache.ibatis.mapping.Environment)1 Configuration (org.apache.ibatis.session.Configuration)1 SqlSessionFactory (org.apache.ibatis.session.SqlSessionFactory)1 SqlSessionFactoryBuilder (org.apache.ibatis.session.SqlSessionFactoryBuilder)1