Search in sources :

Example 6 with LicenseInfoParsingResult

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

the class CombinedCLIParserTest 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(cliTestfile)));
    List<LicenseInfoParsingResult> results = parser.getLicenseInfos(cliAttachment, new User(), new Project());
    assertThat(results.size(), is(1));
    LicenseInfoParsingResult res = results.get(0);
    assertLicenseInfoParsingResult(res);
    assertThat(res.getLicenseInfo().getFilenames(), containsInAnyOrder("a.xml"));
    assertThat(res.getLicenseInfo().getLicenseNamesWithTexts().size(), is(3));
    assertThat(res.getLicenseInfo().getLicenseNamesWithTexts().stream().map(LicenseNameWithText::getLicenseText).collect(Collectors.toSet()), containsInAnyOrder("License1Text", "License2Text", "License3&'Text"));
    LicenseNameWithText l2 = res.getLicenseInfo().getLicenseNamesWithTexts().stream().filter(l -> l.getLicenseName().equals("License2")).findFirst().orElseThrow(AssertionError::new);
    assertThat(l2.getAcknowledgements(), is("License2Acknowledgements"));
    assertThat(res.getLicenseInfo().getCopyrights().size(), is(5));
    assertThat(res.getLicenseInfo().getCopyrights(), containsInAnyOrder("Copyright1", "Copyright2", "Copyright3", "Copyright4", "Copyright5"));
    assertThat(res.getVendor(), is("VendorA"));
    assertThat(res.getName(), is("r1"));
    assertThat(res.getVersion(), is("1.0"));
}
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 7 with LicenseInfoParsingResult

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

the class DocxGenerator method addReleaseTitle.

private void addReleaseTitle(XWPFDocument document, LicenseInfoParsingResult parsingResult) {
    String releaseTitle = getComponentLongName(parsingResult);
    XWPFParagraph releaseTitleParagraph = document.createParagraph();
    releaseTitleParagraph.setStyle(STYLE_HEADING);
    addBookmark(releaseTitleParagraph, releaseTitle, releaseTitle);
    addNewLines(document, 0);
}
Also used : XWPFParagraph(org.apache.poi.xwpf.usermodel.XWPFParagraph) CommonUtils.nullToEmptyString(org.eclipse.sw360.datahandler.common.CommonUtils.nullToEmptyString)

Example 8 with LicenseInfoParsingResult

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

the class DocxGenerator method addLicenses.

private void addLicenses(XWPFDocument document, LicenseInfoParsingResult parsingResult, boolean includeObligations) throws TException {
    XWPFRun licensesTitleRun = document.createParagraph().createRun();
    addNewLines(licensesTitleRun, 1);
    addFormattedText(licensesTitleRun, "Licenses", FONT_SIZE, true);
    for (String licenseName : getReleasesLicenses(parsingResult)) {
        XWPFParagraph licensePara = document.createParagraph();
        licensePara.setSpacingAfter(0);
        addBookmarkHyperLink(licensePara, licenseName, licenseName);
        if (includeObligations) {
            addLicenseObligations(document, licenseName);
        }
    }
}
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 9 with LicenseInfoParsingResult

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

the class DocxGenerator method addCopyrights.

private void addCopyrights(XWPFDocument document, LicenseInfoParsingResult parsingResult) {
    XWPFRun copyrightTitleRun = document.createParagraph().createRun();
    addFormattedText(copyrightTitleRun, "Copyrights", FONT_SIZE, true);
    for (String copyright : getReleaseCopyrights(parsingResult)) {
        XWPFParagraph copyPara = document.createParagraph();
        copyPara.setSpacingAfter(0);
        setText(copyPara.createRun(), copyright);
    }
}
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 10 with LicenseInfoParsingResult

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

the class OutputGenerator method renderTemplateWithDefaultValues.

/**
 * Creates a velocity context and fills it with the default, commonly used
 * values:
 * <ul>
 * <li>allLicenseNamesWithTexts: list of {@link LicenseNameWithText} objects,
 * sorted by license name</li>
 * <li>licenseNameWithTextToReferenceId: map from the license name to a unique
 * id inside the file. May be used to reference a license.</li>
 * <li>licenseInfoResults: map of {@link LicenseInfoParsingResult} objects,
 * where the key is the name of the release. The licenses within the objects are
 * sorted by name. Contains only the results with status {@link LicenseInfoRequestStatus#SUCCESS}</li>
 * <li>licenseInfoErrorResults: map {@link List}of {@link LicenseInfoParsingResult} objects,
 * where the key is the name of the release. Contains only the results with status other than
 * {@link LicenseInfoRequestStatus#SUCCESS}. These results are not merged, that's why the map values are lists.</li>
 * <li>acknowledgments: map of acknowledgments for a release where the key is
 * the release and the value is a set of strings (acknowledgments)</li>
 * </ul>
 * The given file will be used as velocity template and will be rendered with
 * the described data.
 *
 * @param projectLicenseInfoResults
 *            parsing results to be rendered
 * @param file
 *            name of template file
 * @return rendered template
 */
