ref #11879: TDM - Update to StorageHUB

https://support.d4science.org/issues/#11879

Updated to StorageHub



git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/tabular-data-gwt-service@169564 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Giancarlo Panichi 2018-06-29 16:04:59 +00:00
parent 0320dd2597
commit 309ea09453
4 changed files with 86 additions and 103 deletions

View File

@ -1,12 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<classpath> <classpath>
<classpathentry kind="src" output="target/tabular-data-gwt-service-2.20.0-SNAPSHOT/WEB-INF/classes" path="src/main/java"> <classpathentry kind="src" output="target/tabular-data-gwt-service-2.21.0-SNAPSHOT/WEB-INF/classes" path="src/main/java">
<attributes> <attributes>
<attribute name="optional" value="true"/> <attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/> <attribute name="maven.pomderived" value="true"/>
</attributes> </attributes>
</classpathentry> </classpathentry>
<classpathentry excluding="**" kind="src" output="target/tabular-data-gwt-service-2.20.0-SNAPSHOT/WEB-INF/classes" path="src/main/resources"> <classpathentry excluding="**" kind="src" output="target/tabular-data-gwt-service-2.21.0-SNAPSHOT/WEB-INF/classes" path="src/main/resources">
<attributes> <attributes>
<attribute name="maven.pomderived" value="true"/> <attribute name="maven.pomderived" value="true"/>
</attributes> </attributes>
@ -33,5 +33,5 @@
<attribute name="org.eclipse.jst.component.nondependency" value=""/> <attribute name="org.eclipse.jst.component.nondependency" value=""/>
</attributes> </attributes>
</classpathentry> </classpathentry>
<classpathentry kind="output" path="target/tabular-data-gwt-service-2.20.0-SNAPSHOT/WEB-INF/classes"/> <classpathentry kind="output" path="target/tabular-data-gwt-service-2.21.0-SNAPSHOT/WEB-INF/classes"/>
</classpath> </classpath>

View File

