Search in sources :

Example 51 with AttachmentContent

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

the class FossologyUploaderTest method testUploadToFossology.

@Test
public void testUploadToFossology() throws Exception {
    AttachmentContent attachment = mock(AttachmentContent.class);
    when(attachment.getId()).thenReturn("id");
    when(attachment.getFilename()).thenReturn("fileName");
    String clearingTeam = "cl";
    final InputStream inputStream = mock(InputStream.class);
    doAnswer(new Answer() {

        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            final Object[] arguments = invocation.getArguments();
            String command = (String) arguments[0];
            InputStream input = (InputStream) arguments[1];
            OutputStream outputStream = (OutputStream) arguments[2];
            assertThat(input, sameInstance(inputStream));
            assertThat(command, is("./uploadFromSW360 -i 'id' -g 'cl' -f 'fileName'"));
            outputStream.write("uploadId=60".getBytes());
            return 0;
        }
    }).when(sshConnector).runInFossologyViaSsh(anyString(), eq(inputStream), any(OutputStream.class));
    final long uploadId = fossologyUploader.uploadToFossology(inputStream, attachment, clearingTeam);
    verify(sshConnector).runInFossologyViaSsh(anyString(), eq(inputStream), any(OutputStream.class));
    assertThat(uploadId, is((long) 60));
}
Also used : Answer(org.mockito.stubbing.Answer) InputStream(java.io.InputStream) InvocationOnMock(org.mockito.invocation.InvocationOnMock) OutputStream(java.io.OutputStream) AttachmentContent(org.eclipse.sw360.datahandler.thrift.attachments.AttachmentContent) Test(org.junit.Test)

Example 52 with AttachmentContent

use of org.eclipse.sw360.datahandler.thrift.attachments.AttachmentContent 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)

Example 53 with AttachmentContent

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

the class CLIParserTest method testIsApplicableToFailsOnIncorrectRootElement.

@Test
public void testIsApplicableToFailsOnIncorrectRootElement() throws Exception {
    AttachmentContent content = new AttachmentContent().setId("A1").setFilename("a.xml").setContentType("application/xml");
    when(connector.getAttachmentStream(eq(content), anyObject(), anyObject())).thenReturn(new ReaderInputStream(new StringReader("<wrong-root/>")));
    assertFalse(parser.isApplicableTo(attachment, new User(), new Project()));
}
Also used : Project(org.eclipse.sw360.datahandler.thrift.projects.Project) ReaderInputStream(org.apache.commons.io.input.ReaderInputStream) User(org.eclipse.sw360.datahandler.thrift.users.User) StringReader(java.io.StringReader) AttachmentContent(org.eclipse.sw360.datahandler.thrift.attachments.AttachmentContent) Test(org.junit.Test)

Example 54 with AttachmentContent

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

the class ComponentCSVRecord method getRelease.

