Skip to content

Commit 910d984

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 910d984

File tree

7 files changed

+66
-33
lines changed

7 files changed

+66
-33
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

+43-23
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,13 +48,14 @@ 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;
5860
public static final int ADDITIONAL_REQ_TABLE_INDEX = 5;
5961
public static final int DEV_DETAIL_TABLE_INDEX = 2;
@@ -136,7 +138,7 @@ private void fillDisclosureDocument(
136138
fillReleaseBulletList(document, projectLicenseInfoResults);
137139
fillReleaseDetailList(document, projectLicenseInfoResults, includeObligations);
138140
fillLicenseList(document, projectLicenseInfoResults);
139-
}
141+
}
140142

141143
private void fillReportDocument(
142144
XWPFDocument document,
@@ -147,6 +149,7 @@ private void fillReportDocument(
147149
Collection<ObligationParsingResult> obligationResults,
148150
User user) throws XmlException, TException {
149151

152+
String businessUnit = project.getBusinessUnit();
150153
String projectName = project.getName();
151154
String projectVersion = project.getVersion();
152155
String obligationsText = project.getObligationsText();
@@ -157,11 +160,13 @@ private void fillReportDocument(
157160
String deliveryChannelsText = project.getDeliveryChannels();
158161
String remarksAdditionalRequirementsText = project.getRemarksAdditionalRequirements();
159162
String projectDescription = project.getDescription();
160-
163+
// extract licenses that appear at least ADDITIONAL_REQ_THRESHOLD times
164+
Set<String> mostLicenses = extractMostCommonLicenses(obligationResults, ADDITIONAL_REQ_THRESHOLD);
161165

162166
fillOwnerGroup(document, project);
163167
fillAttendeesTable(document, project);
164168

169+
replaceText(document, "$bunit", businessUnit);
165170
replaceText(document, "$license-info-header", licenseInfoHeaderText);
166171
replaceText(document, "$project-name", projectName);
167172
replaceText(document, "$project-version", projectVersion);
@@ -180,8 +185,6 @@ private void fillReportDocument(
180185
fillCommonRulesTable(document, project);
181186
fillAdditionalRequirementsTable(document, obligationResults);
182187

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
185188
writeComponentSubsections(document, projectLicenseInfoResults, obligationResults);
186189
}
187190

@@ -194,9 +197,9 @@ private void fillOwnerGroup(XWPFDocument document, Project project) throws XmlEx
194197
}
195198

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

199-
int currentRow = 6;
202+
int currentRow = 7;
200203

201204
UserService.Iface userClient = new ThriftClients().makeUserClient();
202205

@@ -220,7 +223,12 @@ private void fillAttendeesTable(XWPFDocument document, Project project) throws X
220223
continue;
221224
}
222225

223-
User user = userClient.getByEmail(email);
226+
User user = null;
227+
try {
228+
user = userClient.getByEmail(email);
229+
} catch (TException te) {
230+
231+
}
224232

225233
XWPFTableRow row = table.insertNewTableRow(currentRow++);
226234
String name = email;
@@ -229,7 +237,7 @@ private void fillAttendeesTable(XWPFDocument document, Project project) throws X
229237
}
230238
String department = "N.A.";
231239
if(user != null) {
232-
name = user.getDepartment();
240+
department = user.getDepartment();
233241
}
234242

235243
row.addNewTableCell().setText(name);
@@ -241,7 +249,7 @@ private void fillAttendeesTable(XWPFDocument document, Project project) throws X
241249
}
242250

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

247255
obligationResults.stream()
@@ -260,7 +268,7 @@ private void fillSpecialOSSRisksTable(XWPFDocument document, Project project, Co
260268
}
261269

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

265273
int currentRow = 1;
266274
for(LicenseInfoParsingResult result : projectLicenseInfoResults) {
@@ -292,17 +300,31 @@ private static Optional<ObligationParsingResult> obligationsForRelease(Release r
292300
return obligationResults.stream().filter(opr -> opr.getRelease() == release).findFirst();
293301
}
294302

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

297307
for (LicenseInfoParsingResult result : projectLicenseInfoResults) {
308+
while (cursor.currentTokenType() != XmlCursor.TokenType.START && cursor.hasNextToken()) {
309+
cursor.toNextToken();
310+
}
311+
312+
if (cursor.currentTokenType() != XmlCursor.TokenType.START) {
313+
throw new SW360Exception("Corrupt template; unable find start token");
314+
}
298315

299-
XWPFParagraph title = document.createParagraph();
316+
XWPFParagraph title = document.insertNewParagraph(cursor);
300317
title.setStyle(STYLE_HEADING_3);
301318
title.setNumID(new BigInteger("2"));
302319
XWPFRun titleRun = title.createRun();
303320
titleRun.setText(result.getVendor() + " " + result.getName());
304321

305-
XWPFParagraph description = document.createParagraph();
322+
if (cursor.hasNextToken()) {
323+
cursor.toNextToken();
324+
} else {
325+
throw new SW360Exception("Corrupt template; unable to proceed to next token");
326+
}
327+
XWPFParagraph description = document.insertNewParagraph(cursor);
306328
XWPFRun descriptionRun = description.createRun();
307329

308330
LicenseInfo licenseInfo = result.getLicenseInfo();
@@ -331,7 +353,7 @@ private void writeComponentSubsections(XWPFDocument document, Collection<License
331353

332354
int currentRow = 0;
333355
Collection<Obligation> obligations = obligationsResult.getObligations();
334-
XWPFTable table = document.createTable();
356+
XWPFTable table = document.insertNewTbl(cursor);
335357
for (Obligation o : obligations) {
336358
XWPFTableRow row = table.insertNewTableRow(currentRow++);
337359
String licensesString = String.join(" ", o.getLicenseIDs());
@@ -359,13 +381,13 @@ private void fillDevelopmentDetailsTable(XWPFDocument document, Project project,
359381

360382
row.addNewTableCell().setText(component.getName());
361383

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

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

368-
String platforms = component.getSoftwarePlatformsSize() == 0 ? "Unknown platforms" : String.join(" ", component.getSoftwarePlatforms());
390+
String platforms = component.getSoftwarePlatformsSize() == 0 ? "N/A" : String.join(" ", component.getSoftwarePlatforms());
369391
row.addNewTableCell().setText(platforms);
370392
}
371393
}
@@ -379,21 +401,19 @@ protected static Set<String> extractMostCommonLicenses(Collection<ObligationPars
379401
.entrySet().stream()
380402
.filter(entry -> entry.getValue().longValue() >= threshold)
381403
.map(entry -> entry.getKey())
404+
.map(license -> license.replace("\n", "").replace("\r", ""))
382405
.collect(Collectors.toSet());
383406
}
384407

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-
408+
private void fillAdditionalRequirementsTable(XWPFDocument document, Collection<ObligationParsingResult> obligationResults, Set<String> mostLicenses) throws XmlException {
389409
XWPFTable table = document.getTables().get(ADDITIONAL_REQ_TABLE_INDEX);
390410
final int[] currentRow = new int[]{0};
391411

392412
obligationResults.stream()
393413
.filter(opr -> opr.getStatus() == ObligationInfoRequestStatus.SUCCESS)
394414
.flatMap(opr -> opr.getObligations().stream())
395415
.filter(o -> o.getLicenseIDs().stream()
396-
.anyMatch(lid -> mostLicenses.parallelStream().anyMatch(mlid -> mlid.equals(lid))))
416+
.anyMatch(lid -> mostLicenses.parallelStream().anyMatch(mlid -> mlid.equals(lid.replace("\n", "").replace("\r", "")))))
397417
.forEach(o -> {
398418
currentRow[0] = currentRow[0] + 1;
399419
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)