Search in sources :

Example 16 with LicenseNameWithText

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

the class DocxGenerator method fillLicenseList.

private void fillLicenseList(XWPFDocument document, Collection<LicenseInfoParsingResult> projectLicenseInfoResults) {
    List<LicenseNameWithText> licenseNameWithTexts = OutputGenerator.getSortedLicenseNameWithTexts(projectLicenseInfoResults);
    XWPFRun licenseHeaderRun = document.createParagraph().createRun();
    addFormattedText(licenseHeaderRun, "License texts", FONT_SIZE + 2, true);
    addNewLines(document, 0);
    for (LicenseNameWithText licenseNameWithText : licenseNameWithTexts) {
        XWPFParagraph licenseParagraph = document.createParagraph();
        licenseParagraph.setStyle(STYLE_HEADING);
        String licenseName = licenseNameWithText.isSetLicenseName() ? licenseNameWithText.getLicenseName() : UNKNOWN_LICENSE_NAME;
        addBookmark(licenseParagraph, licenseName, licenseName);
        addNewLines(document, 0);
        setText(document.createParagraph().createRun(), nullToEmptyString(licenseNameWithText.getLicenseText()));
        addNewLines(document, 1);
    }
}
Also used : XWPFParagraph(org.apache.poi.xwpf.usermodel.XWPFParagraph) XWPFRun(org.apache.poi.xwpf.usermodel.XWPFRun) CommonUtils.nullToEmptyString(org.eclipse.sw360.datahandler.common.CommonUtils.nullToEmptyString)

Example 17 with LicenseNameWithText

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

the class CombinedCLIParser method nodeListToLicenseNamesWithTextsSetsByExternalId.

private Map<String, Set<LicenseNameWithText>> nodeListToLicenseNamesWithTextsSetsByExternalId(NodeList nodes, String externalIdAttributeName) {
    Map<String, Set<LicenseNameWithText>> result = Maps.newHashMap();
    for (int i = 0; i < nodes.getLength(); i++) {
        Node node = nodes.item(i);
        Optional<Node> externalIdOptional = findNamedAttribute(node, externalIdAttributeName);
        String externalId = externalIdOptional.map(Node::getNodeValue).orElse(null);
        LicenseNameWithText licenseNameWithText = getLicenseNameWithTextFromLicenseNode(node);
        if (!result.containsKey(externalId)) {
            result.put(externalId, Sets.newHashSet());
        }
        result.get(externalId).add(licenseNameWithText);
    }
    return result;
}
Also used : Node(org.w3c.dom.Node) LicenseNameWithText(org.eclipse.sw360.datahandler.thrift.licenseinfo.LicenseNameWithText)

Example 18 with LicenseNameWithText

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

the class CLIParserTest method testGetCLI.

@Test
public void testGetCLI() throws Exception {
    Attachment cliAttachment = new Attachment("A1", "a.xml");
    when(connector.getAttachmentStream(anyObject(), anyObject(), anyObject())).thenReturn(new ReaderInputStream(new StringReader(CLI_TESTFILE)));
    LicenseInfoParsingResult res = parser.getLicenseInfos(cliAttachment, new User(), new Project()).stream().findFirst().orElseThrow(() -> new RuntimeException("Parser returned empty LisenceInfoParsingResult list"));
    assertLicenseInfoParsingResult(res);
    assertThat(res.getStatus(), is(LicenseInfoRequestStatus.SUCCESS));
    assertThat(res.getLicenseInfo(), notNullValue());
    assertThat(res.getLicenseInfo().getFilenames(), contains("a.xml"));
    assertThat(res.getLicenseInfo().getLicenseNamesWithTexts().size(), is(1));
    assertThat(res.getLicenseInfo().getLicenseNamesWithTexts().stream().map(LicenseNameWithText::getLicenseText).collect(Collectors.toSet()), containsInAnyOrder("jQuery projects are released under the terms of the MIT license."));
    assertThat(res.getLicenseInfo().getCopyrights().size(), is(2));
    assertThat(res.getLicenseInfo().getCopyrights(), containsInAnyOrder("Copyrights", "(c) jQuery Foundation, Inc. | jquery.org"));
}
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) LicenseNameWithText(org.eclipse.sw360.datahandler.thrift.licenseinfo.LicenseNameWithText) StringReader(java.io.StringReader) Attachment(org.eclipse.sw360.datahandler.thrift.attachments.Attachment) LicenseInfoParsingResult(org.eclipse.sw360.datahandler.thrift.licenseinfo.LicenseInfoParsingResult) TestHelper.assertLicenseInfoParsingResult(org.eclipse.sw360.licenseinfo.TestHelper.assertLicenseInfoParsingResult) Test(org.junit.Test)

Example 19 with LicenseNameWithText

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

the class LicenseNameWithTextUtilsTest method testSanitize.

@Test
public void testSanitize() {
    LicenseNameWithText licenseNameWithText;
    licenseNameWithText = createLicense("name", null, null);
    LicenseNameWithTextUtils.sanitize(licenseNameWithText);
    Assert.assertThat(licenseNameWithText.getLicenseName(), Matchers.is("name"));
    licenseNameWithText = createLicense("\n", null, null);
    LicenseNameWithTextUtils.sanitize(licenseNameWithText);
    Assert.assertNull(licenseNameWithText.getLicenseName());
    licenseNameWithText = createLicense(null, "text", null);
    LicenseNameWithTextUtils.sanitize(licenseNameWithText);
    Assert.assertThat(licenseNameWithText.getLicenseText(), Matchers.is("text"));
    licenseNameWithText = createLicense(null, " ", null);
    LicenseNameWithTextUtils.sanitize(licenseNameWithText);
    Assert.assertNull(licenseNameWithText.getLicenseText());
    licenseNameWithText = createLicense(null, null, "acks");
    LicenseNameWithTextUtils.sanitize(licenseNameWithText);
    Assert.assertThat(licenseNameWithText.getAcknowledgements(), Matchers.is("acks"));
    licenseNameWithText = createLicense(null, null, "  ");
    LicenseNameWithTextUtils.sanitize(licenseNameWithText);
    Assert.assertNull(licenseNameWithText.getAcknowledgements());
}
Also used : LicenseNameWithText(org.eclipse.sw360.datahandler.thrift.licenseinfo.LicenseNameWithText) Test(org.junit.Test)

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