Search in sources :

Example 56 with Attachment

use of org.eclipse.sw360.datahandler.thrift.attachments.Attachment in project sw360portal by sw360.

the class AttachmentController method getAttachmentForId.

@RequestMapping(value = ATTACHMENTS_URL + "/{id}", method = RequestMethod.GET)
public ResponseEntity<Resource<Attachment>> getAttachmentForId(@PathVariable("id") String id, OAuth2Authentication oAuth2Authentication) throws TException {
    User sw360User = restControllerHelper.getSw360UserFromAuthentication(oAuth2Authentication);
    AttachmentInfo attachmentInfo = attachmentService.getAttachmentByIdForUser(id, sw360User);
    HalResource<Attachment> attachmentResource = createHalAttachment(attachmentInfo.getAttachment(), attachmentInfo.getRelease(), sw360User);
    return new ResponseEntity<>(attachmentResource, HttpStatus.OK);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) User(org.eclipse.sw360.datahandler.thrift.users.User) Attachment(org.eclipse.sw360.datahandler.thrift.attachments.Attachment) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 57 with Attachment

use of org.eclipse.sw360.datahandler.thrift.attachments.Attachment in project sw360portal by sw360.

the class AttachmentController method getAttachmentForSha1.

@RequestMapping(value = ATTACHMENTS_URL, params = "sha1", method = RequestMethod.GET)
public ResponseEntity<Resource<Attachment>> getAttachmentForSha1(OAuth2Authentication oAuth2Authentication, @RequestParam String sha1) throws TException {
    User sw360User = restControllerHelper.getSw360UserFromAuthentication(oAuth2Authentication);
    AttachmentInfo attachmentInfo = attachmentService.getAttachmentBySha1ForUser(sha1, sw360User);
    HalResource<Attachment> attachmentResource = createHalAttachment(attachmentInfo.getAttachment(), attachmentInfo.getRelease(), sw360User);
    return new ResponseEntity<>(attachmentResource, HttpStatus.OK);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) User(org.eclipse.sw360.datahandler.thrift.users.User) Attachment(org.eclipse.sw360.datahandler.thrift.attachments.Attachment) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 58 with Attachment

use of org.eclipse.sw360.datahandler.thrift.attachments.Attachment in project sw360portal by sw360.

the class AttachmentController method createHalAttachment.

private HalResource<Attachment> createHalAttachment(Attachment sw360Attachment, Release sw360Release, User sw360User) {
    HalResource<Attachment> halAttachment = new HalResource<>(sw360Attachment);
    String componentUUID = sw360Attachment.getAttachmentContentId();
    Link releaseLink = linkTo(AttachmentController.class).slash("api/releases/" + sw360Release.getId()).withRel("release");
    halAttachment.add(releaseLink);
    restControllerHelper.addEmbeddedRelease(halAttachment, sw360Release);
    restControllerHelper.addEmbeddedUser(halAttachment, sw360User, "createdBy");
    return halAttachment;
}
Also used : Attachment(org.eclipse.sw360.datahandler.thrift.attachments.Attachment) HalResource(org.eclipse.sw360.rest.resourceserver.core.HalResource) Link(org.springframework.hateoas.Link)

Example 59 with Attachment

use of org.eclipse.sw360.datahandler.thrift.attachments.Attachment in project sw360portal by sw360.

the class AttachmentConnectorTest method testDeleteAttachmentsDifference.

@Test
public void testDeleteAttachmentsDifference() throws Exception {
    Attachment a1 = mock(Attachment.class);
    when(a1.getAttachmentContentId()).thenReturn("a1cid");
    when(a1.getSha1()).thenReturn(null);
    when(a1.isSetSha1()).thenReturn(false);
    Attachment a2 = mock(Attachment.class);
    when(a2.getAttachmentContentId()).thenReturn("a2cid");
    when(a2.getSha1()).thenReturn(null);
    when(a2.isSetSha1()).thenReturn(false);
    Set<Attachment> before = new HashSet<>();
    before.add(a1);
    before.add(a2);
    Attachment a3 = mock(Attachment.class);
    when(a3.getAttachmentContentId()).thenReturn("a1cid");
    when(a3.getSha1()).thenReturn("sha1");
    when(a3.isSetSha1()).thenReturn(true);
    Set<Attachment> after = new HashSet<>();
    after.add(a3);
    Set<String> deletedIds = new HashSet<>();
    deletedIds.add("a2cid");
    attachmentConnector.deleteAttachmentDifference(before, after);
    verify(connector).deleteIds(deletedIds, AttachmentContent.class);
}
Also used : Attachment(org.eclipse.sw360.datahandler.thrift.attachments.Attachment) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 60 with Attachment

use of org.eclipse.sw360.datahandler.thrift.attachments.Attachment in project sw360portal by sw360.

the class AttachmentConnectorTest method testDeleteAttachmentsDifferenceOnlyNonAcceptedIsDeleted.

@Test
public void testDeleteAttachmentsDifferenceOnlyNonAcceptedIsDeleted() throws Exception {
    Attachment a1 = mock(Attachment.class);
    when(a1.getAttachmentContentId()).thenReturn("a1");
    Attachment a2 = mock(Attachment.class);
    when(a2.getAttachmentContentId()).thenReturn("a2");
    when(a2.getCheckStatus()).thenReturn(CheckStatus.REJECTED);
    Attachment a3 = mock(Attachment.class);
    when(a3.getAttachmentContentId()).thenReturn("a3");
    when(a3.getCheckStatus()).thenReturn(CheckStatus.ACCEPTED);
    Set<Attachment> before = new HashSet<>();
    before.add(a1);
    before.add(a2);
    before.add(a3);
    Set<Attachment> after = new HashSet<>();
    after.add(a1);
    Set<String> expectedIdsToDelete = new HashSet<>();
    expectedIdsToDelete.add("a2");
    attachmentConnector.deleteAttachmentDifference(before, after);
    verify(connector).deleteIds(expectedIdsToDelete, AttachmentContent.class);
}
Also used : Attachment(org.eclipse.sw360.datahandler.thrift.attachments.Attachment) HashSet(java.util.HashSet) Test(org.junit.Test)

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