Uplaod Dataset/Mthod now use upload file from desktop instead from Workspace
git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portal/sbd-uploadshare-portlet@164577 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
77454a130d
commit
43e62f42d5
10
.classpath
10
.classpath
|
@ -17,16 +17,16 @@
|
|||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
<attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
|
||||
<attributes>
|
||||
<attribute name="owner.project.facets" value="java"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="output" path="target/classes"/>
|
||||
</classpath>
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
eclipse.preferences.version=1
|
||||
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
|
||||
org.eclipse.jdt.core.compiler.compliance=1.6
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
|
||||
org.eclipse.jdt.core.compiler.compliance=1.8
|
||||
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
|
||||
org.eclipse.jdt.core.compiler.source=1.6
|
||||
org.eclipse.jdt.core.compiler.source=1.8
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<faceted-project>
|
||||
<fixed facet="wst.jsdt.web"/>
|
||||
<installed facet="java" version="1.6"/>
|
||||
<installed facet="jst.web" version="2.4"/>
|
||||
<installed facet="liferay.portlet" version="6.0"/>
|
||||
<installed facet="wst.jsdt.web" version="1.0"/>
|
||||
<installed facet="java" version="1.8"/>
|
||||
</faceted-project>
|
||||
|
|
4
pom.xml
4
pom.xml
|
@ -62,8 +62,8 @@
|
|||
<version>2.5</version>
|
||||
<configuration>
|
||||
<encoding>UTF-8</encoding>
|
||||
<source>1.6</source>
|
||||
<target>1.6</target>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
package org.gcube.portlets.user.sbdportlets;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
@ -8,6 +11,8 @@ import java.util.List;
|
|||
import javax.portlet.ActionRequest;
|
||||
import javax.portlet.ActionResponse;
|
||||
import javax.portlet.PortletException;
|
||||
import javax.portlet.ResourceRequest;
|
||||
import javax.portlet.ResourceResponse;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.gcube.applicationsupportlayer.social.ApplicationNotificationsManager;
|
||||
|
@ -17,11 +22,15 @@ import org.gcube.applicationsupportlayer.social.shared.SocialNetworkingUser;
|
|||
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
||||
import org.gcube.common.homelibary.model.items.type.WorkspaceItemType;
|
||||
import org.gcube.common.homelibrary.home.HomeLibrary;
|
||||
import org.gcube.common.homelibrary.home.exceptions.HomeNotFoundException;
|
||||
import org.gcube.common.homelibrary.home.exceptions.InternalErrorException;
|
||||
import org.gcube.common.homelibrary.home.workspace.Workspace;
|
||||
import org.gcube.common.homelibrary.home.workspace.WorkspaceFolder;
|
||||
import org.gcube.common.homelibrary.home.workspace.WorkspaceItem;
|
||||
import org.gcube.common.homelibrary.home.workspace.exceptions.ItemNotFoundException;
|
||||
import org.gcube.common.homelibrary.home.workspace.exceptions.WorkspaceFolderNotFoundException;
|
||||
import org.gcube.common.homelibrary.home.workspace.folder.FolderItem;
|
||||
import org.gcube.common.homelibrary.util.WorkspaceUtil;
|
||||
import org.gcube.common.portal.PortalContext;
|
||||
import org.gcube.common.scope.api.ScopeProvider;
|
||||
import org.gcube.portal.notifications.bean.GenericItemBean;
|
||||
|
@ -30,10 +39,15 @@ 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.json.JSONFactoryUtil;
|
||||
import com.liferay.portal.kernel.json.JSONObject;
|
||||
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.upload.FileItem;
|
||||
import com.liferay.portal.kernel.upload.UploadPortletRequest;
|
||||
import com.liferay.portal.kernel.util.FileUtil;
|
||||
import com.liferay.portal.kernel.util.ParamUtil;
|
||||
import com.liferay.portal.kernel.util.WebKeys;
|
||||
import com.liferay.portal.model.User;
|
||||
|
@ -49,7 +63,11 @@ import com.liferay.util.bridges.mvc.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 final static String UPLOADED_FILE_ATTR_NAME = "myfile";
|
||||
//make sure in the jsp there's <portlet:resourceURL var="uploadFileURL" id="uploadFiles" />
|
||||
private final static String RESOURCE_URL_ID = "uploadFiles";
|
||||
public static final String ATTACHMENT_FOLDER ="_shared attachments";
|
||||
|
||||
private LiferayRoleManager roleManager = new LiferayRoleManager();
|
||||
private LiferayUserManager userManager = new LiferayUserManager();
|
||||
|
||||
|
@ -85,6 +103,76 @@ public class UploadDataset extends MVCPortlet {
|
|||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void serveResource(ResourceRequest resourceRequest, ResourceResponse resourceResponse) throws PortletException, IOException {
|
||||
String resourceID = resourceRequest.getResourceID();
|
||||
if (resourceID.equals(RESOURCE_URL_ID)) {
|
||||
UploadPortletRequest uploadRequest = PortalUtil.getUploadPortletRequest(resourceRequest);
|
||||
File multipartFile = uploadRequest.getFile(UPLOADED_FILE_ATTR_NAME);
|
||||
|
||||
FileItem[] items = uploadRequest.getMultipartParameterMap().get(UPLOADED_FILE_ATTR_NAME);
|
||||
String fileName = "";
|
||||
String contentType = "";
|
||||
for (int i = 0; i < items.length; i++) {
|
||||
fileName = items[i].getFileName();
|
||||
contentType = items[i].getContentType();
|
||||
System.out.println(fileName);
|
||||
System.out.println(contentType);
|
||||
}
|
||||
// Path written = Files.write(Paths.get(System.getProperty("catalina.home")+"/temp/"+fileName), FileUtil.getBytes(multipartFile));
|
||||
// System.out.println("Written File = " + written.toRealPath());
|
||||
JSONObject fileObject = JSONFactoryUtil.createJSONObject();
|
||||
try {
|
||||
Workspace workspace = getWorkspace(uploadRequest);
|
||||
String wsItemId = uploadToUserWorkspace(workspace, fileName, contentType, new ByteArrayInputStream(FileUtil.getBytes(multipartFile)));
|
||||
fileObject.put("itemId", wsItemId);
|
||||
fileObject.put("fileName", fileName);
|
||||
} catch (Exception e) {
|
||||
_log.error("There was an error uploading the file " + fileName, e);
|
||||
}
|
||||
|
||||
resourceResponse.getWriter().println(fileObject);
|
||||
} else {
|
||||
_log.debug("nothing to do");
|
||||
}
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param uploadRequest is the XHR http servlet request
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
private Workspace getWorkspace(UploadPortletRequest uploadRequest ) throws Exception {
|
||||
Workspace workspace;
|
||||
try{
|
||||
PortalContext pContext = PortalContext.getConfiguration();
|
||||
ScopeProvider.instance.set(pContext.getCurrentScope(uploadRequest));
|
||||
workspace = HomeLibrary.getUserWorkspace(pContext.getCurrentUser(uploadRequest).getUsername());
|
||||
}catch(InternalErrorException | HomeNotFoundException | WorkspaceFolderNotFoundException e){
|
||||
String msg = "Sorry, an error occurred when retrieving workspace item, Refresh an try again";
|
||||
_log.error("HL error: ",e);
|
||||
throw new Exception(msg);
|
||||
}
|
||||
return workspace;
|
||||
}
|
||||
|
||||
private String uploadToUserWorkspace(Workspace ownerWS, String fileName, String mimeType,InputStream fileData) throws Exception {
|
||||
WorkspaceFolder attachment = null;
|
||||
try{
|
||||
attachment = (WorkspaceFolder) ownerWS.getItemByPath(ownerWS.getRoot().getPath() + "/" + ATTACHMENT_FOLDER);
|
||||
} catch (ItemNotFoundException e) {
|
||||
_log.info(ATTACHMENT_FOLDER + " Workspace Folder does not exists, creating it ");
|
||||
attachment = ownerWS.getRoot().createFolder(ATTACHMENT_FOLDER, "Folder created automatically by the System");
|
||||
}
|
||||
String itemName = WorkspaceUtil.getUniqueName(fileName, attachment);
|
||||
FolderItem item = WorkspaceUtil.createExternalFile(attachment, itemName, "File created automatically by the System", mimeType, fileData);
|
||||
String toReturn = item.getId();
|
||||
_log.debug("Uploaded " + item.getName() + " - Returned Workspace id=" +toReturn);
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
|
|
|
@ -7,6 +7,9 @@
|
|||
<icon>/icon.png</icon>
|
||||
<requires-namespaced-parameters>false</requires-namespaced-parameters>
|
||||
<header-portlet-css>/css/main.css</header-portlet-css>
|
||||
<header-portlet-javascript>
|
||||
/js/jquery.min.js
|
||||
</header-portlet-javascript>
|
||||
<footer-portlet-javascript>
|
||||
/js/main.js
|
||||
</footer-portlet-javascript>
|
||||
|
@ -49,12 +52,6 @@
|
|||
access-application-portlet
|
||||
</css-class-wrapper>
|
||||
</portlet>
|
||||
<portlet>
|
||||
<portlet-name>file-upload</portlet-name>
|
||||
<icon>/icon.png</icon>
|
||||
<header-portlet-css>/css/main.css</header-portlet-css>
|
||||
<css-class-wrapper>file-upload-portlet</css-class-wrapper>
|
||||
</portlet>
|
||||
<role-mapper>
|
||||
<role-name>administrator</role-name>
|
||||
<role-link>Administrator</role-link>
|
||||
|
|
|
@ -143,37 +143,4 @@
|
|||
<role-name>user</role-name>
|
||||
</security-role-ref>
|
||||
</portlet>
|
||||
<portlet>
|
||||
<portlet-name>file-upload</portlet-name>
|
||||
<display-name>File Upload</display-name>
|
||||
<portlet-class>
|
||||
org.gcube.portlets.user.sbd.FileUpload
|
||||
</portlet-class>
|
||||
<init-param>
|
||||
<name>view-template</name>
|
||||
<value>/html/fileupload/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>File Upload</title>
|
||||
<short-title>File Upload</short-title>
|
||||
<keywords></keywords>
|
||||
</portlet-info>
|
||||
<security-role-ref>
|
||||
<role-name>administrator</role-name>
|
||||
</security-role-ref>
|
||||
<security-role-ref>
|
||||
<role-name>guest</role-name>
|
||||
</security-role-ref>
|
||||
<security-role-ref>
|
||||
<role-name>power-user</role-name>
|
||||
</security-role-ref>
|
||||
<security-role-ref>
|
||||
<role-name>user</role-name>
|
||||
</security-role-ref>
|
||||
</portlet>
|
||||
</portlet-app>
|
|
@ -9,6 +9,8 @@
|
|||
|
||||
<portlet:defineObjects />
|
||||
<liferay-theme:defineObjects />
|
||||
<portlet:resourceURL var="uploadFileURL" id="uploadFiles" />
|
||||
|
||||
<%
|
||||
String wpExplorerId = "workspaceexplorerportlet_WAR_workspaceexplorerportlet";
|
||||
%>
|
||||
|
@ -49,6 +51,27 @@
|
|||
|
||||
</c:when>
|
||||
<c:otherwise>
|
||||
<script
|
||||
src="<%=request.getContextPath()%>/js/jquery.uploadfile.min.js"></script>
|
||||
<script>
|
||||
$(document).ready(function(){
|
||||
$("#multipleupload").uploadFile({
|
||||
url:"<%=uploadFileURL.toString()%>",
|
||||
multiple : true,
|
||||
dragDrop : true,
|
||||
sequential : true,
|
||||
sequentialCount : 1,
|
||||
maxFileCount : 3,
|
||||
maxFileSize: 10*1024*1024,
|
||||
showStatusAfterSuccess: false,
|
||||
fileName : "myfile",
|
||||
onSuccess : function(files, data, xhr, pd) {
|
||||
var content = JSON.parse(data);
|
||||
appendChip(content.fileName, content.itemId);
|
||||
}
|
||||
});
|
||||
});
|
||||
</script>
|
||||
<a class="btn btn-link btn-large" href="${normalState}"><i
|
||||
class="icon icon-angle-left"></i> Back (Cancel)</a>
|
||||
<p style="font-size: 15px; padding: 15px;">
|
||||
|
@ -72,11 +95,8 @@
|
|||
<aui:input type="textarea" rows="10" name="demo_tutorial"
|
||||
label="Description + Demo/Tutorial, 2 pages max" value=""
|
||||
required="true" style="width:90%;" />
|
||||
<span> Additional Material:</span>
|
||||
<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>
|
||||
<span> Additional Material (max 3 files, allowed max size per file: 10 MB):</span>
|
||||
<div id="multipleupload">Select file to attach</div>
|
||||
<div id="attachedFiles"></div>
|
||||
<aui:input name="experiment_tags" label="Keywords (Comma separated)"
|
||||
value="" required="false" style="width:90%;" />
|
||||
|
|
|
@ -19,7 +19,7 @@ function showWPPopup(url) {
|
|||
}
|
||||
|
||||
|
||||
//handle the event from ws explorer
|
||||
//handle the event from ws explorer (not used anymore)
|
||||
Liferay.on('getSelectedItem', function(event) {
|
||||
var id = event.id;
|
||||
var name = event.name;
|
||||
|
@ -29,6 +29,13 @@ Liferay.on('getSelectedItem', function(event) {
|
|||
$("#attachedFiles").append(chip);
|
||||
});
|
||||
|
||||
function appendChip(name, id) {
|
||||
var chip = $('<span class="badge badge-success" style="margin: 5px; padding:0 5px; line-height: 30px;">'+
|
||||
name + ' <button onClick="removeFromParent(this);" class="close">×</button>'+
|
||||
'<input type="hidden" name="selected-attachment" value="'+id+'"></span>');
|
||||
$("#attachedFiles").append(chip);
|
||||
}
|
||||
|
||||
function removeFromParent(el) {
|
||||
$(el).parent().remove();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue