@ -4,6 +4,7 @@ import java.io.InputStream;
import java.net.URL ;
import java.util.List ;
import java.util.Map ;
import java.util.Set ;
import org.apache.commons.lang.Validate ;
import org.gcube.common.authorization.library.provider.SecurityTokenProvider ;
@ -15,12 +16,14 @@ import org.gcube.common.storagehub.client.dsl.GenericItemContainer;
import org.gcube.common.storagehub.client.dsl.ItemContainer ;
import org.gcube.common.storagehub.client.dsl.ListResolver ;
import org.gcube.common.storagehub.client.dsl.ListResolverTyped ;
import org.gcube.common.storagehub.client.dsl.OpenResolver ;
import org.gcube.common.storagehub.client.dsl.StorageHubClient ;
import org.gcube.common.storagehub.client.plugins.AbstractPlugin ;
import org.gcube.common.storagehub.client.proxies.ItemManagerClient ;
import org.gcube.common.storagehub.client.proxies.WorkspaceManagerClient ;
import org.gcube.common.storagehub.model.Metadata ;
import org.gcube.common.storagehub.model.acls.ACL ;
import org.gcube.common.storagehub.model.acls.AccessType ;
import org.gcube.common.storagehub.model.exceptions.StorageHubException ;
import org.gcube.common.storagehub.model.items.AbstractFileItem ;
import org.gcube.common.storagehub.model.items.ExternalLink ;
@ -32,7 +35,10 @@ import org.gcube.common.storagehub.model.items.VreFolder;
import org.gcube.common.storagehub.model.items.nodes.Accounting ;
import org.gcube.common.storagehub.model.items.nodes.ImageContent ;
import org.gcube.common.storagehub.model.service.Version ;
import org.gcube.common.storagehubwrapper.server.converter.HLMapper ;
import org.gcube.common.storagehubwrapper.server.converter.ObjectMapper ;
import org.gcube.common.storagehubwrapper.shared.ACLType ;
import org.gcube.common.storagehubwrapper.shared.tohl.WorkspaceSharedFolder ;
import org.gcube.common.storagehubwrapper.shared.tohl.exceptions.ItemNotFoundException ;
import org.slf4j.Logger ;
import org.slf4j.LoggerFactory ;
@ -141,6 +147,34 @@ public class StorageHubClientService {
return theResolver . getItems ( ) ;
}
/ * *
* Gets the children .
*
* @param id the id
* @param withAccounting the with accounting
* @param withMapProperties the with map properties
* @return the children
* @throws Exception the exception
* /
public List < ? extends Item > getChildren ( String id , boolean withAccounting , boolean withMapProperties , boolean includeHidden ) throws Exception {
setContextProviders ( scope , authorizationToken ) ;
logger . trace ( "Requesting getChildren for id: " + id + " [withAccounting: " + withAccounting + ", withMapProperties: " + withMapProperties + "]" ) ;
if ( ! includeHidden ) {
return getChildren ( id , withAccounting , withMapProperties ) ;
}
ListResolver theResolver = shClient . open ( id ) . asFolder ( ) . list ( ) . includeHidden ( ) . withContent ( ) ;
if ( withAccounting )
theResolver = theResolver . withAccounting ( ) ;
if ( withMapProperties )
theResolver = theResolver . withMetadata ( ) ;
return theResolver . getItems ( ) ;
}
/ * *
@ -194,6 +228,26 @@ public class StorageHubClientService {
return itemCont . get ( ) ;
}
/ * *
*
* @param folderId
* @param relativePath
* @return
* @throws Exception
* /
public Item getItemByPath ( String folderId , String relativePath ) throws Exception {
setContextProviders ( scope , authorizationToken ) ;
FolderContainer itemCont = shClient . open ( folderId ) . asFolder ( ) ;
FolderContainer attachmentFolder = null ;
try {
OpenResolver oRes = itemCont . openByRelativePath ( relativePath ) ;
attachmentFolder = oRes . asFolder ( ) ;
return ( Item ) attachmentFolder . get ( ) ;
} catch ( StorageHubException e ) {
e . printStackTrace ( ) ;
}
return null ;
}
/ * *
* Gets the item .
@ -879,7 +933,70 @@ public class StorageHubClientService {
shClient . open ( itemId ) . asItem ( ) . setMetadata ( new Metadata ( mapProperties ) ) ;
}
/ * *
* Sets the Folder As Hidden or visible .
*
* @param itemId the folder id
* @param hide true to set hide , false to set visible
* @throws Exception the exception
* /
public void setFolderAsHidden ( String folderId , boolean hide ) throws Exception {
Validate . notNull ( folderId , "Bad request to setFolderAsHidden the folderId is null" ) ;
setContextProviders ( scope , authorizationToken ) ;
FolderContainer folderContainer = shClient . open ( folderId ) . asFolder ( ) ;
if ( hide )
folderContainer . setHidden ( ) ; //will not appear in the workspace GUI
else
folderContainer . setVisible ( ) ; //will appear in the workspace GUI
}
/ * *
*
* @param folderId the folder id to share
* @param users the users to share
* @param type the permission
* /
public WorkspaceSharedFolder shareFolder ( String folderId , Set < String > users , ACLType type ) throws Exception {
Validate . notNull ( folderId , "Bad request to setFolderAsHidden the folderId is null" ) ;
setContextProviders ( scope , authorizationToken ) ;
AccessType acType ;
switch ( type ) {
case READ_ONLY :
acType = AccessType . READ_ONLY ;
break ;
case ADMINISTRATOR :
acType = AccessType . ADMINISTRATOR ;
break ;
case WRITE_ALL :
acType = AccessType . WRITE_ALL ;
break ;
case WRITE_OWNER :
acType = AccessType . WRITE_OWNER ;
break ;
case NONE :
acType = null ;
break ;
default :
acType = AccessType . WRITE_OWNER ;
break ;
}
FolderContainer fContainer = shClient . open ( folderId ) . asFolder ( ) . share ( users , acType ) ;
return HLMapper . toWorkspaceItem ( fContainer . get ( ) ) ;
}
/ * *
*
* @param folderId the folder id to share
* @param users the users to share
* /
public WorkspaceSharedFolder unshareFolder ( String folderId , Set < String > users ) throws Exception {
Validate . notNull ( folderId , "Bad request to setFolderAsHidden the folderId is null" ) ;
setContextProviders ( scope , authorizationToken ) ;
FolderContainer fContainer = shClient . open ( folderId ) . asFolder ( ) . unshare ( users ) ;
return HLMapper . toWorkspaceItem ( fContainer . get ( ) ) ;
}
/ * *
* Adds the URL .