Migrated to Liferay 6.2

Updated pom version at 1.4.0

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/widgets/workspace-uploader@128922 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Francesco Mangiacrapa 2016-05-31 13:53:54 +00:00
parent 471ac76beb
commit 77a34755ab
9 changed files with 252 additions and 230 deletions

View File

@ -1,4 +1,8 @@
<ReleaseNotes> <ReleaseNotes>
<Changeset component="org.gcube.portlets-widgets.workspace-uploader.1-4-0"
date="2016-05-31">
<Change>[Feature #4128] Migration to Liferay 6.2</Change>
</Changeset>
<Changeset component="org.gcube.portlets-widgets.workspace-uploader.1-3-0" <Changeset component="org.gcube.portlets-widgets.workspace-uploader.1-3-0"
date="2016-05-18"> date="2016-05-18">
<Change>[Feature #4055] DnD multiple instances</Change> <Change>[Feature #4055] DnD multiple instances</Change>

22
pom.xml
View File

@ -12,7 +12,7 @@
<groupId>org.gcube.portlets.widgets</groupId> <groupId>org.gcube.portlets.widgets</groupId>
<artifactId>workspace-uploader</artifactId> <artifactId>workspace-uploader</artifactId>
<packaging>jar</packaging> <packaging>jar</packaging>
<version>1.3.0-SNAPSHOT</version> <version>1.4.0-SNAPSHOT</version>
<name>Workspace Uploader Widget</name> <name>Workspace Uploader Widget</name>
<description>Workspace Uploader Widget allows your application to upload file/s in the gCube Workspace</description> <description>Workspace Uploader Widget allows your application to upload file/s in the gCube Workspace</description>
<scm> <scm>
@ -37,7 +37,7 @@
<dependency> <dependency>
<groupId>org.gcube.distribution</groupId> <groupId>org.gcube.distribution</groupId>
<artifactId>maven-portal-bom</artifactId> <artifactId>maven-portal-bom</artifactId>
<version>2.6.0-SNAPSHOT</version> <version>LATEST</version>
<type>pom</type> <type>pom</type>
<scope>import</scope> <scope>import</scope>
</dependency> </dependency>
@ -59,13 +59,6 @@
<dependencies> <dependencies>
<!-- UNCOMMENT THIS TO RUN IN DEVO MODE -->
<!-- <dependency> -->
<!-- <groupId>xerces</groupId> -->
<!-- <artifactId>xerces</artifactId> -->
<!-- <version>2.4.0</version> -->
<!-- </dependency> -->
<!-- Google Web Toolkit (GWT) --> <!-- Google Web Toolkit (GWT) -->
<dependency> <dependency>
<groupId>com.google.gwt</groupId> <groupId>com.google.gwt</groupId>
@ -87,6 +80,7 @@
<artifactId>gcube-widgets</artifactId> <artifactId>gcube-widgets</artifactId>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<!-- FWS --> <!-- FWS -->
<dependency> <dependency>
<groupId>org.gcube.resources.discovery</groupId> <groupId>org.gcube.resources.discovery</groupId>
@ -100,9 +94,18 @@
</dependency> </dependency>
<!-- END FWS --> <!-- END FWS -->
<!-- TO USE LIFERAY 6.2 -->
<dependency> <dependency>
<groupId>org.gcube.dvos</groupId> <groupId>org.gcube.dvos</groupId>
<artifactId>usermanagement-core</artifactId> <artifactId>usermanagement-core</artifactId>
<version>[2.0.0-SNAPSHOT, 3.0.0-SNAPSHOT)</version>
<scope>provided</scope>
</dependency>
<!-- TO USE LIFERAY 6.2 -->
<dependency>
<groupId>com.liferay.portal</groupId>
<artifactId>portal-service</artifactId>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
@ -181,6 +184,7 @@
<artifactId>social-networking-library</artifactId> <artifactId>social-networking-library</artifactId>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.gcube.applicationsupportlayer</groupId> <groupId>org.gcube.applicationsupportlayer</groupId>
<artifactId>aslsocial</artifactId> <artifactId>aslsocial</artifactId>

View File

@ -1,5 +1,5 @@
/** /**
* *
*/ */
package org.gcube.portlets.widgets.workspaceuploader.server; package org.gcube.portlets.widgets.workspaceuploader.server;
@ -40,7 +40,7 @@ import org.gcube.portlets.widgets.workspaceuploader.shared.WorkspaceUploaderItem
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
/** /**
* *
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* @Jan 21, 2014 * @Jan 21, 2014
* *
@ -48,7 +48,7 @@ import org.slf4j.LoggerFactory;
public class WorkspaceUploadServlet extends HttpServlet { public class WorkspaceUploadServlet extends HttpServlet {
/** /**
* *
*/ */
private static final long serialVersionUID = -7861878364437065019L; private static final long serialVersionUID = -7861878364437065019L;
@ -61,16 +61,16 @@ public class WorkspaceUploadServlet extends HttpServlet {
public static final String UPLOAD_FORM_ELEMENT = ConstantsWorkspaceUploader.UPLOAD_FORM_ELEMENT; public static final String UPLOAD_FORM_ELEMENT = ConstantsWorkspaceUploader.UPLOAD_FORM_ELEMENT;
public static final String CLIENT_UPLOAD_KEY = ConstantsWorkspaceUploader.CLIENT_UPLOAD_KEYS; public static final String CLIENT_UPLOAD_KEY = ConstantsWorkspaceUploader.CLIENT_UPLOAD_KEYS;
public static final String IS_OVERWRITE = ConstantsWorkspaceUploader.IS_OVERWRITE; public static final String IS_OVERWRITE = ConstantsWorkspaceUploader.IS_OVERWRITE;
public static final String FILE = "File"; public static final String FILE = "File";
public static final String D4ST = Extensions.REPORT_TEMPLATE.getName(); //extension of Report Template type public static final String D4ST = Extensions.REPORT_TEMPLATE.getName(); //extension of Report Template type
public static final String D4SR = Extensions.REPORT.getName(); //extension of Report type public static final String D4SR = Extensions.REPORT.getName(); //extension of Report type
public static Logger logger = LoggerFactory.getLogger(WorkspaceUploadServlet.class); public static Logger logger = LoggerFactory.getLogger(WorkspaceUploadServlet.class);
/*private static String UPLOAD_LOCATION = System.getProperty("java.io.tmpdir"); /*private static String UPLOAD_LOCATION = System.getProperty("java.io.tmpdir");
@Override @Override
public void init() throws ServletException { public void init() throws ServletException {
@ -81,7 +81,7 @@ public class WorkspaceUploadServlet extends HttpServlet {
UPLOAD_LOCATION = System.getenv("CATALINA_TMPDIR"); UPLOAD_LOCATION = System.getenv("CATALINA_TMPDIR");
} }
super.init(); super.init();
}catch(Exception e){ }catch(Exception e){
e.printStackTrace(); e.printStackTrace();
} }
@ -96,7 +96,7 @@ public class WorkspaceUploadServlet extends HttpServlet {
System.out.println("GET method in WorkspaceUploadServlet is running"); System.out.println("GET method in WorkspaceUploadServlet is running");
sendError(response, "Internal error: GET method not supported"); sendError(response, "Internal error: GET method not supported");
} }
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@ -105,49 +105,49 @@ public class WorkspaceUploadServlet extends HttpServlet {
// System.out.println("POST on UploadServlet"); // System.out.println("POST on UploadServlet");
// logger.info("POST on UploadServlet"); // logger.info("POST on UploadServlet");
// //
// if (!ServletFileUpload.isMultipartContent(request)) { // if (!ServletFileUpload.isMultipartContent(request)) {
// logger.error("ERROR: multipart request not found"); // logger.error("ERROR: multipart request not found");
// sendError(response, "ERROR: multipart request not found"); // sendError(response, "ERROR: multipart request not found");
// } // }
// //
// String destinationId = null; // String destinationId = null;
// String uploadType = null; // String uploadType = null;
// boolean isOverwrite = false; // boolean isOverwrite = false;
// String clientUploadKey = null; // String clientUploadKey = null;
// FileItemStream uploadItem = null; // FileItemStream uploadItem = null;
// //
// FileItemFactory factory = new DiskFileItemFactory(); // FileItemFactory factory = new DiskFileItemFactory();
// ServletFileUpload servletFileUpload = new ServletFileUpload(factory); // ServletFileUpload servletFileUpload = new ServletFileUpload(factory);
// //
// try { // try {
// //
// FileItemIterator fileItemIterator = servletFileUpload.getItemIterator(request); // FileItemIterator fileItemIterator = servletFileUpload.getItemIterator(request);
// //
// //GET FILE STREAM // //GET FILE STREAM
// while (fileItemIterator.hasNext()) { // while (fileItemIterator.hasNext()) {
// FileItemStream item = fileItemIterator.next(); // FileItemStream item = fileItemIterator.next();
// //
// if (item.isFormField() && ID_FOLDER.equals(item.getFieldName())){ // if (item.isFormField() && ID_FOLDER.equals(item.getFieldName())){
// destinationId = Streams.asString(item.openStream()); // destinationId = Streams.asString(item.openStream());
// logger.debug("ID_FOLDER OK"); // logger.debug("ID_FOLDER OK");
// } // }
// //
// if (item.isFormField() && UPLOAD_TYPE.equals(item.getFieldName())){ // if (item.isFormField() && UPLOAD_TYPE.equals(item.getFieldName())){
// uploadType = Streams.asString(item.openStream()); // uploadType = Streams.asString(item.openStream());
// logger.debug("UPLOAD_TYPE OK"); // logger.debug("UPLOAD_TYPE OK");
// } // }
// //
// if (item.isFormField() && IS_OVERWRITE.equals(item.getFieldName())){ // if (item.isFormField() && IS_OVERWRITE.equals(item.getFieldName())){
// isOverwrite = Boolean.parseBoolean(Streams.asString(item.openStream())); // isOverwrite = Boolean.parseBoolean(Streams.asString(item.openStream()));
// logger.debug("IS_OVERWRITE OK"); // logger.debug("IS_OVERWRITE OK");
// } // }
// //
// if(item.isFormField() && CLIENT_UPLOAD_KEY.equals(item.getFieldName())){ // if(item.isFormField() && CLIENT_UPLOAD_KEY.equals(item.getFieldName())){
// clientUploadKey = Streams.asString(item.openStream()); // clientUploadKey = Streams.asString(item.openStream());
// logger.debug("CLIENT_UPLOAD_KEY OK"); // logger.debug("CLIENT_UPLOAD_KEY OK");
// } // }
// //
// //MUST BE THE LAST PARAMETER TRASMITTED // //MUST BE THE LAST PARAMETER TRASMITTED
// if (UPLOAD_FORM_ELEMENT.equals(item.getFieldName())){ // if (UPLOAD_FORM_ELEMENT.equals(item.getFieldName())){
// logger.debug(UPLOAD_FORM_ELEMENT); // logger.debug(UPLOAD_FORM_ELEMENT);
@ -162,20 +162,20 @@ public class WorkspaceUploadServlet extends HttpServlet {
// return; // return;
// } // }
} }
private void uploadData(HttpServletRequest request, HttpServletResponse response, FileItemStream uploadItem, String destinationId,String uploadType,String clientUploadKey, boolean isOverwrite) throws ServletException, IOException{ private void uploadData(HttpServletRequest request, HttpServletResponse response, FileItemStream uploadItem, String destinationId,String uploadType,String clientUploadKey, boolean isOverwrite) throws ServletException, IOException{
// String fileName = uploadItem.getName(); // String fileName = uploadItem.getName();
// logger.info("Upload servlet parameters: [fileName: "+fileName+ ", destinationId: "+destinationId +", uploadType: "+uploadType+", isOverwrite: "+isOverwrite+", clientUploadKey: "+clientUploadKey+"]"); // logger.info("Upload servlet parameters: [fileName: "+fileName+ ", destinationId: "+destinationId +", uploadType: "+uploadType+", isOverwrite: "+isOverwrite+", clientUploadKey: "+clientUploadKey+"]");
// //
// if (uploadType == null || uploadType.isEmpty()) { // if (uploadType == null || uploadType.isEmpty()) {
// logger.error("Error processing request in upload servlet: No upload type found"); // logger.error("Error processing request in upload servlet: No upload type found");
// sendError(response, "Internal error: No upload type found"); // sendError(response, "Internal error: No upload type found");
// return; // return;
// } // }
// //
// if(clientUploadKey==null || clientUploadKey.isEmpty()){ // if(clientUploadKey==null || clientUploadKey.isEmpty()){
// logger.error("Error processing request in upload servlet: No client upload key found"); // logger.error("Error processing request in upload servlet: No client upload key found");
// sendError(response, "Internal error: No client upload key found"); // sendError(response, "Internal error: No client upload key found");
@ -220,16 +220,16 @@ public class WorkspaceUploadServlet extends HttpServlet {
// try { // try {
// //we calculate an unique name for the current destination // //we calculate an unique name for the current destination
// String itemName = ""; // String itemName = "";
// //
// logger.debug("getItemName from HL"); // logger.debug("getItemName from HL");
// if(!isOverwrite) // if(!isOverwrite)
// itemName = WorkspaceUtil.getUniqueName(fileName, destinationFolder); // itemName = WorkspaceUtil.getUniqueName(fileName, destinationFolder);
// else // else
// itemName = fileName; // itemName = fileName;
// //
// Long size = Long.parseLong(request.getHeader("Content-Length")); // Long size = Long.parseLong(request.getHeader("Content-Length"));
// logger.debug("size: " + size + " bytes"); // logger.debug("size: " + size + " bytes");
// //
// //
// //Create Item Uploader to read progress // //Create Item Uploader to read progress
// WorkspaceUploadFile wsUploadFile = new WorkspaceUploadFile(destinationFolder.getId(), itemName); // WorkspaceUploadFile wsUploadFile = new WorkspaceUploadFile(destinationFolder.getId(), itemName);
@ -239,17 +239,17 @@ public class WorkspaceUploadServlet extends HttpServlet {
// workspaceUploader.setFile(wsUploadFile); // workspaceUploader.setFile(wsUploadFile);
// workspaceUploader.setStatusDescription("Uploading "+itemName+" at 0%"); // workspaceUploader.setStatusDescription("Uploading "+itemName+" at 0%");
// workspaceUploader.setClientUploadKey(clientUploadKey); // workspaceUploader.setClientUploadKey(clientUploadKey);
// //
// //instanciate the progress listener // //instanciate the progress listener
// AbstractUploadProgressListener uploadProgressListener = new AbstractUploadProgressListener(request, new UploadProgress(), 0, 70); // AbstractUploadProgressListener uploadProgressListener = new AbstractUploadProgressListener(request, new UploadProgress(), 0, 70);
// final UploadProgressInputStream inputStream = new UploadProgressInputStream(uploadItem.openStream(), size); // final UploadProgressInputStream inputStream = new UploadProgressInputStream(uploadItem.openStream(), size);
// inputStream.addListener(uploadProgressListener); // inputStream.addListener(uploadProgressListener);
// workspaceUploader.setUploadProgress(uploadProgressListener.getUploadProgress()); // workspaceUploader.setUploadProgress(uploadProgressListener.getUploadProgress());
// saveWorkspaceUploaderInSession(workspaceUploader, request.getSession()); // saveWorkspaceUploaderInSession(workspaceUploader, request.getSession());
// //
// printStartTime(); // printStartTime();
// File file = StreamUtils.stream2file(inputStream, uploadItem.getName()+UUID.randomUUID(), ".tmp"); // File file = StreamUtils.stream2file(inputStream, uploadItem.getName()+UUID.randomUUID(), ".tmp");
// //
// logger.debug("getMimeType from HL"); // logger.debug("getMimeType from HL");
// String contentType = MimeTypeUtil.getMimeType(itemName, StreamUtils.openInputStream(file)); // String contentType = MimeTypeUtil.getMimeType(itemName, StreamUtils.openInputStream(file));
// logger.debug("Content type (mime type): "+contentType + " unique name: "+itemName); // logger.debug("Content type (mime type): "+contentType + " unique name: "+itemName);
@ -258,46 +258,46 @@ public class WorkspaceUploadServlet extends HttpServlet {
// logger.debug("extension: "+extension); // logger.debug("extension: "+extension);
// //
// if(uploadType.compareTo(FILE)==0) {//IS FILE UPLOAD // if(uploadType.compareTo(FILE)==0) {//IS FILE UPLOAD
// //
// boolean isZipFile = MimeTypeUtil.isZipContentType(contentType); // boolean isZipFile = MimeTypeUtil.isZipContentType(contentType);
// //
// if(isZipFile && (extension.compareToIgnoreCase(D4ST)==0)){ //Create REPORT TEMPLATE // if(isZipFile && (extension.compareToIgnoreCase(D4ST)==0)){ //Create REPORT TEMPLATE
// //
// String newItemName = itemName; // String newItemName = itemName;
// logger.debug("createTemplate: "+newItemName); // logger.debug("createTemplate: "+newItemName);
// createTemplate(request.getSession(), wa, newItemName, file, destinationFolder, response, isOverwrite); // createTemplate(request.getSession(), wa, newItemName, file, destinationFolder, response, isOverwrite);
// //
// }else if(isZipFile && (extension.compareToIgnoreCase(D4SR)==0)){ //Create REPORT // }else if(isZipFile && (extension.compareToIgnoreCase(D4SR)==0)){ //Create REPORT
// //
// String newItemName = itemName; // String newItemName = itemName;
// logger.debug("createReport: "+newItemName); // logger.debug("createReport: "+newItemName);
// createReport(request.getSession(), wa, newItemName, file, destinationFolder, response, isOverwrite); // createReport(request.getSession(), wa, newItemName, file, destinationFolder, response, isOverwrite);
// }else{ //CREATE AN EXTERNAL FILE // }else{ //CREATE AN EXTERNAL FILE
// //
// workspaceUploader = WorkspaceUploaderManager.uploadFile(request, workspaceUploader, wa, itemName, file, destinationFolder, contentType, isOverwrite, size); // workspaceUploader = WorkspaceUploaderManager.uploadFile(request, workspaceUploader, wa, itemName, file, destinationFolder, contentType, isOverwrite, size);
// //
// if(workspaceUploader==null) // if(workspaceUploader==null)
// throw new Exception("Error when creating uploader, it is null!"); // throw new Exception("Error when creating uploader, it is null!");
// //
// sendMessage(response, workspaceUploader.getIdentifier()); // sendMessage(response, workspaceUploader.getIdentifier());
// } // }
// //
// }else {//IS ARCHIVE UPLOAD // }else {//IS ARCHIVE UPLOAD
// //
// if (MimeTypeUtil.isZipContentType(contentType)){ // if (MimeTypeUtil.isZipContentType(contentType)){
// logger.debug("Unziping content"); // logger.debug("Unziping content");
// workspaceUploader = WorkspaceUploaderManager.uploadArchive(request, workspaceUploader, itemName, file, destinationFolder, size); // workspaceUploader = WorkspaceUploaderManager.uploadArchive(request, workspaceUploader, itemName, file, destinationFolder, size);
// //
// if(workspaceUploader==null) // if(workspaceUploader==null)
// throw new Exception("Error when creating uploader, it is null!"); // throw new Exception("Error when creating uploader, it is null!");
// //
// sendMessage(response, workspaceUploader.getIdentifier()); // sendMessage(response, workspaceUploader.getIdentifier());
// } else{ // } else{
// workspaceUploader = WorkspaceUploaderManager.uploadFile(request, workspaceUploader, wa, itemName, file, destinationFolder, contentType, isOverwrite, size); // workspaceUploader = WorkspaceUploaderManager.uploadFile(request, workspaceUploader, wa, itemName, file, destinationFolder, contentType, isOverwrite, size);
// //
// if(workspaceUploader==null) // if(workspaceUploader==null)
// throw new Exception("Error when creating uploader, it is null!"); // throw new Exception("Error when creating uploader, it is null!");
// //
// sendMessage(response, workspaceUploader.getIdentifier()); // sendMessage(response, workspaceUploader.getIdentifier());
// } // }
// } // }
@ -322,7 +322,7 @@ public class WorkspaceUploadServlet extends HttpServlet {
// } // }
} }
public static WorkspaceUploaderItem saveWorkspaceUploaderInSession(WorkspaceUploaderItem workspaceUploader, HttpSession httpSession) throws Exception { public static WorkspaceUploaderItem saveWorkspaceUploaderInSession(WorkspaceUploaderItem workspaceUploader, HttpSession httpSession) throws Exception {
if(workspaceUploader!=null){ if(workspaceUploader!=null){
@ -336,7 +336,7 @@ public class WorkspaceUploadServlet extends HttpServlet {
} }
throw new Exception("An error occurredin the upload. Workspace Uploader not found. Abort and try again"); throw new Exception("An error occurredin the upload. Workspace Uploader not found. Abort and try again");
} }
/** /**
* Gets the random. * Gets the random.
* *
@ -346,7 +346,7 @@ public class WorkspaceUploadServlet extends HttpServlet {
Random randomGenerator = new Random(); Random randomGenerator = new Random();
return randomGenerator.nextInt(Integer.MAX_VALUE); return randomGenerator.nextInt(Integer.MAX_VALUE);
} }
//TEST TIME //TEST TIME
public static Long startTime = new Long(0); public static Long startTime = new Long(0);
//TEST TIME //TEST TIME
@ -364,14 +364,17 @@ public class WorkspaceUploadServlet extends HttpServlet {
/** /**
* * Notify upload in shared folder.
* @param httpSession *
* @param workspace * @param request the request
* @param itemId * @param httpSession the http session
* @param destinationFolderId * @param workspace the workspace
* @param itemId the item id
* @param destinationFolderId the destination folder id
* @param isOverwrite the is overwrite
*/ */
public static void notifyUploadInSharedFolder(final HttpSession httpSession, final Workspace workspace, final String itemId, final String destinationFolderId, final boolean isOverwrite){ public static void notifyUploadInSharedFolder(final HttpServletRequest request, final HttpSession httpSession, final Workspace workspace, final String itemId, final String destinationFolderId, final boolean isOverwrite){
new Thread(){ new Thread(){
public void run() { public void run() {
WorkspaceItem sourceItem; WorkspaceItem sourceItem;
@ -379,20 +382,20 @@ public class WorkspaceUploadServlet extends HttpServlet {
sourceItem = workspace.getItem(itemId); sourceItem = workspace.getItem(itemId);
String sourceSharedId = sourceItem.getIdSharedFolder(); String sourceSharedId = sourceItem.getIdSharedFolder();
WorkspaceItem folderDestinationItem = workspace.getItem(destinationFolderId); WorkspaceItem folderDestinationItem = workspace.getItem(destinationFolderId);
NotificationsWorkspaceUploader.checkSendNotifyChangedItemToShare(httpSession, sourceItem, sourceSharedId, folderDestinationItem,isOverwrite); NotificationsWorkspaceUploader.checkSendNotifyChangedItemToShare(request, httpSession, sourceItem, sourceSharedId, folderDestinationItem,isOverwrite);
} catch (Exception e) { } catch (Exception e) {
logger.error("Error in notifyUploadInSharedFolder", e); logger.error("Error in notifyUploadInSharedFolder", e);
} }
}; };
}.start(); }.start();
} }
private FolderItem overwriteItem(Workspace wa, String itemName, InputStream fileData, WorkspaceFolder destinationFolder){ private FolderItem overwriteItem(Workspace wa, String itemName, InputStream fileData, WorkspaceFolder destinationFolder){
FolderItem overwriteItem = null; FolderItem overwriteItem = null;
try { try {
logger.debug("case overwriting item.. "+itemName); logger.debug("case overwriting item.. "+itemName);
overwriteItem = (FolderItem) wa.find(itemName, destinationFolder.getId()); overwriteItem = (FolderItem) wa.find(itemName, destinationFolder.getId());
@ -416,30 +419,30 @@ public class WorkspaceUploadServlet extends HttpServlet {
}catch (Exception e) { }catch (Exception e) {
logger.error("Error in createExternalFile, Exception", e); logger.error("Error in createExternalFile, Exception", e);
} }
return overwriteItem; return overwriteItem;
} }
private void createReport(HttpSession httpSession, Workspace wa, String itemName, File file, WorkspaceFolder destinationFolder, HttpServletResponse response, boolean isOverwrite) throws InsufficientPrivilegesException, ItemAlreadyExistException, InternalErrorException, IOException{ private void createReport(final HttpServletRequest request, HttpSession httpSession, Workspace wa, String itemName, File file, WorkspaceFolder destinationFolder, HttpServletResponse response, boolean isOverwrite) throws InsufficientPrivilegesException, ItemAlreadyExistException, InternalErrorException, IOException{
try { try {
Report report = null; Report report = null;
if(!isOverwrite){ if(!isOverwrite){
itemName = WorkspaceUtil.getUniqueName(itemName, destinationFolder); itemName = WorkspaceUtil.getUniqueName(itemName, destinationFolder);
report = wa.createReport(itemName, "", Calendar.getInstance(), Calendar.getInstance(), "", "", "", 0, "", StreamUtils.openInputStream(file), destinationFolder.getId()); report = wa.createReport(itemName, "", Calendar.getInstance(), Calendar.getInstance(), "", "", "", 0, "", StreamUtils.openInputStream(file), destinationFolder.getId());
notifyUploadInSharedFolder(httpSession,wa,report.getId(),destinationFolder.getId(), isOverwrite); notifyUploadInSharedFolder(request, httpSession,wa,report.getId(),destinationFolder.getId(), isOverwrite);
sendMessage(response, "File "+report.getName()+" imported correctly in "+destinationFolder.getPath()); sendMessage(response, "File "+report.getName()+" imported correctly in "+destinationFolder.getPath());
} }
else{ //CASE OVERWRITE else{ //CASE OVERWRITE
FolderItem rep = overwriteItem(wa, itemName, StreamUtils.openInputStream(file), destinationFolder); FolderItem rep = overwriteItem(wa, itemName, StreamUtils.openInputStream(file), destinationFolder);
if(rep!=null){ if(rep!=null){
notifyUploadInSharedFolder(httpSession,wa,rep.getId(),destinationFolder.getId(), isOverwrite); notifyUploadInSharedFolder(request, httpSession,wa,rep.getId(),destinationFolder.getId(), isOverwrite);
sendMessage(response, "File "+rep.getName()+" imported correctly in "+destinationFolder.getPath()); sendMessage(response, "File "+rep.getName()+" imported correctly in "+destinationFolder.getPath());
} }
else else
@ -458,28 +461,28 @@ public class WorkspaceUploadServlet extends HttpServlet {
// TODO: handle exception // TODO: handle exception
} }
} }
} }
private void createTemplate(HttpSession httpSession, Workspace wa, String itemName, File file, WorkspaceFolder destinationFolder, HttpServletResponse response, boolean isOverwrite) throws InsufficientPrivilegesException, ItemAlreadyExistException, InternalErrorException, IOException{ private void createTemplate(final HttpServletRequest request, HttpSession httpSession, Workspace wa, String itemName, File file, WorkspaceFolder destinationFolder, HttpServletResponse response, boolean isOverwrite) throws InsufficientPrivilegesException, ItemAlreadyExistException, InternalErrorException, IOException{
try { try {
ReportTemplate template = null; ReportTemplate template = null;
if(!isOverwrite){ if(!isOverwrite){
itemName = WorkspaceUtil.getUniqueName(itemName, destinationFolder); itemName = WorkspaceUtil.getUniqueName(itemName, destinationFolder);
template = wa.createReportTemplate(itemName, "", Calendar.getInstance(), Calendar.getInstance(), "", "", 0, "", StreamUtils.openInputStream(file), destinationFolder.getId()); template = wa.createReportTemplate(itemName, "", Calendar.getInstance(), Calendar.getInstance(), "", "", 0, "", StreamUtils.openInputStream(file), destinationFolder.getId());
notifyUploadInSharedFolder(httpSession,wa,template.getId(),destinationFolder.getId(), isOverwrite); notifyUploadInSharedFolder(request, httpSession,wa,template.getId(),destinationFolder.getId(), isOverwrite);
sendMessage(response, "File "+template.getName()+" imported correctly in "+destinationFolder.getPath()); sendMessage(response, "File "+template.getName()+" imported correctly in "+destinationFolder.getPath());
}else{ //CASE OVERWRITE }else{ //CASE OVERWRITE
FolderItem rep = overwriteItem(wa, itemName, StreamUtils.openInputStream(file), destinationFolder); FolderItem rep = overwriteItem(wa, itemName, StreamUtils.openInputStream(file), destinationFolder);
if(rep!=null){ if(rep!=null){
notifyUploadInSharedFolder(httpSession,wa,rep.getId(),destinationFolder.getId(), isOverwrite); notifyUploadInSharedFolder(request, httpSession,wa,rep.getId(),destinationFolder.getId(), isOverwrite);
sendMessage(response, "File "+rep.getName()+" imported correctly in "+destinationFolder.getPath()); sendMessage(response, "File "+rep.getName()+" imported correctly in "+destinationFolder.getPath());
} }
else else
@ -499,10 +502,10 @@ public class WorkspaceUploadServlet extends HttpServlet {
// TODO: handle exception // TODO: handle exception
} }
} }
} }
protected void sendError(HttpServletResponse response, String message) throws IOException{ protected void sendError(HttpServletResponse response, String message) throws IOException{
try { try {
response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
@ -519,7 +522,7 @@ public class WorkspaceUploadServlet extends HttpServlet {
throw e; //Sending Exceptions throw e; //Sending Exceptions
} }
} }
protected void sendMessage(HttpServletResponse response, String message) throws IOException{ protected void sendMessage(HttpServletResponse response, String message) throws IOException{
try { try {
response.setStatus(HttpServletResponse.SC_ACCEPTED); response.setStatus(HttpServletResponse.SC_ACCEPTED);
@ -536,7 +539,7 @@ public class WorkspaceUploadServlet extends HttpServlet {
throw e; //Sending Exceptions throw e; //Sending Exceptions
} }
} }
protected void sendWarnMessage(HttpServletResponse response, String message) throws IOException{ protected void sendWarnMessage(HttpServletResponse response, String message) throws IOException{
try { try {
response.setStatus(HttpServletResponse.SC_ACCEPTED); response.setStatus(HttpServletResponse.SC_ACCEPTED);

View File

@ -459,16 +459,16 @@ public class WorkspaceUploadServletStream extends HttpServlet implements Servlet
String newItemName = itemName; String newItemName = itemName;
logger.debug("createTemplate: "+newItemName); logger.debug("createTemplate: "+newItemName);
createTemplate(workspaceUploader, request.getSession(), wa, newItemName, inputStream, destinationFolder, response, isOverwrite); createTemplate(request, workspaceUploader, request.getSession(), wa, newItemName, inputStream, destinationFolder, response, isOverwrite);
}else if(isZipFile && extension.compareToIgnoreCase(D4SR)==0){ //Create REPORT }else if(isZipFile && extension.compareToIgnoreCase(D4SR)==0){ //Create REPORT
String newItemName = itemName; String newItemName = itemName;
logger.debug("createReport: "+newItemName); logger.debug("createReport: "+newItemName);
createReport(workspaceUploader, request.getSession(), wa, newItemName, inputStream, destinationFolder, response, isOverwrite); createReport(request, workspaceUploader, request.getSession(), wa, newItemName, inputStream, destinationFolder, response, isOverwrite);
}else{ //CREATE AN EXTERNAL FILE }else{ //CREATE AN EXTERNAL FILE
workspaceUploader = WorkspaceUploaderMng.uploadFile(workspaceUploader, request.getSession(), wa, itemName, inputStream, destinationFolder, contentType, isOverwrite, size); workspaceUploader = WorkspaceUploaderMng.uploadFile(request, workspaceUploader, request.getSession(), wa, itemName, inputStream, destinationFolder, contentType, isOverwrite, size);
if(workspaceUploader==null) if(workspaceUploader==null)
throw new Exception("Error when creating uploader, it is null!"); throw new Exception("Error when creating uploader, it is null!");
@ -489,7 +489,7 @@ public class WorkspaceUploadServletStream extends HttpServlet implements Servlet
sendMessage(response, workspaceUploader.getIdentifier()); sendMessage(response, workspaceUploader.getIdentifier());
} else{ } else{
workspaceUploader = WorkspaceUploaderMng.uploadFile(workspaceUploader, request.getSession(), wa, itemName, inputStream, destinationFolder, contentType, isOverwrite, size); workspaceUploader = WorkspaceUploaderMng.uploadFile(request, workspaceUploader, request.getSession(), wa, itemName, inputStream, destinationFolder, contentType, isOverwrite, size);
if(workspaceUploader==null) if(workspaceUploader==null)
throw new Exception("Error when creating uploader, it is null!"); throw new Exception("Error when creating uploader, it is null!");
@ -630,13 +630,14 @@ public class WorkspaceUploadServletStream extends HttpServlet implements Servlet
/** /**
* Notify upload in shared folder. * Notify upload in shared folder.
* *
* @param request the request
* @param httpSession the http session * @param httpSession the http session
* @param workspace the workspace * @param workspace the workspace
* @param itemId the item id * @param itemId the item id
* @param destinationFolderId the destination folder id * @param destinationFolderId the destination folder id
* @param isOverwrite the is overwrite * @param isOverwrite the is overwrite
*/ */
public static void notifyUploadInSharedFolder(final HttpSession httpSession, final Workspace workspace, final String itemId, final String destinationFolderId, final boolean isOverwrite){ public static void notifyUploadInSharedFolder(final HttpServletRequest request, final HttpSession httpSession, final Workspace workspace, final String itemId, final String destinationFolderId, final boolean isOverwrite){
new Thread(){ new Thread(){
public void run() { public void run() {
@ -645,7 +646,7 @@ public class WorkspaceUploadServletStream extends HttpServlet implements Servlet
sourceItem = workspace.getItem(itemId); sourceItem = workspace.getItem(itemId);
String sourceSharedId = sourceItem.getIdSharedFolder(); String sourceSharedId = sourceItem.getIdSharedFolder();
WorkspaceItem folderDestinationItem = workspace.getItem(destinationFolderId); WorkspaceItem folderDestinationItem = workspace.getItem(destinationFolderId);
NotificationsWorkspaceUploader.checkSendNotifyChangedItemToShare(httpSession, sourceItem, sourceSharedId, folderDestinationItem,isOverwrite); NotificationsWorkspaceUploader.checkSendNotifyChangedItemToShare(request, httpSession, sourceItem, sourceSharedId, folderDestinationItem,isOverwrite);
} catch (Exception e) { } catch (Exception e) {
logger.error("Error in notifyUploadInSharedFolder", e); logger.error("Error in notifyUploadInSharedFolder", e);
} }
@ -698,6 +699,7 @@ public class WorkspaceUploadServletStream extends HttpServlet implements Servlet
/** /**
* Creates the report. * Creates the report.
* *
* @param request the request
* @param workspaceUploader the workspace uploader * @param workspaceUploader the workspace uploader
* @param httpSession the http session * @param httpSession the http session
* @param wa the wa * @param wa the wa
@ -711,7 +713,7 @@ public class WorkspaceUploadServletStream extends HttpServlet implements Servlet
* @throws InternalErrorException the internal error exception * @throws InternalErrorException the internal error exception
* @throws IOException Signals that an I/O exception has occurred. * @throws IOException Signals that an I/O exception has occurred.
*/ */
private void createReport(WorkspaceUploaderItem workspaceUploader, HttpSession httpSession, Workspace wa, String itemName, InputStream fileInputStream, WorkspaceFolder destinationFolder, HttpServletResponse response, boolean isOverwrite) throws InsufficientPrivilegesException, ItemAlreadyExistException, InternalErrorException, IOException{ private void createReport(final HttpServletRequest request, WorkspaceUploaderItem workspaceUploader, HttpSession httpSession, Workspace wa, String itemName, InputStream fileInputStream, WorkspaceFolder destinationFolder, HttpServletResponse response, boolean isOverwrite) throws InsufficientPrivilegesException, ItemAlreadyExistException, InternalErrorException, IOException{
try { try {
@ -721,7 +723,7 @@ public class WorkspaceUploadServletStream extends HttpServlet implements Servlet
itemName = WorkspaceUtil.getUniqueName(itemName, destinationFolder); itemName = WorkspaceUtil.getUniqueName(itemName, destinationFolder);
report = wa.createReport(itemName, "", Calendar.getInstance(), Calendar.getInstance(), "", "", "", 0, "",fileInputStream, destinationFolder.getId()); report = wa.createReport(itemName, "", Calendar.getInstance(), Calendar.getInstance(), "", "", "", 0, "",fileInputStream, destinationFolder.getId());
notifyUploadInSharedFolder(httpSession,wa,report.getId(),destinationFolder.getId(), isOverwrite); notifyUploadInSharedFolder(request, httpSession,wa,report.getId(),destinationFolder.getId(), isOverwrite);
sendMessage(response, "File "+report.getName()+" imported correctly in "+destinationFolder.getPath()); sendMessage(response, "File "+report.getName()+" imported correctly in "+destinationFolder.getPath());
} }
else{ //CASE OVERWRITE else{ //CASE OVERWRITE
@ -729,7 +731,7 @@ public class WorkspaceUploadServletStream extends HttpServlet implements Servlet
if(rep!=null){ if(rep!=null){
notifyUploadInSharedFolder(httpSession,wa,rep.getId(),destinationFolder.getId(), isOverwrite); notifyUploadInSharedFolder(request, httpSession,wa,rep.getId(),destinationFolder.getId(), isOverwrite);
sendMessage(response, "File "+rep.getName()+" imported correctly in "+destinationFolder.getPath()); sendMessage(response, "File "+rep.getName()+" imported correctly in "+destinationFolder.getPath());
} }
else else
@ -772,7 +774,7 @@ public class WorkspaceUploadServletStream extends HttpServlet implements Servlet
* @throws InternalErrorException the internal error exception * @throws InternalErrorException the internal error exception
* @throws IOException Signals that an I/O exception has occurred. * @throws IOException Signals that an I/O exception has occurred.
*/ */
private void createTemplate(WorkspaceUploaderItem workspaceUploader, HttpSession httpSession, Workspace wa, String itemName, InputStream fileInputStream, WorkspaceFolder destinationFolder, HttpServletResponse response, boolean isOverwrite) throws InsufficientPrivilegesException, ItemAlreadyExistException, InternalErrorException, IOException{ private void createTemplate(final HttpServletRequest request, WorkspaceUploaderItem workspaceUploader, HttpSession httpSession, Workspace wa, String itemName, InputStream fileInputStream, WorkspaceFolder destinationFolder, HttpServletResponse response, boolean isOverwrite) throws InsufficientPrivilegesException, ItemAlreadyExistException, InternalErrorException, IOException{
try { try {
@ -782,7 +784,7 @@ public class WorkspaceUploadServletStream extends HttpServlet implements Servlet
itemName = WorkspaceUtil.getUniqueName(itemName, destinationFolder); itemName = WorkspaceUtil.getUniqueName(itemName, destinationFolder);
template = wa.createReportTemplate(itemName, "", Calendar.getInstance(), Calendar.getInstance(), "", "", 0, "", fileInputStream, destinationFolder.getId()); template = wa.createReportTemplate(itemName, "", Calendar.getInstance(), Calendar.getInstance(), "", "", 0, "", fileInputStream, destinationFolder.getId());
notifyUploadInSharedFolder(httpSession,wa,template.getId(),destinationFolder.getId(), isOverwrite); notifyUploadInSharedFolder(request, httpSession,wa,template.getId(),destinationFolder.getId(), isOverwrite);
sendMessage(response, "File "+template.getName()+" imported correctly in "+destinationFolder.getPath()); sendMessage(response, "File "+template.getName()+" imported correctly in "+destinationFolder.getPath());
}else{ //CASE OVERWRITE }else{ //CASE OVERWRITE
@ -790,7 +792,7 @@ public class WorkspaceUploadServletStream extends HttpServlet implements Servlet
if(rep!=null){ if(rep!=null){
notifyUploadInSharedFolder(httpSession,wa,rep.getId(),destinationFolder.getId(), isOverwrite); notifyUploadInSharedFolder(request, httpSession,wa,rep.getId(),destinationFolder.getId(), isOverwrite);
sendMessage(response, "File "+rep.getName()+" imported correctly in "+destinationFolder.getPath()); sendMessage(response, "File "+rep.getName()+" imported correctly in "+destinationFolder.getPath());
} }
else else

View File

@ -1,11 +1,12 @@
/** /**
* *
*/ */
package org.gcube.portlets.widgets.workspaceuploader.server.notification; package org.gcube.portlets.widgets.workspaceuploader.server.notification;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession; import javax.servlet.http.HttpSession;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
@ -23,10 +24,10 @@ import org.gcube.portlets.widgets.workspaceuploader.shared.ContactModel;
* *
*/ */
public class NotificationsWorkspaceUploader { public class NotificationsWorkspaceUploader {
protected static Logger logger = Logger.getLogger(NotificationsWorkspaceUploader.class); protected static Logger logger = Logger.getLogger(NotificationsWorkspaceUploader.class);
/** /**
* Send a notification if an item is added or updated to sharing folder * Send a notification if an item is added or updated to sharing folder
* @param httpSession * @param httpSession
@ -34,101 +35,101 @@ public class NotificationsWorkspaceUploader {
* @param sourceSharedId * @param sourceSharedId
* @param folderDestinationItem * @param folderDestinationItem
*/ */
public static void checkSendNotifyChangedItemToShare(HttpSession httpSession, final WorkspaceItem sourceItem, final String sourceSharedId, final WorkspaceItem folderDestinationItem, boolean isOverwrite) { public static void checkSendNotifyChangedItemToShare(HttpServletRequest request, HttpSession httpSession, final WorkspaceItem sourceItem, final String sourceSharedId, final WorkspaceItem folderDestinationItem, boolean isOverwrite) {
logger.trace("checkSendNotifyAddItemToShare"); logger.trace("checkSendNotifyAddItemToShare");
if(folderDestinationItem!=null){ if(folderDestinationItem!=null){
try{ try{
if(folderDestinationItem.isShared()){ //Notify Added Item To Sharing? if(folderDestinationItem.isShared()){ //Notify Added Item To Sharing?
logger.trace("checkNotifyAddItemToShare source item: "+sourceItem.getName()+" sourceSharedId: "+sourceSharedId + " folder destination: "+folderDestinationItem.getName() + " folder destination shared folder id: "+folderDestinationItem.getIdSharedFolder()); logger.trace("checkNotifyAddItemToShare source item: "+sourceItem.getName()+" sourceSharedId: "+sourceSharedId + " folder destination: "+folderDestinationItem.getName() + " folder destination shared folder id: "+folderDestinationItem.getIdSharedFolder());
//share condition is true if source shared folder is not null //share condition is true if source shared folder is not null
boolean shareChangeCondition = sourceSharedId==null?false:true; boolean shareChangeCondition = sourceSharedId==null?false:true;
//System.out.println("shareChangeCondition add item: "+ shareChangeCondition); //System.out.println("shareChangeCondition add item: "+ shareChangeCondition);
logger.trace("shareChangeCondition add item: "+shareChangeCondition); logger.trace("shareChangeCondition add item: "+shareChangeCondition);
//if shareChangeCondition is true.. notifies added item to sharing //if shareChangeCondition is true.. notifies added item to sharing
if(shareChangeCondition){ if(shareChangeCondition){
Workspace workspace = WsUtil.getWorkspace(httpSession); Workspace workspace = WsUtil.getWorkspace(httpSession);
List<ContactModel> listContacts = getListUserSharedByFolderSharedId(workspace, folderDestinationItem.getIdSharedFolder()); List<ContactModel> listContacts = getListUserSharedByFolderSharedId(workspace, folderDestinationItem.getIdSharedFolder());
WorkspaceItem destinationSharedFolder = workspace.getItem(folderDestinationItem.getIdSharedFolder()); WorkspaceItem destinationSharedFolder = workspace.getItem(folderDestinationItem.getIdSharedFolder());
NotificationsWorkspaceUploaderProducer np = new NotificationsWorkspaceUploaderProducer(WsUtil.getAslSession(httpSession)); NotificationsWorkspaceUploaderProducer np = new NotificationsWorkspaceUploaderProducer(WsUtil.getAslSession(httpSession),request);
if(destinationSharedFolder instanceof WorkspaceSharedFolder){ if(destinationSharedFolder instanceof WorkspaceSharedFolder){
//SWITCH BEETWEEN ADDED OR UPDATED //SWITCH BEETWEEN ADDED OR UPDATED
if(!isOverwrite) if(!isOverwrite)
np.notifyAddedItemToSharing(listContacts, sourceItem, (WorkspaceSharedFolder) destinationSharedFolder); np.notifyAddedItemToSharing(listContacts, sourceItem, (WorkspaceSharedFolder) destinationSharedFolder);
else else
np.notifyUpdatedItemToSharing(listContacts, sourceItem, (WorkspaceSharedFolder) destinationSharedFolder); np.notifyUpdatedItemToSharing(listContacts, sourceItem, (WorkspaceSharedFolder) destinationSharedFolder);
logger.trace("The notifies was sent correctly"); logger.trace("The notifies was sent correctly");
}else }else
logger.trace("The notifies doesn't sent because "+destinationSharedFolder+ " is not instance of WorkspaceSharedFolder"); logger.trace("The notifies doesn't sent because "+destinationSharedFolder+ " is not instance of WorkspaceSharedFolder");
// np.notifyAddedItemToSharing(listContacts, (WorkspaceFolder) folderDestinationItem); // np.notifyAddedItemToSharing(listContacts, (WorkspaceFolder) folderDestinationItem);
} }
} }
else else
logger.trace("folder destination is not shared"); logger.trace("folder destination is not shared");
}catch (Exception e) { }catch (Exception e) {
logger.error("An error occurred in checkSendNotifyAddItemToShare ",e); logger.error("An error occurred in checkSendNotifyAddItemToShare ",e);
} }
}else }else
logger.warn("The notifies is failure in checkSendNotifyAddItemToShare because folder destination item is null"); logger.warn("The notifies is failure in checkSendNotifyAddItemToShare because folder destination item is null");
} }
/** /**
* *
* @param workspace * @param workspace
* @param idSharedFolder * @param idSharedFolder
* @return * @return
* @throws Exception * @throws Exception
*/ */
public static List<ContactModel> getListUserSharedByFolderSharedId(Workspace workspace, String idSharedFolder) throws Exception { public static List<ContactModel> getListUserSharedByFolderSharedId(Workspace workspace, String idSharedFolder) throws Exception {
logger.trace("getListUserSharedByFolderSharedId "+ idSharedFolder); logger.trace("getListUserSharedByFolderSharedId "+ idSharedFolder);
try { try {
WorkspaceItem wsItem = workspace.getItem(idSharedFolder); WorkspaceItem wsItem = workspace.getItem(idSharedFolder);
if(isASharedFolder(wsItem)){ if(isASharedFolder(wsItem)){
WorkspaceSharedFolder wsFolder = (WorkspaceSharedFolder) wsItem; WorkspaceSharedFolder wsFolder = (WorkspaceSharedFolder) wsItem;
List<String> listPortalLogin = wsFolder.getUsers(); List<String> listPortalLogin = wsFolder.getUsers();
ArrayList<ContactModel> users = new ArrayList<ContactModel>(listPortalLogin.size()); ArrayList<ContactModel> users = new ArrayList<ContactModel>(listPortalLogin.size());
for (String login : listPortalLogin) { for (String login : listPortalLogin) {
users.add(new ContactModel(login, login, false, UserUtil.getUserFullName(login))); users.add(new ContactModel(login, login, false, UserUtil.getUserFullName(login)));
} }
return users; return users;
} }
else{ else{
logger.info("the item with id: "+idSharedFolder+ " is not "+WorkspaceItemType.SHARED_FOLDER); logger.info("the item with id: "+idSharedFolder+ " is not "+WorkspaceItemType.SHARED_FOLDER);
} }
return new ArrayList<ContactModel>(); return new ArrayList<ContactModel>();
} catch (Exception e) { } catch (Exception e) {
logger.error("Error in getListUserSharedByItemId ", e); logger.error("Error in getListUserSharedByItemId ", e);
throw new Exception(e.getMessage()); throw new Exception(e.getMessage());
} }
} }
/** /**
* *
* @param wsItem * @param wsItem
* @return * @return
*/ */
@ -137,51 +138,51 @@ public class NotificationsWorkspaceUploader {
return wsItem.getType().equals(WorkspaceItemType.SHARED_FOLDER); return wsItem.getType().equals(WorkspaceItemType.SHARED_FOLDER);
return false; return false;
} }
/** /**
* *
* @param wsItem * @param wsItem
* @return * @return
*/ */
public static boolean isASharedFolderForId(HttpSession httpSession, String itemId){ public static boolean isASharedFolderForId(HttpSession httpSession, String itemId){
if(itemId==null || itemId.isEmpty()) if(itemId==null || itemId.isEmpty())
return false; return false;
try { try {
Workspace workspace = WsUtil.getWorkspace(httpSession); Workspace workspace = WsUtil.getWorkspace(httpSession);
WorkspaceItem wsItem = workspace.getItem(itemId); WorkspaceItem wsItem = workspace.getItem(itemId);
if(wsItem!=null) if(wsItem!=null)
return wsItem.getType().equals(WorkspaceItemType.SHARED_FOLDER); return wsItem.getType().equals(WorkspaceItemType.SHARED_FOLDER);
return false; return false;
} catch (Exception e) { } catch (Exception e) {
logger.error("An errror occurred in isASharedFolderForId", e); logger.error("An errror occurred in isASharedFolderForId", e);
return false; return false;
} }
} }
/** /**
* *
* @param itemId * @param itemId
* @param rootFolderSharedId * @param rootFolderSharedId
* @return * @return
*/ */
public static boolean checkIsRootFolderShared(String itemId, String rootFolderSharedId) { public static boolean checkIsRootFolderShared(String itemId, String rootFolderSharedId) {
logger.trace("checkIsRootFolderShared between [itemid: "+itemId +", rootFolderSharedId: "+rootFolderSharedId+"]"); logger.trace("checkIsRootFolderShared between [itemid: "+itemId +", rootFolderSharedId: "+rootFolderSharedId+"]");
if(itemId==null) if(itemId==null)
return false; return false;
if(rootFolderSharedId==null) if(rootFolderSharedId==null)
return false; return false;
if(itemId.compareTo(rootFolderSharedId)==0) if(itemId.compareTo(rootFolderSharedId)==0)
return true; return true;
return false; return false;
} }
} }

View File

@ -1,10 +1,12 @@
/** /**
* *
*/ */
package org.gcube.portlets.widgets.workspaceuploader.server.notification; package org.gcube.portlets.widgets.workspaceuploader.server.notification;
import java.util.List; import java.util.List;
import javax.servlet.http.HttpServletRequest;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.gcube.application.framework.core.session.ASLSession; import org.gcube.application.framework.core.session.ASLSession;
import org.gcube.applicationsupportlayer.social.NotificationsManager; import org.gcube.applicationsupportlayer.social.NotificationsManager;
@ -24,9 +26,9 @@ import org.gcube.portlets.widgets.workspaceuploader.shared.ContactModel;
public class NotificationsWorkspaceUploaderProducer { public class NotificationsWorkspaceUploaderProducer {
protected ScopeBean scope; protected ScopeBean scope;
protected static Logger logger = Logger.getLogger(NotificationsWorkspaceUploaderProducer.class); protected static Logger logger = Logger.getLogger(NotificationsWorkspaceUploaderProducer.class);
protected NotificationsManager notificationsMng; protected NotificationsManager notificationsMng;
protected ASLSession aslSession; protected ASLSession aslSession;
protected String userId; protected String userId;
@ -35,9 +37,10 @@ public class NotificationsWorkspaceUploaderProducer {
* Instantiates a new notifications producer. * Instantiates a new notifications producer.
* *
* @param aslSession the asl session * @param aslSession the asl session
* @param request the request
*/ */
public NotificationsWorkspaceUploaderProducer(ASLSession aslSession) { public NotificationsWorkspaceUploaderProducer(ASLSession aslSession, HttpServletRequest request) {
this.notificationsMng = WsUtil.getNotificationManager(aslSession); this.notificationsMng = WsUtil.getNotificationManager(aslSession, request);
this.aslSession = aslSession; this.aslSession = aslSession;
this.userId = aslSession.getUsername(); this.userId = aslSession.getUsername();
} }
@ -68,8 +71,8 @@ public class NotificationsWorkspaceUploaderProducer {
public ASLSession getAslSession() { public ASLSession getAslSession() {
return aslSession; return aslSession;
} }
/** /**
* Runs a new thread to notify the contacts passed in input. * Runs a new thread to notify the contacts passed in input.
* *
@ -82,19 +85,19 @@ public class NotificationsWorkspaceUploaderProducer {
new Thread() { new Thread() {
@Override @Override
public void run() { public void run() {
// printContacts(listContacts); // printContacts(listContacts);
logger.info("Send notifies added item in sharedfolder is running..."); logger.info("Send notifies added item in sharedfolder is running...");
//DEBUG //DEBUG
System.out.println("Send notifies added item in sharedfolder is running..."); System.out.println("Send notifies added item in sharedfolder is running...");
for (ContactModel infoContactModel : listContacts) { for (ContactModel infoContactModel : listContacts) {
try{ try{
//NOTIFIES ONLY THE USERS THAT ARE DIFFERENT FROM CURRENT USER //NOTIFIES ONLY THE USERS THAT ARE DIFFERENT FROM CURRENT USER
if(infoContactModel.getLogin().compareTo(userId)!=0){ if(infoContactModel.getLogin().compareTo(userId)!=0){
logger.info("Sending notification to user "+infoContactModel.getLogin() +" added item "+workspaceItem.getName()+" in shared folder "+sharedFolder.getName()); logger.info("Sending notification to user "+infoContactModel.getLogin() +" added item "+workspaceItem.getName()+" in shared folder "+sharedFolder.getName());
boolean notify = notificationsMng.notifyAddedItem(infoContactModel.getLogin(), workspaceItem, sharedFolder); boolean notify = notificationsMng.notifyAddedItem(infoContactModel.getLogin(), workspaceItem, sharedFolder);
@ -106,14 +109,14 @@ public class NotificationsWorkspaceUploaderProducer {
logger.error("An error occured in notifyAddedItemToSharing ", e); logger.error("An error occured in notifyAddedItemToSharing ", e);
} }
} }
logger.trace("notifies of added item in shared folder is completed"); logger.trace("notifies of added item in shared folder is completed");
} }
}.start(); }.start();
} }
/** /**
* Runs a new thread to notify the contacts passed in input. * Runs a new thread to notify the contacts passed in input.
* *
@ -126,16 +129,16 @@ public class NotificationsWorkspaceUploaderProducer {
new Thread() { new Thread() {
@Override @Override
public void run() { public void run() {
// printContacts(listContacts); // printContacts(listContacts);
logger.info("Send notifies updated item in shared folder is running..."); logger.info("Send notifies updated item in shared folder is running...");
for (ContactModel infoContactModel : listContacts) { for (ContactModel infoContactModel : listContacts) {
try{ try{
//NOTIFIES ONLY THE USERS THAT ARE DIFFERENT FROM CURRENT USER //NOTIFIES ONLY THE USERS THAT ARE DIFFERENT FROM CURRENT USER
if(infoContactModel.getLogin().compareTo(userId)!=0){ if(infoContactModel.getLogin().compareTo(userId)!=0){
logger.info("Sending notification to user "+infoContactModel.getLogin() +" updated item "+workspaceItem.getName()+" in shared folder "+sharedFolder.getName()); logger.info("Sending notification to user "+infoContactModel.getLogin() +" updated item "+workspaceItem.getName()+" in shared folder "+sharedFolder.getName());
boolean notify = notificationsMng.notifyUpdatedItem(infoContactModel.getLogin(), workspaceItem, sharedFolder); boolean notify = notificationsMng.notifyUpdatedItem(infoContactModel.getLogin(), workspaceItem, sharedFolder);
@ -148,11 +151,11 @@ public class NotificationsWorkspaceUploaderProducer {
e.printStackTrace(); e.printStackTrace();
} }
} }
logger.trace("notifies of updated item in shared folder is completed"); logger.trace("notifies of updated item in shared folder is completed");
} }
}.start(); }.start();
} }
} }

View File

@ -6,6 +6,7 @@ package org.gcube.portlets.widgets.workspaceuploader.server.upload;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession; import javax.servlet.http.HttpSession;
import org.gcube.common.homelibrary.home.exceptions.InternalErrorException; import org.gcube.common.homelibrary.home.exceptions.InternalErrorException;
@ -49,6 +50,7 @@ public class WorkspaceUploaderMng {
/** /**
* Creates the workspace uploader file. * Creates the workspace uploader file.
* *
* @param request the request
* @param workspaceUploader the workspace uploader * @param workspaceUploader the workspace uploader
* @param httpSession the http session * @param httpSession the http session
* @param isOvewrite the is ovewrite * @param isOvewrite the is ovewrite
@ -62,7 +64,7 @@ public class WorkspaceUploaderMng {
* @throws InternalErrorException the internal error exception * @throws InternalErrorException the internal error exception
* @throws IOException Signals that an I/O exception has occurred. * @throws IOException Signals that an I/O exception has occurred.
*/ */
private static WorkspaceUploaderItem createWorkspaceUploaderFile(final WorkspaceUploaderItem workspaceUploader, final HttpSession httpSession, final boolean isOvewrite, final Workspace wa, final InputStream uploadFile, final String itemName, final WorkspaceFolder destinationFolder, final String contentType, final long totalBytes) throws InternalErrorException, IOException{ private static WorkspaceUploaderItem createWorkspaceUploaderFile(HttpServletRequest request, final WorkspaceUploaderItem workspaceUploader, final HttpSession httpSession, final boolean isOvewrite, final Workspace wa, final InputStream uploadFile, final String itemName, final WorkspaceFolder destinationFolder, final String contentType, final long totalBytes) throws InternalErrorException, IOException{
logger.debug("Creating WorkspaceUploaderFile..."); logger.debug("Creating WorkspaceUploaderFile...");
workspaceUploader.setUploadStatus(UPLOAD_STATUS.IN_PROGRESS); workspaceUploader.setUploadStatus(UPLOAD_STATUS.IN_PROGRESS);
@ -86,7 +88,7 @@ public class WorkspaceUploaderMng {
workspaceUploader.getFile().setParentId(createdItem.getParent().getId());//SET PARENT ID workspaceUploader.getFile().setParentId(createdItem.getParent().getId());//SET PARENT ID
workspaceUploader.setStatusDescription("File \""+createdItem.getName()+"\" uploaded correctly in "+destinationFolder.getPath()); workspaceUploader.setStatusDescription("File \""+createdItem.getName()+"\" uploaded correctly in "+destinationFolder.getPath());
workspaceUploader.setUploadStatus(UPLOAD_STATUS.COMPLETED); workspaceUploader.setUploadStatus(UPLOAD_STATUS.COMPLETED);
WorkspaceUploadServletStream.notifyUploadInSharedFolder(httpSession, wa, createdItem.getId(), createdItem.getParent().getId(), isOvewrite); WorkspaceUploadServletStream.notifyUploadInSharedFolder(request, httpSession, wa, createdItem.getId(), createdItem.getParent().getId(), isOvewrite);
}else{ }else{
workspaceUploader.setStatusDescription("An error occurred during upload: \""+itemName + "\". Try again"); workspaceUploader.setStatusDescription("An error occurred during upload: \""+itemName + "\". Try again");
workspaceUploader.setUploadStatus(UPLOAD_STATUS.FAILED); workspaceUploader.setUploadStatus(UPLOAD_STATUS.FAILED);
@ -205,6 +207,7 @@ public class WorkspaceUploaderMng {
/** /**
* Upload file. * Upload file.
* *
* @param request the request
* @param workspaceUploader the workspace uploader * @param workspaceUploader the workspace uploader
* @param httpSession the http session * @param httpSession the http session
* @param wa the wa * @param wa the wa
@ -217,10 +220,10 @@ public class WorkspaceUploaderMng {
* @return the workspace uploader item * @return the workspace uploader item
* @throws Exception the exception * @throws Exception the exception
*/ */
public static WorkspaceUploaderItem uploadFile(WorkspaceUploaderItem workspaceUploader, HttpSession httpSession, Workspace wa, String itemName, InputStream file, WorkspaceFolder destinationFolder, String contentType, boolean isOverwrite, long totolaBytes) throws Exception { public static WorkspaceUploaderItem uploadFile(HttpServletRequest request, WorkspaceUploaderItem workspaceUploader, HttpSession httpSession, Workspace wa, String itemName, InputStream file, WorkspaceFolder destinationFolder, String contentType, boolean isOverwrite, long totolaBytes) throws Exception {
try { try {
return createWorkspaceUploaderFile(workspaceUploader, httpSession, isOverwrite, wa, file, itemName, destinationFolder, contentType, totolaBytes); return createWorkspaceUploaderFile(request, workspaceUploader, httpSession, isOverwrite, wa, file, itemName, destinationFolder, contentType, totolaBytes);
} catch (Exception e) { } catch (Exception e) {
logger.error("Error when uploading file to HL : ",e); logger.error("Error when uploading file to HL : ",e);
throw new Exception("An error occurred during upload: "+itemName+". Try again"); throw new Exception("An error occurred during upload: "+itemName+". Try again");

View File

@ -6,11 +6,10 @@ import java.util.List;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.gcube.portlets.widgets.workspaceuploader.shared.ContactModel; import org.gcube.portlets.widgets.workspaceuploader.shared.ContactModel;
import org.gcube.vomanagement.usermanagement.UserManager; import org.gcube.vomanagement.usermanagement.UserManager;
import org.gcube.vomanagement.usermanagement.exception.UserManagementPortalException;
import org.gcube.vomanagement.usermanagement.exception.UserManagementSystemException; import org.gcube.vomanagement.usermanagement.exception.UserManagementSystemException;
import org.gcube.vomanagement.usermanagement.exception.UserRetrievalFault; import org.gcube.vomanagement.usermanagement.exception.UserRetrievalFault;
import org.gcube.vomanagement.usermanagement.impl.liferay.LiferayUserManager; import org.gcube.vomanagement.usermanagement.impl.LiferayUserManager;
import org.gcube.vomanagement.usermanagement.model.UserModel; import org.gcube.vomanagement.usermanagement.model.GCubeUser;
@ -21,11 +20,11 @@ import org.gcube.vomanagement.usermanagement.model.UserModel;
* Aug 3, 2015 * Aug 3, 2015
*/ */
public class UserUtil { public class UserUtil {
static UserManager um = new LiferayUserManager(); static UserManager um = new LiferayUserManager();
protected static Logger logger = Logger.getLogger(UserUtil.class); protected static Logger logger = Logger.getLogger(UserUtil.class);
/** /**
* Gets the user full name. * Gets the user full name.
* *
@ -35,46 +34,44 @@ public class UserUtil {
public static String getUserFullName(String portalLogin){ public static String getUserFullName(String portalLogin){
if(portalLogin==null) if(portalLogin==null)
return ""; return "";
if (WsUtil.isWithinPortal()) { //INTO PORTAL if (WsUtil.isWithinPortal()) { //INTO PORTAL
UserModel curr = null; GCubeUser curr = null;
try { try {
try { try {
curr = um.getUserByScreenName(portalLogin); curr = um.getUserByUsername(portalLogin);
} catch (UserManagementSystemException e) { } catch (UserManagementSystemException e) {
logger.error("An error occurred in getUserFullName "+e,e); logger.error("An error occurred in getUserByUsername "+e,e);
} catch (UserRetrievalFault e) { } catch (UserRetrievalFault e) {
logger.error("An error occurred in getUserFullName "+e,e); logger.error("An error occurred in getUserByUsername "+e,e);
} }
} catch (UserManagementPortalException ume) {
logger.error("An error occurred in getUserFullName "+ume,ume);
}catch (Exception e) { }catch (Exception e) {
logger.error("An error occurred in getUserFullName "+e,e); logger.error("An error occurred in getUserByUsername "+e,e);
logger.warn("Return portal login "+portalLogin); logger.warn("Return portal login "+portalLogin);
return portalLogin; return portalLogin;
} }
if (curr != null){ if (curr != null){
// logger.trace("Return "+curr.getFullname() +" full name for: "+portalLogin); // logger.trace("Return "+curr.getFullname() +" full name for: "+portalLogin);
return curr.getFullname(); return curr.getFullname();
} }
}else{ }else{
logger.trace("DEVELOPEMENT MODE ON"); logger.trace("DEVELOPEMENT MODE ON");
logger.trace("Returning "+WsUtil.TEST_USER_FULL_NAME +" full name for: "+portalLogin); logger.trace("Returning "+WsUtil.TEST_USER_FULL_NAME +" full name for: "+portalLogin);
return WsUtil.TEST_USER_FULL_NAME; return WsUtil.TEST_USER_FULL_NAME;
} }
logger.trace("Return portal login as full name for: "+portalLogin); logger.trace("Return portal login as full name for: "+portalLogin);
return portalLogin; return portalLogin;
} }
/** /**
* Gets the list login by info contact model. * Gets the list login by info contact model.
* *
@ -82,16 +79,16 @@ public class UserUtil {
* @return the list login by info contact model * @return the list login by info contact model
*/ */
public static List<String> getListLoginByInfoContactModel(List<ContactModel> listContacts){ public static List<String> getListLoginByInfoContactModel(List<ContactModel> listContacts){
List<String> listUsers = new ArrayList<String>(); List<String> listUsers = new ArrayList<String>();
for (ContactModel infoContactModel : listContacts) { for (ContactModel infoContactModel : listContacts) {
listUsers.add(infoContactModel.getLogin()); listUsers.add(infoContactModel.getLogin());
} }
return listUsers; return listUsers;
} }
/** /**
* Separate users names to comma. * Separate users names to comma.
* *
@ -99,20 +96,20 @@ public class UserUtil {
* @return the string * @return the string
*/ */
public static String separateUsersNamesToComma(List<ContactModel> listContacts){ public static String separateUsersNamesToComma(List<ContactModel> listContacts){
String users = ""; String users = "";
for (int i = 0; i < listContacts.size()-1; i++) { for (int i = 0; i < listContacts.size()-1; i++) {
users+= listContacts.get(i).getFullName() + ", "; users+= listContacts.get(i).getFullName() + ", ";
} }
if(listContacts.size()>1) if(listContacts.size()>1)
users += listContacts.get(listContacts.size()-1).getFullName(); users += listContacts.get(listContacts.size()-1).getFullName();
return users; return users;
} }
/** /**
* Separate full name to comma for portal login. * Separate full name to comma for portal login.
* *
@ -120,25 +117,25 @@ public class UserUtil {
* @return the string * @return the string
*/ */
public static String separateFullNameToCommaForPortalLogin(List<String> listLogin){ public static String separateFullNameToCommaForPortalLogin(List<String> listLogin){
String users = ""; String users = "";
logger.trace("SeparateFullNameToCommaForPortalLogin converting: "+listLogin); logger.trace("SeparateFullNameToCommaForPortalLogin converting: "+listLogin);
//N-1 MEMBERS //N-1 MEMBERS
for (int i = 0; i < listLogin.size()-1; i++) { for (int i = 0; i < listLogin.size()-1; i++) {
// logger.trace("Converting: "+i+") "+listLogin.get(i)); // logger.trace("Converting: "+i+") "+listLogin.get(i));
users+= getUserFullName(listLogin.get(i)) + ", "; users+= getUserFullName(listLogin.get(i)) + ", ";
} }
//LAST MEMBER //LAST MEMBER
if(listLogin.size()>=1){ if(listLogin.size()>=1){
// logger.trace("Converting: "+(listLogin.size()-1)+") " +listLogin.get(listLogin.size()-1)); // logger.trace("Converting: "+(listLogin.size()-1)+") " +listLogin.get(listLogin.size()-1));
users += getUserFullName(listLogin.get(listLogin.size()-1)); users += getUserFullName(listLogin.get(listLogin.size()-1));
} }
logger.trace("SeparateFullNameToCommaForPortalLogin returning: "+users); logger.trace("SeparateFullNameToCommaForPortalLogin returning: "+users);
return users; return users;
} }
} }

View File

@ -3,6 +3,7 @@
*/ */
package org.gcube.portlets.widgets.workspaceuploader.server.util; package org.gcube.portlets.widgets.workspaceuploader.server.util;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession; import javax.servlet.http.HttpSession;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
@ -10,6 +11,7 @@ import org.gcube.application.framework.core.session.ASLSession;
import org.gcube.application.framework.core.session.SessionManager; import org.gcube.application.framework.core.session.SessionManager;
import org.gcube.applicationsupportlayer.social.ApplicationNotificationsManager; import org.gcube.applicationsupportlayer.social.ApplicationNotificationsManager;
import org.gcube.applicationsupportlayer.social.NotificationsManager; import org.gcube.applicationsupportlayer.social.NotificationsManager;
import org.gcube.applicationsupportlayer.social.shared.SocialNetworkingSite;
import org.gcube.common.homelibrary.home.HomeLibrary; import org.gcube.common.homelibrary.home.HomeLibrary;
import org.gcube.common.homelibrary.home.exceptions.HomeNotFoundException; import org.gcube.common.homelibrary.home.exceptions.HomeNotFoundException;
import org.gcube.common.homelibrary.home.exceptions.InternalErrorException; import org.gcube.common.homelibrary.home.exceptions.InternalErrorException;
@ -162,9 +164,10 @@ public class WsUtil {
* Gets the notification manager. * Gets the notification manager.
* *
* @param session the session * @param session the session
* @param request the request
* @return the notification manager * @return the notification manager
*/ */
public static NotificationsManager getNotificationManager(ASLSession session) public static NotificationsManager getNotificationManager(ASLSession session, HttpServletRequest request)
{ {
NotificationsManager notifMng = (NotificationsManager) session.getAttribute(NOTIFICATION_MANAGER); NotificationsManager notifMng = (NotificationsManager) session.getAttribute(NOTIFICATION_MANAGER);
@ -173,7 +176,8 @@ public class WsUtil {
try{ try{
logger.trace("Create new NotificationsManager for user: "+session.getUsername()); logger.trace("Create new NotificationsManager for user: "+session.getUsername());
logger.trace("New ApplicationNotificationsManager with portlet class name: "+NOTIFICATION_PORTLET_CLASS_ID); logger.trace("New ApplicationNotificationsManager with portlet class name: "+NOTIFICATION_PORTLET_CLASS_ID);
notifMng = new ApplicationNotificationsManager(session, NOTIFICATION_PORTLET_CLASS_ID); SocialNetworkingSite site = new SocialNetworkingSite(request);
notifMng = new ApplicationNotificationsManager(site, session.getScope(), null, NOTIFICATION_PORTLET_CLASS_ID);
session.setAttribute(NOTIFICATION_MANAGER, notifMng); session.setAttribute(NOTIFICATION_MANAGER, notifMng);
}catch (Exception e) { }catch (Exception e) {
logger.error("An error occurred instancing ApplicationNotificationsManager for user: "+session.getUsername(),e); logger.error("An error occurred instancing ApplicationNotificationsManager for user: "+session.getUsername(),e);
@ -187,16 +191,17 @@ public class WsUtil {
* Gets the notification producer. * Gets the notification producer.
* *
* @param session the session * @param session the session
* @param request the request
* @return the notification producer * @return the notification producer
*/ */
public static NotificationsWorkspaceUploaderProducer getNotificationProducer(ASLSession session) public static NotificationsWorkspaceUploaderProducer getNotificationProducer(ASLSession session, HttpServletRequest request)
{ {
NotificationsWorkspaceUploaderProducer notifProducer = (NotificationsWorkspaceUploaderProducer) session.getAttribute(NOTIFICATION_PRODUCER); NotificationsWorkspaceUploaderProducer notifProducer = (NotificationsWorkspaceUploaderProducer) session.getAttribute(NOTIFICATION_PRODUCER);
if (notifProducer == null) { if (notifProducer == null) {
logger.trace("Create new Notification Producer for user: "+session.getUsername()); logger.trace("Create new Notification Producer for user: "+session.getUsername());
notifProducer = new NotificationsWorkspaceUploaderProducer(session); notifProducer = new NotificationsWorkspaceUploaderProducer(session, request);
session.setAttribute(NOTIFICATION_PRODUCER, notifProducer); session.setAttribute(NOTIFICATION_PRODUCER, notifProducer);
} }