ready to test
git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portal/sbd-uploadshare-portlet@163012 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
61b2a2b0e5
commit
30e57e7efb
|
@ -1,5 +1,39 @@
|
||||||
package org.gcube.portlets.user.sbdportlets;
|
package org.gcube.portlets.user.sbdportlets;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import javax.portlet.ActionRequest;
|
||||||
|
import javax.portlet.ActionResponse;
|
||||||
|
import javax.portlet.PortletException;
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
|
||||||
|
import org.gcube.applicationsupportlayer.social.ApplicationNotificationsManager;
|
||||||
|
import org.gcube.applicationsupportlayer.social.NotificationsManager;
|
||||||
|
import org.gcube.applicationsupportlayer.social.shared.SocialNetworkingSite;
|
||||||
|
import org.gcube.applicationsupportlayer.social.shared.SocialNetworkingUser;
|
||||||
|
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
||||||
|
import org.gcube.common.homelibrary.home.HomeLibrary;
|
||||||
|
import org.gcube.common.homelibrary.home.workspace.Workspace;
|
||||||
|
import org.gcube.common.portal.PortalContext;
|
||||||
|
import org.gcube.common.scope.api.ScopeProvider;
|
||||||
|
import org.gcube.portal.notifications.bean.GenericItemBean;
|
||||||
|
import org.gcube.portal.notifications.thread.MessageNotificationsThread;
|
||||||
|
import org.gcube.vomanagement.usermanagement.impl.LiferayRoleManager;
|
||||||
|
import org.gcube.vomanagement.usermanagement.impl.LiferayUserManager;
|
||||||
|
import org.gcube.vomanagement.usermanagement.model.GCubeUser;
|
||||||
|
|
||||||
|
import com.liferay.portal.kernel.log.Log;
|
||||||
|
import com.liferay.portal.kernel.log.LogFactoryUtil;
|
||||||
|
import com.liferay.portal.kernel.servlet.SessionErrors;
|
||||||
|
import com.liferay.portal.kernel.servlet.SessionMessages;
|
||||||
|
import com.liferay.portal.kernel.util.ParamUtil;
|
||||||
|
import com.liferay.portal.kernel.util.WebKeys;
|
||||||
|
import com.liferay.portal.model.User;
|
||||||
|
import com.liferay.portal.theme.ThemeDisplay;
|
||||||
|
import com.liferay.portal.util.PortalUtil;
|
||||||
import com.liferay.util.bridges.mvc.MVCPortlet;
|
import com.liferay.util.bridges.mvc.MVCPortlet;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -8,6 +42,82 @@ import com.liferay.util.bridges.mvc.MVCPortlet;
|
||||||
* Portlet implementation class UploadDataset
|
* Portlet implementation class UploadDataset
|
||||||
*/
|
*/
|
||||||
public class UploadDataset extends MVCPortlet {
|
public class UploadDataset extends MVCPortlet {
|
||||||
|
private static Log _log = LogFactoryUtil.getLog(UploadDataset.class);
|
||||||
|
private static String UPLOAD_DATASET_ROLE_MANAGER_NAME = "UserUpload-Admin";
|
||||||
|
|
||||||
|
private LiferayRoleManager roleManager = new LiferayRoleManager();
|
||||||
|
private LiferayUserManager userManager = new LiferayUserManager();
|
||||||
|
|
||||||
|
public void addExperiment(ActionRequest actionRequest, ActionResponse actionResponse) throws IOException, PortletException {
|
||||||
|
try{
|
||||||
|
User currentUser = (User) actionRequest.getAttribute(WebKeys.USER);
|
||||||
|
ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);
|
||||||
|
long groupId = themeDisplay.getLayout().getGroupId();
|
||||||
|
String method_name = ParamUtil.getString(actionRequest, "method_name");
|
||||||
|
String people_institutions = ParamUtil.getString(actionRequest, "people_institutions");
|
||||||
|
String demo_tutorial = ParamUtil.getString(actionRequest, "demo_tutorial");
|
||||||
|
String experiment_tags = ParamUtil.getString(actionRequest, "experiment_tags");
|
||||||
|
String[] attachmentIds = ParamUtil.getParameterValues(actionRequest, "selected-attachment");
|
||||||
|
for (int i = 0; i < attachmentIds.length; i++) {
|
||||||
|
System.out.println(i+"id="+attachmentIds[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
_log.debug("new dataset_name : " + method_name);
|
||||||
|
SessionMessages.add(actionRequest.getPortletSession(), "method-form-success");
|
||||||
|
|
||||||
|
|
||||||
|
long teamId = roleManager.getTeam(groupId, UPLOAD_DATASET_ROLE_MANAGER_NAME).getTeamId();
|
||||||
|
List<GCubeUser> theManagers = userManager.listUsersByTeam(teamId);
|
||||||
|
HttpServletRequest request = PortalUtil.getHttpServletRequest(actionRequest);
|
||||||
|
boolean result = sendNotificationToUser(
|
||||||
|
request, groupId, currentUser, theManagers, method_name, people_institutions, demo_tutorial, attachmentIds, experiment_tags);
|
||||||
|
if (result)
|
||||||
|
actionResponse.setRenderParameter("mvcPath", "/html/collaboratewithus/view-method-inserted.jsp");
|
||||||
|
else
|
||||||
|
actionResponse.setRenderParameter("mvcPath", "/html/collaboratewithus/view-method-error.jsp");
|
||||||
|
}catch(Exception e){
|
||||||
|
SessionErrors.add(actionRequest.getPortletSession(),"view-method-error");
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private boolean sendNotificationToUser(HttpServletRequest request, long groupId, User currentUser, List<GCubeUser> theManagers
|
||||||
|
, String method_name, String people_institutions, String demo_tutorial, String[] attachmentIds, String experiment_tags) throws Exception {
|
||||||
|
String scope = PortalContext.getConfiguration().getCurrentScope(""+groupId);
|
||||||
|
_log.info("sendNotificationToUser Scope: " + scope);
|
||||||
|
|
||||||
|
String authorizationToken = PortalContext.getConfiguration().getCurrentUserToken(scope, currentUser.getScreenName());
|
||||||
|
ScopeProvider.instance.set(scope);
|
||||||
|
SecurityTokenProvider.instance.set(authorizationToken);
|
||||||
|
Workspace workspace = HomeLibrary.getUserWorkspace(currentUser.getScreenName());
|
||||||
|
|
||||||
|
List<String> recipientIds = new ArrayList<String>();
|
||||||
|
List<GenericItemBean> recipients = new ArrayList<GenericItemBean>();
|
||||||
|
for (GCubeUser addressee : theManagers) {
|
||||||
|
recipients.add(new GenericItemBean(addressee.getUsername(), addressee.getUsername(), addressee.getFullname(), ""));
|
||||||
|
recipientIds.add(addressee.getUsername());
|
||||||
|
}
|
||||||
|
|
||||||
|
String subject = "A new user uploaded a method or dataset";
|
||||||
|
StringBuilder sb = new StringBuilder("Hi, the following dataset/method was shared by ").append(currentUser.getFullName())
|
||||||
|
.append(" (").append(currentUser.getEmailAddress()).append(").")
|
||||||
|
.append("\n\n").append("Dataset/Method name: ").append(method_name).append("\n")
|
||||||
|
.append("\n").append("Involved people and or institutions: ").append(people_institutions).append("\n")
|
||||||
|
.append("\n").append("Demo/Tutorial:\n").append(demo_tutorial).append("\n")
|
||||||
|
.append("\n").append("Keywords (Comma separated): ").append(experiment_tags).append("\n");
|
||||||
|
|
||||||
|
List<String> attachmentsList = Arrays.asList(attachmentIds);
|
||||||
|
String body = sb.toString();
|
||||||
|
String messageId =
|
||||||
|
workspace.getWorkspaceMessageManager().
|
||||||
|
sendMessageToPortalLogins(subject, body, attachmentsList, recipientIds);
|
||||||
|
|
||||||
|
_log.info("Sending upload method message notification to: " + recipientIds.toString());
|
||||||
|
NotificationsManager nm = new ApplicationNotificationsManager(new SocialNetworkingSite(request), scope, new SocialNetworkingUser(
|
||||||
|
currentUser.getScreenName(), currentUser.getEmailAddress(), currentUser.getFullName(), ""));
|
||||||
|
Thread thread = new Thread(new MessageNotificationsThread(recipients, messageId, subject, body, nm));
|
||||||
|
thread.start();
|
||||||
|
|
||||||
|
return (messageId != null);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,29 @@
|
||||||
|
<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet"%>
|
||||||
|
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
|
||||||
|
<%@ taglib uri="http://liferay.com/tld/aui" prefix="aui"%>
|
||||||
|
<%@ taglib uri="http://liferay.com/tld/ui" prefix="liferay-ui"%>
|
||||||
|
<%@ taglib uri="http://liferay.com/tld/theme" prefix="liferay-theme"%>
|
||||||
|
<%@page import="com.liferay.portal.kernel.portlet.LiferayWindowState"%>
|
||||||
|
<%@page import="com.liferay.portal.kernel.servlet.SessionErrors"%>
|
||||||
|
<%@page import="com.liferay.portal.kernel.servlet.SessionMessages"%>
|
||||||
|
<%@page import="com.liferay.portal.model.User"%>
|
||||||
|
<%@page import="com.liferay.portal.kernel.util.WebKeys"%>
|
||||||
|
<portlet:defineObjects />
|
||||||
|
<liferay-theme:defineObjects />
|
||||||
|
|
||||||
|
<%
|
||||||
|
User currentUser = (User) request.getAttribute(WebKeys.USER);
|
||||||
|
%>
|
||||||
|
|
||||||
|
<portlet:renderURL var="normalState"
|
||||||
|
windowState="<%=LiferayWindowState.NORMAL.toString()%>" />
|
||||||
|
|
||||||
|
<p class="lead">
|
||||||
|
Thank you
|
||||||
|
<%=currentUser.getFirstName()%>. There was an error submitting your request. Please report this issue.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
|
||||||
|
<a class="btn btn-large btn-primary" href="${normalState}"><i
|
||||||
|
class="icon icon-angle-left"></i> Close and return to home</a>
|
||||||
|
<div
|
|
@ -0,0 +1,30 @@
|
||||||
|
<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet"%>
|
||||||
|
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
|
||||||
|
<%@ taglib uri="http://liferay.com/tld/aui" prefix="aui"%>
|
||||||
|
<%@ taglib uri="http://liferay.com/tld/ui" prefix="liferay-ui"%>
|
||||||
|
<%@ taglib uri="http://liferay.com/tld/theme" prefix="liferay-theme"%>
|
||||||
|
<%@page import="com.liferay.portal.kernel.portlet.LiferayWindowState"%>
|
||||||
|
<%@page import="com.liferay.portal.kernel.servlet.SessionErrors"%>
|
||||||
|
<%@page import="com.liferay.portal.kernel.servlet.SessionMessages"%>
|
||||||
|
<%@page import="com.liferay.portal.model.User"%>
|
||||||
|
<%@page import="com.liferay.portal.kernel.util.WebKeys"%>
|
||||||
|
<portlet:defineObjects />
|
||||||
|
<liferay-theme:defineObjects />
|
||||||
|
|
||||||
|
<%
|
||||||
|
User currentUser = (User) request.getAttribute(WebKeys.USER);
|
||||||
|
%>
|
||||||
|
|
||||||
|
<portlet:renderURL var="normalState"
|
||||||
|
windowState="<%=LiferayWindowState.NORMAL.toString()%>" />
|
||||||
|
|
||||||
|
<p class="lead">
|
||||||
|
Thank you
|
||||||
|
<%=currentUser.getFirstName()%>. We have been notified about your
|
||||||
|
request, will get back to you shortly.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
|
||||||
|
<a class="btn btn-large btn-primary" href="${normalState}"><i
|
||||||
|
class="icon icon-angle-left"></i> Close and return to home</a>
|
||||||
|
<div
|
|
@ -5,22 +5,30 @@
|
||||||
<%@ taglib uri="http://liferay.com/tld/theme" prefix="liferay-theme"%>
|
<%@ taglib uri="http://liferay.com/tld/theme" prefix="liferay-theme"%>
|
||||||
<%@page import="com.liferay.portal.kernel.portlet.LiferayWindowState"%>
|
<%@page import="com.liferay.portal.kernel.portlet.LiferayWindowState"%>
|
||||||
<%@page import="com.liferay.portal.kernel.servlet.SessionErrors"%>
|
<%@page import="com.liferay.portal.kernel.servlet.SessionErrors"%>
|
||||||
<%@ taglib uri="http://liferay.com/tld/portlet" prefix="liferay-portlet" %>
|
<%@ taglib uri="http://liferay.com/tld/portlet" prefix="liferay-portlet"%>
|
||||||
|
|
||||||
<portlet:defineObjects />
|
<portlet:defineObjects />
|
||||||
<liferay-theme:defineObjects />
|
<liferay-theme:defineObjects />
|
||||||
<% String wpExplorerId = "workspaceexplorerportlet_WAR_workspaceexplorerportlet"; %>
|
<%
|
||||||
|
String wpExplorerId = "workspaceexplorerportlet_WAR_workspaceexplorerportlet";
|
||||||
|
%>
|
||||||
|
|
||||||
<% if(SessionErrors.contains(renderRequest.getPortletSession(),"dataset-form-error")){%>
|
<%
|
||||||
<liferay-ui:error key="dataset-form-error" message="Dataset experiment form submit had an issue, Please try again." />
|
if (SessionErrors.contains(renderRequest.getPortletSession(), "dataset-form-error")) {
|
||||||
<%} %>
|
%>
|
||||||
|
<liferay-ui:error key="dataset-form-error"
|
||||||
|
message="Dataset experiment form submit had an issue, Please try again." />
|
||||||
|
<%
|
||||||
|
}
|
||||||
|
%>
|
||||||
|
|
||||||
<portlet:actionURL var="addIdeaActionURL" windowState="maximized" name="addIdea">
|
<portlet:actionURL var="addExperimentActionURL" windowState="maximized"
|
||||||
|
name="addExperiment">
|
||||||
</portlet:actionURL>
|
</portlet:actionURL>
|
||||||
|
|
||||||
<liferay-portlet:renderURL var="wpExplorerPopupURL"
|
<liferay-portlet:renderURL var="wpExplorerPopupURL"
|
||||||
portletName="workspaceexplorerportlet_WAR_workspaceexplorerportlet"
|
portletName="workspaceexplorerportlet_WAR_workspaceexplorerportlet"
|
||||||
windowState="<%=LiferayWindowState.POP_UP.toString() %>">
|
windowState="<%=LiferayWindowState.POP_UP.toString()%>">
|
||||||
</liferay-portlet:renderURL>
|
</liferay-portlet:renderURL>
|
||||||
|
|
||||||
<portlet:renderURL var="maximizedState"
|
<portlet:renderURL var="maximizedState"
|
||||||
|
@ -28,17 +36,10 @@
|
||||||
<portlet:renderURL var="normalState"
|
<portlet:renderURL var="normalState"
|
||||||
windowState="<%=LiferayWindowState.NORMAL.toString()%>" />
|
windowState="<%=LiferayWindowState.NORMAL.toString()%>" />
|
||||||
|
|
||||||
<script>
|
|
||||||
Liferay.on('getUserData',function(event) {
|
|
||||||
$("#ciccio").text(event.name);
|
|
||||||
});
|
|
||||||
</script>
|
|
||||||
<div id="ciccio"></div>
|
<div id="ciccio"></div>
|
||||||
<c:set var="maximised" scope="session"
|
<c:set var="maximised" scope="session"
|
||||||
value="${renderRequest.getWindowState().toString().equalsIgnoreCase('maximized')}" />
|
value="${renderRequest.getWindowState().toString().equalsIgnoreCase('maximized')}" />
|
||||||
|
|
||||||
<a href="javascript:showWPPopup('<%=wpExplorerPopupURL%>');">Open Workspace</a>
|
|
||||||
|
|
||||||
<c:choose>
|
<c:choose>
|
||||||
<c:when test="${not maximised}">
|
<c:when test="${not maximised}">
|
||||||
<div style="width: 100%; text-align: center; color: #3B5998;">
|
<div style="width: 100%; text-align: center; color: #3B5998;">
|
||||||
|
@ -51,20 +52,24 @@ Liferay.on('getUserData',function(event) {
|
||||||
class="icon icon-angle-left"></i> Back (Cancel)</a>
|
class="icon icon-angle-left"></i> Back (Cancel)</a>
|
||||||
<div
|
<div
|
||||||
style="width: 100%; text-align: left; padding: 10px; color: #3B5998;">
|
style="width: 100%; text-align: left; padding: 10px; color: #3B5998;">
|
||||||
<aui:form action="<%=addIdeaActionURL%>" method="post" name="fm">
|
<aui:form action="<%=addExperimentActionURL%>" method="post" name="fm">
|
||||||
<aui:input name="dataset_name" label="Dataset/Method name" value=""
|
<aui:input name="method_name" label="Dataset/Method name" value=""
|
||||||
required="true" style="width:90%;" />
|
required="true" style="width:90%;" />
|
||||||
<aui:input type="textarea" rows="3" name="people_institutions"
|
<aui:input type="textarea" rows="3" name="people_institutions"
|
||||||
label="Involved people and or institutions" value=""
|
label="Involved people and or institutions" value=""
|
||||||
required="true" style="width:90%;" />
|
required="true" style="width:90%;" />
|
||||||
|
<aui:input type="textarea" rows="10" name="demo_tutorial"
|
||||||
<aui:input type="textarea" rows="10" name="abstract"
|
label="Description + Demo/Tutorial, 2 pages max" value=""
|
||||||
label="Description + Demo/Tutorial, 2 pages max" value="" required="true"
|
required="true" style="width:90%;" />
|
||||||
style="width:90%;" />
|
<a class="btn btn-primary"
|
||||||
|
href="javascript:showWPPopup('<%=wpExplorerPopupURL%>');" style="margin: 10px 0;"><i
|
||||||
|
class="icon-paper-clip icon-white"></i> Select file to attach</a>
|
||||||
|
<div id="attachedFiles"></div>
|
||||||
<aui:input name="experiment_tags" label="Keywords (Comma separated)"
|
<aui:input name="experiment_tags" label="Keywords (Comma separated)"
|
||||||
value="" required="false" style="width:90%;" />
|
value="" required="false" style="width:90%;" />
|
||||||
<aui:button-row>
|
<aui:button-row>
|
||||||
<a class="btn" href="${normalState}"><i class="icon-remove"></i> Cancel</a>
|
<a class="btn" href="${normalState}"><i class="icon-remove"></i>
|
||||||
|
Cancel</a>
|
||||||
<aui:button type="submit" value="Submit" />
|
<aui:button type="submit" value="Submit" />
|
||||||
</aui:button-row>
|
</aui:button-row>
|
||||||
</aui:form>
|
</aui:form>
|
||||||
|
|
|
@ -7,25 +7,28 @@ function showWPPopup(url) {
|
||||||
{
|
{
|
||||||
dialog: {
|
dialog: {
|
||||||
cache: false,
|
cache: false,
|
||||||
width:600,
|
width:700,
|
||||||
height: 450,
|
height: 550,
|
||||||
modal: true
|
modal: true
|
||||||
},
|
},
|
||||||
id: 'testPopupIdUnique',
|
id: 'testPopupIdUnique',
|
||||||
|
title: 'Select the dataset',
|
||||||
uri: url
|
uri: url
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function closeWPPopup() {
|
|
||||||
var dialog = Liferay.Util.getWindow('testPopupIdUnique');
|
|
||||||
dialog.destroy(); // You can try toggle/hide whatever You want
|
|
||||||
}
|
|
||||||
|
|
||||||
function fireEvent(eventName, eventValue) {
|
//handle the event from ws explorer
|
||||||
Liferay.Util.getOpener().Liferay.fire('getUserData',{
|
Liferay.on('getSelectedItem', function(event) {
|
||||||
name: eventValue
|
var id = event.id;
|
||||||
});
|
var name = event.name;
|
||||||
console.log('fireEvent:done');
|
var chip = $('<span class="badge badge-success" style="margin: 5px; padding:0 5px; line-height: 30px;">'+
|
||||||
closeWPPopup();
|
event.name + ' <button onClick="removeFromParent(this);" class="close">×</button>'+
|
||||||
|
'<input type="hidden" name="selected-attachment" value="'+event.id+'"></span>');
|
||||||
|
$("#attachedFiles").append(chip);
|
||||||
|
});
|
||||||
|
|
||||||
|
function removeFromParent(el) {
|
||||||
|
$(el).parent().remove();
|
||||||
}
|
}
|
Loading…
Reference in New Issue