Search in sources :

Example 6 with LicenseInfo

use of org.eclipse.sw360.datahandler.thrift.licenseinfo.LicenseInfo in project sw360portal by sw360.

the class LicenseInfoHandlerTest method testThatLicensesAreFilteredAndOriginalObejctIsNotTouched.

@Test
public void testThatLicensesAreFilteredAndOriginalObejctIsNotTouched() {
    LicenseInfoParsingResult parsingResults = new LicenseInfoParsingResult();
    LicenseInfo licenseInfo = new LicenseInfo();
    // @formatter:off
    licenseInfo.setLicenseNamesWithTexts(ImmutableSet.of(createLicense("l1", null, null), createLicense("l1", "t1", null), createLicense("l2", "t2", null), createLicense("l3", "t3", null), createLicense("l3", "t3", "a3"), createLicense(null, "t4", null), createLicense("l4", "t4", null), createLicense(null, null, "a5"), createLicense("l5", null, "a5"), createLicense("l", "t", "a6"), createLicense("l", "t", "a7"), createLicense("l8", null, null), createLicense("l8", "t8", null), createLicense("l9", "t9", "a9"), createLicense(null, "t9", "a9")));
    // @formatter:on
    parsingResults.setLicenseInfo(licenseInfo);
    // @formatter:off
    LicenseInfoParsingResult filteredResult = handler.filterLicenses(parsingResults, ImmutableSet.of(createLicense("l1", "t1", null), createLicense("l3", "t3", "a3"), createLicense(null, "t4", null), createLicense(null, null, "a5"), createLicense("l", "t", "a6"), createLicense("l8", null, null), createLicense(null, "t9", "a9")));
    // @formatter:on
    // @formatter:off
    Assert.assertThat(filteredResult.getLicenseInfo().getLicenseNamesWithTexts(), Matchers.containsInAnyOrder(createLicense("l1", null, null), createLicense("l2", "t2", null), createLicense("l3", "t3", null), createLicense("l4", "t4", null), createLicense("l5", null, "a5"), createLicense("l", "t", "a7"), createLicense("l8", "t8", null), createLicense("l9", "t9", "a9")));
// @formatter:on
}
Also used : LicenseInfo(org.eclipse.sw360.datahandler.thrift.licenseinfo.LicenseInfo) LicenseInfoParsingResult(org.eclipse.sw360.datahandler.thrift.licenseinfo.LicenseInfoParsingResult) Test(org.junit.Test)

Example 7 with LicenseInfo

use of org.eclipse.sw360.datahandler.thrift.licenseinfo.LicenseInfo in project sw360portal by sw360.

the class CombinedCLIParser method getLicenseInfoParsingResultForExternalId.

@NotNull
private LicenseInfoParsingResult getLicenseInfoParsingResultForExternalId(AttachmentContent attachmentContent, Map<String, Release> releasesByExternalId, Map<String, Set<String>> copyrightSetsByExternalId, Map<String, Set<LicenseNameWithText>> licenseNamesWithTextsByExternalId, String extId) {
    LicenseInfo licenseInfo = new LicenseInfo().setFilenames(Arrays.asList(attachmentContent.getFilename()));
    licenseInfo.setCopyrights(copyrightSetsByExternalId.get(extId));
    licenseInfo.setLicenseNamesWithTexts(licenseNamesWithTextsByExternalId.get(extId));
    LicenseInfoParsingResult parsingResult = new LicenseInfoParsingResult().setLicenseInfo(licenseInfo);
    Release release = releasesByExternalId.get(extId);
    if (release != null) {
        parsingResult.setVendor(release.isSetVendor() ? release.getVendor().getShortname() : "");
        parsingResult.setName(release.getName());
        parsingResult.setVersion(release.getVersion());
    } else {
        parsingResult.setName("No info found for external component ID " + extId);
    }
    parsingResult.setStatus(LicenseInfoRequestStatus.SUCCESS);
    return parsingResult;
}
Also used : LicenseInfo(org.eclipse.sw360.datahandler.thrift.licenseinfo.LicenseInfo) LicenseInfoParsingResult(org.eclipse.sw360.datahandler.thrift.licenseinfo.LicenseInfoParsingResult) Release(org.eclipse.sw360.datahandler.thrift.components.Release) NotNull(org.jetbrains.annotations.NotNull)

Example 8 with LicenseInfo

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

Aggregations

LicenseInfo (org.eclipse.sw360.datahandler.thrift.licenseinfo.LicenseInfo)6 LicenseInfoParsingResult (org.eclipse.sw360.datahandler.thrift.licenseinfo.LicenseInfoParsingResult)5 Release (org.eclipse.sw360.datahandler.thrift.components.Release)2 User (org.eclipse.sw360.datahandler.thrift.users.User)2 Test (org.junit.Test)2 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 XPathExpressionException (javax.xml.xpath.XPathExpressionException)1 TException (org.apache.thrift.TException)1 WrappedTException (org.eclipse.sw360.datahandler.common.WrappedException.WrappedTException)1 SW360Exception (org.eclipse.sw360.datahandler.thrift.SW360Exception)1 Attachment (org.eclipse.sw360.datahandler.thrift.attachments.Attachment)1 AttachmentContent (org.eclipse.sw360.datahandler.thrift.attachments.AttachmentContent)1 LicenseInfoFile (org.eclipse.sw360.datahandler.thrift.licenseinfo.LicenseInfoFile)1 LicenseNameWithText (org.eclipse.sw360.datahandler.thrift.licenseinfo.LicenseNameWithText)1 OutputFormatInfo (org.eclipse.sw360.datahandler.thrift.licenseinfo.OutputFormatInfo)1 Project (org.eclipse.sw360.datahandler.thrift.projects.Project)1 NotNull (org.jetbrains.annotations.NotNull)1 InvalidSPDXAnalysisException (org.spdx.rdfparser.InvalidSPDXAnalysisException)1