use of org.eclipse.sw360.rest.resourceserver.attachment.AttachmentInfo in project sw360portal by sw360.
the class Sw360AttachmentService method getAttachmentByIdForUser.
public AttachmentInfo getAttachmentByIdForUser(String id, User sw360User) throws TException {
ComponentService.Iface sw360ComponentClient = getThriftComponentClient();
List<Release> releases = sw360ComponentClient.getReleaseSummary(sw360User);
for (Release release : releases) {
final Set<Attachment> attachments = release.getAttachments();
if (attachments != null && attachments.size() > 0) {
for (Attachment attachment : attachments) {
if (id.equals(attachment.getAttachmentContentId())) {
return new AttachmentInfo(attachment, release);
}
}
}
}
return null;
}
use of org.eclipse.sw360.rest.resourceserver.attachment.AttachmentInfo in project sw360portal by sw360.
the class AttachmentSpecTest method before.
@Before
public void before() throws TException {
List<Attachment> attachmentList = new ArrayList<>();
attachment = new Attachment();
attachment.setAttachmentContentId("76537653");
attachment.setFilename("spring-core-4.3.4.RELEASE.jar");
attachment.setSha1("da373e491d3863477568896089ee9457bc316783");
attachment.setAttachmentType(AttachmentType.BINARY_SELF);
attachment.setCreatedTeam("Clearing Team 1");
attachment.setCreatedComment("please check before Christmas :)");
attachment.setCreatedOn("2016-12-18");
attachment.setCreatedBy("admin@sw360.org");
attachment.setCheckedTeam("Clearing Team 2");
attachment.setCheckedComment("everything looks good");
attachment.setCheckedOn("2016-12-18");
attachment.setCheckStatus(CheckStatus.ACCEPTED);
attachmentList.add(attachment);
Release release = new Release();
release.setId("874687");
release.setName("Spring Core 4.3.4");
release.setCpeid("cpe:/a:pivotal:spring-core:4.3.4:");
release.setReleaseDate("2016-12-07");
release.setVersion("4.3.4");
release.setCreatedOn("2016-12-18");
release.setCreatedBy("admin@sw360.org");
release.setModerators(new HashSet<>(Arrays.asList(testUserId, testUserPassword)));
release.setComponentId("678dstzd8");
release.setClearingState(ClearingState.APPROVED);
AttachmentInfo attachmentInfo = new AttachmentInfo(attachment, release);
given(this.attachmentServiceMock.getAttachmentByIdForUser(eq(attachment.getAttachmentContentId()), anyObject())).willReturn(attachmentInfo);
User user = new User();
user.setId("admin@sw360.org");
user.setEmail("admin@sw360.org");
user.setFullname("John Doe");
given(this.userServiceMock.getUserByEmail("admin@sw360.org")).willReturn(user);
}
use of org.eclipse.sw360.rest.resourceserver.attachment.AttachmentInfo 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.rest.resourceserver.attachment.AttachmentInfo 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.rest.resourceserver.attachment.AttachmentInfo in project sw360portal by sw360.
the class Sw360AttachmentService method getAttachmentBySha1ForUser.
public AttachmentInfo getAttachmentBySha1ForUser(String sha1, User sw360User) throws TException {
ComponentService.Iface sw360ComponentClient = getThriftComponentClient();
List<Release> releases = sw360ComponentClient.getReleaseSummary(sw360User);
for (Release release : releases) {
final Set<Attachment> attachments = release.getAttachments();
if (attachments != null && attachments.size() > 0) {
for (Attachment attachment : attachments) {
if (sha1.equals(attachment.getSha1())) {
return new AttachmentInfo(attachment, release);
}
}
}
}
return null;
}
Aggregations