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);
}
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);
}
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;
}
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);
}
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);
}
Aggregations