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 ;
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
2016-09-19 12:17:33 +02:00
import org.gcube.common.encryption.StringEncrypter ;
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 ;
2019-09-13 16:48:26 +02:00
import org.gcube.common.storagehub.model.items.nodes.accounting.AccountEntry ;
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 ;
2019-09-13 16:48:26 +02:00
import org.gcube.common.storagehubwrapper.shared.tohl.items.ImageFileItem ;
import org.gcube.common.storagehubwrapper.shared.tohl.items.PropertyMap ;
import org.gcube.common.storagehubwrapper.shared.tohl.items.URLFileItem ;
import org.gcube.common.storagehubwrapper.shared.tohl.items.URLItem ;
2018-03-28 12:42:50 +02:00
import org.gcube.portal.wssynclibrary.shared.ItemNotSynched ;
import org.gcube.portal.wssynclibrary.shared.WorkspaceFolderLocked ;
2021-05-12 16:33:37 +02:00
import org.gcube.portal.wssynclibrary.shared.thredds.ThSyncFolderDescriptor ;
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 ;
2013-02-06 15:40:17 +01:00
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.SubTree ;
import org.gcube.portlets.user.workspace.client.rpc.GWTWorkspaceService ;
import org.gcube.portlets.user.workspace.client.workspace.GWTWorkspaceItem ;
2019-09-13 16:48:26 +02:00
import org.gcube.portlets.user.workspace.client.workspace.folder.item.GWTExternalUrl ;
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 ;
2019-09-13 16:48:26 +02:00
import org.gcube.portlets.user.workspace.server.tostoragehub.FormatterUtil ;
import org.gcube.portlets.user.workspace.server.tostoragehub.ObjectStorageHubToWorkpaceMapper ;
2018-11-28 16:50:18 +01:00
import org.gcube.portlets.user.workspace.server.tostoragehub.StorageHubToWorkpaceConverter ;
2020-07-28 15:02:19 +02:00
import org.gcube.portlets.user.workspace.server.util.MimeTypeUtility ;
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 ;
2020-05-19 17:22:22 +02:00
import org.gcube.portlets.user.workspace.shared.TrashOperationError ;
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-09-13 16:48:26 +02:00
import org.gcube.portlets.widgets.workspacesharingwidget.server.notifications.NotificationsProducer ;
2019-02-22 11:44:01 +01:00
import org.gcube.portlets.widgets.workspacesharingwidget.shared.InfoContactModel ;
2021-05-18 15:34:43 +02:00
import org.gcube.portlets.widgets.wsthreddssync.server.ThreddsWorkspaceSyncServiceImpl ;
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 ;
2021-05-12 16:33:37 +02:00
import org.gcube.usecases.ws.thredds.faults.WorkspaceNotSynchedException ;
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 ;
2019-09-13 16:48:26 +02:00
import org.slf4j.Logger ;
import org.slf4j.LoggerFactory ;
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
2020-05-19 17:22:22 +02:00
// TODO: Auto-generated Javadoc
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-09-13 16:48:26 +02:00
* @author Francesco Mangiacrapa at ISTI - CNR ( francesco . mangiacrapa @isti.cnr.it )
*
2021-05-18 15:34:43 +02:00
* Aug 1 , 2019
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
2020-03-13 11:20:18 +01:00
public static final String JCR_WILDCARD_TO_SEARCH = " % " ;
2021-05-18 15:34:43 +02:00
public static final String CHAR_FOR_SEARCHING_WITH_EXACTLY_MATCH = " \" " ; // is double quote
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 " ;
2019-09-13 16:48:26 +02:00
protected Logger workspaceLogger = LoggerFactory . getLogger ( GWTWorkspaceServiceImpl . class ) ;
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
}
2021-05-18 15:34:43 +02: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-07-29 15:27:34 +02:00
/ * *
* Gets the name for special folder .
*
* @return the name for special folder
* /
private String getNameForSpecialFolder ( ) {
PropertySpecialFolderReader sfReader = getPropertySpecialFolderReader ( ) ;
if ( sfReader = = null ) {
workspaceLogger . warn ( " Reader is null, skypping set to special folder name " ) ;
return " " ;
}
workspaceLogger
. info ( " Read special folder name: ' " + sfReader . getSpecialFolderName ( ) + " ', from property file.. " ) ;
return sfReader . getSpecialFolderName ( ) ;
}
2019-09-13 16:48:26 +02:00
2017-02-20 11:41:54 +01:00
/ * *
2019-09-13 16:48:26 +02:00
* Gets the servlet context path .
2017-02-20 11:41:54 +01:00
*
2021-05-18 15:34:43 +02:00
* @param protocol the protocol
2019-09-13 16:48:26 +02:00
* @return the servlet context path
2017-02-20 11:41:54 +01:00
* /
2013-02-06 15:40:17 +01:00
@Override
2019-09-13 16:48:26 +02:00
public String getServletContextPath ( String protocol ) {
HttpServletRequest req = getThreadLocalRequest ( ) ;
2013-02-06 15:40:17 +01:00
2019-09-13 16:48:26 +02:00
String scheme = protocol ;
2016-01-19 15:50:40 +01:00
2019-09-13 16:48:26 +02:00
String serverName = req . getServerName ( ) ; // hostname.com
int serverPort = req . getServerPort ( ) ; // 80
String contextPath = req . getServletContext ( ) . getContextPath ( ) ; // /mywebapp
2016-01-19 15:50:40 +01:00
2019-09-13 16:48:26 +02:00
// Reconstruct original requesting URL
StringBuffer url = new StringBuffer ( ) ;
url . append ( scheme ) . append ( " // " ) . append ( serverName ) ;
2014-05-12 14:29:29 +02:00
2019-09-13 16:48:26 +02:00
if ( serverPort ! = 80 & & serverPort ! = 443 ) {
url . append ( " : " ) . append ( serverPort ) ;
}
2016-01-19 15:50:40 +01:00
2019-09-13 16:48:26 +02:00
workspaceLogger . debug ( " server: " + url ) ;
workspaceLogger . debug ( " omitted contextPath: " + contextPath ) ;
2016-01-19 15:50:40 +01:00
2019-09-13 16:48:26 +02:00
url . append ( contextPath ) ;
workspaceLogger . debug ( " getServletContextPath= " + url . toString ( ) ) ;
return url . toString ( ) ;
2013-02-06 15:40:17 +01:00
}
2016-01-19 15:50:40 +01:00
2018-11-28 16:50:18 +01:00
/ * *
2019-09-13 16:48:26 +02:00
* Checks if is item under sync .
2018-11-28 16:50:18 +01:00
*
2021-05-12 16:33:37 +02:00
* @param itemId the item id
2019-09-13 16:48:26 +02:00
* @return true , if is item under sync
2021-05-12 16:33:37 +02:00
* @throws Exception the exception
2018-11-28 16:50:18 +01:00
* /
@Override
2019-09-13 16:48:26 +02:00
public Boolean isItemUnderSync ( String itemId ) throws Exception {
2018-09-14 15:42:36 +02:00
2021-05-12 16:33:37 +02:00
ThSyncFolderDescriptor theConfig = null ;
2018-11-28 16:50:18 +01:00
try {
2021-05-12 16:33:37 +02:00
2019-09-13 16:48:26 +02:00
try {
2021-05-12 16:33:37 +02:00
theConfig = WorkspaceThreddsSynchronize . getInstance ( ) . getConfiguration ( itemId ) ;
} catch ( WorkspaceNotSynchedException e ) {
workspaceLogger
. debug ( " WorkspaceNotSynchedException catched, the item with id: " + itemId + " is not synched " ) ;
return false ;
2019-09-13 16:48:26 +02:00
} catch ( Exception e ) {
2021-05-12 16:33:37 +02:00
workspaceLogger . debug ( " Error on getting configuration for the item id: " + itemId
+ " , returning null (means not synched) " ) ;
return false ;
}
if ( theConfig = = null ) {
workspaceLogger . debug (
" No ws-thredds config found the item with id: " + itemId + " , returning item is not synched " ) ;
2019-09-13 16:48:26 +02:00
return false ;
2015-09-18 16:51:38 +02:00
}
2021-05-12 16:33:37 +02:00
// HERE THE ITEM IS SYNCHED SO CHECKING IF IT IS LOCKED
2019-09-13 16:48:26 +02:00
checkItemLocked ( itemId ) ;
return false ;
2016-01-19 15:50:40 +01:00
2019-09-13 16:48:26 +02:00
} catch ( WorkspaceFolderLocked e1 ) {
return true ;
2013-02-06 15:40:17 +01:00
} catch ( Exception e ) {
2019-09-13 16:48:26 +02:00
throw new Exception ( " Error on checking item " + itemId + " is under sync " ) ;
2013-02-06 15:40:17 +01:00
}
}
2021-05-18 15:34:43 +02:00
2019-02-22 11:44:01 +01:00
/ *
* ( non - Javadoc )
*
* @see org . gcube . portlets . user . workspace . client . rpc . GWTWorkspaceService #
2019-09-13 16:48:26 +02:00
* getMyLogin ( )
2015-03-06 16:12:21 +01:00
* /
2017-02-20 11:41:54 +01:00
/ * *
2019-09-13 16:48:26 +02:00
* Gets the my login .
2017-02-20 11:41:54 +01:00
*
2021-05-18 15:34:43 +02:00
* @param currentPortletUrl the current portlet url
2019-09-13 16:48:26 +02:00
* @return the my login
2017-02-20 11:41:54 +01:00
* /
2013-02-06 15:40:17 +01:00
@Override
2019-09-13 16:48:26 +02:00
public UserBean getMyLogin ( String currentPortletUrl ) {
2021-05-18 15:34:43 +02:00
2019-09-13 16:48:26 +02:00
PortalContextInfo info = WsUtil . getPortalContext ( this . getThreadLocalRequest ( ) ) ;
String username = info . getUsername ( ) ;
String email = info . getUserEmail ( ) ;
String firstName = " Testing " ;
String lastName = " User " ;
2016-01-19 15:50:40 +01:00
2019-09-13 16:48:26 +02:00
if ( isWithinPortal ( ) & & username ! = null ) {
try {
LiferayUserManager l = new LiferayUserManager ( ) ;
GCubeUser user = l . getUserByUsername ( username ) ;
firstName = user . getFirstName ( ) ;
lastName = user . getLastName ( ) ;
email = user . getEmail ( ) ;
} catch ( UserManagementSystemException e ) {
workspaceLogger . error ( " UserManagementSystemException for username: " + username ) ;
} catch ( UserRetrievalFault e ) {
workspaceLogger . error ( " UserRetrievalFault for username: " + username ) ;
2013-02-06 15:40:17 +01:00
2019-09-13 16:48:26 +02:00
} catch ( Exception e ) {
workspaceLogger . error ( " Error during getMyLogin for username: " + username , e ) ;
}
2016-01-19 15:50:40 +01:00
2013-02-06 15:40:17 +01:00
}
2016-01-19 15:50:40 +01:00
2019-09-13 16:48:26 +02:00
UserBean us = new UserBean ( username , firstName , lastName , email ) ;
workspaceLogger . info ( " Returning myLogin: " + us ) ;
return us ;
2013-02-06 15:40:17 +01:00
}
2015-03-06 16:12:21 +01:00
/ * *
2019-09-13 16:48:26 +02:00
* Gets the CLARIN switch board endpoint .
2015-03-06 16:12:21 +01:00
*
2019-09-13 16:48:26 +02:00
* @return the CLARIN switch board endpoint
2015-03-06 16:12:21 +01:00
* /
2019-09-13 16:48:26 +02:00
private String getCLARINSwitchBoardEndpoint ( ) {
// save the context for this resource
String currContext = ScopeProvider . instance . get ( ) ;
// set the context for this resource
ScopeProvider . instance . set ( " / " + PortalContext . getConfiguration ( ) . getInfrastructureName ( ) ) ;
2015-06-24 16:56:13 +02:00
2019-09-13 16:48:26 +02:00
// construct the xquery
SimpleQuery query = queryFor ( ServiceEndpoint . class ) ;
query . addCondition (
" $resource/Profile/Name/text() eq ' " + ConstantsExplorer . CLARIN_SWITCHBOARD_ENDPOINT_NAME + " ' " ) ;
query . addCondition ( " $resource/Profile/Category/text() eq ' "
+ ConstantsExplorer . CLARIN_SWITCHBOARD_ENDPOINT_CATEGORY + " ' " ) ;
2016-01-19 15:50:40 +01:00
2019-09-13 16:48:26 +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 ) ;
// reset the context
ScopeProvider . instance . set ( currContext ) ;
return res . profile ( ) . runtime ( ) . hostedOn ( ) ;
2016-06-22 18:41:51 +02:00
}
2021-05-18 15:34:43 +02:00
2019-02-22 11:44:01 +01:00
/ *
* ( non - Javadoc )
*
* @see org . gcube . portlets . user . workspace . client . rpc . GWTWorkspaceService #
2019-09-13 16:48:26 +02:00
* getMyLogin ( )
2015-03-06 16:12:21 +01:00
* /
2017-02-20 11:41:54 +01:00
/ * *
2019-09-13 16:48:26 +02:00
* Gets the my first name .
2017-02-20 11:41:54 +01:00
*
2019-09-13 16:48:26 +02:00
* @return the my first name
2017-02-20 11:41:54 +01:00
* /
2013-02-06 15:40:17 +01:00
@Override
2019-09-13 16:48:26 +02:00
public String getMyFirstName ( ) {
if ( ! isWithinPortal ( ) )
return " " ;
2015-10-12 15:30:59 +02:00
2019-09-13 16:48:26 +02:00
PortalContextInfo info = WsUtil . getPortalContext ( this . getThreadLocalRequest ( ) ) ;
String username = info . getUsername ( ) ;
String firstName = " " ;
if ( isWithinPortal ( ) & & username ! = null ) {
try {
LiferayUserManager l = new LiferayUserManager ( ) ;
GCubeUser user = l . getUserByUsername ( username ) ;
workspaceLogger . info ( " My login first name is: " + user . getFirstName ( ) ) ;
firstName = user . getFirstName ( ) ;
} catch ( UserManagementSystemException e ) {
workspaceLogger . error ( " UserManagementSystemException for username: " + username ) ;
} catch ( UserRetrievalFault e ) {
workspaceLogger . error ( " UserRetrievalFault for username: " + username ) ;
2015-10-12 15:30:59 +02:00
}
2016-01-19 15:50:40 +01:00
2013-02-06 15:40:17 +01:00
}
2019-09-13 16:48:26 +02:00
return firstName ;
2013-02-06 15:40:17 +01:00
}
2021-05-18 15:34:43 +02:00
2019-02-22 11:44:01 +01:00
/ *
* ( non - Javadoc )
*
* @see org . gcube . portlets . user . workspace . client . rpc . GWTWorkspaceService #
2019-09-13 16:48:26 +02:00
* isSessionExpired ( )
2015-03-06 16:12:21 +01:00
* /
2017-02-20 11:41:54 +01:00
/ * *
2019-09-13 16:48:26 +02:00
* Checks if is session expired .
2017-02-20 11:41:54 +01:00
*
2019-09-13 16:48:26 +02:00
* @return true , if is session expired
2021-05-18 15:34:43 +02:00
* @throws Exception the exception
2017-02-20 11:41:54 +01:00
* /
2013-02-06 15:40:17 +01:00
@Override
2019-09-13 16:48:26 +02:00
public boolean isSessionExpired ( ) throws Exception {
return WsUtil . isSessionExpired ( this . getThreadLocalRequest ( ) ) ;
}
2016-01-19 15:50:40 +01:00
2019-09-13 16:48:26 +02:00
/ * *
* Checks if is within portal .
*
* @return true if you ' re running into the portal , false if in development
* /
private boolean isWithinPortal ( ) {
2013-02-06 15:40:17 +01:00
try {
2019-09-13 16:48:26 +02:00
UserLocalServiceUtil . getService ( ) ;
2013-02-06 15:40:17 +01:00
return true ;
2019-09-13 16:48:26 +02:00
} catch ( Exception ex ) {
workspaceLogger . trace ( " Development Mode ON " ) ;
return false ;
2013-02-06 15:40:17 +01:00
}
}
2016-01-19 15:50:40 +01:00
2017-02-20 11:41:54 +01:00
/ * *
2019-09-13 16:48:26 +02:00
* Gets the workspace from storage hub .
2017-02-20 11:41:54 +01:00
*
2019-09-13 16:48:26 +02:00
* @return the workspace from storage hub
2021-05-18 15:34:43 +02:00
* @throws Exception the exception
2017-02-20 11:41:54 +01:00
* /
2019-09-13 16:48:26 +02:00
protected org . gcube . common . storagehubwrapper . server . tohl . Workspace getWorkspaceFromStorageHub ( ) throws Exception {
GCubeUser user = PortalContext . getConfiguration ( ) . getCurrentUser ( this . getThreadLocalRequest ( ) ) ;
StorageHubWrapper storageHubWrapper = WsUtil . getStorageHubWrapper ( this . getThreadLocalRequest ( ) , null , user ) ;
return storageHubWrapper . getWorkspace ( ) ;
2013-02-06 15:40:17 +01:00
}
2017-02-20 11:41:54 +01:00
/ * *
2019-09-13 16:48:26 +02:00
* Gets the storage hub to workpace converter .
2017-02-20 11:41:54 +01:00
*
2019-09-13 16:48:26 +02:00
* @return the storage hub to workpace converter
2021-05-18 15:34:43 +02:00
* @throws Exception the exception
2017-02-20 11:41:54 +01:00
* /
2019-09-13 16:48:26 +02:00
protected StorageHubToWorkpaceConverter getStorageHubToWorkpaceConverter ( ) throws Exception {
GCubeUser user = PortalContext . getConfiguration ( ) . getCurrentUser ( this . getThreadLocalRequest ( ) ) ;
StorageHubToWorkpaceConverter converter = WsUtil . getStorageHubToWorkpaceConverter ( this . getThreadLocalRequest ( ) ,
null , user ) ;
// SETTING ROOT ID JUST ONCE
if ( converter . getWorkspaceRootId ( ) = = null ) {
org . gcube . common . storagehubwrapper . server . tohl . Workspace ws = getWorkspaceFromStorageHub ( ) ;
converter . setWorkspaceRootId ( ws . getRoot ( ) . getId ( ) ) ;
2013-02-06 15:40:17 +01:00
}
2013-10-04 13:58:07 +02:00
2019-09-13 16:48:26 +02:00
return converter ;
2013-02-06 15:40:17 +01:00
}
2016-01-19 15:50:40 +01:00
2017-02-20 11:41:54 +01:00
/ * *
2019-09-13 16:48:26 +02:00
* Gets the notification producer to storage hub .
2017-02-20 11:41:54 +01:00
*
2019-09-13 16:48:26 +02:00
* @return the notification producer to storage hub
2015-05-20 18:39:49 +02:00
* /
2019-09-13 16:48:26 +02:00
protected NotificationsProducerToStorageHub getNotificationProducerToStorageHub ( ) {
2016-01-19 15:50:40 +01:00
2019-09-13 16:48:26 +02:00
return WsUtil . getNotificationProducerToStorageHub ( this . getThreadLocalRequest ( ) ) ;
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 #
2019-09-13 16:48:26 +02:00
* getRootForTree ( )
2015-03-06 16:12:21 +01:00
* /
2017-02-20 11:41:54 +01:00
/ * *
2019-09-13 16:48:26 +02:00
* Gets the root for tree .
2017-02-20 11:41:54 +01:00
*
2019-09-13 16:48:26 +02:00
* @return the root for tree
2021-05-18 15:34:43 +02:00
* @throws Exception the exception
2017-02-20 11:41:54 +01:00
* /
2013-02-06 15:40:17 +01:00
@Override
2019-09-13 16:48:26 +02:00
public FolderModel getRootForTree ( ) throws Exception {
workspaceLogger . trace ( " getRoot " ) ;
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-09-13 16:48:26 +02:00
org . gcube . common . storagehubwrapper . server . tohl . Workspace workspace = getWorkspaceFromStorageHub ( ) ;
org . gcube . common . storagehubwrapper . shared . tohl . WorkspaceFolder root = workspace . getRoot ( ) ;
2016-01-19 15:50:40 +01:00
2019-09-13 16:48:26 +02:00
if ( root = = null ) {
workspaceLogger . error ( " The root is null " ) ;
throw new Exception ( " The root is null " ) ;
}
2016-01-19 15:50:40 +01:00
2019-09-13 16:48:26 +02:00
workspaceLogger . trace ( " Root converted, returning... " ) ;
StorageHubToWorkpaceConverter converter = getStorageHubToWorkpaceConverter ( ) ;
return converter . toRootFolder ( root ) ;
2013-02-06 15:40:17 +01:00
} catch ( Exception e ) {
2019-09-13 16:48:26 +02:00
workspaceLogger . error ( " Error in server during root retrieving " , e ) ;
// workspaceLogger.trace("Error in server During root retrieving " +
// e);
2019-02-22 11:44:01 +01:00
// GWT can't serialize all exceptions
2019-09-13 16:48:26 +02:00
throw new Exception ( " Error during workspace loading, please contact the support. Exception: " + e ) ;
2013-02-06 15:40:17 +01:00
}
}
2017-02-20 11:41:54 +01:00
/ * *
2019-09-13 16:48:26 +02:00
* Delete item .
2017-02-20 11:41:54 +01:00
*
2021-05-18 15:34:43 +02:00
* @param itemId the item id
2019-09-13 16:48:26 +02:00
* @return the boolean
2021-05-18 15:34:43 +02:00
* @throws Exception the exception
2017-02-20 11:41:54 +01:00
* /
2013-02-06 15:40:17 +01:00
@Override
2019-09-13 16:48:26 +02:00
public Boolean deleteItem ( String itemId ) throws Exception {
2016-01-19 15:50:40 +01:00
2019-09-13 16:48:26 +02:00
org . gcube . common . storagehubwrapper . shared . tohl . WorkspaceItem theItem = null ;
2016-06-22 18:41:51 +02:00
try {
2021-05-18 15:34:43 +02:00
workspaceLogger . error ( " called deleteItem: " + itemId ) ;
2019-09-13 16:48:26 +02:00
if ( itemId = = null )
throw new Exception ( IDENTIFIER_IS_NULL ) ;
2016-01-19 15:50:40 +01:00
2019-09-13 16:48:26 +02:00
checkItemLocked ( itemId ) ;
2016-01-19 15:50:40 +01:00
2019-09-13 16:48:26 +02:00
org . gcube . common . storagehubwrapper . server . tohl . Workspace workspaceSH = getWorkspaceFromStorageHub ( ) ;
theItem = workspaceSH . getItem ( itemId ) ;
String itemName = theItem . getName ( ) ;
String sourceFolderSharedId = null ;
2018-03-28 12:42:50 +02:00
2019-09-13 16:48:26 +02:00
if ( theItem . isShared ( ) ) {
org . gcube . common . storagehubwrapper . shared . tohl . WorkspaceItem rootSharedFolder = workspaceSH
. getRootSharedFolder ( itemId ) ;
sourceFolderSharedId = rootSharedFolder . getId ( ) ;
}
// HERE REMOVING THE ITEM
workspaceLogger . info ( " Calling storageHub to delete item with id: " + itemId ) ;
workspaceSH . deleteItem ( itemId ) ;
2021-05-18 15:34:43 +02:00
2019-09-13 16:48:26 +02:00
NotificationsProducerToStorageHub np = getNotificationProducerToStorageHub ( ) ;
if ( sourceFolderSharedId ! = null )
2021-05-18 15:34:43 +02:00
NotificationStorageHubUtil . checkSendNotifyRemovedItemFromShare ( this . getThreadLocalRequest ( ) ,
theItem . isShared ( ) , itemName , itemId , sourceFolderSharedId , workspaceSH , np ) ;
2018-03-06 14:37:32 +01:00
2019-09-13 16:48:26 +02:00
return Boolean . TRUE ;
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 ( ) ) ;
2019-09-13 16:48:26 +02:00
// } catch (InsufficientPrivilegesException e) {
// workspaceLogger.error("Error in server Item remove", e);
// String error = "Insufficient Privileges to remove the item";
// throw new Exception(error);
//
// } catch (ItemNotFoundException e) {
// String error = "An error occurred on deleting item. " + ConstantsExplorer.ERROR_ITEM_DOES_NOT_EXIST;
// workspaceLogger.error(error, e);
// throw new Exception(error);
//
// //TO STORAGEHUB EXCEPTION
// } catch (UserNotAuthorizedException e) {
// String error = "Insufficient Privileges to delete the item";
// workspaceLogger.error(error, e);
// throw new Exception(error);
2013-02-06 15:40:17 +01:00
} catch ( Exception e ) {
2019-09-13 16:48:26 +02:00
workspaceLogger . error ( " Removing item error: " , e ) ;
StringBuilder error = new StringBuilder ( ) ;
2021-05-18 15:34:43 +02:00
if ( theItem ! = null & & theItem . isShared ( ) ) {
if ( theItem . isFolder ( ) ) {
error . append (
" Deleting shared folders is not supported. Please unshare it if your intent is to no longer share its content with your coworkers. " ) ;
} else {
2019-09-13 16:48:26 +02:00
error . append ( " Ops! This operation is not allowed, we're working hard to make this possible soon. " ) ;
}
throw new SHUBOperationNotAllowedException ( error . toString ( ) ) ;
2021-05-18 15:34:43 +02:00
} 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 " ) ;
2019-09-13 16:48:26 +02:00
throw new Exception ( error . toString ( ) ) ;
}
2013-02-06 15:40:17 +01:00
}
2016-01-19 15:50:40 +01:00
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 #
2019-09-13 16:48:26 +02:00
* getFolderChildren ( org . gcube . portlets . user . workspace . client . model .
* FolderModel )
2015-03-06 16:12:21 +01:00
* /
2017-02-20 11:41:54 +01:00
/ * *
2019-09-13 16:48:26 +02:00
* Gets the folder children .
2017-02-20 11:41:54 +01:00
*
2021-05-18 15:34:43 +02:00
* @param folder the folder
2019-09-13 16:48:26 +02:00
* @return the folder children
2021-05-18 15:34:43 +02:00
* @throws Exception the exception
* @throws SessionExpiredException the session expired exception
2017-02-20 11:41:54 +01:00
* /
2013-02-06 15:40:17 +01:00
@Override
2019-09-13 16:48:26 +02:00
public List < FileModel > getFolderChildren ( FolderModel folder ) throws Exception , SessionExpiredException {
2021-05-18 15:34:43 +02:00
2019-09-13 16:48:26 +02:00
org . gcube . common . storagehubwrapper . server . tohl . Workspace shWorkspace ;
2013-02-06 15:40:17 +01:00
2019-09-13 16:48:26 +02:00
if ( isSessionExpired ( ) )
throw new SessionExpiredException ( ) ;
2016-01-19 15:50:40 +01:00
2013-02-06 15:40:17 +01:00
try {
2016-01-19 15:50:40 +01:00
2019-09-13 16:48:26 +02:00
if ( folder = = null )
throw new Exception ( " Folder is null " ) ;
2013-03-27 17:30:37 +01:00
2021-05-18 15:34:43 +02:00
workspaceLogger . info ( " Get FolderChildren called for folder: " + folder . getIdentifier ( ) ) ;
2019-09-13 16:48:26 +02:00
shWorkspace = getWorkspaceFromStorageHub ( ) ;
2016-01-19 15:50:40 +01:00
2019-09-13 16:48:26 +02:00
// REMEMBER wsItem.isRoot() is always false;
// 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 ) ;
2021-05-18 15:34:43 +02:00
workspaceLogger . info ( " The children are: " + children . size ( ) ) ;
2019-09-13 16:48:26 +02:00
for ( org . gcube . common . storagehubwrapper . shared . tohl . WorkspaceItem workspaceItem : children ) {
workspaceLogger
. trace ( " The ITEM: " + workspaceItem . getName ( ) + " , is shared: " + workspaceItem . isShared ( )
+ " , is folder: " + workspaceItem . isFolder ( ) + " the id: " + workspaceItem . getId ( ) ) ;
}
StorageHubToWorkpaceConverter converter = getStorageHubToWorkpaceConverter ( ) ;
List < FileModel > listFileModels = new ArrayList < FileModel > ( children . size ( ) ) ;
// boolean isParentShared =
// workspace.isItemShared(folder.getIdentifier()); //removed for
// optimization
boolean isParentShared = folder . isShared ( ) ;
for ( org . gcube . common . storagehubwrapper . shared . tohl . WorkspaceItem workspaceItem : children ) {
// 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 ) ) ;
// }
}
boolean isRoot = WsUtil . isRootFolder ( folder , converter ) ;
2021-05-18 15:34:43 +02:00
workspaceLogger . info ( " Is the workspace folder " + folder . getName ( ) + " with id: " + folder . getIdentifier ( )
+ " the root? " + isRoot ) ;
2019-09-13 16:48:26 +02:00
// ADDING VRE FOLDER?
if ( isRoot ) {
folder . setIsRoot ( true ) ;
// ADD VRE FOLDER
try {
String vreFolderId = shWorkspace . getVREFoldersId ( ) ;
org . gcube . common . storagehubwrapper . shared . tohl . WorkspaceItem baseVREFolder = shWorkspace
. getItem ( vreFolderId ) ;
FileModel specialFolderModel = converter . toTreeFileModel ( baseVREFolder , folder , false ) ;
specialFolderModel . setSpecialFolder ( true ) ;
String newName = getNameForSpecialFolder ( ) ;
if ( ! newName . isEmpty ( ) ) {
workspaceLogger . info ( " Special folder name updated as: " + newName ) ;
specialFolderModel . setName ( newName ) ;
} else
workspaceLogger . info ( " Special folder name is empty, skipping " ) ;
listFileModels . add ( specialFolderModel ) ;
} catch ( Exception e ) {
workspaceLogger . warn (
" An error occurred on retrieving special folders for folder id: " + folder . getIdentifier ( ) ,
e ) ;
}
}
workspaceLogger . info ( " Returning " + listFileModels . size ( ) + " tree item/s " ) ;
/ *
* int i = 0 ; for ( FileModel fileModel : listFileModels ) {
* System . out . println ( i + + + " ) " + fileModel ) ; }
* /
// if(!WsUtil.isWithinPortal()){
// workspaceLogger.trace("Sleeping 4 sec...");
// Thread.sleep(4000);
// }
return listFileModels ;
} catch ( Exception e ) {
workspaceLogger . error ( " Error in server During item retrieving " , e ) ;
// workspaceLogger.trace("Error in server During item 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
2019-09-13 16:48:26 +02:00
throw new Exception ( error ) ;
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 #
2019-09-13 16:48:26 +02:00
* getFolderChildrenForFileGrid ( org . gcube . portlets . user . workspace . client .
* model . FileModel )
2015-09-18 15:26:33 +02:00
* /
2017-02-20 11:41:54 +01:00
/ * *
2019-09-13 16:48:26 +02:00
* Gets the folder children for file grid .
2017-02-20 11:41:54 +01:00
*
2021-05-18 15:34:43 +02:00
* @param folder the folder
2019-09-13 16:48:26 +02:00
* @return the folder children for file grid
2021-05-18 15:34:43 +02:00
* @throws Exception the exception
* @throws SessionExpiredException the session expired
* exceptionworkspaceLogger . info ( " The children
* are : " +children.size());
2017-02-20 11:41:54 +01:00
* /
2015-09-18 15:26:33 +02:00
@Override
2019-09-13 16:48:26 +02:00
public List < FileGridModel > getFolderChildrenForFileGrid ( FileModel folder )
throws Exception , SessionExpiredException {
2021-05-18 15:34:43 +02:00
2019-09-13 16:48:26 +02:00
if ( isSessionExpired ( ) )
throw new SessionExpiredException ( ) ;
2016-01-19 15:50:40 +01:00
2013-02-06 15:40:17 +01:00
try {
2016-01-19 15:50:40 +01:00
2019-09-13 16:48:26 +02:00
if ( folder = = null )
throw new Exception ( " Folder is null " ) ;
2021-05-18 15:34:43 +02:00
workspaceLogger . info ( " Get FolderChildrenForFileGrid called for folder: " + folder . getIdentifier ( ) ) ;
2019-09-13 16:48:26 +02:00
org . gcube . common . storagehubwrapper . server . tohl . Workspace shWorkspace = getWorkspaceFromStorageHub ( ) ;
List < ? extends org . gcube . common . storagehubwrapper . shared . tohl . WorkspaceItem > children = shWorkspace
. getChildren ( folder . getIdentifier ( ) ) ;
2019-02-22 11:44:01 +01:00
2021-05-18 15:34:43 +02:00
workspaceLogger . info ( " The children are: " + children . size ( ) ) ;
2019-09-13 16:48:26 +02:00
StorageHubToWorkpaceConverter converter = getStorageHubToWorkpaceConverter ( ) ;
List < FileGridModel > listFileGridModels = new ArrayList < FileGridModel > ( children . size ( ) ) ;
// boolean isParentShared = folder.isShared();
for ( org . gcube . common . storagehubwrapper . shared . tohl . WorkspaceItem workspaceItem : children ) {
workspaceLogger
. debug ( " Converting grid item: " + workspaceItem . getId ( ) + " name " + workspaceItem . getName ( ) ) ;
listFileGridModels . add ( converter . toGridFileModel ( workspaceItem , folder ) ) ;
}
2013-02-06 15:40:17 +01:00
2019-09-13 16:48:26 +02:00
boolean isRoot = WsUtil . isRootFolder ( folder , converter ) ;
workspaceLogger . debug ( " ****** IS ROOT? " + isRoot ) ;
// ADDING VRE FOLDER?
if ( isRoot ) {
folder . setIsRoot ( true ) ;
// ADD VRE FOLDER
try {
2016-01-19 15:50:40 +01:00
2019-09-13 16:48:26 +02:00
String vreFolderId = shWorkspace . getVREFoldersId ( ) ;
2021-05-18 15:34:43 +02:00
org . gcube . common . storagehubwrapper . shared . tohl . WorkspaceItem baseVREFolder = shWorkspace
. getItem ( vreFolderId ) ;
2019-09-13 16:48:26 +02:00
FileGridModel specialFolderModel = converter . toGridFileModel ( baseVREFolder , folder ) ;
2016-01-19 15:50:40 +01:00
2019-09-13 16:48:26 +02:00
specialFolderModel . setSpecialFolder ( true ) ;
String newName = getNameForSpecialFolder ( ) ;
2016-01-19 15:50:40 +01:00
2019-09-13 16:48:26 +02:00
if ( ! newName . isEmpty ( ) ) {
workspaceLogger . info ( " Special folder name updated as: " + newName ) ;
specialFolderModel . setName ( newName ) ;
} else
workspaceLogger . info ( " Special folder name is empty, skipping " ) ;
2016-01-19 15:50:40 +01:00
2019-09-13 16:48:26 +02:00
listFileGridModels . add ( specialFolderModel ) ;
2016-01-19 15:50:40 +01:00
2019-09-13 16:48:26 +02:00
} catch ( Exception e ) {
workspaceLogger . warn (
" An error occurred on retrieving special folders for folder id: " + folder . getIdentifier ( ) ,
e ) ;
}
}
2016-01-19 15:50:40 +01:00
2019-09-13 16:48:26 +02:00
return listFileGridModels ;
2013-02-06 15:40:17 +01:00
} catch ( Exception e ) {
2019-09-13 16:48:26 +02:00
workspaceLogger . error ( " Error in server During items retrieving " , e ) ;
String error = ConstantsExplorer . SERVER_ERROR + RETRIEVING_ITEM_EITHER_ITEM_DOESN_T_EXIST ;
// GWT can't serialize all exceptions
throw new Exception ( error ) ;
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 #
2019-09-13 16:48:26 +02:00
* getFolderChildrenForFileGridById ( java . lang . String )
2015-03-06 16:12:21 +01:00
* /
2017-02-20 11:41:54 +01:00
/ * *
2019-09-13 16:48:26 +02:00
* Gets the folder children for file grid by id .
2017-02-20 11:41:54 +01:00
*
2021-05-18 15:34:43 +02:00
* @param folderId the folder id
2019-09-13 16:48:26 +02:00
* @return the folder children for file grid by id
2021-05-18 15:34:43 +02:00
* @throws Exception the exception
* @throws SessionExpiredException the session expired exception
2017-02-20 11:41:54 +01:00
* /
2013-03-25 11:14:26 +01:00
@Override
2019-09-13 16:48:26 +02:00
public List < FileGridModel > getFolderChildrenForFileGridById ( String folderId )
throws Exception , SessionExpiredException {
2016-01-19 15:50:40 +01:00
2019-09-13 16:48:26 +02:00
if ( isSessionExpired ( ) )
throw new SessionExpiredException ( ) ;
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
2019-09-13 16:48:26 +02:00
if ( folderId = = null | | folderId . isEmpty ( ) )
throw new Exception ( " Folder id is null or empty " ) ;
org . gcube . common . storagehubwrapper . server . tohl . Workspace shWorkspace = getWorkspaceFromStorageHub ( ) ;
workspaceLogger . trace ( " get children for Grid by id: " + folderId ) ;
List < FileGridModel > listFileGridModels = new ArrayList < FileGridModel > ( ) ;
// BUILDING THE PARENT
org . gcube . common . storagehubwrapper . shared . tohl . WorkspaceItem wsItem = shWorkspace . getItem ( folderId ) ;
org . gcube . common . storagehubwrapper . shared . tohl . WorkspaceFolder parent ;
if ( wsItem . isFolder ( ) ) {
workspaceLogger . trace ( " item id: " + folderId + " is of type: " + wsItem . getType ( ) ) ;
parent = ( org . gcube . common . storagehubwrapper . shared . tohl . WorkspaceFolder ) wsItem ;
} 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 ( ) ) ;
}
2016-01-19 15:50:40 +01:00
2019-09-13 16:48:26 +02:00
if ( parent = = null )
return listFileGridModels ;
2016-01-19 15:50:40 +01:00
2019-09-13 16:48:26 +02:00
StorageHubToWorkpaceConverter converter = getStorageHubToWorkpaceConverter ( ) ;
FileGridModel wsParent = converter . toGridFileModel ( parent , null ) ;
2016-01-19 15:50:40 +01:00
2019-09-13 16:48:26 +02:00
// PARENT BUILT IS SHARED?
if ( parent . isShared ( ) ) {
wsParent . setShared ( true ) ;
wsParent . setShareable ( false ) ;
}
2016-01-19 15:50:40 +01:00
2019-09-13 16:48:26 +02:00
Long startTime = System . currentTimeMillis ( ) ;
// GET CHILDREN
List < ? extends org . gcube . common . storagehubwrapper . shared . tohl . WorkspaceItem > children = shWorkspace
. getChildren ( wsParent . getIdentifier ( ) ) ;
Long endTime = System . currentTimeMillis ( ) - startTime ;
String time = String . format ( " %d msc %d sec " , endTime , TimeUnit . MILLISECONDS . toSeconds ( endTime ) ) ;
workspaceLogger . debug ( " grid getChildren() returning " + children . size ( ) + " elements in " + time ) ;
// boolean isParentShared = folder.isShared();
for ( org . gcube . common . storagehubwrapper . shared . tohl . WorkspaceItem workspaceItem : children ) {
workspaceLogger
. debug ( " Converting grid item: " + workspaceItem . getId ( ) + " name " + workspaceItem . getName ( ) ) ;
listFileGridModels . add ( converter . toGridFileModel ( workspaceItem , wsParent ) ) ;
}
workspaceLogger . info ( " All converted grid item/s is/are: " + listFileGridModels . size ( ) ) ;
return listFileGridModels ;
2013-03-25 11:14:26 +01:00
} catch ( Exception e ) {
2019-09-13 16:48:26 +02:00
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 ) ;
2013-03-25 11:14:26 +01:00
}
}
2013-03-25 12:35:05 +01:00
2017-02-20 11:41:54 +01:00
/ * *
2019-09-13 16:48:26 +02:00
* Gets the trash content .
2017-02-20 11:41:54 +01:00
*
2019-09-13 16:48:26 +02:00
* @return the trash content
2021-05-18 15:34:43 +02:00
* @throws Exception the exception
2017-02-20 11:41:54 +01:00
* /
2013-03-25 12:35:05 +01:00
@Override
2019-09-13 16:48:26 +02:00
public List < FileTrashedModel > getTrashContent ( ) throws Exception {
workspaceLogger . trace ( " Get TrashContent: " ) ;
2016-01-19 15:50:40 +01:00
2019-09-13 16:48:26 +02:00
try {
2016-01-19 15:50:40 +01:00
2019-09-13 16:48:26 +02:00
org . gcube . common . storagehubwrapper . server . tohl . Workspace workspace = getWorkspaceFromStorageHub ( ) ;
org . gcube . common . storagehubwrapper . shared . tohl . WorkspaceItem baseTrashFolder = workspace . getTrash ( ) ;
List < ? extends org . gcube . common . storagehubwrapper . shared . tohl . WorkspaceItem > trashChildren = workspace
. getChildren ( baseTrashFolder . getId ( ) ) ;
List < FileTrashedModel > trashContent = new ArrayList < FileTrashedModel > ( trashChildren . size ( ) ) ;
StorageHubToWorkpaceConverter converter = getStorageHubToWorkpaceConverter ( ) ;
for ( org . gcube . common . storagehubwrapper . shared . tohl . WorkspaceItem workspaceItem : trashChildren ) {
if ( workspaceItem . isTrashed ( ) ) {
trashContent . add ( converter . toFileTrashedModel ( ( TrashedItem ) workspaceItem ) ) ;
} else
workspaceLogger . warn ( " The item: " + workspaceItem . getId ( ) + " is not trashed " ) ;
}
return trashContent ;
2016-01-19 15:50:40 +01:00
2013-03-25 12:35:05 +01:00
} catch ( Exception e ) {
2019-09-13 16:48:26 +02:00
workspaceLogger . error ( " Error in server TrashConten " , e ) ;
String error = ConstantsExplorer . SERVER_ERROR + " get Trash content. " + e . getMessage ( ) ;
throw new Exception ( error ) ;
2013-03-25 12:35:05 +01:00
}
}
2017-02-20 11:41:54 +01:00
/ * *
2019-09-13 16:48:26 +02:00
* Update trash content .
2017-02-20 11:41:54 +01:00
*
2021-05-18 15:34:43 +02:00
* @param operation the operation
2019-09-13 16:48:26 +02:00
* @return the trash content
2021-05-18 15:34:43 +02:00
* @throws Exception the exception
2017-02-20 11:41:54 +01:00
* /
2013-03-25 12:35:05 +01:00
@Override
2019-09-13 16:48:26 +02:00
public TrashContent updateTrashContent ( WorkspaceTrashOperation operation ) throws Exception {
workspaceLogger . info ( " Updating TrashContent with operation: " + operation ) ;
2016-01-19 15:50:40 +01:00
2013-03-25 12:35:05 +01:00
try {
2019-09-13 16:48:26 +02:00
org . gcube . common . storagehubwrapper . server . tohl . Workspace workspace = getWorkspaceFromStorageHub ( ) ;
TrashContent result = new TrashContent ( ) ;
2016-01-19 15:50:40 +01:00
2019-09-13 16:48:26 +02:00
switch ( operation ) {
2016-01-19 15:50:40 +01:00
2019-09-13 16:48:26 +02:00
case EMPTY_TRASH :
workspace . emptyTrash ( ) ;
// case RESTORE_ALL:
// //listErrors = trash.restoreAll();
// //workspace.re
// break;
case REFRESH :
default :
result . setTrashContent ( getTrashContent ( ) ) ; // THIS WORKING WITH
// STORAGE-HUB
return result ;
2013-03-25 12:35:05 +01:00
}
2016-01-19 15:50:40 +01:00
2013-03-25 12:35:05 +01:00
} catch ( Exception e ) {
2019-09-13 16:48:26 +02:00
workspaceLogger . error ( " Error in server TrashContent " , e ) ;
String error = ConstantsExplorer . SERVER_ERROR + " update Trash content. " + e . getMessage ( ) ;
throw new Exception ( error ) ;
2013-03-25 12:35:05 +01:00
}
}
2016-01-19 15:50:40 +01:00
2017-02-20 11:41:54 +01:00
/ * *
2019-09-13 16:48:26 +02:00
* Execute operation on trash .
2017-02-20 11:41:54 +01:00
*
2021-05-18 15:34:43 +02:00
* @param listTrashItemIds the list trash item ids
2020-05-19 17:22:22 +02:00
* @param destinationFolderId the destination folder id
2021-05-18 15:34:43 +02:00
* @param operation the operation
2019-09-13 16:48:26 +02:00
* @return the trash operation content
2020-05-19 17:22:22 +02:00
* @throws Exception the exception
2017-02-20 11:41:54 +01:00
* /
2013-03-26 12:35:58 +01:00
@Override
2020-05-19 17:22:22 +02:00
public TrashOperationContent executeOperationOnTrash ( List < String > listTrashItemIds , String destinationFolderId ,
2019-09-13 16:48:26 +02:00
WorkspaceTrashOperation operation ) throws Exception {
2016-01-19 15:50:40 +01:00
2019-09-13 16:48:26 +02:00
workspaceLogger . info ( " Get TrashContent, operation: " + operation ) ;
if ( listTrashItemIds = = null | | listTrashItemIds . size ( ) = = 0 )
throw new Exception ( " List of Trash item ids is null or empty " ) ;
2020-05-19 17:22:22 +02:00
List < TrashOperationError > listOperationError = new ArrayList < TrashOperationError > ( ) ;
2013-03-26 12:35:58 +01:00
try {
2016-01-19 15:50:40 +01:00
2019-09-13 16:48:26 +02:00
org . gcube . common . storagehubwrapper . server . tohl . Workspace workspace = getWorkspaceFromStorageHub ( ) ;
2016-01-19 15:50:40 +01:00
2019-09-13 16:48:26 +02:00
// WorkspaceTrashFolder trash = workspace.getTrash();
TrashOperationContent result = new TrashOperationContent ( ) ;
result . setOperation ( operation ) ;
2016-01-19 15:50:40 +01:00
2019-09-13 16:48:26 +02:00
List < String > listUpdatedTrashIds = new ArrayList < String > ( ) ;
2016-01-19 15:50:40 +01:00
2019-09-13 16:48:26 +02:00
switch ( operation ) {
2013-03-27 17:30:37 +01:00
2019-09-13 16:48:26 +02:00
case DELETE_PERMANENTLY : {
2016-01-19 15:50:40 +01:00
2020-05-19 17:22:22 +02:00
org . gcube . common . storagehubwrapper . shared . tohl . WorkspaceItem trashedItem = null ;
2019-09-13 16:48:26 +02:00
for ( String trashItemId : listTrashItemIds ) {
try {
2021-05-18 15:34:43 +02:00
trashedItem = workspace . getItem ( trashItemId ) ;
2019-09-13 16:48:26 +02:00
if ( trashedItem ! = null & & trashedItem . isTrashed ( ) ) {
workspace . deleteItem ( trashedItem . getId ( ) ) ;
listUpdatedTrashIds . add ( trashItemId ) ;
}
2016-01-19 15:50:40 +01:00
2019-09-13 16:48:26 +02:00
} catch ( Exception e ) {
2021-05-18 15:34:43 +02:00
workspaceLogger . warn ( " Error occurred on " + WorkspaceTrashOperation . DELETE_PERMANENTLY
+ " the item : " + trashItemId , e ) ;
2019-09-13 16:48:26 +02:00
FileTrashedModel fakeFile = new FileTrashedModel ( ) ;
fakeFile . setIdentifier ( trashItemId ) ;
2021-05-18 15:34:43 +02:00
String itemName = trashedItem ! = null ? trashedItem . getName ( ) : " item " ;
2020-05-19 17:22:22 +02:00
fakeFile . setName ( itemName ) ;
2021-05-18 15:34:43 +02:00
String itemRefMsg = trashedItem . isFolder ( ) ? " folder " : " file " ;
itemRefMsg + = " ' " + itemName + " ' " ;
String errorMsg = " Error occurred on deleting permanently the " + itemRefMsg ;
if ( e instanceof UserNotAuthorizedException ) {
errorMsg = String . format ( " Insufficent privileges for you to delete permanently the %s " ,
itemRefMsg ) ;
2020-05-19 17:22:22 +02:00
}
2021-05-18 15:34:43 +02:00
TrashOperationError error = new TrashOperationError ( fakeFile ,
WorkspaceTrashOperation . DELETE_PERMANENTLY , errorMsg ) ;
2020-05-19 17:22:22 +02:00
listOperationError . add ( error ) ;
2019-09-13 16:48:26 +02:00
}
}
break ;
2013-03-27 17:30:37 +01:00
}
2019-09-13 16:48:26 +02:00
case RESTORE : {
2021-05-18 15:34:43 +02:00
if ( destinationFolderId = = null )
2020-05-19 17:22:22 +02:00
throw new Exception ( " Wrong call, the destionFolderId is null " ) ;
2016-01-19 15:50:40 +01:00
2020-05-19 17:22:22 +02:00
org . gcube . common . storagehubwrapper . shared . tohl . WorkspaceItem trashedItem = null ;
2019-09-13 16:48:26 +02:00
for ( String trashItemId : listTrashItemIds ) {
try {
2020-05-19 17:22:22 +02:00
trashedItem = workspace . getItem ( trashItemId ) ;
2019-09-13 16:48:26 +02:00
if ( trashedItem ! = null & & trashedItem . isTrashed ( ) ) {
2020-05-19 17:22:22 +02:00
String destFolderId = destinationFolderId ;
2021-05-18 15:34:43 +02:00
workspaceLogger . info ( " Trying to restore the item id: " + trashedItem . getId ( )
+ " , in the folder id: " + destFolderId ) ;
2020-05-18 18:11:28 +02:00
workspace . restoreThrashItem ( trashedItem . getId ( ) , destFolderId ) ;
2019-09-13 16:48:26 +02:00
listUpdatedTrashIds . add ( trashItemId ) ;
2021-05-18 15:34:43 +02:00
// restored = true;
2019-09-13 16:48:26 +02:00
}
2016-01-19 15:50:40 +01:00
2019-09-13 16:48:26 +02:00
} catch ( Exception e ) {
2021-05-18 15:34:43 +02:00
workspaceLogger . warn (
" Error occurred on " + WorkspaceTrashOperation . RESTORE + " the item : " + trashItemId ,
e ) ;
2019-09-13 16:48:26 +02:00
FileTrashedModel fakeFile = new FileTrashedModel ( ) ;
fakeFile . setIdentifier ( trashItemId ) ;
2021-05-18 15:34:43 +02:00
String itemName = trashedItem ! = null ? trashedItem . getName ( ) : trashItemId ;
2020-05-19 17:22:22 +02:00
fakeFile . setName ( itemName ) ;
2021-05-18 15:34:43 +02:00
String itemRefMsg = trashedItem . isFolder ( ) ? " folder " : " file " ;
itemRefMsg + = " ' " + itemName + " ' " ;
String errorMsg = " Error occurred on restoring the " + itemRefMsg + " . " + e . getMessage ( ) ;
if ( e instanceof UserNotAuthorizedException ) {
errorMsg = String . format (
" Insufficent privileges for you to restore the %s in the selected folder " ,
itemRefMsg ) ;
2020-05-19 17:22:22 +02:00
}
2021-05-18 15:34:43 +02:00
TrashOperationError error = new TrashOperationError ( fakeFile , WorkspaceTrashOperation . RESTORE ,
errorMsg ) ;
2020-05-19 17:22:22 +02:00
listOperationError . add ( error ) ;
2019-09-13 16:48:26 +02:00
}
}
break ;
}
2016-01-19 15:50:40 +01:00
2019-09-13 16:48:26 +02:00
default :
break ;
}
2016-01-19 15:50:40 +01:00
2020-05-19 17:22:22 +02:00
if ( ! listOperationError . isEmpty ( ) ) {
result . setListErrors ( listOperationError ) ;
2019-09-13 16:48:26 +02:00
}
2016-01-19 15:50:40 +01:00
2019-09-13 16:48:26 +02:00
result . setListTrashIds ( listUpdatedTrashIds ) ;
return result ;
2013-05-23 19:03:43 +02:00
} catch ( Exception e ) {
2020-05-19 17:22:22 +02:00
workspaceLogger . error ( " Error occured on performing trash operation " , e ) ;
2019-09-13 16:48:26 +02:00
String error = ConstantsExplorer . SERVER_ERROR + " updating the trash content. " + e . getMessage ( ) ;
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 #
2019-09-13 16:48:26 +02:00
* deleteListItemsForIds ( java . util . List )
2013-06-28 18:42:10 +02:00
* /
2017-02-20 11:41:54 +01:00
/ * *
2019-09-13 16:48:26 +02:00
* Delete list items for ids .
2017-02-20 11:41:54 +01:00
*
2021-05-18 15:34:43 +02:00
* @param ids the ids
2019-09-13 16:48:26 +02:00
* @return the list
2021-05-18 15:34:43 +02:00
* @throws Exception the exception
2017-02-20 11:41:54 +01:00
* /
2013-06-28 18:42:10 +02:00
@Override
2019-09-13 16:48:26 +02:00
public List < GarbageItem > deleteListItemsForIds ( List < String > ids ) throws Exception {
2016-01-19 15:50:40 +01:00
2019-02-22 11:44:01 +01:00
try {
2016-01-19 15:50:40 +01:00
2019-09-13 16:48:26 +02:00
if ( ids = = null )
throw new Exception ( " List identifiers is null " ) ;
2016-01-19 15:50:40 +01:00
2021-05-18 15:34:43 +02:00
workspaceLogger . debug ( " called deleteListItemsForIds with: " + ids . size ( ) + " id/s " ) ;
2019-09-13 16:48:26 +02:00
// Workspace workspace = getWorkspace();
org . gcube . common . storagehubwrapper . server . tohl . Workspace workspace = getWorkspaceFromStorageHub ( ) ;
String [ ] items = new String [ ids . size ( ) ] ;
items = ids . toArray ( items ) ;
2016-01-19 15:50:40 +01:00
2019-09-13 16:48:26 +02:00
Map < String , GarbageItem > garbage = new HashMap < String , GarbageItem > ( items . length ) ;
2016-01-19 15:50:40 +01:00
2019-09-13 16:48:26 +02:00
// SAVE DATE FOR NOTIFICATIONS
for ( String itemId : ids ) {
// NOTIFICATION
org . gcube . common . storagehubwrapper . shared . tohl . WorkspaceItem wsItem = workspace . getItem ( itemId ) ;
checkItemLocked ( itemId ) ;
// SAVING ATTRIBUTE FOR NOTIFICATION
boolean sourceItemIsShared = wsItem . isShared ( ) ;
String itemName = wsItem . getName ( ) ;
String sourceFolderSharedId = null ;
try {
if ( sourceItemIsShared ) {
org . gcube . common . storagehubwrapper . shared . tohl . WorkspaceItem rootSharedFolder = workspace
. getRootSharedFolder ( itemId ) ;
sourceFolderSharedId = rootSharedFolder . getId ( ) ;
}
// REMOVE ITEM
garbage . put ( itemId , new GarbageItem ( sourceItemIsShared , itemName , itemId , sourceFolderSharedId ) ) ;
2016-09-14 12:49:19 +02:00
2019-09-13 16:48:26 +02:00
} catch ( Exception e ) {
workspaceLogger . warn ( " Impossible to send notifiaction for item with id: " + itemId ) ;
}
2016-06-22 18:41:51 +02:00
}
2016-01-19 15:50:40 +01:00
2019-09-13 16:48:26 +02:00
// ITEM ID - ERROR
Map < String , String > backendError = workspace . removeItems ( items ) ;
// GARBAGE ITEM ERROR
List < GarbageItem > frontEndError = new ArrayList < GarbageItem > ( backendError . size ( ) ) ;
2016-08-29 15:39:13 +02:00
2019-09-13 16:48:26 +02:00
// REMOVING IDS WHICH HAVE GENERATED AN ERROR
for ( String idError : backendError . keySet ( ) ) {
GarbageItem gbi = garbage . get ( idError ) ;
if ( gbi ! = null ) {
frontEndError . add ( gbi ) ;
garbage . remove ( idError ) ;
}
}
2016-08-29 15:39:13 +02:00
2019-09-13 16:48:26 +02:00
NotificationsProducerToStorageHub np = getNotificationProducerToStorageHub ( ) ;
for ( String idItem : garbage . keySet ( ) ) {
GarbageItem item = garbage . get ( idItem ) ;
workspaceLogger . trace ( " Check notification for " + item ) ;
// IF SOURCE SHARED FOLDER IS NOT NULL
if ( item . getSourceFolderSharedId ( ) ! = null )
NotificationStorageHubUtil . checkSendNotifyRemovedItemFromShare ( this . getThreadLocalRequest ( ) ,
item . isSourceItemIsShared ( ) , item . getOldItemName ( ) , item . getOldItemName ( ) ,
item . getSourceFolderSharedId ( ) , workspace , np ) ;
}
2016-08-29 15:39:13 +02:00
2019-09-13 16:48:26 +02:00
return frontEndError ;
2016-12-22 11:34:59 +01:00
2019-09-13 16:48:26 +02:00
} catch ( WorkspaceFolderLocked e1 ) {
throw new Exception ( e1 . getMessage ( ) ) ;
2016-08-29 15:39:13 +02:00
2019-09-13 16:48:26 +02:00
// } catch (InsufficientPrivilegesException e) {
// workspaceLogger.error("Error in server Item remove", e);
// String error = "An error occurred on deleting item. " + e.getMessage();
// throw new Exception(error);
//
// } catch (ItemNotFoundException e) {
// String error = "An error occurred on deleting item. " + ConstantsExplorer.ERROR_ITEM_DOES_NOT_EXIST;
// workspaceLogger.error(error, e);
// throw new Exception(error);
} catch ( Exception e ) {
workspaceLogger . error ( " Error in server Item remove " , e ) ;
String error = ConstantsExplorer . SERVER_ERROR + " deleting item. " + e . getMessage ( ) ;
throw new Exception ( error ) ;
2016-08-29 15:39:13 +02:00
}
2019-09-13 16:48:26 +02:00
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 #
2019-09-13 16:48:26 +02:00
* createFolder ( java . lang . String , java . lang . String ,
* org . gcube . portlets . user . workspace . client . model . FileModel )
2015-03-06 16:12:21 +01:00
* /
2017-02-20 11:41:54 +01:00
/ * *
2019-09-13 16:48:26 +02:00
* Creates the folder .
2017-02-20 11:41:54 +01:00
*
2021-05-18 15:34:43 +02:00
* @param nameFolder the name folder
* @param description the description
* @param parent the parent
2019-09-13 16:48:26 +02:00
* @return the folder model
2021-05-18 15:34:43 +02:00
* @throws Exception the exception
2017-02-20 11:41:54 +01:00
* /
2014-11-04 18:20:06 +01:00
@Override
2019-09-13 16:48:26 +02:00
public FolderModel createFolder ( String nameFolder , String description , FileModel parent ) throws Exception {
2016-01-19 15:50:40 +01:00
2019-09-13 16:48:26 +02:00
if ( isSessionExpired ( ) )
throw new SessionExpiredException ( ) ;
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
2019-09-13 16:48:26 +02:00
boolean isParentNull = parent = = null ;
2021-05-18 15:34:43 +02:00
workspaceLogger . debug ( " Create folder: " + nameFolder + " parent is null? " + isParentNull ) ;
2019-09-13 16:48:26 +02:00
if ( nameFolder = = null )
throw new Exception ( " Folder name is null " ) ;
checkItemLocked ( parent . getIdentifier ( ) ) ;
org . gcube . common . storagehubwrapper . server . tohl . Workspace workspace = getWorkspaceFromStorageHub ( ) ;
// 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 ( ) ) ;
NotificationsProducerToStorageHub np = getNotificationProducerToStorageHub ( ) ;
NotificationStorageHubUtil . checkNotifyAddItemToShare ( wsFolder , null , parentFolderDestionation , workspace ,
np ) ;
StorageHubToWorkpaceConverter converter = getStorageHubToWorkpaceConverter ( ) ;
return ( FolderModel ) converter . toTreeFileModel ( wsFolder , parent , parentFolderDestionation . isShared ( ) ) ;
} catch ( WorkspaceFolderLocked e1 ) {
throw new Exception ( e1 . getMessage ( ) ) ;
2016-01-19 15:50:40 +01:00
2019-09-13 16:48:26 +02:00
// } catch (InsufficientPrivilegesException e) {
// String error = "Insufficient Privileges to create the folder";
// workspaceLogger.error(error, e);
// throw new Exception(error);
// } catch (ItemAlreadyExistException e) {
// String error = "An error occurred on creating folder, " + e.getMessage();
// workspaceLogger.error(error, e);
// throw new Exception(error);
2014-11-04 18:20:06 +01:00
} catch ( Exception e ) {
2019-09-13 16:48:26 +02:00
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 ) ;
2014-11-04 18:20:06 +01:00
throw new Exception ( error ) ;
}
2019-09-13 16:48:26 +02:00
2014-11-04 18:20:06 +01:00
}
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 #
2019-09-13 16:48:26 +02:00
* moveItems ( java . util . List , java . lang . String )
2015-03-06 16:12:21 +01:00
* /
2017-02-20 11:41:54 +01:00
/ * *
2019-09-13 16:48:26 +02:00
* Move items .
2017-02-20 11:41:54 +01:00
*
2021-05-18 15:34:43 +02:00
* @param ids the ids
* @param destinationId the destination id
2019-09-13 16:48:26 +02:00
* @return the boolean
2021-05-18 15:34:43 +02:00
* @throws Exception the exception
2017-02-20 11:41:54 +01:00
* /
2014-10-31 17:27:52 +01:00
@Override
2019-09-13 16:48:26 +02:00
public WorkspaceOperationResult moveItems ( List < String > ids , String destinationId ) throws Exception {
workspaceLogger . trace ( " moveItems " + ids . size ( ) + " , destination: " + destinationId ) ;
if ( isSessionExpired ( ) )
throw new SessionExpiredException ( ) ;
// boolean error = false;
WorkspaceOperationResult results = new WorkspaceOperationResult ( ) ;
results . setOperationName ( " Move Items " ) ;
2019-02-22 11:44:01 +01:00
try {
2016-01-19 15:50:40 +01:00
2019-09-13 16:48:26 +02:00
checkItemLocked ( destinationId ) ;
2016-01-19 15:50:40 +01:00
2019-09-13 16:48:26 +02:00
org . gcube . common . storagehubwrapper . server . tohl . Workspace workspace = getWorkspaceFromStorageHub ( ) ;
org . gcube . common . storagehubwrapper . shared . tohl . WorkspaceItem folderDestinationItem = workspace
. getItem ( destinationId ) ; // retrieve folder destination
org . gcube . common . storagehubwrapper . shared . tohl . WorkspaceFolder folderDestination = null ;
2016-01-19 15:50:40 +01:00
2019-09-13 16:48:26 +02:00
if ( folderDestinationItem ! = null & & folderDestinationItem . isFolder ( ) ) {
folderDestination = ( org . gcube . common . storagehubwrapper . shared . tohl . WorkspaceFolder ) folderDestinationItem ;
} else
throw new Exception ( " Wrong destination. Either It is not a folder or not exist " ) ;
2016-01-19 15:50:40 +01:00
2019-09-13 16:48:26 +02:00
for ( String itemId : ids ) {
2014-11-04 18:20:06 +01:00
2019-09-13 16:48:26 +02:00
org . gcube . common . storagehubwrapper . shared . tohl . WorkspaceItem sourceItem = null ;
try {
2016-01-19 15:50:40 +01:00
2019-09-13 16:48:26 +02:00
if ( itemId = = null )
throw new Exception ( IDENTIFIER_IS_NULL ) ;
2016-01-19 15:50:40 +01:00
2019-09-13 16:48:26 +02:00
workspaceLogger . trace ( " Moving item id: " + itemId + " in the destination: " + destinationId ) ;
sourceItem = workspace . getItem ( itemId ) ; // GET SOURCE ITEM
// BEFORE OF MOVE
2016-01-19 15:50:40 +01:00
2019-09-13 16:48:26 +02:00
checkItemLocked ( itemId ) ;
2016-01-19 15:50:40 +01:00
2019-09-13 16:48:26 +02:00
String sourceRootSharedFolderId = null ;
boolean sourceItemIsShared = sourceItem . isShared ( ) ;
2016-01-19 15:50:40 +01:00
2019-09-13 16:48:26 +02: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
}
2016-01-19 15:50:40 +01:00
2019-09-13 16:48:26 +02: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 ) ;
2015-06-12 12:24:01 +02:00
2019-09-13 16:48:26 +02:00
try {
// NOTIFY?
NotificationsProducerToStorageHub np = getNotificationProducerToStorageHub ( ) ;
NotificationStorageHubUtil . checkNotifyAddItemToShare ( movedItem , sourceRootSharedFolderId ,
folderDestination , workspace , np ) ;
NotificationStorageHubUtil . checkNotifyMoveItemFromShare ( sourceItemIsShared , sourceItem ,
sourceRootSharedFolderId , folderDestination , workspace , np ) ;
2016-01-19 15:50:40 +01:00
2019-09-13 16:48:26 +02:00
} catch ( Exception e ) {
workspaceLogger . error ( " An error occurred in checkNotify " , e ) ;
}
2016-01-19 15:50:40 +01:00
2019-09-13 16:48:26 +02:00
} catch ( Exception e ) {
String error = results . getError ( ) ;
if ( error = = null )
error = " Error on moving: " ;
error + = " " ;
error + = sourceItem ! = null ? sourceItem . getName ( ) : " item is null " ;
error + = " , " ;
results . setError ( error ) ;
2015-06-12 15:07:02 +02:00
}
2019-09-13 16:48:26 +02:00
}
// removing last ','
if ( results . getError ( ) ! = null )
results . setError ( results . getError ( ) . substring ( 0 , results . getError ( ) . length ( ) - 1 ) ) ;
workspaceLogger . info ( " Moved error: " + results . getError ( ) ) ;
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 " ) ;
return results ;
} catch ( WorkspaceFolderLocked e1 ) {
throw new Exception ( e1 . getMessage ( ) ) ;
// } catch (InsufficientPrivilegesException e) {
// workspaceLogger.error("Error in server Item move", e);
// String error1 = "An error occurred on moving item. " + e.getMessage();
// throw new Exception(error1);
2016-01-19 15:50:40 +01:00
2015-06-12 12:24:01 +02:00
} catch ( Exception e ) {
2019-09-13 16:48:26 +02:00
workspaceLogger . error ( " Item move error. " , e ) ;
String error2 = ConstantsExplorer . SERVER_ERROR + " moving item/s. " + e . getMessage ( ) ;
throw new Exception ( error2 ) ;
2015-06-12 12:24:01 +02:00
}
2019-09-13 16:48:26 +02:00
2015-06-12 12:24:01 +02:00
}
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 #
2019-09-13 16:48:26 +02:00
* renameItem ( java . lang . String , java . lang . String , java . lang . String )
2016-09-14 12:17:14 +02:00
* /
2017-02-20 11:41:54 +01:00
/ * *
2019-09-13 16:48:26 +02:00
* Rename item .
2017-02-20 11:41:54 +01:00
*
2021-05-18 15:34:43 +02:00
* @param itemId the item id
* @param newName the new name
* @param previousName the previous name
2019-09-13 16:48:26 +02:00
* @return the boolean
2021-05-18 15:34:43 +02:00
* @throws Exception the exception
2017-02-20 11:41:54 +01:00
* /
2016-09-14 12:17:14 +02:00
@Override
2019-09-13 16:48:26 +02:00
public Boolean renameItem ( String itemId , String newName , String previousName ) throws 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 ( ) ;
2019-09-13 16:48:26 +02:00
boolean sourceItemIsShared = false ;
2016-09-14 12:17:14 +02:00
try {
2016-09-19 12:17:33 +02:00
2019-09-13 16:48:26 +02:00
if ( itemId = = null )
throw new Exception ( IDENTIFIER_IS_NULL ) ;
checkItemLocked ( itemId ) ;
org . gcube . common . storagehubwrapper . server . tohl . Workspace workspace = getWorkspaceFromStorageHub ( ) ;
workspaceLogger . debug ( " Renaming item with id: " + itemId + " from old name " + previousName
+ " , to new name: " + newName ) ;
2021-05-18 15:34:43 +02:00
// Needed to check if the item is shared
org . gcube . common . storagehubwrapper . shared . tohl . WorkspaceItem wsItem = workspace . getItem ( itemId ) ;
2019-09-13 16:48:26 +02:00
sourceItemIsShared = wsItem . isShared ( ) ;
2021-05-18 15:34:43 +02:00
2019-09-13 16:48:26 +02:00
wsItem = workspace . renameItem ( itemId , newName ) ;
workspaceLogger . debug ( " Item renamed is: " + wsItem ) ;
// SEND NOTIFY?
if ( sourceItemIsShared ) {
try {
List < InfoContactModel > listSharedContact = new ArrayList < InfoContactModel > ( ) ;
NotificationsProducerToStorageHub np = getNotificationProducerToStorageHub ( ) ;
2021-05-18 15:34:43 +02:00
org . gcube . common . storagehubwrapper . shared . tohl . WorkspaceItem sourceShared = workspace
. getRootSharedFolder ( wsItem . getId ( ) ) ;
2019-09-13 16:48:26 +02:00
// NotificationsManager nManager =
// WsUtil.getNotificationManager(this.getThreadLocalRequest());
listSharedContact = NotificationStorageHubUtil . getListUserSharedByFolderSharedId ( sourceShared ,
workspace ) ;
2021-05-18 15:34:43 +02:00
2019-10-29 10:57:57 +01:00
// THE ITEM RENAMED IS A SHARED FOLDER
if ( NotificationStorageHubUtil . isFolderAndShared ( wsItem ) ) {
2019-09-13 16:48:26 +02:00
np . notifyFolderRenamed ( listSharedContact , wsItem , previousName , newName , sourceShared . getId ( ) ) ;
} else {
2019-10-29 10:57:57 +01:00
// THE ITEM RENAMED IS A SHARED ITEM
2021-05-18 15:34:43 +02:00
// if (sourceShared instanceof
// org.gcube.common.storagehubwrapper.shared.tohl.WorkspaceSharedFolder)
np . notifyItemRenamed ( listSharedContact , previousName , wsItem ,
( org . gcube . common . storagehubwrapper . shared . tohl . WorkspaceFolder ) sourceShared ,
workspace ) ;
2016-09-15 16:42:20 +02:00
}
2019-09-13 16:48:26 +02:00
} catch ( Exception e ) {
workspaceLogger . error ( " An error occurred in checkNotify " , e ) ;
return true ;
2016-09-14 14:30:33 +02:00
}
2019-09-13 16:48:26 +02:00
}
2016-09-21 18:10:14 +02:00
2019-09-13 16:48:26 +02:00
return true ;
2016-09-21 18:10:14 +02:00
2019-09-13 16:48:26 +02:00
} catch ( WorkspaceFolderLocked e1 ) {
throw new Exception ( e1 . getMessage ( ) ) ;
2016-09-21 18:10:14 +02:00
2019-09-13 16:48:26 +02:00
// } catch (ItemAlreadyExistException e) {
// String error = "An error occurred on renaming item, " + e.getMessage();
// workspaceLogger.error(error, e);
// throw new Exception(error);
// } catch (ItemNotFoundException e2) {
// String error = "An error occurred on renaming item. " + ConstantsExplorer.ERROR_ITEM_DOES_NOT_EXIST;
// workspaceLogger.error(error, e2);
// throw new Exception(error);
2021-05-18 15:34:43 +02:00
// TO STORAGEHUB EXCEPTION
2019-09-13 16:48:26 +02:00
} catch ( UserNotAuthorizedException e ) {
String error = " Insufficient Privileges to rename the item " ;
workspaceLogger . error ( error , e ) ;
throw new Exception ( error ) ;
} catch ( Exception e ) {
workspaceLogger . error ( " Renaming item error: " , e ) ;
StringBuilder error = new StringBuilder ( ) ;
2021-05-18 15:34:43 +02:00
if ( sourceItemIsShared ) {
2020-06-29 16:28:13 +02:00
error . append ( " Renaming shared folders is not supported " ) ;
2019-09-13 16:48:26 +02:00
throw new SHUBOperationNotAllowedException ( error . toString ( ) ) ;
2021-05-18 15:34:43 +02:00
} 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 " ) ;
2019-09-13 16:48:26 +02:00
throw new Exception ( error . toString ( ) ) ;
}
2021-05-18 15:34:43 +02:00
2016-09-21 18:10:14 +02:00
}
}
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 #
2019-09-13 16:48:26 +02:00
* copyItems ( java . util . List , java . lang . String )
2017-02-22 11:36:28 +01:00
* /
2017-09-29 17:58:12 +02:00
/ * *
2019-09-13 16:48:26 +02:00
* Copy items .
2017-09-29 17:58:12 +02:00
*
2021-05-18 15:34:43 +02:00
* @param idsItem the ids item
* @param destinationFolderId the destination folder id
2019-09-13 16:48:26 +02:00
* @return the workspace operation result
2021-05-18 15:34:43 +02:00
* @throws Exception the exception
2017-09-29 17:58:12 +02:00
* /
2017-02-22 11:36:28 +01:00
@Override
2019-09-13 16:48:26 +02:00
public WorkspaceOperationResult copyItems ( List < String > idsItem , String destinationFolderId ) throws Exception {
2017-02-22 11:36:28 +01:00
2019-09-13 16:48:26 +02:00
workspaceLogger . debug ( " Copying ids: " + idsItem + " in the destionation folder: " + destinationFolderId ) ;
2017-02-22 11:36:28 +01:00
2019-09-13 16:48:26 +02:00
if ( isSessionExpired ( ) )
throw new SessionExpiredException ( ) ;
// boolean error = false;
WorkspaceOperationResult results = new WorkspaceOperationResult ( ) ;
results . setOperationName ( " Copy Items " ) ;
2017-02-22 11:36:28 +01:00
try {
2019-09-13 16:48:26 +02:00
checkItemLocked ( destinationFolderId ) ;
org . gcube . common . storagehubwrapper . server . tohl . Workspace workspace = getWorkspaceFromStorageHub ( ) ;
org . gcube . common . storagehubwrapper . shared . tohl . WorkspaceItem sourceItem = null ;
2017-02-22 11:36:28 +01:00
2019-09-13 16:48:26 +02:00
org . gcube . common . storagehubwrapper . shared . tohl . WorkspaceItem folderDestinationItem = workspace
. getItem ( destinationFolderId ) ;
NotificationsProducerToStorageHub np = getNotificationProducerToStorageHub ( ) ;
String sourceRootSharedId = null ;
for ( String itemId : idsItem ) {
2017-02-22 11:36:28 +01:00
2019-09-13 16:48:26 +02:00
try {
sourceItem = workspace . getItem ( itemId ) ; // GET SOURCE ITEM
// BEFORE COPY
2017-02-22 11:36:28 +01:00
2019-09-13 16:48:26 +02: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 ( ) ) ;
sourceRootSharedId = sourceShared . getId ( ) ;
2017-02-22 11:36:28 +01:00
}
2019-09-13 16:48:26 +02:00
workspaceLogger . debug ( " Copying item with id: " + sourceItem . getId ( ) ) ;
org . gcube . common . storagehubwrapper . shared . tohl . WorkspaceItem copiedFile = workspace
. copyFile ( sourceItem . getId ( ) , destinationFolderId ) ; // copy
// item
workspaceLogger . debug ( " Copied item is: " + copiedFile ) ;
// 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-09-14 15:38:41 +02:00
2019-09-13 16:48:26 +02:00
} catch ( Exception e ) {
2017-02-22 11:36:28 +01:00
2019-09-13 16:48:26 +02:00
String error = results . getError ( ) ;
if ( error = = null )
error = " Error on copying: " ;
2017-02-22 11:36:28 +01:00
2019-09-13 16:48:26 +02:00
error + = " " ;
error + = sourceItem ! = null ? sourceItem . getName ( ) : " item is null " ;
error + = " , " ;
results . setError ( error ) ;
2017-02-22 11:36:28 +01:00
}
2019-09-13 16:48:26 +02:00
}
2017-02-22 11:36:28 +01:00
2019-09-13 16:48:26 +02:00
// removing last ','
if ( results . getError ( ) ! = null )
results . setError ( results . getError ( ) . substring ( 0 , results . getError ( ) . length ( ) - 1 ) ) ;
2017-02-22 11:36:28 +01:00
2019-09-13 16:48:26 +02:00
workspaceLogger . info ( " Copied error: " + results . getError ( ) ) ;
2017-02-22 11:36:28 +01:00
2019-09-13 16:48:26 +02:00
if ( results . getError ( ) ! = null )
results . setError ( results . getError ( ) + " . Operation not allowed " ) ;
2017-02-22 11:36:28 +01:00
2019-09-13 16:48:26 +02:00
return results ;
2017-03-02 18:13:52 +01:00
2019-09-13 16:48:26 +02:00
} catch ( WorkspaceFolderLocked e1 ) {
throw new Exception ( e1 . getMessage ( ) ) ;
2017-03-02 18:13:52 +01:00
2019-09-13 16:48:26 +02:00
// } catch (InsufficientPrivilegesException e) {
// String error = "An error occurred on copying item, " + e.getMessage() + ". " + ConstantsExplorer.TRY_AGAIN;
// throw new Exception(error);
//
// } catch (ItemAlreadyExistException e) {
// String error = "An error occurred on copying item, " + e.getMessage();
// throw new Exception(error);
} catch ( Exception e ) {
workspaceLogger . error ( " Error in server copyItem by id " , e ) ;
String error = ConstantsExplorer . SERVER_ERROR + " copying item " + ConstantsExplorer . TRY_AGAIN ;
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 #
2019-09-13 16:48:26 +02:00
* getPublicLinkForFileItemId ( java . lang . String , boolean )
2017-05-24 12:01:16 +02:00
* /
2017-09-29 17:58:12 +02:00
/ * *
2019-09-13 16:48:26 +02:00
* Gets the public link for file item id .
2017-09-29 17:58:12 +02:00
*
2021-05-18 15:34:43 +02:00
* @param itemId the item id
* @param shortenUrl the shorten url
2019-09-13 16:48:26 +02:00
* @return the public link for file item id
2021-05-18 15:34:43 +02:00
* @throws Exception the exception
2017-09-29 17:58:12 +02:00
* /
2017-05-24 12:01:16 +02:00
@Override
2019-09-13 16:48:26 +02:00
public PublicLink getPublicLinkForFileItemId ( String itemId , boolean shortenUrl ) throws Exception {
2017-05-24 12:01:16 +02:00
2019-09-13 16:48:26 +02:00
workspaceLogger . trace ( " get Public Link For ItemId: " + itemId ) ;
2017-05-24 12:01:16 +02:00
try {
2019-09-13 16:48:26 +02:00
if ( itemId = = null )
throw new Exception ( " Sorry, The Public Link for empty item is unavailable (itemId is null) " ) ;
2017-05-24 12:01:16 +02:00
2019-09-13 16:48:26 +02:00
org . gcube . common . storagehubwrapper . server . tohl . Workspace workspace = getWorkspaceFromStorageHub ( ) ;
org . gcube . common . storagehubwrapper . shared . tohl . WorkspaceItem wsItem = workspace . getItem ( itemId ) ;
2017-05-24 12:01:16 +02:00
2019-09-13 16:48:26 +02:00
if ( wsItem = = null )
throw new Exception ( " Sorry, The Public Link for empty item is unavailable " ) ;
2017-05-24 12:01:16 +02:00
2019-09-13 16:48:26 +02:00
if ( wsItem . getType ( ) . equals ( org . gcube . common . storagehubwrapper . shared . tohl . WorkspaceItemType . FILE_ITEM ) ) {
2017-05-24 12:01:16 +02:00
2019-09-13 16:48:26 +02:00
URL publicLink = workspace . getPublicLinkForFile ( itemId ) ;
2017-09-27 18:38:30 +02:00
2019-09-13 16:48:26 +02:00
if ( publicLink = = null | | publicLink . toString ( ) = = null )
throw new Exception ( " Sorry, public link on " + wsItem . getName ( ) + " is not available " ) ;
2017-09-27 18:38:30 +02:00
2019-09-13 16:48:26 +02:00
String shortURL = null ;
String httpURL = publicLink . toString ( ) ;
2017-09-28 12:19:04 +02:00
2019-09-13 16:48:26 +02:00
if ( shortenUrl ) {
shortURL = getShortUrl ( httpURL ) ;
shortURL = shortURL ! = null ? shortURL : " not available " ;
}
2017-09-28 12:19:04 +02:00
2019-09-13 16:48:26 +02:00
return new PublicLink ( httpURL , shortURL ) ;
2017-09-27 18:38:30 +02:00
2019-09-13 16:48:26 +02:00
} else {
workspaceLogger . warn ( " ItemId: " + itemId + " is not a file, sent exception Public Link unavailable " ) ;
throw new Exception ( " Sorry, The Public Link for selected item is unavailable " ) ;
2017-09-27 18:38:30 +02:00
}
2019-09-13 16:48:26 +02:00
} catch ( Exception e ) {
workspaceLogger . error ( " Error getPublicLinkForFileItemId for item: " + itemId , e ) ;
throw new Exception ( e . getMessage ( ) ) ;
2017-09-27 18:38:30 +02:00
}
}
2018-03-28 18:35:12 +02:00
/ * *
2019-09-13 16:48:26 +02:00
* Gets the version history .
2018-03-28 18:35:12 +02:00
*
2021-05-18 15:34:43 +02:00
* @param fileIdentifier the file identifier
2019-09-13 16:48:26 +02:00
* @return the version history
2021-05-18 15:34:43 +02:00
* @throws Exception the exception
2018-03-28 18:35:12 +02:00
* /
@Override
2019-09-13 16:48:26 +02:00
public List < FileVersionModel > getVersionHistory ( String fileIdentifier ) throws Exception {
workspaceLogger . info ( " Calling get Version History of: " + fileIdentifier ) ;
if ( fileIdentifier = = null )
throw new Exception ( " File identifier is null " ) ;
2018-03-28 18:35:12 +02:00
try {
2019-09-13 16:48:26 +02:00
org . gcube . common . storagehubwrapper . server . tohl . Workspace workspace = getWorkspaceFromStorageHub ( ) ;
org . gcube . common . storagehubwrapper . shared . tohl . WorkspaceItem wsItem = workspace . getItem ( fileIdentifier ) ;
if ( wsItem . getType ( ) . equals ( org . gcube . common . storagehubwrapper . shared . tohl . WorkspaceItemType . FILE_ITEM ) ) {
List < WorkspaceFileVersion > listOfVersions = workspace . getListVersionsForFile ( fileIdentifier ) ;
StorageHubToWorkpaceConverter converter = getStorageHubToWorkpaceConverter ( ) ;
workspaceLogger
. info ( " Version list for " + fileIdentifier + " has " + listOfVersions . size ( ) + " item/s " ) ;
return converter . toVersionHistory ( listOfVersions ) ;
} else
throw new FileNotVersionedException ( " Selected file is not versioned " ) ;
2019-02-22 11:44:01 +01:00
} catch ( Exception e ) {
2019-09-13 16:48:26 +02:00
if ( e instanceof FileNotVersionedException )
throw new Exception ( e . getMessage ( ) ) ;
String error = " An error occurred when getting version history of: " + fileIdentifier + " , try again " ;
workspaceLogger . error ( error ) ;
throw new Exception ( error ) ;
2018-03-28 18:35:12 +02:00
}
}
2020-05-19 17:22:22 +02:00
/ * *
* Gets the public link for file item id to version .
*
2021-05-18 15:34:43 +02:00
* @param itemId the item id
* @param version the version
2020-05-19 17:22:22 +02:00
* @param shortenUrl the shorten url
* @return the public link for file item id to version
* @throws Exception the exception
* /
2019-09-13 16:48:26 +02:00
/ *
* ( non - Javadoc )
*
* @see org . gcube . portlets . user . workspace . client . rpc . GWTWorkspaceService #
* getPublicLinkForFileItemIdToVersion ( java . lang . String , java . lang . String ,
* boolean )
2018-09-20 12:07:13 +02:00
* /
2019-09-13 16:48:26 +02:00
@Override
public PublicLink getPublicLinkForFileItemIdToVersion ( String itemId , String version , boolean shortenUrl )
throws Exception {
2018-09-14 15:38:41 +02:00
2019-09-13 16:48:26 +02:00
workspaceLogger . trace ( " get Public Link For ItemId: " + itemId + " at the version: " + version ) ;
try {
2018-09-14 15:38:41 +02:00
2019-09-13 16:48:26 +02:00
if ( itemId = = null )
throw new Exception ( " Sorry, The Public Link for empty item is unavailable (itemId is null) " ) ;
2018-09-14 15:38:41 +02:00
2019-09-13 16:48:26 +02:00
org . gcube . common . storagehubwrapper . server . tohl . Workspace workspace = getWorkspaceFromStorageHub ( ) ;
org . gcube . common . storagehubwrapper . shared . tohl . WorkspaceItem wsItem = workspace . getItem ( itemId ) ;
2018-11-28 16:50:18 +01:00
2019-09-13 16:48:26 +02:00
if ( wsItem = = null )
throw new Exception ( " Sorry, The Public Link for empty item is unavailable " ) ;
2018-11-28 16:50:18 +01:00
2019-09-13 16:48:26 +02:00
if ( wsItem . getType ( ) . equals ( org . gcube . common . storagehubwrapper . shared . tohl . WorkspaceItemType . FILE_ITEM ) ) {
2018-11-28 16:50:18 +01:00
2019-09-13 16:48:26 +02:00
URL publicLink = workspace . getPublicLinkForFile ( itemId , version ) ;
2018-11-28 16:50:18 +01:00
2019-09-13 16:48:26 +02:00
if ( publicLink = = null | | publicLink . toString ( ) = = null )
throw new Exception ( " Sorry, public link on " + wsItem . getName ( ) + " is not available " ) ;
String shortURL = null ;
String httpURL = publicLink . toString ( ) ;
if ( shortenUrl ) {
shortURL = getShortUrl ( httpURL ) ;
2019-09-24 11:28:28 +02:00
shortURL = shortURL ! = null ? shortURL : " " ;
2019-09-13 16:48:26 +02:00
}
return new PublicLink ( httpURL , shortURL ) ;
} else {
workspaceLogger . warn ( " ItemId: " + itemId + " is not a file, sent exception Public Link unavailable " ) ;
throw new Exception ( " Sorry, The Public Link for selected item is unavailable " ) ;
}
} catch ( Exception e ) {
workspaceLogger . error (
" Error getPublicLinkForFileItemIdToVersion for item: " + itemId + " at the version: " + version , e ) ;
throw new Exception ( e . getMessage ( ) ) ;
}
2018-11-28 16:50:18 +01:00
}
/ * *
2019-09-13 16:48:26 +02:00
* Gets the list parents by item identifier .
2018-11-28 16:50:18 +01:00
*
2021-05-18 15:34:43 +02:00
* @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
2019-09-13 16:48:26 +02:00
* @return the list parents by item identifier
2021-05-18 15:34:43 +02:00
* @throws Exception the exception
2018-11-28 16:50:18 +01:00
* /
@Override
2019-09-13 16:48:26 +02:00
public List < FileModel > getListParentsByItemIdentifier ( String itemIdentifier , boolean includeItemAsParent )
throws Exception {
2018-11-28 16:50:18 +01:00
2019-09-13 16:48:26 +02:00
workspaceLogger . debug ( " called 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
2018-11-28 16:50:18 +01:00
try {
org . gcube . common . storagehubwrapper . server . tohl . Workspace workspace = getWorkspaceFromStorageHub ( ) ;
2019-09-13 16:48:26 +02:00
StorageHubToWorkpaceConverter converter = getStorageHubToWorkpaceConverter ( ) ;
2021-05-18 15:34:43 +02:00
List < ? extends org . gcube . common . storagehubwrapper . shared . tohl . WorkspaceItem > parents = workspace
. getParentsById ( itemIdentifier ) ;
2019-09-13 16:48:26 +02:00
workspaceLogger . info ( " The Parents returned by SHUB are: " + parents . size ( ) ) ;
2021-05-18 15:34:43 +02:00
if ( workspaceLogger . isTraceEnabled ( ) ) {
2019-09-13 16:48:26 +02:00
workspaceLogger . trace ( " They are: " ) ;
for ( org . gcube . common . storagehubwrapper . shared . tohl . WorkspaceItem workspaceItem : parents ) {
workspaceLogger . trace ( workspaceItem . getName ( ) ) ;
}
}
2021-05-18 15:34:43 +02:00
if ( parents . size ( ) = = 0 ) {
// IT IS THE ROOT
workspaceLogger . info ( " The item id " + itemIdentifier + " is the root, returning empty list " ) ;
2019-09-13 16:48:26 +02:00
return new ArrayList < FileModel > ( 1 ) ;
}
2021-05-18 15:34:43 +02:00
2019-09-13 16:48:26 +02:00
String nameSpecialFolder = getNameForSpecialFolder ( ) ;
2021-05-18 15:34:43 +02:00
2019-09-13 16:48:26 +02:00
List < FileModel > arrayParents = new ArrayList < FileModel > ( parents . size ( ) ) ;
2021-05-18 15:34:43 +02:00
// loop from last to first index of list of parents
int lastIndex = parents . size ( ) - 1 ;
for ( int i = lastIndex ; i > = 0 ; i - - ) {
2019-09-13 16:48:26 +02:00
org . gcube . common . storagehubwrapper . shared . tohl . WorkspaceItem wsFolder = parents . get ( i ) ;
2021-05-18 15:34:43 +02:00
workspaceLogger
. trace ( " Adding the item " + wsFolder . getName ( ) + " at index " + i + " to list of parent " ) ;
2019-09-13 16:48:26 +02:00
org . gcube . common . storagehubwrapper . shared . tohl . WorkspaceItem parent = null ;
2021-05-18 15:34:43 +02:00
if ( i < lastIndex ) {
parent = parents . get ( i + 1 ) ;
workspaceLogger . trace ( " Passing the item " + parent . getName ( ) + " as parent of " + wsFolder . getName ( )
+ " . Is it right? " ) ;
2019-09-13 16:48:26 +02:00
}
2021-05-18 15:34:43 +02:00
arrayParents
. add ( converter . buildGXTFolderModelItemHandleSpecialFolder ( wsFolder , parent , nameSpecialFolder ) ) ;
workspaceLogger
. trace ( " Added " + wsFolder . getName ( ) + " as parent to index " + ( arrayParents . size ( ) - 1 ) ) ;
2019-09-13 16:48:26 +02:00
}
2021-05-18 15:34:43 +02:00
if ( includeItemAsParent ) {
org . gcube . common . storagehubwrapper . shared . tohl . WorkspaceItem theItem = workspace
. getItem ( itemIdentifier ) ;
if ( theItem . isFolder ( ) ) {
2019-09-13 16:48:26 +02:00
workspaceLogger . trace ( " The item passed is a folder, including it as last parent as requested " ) ;
2021-05-18 15:34:43 +02:00
FolderModel passedFolder = converter . buildGXTFolderModelItemHandleSpecialFolder ( theItem ,
parents . get ( parents . size ( ) - 1 ) , nameSpecialFolder ) ;
2019-09-13 16:48:26 +02:00
arrayParents . add ( passedFolder ) ;
}
}
2021-05-18 15:34:43 +02:00
2019-09-13 16:48:26 +02:00
// SET PARENTS
workspaceLogger . trace ( " setting parents.. " ) ;
2021-05-18 15:34:43 +02:00
for ( int i = 0 ; i < arrayParents . size ( ) - 1 ; i + + ) {
2019-09-13 16:48:26 +02:00
FileModel parent = arrayParents . get ( i ) ;
2021-05-18 15:34:43 +02:00
FileModel fileModel = arrayParents . get ( i + 1 ) ;
2019-09-13 16:48:26 +02:00
fileModel . setParentFileModel ( parent ) ;
2018-11-28 16:50:18 +01:00
}
2021-05-18 15:34:43 +02:00
2019-09-13 16:48:26 +02:00
workspaceLogger . trace ( " list parents returning size: " + arrayParents . size ( ) ) ;
2021-05-18 15:34:43 +02:00
// IS THIS CHECK ALREADY NEEDED?
2019-09-13 16:48:26 +02:00
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 ;
2018-11-28 16:50:18 +01:00
} catch ( Exception e ) {
2019-09-13 16:48:26 +02:00
workspaceLogger . error ( " Error in get List Parents By Item Identifier " , e ) ;
e . printStackTrace ( ) ;
throw new Exception ( e . getMessage ( ) ) ;
2018-11-28 16:50:18 +01:00
}
}
/ * *
2019-09-13 16:48:26 +02:00
* Check item locked .
2018-11-28 16:50:18 +01:00
*
2019-09-13 16:48:26 +02:00
* @param itemId the item id
* @return true , if successful
* @throws WorkspaceFolderLocked the workspace folder locked
2021-05-18 15:34:43 +02:00
* @throws Exception the exception
2018-11-28 16:50:18 +01:00
* /
2019-09-13 16:48:26 +02:00
private boolean checkItemLocked ( String itemId ) throws WorkspaceFolderLocked , Exception {
2018-11-28 16:50:18 +01:00
2019-09-13 16:48:26 +02:00
if ( itemId = = null | | itemId . isEmpty ( ) )
throw new Exception ( IDENTIFIER_IS_NULL ) ;
2021-05-18 15:34:43 +02:00
2019-09-13 16:48:26 +02:00
org . gcube . common . storagehubwrapper . server . tohl . Workspace workspace = null ;
org . gcube . common . storagehubwrapper . shared . tohl . WorkspaceItem wsItem = null ;
2018-11-28 16:50:18 +01:00
try {
2019-09-13 16:48:26 +02:00
workspace = getWorkspaceFromStorageHub ( ) ;
wsItem = workspace . getItem ( itemId ) ;
2021-05-19 17:29:38 +02:00
;
GCubeUser user = PortalContext . getConfiguration ( ) . getCurrentUser ( this . getThreadLocalRequest ( ) ) ;
2021-05-18 15:34:43 +02:00
ThreddsWorkspaceSyncServiceImpl workspaceServiceServlet = new ThreddsWorkspaceSyncServiceImpl ( ) ;
2019-09-13 16:48:26 +02:00
// IF THE ITEM IS A FOLDER, CHECKING IT
2021-05-18 15:34:43 +02:00
if ( wsItem . isFolder ( ) ) {
// WorkspaceThreddsSynchronize.getInstance().checkItemSynched(wsItem.getId());
2021-05-19 17:29:38 +02:00
workspaceServiceServlet . getConfiguration ( itemId , true , this . getThreadLocalRequest ( ) , user ) ;
2021-05-18 15:34:43 +02:00
} else {
2019-09-13 16:48:26 +02:00
// IF THE ITEM IS A FILE, CHECKING ITS PARENT
2021-05-18 15:34:43 +02:00
String parentId = wsItem . getParentId ( ) ;
if ( parentId = = null ) {
2019-09-13 16:48:26 +02:00
workspaceLogger . warn ( " I'm not able to check the lock because the parent id is null " ) ;
2021-05-18 15:34:43 +02:00
} else {
//WorkspaceThreddsSynchronize.getInstance().checkItemSynched(parentId);
2021-05-19 17:29:38 +02:00
workspaceServiceServlet . getConfiguration ( itemId , true , this . getThreadLocalRequest ( ) , user ) ;
2019-09-13 16:48:26 +02:00
}
2018-11-28 16:50:18 +01:00
}
2019-09-13 16:48:26 +02:00
// in this case the folder is synched but not locked
return false ;
2018-11-28 16:50:18 +01:00
2019-09-13 16:48:26 +02:00
} catch ( ItemNotSynched e1 ) {
// in this case the folder is not synched;
return false ;
2018-11-28 16:50:18 +01:00
2019-09-13 16:48:26 +02:00
} catch ( WorkspaceFolderLocked e2 ) {
// in this case the folder synching is on-going and the folder is
// locked;
String msg = " The folder " ;
msg + = wsItem ! = null ? " : " + wsItem . getName ( ) : " " ;
msg + = " is locked by a sync. You can not change its content " ;
workspaceLogger . warn ( msg , e2 ) ;
throw new WorkspaceFolderLocked ( itemId , msg ) ;
2018-11-28 16:50:18 +01:00
} catch ( Exception e ) {
2021-05-18 15:34:43 +02:00
workspaceLogger . warn (
" Was there an Exception SHUB or SyncEngine side? Ignoring it.. returning false (that means item not locked) " ) ;
2019-09-13 16:48:26 +02:00
return false ;
2018-11-28 16:50:18 +01:00
}
}
2020-05-19 17:22:22 +02:00
/ * *
* Gets the item for file grid .
*
* @param itemId the item id
* @return the item for file grid
* @throws Exception the exception
* /
2021-05-18 15:34:43 +02:00
/ *
* ( non - Javadoc )
*
* @see org . gcube . portlets . user . workspace . client . rpc . GWTWorkspaceService #
* getItemForFileGrid ( java . lang . String )
2018-11-28 16:50:18 +01:00
* /
@Override
2019-09-13 16:48:26 +02:00
public FileGridModel getItemForFileGrid ( String itemId ) throws Exception {
2018-11-28 16:50:18 +01:00
try {
2021-05-18 15:34:43 +02:00
2019-09-13 16:48:26 +02:00
if ( itemId = = null )
throw new Exception ( IDENTIFIER_IS_NULL ) ;
2021-05-18 15:34:43 +02:00
org . gcube . common . storagehubwrapper . server . tohl . Workspace workspace = getWorkspaceFromStorageHub ( ) ;
org . gcube . common . storagehubwrapper . shared . tohl . WorkspaceItem wsItem = workspace . getItem ( itemId ) ;
2019-02-22 10:57:16 +01:00
2018-11-28 16:50:18 +01:00
StorageHubToWorkpaceConverter converter = getStorageHubToWorkpaceConverter ( ) ;
2019-09-13 16:48:26 +02:00
FileModel parentModel = null ;
2021-05-18 15:34:43 +02:00
if ( wsItem . getParentId ( ) ! = null ) {
org . gcube . common . storagehubwrapper . shared . tohl . WorkspaceItem parent = workspace
. getItem ( wsItem . getParentId ( ) ) ;
2019-09-13 16:48:26 +02:00
parentModel = converter . toTreeFileModel ( parent , null , parent . isShared ( ) ) ;
2018-11-28 16:50:18 +01:00
}
2021-05-18 15:34:43 +02:00
2019-09-13 16:48:26 +02:00
return converter . toGridFileModel ( wsItem , parentModel ) ;
2021-05-18 15:34:43 +02:00
2019-09-13 16:48:26 +02:00
} catch ( Exception e ) {
workspaceLogger . error ( " Error in server during item retrieving, getItemForFileGrid " , e ) ;
String error = ConstantsExplorer . SERVER_ERROR + RETRIEVING_ITEM_EITHER_ITEM_DOESN_T_EXIST ;
throw new Exception ( error ) ;
}
}
2018-11-28 16:50:18 +01:00
2020-05-19 17:22:22 +02:00
/ * *
* Gets the item for file tree .
*
* @param itemId the item id
* @return the item for file tree
* @throws Exception the exception
* /
2021-05-18 15:34:43 +02:00
/ *
* ( non - Javadoc )
*
* @see org . gcube . portlets . user . workspace . client . rpc . GWTWorkspaceService #
* getItemForFileTree ( java . lang . String )
2019-09-13 16:48:26 +02:00
* /
@Override
public FileModel getItemForFileTree ( String itemId ) throws Exception {
try {
2018-11-28 16:50:18 +01:00
2019-09-13 16:48:26 +02:00
if ( itemId = = null )
throw new Exception ( IDENTIFIER_IS_NULL ) ;
2018-11-28 16:50:18 +01:00
2021-05-18 15:34:43 +02:00
org . gcube . common . storagehubwrapper . server . tohl . Workspace workspace = getWorkspaceFromStorageHub ( ) ;
org . gcube . common . storagehubwrapper . shared . tohl . WorkspaceItem wsItem = workspace . getItem ( itemId ) ;
2019-09-13 16:48:26 +02:00
StorageHubToWorkpaceConverter converter = getStorageHubToWorkpaceConverter ( ) ;
FileModel parentModel = null ;
org . gcube . common . storagehubwrapper . shared . tohl . WorkspaceItem parent = null ;
2021-05-18 15:34:43 +02:00
if ( wsItem . getParentId ( ) ! = null ) {
2019-09-13 16:48:26 +02:00
parent = workspace . getItem ( wsItem . getParentId ( ) ) ;
parentModel = converter . toTreeFileModel ( parent , null , parent . isShared ( ) ) ;
}
2021-05-18 15:34:43 +02:00
return converter . toTreeFileModel ( wsItem , parentModel , parent ! = null ? parent . isShared ( ) : false ) ;
2018-11-28 16:50:18 +01:00
2019-09-13 16:48:26 +02:00
} catch ( Exception e ) {
workspaceLogger . error ( " Error in server during item retrieving, getItemForFileGrid " , e ) ;
String error = ConstantsExplorer . SERVER_ERROR + RETRIEVING_ITEM_EITHER_ITEM_DOESN_T_EXIST ;
throw new Exception ( error ) ;
}
}
2018-11-28 16:50:18 +01:00
2020-05-19 17:22:22 +02:00
/ * *
* Gets the image by id .
*
2021-05-18 15:34:43 +02:00
* @param identifier the identifier
2020-05-19 17:22:22 +02:00
* @param isInteralImage the is interal image
2021-05-18 15:34:43 +02:00
* @param fullDetails the full details
2020-05-19 17:22:22 +02:00
* @return the image by id
* @throws Exception the exception
* /
2021-05-18 15:34:43 +02:00
/ *
* ( non - Javadoc )
*
* @see
* org . gcube . portlets . user . workspace . client . rpc . GWTWorkspaceService # getImageById
* ( java . lang . String , boolean , boolean )
2019-09-13 16:48:26 +02:00
* /
@Override
public GWTWorkspaceItem getImageById ( String identifier , boolean isInteralImage , boolean fullDetails )
throws Exception {
2018-11-28 16:50:18 +01:00
2019-09-13 16:48:26 +02:00
if ( identifier = = null )
throw new Exception ( IDENTIFIER_IS_NULL ) ;
2018-11-28 16:50:18 +01:00
2019-09-13 16:48:26 +02:00
try {
2018-11-28 16:50:18 +01:00
2019-09-13 16:48:26 +02:00
workspaceLogger . debug ( " get image by id: " + identifier ) ;
2021-05-18 15:34:43 +02:00
org . gcube . common . storagehubwrapper . server . tohl . Workspace workspace = getWorkspaceFromStorageHub ( ) ;
org . gcube . common . storagehubwrapper . shared . tohl . WorkspaceItem wsItem = workspace . getItem ( identifier ) ;
if ( wsItem instanceof ImageFileItem ) {
2019-09-13 16:48:26 +02:00
ImageFileItem imageFile = ( ImageFileItem ) wsItem ;
PortalContextInfo context = WsUtil . getPortalContext ( this . getThreadLocalRequest ( ) ) ;
GCubeUser user = PortalContext . getConfiguration ( ) . getCurrentUser ( this . getThreadLocalRequest ( ) ) ;
2021-05-18 15:34:43 +02:00
return ObjectStorageHubToWorkpaceMapper . buildGWTWorkspaceImage ( imageFile , isInteralImage , fullDetails ,
context . getCurrGroupId ( ) + " " , user . getUserId ( ) + " " ) ;
} else {
2019-09-13 16:48:26 +02:00
throw new Exception ( " The input id is not an image " ) ;
}
2018-11-28 16:50:18 +01:00
} catch ( Exception e ) {
2019-09-13 16:48:26 +02:00
workspaceLogger . error ( " Error in server get image by id " , e ) ;
throw new Exception ( e . getMessage ( ) ) ;
2018-11-28 16:50:18 +01:00
}
}
2021-05-18 15:34:43 +02:00
2019-02-22 11:44:01 +01:00
/ *
* ( non - Javadoc )
*
* @see org . gcube . portlets . user . workspace . client . rpc . GWTWorkspaceService #
2019-09-13 16:48:26 +02:00
* getUrlById ( java . lang . String , boolean , boolean )
2018-11-28 16:50:18 +01:00
* /
/ * *
2019-09-13 16:48:26 +02:00
* Gets the url by id .
2018-11-28 16:50:18 +01:00
*
2021-05-18 15:34:43 +02:00
* @param identifier the identifier
* @param isInternalUrl the is internal url
* @param fullDetails the full details
2019-09-13 16:48:26 +02:00
* @return the url by id
2021-05-18 15:34:43 +02:00
* @throws Exception the exception
2018-11-28 16:50:18 +01:00
* /
@Override
2019-09-13 16:48:26 +02:00
public GWTWorkspaceItem getUrlById ( String identifier , boolean isInternalUrl , boolean fullDetails ) throws Exception {
2018-11-28 16:50:18 +01:00
try {
2019-09-13 16:48:26 +02:00
if ( identifier = = null )
throw new Exception ( IDENTIFIER_IS_NULL ) ;
2018-11-28 16:50:18 +01:00
2019-09-13 16:48:26 +02:00
workspaceLogger . debug ( " get URL by id: " + identifier ) ;
2021-05-18 15:34:43 +02:00
org . gcube . common . storagehubwrapper . server . tohl . Workspace workspace = getWorkspaceFromStorageHub ( ) ;
org . gcube . common . storagehubwrapper . shared . tohl . WorkspaceItem wsItem = workspace . getItem ( identifier ) ;
// workspace
if ( wsItem instanceof org . gcube . common . storagehubwrapper . shared . tohl . impl . URLFileItem ) {
2019-09-13 16:48:26 +02:00
URLFileItem fileItem = ( URLFileItem ) wsItem ;
2021-05-18 15:34:43 +02:00
return ObjectStorageHubToWorkpaceMapper . buildGWTWorspaceUrl ( workspace , fileItem , isInternalUrl ,
fullDetails ) ;
} else if ( wsItem instanceof URLItem ) {
2019-09-13 16:48:26 +02:00
URLItem urlFile = ( URLItem ) wsItem ;
return new GWTExternalUrl ( urlFile . getValue ( ) . toString ( ) ) ;
2021-05-18 15:34:43 +02:00
} else {
2019-09-13 16:48:26 +02:00
throw new Exception ( " The input id is not a FILE or a URL " ) ;
2018-11-28 16:50:18 +01:00
}
2019-09-13 16:48:26 +02:00
} catch ( Exception e ) {
workspaceLogger . error ( " Error in server get image by id " , e ) ;
// workspaceLogger.trace("Error in server get image by id " + e);
// GWT can't serialize all exceptions
throw new Exception ( e . getMessage ( ) ) ;
}
}
2018-11-28 16:50:18 +01:00
2019-09-13 16:48:26 +02:00
/ * *
* Sets the value in session .
*
2021-05-18 15:34:43 +02:00
* @param name the name
* @param value the value
* @throws Exception the exception
2019-09-13 16:48:26 +02:00
* /
@Override
public void setValueInSession ( String name , String value ) throws Exception {
2018-11-28 16:50:18 +01:00
2019-09-13 16:48:26 +02:00
try {
this . getThreadLocalRequest ( ) . getSession ( ) . setAttribute ( name , value ) ;
workspaceLogger . trace ( " set value in session with name: " + name + " , value: " + value ) ;
} catch ( Exception e ) {
workspaceLogger . error ( " setValueInSession " , e ) ;
throw new Exception ( e . getMessage ( ) ) ;
}
}
2018-11-28 16:50:18 +01:00
2020-05-19 17:22:22 +02:00
/ * *
* Gets the item creation date by id .
*
* @param itemId the item id
* @return the item creation date by id
* @throws Exception the exception
* /
2021-05-18 15:34:43 +02:00
/ *
* ( non - Javadoc )
*
* @see org . gcube . portlets . user . workspace . client . rpc . GWTWorkspaceService #
* getItemCreationDateById ( java . lang . String )
2019-09-13 16:48:26 +02:00
* /
@Override
public Date getItemCreationDateById ( String itemId ) throws Exception {
workspaceLogger . trace ( " get Item Creation Date By ItemId " + itemId ) ;
try {
2018-11-28 16:50:18 +01:00
2019-09-13 16:48:26 +02:00
if ( itemId = = null )
throw new Exception ( IDENTIFIER_IS_NULL ) ;
2018-11-28 16:50:18 +01:00
2019-09-13 16:48:26 +02:00
workspaceLogger . debug ( " getItemCreationDateById by id: " + itemId ) ;
2021-05-18 15:34:43 +02:00
org . gcube . common . storagehubwrapper . server . tohl . Workspace workspace = getWorkspaceFromStorageHub ( ) ;
org . gcube . common . storagehubwrapper . shared . tohl . WorkspaceItem wsItem = workspace . getItem ( itemId ) ;
2019-09-13 16:48:26 +02:00
Calendar cl = wsItem . getCreationTime ( ) ;
2018-11-28 16:50:18 +01:00
2019-09-13 16:48:26 +02:00
if ( cl ! = null )
return cl . getTime ( ) ;
return null ;
2018-11-28 16:50:18 +01:00
} catch ( Exception e ) {
2019-09-13 16:48:26 +02:00
workspaceLogger . error ( " get Item Creation Date By ItemId " , e ) ;
throw new Exception ( e . getMessage ( ) ) ;
2018-11-28 16:50:18 +01:00
}
}
2021-05-18 15:34:43 +02:00
2019-02-22 11:44:01 +01:00
/ *
* ( non - Javadoc )
*
* @see org . gcube . portlets . user . workspace . client . rpc . GWTWorkspaceService #
2019-09-13 16:48:26 +02:00
* loadSizeByItemId ( java . lang . String )
2018-11-28 16:50:18 +01:00
* /
/ * *
2019-09-13 16:48:26 +02:00
* Load size by item id .
2018-11-28 16:50:18 +01:00
*
2021-05-18 15:34:43 +02:00
* @param itemId the item id
2019-09-13 16:48:26 +02:00
* @return the long
2021-05-18 15:34:43 +02:00
* @throws Exception the exception
2018-11-28 16:50:18 +01:00
* /
@Override
2019-09-13 16:48:26 +02:00
public Long loadSizeByItemId ( String itemId ) throws Exception {
2021-05-18 15:34:43 +02:00
2019-09-13 16:48:26 +02:00
if ( itemId = = null )
throw new Exception ( IDENTIFIER_IS_NULL ) ;
2018-11-28 16:50:18 +01:00
2019-09-13 16:48:26 +02:00
workspaceLogger . info ( " get Size By ItemId " + itemId ) ;
2018-11-28 16:50:18 +01:00
try {
2021-05-18 15:34:43 +02:00
org . gcube . common . storagehubwrapper . server . tohl . Workspace workspace = getWorkspaceFromStorageHub ( ) ;
org . gcube . common . storagehubwrapper . shared . tohl . WorkspaceItem wsItem = workspace . getItem ( itemId ) ;
2019-09-13 16:48:26 +02:00
Long size = new Long ( - 1 ) ;
2018-11-28 16:50:18 +01:00
2019-09-13 16:48:26 +02:00
if ( wsItem instanceof org . gcube . common . storagehubwrapper . shared . tohl . impl . FileItem ) { // ITEM
org . gcube . common . storagehubwrapper . shared . tohl . impl . FileItem fileItem = ( org . gcube . common . storagehubwrapper . shared . tohl . impl . FileItem ) wsItem ;
size = new Long ( fileItem . getSize ( ) ) ;
} else if ( wsItem instanceof org . gcube . common . storagehubwrapper . shared . tohl . impl . WorkspaceFolder ) { // FOLDER
org . gcube . common . storagehubwrapper . shared . tohl . impl . WorkspaceFolder theFolder = ( org . gcube . common . storagehubwrapper . shared . tohl . impl . WorkspaceFolder ) wsItem ;
2021-05-18 15:34:43 +02:00
// TODO ASK TO LUCIO;
// size = theFolder.getSize();
} else if ( wsItem instanceof org . gcube . common . storagehubwrapper . shared . tohl . impl . WorkspaceSharedFolder ) { // SHARED
// FOLDER
2019-09-13 16:48:26 +02:00
org . gcube . common . storagehubwrapper . shared . tohl . impl . WorkspaceSharedFolder theFolder = ( org . gcube . common . storagehubwrapper . shared . tohl . impl . WorkspaceSharedFolder ) wsItem ;
2021-05-18 15:34:43 +02:00
// TODO ASK TO LUCIO;
// size = theFolder.getSize();
2018-11-28 16:50:18 +01:00
}
2019-09-13 16:48:26 +02:00
workspaceLogger . info ( " returning size: " + size ) ;
return size ;
2018-11-28 16:50:18 +01:00
} catch ( Exception e ) {
2019-09-13 16:48:26 +02:00
workspaceLogger . error ( " get Size By ItemId " , e ) ;
throw new Exception ( e . getMessage ( ) ) ;
2018-11-28 16:50:18 +01:00
}
}
2020-05-19 17:22:22 +02:00
/ * *
* Load last modification date by id .
*
* @param itemId the item id
* @return the date
* @throws Exception the exception
* /
2021-05-18 15:34:43 +02:00
/ *
* ( non - Javadoc )
*
* @see org . gcube . portlets . user . workspace . client . rpc . GWTWorkspaceService #
* loadLastModificationDateById ( java . lang . String )
2018-11-28 16:50:18 +01:00
* /
@Override
2019-09-13 16:48:26 +02:00
public Date loadLastModificationDateById ( String itemId ) throws Exception {
2021-05-18 15:34:43 +02:00
2019-09-13 16:48:26 +02:00
if ( itemId = = null )
throw new Exception ( IDENTIFIER_IS_NULL ) ;
2018-11-28 16:50:18 +01:00
2019-09-13 16:48:26 +02:00
workspaceLogger . trace ( " get last modification date ItemId " + itemId ) ;
2018-11-28 16:50:18 +01:00
try {
2021-05-18 15:34:43 +02:00
org . gcube . common . storagehubwrapper . server . tohl . Workspace workspace = getWorkspaceFromStorageHub ( ) ;
org . gcube . common . storagehubwrapper . shared . tohl . WorkspaceItem wsItem = workspace . getItem ( itemId ) ;
2019-09-13 16:48:26 +02:00
Date lastModification = null ;
if ( wsItem . getLastModificationTime ( ) ! = null ) {
lastModification = wsItem . getLastModificationTime ( ) . getTime ( ) ;
2018-11-28 16:50:18 +01:00
}
2019-09-13 16:48:26 +02:00
return lastModification ;
2018-11-28 16:50:18 +01:00
2019-02-22 11:44:01 +01:00
} catch ( Exception e ) {
2019-09-13 16:48:26 +02:00
workspaceLogger . error ( " get last modification date ItemId " , e ) ;
throw new Exception ( e . getMessage ( ) ) ;
2018-11-28 16:50:18 +01:00
}
}
2021-05-18 15:34:43 +02:00
/ *
* ( non - Javadoc )
*
* @see org . gcube . portlets . user . workspace . client . rpc . GWTWorkspaceService #
* getParentByItemId ( java . lang . String )
2018-11-28 16:50:18 +01:00
* /
2020-05-19 17:22:22 +02:00
/ * *
* Gets the parent by item id .
*
* @param identifier the identifier
* @return the parent by item id
* @throws Exception the exception
* /
2021-05-18 15:34:43 +02:00
// TODO NEED TO TEST IT
2018-11-28 16:50:18 +01:00
@Override
2019-09-13 16:48:26 +02:00
public FileModel getParentByItemId ( String identifier ) throws Exception {
2021-05-18 15:34:43 +02:00
2019-09-13 16:48:26 +02:00
if ( identifier = = null )
throw new Exception ( IDENTIFIER_IS_NULL ) ;
2018-11-28 16:50:18 +01:00
2019-09-13 16:48:26 +02:00
workspaceLogger . trace ( " get Parent By Item Identifier " + identifier ) ;
2018-11-28 16:50:18 +01:00
try {
2021-05-18 15:34:43 +02:00
org . gcube . common . storagehubwrapper . server . tohl . Workspace workspace = getWorkspaceFromStorageHub ( ) ;
org . gcube . common . storagehubwrapper . shared . tohl . WorkspaceItem wsItem = workspace . getItem ( identifier ) ;
2019-09-13 16:48:26 +02:00
workspaceLogger . trace ( " workspace has returned item name: " + wsItem . getName ( ) ) ;
2021-05-18 15:34:43 +02:00
2019-09-13 16:48:26 +02:00
FileModel parentModel = null ;
2021-05-18 15:34:43 +02:00
if ( wsItem ! = null & & wsItem . getParentId ( ) ! = null ) {
org . gcube . common . storagehubwrapper . shared . tohl . WorkspaceItem parent = workspace
. getItem ( wsItem . getParentId ( ) ) ;
2019-09-13 16:48:26 +02:00
StorageHubToWorkpaceConverter converter = getStorageHubToWorkpaceConverter ( ) ;
parentModel = converter . toTreeFileModel ( parent , null , parent . isShared ( ) ) ;
2021-05-18 15:34:43 +02:00
2018-11-28 16:50:18 +01:00
}
2019-09-13 16:48:26 +02:00
workspaceLogger . trace ( " parent not found - retuning " ) ;
return parentModel ;
2019-02-22 11:44:01 +01:00
} catch ( Exception e ) {
2019-09-13 16:48:26 +02:00
workspaceLogger . error ( " Error in get Parent By Item Identifier " , e ) ;
e . printStackTrace ( ) ;
throw new Exception ( e . getMessage ( ) ) ;
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 #
2019-09-13 16:48:26 +02:00
* getShortUrl ( java . lang . String )
2018-11-28 16:50:18 +01:00
* /
/ * *
2019-09-13 16:48:26 +02:00
* Gets the short url .
2018-11-28 16:50:18 +01:00
*
2021-05-18 15:34:43 +02:00
* @param longUrl the long url
2019-09-13 16:48:26 +02:00
* @return the short url
2021-05-18 15:34:43 +02:00
* @throws Exception the exception
2018-11-28 16:50:18 +01:00
* /
@Override
2019-09-13 16:48:26 +02:00
public String getShortUrl ( String longUrl ) throws Exception {
2018-11-28 16:50:18 +01:00
2019-09-13 16:48:26 +02:00
workspaceLogger . trace ( " get short url for " + longUrl ) ;
UrlShortener shortener = getUrlShortener ( ) ;
2018-11-28 16:50:18 +01:00
try {
2019-09-13 16:48:26 +02:00
if ( shortener ! = null & & shortener . isAvailable ( ) )
return shortener . shorten ( longUrl ) ;
2018-11-28 16:50:18 +01:00
2019-09-13 16:48:26 +02:00
return longUrl ;
2018-11-28 16:50:18 +01:00
2019-02-22 11:44:01 +01:00
} catch ( Exception e ) {
2019-09-13 16:48:26 +02:00
workspaceLogger . error ( " Error get short url for " , e ) ;
return null ;
2018-11-28 16:50:18 +01:00
}
}
2021-05-18 15:34:43 +02:00
2019-02-22 11:44:01 +01:00
/ *
* ( non - Javadoc )
*
* @see org . gcube . portlets . user . workspace . client . rpc . GWTWorkspaceService #
2019-09-13 16:48:26 +02:00
* getLinkForSendToSwitchBoard ( java . lang . String )
2018-11-28 16:50:18 +01:00
* /
/ * *
2019-09-13 16:48:26 +02:00
* Gets the link for send to switch board .
2018-11-28 16:50:18 +01:00
*
2021-05-18 15:34:43 +02:00
* @param itemId the item id
2019-09-13 16:48:26 +02:00
* @return the link for send to switch board
2021-05-18 15:34:43 +02:00
* @throws Exception the exception
2018-11-28 16:50:18 +01:00
* /
@Override
2019-09-13 16:48:26 +02:00
public String getLinkForSendToSwitchBoard ( String itemId ) throws Exception {
String fallbackValue = ConstantsExplorer . CLARIN_SWITCHBOARD_ENDPOINT_FALLBACK ;
String sbEndpoint = " " ;
2018-11-28 16:50:18 +01:00
try {
2019-09-13 16:48:26 +02:00
sbEndpoint = getCLARINSwitchBoardEndpoint ( ) ;
} catch ( Exception e ) {
workspaceLogger . error (
" Could not find CLARINSwitchBoardEndpoint on IS, returning fallback value: " + fallbackValue ) ;
sbEndpoint = fallbackValue ;
}
String URI = getPublicLinkForFileItemId ( itemId , false ) . getCompleteURL ( ) ;
workspaceLogger . debug ( " Got LinkForSendToSwitchBoard: " + URI + " encoding ... " ) ;
String encodedURI = URLEncoder . encode ( getPublicLinkForFileItemId ( itemId , false ) . getCompleteURL ( ) , " UTF-8 " ) ;
workspaceLogger . debug ( " LinkForSendToSwitchBoard: " + encodedURI + " encoded ... " ) ;
return new StringBuilder ( sbEndpoint ) . append ( encodedURI ) . toString ( ) ;
}
2018-11-28 16:50:18 +01:00
2020-05-19 17:22:22 +02:00
/ * *
* Gets the item description by id .
*
* @param identifier the identifier
* @return the item description by id
* @throws Exception the exception
* /
2021-05-18 15:34:43 +02:00
/ *
* ( non - Javadoc )
*
* @see org . gcube . portlets . user . workspace . client . rpc . GWTWorkspaceService #
* getItemDescriptionById ( java . lang . String )
2019-09-13 16:48:26 +02:00
* /
@Override
public String getItemDescriptionById ( String identifier ) throws Exception {
2021-05-18 15:34:43 +02:00
2019-09-13 16:48:26 +02:00
workspaceLogger . info ( " Getting ItemDescriptionById: " + identifier ) ;
if ( identifier = = null | | identifier . isEmpty ( ) ) {
workspaceLogger . warn ( " Getting ItemDescriptionById identifier is null or empty, returning null " ) ;
return null ;
}
2018-11-28 16:50:18 +01:00
2019-09-13 16:48:26 +02:00
try {
2018-11-28 16:50:18 +01:00
2021-05-18 15:34:43 +02:00
org . gcube . common . storagehubwrapper . server . tohl . Workspace workspace = getWorkspaceFromStorageHub ( ) ;
org . gcube . common . storagehubwrapper . shared . tohl . WorkspaceItem wsItem = workspace . getItem ( identifier ) ;
2019-09-13 16:48:26 +02:00
workspaceLogger . trace ( " workspace has returned item name: " + wsItem . getName ( ) ) ;
return wsItem . getDescription ( ) ;
2018-11-28 16:50:18 +01:00
2019-09-13 16:48:26 +02:00
} catch ( Exception e ) {
workspaceLogger . error ( " Error in server ItemDescriptionById: " , e ) ;
String error = ConstantsExplorer . SERVER_ERROR + " getting description for item id: " + identifier ;
2018-11-28 16:50:18 +01:00
throw new Exception ( error ) ;
2019-09-13 16:48:26 +02:00
}
}
2018-11-28 16:50:18 +01:00
2020-05-19 17:22:22 +02:00
/ * *
* Gets the user workspace size .
*
* @return the user workspace size
* @throws Exception the exception
* /
2021-05-18 15:34:43 +02:00
/ *
* ( non - Javadoc )
*
* @see org . gcube . portlets . user . workspace . client . rpc . GWTWorkspaceService #
* getUserWorkspaceSize ( )
2019-09-13 16:48:26 +02:00
* /
@Override
public String getUserWorkspaceSize ( ) throws Exception {
try {
workspaceLogger . info ( " Getting workspace size.. " ) ;
2021-05-18 15:34:43 +02:00
org . gcube . common . storagehubwrapper . server . tohl . Workspace workspace = getWorkspaceFromStorageHub ( ) ;
2019-09-13 16:48:26 +02:00
long size = workspace . getDiskUsage ( ) ;
// workspaceLogger.info("Root size is: "+size +" formatting..");
String formatSize = FormatterUtil . formatFileSize ( size ) ;
workspaceLogger . info ( " returning workspace size: " + formatSize ) ;
return formatSize ;
2018-11-28 16:50:18 +01:00
} catch ( Exception e ) {
2019-09-13 16:48:26 +02:00
workspaceLogger . error ( " Error on UserWorkspaceSize " , e ) ;
String error = ConstantsExplorer . SERVER_ERROR + " getting disk usage " ;
2018-11-28 16:50:18 +01:00
throw new Exception ( error ) ;
}
}
2021-05-18 15:34:43 +02:00
2019-02-22 11:44:01 +01:00
/ *
* ( non - Javadoc )
*
* @see org . gcube . portlets . user . workspace . client . rpc . GWTWorkspaceService #
2019-09-13 16:48:26 +02:00
* getUserWorkspaceTotalItems ( )
2018-11-28 16:50:18 +01:00
* /
/ * *
2019-09-13 16:48:26 +02:00
* Gets the user workspace total items .
2018-11-28 16:50:18 +01:00
*
2019-09-13 16:48:26 +02:00
* @return the user workspace total items
2021-05-18 15:34:43 +02:00
* @throws Exception the exception
2018-11-28 16:50:18 +01:00
* /
@Override
2019-09-13 16:48:26 +02:00
public long getUserWorkspaceTotalItems ( ) throws Exception {
2018-11-28 16:50:18 +01:00
try {
2019-09-13 16:48:26 +02:00
workspaceLogger . info ( " Getting total items.. " ) ;
2021-05-18 15:34:43 +02:00
org . gcube . common . storagehubwrapper . server . tohl . Workspace workspace = getWorkspaceFromStorageHub ( ) ;
2019-09-13 16:48:26 +02:00
long size = workspace . getTotalItems ( ) ;
workspaceLogger . info ( " returning total items value: " + size ) ;
return size ;
2018-11-28 16:50:18 +01:00
} catch ( Exception e ) {
2019-09-13 16:48:26 +02:00
workspaceLogger . error ( " Error on UserWorkspaceSize " , e ) ;
String error = ConstantsExplorer . SERVER_ERROR + " getting total items " ;
2018-11-28 16:50:18 +01:00
throw new Exception ( error ) ;
}
}
2021-05-18 15:34:43 +02:00
2019-02-22 11:44:01 +01:00
/ *
* ( non - Javadoc )
*
* @see org . gcube . portlets . user . workspace . client . rpc . GWTWorkspaceService #
2019-09-13 16:48:26 +02:00
* getUserWorkspaceQuote ( )
2018-11-28 16:50:18 +01:00
* /
/ * *
2019-09-13 16:48:26 +02:00
* Gets the user workspace quote .
2018-11-28 16:50:18 +01:00
*
2019-09-13 16:48:26 +02:00
* @return the user workspace quote
2021-05-18 15:34:43 +02:00
* @throws Exception the exception
2018-11-28 16:50:18 +01:00
* /
@Override
2019-09-13 16:48:26 +02:00
public WorkspaceUserQuote getUserWorkspaceQuote ( ) throws Exception {
2018-11-28 16:50:18 +01:00
try {
2019-09-13 16:48:26 +02:00
workspaceLogger . info ( " Getting UserWorkspaceQuote.. " ) ;
2021-05-18 15:34:43 +02:00
org . gcube . common . storagehubwrapper . server . tohl . Workspace workspace = getWorkspaceFromStorageHub ( ) ;
2019-09-13 16:48:26 +02:00
long size = workspace . getDiskUsage ( ) ;
workspaceLogger . info ( " Root size is: " + size + " formatting.. " ) ;
String formatSize = FormatterUtil . formatFileSize ( size ) ;
long total = getUserWorkspaceTotalItems ( ) ;
2018-11-28 16:50:18 +01:00
2019-09-13 16:48:26 +02:00
WorkspaceUserQuote quote = new WorkspaceUserQuote ( ) ;
quote . setDiskSpace ( size ) ;
quote . setDiskSpaceFormatted ( formatSize ) ;
quote . setTotalItems ( total ) ;
workspaceLogger . info ( " returning user quote: " + quote ) ;
return quote ;
} catch ( Exception e ) {
workspaceLogger . error ( " Error on UserWorkspaceQuote " , e ) ;
return null ;
}
}
2021-05-18 15:34:43 +02:00
2019-09-13 16:48:26 +02:00
/ *
* ( non - Javadoc )
*
* @see org . gcube . portlets . user . workspace . client . rpc . GWTWorkspaceService #
* loadGcubeItemProperties ( java . lang . String )
* /
/ * *
* Load gcube item properties .
*
2021-05-18 15:34:43 +02:00
* @param itemId the item id
2019-09-13 16:48:26 +02:00
* @return the map
2021-05-18 15:34:43 +02:00
* @throws Exception the exception
2019-09-13 16:48:26 +02:00
* /
@Override
public Map < String , String > loadGcubeItemProperties ( String itemId ) throws Exception {
2021-05-18 15:34:43 +02:00
2019-09-13 16:48:26 +02:00
workspaceLogger . info ( " Getting GcubeItemProperties for itemId: " + itemId ) ;
if ( itemId = = null | | itemId . isEmpty ( ) ) {
workspaceLogger . warn ( " Getting GcubeItemProperties identifier is null or empty, returning null " ) ;
return null ;
}
2018-11-28 16:50:18 +01:00
2019-09-13 16:48:26 +02:00
try {
2021-05-18 15:34:43 +02:00
org . gcube . common . storagehubwrapper . server . tohl . Workspace workspace = getWorkspaceFromStorageHub ( ) ;
2019-09-13 16:48:26 +02:00
PropertyMap properties = workspace . getGcubeItemProperties ( itemId ) ;
StorageHubToWorkpaceConverter converter = getStorageHubToWorkpaceConverter ( ) ;
Map < String , String > mapProperties = converter . toSimpleMap ( properties ) ;
if ( mapProperties ! = null )
workspaceLogger . info ( " Returning " + mapProperties . size ( ) + " properties " ) ;
else
workspaceLogger . info ( " Returning null properties " ) ;
2018-11-28 16:50:18 +01:00
2019-09-13 16:48:26 +02:00
return mapProperties ;
} catch ( Exception e ) {
workspaceLogger . error ( " Error in server GcubeItemProperties: " , e ) ;
String error = ConstantsExplorer . SERVER_ERROR + " getting gcube item properties for item id: " + itemId ;
throw new Exception ( error ) ;
}
}
2021-05-18 15:34:43 +02:00
2019-09-13 16:48:26 +02:00
/ *
* ( non - Javadoc )
*
* @see org . gcube . portlets . user . workspace . client . rpc . GWTWorkspaceService #
* getItemsBySearchName ( java . lang . String )
* /
/ * *
* Gets the items by search name .
*
2021-05-18 15:34:43 +02:00
* @param text the text
* @param folderId the folder id
2019-09-13 16:48:26 +02:00
* @return the items by search name
2021-05-18 15:34:43 +02:00
* @throws Exception the exception
2019-09-13 16:48:26 +02:00
* /
@Override
public List < FileGridModel > getItemsBySearchName ( String text , String folderId ) throws Exception {
2018-11-28 16:50:18 +01:00
2019-09-13 16:48:26 +02:00
try {
2021-05-18 15:34:43 +02:00
org . gcube . common . storagehubwrapper . server . tohl . Workspace workspace = getWorkspaceFromStorageHub ( ) ;
2019-09-13 16:48:26 +02:00
if ( folderId = = null | | folderId . isEmpty ( ) ) {
workspaceLogger . debug ( " searching folderId is null, searching from the root folder " ) ;
folderId = workspace . getRoot ( ) . getId ( ) ;
}
2021-05-18 15:34:43 +02:00
2020-03-13 11:20:18 +01:00
workspaceLogger . debug ( " applying business logic for searching, see #18174 " ) ;
2021-05-18 15:34:43 +02:00
2020-03-13 11:20:18 +01:00
String toSearch = text ;
2021-05-18 15:34:43 +02:00
if ( toSearch . startsWith ( CHAR_FOR_SEARCHING_WITH_EXACTLY_MATCH )
& & toSearch . endsWith ( CHAR_FOR_SEARCHING_WITH_EXACTLY_MATCH ) ) {
workspaceLogger . info ( " Detected intent of exactly matching (the input text is between "
+ CHAR_FOR_SEARCHING_WITH_EXACTLY_MATCH + " char) " ) ;
toSearch = toSearch . substring ( 1 , toSearch . length ( ) - 1 ) ;
workspaceLogger . info ( " exactly matching changed the input text to: " + toSearch ) ;
} else {
toSearch = String . format ( " %s%s%s " , JCR_WILDCARD_TO_SEARCH , toSearch , JCR_WILDCARD_TO_SEARCH ) ;
workspaceLogger . info ( " prepending and appending the wildcard " + JCR_WILDCARD_TO_SEARCH
+ " , changed the input text to: " + toSearch ) ;
2020-03-13 11:20:18 +01:00
}
2018-11-28 16:50:18 +01:00
2020-03-13 11:20:18 +01:00
workspaceLogger . info ( " backend searching for text: " + toSearch + " in the folder id: " + folderId ) ;
2021-05-18 15:34:43 +02:00
List < org . gcube . common . storagehubwrapper . shared . tohl . WorkspaceItem > foundItems = workspace . search ( toSearch ,
folderId ) ;
if ( foundItems = = null ) {
2019-09-13 16:48:26 +02:00
workspaceLogger . info ( " Searching by SHUB returned null, instancing empty list " ) ;
foundItems = new ArrayList < org . gcube . common . storagehubwrapper . shared . tohl . WorkspaceItem > ( ) ;
}
2021-05-18 15:34:43 +02:00
2020-02-03 15:13:02 +01:00
workspaceLogger . info ( " Searching by SHUB returned " + foundItems . size ( ) + " item/s, converting it/them " ) ;
2018-11-28 16:50:18 +01:00
2019-09-13 16:48:26 +02:00
StorageHubToWorkpaceConverter converter = getStorageHubToWorkpaceConverter ( ) ;
List < FileGridModel > listFileGridModels = new ArrayList < FileGridModel > ( ) ;
2021-05-18 15:34:43 +02:00
2019-09-13 16:48:26 +02:00
for ( org . gcube . common . storagehubwrapper . shared . tohl . WorkspaceItem workspaceItem : foundItems ) {
2021-05-18 15:34:43 +02:00
workspaceLogger
. debug ( " Converting grid item: " + workspaceItem . getId ( ) + " name " + workspaceItem . getName ( ) ) ;
2019-09-13 16:48:26 +02:00
listFileGridModels . add ( converter . toGridFileModel ( workspaceItem , null ) ) ;
}
2021-05-18 15:34:43 +02:00
workspaceLogger
. info ( " Search objects converted is/are: " + listFileGridModels . size ( ) + " , returning it/them " ) ;
2018-11-28 16:50:18 +01:00
2019-09-13 16:48:26 +02:00
return listFileGridModels ;
2018-11-28 16:50:18 +01:00
} catch ( Exception e ) {
2019-09-13 16:48:26 +02:00
workspaceLogger . error ( " Error occured on searching: " , e ) ;
throw new Exception ( " Error occured on searching, please retry or contact the support " ) ;
2018-11-28 16:50:18 +01:00
}
}
2021-05-18 15:34:43 +02:00
2019-09-13 16:48:26 +02:00
/ * *
* Gets the children sub tree to root by identifier .
*
2021-05-18 15:34:43 +02:00
* @param itemIdentifier the item identifier
2019-09-13 16:48:26 +02:00
* @return the children sub tree to root by identifier
2021-05-18 15:34:43 +02:00
* @throws Exception the exception
2019-09-13 16:48:26 +02:00
* /
@Override
public ArrayList < SubTree > getChildrenSubTreeToRootByIdentifier ( String itemIdentifier ) throws Exception {
2021-05-18 15:34:43 +02:00
2019-09-13 16:48:26 +02:00
throw new Exception ( " The method getChildrenSubTreeToRootByIdentifier is not implement to interact with SHUB " ) ;
}
2021-05-18 15:34:43 +02:00
2019-02-22 11:44:01 +01:00
/ *
* ( non - Javadoc )
*
* @see org . gcube . portlets . user . workspace . client . rpc . GWTWorkspaceService #
2019-09-13 16:48:26 +02:00
* itemExistsInWorkpaceFolder ( java . lang . String , java . lang . String )
2018-11-28 16:50:18 +01:00
* /
/ * *
2019-09-13 16:48:26 +02:00
* Item exists in workpace folder .
2018-11-28 16:50:18 +01:00
*
2021-05-18 15:34:43 +02:00
* @param parentId the parent id
* @param itemName the item name
2019-09-13 16:48:26 +02:00
* @return the string
2021-05-18 15:34:43 +02:00
* @throws Exception the exception
2018-11-28 16:50:18 +01:00
* /
@Override
2019-09-13 16:48:26 +02:00
public String itemExistsInWorkpaceFolder ( String parentId , String itemName ) throws Exception {
2021-05-18 15:34:43 +02:00
workspaceLogger . debug ( " called itemExistsInWorkpace for name " + itemName + " in the parent Id: " + parentId ) ;
2018-11-28 16:50:18 +01:00
2019-09-13 16:48:26 +02:00
if ( parentId = = null )
throw new Exception ( " I'm not able to perform searching.. the folder id is null " ) ;
2018-11-28 16:50:18 +01:00
try {
2021-05-18 15:34:43 +02:00
org . gcube . common . storagehubwrapper . server . tohl . Workspace workspace = getWorkspaceFromStorageHub ( ) ;
2020-03-12 10:29:04 +01:00
workspaceLogger . info ( " finding by name: " + itemName + " in the folder id: " + parentId ) ;
2021-05-18 15:34:43 +02:00
List < org . gcube . common . storagehubwrapper . shared . tohl . WorkspaceItem > foundItems = workspace . find ( itemName ,
parentId ) ;
2018-11-28 16:50:18 +01:00
2019-09-13 16:48:26 +02:00
if ( foundItems = = null | | foundItems . isEmpty ( ) )
return null ;
2021-05-18 15:34:43 +02:00
2019-09-13 16:48:26 +02:00
return foundItems . get ( 0 ) . getId ( ) ;
2018-11-28 16:50:18 +01:00
2019-09-13 16:48:26 +02:00
// } catch (InternalErrorException e) {
// return null;
// } catch (ItemNotFoundException e) {
// return null;
2018-11-28 16:50:18 +01:00
} catch ( Exception e ) {
2021-05-18 15:34:43 +02:00
String error = " Error on searching the item " + itemName + " in the passed folder id " ;
2019-09-13 16:48:26 +02:00
workspaceLogger . error ( error , e ) ;
throw new Exception ( e . getMessage ( ) ) ;
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 #
2019-09-13 16:48:26 +02:00
* getAccountingHistory ( java . lang . String )
2018-11-28 16:50:18 +01:00
* /
/ * *
2019-09-13 16:48:26 +02:00
* Gets the accounting history .
2018-11-28 16:50:18 +01:00
*
2021-05-18 15:34:43 +02:00
* @param identifier the identifier
2019-09-13 16:48:26 +02:00
* @return the accounting history
2021-05-18 15:34:43 +02:00
* @throws Exception the exception
2018-11-28 16:50:18 +01:00
* /
@Override
2019-09-13 16:48:26 +02:00
public List < GxtAccountingField > getAccountingHistory ( String identifier ) throws Exception {
2021-05-18 15:34:43 +02:00
2019-09-13 16:48:26 +02:00
if ( identifier = = null )
throw new Exception ( " I'm not able to get accounting history... the folder id is null " ) ;
2021-05-18 15:34:43 +02:00
2018-11-28 16:50:18 +01:00
try {
2021-05-18 15:34:43 +02:00
org . gcube . common . storagehubwrapper . server . tohl . Workspace workspace = getWorkspaceFromStorageHub ( ) ;
org . gcube . common . storagehubwrapper . shared . tohl . WorkspaceItem wsItem = workspace . getItem ( identifier , true ,
false , false ) ;
2019-09-13 16:48:26 +02:00
List < AccountEntry > accoutings = wsItem . getAccounting ( ) ;
StorageHubToWorkpaceConverter converter = getStorageHubToWorkpaceConverter ( ) ;
2021-05-18 15:34:43 +02:00
List < GxtAccountingField > listAccounting = converter . buildGXTAccountingItem ( accoutings ,
GxtAccountingEntryType . ALL ) ;
2019-09-13 16:48:26 +02:00
workspaceLogger . debug ( " get accouting returning size " + listAccounting . size ( ) ) ;
return listAccounting ;
2018-11-28 16:50:18 +01:00
2019-09-13 16:48:26 +02:00
} catch ( Exception e ) {
2021-05-18 15:34:43 +02:00
workspaceLogger . error ( " Error reading the accounting history for item id: " + identifier , e ) ;
String error = ConstantsExplorer . SERVER_ERROR + " getting accounting History. "
+ ConstantsExplorer . TRY_AGAIN ;
2019-09-13 16:48:26 +02:00
throw new Exception ( error ) ;
}
}
2021-05-18 15:34:43 +02:00
2019-09-13 16:48:26 +02:00
/ *
* ( non - Javadoc )
*
* @see org . gcube . portlets . user . workspace . client . rpc . GWTWorkspaceService #
* getListOfVREsForLoggedUser ( )
* /
/ * *
* Gets the list of vr es for logged user .
*
* @return the list of vr es for logged user
2021-05-18 15:34:43 +02:00
* @throws Exception the exception
2019-09-13 16:48:26 +02:00
* /
@Override
public List < GcubeVRE > getListOfVREsForLoggedUser ( ) throws Exception {
workspaceLogger . debug ( " getListOfVREsForLoggedUser...: " ) ;
// PortalContextInfo context =
// WsUtil.getPortalContext(this.getThreadLocalRequest());
GCubeUser user = PortalContext . getConfiguration ( ) . getCurrentUser ( this . getThreadLocalRequest ( ) ) ;
long userId = user . getUserId ( ) ;
2018-11-28 16:50:18 +01:00
2019-09-13 16:48:26 +02:00
// Instanciate the manager
GroupManager groupManager = new LiferayGroupManager ( ) ;
List < GcubeVRE > listOfVres = new ArrayList < GcubeVRE > ( ) ;
2018-11-28 16:50:18 +01:00
2019-09-13 16:48:26 +02:00
if ( isTestMode ( ) ) {
listOfVres . add ( new GcubeVRE ( " devVRE " , " /gcube/devsec/devVRE " ) ) ;
listOfVres . add ( new GcubeVRE ( " NextNext " , " /gcube/devNext/NextNext " ) ) ;
return listOfVres ;
}
2018-11-28 16:50:18 +01:00
2019-09-13 16:48:26 +02:00
try {
List < GCubeGroup > listOfGroups = groupManager . listGroupsByUser ( userId ) ;
for ( GCubeGroup gCubeGroup : listOfGroups ) {
if ( groupManager . isVRE ( gCubeGroup . getGroupId ( ) ) ) {
GcubeVRE gcubeVRE = new GcubeVRE ( gCubeGroup . getGroupName ( ) ,
groupManager . getInfrastructureScope ( gCubeGroup . getGroupId ( ) ) ) ;
listOfVres . add ( gcubeVRE ) ;
2018-11-28 16:50:18 +01:00
}
}
2019-09-13 16:48:26 +02:00
} catch ( UserRetrievalFault | UserManagementSystemException | GroupRetrievalFault e ) {
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 " ) ;
}
2018-11-28 16:50:18 +01:00
2019-09-13 16:48:26 +02:00
workspaceLogger . info ( " Returning list of VREs: " + listOfVres ) ;
return listOfVres ;
}
2021-05-18 15:34:43 +02:00
2019-09-13 16:48:26 +02:00
/ * *
* Gets the HTML gcube item properties .
*
2021-05-18 15:34:43 +02: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
2019-09-13 16:48:26 +02:00
* /
@Override
public String getHTMLGcubeItemProperties ( String itemId ) throws Exception {
workspaceLogger . info ( " getting HTMLGcubeItemProperties for itemId: " + itemId ) ;
if ( itemId = = null | | itemId . isEmpty ( ) ) {
2021-05-18 15:34:43 +02:00
workspaceLogger
. warn ( " Error on getting GcubeItemProperties the identifier is null or empty, returning null " ) ;
2019-09-13 16:48:26 +02:00
return null ;
}
2021-05-18 15:34:43 +02:00
2019-09-13 16:48:26 +02:00
try {
2018-11-28 16:50:18 +01:00
2021-05-18 15:34:43 +02:00
org . gcube . common . storagehubwrapper . server . tohl . Workspace workspace = getWorkspaceFromStorageHub ( ) ;
org . gcube . common . storagehubwrapper . shared . tohl . WorkspaceItem wsItem = workspace . getItem ( itemId ) ;
2019-09-13 16:48:26 +02:00
StorageHubToWorkpaceConverter converter = getStorageHubToWorkpaceConverter ( ) ;
return converter . getGcubeItemPropertiesForGcubeItemAsHTML ( wsItem ) ;
2018-11-28 16:50:18 +01:00
2019-09-13 16:48:26 +02:00
} catch ( Exception e ) {
workspaceLogger . error ( " Error in server FormattedGcubeItemProperties: " , e ) ;
String error = ConstantsExplorer . SERVER_ERROR + " getting gcube item properties for item id: " + itemId ;
2018-11-28 16:50:18 +01:00
throw new Exception ( error ) ;
2019-09-13 16:48:26 +02:00
}
}
2021-05-18 15:34:43 +02:00
2019-09-13 16:48:26 +02:00
/ * *
* Gets the accounting readers .
*
2021-05-18 15:34:43 +02:00
* @param identifier the identifier
2019-09-13 16:48:26 +02:00
* @return the accounting readers
2021-05-18 15:34:43 +02:00
* @throws Exception the exception
2019-09-13 16:48:26 +02:00
* /
@Override
public List < GxtAccountingField > getAccountingReaders ( String identifier ) throws Exception {
2021-05-18 15:34:43 +02:00
2019-09-13 16:48:26 +02:00
if ( identifier = = null | | identifier . isEmpty ( ) ) {
workspaceLogger . warn ( " Error on getting accounting history to readers, identifier is null, returning null " ) ;
return null ;
}
2018-11-28 16:50:18 +01:00
2021-05-18 15:34:43 +02:00
workspaceLogger
. debug ( " reading accounting history only to " + GxtAccountingEntryType . READ + " for id: " + identifier ) ;
2019-09-13 16:48:26 +02:00
try {
2021-05-18 15:34:43 +02:00
org . gcube . common . storagehubwrapper . server . tohl . Workspace workspace = getWorkspaceFromStorageHub ( ) ;
org . gcube . common . storagehubwrapper . shared . tohl . WorkspaceItem wsItem = workspace . getItem ( identifier , true ,
false , false ) ;
2019-09-13 16:48:26 +02:00
List < AccountEntry > accoutings = wsItem . getAccounting ( ) ;
StorageHubToWorkpaceConverter converter = getStorageHubToWorkpaceConverter ( ) ;
2021-05-18 15:34:43 +02:00
List < GxtAccountingField > listOfReadFromAccounting = converter . buildGXTAccountingItem ( accoutings ,
GxtAccountingEntryType . READ ) ;
workspaceLogger . info ( " list of " + GxtAccountingEntryType . READ + " into accounting are: "
+ listOfReadFromAccounting . size ( ) ) ;
2019-09-13 16:48:26 +02:00
return listOfReadFromAccounting ;
2021-05-18 15:34:43 +02:00
2018-11-28 16:50:18 +01:00
} catch ( Exception e ) {
2019-09-13 16:48:26 +02:00
workspaceLogger . error ( " Error get accounting readers " , e ) ;
String error = ConstantsExplorer . SERVER_ERROR + " getting account. " + ConstantsExplorer . TRY_AGAIN ;
2018-11-28 16:50:18 +01:00
throw new Exception ( error ) ;
}
}
2021-05-18 15:34:43 +02:00
2018-11-28 16:50:18 +01:00
/ * *
2019-09-13 16:48:26 +02:00
* Sets the gcube item properties .
2018-11-28 16:50:18 +01:00
*
2021-05-18 15:34:43 +02:00
* @param itemId the item id
* @param properties the properties
* @throws Exception the exception
2018-11-28 16:50:18 +01:00
* /
@Override
2019-09-13 16:48:26 +02:00
public void setGcubeItemProperties ( String itemId , Map < String , String > properties ) throws Exception {
workspaceLogger . info ( " Set GcubeItemProperties for itemId: " + itemId ) ;
if ( itemId = = null | | itemId . isEmpty ( ) ) {
workspaceLogger . warn ( " Set GcubeItemProperties, identifier is null or empty, returning " ) ;
throw new Exception ( " The item id is null or empty " ) ;
}
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
2021-05-18 15:34:43 +02:00
org . gcube . common . storagehubwrapper . server . tohl . Workspace workspace = getWorkspaceFromStorageHub ( ) ;
org . gcube . common . storagehubwrapper . shared . tohl . WorkspaceItem wsItem = workspace . getItem ( itemId ) ;
2019-09-13 16:48:26 +02:00
if ( wsItem instanceof org . gcube . common . storagehubwrapper . shared . tohl . impl . GcubeItem ) {
workspaceLogger . info ( " Adding " + properties . size ( ) + " properties to GCubeItem: " + itemId ) ;
2021-05-18 15:34:43 +02:00
Map < String , Object > mapObjs = properties = = null ? null
: new HashMap < String , Object > ( properties . size ( ) ) ;
2019-09-13 16:48:26 +02:00
mapObjs . putAll ( properties ) ;
workspace . updateMetadata ( itemId , mapObjs ) ;
} else
throw new NoGcubeItemTypeException ( " The item is not a Gcube Item " ) ;
2018-11-28 16:50:18 +01:00
2019-09-13 16:48:26 +02:00
} catch ( NoGcubeItemTypeException e ) {
workspaceLogger . error ( " Error on settingss properties to GcubeItem: " , e ) ;
2018-11-28 16:50:18 +01:00
throw new Exception ( e . getMessage ( ) ) ;
2019-09-13 16:48:26 +02:00
} catch ( Exception e ) {
workspaceLogger . error ( " Error on settings properties to GcubeItem: " , e ) ;
String error = ConstantsExplorer . SERVER_ERROR + " setting gcube item properties for item id: " + itemId ;
throw new Exception ( error ) ;
2018-11-28 16:50:18 +01:00
}
}
2021-05-18 15:34:43 +02:00
2018-11-28 16:50:18 +01:00
/ * *
2019-09-13 16:48:26 +02:00
* Creates the external url .
2018-11-28 16:50:18 +01:00
*
2021-05-18 15:34:43 +02:00
* @param parentId the parent id
* @param name the name
* @param description the description
* @param url the url
2019-09-13 16:48:26 +02:00
* @return the file model
2021-05-18 15:34:43 +02:00
* @throws Exception the exception
2018-11-28 16:50:18 +01:00
* /
@Override
2019-09-13 16:48:26 +02:00
public FileModel createExternalUrl ( String parentId , String name , String description , String url ) throws Exception {
2021-05-18 15:34:43 +02:00
workspaceLogger . info ( " Called createExternalUrl [parent: " + parentId + " , url: " + url + " ] " ) ;
2018-11-28 16:50:18 +01:00
try {
2021-05-18 15:34:43 +02:00
2019-09-13 16:48:26 +02:00
if ( parentId = = null ) {
workspaceLogger . error ( " Error on creating url. Parent ID is null " ) ;
throw new Exception ( " Parent ID is null " ) ;
}
2021-05-18 15:34:43 +02:00
2019-09-13 16:48:26 +02:00
checkItemLocked ( parentId ) ;
2018-11-28 16:50:18 +01:00
2021-05-18 15:34:43 +02:00
org . gcube . common . storagehubwrapper . server . tohl . Workspace workspace = getWorkspaceFromStorageHub ( ) ;
org . gcube . common . storagehubwrapper . shared . tohl . WorkspaceItem wsFolderParent = workspace . getItem ( parentId ) ;
2019-09-13 16:48:26 +02:00
StorageHubToWorkpaceConverter converter = getStorageHubToWorkpaceConverter ( ) ;
FileModel parentModel = converter . toTreeFileModel ( wsFolderParent , null , wsFolderParent . isShared ( ) ) ;
2021-05-18 15:34:43 +02:00
2019-09-13 16:48:26 +02:00
workspaceLogger . debug ( " creating the URL... " ) ;
URLItem ext = workspace . createURL ( name , description , url , parentId ) ;
workspaceLogger . info ( " created URL file: " + ext . getName ( ) ) ;
FileModel urlFile = converter . toTreeFileModel ( ext , parentModel , wsFolderParent . isShared ( ) ) ;
return urlFile ;
2018-11-28 16:50:18 +01:00
2019-09-13 16:48:26 +02:00
} catch ( WorkspaceFolderLocked e1 ) {
throw new Exception ( e1 . getMessage ( ) ) ;
2018-11-28 16:50:18 +01:00
2019-02-22 11:44:01 +01:00
} catch ( Exception e ) {
2021-05-18 15:34:43 +02:00
workspaceLogger . error ( " Error on creating the URL in the folder id: " + parentId , e ) ;
2019-09-13 16:48:26 +02:00
throw new Exception ( e . getMessage ( ) ) ;
2018-11-28 16:50:18 +01:00
}
}
2021-05-18 15:34:43 +02:00
2019-02-22 11:44:01 +01:00
/ *
* ( non - Javadoc )
*
* @see org . gcube . portlets . user . workspace . client . rpc . GWTWorkspaceService #
2019-09-13 16:48:26 +02:00
* markFolderAsPublicForFolderItemId ( java . lang . String , boolean )
* /
/ * *
* Mark folder as public for folder item id .
*
2021-05-18 15:34:43 +02:00
* @param folderId the item id
* @param setPublic the set public
2019-09-13 16:48:26 +02:00
* @return the public link
2021-05-18 15:34:43 +02:00
* @throws SessionExpiredException the session expired exception
* @throws Exception the exception
2019-01-09 11:47:58 +01:00
* /
@Override
2019-09-13 16:48:26 +02:00
public PublicLink markFolderAsPublicForFolderItemId ( String folderId , boolean setPublic )
throws SessionExpiredException , Exception {
2021-05-18 15:34:43 +02:00
workspaceLogger . info (
" called markFolderAsPublicForFolderItemId on folder id: " + folderId + " setPublic: " + setPublic ) ;
2019-09-13 16:48:26 +02:00
if ( isSessionExpired ( ) )
throw new SessionExpiredException ( ) ;
2019-01-09 11:47:58 +01:00
2019-02-22 11:44:01 +01:00
try {
2021-05-18 15:34:43 +02:00
org . gcube . common . storagehubwrapper . server . tohl . Workspace workspace = getWorkspaceFromStorageHub ( ) ;
2019-09-13 16:48:26 +02:00
String folderLink = null ;
try {
2021-05-18 15:34:43 +02:00
// Changing access to.. if needed
2019-09-13 16:48:26 +02:00
boolean newStatus = workspace . setFolderAsPublic ( folderId , setPublic ) ;
2021-05-18 15:34:43 +02:00
workspaceLogger . info ( " The folder " + folderId + " has the public status at " + newStatus + " on SHUB " ) ;
// If the folder was published
2019-09-13 16:48:26 +02:00
if ( newStatus ) {
2021-05-18 15:34:43 +02:00
2019-09-13 16:48:26 +02:00
workspaceLogger . info ( " SHUB returned the folder link id: " + folderId ) ;
2021-05-18 15:34:43 +02:00
ApplicationProfileReader apReader = new ApplicationProfileReader ( " Workspace-Explorer-App " ,
" org.gcube.portlets.user.workspaceexplorerapp.server.WorkspaceExplorerAppServiceImpl " ) ;
2019-09-13 16:48:26 +02:00
ApplicationProfile ap = apReader . readProfileFromInfrastrucure ( ) ;
2019-01-09 11:47:58 +01:00
2019-09-13 16:48:26 +02:00
String encriptedFId = StringEncrypter . getEncrypter ( ) . encrypt ( folderId ) ;
workspaceLogger . info ( " Encrypted folder Id: " + encriptedFId ) ;
String encodedFId = StringUtil . base64EncodeStringURLSafe ( encriptedFId ) ;
workspaceLogger . info ( " Encoded in Base 64: " + encodedFId ) ;
workspaceLogger . info ( " Application profile returning url: " + ap . getUrl ( ) ) ;
folderLink = ap . getUrl ( ) + " ?folderId= " + encodedFId ;
String shortURL = null ;
try {
shortURL = getShortUrl ( folderLink ) ;
shortURL = shortURL ! = null ? shortURL : " not available " ;
} catch ( Exception e ) {
workspaceLogger . warn ( " Short url error, skipping " ) ;
shortURL = " not available " ;
}
PublicLink pubL = new PublicLink ( folderLink , shortURL ) ;
2021-05-18 15:34:43 +02:00
workspaceLogger . info ( " Returning the: " + pubL ) ;
2019-09-13 16:48:26 +02:00
return pubL ;
2019-01-09 11:47:58 +01:00
}
2021-05-18 15:34:43 +02:00
workspaceLogger
. info ( " The folder has the public status at " + setPublic + " so returning Public Link as null " ) ;
2019-09-13 16:48:26 +02:00
return null ;
2021-05-18 15:34:43 +02:00
} catch ( Exception e ) {
workspaceLogger . error ( " Error on changing access to folder as public: " + setPublic , e ) ;
2019-09-13 16:48:26 +02:00
String error = ConstantsExplorer . SERVER_ERROR + " changing access to folder id: " + folderId ;
throw new Exception ( error ) ;
2019-01-09 11:47:58 +01:00
}
2019-02-22 11:44:01 +01:00
} catch ( Exception e ) {
2021-05-18 15:34:43 +02:00
workspaceLogger . error ( " Error on getting the folder id: " + folderId , e ) ;
2019-01-09 11:47:58 +01:00
throw new Exception ( e . getMessage ( ) ) ;
}
2019-09-13 16:48:26 +02:00
2019-01-09 11:47:58 +01:00
}
2021-05-18 15:34:43 +02:00
2019-09-13 16:48:26 +02:00
/ *
* ( non - Javadoc )
*
* @see org . gcube . portlets . user . workspace . client . rpc . GWTWorkspaceService #
* getImagesForFolder ( java . lang . String , java . lang . String )
* /
2019-04-17 11:42:48 +02:00
/ * *
2019-09-13 16:48:26 +02:00
* Gets the images for folder .
2019-04-17 11:42:48 +02:00
*
2021-05-18 15:34:43 +02:00
* @param folderId the folder id
* @param currentImageId the current image id
2019-09-13 16:48:26 +02:00
* @return the images for folder
2021-05-18 15:34:43 +02:00
* @throws Exception the exception
2019-04-17 11:42:48 +02:00
* /
@Override
2019-09-13 16:48:26 +02:00
public List < GWTWorkspaceItem > getImagesForFolder ( String folderId , String currentImageId ) throws Exception {
2019-04-17 11:42:48 +02:00
2019-09-13 16:48:26 +02:00
if ( folderId = = null )
return null ;
2019-04-17 11:42:48 +02:00
2019-09-13 16:48:26 +02:00
try {
workspaceLogger . debug ( " get images for folder id: " + folderId ) ;
2021-05-18 15:34:43 +02:00
org . gcube . common . storagehubwrapper . server . tohl . Workspace workspace = getWorkspaceFromStorageHub ( ) ;
org . gcube . common . storagehubwrapper . shared . tohl . WorkspaceItem wsItem = workspace . getItem ( folderId ) ;
2019-04-17 11:42:48 +02:00
2019-09-13 16:48:26 +02:00
List < GWTWorkspaceItem > images = new ArrayList < GWTWorkspaceItem > ( ) ;
2019-04-17 11:42:48 +02:00
2019-09-13 16:48:26 +02:00
if ( wsItem . isFolder ( ) ) {
org . gcube . common . storagehubwrapper . shared . tohl . WorkspaceFolder folder = ( org . gcube . common . storagehubwrapper . shared . tohl . WorkspaceFolder ) wsItem ;
2021-05-18 15:34:43 +02:00
List < ? extends org . gcube . common . storagehubwrapper . shared . tohl . WorkspaceItem > children = workspace
. getChildren ( folder . getId ( ) ) ;
2019-09-13 16:48:26 +02:00
// GWTWorkspaceBuilder builder = getGWTWorkspaceBuilder();
PortalContextInfo context = WsUtil . getPortalContext ( this . getThreadLocalRequest ( ) ) ;
GCubeUser user = PortalContext . getConfiguration ( ) . getCurrentUser ( this . getThreadLocalRequest ( ) ) ;
2019-04-17 11:42:48 +02:00
2019-09-13 16:48:26 +02:00
for ( org . gcube . common . storagehubwrapper . shared . tohl . WorkspaceItem workspaceItem : children ) {
boolean foundCurrentImage = false ;
2021-05-18 15:34:43 +02:00
// IS AN IMAGE?
2019-09-13 16:48:26 +02:00
if ( workspaceItem instanceof ImageFileItem ) {
try {
ImageFileItem imageFileItem = ( ImageFileItem ) workspaceItem ;
GWTWorkspaceItem image = null ;
2021-05-18 15:34:43 +02:00
2019-09-13 16:48:26 +02:00
image = ObjectStorageHubToWorkpaceMapper . buildGWTWorkspaceImage ( imageFileItem , true , false ,
context . getCurrGroupId ( ) + " " , user . getUserId ( ) + " " ) ;
image . setId ( workspaceItem . getId ( ) ) ;
2021-05-18 15:34:43 +02:00
2019-09-13 16:48:26 +02:00
if ( image ! = null ) {
if ( ! foundCurrentImage & & image . getId ( ) . compareTo ( currentImageId ) = = 0 ) {
2021-05-18 15:34:43 +02:00
workspaceLogger . debug ( image . getName ( )
+ " is the current displaying image so adding to list as first element " ) ;
2019-09-13 16:48:26 +02:00
images . add ( 0 , image ) ;
foundCurrentImage = true ;
} else {
workspaceLogger . debug ( " Adding thumbnail name to list: " + image . getName ( ) ) ;
images . add ( image ) ;
}
}
2021-05-18 15:34:43 +02:00
} catch ( Exception e ) {
workspaceLogger . warn ( " Error on managing the file item: " + workspaceItem . getId ( ) + " as an "
+ ImageFileItem . class . getName ( ) ) ;
2019-09-13 16:48:26 +02:00
}
}
2019-04-17 11:42:48 +02:00
}
}
2021-05-18 15:34:43 +02:00
if ( workspaceLogger . isTraceEnabled ( ) ) {
workspaceLogger . trace ( " Returning list of images for folder: " + folderId ) ;
2019-09-13 16:48:26 +02:00
for ( GWTWorkspaceItem gwtWorkspaceItem : images ) {
workspaceLogger . trace ( gwtWorkspaceItem . toString ( ) ) ;
2019-04-17 11:42:48 +02:00
}
}
2019-09-13 16:48:26 +02:00
workspaceLogger . info ( " Returning " + images . size ( ) + " images for folder id: " + folderId ) ;
return images ;
2019-04-17 11:42:48 +02:00
} catch ( Exception e ) {
2019-09-13 16:48:26 +02:00
workspaceLogger . error ( " Error in server get images by folder id: " + folderId , e ) ;
2019-04-17 11:42:48 +02:00
throw new Exception ( e . getMessage ( ) ) ;
}
}
2019-06-19 14:10:24 +02:00
/ * *
2019-09-13 16:48:26 +02:00
* Perform operation on versioned file .
2019-06-19 14:10:24 +02:00
*
2021-05-18 15:34:43 +02:00
* @param fileId the file id
* @param olderVersionIDs the older version i ds
* @param operation the operation
2019-09-13 16:48:26 +02:00
* @return the list
2021-05-18 15:34:43 +02:00
* @throws Exception the exception
2019-06-19 14:10:24 +02:00
* /
@Override
2019-09-13 16:48:26 +02:00
public List < FileVersionModel > performOperationOnVersionedFile ( String fileId , List < String > olderVersionIDs ,
WorkspaceVersioningOperation operation ) throws Exception {
2021-05-18 15:34:43 +02:00
workspaceLogger . info ( " Called perform operation on Versioned File Id: " + fileId + " , Ids Version: "
+ olderVersionIDs + " perform operation: " + operation ) ;
2019-09-13 16:48:26 +02:00
if ( fileId = = null | | olderVersionIDs = = null | | olderVersionIDs . size ( ) = = 0 )
throw new Exception ( " Versioned File id or List of versioned file is null " ) ;
2019-06-19 14:10:24 +02:00
try {
2021-05-18 15:34:43 +02:00
org . gcube . common . storagehubwrapper . server . tohl . Workspace workspace = getWorkspaceFromStorageHub ( ) ;
org . gcube . common . storagehubwrapper . shared . tohl . WorkspaceItem wsItem = workspace . getItem ( fileId ) ;
2019-09-13 16:48:26 +02:00
if ( wsItem instanceof org . gcube . common . storagehubwrapper . shared . tohl . items . FileItem ) {
2021-05-18 15:34:43 +02:00
// org.gcube.common.storagehubwrapper.shared.tohl.items.FileItem fileItem =
// (org.gcube.common.storagehubwrapper.shared.tohl.items.FileItem) wsItem;
2019-09-13 16:48:26 +02:00
switch ( operation ) {
2019-06-19 14:10:24 +02:00
2021-05-18 15:34:43 +02:00
case DOWNLOAD : {
// IMPLEMENTED CLIENT-SIDE
break ;
}
case DELETE_ALL_OLDER_VERSIONS : {
throw new Exception ( operation + " must be implemented on SHUB-side " ) ;
// MUST BE OPTIMIZED HL-SIDE
// for (String olderVersionId : olderVersionIDs) {
//// fileItem.removeVersion(olderVersionId);
// throw new Exception(operation+" must be implemented on SHUB-side");
// workspaceLogger.info("Version " + olderVersionId + " of file id: " + fileId +
// " removed");
// }
// return getVersionHistory(fileId);
}
case REFRESH : {
return getVersionHistory ( fileId ) ;
}
case DELETE_PERMANENTLY : {
throw new Exception ( operation + " must be implemented on SHUB-side " ) ;
// for (String olderVersionId : olderVersionIDs) {
// fileItem.removeVersion(olderVersionId);
// workspaceLogger.info("Version " + olderVersionId + " of file id: " + fileId +
// " removed");
// }
// return getVersionHistory(fileId);
}
default : {
break ;
}
2019-09-13 16:48:26 +02:00
}
2019-07-29 15:27:34 +02:00
2019-09-13 16:48:26 +02:00
return getVersionHistory ( fileId ) ;
2019-07-29 15:27:34 +02:00
2019-09-13 16:48:26 +02:00
} else
throw new FileNotVersionedException ( " Selected file is not versioned " ) ;
2019-07-29 15:27:34 +02:00
} catch ( Exception e ) {
2021-05-18 15:34:43 +02:00
2019-09-13 16:48:26 +02:00
workspaceLogger . error ( " Error during performing operation on versioned file with id: " + fileId , e ) ;
String error = ConstantsExplorer . SERVER_ERROR + " updating versioning of file id: " + fileId ;
2019-07-29 15:27:34 +02:00
throw new Exception ( error ) ;
}
}
2020-07-28 15:02:19 +02:00
/ * *
* Update description for item .
*
2021-05-18 15:34:43 +02:00
* @param itemId the item id
2020-07-28 15:02:19 +02:00
* @param newDescription the new description
* @return the string
* @throws Exception the exception
* /
@Override
public String updateDescriptionForItem ( String itemId , String newDescription ) throws Exception {
workspaceLogger . info ( " Called updateDescriptionForItem for itemID: " + itemId ) ;
if ( itemId = = null | | itemId . isEmpty ( ) )
throw new Exception ( " I can't update the description, the itemId is null " ) ;
workspaceLogger . debug ( " New description is: " + newDescription ) ;
try {
org . gcube . common . storagehubwrapper . server . tohl . Workspace workspace = getWorkspaceFromStorageHub ( ) ;
newDescription = workspace . updateDescriptionForItem ( itemId , newDescription ) ;
} catch ( Exception e ) {
workspaceLogger . error ( " Error on updating the description for item: " + itemId , e ) ;
2021-05-18 15:34:43 +02:00
if ( e . getMessage ( ) . toLowerCase ( ) . contains ( " insufficent privileges " ) ) {
2020-09-29 09:43:52 +02:00
throw new Exception ( " You don't have permission to update this description " ) ;
}
2021-05-18 15:34:43 +02:00
String error = ConstantsExplorer . SERVER_ERROR + " updating the description for item with id: " + " " + itemId
+ " . Error reported: " + e . getMessage ( ) ;
2020-07-28 15:02:19 +02:00
throw new Exception ( error ) ;
}
return newDescription ;
}
/ * *
* Gets the allowed mimetypes for preview .
*
* @return the allowed mimetypes for preview
* /
2021-05-18 15:34:43 +02:00
2020-07-28 15:02:19 +02:00
@Override
2021-05-18 15:34:43 +02:00
public Map < String , List < String > > getAllowedMimetypesForPreview ( ) {
2020-07-28 15:02:19 +02:00
workspaceLogger . info ( " Called getAllowedMimetypesForPreview " ) ;
2021-05-18 15:34:43 +02:00
2020-07-28 15:02:19 +02:00
Map < String , List < String > > map = MimeTypeUtility . getPreviewMimetypeExtensionMap ( ) ;
2021-05-18 15:34:43 +02:00
workspaceLogger . debug ( " Returning allowed mimetypes for preview: " + map . keySet ( ) ) ;
2020-07-28 15:02:19 +02:00
return map ;
2021-05-18 15:34:43 +02:00
2020-07-28 15:02:19 +02:00
}
2019-07-29 15:27:34 +02:00
2013-02-06 15:40:17 +01:00
}