Skip to content

Commit 3c674cb

Browse files
Markus HerpichNikolas Sepos
Markus Herpich
authored and
Nikolas Sepos
committed
Corrections to the license report
As per: siemens#18 Signed-off-by: Nikolas Sepos <[email protected]>
1 parent 851051e commit 3c674cb

File tree

8 files changed

+75
-35
lines changed

8 files changed

+75
-35
lines changed

backend/src/src-licenseinfo/src/main/java/org/eclipse/sw360/licenseinfo/LicenseInfoHandler.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ protected LicenseInfoHandler(AttachmentDatabaseHandler attachmentDatabaseHandler
9494
new TextGenerator(DISCLOSURE, "License Disclosure as TEXT"),
9595
new XhtmlGenerator(DISCLOSURE, "License Disclosure as XHTML"),
9696
new DocxGenerator(DISCLOSURE, "License Disclosure as DOCX"),
97-
new DocxGenerator(REPORT, "License Report as DOCX")
97+
new DocxGenerator(REPORT, "Project Clearing Report as DOCX")
9898
);
9999
// @formatter:on
100100
}

backend/src/src-licenseinfo/src/main/java/org/eclipse/sw360/licenseinfo/outputGenerators/DocxGenerator.java

+52-25
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import org.apache.log4j.Logger;
1616
import org.apache.poi.xwpf.usermodel.*;
1717
import org.apache.thrift.TException;
18+
import org.apache.xmlbeans.XmlCursor;
1819
import org.apache.xmlbeans.XmlException;
1920
import org.eclipse.sw360.datahandler.common.CommonUtils;
2021
import org.eclipse.sw360.datahandler.thrift.SW360Exception;
@@ -46,16 +47,23 @@ public class DocxGenerator extends OutputGenerator<byte[]> {
4647
private static final Logger LOGGER = Logger.getLogger(DocxGenerator.class);
4748
private static final String UNKNOWN_LICENSE_NAME = "Unknown license name";
4849
private static final String UNKNOWN_FILE_NAME = "Unknown file name";
50+
private static final String UNKNOWN_LICENSE = "Unknown";
4951
private static final String TODO_DEFAULT_TEXT = "todo not determined so far.";
5052

5153
private static final String DOCX_TEMPLATE_FILE = "/templateFrontpageContent.docx";
5254
private static final String DOCX_TEMPLATE_REPORT_FILE = "/templateReport.docx";
5355
private static final String DOCX_MIME_TYPE = "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
5456
private static final String DOCX_OUTPUT_TYPE = "docx";
55-
public static final String UNKNOWN_LICENSE = "Unknown";
57+
5658
private static final long ADDITIONAL_REQ_THRESHOLD = 3;
57-
public static final int ADDITIONAL_REQ_TABLE_INDEX = 4;
59+
60+
public static final int OVERVIEW_TABLE_INDEX = 0;
61+
public static final int SPECIAL_OSS_RISKS_TABLE_INDEX = 1;
5862
public static final int DEV_DETAIL_TABLE_INDEX = 2;
63+
public static final int THIRD_PARTY_COMPONENT_OVERVIEW_TABLE_INDEX = 3;
64+
public static final int ADDITIONAL_REQ_TABLE_INDEX = 4;
65+
66+
5967

6068
public DocxGenerator(OutputFormatVariant outputFormatVariant, String description) {
6169
super(DOCX_OUTPUT_TYPE, description, true, DOCX_MIME_TYPE, outputFormatVariant);
@@ -134,7 +142,7 @@ private void fillDisclosureDocument(
134142
fillReleaseBulletList(document, projectLicenseInfoResults);
135143
fillReleaseDetailList(document, projectLicenseInfoResults, includeObligations);
136144
fillLicenseList(document, projectLicenseInfoResults);
137-
}
145+
}
138146

139147
private void fillReportDocument(
140148
XWPFDocument document,
@@ -145,6 +153,7 @@ private void fillReportDocument(
145153
Collection<ObligationParsingResult> obligationResults,
146154
User user) throws XmlException, TException {
147155

156+
String businessUnit = project.getBusinessUnit();
148157
String projectName = project.getName();
149158
String projectVersion = project.getVersion();
150159
String obligationsText = project.getObligationsText();
@@ -155,11 +164,13 @@ private void fillReportDocument(
155164
String deliveryChannelsText = project.getDeliveryChannels();
156165
String remarksAdditionalRequirementsText = project.getRemarksAdditionalRequirements();
157166
String projectDescription = project.getDescription();
158-
167+
// extract licenses that appear at least ADDITIONAL_REQ_THRESHOLD times
168+
Set<String> mostLicenses = extractMostCommonLicenses(obligationResults, ADDITIONAL_REQ_THRESHOLD);
159169

160170
fillOwnerGroup(document, project);
161171
fillAttendeesTable(document, project);
162172

173+
replaceText(document, "$bunit", businessUnit);
163174
replaceText(document, "$license-info-header", licenseInfoHeaderText);
164175
replaceText(document, "$project-name", projectName);
165176
replaceText(document, "$project-version", projectVersion);
@@ -175,10 +186,9 @@ private void fillReportDocument(
175186
fillSpecialOSSRisksTable(document, project, obligationResults);
176187
fillDevelopmentDetailsTable(document, project, user);
177188
fillOverview3rdPartyComponentTable(document, projectLicenseInfoResults);
178-
fillAdditionalRequirementsTable(document, obligationResults);
189+
replaceText(document, "$list_comma_sep_licenses_above_threshold", String.join(", ", mostLicenses));
190+
fillAdditionalRequirementsTable(document, obligationResults, mostLicenses);
179191

180-
// because of the impossible API component subsections must be the last thing in the docx file
181-
// the rest of the sections must be generated after this
182192
writeComponentSubsections(document, projectLicenseInfoResults, obligationResults);
183193
}
184194

@@ -191,9 +201,9 @@ private void fillOwnerGroup(XWPFDocument document, Project project) throws XmlEx
191201
}
192202

193203
private void fillAttendeesTable(XWPFDocument document, Project project) throws XmlException, TException {
194-
XWPFTable table = document.getTables().get(0);
204+
XWPFTable table = document.getTables().get(OVERVIEW_TABLE_INDEX);
195205

196-
int currentRow = 6;
206+
int currentRow = 7;
197207

198208
UserService.Iface userClient = new ThriftClients().makeUserClient();
199209

@@ -217,7 +227,12 @@ private void fillAttendeesTable(XWPFDocument document, Project project) throws X
217227
continue;
218228
}
219229

220-
User user = userClient.getByEmail(email);
230+
User user = null;
231+
try {
232+
user = userClient.getByEmail(email);
233+
} catch (TException te) {
234+
235+
}
221236

222237
XWPFTableRow row = table.insertNewTableRow(currentRow++);
223238
String name = email;
@@ -226,7 +241,7 @@ private void fillAttendeesTable(XWPFDocument document, Project project) throws X
226241
}
227242
String department = "N.A.";
228243
if(user != null) {
229-
name = user.getDepartment();
244+
department = user.getDepartment();
230245
}
231246

232247
row.addNewTableCell().setText(name);
@@ -238,7 +253,7 @@ private void fillAttendeesTable(XWPFDocument document, Project project) throws X
238253
}
239254

240255
private void fillSpecialOSSRisksTable(XWPFDocument document, Project project, Collection<ObligationParsingResult> obligationResults) throws XmlException, TException {
241-
XWPFTable table = document.getTables().get(1);
256+
XWPFTable table = document.getTables().get(SPECIAL_OSS_RISKS_TABLE_INDEX);
242257
final int[] currentRow = new int[]{0};
243258

244259
obligationResults.stream()
@@ -257,7 +272,7 @@ private void fillSpecialOSSRisksTable(XWPFDocument document, Project project, Co
257272
}
258273

259274
private void fillOverview3rdPartyComponentTable(XWPFDocument document, Collection<LicenseInfoParsingResult> projectLicenseInfoResults) throws XmlException {
260-
XWPFTable table = document.getTables().get(3);
275+
XWPFTable table = document.getTables().get(THIRD_PARTY_COMPONENT_OVERVIEW_TABLE_INDEX);
261276

262277
int currentRow = 1;
263278
for(LicenseInfoParsingResult result : projectLicenseInfoResults) {
@@ -289,17 +304,31 @@ private static Optional<ObligationParsingResult> obligationsForRelease(Release r
289304
return obligationResults.stream().filter(opr -> opr.getRelease() == release).findFirst();
290305
}
291306

292-
private void writeComponentSubsections(XWPFDocument document, Collection<LicenseInfoParsingResult> projectLicenseInfoResults, Collection<ObligationParsingResult> obligationResults) throws XmlException {
307+
private void writeComponentSubsections(XWPFDocument document, Collection<LicenseInfoParsingResult> projectLicenseInfoResults, Collection<ObligationParsingResult> obligationResults) throws SW360Exception, XmlException {
308+
XmlCursor cursor = document.getTables().get(ADDITIONAL_REQ_TABLE_INDEX).getCTTbl().newCursor();
309+
cursor.toEndToken();
293310

294311
for (LicenseInfoParsingResult result : projectLicenseInfoResults) {
312+
while (cursor.currentTokenType() != XmlCursor.TokenType.START && cursor.hasNextToken()) {
313+
cursor.toNextToken();
314+
}
315+
316+
if (cursor.currentTokenType() != XmlCursor.TokenType.START) {
317+
throw new SW360Exception("Corrupt template; unable find start token");
318+
}
295319

296-
XWPFParagraph title = document.createParagraph();
320+
XWPFParagraph title = document.insertNewParagraph(cursor);
297321
title.setStyle(STYLE_HEADING_3);
298322
title.setNumID(new BigInteger("2"));
299323
XWPFRun titleRun = title.createRun();
300324
titleRun.setText(result.getVendor() + " " + result.getName());
301325

302-
XWPFParagraph description = document.createParagraph();
326+
if (cursor.hasNextToken()) {
327+
cursor.toNextToken();
328+
} else {
329+
throw new SW360Exception("Corrupt template; unable to proceed to next token");
330+
}
331+
XWPFParagraph description = document.insertNewParagraph(cursor);
303332
XWPFRun descriptionRun = description.createRun();
304333

305334
LicenseInfo licenseInfo = result.getLicenseInfo();
@@ -328,7 +357,7 @@ private void writeComponentSubsections(XWPFDocument document, Collection<License
328357

329358
int currentRow = 0;
330359
Collection<Obligation> obligations = obligationsResult.getObligations();
331-
XWPFTable table = document.createTable();
360+
XWPFTable table = document.insertNewTbl(cursor);
332361
for (Obligation o : obligations) {
333362
XWPFTableRow row = table.insertNewTableRow(currentRow++);
334363
String licensesString = String.join(" ", o.getLicenseIDs());
@@ -356,13 +385,13 @@ private void fillDevelopmentDetailsTable(XWPFDocument document, Project project,
356385

357386
row.addNewTableCell().setText(component.getName());
358387

359-
String operatingSystems = component.getOperatingSystemsSize() == 0 ? "Unknown operating systems" : String.join(" ", component.getOperatingSystems());
388+
String operatingSystems = component.getOperatingSystemsSize() == 0 ? "N/A" : String.join(" ", component.getOperatingSystems());
360389
row.addNewTableCell().setText(operatingSystems);
361390

362-
String langs = component.getLanguagesSize() == 0 ? "Unknown languages" : String.join(" ", component.getLanguages());
391+
String langs = component.getLanguagesSize() == 0 ? "N/A" : String.join(" ", component.getLanguages());
363392
row.addNewTableCell().setText(langs);
364393

365-
String platforms = component.getSoftwarePlatformsSize() == 0 ? "Unknown platforms" : String.join(" ", component.getSoftwarePlatforms());
394+
String platforms = component.getSoftwarePlatformsSize() == 0 ? "N/A" : String.join(" ", component.getSoftwarePlatforms());
366395
row.addNewTableCell().setText(platforms);
367396
}
368397
}
@@ -376,21 +405,19 @@ protected static Set<String> extractMostCommonLicenses(Collection<ObligationPars
376405
.entrySet().stream()
377406
.filter(entry -> entry.getValue().longValue() >= threshold)
378407
.map(entry -> entry.getKey())
408+
.map(license -> license.replace("\n", "").replace("\r", ""))
379409
.collect(Collectors.toSet());
380410
}
381411

382-
private void fillAdditionalRequirementsTable(XWPFDocument document, Collection<ObligationParsingResult> obligationResults) throws XmlException {
383-
// extract licenses that appear at least ADDITIONAL_REQ_THRESHOLD times
384-
Set<String> mostLicenses = extractMostCommonLicenses(obligationResults, ADDITIONAL_REQ_THRESHOLD);
385-
412+
private void fillAdditionalRequirementsTable(XWPFDocument document, Collection<ObligationParsingResult> obligationResults, Set<String> mostLicenses) throws XmlException {
386413
XWPFTable table = document.getTables().get(ADDITIONAL_REQ_TABLE_INDEX);
387414
final int[] currentRow = new int[]{0};
388415

389416
obligationResults.stream()
390417
.filter(opr -> opr.getStatus() == ObligationInfoRequestStatus.SUCCESS)
391418
.flatMap(opr -> opr.getObligations().stream())
392419
.filter(o -> o.getLicenseIDs().stream()
393-
.anyMatch(lid -> mostLicenses.parallelStream().anyMatch(mlid -> mlid.equals(lid))))
420+
.anyMatch(lid -> mostLicenses.parallelStream().anyMatch(mlid -> mlid.equals(lid.replace("\n", "").replace("\r", "")))))
394421
.forEach(o -> {
395422
currentRow[0] = currentRow[0] + 1;
396423
XWPFTableRow row = table.insertNewTableRow(currentRow[0]);
Binary file not shown.

frontend/sw360-portlet/src/main/java/org/eclipse/sw360/portal/portlets/projects/ProjectPortlet.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -284,8 +284,9 @@ private void downloadLicenseInfo(ResourceRequest request, ResourceResponse respo
284284
}
285285

286286
private void sendLicenseInfoResponse(ResourceRequest request, ResourceResponse response, Project project, LicenseInfoFile licenseInfoFile) throws IOException {
287-
OutputFormatInfo outputFormatInfo = licenseInfoFile.getOutputFormatInfo();
288-
String filename = String.format("LicenseInfo-%s%s-%s.%s", project.getName(),
287+
OutputFormatInfo outputFormatInfo = licenseInfoFile.getOutputFormatInfo();
288+
String documentVariant = licenseInfoFile.getOutputFormatInfo().getVariant() == OutputFormatVariant.DISCLOSURE ? "LicenseInfo" : "ProjectClearingReport";
289+
String filename = String.format("%s-%s%s-%s.%s", documentVariant, project.getName(),
289290
StringUtils.isBlank(project.getVersion()) ? "" : "-" + project.getVersion(),
290291
SW360Utils.getCreatedOnTime().replaceAll("\\s", "_").replace(":", "_"),
291292
outputFormatInfo.getFileExtension());

frontend/sw360-portlet/src/main/webapp/html/components/editRelease.jsp

+2
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353

5454
<core_rt:set var="programmingLanguages" value='<%=PortalConstants.PROGRAMMING_LANGUAGES%>'/>
5555
<core_rt:set var="operatingSystemsAutoC" value='<%=PortalConstants.OPERATING_SYSTEMS%>'/>
56+
<core_rt:set var="platformsAutoC" value='<%=PortalConstants.SOFTWARE_PLATFORMS%>'/>
5657

5758
<core_rt:set var="addMode" value="${empty release.id}"/>
5859
<core_rt:set var="cotsMode" value="<%=component.componentType == ComponentType.COTS%>"/>
@@ -176,6 +177,7 @@
176177
Liferay.on('allPortletsReady', function() {
177178
autocomplete.prepareForMultipleHits('programminglanguages', ${programmingLanguages});
178179
autocomplete.prepareForMultipleHits('op_systems', ${operatingSystemsAutoC});
180+
autocomplete.prepareForMultipleHits('platformsTB', ${platformsAutoC});
179181
180182
sw360Validate.validateWithInvalidHandlerNoIgnore('#releaseEditForm');
181183

frontend/sw360-portlet/src/main/webapp/html/components/includes/releases/editReleaseInformation.jspf

+11-4
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<table class="table info_table" id="ComponentBasicInfo">
1616
<thead>
1717
<tr>
18-
<th colspan="3" class="headlabel">Release Summary</th>
18+
<th colspan="4" class="headlabel">Release Summary</th>
1919
</tr>
2020
</thead>
2121
<tr>
@@ -37,21 +37,28 @@
3737
</td>
3838
</tr>
3939
<tr>
40-
<td width="33%">
40+
<td width="25%">
4141
<label class="textlabel stackedLabel" for="programminglanguages">Programming Languages</label>
4242
<input class="toplabelledInput" name="<portlet:namespace/><%=Component._Fields.LANGUAGES%>"
4343
id="programminglanguages" type="text"
4444
placeholder="e.g., Java,C++, C#,..."
4545
value="<sw360:DisplayCollection value='${release.languages}' />"/>
4646
</td>
47-
<td width="33%">
47+
<td width="25%">
4848
<label class="textlabel stackedLabel" for="op_systems">Operating Systems</label>
4949
<input class="toplabelledInput" id="op_systems"
5050
name="<portlet:namespace/><%=Component._Fields.OPERATING_SYSTEMS%>" type="text" align="middle"
5151
placeholder="e.g.,Linux,MAC,Windows,..."
5252
value="<sw360:DisplayCollection value="${release.operatingSystems}" />"/>
5353
</td>
54-
<td width="33%">
54+
<td width="25%">
55+
<label class="textlabel stackedLabel" for="platformsTB">Software Platforms</label>
56+
<input class="toplabelledInput" id="platformsTB"
57+
name="<portlet:namespace/><%=Component._Fields.SOFTWARE_PLATFORMS%>" type="text" align="middle"
58+
placeholder="e.g.,Adobe AIR,.NET,Qt,..."
59+
value="<sw360:DisplayCollection value="${release.softwarePlatforms}" />"/>
60+
</td>
61+
<td width="25%">
5562
<label class="textlabel stackedLabel" for="comp_id">CPE ID</label>
5663
<input id="comp_id" name="<portlet:namespace/><%=Release._Fields.CPEID%>" type="text"
5764
class="toplabelledInput followedByImg"

libraries/lib-datahandler/src/main/thrift/components.thrift

+1
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@ struct Release {
206206
53: optional set<string> operatingSystems,
207207
54: optional COTSDetails cotsDetails,
208208
55: optional EccInformation eccInformation,
209+
56: optional set<string> softwarePlatforms,
209210

210211
65: optional set<string> mainLicenseIds,
211212

rest/resource-server/src/main/java/org/eclipse/sw360/rest/resourceserver/project/ProjectController.java

+5-3
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import org.eclipse.sw360.datahandler.thrift.licenseinfo.LicenseInfoFile;
2929
import org.eclipse.sw360.datahandler.thrift.licenseinfo.LicenseNameWithText;
3030
import org.eclipse.sw360.datahandler.thrift.licenseinfo.OutputFormatInfo;
31+
import org.eclipse.sw360.datahandler.thrift.licenseinfo.OutputFormatVariant;
3132
import org.eclipse.sw360.datahandler.thrift.licenses.License;
3233
import org.eclipse.sw360.datahandler.thrift.projects.Project;
3334
import org.eclipse.sw360.datahandler.thrift.projects.ProjectRelationship;
@@ -282,9 +283,10 @@ public void downloadLicenseInfo(@PathVariable("id") String id,
282283

283284
final String projectName = sw360Project.getName();
284285
final String projectVersion = sw360Project.getVersion();
285-
final String timestamp = SW360Utils.getCreatedOnTime().replaceAll("\\s", "_").replace(":", "_");
286-
final OutputFormatInfo outputFormatInfo = licenseInfoService.getOutputFormatInfoForGeneratorClass(generatorClassName);
287-
final String filename = String.format("LicenseInfo-%s%s-%s.%s", projectName,
286+
final String timestamp = SW360Utils.getCreatedOnTime().replaceAll("\\s", "_").replace(":", "_");
287+
final OutputFormatInfo outputFormatInfo = licenseInfoService.getOutputFormatInfoForGeneratorClass(generatorClassName);
288+
final String variant = outputFormatInfo.variant == OutputFormatVariant.DISCLOSURE ? "LicenseInfo" : "ProjectClearingReport";
289+
final String filename = String.format("%s-%s%s-%s.%s", variant, projectName,
288290
StringUtils.isBlank(projectVersion) ? "" : "-" + projectVersion, timestamp,
289291
outputFormatInfo.getFileExtension());
290292

0 commit comments

Comments
 (0)