Search in sources :

Example 6 with FilledAttachment

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

the class FossologyFileHandlerTest method testSendToFossologySendsAnAttachment.

@Test
public void testSendToFossologySendsAnAttachment() throws Exception {
    final String id = "41";
    final FilledAttachment filledAttachment = getMockFilledAttachment(id);
    final AttachmentContent attachmentContent = filledAttachment.getAttachmentContent();
    final Release release = mock(Release.class);
    when(componentService.getReleaseById(releaseId, user)).thenReturn(release);
    spyGetFilledSourceAttachment(filledAttachment);
    final InputStream inputStream = mock(InputStream.class);
    when(release.isSetFossologyId()).thenReturn(false);
    when(release.getClearingState()).thenReturn(ClearingState.NEW_CLEARING);
    when(attachmentConnector.getAttachmentStream(attachmentContent, user, release)).thenReturn(inputStream);
    when(fossologyUploader.uploadToFossology(inputStream, attachmentContent, clearingTeam)).thenReturn(1);
    doNothing().when(fossologyFileHandler).setFossologyStatus(eq(release), anyString(), eq(FossologyStatus.SENT), eq("" + 1), eq(id));
    doReturn(true).when(fossologyFileHandler).checkSourceAttachment(release, filledAttachment);
    assertThat(fossologyFileHandler.sendToFossology(releaseId, user, clearingTeam), is(RequestStatus.SUCCESS));
    verify(inputStream).close();
    // the release should be updated
    verify(componentService).updateReleaseFossology(release, user);
    verify(fossologyFileHandler).setFossologyStatus(eq(release), anyString(), eq(FossologyStatus.SENT), eq("" + 1), eq(id));
    // unimportant verifies
    verify(componentService, times(1)).getReleaseById(releaseId, user);
    verify(attachmentConnector).getAttachmentStream(attachmentContent, user, release);
    verify(fossologyUploader).uploadToFossology(inputStream, attachmentContent, clearingTeam);
}
Also used : InputStream(java.io.InputStream) AttachmentContent(org.eclipse.sw360.datahandler.thrift.attachments.AttachmentContent) FilledAttachment(org.eclipse.sw360.datahandler.thrift.attachments.FilledAttachment) Release(org.eclipse.sw360.datahandler.thrift.components.Release) Test(org.junit.Test)

Example 7 with FilledAttachment

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

the class FossologyFileHandler method sendToFossology.

public RequestStatus sendToFossology(String releaseId, User user, String clearingTeam) throws TException {
    Release release;
    final ComponentService.Iface componentClient = thriftClients.makeComponentClient();
    release = getReleaseAndUnlockIt(releaseId, user, componentClient);
    Set<Attachment> sourceAttachments = getSourceAttachment(releaseId, user, componentClient);
    if (sourceAttachments.size() != 1) {
        log.error("release " + releaseId + " does not have a single source attachment");
        // TODO return a summary and better fitting status
        return RequestStatus.FAILURE;
    }
    final Attachment attachment = getFirst(sourceAttachments);
    final FilledAttachment filledAttachment = fillAttachment(attachment);
    if (!release.isSetFossologyId()) {
        /* send the attachment as a new upload */
        AttachmentContent attachmentContent = filledAttachment.getAttachmentContent();
        return sendToFossologyNewUpload(release, user, clearingTeam, attachmentContent, componentClient);
    } else {
        if (!checkSourceAttachment(release, filledAttachment)) {
            // TODO summary
            return RequestStatus.FAILURE;
        } else {
            /* duplicate the old upload making it visible for clearingTeam */
            return sendToFossologyExistingUpload(release, user, clearingTeam, componentClient);
        }
    }
}
Also used : AttachmentContent(org.eclipse.sw360.datahandler.thrift.attachments.AttachmentContent) Attachment(org.eclipse.sw360.datahandler.thrift.attachments.Attachment) FilledAttachment(org.eclipse.sw360.datahandler.thrift.attachments.FilledAttachment) ComponentService(org.eclipse.sw360.datahandler.thrift.components.ComponentService) FilledAttachment(org.eclipse.sw360.datahandler.thrift.attachments.FilledAttachment) Release(org.eclipse.sw360.datahandler.thrift.components.Release)

Example 8 with FilledAttachment

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

the class FossologyFileHandler method fillAttachment.

protected FilledAttachment fillAttachment(Attachment attachment) throws SW360Exception {
    String attachmentContentId = attachment.getAttachmentContentId();
    try {
        AttachmentContent attachmentContent = attachmentConnector.getAttachmentContent(attachmentContentId);
        assertNotNull(attachmentContent);
        return new FilledAttachment().setAttachment(attachment).setAttachmentContent(attachmentContent);
    } catch (SW360Exception e) {
        log.error("cannot retrieve attachment " + attachmentContentId, e);
        throw e;
    }
}
Also used : AttachmentContent(org.eclipse.sw360.datahandler.thrift.attachments.AttachmentContent) FilledAttachment(org.eclipse.sw360.datahandler.thrift.attachments.FilledAttachment) SW360Exception(org.eclipse.sw360.datahandler.thrift.SW360Exception)

Example 9 with FilledAttachment

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

the class FossologyFileHandlerTest method testSendToFossologyDuplicates.

@Test
public void testSendToFossologyDuplicates() throws Exception {
    final FilledAttachment filledAttachment = getMockFilledAttachment("17");
    final Release release = mock(Release.class);
    when(componentService.getReleaseById(releaseId, user)).thenReturn(release);
    when(release.getFossologyId()).thenReturn("41");
    when(release.isSetFossologyId()).thenReturn(true);
    when(release.getClearingState()).thenReturn(ClearingState.SENT_TO_FOSSOLOGY);
    spyGetFilledSourceAttachment(filledAttachment);
    when(fossologyUploader.duplicateInFossology(41, clearingTeam)).thenReturn(true);
    doNothing().when(fossologyFileHandler).setFossologyStatus(eq(release), anyString(), any(FossologyStatus.class));
    doReturn(true).when(fossologyFileHandler).checkSourceAttachment(release, filledAttachment);
    assertThat(fossologyFileHandler.sendToFossology(releaseId, user, clearingTeam), is(RequestStatus.SUCCESS));
    verify(fossologyUploader).duplicateInFossology(41, clearingTeam);
    verify(fossologyUploader).getStatusInFossology(eq(41), eq(clearingTeam));
    verify(fossologyFileHandler).setFossologyStatus(eq(release), eq(clearingTeam), eq(FossologyStatus.SENT));
    verify(componentService).updateReleaseFossology(release, user);
    verify(componentService, atLeastOnce()).getReleaseById(releaseId, user);
    verifyNoMoreInteractions(attachmentConnector);
}
Also used : FilledAttachment(org.eclipse.sw360.datahandler.thrift.attachments.FilledAttachment) FossologyStatus(org.eclipse.sw360.datahandler.thrift.components.FossologyStatus) Release(org.eclipse.sw360.datahandler.thrift.components.Release) Test(org.junit.Test)

Example 10 with FilledAttachment

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

the class FossologyFileHandlerTest method getMockFilledAttachment.

private static FilledAttachment getMockFilledAttachment(String attachmentContentId) {
    final FilledAttachment filledAttachment = mock(FilledAttachment.class);
    final Attachment attachment = mock(Attachment.class);
    when(filledAttachment.getAttachment()).thenReturn(attachment);
    final AttachmentContent attachmentContent = mock(AttachmentContent.class);
    when(filledAttachment.getAttachmentContent()).thenReturn(attachmentContent);
    when(attachment.getAttachmentContentId()).thenReturn(attachmentContentId);
    when(attachmentContent.getId()).thenReturn(attachmentContentId);
    return filledAttachment;
}
Also used : AttachmentContent(org.eclipse.sw360.datahandler.thrift.attachments.AttachmentContent) Attachment(org.eclipse.sw360.datahandler.thrift.attachments.Attachment) FilledAttachment(org.eclipse.sw360.datahandler.thrift.attachments.FilledAttachment) FilledAttachment(org.eclipse.sw360.datahandler.thrift.attachments.FilledAttachment)

Aggregations

FilledAttachment (org.eclipse.sw360.datahandler.thrift.attachments.FilledAttachment)10 Release (org.eclipse.sw360.datahandler.thrift.components.Release)7 Test (org.junit.Test)6 AttachmentContent (org.eclipse.sw360.datahandler.thrift.attachments.AttachmentContent)5 Attachment (org.eclipse.sw360.datahandler.thrift.attachments.Attachment)3 InputStream (java.io.InputStream)2 FossologyStatus (org.eclipse.sw360.datahandler.thrift.components.FossologyStatus)2 SW360Exception (org.eclipse.sw360.datahandler.thrift.SW360Exception)1 ComponentService (org.eclipse.sw360.datahandler.thrift.components.ComponentService)1