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@171374 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
309ea09453
commit
f840ffae53
2
pom.xml
2
pom.xml
|
@ -227,7 +227,7 @@
|
||||||
<groupId>org.gcube.common</groupId>
|
<groupId>org.gcube.common</groupId>
|
||||||
<artifactId>home-library-model</artifactId>
|
<artifactId>home-library-model</artifactId>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- Service Client -->
|
<!-- Service Client -->
|
||||||
<dependency>
|
<dependency>
|
||||||
|
|
|
@ -7434,7 +7434,7 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements TDGWTServi
|
||||||
try {
|
try {
|
||||||
FilesStorage filesStorage = new FilesStorage();
|
FilesStorage filesStorage = new FilesStorage();
|
||||||
InputStream is = filesStorage.retrieveInputStream(serviceCredentials.getUserName(), wi);
|
InputStream is = filesStorage.retrieveInputStream(serviceCredentials.getUserName(), wi);
|
||||||
|
|
||||||
FileUtil.setImportFileCodelistMapping(fileUploadSession, is, wi.getName(), Constants.FILE_XML_MIMETYPE);
|
FileUtil.setImportFileCodelistMapping(fileUploadSession, is, wi.getName(), Constants.FILE_XML_MIMETYPE);
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
FileUploadMonitor fum = SessionUtil.getFileUploadMonitor(httpRequest, serviceCredentials);
|
FileUploadMonitor fum = SessionUtil.getFileUploadMonitor(httpRequest, serviceCredentials);
|
||||||
|
|
|
@ -1,24 +1,17 @@
|
||||||
package org.gcube.portlets.user.td.gwtservice.server.storage;
|
package org.gcube.portlets.user.td.gwtservice.server.storage;
|
||||||
|
|
||||||
import java.io.BufferedInputStream;
|
|
||||||
import java.io.BufferedOutputStream;
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileOutputStream;
|
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.net.URLConnection;
|
import java.net.URLConnection;
|
||||||
|
|
||||||
import org.gcube.common.homelibrary.home.HomeLibrary;
|
|
||||||
import org.gcube.common.homelibrary.home.workspace.Workspace;
|
|
||||||
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.util.WorkspaceUtil;
|
|
||||||
import org.gcube.common.storagehub.client.StreamDescriptor;
|
import org.gcube.common.storagehub.client.StreamDescriptor;
|
||||||
import org.gcube.common.storagehub.client.dsl.FileContainer;
|
import org.gcube.common.storagehub.client.dsl.FileContainer;
|
||||||
import org.gcube.common.storagehub.client.dsl.FolderContainer;
|
import org.gcube.common.storagehub.client.dsl.FolderContainer;
|
||||||
import org.gcube.common.storagehub.client.dsl.StorageHubClient;
|
import org.gcube.common.storagehub.client.dsl.StorageHubClient;
|
||||||
import org.gcube.common.storagehub.model.items.AbstractFileItem;
|
import org.gcube.common.storagehub.model.items.AbstractFileItem;
|
||||||
|
import org.gcube.common.storagehub.model.items.FolderItem;
|
||||||
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,6 +45,8 @@ public class FilesStorage {
|
||||||
String remotePath = "/CSVimport/" + file.getName();
|
String remotePath = "/CSVimport/" + file.getName();
|
||||||
logger.debug("remotePath: " + remotePath);
|
logger.debug("remotePath: " + remotePath);
|
||||||
String id = client.put(true).LFile(file.getAbsolutePath()).RFile(remotePath);
|
String id = client.put(true).LFile(file.getAbsolutePath()).RFile(remotePath);
|
||||||
|
client.close();
|
||||||
|
|
||||||
return id;
|
return id;
|
||||||
|
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
|
@ -75,6 +70,7 @@ public class FilesStorage {
|
||||||
String remotePath = "/CodelistMappingImport/" + file.getName();
|
String remotePath = "/CodelistMappingImport/" + file.getName();
|
||||||
logger.debug("remotePath: " + remotePath);
|
logger.debug("remotePath: " + remotePath);
|
||||||
String id = client.put(true).LFile(file.getAbsolutePath()).RFile(remotePath);
|
String id = client.put(true).LFile(file.getAbsolutePath()).RFile(remotePath);
|
||||||
|
client.close();
|
||||||
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());
|
||||||
|
@ -104,6 +100,7 @@ public class FilesStorage {
|
||||||
String remotePath = "/CodelistMappingImport/" + address.getFile();
|
String remotePath = "/CodelistMappingImport/" + address.getFile();
|
||||||
logger.debug("remotePath: " + remotePath);
|
logger.debug("remotePath: " + remotePath);
|
||||||
id = client.put(true).LFile(is).RFile(remotePath);
|
id = client.put(true).LFile(is).RFile(remotePath);
|
||||||
|
client.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
return id;
|
return id;
|
||||||
|
@ -115,7 +112,9 @@ public class FilesStorage {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* user
|
*
|
||||||
|
*
|
||||||
|
*
|
||||||
*
|
*
|
||||||
* @param user
|
* @param user
|
||||||
* User
|
* User
|
||||||
|
@ -126,35 +125,35 @@ public class FilesStorage {
|
||||||
* @throws TDGWTServiceException
|
* @throws TDGWTServiceException
|
||||||
* Exception
|
* Exception
|
||||||
*/
|
*/
|
||||||
public void retrieveFile(String user, WorkspaceItem wi, File file) throws TDGWTServiceException {
|
/*
|
||||||
try {
|
* public void retrieveFile(String user, WorkspaceItem wi, File file) throws
|
||||||
logger.debug("retrieveFile: [user=" + user + ", item=" + wi + "]");
|
* TDGWTServiceException { try { logger.debug("retrieveFile: [user=" + user
|
||||||
StorageHubClient shc = new StorageHubClient();
|
* + ", item=" + wi + "]"); StorageHubClient shc = new StorageHubClient();
|
||||||
FileContainer fileContainer = shc.open(wi.getId()).asFile();
|
* FileContainer fileContainer = shc.open(wi.getId()).asFile();
|
||||||
StreamDescriptor streamDescriptor = fileContainer.download();
|
* StreamDescriptor streamDescriptor = fileContainer.download(); try
|
||||||
try (BufferedInputStream bis = new BufferedInputStream(streamDescriptor.getStream())) {
|
* (BufferedInputStream bis = new
|
||||||
try (BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(file))) {
|
* BufferedInputStream(streamDescriptor.getStream())) { try
|
||||||
|
* (BufferedOutputStream bos = new BufferedOutputStream(new
|
||||||
byte[] buffer = new byte[1024];
|
* FileOutputStream(file))) {
|
||||||
int readCount;
|
*
|
||||||
while ((readCount = bis.read(buffer)) > 0) {
|
* byte[] buffer = new byte[1024]; int readCount; while ((readCount =
|
||||||
bos.write(buffer, 0, readCount);
|
* bis.read(buffer)) > 0) { bos.write(buffer, 0, readCount); } } catch
|
||||||
}
|
* (Throwable e) { logger.error("Error trasferring file from storage: " +
|
||||||
} catch (Throwable e) {
|
* e.getLocalizedMessage(), e); throw new
|
||||||
logger.error("Error trasferring file from storage: " + e.getLocalizedMessage(), e);
|
* TDGWTServiceException("Error trasferring file from storage: " +
|
||||||
throw new TDGWTServiceException("Error trasferring file from storage: " + e.getLocalizedMessage(),
|
* e.getLocalizedMessage(), e); } }
|
||||||
e);
|
*
|
||||||
}
|
* } catch (Throwable e) {
|
||||||
}
|
* logger.error("Error retrieving file from StorageHub", e); throw new
|
||||||
|
* TDGWTServiceException("Error retrieving file from StorageHub: " +
|
||||||
} catch (Throwable e) {
|
* e.getLocalizedMessage(), e); }
|
||||||
logger.error("Error retrieving file from StorageHub", e);
|
*
|
||||||
throw new TDGWTServiceException("Error retrieving file from StorageHub: " + e.getLocalizedMessage(), e);
|
* }
|
||||||
}
|
*/
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
*
|
||||||
|
*
|
||||||
*
|
*
|
||||||
* @param user
|
* @param user
|
||||||
* User
|
* User
|
||||||
|
@ -165,6 +164,7 @@ public class FilesStorage {
|
||||||
* @throws TDGWTServiceException
|
* @throws TDGWTServiceException
|
||||||
* Exception
|
* Exception
|
||||||
*/
|
*/
|
||||||
|
|
||||||
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 {
|
||||||
|
@ -173,7 +173,7 @@ public class FilesStorage {
|
||||||
FileContainer fileContainer = shc.open(wi.getId()).asFile();
|
FileContainer fileContainer = shc.open(wi.getId()).asFile();
|
||||||
StreamDescriptor streamDescriptor = fileContainer.download();
|
StreamDescriptor streamDescriptor = fileContainer.download();
|
||||||
is = streamDescriptor.getStream();
|
is = streamDescriptor.getStream();
|
||||||
|
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
logger.error("Error retrieving file from StorageHub", e);
|
logger.error("Error retrieving file from StorageHub", e);
|
||||||
throw new TDGWTServiceException("Error retrieving file from StorageHub: " + e.getLocalizedMessage(), e);
|
throw new TDGWTServiceException("Error retrieving file from StorageHub: " + e.getLocalizedMessage(), e);
|
||||||
|
@ -186,7 +186,7 @@ public class FilesStorage {
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param uri
|
* @param uri
|
||||||
* Usi
|
* Uri
|
||||||
* @return Input stream
|
* @return Input stream
|
||||||
* @throws TDGWTServiceException
|
* @throws TDGWTServiceException
|
||||||
* Exception
|
* Exception
|
||||||
|
@ -259,6 +259,7 @@ public class FilesStorage {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
*
|
||||||
*
|
*
|
||||||
* @param storageId
|
* @param storageId
|
||||||
* Storage id
|
* Storage id
|
||||||
|
@ -275,19 +276,22 @@ public class FilesStorage {
|
||||||
* @throws TDGWTServiceException
|
* @throws TDGWTServiceException
|
||||||
* Exception
|
* Exception
|
||||||
*/
|
*/
|
||||||
public void createItemOnWorkspaceByStorageId(String storageId, String user, String itemName,
|
public void createItemOnWorkspaceByStorageId(String storageId, String user, String itemName, String itemDescription,
|
||||||
String itemDescription, String itemMimetype, String itemFolder) throws TDGWTServiceException {
|
String itemMimetype, String itemFolder) throws TDGWTServiceException {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
IClient client = new StorageClient(user, AccessType.PUBLIC, MemoryType.VOLATILE).getClient();
|
||||||
|
|
||||||
Workspace ws = HomeLibrary.getUserWorkspace(user);
|
try (InputStream is = client.get().RFileAsInputStream(storageId)) {
|
||||||
|
|
||||||
WorkspaceFolder folder = (WorkspaceFolder) ws.getItem(itemFolder);
|
|
||||||
String uniqueName = WorkspaceUtil.getUniqueName(itemName, folder);
|
|
||||||
|
|
||||||
logger.debug("ws.createExternalFile [folder: " + folder + ", uniqueName: " + uniqueName + ", description: "
|
StorageHubClient shc = new StorageHubClient();
|
||||||
+ itemDescription + ", mimetype: " + itemMimetype + ", StorageId: " + storageId + "]");
|
FolderContainer folderContainer = shc.open(itemFolder).asFolder();
|
||||||
WorkspaceUtil.createExternalFile(folder, uniqueName, itemDescription, itemMimetype, storageId);
|
FileContainer fileContainer = folderContainer.uploadFile(is, itemName, itemDescription);
|
||||||
|
AbstractFileItem afi = fileContainer.get();
|
||||||
|
logger.debug("Created file on workspace: " + afi.getId());
|
||||||
|
}
|
||||||
|
client.close();
|
||||||
|
|
||||||
|
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
logger.error("Error creating item on workspace: " + e.getLocalizedMessage(), e);
|
logger.error("Error creating item on workspace: " + e.getLocalizedMessage(), e);
|
||||||
|
@ -297,6 +301,7 @@ public class FilesStorage {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
*
|
||||||
*
|
*
|
||||||
* @param user
|
* @param user
|
||||||
* User
|
* User
|
||||||
|
@ -309,12 +314,15 @@ public class FilesStorage {
|
||||||
public String getVREFolderIdByScope(String user, String scope) throws TDGWTServiceException {
|
public String getVREFolderIdByScope(String user, String scope) throws TDGWTServiceException {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
StorageHubClient shc = new StorageHubClient();
|
||||||
|
FolderContainer folderContainer = shc.openVREFolder();
|
||||||
|
FolderItem vreFolder = folderContainer.get();
|
||||||
|
|
||||||
Workspace ws = HomeLibrary.getUserWorkspace(user);
|
if (vreFolder != null) {
|
||||||
WorkspaceSharedFolder folder = ws.getVREFolderByScope(scope);
|
logger.debug("VRE folder id: " + vreFolder.getId());
|
||||||
if (folder != null) {
|
return vreFolder.getId();
|
||||||
return folder.getId();
|
|
||||||
} else {
|
} else {
|
||||||
|
logger.debug("VRE folder id: " + vreFolder);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue