use of org.eclipse.sw360.datahandler.thrift.licenseinfo.LicenseNameWithText in project sw360portal by sw360.
the class LicenseNameWithTextUtilsTest method createLicense.
private LicenseNameWithText createLicense(String name, String text, String acknowledgements) {
LicenseNameWithText licenseNameWithText = new LicenseNameWithText();
licenseNameWithText.setLicenseName(name);
licenseNameWithText.setLicenseText(text);
licenseNameWithText.setAcknowledgements(acknowledgements);
return licenseNameWithText;
}
use of org.eclipse.sw360.datahandler.thrift.licenseinfo.LicenseNameWithText in project sw360portal by sw360.
the class ProjectPortletUtilsTest method createLicense.
private LicenseNameWithText createLicense(String name, String text) {
LicenseNameWithText licenseNameWithText = new LicenseNameWithText();
licenseNameWithText.setLicenseName(name);
licenseNameWithText.setLicenseText(text);
return licenseNameWithText;
}
use of org.eclipse.sw360.datahandler.thrift.licenseinfo.LicenseNameWithText in project sw360portal by sw360.
the class ProjectPortlet method serveAttachmentFileLicenses.
private void serveAttachmentFileLicenses(ResourceRequest request, ResourceResponse response) throws IOException {
final User user = UserCacheHolder.getUserFromRequest(request);
final String attachmentContentId = request.getParameter(PortalConstants.ATTACHMENT_ID);
final ComponentService.Iface componentClient = thriftClients.makeComponentClient();
final LicenseInfoService.Iface licenseInfoClient = thriftClients.makeLicenseInfoClient();
try {
Release release = componentClient.getReleaseById(request.getParameter(PortalConstants.RELEASE_ID), user);
List<LicenseInfoParsingResult> licenseInfos = licenseInfoClient.getLicenseInfoForAttachment(release, attachmentContentId, user);
// We generate a JSON-serializable list of licenses here.
// In addition we remember the license information for exclusion later on
Map<String, LicenseNameWithText> licenseStore = Maps.newHashMap();
List<Map<String, String>> licenses = Lists.newArrayList();
licenseInfos.forEach(licenseInfoResult -> addLicenseInfoResultToJsonSerializableLicensesList(licenseInfoResult, licenses, licenseStore::put));
licenses.sort((l1, l2) -> Strings.nullToEmpty(l1.get(LICENSE_NAME_WITH_TEXT_NAME)).compareTo(l2.get(LICENSE_NAME_WITH_TEXT_NAME)));
request.getPortletSession().setAttribute(LICENSE_STORE_KEY_PREFIX + attachmentContentId, licenseStore);
writeJSON(request, response, OBJECT_MAPPER.writeValueAsString(licenses));
} catch (TException exception) {
log.error("Cannot retrieve license information for attachment id " + attachmentContentId + ".", exception);
response.setProperty(ResourceResponse.HTTP_STATUS_CODE, "500");
}
}
use of org.eclipse.sw360.datahandler.thrift.licenseinfo.LicenseNameWithText in project sw360portal by sw360.
the class SPDXParserTools method getAllLicenseTextsFromInfo.
private static Stream<LicenseNameWithText> getAllLicenseTextsFromInfo(AnyLicenseInfo spdxLicenseInfo) {
log.trace("Seen the spdxLicenseInfo=" + spdxLicenseInfo.toString() + "]");
if (spdxLicenseInfo instanceof LicenseSet) {
LicenseSet LicenseSet = (LicenseSet) spdxLicenseInfo;
return Arrays.stream(LicenseSet.getMembers()).flatMap(SPDXParserTools::getAllLicenseTextsFromInfo);
} else if (spdxLicenseInfo instanceof ExtractedLicenseInfo) {
ExtractedLicenseInfo extractedLicenseInfo = (ExtractedLicenseInfo) spdxLicenseInfo;
return Stream.of(new LicenseNameWithText().setLicenseName(extractLicenseName(extractedLicenseInfo)).setLicenseText(extractedLicenseInfo.getExtractedText()));
} else if (spdxLicenseInfo instanceof License) {
License license = (License) spdxLicenseInfo;
return Stream.of(new LicenseNameWithText().setLicenseName(extractLicenseName(license)).setLicenseText(license.getLicenseText()));
} else if (spdxLicenseInfo instanceof OrLaterOperator) {
OrLaterOperator orLaterOperator = (OrLaterOperator) spdxLicenseInfo;
return getAllLicenseTextsFromInfo(orLaterOperator.getLicense()).map(lnwt -> lnwt.setLicenseName(lnwt.getLicenseName() + " or later"));
} else if (spdxLicenseInfo instanceof WithExceptionOperator) {
WithExceptionOperator withExceptionOperator = (WithExceptionOperator) spdxLicenseInfo;
String licenseExceptionText = withExceptionOperator.getException().getLicenseExceptionText();
return getAllLicenseTextsFromInfo(withExceptionOperator.getLicense()).map(licenseNWT -> licenseNWT.setLicenseText(licenseNWT.getLicenseText() + "\n\n" + licenseExceptionText).setLicenseName(licenseNWT.getLicenseName() + " with " + withExceptionOperator.getException().getName()));
}
log.debug("the spdxLicenseInfo=[" + spdxLicenseInfo.toString() + "] did not contain any license information");
return Stream.empty();
}
use of org.eclipse.sw360.datahandler.thrift.licenseinfo.LicenseNameWithText in project sw360portal by sw360.
the class LicenseInfoHandlerTest method createLicense.
private LicenseNameWithText createLicense(String name, String text, String acknowledgements) {
LicenseNameWithText licenseNameWithText = new LicenseNameWithText();
licenseNameWithText.setLicenseName(name);
licenseNameWithText.setLicenseText(text);
licenseNameWithText.setAcknowledgements(acknowledgements);
return licenseNameWithText;
}
Aggregations