Skip to content

Commit

Permalink
Merge pull request #507 from siemens/markusherpich/commonrules
Browse files Browse the repository at this point in the history
feat(report): add common rules table

review-by:[email protected]
tested-by:[email protected]
  • Loading branch information
mcjaeger authored Apr 8, 2019
2 parents 851051e + b46cb4d commit 4414cfd
Show file tree
Hide file tree
Showing 14 changed files with 209 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ public void testAllRequiredFieldsAreSet() throws Exception {
case ENABLE_VULNERABILITIES_DISPLAY:
project.enableVulnerabilitiesDisplay = true;
break;
case TODOS:
project.todos = Collections.emptySet();
break;
default: //most fields are string
project.setFieldValue(renderedField, "asd");
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.apache.thrift.TException;
import org.apache.xmlbeans.XmlException;
import org.eclipse.sw360.datahandler.common.CommonUtils;
import org.eclipse.sw360.datahandler.common.SW360Utils;
import org.eclipse.sw360.datahandler.thrift.SW360Exception;
import org.eclipse.sw360.datahandler.thrift.ThriftClients;
import org.eclipse.sw360.datahandler.thrift.components.Component;
Expand Down Expand Up @@ -54,8 +55,9 @@ public class DocxGenerator extends OutputGenerator<byte[]> {
private static final String DOCX_OUTPUT_TYPE = "docx";
public static final String UNKNOWN_LICENSE = "Unknown";
private static final long ADDITIONAL_REQ_THRESHOLD = 3;
public static final int ADDITIONAL_REQ_TABLE_INDEX = 4;
public static final int ADDITIONAL_REQ_TABLE_INDEX = 5;
public static final int DEV_DETAIL_TABLE_INDEX = 2;
private static final int COMMON_RULES_TABLE_INDEX = 4;

public DocxGenerator(OutputFormatVariant outputFormatVariant, String description) {
super(DOCX_OUTPUT_TYPE, description, true, DOCX_MIME_TYPE, outputFormatVariant);
Expand Down Expand Up @@ -175,6 +177,7 @@ private void fillReportDocument(
fillSpecialOSSRisksTable(document, project, obligationResults);
fillDevelopmentDetailsTable(document, project, user);
fillOverview3rdPartyComponentTable(document, projectLicenseInfoResults);
fillCommonRulesTable(document, project);
fillAdditionalRequirementsTable(document, obligationResults);

// because of the impossible API component subsections must be the last thing in the docx file
Expand Down Expand Up @@ -551,4 +554,17 @@ private void fillLicenseList(XWPFDocument document, Collection<LicenseInfoParsin
addNewLines(document, 1);
}
}

private void fillCommonRulesTable(XWPFDocument document, Project project) throws TException {
XWPFTable table = document.getTables().get(COMMON_RULES_TABLE_INDEX);
final int[] currentRow = new int[]{0};

SW360Utils.getProjectObligations(project).entrySet().stream()
.forEachOrdered(todo -> {
currentRow[0] = currentRow[0] + 1;
XWPFTableRow row = table.insertNewTableRow(currentRow[0]);
row.addNewTableCell().setText(todo.getKey().getText());
row.addNewTableCell().setText(todo.getValue().fulfilled ? "yes" : "no");
});
}
}
Binary file modified backend/src/src-licenseinfo/src/main/resources/templateReport.docx
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ public class PortalConstants {
public static final String DEFAULT_OBLIGATIONS_TEXT = "defaultObligationsText";
public static final String DEFAULT_LICENSE_INFO_HEADER_TEXT_FOR_DISPALY = "--default text--";
public static final String DEFAULT_OBLIGATIONS_TEXT_FOR_DISPALY = "--default text--";
public static final String PROJECT_OBLIGATIONS = "projectObligations";
public static final Set<String> PROJECT_EXTERNAL_ID_KEYS;
public static final String PROJECT_SELECTED_ATTACHMENT_USAGES = "selectedAttachmentUsages";
public static final String PROJECT_SELECTED_ATTACHMENT_USAGES_SHADOWS = "selectedAttachmentUsagesShadows";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public void updateVendor(ActionRequest request, ActionResponse response) throws
RequestStatus requestStatus = vendorClient.updateVendor(vendor, user);
setSessionMessage(request, requestStatus, "Vendor", "update", vendor.getShortname());
} catch (TException e) {
log.error("Error fetching release from backend!", e);
log.error("Error fetching vendor from backend!", e);
}
}
else{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,6 @@ public void renderProjectModeration(RenderRequest request, RenderResponse respon
is_used = client.projectIsUsed(actual_project.getId());
request.setAttribute(PortalConstants.ACTUAL_PROJECT, actual_project);
request.setAttribute(PortalConstants.DEFAULT_LICENSE_INFO_HEADER_TEXT, getDefaultLicenseInfoHeaderText());
request.setAttribute(PortalConstants.DEFAULT_OBLIGATIONS_TEXT, getDefaultObligationsText());
} catch (TException e) {
log.error("Could not retrieve project", e);
}
Expand Down Expand Up @@ -603,14 +602,4 @@ private String getDefaultLicenseInfoHeaderText() {
return "";
}
}

private String getDefaultObligationsText() {
final LicenseInfoService.Iface licenseInfoClient = thriftClients.makeLicenseInfoClient();
try {
return licenseInfoClient.getDefaultObligationsText();
} catch (TException e) {
log.error("Could not load default clearing summary text from backend.", e);
return "";
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,32 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.base.Strings;
import com.google.common.collect.*;
import com.liferay.portal.kernel.json.*;
import com.liferay.portal.kernel.json.JSONArray;
import com.liferay.portal.kernel.json.JSONException;
import com.liferay.portal.kernel.json.JSONFactoryUtil;
import com.liferay.portal.kernel.json.JSONObject;
import com.liferay.portal.kernel.portlet.PortletResponseUtil;
import com.liferay.portal.kernel.servlet.SessionMessages;
import com.liferay.portal.model.Organization;
import com.liferay.portal.util.PortalUtil;

import org.eclipse.sw360.datahandler.common.*;
import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import org.apache.thrift.TException;
import org.apache.thrift.TSerializer;
import org.apache.thrift.protocol.TSimpleJSONProtocol;
import org.eclipse.sw360.datahandler.common.CommonUtils;
import org.eclipse.sw360.datahandler.common.SW360Constants;
import org.eclipse.sw360.datahandler.common.SW360Utils;
import org.eclipse.sw360.datahandler.common.ThriftEnumUtils;
import org.eclipse.sw360.datahandler.common.WrappedException.WrappedTException;
import org.eclipse.sw360.datahandler.couchdb.lucene.LuceneAwareDatabaseConnector;
import org.eclipse.sw360.datahandler.permissions.PermissionUtils;
import org.eclipse.sw360.datahandler.thrift.*;
import org.eclipse.sw360.datahandler.thrift.attachments.*;
import org.eclipse.sw360.datahandler.thrift.components.*;
import org.eclipse.sw360.datahandler.thrift.components.ComponentService;
import org.eclipse.sw360.datahandler.thrift.components.Release;
import org.eclipse.sw360.datahandler.thrift.components.ReleaseClearingStatusData;
import org.eclipse.sw360.datahandler.thrift.components.ReleaseLink;
import org.eclipse.sw360.datahandler.thrift.cvesearch.CveSearchService;
import org.eclipse.sw360.datahandler.thrift.cvesearch.VulnerabilityUpdateStatus;
import org.eclipse.sw360.datahandler.thrift.licenseinfo.*;
Expand All @@ -44,24 +57,20 @@
import org.eclipse.sw360.portal.users.LifeRayUserSession;
import org.eclipse.sw360.portal.users.UserCacheHolder;
import org.eclipse.sw360.portal.users.UserUtils;

import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import org.apache.thrift.TException;
import org.apache.thrift.TSerializer;
import org.apache.thrift.protocol.TSimpleJSONProtocol;
import org.jetbrains.annotations.NotNull;

import javax.portlet.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import java.io.IOException;
import java.io.PrintWriter;
import java.net.URLConnection;
import java.util.*;
import java.util.Map.Entry;
import java.util.function.*;
import java.util.function.BiConsumer;
import java.util.function.BiFunction;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.stream.Collector;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -837,6 +846,7 @@ private void prepareDetailView(RenderRequest request, RenderResponse response) t
request.setAttribute(DOCUMENT_TYPE, SW360Constants.TYPE_PROJECT);
request.setAttribute(DOCUMENT_ID, id);
request.setAttribute(DEFAULT_LICENSE_INFO_HEADER_TEXT, getProjectDefaultLicenseInfoHeaderText());

request.setAttribute(DEFAULT_OBLIGATIONS_TEXT, getProjectDefaultObligationsText());
if (id != null) {
try {
Expand All @@ -860,6 +870,7 @@ private void prepareDetailView(RenderRequest request, RenderResponse response) t
PermissionUtils.makePermission(project, user).isActionAllowed(RequestedAction.WRITE));

addProjectBreadcrumb(request, response, project);
request.setAttribute(PROJECT_OBLIGATIONS, SW360Utils.getProjectObligations(project));

} catch (TException e) {
log.error("Error fetching project from backend!", e);
Expand Down Expand Up @@ -1076,6 +1087,7 @@ private void prepareProjectEdit(RenderRequest request) {

request.setAttribute(PROJECT, project);
request.setAttribute(DOCUMENT_ID, id);
request.setAttribute(PROJECT_OBLIGATIONS, SW360Utils.getProjectObligations(project));

setAttachmentsInRequest(request, project);
try {
Expand Down Expand Up @@ -1106,6 +1118,7 @@ private void prepareProjectEdit(RenderRequest request) {
}
request.setAttribute(USING_PROJECTS, Collections.emptySet());
request.setAttribute(ALL_USING_PROJECTS_COUNT, 0);
request.setAttribute(PROJECT_OBLIGATIONS, SW360Utils.getProjectObligations(project));

SessionMessages.add(request, "request_processed", "New Project");
}
Expand Down Expand Up @@ -1284,6 +1297,8 @@ private String getProjectDefaultObligationsText() {
}
}



private void serveProjectList(ResourceRequest request, ResourceResponse response) throws IOException, PortletException {
HttpServletRequest originalServletRequest = PortalUtil.getOriginalServletRequest(PortalUtil.getHttpServletRequest(request));
PaginationParameters paginationParameters = PaginationParser.parametersFrom(originalServletRequest);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.eclipse.sw360.datahandler.thrift.projects.Project;
import org.eclipse.sw360.datahandler.thrift.projects.ProjectLink;
import org.eclipse.sw360.datahandler.thrift.projects.ProjectRelationship;
import org.eclipse.sw360.datahandler.thrift.projects.ProjectTodo;
import org.eclipse.sw360.datahandler.thrift.users.User;
import org.eclipse.sw360.datahandler.thrift.vulnerabilities.ProjectVulnerabilityRating;
import org.eclipse.sw360.datahandler.thrift.vulnerabilities.VulnerabilityCheckStatus;
Expand Down Expand Up @@ -107,12 +108,53 @@ public static void updateProjectFromRequest(PortletRequest request, Project proj
case EXTERNAL_IDS:
project.setExternalIds(PortletUtils.getExternalIdMapFromRequest(request));
break;
case TODOS:
String userId = UserCacheHolder.getUserFromRequest(request).getId();
updateProjectTodosFromRequest(request.getParameterValues(field.toString()), userId, project);
break;
default:
setFieldValue(request, project, field);
}
}
}

private static void updateProjectTodosFromRequest(String[] ids, String userId, Project project) {
Set<String> idSet = ids != null ? Arrays.stream(ids).collect(Collectors.toSet()) : Collections.emptySet();
Set<ProjectTodo> currentTodos = project.getTodosSize() > 0 ? project.getTodos() : Collections.emptySet();
String updated = SW360Utils.getCreatedOnTime();

// assemble set of project todos
Set<ProjectTodo> projectTodos = idSet.stream()
.map(id -> currentTodos.stream()
.filter(pt -> pt.getTodoId().equals(id))
.findAny()
.orElseGet(() -> new ProjectTodo(id, userId, updated, true)))
.collect(Collectors.toSet());

// update changed to fulfilled
projectTodos.stream()
.filter(projectTodo -> !projectTodo.fulfilled)
.forEach(projectTodo -> {
projectTodo.fulfilled = true;
projectTodo.setUserId(userId);
projectTodo.setUpdated(updated);
});

// update changed to not fulfilled
Set<ProjectTodo> changedToNotFulfilled = currentTodos.stream()
.filter(projectTodo -> idSet.stream().noneMatch(id -> id.equals(projectTodo.todoId)))
.map(projectTodo -> {
projectTodo.fulfilled = false;
projectTodo.setUserId(userId);
projectTodo.setUpdated(updated);
return projectTodo;
})
.collect(Collectors.toSet());

projectTodos.addAll(changedToNotFulfilled);
project.setTodos(projectTodos);
}

private static void updateLinkedReleasesFromRequest(PortletRequest request, Map<String, ProjectReleaseRelationship> releaseUsage) {
releaseUsage.clear();
String[] ids = request.getParameterValues(Project._Fields.RELEASE_ID_TO_USAGE.toString() + ReleaseLink._Fields.ID.toString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
~ http://www.eclipse.org/legal/epl-v10.html
--%>

<%@ taglib prefix="core_rt" uri="http://java.sun.com/jstl/core_rt" %>

<table class="table info_table" id="clearing">
<thead>
<tr>
Expand Down Expand Up @@ -96,6 +98,24 @@
</tr>
</table>

<table class="table info_table" id="obligations">
<thead>
<tr><th>Obligation</th><th>Fulfilled</th><th>Modified</th></tr>
</thead>
<tbody>
<core_rt:forEach items="${projectObligations}" var="entry">
<tr>
<td>${entry.getKey().getText()}</td>
<td><input type="checkbox" value="${entry.getKey().getId()}"
disabled="disabled"
<core_rt:if test="${entry.getValue().isFulfilled()}">checked="checked"</core_rt:if>
/></td>
<td>${entry.getValue().getModificationHint()}</td>
</tr>
</core_rt:forEach>
</tbody>
</table>

<table class="table info_table" id="lifecycle">
<thead>
<tr>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

<%@ page import="org.eclipse.sw360.datahandler.thrift.projects.Project" %>

<%@ taglib prefix="core_rt" uri="http://java.sun.com/jstl/core_rt" %>

<table class="table info_table" id="ProjectClearingInfo" title="Clearing">
<thead>
<tr>
Expand Down Expand Up @@ -111,6 +113,24 @@
</tr>
</table>

<table class="table info_table" id="obligations">
<thead>
<tr><th>Obligation</th><th>Fulfilled</th></tr>
</thead>
<tbody>
<core_rt:forEach items="${projectObligations}" var="entry">
<tr>
<td>${entry.getKey().getText()}</td>
<td><input type="checkbox"
name="<portlet:namespace/><%=Project._Fields.TODOS%>"
value="${entry.getKey().getId()}"
<core_rt:if test="${entry.getValue().fulfilled}">checked="checked"</core_rt:if>
/></td>
</tr>
</core_rt:forEach>
</tbody>
</table>

<table class="table info_table" id="ProjectLifecycleInfo" title="Lifecycle">
<thead>
<tr>
Expand Down
Loading

0 comments on commit 4414cfd

Please sign in to comment.