protected String renderTemplateWithDefaultValues(Collection<LicenseInfoParsingResult> projectLicenseInfoResults, String file, String projectTitle, String licenseInfoHeaderText) {
    VelocityContext vc = getConfiguredVelocityContext();
    // set header
    vc.put(LICENSE_INFO_PROJECT_TITLE, projectTitle);
    vc.put(LICENSE_INFO_HEADER_TEXT, licenseInfoHeaderText);
    // sorted lists of all license to be displayed at the end of the file at once
    List<LicenseNameWithText> licenseNamesWithTexts = getSortedLicenseNameWithTexts(projectLicenseInfoResults);
    vc.put(ALL_LICENSE_NAMES_WITH_TEXTS, licenseNamesWithTexts);
    // assign a reference id to each license in order to only display references for
    // each release. The references will point to
    // the list with all details at the and of the file (see above)
    int referenceId = 1;
    Map<LicenseNameWithText, Integer> licenseToReferenceId = Maps.newHashMap();
    for (LicenseNameWithText licenseNamesWithText : licenseNamesWithTexts) {
        licenseToReferenceId.put(licenseNamesWithText, referenceId++);
    }
    vc.put(LICENSE_REFERENCE_ID_MAP_CONTEXT_PROPERTY, licenseToReferenceId);
    Map<Boolean, List<LicenseInfoParsingResult>> partitionedResults = projectLicenseInfoResults.stream().collect(Collectors.partitioningBy(r -> r.getStatus() == LicenseInfoRequestStatus.SUCCESS));
    List<LicenseInfoParsingResult> goodResults = partitionedResults.get(true);
    Map<String, List<LicenseInfoParsingResult>> badResultsPerRelease = partitionedResults.get(false).stream().collect(Collectors.groupingBy(this::getComponentLongName));
    vc.put(LICENSE_INFO_ERROR_RESULTS_CONTEXT_PROPERTY, badResultsPerRelease);
    // be sure that the licenses inside a release are sorted by id. This looks nicer
    SortedMap<String, LicenseInfoParsingResult> sortedLicenseInfos = getSortedLicenseInfos(goodResults);
    // this will effectively change the objects in the collection and therefore the
    // objects in the sorted map above
    sortLicenseNamesWithinEachLicenseInfoById(sortedLicenseInfos.values(), licenseToReferenceId);
    vc.put(LICENSE_INFO_RESULTS_CONTEXT_PROPERTY, sortedLicenseInfos);
    // also display acknowledgments
    SortedMap<String, Set<String>> acknowledgements = getSortedAcknowledgements(sortedLicenseInfos);
    vc.put(ACKNOWLEDGEMENTS_CONTEXT_PROPERTY, acknowledgements);
    StringWriter sw = new StringWriter();
    Velocity.mergeTemplate(file, "utf-8", vc, sw);
    IOUtils.closeQuietly(sw);
    return sw.toString();
}
Also used : SW360Utils(org.eclipse.sw360.datahandler.common.SW360Utils) java.util(java.util) StringWriter(java.io.StringWriter) RuntimeConstants(org.apache.velocity.runtime.RuntimeConstants) ClasspathResourceLoader(org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader) LicenseNameWithTextUtils(org.eclipse.sw360.licenseinfo.util.LicenseNameWithTextUtils) SW360Exception(org.eclipse.sw360.datahandler.thrift.SW360Exception) Maps(com.google.common.collect.Maps) VelocityContext(org.apache.velocity.VelocityContext) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) ToolManager(org.apache.velocity.tools.ToolManager) IOUtils(org.apache.commons.io.IOUtils) CommonUtils(org.eclipse.sw360.datahandler.common.CommonUtils) org.eclipse.sw360.datahandler.thrift.licenseinfo(org.eclipse.sw360.datahandler.thrift.licenseinfo) Velocity(org.apache.velocity.app.Velocity) NotNull(org.jetbrains.annotations.NotNull) FileResourceLoader(org.apache.velocity.runtime.resource.loader.FileResourceLoader) VelocityContext(org.apache.velocity.VelocityContext) StringWriter(java.io.StringWriter)

Aggregations

LicenseInfoParsingResult (org.eclipse.sw360.datahandler.thrift.licenseinfo.LicenseInfoParsingResult)12 Test (org.junit.Test)7 CommonUtils.nullToEmptyString (org.eclipse.sw360.datahandler.common.CommonUtils.nullToEmptyString)5 Attachment (org.eclipse.sw360.datahandler.thrift.attachments.Attachment)5 Release (org.eclipse.sw360.datahandler.thrift.components.Release)5 LicenseInfo (org.eclipse.sw360.datahandler.thrift.licenseinfo.LicenseInfo)5 Project (org.eclipse.sw360.datahandler.thrift.projects.Project)5 User (org.eclipse.sw360.datahandler.thrift.users.User)5 XWPFParagraph (org.apache.poi.xwpf.usermodel.XWPFParagraph)4 XWPFRun (org.apache.poi.xwpf.usermodel.XWPFRun)4 TException (org.apache.thrift.TException)4 SW360Exception (org.eclipse.sw360.datahandler.thrift.SW360Exception)4 AttachmentContent (org.eclipse.sw360.datahandler.thrift.attachments.AttachmentContent)4 IOException (java.io.IOException)3 InputStream (java.io.InputStream)3 StringReader (java.io.StringReader)3 WrappedTException (org.eclipse.sw360.datahandler.common.WrappedException.WrappedTException)3 LicenseNameWithText (org.eclipse.sw360.datahandler.thrift.licenseinfo.LicenseNameWithText)3 Maps (com.google.common.collect.Maps)2 Sets (com.google.common.collect.Sets)2