@ -1,4 +1,8 @@
<ReleaseNotes> <ReleaseNotes>
<Changeset component="org.gcube.portlets-user.tabular-data-gwt-service.2-21-0"
date="2018-07-01">
<Change>Updated to StorageHub [task #11879]</Change>
</Changeset>
<Changeset component="org.gcube.portlets-user.tabular-data-gwt-service.2-20-0" <Changeset component="org.gcube.portlets-user.tabular-data-gwt-service.2-20-0"
date="2018-01-12"> date="2018-01-12">
<Change>Added Excel Dataset Export support [ticket #9944]</Change> <Change>Added Excel Dataset Export support [ticket #9944]</Change>

View File

@ -14,7 +14,7 @@
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>org.gcube.portlets.user</groupId> <groupId>org.gcube.portlets.user</groupId>
<artifactId>tabular-data-gwt-service</artifactId> <artifactId>tabular-data-gwt-service</artifactId>
<version>2.20.0-SNAPSHOT</version> <version>2.21.0-SNAPSHOT</version>
<name>tabular-data-gwt-service</name> <name>tabular-data-gwt-service</name>
<description>tabular-data-gwt-service allows communication between the GUI and services</description> <description>tabular-data-gwt-service allows communication between the GUI and services</description>
@ -202,6 +202,13 @@
<artifactId>storage-manager-wrapper</artifactId> <artifactId>storage-manager-wrapper</artifactId>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<!-- StorageHub -->
<dependency>
<groupId>org.gcube.common</groupId>
<artifactId>storagehub-client-library</artifactId>
<scope>provided</scope>
</dependency>
<!-- Home Library --> <!-- Home Library -->
<dependency> <dependency>

View File

@ -4,7 +4,6 @@ import java.io.BufferedInputStream;
import java.io.BufferedOutputStream; import java.io.BufferedOutputStream;
import java.io.File; import java.io.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.net.URL; import java.net.URL;
import java.net.URLConnection; import java.net.URLConnection;
@ -15,6 +14,11 @@ import org.gcube.common.homelibrary.home.workspace.WorkspaceFolder;
import org.gcube.common.homelibrary.home.workspace.WorkspaceItem; import org.gcube.common.homelibrary.home.workspace.WorkspaceItem;
import org.gcube.common.homelibrary.home.workspace.WorkspaceSharedFolder; import org.gcube.common.homelibrary.home.workspace.WorkspaceSharedFolder;
import org.gcube.common.homelibrary.util.WorkspaceUtil; import org.gcube.common.homelibrary.util.WorkspaceUtil;
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.StorageHubClient;
import org.gcube.common.storagehub.model.items.AbstractFileItem;
import org.gcube.contentmanagement.blobstorage.service.IClient; import org.gcube.contentmanagement.blobstorage.service.IClient;
import org.gcube.contentmanager.storageclient.wrapper.AccessType; import org.gcube.contentmanager.storageclient.wrapper.AccessType;
import org.gcube.contentmanager.storageclient.wrapper.MemoryType; import org.gcube.contentmanager.storageclient.wrapper.MemoryType;
@ -52,7 +56,6 @@ public class FilesStorage {
} catch (Throwable e) { } catch (Throwable e) {
logger.error("Error no csv file loaded on storage" + e.getLocalizedMessage()); logger.error("Error no csv file loaded on storage" + e.getLocalizedMessage());
e.printStackTrace();
throw e; throw e;
} }
@ -75,7 +78,6 @@ public class FilesStorage {
return id; return id;
} catch (Throwable e) { } catch (Throwable e) {
logger.error("Error no codelist mapping file loaded on storage" + e.getLocalizedMessage()); logger.error("Error no codelist mapping file loaded on storage" + e.getLocalizedMessage());
e.printStackTrace();
throw e; throw e;
} }
@ -92,29 +94,24 @@ public class FilesStorage {
* Exception * Exception
*/ */
public String storageCodelistMappingTempFile(String user, String url) throws TDGWTServiceException { public String storageCodelistMappingTempFile(String user, String url) throws TDGWTServiceException {
InputStream is = null;
try { try {
URL address = new URL(url); String id = null;
is = address.openStream();
IClient client = new StorageClient(user, AccessType.PUBLIC, MemoryType.VOLATILE).getClient(); URL address = new URL(url);
String remotePath = "/CodelistMappingImport/" + address.getFile(); try (InputStream is = address.openStream()) {
logger.debug("remotePath: " + remotePath);
String id = client.put(true).LFile(is).RFile(remotePath); IClient client = new StorageClient(user, AccessType.PUBLIC, MemoryType.VOLATILE).getClient();
is.close(); String remotePath = "/CodelistMappingImport/" + address.getFile();
logger.debug("remotePath: " + remotePath);
id = client.put(true).LFile(is).RFile(remotePath);
}
return id; return id;
} catch (IOException e) {
logger.error("Error no codelist mapping file loaded on storage" + e.getLocalizedMessage());
e.printStackTrace();
throw new TDGWTServiceException(
"Error no codelist mapping file loaded on storage" + e.getLocalizedMessage());
} catch (Throwable e) { } catch (Throwable e) {
logger.error("Error no codelist mapping file loaded on storage" + e.getLocalizedMessage()); logger.error("Error no codelist mapping file loaded on storage" + e.getLocalizedMessage());
e.printStackTrace(); throw new TDGWTServiceException(
throw e; "Error no codelist mapping file loaded on storage" + e.getLocalizedMessage());
} }
} }
/** /**
@ -130,41 +127,31 @@ public class FilesStorage {
* Exception * Exception
*/ */
public void retrieveFile(String user, WorkspaceItem wi, File file) throws TDGWTServiceException { public void retrieveFile(String user, WorkspaceItem wi, File file) throws TDGWTServiceException {
InputStream is = null;
try { try {
logger.debug("retrieveFile: [user=" + user + ", item=" + wi + "]");
org.gcube.common.homelibrary.home.workspace.folder.items.File gcubeItem = ((org.gcube.common.homelibrary.home.workspace.folder.items.File) wi); StorageHubClient shc = new StorageHubClient();
// SMPUrl smsHome = new SMPUrl(gcubeItem.getPublicLink()); FileContainer fileContainer = shc.open(wi.getId()).asFile();
URL url = new URL(gcubeItem.getPublicLink()); StreamDescriptor streamDescriptor = fileContainer.download();
try (BufferedInputStream bis = new BufferedInputStream(streamDescriptor.getStream())) {
logger.debug("smsHome: [host:" + url.getHost() + " path:" + url.getPath() + " ref:" + url.getRef() try (BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(file))) {
+ " userinfo:" + url.getUserInfo() + " ]");
URLConnection uc = null; byte[] buffer = new byte[1024];
uc = (URLConnection) url.openConnection(); int readCount;
is = uc.getInputStream(); while ((readCount = bis.read(buffer)) > 0) {
bos.write(buffer, 0, readCount);
} catch (Throwable e) { }
logger.error("Error retrieving file from storage", e); } catch (Throwable e) {
e.printStackTrace(); logger.error("Error trasferring file from storage: " + e.getLocalizedMessage(), e);
throw new TDGWTServiceException("Error retrieving file from storage: " + e.getLocalizedMessage(), e); throw new TDGWTServiceException("Error trasferring file from storage: " + e.getLocalizedMessage(),
} e);
}
try {
BufferedInputStream bis = new BufferedInputStream(is);
FileOutputStream os = new FileOutputStream(file);
BufferedOutputStream bos = new BufferedOutputStream(os);
byte[] buffer = new byte[1024];
int readCount;
while ((readCount = bis.read(buffer)) > 0) {
bos.write(buffer, 0, readCount);
} }
bos.close();
} catch (Throwable e) {
logger.error("Error trasferring file from storage: " + e.getLocalizedMessage(), e);
e.printStackTrace();
throw new TDGWTServiceException("Error trasferring file from storage: " + e.getLocalizedMessage(), e);
} catch (Throwable e) {
logger.error("Error retrieving file from StorageHub", e);
throw new TDGWTServiceException("Error retrieving file from StorageHub: " + e.getLocalizedMessage(), e);
} }
} }
/** /**
@ -181,21 +168,15 @@ public class FilesStorage {
public InputStream retrieveInputStream(String user, WorkspaceItem wi) throws TDGWTServiceException { public InputStream retrieveInputStream(String user, WorkspaceItem wi) throws TDGWTServiceException {
InputStream is = null; InputStream is = null;
try { try {
logger.debug("retrieveFile: [user=" + user + ", item=" + wi + "]");
org.gcube.common.homelibrary.home.workspace.folder.items.File gcubeItem = ((org.gcube.common.homelibrary.home.workspace.folder.items.File) wi); StorageHubClient shc = new StorageHubClient();
// SMPUrl smsHome = new SMPUrl(gcubeItem.getPublicLink()); FileContainer fileContainer = shc.open(wi.getId()).asFile();
URL url = new URL(gcubeItem.getPublicLink()); StreamDescriptor streamDescriptor = fileContainer.download();
is = streamDescriptor.getStream();
logger.debug("smsHome: [host:" + url.getHost() + " path:" + url.getPath() + " ref:" + url.getRef()
+ " userinfo:" + url.getUserInfo() + " ]");
URLConnection uc = null;
uc = (URLConnection) url.openConnection();
is = uc.getInputStream();
} catch (Throwable e) { } catch (Throwable e) {
logger.error("Error retrieving file from storage", e); logger.error("Error retrieving file from StorageHub", e);
e.printStackTrace(); throw new TDGWTServiceException("Error retrieving file from StorageHub: " + e.getLocalizedMessage(), e);
throw new TDGWTServiceException("Error retrieving file from storage: " + e.getLocalizedMessage(), e);
} }
return is; return is;
@ -225,7 +206,6 @@ public class FilesStorage {
} catch (Throwable e) { } catch (Throwable e) {
logger.error("Error retrieving file from storage", e); logger.error("Error retrieving file from storage", e);
e.printStackTrace();
throw new TDGWTServiceException("Error retrieving file from storage: " + e.getLocalizedMessage(), e); throw new TDGWTServiceException("Error retrieving file from storage: " + e.getLocalizedMessage(), e);
} }
@ -239,23 +219,22 @@ public class FilesStorage {
* Uri * Uri
* @param user * @param user
* User * User
* @param item_name * @param itemName
* Item name * Item name
* @param item_description * @param itemDescription
* Item description * Item description
* @param item_mimetype * @param itemMimetype
* Item mime type * Item mime type
* @param item_folder * @param folderId
* Destination folder * Destination folder
* @throws TDGWTServiceException * @throws TDGWTServiceException
* Exception * Exception
*/ */
public void createItemOnWorkspace(String uri, String user, String item_name, String item_description, public void createItemOnWorkspace(String uri, String user, String itemName, String itemDescription,
String item_mimetype, String item_folder) throws TDGWTServiceException { String itemMimetype, String folderId) throws TDGWTServiceException {
InputStream is = null;
try { try {
// SMPUrl smsHome = new SMPUrl(uri);
URL url = new URL(uri); URL url = new URL(uri);
logger.debug("smsHome: [host:" + url.getHost() + " path:" + url.getPath() + " ref:" + url.getRef() logger.debug("smsHome: [host:" + url.getHost() + " path:" + url.getPath() + " ref:" + url.getRef()
@ -263,22 +242,17 @@ public class FilesStorage {
URLConnection uc = null; URLConnection uc = null;
uc = (URLConnection) url.openConnection(); uc = (URLConnection) url.openConnection();
is = uc.getInputStream(); try (InputStream is = uc.getInputStream()) {
Workspace ws = HomeLibrary.getUserWorkspace(user); StorageHubClient shc = new StorageHubClient();
FolderContainer folderContainer = shc.open(folderId).asFolder();
WorkspaceFolder folder = (WorkspaceFolder) ws.getItem(item_folder); FileContainer fileContainer = folderContainer.uploadFile(is, itemName, itemDescription);
String uniqueName = WorkspaceUtil.getUniqueName(item_name, folder); AbstractFileItem afi = fileContainer.get();
logger.debug("Created file on workspace: " + afi.getId());
logger.debug("ws.createExternalFile [folder: " + folder + ", uniqueName: " + uniqueName + ", description: " }
+ item_description + ", mimetype: " + item_mimetype + ", InputStream: " + is + "]");
WorkspaceUtil.createExternalFile(folder, uniqueName, item_description, item_mimetype, is);
is.close();
} catch (Throwable e) { } catch (Throwable e) {
logger.error("Error creating item on workspace", e); logger.error("Error creating item on workspace", e);
e.printStackTrace();
throw new TDGWTServiceException("Error creating item on workspace: " + e.getLocalizedMessage(), e); throw new TDGWTServiceException("Error creating item on workspace: " + e.getLocalizedMessage(), e);
} }
@ -290,34 +264,33 @@ public class FilesStorage {
* Storage id * Storage id
* @param user * @param user
* User * User
* @param item_name * @param itemName
* Item name * Item name
* @param item_description * @param itemDescription
* Item description * Item description
* @param item_mimetype * @param itemMimetype
* Item mime type * Item mime type
* @param item_folder * @param itemFolder
* Destination Folder * Destination Folder
* @throws TDGWTServiceException * @throws TDGWTServiceException
* Exception * Exception
*/ */
public void createItemOnWorkspaceByStorageId(String storageId, String user, String item_name, public void createItemOnWorkspaceByStorageId(String storageId, String user, String itemName,
String item_description, String item_mimetype, String item_folder) throws TDGWTServiceException { String itemDescription, String itemMimetype, String itemFolder) throws TDGWTServiceException {
try { try {
Workspace ws = HomeLibrary.getUserWorkspace(user); Workspace ws = HomeLibrary.getUserWorkspace(user);
WorkspaceFolder folder = (WorkspaceFolder) ws.getItem(item_folder); WorkspaceFolder folder = (WorkspaceFolder) ws.getItem(itemFolder);
String uniqueName = WorkspaceUtil.getUniqueName(item_name, folder); String uniqueName = WorkspaceUtil.getUniqueName(itemName, folder);
logger.debug("ws.createExternalFile [folder: " + folder + ", uniqueName: " + uniqueName + ", description: " logger.debug("ws.createExternalFile [folder: " + folder + ", uniqueName: " + uniqueName + ", description: "
+ item_description + ", mimetype: " + item_mimetype + ", StorageId: " + storageId + "]"); + itemDescription + ", mimetype: " + itemMimetype + ", StorageId: " + storageId + "]");
WorkspaceUtil.createExternalFile(folder, uniqueName, item_description, item_mimetype, storageId); WorkspaceUtil.createExternalFile(folder, uniqueName, itemDescription, itemMimetype, storageId);
} catch (Throwable e) { } catch (Throwable e) {
logger.error("Error creating item on workspace", e); logger.error("Error creating item on workspace: " + e.getLocalizedMessage(), e);
e.printStackTrace();
throw new TDGWTServiceException("Error creating item on workspace: " + e.getLocalizedMessage(), e); throw new TDGWTServiceException("Error creating item on workspace: " + e.getLocalizedMessage(), e);
} }
@ -346,8 +319,7 @@ public class FilesStorage {
} }
} catch (Throwable e) { } catch (Throwable e) {
logger.error("Error retrieving VRE folder by scope!", e); logger.error("Error retrieving VRE folder by scope! " + e.getLocalizedMessage(), e);
e.printStackTrace();
throw new TDGWTServiceException("Error retrieving VRE folder by scope: " + e.getLocalizedMessage(), e); throw new TDGWTServiceException("Error retrieving VRE folder by scope: " + e.getLocalizedMessage(), e);
} }