Add Channel and ObjectReference to AttachmentSummary

This commit is contained in:
BVier 2018-07-04 16:37:58 +02:00 committed by Mustapha Zorgati
parent 42197bee6c
commit 85c9a7ed8a
7 changed files with 223 additions and 4 deletions

View File

@ -36,6 +36,20 @@ public interface AttachmentSummary {
*/ */
Instant getModified(); Instant getModified();
/**
* Gets the {@link ObjectReference primaryObjectReference} of the attachment.
*
* @return {@link ObjectReference primaryObjectReference} of the attachment
**/
ObjectReference getObjectReference();
/**
* Gets the Channel on which the attachment was received.
*
* @return the channel
**/
String getChannel();
/** /**
* Gets the classificationSummary of the attachment. * Gets the classificationSummary of the attachment.
* *

View File

@ -134,6 +134,8 @@ public class AttachmentImpl implements Attachment {
summary.setModified(this.modified); summary.setModified(this.modified);
summary.setReceived(this.received); summary.setReceived(this.received);
summary.setTaskId(this.taskId); summary.setTaskId(this.taskId);
summary.setChannel(this.channel);
summary.setObjectReference(this.objectReference);
return summary; return summary;
} }

View File

@ -4,6 +4,7 @@ import java.time.Instant;
import pro.taskana.AttachmentSummary; import pro.taskana.AttachmentSummary;
import pro.taskana.ClassificationSummary; import pro.taskana.ClassificationSummary;
import pro.taskana.ObjectReference;
/** /**
* The most important fields of the Attachment entity. * The most important fields of the Attachment entity.
@ -15,6 +16,8 @@ public class AttachmentSummaryImpl implements AttachmentSummary {
private Instant created; private Instant created;
private Instant modified; private Instant modified;
private ClassificationSummary classificationSummary; private ClassificationSummary classificationSummary;
private ObjectReference objectReference;
private String channel;
private Instant received; private Instant received;
AttachmentSummaryImpl() { AttachmentSummaryImpl() {
@ -86,6 +89,32 @@ public class AttachmentSummaryImpl implements AttachmentSummary {
this.classificationSummary = classificationSummary; this.classificationSummary = classificationSummary;
} }
/*
* (non-Javadoc)
* @see pro.taskana.AttachmentSummary#getObjectReference()
*/
@Override
public ObjectReference getObjectReference() {
return objectReference;
}
public void setObjectReference(ObjectReference objectReference) {
this.objectReference = objectReference;
}
/*
* (non-Javadoc)
* @see pro.taskana.AttachmentSummary#getChannel()
*/
@Override
public String getChannel() {
return channel;
}
public void setChannel(String channel) {
this.channel = channel;
}
// auxiliary method to enable MyBatis access to classificationSummary // auxiliary method to enable MyBatis access to classificationSummary
public ClassificationSummaryImpl getClassificationSummaryImpl() { public ClassificationSummaryImpl getClassificationSummaryImpl() {
return (ClassificationSummaryImpl) classificationSummary; return (ClassificationSummaryImpl) classificationSummary;
@ -113,10 +142,12 @@ public class AttachmentSummaryImpl implements AttachmentSummary {
public int hashCode() { public int hashCode() {
final int prime = 31; final int prime = 31;
int result = 1; int result = 1;
result = prime * result + ((channel == null) ? 0 : channel.hashCode());
result = prime * result + ((classificationSummary == null) ? 0 : classificationSummary.hashCode()); result = prime * result + ((classificationSummary == null) ? 0 : classificationSummary.hashCode());
result = prime * result + ((created == null) ? 0 : created.hashCode()); result = prime * result + ((created == null) ? 0 : created.hashCode());
result = prime * result + ((id == null) ? 0 : id.hashCode()); result = prime * result + ((id == null) ? 0 : id.hashCode());
result = prime * result + ((modified == null) ? 0 : modified.hashCode()); result = prime * result + ((modified == null) ? 0 : modified.hashCode());
result = prime * result + ((objectReference == null) ? 0 : objectReference.hashCode());
result = prime * result + ((received == null) ? 0 : received.hashCode()); result = prime * result + ((received == null) ? 0 : received.hashCode());
result = prime * result + ((taskId == null) ? 0 : taskId.hashCode()); result = prime * result + ((taskId == null) ? 0 : taskId.hashCode());
return result; return result;
@ -176,13 +207,27 @@ public class AttachmentSummaryImpl implements AttachmentSummary {
} else if (!taskId.equals(other.taskId)) { } else if (!taskId.equals(other.taskId)) {
return false; return false;
} }
if (objectReference == null) {
if (other.objectReference != null) {
return false;
}
} else if (!objectReference.equals(other.objectReference)) {
return false;
}
if (channel == null) {
if (other.channel != null) {
return false;
}
} else if (!channel.equals(other.channel)) {
return false;
}
return true; return true;
} }
@Override @Override
public String toString() { public String toString() {
StringBuilder builder = new StringBuilder(); StringBuilder builder = new StringBuilder();
builder.append("AttachmentSummaryImpl [id="); builder.append("AttachmentImpl [id=");
builder.append(id); builder.append(id);
builder.append(", taskId="); builder.append(", taskId=");
builder.append(taskId); builder.append(taskId);
@ -192,6 +237,10 @@ public class AttachmentSummaryImpl implements AttachmentSummary {
builder.append(modified); builder.append(modified);
builder.append(", classificationSummary="); builder.append(", classificationSummary=");
builder.append(classificationSummary); builder.append(classificationSummary);
builder.append(", objectReference=");
builder.append(objectReference);
builder.append(", channel=");
builder.append(channel);
builder.append(", received="); builder.append(", received=");
builder.append(received); builder.append(received);
builder.append("]"); builder.append("]");

View File

@ -741,7 +741,7 @@ public class TaskServiceImpl implements TaskService {
Set<String> taskIdSet = taskSummaries.stream().map(TaskSummaryImpl::getTaskId).collect(Collectors.toSet()); Set<String> taskIdSet = taskSummaries.stream().map(TaskSummaryImpl::getTaskId).collect(Collectors.toSet());
String[] taskIdArray = taskIdSet.toArray(new String[0]); String[] taskIdArray = taskIdSet.toArray(new String[0]);
LOGGER.debug("augmentTaskSummariesByContainedSummaries() about to query for attachments "); LOGGER.debug("augmentTaskSummariesByContainedSummaries() about to query for attachmentSummaries ");
List<AttachmentSummaryImpl> attachmentSummaries = attachmentMapper List<AttachmentSummaryImpl> attachmentSummaries = attachmentMapper
.findAttachmentSummariesByTaskIds(taskIdArray); .findAttachmentSummariesByTaskIds(taskIdArray);

View File

@ -74,7 +74,7 @@ public interface AttachmentMapper {
}) })
AttachmentImpl getAttachment(@Param("attachmentId") String attachmentId); AttachmentImpl getAttachment(@Param("attachmentId") String attachmentId);
@Select("<script>SELECT ID, TASK_ID, CREATED, MODIFIED, CLASSIFICATION_KEY, CLASSIFICATION_ID, RECEIVED " @Select("<script>SELECT ID, TASK_ID, CREATED, MODIFIED, CLASSIFICATION_KEY, CLASSIFICATION_ID, REF_COMPANY, REF_SYSTEM, REF_INSTANCE, REF_TYPE, REF_VALUE, CHANNEL, RECEIVED "
+ "FROM TASKANA.ATTACHMENT " + "FROM TASKANA.ATTACHMENT "
+ "<where>" + "<where>"
+ "TASK_ID IN (<foreach collection='array' item='item' separator=',' >#{item}</foreach>)" + "TASK_ID IN (<foreach collection='array' item='item' separator=',' >#{item}</foreach>)"
@ -88,7 +88,13 @@ public interface AttachmentMapper {
@Result(property = "modified", column = "MODIFIED"), @Result(property = "modified", column = "MODIFIED"),
@Result(property = "classificationSummaryImpl.key", column = "CLASSIFICATION_KEY"), @Result(property = "classificationSummaryImpl.key", column = "CLASSIFICATION_KEY"),
@Result(property = "classificationSummaryImpl.id", column = "CLASSIFICATION_ID"), @Result(property = "classificationSummaryImpl.id", column = "CLASSIFICATION_ID"),
@Result(property = "received", column = "RECEIVED"), @Result(property = "objectReference.company", column = "REF_COMPANY"),
@Result(property = "objectReference.system", column = "REF_SYSTEM"),
@Result(property = "objectReference.systemInstance", column = "REF_INSTANCE"),
@Result(property = "objectReference.type", column = "REF_TYPE"),
@Result(property = "objectReference.value", column = "REF_VALUE"),
@Result(property = "channel", column = "CHANNEL"),
@Result(property = "received", column = "RECEIVED")
}) })
List<AttachmentSummaryImpl> findAttachmentSummariesByTaskIds(String[] taskIds); List<AttachmentSummaryImpl> findAttachmentSummariesByTaskIds(String[] taskIds);

View File

@ -0,0 +1,99 @@
package acceptance.task;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotNull;
import java.util.List;
import org.junit.Test;
import org.junit.runner.RunWith;
import acceptance.AbstractAccTest;
import pro.taskana.Attachment;
import pro.taskana.AttachmentSummary;
import pro.taskana.Task;
import pro.taskana.TaskService;
import pro.taskana.TaskSummary;
import pro.taskana.exceptions.InvalidArgumentException;
import pro.taskana.exceptions.NotAuthorizedException;
import pro.taskana.exceptions.TaskNotFoundException;
import pro.taskana.security.JAASRunner;
import pro.taskana.security.WithAccessId;
/**
* Acceptance test for the usecase of adding/removing an attachment of a task and update the result correctly.
*/
@RunWith(JAASRunner.class)
public class QueryTaskWithAttachment extends AbstractAccTest {
public QueryTaskWithAttachment() {
super();
}
@WithAccessId(
userName = "user_1_1",
groupNames = {"group_1"})
@Test
public void testGetAttachmentSummariesFromTask() {
TaskService taskService = taskanaEngine.getTaskService();
List<TaskSummary> tasks = taskService.createTaskQuery()
.classificationKeyIn("L110102")
.list();
assertEquals(1, tasks.size());
List<AttachmentSummary> attachmentSummaries = tasks.get(0).getAttachmentSummaries();
assertNotNull(attachmentSummaries);
assertEquals(2, attachmentSummaries.size());
}
@WithAccessId(
userName = "user_1_2")
@Test
public void testGetNoAttachmentSummaryFromTask() {
TaskService taskService = taskanaEngine.getTaskService();
List<TaskSummary> tasks = taskService.createTaskQuery()
.list();
assertEquals(20, tasks.size());
List<AttachmentSummary> attachmentSummaries = tasks.get(0).getAttachmentSummaries();
assertEquals(null, attachmentSummaries);
}
@WithAccessId(
userName = "user_1_1",
groupNames = {"group_1"})
@Test
public void testIfAttachmentSummariesAreCorrect()
throws InvalidArgumentException, TaskNotFoundException, NotAuthorizedException {
TaskService taskService = taskanaEngine.getTaskService();
// find Task with ID TKI:00...00
List<TaskSummary> tasks = taskService.createTaskQuery()
.classificationKeyIn("T2000")
.customAttributeIn("1", "custom1")
.list();
assertEquals(1, tasks.size());
Task originalTask = taskService.getTask("TKI:000000000000000000000000000000000000");
Attachment originalAttachment = originalTask.getAttachments().get(0);
// Test if it's the Summary of the Original Attachment
AttachmentSummary queryAttachmentSummary = tasks.get(0).getAttachmentSummaries().get(0);
assertEquals(originalAttachment.asSummary(), queryAttachmentSummary);
// Test if the values are correct
assertEquals(originalAttachment.getChannel(), queryAttachmentSummary.getChannel());
assertEquals(originalAttachment.getClassificationSummary(), queryAttachmentSummary.getClassificationSummary());
assertEquals(originalAttachment.getCreated(), queryAttachmentSummary.getCreated());
assertEquals(originalAttachment.getId(), queryAttachmentSummary.getId());
assertEquals(originalAttachment.getModified(), queryAttachmentSummary.getModified());
assertEquals(originalAttachment.getObjectReference(), queryAttachmentSummary.getObjectReference());
assertEquals(originalAttachment.getReceived(), queryAttachmentSummary.getReceived());
assertEquals(originalAttachment.getTaskId(), queryAttachmentSummary.getTaskId());
// Verify that they're not the same Object
assertNotEquals(originalAttachment.hashCode(), queryAttachmentSummary.hashCode());
assertNotEquals(originalAttachment.getClass(), queryAttachmentSummary.getClass());
}
}

View File

@ -1,14 +1,22 @@
package pro.taskana.impl; package pro.taskana.impl;
import static org.hamcrest.core.IsEqual.equalTo; import static org.hamcrest.core.IsEqual.equalTo;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertThat; import static org.junit.Assert.assertThat;
import java.time.Instant;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.mockito.InjectMocks; import org.mockito.InjectMocks;
import org.mockito.junit.MockitoJUnitRunner; import org.mockito.junit.MockitoJUnitRunner;
import pro.taskana.Attachment; import pro.taskana.Attachment;
import pro.taskana.AttachmentSummary;
import pro.taskana.ObjectReference;
/** /**
* Unit Test for methods needed fot attachment at TaskImpl.<br> * Unit Test for methods needed fot attachment at TaskImpl.<br>
@ -92,6 +100,47 @@ public class TaskAttachmentTest {
assertThat(actual, equalTo(attachment1)); assertThat(actual, equalTo(attachment1));
} }
@Test
public void testGetAttachmentSummaries() {
ObjectReference objRef = new ObjectReference();
objRef.setId("ObjRefId");
objRef.setCompany("company");
Map<String, String> customAttr = new HashMap<String, String>();
customAttr.put("key", "value");
Attachment attachment1 = createAttachment("ID1", "taskId1");
attachment1.setChannel("channel");
attachment1.setClassificationSummary(new ClassificationImpl().asSummary());
attachment1.setReceived(Instant.now());
attachment1.setObjectReference(objRef);
//attachment1.setCustomAttributes(customAttr);
cut.addAttachment(attachment1);
List<AttachmentSummary> summaries = cut.asSummary().getAttachmentSummaries();
AttachmentSummary attachmentSummary = summaries.get(0);
assertThat(attachmentSummary, equalTo(attachment1.asSummary()));
assertThat(attachmentSummary.getId(), equalTo(attachment1.getId()));
assertThat(attachmentSummary.getTaskId(), equalTo(attachment1.getTaskId()));
assertThat(attachmentSummary.getChannel(), equalTo(attachment1.getChannel()));
assertThat(attachmentSummary.getClassificationSummary(), equalTo(attachment1.getClassificationSummary()));
assertThat(attachmentSummary.getObjectReference(), equalTo(attachment1.getObjectReference()));
assertThat(attachmentSummary.getCreated(), equalTo(attachment1.getCreated()));
assertThat(attachmentSummary.getReceived(), equalTo(attachment1.getReceived()));
assertThat(attachmentSummary.getModified(), equalTo(attachment1.getModified()));
// Must be different
assertNotEquals(attachmentSummary.hashCode(), attachment1.hashCode());
cut.removeAttachment("ID1");
assertThat(summaries.size(), equalTo(1));
summaries = cut.asSummary().getAttachmentSummaries();
assertThat(summaries.size(), equalTo(0));
}
private Attachment createAttachment(String id, String taskId) { private Attachment createAttachment(String id, String taskId) {
AttachmentImpl attachment = new AttachmentImpl(); AttachmentImpl attachment = new AttachmentImpl();
attachment.setId(id); attachment.setId(id);