Search in sources :

Example 11 with LicenseNameWithText

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;
}
Also used : LicenseNameWithText(org.eclipse.sw360.datahandler.thrift.licenseinfo.LicenseNameWithText)

Example 12 with 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;
}
Also used : LicenseNameWithText(org.eclipse.sw360.datahandler.thrift.licenseinfo.LicenseNameWithText)

Example 13 with 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");
    }
}
Also used : WrappedTException(org.eclipse.sw360.datahandler.common.WrappedException.WrappedTException) TException(org.apache.thrift.TException) User(org.eclipse.sw360.datahandler.thrift.users.User) ComponentService(org.eclipse.sw360.datahandler.thrift.components.ComponentService) Release(org.eclipse.sw360.datahandler.thrift.components.Release)

Example 14 with LicenseNameWithText

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();
}
Also used : LicenseInfoParsingResult(org.eclipse.sw360.datahandler.thrift.licenseinfo.LicenseInfoParsingResult) Arrays(java.util.Arrays) SpdxPackage(org.spdx.rdfparser.model.SpdxPackage) SpdxFile(org.spdx.rdfparser.model.SpdxFile) LicenseInfoRequestStatus(org.eclipse.sw360.datahandler.thrift.licenseinfo.LicenseInfoRequestStatus) Collectors(java.util.stream.Collectors) org.spdx.rdfparser.license(org.spdx.rdfparser.license) HashSet(java.util.HashSet) Logger(org.apache.log4j.Logger) AttachmentContent(org.eclipse.sw360.datahandler.thrift.attachments.AttachmentContent) Stream(java.util.stream.Stream) LicenseInfo(org.eclipse.sw360.datahandler.thrift.licenseinfo.LicenseInfo) InvalidSPDXAnalysisException(org.spdx.rdfparser.InvalidSPDXAnalysisException) SpdxItem(org.spdx.rdfparser.model.SpdxItem) SpdxDocument(org.spdx.rdfparser.model.SpdxDocument) LicenseNameWithText(org.eclipse.sw360.datahandler.thrift.licenseinfo.LicenseNameWithText) CommonUtils.isNullEmptyOrWhitespace(org.eclipse.sw360.datahandler.common.CommonUtils.isNullEmptyOrWhitespace) LicenseNameWithText(org.eclipse.sw360.datahandler.thrift.licenseinfo.LicenseNameWithText)

Example 15 with LicenseNameWithText

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;
}
Also used : LicenseNameWithText(org.eclipse.sw360.datahandler.thrift.licenseinfo.LicenseNameWithText)

Aggregations

LicenseNameWithText (org.eclipse.sw360.datahandler.thrift.licenseinfo.LicenseNameWithText)11 LicenseInfoParsingResult (org.eclipse.sw360.datahandler.thrift.licenseinfo.LicenseInfoParsingResult)6 User (org.eclipse.sw360.datahandler.thrift.users.User)6 Release (org.eclipse.sw360.datahandler.thrift.components.Release)5 Project (org.eclipse.sw360.datahandler.thrift.projects.Project)4 Collectors (java.util.stream.Collectors)3 TException (org.apache.thrift.TException)3 WrappedTException (org.eclipse.sw360.datahandler.common.WrappedException.WrappedTException)3 SW360Exception (org.eclipse.sw360.datahandler.thrift.SW360Exception)3 Attachment (org.eclipse.sw360.datahandler.thrift.attachments.Attachment)3 AttachmentContent (org.eclipse.sw360.datahandler.thrift.attachments.AttachmentContent)3 LicenseInfo (org.eclipse.sw360.datahandler.thrift.licenseinfo.LicenseInfo)3 Maps (com.google.common.collect.Maps)2 Sets (com.google.common.collect.Sets)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 StringReader (java.io.StringReader)2 java.util (java.util)2 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)2 XPathExpressionException (javax.xml.xpath.XPathExpressionException)2