diff --git a/backend/licenseinfo/src/main/java/org/eclipse/sw360/licenseinfo/LicenseInfoHandler.java b/backend/licenseinfo/src/main/java/org/eclipse/sw360/licenseinfo/LicenseInfoHandler.java index 403024f2b6..d9cfedc904 100644 --- a/backend/licenseinfo/src/main/java/org/eclipse/sw360/licenseinfo/LicenseInfoHandler.java +++ b/backend/licenseinfo/src/main/java/org/eclipse/sw360/licenseinfo/LicenseInfoHandler.java @@ -127,6 +127,16 @@ public LicenseInfoFile getLicenseInfoFile(Project project, User user, String out Map> releaseIdsToSelectedAttachmentIds, Map> excludedLicensesPerAttachment, String externalIds, String fileName) throws TException { + return getLicenseInfoFileWithoutReleaseVersion(project, user, outputGenerator, + releaseIdsToSelectedAttachmentIds, excludedLicensesPerAttachment, externalIds, fileName, false); + } + + @Override + public LicenseInfoFile getLicenseInfoFileWithoutReleaseVersion(Project project, User user, String outputGenerator, + Map> releaseIdsToSelectedAttachmentIds, + Map> excludedLicensesPerAttachment, String externalIds, String fileName, + boolean excludeReleaseVersion) + throws TException { assertNotNull(project); assertNotNull(user); assertNotNull(outputGenerator); @@ -170,7 +180,7 @@ public LicenseInfoFile getLicenseInfoFile(Project project, User user, String out } Object output = generator.generateOutputFile(projectLicenseInfoResults, project, obligationsResults, user, - filteredExtIdMap, obligationsStatusInfoMap, fileName); + filteredExtIdMap, obligationsStatusInfoMap, fileName, excludeReleaseVersion); if (output instanceof byte[]) { licenseInfoFile.setGeneratedOutput((byte[]) output); } else if (output instanceof String) { @@ -182,6 +192,7 @@ public LicenseInfoFile getLicenseInfoFile(Project project, User user, String out return licenseInfoFile; } + @Override public Map> evaluateAttachments(String releaseId, User user) throws TException { Release release = componentDatabaseHandler.getRelease(releaseId, user); Map parsedResults = new HashMap(); @@ -619,7 +630,7 @@ public List getLicenseInfoForAttachment(Release releas } @Override - public LicenseObligationsStatusInfo getProjectObligationStatus(Map obligationStatusMap, List licenseResults, + public LicenseObligationsStatusInfo getProjectObligationStatus(Map obligationStatusMap, List licenseResults, Map excludedReleaseIdToAcceptedCLI) { Map filteredObligationStatusMap = obligationStatusMap.isEmpty() diff --git a/backend/licenseinfo/src/main/java/org/eclipse/sw360/licenseinfo/outputGenerators/DocxGenerator.java b/backend/licenseinfo/src/main/java/org/eclipse/sw360/licenseinfo/outputGenerators/DocxGenerator.java index 94d0e21a82..abb923a44d 100644 --- a/backend/licenseinfo/src/main/java/org/eclipse/sw360/licenseinfo/outputGenerators/DocxGenerator.java +++ b/backend/licenseinfo/src/main/java/org/eclipse/sw360/licenseinfo/outputGenerators/DocxGenerator.java @@ -101,7 +101,9 @@ public DocxGenerator(OutputFormatVariant outputFormatVariant, String description } @Override - public byte[] generateOutputFile(Collection projectLicenseInfoResults, Project project, Collection obligationResults, User user, Map externalIds, Map obligationsStatus, String fileName) throws SW360Exception { + public byte[] generateOutputFile(Collection projectLicenseInfoResults, Project project, + Collection obligationResults, User user, Map externalIds, + Map obligationsStatus, String fileName, boolean excludeReleaseVersion) throws SW360Exception { String licenseInfoHeaderText = project.getLicenseInfoHeaderText(); ByteArrayOutputStream docxOutputStream = new ByteArrayOutputStream(); @@ -119,7 +121,8 @@ public byte[] generateOutputFile(Collection projectLic project, licenseInfoHeaderText, false, - externalIds + externalIds, + excludeReleaseVersion ); } else { throw new SW360Exception("Could not load the template for xwpf document: " + DOCX_TEMPLATE_FILE); @@ -168,7 +171,8 @@ private void fillDisclosureDocument( Collection projectLicenseInfoResults, Project project, String licenseInfoHeaderText, - boolean includeObligations, Map externalIds) throws XmlException, TException { + boolean includeObligations, Map externalIds, boolean excludeReleaseVersion) + throws XmlException, TException { if (CommonUtils.isNotEmpty(projectLicenseInfoResults)) { projectLicenseInfoResults = projectLicenseInfoResults.stream().filter(Objects::nonNull) .sorted(Comparator.comparing(li -> getComponentLongName(li), String.CASE_INSENSITIVE_ORDER)) @@ -188,8 +192,8 @@ private void fillDisclosureDocument( return; } - fillReleaseBulletList(document, projectLicenseInfoResults); - fillReleaseDetailList(document, projectLicenseInfoResults, includeObligations, licenseToReferenceId); + fillReleaseBulletList(document, projectLicenseInfoResults, excludeReleaseVersion); + fillReleaseDetailList(document, projectLicenseInfoResults, includeObligations, licenseToReferenceId, excludeReleaseVersion); fillLicenseList(document, projectLicenseInfoResults, licenseToReferenceId); } @@ -308,9 +312,9 @@ private void fillReportDocument( List obligations = SW360Utils.getObligations(); fillProjectComponentOrganisationObligationsTable(document, obligationsStatus, obligations, ObligationLevel.ORGANISATION_OBLIGATION, COMMON_RULES_TABLE_INDEX, NO_ORGANISATION_OBLIGATIONS); - fillProjectComponentOrganisationObligationsTable(document, obligationsStatus, obligations, + fillProjectComponentOrganisationObligationsTable(document, obligationsStatus, obligations, ObligationLevel.PROJECT_OBLIGATION, PROJECT_OBLIGATIONS_TABLE_INDEX, NO_PROJECT_OBLIGATIONS); - fillProjectComponentOrganisationObligationsTable(document, obligationsStatus, obligations, + fillProjectComponentOrganisationObligationsTable(document, obligationsStatus, obligations, ObligationLevel.COMPONENT_OBLIGATION, COMPONENT_OBLIGATIONS_TABLE_INDEX, NO_COMPONENT_OBLIGATIONS); fillComponentObligationsTable(document, obligationResults, mostLicenses, project); @@ -720,24 +724,38 @@ private XmlCursor moveCursor(XmlCursor cursor) throws SW360Exception { return cursor; } - private void fillReleaseBulletList(XWPFDocument document, Collection projectLicenseInfoResults) throws XmlException { + private void fillReleaseBulletList(XWPFDocument document, Collection projectLicenseInfoResults, + boolean excludeReleaseVersion) throws XmlException { List releaseList = new ArrayList<>(); - for (LicenseInfoParsingResult result : projectLicenseInfoResults) { - releaseList.add(getComponentLongName(result)); + + if (excludeReleaseVersion) { + for (LicenseInfoParsingResult result : projectLicenseInfoResults) { + releaseList.add(getComponentLongNameWithoutVersion(result)); + } + } else { + for (LicenseInfoParsingResult result : projectLicenseInfoResults) { + releaseList.add(getComponentLongName(result)); + } } addBulletList(document, releaseList, true); addPageBreak(document); } - private void fillReleaseDetailList(XWPFDocument document, Collection projectLicenseInfoResults, boolean includeObligations, Map licenseToReferenceId) throws TException { + private void fillReleaseDetailList(XWPFDocument document, + Collection projectLicenseInfoResults, boolean includeObligations, + Map licenseToReferenceId, boolean excludeReleaseVersion) throws TException { addFormattedText(document.createParagraph().createRun(), "Detailed Releases Information", FONT_SIZE + 2, true); setText(document.createParagraph().createRun(), "Please note the following license conditions and copyright " + "notices applicable to Open Source Software and/or other components (or parts thereof):"); addNewLines(document, 0); - Map> sortedAcknowledgement = getAcknowledgement(projectLicenseInfoResults); + Map> sortedAcknowledgement = getAcknowledgement(projectLicenseInfoResults, excludeReleaseVersion); for (LicenseInfoParsingResult parsingResult : projectLicenseInfoResults) { - addReleaseTitle(document, parsingResult); - addAcknowledgement(document, sortedAcknowledgement.get(getComponentLongName(parsingResult))); + addReleaseTitle(document, parsingResult, excludeReleaseVersion); + if (excludeReleaseVersion) { + addAcknowledgement(document, sortedAcknowledgement.get(getComponentLongNameWithoutVersion(parsingResult))); + } else { + addAcknowledgement(document, sortedAcknowledgement.get(getComponentLongName(parsingResult))); + } if (parsingResult.getStatus() == LicenseInfoRequestStatus.SUCCESS) { addLicenses(document, parsingResult, includeObligations, licenseToReferenceId); addNewLines(document, 1); @@ -766,18 +784,17 @@ private void addAcknowledgement(XWPFDocument document, Set acknowledgeme } private SortedMap> getAcknowledgement( - Collection projectLicenseInfoResults) { + Collection projectLicenseInfoResults, boolean excludeReleaseVersion) { Map> partitionedResults = projectLicenseInfoResults.stream() .collect(Collectors.partitioningBy(r -> r.getStatus() == LicenseInfoRequestStatus.SUCCESS)); List goodResults = partitionedResults.get(true); - return getSortedAcknowledgements(getSortedLicenseInfos(goodResults)); - + return getSortedAcknowledgements(getSortedLicenseInfos(goodResults, excludeReleaseVersion)); } - private void addReleaseTitle(XWPFDocument document, LicenseInfoParsingResult parsingResult) { - String releaseTitle = getComponentLongName(parsingResult); + private void addReleaseTitle(XWPFDocument document, LicenseInfoParsingResult parsingResult, boolean excludeReleaseVersion) { + String releaseTitle = excludeReleaseVersion ? getComponentLongNameWithoutVersion(parsingResult) : getComponentLongName(parsingResult); XWPFParagraph releaseTitleParagraph = document.createParagraph(); releaseTitleParagraph.setStyle(STYLE_HEADING); addBookmark(releaseTitleParagraph, releaseTitle, releaseTitle); diff --git a/backend/licenseinfo/src/main/java/org/eclipse/sw360/licenseinfo/outputGenerators/JsonGenerator.java b/backend/licenseinfo/src/main/java/org/eclipse/sw360/licenseinfo/outputGenerators/JsonGenerator.java index 43ea0abbb1..abf0bde184 100644 --- a/backend/licenseinfo/src/main/java/org/eclipse/sw360/licenseinfo/outputGenerators/JsonGenerator.java +++ b/backend/licenseinfo/src/main/java/org/eclipse/sw360/licenseinfo/outputGenerators/JsonGenerator.java @@ -37,8 +37,9 @@ public JsonGenerator(OutputFormatVariant outputFormatVariant, String description } @Override - public String generateOutputFile(Collection projectLicenseInfoResults, Project project, Collection obligationResults, User user, Map externalIds, Map obligationsStatus, String fileName) throws SW360Exception { + public String generateOutputFile(Collection projectLicenseInfoResults, Project project, + Collection obligationResults, User user, Map externalIds, + Map obligationsStatus, String fileName, boolean excludeReleaseVersion) throws SW360Exception { return ""; - } -} \ No newline at end of file +} diff --git a/backend/licenseinfo/src/main/java/org/eclipse/sw360/licenseinfo/outputGenerators/OutputGenerator.java b/backend/licenseinfo/src/main/java/org/eclipse/sw360/licenseinfo/outputGenerators/OutputGenerator.java index 0e74779b01..8077b3fe61 100644 --- a/backend/licenseinfo/src/main/java/org/eclipse/sw360/licenseinfo/outputGenerators/OutputGenerator.java +++ b/backend/licenseinfo/src/main/java/org/eclipse/sw360/licenseinfo/outputGenerators/OutputGenerator.java @@ -64,7 +64,11 @@ public abstract class OutputGenerator { this.outputVariant = variant; } - public abstract T generateOutputFile(Collection projectLicenseInfoResults, Project project, Collection obligationResults, User user, Map externalIds, Map obligationsStatus, String fileName) throws SW360Exception; + public abstract T generateOutputFile(Collection projectLicenseInfoResults, + Project project, Collection obligationResults, User user, + Map externalIds, Map obligationsStatus, String fileName, + boolean excludeReleaseVersion) + throws SW360Exception; public String getOutputType() { return outputType; @@ -100,6 +104,10 @@ public String getComponentLongName(LicenseInfoParsingResult li) { return SW360Utils.getReleaseFullname(li.getVendor(), li.getName(), li.getVersion()); } + public String getComponentLongNameWithoutVersion(LicenseInfoParsingResult li) { + return SW360Utils.getReleaseFullname(li.getVendor(), li.getName(), ""); + } + public String getComponentShortName(LicenseInfoParsingResult li) { return SW360Utils.getReleaseFullname("", li.getName(), li.getVersion()); } @@ -116,17 +124,25 @@ public VelocityContext getConfiguredVelocityContext() { return new VelocityContext(velocityToolManager.createContext()); } - @NotNull - protected SortedMap getSortedLicenseInfos(Collection projectLicenseInfoResults) { - Map licenseInfos = projectLicenseInfoResults.stream() - .collect(Collectors.toMap(this::getComponentLongName, li -> li, this::mergeLicenseInfoParsingResults)); - return sortStringKeyedMap(licenseInfos); - } + @NotNull + protected SortedMap getSortedLicenseInfos( + Collection projectLicenseInfoResults, boolean excludeReleaseVersion) { + Map licenseInfos = excludeReleaseVersion + ? projectLicenseInfoResults.stream() + .collect(Collectors.toMap(this::getComponentLongNameWithoutVersion, li -> li, + (l1, l2) -> mergeLicenseInfoParsingResults(l1, l2, true))) + : projectLicenseInfoResults.stream().collect(Collectors.toMap(this::getComponentLongName, li -> li, + (l1, l2) -> mergeLicenseInfoParsingResults(l1, l2, false))); + return sortStringKeyedMap(licenseInfos); + } @NotNull - protected LicenseInfoParsingResult mergeLicenseInfoParsingResults(LicenseInfoParsingResult r1, LicenseInfoParsingResult r2){ + protected LicenseInfoParsingResult mergeLicenseInfoParsingResults(LicenseInfoParsingResult r1, LicenseInfoParsingResult r2, boolean excludeReleaseVersion){ + String r1_name = excludeReleaseVersion ? getComponentLongNameWithoutVersion(r1) : getComponentLongName(r1); + String r2_name = excludeReleaseVersion ? getComponentLongNameWithoutVersion(r2) : getComponentLongName(r2); + if (r1.getStatus() != LicenseInfoRequestStatus.SUCCESS || r2.getStatus() != LicenseInfoRequestStatus.SUCCESS || - !getComponentLongName(r1).equals(getComponentLongName(r2))){ + !r1_name.equals(r2_name)){ throw new IllegalArgumentException("Only successful parsing results for the same release can be merged"); } @@ -230,8 +246,9 @@ private static SortedMap sortStringKeyedMap(Map unsort * @param externalIds * @return rendered template */ - protected String renderTemplateWithDefaultValues(Collection projectLicenseInfoResults, String file, - String projectTitle, String licenseInfoHeaderText, String obligationsText, Map externalIds) { + protected String renderTemplateWithDefaultValues(Collection projectLicenseInfoResults, + String file, String projectTitle, String licenseInfoHeaderText, String obligationsText, + Map externalIds, boolean excludeReleaseVersion) { VelocityContext vc = getConfiguredVelocityContext(); // set header vc.put(LICENSE_INFO_PROJECT_TITLE, projectTitle); @@ -254,12 +271,15 @@ protected String renderTemplateWithDefaultValues(Collection> partitionedResults = projectLicenseInfoResults.stream().collect(Collectors.partitioningBy(r -> r.getStatus() == LicenseInfoRequestStatus.SUCCESS)); List goodResults = partitionedResults.get(true); - Map> badResultsPerRelease = - partitionedResults.get(false).stream().collect(Collectors.groupingBy(this::getComponentLongName)); + + Map> badResultsPerRelease = excludeReleaseVersion + ? partitionedResults.get(false).stream() + .collect(Collectors.groupingBy(this::getComponentLongNameWithoutVersion)) + : 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 sortedLicenseInfos = getSortedLicenseInfos(goodResults); + SortedMap sortedLicenseInfos = getSortedLicenseInfos(goodResults, excludeReleaseVersion); // this will effectively change the objects in the collection and therefore the // objects in the sorted map above sortLicenseNamesWithinEachLicenseInfoById(sortedLicenseInfos.values(), licenseToReferenceId); diff --git a/backend/licenseinfo/src/main/java/org/eclipse/sw360/licenseinfo/outputGenerators/TextGenerator.java b/backend/licenseinfo/src/main/java/org/eclipse/sw360/licenseinfo/outputGenerators/TextGenerator.java index ecac32f6d6..553d8f654a 100644 --- a/backend/licenseinfo/src/main/java/org/eclipse/sw360/licenseinfo/outputGenerators/TextGenerator.java +++ b/backend/licenseinfo/src/main/java/org/eclipse/sw360/licenseinfo/outputGenerators/TextGenerator.java @@ -37,7 +37,10 @@ public TextGenerator(OutputFormatVariant outputFormatVariant, String outputDescr } @Override - public String generateOutputFile(Collection projectLicenseInfoResults, Project project, Collection obligationResults, User user, Map externalIds, Map obligationsStatus, String fileName) throws SW360Exception { + public String generateOutputFile(Collection projectLicenseInfoResults, Project project, + Collection obligationResults, User user, Map externalIds, + Map obligationsStatus, String fileName, + boolean excludeReleaseVersion) throws SW360Exception { String projectName = project.getName(); String projectVersion = project.getVersion(); String licenseInfoHeaderText = project.getLicenseInfoHeaderText(); @@ -45,14 +48,19 @@ public String generateOutputFile(Collection projectLic switch (getOutputVariant()) { case DISCLOSURE: - return generateDisclosure(projectLicenseInfoResults, projectName + " " + projectVersion, licenseInfoHeaderText, obligationsText, externalIds); + return generateDisclosure(projectLicenseInfoResults, projectName + " " + projectVersion, + licenseInfoHeaderText, obligationsText, externalIds, excludeReleaseVersion); default: throw new IllegalArgumentException("Unknown generator variant type: " + getOutputVariant()); } } - private String generateDisclosure(Collection projectLicenseInfoResults, String projectTitle, String licenseInfoHeaderText, String obligationsText, Map externalIds) { + + private String generateDisclosure(Collection projectLicenseInfoResults, + String projectTitle, String licenseInfoHeaderText, String obligationsText, + Map externalIds, boolean excludeReleaseVersion) { try { - return renderTemplateWithDefaultValues(projectLicenseInfoResults, TXT_TEMPLATE_FILE, projectTitle, licenseInfoHeaderText, obligationsText, externalIds); + return renderTemplateWithDefaultValues(projectLicenseInfoResults, TXT_TEMPLATE_FILE, projectTitle, + licenseInfoHeaderText, obligationsText, externalIds, excludeReleaseVersion); } catch (Exception e) { LOGGER.error("Could not generate text licenseinfo file for project " + projectTitle, e); return "License information could not be generated.\nAn exception occurred: " + e.toString(); diff --git a/backend/licenseinfo/src/main/java/org/eclipse/sw360/licenseinfo/outputGenerators/XhtmlGenerator.java b/backend/licenseinfo/src/main/java/org/eclipse/sw360/licenseinfo/outputGenerators/XhtmlGenerator.java index 73c117ef8d..e4d0054015 100644 --- a/backend/licenseinfo/src/main/java/org/eclipse/sw360/licenseinfo/outputGenerators/XhtmlGenerator.java +++ b/backend/licenseinfo/src/main/java/org/eclipse/sw360/licenseinfo/outputGenerators/XhtmlGenerator.java @@ -38,7 +38,9 @@ public XhtmlGenerator(OutputFormatVariant outputFormatVariant, String descriptio } @Override - public String generateOutputFile(Collection projectLicenseInfoResults, Project project, Collection obligationResults, User user, Map externalIds, Map obligationsStatus, String fileName) throws SW360Exception { + public String generateOutputFile(Collection projectLicenseInfoResults, Project project, + Collection obligationResults, User user, Map externalIds, + Map obligationsStatus, String fileName, boolean excludeReleaseVersion) throws SW360Exception { String projectName = project.getName(); String projectVersion = project.getVersion(); String licenseInfoHeaderText = project.getLicenseInfoHeaderText(); @@ -46,15 +48,19 @@ public String generateOutputFile(Collection projectLic switch (getOutputVariant()) { case DISCLOSURE: - return generateDisclosure(projectLicenseInfoResults, projectName + " " + projectVersion, licenseInfoHeaderText, obligationsText, externalIds); + return generateDisclosure(projectLicenseInfoResults, projectName + " " + projectVersion, licenseInfoHeaderText, obligationsText, externalIds, excludeReleaseVersion); default: throw new IllegalArgumentException("Unknown generator variant type: " + getOutputVariant()); } } - private String generateDisclosure(Collection projectLicenseInfoResults, String projectTitle, String licenseInfoHeaderText, String obligationsText, Map externalIds) { + private String generateDisclosure(Collection projectLicenseInfoResults, + String projectTitle, String licenseInfoHeaderText, String obligationsText, Map externalIds, + boolean excludeReleaseVersion) { try { - return renderTemplateWithDefaultValues(projectLicenseInfoResults, XHTML_TEMPLATE_FILE, projectTitle, convertHeaderTextToHTML(licenseInfoHeaderText), convertHeaderTextToHTML(obligationsText), externalIds); + return renderTemplateWithDefaultValues(projectLicenseInfoResults, XHTML_TEMPLATE_FILE, projectTitle, + convertHeaderTextToHTML(licenseInfoHeaderText), convertHeaderTextToHTML(obligationsText), + externalIds, excludeReleaseVersion); } catch (Exception e) { LOGGER.error("Could not generate xhtml license info file for project " + projectTitle, e); return "License information could not be generated.\nAn exception occured: " + e.toString(); diff --git a/backend/licenseinfo/src/test/java/org/eclipse/sw360/licenseinfo/outputGenerators/XhtmlGeneratorTest.java b/backend/licenseinfo/src/test/java/org/eclipse/sw360/licenseinfo/outputGenerators/XhtmlGeneratorTest.java index 3c0d4d097d..0b5baae371 100644 --- a/backend/licenseinfo/src/test/java/org/eclipse/sw360/licenseinfo/outputGenerators/XhtmlGeneratorTest.java +++ b/backend/licenseinfo/src/test/java/org/eclipse/sw360/licenseinfo/outputGenerators/XhtmlGeneratorTest.java @@ -136,10 +136,10 @@ public static void setUp() throws Exception { Map externalIds = Collections.emptyMap(); Map obligationsStatus = Collections.emptyMap(); - xmlString = xhtmlGenerator.generateOutputFile(lipresults, p, obligationResults, null, externalIds, obligationsStatus, ""); - xmlString2 = xhtmlGenerator.generateOutputFile(lipresults2, p, obligationResults, null, externalIds, obligationsStatus, ""); - xmlString3 = xhtmlGenerator.generateOutputFile(lipresults3, p, obligationResults, null, externalIds, obligationsStatus, ""); - xmlStringEmpty = xhtmlGenerator.generateOutputFile(lipresultsEmpty, p, obligationResults, null, externalIds, obligationsStatus, ""); + xmlString = xhtmlGenerator.generateOutputFile(lipresults, p, obligationResults, null, externalIds, obligationsStatus, "", false); + xmlString2 = xhtmlGenerator.generateOutputFile(lipresults2, p, obligationResults, null, externalIds, obligationsStatus, "", false); + xmlString3 = xhtmlGenerator.generateOutputFile(lipresults3, p, obligationResults, null, externalIds, obligationsStatus, "", false); + xmlStringEmpty = xhtmlGenerator.generateOutputFile(lipresultsEmpty, p, obligationResults, null, externalIds, obligationsStatus, "", false); generateDocumentsFromXml(); } diff --git a/libraries/datahandler/src/main/thrift/licenseinfo.thrift b/libraries/datahandler/src/main/thrift/licenseinfo.thrift index 2e3305050b..8368e4aa9d 100644 --- a/libraries/datahandler/src/main/thrift/licenseinfo.thrift +++ b/libraries/datahandler/src/main/thrift/licenseinfo.thrift @@ -144,6 +144,17 @@ service LicenseInfoService { */ LicenseInfoFile getLicenseInfoFile(1: Project project, 2: User user, 3: string outputGeneratorClassName, 4: map> releaseIdsToSelectedAttachmentIds, 5: map> excludedLicensesPerAttachment, 6: string externalIds, 7: string fileName); + /** + * Get copyright and license information file of linked releases of the project and its sub-projects (recursively) + * If excludeReleaseVersion is true, the release version will be excluded from the license file + * Output format as specified by outputType + */ + LicenseInfoFile getLicenseInfoFileWithoutReleaseVersion(1: Project project, 2: User user, 3: string outputGeneratorClassName, + 4: map> releaseIdsToSelectedAttachmentIds, + 5: map> excludedLicensesPerAttachment, 6: string externalIds, 7: string fileName, + 8: bool excludeReleaseVersion); + + /** * returns all available output types */ diff --git a/rest/resource-server/src/docs/asciidoc/projects.adoc b/rest/resource-server/src/docs/asciidoc/projects.adoc index 7f08d4702a..fa05b5cab9 100644 --- a/rest/resource-server/src/docs/asciidoc/projects.adoc +++ b/rest/resource-server/src/docs/asciidoc/projects.adoc @@ -701,7 +701,7 @@ include::{snippets}/should_document_get_download_license_info/http-response.adoc [[resources-project-get-download-licenseinfo-with-all-attachments]] ==== Download License Info with all attachments -A `GET` request is used to download the project's license information. The resulting file will include findings from either the CLX or ISR attachment of a linked release. +A `GET` request is used to download the project's license information. The resulting file will include findings from the CLX, and if not available, the ISR attachment of a linked release. ===== Request parameter include::{snippets}/should_document_get_download_license_info_with_all_attachemnts/request-parameters.adoc[] @@ -712,6 +712,20 @@ include::{snippets}/should_document_get_download_license_info_with_all_attachemn ===== Example response include::{snippets}/should_document_get_download_license_info_with_all_attachemnts/http-response.adoc[] +[[resources-project-get-download-licenseinfo-without-release-version]] +==== Download License Info without component versions + +A `GET` request is used to download license info for the project. If the `excludeReleaseVersion` parameter is set to true, the component versions will be omitted from the output file. + +===== Request parameter +include::{snippets}/should_document_get_download_license_info_without_release_version/request-parameters.adoc[] + +===== Example request +include::{snippets}/should_document_get_download_license_info_without_release_version/curl-request.adoc[] + +===== Example response +include::{snippets}/should_document_get_download_license_info_without_release_version/http-response.adoc[] + [[resources-project-usedby-list]] ==== Resources using the project diff --git a/rest/resource-server/src/main/java/org/eclipse/sw360/rest/resourceserver/licenseinfo/Sw360LicenseInfoService.java b/rest/resource-server/src/main/java/org/eclipse/sw360/rest/resourceserver/licenseinfo/Sw360LicenseInfoService.java index 3ab5b08cf9..c508fd191e 100644 --- a/rest/resource-server/src/main/java/org/eclipse/sw360/rest/resourceserver/licenseinfo/Sw360LicenseInfoService.java +++ b/rest/resource-server/src/main/java/org/eclipse/sw360/rest/resourceserver/licenseinfo/Sw360LicenseInfoService.java @@ -50,10 +50,17 @@ public OutputFormatInfo getOutputFormatInfoForGeneratorClass(String generatorCla public LicenseInfoFile getLicenseInfoFile(Project project, User sw360User, String generatorClassNameWithVariant, Map> selectedReleaseAndAttachmentIds, - Map> excludedLicenses, String externalIds, String fileName) { + Map> excludedLicenses, String externalIds, String fileName, + boolean excludeReleaseVersion) { try { LicenseInfoService.Iface sw360LicenseInfoClient = getThriftLicenseInfoClient(); - return sw360LicenseInfoClient.getLicenseInfoFile(project, sw360User, generatorClassNameWithVariant, selectedReleaseAndAttachmentIds, excludedLicenses, externalIds, fileName); + if (excludeReleaseVersion) { + return sw360LicenseInfoClient.getLicenseInfoFileWithoutReleaseVersion(project, sw360User, + generatorClassNameWithVariant, selectedReleaseAndAttachmentIds, excludedLicenses, externalIds, + fileName, excludeReleaseVersion); + } + return sw360LicenseInfoClient.getLicenseInfoFile(project, sw360User, generatorClassNameWithVariant, + selectedReleaseAndAttachmentIds, excludedLicenses, externalIds, fileName); } catch (TException e) { throw new RuntimeException(e); } diff --git a/rest/resource-server/src/main/java/org/eclipse/sw360/rest/resourceserver/project/ProjectController.java b/rest/resource-server/src/main/java/org/eclipse/sw360/rest/resourceserver/project/ProjectController.java index 3e8ec75449..503492eec1 100644 --- a/rest/resource-server/src/main/java/org/eclipse/sw360/rest/resourceserver/project/ProjectController.java +++ b/rest/resource-server/src/main/java/org/eclipse/sw360/rest/resourceserver/project/ProjectController.java @@ -1370,6 +1370,8 @@ public void downloadLicenseInfo( @RequestParam(value = "template", required = false) String template, @Parameter(description = "Generate license info including all attachments of the linked releases") @RequestParam(value = "includeAllAttachments", required = false ) boolean includeAllAttachments, + @Parameter(description = "Exclude release version from the license info file") + @RequestParam(value = "excludeReleaseVersion", required = false, defaultValue = "false") boolean excludeReleaseVersion, HttpServletResponse response ) throws TException, IOException { final User sw360User = restControllerHelper.getSw360UserFromAuthentication(); @@ -1448,7 +1450,7 @@ public void downloadLicenseInfo( final LicenseInfoFile licenseInfoFile = licenseInfoService.getLicenseInfoFile(sw360Project, sw360User, outputGeneratorClassNameWithVariant, selectedReleaseAndAttachmentIds, excludedLicensesPerAttachments, - externalIds, fileName); + externalIds, fileName, excludeReleaseVersion); byte[] byteContent = licenseInfoFile.bufferForGeneratedOutput().array(); response.setContentType(outputFormatInfo.getMimeType()); response.setHeader("Content-Disposition", String.format("attachment; filename=\"%s\"", filename)); diff --git a/rest/resource-server/src/test/java/org/eclipse/sw360/rest/resourceserver/restdocs/ProjectSpecTest.java b/rest/resource-server/src/test/java/org/eclipse/sw360/rest/resourceserver/restdocs/ProjectSpecTest.java index a5dc6dc5d9..88cab393bf 100644 --- a/rest/resource-server/src/test/java/org/eclipse/sw360/rest/resourceserver/restdocs/ProjectSpecTest.java +++ b/rest/resource-server/src/test/java/org/eclipse/sw360/rest/resourceserver/restdocs/ProjectSpecTest.java @@ -709,7 +709,9 @@ public void before() throws TException, IOException { LicenseInfoFile licenseInfoFile = new LicenseInfoFile(); licenseInfoFile.setGeneratedOutput(new byte[0]); given(this.licenseInfoMockService.getLicenseInfoFile(any(), any(), any(), any(), - any(),any(), any())).willReturn(licenseInfoFile); + any(),any(), any(), eq(false))).willReturn(licenseInfoFile); + given(this.licenseInfoMockService.getLicenseInfoFile(any(), any(), any(), any(), + any(),any(), any(), eq(true))).willReturn(licenseInfoFile); Source ownerSrc1 = Source.releaseId("9988776655"); Source usedBySrc = Source.projectId(project.getId()); @@ -2072,6 +2074,24 @@ public void should_document_get_download_license_info() throws Exception { parameterWithName("externalIds").description("The external Ids of the project") ))); } + + @Test + public void should_document_get_download_license_info_without_release_version() throws Exception { + this.mockMvc.perform(get("/api/projects/" + project.getId()+ "/licenseinfo?generatorClassName=XhtmlGenerator&variant=DISCLOSURE&excludeReleaseVersion=true") + .header("Authorization", TestHelper.generateAuthHeader(testUserId, testUserPassword)) + .accept("application/xhtml+xml")) + .andExpect(status().isOk()) + .andDo(this.documentationHandler + .document(queryParameters( + parameterWithName("generatorClassName") + .description("All possible values for output generator class names are " + + Arrays.asList("DocxGenerator", "XhtmlGenerator", "TextGenerator")), + parameterWithName("variant").description("All the possible values for variants are " + + Arrays.asList(OutputFormatVariant.values())), + parameterWithName("excludeReleaseVersion").description("Exclude version of the components from the generated license info file. " + + "Possible values are ``") + ))); + } @Test public void should_document_get_download_license_info_with_all_attachemnts() throws Exception {