public Release getRelease(String vendorId, String componentId, List<AttachmentContent> attachments) {
    Release release = new Release();
    // required
    release.setName(releaseName).setVersion(releaseVersion).setComponentId(componentId);
    // optionals
    if (!isNullOrEmpty(vendorId)) {
        release.setVendorId(vendorId);
    }
    if (!isNullOrEmpty(CPEId)) {
        release.setCpeid(CPEId);
    }
    if (!isNullOrEmpty(releaseDate)) {
        release.setReleaseDate(releaseDate);
    }
    if (!isNullOrEmpty(releaseCreatedOn)) {
        release.setCreatedOn(releaseCreatedOn);
    }
    if (!isNullOrEmpty(releaseCreatedBy)) {
        release.setCreatedBy(releaseCreatedBy);
    }
    if (CommonUtils.isValidUrl(releaseDownloadURL)) {
        release.setDownloadurl(releaseDownloadURL);
    }
    if (isSetRepository()) {
        release.setRepository(getRepository());
    }
    if (!isNullOrEmpty(releaseMainlineState)) {
        final MainlineState mainlineState = ThriftEnumUtils.stringToEnum(releaseMainlineState, MainlineState.class);
        if (mainlineState != null)
            release.setMainlineState(mainlineState);
    }
    if (!isNullOrEmpty(releaseClearingState)) {
        final ClearingState clearingState = ThriftEnumUtils.stringToEnum(releaseClearingState, ClearingState.class);
        if (clearingState != null)
            release.setClearingState(clearingState);
    }
    if (!isNullOrEmpty(releaseContributors)) {
        release.setContributors(CommonUtils.splitToSet(releaseContributors));
    }
    if (!isNullOrEmpty(releaseModerators)) {
        release.setModerators(CommonUtils.splitToSet(releaseModerators));
    }
    if (!isNullOrEmpty(releaseSubscribers)) {
        release.setSubscribers(CommonUtils.splitToSet(releaseSubscribers));
    }
    if (!isNullOrEmpty(releaseLanguages)) {
        release.setLanguages(CommonUtils.splitToSet(releaseLanguages));
    }
    if (!isNullOrEmpty(releaseOperatingSystems)) {
        release.setOperatingSystems(CommonUtils.splitToSet(releaseOperatingSystems));
    }
    if (!isNullOrEmpty(releaseMainLicenseIds)) {
        release.setMainLicenseIds(CommonUtils.splitToSet(releaseMainLicenseIds));
    }
    if (isSetClearingInformation()) {
        release.setClearingInformation(getClearingInformation());
    }
    if (isSetEccInformation()) {
        release.setEccInformation(getEccInformation());
    }
    // TODO: There should be only one SOURCE per Release
    if (attachments != null) {
        for (AttachmentContent attachmentContent : attachments) {
            String attachmentContentId = attachmentContent.getId();
            release.addToAttachments(new Attachment().setAttachmentContentId(attachmentContentId).setCreatedOn(SW360Utils.getCreatedOn()).setCreatedBy(releaseCreatedBy).setAttachmentType(AttachmentType.SOURCE).setFilename(attachmentContent.getFilename()));
        }
    }
    return release;
}
Also used : MainlineState(org.eclipse.sw360.datahandler.thrift.MainlineState) AttachmentContent(org.eclipse.sw360.datahandler.thrift.attachments.AttachmentContent) Attachment(org.eclipse.sw360.datahandler.thrift.attachments.Attachment) CommonUtils.nullToEmptyString(org.eclipse.sw360.datahandler.common.CommonUtils.nullToEmptyString)

Example 55 with AttachmentContent

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

the class ComponentImportUtils method getAttachmentContents.

@Nullable
private static List<AttachmentContent> getAttachmentContents(HashMap<String, List<String>> releaseIdentifierToDownloadURL, ImmutableMap<String, AttachmentContent> URLtoAttachment, String releaseIdentifier) {
    List<AttachmentContent> attachmentContents = null;
    if (releaseIdentifierToDownloadURL.containsKey(releaseIdentifier)) {
        final List<String> URLs = releaseIdentifierToDownloadURL.get(releaseIdentifier);
        attachmentContents = new ArrayList<>(URLs.size());
        for (String url : URLs) {
            if (URLtoAttachment.containsKey(url)) {
                final AttachmentContent attachmentContent = URLtoAttachment.get(url);
                attachmentContents.add(attachmentContent);
            }
        }
    }
    return attachmentContents;
}
Also used : AttachmentContent(org.eclipse.sw360.datahandler.thrift.attachments.AttachmentContent) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

AttachmentContent (org.eclipse.sw360.datahandler.thrift.attachments.AttachmentContent)52 InputStream (java.io.InputStream)24 Test (org.junit.Test)20 Attachment (org.eclipse.sw360.datahandler.thrift.attachments.Attachment)13 Project (org.eclipse.sw360.datahandler.thrift.projects.Project)11 IOException (java.io.IOException)10 SW360Exception (org.eclipse.sw360.datahandler.thrift.SW360Exception)10 User (org.eclipse.sw360.datahandler.thrift.users.User)10 Release (org.eclipse.sw360.datahandler.thrift.components.Release)8 TException (org.apache.thrift.TException)7 LicenseInfoParsingResult (org.eclipse.sw360.datahandler.thrift.licenseinfo.LicenseInfoParsingResult)6 AttachmentInputStream (org.ektorp.AttachmentInputStream)6 OutputStream (java.io.OutputStream)5 FilledAttachment (org.eclipse.sw360.datahandler.thrift.attachments.FilledAttachment)5 StringReader (java.io.StringReader)4 ReaderInputStream (org.apache.commons.io.input.ReaderInputStream)4 RequestSummary (org.eclipse.sw360.datahandler.thrift.RequestSummary)4 DatabaseConnector (org.eclipse.sw360.datahandler.couchdb.DatabaseConnector)3 LicenseInfo (org.eclipse.sw360.datahandler.thrift.licenseinfo.LicenseInfo)3 PipedInputStream (java.io.PipedInputStream)2