Search in sources :

Example 46 with AttachmentContent

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

the class SPDXParserTools method getLicenseInfoFromSpdx.

protected static LicenseInfoParsingResult getLicenseInfoFromSpdx(AttachmentContent attachmentContent, SpdxDocument doc) {
    LicenseInfo licenseInfo = new LicenseInfo().setFilenames(Arrays.asList(attachmentContent.getFilename()));
    licenseInfo.setLicenseNamesWithTexts(new HashSet<>());
    licenseInfo.setCopyrights(new HashSet<>());
    try {
        for (SpdxItem spdxItem : doc.getDocumentDescribes()) {
            licenseInfo.getLicenseNamesWithTexts().addAll(getAllLicenseTexts(spdxItem, true).collect(Collectors.toSet()));
            licenseInfo.getCopyrights().addAll(getAllCopyrights(spdxItem).collect(Collectors.toSet()));
        }
    } catch (UncheckedInvalidSPDXAnalysisException e) {
        return new LicenseInfoParsingResult().setStatus(LicenseInfoRequestStatus.FAILURE).setMessage(e.getInvalidSPDXAnalysisExceptionCause().getMessage());
    } catch (InvalidSPDXAnalysisException e) {
        return new LicenseInfoParsingResult().setStatus(LicenseInfoRequestStatus.FAILURE).setMessage(e.getMessage());
    }
    return new LicenseInfoParsingResult().setLicenseInfo(licenseInfo).setStatus(LicenseInfoRequestStatus.SUCCESS);
}
Also used : LicenseInfo(org.eclipse.sw360.datahandler.thrift.licenseinfo.LicenseInfo) SpdxItem(org.spdx.rdfparser.model.SpdxItem) LicenseInfoParsingResult(org.eclipse.sw360.datahandler.thrift.licenseinfo.LicenseInfoParsingResult) InvalidSPDXAnalysisException(org.spdx.rdfparser.InvalidSPDXAnalysisException)

Example 47 with AttachmentContent

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

the class CombinedCLIParserTest method testIsApplicableToFailsOnIncorrectRootElement.

@Test
public void testIsApplicableToFailsOnIncorrectRootElement() throws Exception {
    AttachmentContent content = new AttachmentContent().setId("A1").setFilename("a.xml").setContentType("application/xml");
    when(connector.getAttachmentStream(content, new User(), new Project())).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 48 with AttachmentContent

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

the class CombinedCLIParserTest method setUp.

@Before
public void setUp() throws Exception {
    cliTestfile = IOUtils.toString(makeAttachmentContentStream(TEST_XML_FILENAME));
    attachment = new Attachment("A1", "a.xml").setAttachmentType(AttachmentType.COMPONENT_LICENSE_INFO_COMBINED);
    content = new AttachmentContent().setId("A1").setFilename("a.xml").setContentType("application/xml");
    parser = spy(new CombinedCLIParser(connector, attachment -> content, componentDatabaseHandler));
    doReturn("external-correlation-id").when(parser).getCorrelationKey();
    Release r1 = new Release().setId("id1").setName("r1").setVersion("1.0").setVendor(new Vendor().setFullname("VendorA Fullname").setShortname("VendorA")).setExternalIds(ImmutableMap.of(parser.getCorrelationKey(), "1234"));
    Release r2 = new Release().setId("id2").setName("r2").setVersion("2.0").setVendor(new Vendor().setFullname("VendorB Fullname").setShortname("VendorB")).setExternalIds(ImmutableMap.of(parser.getCorrelationKey(), "4321"));
    Release r3 = new Release().setId("id3").setName("r3").setVersion("3.0").setVendor(new Vendor().setFullname("VendorC Fullname").setShortname("VendorC"));
    Release r4 = new Release().setId("id4").setName("r4").setVersion("4.0").setVendor(new Vendor().setFullname("VendorD Fullname").setShortname("VendorD")).setExternalIds(ImmutableMap.of("some_external_id", "1234"));
    when(componentDatabaseHandler.getAllReleasesIdMap()).thenReturn(ImmutableMap.of(r1.getId(), r1, r2.getId(), r2, r3.getId(), r3, r4.getId(), r4));
}
Also used : AttachmentContent(org.eclipse.sw360.datahandler.thrift.attachments.AttachmentContent) Attachment(org.eclipse.sw360.datahandler.thrift.attachments.Attachment) Vendor(org.eclipse.sw360.datahandler.thrift.vendors.Vendor) Release(org.eclipse.sw360.datahandler.thrift.components.Release) Before(org.junit.Before)

Example 49 with AttachmentContent

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

the class SPDXParserTest method testAddSPDXContentToCLI.

@Test
@UseDataProvider("dataProviderAdd")
public void testAddSPDXContentToCLI(String exampleFile, List<String> expectedLicenses, int numberOfCoyprights, String exampleCopyright) throws Exception {
    AttachmentContent attachmentContent = new AttachmentContent().setFilename(exampleFile);
    InputStream input = makeAttachmentContentStream(exampleFile);
    SpdxDocument spdxDocument = SPDXDocumentFactory.createSpdxDocument(input, parser.getUriOfAttachment(attachmentContentStore.get(exampleFile)), FILETYPE_SPDX_INTERNAL);
    LicenseInfoParsingResult result = SPDXParserTools.getLicenseInfoFromSpdx(attachmentContent, spdxDocument);
    assertIsResultOfExample(result.getLicenseInfo(), exampleFile, expectedLicenses, numberOfCoyprights, exampleCopyright);
}
Also used : InputStream(java.io.InputStream) AttachmentContent(org.eclipse.sw360.datahandler.thrift.attachments.AttachmentContent) LicenseInfoParsingResult(org.eclipse.sw360.datahandler.thrift.licenseinfo.LicenseInfoParsingResult) SpdxDocument(org.spdx.rdfparser.model.SpdxDocument) Test(org.junit.Test) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Example 50 with AttachmentContent

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

the class FossologyUploaderTest method testUploadToFossologyWithNonIntReturn.

@Test
public void testUploadToFossologyWithNonIntReturn() 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 {
            OutputStream outputStream = (OutputStream) invocation.getArguments()[2];
            outputStream.write("uploadId=60000000000000000".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) -1));
}
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)

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