Skip to content

Commit bb9bee4

Browse files
author
Nikolas Sepos
committed
Corrections to the license report
As per: siemens#18 Signed-off-by: Nikolas Sepos <[email protected]>
1 parent 3a1d1e6 commit bb9bee4

File tree

7 files changed

+78
-35
lines changed

7 files changed

+78
-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

+55-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.common.SW360Utils;
@@ -47,17 +48,23 @@ public class DocxGenerator extends OutputGenerator<byte[]> {
4748
private static final Logger LOGGER = Logger.getLogger(DocxGenerator.class);
4849
private static final String UNKNOWN_LICENSE_NAME = "Unknown license name";
4950
private static final String UNKNOWN_FILE_NAME = "Unknown file name";
51+
private static final String UNKNOWN_LICENSE = "Unknown";
5052
private static final String TODO_DEFAULT_TEXT = "todo not determined so far.";
5153

5254
private static final String DOCX_TEMPLATE_FILE = "/templateFrontpageContent.docx";
5355
private static final String DOCX_TEMPLATE_REPORT_FILE = "/templateReport.docx";
5456
private static final String DOCX_MIME_TYPE = "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
5557
private static final String DOCX_OUTPUT_TYPE = "docx";
56-
public static final String UNKNOWN_LICENSE = "Unknown";
58+
5759
private static final long ADDITIONAL_REQ_THRESHOLD = 3;
58-
public static final int ADDITIONAL_REQ_TABLE_INDEX = 5;
60+
61+
public static final int OVERVIEW_TABLE_INDEX = 0;
62+
public static final int SPECIAL_OSS_RISKS_TABLE_INDEX = 1;
5963
public static final int DEV_DETAIL_TABLE_INDEX = 2;
60-
private static final int COMMON_RULES_TABLE_INDEX = 4;
64+
public static final int THIRD_PARTY_COMPONENT_OVERVIEW_TABLE_INDEX = 3;
65+
public static final int ADDITIONAL_REQ_TABLE_INDEX = 4;
66+
67+
6168

6269
public DocxGenerator(OutputFormatVariant outputFormatVariant, String description) {
6370
super(DOCX_OUTPUT_TYPE, description, true, DOCX_MIME_TYPE, outputFormatVariant);
@@ -136,7 +143,7 @@ private void fillDisclosureDocument(
136143
fillReleaseBulletList(document, projectLicenseInfoResults);
137144
fillReleaseDetailList(document, projectLicenseInfoResults, includeObligations);
138145
fillLicenseList(document, projectLicenseInfoResults);
139-
}
146+
}
140147

141148
private void fillReportDocument(
142149
XWPFDocument document,
@@ -147,6 +154,7 @@ private void fillReportDocument(
147154
Collection<ObligationParsingResult> obligationResults,
148155
User user) throws XmlException, TException {
149156

157+
String businessUnit = project.getBusinessUnit();
150158
String projectName = project.getName();
151159
String projectVersion = project.getVersion();
152160
String obligationsText = project.getObligationsText();
@@ -157,11 +165,13 @@ private void fillReportDocument(
157165
String deliveryChannelsText = project.getDeliveryChannels();
158166
String remarksAdditionalRequirementsText = project.getRemarksAdditionalRequirements();
159167
String projectDescription = project.getDescription();
160-
168+
// extract licenses that appear at least ADDITIONAL_REQ_THRESHOLD times
169+
Set<String> mostLicenses = extractMostCommonLicenses(obligationResults, ADDITIONAL_REQ_THRESHOLD);
161170

162171
fillOwnerGroup(document, project);
163172
fillAttendeesTable(document, project);
164173

174+
replaceText(document, "$bunit", businessUnit);
165175
replaceText(document, "$license-info-header", licenseInfoHeaderText);
166176
replaceText(document, "$project-name", projectName);
167177
replaceText(document, "$project-version", projectVersion);
@@ -177,11 +187,14 @@ private void fillReportDocument(
177187
fillSpecialOSSRisksTable(document, project, obligationResults);
178188
fillDevelopmentDetailsTable(document, project, user);
179189
fillOverview3rdPartyComponentTable(document, projectLicenseInfoResults);
190+
<<<<<<< HEAD
180191
fillCommonRulesTable(document, project);
181192
fillAdditionalRequirementsTable(document, obligationResults);
193+
=======
194+
replaceText(document, "$list_comma_sep_licenses_above_threshold", String.join(", ", mostLicenses));
195+
fillAdditionalRequirementsTable(document, obligationResults, mostLicenses);
196+
>>>>>>> 3c674cb... Corrections to the license report
182197

183-
// because of the impossible API component subsections must be the last thing in the docx file
184-
// the rest of the sections must be generated after this
185198
writeComponentSubsections(document, projectLicenseInfoResults, obligationResults);
186199
}
187200

@@ -194,9 +207,9 @@ private void fillOwnerGroup(XWPFDocument document, Project project) throws XmlEx
194207
}
195208

196209
private void fillAttendeesTable(XWPFDocument document, Project project) throws XmlException, TException {
197-
XWPFTable table = document.getTables().get(0);
210+
XWPFTable table = document.getTables().get(OVERVIEW_TABLE_INDEX);
198211

199-
int currentRow = 6;
212+
int currentRow = 7;
200213

201214
UserService.Iface userClient = new ThriftClients().makeUserClient();
202215

@@ -220,7 +233,12 @@ private void fillAttendeesTable(XWPFDocument document, Project project) throws X
220233
continue;
221234
}
222235

223-
User user = userClient.getByEmail(email);
236+
User user = null;
237+
try {
238+
user = userClient.getByEmail(email);
239+
} catch (TException te) {
240+
241+
}
224242

225243
XWPFTableRow row = table.insertNewTableRow(currentRow++);
226244
String name = email;
@@ -229,7 +247,7 @@ private void fillAttendeesTable(XWPFDocument document, Project project) throws X
229247
}
230248
String department = "N.A.";
231249
if(user != null) {
232-
name = user.getDepartment();
250+
department = user.getDepartment();
233251
}
234252

235253
row.addNewTableCell().setText(name);
@@ -241,7 +259,7 @@ private void fillAttendeesTable(XWPFDocument document, Project project) throws X
241259
}
242260

243261
private void fillSpecialOSSRisksTable(XWPFDocument document, Project project, Collection<ObligationParsingResult> obligationResults) throws XmlException, TException {
244-
XWPFTable table = document.getTables().get(1);
262+
XWPFTable table = document.getTables().get(SPECIAL_OSS_RISKS_TABLE_INDEX);
245263
final int[] currentRow = new int[]{0};
246264

247265
obligationResults.stream()
@@ -260,7 +278,7 @@ private void fillSpecialOSSRisksTable(XWPFDocument document, Project project, Co
260278
}
261279

262280
private void fillOverview3rdPartyComponentTable(XWPFDocument document, Collection<LicenseInfoParsingResult> projectLicenseInfoResults) throws XmlException {
263-
XWPFTable table = document.getTables().get(3);
281+
XWPFTable table = document.getTables().get(THIRD_PARTY_COMPONENT_OVERVIEW_TABLE_INDEX);
264282

265283
int currentRow = 1;
266284
for(LicenseInfoParsingResult result : projectLicenseInfoResults) {
@@ -292,17 +310,31 @@ private static Optional<ObligationParsingResult> obligationsForRelease(Release r
292310
return obligationResults.stream().filter(opr -> opr.getRelease() == release).findFirst();
293311
}
294312

295-
private void writeComponentSubsections(XWPFDocument document, Collection<LicenseInfoParsingResult> projectLicenseInfoResults, Collection<ObligationParsingResult> obligationResults) throws XmlException {
313+
private void writeComponentSubsections(XWPFDocument document, Collection<LicenseInfoParsingResult> projectLicenseInfoResults, Collection<ObligationParsingResult> obligationResults) throws SW360Exception, XmlException {
314+
XmlCursor cursor = document.getTables().get(ADDITIONAL_REQ_TABLE_INDEX).getCTTbl().newCursor();
315+
cursor.toEndToken();
296316

297317
for (LicenseInfoParsingResult result : projectLicenseInfoResults) {
318+
while (cursor.currentTokenType() != XmlCursor.TokenType.START && cursor.hasNextToken()) {
319+
cursor.toNextToken();
320+
}
321+
322+
if (cursor.currentTokenType() != XmlCursor.TokenType.START) {
323+
throw new SW360Exception("Corrupt template; unable find start token");
324+
}
298325

299-
XWPFParagraph title = document.createParagraph();
326+
XWPFParagraph title = document.insertNewParagraph(cursor);
300327
title.setStyle(STYLE_HEADING_3);
301328
title.setNumID(new BigInteger("2"));
302329
XWPFRun titleRun = title.createRun();
303330
titleRun.setText(result.getVendor() + " " + result.getName());
304331

305-
XWPFParagraph description = document.createParagraph();
332+
if (cursor.hasNextToken()) {
333+
cursor.toNextToken();
334+
} else {
335+
throw new SW360Exception("Corrupt template; unable to proceed to next token");
336+
}
337+
XWPFParagraph description = document.insertNewParagraph(cursor);
306338
XWPFRun descriptionRun = description.createRun();
307339

308340
LicenseInfo licenseInfo = result.getLicenseInfo();
@@ -331,7 +363,7 @@ private void writeComponentSubsections(XWPFDocument document, Collection<License
331363

332364
int currentRow = 0;
333365
Collection<Obligation> obligations = obligationsResult.getObligations();
334-
XWPFTable table = document.createTable();
366+
XWPFTable table = document.insertNewTbl(cursor);
335367
for (Obligation o : obligations) {
336368
XWPFTableRow row = table.insertNewTableRow(currentRow++);
337369
String licensesString = String.join(" ", o.getLicenseIDs());
@@ -359,13 +391,13 @@ private void fillDevelopmentDetailsTable(XWPFDocument document, Project project,
359391

360392
row.addNewTableCell().setText(component.getName());
361393

362-
String operatingSystems = component.getOperatingSystemsSize() == 0 ? "Unknown operating systems" : String.join(" ", component.getOperatingSystems());
394+
String operatingSystems = component.getOperatingSystemsSize() == 0 ? "N/A" : String.join(" ", component.getOperatingSystems());
363395
row.addNewTableCell().setText(operatingSystems);
364396

365-
String langs = component.getLanguagesSize() == 0 ? "Unknown languages" : String.join(" ", component.getLanguages());
397+
String langs = component.getLanguagesSize() == 0 ? "N/A" : String.join(" ", component.getLanguages());
366398
row.addNewTableCell().setText(langs);
367399

368-
String platforms = component.getSoftwarePlatformsSize() == 0 ? "Unknown platforms" : String.join(" ", component.getSoftwarePlatforms());
400+
String platforms = component.getSoftwarePlatformsSize() == 0 ? "N/A" : String.join(" ", component.getSoftwarePlatforms());
369401
row.addNewTableCell().setText(platforms);
370402
}
371403
}
@@ -379,21 +411,19 @@ protected static Set<String> extractMostCommonLicenses(Collection<ObligationPars
379411
.entrySet().stream()
380412
.filter(entry -> entry.getValue().longValue() >= threshold)
381413
.map(entry -> entry.getKey())
414+
.map(license -> license.replace("\n", "").replace("\r", ""))
382415
.collect(Collectors.toSet());
383416
}
384417

385-
private void fillAdditionalRequirementsTable(XWPFDocument document, Collection<ObligationParsingResult> obligationResults) throws XmlException {
386-
// extract licenses that appear at least ADDITIONAL_REQ_THRESHOLD times
387-
Set<String> mostLicenses = extractMostCommonLicenses(obligationResults, ADDITIONAL_REQ_THRESHOLD);
388-
418+
private void fillAdditionalRequirementsTable(XWPFDocument document, Collection<ObligationParsingResult> obligationResults, Set<String> mostLicenses) throws XmlException {
389419
XWPFTable table = document.getTables().get(ADDITIONAL_REQ_TABLE_INDEX);
390420
final int[] currentRow = new int[]{0};
391421

392422
obligationResults.stream()
393423
.filter(opr -> opr.getStatus() == ObligationInfoRequestStatus.SUCCESS)
394424
.flatMap(opr -> opr.getObligations().stream())
395425
.filter(o -> o.getLicenseIDs().stream()
396-
.anyMatch(lid -> mostLicenses.parallelStream().anyMatch(mlid -> mlid.equals(lid))))
426+
.anyMatch(lid -> mostLicenses.parallelStream().anyMatch(mlid -> mlid.equals(lid.replace("\n", "").replace("\r", "")))))
397427
.forEach(o -> {
398428
currentRow[0] = currentRow[0] + 1;
399429
XWPFTableRow row = table.insertNewTableRow(currentRow[0]);

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

+3-2
Original file line numberDiff line numberDiff line change
@@ -293,8 +293,9 @@ private void downloadLicenseInfo(ResourceRequest request, ResourceResponse respo
293293
}
294294

295295
private void sendLicenseInfoResponse(ResourceRequest request, ResourceResponse response, Project project, LicenseInfoFile licenseInfoFile) throws IOException {
296-
OutputFormatInfo outputFormatInfo = licenseInfoFile.getOutputFormatInfo();
297-
String filename = String.format("LicenseInfo-%s%s-%s.%s", project.getName(),
296+
OutputFormatInfo outputFormatInfo = licenseInfoFile.getOutputFormatInfo();
297+
String documentVariant = licenseInfoFile.getOutputFormatInfo().getVariant() == OutputFormatVariant.DISCLOSURE ? "LicenseInfo" : "ProjectClearingReport";
298+
String filename = String.format("%s-%s%s-%s.%s", documentVariant, project.getName(),
298299
StringUtils.isBlank(project.getVersion()) ? "" : "-" + project.getVersion(),
299300
SW360Utils.getCreatedOnTime().replaceAll("\\s", "_").replace(":", "_"),
300301
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%>"/>
@@ -179,6 +180,7 @@
179180
Liferay.on('allPortletsReady', function() {
180181
autocomplete.prepareForMultipleHits('programminglanguages', ${programmingLanguages});
181182
autocomplete.prepareForMultipleHits('op_systems', ${operatingSystemsAutoC});
183+
autocomplete.prepareForMultipleHits('platformsTB', ${platformsAutoC});
182184
183185
sw360Validate.validateWithInvalidHandlerNoIgnore('#releaseEditForm');
184186

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

+11-4
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
<table class="table info_table" id="ComponentBasicInfo">
1717
<thead>
1818
<tr>
19-
<th colspan="3" class="headlabel">Release Summary</th>
19+
<th colspan="4" class="headlabel">Release Summary</th>
2020
</tr>
2121
</thead>
2222
<tr>
@@ -38,21 +38,28 @@
3838
</td>
3939
</tr>
4040
<tr>
41-
<td width="33%">
41+
<td width="25%">
4242
<label class="textlabel stackedLabel" for="programminglanguages">Programming Languages</label>
4343
<input class="toplabelledInput" name="<portlet:namespace/><%=Component._Fields.LANGUAGES%>"
4444
id="programminglanguages" type="text"
4545
placeholder="e.g., Java,C++, C#,..."
4646
value="<sw360:DisplayCollection value='${release.languages}' />"/>
4747
</td>
48-
<td width="33%">
48+
<td width="25%">
4949
<label class="textlabel stackedLabel" for="op_systems">Operating Systems</label>
5050
<input class="toplabelledInput" id="op_systems"
5151
name="<portlet:namespace/><%=Component._Fields.OPERATING_SYSTEMS%>" type="text" align="middle"
5252
placeholder="e.g.,Linux,MAC,Windows,..."
5353
value="<sw360:DisplayCollection value="${release.operatingSystems}" />"/>
5454
</td>
55-
<td width="33%">
55+
<td width="25%">
56+
<label class="textlabel stackedLabel" for="platformsTB">Software Platforms</label>
57+
<input class="toplabelledInput" id="platformsTB"
58+
name="<portlet:namespace/><%=Component._Fields.SOFTWARE_PLATFORMS%>" type="text" align="middle"
59+
placeholder="e.g.,Adobe AIR,.NET,Qt,..."
60+
value="<sw360:DisplayCollection value="${release.softwarePlatforms}" />"/>
61+
</td>
62+
<td width="25%">
5663
<label class="textlabel stackedLabel" for="comp_id">CPE ID</label>
5764
<input id="comp_id" name="<portlet:namespace/><%=Release._Fields.CPEID%>" type="text"
5865
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)