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);
}
}
}
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);
}
}
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;
}
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;
}
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);
}
Aggregations