Search in sources :

Example 1 with Attachment

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));
}
Also used : Attachment(org.eclipse.sw360.datahandler.thrift.attachments.Attachment) Test(org.junit.Test)

Example 2 with Attachment

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));
}
Also used : Attachment(org.eclipse.sw360.datahandler.thrift.attachments.Attachment) Test(org.junit.Test)

Example 3 with Attachment

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;
}
Also used : AttachmentContent(org.eclipse.sw360.datahandler.thrift.attachments.AttachmentContent)

Example 4 with 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;
}
Also used : AttachmentContent(org.eclipse.sw360.datahandler.thrift.attachments.AttachmentContent)

Example 5 with 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;
}
Also used : Attachment(org.eclipse.sw360.datahandler.thrift.attachments.Attachment) Link(org.springframework.hateoas.Link)

Aggregations

Attachment (org.eclipse.sw360.datahandler.thrift.attachments.Attachment)65 Test (org.junit.Test)40 AttachmentContent (org.eclipse.sw360.datahandler.thrift.attachments.AttachmentContent)38 User (org.eclipse.sw360.datahandler.thrift.users.User)27 Project (org.eclipse.sw360.datahandler.thrift.projects.Project)22 InputStream (java.io.InputStream)19 Release (org.eclipse.sw360.datahandler.thrift.components.Release)15 IOException (java.io.IOException)13 PortletRequest (javax.portlet.PortletRequest)11 TestUserCacheHolder (org.eclipse.sw360.portal.TestUserCacheHolder)9 StringReader (java.io.StringReader)8 ReaderInputStream (org.apache.commons.io.input.ReaderInputStream)8 TException (org.apache.thrift.TException)8 SW360Exception (org.eclipse.sw360.datahandler.thrift.SW360Exception)8 LicenseInfoParsingResult (org.eclipse.sw360.datahandler.thrift.licenseinfo.LicenseInfoParsingResult)7 OutputStream (java.io.OutputStream)5 AttachmentInputStream (org.ektorp.AttachmentInputStream)5 ResponseEntity (org.springframework.http.ResponseEntity)5 ComponentService (org.eclipse.sw360.datahandler.thrift.components.ComponentService)4 Maps (com.google.common.collect.Maps)3