added getListVersionsForFile

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/Common/storagehub-client-wrapper@173332 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Francesco Mangiacrapa 2018-10-12 12:19:09 +00:00
parent 0b6e876cc3
commit 11b602fd59
8 changed files with 133 additions and 5 deletions

View File

@ -10,6 +10,8 @@
<Change>[Task #12603] added Rename facility to StorageHub</Change>
<Change>[Task #12603] added Public Link facility to StorageHub
</Change>
<Change>[Task #12664] added Versions facility to StorageHub
</Change>
</Changeset>
<Changeset component="org.gcube.common.storagehubwrapper.0-1-0"
date="2018-06-20">

View File

@ -24,6 +24,7 @@ import org.gcube.common.storagehub.model.items.FolderItem;
import org.gcube.common.storagehub.model.items.Item;
import org.gcube.common.storagehub.model.items.SharedFolder;
import org.gcube.common.storagehub.model.items.VreFolder;
import org.gcube.common.storagehub.model.service.Version;
import org.gcube.common.storagehubwrapper.server.converter.ObjectMapper;
import org.gcube.common.storagehubwrapper.shared.tohl.exceptions.ItemNotFoundException;
import org.slf4j.Logger;
@ -544,7 +545,6 @@ public class StorageHubClientService {
}
/**
* Rename item.
*
@ -572,13 +572,29 @@ public class StorageHubClientService {
*/
public URL getPublicLinkForFile(String fileItemId) throws Exception{
Validate.notNull(fileItemId, "Bad invoking get public link, the itemId is null");
Validate.notNull(fileItemId, "Bad invoking get public link, the fileItemId is null");
return shcClient.open(fileItemId).asFile().getPublicLink();
}
/**
* Gets the list versions.
*
* @param fileItemId the file item id
* @return the list versions
* @throws Exception the exception
*/
public List<Version> getListVersions(String fileItemId) throws Exception{
Validate.notNull(fileItemId, "Bad invoking get list of versions, the fileItemId is null");
return shcClient.open(fileItemId).asFile().getVersions();
}
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/

View File

@ -18,6 +18,7 @@ import org.gcube.common.storagehub.client.dsl.FolderContainer;
import org.gcube.common.storagehub.model.items.AbstractFileItem;
import org.gcube.common.storagehub.model.items.FolderItem;
import org.gcube.common.storagehub.model.items.Item;
import org.gcube.common.storagehub.model.service.Version;
import org.gcube.common.storagehub.model.types.GenericItemType;
import org.gcube.common.storagehubwrapper.server.converter.HLMapper;
import org.gcube.common.storagehubwrapper.server.tohl.Workspace;
@ -32,6 +33,7 @@ import org.gcube.common.storagehubwrapper.shared.tohl.exceptions.ItemNotFoundExc
import org.gcube.common.storagehubwrapper.shared.tohl.exceptions.WorkspaceFolderNotFoundException;
import org.gcube.common.storagehubwrapper.shared.tohl.exceptions.WrongDestinationException;
import org.gcube.common.storagehubwrapper.shared.tohl.exceptions.WrongItemTypeException;
import org.gcube.common.storagehubwrapper.shared.tohl.impl.WorkspaceFileVersion;
import org.gcube.common.storagehubwrapper.shared.tohl.impl.WorkspaceFolder;
import org.gcube.common.storagehubwrapper.shared.tohl.items.ItemStreamDescriptor;
import org.gcube.common.storagehubwrapper.shared.tohl.items.URLFileItem;
@ -825,6 +827,37 @@ public final class WorkspaceStorageHubClientService implements Workspace{
}
}
/**
* Gets the list versions for file.
*
* @param fileItemId the file item id
* @return the list versions for file
* @throws Exception the exception
*/
public List<WorkspaceFileVersion> getListVersionsForFile(String fileItemId) throws Exception{
try{
List<Version> versions = storageHubClientService.getListVersions(fileItemId);
if(versions==null || versions.size()==0){
logger.info("No version found for fileItemId: "+fileItemId);
return new ArrayList<WorkspaceFileVersion>(1);
}
List<WorkspaceFileVersion> listVersions = new ArrayList<WorkspaceFileVersion>(versions.size());
for (Version version : versions) {
listVersions.add(HLMapper.toWorkspaceFileVersion(version));
}
return listVersions;
}catch(Exception e){
logger.error("Error on getting public link: "+fileItemId, e);
String error = e.getMessage()!=null?e.getMessage():"Operation not allowed";
throw new Exception("Error on getting public link. "+error);
}
}

View File

@ -23,6 +23,7 @@ import org.gcube.common.storagehub.model.items.nodes.Content;
import org.gcube.common.storagehub.model.items.nodes.ImageContent;
import org.gcube.common.storagehub.model.items.nodes.PDFContent;
import org.gcube.common.storagehub.model.items.nodes.accounting.AccountEntry;
import org.gcube.common.storagehub.model.service.Version;
import org.gcube.common.storagehubwrapper.shared.tohl.WorkspaceItem;
import org.gcube.common.storagehubwrapper.shared.tohl.WorkspaceItemType;
import org.gcube.common.storagehubwrapper.shared.tohl.impl.AccountingEntry;
@ -32,6 +33,7 @@ import org.gcube.common.storagehubwrapper.shared.tohl.impl.ImageFile;
import org.gcube.common.storagehubwrapper.shared.tohl.impl.PDFFile;
import org.gcube.common.storagehubwrapper.shared.tohl.impl.PropertyMap;
import org.gcube.common.storagehubwrapper.shared.tohl.impl.URLFile;
import org.gcube.common.storagehubwrapper.shared.tohl.impl.WorkspaceFileVersion;
import org.gcube.common.storagehubwrapper.shared.tohl.impl.WorkspaceFolder;
import org.gcube.common.storagehubwrapper.shared.tohl.impl.WorkspaceSharedFolder;
import org.gcube.common.storagehubwrapper.shared.tohl.items.FileItemType;
@ -114,6 +116,22 @@ public class HLMapper {
return pm;
}
/**
* To workspace file version.
*
* @param fileVersion the file version
* @return the workspace file version
*/
public static WorkspaceFileVersion toWorkspaceFileVersion(Version fileVersion){
WorkspaceFileVersion wsFileVersion = new WorkspaceFileVersion();
wsFileVersion.setId(fileVersion.getId());
wsFileVersion.setName(fileVersion.getName());
wsFileVersion.setCreated(fileVersion.getCreated());
//TODO MUST BE TERMINATED
return wsFileVersion;
}
/**
* To workspace item.
*

View File

@ -40,4 +40,5 @@ public class ObjectMapper {
logger.debug("Returning "+listUsers.size()+" member/s for sharedFolder with id: "+sharedfolder.getId());
return listUsers;
}
}

View File

@ -23,6 +23,7 @@ import org.gcube.common.storagehubwrapper.shared.tohl.exceptions.ItemNotFoundExc
import org.gcube.common.storagehubwrapper.shared.tohl.exceptions.WorkspaceFolderNotFoundException;
import org.gcube.common.storagehubwrapper.shared.tohl.exceptions.WrongDestinationException;
import org.gcube.common.storagehubwrapper.shared.tohl.exceptions.WrongItemTypeException;
import org.gcube.common.storagehubwrapper.shared.tohl.impl.WorkspaceFileVersion;
import org.gcube.common.storagehubwrapper.shared.tohl.items.ItemStreamDescriptor;
import org.gcube.common.storagehubwrapper.shared.tohl.items.URLFileItem;
@ -283,6 +284,14 @@ public interface Workspace{
public URL getPublicLinkForFile(String fileItemId) throws Exception;
/**
* Gets the list versions for file.
*
* @param fileItemId the file item id
* @return the list versions for file
* @throws Exception the exception
*/
public List<WorkspaceFileVersion> getListVersionsForFile(String fileItemId) throws Exception;

View File

@ -0,0 +1,41 @@
/**
*
*/
package org.gcube.common.storagehubwrapper.shared.tohl.impl;
import java.io.Serializable;
import java.util.Calendar;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;
/**
*
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* Oct 12, 2018
*/
@NoArgsConstructor
@AllArgsConstructor
@Getter
@Setter
@ToString
public class WorkspaceFileVersion implements org.gcube.common.storagehubwrapper.shared.tohl.items.WorkspaceVersion, Serializable{
/**
*
*/
private static final long serialVersionUID = 7925779107708330163L;
String id;
String name;
Calendar created;
String owner;
String remotePath;
Long size;
boolean isCurrentVersion;
}

View File

@ -10,10 +10,18 @@ import java.util.Calendar;
* The Interface WorkspaceVersion.
*
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
* Jun 15, 2018
* Oct 12, 2018
*/
public interface WorkspaceVersion {
/**
* Gets the id.
*
* @return the id
*/
public String getId();
/**
* Gets the name.
*
@ -33,7 +41,7 @@ public interface WorkspaceVersion {
*
* @return the user
*/
public String getUser();
public String getOwner();
/**
* Gets the remote path.
@ -47,7 +55,7 @@ public interface WorkspaceVersion {
*
* @return the size
*/
public long getSize();
public Long getSize();
/**
* Checks if is current version.