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
}
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;
}
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);
}
Aggregations