Added getFilteredChildren

Added FileStreamDescription

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/Common/storagehub-client-wrapper@171672 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Francesco Mangiacrapa 2018-09-26 12:37:11 +00:00
parent 3ecfd5d452
commit 6387c61a51
5 changed files with 137 additions and 1 deletions

View File

@ -6,6 +6,7 @@ import java.util.List;
import org.apache.commons.lang.Validate;
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.common.storagehub.client.StreamDescriptor;
import org.gcube.common.storagehub.client.dsl.FileContainer;
import org.gcube.common.storagehub.client.dsl.FolderContainer;
import org.gcube.common.storagehub.client.dsl.GenericItemContainer;
@ -108,6 +109,19 @@ public class StorageHubClientService {
return shcClient.open(id).asFolder().list().withContent().getItems();
}
/**
* Gets the children.
*
* @param id the id
* @return the children
*/
public List<? extends Item> getFilteredChildren(String id, Class<? extends Item> aType){
setContextProviders(scope, authorizationToken);
return shcClient.open(id).asFolder().list().ofType(aType).withContent().getItems();
}
/**
* Gets the item.
@ -316,6 +330,26 @@ public class StorageHubClientService {
}
}
/**
* Download file.
*
* @param itemId the item id
* @param fileName the file name
* @param nodeIdsToExclude the node ids to exclude
* @return the stream descriptor
* @throws Exception the exception
*/
public StreamDescriptor downloadFile(String itemId, String fileName, String nodeIdsToExclude) throws Exception{
try {
StreamDescriptor streamDesc = shcClient.open(itemId).asFile().download(nodeIdsToExclude);
return new StreamDescriptor(streamDesc.getStream(), streamDesc.getFileName());
} catch (Exception e) {
logger.error("Error on downoloading the file: "+fileName+ " with id: "+itemId, e);
throw new Exception("Error on downoloading the file: "+fileName+". Try again");
}
}
/**
* Upload archive.

View File

@ -266,6 +266,23 @@ public final class WorkspaceStorageHubClientService implements Workspace{
return toChildren;
}
/* (non-Javadoc)
* @see org.gcube.portal.storagehubwrapper.shared.tohl.Workspace#getChildren(java.lang.String)
*/
public List<? extends WorkspaceItem> getFilteredChildren(String id, Class<? extends Item> aType){
Validate.notNull(id,"The input id is null");
List<? extends Item> children = storageHubClientService.getFilteredChildren(id, aType);
List<WorkspaceItem> toChildren = new ArrayList<WorkspaceItem>(children.size());
for (Item item : children) {
WorkspaceItem child = HLMapper.toWorkspaceItem(item);
toChildren.add(child);
}
return toChildren;
}
/* (non-Javadoc)
* @see org.gcube.portal.storagehubwrapper.shared.Workspace#getParentsById(java.lang.String)
*/

View File

@ -160,7 +160,7 @@ public class HLMapper {
}
}
((WorkspaceFolder) theItem).setPublicFolder(folderItem.isPublicFolder());
((WorkspaceFolder) theItem).setPublicFolder(folderItem.getPublicFolder());
if(logger.isTraceEnabled()){
WorkspaceFolder theFolder = (WorkspaceFolder) theItem;

View File

@ -0,0 +1,53 @@
/**
*
*/
package org.gcube.common.storagehubwrapper.shared.tohl.impl;
import java.io.InputStream;
import java.io.Serializable;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.gcube.common.storagehubwrapper.shared.tohl.items.FileStreamDescriptor;
/**
* Instantiates a new stream descriptor.
*/
@NoArgsConstructor
/**
* Instantiates a new stream descriptor.
*
* @param stream the stream
* @param fileName the file name
*/
@AllArgsConstructor
/**
* Gets the file name.
*
* @return the file name
*/
@Getter
/**
* Sets the file name.
*
* @param fileName the new file name
*/
@Setter
public class StreamDescriptor implements FileStreamDescriptor, Serializable{
/**
*
*/
private static final long serialVersionUID = -5482612709953553644L;
private InputStream stream;
private String fileName;
}

View File

@ -0,0 +1,32 @@
/**
*
*/
package org.gcube.common.storagehubwrapper.shared.tohl.items;
import java.io.InputStream;
/**
* The Interface FileStreamDescriptor.
*
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
* Sep 26, 2018
*/
public interface FileStreamDescriptor {
/**
* Gets the stream.
*
* @return the stream
*/
public InputStream getStream();
/**
* Gets the file name.
*
* @return the fileName
*/
public String getFileName();
}