2013-02-06 15:40:17 +01:00
package org.gcube.portlets.user.workspace.server ;
2018-09-14 15:38:41 +02:00
import static org.gcube.resources.discovery.icclient.ICFactory.clientFor ;
import static org.gcube.resources.discovery.icclient.ICFactory.queryFor ;
2014-03-05 18:28:49 +01:00
import java.io.File ;
2018-11-28 16:50:18 +01:00
import java.net.URL ;
2018-09-14 15:38:41 +02:00
import java.net.URLEncoder ;
2013-02-06 15:40:17 +01:00
import java.util.ArrayList ;
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 ;
2013-09-27 17:39:28 +02:00
import org.gcube.common.homelibrary.home.Home ;
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 ;
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.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 ;
2016-12-21 18:49:00 +01:00
import org.gcube.common.portal.PortalContext ;
2018-09-14 15:38:41 +02:00
import org.gcube.common.resources.gcore.ServiceEndpoint ;
import org.gcube.common.scope.api.ScopeProvider ;
2019-05-03 15:31:47 +02:00
import org.gcube.common.storagehub.model.exceptions.UserNotAuthorizedException ;
2018-09-14 15:42:36 +02:00
import org.gcube.common.storagehubwrapper.server.StorageHubWrapper ;
2018-11-28 16:50:18 +01:00
import org.gcube.common.storagehubwrapper.shared.tohl.TrashedItem ;
import org.gcube.common.storagehubwrapper.shared.tohl.impl.WorkspaceFileVersion ;
2018-03-28 12:42:50 +02:00
import org.gcube.portal.wssynclibrary.shared.ItemNotSynched ;
import org.gcube.portal.wssynclibrary.shared.WorkspaceFolderLocked ;
2018-03-28 18:35:12 +02:00
import org.gcube.portal.wssynclibrary.shared.thredds.Sync_Status ;
2018-03-28 12:42:50 +02:00
import org.gcube.portal.wssynclibrary.thredds.WorkspaceThreddsSynchronize ;
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 ;
2017-09-27 18:38:30 +02:00
import org.gcube.portlets.user.workspace.client.model.GcubeVRE ;
2013-02-06 15:40:17 +01:00
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 ;
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 ;
2018-11-28 16:50:18 +01:00
import org.gcube.portlets.user.workspace.server.notifications.tostoragehub.NotificationStorageHubUtil ;
import org.gcube.portlets.user.workspace.server.notifications.tostoragehub.NotificationsProducerToStorageHub ;
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 ;
2018-11-28 16:50:18 +01:00
import org.gcube.portlets.user.workspace.server.tostoragehub.StorageHubToWorkpaceConverter ;
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-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 ;
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 ;
2019-04-30 12:06:04 +02:00
import org.gcube.portlets.user.workspace.shared.SHUBOperationNotAllowedException ;
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 ;
2018-11-28 16:50:18 +01:00
import org.gcube.portlets.user.workspace.shared.WorkspaceOperationResult ;
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 ;
2019-02-22 11:44:01 +01:00
import org.gcube.portlets.widgets.workspacesharingwidget.shared.InfoContactModel ;
2018-09-14 15:38:41 +02:00
import org.gcube.resources.discovery.client.api.DiscoveryClient ;
import org.gcube.resources.discovery.client.queries.api.SimpleQuery ;
2013-10-03 14:45:25 +02:00
import org.gcube.vomanagement.usermanagement.GroupManager ;
2017-09-27 18:38:30 +02:00
import org.gcube.vomanagement.usermanagement.exception.GroupRetrievalFault ;
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 ;
2017-09-27 18:38:30 +02:00
import org.gcube.vomanagement.usermanagement.model.GCubeGroup ;
2016-05-31 17:11:53 +02:00
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
*
2019-02-22 14:40:20 +01:00
* @author Francesco Mangiacrapa francesco . mangiacrapa { @literal @ } isti . cnr . it
2013-02-06 15:40:17 +01:00
* /
2019-02-22 11:44:01 +01:00
public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWTWorkspaceService {
2013-02-06 15:40:17 +01:00
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
* /
2019-02-22 11:44:01 +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
/ * *
2018-11-28 16:50:18 +01:00
* Gets the workspace .
2015-03-06 16:12:21 +01:00
*
2019-02-22 15:02:32 +01:00
*
* @return Workspace
2019-02-22 11:44:01 +01:00
* @throws InternalErrorException
2019-02-22 15:02:32 +01:00
* Internal error
2019-02-22 11:44:01 +01:00
* @throws HomeNotFoundException
2019-02-22 15:02:32 +01:00
* Home not found error
2019-02-22 11:44:01 +01:00
* @throws WorkspaceFolderNotFoundException
2019-02-22 15:02:32 +01:00
* Folder not found error
* @throws org . gcube . common . storagehubwrapper . shared . tohl . exceptions . InternalErrorException
* StorageHub Internal error
2019-02-22 11:44:01 +01:00
* /
protected Workspace getWorkspace ( )
throws InternalErrorException , HomeNotFoundException , WorkspaceFolderNotFoundException ,
org . gcube . common . storagehubwrapper . shared . tohl . exceptions . InternalErrorException {
2018-11-28 16:50:18 +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
* /
2019-02-22 11:44:01 +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
* /
2019-02-22 11:44:01 +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
* /
2019-02-22 11:44:01 +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 ( ) ;
2019-02-22 11:44:01 +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 ) ;
2019-02-22 11:44:01 +01:00
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
2019-02-22 11:44:01 +01:00
/ *
* ( non - Javadoc )
*
* @see org . gcube . portlets . user . workspace . client . rpc . GWTWorkspaceService #
* getItemsBySearchName ( java . lang . String )
2015-03-06 16:12:21 +01:00
* /
2017-02-20 11:41:54 +01:00
/ * *
* Gets the items by search name .
*
2019-02-22 11:44:01 +01:00
* @param text
* the text
* @param folderId
* the folder id
2017-02-20 11:41:54 +01:00
* @return the items by search name
2019-02-22 11:44:01 +01:00
* @throws Exception
* the exception
2017-02-20 11:41:54 +01:00
* /
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 ( ) ;
2019-02-22 11:44:01 +01:00
if ( folderId = = null | | folderId . isEmpty ( ) ) {
2015-10-12 15:30:59 +02:00
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
2019-02-22 11:44:01 +01:00
workspaceLogger . info ( " searching by name: " + text + " in " + folderId ) ;
2015-10-12 15:30:59 +02:00
List < SearchItem > listSearchItems = workspace . searchByName ( text , folderId ) ;
2019-02-22 11:44:01 +01:00
workspaceLogger . info ( " HL search returning " + listSearchItems . size ( ) + " items " ) ;
2016-01-19 15:50:40 +01:00
2019-02-22 11:44:01 +01: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 ) ;
2019-02-22 11:44:01 +01:00
// workspaceLogger.trace("Error in server During search retrieving "
// + e);
2016-01-19 15:50:40 +01:00
2019-02-22 11:44:01 +01:00
// GWT can't serialize all exceptions
2013-02-06 15:40:17 +01:00
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
/ * *
* Gets the name for special folder .
*
* @return the name for special folder
* /
2019-02-22 11:44:01 +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
2019-02-22 11:44:01 +01:00
if ( sfReader = = null ) {
2014-03-05 17:45:33 +01:00
workspaceLogger . warn ( " Reader is null, skypping set to special folder name " ) ;
return " " ;
}
2016-01-19 15:50:40 +01:00
2019-02-22 11:44:01 +01:00
workspaceLogger
. info ( " Read special folder name: ' " + sfReader . getSpecialFolderName ( ) + " ', from property file.. " ) ;
2014-03-05 17:45:33 +01:00
return sfReader . getSpecialFolderName ( ) ;
}
2016-01-19 15:50:40 +01:00
2019-02-22 11:44:01 +01:00
/ *
* ( non - Javadoc )
*
* @see org . gcube . portlets . user . workspace . client . rpc . GWTWorkspaceService #
* getItemForFileGrid ( java . lang . String )
2015-03-06 16:12:21 +01:00
* /
2017-02-20 11:41:54 +01:00
/ * *
2018-11-28 16:50:18 +01:00
* Gets the item for file grid .
2017-02-20 11:41:54 +01:00
*
2019-02-22 11:44:01 +01:00
* @param itemId
* the item id
2018-11-28 16:50:18 +01:00
* @return the item for file grid
2019-02-22 11:44:01 +01:00
* @throws Exception
* the exception
2017-02-20 11:41:54 +01:00
* /
2013-02-06 15:40:17 +01:00
@Override
2018-11-28 16:50:18 +01:00
public FileGridModel getItemForFileGrid ( 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
2019-02-22 11:44:01 +01:00
if ( itemId = = null )
2018-11-28 16:50:18 +01:00
throw new Exception ( IDENTIFIER_IS_NULL ) ;
2016-01-19 15:50:40 +01:00
2013-10-04 13:58:07 +02:00
Workspace workspace = getWorkspace ( ) ;
2019-02-22 11:44:01 +01:00
workspaceLogger . trace ( " get child for Grid by id: " + itemId ) ;
WorkspaceItem wsItem = workspace . getItem ( itemId ) ;
2016-01-19 15:50:40 +01:00
GWTWorkspaceBuilder builder = getGWTWorkspaceBuilder ( ) ;
2019-02-22 11:44:01 +01:00
Long startTime = System . currentTimeMillis ( ) ;
2018-11-28 16:50:18 +01:00
Long endTime = System . currentTimeMillis ( ) - startTime ;
String time = String . format ( " %d msc %d sec " , endTime , TimeUnit . MILLISECONDS . toSeconds ( endTime ) ) ;
workspaceLogger . debug ( " get child for Grid by id returning element in " + time ) ;
2019-02-22 11:44:01 +01:00
// BUILD PARENT
WorkspaceFolder folder = wsItem . getParent ( ) ; // get parent
2018-11-28 16:50:18 +01:00
FileGridModel wsFolder = builder . buildGXTFileGridModelItem ( folder , null ) ;
2019-02-22 11:44:01 +01:00
// BUILD ITEM
2018-11-28 16:50:18 +01:00
return builder . buildGXTFileGridModelItem ( wsItem , wsFolder ) ;
2016-01-19 15:50:40 +01:00
2013-02-06 15:40:17 +01:00
} catch ( Exception e ) {
2018-11-28 16:50:18 +01: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 ;
2013-06-14 15:04:43 +02:00
throw new Exception ( error ) ;
}
}
2016-01-19 15:50:40 +01:00
2019-02-22 11:44:01 +01:00
/ *
* ( non - Javadoc )
*
* @see org . gcube . portlets . user . workspace . client . rpc . GWTWorkspaceService #
* getItemForFileTree ( java . lang . String )
2015-03-06 16:12:21 +01:00
* /
2017-02-20 11:41:54 +01:00
/ * *
2018-11-28 16:50:18 +01:00
* Gets the item for file tree .
2017-02-20 11:41:54 +01:00
*
2019-02-22 11:44:01 +01:00
* @param itemId
* the item id
2018-11-28 16:50:18 +01:00
* @return the item for file tree
2019-02-22 11:44:01 +01:00
* @throws Exception
* the exception
2017-02-20 11:41:54 +01:00
* /
2013-06-14 15:04:43 +02:00
@Override
2018-11-28 16:50:18 +01:00
public FileModel getItemForFileTree ( String itemId ) throws Exception {
2013-06-14 15:04:43 +02:00
try {
2013-10-04 13:58:07 +02:00
2019-02-22 11:44:01 +01:00
if ( itemId = = null )
2018-11-28 16:50:18 +01:00
throw new Exception ( IDENTIFIER_IS_NULL ) ;
2016-01-19 15:50:40 +01:00
2013-10-04 13:58:07 +02:00
Workspace workspace = getWorkspace ( ) ;
2019-02-22 11:44:01 +01:00
WorkspaceItem wsItem = workspace . getItem ( itemId ) ;
2013-06-14 15:04:43 +02:00
GWTWorkspaceBuilder builder = getGWTWorkspaceBuilder ( ) ;
2019-02-22 11:44:01 +01:00
// BUILD PARENT
WorkspaceFolder folderParent = wsItem . getParent ( ) ; // get parent
2018-11-28 16:50:18 +01:00
FileModel wsFolderParent = builder . buildGXTFileModelItem ( folderParent , null ) ;
2019-02-22 11:44:01 +01:00
// BUILD ITEM
2018-11-28 16:50:18 +01:00
return builder . buildGXTFileModelItem ( wsItem , wsFolderParent ) ;
2016-01-19 15:50:40 +01:00
2013-06-14 15:04:43 +02:00
} catch ( Exception e ) {
2018-11-28 16:50:18 +01: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 ;
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
2019-02-22 11:44:01 +01:00
// DEBUG
2015-03-06 16:12:21 +01:00
/ * *
* Prints the contacts .
*
2019-02-22 11:44:01 +01:00
* @param listContacts
* the list contacts
2015-03-06 16:12:21 +01:00
* /
2019-02-22 11:44:01 +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 ) {
2019-02-22 11:44:01 +01:00
workspaceLogger . trace ( " User: " + infoContactModel ) ;
2013-02-27 19:17:22 +01:00
}
}
2015-06-24 16:56:13 +02:00
2019-02-22 11:44:01 +01:00
// DEBUG
2015-03-06 16:12:21 +01:00
/ * *
* Prints the list .
*
2019-02-22 11:44:01 +01:00
* @param list
* the list
2015-03-06 16:12:21 +01:00
* /
2019-02-22 11:44:01 +01:00
private void printList ( List < String > list ) {
2014-09-24 16:51:42 +02:00
for ( String string : list ) {
workspaceLogger . trace ( string ) ;
}
}
2013-02-06 15:40:17 +01:00
2019-02-22 11:44:01 +01:00
/ *
* ( non - Javadoc )
*
* @see org . gcube . portlets . user . workspace . client . rpc . GWTWorkspaceService #
* getDetailsFile ( org . gcube . portlets . user . workspace . client . model . FileModel )
2018-11-28 16:50:18 +01:00
* /
/ * *
* Gets the details file .
*
2019-02-22 11:44:01 +01:00
* @param folder
* the folder
2018-11-28 16:50:18 +01:00
* @return the details file
2019-02-22 11:44:01 +01:00
* @throws Exception
* the exception
2017-02-20 11:41:54 +01:00
* /
2013-02-06 15:40:17 +01:00
@Override
2018-11-28 16:50:18 +01:00
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
2019-02-22 11:44:01 +01:00
if ( folder = = null )
2018-11-28 16:50:18 +01:00
throw new Exception ( " Folder is null " ) ;
2016-01-19 15:50:40 +01:00
2018-11-28 16:50:18 +01:00
workspaceLogger . trace ( " load file details: " + folder . getName ( ) ) ;
Workspace workspace = getWorkspace ( ) ;
WorkspaceItem wsItem = workspace . getItem ( folder . getIdentifier ( ) ) ;
GWTWorkspaceBuilder builder = getGWTWorkspaceBuilder ( ) ;
2018-03-28 12:42:50 +02:00
2018-11-28 16:50:18 +01:00
return builder . buildGWTWorkspaceFileDetails ( wsItem , folder ) ;
2018-09-14 15:42:36 +02:00
2018-11-28 16:50:18 +01:00
} catch ( Exception e ) {
workspaceLogger . error ( " Error in load server file details " , e ) ;
throw new Exception ( e . getMessage ( ) ) ;
}
}
2018-09-14 15:42:36 +02:00
2019-02-22 11:44:01 +01:00
/ *
* ( non - Javadoc )
*
* @see org . gcube . portlets . user . workspace . client . rpc . GWTWorkspaceService #
* getChildrenSubTreeToRootByIdentifier ( java . lang . String )
2018-11-28 16:50:18 +01:00
* /
/ * *
* Gets the children sub tree to root by identifier .
*
2019-02-22 11:44:01 +01:00
* @param itemIdentifier
* the item identifier
2018-11-28 16:50:18 +01:00
* @return the children sub tree to root by identifier
2019-02-22 11:44:01 +01:00
* @throws Exception
* the exception
2018-11-28 16:50:18 +01:00
* /
@Override
public ArrayList < SubTree > getChildrenSubTreeToRootByIdentifier ( String itemIdentifier ) throws Exception {
2018-09-14 15:42:36 +02:00
2019-02-22 11:44:01 +01:00
ArrayList < SubTree > listSubTree = new ArrayList < SubTree > ( ) ;
2018-09-14 15:42:36 +02:00
2018-11-28 16:50:18 +01:00
try {
2018-09-14 15:42:36 +02:00
2019-02-22 11:44:01 +01:00
if ( itemIdentifier = = null )
2018-11-28 16:50:18 +01:00
throw new Exception ( IDENTIFIER_IS_NULL ) ;
2013-10-04 13:58:07 +02:00
2018-11-28 16:50:18 +01:00
Workspace workspace = getWorkspace ( ) ;
2019-02-22 11:44:01 +01:00
workspaceLogger . trace ( " search itemId: " + itemIdentifier ) ;
WorkspaceItem item = workspace . getItem ( itemIdentifier ) ; // get item
// from
// workspace
2018-11-28 16:50:18 +01:00
getListsChildrenByParent ( listSubTree , item ) ;
2019-02-22 11:44:01 +01:00
Collections . reverse ( listSubTree ) ; // reverse order of array
2016-01-19 15:50:40 +01:00
2019-02-22 11:44:01 +01:00
// SET THE ROOT
2015-09-18 17:19:09 +02:00
int lenght = listSubTree . size ( ) ;
2019-02-22 11:44:01 +01:00
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 ) ;
2019-02-22 11:44:01 +01:00
// IF IT CASE - REWRITE SPECIAL FOLDER NAME
if ( lenght > 1 ) {
FolderModel wsFolder = listSubTree . get ( 1 ) . getParent ( ) ; // get
// first
// child
2015-09-18 17:19:09 +02:00
String nameSpecialFolder = getNameForSpecialFolder ( ) ;
2019-02-22 11:44:01 +01:00
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 ( ) )
2015-09-18 17:19:09 +02:00
listSubTree . get ( 1 ) . getParent ( ) . setName ( nameSpecialFolder ) ;
}
}
2015-09-18 16:51:38 +02:00
}
2016-01-19 15:50:40 +01:00
2019-02-22 11:44:01 +01: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
2019-02-22 11:44:01 +01:00
/ *
* ( non - Javadoc )
*
* @see org . gcube . portlets . user . workspace . client . rpc . GWTWorkspaceService #
* getSmartFolderResultsByCategory ( java . lang . String )
2015-03-06 16:12:21 +01:00
* /
2017-02-20 11:41:54 +01:00
/ * *
* Gets the smart folder results by category .
*
2019-02-22 11:44:01 +01:00
* @param category
* the category
2017-02-20 11:41:54 +01:00
* @return the smart folder results by category
2019-02-22 11:44:01 +01:00
* @throws Exception
* the exception
2017-02-20 11:41:54 +01:00
* /
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 ( ) ;
2019-02-22 11:44:01 +01: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
2019-02-22 11:44:01 +01:00
// Category IMAGES
if ( category . equals ( GXTCategorySmartFolder . SMF_IMAGES ) ) {
listWorkspaceItems = workspace . getFolderItems ( FolderItemType . IMAGE_DOCUMENT ,
FolderItemType . EXTERNAL_IMAGE ) ;
// Category BIODIVERSITY
} else if ( category . equals ( GXTCategorySmartFolder . SMF_BIODIVERSITY ) ) {
// listWorkspaceItems =
// workspace.getFolderItems(FolderItemType.AQUAMAPS_ITEM);
// Category DOCUMENTS
} else if ( category . equals ( GXTCategorySmartFolder . SMF_DOCUMENTS ) ) {
listWorkspaceItems = workspace . getFolderItems ( FolderItemType . EXTERNAL_FILE ,
FolderItemType . EXTERNAL_PDF_FILE , FolderItemType . QUERY , FolderItemType . PDF_DOCUMENT ,
FolderItemType . METADATA , FolderItemType . DOCUMENT ) ;
// Category LINKS
} else if ( category . equals ( GXTCategorySmartFolder . SMF_LINKS ) ) {
// listWorkspaceItems =
// workspace.getFolderItems(FolderItemType.EXTERNAL_URL,
// FolderItemType.URL_DOCUMENT,
// FolderItemType.EXTERNAL_RESOURCE_LINK);
// Category REPORTS
} else if ( category . equals ( GXTCategorySmartFolder . SMF_REPORTS ) ) {
2013-02-06 15:40:17 +01:00
listWorkspaceItems = workspace . getFolderItems ( FolderItemType . REPORT_TEMPLATE , FolderItemType . REPORT ) ;
2019-02-22 11:44:01 +01:00
// Category TIME SERIES
} else if ( category . equals ( GXTCategorySmartFolder . SMF_TIMESERIES ) ) {
2013-02-06 15:40:17 +01:00
listWorkspaceItems = workspace . getFolderItems ( FolderItemType . TIME_SERIES ) ;
2019-02-22 11:44:01 +01:00
} else if ( category . equals ( GXTCategorySmartFolder . SMF_PUBLIC_FOLDERS ) ) {
2016-09-29 15:28:32 +02:00
List < WorkspaceItem > listFolder = workspace . getPublicFolders ( ) ;
2019-02-22 11:44:01 +01:00
if ( listFolder = = null | | listFolder . isEmpty ( ) )
2016-09-29 15:28:32 +02:00
return new ArrayList < FileGridModel > ( ) ;
return builder . buildGXTListFileGridModelItem ( listFolder , null ) ;
2019-02-22 11:44:01 +01:00
} 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-03-06 16:12:21 +01:00
/ * *
* Gets the lists children by parents .
*
2019-02-22 11:44:01 +01:00
* @param listSubTree
* the list sub tree
* @param parent
* the parent
2015-03-06 16:12:21 +01:00
* @return the lists children by parents
2019-02-22 11:44:01 +01:00
* @throws Exception
* the exception
2015-03-06 16:12:21 +01:00
* /
2019-02-22 11:44:01 +01:00
private void getListsChildrenByParent ( ArrayList < SubTree > listSubTree , WorkspaceItem parent ) throws Exception {
2016-01-19 15:50:40 +01:00
2019-02-22 11:44:01 +01:00
if ( parent = = null )
2016-06-22 18:41:51 +02:00
return ;
2015-06-24 16:56:13 +02:00
2019-02-22 11:44:01 +01:00
if ( ! parent . isFolder ( ) ) {
workspaceLogger . warn ( " getListsChildrenByParent returning: " + parent . getName ( ) + " is not a folder " ) ;
2016-06-22 18:41:51 +02:00
return ;
}
2016-01-19 15:50:40 +01:00
2019-02-22 11:44:01 +01:00
workspaceLogger . trace ( " getListsChildrenByParent: " + parent . getName ( ) ) ;
2016-06-22 18:41:51 +02:00
GWTWorkspaceBuilder builder = getGWTWorkspaceBuilder ( ) ;
2019-02-22 11:44:01 +01:00
FolderModel parentModel = ( FolderModel ) builder . buildGXTFileModelItem ( parent , null ) ; // get
// folder
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
2019-02-22 11:44:01 +01:00
/ *
* ( non - Javadoc )
*
* @see org . gcube . portlets . user . workspace . client . rpc . GWTWorkspaceService #
* createSmartFolder ( java . lang . String , java . lang . String , java . lang . String )
2015-03-06 16:12:21 +01:00
* /
2017-02-20 11:41:54 +01:00
/ * *
* Creates the smart folder .
*
2019-02-22 11:44:01 +01:00
* @param name
* the name
* @param description
* the description
* @param query
* the query
* @param parentId
* the parent id
2017-02-20 11:41:54 +01:00
* @return the smart folder model
2019-02-22 11:44:01 +01:00
* @throws Exception
* the exception
2017-02-20 11:41:54 +01:00
* /
2013-02-06 15:40:17 +01:00
@Override
2019-02-22 11:44:01 +01:00
public SmartFolderModel createSmartFolder ( String name , String description , String query , String parentId )
throws Exception {
2016-01-19 15:50:40 +01:00
2019-02-22 11:44:01 +01:00
if ( isSessionExpired ( ) )
2016-10-24 14:43:33 +02:00
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 ( ) ;
2019-02-22 11:44:01 +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 ) ;
2019-02-22 11:44:01 +01:00
if ( parentId = = null | | parentId . isEmpty ( ) ) {
2015-10-12 15:30:59 +02:00
workspaceLogger . trace ( " parent id is null using root id " ) ;
parentId = workspace . getRoot ( ) . getId ( ) ;
}
2016-01-19 15:50:40 +01:00
2019-02-22 11:44:01 +01:00
WorkspaceSmartFolder wsSmartFolder = workspace . createSmartFolder ( name , description , query , parentId ) ; // create
// Smart
// Folder
// from
// workspace
workspaceLogger . trace ( " create : " + wsSmartFolder . getName ( ) + " id " + wsSmartFolder . getId ( ) ) ;
2013-02-06 15:40:17 +01:00
GWTWorkspaceBuilder builder = getGWTWorkspaceBuilder ( ) ;
2019-02-22 11:44:01 +01:00
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 ) ;
2019-02-22 11:44:01 +01:00
// workspaceLogger.trace("Error in server create smart folder by id
// " + e);
// GWT can't serialize all exceptions
2013-02-06 15:40:17 +01:00
throw new Exception ( e . getMessage ( ) ) ;
}
}
2016-01-19 15:50:40 +01:00
2019-02-22 11:44:01 +01:00
/ *
* ( non - Javadoc )
*
* @see org . gcube . portlets . user . workspace . client . rpc . GWTWorkspaceService #
* removeSmartFolder ( java . lang . String , java . lang . String )
2015-03-06 16:12:21 +01:00
* /
2017-02-20 11:41:54 +01:00
/ * *
* Removes the smart folder .
*
2019-02-22 11:44:01 +01:00
* @param itemId
* the item id
* @param name
* the name
2017-02-20 11:41:54 +01:00
* @return the boolean
2019-02-22 11:44:01 +01:00
* @throws Exception
* the exception
2017-02-20 11:41:54 +01:00
* /
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
2019-02-22 11:44:01 +01:00
if ( itemId = = null )
2013-10-04 13:58:07 +02:00
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 ( ) ;
2019-02-22 11:44:01 +01:00
workspaceLogger . trace ( " remove smart folder by id: " + itemId ) ;
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
2019-02-22 11:44:01 +01:00
/ *
* ( non - Javadoc )
*
* @see org . gcube . portlets . user . workspace . client . rpc . GWTWorkspaceService #
* getAllSmartFolders ( )
2015-03-06 16:12:21 +01:00
* /
2017-02-20 11:41:54 +01:00
/ * *
* Gets the all smart folders .
*
* @return the all smart folders
2019-02-22 11:44:01 +01:00
* @throws Exception
* the exception
2017-02-20 11:41:54 +01:00
* /
2013-02-06 15:40:17 +01:00
@Override
2019-02-22 11:44:01 +01:00
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 > ( ) ;
2019-02-22 11:44:01 +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 ( ) ) ;
}
}
2019-02-22 11:44:01 +01:00
/ *
* ( non - Javadoc )
*
* @see org . gcube . portlets . user . workspace . client . rpc . GWTWorkspaceService #
* getSmartFolderResultsById ( java . lang . String )
2015-03-06 16:12:21 +01:00
* /
2017-02-20 11:41:54 +01:00
/ * *
* Gets the smart folder results by id .
*
2019-02-22 11:44:01 +01:00
* @param folderId
* the folder id
2017-02-20 11:41:54 +01:00
* @return the smart folder results by id
2019-02-22 11:44:01 +01:00
* @throws Exception
* the exception
2017-02-20 11:41:54 +01:00
* /
2013-02-06 15:40:17 +01:00
@Override
public List < FileGridModel > getSmartFolderResultsById ( String folderId ) throws Exception {
2019-02-22 11:44:01 +01:00
if ( folderId = = null )
2013-10-04 13:58:07 +02:00
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 ( ) ;
2019-02-22 11:44:01 +01:00
workspaceLogger . trace ( " get smart folder by id: " + folderId ) ;
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
2019-02-22 11:44:01 +01:00
if ( searchItems ! = null ) {
workspaceLogger . trace ( " smart folders size " + searchItems . size ( ) ) ;
2015-11-10 12:24:23 +01:00
return builder . buildGXTListFileGridModelItemForSearch ( ( List < SearchItem > ) searchItems ) ;
2019-02-22 11:44:01 +01:00
} else
2015-11-10 12:24:23 +01:00
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 ( ) ) ;
}
}
2019-02-22 11:44:01 +01:00
/ *
* ( non - Javadoc )
*
* @see org . gcube . portlets . user . workspace . client . rpc . GWTWorkspaceService #
* getImageById ( java . lang . String , boolean , boolean )
2015-03-06 16:12:21 +01:00
* /
2017-02-20 11:41:54 +01:00
/ * *
* Gets the image by id .
*
2019-02-22 11:44:01 +01:00
* @param identifier
* the identifier
* @param isInteralImage
* the is interal image
* @param fullDetails
* the full details
2017-02-20 11:41:54 +01:00
* @return the image by id
2019-02-22 11:44:01 +01:00
* @throws Exception
* the exception
2017-02-20 11:41:54 +01:00
* /
2013-02-06 15:40:17 +01:00
@Override
2019-02-22 11:44:01 +01:00
public GWTWorkspaceItem getImageById ( String identifier , boolean isInteralImage , boolean fullDetails )
throws Exception {
2016-01-19 15:50:40 +01:00
2019-02-22 11:44:01 +01:00
if ( identifier = = null )
2013-10-04 13:58:07 +02:00
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 ( ) ;
2019-02-22 11:44:01 +01:00
workspaceLogger . trace ( " get image by id: " + identifier ) ;
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 ( ) ) ;
2019-02-22 11:44:01 +01:00
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
2019-02-22 11:44:01 +01:00
/ *
* ( non - Javadoc )
*
* @see org . gcube . portlets . user . workspace . client . rpc . GWTWorkspaceService #
* getTimeSeriesById ( java . lang . String )
2015-03-06 16:12:21 +01:00
* /
2017-02-20 11:41:54 +01:00
/ * *
* Gets the time series by id .
*
2019-02-22 11:44:01 +01:00
* @param identifier
* the identifier
2017-02-20 11:41:54 +01:00
* @return the time series by id
2019-02-22 11:44:01 +01:00
* @throws Exception
* the exception
2017-02-20 11:41:54 +01:00
* /
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
2019-02-22 11:44:01 +01:00
if ( identifier = = null )
2013-10-04 13:58:07 +02:00
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 ( ) ;
2019-02-22 11:44:01 +01:00
workspaceLogger . trace ( " get timeseries by id: " + identifier ) ;
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
2019-02-22 11:44:01 +01:00
/ *
* ( non - Javadoc )
*
* @see org . gcube . portlets . user . workspace . client . rpc . GWTWorkspaceService #
* getUrlById ( java . lang . String , boolean , boolean )
2015-03-06 16:12:21 +01:00
* /
2017-02-20 11:41:54 +01:00
/ * *
* Gets the url by id .
*
2019-02-22 11:44:01 +01:00
* @param identifier
* the identifier
* @param isInternalUrl
* the is internal url
* @param fullDetails
* the full details
2017-02-20 11:41:54 +01:00
* @return the url by id
2019-02-22 11:44:01 +01:00
* @throws Exception
* the exception
2017-02-20 11:41:54 +01:00
* /
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
2019-02-22 11:44:01 +01:00
if ( identifier = = null )
2013-10-04 13:58:07 +02:00
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 ( ) ;
2019-02-22 11:44:01 +01:00
workspaceLogger . trace ( " get url by id: " + identifier ) ;
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 ) ;
2019-02-22 11:44:01 +01:00
// workspaceLogger.trace("Error in server get image by id " + e);
// GWT can't serialize all exceptions
2013-02-06 15:40:17 +01:00
throw new Exception ( e . getMessage ( ) ) ;
}
}
2019-02-22 11:44:01 +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 )
2015-03-06 16:12:21 +01:00
* /
2018-03-06 14:37:32 +01:00
2017-02-20 11:41:54 +01:00
/ * *
* Creates the external url .
*
2019-02-22 11:44:01 +01:00
* @param parentId
* the parent id
* @param name
* the name
* @param description
* the description
* @param url
* the url
2017-02-20 11:41:54 +01:00
* @return the file model
2019-02-22 11:44:01 +01:00
* @throws Exception
* the exception
2017-02-20 11:41:54 +01:00
* /
2013-02-06 15:40:17 +01:00
@Override
2018-03-06 14:37:32 +01:00
public FileModel createExternalUrl ( String parentId , 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
2019-02-22 11:44:01 +01:00
if ( parentId = = null ) {
2018-03-06 14:37:32 +01:00
workspaceLogger . error ( " Error on creating url. Parent ID is null " ) ;
throw new Exception ( " Parent ID is null " ) ;
}
2016-01-19 15:50:40 +01:00
2018-03-28 12:42:50 +02:00
checkItemLocked ( parentId ) ;
2019-02-22 11:44:01 +01:00
workspaceLogger . trace ( " create url in parent id: " + parentId ) ;
2018-03-06 14:37:32 +01:00
ExternalUrl ext = workspace . createExternalUrl ( name , description , url , parentId ) ;
2019-02-22 11:44:01 +01:00
WorkspaceItem parent = workspace . getItem ( parentId ) ; // get item from
// workspace
2013-02-06 15:40:17 +01:00
workspaceLogger . trace ( " parent name " + parent . getName ( ) ) ;
GWTWorkspaceBuilder builder = getGWTWorkspaceBuilder ( ) ;
2018-03-06 14:37:32 +01:00
FolderModel parentFileModel = builder . buildGXTFolderModelItem ( ( WorkspaceFolder ) parent , null ) ;
2013-02-06 15:40:17 +01:00
return builder . buildGXTFileModelItem ( ext , parentFileModel ) ;
2016-01-19 15:50:40 +01:00
2019-02-22 11:44:01 +01:00
} catch ( WorkspaceFolderLocked e1 ) {
2018-03-28 12:42:50 +02:00
throw new Exception ( e1 . getMessage ( ) ) ;
2013-02-06 15:40:17 +01:00
} catch ( Exception e ) {
workspaceLogger . error ( " Error in server create url in parent id " , e ) ;
2019-02-22 11:44:01 +01:00
// workspaceLogger.trace("Error in server create url in parent id "
// + e);
// GWT can't serialize all exceptions
2013-02-06 15:40:17 +01:00
throw new Exception ( e . getMessage ( ) ) ;
}
}
2016-01-19 15:50:40 +01:00
2019-02-22 11:44:01 +01:00
/ *
* ( non - Javadoc )
*
* @see org . gcube . portlets . user . workspace . client . rpc . GWTWorkspaceService #
* getURLFromApplicationProfile ( java . lang . String )
2015-03-06 16:12:21 +01:00
* /
2017-02-20 11:41:54 +01:00
/ * *
* Gets the URL from application profile .
*
2019-02-22 11:44:01 +01:00
* @param oid
* the oid
2017-02-20 11:41:54 +01:00
* @return the URL from application profile
2019-02-22 11:44:01 +01:00
* @throws Exception
* the exception
2017-02-20 11:41:54 +01:00
* /
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
2019-02-22 11:44:01 +01:00
/ *
* ( non - Javadoc )
*
* @see org . gcube . portlets . user . workspace . client . rpc . GWTWorkspaceService #
* setValueInSession ( java . lang . String , java . lang . String )
2015-03-06 16:12:21 +01:00
* /
2017-02-20 11:41:54 +01:00
/ * *
* Sets the value in session .
*
2019-02-22 11:44:01 +01:00
* @param name
* the name
* @param value
* the value
* @throws Exception
* the exception
2017-02-20 11:41:54 +01:00
* /
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
2019-02-22 11:44:01 +01:00
try {
2016-11-25 12:03:25 +01:00
this . getThreadLocalRequest ( ) . getSession ( ) . setAttribute ( name , value ) ;
2019-02-22 11:44:01 +01:00
workspaceLogger . trace ( " set value in session with name: " + name + " , value: " + value ) ;
2013-02-06 15:40:17 +01:00
} catch ( Exception e ) {
workspaceLogger . error ( " setValueInSession " , e ) ;
throw new Exception ( e . getMessage ( ) ) ;
}
}
2019-02-22 11:44:01 +01:00
/ *
* ( non - Javadoc )
*
* @see org . gcube . portlets . user . workspace . client . rpc . GWTWorkspaceService #
* getAllScope ( )
2015-03-06 16:12:21 +01:00
* /
2017-02-20 11:41:54 +01:00
/ * *
* Gets the all scope .
*
* @return the all scope
2019-02-22 11:44:01 +01:00
* @throws Exception
* the exception
2017-02-20 11:41:54 +01:00
* /
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 ( ) ;
2019-02-22 11:44:01 +01:00
if ( home ! = null ) {
2013-03-27 17:30:37 +01:00
List < String > listIdFilterdScope = scopeUtilFilter . convertListScopeToPortlet ( home . listScopes ( ) ) ;
return builder . buildGXTListScopeModel ( listIdFilterdScope , scopeUtilFilter . getHashScopesFiltered ( ) ) ;
2019-02-22 11:44:01 +01:00
} else {
2013-03-27 17:30:37 +01:00
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 ( ) ;
2019-02-22 11:44:01 +01:00
// workspaceLogger.trace("Error in server get all scope " +
// e.getMessage());
// GWT can't serialize all exceptions
2013-02-06 15:40:17 +01:00
throw new Exception ( e . getMessage ( ) ) ;
}
}
2019-02-22 11:44:01 +01:00
/ *
* ( non - Javadoc )
*
* @see org . gcube . portlets . user . workspace . client . rpc . GWTWorkspaceService #
* sendToById ( java . util . List , java . util . List , java . lang . String ,
* java . lang . String )
2015-09-18 15:26:33 +02:00
* /
2017-02-20 11:41:54 +01:00
/ * *
* Send to by id .
*
2019-02-22 11:44:01 +01:00
* @param listContactsId
* the list contacts id
* @param listAttachmentsId
* the list attachments id
* @param subject
* the subject
* @param body
* the body
2017-02-20 11:41:54 +01:00
* @return true , if successful
2019-02-22 11:44:01 +01:00
* @throws Exception
* the exception
2017-02-20 11:41:54 +01:00
* /
2015-09-18 15:26:33 +02:00
@Override
2019-02-22 11:44:01 +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 ( ) ;
2019-02-22 15:02:32 +01:00
// workspaceLogger.trace("######### SEND TO: ");
// workspaceLogger.trace("subject " + subject);
// workspaceLogger.trace("body " + body);
2019-02-22 11:44:01 +01:00
// DEBUG
for ( String contactId : listContactsId )
2015-06-24 16:56:13 +02:00
workspaceLogger . trace ( " contactId " + contactId ) ;
2019-02-22 11:44:01 +01:00
// DEBUG
for ( String id : listAttachmentsId )
2013-02-06 15:40:17 +01:00
workspaceLogger . trace ( " attachId " + id ) ;
2019-02-22 11:44:01 +01:00
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 ) ;
2019-02-22 11:44:01 +01:00
// GWT can't serialize all exceptions
2013-02-06 15:40:17 +01:00
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 .
*
2019-02-22 11:44:01 +01:00
* @param workspace
* the workspace
* @param listItemsId
* the list items id
2015-03-06 16:12:21 +01:00
* @return the list workspace item by id
2019-02-22 11:44:01 +01:00
* @throws ItemNotFoundException
* the item not found exception
* @throws InternalErrorException
* the internal error exception
2015-03-06 16:12:21 +01:00
* /
2019-02-22 11:44:01 +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
2019-02-22 11:44:01 +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 ) ;
2019-02-22 11:44:01 +01:00
workspaceLogger . trace ( " Attach name: " + item . getName ( ) ) ;
workspaceLogger . trace ( " Attach id: " + item . getId ( ) ) ;
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
2019-02-22 11:44:01 +01:00
/ *
* ( non - Javadoc )
*
* @see org . gcube . portlets . user . workspace . client . rpc . GWTWorkspaceService #
* getUrlWebDav ( java . lang . String )
2015-03-06 16:12:21 +01:00
* /
2017-02-20 11:41:54 +01:00
/ * *
2018-11-28 16:50:18 +01:00
* Gets the url web dav .
2017-02-20 11:41:54 +01:00
*
2019-02-22 11:44:01 +01:00
* @param itemId
* the item id
2018-11-28 16:50:18 +01:00
* @return the url web dav
2019-02-22 11:44:01 +01:00
* @throws Exception
* the exception
2017-02-20 11:41:54 +01:00
* /
2013-02-06 15:40:17 +01:00
@Override
2018-11-28 16:50:18 +01:00
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 ( ) ;
2018-11-28 16:50:18 +01:00
workspaceLogger . trace ( " getWebDavUrl " + itemId ) ;
return workspace . getUrlWebDav ( ) ;
2013-02-06 15:40:17 +01:00
} catch ( Exception e ) {
2018-11-28 16:50:18 +01:00
workspaceLogger . error ( " Error in getNewFolderBulkCreator " , e ) ;
2019-02-22 11:44:01 +01:00
// workspaceLogger.trace("Error in getNewFolderBulkCreator " +
// e.getMessage());
2018-11-28 16:50:18 +01:00
throw new Exception ( e . getMessage ( ) ) ;
2013-02-06 15:40:17 +01:00
}
}
2016-01-19 15:50:40 +01:00
2019-02-22 11:44:01 +01:00
/ *
* ( non - Javadoc )
*
* @see org . gcube . portlets . user . workspace . client . rpc . GWTWorkspaceService #
* itemExistsInWorkpaceFolder ( java . lang . String , java . lang . String )
2015-03-06 16:12:21 +01:00
* /
2017-02-20 11:41:54 +01:00
/ * *
* Item exists in workpace folder .
*
2019-02-22 11:44:01 +01:00
* @param parentId
* the parent id
* @param itemName
* the item name
2017-02-20 11:41:54 +01:00
* @return the string
2019-02-22 11:44:01 +01:00
* @throws Exception
* the exception
2017-02-20 11:41:54 +01:00
* /
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
2019-02-22 11:44:01 +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 ( ) ;
2019-02-22 11:44:01 +01:00
WorkspaceItem wsItem = workspace . getItem ( parentId ) ; // GET PARENT
2016-01-19 15:50:40 +01:00
2019-02-22 11:44:01 +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
2019-02-22 11:44:01 +01:00
if ( itemFound = = null )
2013-03-25 11:14:26 +01:00
return null ;
2016-01-19 15:50:40 +01:00
2013-03-25 11:14:26 +01:00
return itemFound . getId ( ) ;
2019-02-22 11:44:01 +01:00
} else
2013-03-25 11:14:26 +01:00
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
2019-02-22 11:44:01 +01:00
/ *
* ( non - Javadoc )
*
* @see org . gcube . portlets . user . workspace . client . rpc . GWTWorkspaceService #
* getItemCreationDateById ( java . lang . String )
2015-03-06 16:12:21 +01:00
* /
2017-02-20 11:41:54 +01:00
/ * *
* Gets the item creation date by id .
*
2019-02-22 11:44:01 +01:00
* @param itemId
* the item id
2017-02-20 11:41:54 +01:00
* @return the item creation date by id
2019-02-22 11:44:01 +01:00
* @throws Exception
* the exception
2017-02-20 11:41:54 +01:00
* /
2013-03-25 12:35:05 +01:00
@Override
public Date getItemCreationDateById ( String itemId ) throws Exception {
2019-02-22 11:44:01 +01:00
workspaceLogger . trace ( " get Item Creation Date 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 ) ;
Calendar cl = wsItem . getCreationTime ( ) ;
2016-01-19 15:50:40 +01:00
2019-02-22 11:44:01 +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 ( ) ) ;
}
}
2019-02-22 11:44:01 +01:00
/ *
* ( non - Javadoc )
*
* @see org . gcube . portlets . user . workspace . client . rpc . GWTWorkspaceService #
* loadSizeByItemId ( java . lang . String )
2015-03-06 16:12:21 +01:00
* /
2017-02-20 11:41:54 +01:00
/ * *
* Load size by item id .
*
2019-02-22 11:44:01 +01:00
* @param itemId
* the item id
2017-02-20 11:41:54 +01:00
* @return the long
2019-02-22 11:44:01 +01:00
* @throws Exception
* the exception
2017-02-20 11:41:54 +01:00
* /
2013-03-25 12:35:05 +01:00
@Override
public Long loadSizeByItemId ( String itemId ) throws Exception {
2016-01-19 15:50:40 +01:00
2019-02-22 11:44:01 +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
2019-02-22 11:44:01 +01:00
if ( wsItem instanceof FolderItem ) { // ITEM
2013-03-25 12:35:05 +01:00
FolderItem folderItem = ( FolderItem ) wsItem ;
size = new Long ( folderItem . getLength ( ) ) ;
2019-02-22 11:44:01 +01:00
} else if ( wsItem instanceof WorkspaceFolder ) { // FOLDER
2014-10-28 17:12:40 +01:00
WorkspaceFolder theFolder = ( WorkspaceFolder ) wsItem ;
size = theFolder . getSize ( ) ;
2019-02-22 11:44:01 +01:00
} else if ( wsItem instanceof WorkspaceSharedFolder ) { // SHARED
// FOLDER
2014-11-03 14:45:36 +01:00
WorkspaceSharedFolder theFolder = ( WorkspaceSharedFolder ) wsItem ;
size = theFolder . getSize ( ) ;
2013-03-25 12:35:05 +01:00
}
2019-02-22 11:44:01 +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
2019-02-22 11:44:01 +01:00
/ *
* ( non - Javadoc )
*
* @see org . gcube . portlets . user . workspace . client . rpc . GWTWorkspaceService #
* loadLastModificationDateById ( java . lang . String )
2015-03-06 16:12:21 +01:00
* /
2017-02-20 11:41:54 +01:00
/ * *
* Load last modification date by id .
*
2019-02-22 11:44:01 +01:00
* @param itemId
* the item id
2017-02-20 11:41:54 +01:00
* @return the date
2019-02-22 11:44:01 +01:00
* @throws Exception
* the exception
2017-02-20 11:41:54 +01:00
* /
2013-03-26 12:35:58 +01:00
@Override
public Date loadLastModificationDateById ( String itemId ) throws Exception {
2016-01-19 15:50:40 +01:00
2019-02-22 11:44:01 +01:00
workspaceLogger . trace ( " get last modification date ItemId " + itemId ) ;
2013-03-26 12:35:58 +01:00
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 ( ) ;
2019-02-22 11:44:01 +01:00
Date lastModification = null ;
2016-01-19 15:50:40 +01:00
2019-02-22 11:44:01 +01:00
if ( wsItem . getLastModificationTime ( ) ! = null ) {
2013-03-26 12:35:58 +01:00
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
2019-02-22 11:44:01 +01:00
/ *
* ( non - Javadoc )
*
* @see org . gcube . portlets . user . workspace . client . rpc . GWTWorkspaceService #
* getParentByItemId ( java . lang . String )
2015-03-06 16:12:21 +01:00
* /
2017-02-20 11:41:54 +01:00
/ * *
* Gets the parent by item id .
*
2019-02-22 11:44:01 +01:00
* @param identifier
* the identifier
2017-02-20 11:41:54 +01:00
* @return the parent by item id
2019-02-22 11:44:01 +01:00
* @throws Exception
* the exception
2017-02-20 11:41:54 +01:00
* /
2013-03-27 17:30:37 +01:00
@Override
public FileModel getParentByItemId ( String identifier ) throws Exception {
2016-01-19 15:50:40 +01:00
2019-02-22 11:44:01 +01:00
workspaceLogger . trace ( " get Parent By Item Identifier " + identifier ) ;
2013-03-27 17:30:37 +01:00
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 ) ;
2019-02-22 11:44:01 +01:00
workspaceLogger . trace ( " workspace retrieve item name: " + wsItem . getName ( ) ) ;
2013-03-27 17:30:37 +01:00
GWTWorkspaceBuilder builder = getGWTWorkspaceBuilder ( ) ;
2019-02-22 11:44:01 +01:00
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 ( ) ;
2019-02-22 11:44:01 +01:00
workspaceLogger . trace ( " parent was found " + wsFolder . getName ( ) + " retuning " ) ;
2013-03-27 17:30:37 +01:00
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
2019-02-22 11:44:01 +01:00
/ *
* ( non - Javadoc )
*
* @see org . gcube . portlets . user . workspace . client . rpc . GWTWorkspaceService #
* getAccountingReaders ( java . lang . String )
2015-03-06 16:12:21 +01:00
* /
2017-02-20 11:41:54 +01:00
/ * *
* Gets the accounting readers .
*
2019-02-22 11:44:01 +01:00
* @param identifier
* the identifier
2017-02-20 11:41:54 +01:00
* @return the accounting readers
2019-02-22 11:44:01 +01:00
* @throws Exception
* the exception
2017-02-20 11:41:54 +01:00
* /
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
2019-02-22 11:44:01 +01:00
workspaceLogger . trace ( " get accounting readers " + identifier ) ;
2013-05-23 19:03:43 +02:00
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 ( ) ) ;
2019-02-22 11:44:01 +01:00
workspaceLogger . trace ( " get accounting readers - returning size " + listReaders . size ( ) ) ;
2013-05-23 19:03:43 +02:00
return listReaders ;
} catch ( Exception e ) {
workspaceLogger . error ( " Error get accounting readers " , e ) ;
2019-02-22 11:44:01 +01:00
String error = ConstantsExplorer . SERVER_ERROR + " getting account. " + ConstantsExplorer . TRY_AGAIN ;
2013-05-23 19:03:43 +02:00
throw new Exception ( error ) ;
}
}
2016-01-19 15:50:40 +01:00
2019-02-22 11:44:01 +01:00
/ *
* ( non - Javadoc )
*
* @see org . gcube . portlets . user . workspace . client . rpc . GWTWorkspaceService #
* getAccountingHistory ( java . lang . String )
2015-03-06 16:12:21 +01:00
* /
2017-02-20 11:41:54 +01:00
/ * *
* Gets the accounting history .
*
2019-02-22 11:44:01 +01:00
* @param identifier
* the identifier
2017-02-20 11:41:54 +01:00
* @return the accounting history
2019-02-22 11:44:01 +01:00
* @throws Exception
* the exception
2017-02-20 11:41:54 +01:00
* /
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
2019-02-22 11:44:01 +01:00
workspaceLogger . trace ( " get accounting history " + identifier ) ;
2013-05-23 19:03:43 +02:00
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 ( ) ;
2019-02-22 11:44:01 +01:00
List < GxtAccountingField > listReaders = builder . buildGXTAccountingItem ( accoutings ,
GxtAccountingEntryType . ALL ) ;
workspaceLogger . trace ( " get accounting readers - returning size " + listReaders . size ( ) ) ;
2013-05-23 19:03:43 +02:00
return listReaders ;
} catch ( Exception e ) {
workspaceLogger . error ( " Error get accounting readers " , e ) ;
2019-02-22 11:44:01 +01:00
String error = ConstantsExplorer . SERVER_ERROR + " getting account. " + ConstantsExplorer . TRY_AGAIN ;
2013-05-23 19:03:43 +02:00
throw new Exception ( error ) ;
}
}
2013-06-28 18:42:10 +02:00
2019-02-22 11:44:01 +01:00
/ *
* ( non - Javadoc )
*
* @see org . gcube . portlets . user . workspace . client . rpc . GWTWorkspaceService #
* getShortUrl ( java . lang . String )
2013-06-28 18:42:10 +02:00
* /
2017-02-20 11:41:54 +01:00
/ * *
* Gets the short url .
*
2019-02-22 11:44:01 +01:00
* @param longUrl
* the long url
2017-02-20 11:41:54 +01:00
* @return the short url
2019-02-22 11:44:01 +01:00
* @throws Exception
* the exception
2017-02-20 11:41:54 +01:00
* /
2013-06-28 18:42:10 +02:00
@Override
public String getShortUrl ( String longUrl ) throws Exception {
2016-01-19 15:50:40 +01:00
2019-02-22 11:44:01 +01:00
workspaceLogger . trace ( " get short url for " + longUrl ) ;
2013-07-01 15:54:54 +02:00
UrlShortener shortener = getUrlShortener ( ) ;
2019-02-22 11:44:01 +01:00
try {
2016-01-19 15:50:40 +01:00
2019-02-22 11:44:01 +01:00
if ( shortener ! = null & & shortener . isAvailable ( ) )
2013-07-01 15:54:54 +02:00
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
2019-02-22 11:44:01 +01:00
} catch ( Exception e ) {
2013-06-28 18:42:10 +02:00
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
}
}
2018-09-20 12:07:13 +02:00
2019-02-22 11:44:01 +01:00
/ *
* ( non - Javadoc )
*
* @see org . gcube . portlets . user . workspace . client . rpc . GWTWorkspaceService #
* getLinkForSendToSwitchBoard ( java . lang . String )
2018-09-20 12:07:13 +02:00
* /
2018-11-28 16:50:18 +01:00
/ * *
* Gets the link for send to switch board .
*
2019-02-22 11:44:01 +01:00
* @param itemId
* the item id
2018-11-28 16:50:18 +01:00
* @return the link for send to switch board
2019-02-22 11:44:01 +01:00
* @throws Exception
* the exception
2018-11-28 16:50:18 +01:00
* /
2018-09-14 15:38:41 +02:00
@Override
public String getLinkForSendToSwitchBoard ( String itemId ) throws Exception {
String fallbackValue = ConstantsExplorer . CLARIN_SWITCHBOARD_ENDPOINT_FALLBACK ;
String sbEndpoint = " " ;
try {
sbEndpoint = getCLARINSwitchBoardEndpoint ( ) ;
2019-02-22 11:44:01 +01:00
} catch ( Exception e ) {
workspaceLogger . error (
" Could not find CLARINSwitchBoardEndpoint on IS, returning fallback value: " + fallbackValue ) ;
2018-09-14 15:38:41 +02:00
sbEndpoint = fallbackValue ;
}
2018-11-28 16:50:18 +01:00
String URI = getPublicLinkForFileItemId ( itemId , false ) . getCompleteURL ( ) ;
2018-09-14 15:38:41 +02:00
workspaceLogger . debug ( " Got LinkForSendToSwitchBoard: " + URI + " encoding ... " ) ;
2019-02-22 11:44:01 +01:00
String encodedURI = URLEncoder . encode ( getPublicLinkForFileItemId ( itemId , false ) . getCompleteURL ( ) , " UTF-8 " ) ;
2018-09-14 15:38:41 +02:00
workspaceLogger . debug ( " LinkForSendToSwitchBoard: " + encodedURI + " encoded ... " ) ;
return new StringBuilder ( sbEndpoint ) . append ( encodedURI ) . toString ( ) ;
}
2019-02-22 11:44:01 +01:00
/ *
* ( non - Javadoc )
*
* @see org . gcube . portlets . user . workspace . client . rpc . GWTWorkspaceService #
* isSessionExpired ( )
2013-09-02 12:43:57 +02:00
* /
2017-02-20 11:41:54 +01:00
/ * *
* Checks if is session expired .
*
* @return true , if is session expired
2019-02-22 11:44:01 +01:00
* @throws Exception
* the exception
2017-02-20 11:41:54 +01:00
* /
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
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 ;
2019-02-22 11:44:01 +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
2019-02-22 11:44:01 +01:00
/ *
* ( non - Javadoc )
*
* @see org . gcube . portlets . user . workspace . client . rpc . GWTWorkspaceService #
* getMyLogin ( )
2015-03-06 16:12:21 +01:00
* /
2017-02-20 11:41:54 +01:00
/ * *
* Gets the my login .
*
2019-02-22 11:44:01 +01:00
* @param currentPortletUrl
* the current portlet url
2017-02-20 11:41:54 +01:00
* @return the my login
* /
2014-02-12 12:49:07 +01:00
@Override
2019-02-22 11:44:01 +01: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 ( ) ;
2019-02-22 11:44:01 +01:00
} 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
2019-02-22 11:44:01 +01:00
} catch ( Exception e ) {
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 ) ;
2019-02-22 11:44:01 +01:00
workspaceLogger . info ( " Returning myLogin: " + us ) ;
2016-08-29 15:39:13 +02:00
return us ;
}
2019-02-22 11:44:01 +01:00
/ *
* ( non - Javadoc )
*
* @see org . gcube . portlets . user . workspace . client . rpc . GWTWorkspaceService #
* getMyLogin ( )
2016-08-29 15:39:13 +02:00
* /
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
2019-02-22 11:44:01 +01:00
public String getMyFirstName ( ) {
if ( ! isWithinPortal ( ) )
2016-12-22 11:34:59 +01:00
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 ) ;
2019-02-22 11:44:01 +01:00
workspaceLogger . info ( " My login first name is: " + user . getFirstName ( ) ) ;
2016-08-29 15:39:13 +02:00
firstName = user . getFirstName ( ) ;
2019-02-22 11:44:01 +01:00
} catch ( UserManagementSystemException e ) {
workspaceLogger . error ( " UserManagementSystemException for username: " + username ) ;
} catch ( UserRetrievalFault e ) {
workspaceLogger . error ( " UserRetrievalFault for username: " + username ) ;
2016-08-29 15:39:13 +02:00
}
}
return firstName ;
2014-02-12 12:49:07 +01:00
}
2016-01-19 15:50:40 +01:00
2019-02-22 11:44:01 +01:00
/ *
* ( non - Javadoc )
*
* @see org . gcube . portlets . user . workspace . client . rpc . GWTWorkspaceService #
* getItemDescriptionById ( java . lang . String )
2015-03-06 16:12:21 +01:00
* /
2017-02-20 11:41:54 +01:00
/ * *
* Gets the item description by id .
*
2019-02-22 11:44:01 +01:00
* @param identifier
* the identifier
2017-02-20 11:41:54 +01:00
* @return the item description by id
2019-02-22 11:44:01 +01:00
* @throws Exception
* the exception
2017-02-20 11:41:54 +01:00
* /
2014-11-04 18:20:06 +01:00
@Override
public String getItemDescriptionById ( String identifier ) throws Exception {
2016-01-19 15:50:40 +01:00
2019-02-22 11:44:01 +01:00
workspaceLogger . info ( " Getting ItemDescriptionById: " + identifier ) ;
if ( identifier = = null | | identifier . isEmpty ( ) ) {
2014-11-04 18:20:06 +01:00
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 ) ;
2019-02-22 11:44:01 +01:00
String error = ConstantsExplorer . SERVER_ERROR + " getting description for item id: " + identifier ;
2014-11-04 18:20:06 +01:00
throw new Exception ( error ) ;
}
}
2014-09-24 12:55:32 +02:00
2019-02-22 11:44:01 +01:00
/ *
* ( non - Javadoc )
*
* @see org . gcube . portlets . user . workspace . client . rpc . GWTWorkspaceService #
* getUserWorkspaceQuote ( )
2015-03-06 16:12:21 +01:00
* /
2017-02-20 11:41:54 +01:00
/ * *
* Gets the user workspace quote .
*
* @return the user workspace quote
2019-02-22 11:44:01 +01:00
* @throws Exception
* the exception
2017-02-20 11:41:54 +01:00
* /
2014-10-31 17:27:52 +01:00
@Override
public WorkspaceUserQuote getUserWorkspaceQuote ( ) throws Exception {
2019-02-22 11:44:01 +01:00
try {
2014-10-31 17:27:52 +01:00
workspaceLogger . info ( " Getting UserWorkspaceQuote.. " ) ;
Workspace workspace = getWorkspace ( ) ;
long size = workspace . getDiskUsage ( ) ;
2019-02-22 11:44:01 +01:00
workspaceLogger . info ( " Root size is: " + size + " formatting.. " ) ;
2014-10-31 17:27:52 +01:00
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 ) ;
2019-02-22 11:44:01 +01:00
workspaceLogger . info ( " returning user quote: " + quote ) ;
2014-10-31 17:27:52 +01:00
return quote ;
2019-02-22 11:44:01 +01:00
} catch ( Exception e ) {
workspaceLogger . error ( " Error on UserWorkspaceQuote " , e ) ;
2014-10-31 17:27:52 +01:00
return null ;
}
}
2016-01-19 15:50:40 +01:00
2019-02-22 11:44:01 +01:00
/ *
* ( non - Javadoc )
*
* @see org . gcube . portlets . user . workspace . client . rpc . GWTWorkspaceService #
* getUserWorkspaceSize ( )
2015-03-06 16:12:21 +01:00
* /
2017-02-20 11:41:54 +01:00
/ * *
* Gets the user workspace size .
*
* @return the user workspace size
2019-02-22 11:44:01 +01:00
* @throws Exception
* the exception
2017-02-20 11:41:54 +01:00
* /
2014-10-28 17:12:40 +01:00
@Override
public String getUserWorkspaceSize ( ) throws Exception {
2019-02-22 11:44:01 +01:00
try {
2014-10-31 17:27:52 +01:00
workspaceLogger . info ( " Getting workspace size.. " ) ;
Workspace workspace = getWorkspace ( ) ;
long size = workspace . getDiskUsage ( ) ;
2019-02-22 11:44:01 +01:00
// workspaceLogger.info("Root size is: "+size +" formatting..");
2014-10-31 17:27:52 +01:00
String formatSize = GWTWorkspaceBuilder . formatFileSize ( size ) ;
2019-02-22 11:44:01 +01:00
workspaceLogger . info ( " returning workspace size: " + formatSize ) ;
2014-10-31 17:27:52 +01:00
return formatSize ;
2019-02-22 11:44:01 +01:00
} catch ( Exception e ) {
workspaceLogger . error ( " Error on UserWorkspaceSize " , e ) ;
String error = ConstantsExplorer . SERVER_ERROR + " getting disk usage " ;
2014-10-31 17:27:52 +01:00
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
2019-02-22 11:44:01 +01:00
/ *
* ( non - Javadoc )
*
* @see org . gcube . portlets . user . workspace . client . rpc . GWTWorkspaceService #
* getUserWorkspaceTotalItems ( )
2015-03-06 16:12:21 +01:00
* /
2017-02-20 11:41:54 +01:00
/ * *
* Gets the user workspace total items .
*
* @return the user workspace total items
2019-02-22 11:44:01 +01:00
* @throws Exception
* the exception
2017-02-20 11:41:54 +01:00
* /
2014-10-31 17:27:52 +01:00
@Override
public long getUserWorkspaceTotalItems ( ) throws Exception {
2019-02-22 11:44:01 +01:00
try {
2014-10-31 17:27:52 +01:00
workspaceLogger . info ( " Getting total items.. " ) ;
Workspace workspace = getWorkspace ( ) ;
long size = workspace . getTotalItems ( ) ;
2019-02-22 11:44:01 +01:00
workspaceLogger . info ( " returning total items value: " + size ) ;
2014-10-31 17:27:52 +01:00
return size ;
2019-02-22 11:44:01 +01:00
} catch ( Exception e ) {
workspaceLogger . error ( " Error on UserWorkspaceSize " , e ) ;
String error = ConstantsExplorer . SERVER_ERROR + " getting total items " ;
2014-10-31 17:27:52 +01:00
throw new Exception ( error ) ;
}
2014-10-28 17:12:40 +01:00
}
2014-11-04 18:20:06 +01:00
2019-02-22 11:44:01 +01:00
/ *
* ( non - Javadoc )
*
* @see org . gcube . portlets . user . workspace . client . rpc . GWTWorkspaceService #
* loadGcubeItemProperties ( java . lang . String )
2015-06-12 12:24:01 +02:00
* /
2017-02-20 11:41:54 +01:00
/ * *
* Load gcube item properties .
*
2019-02-22 11:44:01 +01:00
* @param itemId
* the item id
2017-02-20 11:41:54 +01:00
* @return the map
2019-02-22 11:44:01 +01:00
* @throws Exception
* the exception
2017-02-20 11:41:54 +01:00
* /
2015-06-12 12:24:01 +02:00
@Override
public Map < String , String > loadGcubeItemProperties ( String itemId ) throws Exception {
2019-02-22 11:44:01 +01:00
workspaceLogger . info ( " Getting GcubeItemProperties for itemId: " + itemId ) ;
if ( itemId = = null | | itemId . isEmpty ( ) ) {
2015-06-12 12:24:01 +02:00
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 ) ;
2019-02-22 11:44:01 +01:00
if ( mapProperties ! = null )
workspaceLogger . info ( " Returning " + mapProperties . size ( ) + " properties " ) ;
2015-06-12 12:24:01 +02:00
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 ) ;
2019-02-22 11:44:01 +01:00
String error = ConstantsExplorer . SERVER_ERROR + " getting gcube item properties for item id: " + itemId ;
2015-06-12 12:24:01 +02:00
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 .
*
2019-02-22 11:44:01 +01:00
* @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
2015-06-12 12:24:01 +02:00
* /
@Override
public String getHTMLGcubeItemProperties ( String itemId ) throws Exception {
2019-02-22 11:44:01 +01:00
workspaceLogger . info ( " Getting FormattedGcubeItemProperties for itemId: " + itemId ) ;
if ( itemId = = null | | itemId . isEmpty ( ) ) {
2015-06-12 12:24:01 +02:00
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 ) ;
2019-02-22 11:44:01 +01:00
String error = ConstantsExplorer . SERVER_ERROR + " getting gcube item properties for item id: " + itemId ;
2015-06-12 12:24:01 +02:00
throw new Exception ( error ) ;
}
}
/ * *
* Sets the gcube item properties .
*
2019-02-22 11:44:01 +01:00
* @param itemId
* the item id
* @param properties
* the properties
* @throws Exception
* the exception
2015-06-12 12:24:01 +02:00
* /
@Override
public void setGcubeItemProperties ( String itemId , Map < String , String > properties ) throws Exception {
2019-02-22 11:44:01 +01:00
workspaceLogger . info ( " Set GcubeItemProperties for itemId: " + itemId ) ;
if ( itemId = = null | | itemId . isEmpty ( ) ) {
2015-06-12 12:24:01 +02:00
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 ) ;
2019-02-22 11:44:01 +01:00
if ( item instanceof GCubeItem ) {
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 ( ) ) {
2019-02-22 11:44:01 +01:00
// ADD PROPERTIES
workspaceLogger . trace ( " Adding property: [ " + key + " , " + properties . get ( key ) + " ] " ) ;
2015-06-12 15:07:02 +02:00
gItem . getProperties ( ) . addProperty ( key , properties . get ( key ) ) ;
}
2015-06-12 17:18:08 +02:00
gItem . getProperties ( ) . update ( ) ;
2019-02-22 11:44:01 +01:00
} else
2015-06-12 12:24:01 +02:00
throw new NoGcubeItemTypeException ( " The item is not a Gcube Item " ) ;
2016-01-19 15:50:40 +01:00
2019-02-22 11:44:01 +01:00
} catch ( NoGcubeItemTypeException e ) {
2015-06-12 12:24:01 +02:00
workspaceLogger . error ( " Error in server FormattedGcubeItemProperties: " , e ) ;
throw new Exception ( e . getMessage ( ) ) ;
} catch ( Exception e ) {
workspaceLogger . error ( " Error in server FormattedGcubeItemProperties: " , e ) ;
2019-02-22 11:44:01 +01:00
String error = ConstantsExplorer . SERVER_ERROR + " setting gcube item properties for item id: " + itemId ;
2015-06-12 12:24:01 +02:00
throw new Exception ( error ) ;
}
}
2016-08-29 10:38:35 +02:00
2019-02-22 11:44:01 +01:00
/ *
* ( non - Javadoc )
*
* @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 .
*
2019-02-22 11:44:01 +01:00
* @param itemId
* the item id
* @param setPublic
* the set public
2017-02-20 11:41:54 +01:00
* @return the public link
2019-02-22 11:44:01 +01:00
* @throws SessionExpiredException
* the session expired exception
* @throws Exception
* the exception
2017-02-20 11:41:54 +01:00
* /
2016-09-14 12:17:14 +02:00
@Override
2019-02-22 11:44:01 +01:00
public PublicLink markFolderAsPublicForFolderItemId ( String itemId , boolean setPublic )
throws SessionExpiredException , Exception {
2016-09-14 12:17:14 +02:00
2019-02-22 11:44:01 +01:00
if ( isSessionExpired ( ) )
2016-09-14 12:17:14 +02:00
throw new SessionExpiredException ( ) ;
try {
Workspace workspace = getWorkspace ( ) ;
WorkspaceItem item = workspace . getItem ( itemId ) ;
2019-02-22 11:44:01 +01:00
if ( item instanceof WorkspaceFolder ) {
2016-09-14 12:17:14 +02:00
WorkspaceFolder folder = ( WorkspaceFolder ) item ;
2017-04-10 16:43:21 +02:00
2019-02-22 11:44:01 +01:00
if ( setPublic ) {
if ( ! folder . isPublic ( ) )
2017-04-10 16:43:21 +02:00
folder . setPublic ( true ) ;
2016-09-15 16:42:20 +02:00
String folderId = item . getId ( ) ;
2019-02-22 11:44:01 +01:00
workspaceLogger . info ( " HL returning folder link id: " + folderId ) ;
ApplicationProfileReader apReader = new ApplicationProfileReader ( " Workspace-Explorer-App " ,
" org.gcube.portlets.user.workspaceexplorerapp.server.WorkspaceExplorerAppServiceImpl " ) ;
2016-09-15 16:42:20 +02:00
ApplicationProfile ap = apReader . readProfileFromInfrastrucure ( ) ;
2016-09-19 12:17:33 +02:00
String encriptedFId = StringEncrypter . getEncrypter ( ) . encrypt ( folderId ) ;
2019-02-22 11:44:01 +01:00
workspaceLogger . info ( " Encrypted folder Id: " + encriptedFId ) ;
2016-09-19 12:17:33 +02:00
String encodedFId = StringUtil . base64EncodeStringURLSafe ( encriptedFId ) ;
2019-02-22 11:44:01 +01:00
workspaceLogger . info ( " Encoded in Base 64: " + encodedFId ) ;
workspaceLogger . info ( " Application profile returning url: " + ap . getUrl ( ) ) ;
String folderLink = ap . getUrl ( ) + " ?folderId= " + encodedFId ;
2016-09-15 16:42:20 +02:00
String shortURL = null ;
2019-02-22 11:44:01 +01:00
try {
2016-09-15 16:42:20 +02:00
shortURL = getShortUrl ( folderLink ) ;
2019-02-22 11:44:01 +01:00
shortURL = shortURL ! = null ? shortURL : " not available " ;
} catch ( Exception e ) {
2016-09-15 16:42:20 +02:00
workspaceLogger . warn ( " Short url error, skipping " ) ;
shortURL = " not available " ;
}
return new PublicLink ( folderLink , shortURL ) ;
2019-02-22 11:44:01 +01:00
} else {
2016-09-15 16:42:20 +02:00
folder . setPublic ( false ) ;
return null ;
2016-09-14 14:30:33 +02:00
}
2019-02-22 11:44:01 +01:00
} else
2016-09-14 12:17:14 +02:00
throw new NoGcubeItemTypeException ( " The item is not a Gcube Item " ) ;
2019-02-22 11:44:01 +01:00
} 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 ) ;
2019-02-22 11:44:01 +01:00
String error = ConstantsExplorer . SERVER_ERROR + " reading Folder Link for id: " + itemId ;
2016-09-14 12:17:14 +02:00
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 .
*
2019-02-22 11:44:01 +01:00
* @param protocol
* the protocol
2017-02-20 11:41:54 +01:00
* @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 ;
2019-02-22 11:44:01 +01:00
String serverName = req . getServerName ( ) ; // hostname.com
int serverPort = req . getServerPort ( ) ; // 80
String contextPath = req . getServletContext ( ) . getContextPath ( ) ; // /mywebapp
2016-09-21 18:10:14 +02:00
// Reconstruct original requesting URL
2019-02-22 11:44:01 +01:00
StringBuffer url = new StringBuffer ( ) ;
2016-09-21 18:10:14 +02:00
url . append ( scheme ) . append ( " // " ) . append ( serverName ) ;
if ( serverPort ! = 80 & & serverPort ! = 443 ) {
url . append ( " : " ) . append ( serverPort ) ;
}
2019-02-22 11:44:01 +01:00
workspaceLogger . debug ( " server: " + url ) ;
workspaceLogger . debug ( " omitted contextPath: " + contextPath ) ;
2016-09-21 18:10:14 +02:00
url . append ( contextPath ) ;
workspaceLogger . debug ( " getServletContextPath= " + url . toString ( ) ) ;
return url . toString ( ) ;
}
2016-11-29 15:16:47 +01:00
2019-02-22 11:44:01 +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 )
2017-02-22 11:36:28 +01:00
* /
2017-09-29 17:58:12 +02:00
/ * *
* Perform operation on versioned file .
*
2019-02-22 11:44:01 +01:00
* @param fileId
* the file id
* @param olderVersionIDs
* the older version i ds
* @param operation
* the operation
2017-09-29 17:58:12 +02:00
* @return the list
2019-02-22 11:44:01 +01:00
* @throws Exception
* the exception
2017-09-29 17:58:12 +02:00
* /
2017-02-22 11:36:28 +01:00
@Override
2019-02-22 11:44:01 +01:00
public List < FileVersionModel > performOperationOnVersionedFile ( String fileId , List < String > olderVersionIDs ,
2018-09-14 15:38:41 +02:00
WorkspaceVersioningOperation operation ) throws Exception {
2017-02-22 11:36:28 +01:00
2019-02-22 11:44:01 +01:00
if ( fileId = = null | | olderVersionIDs = = null | | olderVersionIDs . size ( ) = = 0 )
2017-02-22 11:36:28 +01:00
throw new Exception ( " File Versioned is null " ) ;
2019-02-22 11:44:01 +01:00
workspaceLogger
. info ( " File Id: " + fileId + " , Ids Version: " + olderVersionIDs + " perform operation: " + operation ) ;
2017-02-22 11:36:28 +01:00
try {
Workspace workspace = getWorkspace ( ) ;
WorkspaceItem fileHL = workspace . getItem ( fileId ) ;
2019-02-22 11:44:01 +01:00
if ( fileHL instanceof ExternalFile ) {
2017-02-22 11:36:28 +01:00
ExternalFile extFile = ( ExternalFile ) fileHL ;
switch ( operation ) {
2018-09-14 15:38:41 +02:00
case DOWNLOAD : {
2019-02-22 11:44:01 +01:00
// IMPLEMENTED CLIENT-SIDE
2018-09-14 15:38:41 +02:00
break ;
}
2017-02-22 11:36:28 +01:00
2019-02-22 11:44:01 +01:00
case DELETE_ALL_OLDER_VERSIONS : {
// MUST BE OPTIMIZED HL-SIDE
2018-09-14 15:38:41 +02:00
for ( String olderVersionId : olderVersionIDs ) {
extFile . removeVersion ( olderVersionId ) ;
2019-02-22 11:44:01 +01:00
workspaceLogger . info ( " Version " + olderVersionId + " of file id: " + fileId + " removed " ) ;
2017-02-22 11:36:28 +01:00
}
2018-09-14 15:38:41 +02:00
return getVersionHistory ( fileId ) ;
}
2017-02-22 11:36:28 +01:00
2019-02-22 11:44:01 +01:00
// case RESTORE: {
// for (String olderVersionId : olderVersionIDs) {
// extFile.restoreVersion(olderVersionId);
// workspaceLogger.info("Version "+olderVersionId +" of file id:
// "+fileId+" restored");
// }
// return getVersionHistory(fileId);
//
// }
2017-02-22 11:36:28 +01:00
2018-09-14 15:38:41 +02:00
case REFRESH : {
return getVersionHistory ( fileId ) ;
}
case DELETE_PERMANENTLY : {
for ( String olderVersionId : olderVersionIDs ) {
extFile . removeVersion ( olderVersionId ) ;
2019-02-22 11:44:01 +01:00
workspaceLogger . info ( " Version " + olderVersionId + " of file id: " + fileId + " removed " ) ;
2017-02-22 11:36:28 +01:00
}
2018-09-14 15:38:41 +02:00
return getVersionHistory ( fileId ) ;
}
2017-02-22 11:36:28 +01:00
2019-02-22 11:44:01 +01:00
default : {
2017-02-22 11:36:28 +01:00
2018-09-14 15:38:41 +02:00
break ;
}
2017-02-22 11:36:28 +01:00
}
return getVersionHistory ( fileId ) ;
2019-02-22 11:44:01 +01:00
} else
2017-02-22 11:36:28 +01:00
throw new FileNotVersionedException ( " Selected file is not versioned " ) ;
2019-02-22 11:44:01 +01:00
} catch ( Exception e ) {
2017-02-22 11:36:28 +01:00
if ( e instanceof FileNotVersionedException )
throw new Exception ( e . getMessage ( ) ) ;
2017-03-02 18:13:52 +01:00
2019-02-22 11:44:01 +01:00
if ( e instanceof InsufficientPrivilegesException )
2017-03-02 18:13:52 +01:00
throw new Exception ( e . getMessage ( ) ) ;
2019-02-22 11:44:01 +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 ;
2017-02-22 11:36:28 +01:00
throw new Exception ( error ) ;
}
}
2017-05-24 12:01:16 +02:00
2019-02-22 11:44:01 +01:00
/ *
* ( non - Javadoc )
*
* @see org . gcube . portlets . user . workspace . client . rpc . GWTWorkspaceService #
* getImagesForFolder ( java . lang . String , java . lang . String )
2017-05-24 12:01:16 +02:00
* /
2017-09-29 17:58:12 +02:00
/ * *
* Gets the images for folder .
*
2019-02-22 11:44:01 +01:00
* @param folderId
* the folder id
* @param currentImageId
* the current image id
2017-09-29 17:58:12 +02:00
* @return the images for folder
2019-02-22 11:44:01 +01:00
* @throws Exception
* the exception
2017-09-29 17:58:12 +02:00
* /
2017-05-24 12:01:16 +02:00
@Override
public List < GWTWorkspaceItem > getImagesForFolder ( String folderId , String currentImageId ) throws Exception {
2019-02-22 11:44:01 +01:00
if ( folderId = = null )
2017-05-24 12:01:16 +02:00
return null ;
try {
Workspace workspace = getWorkspace ( ) ;
2019-02-22 11:44:01 +01:00
workspaceLogger . debug ( " get images for folder id: " + folderId ) ;
WorkspaceItem item = workspace . getItem ( folderId ) ; // get item from
// workspace
2017-05-24 12:01:16 +02:00
List < GWTWorkspaceItem > images = new ArrayList < GWTWorkspaceItem > ( ) ;
2019-02-22 11:44:01 +01:00
if ( item . isFolder ( ) ) {
2017-05-24 12:01:16 +02:00
WorkspaceFolder folder = ( WorkspaceFolder ) item ;
GWTWorkspaceBuilder builder = getGWTWorkspaceBuilder ( ) ;
PortalContextInfo context = WsUtil . getPortalContext ( this . getThreadLocalRequest ( ) ) ;
GCubeUser user = PortalContext . getConfiguration ( ) . getCurrentUser ( this . getThreadLocalRequest ( ) ) ;
List < WorkspaceItem > children = folder . getChildren ( ) ;
for ( WorkspaceItem workspaceItem : children ) {
boolean foundCurrentImage = false ;
2019-02-22 11:44:01 +01:00
if ( workspaceItem . getType ( ) . compareTo ( WorkspaceItemType . FOLDER_ITEM ) = = 0 ) {
2017-05-24 12:01:16 +02:00
FolderItem file = ( FolderItem ) workspaceItem ;
GWTWorkspaceItem image = null ;
switch ( file . getFolderItemType ( ) ) {
case EXTERNAL_IMAGE :
2019-02-22 11:44:01 +01:00
image = builder . buildGWTWorkspaceImage ( workspaceItem , false , false ,
context . getCurrGroupId ( ) + " " , user . getUserId ( ) + " " ) ;
2017-05-24 12:01:16 +02:00
image . setId ( workspaceItem . getId ( ) ) ;
break ;
case IMAGE_DOCUMENT :
2019-02-22 11:44:01 +01:00
image = builder . buildGWTWorkspaceImage ( workspaceItem , true , false ,
context . getCurrGroupId ( ) + " " , user . getUserId ( ) + " " ) ;
2017-05-24 12:01:16 +02:00
image . setId ( workspaceItem . getId ( ) ) ;
break ;
default :
break ;
}
2019-02-22 11:44:01 +01:00
if ( image ! = null ) {
if ( ! foundCurrentImage & & image . getId ( ) . compareTo ( currentImageId ) = = 0 ) {
workspaceLogger . debug (
" It is current thumbnail adding to list as first element: " + image . getName ( ) ) ;
2017-05-24 12:01:16 +02:00
images . add ( 0 , image ) ;
foundCurrentImage = true ;
2019-02-22 11:44:01 +01:00
} else {
workspaceLogger . debug ( " Adding thumbnail name to list: " + image . getName ( ) ) ;
2017-05-24 12:01:16 +02:00
images . add ( image ) ;
}
}
}
}
}
2019-02-22 11:44:01 +01:00
workspaceLogger . info ( " Returning " + images . size ( ) + " images for folder id: " + folderId ) ;
2017-05-24 12:01:16 +02:00
return images ;
} catch ( Exception e ) {
2019-02-22 11:44:01 +01:00
workspaceLogger . error ( " Error in server get images by folder id: " + folderId , e ) ;
2017-05-24 12:01:16 +02:00
throw new Exception ( e . getMessage ( ) ) ;
}
}
2017-09-27 18:38:30 +02:00
2019-02-22 11:44:01 +01:00
/ *
* ( non - Javadoc )
*
* @see org . gcube . portlets . user . workspace . client . rpc . GWTWorkspaceService #
* getListOfVREsForLoggedUser ( )
2017-09-27 18:38:30 +02:00
* /
2017-09-29 17:58:12 +02:00
/ * *
* Gets the list of vr es for logged user .
*
* @return the list of vr es for logged user
2019-02-22 11:44:01 +01:00
* @throws Exception
* the exception
2017-09-29 17:58:12 +02:00
* /
2017-09-27 18:38:30 +02:00
@Override
2019-02-22 11:44:01 +01:00
public List < GcubeVRE > getListOfVREsForLoggedUser ( ) throws Exception {
2017-09-27 18:38:30 +02:00
workspaceLogger . debug ( " getListOfVREsForLoggedUser...: " ) ;
2019-02-22 11:44:01 +01:00
// PortalContextInfo context =
// WsUtil.getPortalContext(this.getThreadLocalRequest());
2017-09-27 18:38:30 +02:00
GCubeUser user = PortalContext . getConfiguration ( ) . getCurrentUser ( this . getThreadLocalRequest ( ) ) ;
long userId = user . getUserId ( ) ;
// Instanciate the manager
GroupManager groupManager = new LiferayGroupManager ( ) ;
List < GcubeVRE > listOfVres = new ArrayList < GcubeVRE > ( ) ;
2017-09-28 12:19:04 +02:00
2019-02-22 11:44:01 +01:00
if ( isTestMode ( ) ) {
2017-09-28 12:19:04 +02:00
listOfVres . add ( new GcubeVRE ( " devVRE " , " /gcube/devsec/devVRE " ) ) ;
listOfVres . add ( new GcubeVRE ( " NextNext " , " /gcube/devNext/NextNext " ) ) ;
return listOfVres ;
}
2017-09-27 18:38:30 +02:00
try {
List < GCubeGroup > listOfGroups = groupManager . listGroupsByUser ( userId ) ;
for ( GCubeGroup gCubeGroup : listOfGroups ) {
2019-02-22 11:44:01 +01:00
if ( groupManager . isVRE ( gCubeGroup . getGroupId ( ) ) ) {
GcubeVRE gcubeVRE = new GcubeVRE ( gCubeGroup . getGroupName ( ) ,
groupManager . getInfrastructureScope ( gCubeGroup . getGroupId ( ) ) ) ;
2017-09-27 18:38:30 +02:00
listOfVres . add ( gcubeVRE ) ;
}
}
2019-02-22 11:44:01 +01:00
} catch ( UserRetrievalFault | UserManagementSystemException | GroupRetrievalFault e ) {
2017-09-27 18:38:30 +02:00
workspaceLogger . error ( " Error occurred server-side getting VRE folders: " , e ) ;
throw new Exception ( " Sorry, an error occurred server-side getting VRE folders, try again later " ) ;
}
2019-02-22 11:44:01 +01:00
workspaceLogger . info ( " Returning list of VREs: " + listOfVres ) ;
2017-09-27 18:38:30 +02:00
return listOfVres ;
}
2018-03-28 12:42:50 +02:00
/ * *
* Check item locked .
*
2019-02-22 11:44:01 +01:00
* @param itemId
* the item id
2018-03-28 12:42:50 +02:00
* @return true , if successful
2019-02-22 11:44:01 +01:00
* @throws WorkspaceFolderLocked
* the workspace folder locked
* @throws Exception
* the exception
2018-03-28 12:42:50 +02:00
* /
2019-02-22 11:44:01 +01:00
private boolean checkItemLocked ( String itemId ) throws WorkspaceFolderLocked , Exception {
2018-03-28 12:42:50 +02:00
2019-02-22 11:44:01 +01:00
if ( itemId = = null | | itemId . isEmpty ( ) )
2018-03-28 12:42:50 +02:00
throw new Exception ( IDENTIFIER_IS_NULL ) ;
Workspace ws ;
WorkspaceItem workItem = null ;
2019-02-22 11:44:01 +01:00
try {
2018-03-28 12:42:50 +02:00
ws = getWorkspace ( ) ;
workItem = ws . getItem ( itemId ) ;
2019-02-22 11:44:01 +01:00
// IF THE ITEM IS A FOLDER, CHECKING IT
if ( workItem . isFolder ( ) )
2018-03-28 12:42:50 +02:00
WorkspaceThreddsSynchronize . getInstance ( ) . checkItemSynched ( workItem . getId ( ) ) ;
2019-02-22 11:44:01 +01:00
else {
// IF THE ITEM IS A FILE, CHECKING ITS PARENT
2018-03-28 12:42:50 +02:00
WorkspaceFolder parent = workItem . getParent ( ) ;
2019-02-22 11:44:01 +01:00
if ( parent ! = null ) {
2018-03-28 12:42:50 +02:00
WorkspaceThreddsSynchronize . getInstance ( ) . checkItemSynched ( parent . getId ( ) ) ;
}
}
2019-02-22 11:44:01 +01:00
// in this case the folder is synched but not locked
2018-03-28 12:42:50 +02:00
return false ;
2019-02-22 11:44:01 +01:00
} catch ( ItemNotSynched e1 ) {
2018-03-28 12:42:50 +02:00
2019-02-22 11:44:01 +01:00
// in this case the folder is not synched;
2018-03-28 12:42:50 +02:00
return false ;
2019-02-22 11:44:01 +01:00
} catch ( WorkspaceFolderLocked e2 ) {
// in this case the folder synching is on-going and the folder is
// locked;
2018-03-28 12:42:50 +02:00
String msg = " The folder " ;
2019-02-22 11:44:01 +01:00
msg + = workItem ! = null ? " : " + workItem . getName ( ) : " " ;
2018-03-28 12:42:50 +02:00
msg + = " is locked by a sync. You can not change its content " ;
workspaceLogger . warn ( msg , e2 ) ;
throw new WorkspaceFolderLocked ( itemId , msg ) ;
2019-02-22 11:44:01 +01:00
} catch ( InternalErrorException | ItemNotFoundException | HomeNotFoundException
| WorkspaceFolderNotFoundException e ) {
2018-03-28 12:42:50 +02:00
workspaceLogger . warn ( e ) ;
throw new Exception ( " Sorry an error occurred during checking is folder locked, Refresh and try again " ) ;
2018-04-19 11:11:23 +02:00
2019-02-22 11:44:01 +01:00
} catch ( Exception e ) {
workspaceLogger
. warn ( " Was there an Exception HL side? Ignoring it.. returning false (that means item not locked) " ) ;
2018-04-19 11:11:23 +02:00
return false ;
2018-03-28 12:42:50 +02:00
}
}
2018-03-28 18:35:12 +02:00
/ * *
* Checks if is item under sync .
*
2019-02-22 11:44:01 +01:00
* @param itemId
* the item id
2018-03-28 18:35:12 +02:00
* @return true , if is item under sync
2019-02-22 11:44:01 +01:00
* @throws Exception
* the exception
2018-03-28 18:35:12 +02:00
* /
@Override
2019-02-22 11:44:01 +01:00
public Boolean isItemUnderSync ( String itemId ) throws Exception {
2018-03-28 18:35:12 +02:00
try {
GCubeUser user = PortalContext . getConfiguration ( ) . getCurrentUser ( this . getThreadLocalRequest ( ) ) ;
2019-02-22 11:44:01 +01:00
try {
Sync_Status status = WorkspaceThreddsSynchronize . getInstance ( ) . getSynchedStatusFromItemProperty ( itemId ,
user . getUsername ( ) ) ;
} catch ( Exception e ) {
2018-03-28 18:35:12 +02:00
return false ;
}
2019-02-22 11:44:01 +01:00
// HERE THE ITEM IS SYNCHED SO CHECK IF IT IS LOCKED
2018-03-28 18:35:12 +02:00
checkItemLocked ( itemId ) ;
return false ;
2019-02-22 11:44:01 +01:00
} catch ( WorkspaceFolderLocked e1 ) {
2018-03-28 18:35:12 +02:00
return true ;
2019-02-22 11:44:01 +01:00
} catch ( Exception e ) {
throw new Exception ( " Error on checking item " + itemId + " is under sync " ) ;
2018-03-28 18:35:12 +02:00
}
}
2018-09-20 12:07:13 +02:00
/ * *
* Gets the CLARIN switch board endpoint .
*
* @return the CLARIN switch board endpoint
* /
2018-09-14 15:38:41 +02:00
private String getCLARINSwitchBoardEndpoint ( ) {
2019-02-22 11:44:01 +01:00
// save the context for this resource
2018-09-14 15:38:41 +02:00
String currContext = ScopeProvider . instance . get ( ) ;
2019-02-22 11:44:01 +01:00
// set the context for this resource
ScopeProvider . instance . set ( " / " + PortalContext . getConfiguration ( ) . getInfrastructureName ( ) ) ;
2018-09-14 15:38:41 +02:00
2019-02-22 11:44:01 +01:00
// construct the xquery
2018-09-14 15:38:41 +02:00
SimpleQuery query = queryFor ( ServiceEndpoint . class ) ;
2019-02-22 11:44:01 +01:00
query . addCondition (
" $resource/Profile/Name/text() eq ' " + ConstantsExplorer . CLARIN_SWITCHBOARD_ENDPOINT_NAME + " ' " ) ;
query . addCondition ( " $resource/Profile/Category/text() eq ' "
+ ConstantsExplorer . CLARIN_SWITCHBOARD_ENDPOINT_CATEGORY + " ' " ) ;
2018-09-14 15:38:41 +02:00
DiscoveryClient < ServiceEndpoint > client = clientFor ( ServiceEndpoint . class ) ;
List < ServiceEndpoint > conf = client . submit ( query ) ;
if ( conf = = null | | conf . isEmpty ( ) )
return null ;
ServiceEndpoint res = conf . get ( 0 ) ;
2019-02-22 11:44:01 +01:00
// reset the context
2018-09-14 15:42:36 +02:00
ScopeProvider . instance . set ( currContext ) ;
2018-09-14 15:38:41 +02:00
return res . profile ( ) . runtime ( ) . hostedOn ( ) ;
}
2018-11-28 16:50:18 +01:00
/ * *
* Gets the workspace from storage hub .
*
* @return the workspace from storage hub
2019-02-22 11:44:01 +01:00
* @throws Exception
* the exception
2018-11-28 16:50:18 +01:00
* /
2019-02-22 11:44:01 +01:00
protected org . gcube . common . storagehubwrapper . server . tohl . Workspace getWorkspaceFromStorageHub ( ) throws Exception {
2018-11-28 16:50:18 +01:00
GCubeUser user = PortalContext . getConfiguration ( ) . getCurrentUser ( this . getThreadLocalRequest ( ) ) ;
StorageHubWrapper storageHubWrapper = WsUtil . getStorageHubWrapper ( this . getThreadLocalRequest ( ) , null , user ) ;
return storageHubWrapper . getWorkspace ( ) ;
}
/ * *
* Gets the storage hub to workpace converter .
*
* @return the storage hub to workpace converter
2019-02-22 11:44:01 +01:00
* @throws Exception
* the exception
2018-11-28 16:50:18 +01:00
* /
2019-02-22 11:44:01 +01:00
protected StorageHubToWorkpaceConverter getStorageHubToWorkpaceConverter ( ) throws Exception {
2018-11-28 16:50:18 +01:00
GCubeUser user = PortalContext . getConfiguration ( ) . getCurrentUser ( this . getThreadLocalRequest ( ) ) ;
2019-02-22 11:44:01 +01:00
StorageHubToWorkpaceConverter converter = WsUtil . getStorageHubToWorkpaceConverter ( this . getThreadLocalRequest ( ) ,
null , user ) ;
// SETTING ROOT ID JUST ONCE
if ( converter . getWorkspaceRootId ( ) = = null ) {
2018-11-28 16:50:18 +01:00
org . gcube . common . storagehubwrapper . server . tohl . Workspace ws = getWorkspaceFromStorageHub ( ) ;
converter . setWorkspaceRootId ( ws . getRoot ( ) . getId ( ) ) ;
}
return converter ;
}
/ * *
* Gets the notification producer to storage hub .
*
* @return the notification producer to storage hub
* /
2019-02-22 11:44:01 +01:00
protected NotificationsProducerToStorageHub getNotificationProducerToStorageHub ( ) {
2018-11-28 16:50:18 +01:00
return WsUtil . getNotificationProducerToStorageHub ( this . getThreadLocalRequest ( ) ) ;
}
2019-02-22 11:44:01 +01:00
/ *
* ( non - Javadoc )
*
* @see org . gcube . portlets . user . workspace . client . rpc . GWTWorkspaceService #
* getRootForTree ( )
2018-11-28 16:50:18 +01:00
* /
/ * *
* Gets the root for tree .
*
* @return the root for tree
2019-02-22 11:44:01 +01:00
* @throws Exception
* the exception
2018-11-28 16:50:18 +01:00
* /
@Override
public FolderModel getRootForTree ( ) throws Exception {
workspaceLogger . trace ( " getRoot " ) ;
try {
org . gcube . common . storagehubwrapper . server . tohl . Workspace workspace = getWorkspaceFromStorageHub ( ) ;
org . gcube . common . storagehubwrapper . shared . tohl . WorkspaceFolder root = workspace . getRoot ( ) ;
if ( root = = null ) {
workspaceLogger . error ( " The root is null " ) ;
throw new Exception ( " The root is null " ) ;
}
workspaceLogger . trace ( " Root converted, returning... " ) ;
StorageHubToWorkpaceConverter converter = getStorageHubToWorkpaceConverter ( ) ;
return converter . toRootFolder ( root ) ;
} catch ( Exception e ) {
workspaceLogger . error ( " Error in server during root retrieving " , e ) ;
2019-02-22 11:44:01 +01:00
// workspaceLogger.trace("Error in server During root retrieving " +
// e);
2018-11-28 16:50:18 +01:00
2019-02-22 11:44:01 +01:00
// GWT can't serialize all exceptions
throw new Exception ( " Error during workspace loading, please contact the support. Exception: " + e ) ;
2018-11-28 16:50:18 +01:00
}
}
/ * *
* Delete item .
*
2019-02-22 11:44:01 +01:00
* @param itemId
* the item id
2018-11-28 16:50:18 +01:00
* @return the boolean
2019-02-22 11:44:01 +01:00
* @throws Exception
* the exception
2018-11-28 16:50:18 +01:00
* /
@Override
public Boolean deleteItem ( String itemId ) throws Exception {
2019-04-30 12:06:04 +02:00
boolean sourceItemIsShared = false ;
2018-11-28 16:50:18 +01:00
try {
2019-02-22 11:44:01 +01:00
if ( itemId = = null )
2018-11-28 16:50:18 +01:00
throw new Exception ( IDENTIFIER_IS_NULL ) ;
checkItemLocked ( itemId ) ;
org . gcube . common . storagehubwrapper . server . tohl . Workspace workspaceSH = getWorkspaceFromStorageHub ( ) ;
org . gcube . common . storagehubwrapper . shared . tohl . WorkspaceItem theItem = workspaceSH . getItem ( itemId ) ;
2019-04-30 12:06:04 +02:00
sourceItemIsShared = theItem . isShared ( ) ;
2018-11-28 16:50:18 +01:00
String itemName = theItem . getName ( ) ;
String sourceFolderSharedId = null ;
2019-02-22 11:44:01 +01:00
if ( sourceItemIsShared ) {
org . gcube . common . storagehubwrapper . shared . tohl . WorkspaceItem rootSharedFolder = workspaceSH
. getRootSharedFolder ( itemId ) ;
2018-11-28 16:50:18 +01:00
sourceFolderSharedId = rootSharedFolder . getId ( ) ;
}
2019-02-22 11:44:01 +01:00
// HERE REMOVING THE ITEM
workspaceLogger . info ( " Calling storageHub to delete item with id: " + itemId ) ;
2018-11-28 16:50:18 +01:00
workspaceSH . deleteItem ( itemId ) ;
2019-02-22 11:44:01 +01:00
if ( sourceFolderSharedId ! = null )
NotificationsUtil . checkSendNotifyRemoveItemToShare ( this . getThreadLocalRequest ( ) , sourceItemIsShared ,
itemName , itemId , sourceFolderSharedId ) ;
2018-11-28 16:50:18 +01:00
return Boolean . TRUE ;
2019-02-22 11:44:01 +01:00
} catch ( WorkspaceFolderLocked e1 ) {
2018-11-28 16:50:18 +01:00
throw new Exception ( e1 . getMessage ( ) ) ;
} catch ( InsufficientPrivilegesException e ) {
workspaceLogger . error ( " Error in server Item remove " , e ) ;
String error = " Insufficient Privileges to remove the item " ;
throw new Exception ( error ) ;
2019-02-22 11:44:01 +01:00
} catch ( ItemNotFoundException e ) {
String error = " An error occurred on deleting item. " + ConstantsExplorer . ERROR_ITEM_DOES_NOT_EXIST ;
2018-11-28 16:50:18 +01:00
workspaceLogger . error ( error , e ) ;
throw new Exception ( error ) ;
2019-05-03 15:31:47 +02:00
//TO STORAGEHUB EXCEPTION
} catch ( UserNotAuthorizedException e ) {
String error = " Insufficient Privileges to delete the item " ;
workspaceLogger . error ( error , e ) ;
throw new Exception ( error ) ;
2018-11-28 16:50:18 +01:00
} catch ( Exception e ) {
2019-04-30 12:06:04 +02:00
workspaceLogger . error ( " Remoing item error: " , e ) ;
StringBuilder error = new StringBuilder ( ) ;
if ( sourceItemIsShared ) {
error . append ( " Ops! This operation is not allowed, we're working hard to make this possible soon. " ) ;
throw new SHUBOperationNotAllowedException ( error . toString ( ) ) ;
} else {
error . append ( " Ops an error occurred deleting the item! Either you have not the permission to delete it or a server error occurred. Please, refresh and try again " ) ;
throw new Exception ( error . toString ( ) ) ;
}
2018-11-28 16:50:18 +01:00
}
}
2019-02-22 11:44:01 +01:00
/ *
* ( non - Javadoc )
*
* @see org . gcube . portlets . user . workspace . client . rpc . GWTWorkspaceService #
* getFolderChildren ( org . gcube . portlets . user . workspace . client . model .
* FolderModel )
2018-11-28 16:50:18 +01:00
* /
/ * *
* Gets the folder children .
*
2019-02-22 11:44:01 +01:00
* @param folder
* the folder
2018-11-28 16:50:18 +01:00
* @return the folder children
2019-02-22 11:44:01 +01:00
* @throws Exception
* the exception
* @throws SessionExpiredException
* the session expired exception
2018-11-28 16:50:18 +01:00
* /
@Override
2019-02-22 11:44:01 +01:00
public List < FileModel > getFolderChildren ( FolderModel folder ) throws Exception , SessionExpiredException {
2019-04-10 16:46:46 +02:00
2018-11-28 16:50:18 +01:00
org . gcube . common . storagehubwrapper . server . tohl . Workspace shWorkspace ;
2019-02-22 11:44:01 +01:00
if ( isSessionExpired ( ) )
2018-11-28 16:50:18 +01:00
throw new SessionExpiredException ( ) ;
try {
2019-02-22 11:44:01 +01:00
if ( folder = = null )
2018-11-28 16:50:18 +01:00
throw new Exception ( " Folder is null " ) ;
2019-04-10 16:46:46 +02:00
workspaceLogger . info ( " Get FolderChildren called for folder: " + folder . getIdentifier ( ) ) ;
2018-11-28 16:50:18 +01:00
shWorkspace = getWorkspaceFromStorageHub ( ) ;
2019-02-22 11:44:01 +01:00
// REMEMBER wsItem.isRoot() is always false;
2018-11-28 16:50:18 +01:00
2019-02-22 11:44:01 +01:00
// REQUIRING ONLY THE FOLDERS
List < ? extends org . gcube . common . storagehubwrapper . shared . tohl . WorkspaceItem > children = shWorkspace
. getFilteredChildren ( folder . getIdentifier ( ) ,
org . gcube . common . storagehub . model . items . FolderItem . class ) ;
2018-11-28 16:50:18 +01:00
2019-04-10 16:46:46 +02:00
workspaceLogger . info ( " The children are: " + children . size ( ) ) ;
2019-02-22 10:57:16 +01:00
for ( org . gcube . common . storagehubwrapper . shared . tohl . WorkspaceItem workspaceItem : children ) {
2019-02-22 15:02:32 +01:00
workspaceLogger
. trace ( " The ITEM: " + workspaceItem . getName ( ) + " , is shared: " + workspaceItem . isShared ( )
+ " , is folder: " + workspaceItem . isFolder ( ) + " the id: " + workspaceItem . getId ( ) ) ;
2019-02-22 10:57:16 +01:00
}
2018-11-28 16:50:18 +01:00
StorageHubToWorkpaceConverter converter = getStorageHubToWorkpaceConverter ( ) ;
List < FileModel > listFileModels = new ArrayList < FileModel > ( children . size ( ) ) ;
2019-02-22 11:44:01 +01:00
// boolean isParentShared =
// workspace.isItemShared(folder.getIdentifier()); //removed for
// optimization
2018-11-28 16:50:18 +01:00
boolean isParentShared = folder . isShared ( ) ;
for ( org . gcube . common . storagehubwrapper . shared . tohl . WorkspaceItem workspaceItem : children ) {
2019-02-22 11:44:01 +01:00
// TO BE SURE IT IS A FOLDER
// if(workspaceItem.isFolder()){
workspaceLogger
. debug ( " Converting tree folder: " + workspaceItem . getId ( ) + " name " + workspaceItem . getName ( ) ) ;
listFileModels . add ( converter . toTreeFileModel ( workspaceItem , folder , isParentShared ) ) ;
// }
2018-11-28 16:50:18 +01:00
}
boolean isRoot = WsUtil . isRootFolder ( folder , converter ) ;
2019-04-10 16:46:46 +02:00
workspaceLogger . info ( " Is the workspace folder " + folder . getName ( ) + " with id: " + folder . getIdentifier ( ) + " the root? " + isRoot ) ;
2018-11-28 16:50:18 +01:00
2019-02-22 11:44:01 +01:00
// ADDING VRE FOLDER?
if ( isRoot ) {
2018-11-28 16:50:18 +01:00
folder . setIsRoot ( true ) ;
2019-02-22 11:44:01 +01:00
// ADD VRE FOLDER
try {
2018-11-28 16:50:18 +01:00
String vreFolderId = shWorkspace . getVREFoldersId ( ) ;
2019-02-22 11:44:01 +01:00
org . gcube . common . storagehubwrapper . shared . tohl . WorkspaceItem baseVREFolder = shWorkspace
. getItem ( vreFolderId ) ;
2018-11-28 16:50:18 +01:00
FileModel specialFolderModel = converter . toTreeFileModel ( baseVREFolder , folder , false ) ;
specialFolderModel . setSpecialFolder ( true ) ;
String newName = getNameForSpecialFolder ( ) ;
2019-02-22 11:44:01 +01:00
if ( ! newName . isEmpty ( ) ) {
workspaceLogger . info ( " Special folder name updated as: " + newName ) ;
2018-11-28 16:50:18 +01:00
specialFolderModel . setName ( newName ) ;
2019-02-22 11:44:01 +01:00
} else
2018-11-28 16:50:18 +01:00
workspaceLogger . info ( " Special folder name is empty, skipping " ) ;
listFileModels . add ( specialFolderModel ) ;
2019-02-22 11:44:01 +01:00
} catch ( Exception e ) {
workspaceLogger . warn (
" An error occurred on retrieving special folders for folder id: " + folder . getIdentifier ( ) ,
e ) ;
2018-11-28 16:50:18 +01:00
}
}
2019-02-22 11:44:01 +01:00
workspaceLogger . info ( " Returning " + listFileModels . size ( ) + " tree item/s " ) ;
/ *
* int i = 0 ; for ( FileModel fileModel : listFileModels ) {
* System . out . println ( i + + + " ) " + fileModel ) ; }
* /
2019-02-22 10:57:16 +01:00
2019-02-22 15:02:32 +01:00
// if(!WsUtil.isWithinPortal()){
// workspaceLogger.trace("Sleeping 4 sec...");
// Thread.sleep(4000);
// }
2018-11-28 16:50:18 +01:00
return listFileModels ;
} catch ( Exception e ) {
workspaceLogger . error ( " Error in server During item retrieving " , e ) ;
2019-02-22 11:44:01 +01:00
// workspaceLogger.trace("Error in server During item retrieving " +
// e);
2018-11-28 16:50:18 +01:00
String error = ConstantsExplorer . SERVER_ERROR + RETRIEVING_ITEM_EITHER_ITEM_DOESN_T_EXIST ;
2019-02-22 11:44:01 +01:00
// GWT can't serialize all exceptions
2018-11-28 16:50:18 +01:00
throw new Exception ( error ) ;
}
}
2019-02-22 11:44:01 +01:00
/ *
* ( non - Javadoc )
*
* @see org . gcube . portlets . user . workspace . client . rpc . GWTWorkspaceService #
* getFolderChildrenForFileGrid ( org . gcube . portlets . user . workspace . client .
* model . FileModel )
2018-11-28 16:50:18 +01:00
* /
/ * *
* Gets the folder children for file grid .
*
2019-02-22 11:44:01 +01:00
* @param folder
* the folder
2018-11-28 16:50:18 +01:00
* @return the folder children for file grid
2019-02-22 11:44:01 +01:00
* @throws Exception
* the exception
* @throws SessionExpiredException
2019-04-10 16:46:46 +02:00
* the session expired exceptionworkspaceLogger . info ( " The children are: " + children . size ( ) ) ;
2018-11-28 16:50:18 +01:00
* /
@Override
2019-02-22 11:44:01 +01:00
public List < FileGridModel > getFolderChildrenForFileGrid ( FileModel folder )
throws Exception , SessionExpiredException {
2019-04-10 16:46:46 +02:00
2019-02-22 11:44:01 +01:00
if ( isSessionExpired ( ) )
2018-11-28 16:50:18 +01:00
throw new SessionExpiredException ( ) ;
try {
2019-02-22 11:44:01 +01:00
if ( folder = = null )
2018-11-28 16:50:18 +01:00
throw new Exception ( " Folder is null " ) ;
2019-04-10 16:46:46 +02:00
workspaceLogger . info ( " Get FolderChildrenForFileGrid called for folder: " + folder . getIdentifier ( ) ) ;
2018-11-28 16:50:18 +01:00
org . gcube . common . storagehubwrapper . server . tohl . Workspace shWorkspace = getWorkspaceFromStorageHub ( ) ;
2019-02-22 11:44:01 +01:00
List < ? extends org . gcube . common . storagehubwrapper . shared . tohl . WorkspaceItem > children = shWorkspace
. getChildren ( folder . getIdentifier ( ) ) ;
2018-11-28 16:50:18 +01:00
2019-04-10 16:46:46 +02:00
workspaceLogger . info ( " The children are: " + children . size ( ) ) ;
2018-11-28 16:50:18 +01:00
StorageHubToWorkpaceConverter converter = getStorageHubToWorkpaceConverter ( ) ;
List < FileGridModel > listFileGridModels = new ArrayList < FileGridModel > ( children . size ( ) ) ;
2019-02-22 11:44:01 +01:00
// boolean isParentShared = folder.isShared();
2018-11-28 16:50:18 +01:00
for ( org . gcube . common . storagehubwrapper . shared . tohl . WorkspaceItem workspaceItem : children ) {
2019-02-22 11:44:01 +01:00
workspaceLogger
. debug ( " Converting grid item: " + workspaceItem . getId ( ) + " name " + workspaceItem . getName ( ) ) ;
2018-11-28 16:50:18 +01:00
listFileGridModels . add ( converter . toGridFileModel ( workspaceItem , folder ) ) ;
}
boolean isRoot = WsUtil . isRootFolder ( folder , converter ) ;
2019-02-22 11:44:01 +01:00
workspaceLogger . debug ( " ****** IS ROOT? " + isRoot ) ;
// ADDING VRE FOLDER?
if ( isRoot ) {
2018-11-28 16:50:18 +01:00
folder . setIsRoot ( true ) ;
2019-02-22 11:44:01 +01:00
// ADD VRE FOLDER
try {
2018-11-28 16:50:18 +01:00
String vreFolderId = shWorkspace . getVREFoldersId ( ) ;
2019-04-17 11:42:48 +02:00
org . gcube . common . storagehubwrapper . shared . tohl . WorkspaceItem baseVREFolder = shWorkspace . getItem ( vreFolderId ) ;
2018-11-28 16:50:18 +01:00
FileGridModel specialFolderModel = converter . toGridFileModel ( baseVREFolder , folder ) ;
specialFolderModel . setSpecialFolder ( true ) ;
String newName = getNameForSpecialFolder ( ) ;
2019-02-22 11:44:01 +01:00
if ( ! newName . isEmpty ( ) ) {
workspaceLogger . info ( " Special folder name updated as: " + newName ) ;
2018-11-28 16:50:18 +01:00
specialFolderModel . setName ( newName ) ;
2019-02-22 11:44:01 +01:00
} else
2018-11-28 16:50:18 +01:00
workspaceLogger . info ( " Special folder name is empty, skipping " ) ;
listFileGridModels . add ( specialFolderModel ) ;
2019-02-22 11:44:01 +01:00
} catch ( Exception e ) {
workspaceLogger . warn (
" An error occurred on retrieving special folders for folder id: " + folder . getIdentifier ( ) ,
e ) ;
2018-11-28 16:50:18 +01:00
}
}
return listFileGridModels ;
} catch ( Exception e ) {
workspaceLogger . error ( " Error in server During items retrieving " , e ) ;
String error = ConstantsExplorer . SERVER_ERROR + RETRIEVING_ITEM_EITHER_ITEM_DOESN_T_EXIST ;
2019-02-22 11:44:01 +01:00
// GWT can't serialize all exceptions
2018-11-28 16:50:18 +01:00
throw new Exception ( error ) ;
}
}
2019-02-22 11:44:01 +01:00
/ *
* ( non - Javadoc )
*
* @see org . gcube . portlets . user . workspace . client . rpc . GWTWorkspaceService #
* getFolderChildrenForFileGridById ( java . lang . String )
2018-11-28 16:50:18 +01:00
* /
/ * *
* Gets the folder children for file grid by id .
*
2019-02-22 11:44:01 +01:00
* @param folderId
* the folder id
2018-11-28 16:50:18 +01:00
* @return the folder children for file grid by id
2019-02-22 11:44:01 +01:00
* @throws Exception
* the exception
* @throws SessionExpiredException
* the session expired exception
2018-11-28 16:50:18 +01:00
* /
@Override
2019-02-22 11:44:01 +01:00
public List < FileGridModel > getFolderChildrenForFileGridById ( String folderId )
throws Exception , SessionExpiredException {
2018-11-28 16:50:18 +01:00
2019-02-22 11:44:01 +01:00
if ( isSessionExpired ( ) )
2018-11-28 16:50:18 +01:00
throw new SessionExpiredException ( ) ;
try {
2019-02-22 11:44:01 +01:00
if ( folderId = = null | | folderId . isEmpty ( ) )
2018-11-28 16:50:18 +01:00
throw new Exception ( " Folder id is null or empty " ) ;
org . gcube . common . storagehubwrapper . server . tohl . Workspace shWorkspace = getWorkspaceFromStorageHub ( ) ;
2019-02-22 11:44:01 +01:00
workspaceLogger . trace ( " get children for Grid by id: " + folderId ) ;
2018-11-28 16:50:18 +01:00
List < FileGridModel > listFileGridModels = new ArrayList < FileGridModel > ( ) ;
2019-02-22 11:44:01 +01:00
// BUILDING THE PARENT
2018-11-28 16:50:18 +01:00
org . gcube . common . storagehubwrapper . shared . tohl . WorkspaceItem wsItem = shWorkspace . getItem ( folderId ) ;
org . gcube . common . storagehubwrapper . shared . tohl . WorkspaceFolder parent ;
2019-02-22 11:44:01 +01:00
if ( wsItem . isFolder ( ) ) {
workspaceLogger . trace ( " item id: " + folderId + " is of type: " + wsItem . getType ( ) ) ;
2018-11-28 16:50:18 +01:00
parent = ( org . gcube . common . storagehubwrapper . shared . tohl . WorkspaceFolder ) wsItem ;
2019-02-22 11:44:01 +01:00
} else {
workspaceLogger . trace (
" item id: " + folderId + " is not a folder but of type: " + wsItem . getType ( ) + " , get parent " ) ;
parent = ( org . gcube . common . storagehubwrapper . shared . tohl . WorkspaceFolder ) shWorkspace
. getItem ( wsItem . getParentId ( ) ) ;
2018-11-28 16:50:18 +01:00
}
2019-02-22 11:44:01 +01:00
if ( parent = = null )
2018-11-28 16:50:18 +01:00
return listFileGridModels ;
StorageHubToWorkpaceConverter converter = getStorageHubToWorkpaceConverter ( ) ;
FileGridModel wsParent = converter . toGridFileModel ( parent , null ) ;
2019-02-22 11:44:01 +01:00
// PARENT BUILT IS SHARED?
if ( parent . isShared ( ) ) {
2018-11-28 16:50:18 +01:00
wsParent . setShared ( true ) ;
wsParent . setShareable ( false ) ;
}
2019-02-22 11:44:01 +01:00
Long startTime = System . currentTimeMillis ( ) ;
2018-11-28 16:50:18 +01:00
2019-02-22 11:44:01 +01:00
// GET CHILDREN
List < ? extends org . gcube . common . storagehubwrapper . shared . tohl . WorkspaceItem > children = shWorkspace
. getChildren ( wsParent . getIdentifier ( ) ) ;
2018-11-28 16:50:18 +01:00
Long endTime = System . currentTimeMillis ( ) - startTime ;
String time = String . format ( " %d msc %d sec " , endTime , TimeUnit . MILLISECONDS . toSeconds ( endTime ) ) ;
2019-02-22 11:44:01 +01:00
workspaceLogger . debug ( " grid getChildren() returning " + children . size ( ) + " elements in " + time ) ;
// boolean isParentShared = folder.isShared();
2018-11-28 16:50:18 +01:00
for ( org . gcube . common . storagehubwrapper . shared . tohl . WorkspaceItem workspaceItem : children ) {
2019-02-22 11:44:01 +01:00
workspaceLogger
. debug ( " Converting grid item: " + workspaceItem . getId ( ) + " name " + workspaceItem . getName ( ) ) ;
2018-11-28 16:50:18 +01:00
listFileGridModels . add ( converter . toGridFileModel ( workspaceItem , wsParent ) ) ;
}
return listFileGridModels ;
} catch ( Exception e ) {
workspaceLogger . error ( " Error in server During items retrieving " , e ) ;
String error = ConstantsExplorer . SERVER_ERROR + RETRIEVING_ITEM_EITHER_ITEM_DOESN_T_EXIST ;
throw new Exception ( error ) ;
}
}
/ * *
* Gets the trash content .
*
* @return the trash content
2019-02-22 11:44:01 +01:00
* @throws Exception
* the exception
2018-11-28 16:50:18 +01:00
* /
@Override
2019-02-22 11:44:01 +01:00
public List < FileTrashedModel > getTrashContent ( ) throws Exception {
2018-11-28 16:50:18 +01:00
workspaceLogger . trace ( " Get TrashContent: " ) ;
try {
org . gcube . common . storagehubwrapper . server . tohl . Workspace workspace = getWorkspaceFromStorageHub ( ) ;
org . gcube . common . storagehubwrapper . shared . tohl . WorkspaceItem baseTrashFolder = workspace . getTrash ( ) ;
2019-02-22 11:44:01 +01:00
List < ? extends org . gcube . common . storagehubwrapper . shared . tohl . WorkspaceItem > trashChildren = workspace
. getChildren ( baseTrashFolder . getId ( ) ) ;
2018-11-28 16:50:18 +01:00
List < FileTrashedModel > trashContent = new ArrayList < FileTrashedModel > ( trashChildren . size ( ) ) ;
StorageHubToWorkpaceConverter converter = getStorageHubToWorkpaceConverter ( ) ;
for ( org . gcube . common . storagehubwrapper . shared . tohl . WorkspaceItem workspaceItem : trashChildren ) {
2019-02-22 11:44:01 +01:00
if ( workspaceItem . isTrashed ( ) ) {
2018-11-28 16:50:18 +01:00
trashContent . add ( converter . toFileTrashedModel ( ( TrashedItem ) workspaceItem ) ) ;
2019-02-22 11:44:01 +01:00
} else
workspaceLogger . warn ( " The item: " + workspaceItem . getId ( ) + " is not trashed " ) ;
2018-11-28 16:50:18 +01:00
}
return trashContent ;
2019-02-22 11:44:01 +01:00
} catch ( Exception e ) {
2018-11-28 16:50:18 +01:00
workspaceLogger . error ( " Error in server TrashConten " , e ) ;
2019-02-22 11:44:01 +01:00
String error = ConstantsExplorer . SERVER_ERROR + " get Trash content. " + e . getMessage ( ) ;
2018-11-28 16:50:18 +01:00
throw new Exception ( error ) ;
}
}
/ * *
* Update trash content .
*
2019-02-22 11:44:01 +01:00
* @param operation
* the operation
2018-11-28 16:50:18 +01:00
* @return the trash content
2019-02-22 11:44:01 +01:00
* @throws Exception
* the exception
2018-11-28 16:50:18 +01:00
* /
@Override
2019-02-22 11:44:01 +01:00
public TrashContent updateTrashContent ( WorkspaceTrashOperation operation ) throws Exception {
2018-11-28 16:50:18 +01:00
2019-02-22 11:44:01 +01:00
workspaceLogger . info ( " Updating TrashContent with operation: " + operation ) ;
2018-11-28 16:50:18 +01:00
try {
org . gcube . common . storagehubwrapper . server . tohl . Workspace workspace = getWorkspaceFromStorageHub ( ) ;
TrashContent result = new TrashContent ( ) ;
switch ( operation ) {
case EMPTY_TRASH :
workspace . emptyTrash ( ) ;
2019-02-22 11:44:01 +01:00
// case RESTORE_ALL:
// //listErrors = trash.restoreAll();
// //workspace.re
// break;
2018-11-28 16:50:18 +01:00
case REFRESH :
default :
2019-02-22 11:44:01 +01:00
result . setTrashContent ( getTrashContent ( ) ) ; // THIS WORKING WITH
// STORAGE-HUB
2018-11-28 16:50:18 +01:00
return result ;
}
2019-02-22 11:44:01 +01:00
} catch ( Exception e ) {
2018-11-28 16:50:18 +01:00
workspaceLogger . error ( " Error in server TrashContent " , e ) ;
2019-02-22 11:44:01 +01:00
String error = ConstantsExplorer . SERVER_ERROR + " update Trash content. " + e . getMessage ( ) ;
2018-11-28 16:50:18 +01:00
throw new Exception ( error ) ;
}
}
2019-02-22 11:44:01 +01:00
/ *
* ( non - Javadoc )
*
* @see org . gcube . portlets . user . workspace . client . rpc . GWTWorkspaceService #
* executeOperationOnTrash ( java . util . List ,
* org . gcube . portlets . user . workspace . shared . WorkspaceTrashOperation )
2018-11-28 16:50:18 +01:00
* /
/ * *
* Execute operation on trash .
*
2019-02-22 11:44:01 +01:00
* @param listTrashItemIds
* the list trash item ids
* @param operation
* the operation
2018-11-28 16:50:18 +01:00
* @return the trash operation content
2019-02-22 11:44:01 +01:00
* @throws Exception
* the exception
2018-11-28 16:50:18 +01:00
* /
@Override
2019-02-22 11:44:01 +01:00
public TrashOperationContent executeOperationOnTrash ( List < String > listTrashItemIds ,
WorkspaceTrashOperation operation ) throws Exception {
2018-11-28 16:50:18 +01:00
2019-02-22 11:44:01 +01:00
workspaceLogger . info ( " Get TrashContent, operation: " + operation ) ;
2018-11-28 16:50:18 +01:00
2019-02-22 11:44:01 +01:00
if ( listTrashItemIds = = null | | listTrashItemIds . size ( ) = = 0 )
2018-11-28 16:50:18 +01:00
throw new Exception ( " List of Trash item ids is null or empty " ) ;
List < FileTrashedModel > listContentError = new ArrayList < FileTrashedModel > ( ) ;
try {
org . gcube . common . storagehubwrapper . server . tohl . Workspace workspace = getWorkspaceFromStorageHub ( ) ;
2019-02-22 11:44:01 +01:00
// WorkspaceTrashFolder trash = workspace.getTrash();
2018-11-28 16:50:18 +01:00
TrashOperationContent result = new TrashOperationContent ( ) ;
result . setOperation ( operation ) ;
List < String > listUpdatedTrashIds = new ArrayList < String > ( ) ;
switch ( operation ) {
2019-02-22 11:44:01 +01:00
case DELETE_PERMANENTLY : {
2018-11-28 16:50:18 +01:00
boolean deleted = false ;
for ( String trashItemId : listTrashItemIds ) {
2019-02-22 11:44:01 +01:00
try {
org . gcube . common . storagehubwrapper . shared . tohl . WorkspaceItem trashedItem = workspace
. getItem ( trashItemId ) ;
if ( trashedItem ! = null & & trashedItem . isTrashed ( ) ) {
2018-11-28 16:50:18 +01:00
workspace . deleteItem ( trashedItem . getId ( ) ) ;
listUpdatedTrashIds . add ( trashItemId ) ;
deleted = true ;
}
2019-02-22 11:44:01 +01:00
} catch ( Exception e ) {
workspaceLogger . warn ( " Error on DELETE_PERMANENTLY the item : " + trashItemId , e ) ;
2018-11-28 16:50:18 +01:00
FileTrashedModel fakeFile = new FileTrashedModel ( ) ;
fakeFile . setIdentifier ( trashItemId ) ;
listContentError . add ( fakeFile ) ;
}
}
2019-02-22 11:44:01 +01: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 " ) ;
2018-11-28 16:50:18 +01:00
break ;
}
2019-02-22 11:44:01 +01:00
case RESTORE : {
2018-11-28 16:50:18 +01:00
boolean restored = false ;
for ( String trashItemId : listTrashItemIds ) {
2019-02-22 11:44:01 +01:00
try {
org . gcube . common . storagehubwrapper . shared . tohl . WorkspaceItem trashedItem = workspace
. getItem ( trashItemId ) ;
if ( trashedItem ! = null & & trashedItem . isTrashed ( ) ) {
2018-11-28 16:50:18 +01:00
workspace . restoreThrashItem ( trashedItem . getId ( ) ) ;
listUpdatedTrashIds . add ( trashItemId ) ;
restored = true ;
}
2019-02-22 11:44:01 +01:00
} catch ( Exception e ) {
workspaceLogger . warn ( " Error on RESTORE the item : " + trashItemId , e ) ;
2018-11-28 16:50:18 +01:00
FileTrashedModel fakeFile = new FileTrashedModel ( ) ;
fakeFile . setIdentifier ( trashItemId ) ;
listContentError . add ( fakeFile ) ;
}
}
2019-02-22 11:44:01 +01:00
String label = listTrashItemIds . size ( ) > 1 ? " items " : " item " ;
2018-11-28 16:50:18 +01:00
2019-02-22 11:44:01 +01:00
if ( ! restored )
throw new Exception ( " Sorry, an error occurred on restoring the trash " + label + " , try again " ) ;
2018-11-28 16:50:18 +01:00
break ;
}
default :
break ;
}
2019-02-22 11:44:01 +01:00
if ( ! listContentError . isEmpty ( ) ) {
2018-11-28 16:50:18 +01:00
result . setListErrors ( listContentError ) ;
}
result . setListTrashIds ( listUpdatedTrashIds ) ;
return result ;
2019-02-22 11:44:01 +01:00
} catch ( Exception e ) {
2018-11-28 16:50:18 +01:00
workspaceLogger . error ( " Error in server executeOperationOnTrash " , e ) ;
2019-02-22 11:44:01 +01:00
String error = ConstantsExplorer . SERVER_ERROR + " updating the trash content. " + e . getMessage ( ) ;
2018-11-28 16:50:18 +01:00
throw new Exception ( error ) ;
}
}
2019-02-22 11:44:01 +01:00
/ *
* ( non - Javadoc )
*
* @see org . gcube . portlets . user . workspace . client . rpc . GWTWorkspaceService #
* deleteListItemsForIds ( java . util . List )
2018-11-28 16:50:18 +01:00
* /
/ * *
* Delete list items for ids .
*
2019-02-22 11:44:01 +01:00
* @param ids
* the ids
2018-11-28 16:50:18 +01:00
* @return the list
2019-02-22 11:44:01 +01:00
* @throws Exception
* the exception
2018-11-28 16:50:18 +01:00
* /
@Override
public List < GarbageItem > deleteListItemsForIds ( List < String > ids ) throws Exception {
try {
2019-02-22 11:44:01 +01:00
if ( ids = = null )
2018-11-28 16:50:18 +01:00
throw new Exception ( " List identifiers is null " ) ;
2019-02-22 11:44:01 +01:00
// Workspace workspace = getWorkspace();
2018-11-28 16:50:18 +01:00
org . gcube . common . storagehubwrapper . server . tohl . Workspace workspace = getWorkspaceFromStorageHub ( ) ;
2019-02-22 11:44:01 +01:00
workspaceLogger . trace ( " removeItem item for list size: " + ids . size ( ) ) ;
2018-11-28 16:50:18 +01:00
String [ ] items = new String [ ids . size ( ) ] ;
items = ids . toArray ( items ) ;
Map < String , GarbageItem > garbage = new HashMap < String , GarbageItem > ( items . length ) ;
2019-02-22 11:44:01 +01:00
// SAVE DATE FOR NOTIFICATIONS
2018-11-28 16:50:18 +01:00
for ( String itemId : ids ) {
2019-02-22 11:44:01 +01:00
// NOTIFICATION
2018-11-28 16:50:18 +01:00
org . gcube . common . storagehubwrapper . shared . tohl . WorkspaceItem wsItem = workspace . getItem ( itemId ) ;
checkItemLocked ( itemId ) ;
2019-02-22 11:44:01 +01:00
// SAVING ATTRIBUTE FOR NOTIFICATION
2018-11-28 16:50:18 +01:00
boolean sourceItemIsShared = wsItem . isShared ( ) ;
String itemName = wsItem . getName ( ) ;
String sourceFolderSharedId = null ;
2019-02-22 11:44:01 +01:00
try {
if ( sourceItemIsShared ) {
org . gcube . common . storagehubwrapper . shared . tohl . WorkspaceItem rootSharedFolder = workspace
. getRootSharedFolder ( itemId ) ;
2018-11-28 16:50:18 +01:00
sourceFolderSharedId = rootSharedFolder . getId ( ) ;
}
2019-02-22 11:44:01 +01:00
// REMOVE ITEM
2018-11-28 16:50:18 +01:00
garbage . put ( itemId , new GarbageItem ( sourceItemIsShared , itemName , itemId , sourceFolderSharedId ) ) ;
2019-02-22 11:44:01 +01:00
} catch ( Exception e ) {
workspaceLogger . warn ( " Impossible to send notifiaction for item with id: " + itemId ) ;
2018-11-28 16:50:18 +01:00
}
2019-02-22 11:44:01 +01:00
// workspace.removeItem(itemId);
//// IF SOURCE SHARED FOLDER IS NOT NULL
// if(sourceFolderSharedId!=null)
// NotificationsUtil.checkSendNotifyRemoveItemToShare(this.getThreadLocalRequest().getSession(),
// sourceItemIsShared, itemName, itemId, sourceFolderSharedId);
2018-11-28 16:50:18 +01:00
}
2019-02-22 11:44:01 +01:00
// ITEM ID - ERROR
2018-11-28 16:50:18 +01:00
Map < String , String > backendError = workspace . removeItems ( items ) ;
2019-02-22 11:44:01 +01:00
// GARBAGE ITEM ERROR
2018-11-28 16:50:18 +01:00
List < GarbageItem > frontEndError = new ArrayList < GarbageItem > ( backendError . size ( ) ) ;
2019-02-22 11:44:01 +01:00
// REMOVING IDS WHICH HAVE GENERATED AN ERROR
2018-11-28 16:50:18 +01:00
for ( String idError : backendError . keySet ( ) ) {
GarbageItem gbi = garbage . get ( idError ) ;
2019-02-22 11:44:01 +01:00
if ( gbi ! = null ) {
2018-11-28 16:50:18 +01:00
frontEndError . add ( gbi ) ;
garbage . remove ( idError ) ;
}
}
for ( String idItem : garbage . keySet ( ) ) {
GarbageItem item = garbage . get ( idItem ) ;
2019-02-22 11:44:01 +01:00
workspaceLogger . trace ( " Check notification for " + item ) ;
// IF SOURCE SHARED FOLDER IS NOT NULL
if ( item . getSourceFolderSharedId ( ) ! = null )
NotificationsUtil . checkSendNotifyRemoveItemToShare ( this . getThreadLocalRequest ( ) ,
item . isSourceItemIsShared ( ) , item . getOldItemName ( ) , item . getOldItemName ( ) ,
item . getSourceFolderSharedId ( ) ) ;
2018-11-28 16:50:18 +01:00
}
return frontEndError ;
2019-02-22 11:44:01 +01:00
} catch ( WorkspaceFolderLocked e1 ) {
2018-11-28 16:50:18 +01:00
throw new Exception ( e1 . getMessage ( ) ) ;
} catch ( InsufficientPrivilegesException e ) {
workspaceLogger . error ( " Error in server Item remove " , e ) ;
2019-02-22 11:44:01 +01:00
String error = " An error occurred on deleting item. " + e . getMessage ( ) ;
2018-11-28 16:50:18 +01:00
throw new Exception ( error ) ;
2019-02-22 11:44:01 +01:00
} catch ( ItemNotFoundException e ) {
String error = " An error occurred on deleting item. " + ConstantsExplorer . ERROR_ITEM_DOES_NOT_EXIST ;
2018-11-28 16:50:18 +01:00
workspaceLogger . error ( error , e ) ;
throw new Exception ( error ) ;
} catch ( Exception e ) {
workspaceLogger . error ( " Error in server Item remove " , e ) ;
2019-02-22 11:44:01 +01:00
String error = ConstantsExplorer . SERVER_ERROR + " deleting item. " + e . getMessage ( ) ;
2018-11-28 16:50:18 +01:00
throw new Exception ( error ) ;
}
}
2019-02-22 11:44:01 +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 )
2018-11-28 16:50:18 +01:00
* /
/ * *
* Creates the folder .
*
2019-02-22 11:44:01 +01:00
* @param nameFolder
* the name folder
* @param description
* the description
* @param parent
* the parent
2018-11-28 16:50:18 +01:00
* @return the folder model
2019-02-22 11:44:01 +01:00
* @throws Exception
* the exception
2018-11-28 16:50:18 +01:00
* /
@Override
public FolderModel createFolder ( String nameFolder , String description , FileModel parent ) throws Exception {
2019-02-22 11:44:01 +01:00
workspaceLogger . debug ( " Create folder: " + nameFolder + " parent is null? " + parent = = null ) ;
2018-11-28 16:50:18 +01:00
2019-02-22 11:44:01 +01:00
if ( isSessionExpired ( ) )
2018-11-28 16:50:18 +01:00
throw new SessionExpiredException ( ) ;
try {
2019-02-22 11:44:01 +01:00
if ( nameFolder = = null )
2018-11-28 16:50:18 +01:00
throw new Exception ( " Folder name is null " ) ;
checkItemLocked ( parent . getIdentifier ( ) ) ;
org . gcube . common . storagehubwrapper . server . tohl . Workspace workspace = getWorkspaceFromStorageHub ( ) ;
2019-02-22 11:44:01 +01:00
// Creating the folder
org . gcube . common . storagehubwrapper . shared . tohl . WorkspaceFolder wsFolder = workspace . createFolder ( nameFolder ,
description , parent . getIdentifier ( ) ) ;
// Getting the parent folder
org . gcube . common . storagehubwrapper . shared . tohl . WorkspaceFolder parentFolderDestionation = ( org . gcube . common . storagehubwrapper . shared . tohl . WorkspaceFolder ) workspace
. getItem ( parent . getIdentifier ( ) ) ;
2018-11-28 16:50:18 +01:00
NotificationsProducerToStorageHub np = getNotificationProducerToStorageHub ( ) ;
2019-02-22 11:44:01 +01:00
NotificationStorageHubUtil . checkNotifyAddItemToShare ( wsFolder , null , parentFolderDestionation , workspace ,
np ) ;
2018-11-28 16:50:18 +01:00
StorageHubToWorkpaceConverter converter = getStorageHubToWorkpaceConverter ( ) ;
return ( FolderModel ) converter . toTreeFileModel ( wsFolder , parent , parentFolderDestionation . isShared ( ) ) ;
2019-02-22 11:44:01 +01:00
} catch ( WorkspaceFolderLocked e1 ) {
2018-11-28 16:50:18 +01:00
throw new Exception ( e1 . getMessage ( ) ) ;
2019-02-22 11:44:01 +01:00
} catch ( InsufficientPrivilegesException e ) {
2018-11-28 16:50:18 +01:00
String error = " Insufficient Privileges to create the folder " ;
workspaceLogger . error ( error , e ) ;
throw new Exception ( error ) ;
} catch ( ItemAlreadyExistException e ) {
2019-02-22 11:44:01 +01:00
String error = " An error occurred on creating folder, " + e . getMessage ( ) ;
2018-11-28 16:50:18 +01:00
workspaceLogger . error ( error , e ) ;
throw new Exception ( error ) ;
} catch ( Exception e ) {
String error = " Error on creating folder. Either the folder already exist or you do not have the permission to create it " ;
workspaceLogger . error ( error , e ) ;
throw new Exception ( error ) ;
}
}
2019-02-22 11:44:01 +01:00
/ *
* ( non - Javadoc )
*
* @see org . gcube . portlets . user . workspace . client . rpc . GWTWorkspaceService #
* moveItems ( java . util . List , java . lang . String )
2018-11-28 16:50:18 +01:00
* /
/ * *
* Move items .
*
2019-02-22 11:44:01 +01:00
* @param ids
* the ids
* @param destinationId
* the destination id
2018-11-28 16:50:18 +01:00
* @return the boolean
2019-02-22 11:44:01 +01:00
* @throws Exception
* the exception
2018-11-28 16:50:18 +01:00
* /
@Override
public WorkspaceOperationResult moveItems ( List < String > ids , String destinationId ) throws Exception {
2019-02-22 11:44:01 +01:00
workspaceLogger . trace ( " moveItems " + ids . size ( ) + " , destination: " + destinationId ) ;
2018-11-28 16:50:18 +01:00
2019-02-22 11:44:01 +01:00
if ( isSessionExpired ( ) )
2018-11-28 16:50:18 +01:00
throw new SessionExpiredException ( ) ;
2019-02-22 11:44:01 +01:00
// boolean error = false;
2018-11-28 16:50:18 +01:00
WorkspaceOperationResult results = new WorkspaceOperationResult ( ) ;
results . setOperationName ( " Move Items " ) ;
try {
checkItemLocked ( destinationId ) ;
org . gcube . common . storagehubwrapper . server . tohl . Workspace workspace = getWorkspaceFromStorageHub ( ) ;
2019-02-22 11:44:01 +01:00
org . gcube . common . storagehubwrapper . shared . tohl . WorkspaceItem folderDestinationItem = workspace
. getItem ( destinationId ) ; // retrieve folder destination
2018-11-28 16:50:18 +01:00
org . gcube . common . storagehubwrapper . shared . tohl . WorkspaceFolder folderDestination = null ;
2019-02-22 11:44:01 +01:00
if ( folderDestinationItem ! = null & & folderDestinationItem . isFolder ( ) ) {
2018-11-28 16:50:18 +01:00
folderDestination = ( org . gcube . common . storagehubwrapper . shared . tohl . WorkspaceFolder ) folderDestinationItem ;
2019-02-22 11:44:01 +01:00
} else
2018-11-28 16:50:18 +01:00
throw new Exception ( " Wrong destination. Either It is not a folder or not exist " ) ;
for ( String itemId : ids ) {
org . gcube . common . storagehubwrapper . shared . tohl . WorkspaceItem sourceItem = null ;
2019-02-22 11:44:01 +01:00
try {
2018-11-28 16:50:18 +01:00
2019-02-22 11:44:01 +01:00
if ( itemId = = null )
2018-11-28 16:50:18 +01:00
throw new Exception ( IDENTIFIER_IS_NULL ) ;
2019-02-22 11:44:01 +01:00
workspaceLogger . trace ( " Moving item id: " + itemId + " in the destination: " + destinationId ) ;
sourceItem = workspace . getItem ( itemId ) ; // GET SOURCE ITEM
// BEFORE OF MOVE
2018-11-28 16:50:18 +01:00
checkItemLocked ( itemId ) ;
String sourceRootSharedFolderId = null ;
boolean sourceItemIsShared = sourceItem . isShared ( ) ;
2019-02-22 11:44:01 +01:00
// JUST ONCE TO REDUCE THE NUMBER OF CALLS TO STORAGEHUB
if ( sourceItemIsShared & & sourceRootSharedFolderId = = null ) {
org . gcube . common . storagehubwrapper . shared . tohl . WorkspaceItem sourceShared = workspace
. getRootSharedFolder ( itemId ) ;
sourceRootSharedFolderId = sourceShared . getId ( ) ; // GET
// SHARED
// ID
// BEFORE
// OF
// MOVE
2018-11-28 16:50:18 +01:00
}
2019-02-22 11:44:01 +01:00
workspaceLogger
. debug ( " Invoking move on source item id: " + itemId + " with name: " + sourceItem . getName ( )
+ " shared: " + sourceItemIsShared + " destination: " + destinationId ) ;
org . gcube . common . storagehubwrapper . shared . tohl . WorkspaceItem movedItem = workspace . moveItem ( itemId ,
destinationId ) ; // move item
workspaceLogger . debug ( " Moved item: " + movedItem ) ;
2018-11-28 16:50:18 +01:00
2019-02-22 11:44:01 +01:00
try {
// NOTIFY?
2018-11-28 16:50:18 +01:00
NotificationsProducerToStorageHub np = getNotificationProducerToStorageHub ( ) ;
2019-02-22 11:44:01 +01:00
NotificationStorageHubUtil . checkNotifyAddItemToShare ( movedItem , sourceRootSharedFolderId ,
folderDestination , workspace , np ) ;
NotificationStorageHubUtil . checkNotifyMoveItemFromShare ( sourceItemIsShared , sourceItem ,
sourceRootSharedFolderId , folderDestination , workspace , np ) ;
2018-11-28 16:50:18 +01:00
2019-02-22 11:44:01 +01:00
} catch ( Exception e ) {
2018-11-28 16:50:18 +01:00
workspaceLogger . error ( " An error occurred in checkNotify " , e ) ;
}
2019-02-22 11:44:01 +01:00
} catch ( Exception e ) {
2018-11-28 16:50:18 +01:00
String error = results . getError ( ) ;
2019-02-22 11:44:01 +01:00
if ( error = = null )
2018-11-28 16:50:18 +01:00
error = " Error on moving: " ;
2019-02-22 11:44:01 +01:00
error + = " " ;
error + = sourceItem ! = null ? sourceItem . getName ( ) : " item is null " ;
error + = " , " ;
2018-11-28 16:50:18 +01:00
results . setError ( error ) ;
}
}
2019-02-22 11:44:01 +01:00
// removing last ','
if ( results . getError ( ) ! = null )
results . setError ( results . getError ( ) . substring ( 0 , results . getError ( ) . length ( ) - 1 ) ) ;
2018-11-28 16:50:18 +01:00
2019-02-22 11:44:01 +01:00
workspaceLogger . info ( " Moved error: " + results . getError ( ) ) ;
2018-11-28 16:50:18 +01:00
2019-02-22 11:44:01 +01:00
if ( results . getError ( ) ! = null )
results . setError ( results . getError ( )
+ " . Operation not allowed. Moving to wrong path, either it is a shared folder or you have not the permission to move the item " ) ;
2018-11-28 16:50:18 +01:00
return results ;
2019-02-22 11:44:01 +01:00
} catch ( WorkspaceFolderLocked e1 ) {
2018-11-28 16:50:18 +01:00
throw new Exception ( e1 . getMessage ( ) ) ;
2019-02-22 11:44:01 +01:00
} catch ( InsufficientPrivilegesException e ) {
2018-11-28 16:50:18 +01:00
workspaceLogger . error ( " Error in server Item move " , e ) ;
2019-02-22 11:44:01 +01:00
String error1 = " An error occurred on moving item. " + e . getMessage ( ) ;
2018-11-28 16:50:18 +01:00
throw new Exception ( error1 ) ;
} catch ( Exception e ) {
workspaceLogger . error ( " Item move error. " , e ) ;
2019-02-22 11:44:01 +01:00
String error2 = ConstantsExplorer . SERVER_ERROR + " moving item/s. " + e . getMessage ( ) ;
2018-11-28 16:50:18 +01:00
throw new Exception ( error2 ) ;
}
}
2019-02-22 11:44:01 +01:00
/ *
* ( non - Javadoc )
*
* @see org . gcube . portlets . user . workspace . client . rpc . GWTWorkspaceService #
* renameItem ( java . lang . String , java . lang . String , java . lang . String )
2018-11-28 16:50:18 +01:00
* /
/ * *
* Rename item .
*
2019-02-22 11:44:01 +01:00
* @param itemId
* the item id
* @param newName
* the new name
* @param previousName
* the previous name
2018-11-28 16:50:18 +01:00
* @return the boolean
2019-02-22 11:44:01 +01:00
* @throws Exception
* the exception
2018-11-28 16:50:18 +01:00
* /
@Override
public Boolean renameItem ( String itemId , String newName , String previousName ) throws Exception {
2019-02-22 11:44:01 +01:00
if ( isSessionExpired ( ) )
2018-11-28 16:50:18 +01:00
throw new SessionExpiredException ( ) ;
2019-04-30 12:06:04 +02:00
boolean sourceItemIsShared = false ;
2018-11-28 16:50:18 +01:00
try {
2019-02-22 11:44:01 +01:00
if ( itemId = = null )
2018-11-28 16:50:18 +01:00
throw new Exception ( IDENTIFIER_IS_NULL ) ;
checkItemLocked ( itemId ) ;
org . gcube . common . storagehubwrapper . server . tohl . Workspace workspace = getWorkspaceFromStorageHub ( ) ;
2019-02-22 11:44:01 +01:00
workspaceLogger . debug ( " Renaming item with id: " + itemId + " from old name " + previousName
+ " , to new name: " + newName ) ;
2019-04-30 12:06:04 +02:00
//Needed to check if the item is shared
org . gcube . common . storagehubwrapper . shared . tohl . WorkspaceItem wsItem = workspace . getItem ( itemId ) ;
sourceItemIsShared = wsItem . isShared ( ) ;
wsItem = workspace . renameItem ( itemId , newName ) ;
2019-02-22 11:44:01 +01:00
workspaceLogger . debug ( " Item renamed is: " + wsItem ) ;
2018-11-28 16:50:18 +01:00
2019-02-22 11:44:01 +01:00
// SEND NOTIFY?
2019-04-30 12:06:04 +02:00
if ( sourceItemIsShared ) {
2018-11-28 16:50:18 +01:00
2019-02-22 11:44:01 +01:00
try {
2018-11-28 16:50:18 +01:00
List < InfoContactModel > listSharedContact = new ArrayList < InfoContactModel > ( ) ;
NotificationsProducerToStorageHub np = getNotificationProducerToStorageHub ( ) ;
2019-02-22 11:44:01 +01:00
org . gcube . common . storagehubwrapper . shared . tohl . WorkspaceItem sourceShared = workspace
. getRootSharedFolder ( wsItem . getId ( ) ) ;
// NotificationsManager nManager =
// WsUtil.getNotificationManager(this.getThreadLocalRequest());
listSharedContact = NotificationStorageHubUtil . getListUserSharedByFolderSharedId ( sourceShared ,
workspace ) ;
// IS A SHARED FOLDER
if ( NotificationStorageHubUtil . isASharedFolder ( wsItem ) ) {
2018-11-28 16:50:18 +01:00
np . notifyFolderRenamed ( listSharedContact , wsItem , previousName , newName , sourceShared . getId ( ) ) ;
2019-02-22 11:44:01 +01:00
// NotificationStorageHubUtil.checkNotifyAddItemToShare(movedItem,
// sourceRootSharedFolderId, folderDestination,
// workspace, np);
// NotificationStorageHubUtil.checkNotifyMoveItemFromShare(sourceItemIsShared,
// sourceItem, sourceRootSharedFolderId,
// folderDestination, workspace, np);
} else {
// IS AN SHARED ITEM
if ( sourceShared instanceof org . gcube . common . storagehubwrapper . shared . tohl . WorkspaceSharedFolder )
np . notifyItemRenamed ( listSharedContact , previousName , wsItem ,
( org . gcube . common . storagehubwrapper . shared . tohl . WorkspaceSharedFolder ) sourceShared ,
workspace ) ;
// //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");
2018-11-28 16:50:18 +01:00
}
2019-02-22 11:44:01 +01:00
} catch ( Exception e ) {
2018-11-28 16:50:18 +01:00
workspaceLogger . error ( " An error occurred in checkNotify " , e ) ;
return true ;
}
}
return true ;
2019-02-22 11:44:01 +01:00
} catch ( WorkspaceFolderLocked e1 ) {
2018-11-28 16:50:18 +01:00
throw new Exception ( e1 . getMessage ( ) ) ;
} catch ( ItemAlreadyExistException e ) {
2019-02-22 11:44:01 +01:00
String error = " An error occurred on renaming item, " + e . getMessage ( ) ;
2018-11-28 16:50:18 +01:00
workspaceLogger . error ( error , e ) ;
throw new Exception ( error ) ;
2019-02-22 11:44:01 +01:00
} catch ( ItemNotFoundException e2 ) {
String error = " An error occurred on renaming item. " + ConstantsExplorer . ERROR_ITEM_DOES_NOT_EXIST ;
2018-11-28 16:50:18 +01:00
workspaceLogger . error ( error , e2 ) ;
throw new Exception ( error ) ;
2019-05-03 15:31:47 +02:00
//TO STORAGEHUB EXCEPTION
} catch ( UserNotAuthorizedException e ) {
String error = " Insufficient Privileges to rename the item " ;
workspaceLogger . error ( error , e ) ;
throw new Exception ( error ) ;
2018-11-28 16:50:18 +01:00
} catch ( Exception e ) {
2019-04-30 12:06:04 +02:00
workspaceLogger . error ( " Renaming item error: " , e ) ;
StringBuilder error = new StringBuilder ( ) ;
if ( sourceItemIsShared ) {
error . append ( " Ops! This operation is not allowed, we're working hard to make this possible soon. " ) ;
throw new SHUBOperationNotAllowedException ( error . toString ( ) ) ;
} else {
error . append ( " Ops an error occurred renaming the item! Either you have not the permission to rename it or a server error occurred. Please, refresh and try again " ) ;
throw new Exception ( error . toString ( ) ) ;
}
2018-11-28 16:50:18 +01:00
}
}
2019-02-22 11:44:01 +01:00
/ *
* ( non - Javadoc )
*
* @see org . gcube . portlets . user . workspace . client . rpc . GWTWorkspaceService #
* copyItems ( java . util . List , java . lang . String )
2018-11-28 16:50:18 +01:00
* /
/ * *
* Copy items .
*
2019-02-22 11:44:01 +01:00
* @param idsItem
* the ids item
* @param destinationFolderId
* the destination folder id
2018-11-28 16:50:18 +01:00
* @return the workspace operation result
2019-02-22 11:44:01 +01:00
* @throws Exception
* the exception
2018-11-28 16:50:18 +01:00
* /
@Override
public WorkspaceOperationResult copyItems ( List < String > idsItem , String destinationFolderId ) throws Exception {
2019-02-22 11:44:01 +01:00
workspaceLogger . debug ( " Copying ids: " + idsItem + " in the destionation folder: " + destinationFolderId ) ;
2018-11-28 16:50:18 +01:00
2019-02-22 11:44:01 +01:00
if ( isSessionExpired ( ) )
2018-11-28 16:50:18 +01:00
throw new SessionExpiredException ( ) ;
2019-02-22 11:44:01 +01:00
// boolean error = false;
2018-11-28 16:50:18 +01:00
WorkspaceOperationResult results = new WorkspaceOperationResult ( ) ;
results . setOperationName ( " Copy Items " ) ;
try {
checkItemLocked ( destinationFolderId ) ;
org . gcube . common . storagehubwrapper . server . tohl . Workspace workspace = getWorkspaceFromStorageHub ( ) ;
org . gcube . common . storagehubwrapper . shared . tohl . WorkspaceItem sourceItem = null ;
2019-02-22 11:44:01 +01:00
org . gcube . common . storagehubwrapper . shared . tohl . WorkspaceItem folderDestinationItem = workspace
. getItem ( destinationFolderId ) ;
2018-11-28 16:50:18 +01:00
NotificationsProducerToStorageHub np = getNotificationProducerToStorageHub ( ) ;
String sourceRootSharedId = null ;
for ( String itemId : idsItem ) {
2019-02-22 11:44:01 +01:00
try {
sourceItem = workspace . getItem ( itemId ) ; // GET SOURCE ITEM
// BEFORE COPY
2018-11-28 16:50:18 +01:00
2019-02-22 11:44:01 +01:00
// JUST ONCE. THE ROOT SHARED IS THE SAME FOR ALL ITEMS
if ( sourceItem . isShared ( ) & & sourceRootSharedId ! = null ) {
org . gcube . common . storagehubwrapper . shared . tohl . WorkspaceItem sourceShared = workspace
. getRootSharedFolder ( sourceItem . getId ( ) ) ;
2018-11-28 16:50:18 +01:00
sourceRootSharedId = sourceShared . getId ( ) ;
}
workspaceLogger . debug ( " Copying item with id: " + sourceItem . getId ( ) ) ;
2019-02-22 11:44:01 +01:00
org . gcube . common . storagehubwrapper . shared . tohl . WorkspaceItem copiedFile = workspace
. copyFile ( sourceItem . getId ( ) , destinationFolderId ) ; // copy
// item
2018-11-28 16:50:18 +01:00
workspaceLogger . debug ( " Copied item is: " + copiedFile ) ;
2019-02-22 11:44:01 +01:00
// final WorkspaceItem workspaceItem, final String
// sourceRootSharedFolderId, final WorkspaceFolder
// parentFolderItem,
// org.gcube.common.storagehubwrapper.server.tohl.Workspace
// workspace, NotificationsProducerToStorageHub np) {
NotificationStorageHubUtil . checkNotifyAddItemToShare ( copiedFile , sourceRootSharedId ,
( org . gcube . common . storagehubwrapper . shared . tohl . WorkspaceFolder ) folderDestinationItem ,
workspace , np ) ;
2018-11-28 16:50:18 +01:00
2019-02-22 11:44:01 +01:00
} catch ( Exception e ) {
2018-11-28 16:50:18 +01:00
String error = results . getError ( ) ;
2019-02-22 11:44:01 +01:00
if ( error = = null )
2018-11-28 16:50:18 +01:00
error = " Error on copying: " ;
2019-02-22 11:44:01 +01:00
error + = " " ;
error + = sourceItem ! = null ? sourceItem . getName ( ) : " item is null " ;
error + = " , " ;
2018-11-28 16:50:18 +01:00
results . setError ( error ) ;
}
}
2019-02-22 11:44:01 +01:00
// removing last ','
if ( results . getError ( ) ! = null )
results . setError ( results . getError ( ) . substring ( 0 , results . getError ( ) . length ( ) - 1 ) ) ;
2018-11-28 16:50:18 +01:00
2019-02-22 11:44:01 +01:00
workspaceLogger . info ( " Copied error: " + results . getError ( ) ) ;
2018-11-28 16:50:18 +01:00
2019-02-22 11:44:01 +01:00
if ( results . getError ( ) ! = null )
results . setError ( results . getError ( ) + " . Operation not allowed " ) ;
2018-11-28 16:50:18 +01:00
return results ;
2019-02-22 11:44:01 +01:00
} catch ( WorkspaceFolderLocked e1 ) {
2018-11-28 16:50:18 +01:00
throw new Exception ( e1 . getMessage ( ) ) ;
2019-02-22 11:44:01 +01:00
} catch ( InsufficientPrivilegesException e ) {
String error = " An error occurred on copying item, " + e . getMessage ( ) + " . " + ConstantsExplorer . TRY_AGAIN ;
2018-11-28 16:50:18 +01:00
throw new Exception ( error ) ;
2019-02-22 11:44:01 +01:00
} catch ( ItemAlreadyExistException e ) {
String error = " An error occurred on copying item, " + e . getMessage ( ) ;
2018-11-28 16:50:18 +01:00
throw new Exception ( error ) ;
} catch ( Exception e ) {
workspaceLogger . error ( " Error in server copyItem by id " , e ) ;
2019-02-22 11:44:01 +01:00
String error = ConstantsExplorer . SERVER_ERROR + " copying item " + ConstantsExplorer . TRY_AGAIN ;
2018-11-28 16:50:18 +01:00
throw new Exception ( error ) ;
}
}
2019-02-22 11:44:01 +01:00
/ *
* ( non - Javadoc )
*
* @see org . gcube . portlets . user . workspace . client . rpc . GWTWorkspaceService #
* getPublicLinkForFileItemId ( java . lang . String , boolean )
2018-11-28 16:50:18 +01:00
* /
/ * *
* Gets the public link for file item id .
*
2019-02-22 11:44:01 +01:00
* @param itemId
* the item id
* @param shortenUrl
* the shorten url
2018-11-28 16:50:18 +01:00
* @return the public link for file item id
2019-02-22 11:44:01 +01:00
* @throws Exception
* the exception
2018-11-28 16:50:18 +01:00
* /
@Override
2019-02-22 11:44:01 +01:00
public PublicLink getPublicLinkForFileItemId ( String itemId , boolean shortenUrl ) throws Exception {
2018-11-28 16:50:18 +01:00
2019-02-22 11:44:01 +01:00
workspaceLogger . trace ( " get Public Link For ItemId: " + itemId ) ;
try {
2018-11-28 16:50:18 +01:00
2019-02-22 11:44:01 +01:00
if ( itemId = = null )
2018-11-28 16:50:18 +01:00
throw new Exception ( " Sorry, The Public Link for empty item is unavailable (itemId is null) " ) ;
org . gcube . common . storagehubwrapper . server . tohl . Workspace workspace = getWorkspaceFromStorageHub ( ) ;
org . gcube . common . storagehubwrapper . shared . tohl . WorkspaceItem wsItem = workspace . getItem ( itemId ) ;
2019-02-22 11:44:01 +01:00
if ( wsItem = = null )
2018-11-28 16:50:18 +01:00
throw new Exception ( " Sorry, The Public Link for empty item is unavailable " ) ;
2019-02-22 11:44:01 +01:00
if ( wsItem . getType ( ) . equals ( org . gcube . common . storagehubwrapper . shared . tohl . WorkspaceItemType . FILE_ITEM ) ) {
2018-11-28 16:50:18 +01:00
URL publicLink = workspace . getPublicLinkForFile ( itemId ) ;
2019-02-22 11:44:01 +01:00
if ( publicLink = = null | | publicLink . toString ( ) = = null )
throw new Exception ( " Sorry, public link on " + wsItem . getName ( ) + " is not available " ) ;
2018-11-28 16:50:18 +01:00
String shortURL = null ;
String httpURL = publicLink . toString ( ) ;
2019-02-22 11:44:01 +01:00
if ( shortenUrl ) {
2018-11-28 16:50:18 +01:00
shortURL = getShortUrl ( httpURL ) ;
2019-02-22 11:44:01 +01:00
shortURL = shortURL ! = null ? shortURL : " not available " ;
2018-11-28 16:50:18 +01:00
}
return new PublicLink ( httpURL , shortURL ) ;
2019-02-22 11:44:01 +01:00
} else {
workspaceLogger . warn ( " ItemId: " + itemId + " is not a file, sent exception Public Link unavailable " ) ;
2018-11-28 16:50:18 +01:00
throw new Exception ( " Sorry, The Public Link for selected item is unavailable " ) ;
}
2019-02-22 11:44:01 +01:00
} catch ( Exception e ) {
workspaceLogger . error ( " Error getPublicLinkForFileItemId for item: " + itemId , e ) ;
2018-11-28 16:50:18 +01:00
throw new Exception ( e . getMessage ( ) ) ;
}
}
/ * *
* Gets the version history .
*
2019-02-22 11:44:01 +01:00
* @param fileIdentifier
* the file identifier
2018-11-28 16:50:18 +01:00
* @return the version history
2019-02-22 11:44:01 +01:00
* @throws Exception
* the exception
2018-11-28 16:50:18 +01:00
* /
@Override
2019-02-22 11:44:01 +01:00
public List < FileVersionModel > getVersionHistory ( String fileIdentifier ) throws Exception {
2018-11-28 16:50:18 +01:00
2019-02-22 11:44:01 +01:00
workspaceLogger . info ( " Calling get Version History of: " + fileIdentifier ) ;
2018-11-28 16:50:18 +01:00
2019-02-22 11:44:01 +01:00
if ( fileIdentifier = = null )
2018-11-28 16:50:18 +01:00
throw new Exception ( " File identifier is null " ) ;
try {
org . gcube . common . storagehubwrapper . server . tohl . Workspace workspace = getWorkspaceFromStorageHub ( ) ;
org . gcube . common . storagehubwrapper . shared . tohl . WorkspaceItem wsItem = workspace . getItem ( fileIdentifier ) ;
2019-02-22 11:44:01 +01:00
if ( wsItem . getType ( ) . equals ( org . gcube . common . storagehubwrapper . shared . tohl . WorkspaceItemType . FILE_ITEM ) ) {
2018-11-28 16:50:18 +01:00
List < WorkspaceFileVersion > listOfVersions = workspace . getListVersionsForFile ( fileIdentifier ) ;
StorageHubToWorkpaceConverter converter = getStorageHubToWorkpaceConverter ( ) ;
2019-02-22 11:44:01 +01:00
workspaceLogger
. info ( " Version list for " + fileIdentifier + " has " + listOfVersions . size ( ) + " item/s " ) ;
2018-11-28 16:50:18 +01:00
return converter . toVersionHistory ( listOfVersions ) ;
2019-02-22 11:44:01 +01:00
} else
2018-11-28 16:50:18 +01:00
throw new FileNotVersionedException ( " Selected file is not versioned " ) ;
2019-02-22 11:44:01 +01:00
} catch ( Exception e ) {
2018-11-28 16:50:18 +01:00
if ( e instanceof FileNotVersionedException )
throw new Exception ( e . getMessage ( ) ) ;
2019-02-22 11:44:01 +01:00
String error = " An error occurred when getting version history of: " + fileIdentifier + " , try again " ;
2018-11-28 16:50:18 +01:00
workspaceLogger . error ( error ) ;
throw new Exception ( error ) ;
}
}
2019-02-22 11:44:01 +01:00
/ *
* ( non - Javadoc )
*
* @see org . gcube . portlets . user . workspace . client . rpc . GWTWorkspaceService #
* getPublicLinkForFileItemIdToVersion ( java . lang . String , java . lang . String ,
* boolean )
2019-01-09 11:47:58 +01:00
* /
@Override
2019-02-22 11:44:01 +01:00
public PublicLink getPublicLinkForFileItemIdToVersion ( String itemId , String version , boolean shortenUrl )
throws Exception {
2019-01-09 11:47:58 +01:00
2019-02-22 11:44:01 +01:00
workspaceLogger . trace ( " get Public Link For ItemId: " + itemId + " at the version: " + version ) ;
try {
2019-01-09 11:47:58 +01:00
2019-02-22 11:44:01 +01:00
if ( itemId = = null )
2019-01-09 11:47:58 +01:00
throw new Exception ( " Sorry, The Public Link for empty item is unavailable (itemId is null) " ) ;
org . gcube . common . storagehubwrapper . server . tohl . Workspace workspace = getWorkspaceFromStorageHub ( ) ;
org . gcube . common . storagehubwrapper . shared . tohl . WorkspaceItem wsItem = workspace . getItem ( itemId ) ;
2019-02-22 11:44:01 +01:00
if ( wsItem = = null )
2019-01-09 11:47:58 +01:00
throw new Exception ( " Sorry, The Public Link for empty item is unavailable " ) ;
2019-02-22 11:44:01 +01:00
if ( wsItem . getType ( ) . equals ( org . gcube . common . storagehubwrapper . shared . tohl . WorkspaceItemType . FILE_ITEM ) ) {
2019-01-09 11:47:58 +01:00
URL publicLink = workspace . getPublicLinkForFile ( itemId , version ) ;
2019-02-22 11:44:01 +01:00
if ( publicLink = = null | | publicLink . toString ( ) = = null )
throw new Exception ( " Sorry, public link on " + wsItem . getName ( ) + " is not available " ) ;
2019-01-09 11:47:58 +01:00
String shortURL = null ;
String httpURL = publicLink . toString ( ) ;
2019-02-22 11:44:01 +01:00
if ( shortenUrl ) {
2019-01-09 11:47:58 +01:00
shortURL = getShortUrl ( httpURL ) ;
2019-02-22 11:44:01 +01:00
shortURL = shortURL ! = null ? shortURL : " not available " ;
2019-01-09 11:47:58 +01:00
}
return new PublicLink ( httpURL , shortURL ) ;
2019-02-22 11:44:01 +01:00
} else {
workspaceLogger . warn ( " ItemId: " + itemId + " is not a file, sent exception Public Link unavailable " ) ;
2019-01-09 11:47:58 +01:00
throw new Exception ( " Sorry, The Public Link for selected item is unavailable " ) ;
}
2019-02-22 11:44:01 +01:00
} catch ( Exception e ) {
workspaceLogger . error (
" Error getPublicLinkForFileItemIdToVersion for item: " + itemId + " at the version: " + version , e ) ;
2019-01-09 11:47:58 +01:00
throw new Exception ( e . getMessage ( ) ) ;
}
}
2019-04-17 11:42:48 +02:00
/ * *
* Gets the list parents by item identifier .
*
* @param itemIdentifier
* the item identifier
* @param includeItemAsParent
* - if parameter is true and item passed in input is a folder ,
* the folder is included in path returned as last parent
* @return the list parents by item identifier
* @throws Exception
* the exception
* /
@Override
public List < FileModel > getListParentsByItemIdentifier ( String itemIdentifier , boolean includeItemAsParent )
throws Exception {
workspaceLogger . debug ( " get List Parents by SHUB for id " + itemIdentifier
+ " , include Item As (Last) Parent: " + includeItemAsParent ) ;
if ( isSessionExpired ( ) )
throw new SessionExpiredException ( ) ;
if ( itemIdentifier = = null )
return new ArrayList < FileModel > ( ) ; // empty list
try {
org . gcube . common . storagehubwrapper . server . tohl . Workspace workspace = getWorkspaceFromStorageHub ( ) ;
StorageHubToWorkpaceConverter converter = getStorageHubToWorkpaceConverter ( ) ;
List < ? extends org . gcube . common . storagehubwrapper . shared . tohl . WorkspaceItem > parents = workspace . getParentsById ( itemIdentifier ) ;
workspaceLogger . info ( " The Parents returned by SHUB are: " + parents . size ( ) ) ;
if ( workspaceLogger . isTraceEnabled ( ) ) {
workspaceLogger . trace ( " They are: " ) ;
for ( org . gcube . common . storagehubwrapper . shared . tohl . WorkspaceItem workspaceItem : parents ) {
workspaceLogger . trace ( workspaceItem . getName ( ) ) ;
}
}
if ( parents . size ( ) = = 0 ) {
//IT IS THE ROOT
workspaceLogger . info ( " The item id " + itemIdentifier + " is the root, returning empty list " ) ;
return new ArrayList < FileModel > ( 1 ) ;
}
String nameSpecialFolder = getNameForSpecialFolder ( ) ;
List < FileModel > arrayParents = new ArrayList < FileModel > ( parents . size ( ) ) ;
//loop from last to first index of list of parents
int lastIndex = parents . size ( ) - 1 ;
for ( int i = lastIndex ; i > = 0 ; i - - ) {
org . gcube . common . storagehubwrapper . shared . tohl . WorkspaceItem wsFolder = parents . get ( i ) ;
workspaceLogger . trace ( " Adding the item " + wsFolder . getName ( ) + " at index " + i + " to list of parent " ) ;
org . gcube . common . storagehubwrapper . shared . tohl . WorkspaceItem parent = null ;
if ( i < lastIndex ) {
parent = parents . get ( i + 1 ) ;
workspaceLogger . trace ( " Passing the item " + parent . getName ( ) + " as parent of " + wsFolder . getName ( ) + " . Is it right? " ) ;
}
arrayParents . add ( converter . buildGXTFolderModelItemHandleSpecialFolder ( wsFolder , parent , nameSpecialFolder ) ) ;
workspaceLogger . trace ( " Added " + wsFolder . getName ( ) + " as parent to index " + ( arrayParents . size ( ) - 1 ) ) ;
}
if ( includeItemAsParent ) {
org . gcube . common . storagehubwrapper . shared . tohl . WorkspaceItem theItem = workspace . getItem ( itemIdentifier ) ;
if ( theItem . isFolder ( ) ) {
workspaceLogger . trace ( " The item passed is a folder, including it as last parent as requested " ) ;
2019-05-14 15:52:54 +02:00
FolderModel passedFolder = converter . buildGXTFolderModelItemHandleSpecialFolder ( theItem , parents . get ( parents . size ( ) - 1 ) , nameSpecialFolder ) ;
2019-04-17 11:42:48 +02:00
arrayParents . add ( passedFolder ) ;
}
}
// SET PARENTS
workspaceLogger . trace ( " setting parents.. " ) ;
for ( int i = 0 ; i < arrayParents . size ( ) - 1 ; i + + ) {
FileModel parent = arrayParents . get ( i ) ;
FileModel fileModel = arrayParents . get ( i + 1 ) ;
fileModel . setParentFileModel ( parent ) ;
}
workspaceLogger . trace ( " list parents returning size: " + arrayParents . size ( ) ) ;
//IS THIS CHECK ALREADY NEEDED?
if ( arrayParents . get ( 0 ) = = null ) { // EXIT BY BREAK IN CASE OF SPECIAL FOLDER
List < FileModel > breadcrumbs = new ArrayList < FileModel > ( arrayParents . size ( ) - 1 ) ;
for ( int i = 1 ; i < arrayParents . size ( ) ; i + + ) {
breadcrumbs . add ( arrayParents . get ( i ) ) ;
}
return breadcrumbs ;
} else
return arrayParents ;
} catch ( Exception e ) {
workspaceLogger . error ( " Error in get List Parents By Item Identifier " , e ) ;
e . printStackTrace ( ) ;
throw new Exception ( e . getMessage ( ) ) ;
}
}
2019-01-09 11:47:58 +01:00
2013-02-06 15:40:17 +01:00
}