changes on StorageBachend interface
This commit is contained in:
parent
0649acb8a9
commit
8b235da142
|
@ -163,7 +163,7 @@ public class TrashHandler {
|
|||
public void run() {
|
||||
for (ContentPair cp: contentToDelete ) {
|
||||
try {
|
||||
cp.getStorageBackend().onDelete(cp.getContent());
|
||||
cp.getStorageBackend().delete(cp.getContent().getStorageId());
|
||||
log.debug("file with id {} correctly removed from storage {}",cp.getContent().getStorageId(),cp.getStorageBackend().getClass().getSimpleName());
|
||||
}catch(Throwable t) {
|
||||
log.warn("error removing file with id {} from storage {}",cp.getContent().getStorageId(), cp.getStorageBackend().getClass().getSimpleName(), t);
|
||||
|
|
|
@ -212,7 +212,7 @@ public class Item2NodeConverter {
|
|||
node.setProperty(NodeProperty.LAST_ACTION.toString(), action.name());
|
||||
|
||||
|
||||
replaceContentFieldIterator(contentNode, item.getContent().getClass(),item.getContent());
|
||||
replaceContentNodeInternal(contentNode, item.getContent().getClass(),item.getContent());
|
||||
|
||||
|
||||
} catch (RepositoryException e) {
|
||||
|
@ -223,7 +223,7 @@ public class Item2NodeConverter {
|
|||
}
|
||||
|
||||
//VALID ONLY FOR CONTENT
|
||||
private void replaceContentFieldIterator(Node node, Class<?> clazz, Object instance) {
|
||||
public void replaceContentNodeInternal(Node node, Class<?> clazz, Object instance) {
|
||||
for (Field field : retrieveAllFields(clazz)){
|
||||
if (field.isAnnotationPresent(Attribute.class)){
|
||||
Attribute attribute = field.getAnnotation(Attribute.class);
|
||||
|
|
|
@ -34,6 +34,7 @@ import org.gcube.data.access.storagehub.handlers.items.builders.ItemsParameterBu
|
|||
import org.gcube.data.access.storagehub.scripting.AbstractScript;
|
||||
import org.gcube.data.access.storagehub.scripting.ScriptUtil;
|
||||
import org.gcube.data.access.storagehub.services.RepositoryInitializer;
|
||||
import org.gcube.smartgears.utils.InnerMethodName;
|
||||
import org.glassfish.jersey.media.multipart.FormDataContentDisposition;
|
||||
import org.glassfish.jersey.media.multipart.FormDataParam;
|
||||
import org.slf4j.Logger;
|
||||
|
@ -72,6 +73,7 @@ public class ScriptManager {
|
|||
@FormDataParam("file") InputStream stream,
|
||||
@FormDataParam("file") FormDataContentDisposition fileDetail) {
|
||||
try {
|
||||
InnerMethodName.instance.set("executeScript");
|
||||
ScriptClassLoader scriptClassLoader = new ScriptClassLoader(Thread.currentThread().getContextClassLoader());
|
||||
Class<?> scriptClass = uploadClass(stream, scriptClassLoader, fileDetail.getFileName().replace(".class", ""));
|
||||
return run(scriptClass, name, destinationFolderId, asynch!=null? asynch : false);
|
||||
|
|
|
@ -13,9 +13,11 @@ import javax.jcr.Session;
|
|||
import org.gcube.common.storagehub.model.exceptions.BackendGenericError;
|
||||
import org.gcube.common.storagehub.model.exceptions.StorageHubException;
|
||||
import org.gcube.common.storagehub.model.items.Item;
|
||||
import org.gcube.common.storagehub.model.items.nodes.Content;
|
||||
import org.gcube.common.storagehub.model.storages.StorageBackendFactory;
|
||||
import org.gcube.data.access.storagehub.Utils;
|
||||
import org.gcube.data.access.storagehub.handlers.TrashHandler;
|
||||
import org.gcube.data.access.storagehub.handlers.items.Item2NodeConverter;
|
||||
import org.gcube.data.access.storagehub.handlers.items.Node2ItemConverter;
|
||||
import org.gcube.data.access.storagehub.handlers.plugins.StorageBackendHandler;
|
||||
import org.gcube.data.access.storagehub.scripting.ScriptUtil;
|
||||
|
@ -25,6 +27,8 @@ public class ScriptUtilImpl implements ScriptUtil {
|
|||
|
||||
@Inject Node2ItemConverter node2Item;
|
||||
|
||||
@Inject Item2NodeConverter item2Node;
|
||||
|
||||
@Inject TrashHandler trashHandler;
|
||||
|
||||
@Inject StorageBackendHandler backendHandler;
|
||||
|
@ -48,5 +52,10 @@ public class ScriptUtilImpl implements ScriptUtil {
|
|||
public Collection<StorageBackendFactory> getStorageBackendHandler() {
|
||||
return backendHandler.getAllImplementations();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateContentNode(Content content, Node node) throws Exception {
|
||||
item2Node.replaceContentNodeInternal(node, content.getClass(), content);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -79,13 +79,12 @@ public class GCubeMongoStorageBackend extends StorageBackend {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onDelete(Content content) {
|
||||
log.debug("deleting");
|
||||
public void delete(String storageId) {
|
||||
log.debug("deleting object {} ",storageId);
|
||||
IClient storageClient = getStorageClient(SecretManagerProvider.instance.get().getOwner().getId()).getClient();
|
||||
storageClient.remove().RFileById(content.getStorageId());
|
||||
storageClient.remove().RFileById(storageId);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getTotalSizeStored() {
|
||||
IClient storageClient = getStorageClient(SecretManagerProvider.instance.get().getOwner().getId()).getClient();
|
||||
|
|
|
@ -89,18 +89,14 @@ public class S3Backend extends StorageBackend{
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onDelete(Content content) {
|
||||
public void delete(String storageId) {
|
||||
try {
|
||||
|
||||
String storageId = content.getStorageId();
|
||||
|
||||
client.removeObject(RemoveObjectArgs.builder().bucket(bucketName).object(storageId).build());
|
||||
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("error deleting file on s3", e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public MetaInfo upload(InputStream stream, String relativePath, String name) {
|
||||
|
@ -186,6 +182,4 @@ public class S3Backend extends StorageBackend{
|
|||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue