Migrated to Liferay 6.2

Updated pom version at 6.13.0
Removed LocalUploadServlet
Removed UploadServlet

git-svn-id: http://svn.d4science-ii.research-infrastructures.eu/gcube/trunk/portlets/user/workspace-tree-widget@128930 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Francesco Mangiacrapa 2016-05-31 15:11:53 +00:00
parent f15531fba3
commit 1a447cacb4
12 changed files with 201 additions and 1131 deletions

View File

@ -1,4 +1,8 @@
<ReleaseNotes>
<Changeset component="org.gcube.portlets-user.workspace-portlet-tree.6-13-0"
date="2016-05-31">
<Change>[Feature #4128] Migration to Liferay 6.2</Change>
</Changeset>
<Changeset component="org.gcube.portlets-user.workspace-portlet-tree.6-12-0"
date="2016-05-16">
<Change>Integrated with new workspace uploader</Change>

13
pom.xml
View File

@ -10,7 +10,7 @@
<groupId>org.gcube.portlets.user</groupId>
<artifactId>workspace-tree-widget</artifactId>
<version>6.12.0-SNAPSHOT</version>
<version>6.13.0-SNAPSHOT</version>
<name>gCube Workspace Tree Widget</name>
<description>
gCube Workspace Tree Widget is a widget to navigate and interact with gCube Workspace
@ -37,7 +37,7 @@
<dependency>
<groupId>org.gcube.distribution</groupId>
<artifactId>maven-portal-bom</artifactId>
<version>2.6.0-SNAPSHOT</version>
<version>LATEST</version>
<type>pom</type>
<scope>import</scope>
</dependency>
@ -62,14 +62,6 @@
<scope>provided</scope>
</dependency>
<!-- <dependency> -->
<!-- <groupId>com.google.web.bindery</groupId> -->
<!-- <artifactId>requestfactory-server</artifactId> -->
<!-- <version>${gwtVersion}</version> -->
<!-- <scope>runtime</scope> -->
<!-- </dependency> -->
<!-- Google Web Toolkit (GWT) -->
<dependency>
<groupId>com.google.gwt</groupId>
@ -213,7 +205,6 @@
<dependency>
<groupId>com.liferay.portal</groupId>
<artifactId>portal-service</artifactId>
<version>6.0.6</version>
<scope>provided</scope>
</dependency>
<dependency>

View File

@ -274,12 +274,12 @@ public class AppControllerExplorer implements EventHandler, TreeAppControllerInt
//IF NOT CANCELLED
String clickedButton = be.getButtonClicked().getItemId();
if(clickedButton.equals(Dialog.YES)){
explorerPanel.getAsycTreePanel().mask(ConstantsExplorer.UNSHARING,ConstantsExplorer.LOADINGSTYLE);
rpcWorkspaceService.unSharedFolderByFolderSharedId(folderIdentification, new AsyncCallback<Boolean>() {
@Override
public void onFailure(Throwable caught) {
explorerPanel.getAsycTreePanel().unmask();
if(caught instanceof SessionExpiredException){
GWT.log("Session expired");
eventBus.fireEvent(new SessionExpiredEvent());
@ -292,6 +292,7 @@ public class AppControllerExplorer implements EventHandler, TreeAppControllerInt
@Override
public void onSuccess(Boolean result) {
explorerPanel.getAsycTreePanel().unmask();
if(result) //REFRESH PARENT FOLDER
eventBus.fireEvent(new RefreshFolderEvent(source.getParentFileModel(), true, false, false));

View File

@ -87,6 +87,7 @@ public class ConstantsExplorer {
public static final String TITLEACCESSWEBDAV = "Access from Desktop";
public static final String ACCESSWEBDAVMSG = "Files and folders can be managed directly from the file explorer of your desktop operating system.";
public static final String MOVING = "Moving...";
protected static final String UNSHARING = "Unsharing...";
public static final String FILEUPLOADHEADER = "File upload in: ";
// public static final String FILE = "File";
@ -224,4 +225,5 @@ public class ConstantsExplorer {
public static final String MY_SPECIAL_FOLDERS = "MySpecialFolders";
}

View File

@ -83,7 +83,7 @@ import org.gcube.portlets.user.workspace.shared.WorkspaceACL;
import org.gcube.portlets.user.workspace.shared.WorkspaceACL.USER_TYPE;
import org.gcube.portlets.user.workspace.shared.accounting.GxtAccountingEntryType;
import org.gcube.portlets.user.workspace.shared.accounting.GxtAccountingField;
import org.gcube.vomanagement.usermanagement.model.UserModel;
import org.gcube.vomanagement.usermanagement.model.GCubeUser;
import com.thoughtworks.xstream.XStream;
@ -1459,7 +1459,7 @@ public class GWTWorkspaceBuilder {
* @return the list
* @throws InternalErrorException the internal error exception
*/
public List<InfoContactModel> buildGXTListContactsModelFromUserModel(List<UserModel> listUsers) throws InternalErrorException {
public List<InfoContactModel> buildGXTListContactsModelFromUserModel(List<GCubeUser> listUsers) throws InternalErrorException {
List<InfoContactModel> listContactsModel = new ArrayList<InfoContactModel>();
@ -1469,7 +1469,7 @@ public class GWTWorkspaceBuilder {
logger.trace("List<UserModel> size returned from Portal VO is: "+ listUsers.size());
logger.trace("Building list contact model list user model");
for (UserModel userModel : listUsers) {
for (GCubeUser userModel : listUsers) {
String fullName = userModel.getFullname();
if(fullName!=null && !fullName.isEmpty())

View File

@ -40,7 +40,6 @@ import org.gcube.common.homelibrary.home.workspace.search.SearchItem;
import org.gcube.common.homelibrary.home.workspace.trash.WorkspaceTrashFolder;
import org.gcube.common.homelibrary.home.workspace.trash.WorkspaceTrashItem;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.portal.custom.communitymanager.OrganizationsUtil;
import org.gcube.portlets.user.workspace.client.ConstantsExplorer;
import org.gcube.portlets.user.workspace.client.interfaces.GXTCategoryItemInterface;
import org.gcube.portlets.user.workspace.client.model.FileDetailsModel;
@ -81,12 +80,13 @@ import org.gcube.portlets.user.workspace.shared.accounting.GxtAccountingField;
import org.gcube.portlets.user.workspaceapplicationhandler.ApplicationReaderFromGenericResource;
import org.gcube.vomanagement.usermanagement.GroupManager;
import org.gcube.vomanagement.usermanagement.UserManager;
import org.gcube.vomanagement.usermanagement.impl.liferay.LiferayGroupManager;
import org.gcube.vomanagement.usermanagement.impl.liferay.LiferayUserManager;
import org.gcube.vomanagement.usermanagement.exception.UserManagementSystemException;
import org.gcube.vomanagement.usermanagement.exception.UserRetrievalFault;
import org.gcube.vomanagement.usermanagement.impl.LiferayGroupManager;
import org.gcube.vomanagement.usermanagement.impl.LiferayUserManager;
import org.gcube.vomanagement.usermanagement.model.GCubeUser;
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
import com.liferay.portal.kernel.exception.PortalException;
import com.liferay.portal.kernel.exception.SystemException;
import com.liferay.portal.service.UserLocalServiceUtil;
@ -134,7 +134,7 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT
*/
protected NotificationsProducer getNotificationProducer(){
return WsUtil.getNotificationProducer(WsUtil.getAslSession(this.getThreadLocalRequest().getSession()));
return WsUtil.getNotificationProducer(WsUtil.getAslSession(this.getThreadLocalRequest().getSession()), this.getThreadLocalRequest());
}
/**
@ -863,7 +863,7 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT
workspace.removeItem(itemId);
//IF SOURCE SHARED FOLDER IS NOT NULL
if(sourceFolderSharedId!=null)
NotificationsUtil.checkSendNotifyRemoveItemToShare(this.getThreadLocalRequest().getSession(), sourceItemIsShared, itemName, itemId, sourceFolderSharedId);
NotificationsUtil.checkSendNotifyRemoveItemToShare(this.getThreadLocalRequest(), this.getThreadLocalRequest().getSession(), sourceItemIsShared, itemName, itemId, sourceFolderSharedId);
return Boolean.TRUE;
@ -1496,7 +1496,7 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT
UserManager userManag = new LiferayUserManager();
GroupManager gm = new LiferayGroupManager();
String groupId = gm.getRootVO().getGroupId();
long groupId = gm.getRootVO().getGroupId();
workspaceLogger.trace("Liferay User Manager getting list users by group: "+groupId);
List<InfoContactModel> listContactsModel = builder.buildGXTListContactsModelFromUserModel(userManag.listUsersByGroup(groupId));
@ -2435,7 +2435,7 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT
workspaceLogger.trace("Check notification for "+item);
//IF SOURCE SHARED FOLDER IS NOT NULL
if(item.getSourceFolderSharedId()!=null)
NotificationsUtil.checkSendNotifyRemoveItemToShare(this.getThreadLocalRequest().getSession(), item.isSourceItemIsShared(), item.getOldItemName(), item.getOldItemName(), item.getSourceFolderSharedId());
NotificationsUtil.checkSendNotifyRemoveItemToShare(this.getThreadLocalRequest(), this.getThreadLocalRequest().getSession(), item.isSourceItemIsShared(), item.getOldItemName(), item.getOldItemName(), item.getSourceFolderSharedId());
}
return frontEndError;
@ -2661,14 +2661,17 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT
if (isWithinPortal() && username.compareTo(WsUtil.TEST_USER) != 0) {
com.liferay.portal.model.UserModel user = null;
try {
user = UserLocalServiceUtil.getUserByScreenName(OrganizationsUtil.getCompany().getCompanyId(), username);
LiferayUserManager l = new LiferayUserManager();
GCubeUser user = l.getUserByUsername(username);
firstName = user.getFirstName();
lastName = user.getLastName();
email = user.getEmailAddress();
} catch (PortalException | SystemException e) {
e.printStackTrace();
email = user.getEmail();
}catch (UserManagementSystemException e) {
workspaceLogger.error("UserManagementSystemException for username: "+username);
}
catch (UserRetrievalFault e) {
workspaceLogger.error("UserRetrievalFault for username: "+username);
}
}

View File

@ -1,500 +0,0 @@
/**
*
*/
package org.gcube.portlets.user.workspace.server;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.Calendar;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.apache.commons.fileupload.FileUploadException;
import org.apache.commons.io.FilenameUtils;
import org.apache.log4j.Logger;
import org.gcube.common.homelibary.model.items.type.WorkspaceItemType;
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.InsufficientPrivilegesException;
import org.gcube.common.homelibrary.home.workspace.exceptions.ItemAlreadyExistException;
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.exceptions.WrongDestinationException;
import org.gcube.common.homelibrary.home.workspace.exceptions.WrongItemTypeException;
import org.gcube.common.homelibrary.home.workspace.folder.FolderItem;
import org.gcube.common.homelibrary.home.workspace.folder.items.Report;
import org.gcube.common.homelibrary.home.workspace.folder.items.ReportTemplate;
import org.gcube.common.homelibrary.util.Extensions;
import org.gcube.common.homelibrary.util.MimeTypeUtil;
import org.gcube.common.homelibrary.util.WorkspaceUtil;
import org.gcube.common.homelibrary.util.zip.UnzipUtil;
import org.gcube.portlets.user.workspace.client.ConstantsExplorer;
import org.gcube.portlets.user.workspace.server.notifications.NotificationsUtil;
import org.gcube.portlets.user.workspace.server.util.WsUtil;
import org.gcube.portlets.user.workspace.shared.HandlerResultMessage;
/**
*
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* @Jan 21, 2014
*
*/
public class LocalUploadServlet extends HttpServlet {
/**
*
*/
protected static final String UTF_8 = "UTF-8";
public static final String UPLOAD_TYPE = ConstantsExplorer.UPLOAD_TYPE;
public static final String ID_FOLDER = ConstantsExplorer.ID_FOLDER;
public static final String UPLOAD_FORM_ELEMENT = ConstantsExplorer.UPLOAD_FORM_ELEMENT;
public static final String IS_OVERWRITE = ConstantsExplorer.IS_OVERWRITE;
public static final String FILE = "File";
protected static Logger logger = Logger.getLogger(LocalUploadServlet.class);
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
/**
*
*/
private static final long serialVersionUID = -4197748678713054285L;
/**
* {@inheritDoc}
*/
@Override
public void init() throws ServletException {
super.init();
logger.trace("Workspace "+LocalUploadServlet.class+" ready.");
}
/**
* {@inheritDoc}
*/
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// System.out.println("GET on LocalUploadServlet");
logger.trace("GET method in LocalUploadServlet is running");
String absolutePathFile = "";
String destinationId = "";
String uploadType = "";
boolean isOverwrite = false;
try{
absolutePathFile = request.getParameter(UPLOAD_FORM_ELEMENT);
destinationId = request.getParameter(ID_FOLDER);
uploadType = request.getParameter(UPLOAD_TYPE);
isOverwrite = Boolean.parseBoolean(request.getParameter(IS_OVERWRITE));
}catch (Exception e) {
logger.error("Error processing GET parameters", e);
sendError(response, "Internal error: Error during request processing");
return;
}
uploadData(request, response, absolutePathFile, destinationId, uploadType, isOverwrite);
}
/**
* {@inheritDoc}
*/
@SuppressWarnings("rawtypes")
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
logger.trace("POST method in LocalUploadServlet is running");
String absolutePathFile = "";
String destinationId = "";
String uploadType = "";
boolean isOverwrite = false;
try{
absolutePathFile = request.getParameter(UPLOAD_FORM_ELEMENT);
destinationId = request.getParameter(ID_FOLDER);
uploadType = request.getParameter(UPLOAD_TYPE);
isOverwrite = Boolean.parseBoolean(request.getParameter(IS_OVERWRITE));
}catch (Exception e) {
logger.error("Error processing POST parameters", e);
sendError(response, "Internal error: Error during request processing");
return;
}
uploadData(request, response, absolutePathFile, destinationId, uploadType, isOverwrite);
}
private void uploadData(HttpServletRequest request, HttpServletResponse response, String absolutePathFile, String destinationId,String uploadType,boolean isOverwrite) throws ServletException, IOException{
File file = null;
InputStream fileUploadIS = null;
try {
logger.info("Upload servlet parameters: [uploadItem: "+absolutePathFile +", destinationId: "+destinationId +", uploadType: "+uploadType+", isOverwrite: "+isOverwrite+"]");
if(absolutePathFile==null || absolutePathFile.isEmpty())
throw new FileUploadException("Absolute path is null or empty");
file = new File(absolutePathFile);
fileUploadIS = openInputStream(file);
} catch (Exception e) {
logger.error("Error processing request in upload servlet", e);
sendError(response, "Internal error: Error during request processing");
return;
}
if (destinationId == null) {
logger.error("Error processing request in upload servlet: No destination folder id found");
sendError(response, "Internal error: No destination folder id found");
return;
}
logger.trace("destination folder id: "+destinationId);
logger.trace("uploadType: "+uploadType);
Workspace wa = null;
try {
wa = WsUtil.getWorkspace(request.getSession());
} catch (Exception e) {
logger.error("Error during workspace retrieving", e);
response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Error processing request in upload servlet");
return;
}
if (wa == null) {
logger.error("Now workspace found in session");
sendError(response, "Internal error: No workspace in session");
return;
}
WorkspaceItem item;
try {
item = wa.getItem(destinationId);
} catch (ItemNotFoundException e) {
logger.error("Error, no destination folder found", e);
sendError(response, "Internal error: No destination folder found");
return;
}
if (item.getType() != WorkspaceItemType.FOLDER && item.getType() != WorkspaceItemType.SHARED_FOLDER) {
logger.error("Error processing request in upload servlet: Wrong destination item");
sendError(response, "Internal error: Wrong destination item");
return;
}
WorkspaceFolder destinationFolder = (WorkspaceFolder) item;
try {
//we calculate an unique name for the current destination
String itemName = "";
if(!isOverwrite)
itemName = WorkspaceUtil.getUniqueName(file.getName(), destinationFolder);
else
itemName = file.getName();
String contentType = MimeTypeUtil.getMimeType(itemName, new BufferedInputStream(fileUploadIS));
logger.trace("Content type (mime type): "+contentType + " unique name: "+itemName);
String extension = FilenameUtils.getExtension(itemName);
logger.trace("extension: "+extension);
if(uploadType.compareTo(FILE)==0) {//IS FILE UPLOAD
boolean isZipFile = MimeTypeUtil.isZipContentType(contentType);
if(isZipFile && (extension.compareToIgnoreCase(D4ST)==0)){ //Create REPORT TEMPLATE
String newItemName = itemName;
logger.trace("createTemplate: "+newItemName);
createTemplate(request.getSession(), wa, newItemName, openInputStream(file), destinationFolder, response, isOverwrite);
}else if(isZipFile && (extension.compareToIgnoreCase(D4SR)==0)){ //Create REPORT
String newItemName = itemName;
logger.trace("createReport: "+newItemName);
createReport(request.getSession(), wa, newItemName, openInputStream(file), destinationFolder, response, isOverwrite);
}else{ //CREATE AN EXTERNAL FILE
createExternalFile(request.getSession(), wa, itemName, openInputStream(file), destinationFolder, contentType, response, isOverwrite);
}
}else {//IS ARCHIVE UPLOAD
if (MimeTypeUtil.isZipContentType(contentType)){
logger.trace("Unziping content");
UnzipUtil.unzip(destinationFolder, openInputStream(file), itemName);
//TODO NOTIFY UPLOAD ARCHIVE
sendMessage(response, "Archive "+absolutePathFile+" imported correctly in "+destinationFolder.getPath());
} else
createExternalFile(request.getSession(), wa, itemName, openInputStream(file), destinationFolder, contentType, response, isOverwrite);
}
file.delete();
} catch (InsufficientPrivilegesException e) {
logger.error("Error creating elements", e);
sendError(response, "Internal error: Insufficient privileges");
return;
} catch (InternalErrorException e) {
logger.error("Error creating elements", e);
sendError(response, "Internal error: "+e.getMessage());
return;
} catch (ItemAlreadyExistException e) {
logger.error("Error creating elements", e);
sendError(response, "Internal error: An item with that name already exists");
return;
}catch (Exception e) {
logger.error("Error creating elements", e);
sendError(response, "Internal error: An error occurred on uploading the file, try again later");
return;
}
}
/**
*
* @param file
* @return
* @throws IOException
*/
public FileInputStream openInputStream(File file) throws IOException {
if (file.exists()) {
if (file.isDirectory()) {
throw new IOException("File '" + file
+ "' exists but is a directory");
}
if (file.canRead() == false) {
throw new IOException("File '" + file + "' cannot be read");
}
} else {
throw new FileNotFoundException("File '" + file
+ "' does not exist");
}
return new FileInputStream(file);
}
/**
*
* @param httpSession
* @param workspace
* @param itemId
* @param destinationFolderId
*/
private void notifyUploadInSharedFolder(final HttpSession httpSession, final Workspace workspace, final String itemId, final String destinationFolderId, final boolean isOverwrite){
new Thread(){
public void run() {
WorkspaceItem sourceItem;
try {
sourceItem = workspace.getItem(itemId);
String sourceSharedId = sourceItem.getIdSharedFolder();
WorkspaceItem folderDestinationItem = workspace.getItem(destinationFolderId);
NotificationsUtil.checkSendNotifyChangedItemToShare(httpSession, sourceItem, sourceSharedId, folderDestinationItem,isOverwrite);
} catch (Exception e) {
logger.error("Error in notifyUploadInSharedFolder", e);
}
};
}.start();
}
private void createExternalFile(HttpSession httpSession, Workspace wa, String itemName, InputStream uploadItem, WorkspaceFolder destinationFolder, String contentType, HttpServletResponse response, boolean isOverwrite) throws InternalErrorException, InsufficientPrivilegesException, ItemAlreadyExistException, IOException {
FolderItem createdItem = null;
if(!isOverwrite){
//we need to recalculate the item name
itemName = WorkspaceUtil.getUniqueName(itemName, destinationFolder);
logger.trace("before calling createExternalFile - [itemName: "+itemName+", contentType: "+contentType+"]");
createdItem = WorkspaceUtil.createExternalFile(destinationFolder, itemName, "", contentType, uploadItem);
if(createdItem!=null)
logger.info("Item "+createdItem.getName() + " uploaded correctly");
}
else{
createdItem = overwriteItem(wa, itemName, uploadItem, destinationFolder); //CASE OVERWRITE
if(createdItem!=null)
logger.info("Overwrite item "+createdItem.getName() + " uploaded correctly");
}
if(createdItem!=null){
notifyUploadInSharedFolder(httpSession,wa,createdItem.getId(),destinationFolder.getId(), isOverwrite);
sendMessage(response, "File "+createdItem.getName()+" imported correctly in "+destinationFolder.getPath());
}
else
sendError(response,"Internal error: Workspace Item Not Found");
}
private FolderItem overwriteItem(Workspace wa, String itemName, InputStream fileData, WorkspaceFolder destinationFolder){
FolderItem overwriteItem = null;
try {
logger.trace("case overwriting item.. "+itemName);
overwriteItem = (FolderItem) wa.find(itemName, destinationFolder.getId());
logger.trace("overwriteItem item was found, id is: "+overwriteItem.getId());
wa.updateItem(overwriteItem.getId(), fileData);
logger.trace("updateItem with id: "+overwriteItem.getId()+ ", is completed");
} catch (ItemNotFoundException e) {
logger.error("Error in createExternalFile, ItemNotFoundException", e);
} catch (WrongItemTypeException e) {
logger.error("Error in createExternalFile, WrongItemTypeException", e);
} catch (WorkspaceFolderNotFoundException e) {
logger.error("Error in createExternalFile, WorkspaceFolderNotFoundException", e);
} catch (WrongDestinationException e) {
logger.error("Error in createExternalFile, WrongDestinationException", e);
} catch (InsufficientPrivilegesException e) {
logger.error("Error in createExternalFile, InsufficientPrivilegesException", e);
} catch (ItemAlreadyExistException e) {
logger.error("Error in createExternalFile, ItemAlreadyExistException", e);
} catch (InternalErrorException e) {
logger.error("Error in createExternalFile, InternalErrorException", e);
}catch (Exception e) {
logger.error("Error in createExternalFile, Exception", e);
}
return overwriteItem;
}
private void createReport(HttpSession httpSession, Workspace wa, String itemName, InputStream stream, WorkspaceFolder destinationFolder, HttpServletResponse response, boolean isOverwrite) throws InsufficientPrivilegesException, ItemAlreadyExistException, InternalErrorException, IOException{
try {
Report report = null;
if(!isOverwrite){
itemName = WorkspaceUtil.getUniqueName(itemName, destinationFolder);
report = wa.createReport(itemName, "", Calendar.getInstance(), Calendar.getInstance(), "", "", "", 0, "", stream, destinationFolder.getId());
notifyUploadInSharedFolder(httpSession,wa,report.getId(),destinationFolder.getId(), isOverwrite);
sendMessage(response, "File "+report.getName()+" imported correctly in "+destinationFolder.getPath());
}
else{ //CASE OVERWRITE
FolderItem rep = overwriteItem(wa, itemName, stream, destinationFolder);
if(rep!=null){
notifyUploadInSharedFolder(httpSession,wa,rep.getId(),destinationFolder.getId(), isOverwrite);
sendMessage(response, "File "+rep.getName()+" imported correctly in "+destinationFolder.getPath());
}
else
sendError(response,"Internal error: Workspace Item Not Found");
}
} catch (WrongDestinationException e) {
logger.error("Error creating elements", e);
sendError(response, "Internal error: Wrong Destination");
} catch (WorkspaceFolderNotFoundException e) {
logger.error("Error creating elements", e);
sendError(response, "Internal error: Workspace Folder Not Found");
}
}
private void createTemplate(HttpSession httpSession, Workspace wa, String itemName, InputStream stream, WorkspaceFolder destinationFolder, HttpServletResponse response, boolean isOverwrite) throws InsufficientPrivilegesException, ItemAlreadyExistException, InternalErrorException, IOException{
try {
ReportTemplate template = null;
if(!isOverwrite){
itemName = WorkspaceUtil.getUniqueName(itemName, destinationFolder);
template = wa.createReportTemplate(itemName, "", Calendar.getInstance(), Calendar.getInstance(), "", "", 0, "", stream, destinationFolder.getId());
notifyUploadInSharedFolder(httpSession,wa,template.getId(),destinationFolder.getId(), isOverwrite);
sendMessage(response, "File "+template.getName()+" imported correctly in "+destinationFolder.getPath());
}else{ //CASE OVERWRITE
FolderItem rep = overwriteItem(wa, itemName, stream, destinationFolder);
if(rep!=null){
notifyUploadInSharedFolder(httpSession,wa,rep.getId(),destinationFolder.getId(), isOverwrite);
sendMessage(response, "File "+rep.getName()+" imported correctly in "+destinationFolder.getPath());
}
else
sendError(response,"Internal error: Workspace Item Not Found");
}
} catch (WrongDestinationException e) {
logger.error("Error creating elements", e);
sendError(response, "Internal error: Wrong Destination");
} catch (WorkspaceFolderNotFoundException e) {
logger.error("Error creating elements", e);
sendError(response, "Internal error: Workspace Folder Not Found");
}
}
protected void sendError(HttpServletResponse response, String message) throws IOException{
try {
response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
HandlerResultMessage resultMessage = HandlerResultMessage.errorResult(message);
response.getWriter().write(resultMessage.toString());
//5.6 Closure of Response Object:
//When a response is closed, the container must immediately flush all remaining content in the response buffer to the client
// response.flushBuffer();
} catch (IOException e){
logger.warn("IOException class name: "+e.getClass().getSimpleName());
if (e.getClass().getSimpleName().equals("ClientAbortException"))
logger.warn("Skipping ClientAbortException: "+e.getMessage());
else
throw e; //Sending Exceptions
}
}
protected void sendMessage(HttpServletResponse response, String message) throws IOException{
try {
response.setStatus(HttpServletResponse.SC_ACCEPTED);
HandlerResultMessage resultMessage = HandlerResultMessage.okResult(message);
response.getWriter().write(resultMessage.toString());
//5.6 Closure of Response Object:
//When a response is closed, the container must immediately flush all remaining content in the response buffer to the client
// response.flushBuffer();
} catch (IOException e){
logger.warn("IOException class name: "+e.getClass().getSimpleName());
if (e.getClass().getSimpleName().equals("ClientAbortException"))
logger.warn("Skipping ClientAbortException: "+e.getMessage());
else
throw e; //Sending Exceptions
}
}
protected void sendWarnMessage(HttpServletResponse response, String message) throws IOException{
try {
response.setStatus(HttpServletResponse.SC_ACCEPTED);
HandlerResultMessage resultMessage = HandlerResultMessage.warnResult(message);
response.getWriter().write(resultMessage.toString());
//5.6 Closure of Response Object:
//When a response is closed, the container must immediately flush all remaining content in the response buffer to the client
// response.flushBuffer();
} catch (IOException e){
logger.warn("IOException class name: "+e.getClass().getSimpleName());
if (e.getClass().getSimpleName().equals("ClientAbortException"))
logger.warn("Skipping ClientAbortException: "+e.getMessage());
else
throw e; //Sending Exceptions
}
}
}

View File

@ -1,470 +0,0 @@
/**
*
*/
package org.gcube.portlets.user.workspace.server;
import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Calendar;
import java.util.Iterator;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.FileItemFactory;
import org.apache.commons.fileupload.FileUploadException;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.commons.fileupload.servlet.ServletFileUpload;
import org.apache.commons.io.FilenameUtils;
import org.apache.log4j.Logger;
import org.gcube.common.homelibary.model.items.type.WorkspaceItemType;
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.InsufficientPrivilegesException;
import org.gcube.common.homelibrary.home.workspace.exceptions.ItemAlreadyExistException;
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.exceptions.WrongDestinationException;
import org.gcube.common.homelibrary.home.workspace.exceptions.WrongItemTypeException;
import org.gcube.common.homelibrary.home.workspace.folder.FolderItem;
import org.gcube.common.homelibrary.home.workspace.folder.items.Report;
import org.gcube.common.homelibrary.home.workspace.folder.items.ReportTemplate;
import org.gcube.common.homelibrary.util.Extensions;
import org.gcube.common.homelibrary.util.MimeTypeUtil;
import org.gcube.common.homelibrary.util.WorkspaceUtil;
import org.gcube.common.homelibrary.util.zip.UnzipUtil;
import org.gcube.portlets.user.workspace.client.ConstantsExplorer;
import org.gcube.portlets.user.workspace.server.notifications.NotificationsUtil;
import org.gcube.portlets.user.workspace.server.util.WsUtil;
import org.gcube.portlets.user.workspace.shared.HandlerResultMessage;
/**
* @author Federico De Faveri defaveri@isti.cnr.it
*
*/
public class UploadServlet extends HttpServlet {
public static final String UPLOAD_TYPE = ConstantsExplorer.UPLOAD_TYPE;
public static final String ID_FOLDER = ConstantsExplorer.ID_FOLDER;
public static final String UPLOAD_FORM_ELEMENT = ConstantsExplorer.UPLOAD_FORM_ELEMENT;
public static final String IS_OVERWRITE = ConstantsExplorer.IS_OVERWRITE;
public static final String FILE = "File";
protected static Logger logger = Logger.getLogger(UploadServlet.class);
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
/**
*
*/
private static final long serialVersionUID = -4197748678713054285L;
/**
* {@inheritDoc}
*/
@Override
public void init() throws ServletException {
super.init();
System.out.println("Workspace UploadServlet ready.");
}
/**
* {@inheritDoc}
*/
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
System.out.println("GET on UploadServlet");
}
/**
* {@inheritDoc}
*/
@SuppressWarnings("rawtypes")
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
System.out.println("POST on UploadServlet");
logger.trace("POST on UploadServlet");
FileItemFactory factory = new DiskFileItemFactory();
ServletFileUpload upload = new ServletFileUpload(factory);
FileItem uploadItem = null;
String destinationId = null;
String uploadType = null;
boolean isOverwrite = false;
try {
logger.trace("parsing request");
List items = upload.parseRequest(request);
Iterator it = items.iterator();
while (it.hasNext()) {
FileItem item = (FileItem) it.next();
if (UPLOAD_FORM_ELEMENT.equals(item.getFieldName())) {
uploadItem = item;
}
if (item.isFormField() && ID_FOLDER.equals(item.getFieldName())){
destinationId = item.getString();
}
if (item.isFormField() && UPLOAD_TYPE.equals(item.getFieldName())){
uploadType = item.getString();
}
if (item.isFormField() && IS_OVERWRITE.equals(item.getFieldName())){
isOverwrite = Boolean.parseBoolean(item.getString());
}
}
logger.info("Upload servlet parameters: [uploadItem: "+uploadItem +", destinationId: "+destinationId +", uploadType: "+uploadType+", isOverwrite: "+isOverwrite+"]");
} catch (FileUploadException e) {
logger.error("Error processing request in upload servlet", e);
sendError(response, "Internal error: Error during request processing");
return;
}
if (uploadItem == null) {
logger.error("Error processing request in upload servlet: No file to upload");
sendError(response, "Internal error: No file to upload");
return;
}
if (destinationId == null) {
logger.error("Error processing request in upload servlet: No destination folder id found");
sendError(response, "Internal error: No destination folder id found");
return;
}
logger.trace("destination folder id: "+destinationId);
logger.trace("uploadType: "+uploadType);
Workspace wa = null;
try {
wa = WsUtil.getWorkspace(request.getSession());
} catch (Exception e) {
logger.error("Error during workspace retrieving", e);
response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Error processing request in upload servlet");
return;
}
if (wa == null) {
logger.error("Now workspace found in session");
sendError(response, "Internal error: No workspace in session");
return;
}
WorkspaceItem item;
try {
item = wa.getItem(destinationId);
} catch (ItemNotFoundException e) {
logger.error("Error, no destination folder found", e);
sendError(response, "Internal error: No destination folder found");
return;
}
if (item.getType() != WorkspaceItemType.FOLDER && item.getType() != WorkspaceItemType.SHARED_FOLDER) {
logger.error("Error processing request in upload servlet: Wrong destination item");
sendError(response, "Internal error: Wrong destination item");
return;
}
WorkspaceFolder destinationFolder = (WorkspaceFolder) item;
try {
//we calculate an unique name for the current destination
String itemName = "";
if(!isOverwrite)
itemName = WorkspaceUtil.getUniqueName(uploadItem.getName(), destinationFolder);
else
itemName = uploadItem.getName();
String contentType = MimeTypeUtil.getMimeType(itemName, new BufferedInputStream(uploadItem.getInputStream()));
logger.trace("Content type (mime type): "+contentType + " unique name: "+itemName);
// System.out.println("Content type: "+contentType + " unique name: "+itemName);
String extension = FilenameUtils.getExtension(itemName);
logger.trace("extension: "+extension);
// System.out.println("extension: "+extension);
if(uploadType.compareTo(FILE)==0) {//IS FILE UPLOAD
boolean isZipFile = MimeTypeUtil.isZipContentType(contentType);
if(isZipFile && (extension.compareToIgnoreCase(D4ST)==0)){ //Create REPORT TEMPLATE
// String newItemName = "";
//
// if(!isOverwrite)
// newItemName = itemName.substring(0,itemName.lastIndexOf(D4ST)-1); //remove extension
// else
// newItemName = item.getName();
// System.out.println("itemwithoutext " +itemwithoutext);
String newItemName = itemName;
logger.trace("createTemplate: "+newItemName);
createTemplate(request.getSession(), wa, newItemName, uploadItem.getInputStream(), destinationFolder, response, isOverwrite);
}else if(isZipFile && (extension.compareToIgnoreCase(D4SR)==0)){ //Create REPORT
// String newItemName = "";
//
// if(!isOverwrite)
// newItemName = itemName.substring(0,itemName.lastIndexOf(D4SR)-1); //remove extension
// else
// newItemName = item.getName();
// System.out.println("itemwithoutext " +itemwithoutext);
String newItemName = itemName;
logger.trace("createReport: "+newItemName);
createReport(request.getSession(), wa, newItemName, uploadItem.getInputStream(), destinationFolder, response, isOverwrite);
}else{ //CREATE AN EXTERNAL FILE
createExternalFile(request.getSession(), wa, itemName, uploadItem, destinationFolder, contentType, response, isOverwrite);
}
}else {//IS ARCHIVE UPLOAD
if (MimeTypeUtil.isZipContentType(contentType)){
logger.trace("Unziping content");
UnzipUtil.unzip(destinationFolder, uploadItem.getInputStream(), itemName);
//TODO NOTIFY UPLOAD ARCHIVE
sendMessage(response, "Archive "+uploadItem.getName()+" imported correctly in "+destinationFolder.getPath());
} else
createExternalFile(request.getSession(), wa, itemName, uploadItem, destinationFolder, contentType, response, isOverwrite);
}
uploadItem.delete();
} catch (InsufficientPrivilegesException e) {
logger.error("Error creating elements", e);
sendError(response, "Internal error: Insufficient privileges");
return;
} catch (InternalErrorException e) {
logger.error("Error creating elements", e);
sendError(response, "Internal error: "+e.getMessage());
return;
} catch (ItemAlreadyExistException e) {
logger.error("Error creating elements", e);
sendError(response, "Internal error: An item with that name already exists");
return;
}catch (Exception e) {
logger.error("Error creating elements", e);
sendError(response, "Internal error: An error occurred on uploading the file, try again later");
return;
}
}
/**
*
* @param httpSession
* @param workspace
* @param itemId
* @param destinationFolderId
*/
private void notifyUploadInSharedFolder(final HttpSession httpSession, final Workspace workspace, final String itemId, final String destinationFolderId, final boolean isOverwrite){
new Thread(){
public void run() {
WorkspaceItem sourceItem;
try {
sourceItem = workspace.getItem(itemId);
String sourceSharedId = sourceItem.getIdSharedFolder();
WorkspaceItem folderDestinationItem = workspace.getItem(destinationFolderId);
NotificationsUtil.checkSendNotifyChangedItemToShare(httpSession, sourceItem, sourceSharedId, folderDestinationItem,isOverwrite);
} catch (Exception e) {
logger.error("Error in notifyUploadInSharedFolder", e);
}
};
}.start();
}
private void createExternalFile(HttpSession httpSession, Workspace wa, String itemName, FileItem uploadItem, WorkspaceFolder destinationFolder, String contentType, HttpServletResponse response, boolean isOverwrite) throws InternalErrorException, InsufficientPrivilegesException, ItemAlreadyExistException, IOException {
FolderItem createdItem = null;
if(!isOverwrite){
//we need to recalculate the item name
itemName = WorkspaceUtil.getUniqueName(uploadItem.getName(), destinationFolder);
createdItem = WorkspaceUtil.createExternalFile(destinationFolder, itemName, "", contentType, uploadItem.getInputStream());
}
else
createdItem = overwriteItem(wa, itemName, uploadItem.getInputStream(), destinationFolder); //CASE OVERWRITE
if(createdItem!=null){
notifyUploadInSharedFolder(httpSession,wa,createdItem.getId(),destinationFolder.getId(), isOverwrite);
sendMessage(response, "File "+createdItem.getName()+" imported correctly in "+destinationFolder.getPath());
}
else
sendError(response,"Internal error: Workspace Item Not Found");
}
private FolderItem overwriteItem(Workspace wa, String itemName, InputStream fileData, WorkspaceFolder destinationFolder){
FolderItem overwriteItem = null;
try {
logger.trace("case overwriting item.. "+itemName);
overwriteItem = (FolderItem) wa.find(itemName, destinationFolder.getId());
logger.trace("overwriteItem item was found, id is: "+overwriteItem.getId());
wa.updateItem(overwriteItem.getId(), fileData);
logger.trace("updateItem with id: "+overwriteItem.getId()+ ", is completed");
} catch (ItemNotFoundException e) {
logger.error("Error in createExternalFile, ItemNotFoundException", e);
} catch (WrongItemTypeException e) {
logger.error("Error in createExternalFile, WrongItemTypeException", e);
} catch (WorkspaceFolderNotFoundException e) {
logger.error("Error in createExternalFile, WorkspaceFolderNotFoundException", e);
} catch (WrongDestinationException e) {
logger.error("Error in createExternalFile, WrongDestinationException", e);
} catch (InsufficientPrivilegesException e) {
logger.error("Error in createExternalFile, InsufficientPrivilegesException", e);
} catch (ItemAlreadyExistException e) {
logger.error("Error in createExternalFile, ItemAlreadyExistException", e);
} catch (InternalErrorException e) {
logger.error("Error in createExternalFile, InternalErrorException", e);
}catch (Exception e) {
logger.error("Error in createExternalFile, Exception", e);
}
return overwriteItem;
}
private void createReport(HttpSession httpSession, Workspace wa, String itemName, InputStream stream, WorkspaceFolder destinationFolder, HttpServletResponse response, boolean isOverwrite) throws InsufficientPrivilegesException, ItemAlreadyExistException, InternalErrorException, IOException{
try {
Report report = null;
if(!isOverwrite){
itemName = WorkspaceUtil.getUniqueName(itemName, destinationFolder);
report = wa.createReport(itemName, "", Calendar.getInstance(), Calendar.getInstance(), "", "", "", 0, "", stream, destinationFolder.getId());
notifyUploadInSharedFolder(httpSession,wa,report.getId(),destinationFolder.getId(), isOverwrite);
sendMessage(response, "File "+report.getName()+" imported correctly in "+destinationFolder.getPath());
}
else{ //CASE OVERWRITE
FolderItem rep = overwriteItem(wa, itemName, stream, destinationFolder);
if(rep!=null){
notifyUploadInSharedFolder(httpSession,wa,rep.getId(),destinationFolder.getId(), isOverwrite);
sendMessage(response, "File "+rep.getName()+" imported correctly in "+destinationFolder.getPath());
}
else
sendError(response,"Internal error: Workspace Item Not Found");
}
} catch (WrongDestinationException e) {
logger.error("Error creating elements", e);
sendError(response, "Internal error: Wrong Destination");
} catch (WorkspaceFolderNotFoundException e) {
logger.error("Error creating elements", e);
sendError(response, "Internal error: Workspace Folder Not Found");
}
}
private void createTemplate(HttpSession httpSession, Workspace wa, String itemName, InputStream stream, WorkspaceFolder destinationFolder, HttpServletResponse response, boolean isOverwrite) throws InsufficientPrivilegesException, ItemAlreadyExistException, InternalErrorException, IOException{
try {
ReportTemplate template = null;
if(!isOverwrite){
itemName = WorkspaceUtil.getUniqueName(itemName, destinationFolder);
template = wa.createReportTemplate(itemName, "", Calendar.getInstance(), Calendar.getInstance(), "", "", 0, "", stream, destinationFolder.getId());
notifyUploadInSharedFolder(httpSession,wa,template.getId(),destinationFolder.getId(), isOverwrite);
sendMessage(response, "File "+template.getName()+" imported correctly in "+destinationFolder.getPath());
}else{ //CASE OVERWRITE
FolderItem rep = overwriteItem(wa, itemName, stream, destinationFolder);
if(rep!=null){
notifyUploadInSharedFolder(httpSession,wa,rep.getId(),destinationFolder.getId(), isOverwrite);
sendMessage(response, "File "+rep.getName()+" imported correctly in "+destinationFolder.getPath());
}
else
sendError(response,"Internal error: Workspace Item Not Found");
}
} catch (WrongDestinationException e) {
logger.error("Error creating elements", e);
sendError(response, "Internal error: Wrong Destination");
} catch (WorkspaceFolderNotFoundException e) {
logger.error("Error creating elements", e);
sendError(response, "Internal error: Workspace Folder Not Found");
}
}
protected void sendError(HttpServletResponse response, String message) throws IOException
{
response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
HandlerResultMessage resultMessage = HandlerResultMessage.errorResult(message);
response.getWriter().write(resultMessage.toString());
response.flushBuffer();
}
protected void sendMessage(HttpServletResponse response, String message) throws IOException
{
response.setStatus(HttpServletResponse.SC_ACCEPTED);
HandlerResultMessage resultMessage = HandlerResultMessage.okResult(message);
response.getWriter().write(resultMessage.toString());
response.flushBuffer();
}
protected void sendWarnMessage(HttpServletResponse response, String message) throws IOException
{
response.setStatus(HttpServletResponse.SC_ACCEPTED);
HandlerResultMessage resultMessage = HandlerResultMessage.warnResult(message);
response.getWriter().write(resultMessage.toString());
response.flushBuffer();
}
}

View File

@ -6,9 +6,10 @@ package org.gcube.portlets.user.workspace.server.notifications;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import org.apache.log4j.Logger;
import org.gcube.application.framework.core.session.ASLSession;
import org.gcube.application.framework.core.session.SessionManager;
import org.gcube.applicationsupportlayer.social.NotificationsManager;
import org.gcube.common.homelibrary.home.exceptions.InternalErrorException;
import org.gcube.common.homelibrary.home.workspace.WorkspaceItem;
@ -39,9 +40,10 @@ public class NotificationsProducer {
* Instantiates a new notifications producer.
*
* @param aslSession the asl session
* @param request the request
*/
public NotificationsProducer(ASLSession aslSession) {
this.notificationsMng = WsUtil.getNotificationManager(aslSession);
public NotificationsProducer(ASLSession aslSession, HttpServletRequest request) {
this.notificationsMng = WsUtil.getNotificationManager(aslSession, request);
this.aslSession = aslSession;
this.userId = aslSession.getUsername();
}
@ -226,7 +228,7 @@ public class NotificationsProducer {
/**
* Runs a new thread to notify the updated (add/remove) contacts to sharing
* Runs a new thread to notify the updated (add/remove) contacts to sharing.
*
* @param listSharedContact - list of contacts already shared
* @param listSharingContact - list of "new" contacts to share
@ -380,7 +382,7 @@ public class NotificationsProducer {
* Notify folder removed user.
*
* @param userUnShared the user un shared
* @param unSharedFolder the un shared folder
* @param shareFolder the share folder
*/
public void notifyFolderRemovedUser(final InfoContactModel userUnShared, final WorkspaceSharedFolder shareFolder) {
@ -813,7 +815,7 @@ public class NotificationsProducer {
* @param args the arguments
* @throws Exception the exception
*/
public static void main(String[] args) throws Exception
/*public static void main(String[] args) throws Exception
{
String sessionID = "1";
String user = "francesco.mangiacrapa";
@ -832,7 +834,6 @@ public class NotificationsProducer {
NotificationsProducer feeder = new NotificationsProducer(session);
}
}*/
}

View File

@ -6,6 +6,7 @@ package org.gcube.portlets.user.workspace.server.notifications;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import org.apache.log4j.Logger;
@ -28,13 +29,16 @@ public class NotificationsUtil {
protected static Logger logger = Logger.getLogger(NotificationsUtil.class);
/**
* Send a notification if an item is added or updated to sharing folder
* @param httpSession
* @param sourceItem
* @param sourceSharedId
* @param folderDestinationItem
* Send a notification if an item is added or updated to sharing folder.
*
* @param request the request
* @param httpSession the http session
* @param sourceItem the source item
* @param sourceSharedId the source shared id
* @param folderDestinationItem the folder destination item
* @param isOverwrite the is overwrite
*/
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");
@ -44,24 +48,18 @@ public class NotificationsUtil {
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());
//share condition is true if source shared folder is not null
boolean shareChangeCondition = sourceSharedId==null?false:true;
//System.out.println("shareChangeCondition add item: "+ shareChangeCondition);
logger.trace("shareChangeCondition add item: "+shareChangeCondition);
//if shareChangeCondition is true.. notifies added item to sharing
if(shareChangeCondition){
Workspace workspace = WsUtil.getWorkspace(httpSession);
List<InfoContactModel> listContacts = getListUsersSharedByFolderSharedId(workspace, folderDestinationItem.getIdSharedFolder());
WorkspaceItem destinationSharedFolder = workspace.getItem(folderDestinationItem.getIdSharedFolder());
NotificationsProducer np = new NotificationsProducer(WsUtil.getAslSession(httpSession));
NotificationsProducer np = new NotificationsProducer(WsUtil.getAslSession(httpSession), request);
if(destinationSharedFolder instanceof WorkspaceSharedFolder){
@ -71,7 +69,6 @@ public class NotificationsUtil {
else
np.notifyUpdatedItemToSharing(listContacts, sourceItem, (WorkspaceSharedFolder) destinationSharedFolder);
logger.trace("The notifies was sent correctly");
}else
logger.trace("The notifies doesn't sent because "+destinationSharedFolder+ " is not instance of WorkspaceSharedFolder");
@ -107,15 +104,10 @@ public class NotificationsUtil {
if(isASharedFolder(wsItem)){
WorkspaceSharedFolder wsFolder = (WorkspaceSharedFolder) wsItem;
GWTWorkspaceBuilder builder = new GWTWorkspaceBuilder();
List<String> listPortalLogin = wsFolder.getUsers();
logger.trace("getListUserSharedByFolderSharedId return "+ listPortalLogin.size() + " user");
return builder.buildGxtInfoContactsFromPortalLogins(listPortalLogin);
}
else{
logger.trace("the item with id: "+idSharedFolder+ " is not "+WorkspaceItemType.SHARED_FOLDER);
@ -131,62 +123,45 @@ public class NotificationsUtil {
}
}
/**
* Check send notify remove item to share.
*
* @param httpSession
* @param sourceItemIsShared
* @param oldItemName
* @param oldItemId
* @param sourceFolderSharedId
* @param request the request
* @param httpSession the http session
* @param sourceItemIsShared the source item is shared
* @param oldItemName the old item name
* @param oldItemId the old item id
* @param sourceFolderSharedId the source folder shared id
*/
public static void checkSendNotifyRemoveItemToShare(HttpSession httpSession, final boolean sourceItemIsShared, final String oldItemName, String oldItemId, final String sourceFolderSharedId) {
public static void checkSendNotifyRemoveItemToShare(HttpServletRequest request, HttpSession httpSession, final boolean sourceItemIsShared, final String oldItemName, String oldItemId, final String sourceFolderSharedId) {
logger.trace("checkNotifyRemoveItemToShare:");
try{
if(!sourceItemIsShared){
logger.trace("checkSendNotifyRemoveItemToShare returned, source item is not shared");
return;
}
String idSharedFolder = sourceFolderSharedId!=null?sourceFolderSharedId:"";
// System.out.println("shareChangeCondition remove item: "+ shareChangeCondition);
boolean isRootFolderShared = checkIsRootFolderShared(oldItemId, idSharedFolder);
logger.trace("isRootFolderShared is: "+ isRootFolderShared);
/*
if(isRootFolderShared){
logger.trace("Notification doesn't sent because the event is on root shared folder");
return;
}*/
boolean isSharedFolder = isASharedFolderForId(httpSession,idSharedFolder);
if(isSharedFolder){
logger.trace("idSharedFolder is: "+ idSharedFolder +" is shared folder: "+isSharedFolder);
Workspace workspace = WsUtil.getWorkspace(httpSession);
//get contacts
List<InfoContactModel> listContacts = getListUsersSharedByFolderSharedId(workspace, idSharedFolder);
WorkspaceItem sourceSharedFolder = workspace.getItem(idSharedFolder);
//System.out.println(" name sourceSharedFolder: "+ sourceSharedFolder.getName());
NotificationsProducer np = new NotificationsProducer(WsUtil.getAslSession(httpSession));
NotificationsProducer np = new NotificationsProducer(WsUtil.getAslSession(httpSession), request);
//Notify Removed Item To Sharing?
if(!isRootFolderShared){

View File

@ -6,12 +6,10 @@ import java.util.List;
import org.apache.log4j.Logger;
import org.gcube.portlets.user.workspace.client.model.InfoContactModel;
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.UserRetrievalFault;
import org.gcube.vomanagement.usermanagement.impl.liferay.LiferayUserManager;
import org.gcube.vomanagement.usermanagement.model.UserModel;
import org.gcube.vomanagement.usermanagement.impl.LiferayUserManager;
import org.gcube.vomanagement.usermanagement.model.GCubeUser;
/**
@ -42,7 +40,7 @@ public class UserUtil {
if (WsUtil.isWithinPortal()) { //INTO PORTAL
UserModel curr = null;
GCubeUser curr = null;
try {
try {
@ -55,8 +53,6 @@ public class UserUtil {
logger.error("An error occurred in getUserFullName "+e,e);
}
} catch (UserManagementPortalException ume) {
logger.error("An error occurred in getUserFullName "+ume,ume);
}catch (Exception e) {
logger.error("An error occurred in getUserFullName "+e,e);
logger.warn("Return portal login "+portalLogin);

View File

@ -3,6 +3,7 @@
*/
package org.gcube.portlets.user.workspace.server.util;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import org.apache.commons.lang.StringUtils;
@ -11,6 +12,8 @@ import org.gcube.application.framework.core.session.ASLSession;
import org.gcube.application.framework.core.session.SessionManager;
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.homelibrary.home.HomeLibrary;
import org.gcube.common.homelibrary.home.exceptions.HomeNotFoundException;
import org.gcube.common.homelibrary.home.exceptions.InternalErrorException;
@ -31,10 +34,10 @@ import com.liferay.portal.service.UserLocalServiceUtil;
/**
* The Class WsUtil.
*
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* @Feb 18, 2014
*
*/
public class WsUtil {
@ -75,6 +78,7 @@ public class WsUtil {
// public static boolean withoutPortal = false;
/**
* Checks if is within portal.
*
* @return true if you're running into the portal, false if in development
*/
@ -89,6 +93,12 @@ public class WsUtil {
}
}
/**
* Gets the asl session.
*
* @param httpSession the http session
* @return the asl session
*/
public static ASLSession getAslSession(HttpSession httpSession)
{
String sessionID = httpSession.getId();
@ -133,10 +143,11 @@ public class WsUtil {
}
/**
* Checks if is session expired.
*
* @param httpSession
* @param httpSession the http session
* @return true if current username into ASL session is WsUtil.TEST_USER, false otherwise
* @throws Exception
* @throws Exception the exception
*/
public static boolean isSessionExpired(HttpSession httpSession) throws Exception {
logger.trace("workspace session validating...");
@ -159,6 +170,15 @@ public class WsUtil {
}
/**
* Gets the workspace.
*
* @param httpSession the http session
* @return the workspace
* @throws InternalErrorException the internal error exception
* @throws HomeNotFoundException the home not found exception
* @throws WorkspaceFolderNotFoundException the workspace folder not found exception
*/
public static Workspace getWorkspace(final HttpSession httpSession) throws InternalErrorException, HomeNotFoundException, WorkspaceFolderNotFoundException
{
logger.trace("Get Workspace");
@ -174,6 +194,12 @@ public class WsUtil {
}
/**
* Gets the GWT workspace builder.
*
* @param httpSession the http session
* @return the GWT workspace builder
*/
public static GWTWorkspaceBuilder getGWTWorkspaceBuilder(HttpSession httpSession)
{
ASLSession session = getAslSession(httpSession);
@ -189,7 +215,14 @@ public class WsUtil {
return builder;
}
public static NotificationsManager getNotificationManager(ASLSession session)
/**
* Gets the notification manager.
*
* @param session the session
* @param request the request
* @return the notification manager
*/
public static NotificationsManager getNotificationManager(ASLSession session, HttpServletRequest request)
{
NotificationsManager notifMng = (NotificationsManager) session.getAttribute(NOTIFICATION_MANAGER);
@ -198,7 +231,9 @@ public class WsUtil {
try{
logger.trace("Create new NotificationsManager for user: "+session.getUsername());
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);
SocialNetworkingUser curser = new SocialNetworkingUser(session.getUsername(), session.getUserEmailAddress(), session.getUserFullName(), session.getUserAvatarId());
notifMng = new ApplicationNotificationsManager(site, session.getScope(), curser, NOTIFICATION_PORTLET_CLASS_ID);
session.setAttribute(NOTIFICATION_MANAGER, notifMng);
}catch (Exception e) {
logger.error("An error occurred instancing ApplicationNotificationsManager for user: "+session.getUsername(),e);
@ -208,20 +243,33 @@ public class WsUtil {
return notifMng;
}
public static NotificationsProducer getNotificationProducer(ASLSession session)
/**
* Gets the notification producer.
*
* @param session the session
* @param request the request
* @return the notification producer
*/
public static NotificationsProducer getNotificationProducer(ASLSession session, HttpServletRequest request)
{
NotificationsProducer notifProducer = (NotificationsProducer) session.getAttribute(NOTIFICATION_PRODUCER);
if (notifProducer == null) {
logger.trace("Create new Notification Producer for user: "+session.getUsername());
notifProducer = new NotificationsProducer(session);
notifProducer = new NotificationsProducer(session, request);
session.setAttribute(NOTIFICATION_PRODUCER, notifProducer);
}
return notifProducer;
}
/**
* Gets the user id.
*
* @param httpSession the http session
* @return the user id
*/
public static String getUserId(HttpSession httpSession) {
ASLSession session = getAslSession(httpSession);
@ -229,6 +277,12 @@ public class WsUtil {
return session.getUsername();
}
/**
* Checks if is vre.
*
* @param session the session
* @return true, if is vre
*/
public static boolean isVRE(ASLSession session){
String currentScope = session.getScopeName();
@ -245,6 +299,12 @@ public class WsUtil {
}
/**
* Gets the scope util filter.
*
* @param httpSession the http session
* @return the scope util filter
*/
public static ScopeUtilFilter getScopeUtilFilter(HttpSession httpSession){
ASLSession session = getAslSession(httpSession);
@ -265,8 +325,10 @@ public class WsUtil {
/**
* @param session
* @return
* Gets the url shortener.
*
* @param httpSession the http session
* @return the url shortener
*/
public static UrlShortener getUrlShortener(HttpSession httpSession) {
@ -289,8 +351,10 @@ public class WsUtil {
/**
* @param session
* @return
* Gets the uri resolver.
*
* @param httpSession the http session
* @return the uri resolver
*/
public static UriResolverReaderParameterForResolverIndex getUriResolver(HttpSession httpSession) {
@ -313,8 +377,11 @@ public class WsUtil {
}
/**
* @param session
* @return
* Gets the property special folder reader.
*
* @param httpSession the http session
* @param pathProperty the path property
* @return the property special folder reader
*/
public static PropertySpecialFolderReader getPropertySpecialFolderReader(HttpSession httpSession, String pathProperty) {
ASLSession session = getAslSession(httpSession);