Skip to content

chore(licenseinfo): Reporting Component Subsection #438

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,8 @@ private List<ObligationParsingResult> getObligationsForAttachment(Release releas
.map(parser -> wrapTException(() -> parser.getObligations(attachment, user, release)))
.collect(Collectors.toList());

results = assignReleaseToObligationParsingResults(results, release);

obligationCache.put(attachmentContentId, results);
return results;
} catch (WrappedTException exception) {
Expand Down Expand Up @@ -369,11 +371,20 @@ protected List<LicenseInfoParsingResult> assignReleaseToLicenseInfoParsingResult
r.setVendor(release.isSetVendor() ? release.getVendor().getShortname() : "");
r.setName(release.getName());
r.setVersion(release.getVersion());
r.setRelease(release);
}
});
return parsingResults;
}

protected List<ObligationParsingResult> assignReleaseToObligationParsingResults(List<ObligationParsingResult> parsingResults,
Release release) {
parsingResults.stream()
.filter(r -> ! r.isSetRelease())
.forEach(r -> r.setRelease(release));
return parsingResults;
}

protected List<LicenseInfoParsingResult> assignComponentToLicenseInfoParsingResults(List<LicenseInfoParsingResult> parsingResults, Release release, User user) throws TException {
final ComponentService.Iface componentClient = new ThriftClients().makeComponentClient();
final Component component = componentClient.getComponentById(release.getComponentId(), user);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.apache.log4j.Logger;
import org.apache.xmlbeans.XmlException;
import org.eclipse.sw360.datahandler.common.CommonUtils;
import org.eclipse.sw360.datahandler.thrift.components.Release;
import org.eclipse.sw360.datahandler.thrift.SW360Exception;
import org.eclipse.sw360.datahandler.thrift.ThriftClients;
import org.eclipse.sw360.datahandler.thrift.licenseinfo.*;
Expand All @@ -32,6 +33,7 @@
import org.eclipse.sw360.datahandler.thrift.users.UserService;
import org.eclipse.sw360.datahandler.thrift.users.User;

import java.math.BigInteger;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
Expand All @@ -49,6 +51,7 @@ public class DocxGenerator extends OutputGenerator<byte[]> {
private static final String DOCX_TEMPLATE_REPORT_FILE = "/templateReport.docx";
private static final String DOCX_MIME_TYPE = "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
private static final String DOCX_OUTPUT_TYPE = "docx";
public static final String UNKNOWN_LICENSE = "Unknown";

public DocxGenerator(OutputFormatVariant outputFormatVariant, String description) {
super(DOCX_OUTPUT_TYPE, description, true, DOCX_MIME_TYPE, outputFormatVariant);
Expand Down Expand Up @@ -165,9 +168,11 @@ private void fillReportDocument(


fillSpecialOSSRisksTable(document, project, obligationResults);
fillReleaseBulletList(document, projectLicenseInfoResults);
fillReleaseDetailList(document, projectLicenseInfoResults, includeObligations);
fillLicenseList(document, projectLicenseInfoResults);

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

}

private void fillOwnerGroup(XWPFDocument document, Project project) throws XmlException, TException {
Expand Down Expand Up @@ -306,6 +311,61 @@ private void fillOverview3rdPartyComponentTable(XWPFDocument document, Collectio
}
}

private static Optional<ObligationParsingResult> obligationsForRelease(Release release, Collection<ObligationParsingResult> obligationResults) {
return obligationResults.stream().filter(opr -> opr.getRelease() == release).findFirst();
}

private void writeComponentSubsections(XWPFDocument document, Collection<LicenseInfoParsingResult> projectLicenseInfoResults, Collection<ObligationParsingResult> obligationResults) throws XmlException {

for(LicenseInfoParsingResult result : projectLicenseInfoResults) {

XWPFParagraph title = document.createParagraph();
title.setStyle(STYLE_HEADING_3);
title.setNumID(new BigInteger("2"));
XWPFRun titleRun = title.createRun();
titleRun.setText(result.getVendor() + " " + result.getName());

XWPFParagraph description = document.createParagraph();
XWPFRun descriptionRun = description.createRun();

LicenseInfo licenseInfo = result.getLicenseInfo();
String globalLicense = UNKNOWN_LICENSE;
for(LicenseNameWithText l : licenseInfo.getLicenseNamesWithTexts()) {
if("global".equals(l.getType())) {
globalLicense = l.getLicenseName();
break;
}
}

descriptionRun.setText("The component is licensed under " + globalLicense + ".");

if(result.isSetRelease()) {
Optional<ObligationParsingResult> obligationsResultOp = obligationsForRelease(result.getRelease(), obligationResults);

if(!obligationsResultOp.isPresent()) {
continue;
}

ObligationParsingResult obligationsResult = obligationsResultOp.get();

if(!obligationsResult.isSetObligations()) {
continue;
}

int currentRow = 0;
Collection<Obligation> obligations = obligationsResult.getObligations();
XWPFTable table = document.createTable();
for(Obligation o : obligations) {
XWPFTableRow row = table.insertNewTableRow(currentRow++);
String licensesString = String.join(" ", o.getLicenseIDs());
row.addNewTableCell().setText(o.getTopic());
row.addNewTableCell().setText(licensesString);
row.addNewTableCell().setText(o.getText());
}
}
}
}

private void fillReleaseBulletList(XWPFDocument document, Collection<LicenseInfoParsingResult> projectLicenseInfoResults) throws XmlException {
List<String> releaseList = new ArrayList<>();
for (LicenseInfoParsingResult result : projectLicenseInfoResults) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public class DocxUtils {
public static final String ALERT_COLOR = "e95850";
public static final String FONT_FAMILY = "Calibri";
public static final String STYLE_HEADING = "Heading2";
public static final String STYLE_HEADING_3 = "Heading 3";
private static final int BUFFER_SIZE = 16;
private static final int ANCHOR_MAX_SIZE = 40;
private static final String BOOKMARK_PREFIX = "bookmark_";
Expand Down
Binary file modified backend/src/src-licenseinfo/src/main/resources/templateReport.docx
Binary file not shown.
2 changes: 2 additions & 0 deletions libraries/lib-datahandler/src/main/thrift/licenseinfo.thrift
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ struct LicenseInfoParsingResult {
31: optional string name,
32: optional string version,
33: optional string componentType,
34: optional Release release,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this potentially redundant information? E.g. if 30 to 33 is set

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How do you want us to handle this?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

only add only the necessary information / refactor the other part

}

enum ObligationInfoRequestStatus {
Expand All @@ -82,6 +83,7 @@ struct ObligationParsingResult {
1: required ObligationInfoRequestStatus status,
2: optional string message,
3: optional list<Obligation> obligations,
4: optional Release release,
}

struct Obligation {
Expand Down