use of org.eclipse.sw360.datahandler.thrift.attachments.Attachment in project sw360portal by sw360.
the class AttachmentAwareDatabaseHandlerTest method testGetAllAttachmentsToKeep.
@Test
public void testGetAllAttachmentsToKeep() throws Exception {
// Try to delete one approved and one rejected attachment.
// -> the approved one should not be deleted.
Attachment attachmentAccepted = new Attachment().setAttachmentContentId("acceptedAtt").setFilename("att1.file").setCheckStatus(CheckStatus.ACCEPTED);
Attachment attachmentRejected = new Attachment().setAttachmentContentId("rejectedAtt").setFilename("att2.file").setCheckStatus(CheckStatus.REJECTED);
Set<Attachment> attachmentsBefore = new HashSet<>();
attachmentsBefore.add(attachmentAccepted);
attachmentsBefore.add(attachmentRejected);
Set<Attachment> attachmentsAfter = new HashSet<>();
Set<Attachment> attachmentsToKeep = handler.getAllAttachmentsToKeep(attachmentsBefore, attachmentsAfter);
assertEquals(1, attachmentsToKeep.size());
assertTrue(attachmentsToKeep.contains(attachmentAccepted));
assertFalse(attachmentsToKeep.contains(attachmentRejected));
// Change an attachment
// -> it should not be stored twice
Attachment originalAttachment = new Attachment().setAttachmentContentId("att").setFilename("att.file").setCheckStatus(CheckStatus.ACCEPTED);
attachmentsBefore = new HashSet<>();
attachmentsBefore.add(originalAttachment);
Attachment changedAttachment = originalAttachment.deepCopy().setCheckStatus(CheckStatus.REJECTED);
attachmentsAfter = new HashSet<>();
attachmentsAfter.add(changedAttachment);
attachmentsToKeep = handler.getAllAttachmentsToKeep(attachmentsBefore, attachmentsAfter);
assertEquals(1, attachmentsToKeep.size());
assertTrue(attachmentsToKeep.contains(changedAttachment));
}
use of org.eclipse.sw360.datahandler.thrift.attachments.Attachment in project sw360portal by sw360.
the class AttachmentAwareDatabaseHandlerTest method testGetAllAttachmentsToKeepCanHandleNull.
@Test
public void testGetAllAttachmentsToKeepCanHandleNull() throws Exception {
// Test what happens if `changedAttachments` are `null`
// -> only not-accepted attachments should be deleted
Attachment attachmentAccepted1 = new Attachment().setAttachmentContentId("acceptedAtt1").setFilename("att1.file").setCheckStatus(CheckStatus.ACCEPTED);
Attachment attachmentRejected1 = new Attachment().setAttachmentContentId("rejectedAtt1").setFilename("att2.file").setCheckStatus(CheckStatus.REJECTED);
Attachment attachmentRejected2 = new Attachment().setAttachmentContentId("rejectedAtt2").setFilename("att3.file").setCheckStatus(CheckStatus.NOTCHECKED);
Set<Attachment> attachments = new HashSet<>();
attachments.add(attachmentAccepted1);
attachments.add(attachmentRejected1);
attachments.add(attachmentRejected2);
Set<Attachment> attachmentsToKeep = handler.getAllAttachmentsToKeep(attachments, null);
assertEquals(1, attachmentsToKeep.size());
assertTrue(attachmentsToKeep.contains(attachmentAccepted1));
assertFalse(attachmentsToKeep.contains(attachmentRejected1));
assertFalse(attachmentsToKeep.contains(attachmentRejected2));
// Test what happens if `originalAttachments` are `null` (this means adding of attachments)
// -> all should be added
attachmentsToKeep = handler.getAllAttachmentsToKeep(null, attachments);
assertEquals(3, attachmentsToKeep.size());
assertTrue(attachmentsToKeep.contains(attachmentAccepted1));
assertTrue(attachmentsToKeep.contains(attachmentRejected1));
assertTrue(attachmentsToKeep.contains(attachmentRejected2));
}
use of org.eclipse.sw360.datahandler.thrift.attachments.Attachment in project sw360portal by sw360.
the class AttachmentHandler method getAttachmentContent.
@Override
public AttachmentContent getAttachmentContent(String id) throws TException {
assertNotEmpty(id);
AttachmentContent attachment = attachmentRepository.get(id);
assertNotNull(attachment, "Cannot find " + id + " in database.");
validateAttachment(attachment);
return attachment;
}
use of org.eclipse.sw360.datahandler.thrift.attachments.Attachment in project sw360portal by sw360.
the class AttachmentDatabaseHandler method getAttachmentContent.
public AttachmentContent getAttachmentContent(String id) throws TException {
AttachmentContent attachment = repository.get(id);
assertNotNull(attachment, "Cannot find " + id + " in database.");
validateAttachment(attachment);
return attachment;
}
use of org.eclipse.sw360.datahandler.thrift.attachments.Attachment in project sw360portal by sw360.
the class AttachmentResourceProcessor method process.
@Override
public Resource<Attachment> process(Resource<Attachment> resource) {
Attachment attachment = resource.getContent();
Link selfLink = linkTo(AttachmentController.class).slash("api" + AttachmentController.ATTACHMENTS_URL + "/" + attachment.getAttachmentContentId()).withSelfRel();
resource.add(selfLink);
return resource;
}
Aggregations