-
Notifications
You must be signed in to change notification settings - Fork 101
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(licenses): adding support for project-only obligations
This change introduces a new portlet for managing TODOs under the Admin menu. There are 2 views. One for listing TODOs saved in the database and one for adding a new one. In the listing view, the delete action is also available but can only be executed by users with SW360_ADMIN rights and above. Signed-off-by: Nikolas Sepos <[email protected]>
- Loading branch information
Nikolas Sepos
committed
May 15, 2019
1 parent
94d2ee4
commit dd4c33a
Showing
19 changed files
with
459 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
108 changes: 108 additions & 0 deletions
108
...tend/sw360-portlet/src/main/java/org/eclipse/sw360/portal/portlets/admin/TodoPortlet.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | ||
* | ||
* 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"); | ||
final User user = UserCacheHolder.getUserFromRequest(request); | ||
|
||
LicenseService.Iface licenseClient = thriftClients.makeLicenseClient(); | ||
|
||
|
||
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); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
101 changes: 101 additions & 0 deletions
101
frontend/sw360-portlet/src/main/webapp/html/admin/todos/add.jsp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
<%-- | ||
~ Copyright Siemens AG, 2013-2017. Part of the SW360 Portal Project. | ||
~ | ||
~ 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 | ||
--%> | ||
<%@ page import="org.eclipse.sw360.portal.common.PortalConstants" %> | ||
<%@include file="/html/init.jsp"%> | ||
<%-- the following is needed by liferay to display error messages--%> | ||
<%@include file="/html/utils/includes/errorKeyToMessage.jspf"%> | ||
<portlet:defineObjects /> | ||
<liferay-theme:defineObjects /> | ||
|
||
<%@ page import="javax.portlet.PortletRequest" %> | ||
<%@ page import="com.liferay.portlet.PortletURLFactoryUtil" %> | ||
<%@ page import="org.eclipse.sw360.datahandler.thrift.licenses.Todo" %> | ||
|
||
|
||
<jsp:useBean id="todo" class="org.eclipse.sw360.datahandler.thrift.licenses.Todo" scope="request" /> | ||
|
||
|
||
|
||
<portlet:actionURL var="addURL" name="addTodo"> | ||
</portlet:actionURL> | ||
|
||
|
||
<link rel="stylesheet" href="<%=request.getContextPath()%>/css/sw360.css"> | ||
<link rel="stylesheet" href="<%=request.getContextPath()%>/webjars/jquery-ui/themes/base/jquery-ui.min.css"> | ||
<link rel="stylesheet" href="<%=request.getContextPath()%>/webjars/jquery-confirm2/dist/jquery-confirm.min.css"> | ||
<script src="<%=request.getContextPath()%>/webjars/jquery/dist/jquery.min.js" type="text/javascript"></script> | ||
<script src="<%=request.getContextPath()%>/webjars/jquery-validation/dist/jquery.validate.min.js" type="text/javascript"></script> | ||
<script src="<%=request.getContextPath()%>/webjars/jquery-validation/dist/additional-methods.min.js" type="text/javascript"></script> | ||
<script src="<%=request.getContextPath()%>/webjars/jquery-confirm2/dist/jquery-confirm.min.js" type="text/javascript"></script> | ||
<script src="<%=request.getContextPath()%>/webjars/jquery-ui/jquery-ui.min.js"></script> | ||
|
||
|
||
<div id="where" class="content1"> | ||
<p class="pageHeader"><span class="pageHeaderBigSpan"></span> | ||
</p> | ||
</div> | ||
|
||
<div id="editField" class="content2"> | ||
|
||
<form id="todoAddForm" name="todoAddForm" action="<%=addURL%>" method="post" > | ||
<table class="table info_table" id="todoAddTable"> | ||
<col width="30%"> | ||
<col width="60%"> | ||
<col width="10%"> | ||
<thead> | ||
<tr> | ||
<th colspan="3" class="headlabel">Add TODO</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
<tr> | ||
<td> | ||
<label class="textlabel stackedLabel mandatory" for="todoTitle">Title</label> | ||
<input style="width:100%;" id="todoTitle" type="text" required class="toplabelledInput" placeholder="Enter TODO Title" name="<portlet:namespace/><%=Todo._Fields.TITLE%>"/> | ||
</td> | ||
<td> | ||
<label class="textlabel stackedLabel mandatory" for="todoText">Text</label> | ||
<textarea style="width:100%;" name="<portlet:namespace/><%=Todo._Fields.TEXT%>" id="todoText" cols="50"rows="10" required class="toplabelledInput"></textarea> | ||
</td> | ||
<td> | ||
<label class="textlabel stackedLabel mandatory" for="todoValidForProject">Valid For Projects</label> | ||
<input id="todoValidForProject" type="checkbox" class="toplabelledInput" name="<portlet:namespace/><%=Todo._Fields.VALID_FOR_PROJECT%>"/> | ||
</td> | ||
</tr> | ||
|
||
</tbody> | ||
</table> | ||
<input type="submit" value="Add Todo" class="addButton"> | ||
<input type="button" value="Cancel" onclick="cancel()" class="cancelButton"> | ||
</form> | ||
|
||
|
||
</div> | ||
|
||
<script> | ||
function cancel() { | ||
var baseUrl = '<%= PortletURLFactoryUtil.create(request, portletDisplay.getId(), themeDisplay.getPlid(), PortletRequest.RENDER_PHASE) %>'; | ||
var portletURL = Liferay.PortletURL.createURL( baseUrl ) | ||
.setParameter('<%=PortalConstants.PAGENAME%>','<%=PortalConstants.PAGENAME_VIEW%>') | ||
window.location = portletURL.toString(); | ||
} | ||
var contextpath; | ||
$( document ).ready(function() { | ||
contextpath = '<%=request.getContextPath()%>'; | ||
$('#todoAddForm').validate({ | ||
ignore: [], | ||
invalidHandler: invalidHandlerShowErrorTab | ||
}); | ||
}); | ||
</script> |
Oops, something went wrong.