TSK-44 allow to add a list of attachments to a Task
This commit is contained in:
parent
bc338b1dc7
commit
8b26f7564d
|
@ -0,0 +1,116 @@
|
|||
package pro.taskana;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
import java.util.Map;
|
||||
|
||||
import pro.taskana.model.ObjectReference;
|
||||
|
||||
/**
|
||||
* Attachment-Interface to specify Attachment Attributes.
|
||||
*/
|
||||
public interface Attachment {
|
||||
|
||||
/**
|
||||
* Returns the current id of the attachment.
|
||||
*
|
||||
* @return ID of attachment
|
||||
*/
|
||||
String getId();
|
||||
|
||||
/**
|
||||
* Returns the id of the associated task.
|
||||
*
|
||||
* @return taskId
|
||||
*/
|
||||
String getTaskId();
|
||||
|
||||
/**
|
||||
* Returns the time when the attachment was created.
|
||||
*
|
||||
* @return the created time as {@link Timestamp}
|
||||
*/
|
||||
Timestamp getCreated();
|
||||
|
||||
/**
|
||||
* Returns the time when the attachment was last modified.
|
||||
*
|
||||
* @return modified {@link Timestamp} of the attachment
|
||||
*/
|
||||
Timestamp getModified();
|
||||
|
||||
/**
|
||||
* Returns the classification of the attachment.
|
||||
*
|
||||
* @return the {@link Classification} of this attachment
|
||||
*/
|
||||
Classification getClassification();
|
||||
|
||||
/**
|
||||
* Set the classification for this attachment.
|
||||
*
|
||||
* @param classification
|
||||
* the {@link Classification} for this attachment
|
||||
*/
|
||||
void setClassification(Classification classification);
|
||||
|
||||
/**
|
||||
* Returns the {@link ObjectReference primaryObjectReference} of the attachment.
|
||||
*
|
||||
* @return {@link ObjectReference primaryObjectReference} of the attachment
|
||||
**/
|
||||
ObjectReference getObjectReference();
|
||||
|
||||
/**
|
||||
* Sets the {@link ObjectReference primaryObjectReference} of the attachment.
|
||||
*
|
||||
* @param objectReference
|
||||
* the {@link ObjectReference primaryObjectReference} of the attachment
|
||||
*/
|
||||
void setObjectReference(ObjectReference objectReference);
|
||||
|
||||
/**
|
||||
* Returns the Channel on which the attachment was received.
|
||||
*
|
||||
* @return the Channel on which the attachment was received.
|
||||
**/
|
||||
String getChannel();
|
||||
|
||||
/**
|
||||
* Sets the Channel on which the attachment was received.
|
||||
*
|
||||
* @param channel
|
||||
* the channel on which the attachment was received
|
||||
*/
|
||||
void setChannel(String channel);
|
||||
|
||||
/**
|
||||
* Returns the time when this attachment was received.
|
||||
*
|
||||
* @return received time as exact {@link Timestamp}
|
||||
*/
|
||||
Timestamp getReceived();
|
||||
|
||||
/**
|
||||
* Sets the time when the attachment was received.
|
||||
*
|
||||
* @param received
|
||||
* the time as {@link Timestamp} when the attachment was received
|
||||
**/
|
||||
void setReceived(Timestamp received);
|
||||
|
||||
/**
|
||||
* Returns the custom attributes of this attachment.
|
||||
*
|
||||
* @return customAttributes as {@link Map}
|
||||
*/
|
||||
Map<String, Object> getCustomAttributes();
|
||||
|
||||
/**
|
||||
* Sets the custom attribute Map of the attachment.
|
||||
*
|
||||
* @param customAttributes
|
||||
* a {@link Map} that contains the custom attributes of the attachment as key, value pairs
|
||||
*/
|
||||
void setCustomAttributes(Map<String, Object> customAttributes);
|
||||
|
||||
}
|
|
@ -1,6 +1,7 @@
|
|||
package pro.taskana;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import pro.taskana.model.ObjectReference;
|
||||
|
@ -356,4 +357,19 @@ public interface Task {
|
|||
* the custom10 property of the task
|
||||
*/
|
||||
void setCustom10(String custom10);
|
||||
|
||||
/**
|
||||
* Add an attachment.
|
||||
*
|
||||
* @param attachment
|
||||
* the {@link Attachment attachment} to be added to the task
|
||||
*/
|
||||
void addAttachment(Attachment attachment);
|
||||
|
||||
/**
|
||||
* Return the attachments for this task.
|
||||
*
|
||||
* @return the {@link List list} of {@link Attachment attachments} for this task
|
||||
*/
|
||||
List<Attachment> getAttachments();
|
||||
}
|
||||
|
|
|
@ -193,10 +193,17 @@ public interface TaskService {
|
|||
/**
|
||||
* Returns a not persisted instance of {@link Task}.
|
||||
*
|
||||
* @return task - with default values
|
||||
* @return an empty new Task
|
||||
*/
|
||||
Task newTask();
|
||||
|
||||
/**
|
||||
* Returns a not persisted instance of {@link Attachment}.
|
||||
*
|
||||
* @return an empty new Attachment
|
||||
*/
|
||||
Attachment newAttachment();
|
||||
|
||||
/**
|
||||
* Update a task.
|
||||
*
|
||||
|
|
|
@ -0,0 +1,142 @@
|
|||
package pro.taskana.impl;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
import java.util.Map;
|
||||
|
||||
import pro.taskana.Attachment;
|
||||
import pro.taskana.Classification;
|
||||
import pro.taskana.model.ObjectReference;
|
||||
|
||||
/**
|
||||
* Attachment entity.
|
||||
*
|
||||
* @author bbr
|
||||
*/
|
||||
public class AttachmentImpl implements Attachment {
|
||||
|
||||
private String id;
|
||||
private String taskId;
|
||||
private Timestamp created;
|
||||
private Timestamp modified;
|
||||
private Classification classification;
|
||||
private ObjectReference objectReference;
|
||||
private String channel;
|
||||
private Timestamp received;
|
||||
private Map<String, Object> customAttributes;
|
||||
|
||||
AttachmentImpl() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTaskId() {
|
||||
return taskId;
|
||||
}
|
||||
|
||||
public void setTaskId(String taskId) {
|
||||
this.taskId = taskId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Timestamp getCreated() {
|
||||
return created;
|
||||
}
|
||||
|
||||
public void setCreated(Timestamp created) {
|
||||
this.created = created;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Timestamp getModified() {
|
||||
return modified;
|
||||
}
|
||||
|
||||
public void setModified(Timestamp modified) {
|
||||
this.modified = modified;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Classification getClassification() {
|
||||
return classification;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setClassification(Classification classification) {
|
||||
this.classification = classification;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectReference getObjectReference() {
|
||||
return objectReference;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setObjectReference(ObjectReference objectReference) {
|
||||
this.objectReference = objectReference;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getChannel() {
|
||||
return channel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setChannel(String channel) {
|
||||
this.channel = channel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Timestamp getReceived() {
|
||||
return received;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setReceived(Timestamp received) {
|
||||
this.received = received;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> getCustomAttributes() {
|
||||
return customAttributes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCustomAttributes(Map<String, Object> customAttributes) {
|
||||
this.customAttributes = customAttributes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append("Attachment [id=");
|
||||
builder.append(id);
|
||||
builder.append(", taskId=");
|
||||
builder.append(taskId);
|
||||
builder.append(", created=");
|
||||
builder.append(created);
|
||||
builder.append(", modified=");
|
||||
builder.append(modified);
|
||||
builder.append(", classification=");
|
||||
builder.append(classification);
|
||||
builder.append(", objectReference=");
|
||||
builder.append(objectReference);
|
||||
builder.append(", channel=");
|
||||
builder.append(channel);
|
||||
builder.append(", received=");
|
||||
builder.append(received);
|
||||
builder.append(", customAttributes=");
|
||||
builder.append(customAttributes);
|
||||
builder.append("]");
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
}
|
|
@ -1,9 +1,12 @@
|
|||
package pro.taskana.impl;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import pro.taskana.Attachment;
|
||||
import pro.taskana.Classification;
|
||||
import pro.taskana.Task;
|
||||
import pro.taskana.model.ObjectReference;
|
||||
|
@ -40,6 +43,7 @@ public class TaskImpl implements Task {
|
|||
private String porSystemInstance; // auxiliary field needed to avoid 2nd query for primaryObjRef in TaskMapper
|
||||
private String porType; // auxiliary field needed to avoid 2nd query for primaryObjRef in TaskMapper
|
||||
private String porValue; // auxiliary field needed to avoid 2nd query for primaryObjRef in TaskMapper
|
||||
private List<Attachment> attachments;
|
||||
private String custom1;
|
||||
private String custom2;
|
||||
private String custom3;
|
||||
|
@ -341,6 +345,23 @@ public class TaskImpl implements Task {
|
|||
this.custom10 = custom10;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addAttachment(Attachment attachment) {
|
||||
if (attachments == null) {
|
||||
attachments = new ArrayList<Attachment>();
|
||||
}
|
||||
attachments.add(attachment);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Attachment> getAttachments() {
|
||||
return attachments;
|
||||
}
|
||||
|
||||
public void setAttachments(List<Attachment> attachments) {
|
||||
this.attachments = attachments;
|
||||
}
|
||||
|
||||
public String getPorCompany() {
|
||||
return porCompany;
|
||||
}
|
||||
|
@ -434,6 +455,8 @@ public class TaskImpl implements Task {
|
|||
builder.append(porType);
|
||||
builder.append(", porValue=");
|
||||
builder.append(porValue);
|
||||
builder.append(", attachments=");
|
||||
builder.append(attachments);
|
||||
builder.append(", custom1=");
|
||||
builder.append(custom1);
|
||||
builder.append(", custom2=");
|
||||
|
|
|
@ -9,6 +9,7 @@ import java.util.List;
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import pro.taskana.Attachment;
|
||||
import pro.taskana.Classification;
|
||||
import pro.taskana.ClassificationService;
|
||||
import pro.taskana.Task;
|
||||
|
@ -33,6 +34,7 @@ import pro.taskana.model.ObjectReference;
|
|||
import pro.taskana.model.TaskState;
|
||||
import pro.taskana.model.TaskSummary;
|
||||
import pro.taskana.model.WorkbasketAuthorization;
|
||||
import pro.taskana.model.mappings.AttachmentMapper;
|
||||
import pro.taskana.model.mappings.ObjectReferenceMapper;
|
||||
import pro.taskana.model.mappings.TaskMapper;
|
||||
import pro.taskana.security.CurrentUserContext;
|
||||
|
@ -44,6 +46,7 @@ public class TaskServiceImpl implements TaskService {
|
|||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(TaskServiceImpl.class);
|
||||
private static final String ID_PREFIX_OBJECT_REFERENCE = "ORI";
|
||||
private static final String ID_PREFIX_ATTACHMENT = "ATT";
|
||||
private static final String ID_PREFIX_TASK = "TKI";
|
||||
private static final String ID_PREFIX_BUSINESS_PROCESS = "BPI";
|
||||
private TaskanaEngine taskanaEngine;
|
||||
|
@ -52,9 +55,10 @@ public class TaskServiceImpl implements TaskService {
|
|||
private ClassificationService classificationService;
|
||||
private TaskMapper taskMapper;
|
||||
private ObjectReferenceMapper objectReferenceMapper;
|
||||
private AttachmentMapper attachmentMapper;
|
||||
|
||||
public TaskServiceImpl(TaskanaEngine taskanaEngine, TaskMapper taskMapper,
|
||||
ObjectReferenceMapper objectReferenceMapper) {
|
||||
ObjectReferenceMapper objectReferenceMapper, AttachmentMapper attachmentMapper) {
|
||||
super();
|
||||
this.taskanaEngine = taskanaEngine;
|
||||
this.taskanaEngineImpl = (TaskanaEngineImpl) taskanaEngine;
|
||||
|
@ -62,6 +66,7 @@ public class TaskServiceImpl implements TaskService {
|
|||
this.objectReferenceMapper = objectReferenceMapper;
|
||||
this.workbasketService = taskanaEngineImpl.getWorkbasketService();
|
||||
this.classificationService = taskanaEngineImpl.getClassificationService();
|
||||
this.attachmentMapper = attachmentMapper;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -172,8 +177,9 @@ public class TaskServiceImpl implements TaskService {
|
|||
this.classificationService.getClassification(classification.getKey(),
|
||||
classification.getDomain());
|
||||
|
||||
validatePrimaryObjectReference(task.getPrimaryObjRef(), "Task");
|
||||
validateAttachments(task);
|
||||
standardSettings(task);
|
||||
validatePrimaryObjectReference(task);
|
||||
this.taskMapper.insert(task);
|
||||
LOGGER.debug("Method createTask() created Task '{}'.", task.getId());
|
||||
}
|
||||
|
@ -354,6 +360,19 @@ public class TaskServiceImpl implements TaskService {
|
|||
}
|
||||
}
|
||||
|
||||
// insert Attachments if needed
|
||||
List<Attachment> attachments = task.getAttachments();
|
||||
if (attachments != null) {
|
||||
for (Attachment attachment : attachments) {
|
||||
AttachmentImpl attImpl = (AttachmentImpl) attachment;
|
||||
attImpl.setId(IdGenerator.generateWithPrefix(ID_PREFIX_ATTACHMENT));
|
||||
attImpl.setTaskId(task.getId());
|
||||
attImpl.setCreated(now);
|
||||
attImpl.setModified(now);
|
||||
attachmentMapper.insert(attImpl);
|
||||
}
|
||||
}
|
||||
|
||||
// insert ObjectReference if needed. Comment this out for the scope of tsk-123
|
||||
// if (task.getPrimaryObjRef() != null) {
|
||||
// ObjectReference objectReference = this.objectReferenceMapper.findByObjectReference(task.getPrimaryObjRef());
|
||||
|
@ -397,6 +416,11 @@ public class TaskServiceImpl implements TaskService {
|
|||
return new TaskImpl();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Attachment newAttachment() {
|
||||
return new AttachmentImpl();
|
||||
}
|
||||
|
||||
static void setPrimaryObjRef(TaskImpl task) {
|
||||
ObjectReference objRef = new ObjectReference();
|
||||
objRef.setCompany(task.getPorCompany());
|
||||
|
@ -407,27 +431,46 @@ public class TaskServiceImpl implements TaskService {
|
|||
task.setPrimaryObjRef(objRef);
|
||||
}
|
||||
|
||||
private void validatePrimaryObjectReference(TaskImpl task) throws InvalidArgumentException {
|
||||
private void validatePrimaryObjectReference(ObjectReference primObjRef, String objName)
|
||||
throws InvalidArgumentException {
|
||||
// check that all values in the primary ObjectReference are set correctly
|
||||
ObjectReference primObjRef = task.getPrimaryObjRef();
|
||||
if (primObjRef == null) {
|
||||
throw new InvalidArgumentException("primary ObjectReference of task must not be null");
|
||||
throw new InvalidArgumentException("primary ObjectReference of " + objName + " must not be null");
|
||||
} else if (primObjRef.getCompany() == null || primObjRef.getCompany().length() == 0) {
|
||||
throw new InvalidArgumentException("Company of primary ObjectReference of task must not be empty");
|
||||
throw new InvalidArgumentException(
|
||||
"Company of primary ObjectReference of " + objName + " must not be empty");
|
||||
} else if (primObjRef.getSystem() == null || primObjRef.getSystem().length() == 0) {
|
||||
throw new InvalidArgumentException("System of primary ObjectReference of task must not be empty");
|
||||
throw new InvalidArgumentException(
|
||||
"System of primary ObjectReference of " + objName + " must not be empty");
|
||||
} else if (primObjRef.getSystemInstance() == null || primObjRef.getSystemInstance().length() == 0) {
|
||||
throw new InvalidArgumentException("SystemInstance of primary ObjectReference of task must not be empty");
|
||||
throw new InvalidArgumentException(
|
||||
"SystemInstance of primary ObjectReference of " + objName + " must not be empty");
|
||||
} else if (primObjRef.getType() == null || primObjRef.getType().length() == 0) {
|
||||
throw new InvalidArgumentException("Type of primary ObjectReference of task must not be empty");
|
||||
throw new InvalidArgumentException("Type of primary ObjectReference of " + objName + " must not be empty");
|
||||
} else if (primObjRef.getValue() == null || primObjRef.getValue().length() == 0) {
|
||||
throw new InvalidArgumentException("Value of primary ObjectReference of task must not be empty");
|
||||
throw new InvalidArgumentException("Value of primary ObjectReference of " + objName + " must not be empty");
|
||||
}
|
||||
}
|
||||
|
||||
private void validateAttachments(TaskImpl task) throws InvalidArgumentException {
|
||||
List<Attachment> attachments = task.getAttachments();
|
||||
if (attachments == null || attachments.size() == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (Attachment attachment : attachments) {
|
||||
ObjectReference objRef = attachment.getObjectReference();
|
||||
validatePrimaryObjectReference(objRef, "Attachment");
|
||||
if (attachment.getClassification() == null) {
|
||||
throw new InvalidArgumentException("Classification of attachment " + attachment + " must not be null");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void standardUpdateActions(TaskImpl oldTaskImpl, TaskImpl newTaskImpl)
|
||||
throws InvalidArgumentException, ConcurrencyException {
|
||||
validatePrimaryObjectReference(newTaskImpl);
|
||||
validatePrimaryObjectReference(newTaskImpl.getPrimaryObjRef(), "Task");
|
||||
if (oldTaskImpl.getModified() != null && !oldTaskImpl.getModified().equals(newTaskImpl.getModified())
|
||||
|| oldTaskImpl.getClaimed() != null && !oldTaskImpl.getClaimed().equals(newTaskImpl.getClaimed())
|
||||
|| oldTaskImpl.getState() != null && !oldTaskImpl.getState().equals(newTaskImpl.getState())) {
|
||||
|
|
|
@ -23,6 +23,7 @@ import pro.taskana.configuration.TaskanaEngineConfiguration;
|
|||
import pro.taskana.exceptions.AutocommitFailedException;
|
||||
import pro.taskana.exceptions.ConnectionNotSetException;
|
||||
import pro.taskana.impl.persistence.MapTypeHandler;
|
||||
import pro.taskana.model.mappings.AttachmentMapper;
|
||||
import pro.taskana.model.mappings.ClassificationMapper;
|
||||
import pro.taskana.model.mappings.DistributionTargetMapper;
|
||||
import pro.taskana.model.mappings.ObjectReferenceMapper;
|
||||
|
@ -65,7 +66,7 @@ public class TaskanaEngineImpl implements TaskanaEngine {
|
|||
public TaskService getTaskService() {
|
||||
SqlSession session = this.sessionManager;
|
||||
TaskServiceImpl taskServiceImpl = new TaskServiceImpl(this, session.getMapper(TaskMapper.class),
|
||||
session.getMapper(ObjectReferenceMapper.class));
|
||||
session.getMapper(ObjectReferenceMapper.class), session.getMapper(AttachmentMapper.class));
|
||||
return taskServiceImpl;
|
||||
}
|
||||
|
||||
|
@ -233,6 +234,7 @@ public class TaskanaEngineImpl implements TaskanaEngine {
|
|||
configuration.addMapper(WorkbasketAccessMapper.class);
|
||||
configuration.addMapper(ObjectReferenceMapper.class);
|
||||
configuration.addMapper(QueryMapper.class);
|
||||
configuration.addMapper(AttachmentMapper.class);
|
||||
configuration.getTypeHandlerRegistry().register(MapTypeHandler.class);
|
||||
SqlSessionFactory sessionFactory = new SqlSessionFactoryBuilder().build(configuration);
|
||||
SqlSessionManager sessionManager = SqlSessionManager.newInstance(sessionFactory);
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
package pro.taskana.model.mappings;
|
||||
|
||||
import org.apache.ibatis.annotations.Insert;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import pro.taskana.impl.AttachmentImpl;
|
||||
|
||||
/**
|
||||
* This class is the mybatis mapping of Attachment.
|
||||
*/
|
||||
public interface AttachmentMapper {
|
||||
|
||||
@Insert("INSERT INTO ATTACHMENT (ID, TASK_ID, CREATED, MODIFIED, CLASSIFICATION_KEY, REF_COMPANY, REF_SYSTEM, REF_INSTANCE, REF_TYPE, REF_VALUE, CHANNEL, RECEIVED, CUSTOM_ATTRIBUTES) "
|
||||
+ "VALUES (#{att.id}, #{att.taskId}, #{att.created}, #{att.modified}, #{att.classification.key}, #{att.objectReference.company}, #{att.objectReference.system}, #{att.objectReference.systemInstance}, "
|
||||
+ " #{att.objectReference.type}, #{att.objectReference.value}, #{att.channel}, #{att.received}, #{att.customAttributes,jdbcType=BLOB,javaType=java.util.Map,typeHandler=pro.taskana.impl.persistence.MapTypeHandler} )")
|
||||
void insert(@Param("att") AttachmentImpl att);
|
||||
|
||||
}
|
|
@ -125,3 +125,20 @@ CREATE TABLE OBJECT_REFERENCE(
|
|||
TYPE VARCHAR(32) NOT NULL,
|
||||
VALUE VARCHAR(128) NOT NULL
|
||||
);
|
||||
|
||||
CREATE TABLE ATTACHMENT(
|
||||
ID CHAR(40) NOT NULL,
|
||||
TASK_ID CHAR(40) NOT NULL,
|
||||
CREATED TIMESTAMP NULL,
|
||||
MODIFIED TIMESTAMP NULL,
|
||||
CLASSIFICATION_KEY VARCHAR(32) NULL,
|
||||
REF_COMPANY VARCHAR(32) NOT NULL,
|
||||
REF_SYSTEM VARCHAR(32) NOT NULL,
|
||||
REF_INSTANCE VARCHAR(32) NOT NULL,
|
||||
REF_TYPE VARCHAR(32) NOT NULL,
|
||||
REF_VALUE VARCHAR(128) NOT NULL,
|
||||
CHANNEL VARCHAR(64) NULL,
|
||||
RECEIVED TIMESTAMP NULL,
|
||||
CUSTOM_ATTRIBUTES BLOB NULL,
|
||||
PRIMARY KEY (ID)
|
||||
);
|
|
@ -1,6 +1,7 @@
|
|||
package acceptance;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Timestamp;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
|
@ -8,10 +9,12 @@ import javax.sql.DataSource;
|
|||
|
||||
import org.junit.BeforeClass;
|
||||
|
||||
import pro.taskana.Attachment;
|
||||
import pro.taskana.TaskanaEngine;
|
||||
import pro.taskana.TaskanaEngine.ConnectionManagementMode;
|
||||
import pro.taskana.configuration.TaskanaEngineConfiguration;
|
||||
import pro.taskana.database.TestDataGenerator;
|
||||
import pro.taskana.exceptions.ClassificationNotFoundException;
|
||||
import pro.taskana.impl.TaskanaEngineImpl;
|
||||
import pro.taskana.impl.configuration.DBCleaner;
|
||||
import pro.taskana.impl.configuration.TaskanaEngineConfigurationTest;
|
||||
|
@ -63,4 +66,25 @@ public abstract class AbstractAccTest {
|
|||
return properties;
|
||||
}
|
||||
|
||||
protected Attachment createAttachment(String classificationKey, ObjectReference objRef,
|
||||
String channel, String receivedDate, Map<String, Object> customAttributes)
|
||||
throws ClassificationNotFoundException {
|
||||
Attachment attachment = taskanaEngine.getTaskService().newAttachment();
|
||||
attachment.setClassification(
|
||||
taskanaEngine.getClassificationService().getClassification(classificationKey, "DOMAIN_A"));
|
||||
attachment.setObjectReference(objRef);
|
||||
attachment.setChannel(channel);
|
||||
Timestamp receivedTimestamp = null;
|
||||
if (receivedDate != null && receivedDate.length() < 11) {
|
||||
// contains only the date, not the time
|
||||
java.sql.Date date = java.sql.Date.valueOf(receivedDate);
|
||||
receivedTimestamp = new Timestamp(date.getTime());
|
||||
} else {
|
||||
receivedTimestamp = Timestamp.valueOf(receivedDate);
|
||||
}
|
||||
attachment.setReceived(receivedTimestamp);
|
||||
attachment.setCustomAttributes(customAttributes);
|
||||
|
||||
return attachment;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -66,7 +66,6 @@ public class CreateTaskAccTest extends AbstractAccTest {
|
|||
assertEquals(false, createdTask.isTransferred());
|
||||
}
|
||||
|
||||
@Ignore
|
||||
@WithAccessId(
|
||||
userName = "user_1_1",
|
||||
groupNames = {"group_1"})
|
||||
|
@ -80,10 +79,10 @@ public class CreateTaskAccTest extends AbstractAccTest {
|
|||
newTask.setClassification(taskanaEngine.getClassificationService().getClassification("L12010", "DOMAIN_A"));
|
||||
newTask.setPrimaryObjRef(createObjectReference("COMPANY_A", "SYSTEM_A", "INSTANCE_A", "VNR", "1234567"));
|
||||
newTask.setWorkbasketKey("USER_1_1");
|
||||
// newTask.addAttachment(createAttachment("DOKTYP_DEFAULT",
|
||||
// createObjectReference("COMPANY_A", "SYSTEM_B", "INSTANCE_B", "ArchiveId",
|
||||
// "12345678901234567890123456789012345678901234567890"),
|
||||
// "E-MAIL", "2018-01-15", createSimpleCustomProperties(3)));
|
||||
newTask.addAttachment(createAttachment("DOKTYP_DEFAULT",
|
||||
createObjectReference("COMPANY_A", "SYSTEM_B", "INSTANCE_B", "ArchiveId",
|
||||
"12345678901234567890123456789012345678901234567890"),
|
||||
"E-MAIL", "2018-01-15", createSimpleCustomProperties(3)));
|
||||
Task createdTask = taskService.createTask(newTask);
|
||||
|
||||
assertNotNull(createdTask);
|
||||
|
@ -91,7 +90,6 @@ public class CreateTaskAccTest extends AbstractAccTest {
|
|||
// assertEquals(1, createdTask.getAttachments().size());
|
||||
}
|
||||
|
||||
@Ignore
|
||||
@WithAccessId(
|
||||
userName = "user_1_1",
|
||||
groupNames = {"group_1"})
|
||||
|
@ -105,14 +103,14 @@ public class CreateTaskAccTest extends AbstractAccTest {
|
|||
newTask.setClassification(taskanaEngine.getClassificationService().getClassification("L12010", "DOMAIN_A"));
|
||||
newTask.setPrimaryObjRef(createObjectReference("COMPANY_A", "SYSTEM_A", "INSTANCE_A", "VNR", "1234567"));
|
||||
newTask.setWorkbasketKey("USER_1_1");
|
||||
// newTask.addAttachment(createAttachment("DOKTYP_DEFAULT",
|
||||
// createObjectReference("COMPANY_A", "SYSTEM_B", "INSTANCE_B", "ArchiveId",
|
||||
// "12345678901234567890123456789012345678901234567890"),
|
||||
// "E-MAIL", "2018-01-15", createSimpleCustomProperties(3)));
|
||||
// newTask.addAttachment(createAttachment("DOKTYP_DEFAULT",
|
||||
// createObjectReference("COMPANY_A", "SYSTEM_B", "INSTANCE_B", "ArchiveId",
|
||||
// "12345678901234567890123456789012345678901234567890"),
|
||||
// "E-MAIL", "2018-01-15", createSimpleCustomProperties(3)));
|
||||
newTask.addAttachment(createAttachment("DOKTYP_DEFAULT",
|
||||
createObjectReference("COMPANY_A", "SYSTEM_B", "INSTANCE_B", "ArchiveId",
|
||||
"12345678901234567890123456789012345678901234567890"),
|
||||
"E-MAIL", "2018-01-15", createSimpleCustomProperties(3)));
|
||||
newTask.addAttachment(createAttachment("DOKTYP_DEFAULT",
|
||||
createObjectReference("COMPANY_A", "SYSTEM_B", "INSTANCE_B", "ArchiveId",
|
||||
"12345678901234567890123456789012345678901234567890"),
|
||||
"E-MAIL", "2018-01-15", createSimpleCustomProperties(3)));
|
||||
Task createdTask = taskService.createTask(newTask);
|
||||
|
||||
assertNotNull(createdTask);
|
||||
|
@ -121,7 +119,6 @@ public class CreateTaskAccTest extends AbstractAccTest {
|
|||
// further assertions
|
||||
}
|
||||
|
||||
@Ignore
|
||||
@WithAccessId(
|
||||
userName = "user_1_1",
|
||||
groupNames = {"group_1"})
|
||||
|
@ -131,19 +128,77 @@ public class CreateTaskAccTest extends AbstractAccTest {
|
|||
WorkbasketNotFoundException, TaskAlreadyExistException, InvalidWorkbasketException {
|
||||
|
||||
TaskService taskService = taskanaEngine.getTaskService();
|
||||
Task newTask = taskService.newTask();
|
||||
newTask.setClassification(taskanaEngine.getClassificationService().getClassification("L12010", "DOMAIN_A"));
|
||||
Task createdTask = null;
|
||||
Task newTask = makeNewTask(taskService);
|
||||
newTask.addAttachment(createAttachment("DOKTYP_DEFAULT",
|
||||
null,
|
||||
"E-MAIL", "2018-01-15", createSimpleCustomProperties(3)));
|
||||
try {
|
||||
createdTask = taskService.createTask(newTask);
|
||||
} catch (InvalidArgumentException ex) {
|
||||
assertEquals("primary ObjectReference of Attachment must not be null", ex.getMessage());
|
||||
}
|
||||
|
||||
newTask = makeNewTask(taskService);
|
||||
newTask.addAttachment(createAttachment("DOKTYP_DEFAULT",
|
||||
createObjectReference("COMPANY_A", "SYSTEM_B", "INSTANCE_B", "ArchiveId", null),
|
||||
"E-MAIL", "2018-01-15", createSimpleCustomProperties(3)));
|
||||
try {
|
||||
createdTask = taskService.createTask(newTask);
|
||||
} catch (InvalidArgumentException ex) {
|
||||
assertEquals("Value of primary ObjectReference of Attachment must not be empty", ex.getMessage());
|
||||
}
|
||||
|
||||
newTask = makeNewTask(taskService);
|
||||
newTask.addAttachment(createAttachment("DOKTYP_DEFAULT",
|
||||
createObjectReference("COMPANY_A", "SYSTEM_B", "INSTANCE_B", null,
|
||||
"12345678901234567890123456789012345678901234567890"),
|
||||
"E-MAIL", "2018-01-15", createSimpleCustomProperties(3)));
|
||||
try {
|
||||
createdTask = taskService.createTask(newTask);
|
||||
} catch (InvalidArgumentException ex) {
|
||||
assertEquals("Type of primary ObjectReference of Attachment must not be empty", ex.getMessage());
|
||||
}
|
||||
newTask = makeNewTask(taskService);
|
||||
newTask.addAttachment(createAttachment("DOKTYP_DEFAULT",
|
||||
createObjectReference("COMPANY_A", "SYSTEM_B", null, "ArchiveId",
|
||||
"12345678901234567890123456789012345678901234567890"),
|
||||
"E-MAIL", "2018-01-15", createSimpleCustomProperties(3)));
|
||||
try {
|
||||
createdTask = taskService.createTask(newTask);
|
||||
} catch (InvalidArgumentException ex) {
|
||||
assertEquals("SystemInstance of primary ObjectReference of Attachment must not be empty", ex.getMessage());
|
||||
}
|
||||
newTask = makeNewTask(taskService);
|
||||
newTask.addAttachment(createAttachment("DOKTYP_DEFAULT",
|
||||
createObjectReference("COMPANY_A", null, "INSTANCE_B", "ArchiveId",
|
||||
"12345678901234567890123456789012345678901234567890"),
|
||||
"E-MAIL", "2018-01-15", createSimpleCustomProperties(3)));
|
||||
try {
|
||||
createdTask = taskService.createTask(newTask);
|
||||
} catch (InvalidArgumentException ex) {
|
||||
assertEquals("System of primary ObjectReference of Attachment must not be empty", ex.getMessage());
|
||||
}
|
||||
newTask = makeNewTask(taskService);
|
||||
newTask.addAttachment(createAttachment("DOKTYP_DEFAULT",
|
||||
createObjectReference(null, "SYSTEM_B", "INSTANCE_B", "ArchiveId",
|
||||
"12345678901234567890123456789012345678901234567890"),
|
||||
"E-MAIL", "2018-01-15", createSimpleCustomProperties(3)));
|
||||
try {
|
||||
createdTask = taskService.createTask(newTask);
|
||||
} catch (InvalidArgumentException ex) {
|
||||
assertEquals("Company of primary ObjectReference of Attachment must not be empty", ex.getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private Task makeNewTask(TaskService taskService) throws ClassificationNotFoundException {
|
||||
Task newTask;
|
||||
newTask = taskService.newTask();
|
||||
newTask.setPrimaryObjRef(createObjectReference("COMPANY_A", "SYSTEM_A", "INSTANCE_A", "VNR", "1234567"));
|
||||
newTask.setWorkbasketKey("USER_1_1");
|
||||
// newTask.addAttachment(createAttachment("DOKTYP_DEFAULT",
|
||||
// null,
|
||||
// "E-MAIL", "2018-01-15", createSimpleCustomProperties(3)));
|
||||
Task createdTask = taskService.createTask(newTask);
|
||||
|
||||
// Further exceptions
|
||||
// null in object reference
|
||||
//
|
||||
|
||||
newTask.setClassification(taskanaEngine.getClassificationService().getClassification("L12010", "DOMAIN_A"));
|
||||
return newTask;
|
||||
}
|
||||
|
||||
@WithAccessId(
|
||||
|
@ -256,7 +311,7 @@ public class CreateTaskAccTest extends AbstractAccTest {
|
|||
try {
|
||||
createdTask = taskService.createTask(newTask);
|
||||
} catch (InvalidArgumentException ex) {
|
||||
assertEquals("primary ObjectReference of task must not be null", ex.getMessage());
|
||||
assertEquals("primary ObjectReference of Task must not be null", ex.getMessage());
|
||||
}
|
||||
|
||||
// Exception
|
||||
|
@ -268,7 +323,7 @@ public class CreateTaskAccTest extends AbstractAccTest {
|
|||
try {
|
||||
createdTask = taskService.createTask(newTask);
|
||||
} catch (InvalidArgumentException ex) {
|
||||
assertEquals("Value of primary ObjectReference of task must not be empty", ex.getMessage());
|
||||
assertEquals("Value of primary ObjectReference of Task must not be empty", ex.getMessage());
|
||||
}
|
||||
|
||||
// Exception
|
||||
|
@ -281,7 +336,7 @@ public class CreateTaskAccTest extends AbstractAccTest {
|
|||
try {
|
||||
createdTask = taskService.createTask(newTask);
|
||||
} catch (InvalidArgumentException ex) {
|
||||
assertEquals("Type of primary ObjectReference of task must not be empty", ex.getMessage());
|
||||
assertEquals("Type of primary ObjectReference of Task must not be empty", ex.getMessage());
|
||||
}
|
||||
|
||||
// Exception
|
||||
|
@ -294,7 +349,7 @@ public class CreateTaskAccTest extends AbstractAccTest {
|
|||
try {
|
||||
createdTask = taskService.createTask(newTask);
|
||||
} catch (InvalidArgumentException ex) {
|
||||
assertEquals("SystemInstance of primary ObjectReference of task must not be empty", ex.getMessage());
|
||||
assertEquals("SystemInstance of primary ObjectReference of Task must not be empty", ex.getMessage());
|
||||
}
|
||||
|
||||
// Exception
|
||||
|
@ -307,7 +362,7 @@ public class CreateTaskAccTest extends AbstractAccTest {
|
|||
try {
|
||||
createdTask = taskService.createTask(newTask);
|
||||
} catch (InvalidArgumentException ex) {
|
||||
assertEquals("System of primary ObjectReference of task must not be empty", ex.getMessage());
|
||||
assertEquals("System of primary ObjectReference of Task must not be empty", ex.getMessage());
|
||||
}
|
||||
|
||||
// Exception
|
||||
|
@ -320,7 +375,7 @@ public class CreateTaskAccTest extends AbstractAccTest {
|
|||
try {
|
||||
createdTask = taskService.createTask(newTask);
|
||||
} catch (InvalidArgumentException ex) {
|
||||
assertEquals("Company of primary ObjectReference of task must not be empty", ex.getMessage());
|
||||
assertEquals("Company of primary ObjectReference of Task must not be empty", ex.getMessage());
|
||||
}
|
||||
|
||||
// Exception
|
||||
|
|
|
@ -74,39 +74,39 @@ public class UpdateTaskAccTest extends AbstractAccTest {
|
|||
try {
|
||||
updatedTask = taskService.updateTask(task);
|
||||
} catch (InvalidArgumentException ex) {
|
||||
assertEquals("primary ObjectReference of task must not be null", ex.getMessage());
|
||||
assertEquals("primary ObjectReference of Task must not be null", ex.getMessage());
|
||||
}
|
||||
|
||||
task.setPrimaryObjRef(createObjectReference("COMPANY_A", "SYSTEM_A", "INSTANCE_A", "VNR", null));
|
||||
try {
|
||||
updatedTask = taskService.updateTask(task);
|
||||
} catch (InvalidArgumentException ex) {
|
||||
assertEquals("Value of primary ObjectReference of task must not be empty", ex.getMessage());
|
||||
assertEquals("Value of primary ObjectReference of Task must not be empty", ex.getMessage());
|
||||
}
|
||||
|
||||
task.setPrimaryObjRef(createObjectReference("COMPANY_A", "SYSTEM_A", "INSTANCE_A", null, "1234567"));
|
||||
try {
|
||||
updatedTask = taskService.updateTask(task);
|
||||
} catch (InvalidArgumentException ex) {
|
||||
assertEquals("Type of primary ObjectReference of task must not be empty", ex.getMessage());
|
||||
assertEquals("Type of primary ObjectReference of Task must not be empty", ex.getMessage());
|
||||
}
|
||||
task.setPrimaryObjRef(createObjectReference("COMPANY_A", "SYSTEM_A", null, "VNR", "1234567"));
|
||||
try {
|
||||
updatedTask = taskService.updateTask(task);
|
||||
} catch (InvalidArgumentException ex) {
|
||||
assertEquals("SystemInstance of primary ObjectReference of task must not be empty", ex.getMessage());
|
||||
assertEquals("SystemInstance of primary ObjectReference of Task must not be empty", ex.getMessage());
|
||||
}
|
||||
task.setPrimaryObjRef(createObjectReference("COMPANY_A", null, "INSTANCE_A", "VNR", "1234567"));
|
||||
try {
|
||||
updatedTask = taskService.updateTask(task);
|
||||
} catch (InvalidArgumentException ex) {
|
||||
assertEquals("System of primary ObjectReference of task must not be empty", ex.getMessage());
|
||||
assertEquals("System of primary ObjectReference of Task must not be empty", ex.getMessage());
|
||||
}
|
||||
task.setPrimaryObjRef(createObjectReference(null, "SYSTEM_A", "INSTANCE_A", "VNR", "1234567"));
|
||||
try {
|
||||
updatedTask = taskService.updateTask(task);
|
||||
} catch (InvalidArgumentException ex) {
|
||||
assertEquals("Company of primary ObjectReference of task must not be empty", ex.getMessage());
|
||||
assertEquals("Company of primary ObjectReference of Task must not be empty", ex.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -4,4 +4,5 @@ DELETE FROM DISTRIBUTION_TARGETS;
|
|||
DELETE FROM CLASSIFICATION;
|
||||
DELETE FROM WORKBASKET_ACCESS_LIST;
|
||||
DELETE FROM OBJECT_REFERENCE;
|
||||
DELETE FROM ATTACHMENT;
|
||||
COMMIT;
|
||||
|
|
|
@ -5,4 +5,5 @@ DROP TABLE DISTRIBUTION_TARGETS;
|
|||
DROP TABLE CLASSIFICATION;
|
||||
DROP TABLE WORKBASKET_ACCESS_LIST;
|
||||
DROP TABLE OBJECT_REFERENCE;
|
||||
DROP TABLE ATTACHMENT;
|
||||
COMMIT;
|
||||
|
|
Loading…
Reference in New Issue