Skip to content
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

feat(licenses): adding support for project-only obligations #517

Merged
merged 2 commits into from
Jul 18, 2019
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 @@ -24,6 +24,10 @@
import org.eclipse.sw360.datahandler.thrift.components.ComponentService;
import org.eclipse.sw360.datahandler.thrift.components.Release;
import org.eclipse.sw360.datahandler.thrift.components.ReleaseLink;
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.Release;
import org.eclipse.sw360.datahandler.thrift.licenseinfo.*;
import org.eclipse.sw360.datahandler.thrift.licenses.License;
import org.eclipse.sw360.datahandler.thrift.licenses.LicenseService;
Expand Down Expand Up @@ -180,6 +184,8 @@ private void fillReportDocument(
fillCommonRulesTable(document, project);
fillAdditionalRequirementsTable(document, obligationResults);

fillCommonRulesTable(document, project);

// 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -319,4 +319,11 @@ public RequestSummary importAllSpdxLicenses(User user) throws TException {
return handler.importAllSpdxLicenses(user);
}

@Override
public RequestStatus deleteTodo(String id, User user) throws TException {
assertId(id);
assertUser(user);
return handler.deleteTodo(id, user);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.eclipse.sw360.datahandler.thrift.moderation.ModerationRequest;
import org.eclipse.sw360.datahandler.thrift.users.RequestedAction;
import org.eclipse.sw360.datahandler.thrift.users.User;
import org.eclipse.sw360.datahandler.thrift.users.UserGroup;
import org.eclipse.sw360.licenses.tools.SpdxConnector;

import org.apache.log4j.Logger;
Expand All @@ -43,7 +44,6 @@
import static org.eclipse.sw360.datahandler.common.SW360Assert.assertNotNull;
import static org.eclipse.sw360.datahandler.permissions.PermissionUtils.makePermission;
import static org.eclipse.sw360.datahandler.thrift.ThriftValidate.*;
import static org.eclipse.sw360.datahandler.thrift.users.UserGroup.CLEARING_ADMIN;

/**
* Class for accessing the CouchDB database
Expand Down Expand Up @@ -222,7 +222,7 @@ private void fillLicenseForOrganisation(String organisation, License license) {
* @return ID of the added todo.
*/
public String addTodo(@NotNull Todo todo, User user) throws SW360Exception {
if (!PermissionUtils.isUserAtLeast(CLEARING_ADMIN, user)){
if (!PermissionUtils.isUserAtLeast(UserGroup.CLEARING_ADMIN, user)){
return null;
}
prepareTodo(todo);
Expand Down Expand Up @@ -533,7 +533,7 @@ private List<LicenseType> getLicenseTypesFromLicenses(List<License> licenses) {
}

public List<RiskCategory> addRiskCategories(List<RiskCategory> riskCategories, User user) throws SW360Exception {
if (!PermissionUtils.isUserAtLeast(CLEARING_ADMIN, user)){
if (!PermissionUtils.isUserAtLeast(UserGroup.CLEARING_ADMIN, user)){
return null;
}
for (RiskCategory riskCategory : riskCategories) {
Expand All @@ -547,7 +547,7 @@ public List<RiskCategory> addRiskCategories(List<RiskCategory> riskCategories, U
}

public List<Risk> addRisks(List<Risk> risks, User user) throws SW360Exception {
if (!PermissionUtils.isUserAtLeast(CLEARING_ADMIN, user)){
if (!PermissionUtils.isUserAtLeast(UserGroup.CLEARING_ADMIN, user)){
return null;
}
for (Risk risk : risks) {
Expand All @@ -561,7 +561,7 @@ public List<Risk> addRisks(List<Risk> risks, User user) throws SW360Exception {
}

public List<LicenseType> addLicenseTypes(List<LicenseType> licenseTypes, User user) {
if (!PermissionUtils.isUserAtLeast(CLEARING_ADMIN, user)){
if (!PermissionUtils.isUserAtLeast(UserGroup.CLEARING_ADMIN, user)){
return null;
}
final List<DocumentOperationResult> documentOperationResults = licenseTypeRepository.executeBulk(licenseTypes);
Expand Down Expand Up @@ -605,7 +605,7 @@ public List<License> addOrOverwriteLicenses(List<License> licenses, User user, b
}

public List<Obligation> addObligations(List<Obligation> obligations, User user) throws SW360Exception {
if (!PermissionUtils.isUserAtLeast(CLEARING_ADMIN, user)){
if (!PermissionUtils.isUserAtLeast(UserGroup.CLEARING_ADMIN, user)){
return null;
}
for (Obligation obligation : obligations) {
Expand All @@ -619,7 +619,7 @@ public List<Obligation> addObligations(List<Obligation> obligations, User user)
}

public List<Todo> addTodos(List<Todo> todos, User user) throws SW360Exception {
if (!PermissionUtils.isUserAtLeast(CLEARING_ADMIN, user)){
if (!PermissionUtils.isUserAtLeast(UserGroup.CLEARING_ADMIN, user)){
return null;
}
for (Todo todo : todos) {
Expand Down Expand Up @@ -897,4 +897,18 @@ public RequestSummary importAllSpdxLicenses(User user) {
.setTotalElements(spdxIds.size())
.setRequestStatus(RequestStatus.SUCCESS);
}

public RequestStatus deleteTodo(String id, User user) throws SW360Exception {
thegrumpylion marked this conversation as resolved.
Show resolved Hide resolved
Todo todo = todoRepository.get(id);
assertNotNull(todo);

// Remove the license if the user is allowed to do it by himself
if (PermissionUtils.isUserAtLeast(UserGroup.SW360_ADMIN, user)) {
todoRepository.remove(todo);
return RequestStatus.SUCCESS;
} else {
log.error(user + " does not have the permission to delete todo.");
return RequestStatus.ACCESS_DENIED;
}
}
}
Binary file modified frontend/configuration/PrivatePages.lar
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public class PortalConstants {
public static final String PAGENAME_DETAIL = "detail";
public static final String PAGENAME_VIEW = "view";
public static final String PAGENAME_IMPORT = "import";
public static final String PAGENAME_ADD = "add";
public static final String PAGENAME_EDIT = "edit";
public static final String PAGENAME_ACTION = "action";
public static final String PAGENAME_DUPLICATE = "duplicate";
Expand Down Expand Up @@ -126,6 +127,10 @@ public class PortalConstants {
public static final String VENDOR_ID = "vendorId";
public static final String VENDOR_LIST = "vendorList";

//! Specialized keys for todos
public static final String TODO_LIST = "todoList";
public static final String TODO_ID = "todoId";

//! Specialized keys for attachments
public static final String ATTACHMENTS = "attachments";
public static final String SPDX_ATTACHMENTS = "spdxAttachments";
Expand Down Expand Up @@ -341,6 +346,9 @@ public class PortalConstants {
// vendor actions
public static final String REMOVE_VENDOR = "remove_vendor";

// todo actions
public static final String REMOVE_TODO = "removeTodo";

// user actions
public static final String USER_PREFIX = "user";
public static final String USER_SEARCH = USER_PREFIX + "search";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
/*
* Copyright Siemens AG, 2013-2015. Part of the SW360 Portal Project.
thegrumpylion marked this conversation as resolved.
Show resolved Hide resolved
*
* SPDX-License-Identifier: EPL-1.0
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*/
package org.eclipse.sw360.portal.portlets.admin;

import org.apache.log4j.Logger;
import org.apache.thrift.TException;
import org.eclipse.sw360.datahandler.permissions.PermissionUtils;
import org.eclipse.sw360.datahandler.thrift.RequestStatus;
import org.eclipse.sw360.datahandler.thrift.licenses.LicenseService;
import org.eclipse.sw360.datahandler.thrift.licenses.Todo;
import org.eclipse.sw360.datahandler.thrift.users.User;
import org.eclipse.sw360.datahandler.thrift.users.UserGroup;
import org.eclipse.sw360.portal.common.UsedAsLiferayAction;
import org.eclipse.sw360.portal.portlets.Sw360Portlet;
import org.eclipse.sw360.portal.portlets.components.ComponentPortletUtils;
import org.eclipse.sw360.portal.users.UserCacheHolder;

import javax.portlet.*;
import java.io.IOException;
import java.util.Collections;
import java.util.List;

import static org.eclipse.sw360.portal.common.PortalConstants.*;

/**
* Todo portlet implementation
*
* @author [email protected]
*/
public class TodoPortlet extends Sw360Portlet {

private static final Logger log = Logger.getLogger(TodoPortlet.class);


//! Serve resource and helpers
@Override
public void serveResource(ResourceRequest request, ResourceResponse response) {

final String id = request.getParameter("id");
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 there a static var for that?

Copy link
Author

Choose a reason for hiding this comment

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

I don't know. Please provide some pointers on where i can find this static var.

Copy link
Contributor

Choose a reason for hiding this comment

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

It seems like there is none yet but normally the available parameters are defined in org.eclipse.sw360.portal.common.PortalConstants. Maybe just the new ones for Todos there as well?

final User user = UserCacheHolder.getUserFromRequest(request);

LicenseService.Iface licenseClient = thriftClients.makeLicenseClient();
thegrumpylion marked this conversation as resolved.
Show resolved Hide resolved


try {
RequestStatus status = licenseClient.deleteTodo(id, user);
renderRequestStatus(request,response, status);
} catch (TException e) {
log.error("Error deleting todo", e);
renderRequestStatus(request,response, RequestStatus.FAILURE);
}
}


//! VIEW and helpers
@Override
public void doView(RenderRequest request, RenderResponse response) throws IOException, PortletException {


String pageName = request.getParameter(PAGENAME);
if (PAGENAME_ADD.equals(pageName)) {
include("/html/admin/todos/add.jsp", request, response);
} else {
prepareStandardView(request);
super.doView(request, response);
}
}

private void prepareStandardView(RenderRequest request) {
List<Todo> todoList;
try {
final User user = UserCacheHolder.getUserFromRequest(request);
LicenseService.Iface licenseClient = thriftClients.makeLicenseClient();

todoList = licenseClient.getTodos();

} catch (TException e) {
log.error("Could not get Todos from backend ", e);
todoList = Collections.emptyList();
}

request.setAttribute(TODO_LIST, todoList);
}

@UsedAsLiferayAction
public void addTodo(ActionRequest request, ActionResponse response) {

final Todo todo = new Todo();
ComponentPortletUtils.updateTodoFromRequest(request, todo);

try {
LicenseService.Iface licenseClient = thriftClients.makeLicenseClient();
final User user = UserCacheHolder.getUserFromRequest(request);

licenseClient.addTodo(todo, user);
} catch (TException e) {
log.error("Error adding todo", e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.eclipse.sw360.datahandler.common.SW360Utils;
import org.eclipse.sw360.datahandler.thrift.*;
import org.eclipse.sw360.datahandler.thrift.components.*;
import org.eclipse.sw360.datahandler.thrift.licenses.Todo;
import org.eclipse.sw360.datahandler.thrift.users.RequestedAction;
import org.eclipse.sw360.datahandler.thrift.users.User;
import org.eclipse.sw360.datahandler.thrift.vendors.Vendor;
Expand Down Expand Up @@ -148,6 +149,12 @@ public static void updateVendorFromRequest(PortletRequest request, Vendor vendor
setFieldValue(request, vendor, Vendor._Fields.URL);
}

public static void updateTodoFromRequest(PortletRequest request, Todo todo) {
thegrumpylion marked this conversation as resolved.
Show resolved Hide resolved
setFieldValue(request, todo, Todo._Fields.TITLE);
setFieldValue(request, todo, Todo._Fields.TEXT);
setFieldValue(request, todo, Todo._Fields.VALID_FOR_PROJECT);
}

private static void updateLinkedReleaseFromRequest(PortletRequest request, Map<String, ReleaseRelationship> linkedReleases) {
linkedReleases.clear();
String[] ids = request.getParameterValues(Release._Fields.RELEASE_ID_TO_RELATIONSHIP.toString() + ReleaseLink._Fields.ID.toString());
Expand Down Expand Up @@ -186,6 +193,10 @@ private static void setFieldValue(PortletRequest request, Vendor vendor, Vendor.
PortletUtils.setFieldValue(request, vendor, field, Vendor.metaDataMap.get(field), "");
}

private static void setFieldValue(PortletRequest request, Todo todo, Todo._Fields field) {
PortletUtils.setFieldValue(request, todo, field, Todo.metaDataMap.get(field), "");
}

public static RequestStatus deleteRelease(PortletRequest request, Logger log) {
String releaseId = request.getParameter(PortalConstants.RELEASE_ID);
if (releaseId != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ private static boolean isFieldRelevant(Todo._Fields field) {
case REVISION:
case TYPE:
case OBLIGATION_DATABASE_IDS:
case TODO_ID:
case TITLE:
Copy link
Contributor

Choose a reason for hiding this comment

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

I am not sure if this will not causing problems in existing installations. At least in my test instance, where I had some todos before I switched to this branch, I get the exceptions below. Jackson is configured to break on unknown properties and the persistence might already contain todoId fields.

sw360                  | 2019-05-31 10:58:30 ERROR CouchDbRepositorySupport:197 - Documents could not be successfully converted.
sw360                  |  org.ektorp.DbAccessException: com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field "todoId" (class org.eclipse.sw360.datahandler.thrift.licenses.Todo), not marked as ignorable (31 known properties: "distribution", "whitelist", "customPropertyToValueIsSet", "developmentStringIsSet", "validForProjectIsSet", "whitelistIsSet", "title", "developmentIsSet", "obligationDatabaseIds" [truncated]])
sw360                  |  at [Source: N/A; line: -1, column: -1] (through reference chain: org.eclipse.sw360.datahandler.thrift.licenses.Todo["todoId"])
sw360                  | 	at org.ektorp.util.Exceptions.propagate(Exceptions.java:19)
sw360                  | 	at org.ektorp.http.RestTemplate.handleResponse(RestTemplate.java:128)
sw360                  | 	at org.ektorp.http.RestTemplate.getUncached(RestTemplate.java:27)
sw360                  | 	at org.ektorp.impl.DefaultQueryExecutor.executeQuery(DefaultQueryExecutor.java:50)
sw360                  | 	at org.ektorp.impl.StdCouchDbConnector.executeQuery(StdCouchDbConnector.java:433)
sw360                  | 	at org.ektorp.impl.StdCouchDbConnector.queryView(StdCouchDbConnector.java:429)
sw360                  | 	at org.ektorp.support.CouchDbRepositorySupport.queryView(CouchDbRepositorySupport.java:256)
sw360                  | 	at org.ektorp.support.CouchDbRepositorySupport.getAll(CouchDbRepositorySupport.java:118)
sw360                  | 2019-05-31 10:58:30 ERROR ProcessFunction:47 - Internal error processing getTodos
sw360                  |  java.lang.NullPointerException
sw360                  | 	at org.eclipse.sw360.licenses.db.LicenseDatabaseHandler.fillTodos(LicenseDatabaseHandler.java:714)
sw360                  | 	at org.eclipse.sw360.licenses.db.LicenseDatabaseHandler.getTodos(LicenseDatabaseHandler.java:669)
sw360                  | 	at org.eclipse.sw360.licenses.LicenseHandler.getTodos(LicenseHandler.java:142)
sw360                  | 	at org.eclipse.sw360.datahandler.thrift.licenses.LicenseService$Processor$getTodos.getResult(LicenseService.java:3450)
sw360                  | 	at org.eclipse.sw360.datahandler.thrift.licenses.LicenseService$Processor$getTodos.getResult(LicenseService.java:3430)
sw360                  | 	at org.apache.thrift.ProcessFunction.process(ProcessFunction.java:38)
sw360                  | 	at org.apache.thrift.TBaseProcessor.process(TBaseProcessor.java:39)
sw360                  | 	at org.apache.thrift.server.TServlet.doPost(TServlet.java:83)
sw360                  | 	at org.eclipse.sw360.projects.Sw360ThriftServlet.doPost(Sw360ThriftServlet.java:42)
sw360                  | 2019-05-31 10:58:30,878 ERROR TodoPortlet:86 - Could not get Todos from backend
sw360                  |  org.apache.thrift.TApplicationException: Internal error processing getTodos
sw360                  | 	at org.apache.thrift.TServiceClient.receiveBase(TServiceClient.java:79)
sw360                  | 	at org.eclipse.sw360.datahandler.thrift.licenses.LicenseService$Client.recv_getTodos(LicenseService.java:1016)
sw360                  | 	at org.eclipse.sw360.datahandler.thrift.licenses.LicenseService$Client.getTodos(LicenseService.java:1004)
sw360                  | 	at org.eclipse.sw360.portal.portlets.admin.TodoPortlet.prepareStandardView(TodoPortlet.java:83)
sw360                  | 	at org.eclipse.sw360.portal.portlets.admin.TodoPortlet.doView(TodoPortlet.java:72)
sw360                  | 	at com.liferay.portal.kernel.portlet.LiferayPortlet.doDispatch(LiferayPortlet.java:235)
sw360                  | 	at com.liferay.util.bridges.mvc.MVCPortlet.doDispatch(MVCPortlet.java:314)
sw360                  | 	at javax.portlet.GenericPortlet.render(GenericPortlet.java:262)
sw360                  | 	at com.liferay.portlet.FilterChainImpl.doFilter(FilterChainImpl.java:103)

EDIT: This comment would have had a better place in libraries/lib-datahandler/src/main/thrift/licenses.thrift L44... Sorry!

Copy link
Author

Choose a reason for hiding this comment

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

This was extensively discussed with @mcjaeger as it was his suggestion. Please also see this siemens#19

Copy link
Contributor

@imaykay imaykay Jun 5, 2019

Choose a reason for hiding this comment

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

Okay, it might be causing trouble though. But let's see how this behaves on other running test instances. I just wanted to warn early.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, we have discused it to change it, but I think we would need a migration script before rolling out: https://github.com/eclipse/sw360/tree/master/scripts/migrations

Copy link
Author

Choose a reason for hiding this comment

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

@sebastian-su please have a look

case DEVELOPMENT_STRING:
case DISTRIBUTION_STRING:
case WHITELIST:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<portlet id="licenses"/>
<portlet id="components"/>
<portlet id="vendors"/>
<portlet id="todos"/>
<portlet id="projects"/>
<portlet id="search"/>
<portlet id="users"/>
Expand Down
11 changes: 11 additions & 0 deletions frontend/sw360-portlet/src/main/webapp/WEB-INF/liferay-portlet.xml
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,17 @@
<header-portlet-javascript>/js/main.js</header-portlet-javascript>
</portlet>

<portlet>
<portlet-name>todos</portlet-name>
<icon>/icon.png</icon>
<instanceable>false</instanceable>
<private-request-attributes>false</private-request-attributes>
<header-portlet-css>/css/main.css</header-portlet-css>
<header-portlet-css>/css/print.css</header-portlet-css>
<header-portlet-css>/css/tooltips.css</header-portlet-css>
<header-portlet-javascript>/js/main.js</header-portlet-javascript>
</portlet>

<portlet>
<portlet-name>projects</portlet-name>
<icon>/icon.png</icon>
Expand Down
25 changes: 25 additions & 0 deletions frontend/sw360-portlet/src/main/webapp/WEB-INF/portlet.xml
Original file line number Diff line number Diff line change
Expand Up @@ -656,6 +656,31 @@
</security-role-ref>
</portlet>

<portlet>
<portlet-name>todos</portlet-name>
<display-name>TODOs</display-name>
<portlet-class>
org.eclipse.sw360.portal.portlets.admin.TodoPortlet
</portlet-class>
<init-param>
<name>view-template</name>
<value>/html/admin/todos/view.jsp</value>
</init-param>
<expiration-cache>0</expiration-cache>
<supports>
<mime-type>text/html</mime-type>
<portlet-mode>view</portlet-mode>
</supports>
<portlet-info>
<title>TODOs</title>
<short-title>TODOs</short-title>
<keywords/>
</portlet-info>
<security-role-ref>
<role-name>administrator</role-name>
</security-role-ref>
</portlet>

<portlet>
<portlet-name>signup</portlet-name>
<display-name>Sign-Up</display-name>
Expand Down
Loading