git-svn-id: https://svn.d4science-ii.research-infrastructures.eu/gcube/branches/data-access/storagehub-webapp/1.0@179528 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
15f58c59c5
commit
6a3a6cca17
|
@ -60,7 +60,7 @@ public class Item2NodeConverter {
|
||||||
if (values.isMulti()) newNode.setProperty(attribute.value(), values.getValues());
|
if (values.isMulti()) newNode.setProperty(attribute.value(), values.getValues());
|
||||||
else newNode.setProperty(attribute.value(), values.getValue());
|
else newNode.setProperty(attribute.value(), values.getValue());
|
||||||
} catch (Exception e ) {
|
} catch (Exception e ) {
|
||||||
logger.warn("error setting value for attribute "+attribute.value(),e);
|
logger.warn("error setting value for attribute {}: {}",attribute.value(), e.getMessage());
|
||||||
}
|
}
|
||||||
} else if (field.isAnnotationPresent(NodeAttribute.class)){
|
} else if (field.isAnnotationPresent(NodeAttribute.class)){
|
||||||
NodeAttribute nodeAttribute = field.getAnnotation(NodeAttribute.class);
|
NodeAttribute nodeAttribute = field.getAnnotation(NodeAttribute.class);
|
||||||
|
|
|
@ -10,11 +10,15 @@ import javax.inject.Singleton;
|
||||||
import javax.jcr.Node;
|
import javax.jcr.Node;
|
||||||
import javax.jcr.RepositoryException;
|
import javax.jcr.RepositoryException;
|
||||||
import javax.jcr.Session;
|
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.authorization.library.provider.AuthorizationProvider;
|
||||||
import org.gcube.common.storagehub.model.Excludes;
|
import org.gcube.common.storagehub.model.Excludes;
|
||||||
import org.gcube.common.storagehub.model.Paths;
|
import org.gcube.common.storagehub.model.Paths;
|
||||||
import org.gcube.common.storagehub.model.exceptions.BackendGenericError;
|
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.exceptions.UserNotAuthorizedException;
|
||||||
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.common.storagehub.model.items.FolderItem;
|
||||||
|
@ -47,18 +51,16 @@ public class TrashHandler {
|
||||||
Item2NodeConverter item2Node;
|
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);
|
log.debug("defnitively removing nodes with ids {}",itemsToDelete);
|
||||||
for (Item item: itemsToDelete) {
|
for (Item item: itemsToDelete) {
|
||||||
removeNodesInternally(ses, item);
|
removeNodesInternally(ses, item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void removeNodesInternally(Session ses, Item itemToDelete) throws RepositoryException, BackendGenericError {
|
private void removeNodesInternally(Session ses, Item itemToDelete) throws RepositoryException, StorageHubException {
|
||||||
final String login = AuthorizationProvider.instance.get().getClient().getId();
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
ses.getWorkspace().getLockManager().lock(itemToDelete.getPath(), true, true, 0,login);
|
|
||||||
Set<String> contentIdsToDelete = new HashSet<>();
|
Set<String> contentIdsToDelete = new HashSet<>();
|
||||||
|
|
||||||
Node nodeToDelete = ses.getNodeByIdentifier(itemToDelete.getId());
|
Node nodeToDelete = ses.getNodeByIdentifier(itemToDelete.getId());
|
||||||
|
@ -74,11 +76,10 @@ public class TrashHandler {
|
||||||
|
|
||||||
log.debug("content ids to remove are {}",contentIdsToDelete);
|
log.debug("content ids to remove are {}",contentIdsToDelete);
|
||||||
|
|
||||||
|
|
||||||
//TODO: make it as an authorizableTask
|
|
||||||
String user = AuthorizationProvider.instance.get().getClient().getId();
|
String user = AuthorizationProvider.instance.get().getClient().getId();
|
||||||
new Thread() {
|
Runnable deleteFromStorageRunnable = AuthorizedTasks.bind(new Runnable() {
|
||||||
|
|
||||||
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
for (String id: contentIdsToDelete) {
|
for (String id: contentIdsToDelete) {
|
||||||
try {
|
try {
|
||||||
|
@ -91,12 +92,14 @@ public class TrashHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}.start();;
|
});
|
||||||
|
new Thread(deleteFromStorageRunnable).start();
|
||||||
|
|
||||||
ses.save();
|
ses.save();
|
||||||
|
}catch (LockException e) {
|
||||||
|
throw new ItemLockedException("the node or is parent is locked", e);
|
||||||
}catch (Exception e) {
|
}catch (Exception e) {
|
||||||
throw new BackendGenericError("error permanetly deleting items",e);
|
throw new BackendGenericError("error permanetly deleting items",e);
|
||||||
}finally {
|
|
||||||
ses.getWorkspace().getLockManager().unlock(itemToDelete.getPath());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -969,7 +969,7 @@ public class ItemsManager {
|
||||||
@DELETE
|
@DELETE
|
||||||
@Path("{id}")
|
@Path("{id}")
|
||||||
public Response deleteItem(@QueryParam("force") boolean force){
|
public Response deleteItem(@QueryParam("force") boolean force){
|
||||||
InnerMethodName.instance.set("deleteItem");
|
InnerMethodName.instance.set("deleteItem("+force+")");
|
||||||
|
|
||||||
Session ses = null;
|
Session ses = null;
|
||||||
try{
|
try{
|
||||||
|
@ -990,11 +990,13 @@ public class ItemsManager {
|
||||||
|
|
||||||
log.debug("item is trashed? {}", itemToDelete.isTrashed());
|
log.debug("item is trashed? {}", itemToDelete.isTrashed());
|
||||||
|
|
||||||
if (!force && !itemToDelete.isTrashed() )
|
if (!itemToDelete.isTrashed() && !force)
|
||||||
trashHandler.moveToTrash(ses, nodeToDelete, itemToDelete);
|
trashHandler.moveToTrash(ses, nodeToDelete, itemToDelete);
|
||||||
else
|
else
|
||||||
trashHandler.removeNodes(ses, Collections.singletonList(itemToDelete));
|
trashHandler.removeNodes(ses, Collections.singletonList(itemToDelete));
|
||||||
|
|
||||||
|
}catch (LockException e) {
|
||||||
|
|
||||||
}catch(RepositoryException re ){
|
}catch(RepositoryException re ){
|
||||||
log.error("jcr error moving item", re);
|
log.error("jcr error moving item", re);
|
||||||
GXOutboundErrorResponse.throwException(new BackendGenericError(re));
|
GXOutboundErrorResponse.throwException(new BackendGenericError(re));
|
||||||
|
|
Loading…
Reference in New Issue