|
|
|
@ -10,11 +10,15 @@ import javax.inject.Singleton;
|
|
|
|
|
import javax.jcr.Node;
|
|
|
|
|
import javax.jcr.RepositoryException;
|
|
|
|
|
import javax.jcr.Session;
|
|
|
|
|
import javax.jcr.lock.LockException;
|
|
|
|
|
|
|
|
|
|
import org.gcube.common.authorization.library.AuthorizedTasks;
|
|
|
|
|
import org.gcube.common.authorization.library.provider.AuthorizationProvider;
|
|
|
|
|
import org.gcube.common.storagehub.model.Excludes;
|
|
|
|
|
import org.gcube.common.storagehub.model.Paths;
|
|
|
|
|
import org.gcube.common.storagehub.model.exceptions.BackendGenericError;
|
|
|
|
|
import org.gcube.common.storagehub.model.exceptions.ItemLockedException;
|
|
|
|
|
import org.gcube.common.storagehub.model.exceptions.StorageHubException;
|
|
|
|
|
import org.gcube.common.storagehub.model.exceptions.UserNotAuthorizedException;
|
|
|
|
|
import org.gcube.common.storagehub.model.items.AbstractFileItem;
|
|
|
|
|
import org.gcube.common.storagehub.model.items.FolderItem;
|
|
|
|
@ -47,18 +51,16 @@ public class TrashHandler {
|
|
|
|
|
Item2NodeConverter item2Node;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void removeNodes(Session ses, List<Item> itemsToDelete) throws RepositoryException, BackendGenericError{
|
|
|
|
|
public void removeNodes(Session ses, List<Item> itemsToDelete) throws RepositoryException, StorageHubException{
|
|
|
|
|
log.debug("defnitively removing nodes with ids {}",itemsToDelete);
|
|
|
|
|
for (Item item: itemsToDelete) {
|
|
|
|
|
removeNodesInternally(ses, item);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void removeNodesInternally(Session ses, Item itemToDelete) throws RepositoryException, BackendGenericError {
|
|
|
|
|
final String login = AuthorizationProvider.instance.get().getClient().getId();
|
|
|
|
|
|
|
|
|
|
private void removeNodesInternally(Session ses, Item itemToDelete) throws RepositoryException, StorageHubException {
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
ses.getWorkspace().getLockManager().lock(itemToDelete.getPath(), true, true, 0,login);
|
|
|
|
|
Set<String> contentIdsToDelete = new HashSet<>();
|
|
|
|
|
|
|
|
|
|
Node nodeToDelete = ses.getNodeByIdentifier(itemToDelete.getId());
|
|
|
|
@ -74,11 +76,10 @@ public class TrashHandler {
|
|
|
|
|
|
|
|
|
|
log.debug("content ids to remove are {}",contentIdsToDelete);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//TODO: make it as an authorizableTask
|
|
|
|
|
String user = AuthorizationProvider.instance.get().getClient().getId();
|
|
|
|
|
new Thread() {
|
|
|
|
|
|
|
|
|
|
Runnable deleteFromStorageRunnable = AuthorizedTasks.bind(new Runnable() {
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void run() {
|
|
|
|
|
for (String id: contentIdsToDelete) {
|
|
|
|
|
try {
|
|
|
|
@ -89,14 +90,16 @@ public class TrashHandler {
|
|
|
|
|
log.warn("error removing file on storage with id {}",id, t);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}.start();;
|
|
|
|
|
});
|
|
|
|
|
new Thread(deleteFromStorageRunnable).start();
|
|
|
|
|
|
|
|
|
|
ses.save();
|
|
|
|
|
}catch (LockException e) {
|
|
|
|
|
throw new ItemLockedException("the node or is parent is locked", e);
|
|
|
|
|
}catch (Exception e) {
|
|
|
|
|
throw new BackendGenericError("error permanetly deleting items",e);
|
|
|
|
|
}finally {
|
|
|
|
|
ses.getWorkspace().getLockManager().unlock(itemToDelete.getPath());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|