2013-02-06 15:40:17 +01:00
package org.gcube.portlets.user.workspace.server ;
2014-03-05 18:28:49 +01:00
import java.io.File ;
2013-02-06 15:40:17 +01:00
import java.util.ArrayList ;
2014-02-17 15:56:42 +01:00
import java.util.Arrays ;
2013-03-25 12:35:05 +01:00
import java.util.Calendar ;
2013-02-06 15:40:17 +01:00
import java.util.Collections ;
2013-03-25 12:35:05 +01:00
import java.util.Date ;
2014-05-09 17:48:30 +02:00
import java.util.HashMap ;
2013-02-06 15:40:17 +01:00
import java.util.List ;
2014-03-17 14:43:06 +01:00
import java.util.Map ;
2013-02-06 15:40:17 +01:00
import java.util.concurrent.TimeUnit ;
2014-03-05 18:28:49 +01:00
import javax.servlet.ServletContext ;
2016-09-21 18:10:14 +02:00
import javax.servlet.http.HttpServletRequest ;
2014-03-05 18:28:49 +01:00
2013-03-11 19:06:56 +01:00
import org.apache.log4j.Logger ;
2016-09-19 12:17:33 +02:00
import org.gcube.common.encryption.StringEncrypter ;
2015-05-20 18:39:49 +02:00
import org.gcube.common.homelibary.model.items.type.FolderItemType ;
import org.gcube.common.homelibary.model.items.type.WorkspaceItemType ;
2017-02-20 18:03:49 +01:00
import org.gcube.common.homelibary.model.versioning.WorkspaceVersion ;
2013-09-27 17:39:28 +02:00
import org.gcube.common.homelibrary.home.Home ;
import org.gcube.common.homelibrary.home.HomeLibrary ;
import org.gcube.common.homelibrary.home.exceptions.HomeNotFoundException ;
import org.gcube.common.homelibrary.home.exceptions.InternalErrorException ;
import org.gcube.common.homelibrary.home.workspace.Workspace ;
import org.gcube.common.homelibrary.home.workspace.WorkspaceFolder ;
import org.gcube.common.homelibrary.home.workspace.WorkspaceItem ;
import org.gcube.common.homelibrary.home.workspace.WorkspaceSharedFolder ;
import org.gcube.common.homelibrary.home.workspace.WorkspaceSmartFolder ;
2014-02-11 12:53:10 +01:00
import org.gcube.common.homelibrary.home.workspace.accessmanager.ACLType ;
2013-09-27 17:39:28 +02:00
import org.gcube.common.homelibrary.home.workspace.accounting.AccountingEntry ;
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.folder.FolderItem ;
2017-02-20 11:41:54 +01:00
import org.gcube.common.homelibrary.home.workspace.folder.items.ExternalFile ;
2013-09-27 17:39:28 +02:00
import org.gcube.common.homelibrary.home.workspace.folder.items.ExternalUrl ;
2015-06-12 12:24:01 +02:00
import org.gcube.common.homelibrary.home.workspace.folder.items.GCubeItem ;
2013-09-27 17:39:28 +02:00
import org.gcube.common.homelibrary.home.workspace.search.SearchItem ;
2014-02-17 15:56:42 +01:00
import org.gcube.common.homelibrary.home.workspace.trash.WorkspaceTrashFolder ;
2014-05-13 11:10:54 +02:00
import org.gcube.common.homelibrary.home.workspace.trash.WorkspaceTrashItem ;
2016-12-21 18:49:00 +01:00
import org.gcube.common.portal.PortalContext ;
2016-09-14 14:30:33 +02:00
import org.gcube.portlets.user.urlshortener.UrlShortener ;
2013-02-20 14:51:36 +01:00
import org.gcube.portlets.user.workspace.client.ConstantsExplorer ;
2016-09-29 15:28:32 +02:00
import org.gcube.portlets.user.workspace.client.interfaces.GXTCategorySmartFolder ;
2013-02-06 15:40:17 +01:00
import org.gcube.portlets.user.workspace.client.model.FileDetailsModel ;
import org.gcube.portlets.user.workspace.client.model.FileGridModel ;
import org.gcube.portlets.user.workspace.client.model.FileModel ;
2014-02-17 15:56:42 +01:00
import org.gcube.portlets.user.workspace.client.model.FileTrashedModel ;
2017-02-20 18:03:49 +01:00
import org.gcube.portlets.user.workspace.client.model.FileVersionModel ;
2013-02-06 15:40:17 +01:00
import org.gcube.portlets.user.workspace.client.model.FolderModel ;
import org.gcube.portlets.user.workspace.client.model.InfoContactModel ;
import org.gcube.portlets.user.workspace.client.model.ScopeModel ;
import org.gcube.portlets.user.workspace.client.model.SmartFolderModel ;
import org.gcube.portlets.user.workspace.client.model.SubTree ;
import org.gcube.portlets.user.workspace.client.rpc.GWTWorkspaceService ;
import org.gcube.portlets.user.workspace.client.workspace.GWTWorkspaceItem ;
2015-02-16 14:46:38 +01:00
import org.gcube.portlets.user.workspace.client.workspace.folder.item.gcube.WorkspaceHandledException ;
2013-02-13 18:39:33 +01:00
import org.gcube.portlets.user.workspace.server.notifications.NotificationsProducer ;
2013-06-13 18:44:46 +02:00
import org.gcube.portlets.user.workspace.server.notifications.NotificationsUtil ;
2016-09-14 12:17:14 +02:00
import org.gcube.portlets.user.workspace.server.reader.ApplicationProfile ;
import org.gcube.portlets.user.workspace.server.reader.ApplicationProfileReader ;
2016-01-13 15:38:33 +01:00
import org.gcube.portlets.user.workspace.server.resolver.UriResolverReaderParameterForResolverIndex ;
2015-03-06 16:12:21 +01:00
import org.gcube.portlets.user.workspace.server.util.AclTypeComparator ;
2015-11-19 17:17:13 +01:00
import org.gcube.portlets.user.workspace.server.util.DifferenceBetweenInfoContactModel ;
2016-11-25 12:03:25 +01:00
import org.gcube.portlets.user.workspace.server.util.PortalContextInfo ;
2016-09-19 12:17:33 +02:00
import org.gcube.portlets.user.workspace.server.util.StringUtil ;
2013-03-25 17:35:27 +01:00
import org.gcube.portlets.user.workspace.server.util.UserUtil ;
2013-06-13 18:44:46 +02:00
import org.gcube.portlets.user.workspace.server.util.WsUtil ;
2014-03-05 17:45:33 +01:00
import org.gcube.portlets.user.workspace.server.util.resource.PropertySpecialFolderReader ;
2013-03-27 17:30:37 +01:00
import org.gcube.portlets.user.workspace.server.util.scope.ScopeUtilFilter ;
2016-11-29 15:16:47 +01:00
import org.gcube.portlets.user.workspace.shared.AllowAccess ;
2014-07-14 15:59:32 +02:00
import org.gcube.portlets.user.workspace.shared.ExtendedWorkspaceACL ;
2015-10-29 15:36:27 +01:00
import org.gcube.portlets.user.workspace.shared.GarbageItem ;
2015-07-03 12:18:27 +02:00
import org.gcube.portlets.user.workspace.shared.PublicLink ;
2015-03-06 16:12:21 +01:00
import org.gcube.portlets.user.workspace.shared.ReportAssignmentACL ;
2013-09-04 15:30:17 +02:00
import org.gcube.portlets.user.workspace.shared.SessionExpiredException ;
2014-05-13 11:10:54 +02:00
import org.gcube.portlets.user.workspace.shared.TrashContent ;
import org.gcube.portlets.user.workspace.shared.TrashOperationContent ;
2014-10-28 17:12:40 +01:00
import org.gcube.portlets.user.workspace.shared.UserBean ;
2014-02-11 12:53:10 +01:00
import org.gcube.portlets.user.workspace.shared.WorkspaceACL ;
2014-02-17 15:56:42 +01:00
import org.gcube.portlets.user.workspace.shared.WorkspaceTrashOperation ;
2014-10-31 17:27:52 +01:00
import org.gcube.portlets.user.workspace.shared.WorkspaceUserQuote ;
2017-02-20 11:41:54 +01:00
import org.gcube.portlets.user.workspace.shared.WorkspaceVersioningOperation ;
2013-05-23 19:03:43 +02:00
import org.gcube.portlets.user.workspace.shared.accounting.GxtAccountingEntryType ;
import org.gcube.portlets.user.workspace.shared.accounting.GxtAccountingField ;
2013-10-03 14:45:25 +02:00
import org.gcube.vomanagement.usermanagement.GroupManager ;
2013-10-02 15:39:39 +02:00
import org.gcube.vomanagement.usermanagement.UserManager ;
2016-05-31 17:11:53 +02:00
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 ;
2013-02-06 15:40:17 +01:00
import com.google.gwt.user.server.rpc.RemoteServiceServlet ;
2014-10-28 17:12:40 +01:00
import com.liferay.portal.service.UserLocalServiceUtil ;
2013-02-06 15:40:17 +01:00
/ * *
2015-03-06 16:12:21 +01:00
* The Class GWTWorkspaceServiceImpl .
2013-02-06 15:40:17 +01:00
*
2015-03-06 16:12:21 +01:00
* @author Francesco Mangiacrapa francesco . mangiacrapa @isti.cnr.it
2013-02-06 15:40:17 +01:00
* /
public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWTWorkspaceService {
2013-10-04 13:58:07 +02:00
protected static final String IDENTIFIER_IS_NULL = " Identifier is null " ;
2013-07-08 17:42:08 +02:00
protected static final String RETRIEVING_ITEM_EITHER_ITEM_DOESN_T_EXIST = " retrieving item. Either the item doesn't exist anymore or you do not have the permission to access it " ;
2013-02-06 15:40:17 +01:00
private static final long serialVersionUID = 2828885661214875589L ;
public static final String LAST_OPEN_FOLDER_ATTRIBUTE = " WORKSPACE.LAST_OPEN_FOLDER " ;
public static final String SELECTION_STATE_ATTRIBUTE = " WORKSPACE.SELECTION_STATE " ;
2013-03-11 19:06:56 +01:00
protected Logger workspaceLogger = Logger . getLogger ( GWTWorkspaceServiceImpl . class ) ;
2015-06-24 16:56:13 +02:00
2015-03-06 16:12:21 +01:00
/ * *
* Gets the GWT workspace builder .
*
* @return the GWT workspace builder
* /
2013-02-06 15:40:17 +01:00
protected GWTWorkspaceBuilder getGWTWorkspaceBuilder ( )
{
2016-11-25 12:03:25 +01:00
return WsUtil . getGWTWorkspaceBuilder ( this . getThreadLocalRequest ( ) ) ;
2013-02-06 15:40:17 +01:00
}
2015-03-06 16:12:21 +01:00
/ * *
* Gets the workspace .
*
* @return the workspace
* @throws InternalErrorException the internal error exception
* @throws HomeNotFoundException the home not found exception
* @throws WorkspaceFolderNotFoundException the workspace folder not found exception
* /
2013-02-06 15:40:17 +01:00
protected Workspace getWorkspace ( ) throws InternalErrorException , HomeNotFoundException , WorkspaceFolderNotFoundException
{
2016-11-25 12:03:25 +01:00
return WsUtil . getWorkspace ( this . getThreadLocalRequest ( ) ) ;
2013-02-06 15:40:17 +01:00
}
2016-01-19 15:50:40 +01:00
2015-03-06 16:12:21 +01:00
/ * *
* Gets the notification producer .
*
* @return the notification producer
* /
2013-02-13 18:39:33 +01:00
protected NotificationsProducer getNotificationProducer ( ) {
2016-01-19 15:50:40 +01:00
2016-11-25 12:03:25 +01:00
return WsUtil . getNotificationProducer ( this . getThreadLocalRequest ( ) ) ;
2013-02-13 18:39:33 +01:00
}
2016-01-19 15:50:40 +01:00
2015-03-06 16:12:21 +01:00
/ * *
* Gets the scope util filter .
*
* @return the scope util filter
* /
2013-03-27 17:30:37 +01:00
protected ScopeUtilFilter getScopeUtilFilter ( ) {
2016-01-19 15:50:40 +01:00
2016-11-25 12:03:25 +01:00
return WsUtil . getScopeUtilFilter ( this . getThreadLocalRequest ( ) ) ;
2013-03-27 17:30:37 +01:00
}
2016-01-19 15:50:40 +01:00
2015-03-06 16:12:21 +01:00
/ * *
* Checks if is test mode .
*
* @return true , if is test mode
* /
2013-02-14 15:06:34 +01:00
protected boolean isTestMode ( ) {
2015-01-28 15:02:18 +01:00
return ! WsUtil . isWithinPortal ( ) ;
2013-02-13 18:39:33 +01:00
}
2016-01-19 15:50:40 +01:00
2015-03-06 16:12:21 +01:00
/ * *
* Gets the url shortener .
*
* @return the url shortener
* /
2013-07-01 15:54:54 +02:00
protected UrlShortener getUrlShortener ( ) {
2016-11-25 12:03:25 +01:00
return WsUtil . getUrlShortener ( this . getThreadLocalRequest ( ) ) ;
2013-07-01 15:54:54 +02:00
}
2013-02-06 15:40:17 +01:00
2015-03-06 16:12:21 +01:00
/ * *
* Gets the uri resolver .
*
* @return the uri resolver
* /
2016-01-13 15:38:33 +01:00
protected UriResolverReaderParameterForResolverIndex getUriResolver ( ) {
2016-11-25 12:03:25 +01:00
return WsUtil . getUriResolver ( this . getThreadLocalRequest ( ) ) ;
2013-07-08 17:42:08 +02:00
}
2016-01-19 15:50:40 +01:00
2015-03-06 16:12:21 +01:00
/ * *
* Gets the property special folder reader .
*
* @return the property special folder reader
* /
2014-03-05 17:45:33 +01:00
protected PropertySpecialFolderReader getPropertySpecialFolderReader ( ) {
2014-03-05 18:28:49 +01:00
String absolutePathProperty = getSpecialFolderPath ( ) ;
2016-11-25 12:03:25 +01:00
return WsUtil . getPropertySpecialFolderReader ( this . getThreadLocalRequest ( ) , absolutePathProperty ) ;
2014-03-05 18:28:49 +01:00
}
2016-01-19 15:50:40 +01:00
2014-03-05 18:28:49 +01:00
/ * *
2015-03-06 16:12:21 +01:00
* Gets the special folder path .
*
2014-03-17 14:43:06 +01:00
* @return the Category if there is correspondance , null otherwise
2014-03-05 18:28:49 +01:00
* /
private String getSpecialFolderPath ( ) {
ServletContext servletContext = getServletContext ( ) ;
String contextPath = servletContext . getRealPath ( File . separator ) ;
return contextPath + File . separator + " conf " + File . separator + ConstantsExplorer . SPECIALFOLDERNAMEPROPERTIESFILE ;
2014-03-05 17:45:33 +01:00
}
2016-01-19 15:50:40 +01:00
2015-03-06 16:12:21 +01:00
/ * ( non - Javadoc )
* @see org . gcube . portlets . user . workspace . client . rpc . GWTWorkspaceService # getRootForTree ( )
* /
2017-02-20 11:41:54 +01:00
/ * *
* Gets the root for tree .
*
* @return the root for tree
* @throws Exception the exception
* /
2013-02-06 15:40:17 +01:00
@Override
public FolderModel getRootForTree ( ) throws Exception {
2013-02-27 19:17:22 +01:00
workspaceLogger . trace ( " getRoot " ) ;
2016-01-19 15:50:40 +01:00
2013-02-06 15:40:17 +01:00
try {
workspaceLogger . trace ( " getting workspace " ) ;
Workspace workspace = getWorkspace ( ) ;
WorkspaceFolder root = workspace . getRoot ( ) ;
if ( root = = null ) {
2013-10-04 13:58:07 +02:00
workspaceLogger . error ( " The root is null " ) ;
2013-02-06 15:40:17 +01:00
throw new Exception ( " The root is null " ) ;
}
workspaceLogger . trace ( " Root loaded, gxt conversion " ) ;
GWTWorkspaceBuilder builder = getGWTWorkspaceBuilder ( ) ;
FolderModel gwtroot = builder . buildWorkspaceFileModelRoot ( root ) ;
workspaceLogger . trace ( " Root converted, returnig... " ) ;
return gwtroot ;
} catch ( Exception e ) {
workspaceLogger . error ( " Error in server during root retrieving " , e ) ;
2016-06-22 18:41:51 +02:00
// workspaceLogger.trace("Error in server During root retrieving " + e);
2016-01-19 15:50:40 +01:00
2013-02-06 15:40:17 +01:00
//GWT can't serialize all exceptions
throw new Exception ( " Error during workspace loading, please contact the support. Exception: " + e ) ;
}
}
2016-01-19 15:50:40 +01:00
2015-03-06 16:12:21 +01:00
/ * ( non - Javadoc )
* @see org . gcube . portlets . user . workspace . client . rpc . GWTWorkspaceService # getRootForTree ( java . lang . String )
* /
2017-02-20 11:41:54 +01:00
/ * *
* Gets the root for tree .
*
* @param scopeId the scope id
* @return the root for tree
* @throws Exception the exception
* /
2013-02-06 15:40:17 +01:00
@Override
public FolderModel getRootForTree ( String scopeId ) throws Exception {
workspaceLogger . info ( " getRoot for scope " + scopeId ) ;
workspaceLogger . trace ( " getting workspace " ) ;
2016-01-19 15:50:40 +01:00
2013-02-06 15:40:17 +01:00
try {
Workspace workspace = getWorkspace ( ) ;
workspaceLogger . trace ( " on server getRoot for scope: " + scopeId ) ;
2016-01-19 15:50:40 +01:00
2016-06-22 18:41:51 +02:00
// GCUBEScope gcubeScope = null;
//
// if(scopeId.compareTo(ScopeUtilFilter.IDALLSCOPE)!=0){
// gcubeScope = GCUBEScope.getScope(scopeId);
// }
2016-01-19 15:50:40 +01:00
2013-09-27 17:39:28 +02:00
WorkspaceFolder root = workspace . getRoot ( ) ;
2013-02-06 15:40:17 +01:00
if ( root = = null ) {
2013-10-04 13:58:07 +02:00
workspaceLogger . error ( " The root is null " ) ;
2013-02-06 15:40:17 +01:00
throw new Exception ( " The root is null " ) ;
}
workspaceLogger . trace ( " Root loaded, gxt conversion " ) ;
GWTWorkspaceBuilder builder = getGWTWorkspaceBuilder ( ) ;
workspaceLogger . trace ( " Root converted, returnig... " ) ;
return builder . buildWorkspaceFileModelRoot ( root ) ;
} catch ( Exception e ) {
workspaceLogger . error ( " Error in server during root retrieving " , e ) ;
//GWT can't serialize all exceptions
throw new Exception ( " Error during workspace loading, please contact the support. Exception: " + e ) ;
}
}
2016-01-19 15:50:40 +01:00
2013-02-06 15:40:17 +01:00
2015-03-06 16:12:21 +01:00
/ * ( non - Javadoc )
* @see org . gcube . portlets . user . workspace . client . rpc . GWTWorkspaceService # getItemsBySearchName ( java . lang . String )
* /
2017-02-20 11:41:54 +01:00
/ * *
* Gets the items by search name .
*
* @param text the text
* @param folderId the folder id
* @return the items by search name
* @throws Exception the exception
* /
2013-02-06 15:40:17 +01:00
@Override
2015-10-12 15:30:59 +02:00
public List < FileGridModel > getItemsBySearchName ( String text , String folderId ) throws Exception {
2013-02-06 15:40:17 +01:00
try {
Workspace workspace = getWorkspace ( ) ;
2015-10-12 15:30:59 +02:00
if ( folderId = = null | | folderId . isEmpty ( ) ) {
workspaceLogger . trace ( " searching folderId is null, settings root Id " ) ;
2016-01-19 15:50:40 +01:00
folderId = workspace . getRoot ( ) . getId ( ) ;
2015-10-12 15:30:59 +02:00
}
2016-01-19 15:50:40 +01:00
2015-10-12 15:30:59 +02:00
workspaceLogger . info ( " searching by name: " + text + " in " + folderId ) ;
List < SearchItem > listSearchItems = workspace . searchByName ( text , folderId ) ;
2014-05-12 14:29:29 +02:00
workspaceLogger . info ( " HL search returning " + listSearchItems . size ( ) + " items " ) ;
2016-01-19 15:50:40 +01:00
2014-05-12 14:29:29 +02:00
workspaceLogger . info ( " Converting " + listSearchItems . size ( ) + " items " ) ;
2013-02-06 15:40:17 +01:00
GWTWorkspaceBuilder builder = getGWTWorkspaceBuilder ( ) ;
List < FileGridModel > listFileGridModels = new ArrayList < FileGridModel > ( ) ;
2014-05-12 14:29:29 +02:00
2013-11-15 12:12:17 +01:00
listFileGridModels = builder . buildGXTListFileGridModelItemForSearch ( listSearchItems ) ;
2014-05-12 14:29:29 +02:00
workspaceLogger . info ( " Search objects converted, returning " ) ;
2016-01-19 15:50:40 +01:00
2013-02-06 15:40:17 +01:00
return listFileGridModels ;
} catch ( Exception e ) {
workspaceLogger . error ( " Error in server During search retrieving " , e ) ;
2016-06-22 18:41:51 +02:00
// workspaceLogger.trace("Error in server During search retrieving " + e);
2016-01-19 15:50:40 +01:00
2013-02-06 15:40:17 +01:00
//GWT can't serialize all exceptions
throw new Exception ( " Error during searching, please contact the support. " ) ;
}
}
2016-01-19 15:50:40 +01:00
2015-03-06 16:12:21 +01:00
/ * ( non - Javadoc )
* @see org . gcube . portlets . user . workspace . client . rpc . GWTWorkspaceService # getFolderChildren ( org . gcube . portlets . user . workspace . client . model . FolderModel )
* /
2017-02-20 11:41:54 +01:00
/ * *
* Gets the folder children .
*
* @param folder the folder
* @return the folder children
* @throws Exception the exception
* @throws SessionExpiredException the session expired exception
* /
2013-02-06 15:40:17 +01:00
@Override
2013-09-04 15:30:17 +02:00
public List < FileModel > getFolderChildren ( FolderModel folder ) throws Exception , SessionExpiredException {
2016-01-19 15:50:40 +01:00
2013-02-06 15:40:17 +01:00
Workspace workspace ;
2013-10-04 13:58:07 +02:00
2013-09-04 15:30:17 +02:00
if ( isSessionExpired ( ) )
throw new SessionExpiredException ( ) ;
2016-01-19 15:50:40 +01:00
2013-02-06 15:40:17 +01:00
try {
2016-01-19 15:50:40 +01:00
2013-10-04 13:58:07 +02:00
if ( folder = = null )
2016-01-19 15:50:40 +01:00
throw new Exception ( " Folder is null " ) ;
2013-09-04 15:30:17 +02:00
2015-09-18 15:26:33 +02:00
workspaceLogger . trace ( " get folder children for: " + folder . getIdentifier ( ) + " name: " + folder . getName ( ) ) ;
2013-02-06 15:40:17 +01:00
workspace = getWorkspace ( ) ;
List < FileModel > listFileModels = new ArrayList < FileModel > ( ) ;
WorkspaceItem wsItem = workspace . getItem ( folder . getIdentifier ( ) ) ;
GWTWorkspaceBuilder builder = getGWTWorkspaceBuilder ( ) ;
listFileModels = builder . buildGXTListFileModelItem ( wsItem , folder ) ;
2016-01-19 15:50:40 +01:00
2014-03-05 17:45:33 +01:00
//ADDING SPECIAL FOLDER?
if ( wsItem . isRoot ( ) ) {
//ADD SPECIAL FOLDER
try {
workspaceLogger . info ( " Folder is root, loading special folders.. " ) ;
WorkspaceFolder specialFolder = workspace . getMySpecialFolders ( ) ;
FileModel specialFolderModel = builder . buildGXTFileModelItem ( specialFolder , folder ) ;
specialFolderModel . setSpecialFolder ( true ) ;
String newName = getNameForSpecialFolder ( ) ;
2016-01-19 15:50:40 +01:00
2014-03-05 17:45:33 +01:00
if ( ! newName . isEmpty ( ) ) {
workspaceLogger . info ( " Special folder name updated as: " + newName ) ;
specialFolderModel . setName ( newName ) ;
} else
workspaceLogger . info ( " Special folder name is empty, skipping " ) ;
2016-01-19 15:50:40 +01:00
2014-03-05 17:45:33 +01:00
listFileModels . add ( specialFolderModel ) ;
} catch ( Exception e ) {
workspaceLogger . warn ( " An error occurred on retrieving special folders for folder id: " + folder . getIdentifier ( ) , e ) ;
}
}
2013-02-06 15:40:17 +01:00
return listFileModels ;
2016-01-19 15:50:40 +01:00
2013-02-06 15:40:17 +01:00
} catch ( Exception e ) {
workspaceLogger . error ( " Error in server During item retrieving " , e ) ;
2016-06-22 18:41:51 +02:00
// workspaceLogger.trace("Error in server During item retrieving " + e);
2013-07-08 17:42:08 +02:00
String error = ConstantsExplorer . SERVER_ERROR + RETRIEVING_ITEM_EITHER_ITEM_DOESN_T_EXIST ;
2013-02-06 15:40:17 +01:00
//GWT can't serialize all exceptions
2013-06-14 15:04:43 +02:00
throw new Exception ( error ) ;
2013-02-06 15:40:17 +01:00
}
}
2016-01-19 15:50:40 +01:00
2015-03-06 16:12:21 +01:00
/ * *
* Gets the name for special folder .
*
* @return the name for special folder
* /
2014-03-05 17:45:33 +01:00
private String getNameForSpecialFolder ( ) {
2016-01-19 15:50:40 +01:00
2014-03-05 17:45:33 +01:00
PropertySpecialFolderReader sfReader = getPropertySpecialFolderReader ( ) ;
2016-01-19 15:50:40 +01:00
2014-03-05 17:45:33 +01:00
if ( sfReader = = null ) {
workspaceLogger . warn ( " Reader is null, skypping set to special folder name " ) ;
return " " ;
}
2016-01-19 15:50:40 +01:00
2014-03-05 17:45:33 +01:00
workspaceLogger . info ( " Read special folder name: ' " + sfReader . getSpecialFolderName ( ) + " ', from property file.. " ) ;
return sfReader . getSpecialFolderName ( ) ;
}
2016-01-19 15:50:40 +01:00
2013-02-06 15:40:17 +01:00
2015-03-06 16:12:21 +01:00
/ * ( non - Javadoc )
* @see org . gcube . portlets . user . workspace . client . rpc . GWTWorkspaceService # getFolderChildrenForFileGrid ( org . gcube . portlets . user . workspace . client . model . FileModel )
* /
2017-02-20 11:41:54 +01:00
/ * *
* Gets the folder children for file grid .
*
* @param folder the folder
* @return the folder children for file grid
* @throws Exception the exception
* @throws SessionExpiredException the session expired exception
* /
2013-02-06 15:40:17 +01:00
@Override
2013-09-04 15:30:17 +02:00
public List < FileGridModel > getFolderChildrenForFileGrid ( FileModel folder ) throws Exception , SessionExpiredException {
2016-01-19 15:50:40 +01:00
2013-09-04 15:30:17 +02:00
if ( isSessionExpired ( ) )
throw new SessionExpiredException ( ) ;
2016-01-19 15:50:40 +01:00
2013-02-06 15:40:17 +01:00
try {
2016-01-19 15:50:40 +01:00
2013-10-04 13:58:07 +02:00
if ( folder = = null )
2016-01-19 15:50:40 +01:00
throw new Exception ( " Folder is null " ) ;
2013-10-04 13:58:07 +02:00
workspaceLogger . trace ( " get children for Grid for folder: " + folder . getIdentifier ( ) ) ;
Workspace workspace = getWorkspace ( ) ;
List < FileGridModel > listFileGridModels = new ArrayList < FileGridModel > ( ) ;
2016-01-19 15:50:40 +01:00
WorkspaceFolder wsFolder = ( WorkspaceFolder ) workspace . getItem ( folder . getIdentifier ( ) ) ;
GWTWorkspaceBuilder builder = getGWTWorkspaceBuilder ( ) ;
List < WorkspaceItem > listItems = wsFolder . getChildren ( ) ;
2013-02-06 15:40:17 +01:00
listFileGridModels = builder . buildGXTListFileGridModelItem ( listItems , folder ) ;
2016-01-19 15:50:40 +01:00
2014-03-05 17:45:33 +01:00
//ADDING SPECIAL FOLDER?
if ( wsFolder . isRoot ( ) ) {
//ADD SPECIAL FOLDER
try {
workspaceLogger . info ( " Folder is root, loading special folders.. " ) ;
WorkspaceFolder specialFolder = workspace . getMySpecialFolders ( ) ;
FileGridModel specialFolderModel = builder . buildGXTFileGridModelItem ( specialFolder , folder ) ;
2016-06-22 18:41:51 +02:00
// specialFolderModel.setShortcutCategory(GXTCategoryItemInterface.SMF_VRE_FOLDERS);
2014-03-05 17:45:33 +01:00
specialFolderModel . setSpecialFolder ( true ) ;
String newName = getNameForSpecialFolder ( ) ;
2016-01-19 15:50:40 +01:00
2014-03-05 17:45:33 +01:00
if ( ! newName . isEmpty ( ) ) {
workspaceLogger . info ( " Special folder name updated as: " + newName ) ;
specialFolderModel . setName ( newName ) ;
} else
workspaceLogger . info ( " Special folder name is empty, skipping " ) ;
2016-01-19 15:50:40 +01:00
2014-03-05 17:45:33 +01:00
listFileGridModels . add ( specialFolderModel ) ;
} catch ( Exception e ) {
workspaceLogger . warn ( " An error occurred on retrieving special folders for folder id: " + folder . getIdentifier ( ) , e ) ;
}
}
2016-01-19 15:50:40 +01:00
2013-02-06 15:40:17 +01:00
return listFileGridModels ;
2016-01-19 15:50:40 +01:00
2013-02-06 15:40:17 +01:00
} catch ( Exception e ) {
workspaceLogger . error ( " Error in server During items retrieving " , e ) ;
2013-07-08 17:42:08 +02:00
String error = ConstantsExplorer . SERVER_ERROR + RETRIEVING_ITEM_EITHER_ITEM_DOESN_T_EXIST ;
2013-06-14 15:04:43 +02:00
//GWT can't serialize all exceptions
throw new Exception ( error ) ;
}
}
2016-01-19 15:50:40 +01:00
2015-03-06 16:12:21 +01:00
/ * ( non - Javadoc )
* @see org . gcube . portlets . user . workspace . client . rpc . GWTWorkspaceService # getFolderChildrenForFileGridById ( java . lang . String )
* /
2017-02-20 11:41:54 +01:00
/ * *
* Gets the folder children for file grid by id .
*
* @param folderId the folder id
* @return the folder children for file grid by id
* @throws Exception the exception
* @throws SessionExpiredException the session expired exception
* /
2013-06-14 15:04:43 +02:00
@Override
2013-09-04 16:34:31 +02:00
public List < FileGridModel > getFolderChildrenForFileGridById ( String folderId ) throws Exception , SessionExpiredException {
2016-01-19 15:50:40 +01:00
2013-10-04 13:58:07 +02:00
2013-09-04 15:30:17 +02:00
if ( isSessionExpired ( ) )
throw new SessionExpiredException ( ) ;
2016-01-19 15:50:40 +01:00
2013-06-14 15:04:43 +02:00
try {
2013-10-04 13:58:07 +02:00
if ( folderId = = null )
2016-01-19 15:50:40 +01:00
throw new Exception ( " Folder id is null " ) ;
2013-10-04 13:58:07 +02:00
Workspace workspace = getWorkspace ( ) ;
workspaceLogger . trace ( " get children for Grid by id: " + folderId ) ;
2013-06-14 15:04:43 +02:00
List < FileGridModel > listFileGridModels = new ArrayList < FileGridModel > ( ) ;
2016-01-19 15:50:40 +01:00
2013-06-14 15:04:43 +02:00
if ( folderId = = null | | folderId . isEmpty ( ) ) {
2013-10-04 13:58:07 +02:00
workspaceLogger . trace ( " id is null or empty, return " ) ;
2013-06-14 15:04:43 +02:00
return listFileGridModels ;
}
2016-01-19 15:50:40 +01:00
2013-06-14 15:04:43 +02:00
workspaceLogger . trace ( " get children for Grid by id: " + folderId ) ;
GWTWorkspaceBuilder builder = getGWTWorkspaceBuilder ( ) ;
2016-01-19 15:50:40 +01:00
2013-06-14 15:04:43 +02:00
//BUILD PARENT
WorkspaceItem wsItem = workspace . getItem ( folderId ) ;
WorkspaceFolder parent ;
2013-09-24 15:51:02 +02:00
2013-06-14 15:04:43 +02:00
if ( wsItem . getType ( ) . equals ( WorkspaceItemType . SHARED_FOLDER ) | | wsItem . getType ( ) . equals ( WorkspaceItemType . FOLDER ) ) {
workspaceLogger . trace ( " item id: " + folderId + " is of type: " + wsItem . getType ( ) ) ;
2013-09-24 15:51:02 +02:00
parent = ( WorkspaceFolder ) wsItem ;
2016-01-19 15:50:40 +01:00
2013-06-14 15:04:43 +02:00
} else {
workspaceLogger . trace ( " item id: " + folderId + " is not a folder but of type: " + wsItem . getType ( ) + " , get parent " ) ;
parent = wsItem . getParent ( ) ;
}
2016-01-19 15:50:40 +01:00
2013-06-14 15:04:43 +02:00
if ( parent = = null )
return listFileGridModels ;
2016-01-19 15:50:40 +01:00
2013-06-14 15:04:43 +02:00
FileGridModel wsParent = builder . buildGXTFileGridModelItem ( parent , null ) ;
2016-01-19 15:50:40 +01:00
2013-09-24 15:51:02 +02:00
//PARENT BUILDED IS SHARED?
if ( parent . isShared ( ) ) {
wsParent . setShared ( true ) ;
wsParent . setShareable ( false ) ;
}
2016-01-19 15:50:40 +01:00
2013-06-14 15:04:43 +02:00
Long startTime = System . currentTimeMillis ( ) ;
2016-01-19 15:50:40 +01:00
2013-06-14 15:04:43 +02:00
//GET CHILDREN
2016-01-19 15:50:40 +01:00
List < WorkspaceItem > listItems = parent . getChildren ( ) ;
2013-06-14 15:04:43 +02:00
Long endTime = System . currentTimeMillis ( ) - startTime ;
String time = String . format ( " %d msc %d sec " , endTime , TimeUnit . MILLISECONDS . toSeconds ( endTime ) ) ;
2013-10-04 13:58:07 +02:00
workspaceLogger . debug ( " grid getChildren() returning " + listItems . size ( ) + " elements in " + time ) ;
2013-06-14 15:04:43 +02:00
listFileGridModels = builder . buildGXTListFileGridModelItem ( listItems , wsParent ) ;
return listFileGridModels ;
2016-01-19 15:50:40 +01:00
2013-06-14 15:04:43 +02:00
} catch ( Exception e ) {
workspaceLogger . error ( " Error in server During items retrieving " , e ) ;
2013-07-08 17:42:08 +02:00
String error = ConstantsExplorer . SERVER_ERROR + RETRIEVING_ITEM_EITHER_ITEM_DOESN_T_EXIST ;
2013-06-14 15:04:43 +02:00
throw new Exception ( error ) ;
2013-06-06 18:04:06 +02:00
}
}
2016-01-19 15:50:40 +01:00
2015-03-06 16:12:21 +01:00
/ * ( non - Javadoc )
* @see org . gcube . portlets . user . workspace . client . rpc . GWTWorkspaceService # getItemForFileGrid ( java . lang . String )
* /
2017-02-20 11:41:54 +01:00
/ * *
* Gets the item for file grid .
*
* @param itemId the item id
* @return the item for file grid
* @throws Exception the exception
* /
2013-06-06 18:04:06 +02:00
@Override
public FileGridModel getItemForFileGrid ( String itemId ) throws Exception {
2013-10-04 13:58:07 +02:00
2013-06-06 18:04:06 +02:00
try {
2016-01-19 15:50:40 +01:00
2013-10-04 13:58:07 +02:00
if ( itemId = = null )
2016-01-19 15:50:40 +01:00
throw new Exception ( IDENTIFIER_IS_NULL ) ;
2013-10-04 13:58:07 +02:00
Workspace workspace = getWorkspace ( ) ;
workspaceLogger . trace ( " get child for Grid by id: " + itemId ) ;
2013-06-06 18:04:06 +02:00
WorkspaceItem wsItem = workspace . getItem ( itemId ) ;
GWTWorkspaceBuilder builder = getGWTWorkspaceBuilder ( ) ;
Long startTime = System . currentTimeMillis ( ) ;
Long endTime = System . currentTimeMillis ( ) - startTime ;
String time = String . format ( " %d msc %d sec " , endTime , TimeUnit . MILLISECONDS . toSeconds ( endTime ) ) ;
2013-10-04 13:58:07 +02:00
workspaceLogger . debug ( " get child for Grid by id returning element in " + time ) ;
2013-06-10 11:42:36 +02:00
//BUILD PARENT
WorkspaceFolder folder = wsItem . getParent ( ) ; //get parent
FileGridModel wsFolder = builder . buildGXTFileGridModelItem ( folder , null ) ;
2016-01-19 15:50:40 +01:00
//BUILD ITEM
2013-06-10 11:42:36 +02:00
return builder . buildGXTFileGridModelItem ( wsItem , wsFolder ) ;
2013-06-06 18:04:06 +02:00
} catch ( Exception e ) {
2013-06-10 11:42:36 +02:00
workspaceLogger . error ( " Error in server during item retrieving, getItemForFileGrid " , e ) ;
2013-07-08 17:42:08 +02:00
String error = ConstantsExplorer . SERVER_ERROR + RETRIEVING_ITEM_EITHER_ITEM_DOESN_T_EXIST ;
2015-10-05 18:33:14 +02:00
throw new Exception ( error ) ;
}
}
2016-01-19 15:50:40 +01:00
2015-10-05 18:33:14 +02:00
/ * ( non - Javadoc )
* @see org . gcube . portlets . user . workspace . client . rpc . GWTWorkspaceService # getItemForFileTree ( java . lang . String )
* /
2017-02-20 11:41:54 +01:00
/ * *
* Gets the item for file tree .
*
* @param itemId the item id
* @return the item for file tree
* @throws Exception the exception
* /
2015-10-05 18:33:14 +02:00
@Override
public FileModel getItemForFileTree ( String itemId ) throws Exception {
try {
2016-01-19 15:50:40 +01:00
2015-10-05 18:33:14 +02:00
if ( itemId = = null )
2016-01-19 15:50:40 +01:00
throw new Exception ( IDENTIFIER_IS_NULL ) ;
2015-10-05 18:33:14 +02:00
Workspace workspace = getWorkspace ( ) ;
WorkspaceItem wsItem = workspace . getItem ( itemId ) ;
GWTWorkspaceBuilder builder = getGWTWorkspaceBuilder ( ) ;
//BUILD PARENT
WorkspaceFolder folderParent = wsItem . getParent ( ) ; //get parent
FileModel wsFolderParent = builder . buildGXTFileModelItem ( folderParent , null ) ;
2016-01-19 15:50:40 +01:00
//BUILD ITEM
2015-10-05 18:33:14 +02:00
return builder . buildGXTFileModelItem ( wsItem , wsFolderParent ) ;
} catch ( Exception e ) {
workspaceLogger . error ( " Error in server during item retrieving, getItemForFileGrid " , e ) ;
String error = ConstantsExplorer . SERVER_ERROR + RETRIEVING_ITEM_EITHER_ITEM_DOESN_T_EXIST ;
2013-06-10 11:42:36 +02:00
throw new Exception ( error ) ;
2013-02-06 15:40:17 +01:00
}
}
2016-01-19 15:50:40 +01:00
2015-03-06 16:12:21 +01:00
/ * ( non - Javadoc )
* @see org . gcube . portlets . user . workspace . client . rpc . GWTWorkspaceService # moveItem ( java . lang . String , java . lang . String )
* /
2017-02-20 11:41:54 +01:00
/ * *
* Move item .
*
* @param itemId the item id
* @param destinationId the destination id
* @return the boolean
* @throws Exception the exception
* /
2013-02-06 15:40:17 +01:00
@Override
public Boolean moveItem ( String itemId , String destinationId ) throws Exception {
2013-02-27 19:17:22 +01:00
workspaceLogger . trace ( " moveItem itemId: " + itemId + " destination: " + destinationId ) ;
2013-02-06 15:40:17 +01:00
2014-01-14 14:41:03 +01:00
if ( isSessionExpired ( ) )
throw new SessionExpiredException ( ) ;
2016-01-19 15:50:40 +01:00
2013-02-06 15:40:17 +01:00
try {
Workspace workspace = getWorkspace ( ) ;
2016-01-19 15:50:40 +01:00
2013-10-04 13:58:07 +02:00
if ( itemId = = null )
2016-01-19 15:50:40 +01:00
throw new Exception ( IDENTIFIER_IS_NULL ) ;
2013-10-04 13:58:07 +02:00
workspaceLogger . trace ( " moveItem item: " + itemId + " destination: " + destinationId ) ;
2013-02-27 19:17:22 +01:00
WorkspaceItem sourceItem = workspace . getItem ( itemId ) ; //GET SOURCE ITEM BEFORE OF MOVE
2016-01-19 15:50:40 +01:00
2013-02-27 19:17:22 +01:00
if ( sourceItem = = null )
return Boolean . FALSE ;
2016-01-19 15:50:40 +01:00
2013-02-27 19:17:22 +01:00
String sourceSharedId = null ;
boolean sourceItemIsShared = sourceItem . isShared ( ) ;
2016-01-19 15:50:40 +01:00
2013-02-27 19:17:22 +01:00
if ( sourceItemIsShared )
sourceSharedId = sourceItem . getIdSharedFolder ( ) ; //GET SHARED ID BEFORE OF MOVE
2014-07-14 17:21:43 +02:00
workspaceLogger . trace ( " moveItem item: " + itemId + " sourceItem name " + sourceItem . getName ( ) + " shared: " + sourceItemIsShared + " destination: " + destinationId ) ;
WorkspaceItem destinationItem = workspace . moveItem ( itemId , destinationId ) ; //move item
2013-02-27 19:17:22 +01:00
WorkspaceItem folderDestinationItem = workspace . getItem ( destinationId ) ; //retrieve folder destination
2014-07-14 17:21:43 +02:00
workspaceLogger . trace ( " sourceItem.isShared() " + sourceItemIsShared ) ;
workspaceLogger . trace ( " folderDestinationItem item: " + destinationId + " folderDestinationItem name " + folderDestinationItem . getName ( ) + " folderDestinationItem shared: " + folderDestinationItem . isShared ( ) ) ;
2016-01-19 15:50:40 +01:00
if ( folderDestinationItem ! = null ) {
2013-02-27 19:17:22 +01:00
try {
2014-07-14 17:21:43 +02:00
checkNotifyAddItemToShare ( destinationItem , sourceSharedId , folderDestinationItem ) ;
2013-06-13 18:44:46 +02:00
checkNotifyMoveItemFromShare ( sourceItemIsShared , sourceItem , sourceSharedId , folderDestinationItem ) ;
2016-01-19 15:50:40 +01:00
2013-02-27 19:17:22 +01:00
} catch ( Exception e ) {
workspaceLogger . error ( " An error occurred in checkNotify " , e ) ;
}
}
2016-01-19 15:50:40 +01:00
2013-02-06 15:40:17 +01:00
return Boolean . TRUE ;
2013-02-20 14:51:36 +01:00
} catch ( InsufficientPrivilegesException e ) {
workspaceLogger . error ( " Error in server Item move " , e ) ;
String error = " An error occurred on moving item. " + e . getMessage ( ) ;
throw new Exception ( error ) ;
2016-01-19 15:50:40 +01:00
2013-02-06 15:40:17 +01:00
} catch ( Exception e ) {
workspaceLogger . error ( " Error in server Item move " , e ) ;
2013-02-20 14:51:36 +01:00
String error = ConstantsExplorer . SERVER_ERROR + " moving item. " + e . getMessage ( ) ;
throw new Exception ( error ) ;
2013-02-06 15:40:17 +01:00
}
}
2016-01-19 15:50:40 +01:00
2015-03-06 16:12:21 +01:00
/ * ( non - Javadoc )
* @see org . gcube . portlets . user . workspace . client . rpc . GWTWorkspaceService # moveItems ( java . util . List , java . lang . String )
* /
2017-02-20 11:41:54 +01:00
/ * *
* Move items .
*
* @param ids the ids
* @param destinationId the destination id
* @return the boolean
* @throws Exception the exception
* /
2014-01-24 16:01:15 +01:00
@Override
public Boolean moveItems ( List < String > ids , String destinationId ) throws Exception {
workspaceLogger . trace ( " moveItems " + ids . size ( ) + " , destination: " + destinationId ) ;
if ( isSessionExpired ( ) )
throw new SessionExpiredException ( ) ;
2016-01-19 15:50:40 +01:00
2014-01-24 16:01:15 +01:00
boolean error = false ;
2016-01-19 15:50:40 +01:00
2014-01-24 16:01:15 +01:00
try {
Workspace workspace = getWorkspace ( ) ;
2016-01-19 15:50:40 +01:00
2014-01-24 16:01:15 +01:00
for ( String itemId : ids ) {
2016-01-19 15:50:40 +01:00
2014-01-24 16:01:15 +01:00
if ( itemId = = null )
2016-01-19 15:50:40 +01:00
throw new Exception ( IDENTIFIER_IS_NULL ) ;
2014-01-24 16:01:15 +01:00
workspaceLogger . trace ( " moveItem item: " + itemId + " destination: " + destinationId ) ;
WorkspaceItem sourceItem = workspace . getItem ( itemId ) ; //GET SOURCE ITEM BEFORE OF MOVE
2016-01-19 15:50:40 +01:00
2014-01-24 16:01:15 +01:00
if ( sourceItem = = null ) {
error = true ;
break ;
}
2016-01-19 15:50:40 +01:00
2014-01-24 16:01:15 +01:00
String sourceSharedId = null ;
boolean sourceItemIsShared = sourceItem . isShared ( ) ;
2016-01-19 15:50:40 +01:00
2014-01-24 16:01:15 +01:00
if ( sourceItemIsShared )
sourceSharedId = sourceItem . getIdSharedFolder ( ) ; //GET SHARED ID BEFORE OF MOVE
2014-07-14 17:23:07 +02:00
workspaceLogger . trace ( " moveItem item: " + itemId + " sourceItem name " + sourceItem . getName ( ) + " shared: " + sourceItemIsShared + " destination: " + destinationId ) ;
WorkspaceItem destinationItem = workspace . moveItem ( itemId , destinationId ) ; //move item
2014-01-24 16:01:15 +01:00
WorkspaceItem folderDestinationItem = workspace . getItem ( destinationId ) ; //retrieve folder destination
2014-07-14 17:23:07 +02:00
workspaceLogger . trace ( " sourceItem.isShared() " + sourceItemIsShared ) ;
workspaceLogger . trace ( " folderDestinationItem item: " + destinationId + " folderDestinationItem name " + folderDestinationItem . getName ( ) + " folderDestinationItem shared: " + folderDestinationItem . isShared ( ) ) ;
2014-01-24 16:01:15 +01:00
2016-01-19 15:50:40 +01:00
if ( folderDestinationItem ! = null ) {
2014-01-24 16:01:15 +01:00
try {
2014-07-14 17:23:07 +02:00
checkNotifyAddItemToShare ( destinationItem , sourceSharedId , folderDestinationItem ) ;
2016-01-19 15:50:40 +01:00
2014-01-24 16:01:15 +01:00
checkNotifyMoveItemFromShare ( sourceItemIsShared , sourceItem , sourceSharedId , folderDestinationItem ) ;
2016-01-19 15:50:40 +01:00
2014-01-24 16:01:15 +01:00
} catch ( Exception e ) {
workspaceLogger . error ( " An error occurred in checkNotify " , e ) ;
}
}
}
2016-01-19 15:50:40 +01:00
2014-01-24 16:01:15 +01:00
if ( error )
return Boolean . FALSE ;
2016-01-19 15:50:40 +01:00
2014-01-24 16:01:15 +01:00
return Boolean . TRUE ;
} catch ( InsufficientPrivilegesException e ) {
workspaceLogger . error ( " Error in server Item move " , e ) ;
String error1 = " An error occurred on moving item. " + e . getMessage ( ) ;
throw new Exception ( error1 ) ;
2016-01-19 15:50:40 +01:00
2014-01-24 16:01:15 +01:00
} catch ( Exception e ) {
workspaceLogger . error ( " Error in server Item move " , e ) ;
String error2 = ConstantsExplorer . SERVER_ERROR + " moving item. " + e . getMessage ( ) ;
throw new Exception ( error2 ) ;
}
}
2016-01-19 15:50:40 +01:00
2015-03-06 16:12:21 +01:00
/ * *
* Check notify add item to share .
*
* @param destinationItem the destination item
* @param sourceSharedId the source shared id
* @param folderDestinationItem the folder destination item
* /
2014-07-14 17:21:43 +02:00
private void checkNotifyAddItemToShare ( final WorkspaceItem destinationItem , final String sourceSharedId , final WorkspaceItem folderDestinationItem ) {
2016-01-19 15:50:40 +01:00
2013-02-28 12:32:45 +01:00
workspaceLogger . trace ( " checkNotifyAddItemToShare " ) ;
2016-01-19 15:50:40 +01:00
if ( folderDestinationItem ! = null ) {
2013-02-28 12:32:45 +01:00
try {
//if folder destination is shared folder
if ( folderDestinationItem . isShared ( ) ) { //Notify Added Item To Sharing?
2016-01-19 15:50:40 +01:00
2014-07-14 17:21:43 +02:00
workspaceLogger . trace ( " checkNotifyAddItemToShare destination item: " + destinationItem . getName ( ) + " sourceSharedId: " + sourceSharedId + " folder destination: " + folderDestinationItem . getName ( ) ) ;
2016-01-19 15:50:40 +01:00
2013-02-28 12:32:45 +01:00
//share condition is true if source shared folder is null or not equal to destination shared folder
2016-01-19 15:50:40 +01:00
boolean shareChangeCondition = sourceSharedId = = null | | sourceSharedId . compareTo ( folderDestinationItem . getIdSharedFolder ( ) ) ! = 0 ;
2013-02-28 12:32:45 +01:00
//System.out.println("shareChangeCondition add item: "+ shareChangeCondition);
2016-01-19 15:50:40 +01:00
2013-02-28 12:32:45 +01:00
workspaceLogger . trace ( " shareChangeCondition add item: " + shareChangeCondition ) ;
2016-01-19 15:50:40 +01:00
2013-02-28 12:32:45 +01:00
//if shareChangeCondition is true.. notifies added item to sharing
2016-01-19 15:50:40 +01:00
if ( shareChangeCondition ) {
2013-02-28 12:32:45 +01:00
List < InfoContactModel > listContacts = getListUserSharedByFolderSharedId ( folderDestinationItem . getIdSharedFolder ( ) ) ;
//DEBUG
printContacts ( listContacts ) ;
Workspace workspace = getWorkspace ( ) ;
WorkspaceItem destinationSharedFolder = workspace . getItem ( folderDestinationItem . getIdSharedFolder ( ) ) ;
NotificationsProducer np = getNotificationProducer ( ) ;
2016-01-19 15:50:40 +01:00
2014-05-14 15:47:17 +02:00
if ( destinationSharedFolder instanceof WorkspaceSharedFolder ) {
2014-07-14 17:21:43 +02:00
np . notifyAddedItemToSharing ( listContacts , destinationItem , ( WorkspaceSharedFolder ) destinationSharedFolder ) ;
2014-05-14 15:47:17 +02:00
workspaceLogger . trace ( " The notifies sent correctly " ) ;
}
else
2014-07-14 17:21:43 +02:00
workspaceLogger . warn ( " Notifies added item: " + destinationItem + " to share doesn't sent because " + destinationSharedFolder + " is not istance of WorkspaceSharedFolder " ) ;
2016-06-22 18:41:51 +02:00
// np.notifyAddedItemToSharing(listContacts, (WorkspaceFolder) folderDestinationItem);
2016-01-19 15:50:40 +01:00
}
2013-02-28 12:32:45 +01:00
}
else
workspaceLogger . trace ( " folder destination is not shared " ) ;
2016-01-19 15:50:40 +01:00
2013-02-28 12:32:45 +01:00
} catch ( Exception e ) {
workspaceLogger . error ( " An error occurred in verifyNotifyAddItemToShare " , e ) ;
2013-02-27 19:17:22 +01:00
}
} else
2016-01-19 15:50:40 +01:00
workspaceLogger . warn ( " The notifies is failure in verifyNotifyAddItemToShare because folder destination item is null " ) ;
2013-02-27 19:17:22 +01:00
}
2016-01-19 15:50:40 +01:00
2013-02-27 19:17:22 +01:00
2015-03-06 16:12:21 +01:00
/ * *
* Check notify move item from share .
*
* @param sourceItemIsShared the source item is shared
* @param sourceItem the source item
* @param sourceSharedId the source shared id
* @param folderDestinationItem the folder destination item
* /
2013-06-13 18:44:46 +02:00
private void checkNotifyMoveItemFromShare ( final boolean sourceItemIsShared , final WorkspaceItem sourceItem , final String sourceSharedId , final WorkspaceItem folderDestinationItem ) {
2016-01-19 15:50:40 +01:00
2013-06-13 18:44:46 +02:00
workspaceLogger . trace ( " checkNotifyMoveItemFromShare: " ) ;
2016-01-19 15:50:40 +01:00
2013-02-28 12:32:45 +01:00
try {
2016-01-19 15:50:40 +01:00
if ( folderDestinationItem ! = null ) {
2013-02-28 12:32:45 +01:00
String idSharedFolder = folderDestinationItem . getIdSharedFolder ( ) ! = null ? folderDestinationItem . getIdSharedFolder ( ) : " " ;
2016-01-19 15:50:40 +01:00
2013-02-28 12:32:45 +01:00
//share condition is true if source shared folder is not equal to destination shared folder
2016-01-19 15:50:40 +01:00
boolean shareChangeCondition = sourceSharedId = = null ? false : sourceSharedId . compareTo ( idSharedFolder ) ! = 0 ;
2013-06-13 18:44:46 +02:00
workspaceLogger . trace ( " checkNotifyMoveItemFromShare source item: " + sourceItem . getName ( ) + " sourceSharedId: " + sourceSharedId + " folder destination: " + folderDestinationItem . getName ( ) + " sourceItemIsShared: " + sourceItemIsShared ) ;
2016-01-19 15:50:40 +01:00
2016-06-22 18:41:51 +02:00
// System.out.println("shareChangeCondition remove item: "+ shareChangeCondition);
2016-01-19 15:50:40 +01:00
2013-02-28 12:32:45 +01:00
workspaceLogger . trace ( " shareChangeCondition remove item: " + shareChangeCondition ) ;
2016-01-19 15:50:40 +01:00
2013-02-28 12:32:45 +01:00
//Notify Removed Item To Sharing?
//if source Item is shared and folder destination is not shared or shareChangeCondition is true.. notifies removed item to sharing
if ( sourceItemIsShared & & ( ! folderDestinationItem . isShared ( ) | | shareChangeCondition ) ) {
2016-01-19 15:50:40 +01:00
2016-06-22 18:41:51 +02:00
//get contacts
List < InfoContactModel > listContacts = getListUserSharedByFolderSharedId ( sourceSharedId ) ;
2016-01-19 15:50:40 +01:00
2016-06-22 18:41:51 +02:00
//DEBUG
printContacts ( listContacts ) ;
Workspace workspace = getWorkspace ( ) ;
WorkspaceItem sourceSharedFolder = workspace . getItem ( sourceSharedId ) ;
NotificationsProducer np = getNotificationProducer ( ) ;
2016-01-19 15:50:40 +01:00
2016-06-22 18:41:51 +02:00
if ( sourceSharedFolder instanceof WorkspaceSharedFolder ) {
np . notifyMovedItemToSharing ( listContacts , sourceItem , ( WorkspaceSharedFolder ) sourceSharedFolder ) ;
workspaceLogger . trace ( " The notifies was sent correctly " ) ;
} else
workspaceLogger . warn ( " Notifies moved item: " + sourceItem + " from share doesn't sent because " + sourceSharedFolder + " is not istance of WorkspaceSharedFolder " ) ;
2013-02-28 12:32:45 +01:00
}
} else
2013-06-13 18:44:46 +02:00
workspaceLogger . warn ( " The notifies is failure in checkNotifyMoveItemFromShare because folder destination item is null " ) ;
2016-01-19 15:50:40 +01:00
2013-02-28 12:32:45 +01:00
} catch ( Exception e ) {
2013-06-13 18:44:46 +02:00
workspaceLogger . error ( " An error occurred in checkNotifyMoveItemFromShare " , e ) ;
2013-02-28 12:32:45 +01:00
}
2013-02-27 19:17:22 +01:00
}
2016-01-19 15:50:40 +01:00
2013-02-27 19:17:22 +01:00
//DEBUG
2015-03-06 16:12:21 +01:00
/ * *
* Prints the contacts .
*
* @param listContacts the list contacts
* /
2013-02-27 19:17:22 +01:00
private void printContacts ( List < InfoContactModel > listContacts ) {
2016-01-19 15:50:40 +01:00
2015-02-16 15:36:11 +01:00
workspaceLogger . trace ( " Contacts: " ) ;
2013-02-27 19:17:22 +01:00
for ( InfoContactModel infoContactModel : listContacts ) {
2016-06-22 18:41:51 +02:00
workspaceLogger . trace ( " User: " + infoContactModel ) ;
2013-02-27 19:17:22 +01:00
}
}
2015-06-24 16:56:13 +02:00
2014-09-24 16:51:42 +02:00
//DEBUG
2015-03-06 16:12:21 +01:00
/ * *
* Prints the list .
*
* @param list the list
* /
2014-09-24 16:51:42 +02:00
private void printList ( List < String > list ) {
for ( String string : list ) {
workspaceLogger . trace ( string ) ;
}
}
2013-02-06 15:40:17 +01:00
2015-03-06 16:12:21 +01:00
/ * ( non - Javadoc )
* @see org . gcube . portlets . user . workspace . client . rpc . GWTWorkspaceService # removeItem ( java . lang . String )
* /
2017-02-20 11:41:54 +01:00
/ * *
* Removes the item .
*
* @param itemId the item id
* @return the boolean
* @throws Exception the exception
* /
2013-02-06 15:40:17 +01:00
@Override
public Boolean removeItem ( String itemId ) throws Exception {
2016-01-19 15:50:40 +01:00
2013-02-06 15:40:17 +01:00
try {
2016-01-19 15:50:40 +01:00
2013-10-04 13:58:07 +02:00
if ( itemId = = null )
2016-01-19 15:50:40 +01:00
throw new Exception ( IDENTIFIER_IS_NULL ) ;
2013-02-06 15:40:17 +01:00
Workspace workspace = getWorkspace ( ) ;
2013-10-04 13:58:07 +02:00
workspaceLogger . trace ( " removeItem item for id: " + itemId ) ;
2013-06-13 18:44:46 +02:00
//NOTIFICATION
WorkspaceItem wsItem = workspace . getItem ( itemId ) ;
//SAVING ATTRIBUTE FOR NOTIFICATION
boolean sourceItemIsShared = wsItem . isShared ( ) ;
String itemName = wsItem . getName ( ) ;
String sourceFolderSharedId = null ;
2013-10-04 13:58:07 +02:00
2015-06-24 16:56:13 +02:00
if ( sourceItemIsShared )
2013-06-13 18:44:46 +02:00
sourceFolderSharedId = wsItem . getIdSharedFolder ( ) ;
2016-01-19 15:50:40 +01:00
2013-06-13 18:44:46 +02:00
//REMOVE ITEM
2013-02-06 15:40:17 +01:00
workspace . removeItem ( itemId ) ;
2013-06-13 18:44:46 +02:00
//IF SOURCE SHARED FOLDER IS NOT NULL
if ( sourceFolderSharedId ! = null )
2016-11-25 12:03:25 +01:00
NotificationsUtil . checkSendNotifyRemoveItemToShare ( this . getThreadLocalRequest ( ) , sourceItemIsShared , itemName , itemId , sourceFolderSharedId ) ;
2015-06-24 16:56:13 +02:00
2013-02-06 15:40:17 +01:00
return Boolean . TRUE ;
2016-01-19 15:50:40 +01:00
2013-02-20 14:51:36 +01:00
} catch ( InsufficientPrivilegesException e ) {
workspaceLogger . error ( " Error in server Item remove " , e ) ;
2014-02-19 17:13:49 +01:00
String error = " Insufficient Privileges to remove the item " ;
2013-02-20 14:51:36 +01:00
throw new Exception ( error ) ;
2013-02-06 15:40:17 +01:00
2013-06-25 15:33:03 +02:00
} catch ( ItemNotFoundException e ) {
String error = " An error occurred on deleting item. " + ConstantsExplorer . ERROR_ITEM_DOES_NOT_EXIST ;
workspaceLogger . error ( error , e ) ;
throw new Exception ( error ) ;
2013-02-06 15:40:17 +01:00
} catch ( Exception e ) {
workspaceLogger . error ( " Error in server Item remove " , e ) ;
2013-02-20 14:51:36 +01:00
String error = ConstantsExplorer . SERVER_ERROR + " deleting item. " + e . getMessage ( ) ;
throw new Exception ( error ) ;
2013-02-06 15:40:17 +01:00
}
}
2015-03-06 16:12:21 +01:00
/ * ( non - Javadoc )
* @see org . gcube . portlets . user . workspace . client . rpc . GWTWorkspaceService # renameItem ( java . lang . String , java . lang . String , java . lang . String )
* /
2017-02-20 11:41:54 +01:00
/ * *
* Rename item .
*
* @param itemId the item id
* @param newName the new name
* @param previousName the previous name
* @return the boolean
* @throws Exception the exception
* /
2013-02-06 15:40:17 +01:00
@Override
2013-03-25 17:35:27 +01:00
public Boolean renameItem ( String itemId , String newName , String previousName ) throws Exception {
2016-01-19 15:50:40 +01:00
2014-01-14 14:41:03 +01:00
if ( isSessionExpired ( ) )
throw new SessionExpiredException ( ) ;
2016-01-19 15:50:40 +01:00
2013-02-06 15:40:17 +01:00
try {
2016-01-19 15:50:40 +01:00
2013-10-04 13:58:07 +02:00
if ( itemId = = null )
2016-01-19 15:50:40 +01:00
throw new Exception ( IDENTIFIER_IS_NULL ) ;
2013-02-06 15:40:17 +01:00
Workspace workspace = getWorkspace ( ) ;
2013-10-04 13:58:07 +02:00
workspaceLogger . trace ( " rename item itemId: " + itemId + " old name " + previousName + " , new name: " + newName ) ;
2013-02-06 15:40:17 +01:00
workspace . renameItem ( itemId , newName ) ;
2013-03-25 11:14:26 +01:00
//NOTIFIER
WorkspaceItem wsItem = workspace . getItem ( itemId ) ;
2016-01-19 15:50:40 +01:00
2013-03-25 11:14:26 +01:00
if ( wsItem . isShared ( ) ) {
2016-01-19 15:50:40 +01:00
2013-03-25 11:14:26 +01:00
try {
List < InfoContactModel > listSharedContact = new ArrayList < InfoContactModel > ( ) ;
NotificationsProducer notification = getNotificationProducer ( ) ;
listSharedContact = getListUserSharedByFolderSharedId ( wsItem . getIdSharedFolder ( ) ) ;
2013-06-13 18:44:46 +02:00
if ( NotificationsUtil . isASharedFolder ( wsItem ) ) {
notification . notifyFolderRenamed ( listSharedContact , wsItem , previousName , newName , wsItem . getIdSharedFolder ( ) ) ;
2013-03-25 11:14:26 +01:00
} else {
2016-01-19 15:50:40 +01:00
2014-05-14 15:47:17 +02:00
//TWO CASES: EITHER ROOT FOLDER AS WorkspaceSharedFolder OR DOESN'T.
WorkspaceItem sharedFolder = workspace . getItem ( wsItem . getIdSharedFolder ( ) ) ;
if ( sharedFolder instanceof WorkspaceSharedFolder )
notification . notifyItemRenamed ( listSharedContact , previousName , wsItem , ( WorkspaceSharedFolder ) sharedFolder ) ;
else
workspaceLogger . trace ( " Notifies for rename item itemId: " + itemId + " doesn't sent because: " + sharedFolder + " is not an instance of WorkspaceSharedFolder " ) ;
2013-03-25 11:14:26 +01:00
}
} catch ( Exception e ) {
workspaceLogger . error ( " An error occurred in checkNotify " , e ) ;
return true ;
}
}
2013-02-06 15:40:17 +01:00
return true ;
2016-01-19 15:50:40 +01:00
2014-02-12 19:46:39 +01:00
} catch ( InsufficientPrivilegesException e ) {
2014-02-13 18:40:59 +01:00
String error = " Insufficient Privileges to rename the item " ;
2014-02-12 19:46:39 +01:00
workspaceLogger . error ( error , e ) ;
throw new Exception ( error ) ;
2013-03-26 17:31:13 +01:00
} catch ( ItemAlreadyExistException e ) {
2013-06-25 15:33:03 +02:00
String error = " An error occurred on renaming item, " + e . getMessage ( ) ;
workspaceLogger . error ( error , e ) ;
throw new Exception ( error ) ;
} catch ( ItemNotFoundException e2 ) {
String error = " An error occurred on renaming item. " + ConstantsExplorer . ERROR_ITEM_DOES_NOT_EXIST ;
workspaceLogger . error ( error , e2 ) ;
2013-03-26 17:31:13 +01:00
throw new Exception ( error ) ;
2013-02-06 15:40:17 +01:00
} catch ( Exception e ) {
2013-06-25 15:33:03 +02:00
String error = ConstantsExplorer . SERVER_ERROR + " renaming item. " + ConstantsExplorer . TRY_AGAIN ;
workspaceLogger . error ( error , e ) ;
throw new Exception ( error ) ;
2013-02-06 15:40:17 +01:00
}
}
2016-01-19 15:50:40 +01:00
2015-03-06 16:12:21 +01:00
/ * ( non - Javadoc )
* @see org . gcube . portlets . user . workspace . client . rpc . GWTWorkspaceService # createFolder ( java . lang . String , java . lang . String , org . gcube . portlets . user . workspace . client . model . FileModel )
* /
2017-02-20 11:41:54 +01:00
/ * *
* Creates the folder .
*
* @param nameFolder the name folder
* @param description the description
* @param parent the parent
* @return the folder model
* @throws Exception the exception
* /
2013-02-06 15:40:17 +01:00
@Override
public FolderModel createFolder ( String nameFolder , String description , FileModel parent ) throws Exception {
2016-01-19 15:50:40 +01:00
2013-10-04 13:58:07 +02:00
workspaceLogger . trace ( " create folder: " + nameFolder + " parent is null " + parent = = null ) ;
2013-02-06 15:40:17 +01:00
2016-10-24 14:43:33 +02:00
if ( isSessionExpired ( ) )
throw new SessionExpiredException ( ) ;
2013-02-06 15:40:17 +01:00
try {
2016-01-19 15:50:40 +01:00
2013-10-04 13:58:07 +02:00
if ( nameFolder = = null )
2016-01-19 15:50:40 +01:00
throw new Exception ( " Folder name is null " ) ;
2013-10-04 13:58:07 +02:00
Workspace workspace = getWorkspace ( ) ;
2013-02-06 15:40:17 +01:00
WorkspaceFolder wsFolder = workspace . createFolder ( nameFolder , description , parent . getIdentifier ( ) ) ;
2013-02-27 19:17:22 +01:00
WorkspaceItem folderDestinationItem = workspace . getItem ( parent . getIdentifier ( ) ) ;
checkNotifyAddItemToShare ( wsFolder , null , folderDestinationItem ) ;
2013-02-06 15:40:17 +01:00
GWTWorkspaceBuilder builder = getGWTWorkspaceBuilder ( ) ;
return builder . buildGXTFolderModelItem ( wsFolder , parent ) ;
2014-02-13 18:40:59 +01:00
} catch ( InsufficientPrivilegesException e ) {
String error = " Insufficient Privileges to create the folder " ;
workspaceLogger . error ( error , e ) ;
throw new Exception ( error ) ;
} catch ( ItemAlreadyExistException e ) {
String error = " An error occurred on creating folder, " + e . getMessage ( ) ;
workspaceLogger . error ( error , e ) ;
throw new Exception ( error ) ;
2013-02-06 15:40:17 +01:00
} catch ( Exception e ) {
2014-02-13 18:40:59 +01:00
String error = ConstantsExplorer . SERVER_ERROR + " creating folder. " + ConstantsExplorer . TRY_AGAIN ;
workspaceLogger . error ( error , e ) ;
throw new Exception ( error ) ;
2013-02-06 15:40:17 +01:00
}
2016-01-19 15:50:40 +01:00
2013-02-06 15:40:17 +01:00
}
2015-03-06 16:12:21 +01:00
/ * ( non - Javadoc )
* @see org . gcube . portlets . user . workspace . client . rpc . GWTWorkspaceService # getDetailsFile ( org . gcube . portlets . user . workspace . client . model . FileModel )
* /
2017-02-20 11:41:54 +01:00
/ * *
* Gets the details file .
*
* @param folder the folder
* @return the details file
* @throws Exception the exception
* /
2013-02-06 15:40:17 +01:00
@Override
public FileDetailsModel getDetailsFile ( FileModel folder ) throws Exception {
2016-01-19 15:50:40 +01:00
2013-02-06 15:40:17 +01:00
try {
2016-01-19 15:50:40 +01:00
2013-10-04 13:58:07 +02:00
if ( folder = = null )
2016-01-19 15:50:40 +01:00
throw new Exception ( " Folder is null " ) ;
2013-10-04 13:58:07 +02:00
workspaceLogger . trace ( " load file details: " + folder . getName ( ) ) ;
Workspace workspace = getWorkspace ( ) ;
2013-02-06 15:40:17 +01:00
WorkspaceItem wsItem = workspace . getItem ( folder . getIdentifier ( ) ) ;
GWTWorkspaceBuilder builder = getGWTWorkspaceBuilder ( ) ;
2016-01-19 15:50:40 +01:00
2013-02-06 15:40:17 +01:00
return builder . buildGWTWorkspaceFileDetails ( wsItem , folder ) ;
} catch ( Exception e ) {
workspaceLogger . error ( " Error in load server file details " , e ) ;
throw new Exception ( e . getMessage ( ) ) ;
}
}
2016-01-19 15:50:40 +01:00
2015-03-06 16:12:21 +01:00
/ * ( non - Javadoc )
* @see org . gcube . portlets . user . workspace . client . rpc . GWTWorkspaceService # getChildrenSubTreeToRootByIdentifier ( java . lang . String )
* /
2017-02-20 11:41:54 +01:00
/ * *
* Gets the children sub tree to root by identifier .
*
* @param itemIdentifier the item identifier
* @return the children sub tree to root by identifier
* @throws Exception the exception
* /
2013-02-06 15:40:17 +01:00
@Override
public ArrayList < SubTree > getChildrenSubTreeToRootByIdentifier ( String itemIdentifier ) throws Exception {
2016-01-19 15:50:40 +01:00
2013-02-06 15:40:17 +01:00
ArrayList < SubTree > listSubTree = new ArrayList < SubTree > ( ) ;
2016-01-19 15:50:40 +01:00
2013-02-06 15:40:17 +01:00
try {
2016-01-19 15:50:40 +01:00
2013-10-04 13:58:07 +02:00
if ( itemIdentifier = = null )
2016-01-19 15:50:40 +01:00
throw new Exception ( IDENTIFIER_IS_NULL ) ;
2013-02-06 15:40:17 +01:00
Workspace workspace = getWorkspace ( ) ;
2013-10-04 13:58:07 +02:00
workspaceLogger . trace ( " search itemId: " + itemIdentifier ) ;
2016-01-19 15:50:40 +01:00
WorkspaceItem item = workspace . getItem ( itemIdentifier ) ; //get item from workspace
2015-09-18 16:51:38 +02:00
getListsChildrenByParent ( listSubTree , item ) ;
2013-02-06 15:40:17 +01:00
Collections . reverse ( listSubTree ) ; //reverse order of array
2016-01-19 15:50:40 +01:00
2015-09-18 16:51:38 +02:00
//SET THE ROOT
2015-09-18 17:19:09 +02:00
int lenght = listSubTree . size ( ) ;
if ( lenght > 0 ) {
FolderModel firstLevel = listSubTree . get ( 0 ) . getParent ( ) ; //get root
workspaceLogger . trace ( " set: " + firstLevel . getName ( ) + " as root " ) ;
2015-09-18 16:51:38 +02:00
listSubTree . get ( 0 ) . getParent ( ) . setIsRoot ( true ) ;
2015-09-18 17:19:09 +02:00
//IF IT CASE - REWRITE SPECIAL FOLDER NAME
if ( lenght > 1 ) {
FolderModel wsFolder = listSubTree . get ( 1 ) . getParent ( ) ; //get first child
String nameSpecialFolder = getNameForSpecialFolder ( ) ;
if ( wsFolder . getName ( ) . compareTo ( ConstantsExplorer . MY_SPECIAL_FOLDERS ) = = 0 & & firstLevel . isRoot ( ) ) {
//MANAGEMENT SPECIAL FOLDER
workspaceLogger . debug ( " getChildrenSubTreeToRootByIdentifier MANAGEMENT SPECIAL FOLDER NAME REWRITING AS: " + nameSpecialFolder ) ;
if ( nameSpecialFolder ! = null & & ! nameSpecialFolder . isEmpty ( ) )
listSubTree . get ( 1 ) . getParent ( ) . setName ( nameSpecialFolder ) ;
}
}
2015-09-18 16:51:38 +02:00
}
2016-01-19 15:50:40 +01:00
2015-09-18 17:19:09 +02:00
workspaceLogger . trace ( " getChildrenSubTreeToRootByIdentifier returning list SubTree: " + listSubTree ) ;
2013-02-06 15:40:17 +01:00
} catch ( Exception e ) {
workspaceLogger . error ( " Error in server find Item " , e ) ;
throw new Exception ( e . getMessage ( ) ) ;
}
2016-01-19 15:50:40 +01:00
2013-02-06 15:40:17 +01:00
return listSubTree ;
}
2016-01-19 15:50:40 +01:00
2015-03-06 16:12:21 +01:00
/ * ( non - Javadoc )
* @see org . gcube . portlets . user . workspace . client . rpc . GWTWorkspaceService # getSmartFolderResultsByCategory ( java . lang . String )
* /
2017-02-20 11:41:54 +01:00
/ * *
* Gets the smart folder results by category .
*
* @param category the category
* @return the smart folder results by category
* @throws Exception the exception
* /
2013-02-06 15:40:17 +01:00
@Override
2016-09-29 15:28:32 +02:00
public List < FileGridModel > getSmartFolderResultsByCategory ( GXTCategorySmartFolder category ) throws Exception {
2016-01-19 15:50:40 +01:00
2013-02-06 15:40:17 +01:00
try {
2016-01-19 15:50:40 +01:00
2013-02-06 15:40:17 +01:00
Workspace workspace = getWorkspace ( ) ;
2013-10-04 13:58:07 +02:00
workspaceLogger . trace ( " get smart folder by category: " + category ) ;
2013-02-06 15:40:17 +01:00
GWTWorkspaceBuilder builder = getGWTWorkspaceBuilder ( ) ;
List < SearchItem > listWorkspaceItems = new ArrayList < SearchItem > ( ) ;
2016-01-19 15:50:40 +01:00
2013-02-06 15:40:17 +01:00
//Category IMAGES
2016-09-29 15:28:32 +02:00
if ( category . equals ( GXTCategorySmartFolder . SMF_IMAGES ) ) {
2013-02-06 15:40:17 +01:00
listWorkspaceItems = workspace . getFolderItems ( FolderItemType . IMAGE_DOCUMENT , FolderItemType . EXTERNAL_IMAGE ) ;
2016-06-22 18:41:51 +02:00
//Category BIODIVERSITY
2016-09-29 15:28:32 +02:00
} else if ( category . equals ( GXTCategorySmartFolder . SMF_BIODIVERSITY ) ) {
2016-06-22 18:41:51 +02:00
// listWorkspaceItems = workspace.getFolderItems(FolderItemType.AQUAMAPS_ITEM);
//Category DOCUMENTS
2016-09-29 15:28:32 +02:00
} else if ( category . equals ( GXTCategorySmartFolder . SMF_DOCUMENTS ) ) {
2016-01-19 15:50:40 +01:00
2013-02-06 15:40:17 +01:00
listWorkspaceItems = workspace . getFolderItems (
2016-01-19 15:50:40 +01:00
FolderItemType . EXTERNAL_FILE ,
2013-02-06 15:40:17 +01:00
FolderItemType . EXTERNAL_PDF_FILE ,
FolderItemType . QUERY ,
FolderItemType . PDF_DOCUMENT ,
FolderItemType . METADATA ,
FolderItemType . DOCUMENT
) ;
2016-01-19 15:50:40 +01:00
2016-06-22 18:41:51 +02:00
//Category LINKS
2016-09-29 15:28:32 +02:00
} else if ( category . equals ( GXTCategorySmartFolder . SMF_LINKS ) ) {
2016-06-22 18:41:51 +02:00
// listWorkspaceItems = workspace.getFolderItems(FolderItemType.EXTERNAL_URL, FolderItemType.URL_DOCUMENT, FolderItemType.EXTERNAL_RESOURCE_LINK);
//Category REPORTS
2016-09-29 15:28:32 +02:00
} else if ( category . equals ( GXTCategorySmartFolder . SMF_REPORTS ) ) {
2013-02-06 15:40:17 +01:00
listWorkspaceItems = workspace . getFolderItems ( FolderItemType . REPORT_TEMPLATE , FolderItemType . REPORT ) ;
2016-06-22 18:41:51 +02:00
//Category TIME SERIES
2016-09-29 15:28:32 +02:00
} else if ( category . equals ( GXTCategorySmartFolder . SMF_TIMESERIES ) ) {
2013-02-06 15:40:17 +01:00
listWorkspaceItems = workspace . getFolderItems ( FolderItemType . TIME_SERIES ) ;
}
2016-09-29 15:28:32 +02:00
else if ( category . equals ( GXTCategorySmartFolder . SMF_PUBLIC_FOLDERS ) ) {
List < WorkspaceItem > listFolder = workspace . getPublicFolders ( ) ;
if ( listFolder = = null | | listFolder . isEmpty ( ) )
return new ArrayList < FileGridModel > ( ) ;
return builder . buildGXTListFileGridModelItem ( listFolder , null ) ;
} else
2013-02-06 15:40:17 +01:00
new Exception ( " Smart folder category unknown " ) ;
return builder . filterListFileGridModelItemByCategory ( listWorkspaceItems , category ) ;
2016-01-19 15:50:40 +01:00
2013-02-06 15:40:17 +01:00
} catch ( Exception e ) {
workspaceLogger . error ( " Error in server get smart folder by category " , e ) ;
throw new Exception ( e . getMessage ( ) ) ;
}
2016-01-19 15:50:40 +01:00
2013-02-06 15:40:17 +01:00
}
2015-09-18 15:26:33 +02:00
2015-03-06 16:12:21 +01:00
/ * *
* Gets the lists children by parents .
*
* @param listSubTree the list sub tree
2015-09-18 15:26:33 +02:00
* @param parent the parent
2015-03-06 16:12:21 +01:00
* @return the lists children by parents
* @throws Exception the exception
* /
2015-09-18 16:51:38 +02:00
private void getListsChildrenByParent ( ArrayList < SubTree > listSubTree , WorkspaceItem parent ) throws Exception {
2016-01-19 15:50:40 +01:00
2016-06-22 18:41:51 +02:00
if ( parent = = null )
return ;
2015-06-24 16:56:13 +02:00
2016-06-22 18:41:51 +02:00
if ( ! parent . isFolder ( ) ) {
workspaceLogger . warn ( " getListsChildrenByParent returning: " + parent . getName ( ) + " is not a folder " ) ;
return ;
}
2016-01-19 15:50:40 +01:00
2016-06-22 18:41:51 +02:00
workspaceLogger . trace ( " getListsChildrenByParent: " + parent . getName ( ) ) ;
GWTWorkspaceBuilder builder = getGWTWorkspaceBuilder ( ) ;
FolderModel parentModel = ( FolderModel ) builder . buildGXTFileModelItem ( parent , null ) ; //get folder
2015-09-18 16:51:38 +02:00
List < FileModel > childrenList = getFolderChildren ( parentModel ) ; //get children
2013-02-06 15:40:17 +01:00
SubTree subTree = new SubTree ( parentModel , childrenList ) ;
2016-06-22 18:41:51 +02:00
listSubTree . add ( subTree ) ;
getListsChildrenByParent ( listSubTree , parent . getParent ( ) ) ;
}
2013-02-06 15:40:17 +01:00
2015-03-06 16:12:21 +01:00
/ * ( non - Javadoc )
* @see org . gcube . portlets . user . workspace . client . rpc . GWTWorkspaceService # createSmartFolder ( java . lang . String , java . lang . String , java . lang . String )
* /
2017-02-20 11:41:54 +01:00
/ * *
* Creates the smart folder .
*
* @param name the name
* @param description the description
* @param query the query
* @param parentId the parent id
* @return the smart folder model
* @throws Exception the exception
* /
2013-02-06 15:40:17 +01:00
@Override
2015-10-12 15:30:59 +02:00
public SmartFolderModel createSmartFolder ( String name , String description , String query , String parentId ) throws Exception {
2016-01-19 15:50:40 +01:00
2016-10-24 14:43:33 +02:00
if ( isSessionExpired ( ) )
throw new SessionExpiredException ( ) ;
2013-02-06 15:40:17 +01:00
try {
2016-01-19 15:50:40 +01:00
2013-02-06 15:40:17 +01:00
Workspace workspace = getWorkspace ( ) ;
2016-01-19 15:50:40 +01:00
workspaceLogger . trace ( " create smart folder by name: " + name ) ;
2013-10-04 13:58:07 +02:00
workspaceLogger . trace ( " description " + description ) ;
2013-02-06 15:40:17 +01:00
workspaceLogger . trace ( " query " + query ) ;
2015-10-12 15:30:59 +02:00
workspaceLogger . trace ( " parentId " + parentId ) ;
if ( parentId = = null | | parentId . isEmpty ( ) ) {
workspaceLogger . trace ( " parent id is null using root id " ) ;
parentId = workspace . getRoot ( ) . getId ( ) ;
}
2016-01-19 15:50:40 +01:00
WorkspaceSmartFolder wsSmartFolder = workspace . createSmartFolder ( name , description , query , parentId ) ; //create Smart Folder from workspace
2013-02-06 15:40:17 +01:00
workspaceLogger . trace ( " create : " + wsSmartFolder . getName ( ) + " id " + wsSmartFolder . getId ( ) ) ;
GWTWorkspaceBuilder builder = getGWTWorkspaceBuilder ( ) ;
return builder . buildGXTSmartFolderModel ( wsSmartFolder , query ) ;
2016-01-19 15:50:40 +01:00
2013-02-06 15:40:17 +01:00
} catch ( Exception e ) {
workspaceLogger . error ( " Error in server create smart folder by name: " , e ) ;
2016-06-22 18:41:51 +02:00
// workspaceLogger.trace("Error in server create smart folder by id " + e);
2013-02-06 15:40:17 +01:00
//GWT can't serialize all exceptions
throw new Exception ( e . getMessage ( ) ) ;
}
}
2016-01-19 15:50:40 +01:00
2015-03-06 16:12:21 +01:00
/ * ( non - Javadoc )
* @see org . gcube . portlets . user . workspace . client . rpc . GWTWorkspaceService # removeSmartFolder ( java . lang . String , java . lang . String )
* /
2017-02-20 11:41:54 +01:00
/ * *
* Removes the smart folder .
*
* @param itemId the item id
* @param name the name
* @return the boolean
* @throws Exception the exception
* /
2013-02-06 15:40:17 +01:00
@Override
public Boolean removeSmartFolder ( String itemId , String name ) throws Exception {
2016-01-19 15:50:40 +01:00
2013-10-04 13:58:07 +02:00
if ( itemId = = null )
return null ;
2016-01-19 15:50:40 +01:00
2013-02-06 15:40:17 +01:00
try {
2016-01-19 15:50:40 +01:00
2013-02-06 15:40:17 +01:00
Workspace workspace = getWorkspace ( ) ;
2013-10-04 13:58:07 +02:00
workspaceLogger . trace ( " remove smart folder by id: " + itemId ) ;
2016-01-19 15:50:40 +01:00
workspace . removeItem ( itemId ) ; //remove Smart Folder from workspace
2013-02-06 15:40:17 +01:00
return true ;
2016-01-19 15:50:40 +01:00
2013-02-06 15:40:17 +01:00
} catch ( Exception e ) {
workspaceLogger . error ( " Error in remove smart folder by id: " , e ) ;
throw new Exception ( e . getMessage ( ) ) ;
}
}
2016-01-19 15:50:40 +01:00
2015-03-06 16:12:21 +01:00
/ * ( non - Javadoc )
* @see org . gcube . portlets . user . workspace . client . rpc . GWTWorkspaceService # getAllSmartFolders ( )
* /
2017-02-20 11:41:54 +01:00
/ * *
* Gets the all smart folders .
*
* @return the all smart folders
* @throws Exception the exception
* /
2013-02-06 15:40:17 +01:00
@Override
public List < SmartFolderModel > getAllSmartFolders ( ) throws Exception {
2016-01-19 15:50:40 +01:00
2013-02-06 15:40:17 +01:00
try {
2016-01-19 15:50:40 +01:00
2013-02-06 15:40:17 +01:00
Workspace workspace = getWorkspace ( ) ;
2013-10-04 13:58:07 +02:00
workspaceLogger . trace ( " get all smart folder " ) ;
2013-02-06 15:40:17 +01:00
List < WorkspaceSmartFolder > listWorkspaceFolder = new ArrayList < WorkspaceSmartFolder > ( ) ;
2016-01-19 15:50:40 +01:00
listWorkspaceFolder = workspace . getAllSmartFolders ( ) ; //create Smart Folder from workspace
2013-10-04 13:58:07 +02:00
workspaceLogger . trace ( " list smart folders size " + listWorkspaceFolder . size ( ) ) ;
2013-02-06 15:40:17 +01:00
GWTWorkspaceBuilder builder = getGWTWorkspaceBuilder ( ) ;
return builder . buildGXTListSmartFolderModel ( listWorkspaceFolder ) ;
2016-01-19 15:50:40 +01:00
2013-02-06 15:40:17 +01:00
} catch ( Exception e ) {
workspaceLogger . error ( " Error in server get all smart folder: " , e ) ;
throw new Exception ( e . getMessage ( ) ) ;
}
}
2015-03-06 16:12:21 +01:00
/ * ( non - Javadoc )
* @see org . gcube . portlets . user . workspace . client . rpc . GWTWorkspaceService # getSmartFolderResultsById ( java . lang . String )
* /
2017-02-20 11:41:54 +01:00
/ * *
* Gets the smart folder results by id .
*
* @param folderId the folder id
* @return the smart folder results by id
* @throws Exception the exception
* /
2013-02-06 15:40:17 +01:00
@Override
public List < FileGridModel > getSmartFolderResultsById ( String folderId ) throws Exception {
2013-10-04 13:58:07 +02:00
if ( folderId = = null )
return null ;
2016-01-19 15:50:40 +01:00
2013-02-06 15:40:17 +01:00
try {
2016-01-19 15:50:40 +01:00
2013-02-06 15:40:17 +01:00
Workspace workspace = getWorkspace ( ) ;
2013-10-04 13:58:07 +02:00
workspaceLogger . trace ( " get smart folder by id: " + folderId ) ;
2016-01-19 15:50:40 +01:00
WorkspaceSmartFolder wsSmartFolder = workspace . getSmartFolder ( folderId ) ; //get Smart Folder from workspace
2013-02-06 15:40:17 +01:00
workspaceLogger . trace ( " wsFolder " + wsSmartFolder . getName ( ) ) ;
GWTWorkspaceBuilder builder = getGWTWorkspaceBuilder ( ) ;
2016-01-19 15:50:40 +01:00
2015-11-10 12:24:23 +01:00
List < ? extends SearchItem > searchItems = wsSmartFolder . getSearchItems ( ) ;
2016-01-19 15:50:40 +01:00
2015-11-10 12:24:23 +01:00
if ( searchItems ! = null ) {
workspaceLogger . trace ( " smart folders size " + searchItems . size ( ) ) ;
return builder . buildGXTListFileGridModelItemForSearch ( ( List < SearchItem > ) searchItems ) ;
} else
return new ArrayList < FileGridModel > ( ) ;
2016-01-19 15:50:40 +01:00
2013-02-06 15:40:17 +01:00
} catch ( Exception e ) {
workspaceLogger . error ( " Error in get server smart folder by id " , e ) ;
throw new Exception ( e . getMessage ( ) ) ;
}
}
2015-03-06 16:12:21 +01:00
/ * ( non - Javadoc )
* @see org . gcube . portlets . user . workspace . client . rpc . GWTWorkspaceService # getImageById ( java . lang . String , boolean , boolean )
* /
2017-02-20 11:41:54 +01:00
/ * *
* Gets the image by id .
*
* @param identifier the identifier
* @param isInteralImage the is interal image
* @param fullDetails the full details
* @return the image by id
* @throws Exception the exception
* /
2013-02-06 15:40:17 +01:00
@Override
public GWTWorkspaceItem getImageById ( String identifier , boolean isInteralImage , boolean fullDetails ) throws Exception {
2016-01-19 15:50:40 +01:00
2013-10-04 13:58:07 +02:00
if ( identifier = = null )
return null ;
2016-01-19 15:50:40 +01:00
2013-02-06 15:40:17 +01:00
try {
2016-01-19 15:50:40 +01:00
2013-02-06 15:40:17 +01:00
Workspace workspace = getWorkspace ( ) ;
2013-10-04 13:58:07 +02:00
workspaceLogger . trace ( " get image by id: " + identifier ) ;
2016-01-19 15:50:40 +01:00
WorkspaceItem item = workspace . getItem ( identifier ) ; //get item from workspace
2013-02-06 15:40:17 +01:00
workspaceLogger . trace ( " item name " + item . getName ( ) ) ;
GWTWorkspaceBuilder builder = getGWTWorkspaceBuilder ( ) ;
2016-11-30 14:44:00 +01:00
PortalContextInfo context = WsUtil . getPortalContext ( this . getThreadLocalRequest ( ) ) ;
2016-12-21 18:49:00 +01:00
GCubeUser user = PortalContext . getConfiguration ( ) . getCurrentUser ( this . getThreadLocalRequest ( ) ) ;
return builder . buildGWTWorkspaceImage ( item , isInteralImage , fullDetails , context . getCurrGroupId ( ) + " " , user . getUserId ( ) + " " ) ;
2013-10-04 13:58:07 +02:00
2013-02-06 15:40:17 +01:00
} catch ( Exception e ) {
workspaceLogger . error ( " Error in server get image by id " , e ) ;
throw new Exception ( e . getMessage ( ) ) ;
}
}
2016-01-19 15:50:40 +01:00
2015-03-06 16:12:21 +01:00
/ * ( non - Javadoc )
* @see org . gcube . portlets . user . workspace . client . rpc . GWTWorkspaceService # getTimeSeriesById ( java . lang . String )
* /
2017-02-20 11:41:54 +01:00
/ * *
* Gets the time series by id .
*
* @param identifier the identifier
* @return the time series by id
* @throws Exception the exception
* /
2013-02-06 15:40:17 +01:00
@Override
2016-01-19 15:50:40 +01:00
@Deprecated
2015-05-20 18:39:49 +02:00
/ * *
* this method return always null
* /
2013-02-06 15:40:17 +01:00
public GWTWorkspaceItem getTimeSeriesById ( String identifier ) throws Exception {
2016-01-19 15:50:40 +01:00
2013-10-04 13:58:07 +02:00
if ( identifier = = null )
return null ;
2016-01-19 15:50:40 +01:00
2013-02-06 15:40:17 +01:00
try {
2016-01-19 15:50:40 +01:00
2013-02-06 15:40:17 +01:00
Workspace workspace = getWorkspace ( ) ;
2013-10-04 13:58:07 +02:00
workspaceLogger . trace ( " get timeseries by id: " + identifier ) ;
2016-01-19 15:50:40 +01:00
WorkspaceItem item = workspace . getItem ( identifier ) ; //get item from workspace
2013-02-06 15:40:17 +01:00
workspaceLogger . trace ( " item name " + item . getName ( ) ) ;
GWTWorkspaceBuilder builder = getGWTWorkspaceBuilder ( ) ;
2015-05-20 18:39:49 +02:00
return null ;
2013-02-06 15:40:17 +01:00
} catch ( Exception e ) {
workspaceLogger . error ( " Error in server get timeseries by id " , e ) ;
throw new Exception ( e . getMessage ( ) ) ;
}
}
2016-01-19 15:50:40 +01:00
2015-03-06 16:12:21 +01:00
/ * ( non - Javadoc )
* @see org . gcube . portlets . user . workspace . client . rpc . GWTWorkspaceService # getUrlById ( java . lang . String , boolean , boolean )
* /
2017-02-20 11:41:54 +01:00
/ * *
* Gets the url by id .
*
* @param identifier the identifier
* @param isInternalUrl the is internal url
* @param fullDetails the full details
* @return the url by id
* @throws Exception the exception
* /
2013-02-06 15:40:17 +01:00
@Override
public GWTWorkspaceItem getUrlById ( String identifier , boolean isInternalUrl , boolean fullDetails ) throws Exception {
2016-01-19 15:50:40 +01:00
2013-02-06 15:40:17 +01:00
try {
2016-01-19 15:50:40 +01:00
2013-10-04 13:58:07 +02:00
if ( identifier = = null )
throw new Exception ( IDENTIFIER_IS_NULL ) ;
2016-01-19 15:50:40 +01:00
2013-02-06 15:40:17 +01:00
Workspace workspace = getWorkspace ( ) ;
2013-10-04 13:58:07 +02:00
workspaceLogger . trace ( " get url by id: " + identifier ) ;
2016-01-19 15:50:40 +01:00
WorkspaceItem item = workspace . getItem ( identifier ) ; //get item from workspace
2013-02-06 15:40:17 +01:00
workspaceLogger . trace ( " item name " + item . getName ( ) ) ;
GWTWorkspaceBuilder builder = getGWTWorkspaceBuilder ( ) ;
return builder . buildGWTWorspaceUrl ( item , isInternalUrl , fullDetails ) ;
2016-01-19 15:50:40 +01:00
2013-02-06 15:40:17 +01:00
} catch ( Exception e ) {
workspaceLogger . error ( " Error in server get image by id " , e ) ;
2016-06-22 18:41:51 +02:00
// workspaceLogger.trace("Error in server get image by id " + e);
2013-02-06 15:40:17 +01:00
//GWT can't serialize all exceptions
throw new Exception ( e . getMessage ( ) ) ;
}
}
2015-03-06 16:12:21 +01:00
/ * ( non - Javadoc )
* @see org . gcube . portlets . user . workspace . client . rpc . GWTWorkspaceService # createExternalUrl ( org . gcube . portlets . user . workspace . client . model . FileModel , java . lang . String , java . lang . String , java . lang . String )
* /
2017-02-20 11:41:54 +01:00
/ * *
* Creates the external url .
*
* @param parentFileModel the parent file model
* @param name the name
* @param description the description
* @param url the url
* @return the file model
* @throws Exception the exception
* /
2013-02-06 15:40:17 +01:00
@Override
public FileModel createExternalUrl ( FileModel parentFileModel , String name , String description , String url ) throws Exception {
2016-01-19 15:50:40 +01:00
2016-06-22 18:41:51 +02:00
try {
2013-02-06 15:40:17 +01:00
Workspace workspace = getWorkspace ( ) ;
2016-01-19 15:50:40 +01:00
2013-10-04 13:58:07 +02:00
if ( parentFileModel = = null )
throw new Exception ( " Parent item is null " ) ;
2016-01-19 15:50:40 +01:00
2013-10-04 13:58:07 +02:00
workspaceLogger . trace ( " create url in parent id: " + parentFileModel . getIdentifier ( ) ) ;
2013-02-06 15:40:17 +01:00
ExternalUrl ext = workspace . createExternalUrl ( name , description , url , parentFileModel . getIdentifier ( ) ) ;
2016-01-19 15:50:40 +01:00
WorkspaceItem parent = workspace . getItem ( parentFileModel . getIdentifier ( ) ) ; //get item from workspace
2013-02-06 15:40:17 +01:00
workspaceLogger . trace ( " parent name " + parent . getName ( ) ) ;
GWTWorkspaceBuilder builder = getGWTWorkspaceBuilder ( ) ;
return builder . buildGXTFileModelItem ( ext , parentFileModel ) ;
2016-01-19 15:50:40 +01:00
2013-02-06 15:40:17 +01:00
} catch ( Exception e ) {
workspaceLogger . error ( " Error in server create url in parent id " , e ) ;
2016-06-22 18:41:51 +02:00
// workspaceLogger.trace("Error in server create url in parent id " + e);
2013-02-06 15:40:17 +01:00
//GWT can't serialize all exceptions
throw new Exception ( e . getMessage ( ) ) ;
}
}
2016-01-19 15:50:40 +01:00
2015-03-06 16:12:21 +01:00
/ * ( non - Javadoc )
* @see org . gcube . portlets . user . workspace . client . rpc . GWTWorkspaceService # getURLFromApplicationProfile ( java . lang . String )
* /
2017-02-20 11:41:54 +01:00
/ * *
* Gets the URL from application profile .
*
* @param oid the oid
* @return the URL from application profile
* @throws Exception the exception
* /
2013-02-14 15:06:34 +01:00
@Override
2013-02-20 14:28:25 +01:00
public String getURLFromApplicationProfile ( String oid ) throws Exception {
2016-01-19 15:50:40 +01:00
2016-11-25 16:52:03 +01:00
throw new Exception ( " Operation not supported " ) ;
2013-02-14 15:06:34 +01:00
}
2016-01-19 15:50:40 +01:00
2015-03-06 16:12:21 +01:00
/ * ( non - Javadoc )
* @see org . gcube . portlets . user . workspace . client . rpc . GWTWorkspaceService # setValueInSession ( java . lang . String , java . lang . String )
* /
2017-02-20 11:41:54 +01:00
/ * *
* Sets the value in session .
*
* @param name the name
* @param value the value
* @throws Exception the exception
* /
2013-02-06 15:40:17 +01:00
@Override
public void setValueInSession ( String name , String value ) throws Exception {
2016-01-19 15:50:40 +01:00
2013-02-06 15:40:17 +01:00
try {
2016-11-25 12:03:25 +01:00
this . getThreadLocalRequest ( ) . getSession ( ) . setAttribute ( name , value ) ;
2013-02-06 15:40:17 +01:00
workspaceLogger . trace ( " set value in session with name: " + name + " , value: " + value ) ;
} catch ( Exception e ) {
workspaceLogger . error ( " setValueInSession " , e ) ;
throw new Exception ( e . getMessage ( ) ) ;
}
}
2015-03-06 16:12:21 +01:00
/ * ( non - Javadoc )
* @see org . gcube . portlets . user . workspace . client . rpc . GWTWorkspaceService # getAllScope ( )
* /
2017-02-20 11:41:54 +01:00
/ * *
* Gets the all scope .
*
* @return the all scope
* @throws Exception the exception
* /
2013-02-06 15:40:17 +01:00
@Override
public List < ScopeModel > getAllScope ( ) throws Exception {
2016-01-19 15:50:40 +01:00
2013-02-06 15:40:17 +01:00
try {
2016-01-19 15:50:40 +01:00
2013-02-06 15:40:17 +01:00
Workspace workspace = getWorkspace ( ) ;
2013-10-04 13:58:07 +02:00
workspaceLogger . trace ( " get all scope " ) ;
2013-02-06 15:40:17 +01:00
GWTWorkspaceBuilder builder = getGWTWorkspaceBuilder ( ) ;
2013-03-27 17:30:37 +01:00
ScopeUtilFilter scopeUtilFilter = getScopeUtilFilter ( ) ;
Home home = workspace . getHome ( ) ;
if ( home ! = null ) {
List < String > listIdFilterdScope = scopeUtilFilter . convertListScopeToPortlet ( home . listScopes ( ) ) ;
return builder . buildGXTListScopeModel ( listIdFilterdScope , scopeUtilFilter . getHashScopesFiltered ( ) ) ;
} else {
workspaceLogger . error ( " workspace.getHome() is null " ) ;
throw new Exception ( " Sorry, an error occurred on getting all scope. Please try later " ) ;
}
2016-01-19 15:50:40 +01:00
2013-02-06 15:40:17 +01:00
} catch ( Exception e ) {
workspaceLogger . error ( " Error in server get all scope " , e ) ;
e . printStackTrace ( ) ;
2016-06-22 18:41:51 +02:00
// workspaceLogger.trace("Error in server get all scope " + e.getMessage());
2013-02-06 15:40:17 +01:00
//GWT can't serialize all exceptions
throw new Exception ( e . getMessage ( ) ) ;
}
}
2015-03-06 16:12:21 +01:00
/ * ( non - Javadoc )
* @see org . gcube . portlets . user . workspace . client . rpc . GWTWorkspaceService # getAllContacts ( )
* /
2017-02-20 11:41:54 +01:00
/ * *
* Gets the all contacts .
*
* @return the all contacts
* @throws Exception the exception
* /
2013-02-06 15:40:17 +01:00
@Override
public List < InfoContactModel > getAllContacts ( ) throws Exception {
2016-01-19 15:50:40 +01:00
2013-02-06 15:40:17 +01:00
try {
2016-01-19 15:50:40 +01:00
2016-05-05 11:49:36 +02:00
workspaceLogger . debug ( " Get all contacts from server... " ) ;
2013-02-06 15:40:17 +01:00
GWTWorkspaceBuilder builder = getGWTWorkspaceBuilder ( ) ;
2016-09-29 15:28:32 +02:00
getWorkspace ( ) ; //DO NOT REMOVE, IT IS NEEDED TO SET TOKEN IN ECLIPSE
2014-03-10 17:33:33 +01:00
org . gcube . common . homelibrary . home . workspace . usermanager . UserManager hlUserManager = HomeLibrary . getHomeManagerFactory ( ) . getUserManager ( ) ;
2016-01-19 15:50:40 +01:00
2013-02-14 15:06:34 +01:00
if ( isTestMode ( ) ) {
2013-03-11 19:06:56 +01:00
workspaceLogger . warn ( " WORKSPACE PORTLET IS IN TEST MODE - RETURN TEST USERS " ) ;
2013-02-14 15:06:34 +01:00
List < InfoContactModel > listContactsModel = new ArrayList < InfoContactModel > ( ) ;
2014-05-09 17:48:30 +02:00
HashMap < String , InfoContactModel > hashFakeUsers = GWTWorkspaceBuilder . getHashTestUsers ( ) ;
for ( String login : hashFakeUsers . keySet ( ) ) {
InfoContactModel contact = hashFakeUsers . get ( login ) ;
listContactsModel . add ( contact ) ;
}
2014-03-10 17:33:33 +01:00
workspaceLogger . trace ( " Home Library User Manager getting list Gcube Group " ) ;
listContactsModel . addAll ( builder . buildGXTListContactsModelFromGcubeGroup ( hlUserManager . getGroups ( ) ) ) ;
2016-01-19 15:50:40 +01:00
2013-02-14 15:06:34 +01:00
return listContactsModel ;
}
2013-10-02 15:39:39 +02:00
UserManager userManag = new LiferayUserManager ( ) ;
2013-10-03 14:45:25 +02:00
GroupManager gm = new LiferayGroupManager ( ) ;
2016-05-31 17:11:53 +02:00
long groupId = gm . getRootVO ( ) . getGroupId ( ) ;
2016-01-19 15:50:40 +01:00
2014-03-10 17:33:33 +01:00
workspaceLogger . trace ( " Liferay User Manager getting list users by group: " + groupId ) ;
List < InfoContactModel > listContactsModel = builder . buildGXTListContactsModelFromUserModel ( userManag . listUsersByGroup ( groupId ) ) ;
2016-01-19 15:50:40 +01:00
2014-03-10 17:33:33 +01:00
workspaceLogger . trace ( " Home Library User Manager getting list Gcube Group " ) ;
listContactsModel . addAll ( builder . buildGXTListContactsModelFromGcubeGroup ( hlUserManager . getGroups ( ) ) ) ;
2016-01-19 15:50:40 +01:00
2016-05-05 13:00:04 +02:00
workspaceLogger . debug ( " Returning list of contacts " ) ;
2014-03-10 17:33:33 +01:00
return listContactsModel ;
2016-01-19 15:50:40 +01:00
2013-02-06 15:40:17 +01:00
} catch ( Exception e ) {
workspaceLogger . error ( " Error in server get all contacts " , e ) ;
2016-06-22 18:41:51 +02:00
// return new ArrayList<InfoContactModel>();
2013-02-06 15:40:17 +01:00
throw new Exception ( e . getMessage ( ) ) ;
}
}
2015-03-06 16:12:21 +01:00
/ * ( non - Javadoc )
2015-09-18 15:26:33 +02:00
* @see org . gcube . portlets . user . workspace . client . rpc . GWTWorkspaceService # sendToById ( java . util . List , java . util . List , java . lang . String , java . lang . String )
* /
2017-02-20 11:41:54 +01:00
/ * *
* Send to by id .
*
* @param listContactsId the list contacts id
* @param listAttachmentsId the list attachments id
* @param subject the subject
* @param body the body
* @return true , if successful
* @throws Exception the exception
* /
2015-09-18 15:26:33 +02:00
@Override
2013-02-06 15:40:17 +01:00
public boolean sendToById ( List < String > listContactsId , List < String > listAttachmentsId , String subject , String body ) throws Exception {
2016-01-19 15:50:40 +01:00
2013-02-06 15:40:17 +01:00
try {
2016-01-19 15:50:40 +01:00
2013-02-06 15:40:17 +01:00
Workspace workspace = getWorkspace ( ) ;
2016-06-22 18:41:51 +02:00
// workspaceLogger.trace("######### SEND TO: ");
// workspaceLogger.trace("subject " + subject);
// workspaceLogger.trace("body " + body);
2016-01-19 15:50:40 +01:00
2015-09-18 15:26:33 +02:00
//DEBUG
2013-02-06 15:40:17 +01:00
for ( String contactId : listContactsId )
2015-06-24 16:56:13 +02:00
workspaceLogger . trace ( " contactId " + contactId ) ;
2015-09-18 15:26:33 +02:00
//DEBUG
2013-02-06 15:40:17 +01:00
for ( String id : listAttachmentsId )
workspaceLogger . trace ( " attachId " + id ) ;
workspace . getWorkspaceMessageManager ( ) . sendMessageToPortalLogins ( subject , body , listAttachmentsId , listContactsId ) ;
2016-01-19 15:50:40 +01:00
return true ;
2013-02-06 15:40:17 +01:00
} catch ( Exception e ) {
workspaceLogger . error ( " Error in server sendTo " , e ) ;
//GWT can't serialize all exceptions
throw new Exception ( e . getMessage ( ) ) ;
}
2016-01-19 15:50:40 +01:00
2013-02-06 15:40:17 +01:00
}
2016-01-19 15:50:40 +01:00
2015-03-06 16:12:21 +01:00
/ * *
* Gets the list workspace item by id .
*
* @param workspace the workspace
* @param listItemsId the list items id
* @return the list workspace item by id
* @throws ItemNotFoundException the item not found exception
* @throws InternalErrorException the internal error exception
* /
2013-02-06 15:40:17 +01:00
private List < WorkspaceItem > getListWorkspaceItemById ( Workspace workspace , List < String > listItemsId ) throws ItemNotFoundException , InternalErrorException {
2016-01-19 15:50:40 +01:00
2013-02-06 15:40:17 +01:00
List < WorkspaceItem > listWorkspaceItem = new ArrayList < WorkspaceItem > ( ) ;
2016-01-19 15:50:40 +01:00
2013-02-06 15:40:17 +01:00
for ( String itemId : listItemsId ) {
2016-01-19 15:50:40 +01:00
2013-02-06 15:40:17 +01:00
WorkspaceItem item = workspace . getItem ( itemId ) ;
workspaceLogger . trace ( " Attach name: " + item . getName ( ) ) ;
workspaceLogger . trace ( " Attach id: " + item . getId ( ) ) ;
2016-01-19 15:50:40 +01:00
listWorkspaceItem . add ( workspace . getItem ( itemId ) ) ; //get item from workspace
2013-02-06 15:40:17 +01:00
}
2016-01-19 15:50:40 +01:00
2013-02-06 15:40:17 +01:00
return listWorkspaceItem ;
}
2016-01-19 15:50:40 +01:00
2013-02-06 15:40:17 +01:00
2015-03-06 16:12:21 +01:00
/ * ( non - Javadoc )
* @see org . gcube . portlets . user . workspace . client . rpc . GWTWorkspaceService # copyItem ( java . lang . String , java . lang . String )
* /
2017-02-20 11:41:54 +01:00
/ * *
* Copy item .
*
* @param itemId the item id
* @param destinationFolderId the destination folder id
* @return true , if successful
* @throws Exception the exception
* /
2013-02-06 15:40:17 +01:00
@Override
public boolean copyItem ( String itemId , String destinationFolderId ) throws Exception {
2016-01-19 15:50:40 +01:00
2014-01-14 14:41:03 +01:00
if ( isSessionExpired ( ) )
throw new SessionExpiredException ( ) ;
2016-01-19 15:50:40 +01:00
2013-02-06 15:40:17 +01:00
try {
Workspace workspace = getWorkspace ( ) ;
2013-02-27 19:17:22 +01:00
WorkspaceItem sourceItem = workspace . getItem ( itemId ) ; //GET SOURCE ITEM BEFORE COPY
String sourceSharedId = sourceItem . getIdSharedFolder ( ) ;
2013-10-04 13:58:07 +02:00
workspaceLogger . trace ( " copyItem by id: " + itemId ) ;
2014-07-14 17:21:43 +02:00
WorkspaceItem destinationItem = workspace . copy ( itemId , destinationFolderId ) ; //copy item
2013-02-27 19:17:22 +01:00
WorkspaceItem folderDestinationItem = workspace . getItem ( destinationFolderId ) ;
2014-07-14 17:21:43 +02:00
checkNotifyAddItemToShare ( destinationItem , sourceSharedId , folderDestinationItem ) ;
2016-01-19 15:50:40 +01:00
2014-07-14 17:21:43 +02:00
if ( destinationItem ! = null )
2013-02-06 15:40:17 +01:00
return true ;
2016-01-19 15:50:40 +01:00
2013-02-06 15:40:17 +01:00
return false ;
2013-02-20 14:51:36 +01:00
} catch ( InsufficientPrivilegesException e ) {
2013-03-26 17:31:13 +01:00
String error = " An error occurred on copying item, " + e . getMessage ( ) + " . " + ConstantsExplorer . TRY_AGAIN ;
2013-02-20 14:51:36 +01:00
throw new Exception ( error ) ;
2013-02-06 15:40:17 +01:00
2013-03-26 17:31:13 +01:00
} catch ( ItemAlreadyExistException e ) {
String error = " An error occurred on copying item, " + e . getMessage ( ) ;
throw new Exception ( error ) ;
2013-02-06 15:40:17 +01:00
} catch ( Exception e ) {
workspaceLogger . error ( " Error in server copyItem by id " , e ) ;
2013-02-20 14:51:36 +01:00
String error = ConstantsExplorer . SERVER_ERROR + " copying item " + ConstantsExplorer . TRY_AGAIN ;
throw new Exception ( error ) ;
2013-02-06 15:40:17 +01:00
}
}
2016-01-19 15:50:40 +01:00
2015-03-06 16:12:21 +01:00
/ * ( non - Javadoc )
* @see org . gcube . portlets . user . workspace . client . rpc . GWTWorkspaceService # copyItems ( java . util . List , java . lang . String )
* /
2017-02-20 11:41:54 +01:00
/ * *
* Copy items .
*
* @param idsItem the ids item
* @param destinationFolderId the destination folder id
* @return true , if successful
* @throws Exception the exception
* /
2014-01-23 17:20:38 +01:00
@Override
public boolean copyItems ( List < String > idsItem , String destinationFolderId ) throws Exception {
2016-01-19 15:50:40 +01:00
2014-01-23 17:20:38 +01:00
if ( isSessionExpired ( ) )
throw new SessionExpiredException ( ) ;
2016-01-19 15:50:40 +01:00
2014-01-23 17:20:38 +01:00
try {
Workspace workspace = getWorkspace ( ) ;
boolean error = false ;
2016-01-19 15:50:40 +01:00
2014-01-23 17:20:38 +01:00
for ( String itemId : idsItem ) {
WorkspaceItem sourceItem = workspace . getItem ( itemId ) ; //GET SOURCE ITEM BEFORE COPY
String sourceSharedId = sourceItem . getIdSharedFolder ( ) ;
workspaceLogger . trace ( " copyItem by id: " + itemId ) ;
2014-07-14 17:21:43 +02:00
WorkspaceItem destinationItem = workspace . copy ( itemId , destinationFolderId ) ; //copy item
2014-01-23 17:20:38 +01:00
WorkspaceItem folderDestinationItem = workspace . getItem ( destinationFolderId ) ;
2014-07-14 17:21:43 +02:00
checkNotifyAddItemToShare ( destinationItem , sourceSharedId , folderDestinationItem ) ;
2016-01-19 15:50:40 +01:00
2014-07-14 17:21:43 +02:00
if ( destinationItem = = null ) {
2014-01-23 17:20:38 +01:00
error = true ;
break ;
}
}
2016-01-19 15:50:40 +01:00
2014-01-23 17:20:38 +01:00
if ( error )
return false ; //Copied is false
2016-01-19 15:50:40 +01:00
2014-01-23 17:20:38 +01:00
return true ; //copied is true
} catch ( InsufficientPrivilegesException e ) {
String error = " An error occurred on copying item, " + e . getMessage ( ) + " . " + ConstantsExplorer . TRY_AGAIN ;
throw new Exception ( error ) ;
} catch ( ItemAlreadyExistException e ) {
String error = " An error occurred on copying item, " + e . getMessage ( ) ;
throw new Exception ( error ) ;
} catch ( Exception e ) {
workspaceLogger . error ( " Error in server copyItem by id " , e ) ;
String error = ConstantsExplorer . SERVER_ERROR + " copying item " + ConstantsExplorer . TRY_AGAIN ;
throw new Exception ( error ) ;
}
}
2013-02-06 15:40:17 +01:00
2015-03-06 16:12:21 +01:00
/ * ( non - Javadoc )
* @see org . gcube . portlets . user . workspace . client . rpc . GWTWorkspaceService # getUrlWebDav ( java . lang . String )
* /
2017-02-20 11:41:54 +01:00
/ * *
* Gets the url web dav .
*
* @param itemId the item id
* @return the url web dav
* @throws Exception the exception
* /
2013-02-06 15:40:17 +01:00
@Override
public String getUrlWebDav ( String itemId ) throws Exception {
2016-01-19 15:50:40 +01:00
2013-02-06 15:40:17 +01:00
try {
Workspace workspace = getWorkspace ( ) ;
workspaceLogger . trace ( " getWebDavUrl " + itemId ) ;
return workspace . getUrlWebDav ( ) ;
} catch ( Exception e ) {
workspaceLogger . error ( " Error in getNewFolderBulkCreator " , e ) ;
2016-06-22 18:41:51 +02:00
// workspaceLogger.trace("Error in getNewFolderBulkCreator " + e.getMessage());
2013-02-06 15:40:17 +01:00
throw new Exception ( e . getMessage ( ) ) ;
}
}
2016-01-19 15:50:40 +01:00
2015-03-06 16:12:21 +01:00
/ * ( non - Javadoc )
* @see org . gcube . portlets . user . workspace . client . rpc . GWTWorkspaceService # shareFolder ( org . gcube . portlets . user . workspace . client . model . FileModel , java . util . List , boolean , org . gcube . portlets . user . workspace . shared . WorkspaceACL )
* /
2017-02-20 11:41:54 +01:00
/ * *
* Share folder .
*
* @param folder the folder
* @param listContacts the list contacts
* @param isNewFolder the is new folder
* @param acl the acl
* @return true , if successful
* @throws Exception the exception
* /
2013-02-06 15:40:17 +01:00
@Override
2014-02-11 16:41:56 +01:00
public boolean shareFolder ( FileModel folder , List < InfoContactModel > listContacts , boolean isNewFolder , WorkspaceACL acl ) throws Exception {
2016-01-19 15:50:40 +01:00
2014-01-14 14:41:03 +01:00
if ( isSessionExpired ( ) )
throw new SessionExpiredException ( ) ;
2016-01-19 15:50:40 +01:00
2013-02-06 15:40:17 +01:00
try {
2013-02-12 17:17:15 +01:00
2013-02-12 16:02:00 +01:00
Workspace workspace = getWorkspace ( ) ;
2016-01-19 15:50:40 +01:00
workspaceLogger . info ( " shareFolder " + folder . getIdentifier ( )
2016-09-21 18:10:14 +02:00
+ " name: " + folder . getName ( )
+ " parent is: " + folder . getParentFileModel ( )
+ " listContacts size: " + listContacts . size ( )
+ " ACL: " + acl ) ;
2016-01-19 15:50:40 +01:00
2015-02-16 15:36:11 +01:00
//DEBUG
2013-02-28 12:32:45 +01:00
printContacts ( listContacts ) ;
2013-03-25 17:35:27 +01:00
List < String > listLogin = UserUtil . getListLoginByInfoContactModel ( listContacts ) ;
2013-02-06 15:40:17 +01:00
WorkspaceSharedFolder sharedFolder = null ;
2013-02-27 19:17:22 +01:00
List < InfoContactModel > listSharedContact = null ;
2016-01-19 15:50:40 +01:00
2013-02-27 19:17:22 +01:00
boolean sourceFolderIsShared = folder . isShared ( ) ;
2016-01-19 15:50:40 +01:00
2013-02-27 19:17:22 +01:00
if ( sourceFolderIsShared ) { //if source folder is already share... retrieve old list of sharing to notify
listSharedContact = getListUserSharedByFolderSharedId ( folder . getIdentifier ( ) ) ;
}
2013-02-12 17:17:15 +01:00
if ( listLogin . size ( ) > 0 ) {
2016-01-19 15:50:40 +01:00
2013-05-29 14:09:11 +02:00
if ( ! isNewFolder ) {
2016-01-19 15:50:40 +01:00
2013-02-12 17:17:15 +01:00
sharedFolder = workspace . shareFolder ( listLogin , folder . getIdentifier ( ) ) ;
2013-05-29 14:09:11 +02:00
sharedFolder . setDescription ( folder . getDescription ( ) ) ; //SET NEW DESCRIPTION
2016-01-19 15:50:40 +01:00
2016-06-22 18:41:51 +02:00
//USER REMOVED FROM SHARE
2015-11-19 17:17:13 +01:00
DifferenceBetweenInfoContactModel diff2 = new DifferenceBetweenInfoContactModel ( listSharedContact , listContacts ) ;
2015-11-19 15:53:55 +01:00
List < InfoContactModel > listRemovedUsersFromShare = diff2 . getDifferentsContacts ( ) ;
2015-11-19 16:01:28 +01:00
workspaceLogger . info ( " List removed user from share has size: " + listRemovedUsersFromShare . size ( ) ) ;
2015-11-19 15:53:55 +01:00
for ( InfoContactModel userRemoved : listRemovedUsersFromShare ) {
workspaceLogger . info ( " Unsharing user: " + userRemoved . getLogin ( ) ) ;
sharedFolder . unShare ( userRemoved . getLogin ( ) ) ;
}
2013-05-29 14:09:11 +02:00
}
2014-03-17 14:43:06 +01:00
else {
FileModel parent = folder . getParentFileModel ( ) ;
String parentId = " " ;
if ( parent ! = null ) {
parentId = parent . getIdentifier ( ) ;
} else {
workspaceLogger . info ( " Parent is null, reading root ID from workspace " ) ;
parentId = getWorkspace ( ) . getRoot ( ) . getId ( ) ;
}
sharedFolder = workspace . createSharedFolder ( folder . getName ( ) , folder . getDescription ( ) , listLogin , parentId ) ;
}
2013-02-12 17:17:15 +01:00
}
2016-01-19 15:50:40 +01:00
2013-02-12 16:02:00 +01:00
boolean created = sharedFolder = = null ? false : true ;
2013-02-13 18:39:33 +01:00
2014-02-11 16:41:56 +01:00
if ( acl ! = null )
setACLs ( sharedFolder . getId ( ) , listLogin , acl . getId ( ) . toString ( ) ) ;
2016-01-19 15:50:40 +01:00
2013-02-13 18:39:33 +01:00
if ( created ) {
NotificationsProducer np = getNotificationProducer ( ) ;
2013-02-27 19:17:22 +01:00
if ( ! sourceFolderIsShared ) //if source folder is not already shared
np . notifyFolderSharing ( listContacts , sharedFolder ) ;
2013-03-25 17:35:27 +01:00
else {
2016-06-22 18:41:51 +02:00
// printContacts(listContacts);
2015-11-05 11:23:01 +01:00
np . notifyUpdatedUsersToSharing ( listSharedContact , listContacts , sharedFolder ) ;
2013-03-25 17:35:27 +01:00
}
2013-02-13 18:39:33 +01:00
}
2016-01-19 15:50:40 +01:00
2013-02-12 16:02:00 +01:00
return created ;
2013-02-06 15:40:17 +01:00
2013-02-20 14:51:36 +01:00
} catch ( InsufficientPrivilegesException e ) {
workspaceLogger . error ( " Error in shareFolder " , e ) ;
String error = " An error occurred on creating shared folder. " + e . getMessage ( ) ;
throw new Exception ( error ) ;
2016-01-19 15:50:40 +01:00
2013-02-20 14:51:36 +01:00
} catch ( ItemAlreadyExistException e ) {
workspaceLogger . error ( " Error in shareFolder " , e ) ;
String error = " An error occurred on creating shared folder. " + e . getMessage ( ) ;
throw new Exception ( error ) ;
2016-01-19 15:50:40 +01:00
2013-02-20 14:51:36 +01:00
} catch ( WrongDestinationException e ) {
workspaceLogger . error ( " Error in shareFolder " , e ) ;
String error = " An error occurred on creating shared folder. " + e . getMessage ( ) ;
throw new Exception ( error ) ;
2013-02-06 15:40:17 +01:00
} catch ( Exception e ) {
workspaceLogger . error ( " Error in shareFolder " , e ) ;
2013-02-12 16:02:00 +01:00
e . printStackTrace ( ) ;
2013-02-27 19:17:22 +01:00
String error = ConstantsExplorer . SERVER_ERROR + " creating shared folder. " ;
2013-02-20 14:51:36 +01:00
throw new Exception ( error ) ;
2013-02-06 15:40:17 +01:00
}
}
2015-03-06 16:12:21 +01:00
/ * ( non - Javadoc )
* @see org . gcube . portlets . user . workspace . client . rpc . GWTWorkspaceService # getListUserSharedByFolderSharedId ( java . lang . String )
* /
2017-02-20 11:41:54 +01:00
/ * *
* Gets the list user shared by folder shared id .
*
* @param folderSharedId the folder shared id
* @return the list user shared by folder shared id
* @throws Exception the exception
* /
2013-02-06 15:40:17 +01:00
@Override
public List < InfoContactModel > getListUserSharedByFolderSharedId ( String folderSharedId ) throws Exception {
2016-01-19 15:50:40 +01:00
2016-05-13 11:14:42 +02:00
workspaceLogger . debug ( " getListUserSharedByFolderSharedId " + folderSharedId ) ;
2013-03-11 19:06:56 +01:00
2013-02-06 15:40:17 +01:00
try {
Workspace workspace = getWorkspace ( ) ;
WorkspaceItem wsItem = workspace . getItem ( folderSharedId ) ;
2016-01-19 15:50:40 +01:00
2013-06-13 18:44:46 +02:00
if ( NotificationsUtil . isASharedFolder ( wsItem ) ) {
2016-01-19 15:50:40 +01:00
2013-02-06 15:40:17 +01:00
WorkspaceSharedFolder wsFolder = ( WorkspaceSharedFolder ) wsItem ;
GWTWorkspaceBuilder builder = getGWTWorkspaceBuilder ( ) ;
2013-03-11 16:37:10 +01:00
List < String > listPortalLogin = wsFolder . getUsers ( ) ;
2016-05-13 11:14:42 +02:00
workspaceLogger . debug ( " HL return " + listPortalLogin . size ( ) + " user/s " ) ;
2013-03-11 19:06:56 +01:00
if ( isTestMode ( ) )
return builder . buildGxtInfoContactFromPortalLoginTestMode ( listPortalLogin ) ;
2016-01-19 15:50:40 +01:00
2013-05-23 19:03:43 +02:00
return builder . buildGxtInfoContactsFromPortalLogins ( listPortalLogin ) ;
2013-02-06 15:40:17 +01:00
}
2015-02-16 14:46:38 +01:00
else
2013-02-13 18:39:33 +01:00
workspaceLogger . trace ( " the item with id: " + folderSharedId + " is not " + WorkspaceItemType . SHARED_FOLDER ) ;
2016-01-19 15:50:40 +01:00
2013-02-06 15:40:17 +01:00
return new ArrayList < InfoContactModel > ( ) ;
2016-01-19 15:50:40 +01:00
2013-02-06 15:40:17 +01:00
} catch ( Exception e ) {
workspaceLogger . error ( " Error in getListUserSharedByItemId " , e ) ;
throw new Exception ( e . getMessage ( ) ) ;
}
}
2016-01-19 15:50:40 +01:00
2015-03-06 16:12:21 +01:00
/ * ( non - Javadoc )
* @see org . gcube . portlets . user . workspace . client . rpc . GWTWorkspaceService # getListUserSharedBySharedItem ( java . lang . String )
* /
2016-05-13 11:14:42 +02:00
/ * @Override
public List < InfoContactModel > getListUserSharedBySharedItem ( String sharedItemId ) throws Exception {
2015-02-16 14:46:38 +01:00
workspaceLogger . trace ( " Get ListUserSharedBySharedItem " + sharedItemId ) ;
2013-03-25 11:14:26 +01:00
try {
2016-01-19 15:50:40 +01:00
2015-02-16 14:46:38 +01:00
WorkspaceFolder wsFolder = getSharedWorkspaceFolderForId ( sharedItemId ) ;
if ( wsFolder ! = null ) {
if ( isASharedFolder ( wsFolder , true ) ) {
2013-03-25 11:14:26 +01:00
GWTWorkspaceBuilder builder = getGWTWorkspaceBuilder ( ) ;
2016-01-19 15:50:40 +01:00
2015-02-16 14:46:38 +01:00
WorkspaceSharedFolder wsSharedFolder = ( WorkspaceSharedFolder ) wsFolder ;
List < String > listPortalLogin = wsSharedFolder . getUsers ( ) ;
workspaceLogger . trace ( " getListUserSharedByFolderSharedId return " + listPortalLogin . size ( ) + " user/s " ) ;
2016-01-19 15:50:40 +01:00
2013-03-25 11:14:26 +01:00
if ( isTestMode ( ) )
return builder . buildGxtInfoContactFromPortalLoginTestMode ( listPortalLogin ) ;
2016-01-19 15:50:40 +01:00
2013-05-23 19:03:43 +02:00
return builder . buildGxtInfoContactsFromPortalLogins ( listPortalLogin ) ;
2015-02-16 14:46:38 +01:00
} else {
workspaceLogger . warn ( " wsFolder with id: " + sharedItemId + " is not a: " + WorkspaceItemType . SHARED_FOLDER + " , returning null " ) ;
return null ;
2013-03-25 11:14:26 +01:00
}
}
2015-02-16 14:46:38 +01:00
workspaceLogger . warn ( " wsFolder with id: " + sharedItemId + " is null, returning null " ) ;
return null ;
2016-01-19 15:50:40 +01:00
2013-03-25 11:14:26 +01:00
} catch ( Exception e ) {
workspaceLogger . error ( " Error in getListUserSharedByItemId " , e ) ;
throw new Exception ( e . getMessage ( ) ) ;
}
2016-05-13 11:14:42 +02:00
} * /
2016-01-19 15:50:40 +01:00
2015-03-06 16:12:21 +01:00
/ * ( non - Javadoc )
* @see org . gcube . portlets . user . workspace . client . rpc . GWTWorkspaceService # unSharedFolderByFolderSharedId ( java . lang . String )
* /
2017-02-20 11:41:54 +01:00
/ * *
* Un shared folder by folder shared id .
*
* @param folderSharedId the folder shared id
* @return true , if successful
* @throws Exception the exception
* /
2013-02-06 15:40:17 +01:00
@Override
public boolean unSharedFolderByFolderSharedId ( String folderSharedId ) throws Exception {
2016-01-19 15:50:40 +01:00
2013-02-06 15:40:17 +01:00
boolean unShared = false ;
2016-01-19 15:50:40 +01:00
2014-01-14 14:41:03 +01:00
if ( isSessionExpired ( ) )
throw new SessionExpiredException ( ) ;
2016-01-19 15:50:40 +01:00
2013-02-06 15:40:17 +01:00
workspaceLogger . trace ( " unSharedFolderByFolderSharedId " + folderSharedId ) ;
2016-01-19 15:50:40 +01:00
2013-02-06 15:40:17 +01:00
try {
2016-01-19 15:50:40 +01:00
2015-02-16 14:46:38 +01:00
if ( isASharedFolder ( folderSharedId , true ) ) {
Workspace workspace = getWorkspace ( ) ;
WorkspaceItem wsItem = workspace . getItem ( folderSharedId ) ;
workspaceLogger . trace ( " workspace return an item with name " + wsItem . getName ( ) ) ;
2013-02-06 15:40:17 +01:00
WorkspaceSharedFolder wsFolder = ( WorkspaceSharedFolder ) wsItem ;
2016-01-19 15:50:40 +01:00
List < InfoContactModel > contacts = getListUserSharedByFolderSharedId ( folderSharedId ) ;
2014-09-29 18:11:33 +02:00
String sharedFolderName = wsFolder . getName ( ) ;
2016-01-19 15:50:40 +01:00
2014-09-29 18:11:33 +02:00
//RETURN A NEW FOLDER
wsFolder . unShare ( ) ;
workspaceLogger . trace ( " no error incoming on unsharing " ) ;
unShared = true ;
2015-02-16 14:46:38 +01:00
2014-09-29 18:11:33 +02:00
NotificationsProducer np = getNotificationProducer ( ) ;
List < InfoContactModel > purgeMyContact = new ArrayList < InfoContactModel > ( contacts . size ( ) - 1 ) ;
2016-09-16 11:12:03 +02:00
String myLogin = getMyLogin ( null ) . getUsername ( ) ;
2014-09-29 18:11:33 +02:00
workspaceLogger . trace ( " Preparing list of contacts to send un share notification " ) ;
for ( InfoContactModel infoContactModel : contacts ) {
2016-09-16 11:12:03 +02:00
if ( infoContactModel . getLogin ( ) . compareToIgnoreCase ( getMyLogin ( null ) . getUsername ( ) ) = = 0 )
2014-09-29 18:11:33 +02:00
workspaceLogger . trace ( " skipping my login " + myLogin ) ;
else
purgeMyContact . add ( infoContactModel ) ;
2013-02-13 18:39:33 +01:00
}
2014-09-29 18:11:33 +02:00
workspaceLogger . trace ( " UNSHARE WITH: " ) ;
printContacts ( purgeMyContact ) ;
2016-01-19 15:50:40 +01:00
2014-09-29 18:11:33 +02:00
np . notifyFolderUnSharing ( purgeMyContact , folderSharedId , sharedFolderName ) ;
2013-02-06 15:40:17 +01:00
}
2015-02-16 14:46:38 +01:00
else {
String msg = " The item with id: " + folderSharedId + " is not a base shared folder " ;
workspaceLogger . warn ( " the item with id: " + folderSharedId + " is not " + WorkspaceItemType . SHARED_FOLDER + " or root shared folder " ) ;
throw new WorkspaceHandledException ( msg ) ;
}
2016-01-19 15:50:40 +01:00
2013-05-29 14:09:11 +02:00
} catch ( InternalErrorException e ) {
2013-02-20 14:51:36 +01:00
workspaceLogger . error ( " Error in unSharedFolderByFolderSharedId " , e ) ;
String error = " An error occerred on unsharing folder. " + e . getMessage ( ) ;
throw new Exception ( error ) ;
2016-01-19 15:50:40 +01:00
2015-02-16 14:46:38 +01:00
} catch ( WorkspaceHandledException e ) {
String error = ConstantsExplorer . SERVER_ERROR + " unshare folder. " + e . getMessage ( ) ;
throw new Exception ( error ) ;
2016-01-19 15:50:40 +01:00
2013-02-06 15:40:17 +01:00
} catch ( Exception e ) {
workspaceLogger . error ( " Error in unSharedFolderByFolderSharedId " , e ) ;
2015-02-16 14:46:38 +01:00
String error = ConstantsExplorer . SERVER_ERROR + " unshare folder. Refresh folder and " + ConstantsExplorer . TRY_AGAIN ;
2013-02-20 14:51:36 +01:00
throw new Exception ( error ) ;
2013-02-06 15:40:17 +01:00
}
2016-01-19 15:50:40 +01:00
2013-02-06 15:40:17 +01:00
return unShared ;
}
2013-02-13 18:39:33 +01:00
2013-09-12 12:27:18 +02:00
/ * *
2015-03-06 16:12:21 +01:00
* Gets the list parents by item identifier .
*
* @param itemIdentifier the item identifier
2013-09-12 12:27:18 +02:00
* @param includeItemAsParent - if parameter is true and item passed in input is a folder , the folder is included in path returned as last parent
2015-03-06 16:12:21 +01:00
* @return the list parents by item identifier
* @throws Exception the exception
2013-09-12 12:27:18 +02:00
* /
2013-02-13 18:39:33 +01:00
@Override
2013-09-12 12:27:18 +02:00
public List < FileModel > getListParentsByItemIdentifier ( String itemIdentifier , boolean includeItemAsParent ) throws Exception {
2016-01-19 15:50:40 +01:00
2015-09-18 15:26:33 +02:00
workspaceLogger . debug ( " get List Parents By Item Identifier " + itemIdentifier + " , include Item As (Last) Parent: " + includeItemAsParent ) ;
2016-01-19 15:50:40 +01:00
2016-09-14 12:17:14 +02:00
if ( isSessionExpired ( ) )
throw new SessionExpiredException ( ) ;
2015-11-17 12:52:49 +01:00
if ( itemIdentifier = = null )
2016-01-08 12:36:41 +01:00
return new ArrayList < FileModel > ( ) ; //empty list
2016-01-19 15:50:40 +01:00
2013-02-13 18:39:33 +01:00
try {
2016-01-19 15:50:40 +01:00
2013-02-13 18:39:33 +01:00
Workspace workspace = getWorkspace ( ) ;
GWTWorkspaceBuilder builder = getGWTWorkspaceBuilder ( ) ;
2016-01-19 15:50:40 +01:00
List < WorkspaceItem > parents = workspace . getParentsById ( itemIdentifier ) ;
2016-01-08 12:36:41 +01:00
workspaceLogger . debug ( " parents returned by HL, size: " + parents . size ( ) ) ;
2014-03-17 14:43:06 +01:00
String nameSpecialFolder = getNameForSpecialFolder ( ) ;
2016-01-19 15:50:40 +01:00
2016-01-08 12:36:41 +01:00
switch ( parents . size ( ) ) {
case 0 : // itemIdentifier is ROOT
workspaceLogger . trace ( " itemIdentifier isRoot... " ) ;
if ( includeItemAsParent ) { //ADDIND ROOT
WorkspaceFolder wsFolder = ( WorkspaceFolder ) workspace . getItem ( itemIdentifier ) ;
FolderModel root = builder . buildGXTFolderModelItemHandleSpecialFolder ( wsFolder , null , nameSpecialFolder ) ;
List < FileModel > listParents = new ArrayList < FileModel > ( 1 ) ;
listParents . add ( root ) ;
2016-06-22 18:41:51 +02:00
// workspaceLogger.trace("returning: "+listParents.toString());
2016-01-08 12:36:41 +01:00
return listParents ;
}
else {
workspaceLogger . trace ( " returning empty list " ) ;
return new ArrayList < FileModel > ( ) ; // empty list
}
2016-01-19 15:50:40 +01:00
2016-01-08 12:36:41 +01:00
case 1 : //itemIdentifier is first level from root
workspaceLogger . trace ( " itemIdentifier is first level... " ) ;
List < FileModel > listParents = new ArrayList < FileModel > ( ) ;
WorkspaceFolder wsRootFolder = ( WorkspaceFolder ) parents . get ( 0 ) ; //isRoot
FolderModel root = builder . buildGXTFolderModelItemHandleSpecialFolder ( wsRootFolder , null , nameSpecialFolder ) ;
FolderModel parent = null ;
if ( includeItemAsParent ) {
WorkspaceFolder wsFolder1 = ( WorkspaceFolder ) workspace . getItem ( itemIdentifier ) ; //root
2016-09-30 12:50:48 +02:00
parent = builder . buildGXTFolderModelItemHandleSpecialFolder ( wsFolder1 , null , nameSpecialFolder ) ;
2016-01-19 15:50:40 +01:00
}
2016-01-08 12:36:41 +01:00
listParents . add ( root ) ;
if ( parent ! = null )
listParents . add ( parent ) ;
2016-06-22 18:41:51 +02:00
// workspaceLogger.trace("returning: "+listParents.toString());
2016-01-08 12:36:41 +01:00
return listParents ;
2016-01-19 15:50:40 +01:00
2016-01-08 12:36:41 +01:00
default :
break ;
}
2016-01-19 15:50:40 +01:00
2016-01-08 12:36:41 +01:00
WorkspaceItem lastItem = parents . get ( parents . size ( ) - 1 ) ;
2015-11-17 12:52:49 +01:00
FileModel [ ] arrayParents ;
2016-01-19 15:50:40 +01:00
2015-11-17 12:52:49 +01:00
//CONVERTING LAST ELEMENT IF NECESSARY
workspaceLogger . trace ( " converting last element.. " ) ;
2016-01-08 12:36:41 +01:00
if ( includeItemAsParent & & lastItem . isFolder ( ) ) { //FIX BUG #298
2015-11-17 12:52:49 +01:00
arrayParents = new FileModel [ parents . size ( ) ] ;
workspaceLogger . debug ( " including last item into path: " + lastItem . getName ( ) ) ;
arrayParents [ parents . size ( ) - 1 ] = builder . buildGXTFolderModelItemHandleSpecialFolder ( ( WorkspaceFolder ) lastItem , null , nameSpecialFolder ) ;
} else
arrayParents = new FileModel [ parents . size ( ) - 1 ] ;
2015-06-22 15:42:49 +02:00
2015-11-17 12:52:49 +01:00
//CONVERTING PATH
workspaceLogger . trace ( " converting path from second-last.. " ) ;
for ( int i = parents . size ( ) - 2 ; i > = 0 ; i - - ) {
WorkspaceFolder wsFolder = ( WorkspaceFolder ) parents . get ( i ) ;
arrayParents [ i ] = builder . buildGXTFolderModelItemHandleSpecialFolder ( wsFolder , null , nameSpecialFolder ) ;
2013-02-13 18:39:33 +01:00
}
2016-01-19 15:50:40 +01:00
2013-02-13 18:39:33 +01:00
//SET PARENTS
2015-11-17 12:52:49 +01:00
workspaceLogger . trace ( " setting parents.. " ) ;
for ( int i = 0 ; i < arrayParents . length - 1 ; i + + ) {
FileModel parent = arrayParents [ i ] ;
FileModel fileModel = arrayParents [ i + 1 ] ;
2013-02-13 18:39:33 +01:00
fileModel . setParentFileModel ( parent ) ;
}
2016-06-22 18:41:51 +02:00
// workspaceLogger.trace("list parents returning size: "+arrayParents.length);
// return new ArrayList<FileModel>(Arrays.asList(arrayParents));
2015-11-17 12:52:49 +01:00
workspaceLogger . trace ( " list parents returning size: " + arrayParents . length ) ;
2015-12-03 17:36:31 +01:00
if ( arrayParents [ 0 ] = = null ) { //EXIT BY BREAK IN CASE OF SPECIAL FOLDER
List < FileModel > breadcrumbs = new ArrayList < FileModel > ( arrayParents . length - 1 ) ;
for ( int i = 1 ; i < arrayParents . length ; i + + ) {
breadcrumbs . add ( arrayParents [ i ] ) ;
}
return breadcrumbs ;
} else
return new ArrayList < FileModel > ( Arrays . asList ( arrayParents ) ) ;
2015-11-17 12:52:49 +01:00
2013-02-13 18:39:33 +01:00
} catch ( Exception e ) {
2013-03-27 17:30:37 +01:00
workspaceLogger . error ( " Error in get List Parents By Item Identifier " , e ) ;
2013-02-13 18:39:33 +01:00
e . printStackTrace ( ) ;
throw new Exception ( e . getMessage ( ) ) ;
}
}
2013-02-25 19:03:53 +01:00
2015-03-06 16:12:21 +01:00
/ * ( non - Javadoc )
* @see org . gcube . portlets . user . workspace . client . rpc . GWTWorkspaceService # getOwnerByItemId ( java . lang . String )
* /
2017-02-20 11:41:54 +01:00
/ * *
* Gets the owner by item id .
*
* @param itemId the item id
* @return the owner by item id
* @throws Exception the exception
* /
2013-02-25 19:03:53 +01:00
@Override
public InfoContactModel getOwnerByItemId ( String itemId ) throws Exception {
2016-01-19 15:50:40 +01:00
2013-02-25 19:03:53 +01:00
workspaceLogger . trace ( " get Owner By ItemId " + itemId ) ;
try {
2016-01-19 15:50:40 +01:00
2015-01-28 12:42:48 +01:00
//TEST MODE
2016-11-29 15:16:47 +01:00
/ * if ( ! isWithinPortal ( ) ) {
2015-01-29 11:55:28 +01:00
workspaceLogger . info ( " getOwnerByItemId is in test mode returning owner francesco.mangiacrapa " ) ;
2015-01-28 12:42:48 +01:00
return new InfoContactModel ( " francesco.mangiacrapa " , " francesco.mangiacrapa " , " Francesco Mangiacrapa " , false ) ;
2016-11-29 15:16:47 +01:00
} * /
2016-01-19 15:50:40 +01:00
2013-02-25 19:03:53 +01:00
Workspace workspace = getWorkspace ( ) ;
WorkspaceItem wsItem = workspace . getItem ( itemId ) ;
GWTWorkspaceBuilder builder = getGWTWorkspaceBuilder ( ) ;
return builder . buildGXTInfoContactModel ( wsItem . getOwner ( ) ) ;
2016-01-19 15:50:40 +01:00
2013-02-25 19:03:53 +01:00
} catch ( Exception e ) {
workspaceLogger . error ( " Error in getOwnerByItemId " , e ) ;
throw new Exception ( e . getMessage ( ) ) ;
}
}
2016-01-19 15:50:40 +01:00
2015-03-06 16:12:21 +01:00
/ * ( non - Javadoc )
* @see org . gcube . portlets . user . workspace . client . rpc . GWTWorkspaceService # getUsersManagerToSharedFolder ( java . lang . String )
* /
2017-02-20 11:41:54 +01:00
/ * *
* Gets the users manager to shared folder .
*
* @param folderId the folder id
* @return the users manager to shared folder
* @throws Exception the exception
* /
2014-03-17 14:43:06 +01:00
@Override
public List < InfoContactModel > getUsersManagerToSharedFolder ( String folderId ) throws Exception {
2016-01-19 15:50:40 +01:00
2014-03-17 14:43:06 +01:00
try {
2016-01-19 15:50:40 +01:00
2014-03-17 14:43:06 +01:00
workspaceLogger . info ( " Get User Manager to shared folder id: " + folderId ) ;
Workspace workspace = getWorkspace ( ) ;
List < InfoContactModel > listManagers = new ArrayList < InfoContactModel > ( ) ;
workspaceLogger . info ( " Adding owner.. " ) ;
InfoContactModel owner = getOwnerByItemId ( folderId ) ; //GET OWNER
workspaceLogger . info ( " Added owner: " + owner ) ;
listManagers . add ( owner ) ;
WorkspaceItem wsItem = workspace . getItem ( folderId ) ;
2016-01-19 15:50:40 +01:00
if ( wsItem . isShared ( ) & & wsItem . getType ( ) . equals ( WorkspaceItemType . SHARED_FOLDER ) ) {
2016-03-02 16:04:37 +01:00
WorkspaceSharedFolder ite = ( WorkspaceSharedFolder ) wsItem ;
2016-01-19 15:50:40 +01:00
2014-03-17 14:43:06 +01:00
workspaceLogger . info ( " Retrieving administrators... " ) ;
Map < ACLType , List < String > > aclOwner = ite . getACLOwner ( ) ;
if ( aclOwner ! = null ) {
List < String > listLogins = new ArrayList < String > ( ) ;
workspaceLogger . info ( " Adding administrators... " ) ;
for ( ACLType type : aclOwner . keySet ( ) ) {
switch ( type ) {
case ADMINISTRATOR :
listLogins . addAll ( aclOwner . get ( type ) ) ; //ADD ALL ADMINISTRATORS
break ;
}
}
workspaceLogger . info ( " Added " + listLogins . size ( ) + " administrators, converting into InfoContactModel " ) ;
GWTWorkspaceBuilder builder = getGWTWorkspaceBuilder ( ) ;
2016-01-19 15:50:40 +01:00
2014-03-17 14:43:06 +01:00
List < InfoContactModel > adms = builder . buildGxtInfoContactsFromPortalLogins ( listLogins ) ;
listManagers . addAll ( adms ) ;
workspaceLogger . info ( " Returing " + listManagers . size ( ) + " users managers " ) ;
return listManagers ;
}
} else
throw new Exception ( " Source item is not shared or shared folder " ) ;
2016-01-19 15:50:40 +01:00
2014-03-17 14:43:06 +01:00
} catch ( Exception e ) {
String error = " Sorry an error occurred on get managers " ;
workspaceLogger . error ( error , e ) ;
throw new Exception ( e . getMessage ( ) ) ;
}
return null ;
}
2013-03-25 11:14:26 +01:00
2015-03-06 16:12:21 +01:00
/ * ( non - Javadoc )
* @see org . gcube . portlets . user . workspace . client . rpc . GWTWorkspaceService # itemExistsInWorkpaceFolder ( java . lang . String , java . lang . String )
* /
2017-02-20 11:41:54 +01:00
/ * *
* Item exists in workpace folder .
*
* @param parentId the parent id
* @param itemName the item name
* @return the string
* @throws Exception the exception
* /
2013-03-25 11:14:26 +01:00
@Override
public String itemExistsInWorkpaceFolder ( String parentId , String itemName ) throws Exception {
2016-01-19 15:50:40 +01:00
2013-03-25 11:14:26 +01:00
workspaceLogger . trace ( " get itemExistsInWorkpace by parentId: " + parentId ) ;
System . out . println ( " get itemExistsInWorkpace by parentId: " + parentId ) ;
2016-01-19 15:50:40 +01:00
2013-03-25 11:14:26 +01:00
try {
2016-01-19 15:50:40 +01:00
2013-03-25 11:14:26 +01:00
Workspace workspace = getWorkspace ( ) ;
WorkspaceItem wsItem = workspace . getItem ( parentId ) ; //GET PARENT
2016-01-19 15:50:40 +01:00
2013-03-25 11:14:26 +01:00
if ( wsItem . getType ( ) . equals ( WorkspaceItemType . FOLDER ) | | wsItem . getType ( ) . equals ( WorkspaceItemType . SHARED_FOLDER ) ) {
2016-01-19 15:50:40 +01:00
2013-03-25 11:14:26 +01:00
WorkspaceItem itemFound = workspace . find ( itemName , parentId ) ;
2016-01-19 15:50:40 +01:00
2013-03-25 11:14:26 +01:00
if ( itemFound = = null )
return null ;
2016-01-19 15:50:40 +01:00
2013-03-25 11:14:26 +01:00
return itemFound . getId ( ) ;
}
else
throw new Exception ( " Invalid Folder parent " ) ;
} catch ( InternalErrorException e ) {
return null ;
} catch ( ItemNotFoundException e ) {
return null ;
} catch ( Exception e ) {
String error = " an error occurred on search item in folder " ;
workspaceLogger . error ( error , e ) ;
throw new Exception ( e . getMessage ( ) ) ;
}
}
2013-03-25 12:35:05 +01:00
2015-03-06 16:12:21 +01:00
/ * ( non - Javadoc )
* @see org . gcube . portlets . user . workspace . client . rpc . GWTWorkspaceService # getItemCreationDateById ( java . lang . String )
* /
2017-02-20 11:41:54 +01:00
/ * *
* Gets the item creation date by id .
*
* @param itemId the item id
* @return the item creation date by id
* @throws Exception the exception
* /
2013-03-25 12:35:05 +01:00
@Override
public Date getItemCreationDateById ( String itemId ) throws Exception {
workspaceLogger . trace ( " get Item Creation Date By ItemId " + itemId ) ;
try {
2016-01-19 15:50:40 +01:00
2013-03-25 12:35:05 +01:00
Workspace workspace = getWorkspace ( ) ;
WorkspaceItem wsItem = workspace . getItem ( itemId ) ;
Calendar cl = wsItem . getCreationTime ( ) ;
2016-01-19 15:50:40 +01:00
2013-03-25 12:35:05 +01:00
if ( cl ! = null )
return cl . getTime ( ) ;
2016-01-19 15:50:40 +01:00
2013-03-25 12:35:05 +01:00
return null ;
2016-01-19 15:50:40 +01:00
2013-03-25 12:35:05 +01:00
} catch ( Exception e ) {
workspaceLogger . error ( " get Item Creation Date By ItemId " , e ) ;
throw new Exception ( e . getMessage ( ) ) ;
}
}
2015-03-06 16:12:21 +01:00
/ * ( non - Javadoc )
* @see org . gcube . portlets . user . workspace . client . rpc . GWTWorkspaceService # loadSizeByItemId ( java . lang . String )
* /
2017-02-20 11:41:54 +01:00
/ * *
* Load size by item id .
*
* @param itemId the item id
* @return the long
* @throws Exception the exception
* /
2013-03-25 12:35:05 +01:00
@Override
public Long loadSizeByItemId ( String itemId ) throws Exception {
2016-01-19 15:50:40 +01:00
2014-11-03 14:45:36 +01:00
workspaceLogger . info ( " get Size By ItemId " + itemId ) ;
2013-03-25 12:35:05 +01:00
try {
2016-01-19 15:50:40 +01:00
2013-03-25 12:35:05 +01:00
Workspace workspace = getWorkspace ( ) ;
WorkspaceItem wsItem = workspace . getItem ( itemId ) ;
Long size = new Long ( - 1 ) ;
2016-01-19 15:50:40 +01:00
2014-11-03 14:45:36 +01:00
if ( wsItem instanceof FolderItem ) { //ITEM
2013-03-25 12:35:05 +01:00
FolderItem folderItem = ( FolderItem ) wsItem ;
size = new Long ( folderItem . getLength ( ) ) ;
2014-11-03 14:45:36 +01:00
} else if ( wsItem instanceof WorkspaceFolder ) { //FOLDER
2014-10-28 17:12:40 +01:00
WorkspaceFolder theFolder = ( WorkspaceFolder ) wsItem ;
size = theFolder . getSize ( ) ;
2014-11-03 14:45:36 +01:00
} else if ( wsItem instanceof WorkspaceSharedFolder ) { //SHARED FOLDER
WorkspaceSharedFolder theFolder = ( WorkspaceSharedFolder ) wsItem ;
size = theFolder . getSize ( ) ;
2013-03-25 12:35:05 +01:00
}
2014-11-03 14:45:36 +01:00
workspaceLogger . info ( " returning size: " + size ) ;
2013-03-25 12:35:05 +01:00
return size ;
2016-01-19 15:50:40 +01:00
2013-03-25 12:35:05 +01:00
} catch ( Exception e ) {
workspaceLogger . error ( " get Size By ItemId " , e ) ;
throw new Exception ( e . getMessage ( ) ) ;
}
}
2016-01-19 15:50:40 +01:00
2015-03-06 16:12:21 +01:00
/ * ( non - Javadoc )
* @see org . gcube . portlets . user . workspace . client . rpc . GWTWorkspaceService # loadLastModificationDateById ( java . lang . String )
* /
2017-02-20 11:41:54 +01:00
/ * *
* Load last modification date by id .
*
* @param itemId the item id
* @return the date
* @throws Exception the exception
* /
2013-03-26 12:35:58 +01:00
@Override
public Date loadLastModificationDateById ( String itemId ) throws Exception {
2016-01-19 15:50:40 +01:00
2013-03-26 12:35:58 +01:00
workspaceLogger . trace ( " get last modification date ItemId " + itemId ) ;
try {
2016-01-19 15:50:40 +01:00
Workspace workspace = getWorkspace ( ) ;
2013-03-26 12:35:58 +01:00
WorkspaceItem wsItem = workspace . getItem ( itemId ) ;
wsItem . getLastModificationTime ( ) . getTime ( ) ;
Date lastModification = null ;
2016-01-19 15:50:40 +01:00
2013-03-26 12:35:58 +01:00
if ( wsItem . getLastModificationTime ( ) ! = null ) {
lastModification = wsItem . getLastModificationTime ( ) . getTime ( ) ;
}
2016-01-19 15:50:40 +01:00
2013-03-26 12:35:58 +01:00
return lastModification ;
2016-01-19 15:50:40 +01:00
2013-03-26 12:35:58 +01:00
} catch ( Exception e ) {
workspaceLogger . error ( " get last modification date ItemId " , e ) ;
throw new Exception ( e . getMessage ( ) ) ;
}
}
2013-03-27 17:30:37 +01:00
2015-03-06 16:12:21 +01:00
/ * ( non - Javadoc )
* @see org . gcube . portlets . user . workspace . client . rpc . GWTWorkspaceService # getParentByItemId ( java . lang . String )
* /
2017-02-20 11:41:54 +01:00
/ * *
* Gets the parent by item id .
*
* @param identifier the identifier
* @return the parent by item id
* @throws Exception the exception
* /
2013-03-27 17:30:37 +01:00
@Override
public FileModel getParentByItemId ( String identifier ) throws Exception {
2016-01-19 15:50:40 +01:00
2013-03-27 17:30:37 +01:00
workspaceLogger . trace ( " get Parent By Item Identifier " + identifier ) ;
try {
2016-01-19 15:50:40 +01:00
2013-03-27 17:30:37 +01:00
Workspace workspace = getWorkspace ( ) ;
WorkspaceItem wsItem = workspace . getItem ( identifier ) ;
workspaceLogger . trace ( " workspace retrieve item name: " + wsItem . getName ( ) ) ;
GWTWorkspaceBuilder builder = getGWTWorkspaceBuilder ( ) ;
while ( wsItem ! = null & & wsItem . getParent ( ) ! = null ) {
2016-01-19 15:50:40 +01:00
2013-03-27 17:30:37 +01:00
WorkspaceFolder wsFolder = wsItem . getParent ( ) ;
workspaceLogger . trace ( " parent was found " + wsFolder . getName ( ) + " retuning " ) ;
return builder . buildGXTFolderModelItem ( wsFolder , null ) ;
}
workspaceLogger . trace ( " parent not found - retuning " ) ;
return null ;
} catch ( Exception e ) {
workspaceLogger . error ( " Error in get Parent By Item Identifier " , e ) ;
e . printStackTrace ( ) ;
throw new Exception ( e . getMessage ( ) ) ;
}
}
2016-01-19 15:50:40 +01:00
2015-03-06 16:12:21 +01:00
/ * ( non - Javadoc )
* @see org . gcube . portlets . user . workspace . client . rpc . GWTWorkspaceService # getAccountingReaders ( java . lang . String )
* /
2017-02-20 11:41:54 +01:00
/ * *
* Gets the accounting readers .
*
* @param identifier the identifier
* @return the accounting readers
* @throws Exception the exception
* /
2013-05-23 19:03:43 +02:00
@Override
public List < GxtAccountingField > getAccountingReaders ( String identifier ) throws Exception {
2016-01-19 15:50:40 +01:00
2013-05-23 19:03:43 +02:00
workspaceLogger . trace ( " get accounting readers " + identifier ) ;
try {
2016-01-19 15:50:40 +01:00
2013-05-23 19:03:43 +02:00
Workspace workspace = getWorkspace ( ) ;
WorkspaceItem wsItem = workspace . getItem ( identifier ) ;
GWTWorkspaceBuilder builder = getGWTWorkspaceBuilder ( ) ;
List < GxtAccountingField > listReaders = builder . buildGXTAccountingItemFromReaders ( wsItem . getReaders ( ) ) ;
workspaceLogger . trace ( " get accounting readers - returning size " + listReaders . size ( ) ) ;
return listReaders ;
} catch ( Exception e ) {
workspaceLogger . error ( " Error get accounting readers " , e ) ;
String error = ConstantsExplorer . SERVER_ERROR + " getting account. " + ConstantsExplorer . TRY_AGAIN ;
throw new Exception ( error ) ;
}
}
2016-01-19 15:50:40 +01:00
2015-03-06 16:12:21 +01:00
/ * ( non - Javadoc )
* @see org . gcube . portlets . user . workspace . client . rpc . GWTWorkspaceService # getAccountingHistory ( java . lang . String )
* /
2017-02-20 11:41:54 +01:00
/ * *
* Gets the accounting history .
*
* @param identifier the identifier
* @return the accounting history
* @throws Exception the exception
* /
2013-05-23 19:03:43 +02:00
@Override
public List < GxtAccountingField > getAccountingHistory ( String identifier ) throws Exception {
2016-01-19 15:50:40 +01:00
2013-05-23 19:03:43 +02:00
workspaceLogger . trace ( " get accounting history " + identifier ) ;
try {
2016-01-19 15:50:40 +01:00
2013-05-23 19:03:43 +02:00
Workspace workspace = getWorkspace ( ) ;
WorkspaceItem wsItem = workspace . getItem ( identifier ) ;
List < AccountingEntry > accoutings = wsItem . getAccounting ( ) ;
GWTWorkspaceBuilder builder = getGWTWorkspaceBuilder ( ) ;
2013-08-28 14:36:38 +02:00
List < GxtAccountingField > listReaders = builder . buildGXTAccountingItem ( accoutings , GxtAccountingEntryType . ALL ) ;
2013-05-23 19:03:43 +02:00
workspaceLogger . trace ( " get accounting readers - returning size " + listReaders . size ( ) ) ;
return listReaders ;
} catch ( Exception e ) {
workspaceLogger . error ( " Error get accounting readers " , e ) ;
String error = ConstantsExplorer . SERVER_ERROR + " getting account. " + ConstantsExplorer . TRY_AGAIN ;
throw new Exception ( error ) ;
}
}
2013-06-28 18:42:10 +02:00
/ * ( non - Javadoc )
* @see org . gcube . portlets . user . workspace . client . rpc . GWTWorkspaceService # getShortUrl ( java . lang . String )
* /
2017-02-20 11:41:54 +01:00
/ * *
* Gets the short url .
*
* @param longUrl the long url
* @return the short url
* @throws Exception the exception
* /
2013-06-28 18:42:10 +02:00
@Override
public String getShortUrl ( String longUrl ) throws Exception {
2016-01-19 15:50:40 +01:00
2013-06-28 18:42:10 +02:00
workspaceLogger . trace ( " get short url for " + longUrl ) ;
2013-07-01 15:54:54 +02:00
UrlShortener shortener = getUrlShortener ( ) ;
2013-06-28 18:42:10 +02:00
try {
2016-01-19 15:50:40 +01:00
2013-07-01 15:54:54 +02:00
if ( shortener ! = null & & shortener . isAvailable ( ) )
return shortener . shorten ( longUrl ) ;
2016-01-19 15:50:40 +01:00
2013-07-01 15:54:54 +02:00
return longUrl ;
2016-01-19 15:50:40 +01:00
2013-06-28 18:42:10 +02:00
} catch ( Exception e ) {
workspaceLogger . error ( " Error get short url for " , e ) ;
2016-09-14 14:30:33 +02:00
return null ;
2013-06-28 18:42:10 +02:00
}
}
2016-01-19 15:50:40 +01:00
2013-07-08 17:42:08 +02:00
/ * *
2015-03-06 16:12:21 +01:00
* Gets the public link for folder item id .
*
* @param itemId the item id
* @param shortenUrl the shorten url
* @return the public link for folder item id
* @throws Exception the exception
2013-07-08 17:42:08 +02:00
* /
@Override
2015-07-03 12:18:27 +02:00
public PublicLink getPublicLinkForFolderItemId ( String itemId , boolean shortenUrl ) throws Exception {
2013-07-08 17:42:08 +02:00
workspaceLogger . trace ( " get Public Link For ItemId: " + itemId ) ;
try {
2016-01-19 15:50:40 +01:00
if ( itemId = = null )
throw new Exception ( " Sorry, The Public Link for empty item is unavailable (itemId is null) " ) ;
2013-07-08 17:42:08 +02:00
Workspace workspace = getWorkspace ( ) ;
WorkspaceItem wsItem = workspace . getItem ( itemId ) ;
2016-01-19 15:50:40 +01:00
if ( wsItem = = null )
throw new Exception ( " Sorry, The Public Link for empty item is unavailable " ) ;
2013-07-08 17:42:08 +02:00
if ( wsItem . getType ( ) . equals ( WorkspaceItemType . FOLDER_ITEM ) ) {
2016-01-19 15:50:40 +01:00
FolderItem folderItem = ( FolderItem ) wsItem ;
String uriRequest = folderItem . getPublicLink ( false ) ;
if ( uriRequest = = null | | uriRequest . isEmpty ( ) )
throw new Exception ( " Sorry, public link on " + folderItem . getName ( ) + " is not available " ) ;
String shortURL = null ;
2016-09-14 14:30:33 +02:00
if ( shortenUrl ) {
2016-01-19 15:50:40 +01:00
shortURL = getShortUrl ( uriRequest ) ;
2016-09-14 14:30:33 +02:00
shortURL = shortURL ! = null ? shortURL : " not available " ;
}
2016-01-19 15:50:40 +01:00
return new PublicLink ( uriRequest , shortURL ) ;
2013-07-11 15:37:35 +02:00
} else {
2015-07-03 11:23:37 +02:00
workspaceLogger . warn ( " ItemId: " + itemId + " is not a folder item, sent exception Public Link unavailable " ) ;
2013-07-11 15:37:35 +02:00
throw new Exception ( " Sorry, The Public Link for selected file is unavailable " ) ;
2013-07-08 17:42:08 +02:00
}
2013-07-11 15:37:35 +02:00
2013-07-08 17:42:08 +02:00
} catch ( Exception e ) {
2014-01-21 18:11:36 +01:00
workspaceLogger . error ( " Error getPublicLinkForFolderItemId for item: " + itemId , e ) ;
2013-07-11 11:55:56 +02:00
throw new Exception ( e . getMessage ( ) ) ;
2013-07-08 17:42:08 +02:00
}
2016-01-19 15:50:40 +01:00
2013-07-08 17:42:08 +02:00
}
2013-09-02 12:43:57 +02:00
/ * ( non - Javadoc )
* @see org . gcube . portlets . user . workspace . client . rpc . GWTWorkspaceService # isSessionExpired ( )
* /
2017-02-20 11:41:54 +01:00
/ * *
* Checks if is session expired .
*
* @return true , if is session expired
* @throws Exception the exception
* /
2013-09-02 12:43:57 +02:00
@Override
public boolean isSessionExpired ( ) throws Exception {
2016-11-25 12:03:25 +01:00
return WsUtil . isSessionExpired ( this . getThreadLocalRequest ( ) ) ;
2013-09-02 12:43:57 +02:00
}
2014-01-15 12:49:40 +01:00
/ * ( non - Javadoc )
* @see org . gcube . portlets . user . workspace . client . rpc . GWTWorkspaceService # deleteListItemsForIds ( java . util . List )
* /
2017-02-20 11:41:54 +01:00
/ * *
* Delete list items for ids .
*
* @param ids the ids
* @return the list
* @throws Exception the exception
* /
2014-01-15 12:49:40 +01:00
@Override
2015-10-29 15:36:27 +01:00
public List < GarbageItem > deleteListItemsForIds ( List < String > ids ) throws Exception {
2016-01-19 15:50:40 +01:00
2014-01-15 12:49:40 +01:00
try {
2016-01-19 15:50:40 +01:00
2014-01-15 12:49:40 +01:00
if ( ids = = null )
2016-01-19 15:50:40 +01:00
throw new Exception ( " List identifiers is null " ) ;
2014-01-15 12:49:40 +01:00
Workspace workspace = getWorkspace ( ) ;
workspaceLogger . trace ( " removeItem item for list size: " + ids . size ( ) ) ;
2015-10-29 15:36:27 +01:00
String [ ] items = new String [ ids . size ( ) ] ;
items = ids . toArray ( items ) ;
2016-01-19 15:50:40 +01:00
2015-10-29 15:36:27 +01:00
Map < String , GarbageItem > garbage = new HashMap < String , GarbageItem > ( items . length ) ;
2016-01-19 15:50:40 +01:00
2015-10-29 15:36:27 +01:00
//SAVE DATE FOR NOTIFICATIONS
2014-01-15 12:49:40 +01:00
for ( String itemId : ids ) {
//NOTIFICATION
WorkspaceItem wsItem = workspace . getItem ( itemId ) ;
//SAVING ATTRIBUTE FOR NOTIFICATION
boolean sourceItemIsShared = wsItem . isShared ( ) ;
String itemName = wsItem . getName ( ) ;
String sourceFolderSharedId = null ;
if ( sourceItemIsShared ) {
sourceFolderSharedId = wsItem . getIdSharedFolder ( ) ;
2016-01-19 15:50:40 +01:00
}
2014-01-15 12:49:40 +01:00
//REMOVE ITEM
2016-01-19 15:50:40 +01:00
2015-10-29 15:36:27 +01:00
garbage . put ( itemId , new GarbageItem ( sourceItemIsShared , itemName , itemId , sourceFolderSharedId ) ) ;
2016-01-19 15:50:40 +01:00
2016-06-22 18:41:51 +02:00
// workspace.removeItem(itemId);
// //IF SOURCE SHARED FOLDER IS NOT NULL
// if(sourceFolderSharedId!=null)
// NotificationsUtil.checkSendNotifyRemoveItemToShare(this.getThreadLocalRequest().getSession(), sourceItemIsShared, itemName, itemId, sourceFolderSharedId);
2015-10-29 15:36:27 +01:00
}
2016-01-19 15:50:40 +01:00
2015-10-29 15:36:27 +01:00
//ITEM ID - ERROR
Map < String , String > backendError = workspace . removeItems ( items ) ;
2016-01-19 15:50:40 +01:00
2015-10-29 15:36:27 +01:00
//GARBAGE ITEM ERROR
List < GarbageItem > frontEndError = new ArrayList < GarbageItem > ( backendError . size ( ) ) ;
2016-01-19 15:50:40 +01:00
2015-10-29 15:36:27 +01:00
//REMOVING IDS WHICH HAVE GENERATED AN ERROR
for ( String idError : backendError . keySet ( ) ) {
GarbageItem gbi = garbage . get ( idError ) ;
if ( gbi ! = null ) {
frontEndError . add ( gbi ) ;
garbage . remove ( idError ) ;
}
}
2016-01-19 15:50:40 +01:00
2015-10-29 15:36:27 +01:00
for ( String idItem : garbage . keySet ( ) ) {
GarbageItem item = garbage . get ( idItem ) ;
workspaceLogger . trace ( " Check notification for " + item ) ;
2014-01-15 12:49:40 +01:00
//IF SOURCE SHARED FOLDER IS NOT NULL
2015-10-29 15:36:27 +01:00
if ( item . getSourceFolderSharedId ( ) ! = null )
2016-11-25 12:03:25 +01:00
NotificationsUtil . checkSendNotifyRemoveItemToShare ( this . getThreadLocalRequest ( ) , item . isSourceItemIsShared ( ) , item . getOldItemName ( ) , item . getOldItemName ( ) , item . getSourceFolderSharedId ( ) ) ;
2014-01-15 12:49:40 +01:00
}
2016-01-19 15:50:40 +01:00
2015-10-29 15:36:27 +01:00
return frontEndError ;
2014-01-15 12:49:40 +01:00
} catch ( InsufficientPrivilegesException e ) {
workspaceLogger . error ( " Error in server Item remove " , e ) ;
String error = " An error occurred on deleting item. " + e . getMessage ( ) ;
throw new Exception ( error ) ;
} catch ( ItemNotFoundException e ) {
String error = " An error occurred on deleting item. " + ConstantsExplorer . ERROR_ITEM_DOES_NOT_EXIST ;
workspaceLogger . error ( error , e ) ;
throw new Exception ( error ) ;
} catch ( Exception e ) {
workspaceLogger . error ( " Error in server Item remove " , e ) ;
String error = ConstantsExplorer . SERVER_ERROR + " deleting item. " + e . getMessage ( ) ;
throw new Exception ( error ) ;
}
2016-01-19 15:50:40 +01:00
2014-01-15 12:49:40 +01:00
}
2016-01-19 15:50:40 +01:00
2015-03-06 16:12:21 +01:00
/ * ( non - Javadoc )
* @see org . gcube . portlets . user . workspace . client . rpc . GWTWorkspaceService # setACLs ( java . lang . String , java . util . List , java . lang . String )
2014-02-11 12:53:10 +01:00
* /
2017-02-20 11:41:54 +01:00
/ * *
* Sets the ac ls .
*
* @param folderId the folder id
* @param listLogins the list logins
* @param aclType the acl type
* @throws Exception the exception
* /
2014-02-11 12:53:10 +01:00
@Override
public void setACLs ( String folderId , List < String > listLogins , String aclType ) throws Exception {
try {
2014-02-11 16:41:56 +01:00
2014-02-11 12:53:10 +01:00
if ( folderId = = null )
2016-01-19 15:50:40 +01:00
throw new Exception ( " Folder id is null " ) ;
2014-02-11 12:53:10 +01:00
if ( listLogins = = null | | listLogins . size ( ) = = 0 )
throw new Exception ( " List Logins is null or empty " ) ;
2016-01-19 15:50:40 +01:00
2014-02-11 16:41:56 +01:00
workspaceLogger . trace ( " Setting ACL for folder id: " + folderId ) ;
2016-01-19 15:50:40 +01:00
workspaceLogger . trace ( " ACL type is: " + aclType ) ;
2014-02-11 12:53:10 +01:00
Workspace workspace = getWorkspace ( ) ;
WorkspaceItem wsItem = workspace . getItem ( folderId ) ;
2016-01-19 15:50:40 +01:00
2015-02-16 15:36:11 +01:00
//IS A WORKSPACE FOLDER?
2015-01-28 12:42:48 +01:00
if ( wsItem ! = null & & wsItem . isFolder ( ) & & wsItem . isShared ( ) ) {
2015-02-16 15:36:11 +01:00
WorkspaceFolder ite ;
2016-01-19 15:50:40 +01:00
if ( wsItem . getType ( ) . equals ( WorkspaceItemType . SHARED_FOLDER ) ) {
2015-01-28 12:42:48 +01:00
//IS ROOT SHARED FOLDER
2015-02-16 15:36:11 +01:00
ite = ( WorkspaceSharedFolder ) wsItem ;
workspaceLogger . trace ( " Folder " + ite . getName ( ) + " is a " + WorkspaceSharedFolder . class . getName ( ) ) ;
2016-06-22 18:41:51 +02:00
// ite = (WorkspaceSharedFolder) workspace.getItemByPath(wsItem.getPath());
2016-01-19 15:50:40 +01:00
} else {
// IS SUB FOLDER OF THE SHARING
2015-02-16 15:36:11 +01:00
ite = ( WorkspaceFolder ) wsItem ;
workspaceLogger . trace ( " Folder " + ite . getName ( ) + " is a " + WorkspaceFolder . class . getName ( ) ) ;
2016-06-22 18:41:51 +02:00
// ite = (WorkspaceSharedFolder) workspace.getItem(wsItem.getIdSharedFolder());
2015-01-28 12:42:48 +01:00
}
2017-03-03 12:06:49 +01:00
2014-02-11 12:53:10 +01:00
ite . setACL ( listLogins , ACLType . valueOf ( aclType ) ) ;
} else
throw new Exception ( " Source item is not shared or shared folder " ) ;
2016-01-19 15:50:40 +01:00
2015-02-16 15:36:11 +01:00
workspaceLogger . info ( " Setting ACL for " + wsItem . getName ( ) + " completed, returning " ) ;
2014-02-11 12:53:10 +01:00
} catch ( Exception e ) {
workspaceLogger . error ( " Error in set ACLs " , e ) ;
String error = ConstantsExplorer . SERVER_ERROR + " setting permissions. " + e . getMessage ( ) ;
throw new Exception ( error ) ;
}
}
2016-01-19 15:50:40 +01:00
2014-02-11 12:53:10 +01:00
/ * *
2015-03-06 16:12:21 +01:00
* Validate acl to user .
*
* @param folderId the folder id
* @param listLogins the list logins
* @param aclType the acl type
* @return the report assignment acl
* @throws Exception the exception
* /
@Override
public ReportAssignmentACL validateACLToUser ( String folderId , List < String > listLogins , String aclType ) throws Exception {
2016-01-19 15:50:40 +01:00
2015-03-06 16:12:21 +01:00
if ( folderId = = null )
2016-01-19 15:50:40 +01:00
throw new Exception ( " Folder id is null " ) ;
2015-03-06 16:12:21 +01:00
if ( listLogins = = null | | listLogins . size ( ) = = 0 )
throw new Exception ( " List Logins is null or empty " ) ;
if ( isASharedFolder ( folderId , false ) ) {
2016-01-19 15:50:40 +01:00
2015-03-06 16:12:21 +01:00
try {
Workspace workspace = getWorkspace ( ) ;
WorkspaceFolder folder = ( WorkspaceFolder ) workspace . getItem ( folderId ) ;
2016-01-19 15:50:40 +01:00
2015-03-13 17:06:15 +01:00
if ( ! folder . getType ( ) . equals ( WorkspaceItemType . SHARED_FOLDER ) ) { //IS NOT ROOT SHARED FOLDER?
WorkspaceFolder parent = folder . getParent ( ) ;
if ( parent ! = null )
folder = parent ;
else
workspaceLogger . warn ( " Parent folder of folder: " + folder . getName ( ) + " is null, using current folder " ) ;
}
2017-03-03 12:06:49 +01:00
2015-03-06 16:12:21 +01:00
Map < ACLType , List < String > > mapACL = folder . getACLOwner ( ) ;
2016-01-19 15:50:40 +01:00
2015-03-06 16:12:21 +01:00
ACLType settingACL = ACLType . valueOf ( aclType ) ;
2016-01-19 15:50:40 +01:00
2015-03-06 16:12:21 +01:00
workspaceLogger . info ( " Validating assignment: " + settingACL ) ;
workspaceLogger . info ( " To logins: " + listLogins ) ;
2016-01-19 15:50:40 +01:00
2015-03-06 16:12:21 +01:00
AclTypeComparator comparator = new AclTypeComparator ( ) ;
2016-01-19 15:50:40 +01:00
2017-03-03 12:06:49 +01:00
List < String > errors = new ArrayList < String > ( ) ;
2015-03-06 16:12:21 +01:00
//TO REMOVE ADMINS
List < String > admins = mapACL . get ( ACLType . ADMINISTRATOR ) ;
for ( String admin : admins ) {
2017-03-03 12:58:04 +01:00
boolean removed = listLogins . remove ( admin ) ;
2015-03-06 16:12:21 +01:00
workspaceLogger . info ( " Reject username: " + admin + " as " + ACLType . ADMINISTRATOR ) ;
2017-03-03 12:58:04 +01:00
if ( removed ) {
String fullname = isTestMode ( ) ? admin : UserUtil . getUserFullName ( admin ) ;
errors . add ( " Unable to grant the privilege " + settingACL + " for " + fullname + " , he/she is an: " + ACLType . ADMINISTRATOR ) ;
}
2015-03-06 16:12:21 +01:00
}
2016-01-19 15:50:40 +01:00
2017-03-03 12:58:04 +01:00
//TO COMPLETE REPORT
List < String > validLogins = new ArrayList < String > ( listLogins ) ;
2015-03-06 16:12:21 +01:00
ReportAssignmentACL reportValidation = new ReportAssignmentACL ( ) ;
2016-01-19 15:50:40 +01:00
2017-03-03 12:58:04 +01:00
workspaceLogger . debug ( " \ nChecking listLogins: " + listLogins ) ;
2015-03-06 16:12:21 +01:00
for ( String username : listLogins ) {
workspaceLogger . trace ( " \ nChecking username: " + username ) ;
for ( ACLType aclHL : mapACL . keySet ( ) ) {
if ( ! aclHL . equals ( ACLType . ADMINISTRATOR ) ) {
List < String > loginsHL = mapACL . get ( aclHL ) ;
workspaceLogger . trace ( " to ACLType: " + aclHL + " , logins found: " + loginsHL ) ;
if ( loginsHL . contains ( username ) ) {
int cmp = comparator . compare ( settingACL , aclHL ) ;
workspaceLogger . trace ( " Compare result between " + aclHL + " and " + settingACL + " : " + cmp ) ;
String fullname = isTestMode ( ) ? username : UserUtil . getUserFullName ( username ) ;
if ( cmp = = - 1 ) {
//CHANGE ACL IS NOT VALID
workspaceLogger . trace ( " Reject ACL: " + settingACL + " to " + username ) ;
validLogins . remove ( username ) ;
2015-03-13 17:06:15 +01:00
errors . add ( " Unable to grant the privilege " + settingACL + " for " + fullname + " , it's lower than (parent privilege) " + aclHL ) ;
2015-03-06 16:12:21 +01:00
break ;
} else if ( cmp = = 0 ) {
//SAME ACL
workspaceLogger . trace ( " Skipping ACL: " + settingACL + " to " + username ) ;
2015-03-06 18:15:33 +01:00
errors . add ( settingACL + " privilege for " + fullname + " already assigned " ) ;
2015-03-06 16:12:21 +01:00
validLogins . remove ( username ) ;
break ;
} else if ( cmp = = 1 ) {
//CHANGE ACL IS VALID
workspaceLogger . trace ( " Valid ACL: " + settingACL + " to " + username ) ;
}
} else {
//CHANGE ACL IS VALID
workspaceLogger . trace ( " [Login not found], Set ACL: " + settingACL + " to " + username ) ;
}
}
2016-01-19 15:50:40 +01:00
}
2015-03-06 16:12:21 +01:00
}
2017-03-03 12:58:04 +01:00
workspaceLogger . info ( " Valid logins: " ) ;
2015-03-06 16:12:21 +01:00
for ( String username : validLogins ) {
2017-03-03 12:58:04 +01:00
workspaceLogger . info ( " Set ACL: " + settingACL + " to " + username ) ;
2015-03-06 16:12:21 +01:00
}
2017-03-03 12:58:04 +01:00
/ *
2015-03-06 16:12:21 +01:00
System . out . println ( " \ n " ) ;
for ( String error : errors ) {
workspaceLogger . trace ( error ) ;
} * /
2016-01-19 15:50:40 +01:00
2015-03-06 16:12:21 +01:00
reportValidation . setAclType ( aclType ) ;
reportValidation . setErrors ( errors ) ;
reportValidation . setValidLogins ( validLogins ) ;
return reportValidation ;
2016-01-19 15:50:40 +01:00
2015-03-06 16:12:21 +01:00
} catch ( InternalErrorException e ) {
throw new Exception ( " Sorry, an error occurred when validating ACL assignment, try again later " ) ;
}
} else
throw new WorkspaceHandledException ( " the item with " + folderId + " is not a base shared folder! " ) ;
}
/ * *
* Gets the AC ls .
*
* @return the AC ls
* @throws Exception the exception
2014-02-11 12:53:10 +01:00
* /
@Override
public List < WorkspaceACL > getACLs ( ) throws Exception {
try {
2014-02-17 15:56:42 +01:00
GWTWorkspaceBuilder builder = getGWTWorkspaceBuilder ( ) ;
return builder . getWorkspaceACLFromACLs ( Arrays . asList ( ACLType . values ( ) ) ) ;
2014-02-11 12:53:10 +01:00
} catch ( Exception e ) {
workspaceLogger . error ( " Error in server get ACLs " , e ) ;
String error = ConstantsExplorer . SERVER_ERROR + " get ACL rules. " + e . getMessage ( ) ;
throw new Exception ( error ) ;
}
}
2016-01-19 15:50:40 +01:00
2014-10-28 17:12:40 +01:00
/ * *
2015-03-06 16:12:21 +01:00
* Checks if is within portal .
*
2014-10-28 17:12:40 +01:00
* @return true if you ' re running into the portal , false if in development
* /
private boolean isWithinPortal ( ) {
try {
UserLocalServiceUtil . getService ( ) ;
return true ;
2016-01-19 15:50:40 +01:00
}
catch ( Exception ex ) {
2014-10-28 17:12:40 +01:00
workspaceLogger . trace ( " Development Mode ON " ) ;
return false ;
2016-01-19 15:50:40 +01:00
}
2014-10-28 17:12:40 +01:00
}
2016-01-19 15:50:40 +01:00
2015-03-06 16:12:21 +01:00
/ * ( non - Javadoc )
* @see org . gcube . portlets . user . workspace . client . rpc . GWTWorkspaceService # getMyLogin ( )
* /
2017-02-20 11:41:54 +01:00
/ * *
* Gets the my login .
*
* @param currentPortletUrl the current portlet url
* @return the my login
* /
2014-02-12 12:49:07 +01:00
@Override
2016-09-16 11:12:03 +02:00
public UserBean getMyLogin ( String currentPortletUrl ) {
2016-11-25 12:03:25 +01:00
PortalContextInfo info = WsUtil . getPortalContext ( this . getThreadLocalRequest ( ) ) ;
String username = info . getUsername ( ) ;
String email = info . getUserEmail ( ) ;
2014-10-28 17:12:40 +01:00
String firstName = " Testing " ;
String lastName = " User " ;
2016-01-19 15:50:40 +01:00
2016-11-25 12:16:32 +01:00
if ( isWithinPortal ( ) & & username ! = null ) {
2016-06-22 18:41:51 +02:00
try {
LiferayUserManager l = new LiferayUserManager ( ) ;
GCubeUser user = l . getUserByUsername ( username ) ;
firstName = user . getFirstName ( ) ;
lastName = user . getLastName ( ) ;
email = user . getEmail ( ) ;
} catch ( UserManagementSystemException e ) {
workspaceLogger . error ( " UserManagementSystemException for username: " + username ) ;
}
catch ( UserRetrievalFault e ) {
workspaceLogger . error ( " UserRetrievalFault for username: " + username ) ;
2016-09-14 12:49:19 +02:00
} catch ( Exception e ) {
2016-09-14 12:52:48 +02:00
workspaceLogger . error ( " Error during getMyLogin for username: " + username , e ) ;
2016-06-22 18:41:51 +02:00
}
2016-01-19 15:50:40 +01:00
2014-10-28 17:12:40 +01:00
}
2016-08-29 15:39:13 +02:00
2017-01-25 12:05:57 +01:00
UserBean us = new UserBean ( username , firstName , lastName , email ) ;
2016-08-29 15:39:13 +02:00
workspaceLogger . info ( " Returning myLogin: " + us ) ;
return us ;
}
/ * ( non - Javadoc )
* @see org . gcube . portlets . user . workspace . client . rpc . GWTWorkspaceService # getMyLogin ( )
* /
2017-02-20 11:41:54 +01:00
/ * *
* Gets the my first name .
*
* @return the my first name
* /
2016-08-29 15:39:13 +02:00
@Override
public String getMyFirstName ( ) {
2016-12-22 11:34:59 +01:00
if ( ! isWithinPortal ( ) )
return " " ;
2016-11-25 12:03:25 +01:00
PortalContextInfo info = WsUtil . getPortalContext ( this . getThreadLocalRequest ( ) ) ;
String username = info . getUsername ( ) ;
2016-08-29 15:39:13 +02:00
String firstName = " " ;
2016-11-25 12:16:32 +01:00
if ( isWithinPortal ( ) & & username ! = null ) {
2016-08-29 15:39:13 +02:00
try {
LiferayUserManager l = new LiferayUserManager ( ) ;
GCubeUser user = l . getUserByUsername ( username ) ;
workspaceLogger . info ( " My login first name is: " + user . getFirstName ( ) ) ;
firstName = user . getFirstName ( ) ;
} catch ( UserManagementSystemException e ) {
workspaceLogger . error ( " UserManagementSystemException for username: " + username ) ;
}
catch ( UserRetrievalFault e ) {
workspaceLogger . error ( " UserRetrievalFault for username: " + username ) ;
}
}
return firstName ;
2014-02-12 12:49:07 +01:00
}
2016-01-19 15:50:40 +01:00
2016-08-29 15:39:13 +02:00
2014-02-14 15:28:35 +01:00
/ * *
2015-03-06 16:12:21 +01:00
* Update acl for vr eby group name .
*
* @param folderId the folder id
* @param aclType the acl type
* @throws Exception the exception
2014-02-14 15:28:35 +01:00
* /
@Override
2014-03-18 11:13:34 +01:00
public void updateACLForVREbyGroupName ( String folderId , String aclType ) throws Exception {
2014-02-14 15:28:35 +01:00
try {
if ( folderId = = null )
2016-01-19 15:50:40 +01:00
throw new Exception ( " Folder id is null " ) ;
2014-03-06 15:31:04 +01:00
workspaceLogger . trace ( " Updating ACL to VRE FOLDER id: " + folderId ) ;
2014-02-14 15:28:35 +01:00
workspaceLogger . trace ( " ACL type is: " + aclType ) ;
2016-01-19 15:50:40 +01:00
2014-02-14 15:28:35 +01:00
Workspace workspace = getWorkspace ( ) ;
WorkspaceItem wsItem = workspace . getItem ( folderId ) ;
2016-01-19 15:50:40 +01:00
if ( wsItem . isShared ( ) & & wsItem . getType ( ) . equals ( WorkspaceItemType . SHARED_FOLDER ) ) {
2016-03-02 16:04:37 +01:00
WorkspaceSharedFolder ite = ( WorkspaceSharedFolder ) wsItem ;
2014-03-17 18:22:59 +01:00
//PATCH TODO TEMPORARY SOLUTION
if ( ite . isVreFolder ( ) ) {
List < String > groupName = new ArrayList < String > ( ) ;
groupName . add ( wsItem . getName ( ) ) ;
ite . setACL ( groupName , ACLType . valueOf ( aclType ) ) ;
}
2014-02-14 15:28:35 +01:00
} else
throw new Exception ( " Source item is not shared or shared folder " ) ;
2016-01-19 15:50:40 +01:00
2014-03-06 15:31:04 +01:00
workspaceLogger . trace ( " Updating ACL completed, retuning " ) ;
2014-02-14 15:28:35 +01:00
} catch ( Exception e ) {
workspaceLogger . error ( " Error in set ACLs " , e ) ;
2014-03-06 15:31:04 +01:00
String error = ConstantsExplorer . SERVER_ERROR + " updating permissions. " + e . getMessage ( ) ;
2014-02-14 15:28:35 +01:00
throw new Exception ( error ) ;
}
}
2016-01-19 15:50:40 +01:00
2014-02-17 15:56:42 +01:00
/ * *
2015-03-06 16:12:21 +01:00
* Gets the user acl for folder id .
*
* @param folderId the folder id
* @return the user acl for folder id
* @throws Exception the exception
2014-02-17 15:56:42 +01:00
* /
@Override
2014-07-14 15:59:32 +02:00
public List < ExtendedWorkspaceACL > getUserACLForFolderId ( String folderId ) throws Exception {
2014-02-17 15:56:42 +01:00
try {
2014-03-17 17:59:06 +01:00
workspaceLogger . info ( " Get user ACL to FOLDER id: " + folderId ) ;
2015-02-16 14:46:38 +01:00
WorkspaceFolder wsFolder = getSharedWorkspaceFolderForId ( folderId ) ;
2014-02-19 16:11:28 +01:00
GWTWorkspaceBuilder builder = getGWTWorkspaceBuilder ( ) ;
2014-07-14 15:59:32 +02:00
List < WorkspaceACL > listACL = builder . getWorkspaceACLFromACLs ( Arrays . asList ( wsFolder . getACLUser ( ) ) ) ;
2016-01-19 15:50:40 +01:00
2014-07-14 15:59:32 +02:00
List < ExtendedWorkspaceACL > listEACL = new ArrayList < ExtendedWorkspaceACL > ( listACL . size ( ) ) ;
for ( WorkspaceACL workspaceACL : listACL ) {
2016-01-19 15:50:40 +01:00
2015-02-16 14:46:38 +01:00
boolean isBaseSharedFolder = isASharedFolder ( wsFolder , true ) ? true : false ;
2014-07-17 17:07:58 +02:00
ExtendedWorkspaceACL eac = new ExtendedWorkspaceACL ( workspaceACL . getId ( ) , workspaceACL . getLabel ( ) , workspaceACL . getDefaultValue ( ) , workspaceACL . getUserType ( ) , workspaceACL . getDescription ( ) , wsFolder . getOwner ( ) . getPortalLogin ( ) , folderId , isBaseSharedFolder ) ;
workspaceLogger . trace ( " ACL " + workspaceACL + " converted in: " + eac ) ;
listEACL . add ( eac ) ;
2014-07-14 15:59:32 +02:00
}
2016-01-19 15:50:40 +01:00
2014-07-14 15:59:32 +02:00
return listEACL ;
2014-02-18 14:40:19 +01:00
} catch ( Exception e ) {
workspaceLogger . error ( " Error in server get getACLForFolderId " , e ) ;
String error = ConstantsExplorer . SERVER_ERROR + " get ACL rules for selected folder. " + e . getMessage ( ) ;
throw new Exception ( error ) ;
}
}
2016-01-19 15:50:40 +01:00
2014-02-18 14:40:19 +01:00
/ * *
2015-09-18 15:26:33 +02:00
* Gets ACLs Description For WorkspaceItem ById .
2015-03-06 16:12:21 +01:00
*
2015-07-14 18:11:11 +02:00
* @param workspaceItemId the folder id
* @return a description of the ACLs
2015-03-06 16:12:21 +01:00
* @throws Exception the exception
2014-02-18 14:40:19 +01:00
* /
@Override
2015-07-14 18:11:11 +02:00
public String getACLsDescriptionForWorkspaceItemById ( String workspaceItemId ) throws Exception {
2014-02-18 14:40:19 +01:00
try {
2016-01-19 15:50:40 +01:00
2016-05-16 10:50:15 +02:00
workspaceLogger . info ( " Get ACLsDescriptionForWorkspaceItemById: " + workspaceItemId ) ;
2016-01-19 15:50:40 +01:00
2015-07-14 18:11:11 +02:00
Workspace workspace = getWorkspace ( ) ;
WorkspaceItem wsItem = workspace . getItem ( workspaceItemId ) ;
2016-01-19 15:50:40 +01:00
2014-02-19 16:11:28 +01:00
GWTWorkspaceBuilder builder = getGWTWorkspaceBuilder ( ) ;
2016-01-19 15:50:40 +01:00
2015-07-14 18:11:11 +02:00
Map < ACLType , List < String > > acls = wsItem . getACLOwner ( ) ;
2016-01-19 15:50:40 +01:00
2015-07-14 18:11:11 +02:00
if ( acls = = null )
throw new Exception ( " ACLOwner is null! " ) ;
2016-01-19 15:50:40 +01:00
2015-07-14 18:11:11 +02:00
return builder . getFormatHtmlACLFromACLs ( acls ) ;
2014-02-17 15:56:42 +01:00
} catch ( Exception e ) {
2015-07-14 18:11:11 +02:00
workspaceLogger . error ( " Error in getACLsDescriptionForWorkspaceItemById for workspaceItemId: " + workspaceItemId , e ) ;
String error = ConstantsExplorer . SERVER_ERROR + " getting ACL rules for requested item. " + e . getMessage ( ) ;
2014-02-17 15:56:42 +01:00
throw new Exception ( error ) ;
}
}
2016-01-19 15:50:40 +01:00
2015-02-16 14:46:38 +01:00
/ * *
2015-03-06 16:12:21 +01:00
* Gets the shared workspace folder for id .
*
* @param folderId the folder id
* @return the shared workspace folder for id
* @throws Exception the exception
2015-02-16 14:46:38 +01:00
* /
private WorkspaceFolder getSharedWorkspaceFolderForId ( String folderId ) throws Exception {
2016-01-19 15:50:40 +01:00
2014-02-19 16:11:28 +01:00
if ( folderId = = null )
2016-01-19 15:50:40 +01:00
throw new Exception ( " Folder id is null " ) ;
2015-02-16 14:46:38 +01:00
workspaceLogger . trace ( " Get SharedFolderForId: " + folderId ) ;
2016-01-19 15:50:40 +01:00
2014-02-19 16:11:28 +01:00
Workspace workspace = getWorkspace ( ) ;
2015-02-16 14:46:38 +01:00
WorkspaceItem wsItem = null ;
2016-01-19 15:50:40 +01:00
2015-02-16 14:46:38 +01:00
try {
wsItem = workspace . getItem ( folderId ) ;
} catch ( Exception e ) {
workspaceLogger . error ( " Get SharedFolderForId error on folder id: " + folderId , e ) ;
throw new Exception ( ConstantsExplorer . SERVER_ERROR + " retrieving item with id: " + folderId + " . Try again later! " ) ;
}
2016-01-19 15:50:40 +01:00
2015-01-28 17:42:12 +01:00
if ( isASharedFolder ( wsItem , false ) ) {
2014-02-19 16:11:28 +01:00
workspaceLogger . trace ( " Get SharedFolderForId: folder id " + folderId + " is shared " ) ;
2016-01-19 15:50:40 +01:00
2015-01-28 17:42:12 +01:00
//TODO REMOVE wsItem.getIdSharedFolder()
2016-06-22 18:41:51 +02:00
// WorkspaceSharedFolder wsFolder = (WorkspaceSharedFolder) workspace.getItem(wsItem.getIdSharedFolder());
2016-01-19 15:50:40 +01:00
2015-02-16 14:46:38 +01:00
WorkspaceFolder wsFolder = ( WorkspaceFolder ) wsItem ;
2014-02-19 16:11:28 +01:00
if ( wsFolder ! = null ) {
2015-02-16 14:46:38 +01:00
workspaceLogger . info ( " Get SharedFolderForId return name: " + wsFolder . getName ( ) ) ;
2014-02-19 16:11:28 +01:00
return wsFolder ;
2016-01-19 15:50:40 +01:00
2014-02-19 16:11:28 +01:00
} else {
2015-02-16 14:46:38 +01:00
workspaceLogger . warn ( " Source item is not a shared folder, throw exception " ) ;
2014-02-19 16:11:28 +01:00
throw new Exception ( " Source item is not a shared folder " ) ;
}
} else {
2015-02-16 14:46:38 +01:00
workspaceLogger . warn ( " Source item is null or not shared folder, throw exception " ) ;
throw new Exception ( " Source item is null or not shared folder for id: " + folderId ) ;
2014-02-19 16:11:28 +01:00
}
}
2016-01-19 15:50:40 +01:00
2015-01-28 17:42:12 +01:00
/ * *
2015-03-06 16:12:21 +01:00
* Checks if is a shared folder .
*
* @param itemID the item id
2015-01-28 17:42:12 +01:00
* @param asRoot true check if itemID is root , not otherwise
2015-03-06 16:12:21 +01:00
* @return true , if is a shared folder
2015-01-28 17:42:12 +01:00
* /
2016-01-19 15:50:40 +01:00
2015-01-28 17:42:12 +01:00
public boolean isASharedFolder ( String itemID , boolean asRoot ) {
try {
2016-01-19 15:50:40 +01:00
2015-01-28 17:42:12 +01:00
if ( itemID = = null )
throw new Exception ( " ItemId is null " ) ;
2016-01-19 15:50:40 +01:00
2015-01-28 17:42:12 +01:00
Workspace workspace = getWorkspace ( ) ;
WorkspaceItem item = workspace . getItem ( itemID ) ;
return isASharedFolder ( item , asRoot ) ;
2016-01-19 15:50:40 +01:00
2015-01-28 17:42:12 +01:00
} catch ( Exception e ) {
workspaceLogger . error ( " Error in server isASharedFolder " , e ) ;
return false ;
}
}
2016-01-19 15:50:40 +01:00
2015-01-28 17:42:12 +01:00
/ * *
2015-03-06 16:12:21 +01:00
* Checks if is a shared folder .
*
* @param item the item
* @param asRoot the as root
* @return true , if is a shared folder
2015-01-28 17:42:12 +01:00
* @see # isASharedFolder ( String , boolean )
* /
public boolean isASharedFolder ( WorkspaceItem item , boolean asRoot ) {
try {
2016-01-19 15:50:40 +01:00
2015-01-28 17:42:12 +01:00
if ( item ! = null & & item . isFolder ( ) & & item . isShared ( ) ) { //IS A SHARED SUB-FOLDER
if ( asRoot )
return item . getType ( ) . equals ( WorkspaceItemType . SHARED_FOLDER ) ; //IS ROOT?
2016-01-19 15:50:40 +01:00
2015-01-28 17:42:12 +01:00
return true ;
}
return false ;
} catch ( Exception e ) {
workspaceLogger . error ( " Error in server isASharedFolder " , e ) ;
return false ;
}
}
2016-01-19 15:50:40 +01:00
2014-02-17 15:56:42 +01:00
/ * *
2015-03-06 16:12:21 +01:00
* Gets the trash content .
*
* @return the trash content
* @throws Exception the exception
2014-02-17 15:56:42 +01:00
* /
@Override
public List < FileTrashedModel > getTrashContent ( ) throws Exception {
workspaceLogger . trace ( " Get TrashContent: " ) ;
2016-01-19 15:50:40 +01:00
2014-02-17 15:56:42 +01:00
Workspace workspace ;
try {
2016-01-19 15:50:40 +01:00
2014-02-17 15:56:42 +01:00
workspace = getWorkspace ( ) ;
WorkspaceTrashFolder trash = workspace . getTrash ( ) ;
GWTWorkspaceBuilder builder = getGWTWorkspaceBuilder ( ) ;
2016-01-19 15:50:40 +01:00
2014-02-17 15:56:42 +01:00
return builder . buildGXTListTrashContent ( trash ) ;
2016-01-19 15:50:40 +01:00
2014-02-17 15:56:42 +01:00
} catch ( Exception e ) {
workspaceLogger . error ( " Error in server TrashConten " , e ) ;
String error = ConstantsExplorer . SERVER_ERROR + " get Trash content. " + e . getMessage ( ) ;
throw new Exception ( error ) ;
}
}
2016-01-19 15:50:40 +01:00
2014-02-17 15:56:42 +01:00
/ * *
2015-03-06 16:12:21 +01:00
* Update trash content .
*
* @param operation the operation
* @return the trash content
* @throws Exception the exception
2014-02-17 15:56:42 +01:00
* /
2014-02-17 19:20:30 +01:00
@Override
2014-05-13 11:10:54 +02:00
public TrashContent updateTrashContent ( WorkspaceTrashOperation operation ) throws Exception {
2016-01-19 15:50:40 +01:00
2014-10-31 12:32:11 +01:00
workspaceLogger . info ( " Updating TrashContent with operation: " + operation ) ;
2016-01-19 15:50:40 +01:00
2014-02-17 15:56:42 +01:00
Workspace workspace ;
List < String > listErrors = null ;
try {
2016-01-19 15:50:40 +01:00
2014-02-17 15:56:42 +01:00
workspace = getWorkspace ( ) ;
WorkspaceTrashFolder trash = workspace . getTrash ( ) ;
GWTWorkspaceBuilder builder = getGWTWorkspaceBuilder ( ) ;
2014-05-13 11:10:54 +02:00
TrashContent result = new TrashContent ( ) ;
2016-01-19 15:50:40 +01:00
2014-02-17 15:56:42 +01:00
switch ( operation ) {
2016-01-19 15:50:40 +01:00
2016-06-22 18:41:51 +02:00
case EMPTY_TRASH :
listErrors = trash . emptyTrash ( ) ;
break ;
2016-01-19 15:50:40 +01:00
2016-06-22 18:41:51 +02:00
case RESTORE_ALL :
listErrors = trash . restoreAll ( ) ;
break ;
2016-01-19 15:50:40 +01:00
2016-06-22 18:41:51 +02:00
case REFRESH :
default :
result . setTrashContent ( builder . buildGXTListTrashContent ( trash ) ) ;
return result ;
2014-02-17 15:56:42 +01:00
}
trash = workspace . getTrash ( ) ;
result . setTrashContent ( builder . buildGXTListTrashContent ( trash ) ) ;
2016-01-19 15:50:40 +01:00
2014-02-17 15:56:42 +01:00
if ( listErrors ! = null ) {
List < FileTrashedModel > listContentError = new ArrayList < FileTrashedModel > ( listErrors . size ( ) ) ;
for ( String trashedItemId : listErrors ) {
listContentError . add ( builder . buildGXTTrashModelItemById ( trashedItemId , trash ) ) ;
}
2016-01-19 15:50:40 +01:00
2014-02-17 15:56:42 +01:00
result . setListErrors ( listContentError ) ;
}
2016-01-19 15:50:40 +01:00
2014-02-17 15:56:42 +01:00
return result ;
2016-01-19 15:50:40 +01:00
2014-02-17 15:56:42 +01:00
} catch ( Exception e ) {
2014-05-13 11:10:54 +02:00
workspaceLogger . error ( " Error in server TrashContent " , e ) ;
String error = ConstantsExplorer . SERVER_ERROR + " update Trash content. " + e . getMessage ( ) ;
throw new Exception ( error ) ;
}
}
2016-01-19 15:50:40 +01:00
2017-02-20 11:41:54 +01:00
/ * *
* Gets the version history .
*
* @param fileIdentifier the file identifier
* @return the version history
* @throws Exception the exception
* /
2017-02-20 14:57:07 +01:00
@Override
2017-02-20 18:03:49 +01:00
public List < FileVersionModel > getVersionHistory ( String fileIdentifier ) throws Exception {
2017-02-20 11:41:54 +01:00
workspaceLogger . info ( " Get Version History " + fileIdentifier ) ;
if ( fileIdentifier = = null )
throw new Exception ( " File identifier is null " ) ;
try {
Workspace workspace = getWorkspace ( ) ;
WorkspaceItem fileHL = workspace . getItem ( fileIdentifier ) ;
if ( fileHL instanceof ExternalFile ) {
ExternalFile extFile = ( ExternalFile ) fileHL ;
2017-02-20 18:03:49 +01:00
List < WorkspaceVersion > versions = extFile . getVersionHistory ( ) ;
2017-02-20 11:41:54 +01:00
GWTWorkspaceBuilder builder = getGWTWorkspaceBuilder ( ) ;
return builder . toVersionHistory ( versions ) ;
} else
throw new FileNotVersionedException ( " Selected file is not versioned " ) ;
} catch ( Exception e ) {
if ( e instanceof FileNotVersionedException )
throw new Exception ( e . getMessage ( ) ) ;
String error = " An error occurred when getting version history of: " + fileIdentifier + " , try again " ;
workspaceLogger . error ( error ) ;
throw new Exception ( error ) ;
}
}
2015-03-06 16:12:21 +01:00
/ * ( non - Javadoc )
* @see org . gcube . portlets . user . workspace . client . rpc . GWTWorkspaceService # executeOperationOnTrash ( java . util . List , org . gcube . portlets . user . workspace . shared . WorkspaceTrashOperation )
2014-05-13 11:10:54 +02:00
* /
2017-02-20 11:41:54 +01:00
/ * *
* Execute operation on trash .
*
* @param listTrashItemIds the list trash item ids
* @param operation the operation
* @return the trash operation content
* @throws Exception the exception
* /
2014-05-13 11:10:54 +02:00
@Override
2014-05-13 11:26:57 +02:00
public TrashOperationContent executeOperationOnTrash ( List < String > listTrashItemIds , WorkspaceTrashOperation operation ) throws Exception {
2016-01-19 15:50:40 +01:00
2014-05-13 11:10:54 +02:00
workspaceLogger . info ( " Get TrashContent, operation: " + operation ) ;
2016-01-19 15:50:40 +01:00
2014-05-13 11:10:54 +02:00
if ( listTrashItemIds = = null | | listTrashItemIds . size ( ) = = 0 )
throw new Exception ( " List of Trash item ids is null or empty " ) ;
2016-01-19 15:50:40 +01:00
2014-05-13 11:10:54 +02:00
Workspace workspace ;
2014-05-13 11:26:57 +02:00
List < FileTrashedModel > listContentError = new ArrayList < FileTrashedModel > ( ) ;
2014-05-13 11:10:54 +02:00
try {
2016-01-19 15:50:40 +01:00
2014-05-13 11:10:54 +02:00
workspace = getWorkspace ( ) ;
WorkspaceTrashFolder trash = workspace . getTrash ( ) ;
TrashOperationContent result = new TrashOperationContent ( ) ;
2014-05-14 12:14:07 +02:00
result . setOperation ( operation ) ;
2016-01-19 15:50:40 +01:00
2014-05-13 11:10:54 +02:00
List < String > listUpdatedTrashIds = new ArrayList < String > ( ) ;
2016-01-19 15:50:40 +01:00
2014-05-13 11:10:54 +02:00
switch ( operation ) {
2016-01-19 15:50:40 +01:00
2016-06-22 18:41:51 +02:00
case DELETE_PERMANENTLY : {
2016-01-19 15:50:40 +01:00
2016-06-22 18:41:51 +02:00
boolean deleted = false ;
for ( String trashItemId : listTrashItemIds ) {
try {
WorkspaceTrashItem trashItem = trash . getTrashItemById ( trashItemId ) ;
if ( trashItem ! = null ) {
trashItem . deletePermanently ( ) ;
listUpdatedTrashIds . add ( trashItemId ) ;
deleted = true ;
2014-05-13 11:10:54 +02:00
}
2016-01-19 15:50:40 +01:00
2016-06-22 18:41:51 +02:00
} catch ( Exception e ) {
workspaceLogger . warn ( " Error on DELETE_PERMANENTLY the item : " + trashItemId , e ) ;
FileTrashedModel fakeFile = new FileTrashedModel ( ) ;
fakeFile . setIdentifier ( trashItemId ) ;
listContentError . add ( fakeFile ) ;
}
2014-05-13 11:10:54 +02:00
}
2016-01-19 15:50:40 +01:00
2016-06-22 18:41:51 +02:00
String label = listTrashItemIds . size ( ) > 1 ? " items " : " item " ;
if ( ! deleted )
throw new Exception ( " Sorry, an error occurred on deleting permanently the trash " + label + " , try again " ) ;
2016-01-19 15:50:40 +01:00
2016-06-22 18:41:51 +02:00
break ;
}
case RESTORE : {
2016-01-19 15:50:40 +01:00
2016-06-22 18:41:51 +02:00
boolean restored = false ;
for ( String trashItemId : listTrashItemIds ) {
try {
WorkspaceTrashItem trashItem = trash . getTrashItemById ( trashItemId ) ;
if ( trashItem ! = null ) {
trashItem . restore ( ) ;
listUpdatedTrashIds . add ( trashItemId ) ;
restored = true ;
2014-05-13 11:10:54 +02:00
}
2016-06-22 18:41:51 +02:00
} catch ( Exception e ) {
workspaceLogger . warn ( " Error on RESTORE the item : " + trashItemId , e ) ;
FileTrashedModel fakeFile = new FileTrashedModel ( ) ;
fakeFile . setIdentifier ( trashItemId ) ;
listContentError . add ( fakeFile ) ;
2014-05-13 11:10:54 +02:00
}
2016-06-22 18:41:51 +02:00
}
String label = listTrashItemIds . size ( ) > 1 ? " items " : " item " ;
2016-01-19 15:50:40 +01:00
2016-06-22 18:41:51 +02:00
if ( ! restored )
throw new Exception ( " Sorry, an error occurred on restoring the trash " + label + " , try again " ) ;
2016-01-19 15:50:40 +01:00
2016-06-22 18:41:51 +02:00
break ;
}
2016-01-19 15:50:40 +01:00
2014-10-31 12:32:11 +01:00
default :
break ;
2014-05-13 11:10:54 +02:00
}
2016-06-22 18:41:51 +02:00
// trash = workspace.getTrash();
// result.setTrashContent(builder.buildGXTListTrashContent(trash));
2016-01-19 15:50:40 +01:00
2014-05-13 11:26:57 +02:00
if ( ! listContentError . isEmpty ( ) ) {
2014-05-13 11:10:54 +02:00
result . setListErrors ( listContentError ) ;
}
2016-01-19 15:50:40 +01:00
2014-05-13 11:10:54 +02:00
result . setListTrashIds ( listUpdatedTrashIds ) ;
2016-01-19 15:50:40 +01:00
2014-05-13 11:10:54 +02:00
return result ;
2016-01-19 15:50:40 +01:00
2014-05-13 11:10:54 +02:00
} catch ( Exception e ) {
workspaceLogger . error ( " Error in server executeOperationOnTrash " , e ) ;
String error = ConstantsExplorer . SERVER_ERROR + " update Trash content. " + e . getMessage ( ) ;
2014-02-17 15:56:42 +01:00
throw new Exception ( error ) ;
}
}
2014-07-08 18:41:53 +02:00
/ * ( non - Javadoc )
* @see org . gcube . portlets . user . workspace . client . rpc . GWTWorkspaceService # addAdministratorsByFolderId ( java . lang . String , java . util . List )
2016-01-19 15:50:40 +01:00
*
2014-07-08 18:41:53 +02:00
* true if administrators have been added , false otherwise
* /
2017-02-20 11:41:54 +01:00
/ * *
* Adds the administrators by folder id .
*
* @param folderId the folder id
* @param listContactLogins the list contact logins
* @return true , if successful
* @throws Exception the exception
* /
2014-07-08 18:41:53 +02:00
@Override
public boolean addAdministratorsByFolderId ( String folderId , List < String > listContactLogins ) throws Exception {
if ( folderId = = null | | listContactLogins = = null | | listContactLogins . size ( ) = = 0 )
return false ;
try {
2016-01-19 15:50:40 +01:00
2014-07-08 18:41:53 +02:00
Workspace workspace = getWorkspace ( ) ;
WorkspaceItem item = workspace . getItem ( folderId ) ;
workspaceLogger . info ( " Adding administator/s to folder: " + folderId ) ;
2016-01-19 15:50:40 +01:00
2014-07-10 17:27:21 +02:00
if ( item ! = null & & item . getType ( ) . equals ( WorkspaceItemType . SHARED_FOLDER ) ) {
2014-07-08 18:41:53 +02:00
WorkspaceSharedFolder sharedFolder = ( WorkspaceSharedFolder ) item ;
2016-01-19 15:50:40 +01:00
2014-09-30 12:13:26 +02:00
//retrieving old administrators list
GWTWorkspaceBuilder builder = getGWTWorkspaceBuilder ( ) ;
workspaceLogger . info ( " Retrieving old administator/s.. " ) ;
List < InfoContactModel > oldAdmins = builder . buildGxtInfoContactsFromPortalLogins ( sharedFolder . getAdministrators ( ) ) ;
workspaceLogger . info ( " Retrieving old administator/s are/is: " + oldAdmins . size ( ) ) ;
2016-01-19 15:50:40 +01:00
2014-09-24 16:51:42 +02:00
workspaceLogger . info ( " Setting administators: " ) ;
2016-01-19 15:50:40 +01:00
printList ( listContactLogins ) ;
2014-09-24 16:51:42 +02:00
sharedFolder . setAdmins ( listContactLogins ) ;
2016-01-19 15:50:40 +01:00
2014-09-30 12:13:26 +02:00
workspaceLogger . info ( " Converting new administator/s.. " ) ;
List < InfoContactModel > newAdmins = builder . buildGxtInfoContactsFromPortalLogins ( listContactLogins ) ;
NotificationsProducer np = getNotificationProducer ( ) ;
2016-01-19 15:50:40 +01:00
2014-09-30 12:13:26 +02:00
workspaceLogger . info ( " Sending notifications downgrade/upgrade administator/s.. " ) ;
2015-11-19 17:17:13 +01:00
DifferenceBetweenInfoContactModel diff1 = new DifferenceBetweenInfoContactModel ( oldAdmins , newAdmins ) ;
2014-09-30 12:13:26 +02:00
List < InfoContactModel > contactsDowngrade = diff1 . getDifferentsContacts ( ) ;
2016-01-19 15:50:40 +01:00
2014-09-30 12:13:26 +02:00
for ( InfoContactModel infoContactModel : contactsDowngrade ) {
np . notifyAdministratorDowngrade ( infoContactModel , sharedFolder ) ;
}
2016-01-19 15:50:40 +01:00
2015-11-19 17:17:13 +01:00
DifferenceBetweenInfoContactModel diff2 = new DifferenceBetweenInfoContactModel ( newAdmins , oldAdmins ) ;
2014-09-30 12:13:26 +02:00
List < InfoContactModel > contactsUpgrade = diff2 . getDifferentsContacts ( ) ;
2016-01-19 15:50:40 +01:00
2014-09-30 12:13:26 +02:00
for ( InfoContactModel infoContactModel : contactsUpgrade ) {
np . notifyAdministratorUpgrade ( infoContactModel , sharedFolder ) ;
}
2016-01-19 15:50:40 +01:00
2014-07-08 18:41:53 +02:00
return true ;
2016-01-19 15:50:40 +01:00
2014-07-08 18:41:53 +02:00
} else
2014-07-10 17:27:21 +02:00
throw new Exception ( " The item is null or not instanceof " + WorkspaceItemType . SHARED_FOLDER ) ;
2016-01-19 15:50:40 +01:00
2014-07-08 18:41:53 +02:00
} catch ( Exception e ) {
workspaceLogger . error ( " Error in server addAdministratorsByFolderId: " + e . getMessage ( ) ) ;
workspaceLogger . error ( e ) ;
String error = ConstantsExplorer . SERVER_ERROR + " adding administrators, try again later " ;
throw new Exception ( error ) ;
}
2016-01-19 15:50:40 +01:00
2014-07-08 18:41:53 +02:00
}
2014-07-10 17:27:21 +02:00
/ * ( non - Javadoc )
* @see org . gcube . portlets . user . workspace . client . rpc . GWTWorkspaceService # getAdministratorsByFolderId ( java . lang . String )
* /
2017-02-20 11:41:54 +01:00
/ * *
* Gets the administrators by folder id .
*
* @param folderId the folder id
* @return the administrators by folder id
* @throws Exception the exception
* /
2014-07-10 17:27:21 +02:00
@Override
public List < InfoContactModel > getAdministratorsByFolderId ( String folderId ) throws Exception {
List < InfoContactModel > admins = new ArrayList < InfoContactModel > ( ) ;
2016-01-19 15:50:40 +01:00
2014-07-10 17:27:21 +02:00
if ( folderId = = null )
return admins ;
try {
2014-07-30 16:52:22 +02:00
workspaceLogger . info ( " Getting administator/s to folder: " + folderId ) ;
2015-02-16 14:46:38 +01:00
WorkspaceFolder wsFolder = getSharedWorkspaceFolderForId ( folderId ) ;
if ( isASharedFolder ( wsFolder , true ) ) {
2014-07-11 15:56:35 +02:00
GWTWorkspaceBuilder builder = getGWTWorkspaceBuilder ( ) ;
2015-02-16 14:46:38 +01:00
WorkspaceSharedFolder wsSharedFolder = ( WorkspaceSharedFolder ) wsFolder ;
return builder . buildGxtInfoContactsFromPortalLogins ( wsSharedFolder . getAdministrators ( ) ) ;
2014-07-10 17:27:21 +02:00
} else
2015-02-16 14:46:38 +01:00
throw new WorkspaceHandledException ( " the item with " + folderId + " is not a base shared folder! " ) ;
2016-01-19 15:50:40 +01:00
2015-02-16 14:46:38 +01:00
} catch ( WorkspaceHandledException e ) {
workspaceLogger . error ( " Error in server getAdministratorsByFolderId: " + e . getMessage ( ) ) ;
String error = ConstantsExplorer . SERVER_ERROR + " getting Administrators: " + e . getMessage ( ) ;
throw new Exception ( error ) ;
2014-07-10 17:27:21 +02:00
} catch ( Exception e ) {
workspaceLogger . error ( " Error in server getAdministratorsByFolderId: " + e . getMessage ( ) ) ;
workspaceLogger . error ( e ) ;
String error = ConstantsExplorer . SERVER_ERROR + " getting Administrators " ;
throw new Exception ( error ) ;
}
}
2016-01-19 15:50:40 +01:00
2015-03-06 16:12:21 +01:00
/ * ( non - Javadoc )
* @see org . gcube . portlets . user . workspace . client . rpc . GWTWorkspaceService # getItemDescriptionById ( java . lang . String )
* /
2017-02-20 11:41:54 +01:00
/ * *
* Gets the item description by id .
*
* @param identifier the identifier
* @return the item description by id
* @throws Exception the exception
* /
2014-11-04 18:20:06 +01:00
@Override
public String getItemDescriptionById ( String identifier ) throws Exception {
2016-01-19 15:50:40 +01:00
2014-11-04 18:20:06 +01:00
workspaceLogger . info ( " Getting ItemDescriptionById: " + identifier ) ;
if ( identifier = = null | | identifier . isEmpty ( ) ) {
workspaceLogger . warn ( " Getting ItemDescriptionById identifier is null or empty, returning null " ) ;
return null ;
}
2016-01-19 15:50:40 +01:00
2014-11-04 18:20:06 +01:00
try {
2016-01-19 15:50:40 +01:00
2014-11-04 18:20:06 +01:00
Workspace workspace = getWorkspace ( ) ;
WorkspaceItem item = workspace . getItem ( identifier ) ;
GWTWorkspaceBuilder builder = getGWTWorkspaceBuilder ( ) ;
return builder . getItemDescriptionForTypeById ( item ) ;
2016-01-19 15:50:40 +01:00
2014-11-04 18:20:06 +01:00
} catch ( Exception e ) {
workspaceLogger . error ( " Error in server ItemDescriptionById: " , e ) ;
String error = ConstantsExplorer . SERVER_ERROR + " getting description for item id: " + identifier ;
throw new Exception ( error ) ;
}
}
2014-09-24 12:55:32 +02:00
/ * ( non - Javadoc )
* @see org . gcube . portlets . user . workspace . client . rpc . GWTWorkspaceService # getACLBySharedFolderId ( java . lang . String )
* /
2017-02-20 11:41:54 +01:00
/ * *
* Gets the ACL by shared folder id .
*
* @param identifier the identifier
* @return the ACL by shared folder id
* @throws Exception the exception
* /
2014-09-24 12:55:32 +02:00
@Override
public WorkspaceACL getACLBySharedFolderId ( String identifier ) throws Exception {
workspaceLogger . info ( " Getting ACLBySharedFolderId: " + identifier ) ;
if ( identifier = = null | | identifier . isEmpty ( ) ) {
workspaceLogger . warn ( " Getting ACLBySharedFolderId identifier is null or empty, returning null " ) ;
return null ;
}
try {
2015-02-16 14:46:38 +01:00
WorkspaceFolder sharedFolder = getSharedWorkspaceFolderForId ( identifier ) ;
2016-01-19 15:50:40 +01:00
2015-02-16 14:46:38 +01:00
//IS ROOT??
if ( isASharedFolder ( sharedFolder , true ) ) {
2014-09-24 12:55:32 +02:00
GWTWorkspaceBuilder builder = getGWTWorkspaceBuilder ( ) ;
2015-02-16 14:46:38 +01:00
//CASTING TO ROOT
WorkspaceSharedFolder wsSharedFolder = ( WorkspaceSharedFolder ) sharedFolder ;
workspaceLogger . info ( " Read getPrivilege from HL: " + wsSharedFolder . getACLUser ( ) ) ;
List < WorkspaceACL > wsAcls = builder . getWorkspaceACLFromACLs ( Arrays . asList ( wsSharedFolder . getPrivilege ( ) ) ) ;
2016-01-19 15:50:40 +01:00
2014-09-24 12:55:32 +02:00
if ( wsAcls = = null | | wsAcls . isEmpty ( ) ) {
workspaceLogger . info ( " Converted ACLBySharedFolderId is null or empty, returning null " ) ;
return null ;
}
2016-01-19 15:50:40 +01:00
2014-09-24 12:55:32 +02:00
workspaceLogger . info ( " Returning first acl with id: " + wsAcls . get ( 0 ) . getId ( ) ) ;
return wsAcls . get ( 0 ) ;
2015-02-16 14:46:38 +01:00
}
else {
workspaceLogger . warn ( " WorkspaceFolder " + sharedFolder + " is not type of " + WorkspaceItemType . SHARED_FOLDER + " , returning null " ) ;
return null ;
}
2014-09-24 12:55:32 +02:00
} catch ( Exception e ) {
workspaceLogger . error ( " Error in server ACLBySharedFolderId: " + e . getMessage ( ) ) ;
workspaceLogger . error ( e ) ;
String error = ConstantsExplorer . SERVER_ERROR + " getting ACL of WorkspaceSharedFolder " ;
throw new Exception ( error ) ;
}
}
2014-10-28 17:12:40 +01:00
2015-03-06 16:12:21 +01:00
/ * ( non - Javadoc )
* @see org . gcube . portlets . user . workspace . client . rpc . GWTWorkspaceService # getUserWorkspaceQuote ( )
* /
2017-02-20 11:41:54 +01:00
/ * *
* Gets the user workspace quote .
*
* @return the user workspace quote
* @throws Exception the exception
* /
2014-10-31 17:27:52 +01:00
@Override
public WorkspaceUserQuote getUserWorkspaceQuote ( ) throws Exception {
try {
workspaceLogger . info ( " Getting UserWorkspaceQuote.. " ) ;
Workspace workspace = getWorkspace ( ) ;
long size = workspace . getDiskUsage ( ) ;
workspaceLogger . info ( " Root size is: " + size + " formatting.. " ) ;
String formatSize = GWTWorkspaceBuilder . formatFileSize ( size ) ;
long total = getUserWorkspaceTotalItems ( ) ;
2016-01-19 15:50:40 +01:00
2014-10-31 17:27:52 +01:00
WorkspaceUserQuote quote = new WorkspaceUserQuote ( ) ;
quote . setDiskSpace ( size ) ;
quote . setDiskSpaceFormatted ( formatSize ) ;
quote . setTotalItems ( total ) ;
workspaceLogger . info ( " returning user quote: " + quote ) ;
return quote ;
} catch ( Exception e ) {
workspaceLogger . error ( " Error on UserWorkspaceQuote " , e ) ;
return null ;
}
}
2016-01-19 15:50:40 +01:00
2015-03-06 16:12:21 +01:00
/ * ( non - Javadoc )
* @see org . gcube . portlets . user . workspace . client . rpc . GWTWorkspaceService # getUserWorkspaceSize ( )
* /
2017-02-20 11:41:54 +01:00
/ * *
* Gets the user workspace size .
*
* @return the user workspace size
* @throws Exception the exception
* /
2014-10-28 17:12:40 +01:00
@Override
public String getUserWorkspaceSize ( ) throws Exception {
2014-10-31 17:27:52 +01:00
try {
workspaceLogger . info ( " Getting workspace size.. " ) ;
Workspace workspace = getWorkspace ( ) ;
long size = workspace . getDiskUsage ( ) ;
2016-06-22 18:41:51 +02:00
// workspaceLogger.info("Root size is: "+size +" formatting..");
2014-10-31 17:27:52 +01:00
String formatSize = GWTWorkspaceBuilder . formatFileSize ( size ) ;
workspaceLogger . info ( " returning workspace size: " + formatSize ) ;
return formatSize ;
} catch ( Exception e ) {
workspaceLogger . error ( " Error on UserWorkspaceSize " , e ) ;
String error = ConstantsExplorer . SERVER_ERROR + " getting disk usage " ;
throw new Exception ( error ) ;
}
2016-01-19 15:50:40 +01:00
2014-10-28 17:12:40 +01:00
}
2016-01-19 15:50:40 +01:00
2015-03-06 16:12:21 +01:00
/ * ( non - Javadoc )
* @see org . gcube . portlets . user . workspace . client . rpc . GWTWorkspaceService # getUserWorkspaceTotalItems ( )
* /
2017-02-20 11:41:54 +01:00
/ * *
* Gets the user workspace total items .
*
* @return the user workspace total items
* @throws Exception the exception
* /
2014-10-31 17:27:52 +01:00
@Override
public long getUserWorkspaceTotalItems ( ) throws Exception {
try {
workspaceLogger . info ( " Getting total items.. " ) ;
Workspace workspace = getWorkspace ( ) ;
long size = workspace . getTotalItems ( ) ;
workspaceLogger . info ( " returning total items value: " + size ) ;
return size ;
} catch ( Exception e ) {
workspaceLogger . error ( " Error on UserWorkspaceSize " , e ) ;
String error = ConstantsExplorer . SERVER_ERROR + " getting total items " ;
throw new Exception ( error ) ;
}
2014-10-28 17:12:40 +01:00
}
2014-11-04 18:20:06 +01:00
2015-06-12 12:24:01 +02:00
/ * ( non - Javadoc )
* @see org . gcube . portlets . user . workspace . client . rpc . GWTWorkspaceService # loadGcubeItemProperties ( java . lang . String )
* /
2017-02-20 11:41:54 +01:00
/ * *
* Load gcube item properties .
*
* @param itemId the item id
* @return the map
* @throws Exception the exception
* /
2015-06-12 12:24:01 +02:00
@Override
public Map < String , String > loadGcubeItemProperties ( String itemId ) throws Exception {
workspaceLogger . info ( " Getting GcubeItemProperties for itemId: " + itemId ) ;
if ( itemId = = null | | itemId . isEmpty ( ) ) {
workspaceLogger . warn ( " Getting GcubeItemProperties identifier is null or empty, returning null " ) ;
return null ;
}
2016-01-19 15:50:40 +01:00
2015-06-12 12:24:01 +02:00
try {
Workspace workspace = getWorkspace ( ) ;
WorkspaceItem item = workspace . getItem ( itemId ) ;
GWTWorkspaceBuilder builder = getGWTWorkspaceBuilder ( ) ;
Map < String , String > mapProperties = builder . getGcubeItemProperties ( item ) ;
if ( mapProperties ! = null )
workspaceLogger . info ( " Returning " + mapProperties . size ( ) + " properties " ) ;
else
workspaceLogger . info ( " Returning null properties " ) ;
2016-01-19 15:50:40 +01:00
2015-06-12 12:24:01 +02:00
return mapProperties ;
} catch ( Exception e ) {
workspaceLogger . error ( " Error in server GcubeItemProperties: " , e ) ;
String error = ConstantsExplorer . SERVER_ERROR + " getting gcube item properties for item id: " + itemId ;
throw new Exception ( error ) ;
}
}
2016-01-19 15:50:40 +01:00
2015-06-12 12:24:01 +02:00
/ * *
* Gets the HTML gcube item properties .
*
* @param itemId the item id
* @return The Gcube Item Properties in HTML format if itemId is a GcubeItem and contains properties , null otherwise
* @throws Exception the exception
* /
@Override
public String getHTMLGcubeItemProperties ( String itemId ) throws Exception {
workspaceLogger . info ( " Getting FormattedGcubeItemProperties for itemId: " + itemId ) ;
if ( itemId = = null | | itemId . isEmpty ( ) ) {
workspaceLogger . warn ( " Getting FormattedGcubeItemProperties identifier is null or empty, returning null " ) ;
return null ;
}
2016-01-19 15:50:40 +01:00
2015-06-12 12:24:01 +02:00
try {
2016-01-19 15:50:40 +01:00
2015-06-12 12:24:01 +02:00
Workspace workspace = getWorkspace ( ) ;
WorkspaceItem item = workspace . getItem ( itemId ) ;
GWTWorkspaceBuilder builder = getGWTWorkspaceBuilder ( ) ;
return builder . getFormatHtmlGcubeItemProperties ( item ) ;
2016-01-19 15:50:40 +01:00
2015-06-12 12:24:01 +02:00
} catch ( Exception e ) {
workspaceLogger . error ( " Error in server FormattedGcubeItemProperties: " , e ) ;
String error = ConstantsExplorer . SERVER_ERROR + " getting gcube item properties for item id: " + itemId ;
throw new Exception ( error ) ;
}
}
/ * *
* Sets the gcube item properties .
*
* @param itemId the item id
* @param properties the properties
* @throws Exception the exception
* /
@Override
public void setGcubeItemProperties ( String itemId , Map < String , String > properties ) throws Exception {
workspaceLogger . info ( " Set GcubeItemProperties for itemId: " + itemId ) ;
if ( itemId = = null | | itemId . isEmpty ( ) ) {
workspaceLogger . warn ( " Set GcubeItemProperties, identifier is null or empty, returning null " ) ;
throw new Exception ( " The item id is null or empty " ) ;
}
2016-01-19 15:50:40 +01:00
2015-06-12 12:24:01 +02:00
try {
2016-01-19 15:50:40 +01:00
2015-06-12 12:24:01 +02:00
Workspace workspace = getWorkspace ( ) ;
WorkspaceItem item = workspace . getItem ( itemId ) ;
if ( item instanceof GCubeItem ) {
2015-06-12 15:07:02 +02:00
workspaceLogger . info ( " Adding " + properties . size ( ) + " properties to GCubeItem: " + itemId ) ;
2015-06-12 12:24:01 +02:00
GCubeItem gItem = ( GCubeItem ) item ;
2015-06-12 17:18:08 +02:00
for ( String key : properties . keySet ( ) ) {
//ADD PROPERTIES
2015-06-12 15:07:02 +02:00
workspaceLogger . trace ( " Adding property: [ " + key + " , " + properties . get ( key ) + " ] " ) ;
gItem . getProperties ( ) . addProperty ( key , properties . get ( key ) ) ;
}
2015-06-12 17:18:08 +02:00
gItem . getProperties ( ) . update ( ) ;
2015-06-12 12:24:01 +02:00
} else
throw new NoGcubeItemTypeException ( " The item is not a Gcube Item " ) ;
2016-01-19 15:50:40 +01:00
2015-06-12 12:24:01 +02:00
} catch ( NoGcubeItemTypeException e ) {
workspaceLogger . error ( " Error in server FormattedGcubeItemProperties: " , e ) ;
throw new Exception ( e . getMessage ( ) ) ;
} catch ( Exception e ) {
workspaceLogger . error ( " Error in server FormattedGcubeItemProperties: " , e ) ;
String error = ConstantsExplorer . SERVER_ERROR + " setting gcube item properties for item id: " + itemId ;
throw new Exception ( error ) ;
}
}
2016-08-29 10:38:35 +02:00
2016-09-14 12:17:14 +02:00
/ * ( non - Javadoc )
2016-09-15 16:42:20 +02:00
* @see org . gcube . portlets . user . workspace . client . rpc . GWTWorkspaceService # markFolderAsPublicForFolderItemId ( java . lang . String , boolean )
2016-09-14 12:17:14 +02:00
* /
2017-02-20 11:41:54 +01:00
/ * *
* Mark folder as public for folder item id .
*
* @param itemId the item id
* @param setPublic the set public
* @return the public link
* @throws SessionExpiredException the session expired exception
* @throws Exception the exception
* /
2016-09-14 12:17:14 +02:00
@Override
2016-09-15 16:42:20 +02:00
public PublicLink markFolderAsPublicForFolderItemId ( String itemId , boolean setPublic ) throws SessionExpiredException , Exception {
2016-09-14 12:17:14 +02:00
if ( isSessionExpired ( ) )
throw new SessionExpiredException ( ) ;
try {
Workspace workspace = getWorkspace ( ) ;
WorkspaceItem item = workspace . getItem ( itemId ) ;
if ( item instanceof WorkspaceFolder ) {
WorkspaceFolder folder = ( WorkspaceFolder ) item ;
2017-04-10 16:43:21 +02:00
2016-09-15 16:42:20 +02:00
if ( setPublic ) {
2017-04-10 16:43:21 +02:00
if ( ! folder . isPublic ( ) )
folder . setPublic ( true ) ;
2016-09-15 16:42:20 +02:00
String folderId = item . getId ( ) ;
workspaceLogger . info ( " HL returning folder link id: " + folderId ) ;
ApplicationProfileReader apReader = new ApplicationProfileReader ( " Workspace-Explorer-App " , " org.gcube.portlets.user.workspaceexplorerapp.server.WorkspaceExplorerAppServiceImpl " ) ;
ApplicationProfile ap = apReader . readProfileFromInfrastrucure ( ) ;
2016-09-19 12:17:33 +02:00
String encriptedFId = StringEncrypter . getEncrypter ( ) . encrypt ( folderId ) ;
workspaceLogger . info ( " Encrypted folder Id: " + encriptedFId ) ;
String encodedFId = StringUtil . base64EncodeStringURLSafe ( encriptedFId ) ;
workspaceLogger . info ( " Encoded in Base 64: " + encodedFId ) ;
2016-09-15 16:42:20 +02:00
workspaceLogger . info ( " Application profile returning url: " + ap . getUrl ( ) ) ;
2016-09-19 12:17:33 +02:00
String folderLink = ap . getUrl ( ) + " ?folderId= " + encodedFId ;
2016-09-15 16:42:20 +02:00
String shortURL = null ;
try {
shortURL = getShortUrl ( folderLink ) ;
shortURL = shortURL ! = null ? shortURL : " not available " ;
} catch ( Exception e ) {
workspaceLogger . warn ( " Short url error, skipping " ) ;
shortURL = " not available " ;
}
return new PublicLink ( folderLink , shortURL ) ;
} else {
folder . setPublic ( false ) ;
return null ;
2016-09-14 14:30:33 +02:00
}
2016-09-14 12:17:14 +02:00
} else
throw new NoGcubeItemTypeException ( " The item is not a Gcube Item " ) ;
} catch ( NoGcubeItemTypeException e ) {
2017-04-10 16:43:21 +02:00
workspaceLogger . error ( " Error in server: " , e ) ;
throw new Exception ( e . getMessage ( ) ) ;
} catch ( InsufficientPrivilegesException e ) {
workspaceLogger . error ( " Error in server: " , e ) ;
2016-09-14 12:17:14 +02:00
throw new Exception ( e . getMessage ( ) ) ;
} catch ( Exception e ) {
2017-03-16 11:59:48 +01:00
workspaceLogger . error ( " Error in server markFolderAsPublicForFolderItemId: " , e ) ;
2016-09-14 12:17:14 +02:00
String error = ConstantsExplorer . SERVER_ERROR + " reading Folder Link for id: " + itemId ;
throw new Exception ( error ) ;
}
}
2016-09-21 18:10:14 +02:00
2017-02-20 11:41:54 +01:00
/ * *
* Gets the servlet context path .
*
* @param protocol the protocol
* @return the servlet context path
* /
2016-09-21 18:10:14 +02:00
@Override
public String getServletContextPath ( String protocol ) {
HttpServletRequest req = getThreadLocalRequest ( ) ;
2016-09-29 15:28:32 +02:00
2016-09-21 18:10:14 +02:00
String scheme = protocol ;
String serverName = req . getServerName ( ) ; // hostname.com
int serverPort = req . getServerPort ( ) ; // 80
String contextPath = req . getServletContext ( ) . getContextPath ( ) ; // /mywebapp
// Reconstruct original requesting URL
StringBuffer url = new StringBuffer ( ) ;
url . append ( scheme ) . append ( " // " ) . append ( serverName ) ;
if ( serverPort ! = 80 & & serverPort ! = 443 ) {
url . append ( " : " ) . append ( serverPort ) ;
}
workspaceLogger . debug ( " server: " + url ) ;
workspaceLogger . debug ( " omitted contextPath: " + contextPath ) ;
url . append ( contextPath ) ;
workspaceLogger . debug ( " getServletContextPath= " + url . toString ( ) ) ;
return url . toString ( ) ;
}
2016-11-29 15:16:47 +01:00
/ * ( non - Javadoc )
* @see org . gcube . portlets . user . workspace . client . rpc . GWTWorkspaceService # accessToFolderLink ( java . lang . String )
* /
2017-02-20 11:41:54 +01:00
/ * *
* Access to folder link .
*
* @param itemId the item id
* @return the allow access
* @throws SessionExpiredException the session expired exception
* @throws Exception the exception
* /
2016-11-29 15:16:47 +01:00
@Override
public AllowAccess accessToFolderLink ( String itemId ) throws SessionExpiredException , Exception {
workspaceLogger . info ( " Access to Folder Link " + itemId + " working... " ) ;
try {
Workspace workspace = getWorkspace ( ) ;
WorkspaceItem item = workspace . getItem ( itemId ) ;
if ( item instanceof WorkspaceFolder ) {
WorkspaceFolder folder = ( WorkspaceFolder ) item ;
InfoContactModel owner = getOwnerByItemId ( itemId ) ;
PortalContextInfo context = WsUtil . getPortalContext ( this . getThreadLocalRequest ( ) ) ;
2016-12-05 14:34:53 +01:00
if ( folder . isPublic ( ) ) {
workspaceLogger . info ( " The folder is already public. Access granted to " + context . getUsername ( ) ) ;
return new AllowAccess ( itemId , true , " The folder is already public. Access granted to " + context . getUsername ( ) , null ) ;
}
2016-11-29 15:16:47 +01:00
workspaceLogger . info ( " owner of: " + folder . getName ( ) + " is: " + owner ) ;
workspaceLogger . info ( " current context user: " + context . getUsername ( ) ) ;
if ( owner . getLogin ( ) . compareToIgnoreCase ( context . getUsername ( ) ) = = 0 ) {
workspaceLogger . info ( " Access to Folder Link " + folder . getName ( ) + " granted, " + context . getUsername ( ) + " is the owner of: " + itemId ) ;
return new AllowAccess ( itemId , true , context . getUserFullName ( ) + " is the owner of: " + folder . getName ( ) , null ) ;
}
try {
List < InfoContactModel > admins = getAdministratorsByFolderId ( itemId ) ;
for ( InfoContactModel infoContactModel : admins ) {
if ( infoContactModel . getLogin ( ) . compareToIgnoreCase ( context . getUsername ( ) ) = = 0 ) {
workspaceLogger . info ( " Access to Folder Link " + folder . getName ( ) + " granted, " + context . getUsername ( ) + " is the admin of: " + itemId ) ;
return new AllowAccess ( itemId , true , context . getUserFullName ( ) + " is the admin of: " + folder . getName ( ) , null ) ;
}
}
} catch ( Exception e ) {
return new AllowAccess ( itemId , false , " You have not permission to get Folder Link, you must be owner or administrator to the folder " , e . getMessage ( ) ) ;
}
return new AllowAccess ( itemId , false , " You have not permission to get Folder Link, you must be owner or administrator to the folder " , null ) ;
}
return new AllowAccess ( itemId , false , " The item is not a folder " , null ) ;
} catch ( Exception e ) {
workspaceLogger . error ( " Error in server FormattedGcubeItemProperties: " , e ) ;
String error = ConstantsExplorer . SERVER_ERROR + " when reading access policy to Folder Link: " + itemId + " , Refresh and try again " ;
throw new Exception ( error ) ;
}
}
2017-02-22 11:36:28 +01:00
/ * ( non - Javadoc )
* @see org . gcube . portlets . user . workspace . client . rpc . GWTWorkspaceService # performOperationOnVersionedFile ( java . lang . String , java . util . List , org . gcube . portlets . user . workspace . shared . WorkspaceVersioningOperation )
* /
@Override
public List < FileVersionModel > performOperationOnVersionedFile (
String fileId , List < String > olderVersionIDs ,
WorkspaceVersioningOperation operation ) throws Exception {
if ( fileId = = null | | olderVersionIDs = = null | | olderVersionIDs . size ( ) = = 0 )
throw new Exception ( " File Versioned is null " ) ;
workspaceLogger . info ( " File Id: " + fileId + " , Ids Version: " + olderVersionIDs + " perform operation: " + operation ) ;
try {
Workspace workspace = getWorkspace ( ) ;
WorkspaceItem fileHL = workspace . getItem ( fileId ) ;
if ( fileHL instanceof ExternalFile ) {
ExternalFile extFile = ( ExternalFile ) fileHL ;
switch ( operation ) {
case DOWNLOAD : {
//IMPLEMENTED CLIENT-SIDE
break ;
}
case DELETE_ALL_OLDER_VERSIONS : {
//MUST BE OPTIMIZED HL-SIDE
for ( String olderVersionId : olderVersionIDs ) {
extFile . removeVersion ( olderVersionId ) ;
workspaceLogger . info ( " Version " + olderVersionId + " of file id: " + fileId + " removed " ) ;
}
return getVersionHistory ( fileId ) ;
}
case RESTORE : {
for ( String olderVersionId : olderVersionIDs ) {
extFile . restoreVersion ( olderVersionId ) ;
workspaceLogger . info ( " Version " + olderVersionId + " of file id: " + fileId + " restored " ) ;
}
return getVersionHistory ( fileId ) ;
}
case REFRESH : {
return getVersionHistory ( fileId ) ;
}
case DELETE_PERMANENTLY : {
for ( String olderVersionId : olderVersionIDs ) {
extFile . removeVersion ( olderVersionId ) ;
workspaceLogger . info ( " Version " + olderVersionId + " of file id: " + fileId + " removed " ) ;
}
return getVersionHistory ( fileId ) ;
}
default : {
break ;
}
}
return getVersionHistory ( fileId ) ;
} else
throw new FileNotVersionedException ( " Selected file is not versioned " ) ;
} catch ( Exception e ) {
if ( e instanceof FileNotVersionedException )
throw new Exception ( e . getMessage ( ) ) ;
2017-03-02 18:13:52 +01:00
if ( e instanceof InsufficientPrivilegesException )
throw new Exception ( e . getMessage ( ) ) ;
2017-02-22 11:36:28 +01:00
workspaceLogger . error ( " Error in server during perform operation on versioning on file id: " + fileId , e ) ;
String error = ConstantsExplorer . SERVER_ERROR + " updating versioning of file id: " + fileId ;
throw new Exception ( error ) ;
}
}
2013-02-06 15:40:17 +01:00
}