git-svn-id: https://svn.d4science-ii.research-infrastructures.eu/gcube/branches/data-access/storagehub-webapp/1.0@181147 82a268e6-3cf1-43bd-a215-b396298e98cf
parent
62d8c068cc
commit
1c1e067a19
@ -1,36 +0,0 @@
|
||||
package org.gcube.data.access.storagehub;
|
||||
|
||||
|
||||
public class MetaInfo {
|
||||
|
||||
|
||||
private long size;
|
||||
|
||||
private String storageId;
|
||||
|
||||
private String remotePath;
|
||||
|
||||
public long getSize() {
|
||||
return size;
|
||||
}
|
||||
|
||||
public void setSize(long size) {
|
||||
this.size = size;
|
||||
}
|
||||
|
||||
public String getStorageId() {
|
||||
return storageId;
|
||||
}
|
||||
|
||||
public void setStorageId(String storageId) {
|
||||
this.storageId = storageId;
|
||||
}
|
||||
|
||||
public String getRemotePath() {
|
||||
return remotePath;
|
||||
}
|
||||
|
||||
public void setRemotePath(String remotePath) {
|
||||
this.remotePath = remotePath;
|
||||
}
|
||||
}
|
@ -0,0 +1,43 @@
|
||||
package org.gcube.data.access.storagehub.handlers;
|
||||
|
||||
import java.io.InputStream;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
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.storages.MetaInfo;
|
||||
import org.gcube.data.access.storagehub.storage.backend.impl.GCubeStorageBackend;
|
||||
|
||||
|
||||
@Singleton
|
||||
public class StorageBackendHandler {
|
||||
|
||||
@Inject
|
||||
private GCubeStorageBackend defaultBackend;
|
||||
|
||||
|
||||
public String move(Item item, FolderItem destination) {
|
||||
//if item is a folder we have to move everything
|
||||
return defaultBackend.move(((AbstractFileItem) item).getContent().getStorageId());
|
||||
}
|
||||
|
||||
public String copy(AbstractFileItem item) {
|
||||
return defaultBackend.copy(item.getContent().getStorageId(), item.getContent().getRemotePath());
|
||||
}
|
||||
|
||||
public MetaInfo upload(InputStream stream, String itemPath) {
|
||||
return defaultBackend.upload(stream, itemPath);
|
||||
}
|
||||
|
||||
public InputStream download(String id) {
|
||||
return defaultBackend.getContent(id);
|
||||
}
|
||||
|
||||
public void delete(String id) {
|
||||
defaultBackend.delete(id);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,76 @@
|
||||
package org.gcube.data.access.storagehub.storage.backend.impl;
|
||||
|
||||
import java.io.InputStream;
|
||||
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.gcube.common.authorization.library.provider.AuthorizationProvider;
|
||||
import org.gcube.common.storagehub.model.storages.MetaInfo;
|
||||
import org.gcube.common.storagehub.model.storages.StorageBackend;
|
||||
import org.gcube.contentmanagement.blobstorage.service.IClient;
|
||||
import org.gcube.contentmanager.storageclient.wrapper.AccessType;
|
||||
import org.gcube.contentmanager.storageclient.wrapper.MemoryType;
|
||||
import org.gcube.contentmanager.storageclient.wrapper.StorageClient;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@Singleton
|
||||
public class GCubeStorageBackend implements StorageBackend {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(GCubeStorageBackend.class);
|
||||
|
||||
private final static String SERVICE_NAME = "home-library";
|
||||
private final static String SERVICE_CLASS = "org.gcube.portlets.user";
|
||||
|
||||
@Override
|
||||
public InputStream getContent(String id) {
|
||||
return getStorageClient(AuthorizationProvider.instance.get().getClient().getId()).getClient().get().RFileAsInputStream(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return GCubeStorageBackend.class.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String copy(String idToCopy, String path) {
|
||||
String newStorageID = getStorageClient(AuthorizationProvider.instance.get().getClient().getId()).getClient().copyFile(true).from(idToCopy).to(path);
|
||||
log.info("copying storage Id {} to newPath {} and the id returned by storage is {}", idToCopy, path, newStorageID);
|
||||
return newStorageID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String move(String idToMove) {
|
||||
return idToMove;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MetaInfo upload(InputStream stream, String itemPath) {
|
||||
log.debug("uploading file");
|
||||
IClient storageClient = getStorageClient(AuthorizationProvider.instance.get().getClient().getId()).getClient();
|
||||
String storageId =storageClient.put(true).LFile(stream).RFile(itemPath);
|
||||
long size = storageClient.getSize().RFileById(storageId);
|
||||
MetaInfo info = new MetaInfo();
|
||||
info.setSize(size);
|
||||
info.setStorageId(storageId);
|
||||
info.setRemotePath(itemPath);
|
||||
return info;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delete(String id) {
|
||||
log.debug("deleting");
|
||||
IClient storageClient = getStorageClient(AuthorizationProvider.instance.get().getClient().getId()).getClient();
|
||||
storageClient.remove().RFileById(id);
|
||||
}
|
||||
|
||||
private static StorageClient getStorageClient(String login){
|
||||
return new StorageClient(SERVICE_CLASS, SERVICE_NAME, login, AccessType.SHARED, MemoryType.PERSISTENT);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
Loading…
Reference in New Issue