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