added Image Preview to StorageHub
git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/Common/storagehub-client-wrapper@173558 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
a9512d9711
commit
701db13f41
|
@ -12,6 +12,8 @@
|
|||
</Change>
|
||||
<Change>[Task #12664] added Versions facility to StorageHub
|
||||
</Change>
|
||||
<Change>[Task #12720] added Image Preview to StorageHub
|
||||
</Change>
|
||||
</Changeset>
|
||||
<Changeset component="org.gcube.common.storagehubwrapper.0-1-0"
|
||||
date="2018-06-20">
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package org.gcube.common.storagehubwrapper.server;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.InputStream;
|
||||
import java.net.URL;
|
||||
import java.util.List;
|
||||
|
@ -181,7 +182,7 @@ public class StorageHubClientService {
|
|||
* @throws Exception the exception
|
||||
*/
|
||||
public String getIdSharedFolder(String itemId) throws Exception {
|
||||
setContextProviders(scope, authorizationToken);
|
||||
|
||||
return getRootSharedFolder(itemId).getId();
|
||||
}
|
||||
|
||||
|
@ -221,7 +222,6 @@ public class StorageHubClientService {
|
|||
* @throws Exception the exception
|
||||
*/
|
||||
public FolderItem getRootSharedFolder(ItemContainer<Item> itemContainer) throws Exception {
|
||||
setContextProviders(scope, authorizationToken);
|
||||
|
||||
FolderContainer rootSharedFolder = null;
|
||||
Item item = itemContainer.get();
|
||||
|
@ -256,6 +256,7 @@ public class StorageHubClientService {
|
|||
* @return the VRE folders id
|
||||
*/
|
||||
public String getVREFoldersId() {
|
||||
|
||||
setContextProviders(scope, authorizationToken);
|
||||
String toReturn = "";
|
||||
try {
|
||||
|
@ -287,6 +288,7 @@ public class StorageHubClientService {
|
|||
* @throws Exception the exception
|
||||
*/
|
||||
public String getUserACLForFolderId(String infrastructureName, String userName, String folderId) throws Exception {
|
||||
|
||||
setContextProviders(scope, authorizationToken);
|
||||
Item theFolder = getItem(folderId);
|
||||
if (!theFolder.isShared()) {
|
||||
|
@ -321,6 +323,7 @@ public class StorageHubClientService {
|
|||
* @return the item children count
|
||||
*/
|
||||
public int getItemChildrenCount(String itemId) {
|
||||
|
||||
setContextProviders(scope, authorizationToken);
|
||||
ItemManagerClient client = AbstractPlugin.item().build();
|
||||
return client.childrenCount(itemId);
|
||||
|
@ -338,6 +341,7 @@ public class StorageHubClientService {
|
|||
*/
|
||||
public Item uploadFile(String folderId, InputStream is, String fileName, String fileDescription) throws Exception{
|
||||
|
||||
setContextProviders(scope, authorizationToken);
|
||||
FileContainer fileCont = shcClient.open(folderId).asFolder().uploadFile(is, fileName, fileDescription);
|
||||
return fileCont.get();
|
||||
}
|
||||
|
@ -355,6 +359,7 @@ public class StorageHubClientService {
|
|||
*/
|
||||
public StreamDescriptor downloadFile(String itemId, String versionName, String... nodeIdsToExclude) throws Exception{
|
||||
|
||||
setContextProviders(scope, authorizationToken);
|
||||
StreamDescriptor streamDesc;
|
||||
if(versionName!=null && !versionName.isEmpty()){
|
||||
streamDesc = shcClient.open(itemId).asFile().downloadSpecificVersion(versionName);
|
||||
|
@ -376,6 +381,7 @@ public class StorageHubClientService {
|
|||
*/
|
||||
public StreamDescriptor downloadFolder(String folderId, String nodeIdsToExclude) throws Exception{
|
||||
|
||||
setContextProviders(scope, authorizationToken);
|
||||
StreamDescriptor streamDesc = shcClient.open(folderId).asFolder().download(nodeIdsToExclude);
|
||||
return new StreamDescriptor(streamDesc.getStream(), streamDesc.getFileName());
|
||||
|
||||
|
@ -394,6 +400,7 @@ public class StorageHubClientService {
|
|||
*/
|
||||
public Item uploadArchive(String folderId, InputStream is, String extractionFolderName) throws Exception{
|
||||
|
||||
setContextProviders(scope, authorizationToken);
|
||||
FolderContainer folderCont = shcClient.open(folderId).asFolder().uploadArchive(is, extractionFolderName);
|
||||
return folderCont.get();
|
||||
}
|
||||
|
@ -409,6 +416,7 @@ public class StorageHubClientService {
|
|||
*/
|
||||
public List<String> getSharedFolderMembers(String folderId) throws Exception {
|
||||
|
||||
setContextProviders(scope, authorizationToken);
|
||||
Item item = getItem(folderId);
|
||||
if(item instanceof SharedFolder){
|
||||
return ObjectMapper.toListLogins((SharedFolder)item);
|
||||
|
@ -452,7 +460,8 @@ public class StorageHubClientService {
|
|||
*/
|
||||
public void deleteItemById(String itemId) throws Exception{
|
||||
|
||||
Validate.notNull(itemId, "Bad invoking operation the itemId is null");
|
||||
Validate.notNull(itemId, "Bad request of deleteItemById, the itemId is null");
|
||||
setContextProviders(scope, authorizationToken);
|
||||
shcClient.open(itemId).asItem().delete();
|
||||
|
||||
}
|
||||
|
@ -467,6 +476,7 @@ public class StorageHubClientService {
|
|||
*/
|
||||
public Item openTrash() throws Exception{
|
||||
|
||||
setContextProviders(scope, authorizationToken);
|
||||
return shcClient.openTrash().get();
|
||||
|
||||
}
|
||||
|
@ -480,6 +490,7 @@ public class StorageHubClientService {
|
|||
*/
|
||||
public void emptyTrash() throws Exception{
|
||||
|
||||
setContextProviders(scope, authorizationToken);
|
||||
shcClient.emptyTrash();
|
||||
|
||||
}
|
||||
|
@ -494,8 +505,8 @@ public class StorageHubClientService {
|
|||
*/
|
||||
public Item restoreThrashItem(String itemId) throws Exception{
|
||||
|
||||
Validate.notNull(itemId, "Bad invoking restore trash item the item Id is null");
|
||||
|
||||
Validate.notNull(itemId, "Bad request of restoreThrashItem, the itemId is null");
|
||||
setContextProviders(scope, authorizationToken);
|
||||
GenericItemContainer container = shcClient.restoreThrashItem(itemId);
|
||||
|
||||
if(container!=null){
|
||||
|
@ -520,9 +531,9 @@ public class StorageHubClientService {
|
|||
*/
|
||||
public Item moveItem(String itemId, FolderContainer destFolderContainer) throws Exception{
|
||||
|
||||
Validate.notNull(itemId, "Bad invoking move file, the itemId is null");
|
||||
Validate.notNull(destFolderContainer, "Bad invoking move file, the itemId is null");
|
||||
|
||||
Validate.notNull(itemId, "Bad request of moveItem, the itemId is null");
|
||||
Validate.notNull(destFolderContainer, "Bad request of moveItem, the itemId is null");
|
||||
setContextProviders(scope, authorizationToken);
|
||||
shcClient.open(itemId).asItem().move(destFolderContainer);
|
||||
return shcClient.open(itemId).asItem().get();
|
||||
|
||||
|
@ -540,9 +551,9 @@ public class StorageHubClientService {
|
|||
*/
|
||||
public AbstractFileItem copyFileItem(String fileItemId, FolderContainer destFolderContainer, String newFileName) throws Exception{
|
||||
|
||||
Validate.notNull(fileItemId, "Bad invoking copy file, the fileItemId is null");
|
||||
Validate.notNull(destFolderContainer, "Bad invoking copy file, the destFolderContainer is null");
|
||||
|
||||
Validate.notNull(fileItemId, "Bad request of copyFileItem, the fileItemId is null");
|
||||
Validate.notNull(destFolderContainer, "Bad request of copyFileItem, the destFolderContainer is null");
|
||||
setContextProviders(scope, authorizationToken);
|
||||
FileContainer copyingItem = shcClient.open(fileItemId).asFile();
|
||||
String newName = newFileName!=null && !newFileName.isEmpty()?newFileName:"Copy of "+copyingItem.get().getName();
|
||||
FileContainer newItem = copyingItem.copy(destFolderContainer, newName);
|
||||
|
@ -560,8 +571,8 @@ public class StorageHubClientService {
|
|||
*/
|
||||
public Item renameItem(String itemId, String newName) throws Exception{
|
||||
|
||||
Validate.notNull(itemId, "Bad invoking rename item, the itemId is null");
|
||||
|
||||
Validate.notNull(itemId, "Bad request of renameItem, the itemId is null");
|
||||
setContextProviders(scope, authorizationToken);
|
||||
shcClient.open(itemId).asItem().rename(newName);
|
||||
return shcClient.open(itemId).asItem().get();
|
||||
|
||||
|
@ -577,8 +588,8 @@ public class StorageHubClientService {
|
|||
*/
|
||||
public URL getPublicLinkForFile(String fileItemId) throws Exception{
|
||||
|
||||
Validate.notNull(fileItemId, "Bad invoking get public link, the fileItemId is null");
|
||||
|
||||
Validate.notNull(fileItemId, "Bad request of getPublicLinkForFile, the fileItemId is null");
|
||||
setContextProviders(scope, authorizationToken);
|
||||
return shcClient.open(fileItemId).asFile().getPublicLink();
|
||||
|
||||
}
|
||||
|
@ -593,13 +604,39 @@ public class StorageHubClientService {
|
|||
*/
|
||||
public List<Version> getListVersions(String fileItemId) throws Exception{
|
||||
|
||||
Validate.notNull(fileItemId, "Bad invoking get list of versions, the fileItemId is null");
|
||||
Validate.notNull(fileItemId, "Bad request of getListVersions, the fileItemId is null");
|
||||
|
||||
return shcClient.open(fileItemId).asFile().getVersions();
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets the thumbnail data.
|
||||
*
|
||||
* @param itemId the item id
|
||||
* @return the thumbnail data
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
public StreamDescriptor getThumbnailData(String itemId) throws Exception{
|
||||
|
||||
Validate.notNull(itemId, "Bad request of getThumbnailData, the itemId is null");
|
||||
setContextProviders(scope, authorizationToken);
|
||||
ItemContainer<Item> itemCont = shcClient.open(itemId).asItem();
|
||||
Item item = itemCont.get();
|
||||
if(item instanceof org.gcube.common.storagehub.model.items.ImageFile){
|
||||
|
||||
org.gcube.common.storagehub.model.items.ImageFile imgFI = (org.gcube.common.storagehub.model.items.ImageFile) item; //??
|
||||
byte[] thumbBytes = imgFI.getContent().getThumbnailData();
|
||||
if(thumbBytes==null || thumbBytes.length==0)
|
||||
throw new Exception("Thumbnail Data is not available for image: "+item.getName());
|
||||
|
||||
return new StreamDescriptor(new ByteArrayInputStream(thumbBytes), item.getName());
|
||||
}else
|
||||
throw new Exception("Thumbnail Data is not available for type: "+item.getClass().getSimpleName());
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see java.lang.Object#toString()
|
||||
*/
|
||||
|
|
|
@ -859,6 +859,18 @@ public final class WorkspaceStorageHubClientService implements Workspace{
|
|||
}
|
||||
}
|
||||
|
||||
public StreamDescriptor getThumbnailData(String itemId) throws Exception{
|
||||
|
||||
try{
|
||||
|
||||
return storageHubClientService.getThumbnailData(itemId);
|
||||
|
||||
}catch(Exception e){
|
||||
logger.error("Error on getThumbnailData for: "+itemId, e);
|
||||
throw new Exception("Error on getting the Thumbnail. "+e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -9,6 +9,7 @@ import java.net.URL;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.gcube.common.storagehub.client.StreamDescriptor;
|
||||
import org.gcube.common.storagehub.model.items.Item;
|
||||
import org.gcube.common.storagehub.model.types.GenericItemType;
|
||||
import org.gcube.common.storagehubwrapper.shared.ACLType;
|
||||
|
@ -45,7 +46,7 @@ public interface Workspace{
|
|||
*
|
||||
* @return the owner
|
||||
* @throws InternalErrorException the internal error exception
|
||||
* @throws Exception
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
public String getOwner() throws InternalErrorException, Exception;
|
||||
|
||||
|
@ -54,7 +55,7 @@ public interface Workspace{
|
|||
*
|
||||
* @return the root.
|
||||
* @throws InternalErrorException the internal error exception
|
||||
* @throws Exception
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
public WorkspaceFolder getRoot() throws InternalErrorException, Exception;
|
||||
|
||||
|
@ -64,7 +65,7 @@ public interface Workspace{
|
|||
*
|
||||
* @param id the id
|
||||
* @return the children
|
||||
* @throws Exception
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
public List<? extends WorkspaceItem> getChildren(String id) throws Exception;
|
||||
|
||||
|
@ -75,7 +76,7 @@ public interface Workspace{
|
|||
* @param id the id
|
||||
* @return the parents by id
|
||||
* @throws InternalErrorException the internal error exception
|
||||
* @throws Exception
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
public List<? extends WorkspaceItem> getParentsById(String id) throws InternalErrorException, Exception;
|
||||
|
||||
|
@ -86,7 +87,7 @@ public interface Workspace{
|
|||
* @return the item.
|
||||
* @throws ItemNotFoundException if the item has not been found.
|
||||
* @throws InternalErrorException the internal error exception
|
||||
* @throws Exception
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
public WorkspaceItem getItem(String itemId) throws ItemNotFoundException, InternalErrorException, Exception;
|
||||
|
||||
|
@ -101,7 +102,7 @@ public interface Workspace{
|
|||
* @return the item.
|
||||
* @throws ItemNotFoundException if the item has not been found.
|
||||
* @throws InternalErrorException the internal error exception
|
||||
* @throws Exception
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
public WorkspaceItem getItem(String itemId, boolean withAccounting, boolean withFileDetails, boolean withMapProperties) throws ItemNotFoundException, InternalErrorException, Exception;
|
||||
|
||||
|
@ -259,7 +260,7 @@ public interface Workspace{
|
|||
* @param id the id
|
||||
* @param aType the a type
|
||||
* @return the filtered children
|
||||
* @throws Exception
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
public List<? extends WorkspaceItem> getFilteredChildren(String id, Class<? extends Item> aType) throws Exception;
|
||||
|
||||
|
@ -302,7 +303,14 @@ public interface Workspace{
|
|||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Gets the thumbnail data.
|
||||
*
|
||||
* @param itemId the item id
|
||||
* @return the thumbnail data
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
public StreamDescriptor getThumbnailData(String itemId) throws Exception;
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue