Search in sources :

Example 1 with AttachmentInfo

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

Example 2 with AttachmentInfo

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);
}
Also used : User(org.eclipse.sw360.datahandler.thrift.users.User) ArrayList(java.util.ArrayList) AttachmentInfo(org.eclipse.sw360.rest.resourceserver.attachment.AttachmentInfo) Attachment(org.eclipse.sw360.datahandler.thrift.attachments.Attachment) Release(org.eclipse.sw360.datahandler.thrift.components.Release) Before(org.junit.Before)

Example 3 with AttachmentInfo

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);
}
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 4 with AttachmentInfo

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);
}
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 5 with AttachmentInfo

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

Aggregations

Attachment (org.eclipse.sw360.datahandler.thrift.attachments.Attachment)3 Release (org.eclipse.sw360.datahandler.thrift.components.Release)3 User (org.eclipse.sw360.datahandler.thrift.users.User)3 ComponentService (org.eclipse.sw360.datahandler.thrift.components.ComponentService)2 ResponseEntity (org.springframework.http.ResponseEntity)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 ArrayList (java.util.ArrayList)1 AttachmentInfo (org.eclipse.sw360.rest.resourceserver.attachment.AttachmentInfo)1 Before (org.junit.Before)1