refactoring of some classes
This commit is contained in:
parent
e82d695bbf
commit
94d9307b4c
|
@ -0,0 +1,51 @@
|
||||||
|
package org.gcube.data.access.storagehub;
|
||||||
|
|
||||||
|
import java.util.Iterator;
|
||||||
|
|
||||||
|
import javax.jcr.Node;
|
||||||
|
import javax.jcr.NodeIterator;
|
||||||
|
import javax.jcr.RepositoryException;
|
||||||
|
|
||||||
|
import org.gcube.common.storagehub.model.exceptions.BackendGenericError;
|
||||||
|
import org.gcube.data.access.storagehub.handlers.ClassHandler;
|
||||||
|
|
||||||
|
public class NodeChildrenFilterIterator implements Iterator<Node> {
|
||||||
|
|
||||||
|
private NodeIterator it;
|
||||||
|
|
||||||
|
public NodeChildrenFilterIterator(Node node) throws BackendGenericError{
|
||||||
|
super();
|
||||||
|
try {
|
||||||
|
it = node.getNodes();
|
||||||
|
} catch (RepositoryException e) {
|
||||||
|
throw new BackendGenericError(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public NodeChildrenFilterIterator(NodeIterator iterator) throws BackendGenericError{
|
||||||
|
it = iterator;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private Node currentNode = null;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean hasNext() {
|
||||||
|
try {
|
||||||
|
while (it.hasNext()) {
|
||||||
|
currentNode=it.nextNode();
|
||||||
|
if (ClassHandler.instance().get(currentNode.getPrimaryNodeType().getName())!=null)
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}catch (RepositoryException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Node next() {
|
||||||
|
return currentNode;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -119,21 +119,21 @@ public class Utils {
|
||||||
logger.debug("query for search is {}",xpath);
|
logger.debug("query for search is {}",xpath);
|
||||||
long start = System.currentTimeMillis();
|
long start = System.currentTimeMillis();
|
||||||
Query jcrQuery = ses.getWorkspace().getQueryManager().createQuery(xpath, Query.XPATH);
|
Query jcrQuery = ses.getWorkspace().getQueryManager().createQuery(xpath, Query.XPATH);
|
||||||
NodeIterator it = jcrQuery.execute().getNodes();
|
NodeChildrenFilterIterator iterator = new NodeChildrenFilterIterator(jcrQuery.execute().getNodes());
|
||||||
logger.debug("[SEARCH] real search took {} millis",(System.currentTimeMillis()-start));
|
logger.debug("[SEARCH] real search took {} millis",(System.currentTimeMillis()-start));
|
||||||
return getItemListFromNodeIterator(authChecker, it, excludes, range, showHidden, excludeTrashed, nodeTypeToInclude);
|
return getItemListFromNodeIterator(authChecker, iterator , excludes, range, showHidden, excludeTrashed, nodeTypeToInclude);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static <T extends Item> List<T> getItemList(Node parent, List<String> excludes, Range range, boolean showHidden, Class<? extends Item> nodeTypeToInclude) throws RepositoryException, BackendGenericError{
|
public static <T extends Item> List<T> getItemList(Node parent, List<String> excludes, Range range, boolean showHidden, Class<? extends Item> nodeTypeToInclude) throws RepositoryException, BackendGenericError{
|
||||||
logger.trace("getting children of node {}", parent.getIdentifier());
|
logger.trace("getting children of node {}", parent.getIdentifier());
|
||||||
long start = System.currentTimeMillis();
|
long start = System.currentTimeMillis();
|
||||||
NodeIterator iterator = parent.getNodes();
|
NodeChildrenFilterIterator iterator = new NodeChildrenFilterIterator(parent);
|
||||||
logger.trace("time to get iterator {}",(System.currentTimeMillis()-start));
|
logger.trace("time to get iterator {}",(System.currentTimeMillis()-start));
|
||||||
return getItemListFromNodeIterator(null, iterator, excludes, range, showHidden, false, nodeTypeToInclude);
|
return getItemListFromNodeIterator(null, iterator, excludes, range, showHidden, false, nodeTypeToInclude);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static <T extends Item> List<T> getItemListFromNodeIterator(AuthorizationChecker authChecker, NodeIterator iterator, List<String> excludes, Range range, boolean showHidden, boolean excludeTrashed, Class<? extends Item> nodeTypeToInclude) throws RepositoryException, BackendGenericError{
|
private static <T extends Item> List<T> getItemListFromNodeIterator(AuthorizationChecker authChecker, NodeChildrenFilterIterator iterator, List<String> excludes, Range range, boolean showHidden, boolean excludeTrashed, Class<? extends Item> nodeTypeToInclude) throws RepositoryException, BackendGenericError{
|
||||||
List<T> returnList = new ArrayList<T>();
|
List<T> returnList = new ArrayList<T>();
|
||||||
|
|
||||||
logger.trace("nodeType is {}",nodeTypeToInclude);
|
logger.trace("nodeType is {}",nodeTypeToInclude);
|
||||||
|
@ -142,7 +142,7 @@ public class Utils {
|
||||||
Node2ItemConverter node2Item= new Node2ItemConverter();
|
Node2ItemConverter node2Item= new Node2ItemConverter();
|
||||||
Set<String> duplicateId = new HashSet<String>();
|
Set<String> duplicateId = new HashSet<String>();
|
||||||
while (iterator.hasNext()){
|
while (iterator.hasNext()){
|
||||||
Node current = iterator.nextNode();
|
Node current = iterator.next();
|
||||||
|
|
||||||
logger.debug("[SEARCH] evaluating node {} ",current.hasProperty(NodeProperty.TITLE.toString())? current.getProperty(NodeProperty.TITLE.toString()):current.getName());
|
logger.debug("[SEARCH] evaluating node {} ",current.hasProperty(NodeProperty.TITLE.toString())? current.getProperty(NodeProperty.TITLE.toString()):current.getName());
|
||||||
|
|
||||||
|
@ -152,7 +152,7 @@ public class Utils {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
//ECLUDES node not authorized, in case the indexes are not working
|
//EXCLUDES node not authorized, in case the indexes are not working
|
||||||
if (authChecker!=null)
|
if (authChecker!=null)
|
||||||
try {
|
try {
|
||||||
authChecker.checkReadAuthorizationControl(current.getSession(), current.getIdentifier());
|
authChecker.checkReadAuthorizationControl(current.getSession(), current.getIdentifier());
|
||||||
|
@ -269,10 +269,10 @@ public class Utils {
|
||||||
|
|
||||||
public static boolean hasSharedChildren(Node node) throws RepositoryException, BackendGenericError{
|
public static boolean hasSharedChildren(Node node) throws RepositoryException, BackendGenericError{
|
||||||
Node2ItemConverter node2Item = new Node2ItemConverter();
|
Node2ItemConverter node2Item = new Node2ItemConverter();
|
||||||
NodeIterator children = node.getNodes();
|
NodeChildrenFilterIterator children = new NodeChildrenFilterIterator(node);
|
||||||
|
|
||||||
while (children.hasNext()) {
|
while (children.hasNext()) {
|
||||||
Node child= children.nextNode();
|
Node child= children.next();
|
||||||
if (node2Item.checkNodeType(child, SharedFolder.class)) return true;
|
if (node2Item.checkNodeType(child, SharedFolder.class)) return true;
|
||||||
if (node2Item.checkNodeType(child, FolderItem.class) && hasSharedChildren(child)) return true;
|
if (node2Item.checkNodeType(child, FolderItem.class) && hasSharedChildren(child)) return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
package org.gcube.data.access.storagehub.handlers;
|
package org.gcube.data.access.storagehub.handlers;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
@ -24,6 +26,10 @@ public class ClassHandler {
|
||||||
|
|
||||||
private Reflections reflection = new Reflections();
|
private Reflections reflection = new Reflections();
|
||||||
|
|
||||||
|
private List<String> deprecatedNode = Arrays.asList("nthl:query", "nthl:aquamapsItem", "nthl:timeSeriesItem", "nthl:report", "nthl:reportTemplate", "nthl:workflowReport",
|
||||||
|
"nthl:workflowTemplate", "nthl:gCubeMetadata", "nthl:gCubeDocument", "nthl:gCubeDocumentLink", "nthl:gCubeImageDocumentLink", "nthl:gCubePDFDocumentLink",
|
||||||
|
"nthl:gCubeImageDocument", "nthl:gCubePDFDocument", "nthl:gCubeURLDocument", "nthl:gCubeAnnotation", "nthl:externalResourceLink", "nthl:tabularDataLink");
|
||||||
|
|
||||||
private Map<String, Class<? extends Item>> classMap = new HashMap<String, Class<? extends Item>>();
|
private Map<String, Class<? extends Item>> classMap = new HashMap<String, Class<? extends Item>>();
|
||||||
private Map<Class<? extends Item>, String> typeMap = new HashMap<Class<? extends Item>, String>();
|
private Map<Class<? extends Item>, String> typeMap = new HashMap<Class<? extends Item>, String>();
|
||||||
|
|
||||||
|
@ -44,7 +50,8 @@ public class ClassHandler {
|
||||||
|
|
||||||
public Class<? extends Item> get(String nodeType){
|
public Class<? extends Item> get(String nodeType){
|
||||||
if (classMap.containsKey(nodeType)) return classMap.get(nodeType);
|
if (classMap.containsKey(nodeType)) return classMap.get(nodeType);
|
||||||
else return Item.class;
|
if (deprecatedNode.contains(nodeType)) return Item.class;
|
||||||
|
return null;
|
||||||
//throw new RuntimeException("mapping not found for nodetype "+ nodeType);
|
//throw new RuntimeException("mapping not found for nodetype "+ nodeType);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,6 +20,7 @@ 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.InvalidCallParameters;
|
||||||
import org.gcube.common.storagehub.model.exceptions.ItemLockedException;
|
import org.gcube.common.storagehub.model.exceptions.ItemLockedException;
|
||||||
import org.gcube.common.storagehub.model.exceptions.StorageHubException;
|
import org.gcube.common.storagehub.model.exceptions.StorageHubException;
|
||||||
import org.gcube.common.storagehub.model.exceptions.UserNotAuthorizedException;
|
import org.gcube.common.storagehub.model.exceptions.UserNotAuthorizedException;
|
||||||
|
@ -181,10 +182,13 @@ public class TrashHandler {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String restoreItem(Session ses, TrashItem item) throws RepositoryException, BackendGenericError, UserNotAuthorizedException{
|
public String restoreItem(Session ses, TrashItem item, FolderItem destination) throws RepositoryException, StorageHubException, BackendGenericError{
|
||||||
log.debug("restoring node from trash");
|
log.debug("restoring node from trash");
|
||||||
final String login = AuthorizationProvider.instance.get().getClient().getId();
|
final String login = AuthorizationProvider.instance.get().getClient().getId();
|
||||||
//final Node trashFolder = ses.getNode(Paths.append(Utils.getHomePath(),Constants.TRASH_ROOT_FOLDER_NAME).toPath());
|
//final Node trashFolder = ses.getNode(Paths.append(Utils.getHomePath(),Constants.TRASH_ROOT_FOLDER_NAME).toPath());
|
||||||
|
|
||||||
|
Node destinationNode= null;
|
||||||
|
if (destination==null) {
|
||||||
boolean originalParentExists = true;
|
boolean originalParentExists = true;
|
||||||
boolean originalParentTrashed = false;
|
boolean originalParentTrashed = false;
|
||||||
Node originalParent = null;
|
Node originalParent = null;
|
||||||
|
@ -200,7 +204,7 @@ public class TrashHandler {
|
||||||
originalParentTrashed = originalParentItem.isTrashed();
|
originalParentTrashed = originalParentItem.isTrashed();
|
||||||
}
|
}
|
||||||
|
|
||||||
Node destinationNode= null;
|
|
||||||
if(originalParentExists && !originalParentTrashed) {
|
if(originalParentExists && !originalParentTrashed) {
|
||||||
authChecker.checkWriteAuthorizationControl(ses, originalParentItem, originalParent, false );
|
authChecker.checkWriteAuthorizationControl(ses, originalParentItem, originalParent, false );
|
||||||
destinationNode = originalParent;
|
destinationNode = originalParent;
|
||||||
|
@ -210,22 +214,34 @@ public class TrashHandler {
|
||||||
authChecker.checkWriteAuthorizationControl(ses, node.getIdentifier(), false );
|
authChecker.checkWriteAuthorizationControl(ses, node.getIdentifier(), false );
|
||||||
destinationNode = node;
|
destinationNode = node;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
Node node = ses.getNodeByIdentifier(destination.getId());
|
||||||
|
|
||||||
|
if (!node2Item.checkNodeType(node, FolderItem.class))
|
||||||
|
throw new InvalidCallParameters("destination Node is not a folder");
|
||||||
|
|
||||||
ses.getWorkspace().getLockManager().lock(originalParent.getPath(), true, true, 0,login);
|
authChecker.checkWriteAuthorizationControl(ses, node.getIdentifier(), false );
|
||||||
|
destinationNode = node;
|
||||||
|
}
|
||||||
|
|
||||||
|
ses.getWorkspace().getLockManager().lock(destinationNode.getPath(), true, true, 0,login);
|
||||||
|
|
||||||
|
//the real node is a child of the Trash node
|
||||||
List<Item> items = Utils.getItemList(ses.getNodeByIdentifier(item.getId()), Excludes.ALL, null, false, null);
|
List<Item> items = Utils.getItemList(ses.getNodeByIdentifier(item.getId()), Excludes.ALL, null, false, null);
|
||||||
if (items.size()!=1) {
|
if (items.size()!=1) {
|
||||||
log.warn("a problem occurred restoring item from trash");
|
log.warn("a problem occurred restoring item from trash");
|
||||||
throw new BackendGenericError("An error occurred on trash item");
|
throw new BackendGenericError("An error occurred on trash item");
|
||||||
}
|
}
|
||||||
Item itemToMove = items.get(0);
|
Item itemToMove = items.get(0);
|
||||||
|
|
||||||
|
item2Node.updateOwnerOnSubTree(ses.getNodeByIdentifier(itemToMove.getId()), login);
|
||||||
|
|
||||||
String newNodePath = Paths.append(Paths.getPath(destinationNode.getPath()), itemToMove.getName()).toPath();
|
String newNodePath = Paths.append(Paths.getPath(destinationNode.getPath()), itemToMove.getName()).toPath();
|
||||||
ses.move(itemToMove.getPath(), newNodePath);
|
ses.move(itemToMove.getPath(), newNodePath);
|
||||||
Utils.setPropertyOnChangeNode(ses.getNode(newNodePath), login, ItemAction.MOVED);
|
Utils.setPropertyOnChangeNode(ses.getNode(newNodePath), login, ItemAction.MOVED);
|
||||||
ses.removeItem(item.getPath());
|
ses.removeItem(item.getPath());
|
||||||
ses.save();
|
ses.save();
|
||||||
return ses.getNode(newNodePath).getIdentifier();
|
return ses.getNode(newNodePath).getIdentifier();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,6 +24,7 @@ import org.apache.jackrabbit.util.ISO9075;
|
||||||
import org.gcube.common.storagehub.model.Excludes;
|
import org.gcube.common.storagehub.model.Excludes;
|
||||||
import org.gcube.common.storagehub.model.NodeConstants;
|
import org.gcube.common.storagehub.model.NodeConstants;
|
||||||
import org.gcube.common.storagehub.model.items.Item;
|
import org.gcube.common.storagehub.model.items.Item;
|
||||||
|
import org.gcube.data.access.storagehub.NodeChildrenFilterIterator;
|
||||||
import org.gcube.data.access.storagehub.handlers.items.Node2ItemConverter;
|
import org.gcube.data.access.storagehub.handlers.items.Node2ItemConverter;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
@ -73,10 +74,10 @@ public class VREQueryRetriever implements Callable<List<Item>> {
|
||||||
|
|
||||||
jcrQuery.setLimit(CACHE_DIMENSION);
|
jcrQuery.setLimit(CACHE_DIMENSION);
|
||||||
lastTimestamp = System.currentTimeMillis();
|
lastTimestamp = System.currentTimeMillis();
|
||||||
NodeIterator it = jcrQuery.execute().getNodes();
|
NodeChildrenFilterIterator it = new NodeChildrenFilterIterator(jcrQuery.execute().getNodes());
|
||||||
logger.debug("query for recents took {}",System.currentTimeMillis()-start);
|
logger.debug("query for recents took {}",System.currentTimeMillis()-start);
|
||||||
while (it.hasNext()) {
|
while (it.hasNext()) {
|
||||||
Node node = it.nextNode();
|
Node node = it.next();
|
||||||
|
|
||||||
//long lastModifiedTimeItem = node.getProperty(NodeProperty.LAST_MODIFIED.toString()).getLong();
|
//long lastModifiedTimeItem = node.getProperty(NodeProperty.LAST_MODIFIED.toString()).getLong();
|
||||||
|
|
||||||
|
|
|
@ -13,6 +13,7 @@ import java.util.Set;
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
import javax.jcr.ItemExistsException;
|
import javax.jcr.ItemExistsException;
|
||||||
import javax.jcr.Node;
|
import javax.jcr.Node;
|
||||||
|
import javax.jcr.NodeIterator;
|
||||||
import javax.jcr.PathNotFoundException;
|
import javax.jcr.PathNotFoundException;
|
||||||
import javax.jcr.RepositoryException;
|
import javax.jcr.RepositoryException;
|
||||||
import javax.jcr.Value;
|
import javax.jcr.Value;
|
||||||
|
@ -31,10 +32,13 @@ import org.gcube.common.storagehub.model.annotations.ListNodes;
|
||||||
import org.gcube.common.storagehub.model.annotations.MapAttribute;
|
import org.gcube.common.storagehub.model.annotations.MapAttribute;
|
||||||
import org.gcube.common.storagehub.model.annotations.NodeAttribute;
|
import org.gcube.common.storagehub.model.annotations.NodeAttribute;
|
||||||
import org.gcube.common.storagehub.model.annotations.RootNode;
|
import org.gcube.common.storagehub.model.annotations.RootNode;
|
||||||
|
import org.gcube.common.storagehub.model.exceptions.BackendGenericError;
|
||||||
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.Item;
|
import org.gcube.common.storagehub.model.items.Item;
|
||||||
import org.gcube.common.storagehub.model.types.ItemAction;
|
import org.gcube.common.storagehub.model.types.ItemAction;
|
||||||
import org.gcube.common.storagehub.model.types.NodeProperty;
|
import org.gcube.common.storagehub.model.types.NodeProperty;
|
||||||
|
import org.gcube.data.access.storagehub.NodeChildrenFilterIterator;
|
||||||
import org.gcube.data.access.storagehub.Utils;
|
import org.gcube.data.access.storagehub.Utils;
|
||||||
import org.gcube.data.access.storagehub.handlers.ClassHandler;
|
import org.gcube.data.access.storagehub.handlers.ClassHandler;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
|
@ -222,6 +226,28 @@ public class Item2NodeConverter {
|
||||||
node.setProperty(NodeProperty.HIDDEN.toString(), hidden);
|
node.setProperty(NodeProperty.HIDDEN.toString(), hidden);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void updateOwnerOnSubTree(Node node, String owner) throws RepositoryException, BackendGenericError {
|
||||||
|
Class<? extends Item> classToHandle = (Class<? extends Item>)ClassHandler.instance().get(node.getPrimaryNodeType().getName());
|
||||||
|
if (classToHandle==null) return;
|
||||||
|
if (classToHandle.isAssignableFrom(FolderItem.class)) {
|
||||||
|
NodeChildrenFilterIterator iterator = new NodeChildrenFilterIterator(node);
|
||||||
|
while (iterator.hasNext()) {
|
||||||
|
Node nextNode = iterator.next();
|
||||||
|
updateOwnerOnSubTree(nextNode, owner);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
updateOwner(node, owner);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updateOwner(Node node, String owner) throws RepositoryException {
|
||||||
|
//Utils.setPropertyOnChangeNode(node, login, ItemAction.UPDATED);
|
||||||
|
if (node.hasProperty(NodeProperty.PORTAL_LOGIN.toString()))
|
||||||
|
node.setProperty(NodeProperty.PORTAL_LOGIN.toString(), owner);
|
||||||
|
else logger.debug("cannot set new owner to {} "+node.getPath());
|
||||||
|
}
|
||||||
|
|
||||||
public <I extends Item> void updateMetadataNode(Node node, Map<String, Object> meta, String login){
|
public <I extends Item> void updateMetadataNode(Node node, Map<String, Object> meta, String login){
|
||||||
try {
|
try {
|
||||||
|
|
||||||
|
|
|
@ -53,6 +53,7 @@ public class Node2ItemConverter {
|
||||||
public <T extends Item> T getFilteredItem(Node node, List<String> excludes, Class<? extends Item> nodeTypeToInclude) throws RepositoryException, BackendGenericError{
|
public <T extends Item> T getFilteredItem(Node node, List<String> excludes, Class<? extends Item> nodeTypeToInclude) throws RepositoryException, BackendGenericError{
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
Class<T> classToHandle = (Class<T>)ClassHandler.instance().get(node.getPrimaryNodeType().getName());
|
Class<T> classToHandle = (Class<T>)ClassHandler.instance().get(node.getPrimaryNodeType().getName());
|
||||||
|
if (classToHandle==null) return null;
|
||||||
if (nodeTypeToInclude!=null && !(nodeTypeToInclude.isAssignableFrom(classToHandle))) return null;
|
if (nodeTypeToInclude!=null && !(nodeTypeToInclude.isAssignableFrom(classToHandle))) return null;
|
||||||
else return retrieveItem(node, excludes, classToHandle);
|
else return retrieveItem(node, excludes, classToHandle);
|
||||||
}
|
}
|
||||||
|
@ -65,6 +66,7 @@ public class Node2ItemConverter {
|
||||||
public <T extends Item> T getItem(Node node, List<String> excludes) throws RepositoryException, BackendGenericError{
|
public <T extends Item> T getItem(Node node, List<String> excludes) throws RepositoryException, BackendGenericError{
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
Class<T> classToHandle = (Class<T>)ClassHandler.instance().get(node.getPrimaryNodeType().getName());
|
Class<T> classToHandle = (Class<T>)ClassHandler.instance().get(node.getPrimaryNodeType().getName());
|
||||||
|
if (classToHandle==null) return null;
|
||||||
/*Node nodeToRetrieve= node;
|
/*Node nodeToRetrieve= node;
|
||||||
if (SharedFolder.class.isAssignableFrom(classToHandle)) {
|
if (SharedFolder.class.isAssignableFrom(classToHandle)) {
|
||||||
NodeIterator it= node.getSharedSet();
|
NodeIterator it= node.getSharedSet();
|
||||||
|
@ -323,6 +325,7 @@ public class Node2ItemConverter {
|
||||||
return values;
|
return values;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Checks if a node is a subtype od classToCompare
|
||||||
public boolean checkNodeType(Node node, Class<? extends Item> classToCompare) throws BackendGenericError{
|
public boolean checkNodeType(Node node, Class<? extends Item> classToCompare) throws BackendGenericError{
|
||||||
try {
|
try {
|
||||||
|
|
||||||
|
|
|
@ -17,6 +17,7 @@ import javax.jcr.query.QueryResult;
|
||||||
import javax.servlet.ServletContext;
|
import javax.servlet.ServletContext;
|
||||||
import javax.ws.rs.Consumes;
|
import javax.ws.rs.Consumes;
|
||||||
import javax.ws.rs.DELETE;
|
import javax.ws.rs.DELETE;
|
||||||
|
import javax.ws.rs.FormParam;
|
||||||
import javax.ws.rs.GET;
|
import javax.ws.rs.GET;
|
||||||
import javax.ws.rs.PUT;
|
import javax.ws.rs.PUT;
|
||||||
import javax.ws.rs.Path;
|
import javax.ws.rs.Path;
|
||||||
|
@ -30,12 +31,14 @@ import org.gcube.common.gxrest.response.outbound.GXOutboundErrorResponse;
|
||||||
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.InvalidCallParameters;
|
||||||
import org.gcube.common.storagehub.model.exceptions.InvalidItemException;
|
import org.gcube.common.storagehub.model.exceptions.InvalidItemException;
|
||||||
import org.gcube.common.storagehub.model.exceptions.StorageHubException;
|
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.expressions.Expression;
|
import org.gcube.common.storagehub.model.expressions.Expression;
|
||||||
import org.gcube.common.storagehub.model.expressions.logical.And;
|
import org.gcube.common.storagehub.model.expressions.logical.And;
|
||||||
import org.gcube.common.storagehub.model.expressions.logical.ISDescendant;
|
import org.gcube.common.storagehub.model.expressions.logical.ISDescendant;
|
||||||
|
import org.gcube.common.storagehub.model.items.FolderItem;
|
||||||
import org.gcube.common.storagehub.model.items.Item;
|
import org.gcube.common.storagehub.model.items.Item;
|
||||||
import org.gcube.common.storagehub.model.items.TrashItem;
|
import org.gcube.common.storagehub.model.items.TrashItem;
|
||||||
import org.gcube.common.storagehub.model.service.ItemList;
|
import org.gcube.common.storagehub.model.service.ItemList;
|
||||||
|
@ -273,22 +276,22 @@ public class WorkspaceManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
@PUT
|
@PUT
|
||||||
@Consumes(MediaType.TEXT_PLAIN)
|
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
|
||||||
@Path("trash/restore")
|
@Path("trash/restore")
|
||||||
public String restoreItem(String identifier){
|
public String restoreItem(@FormParam("trashedItemId") String trashedItemId,@FormParam("destinationId") String destinationFolderId){
|
||||||
InnerMethodName.instance.set("restoreItem");
|
InnerMethodName.instance.set("restoreItem");
|
||||||
Session ses = null;
|
Session ses = null;
|
||||||
String toReturn = null;
|
String toReturn = null;
|
||||||
try{
|
try{
|
||||||
|
|
||||||
log.info("restoring node with id {}", identifier);
|
log.info("restoring node with id {}", trashedItemId);
|
||||||
|
|
||||||
//TODO check if it is possible to change all the ACL on a workspace
|
//TODO check if it is possible to change all the ACL on a workspace
|
||||||
ses = repository.getRepository().login(CredentialHandler.getAdminCredentials(context));
|
ses = repository.getRepository().login(CredentialHandler.getAdminCredentials(context));
|
||||||
|
|
||||||
//authChecker.checkWriteAuthorizationControl(ses, identifier, false);
|
//authChecker.checkWriteAuthorizationControl(ses, identifier, false);
|
||||||
|
|
||||||
final Node nodeToRestore = ses.getNodeByIdentifier(identifier);
|
final Node nodeToRestore = ses.getNodeByIdentifier(trashedItemId);
|
||||||
|
|
||||||
Item itemToRestore = node2Item.getItem(nodeToRestore, Excludes.ALL);
|
Item itemToRestore = node2Item.getItem(nodeToRestore, Excludes.ALL);
|
||||||
|
|
||||||
|
@ -300,10 +303,20 @@ public class WorkspaceManager {
|
||||||
if (!itemToRestore.getPath().startsWith(trashPath.toPath()))
|
if (!itemToRestore.getPath().startsWith(trashPath.toPath()))
|
||||||
throw new UserNotAuthorizedException("this item is not in the user "+user+" trash");
|
throw new UserNotAuthorizedException("this item is not in the user "+user+" trash");
|
||||||
|
|
||||||
toReturn = trashHandler.restoreItem(ses, (TrashItem)itemToRestore);
|
Item destinationItem = null;
|
||||||
|
if (destinationFolderId!=null ) {
|
||||||
|
destinationItem = node2Item.getItem(ses.getNodeByIdentifier(destinationFolderId), Excludes.ALL);
|
||||||
|
if (!(destinationItem instanceof FolderItem))
|
||||||
|
throw new InvalidCallParameters("destintation item is not a folder");
|
||||||
|
|
||||||
|
toReturn = trashHandler.restoreItem(ses, (TrashItem)itemToRestore, (FolderItem) destinationItem);
|
||||||
|
} else {
|
||||||
|
toReturn = trashHandler.restoreItem(ses, (TrashItem)itemToRestore, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}catch(RepositoryException re ){
|
}catch(RepositoryException re ){
|
||||||
log.error("error restoring item with id {}",identifier, re);
|
log.error("error restoring item with id {}",trashedItemId, re);
|
||||||
GXOutboundErrorResponse.throwException(new BackendGenericError(re));
|
GXOutboundErrorResponse.throwException(new BackendGenericError(re));
|
||||||
}catch(StorageHubException she ){
|
}catch(StorageHubException she ){
|
||||||
log.error(she.getErrorMessage(), she);
|
log.error(she.getErrorMessage(), she);
|
||||||
|
|
|
@ -0,0 +1,22 @@
|
||||||
|
package org.gcube.data.access.storagehub.services.admin;
|
||||||
|
|
||||||
|
import javax.jcr.Item;
|
||||||
|
import javax.ws.rs.Consumes;
|
||||||
|
import javax.ws.rs.POST;
|
||||||
|
import javax.ws.rs.Path;
|
||||||
|
import javax.ws.rs.core.MediaType;
|
||||||
|
|
||||||
|
@Path("admin/items")
|
||||||
|
public class ItemManager {
|
||||||
|
|
||||||
|
|
||||||
|
@POST
|
||||||
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
|
private String createItem(Item item) {
|
||||||
|
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -25,7 +25,7 @@ The projects leading to this software have received funding from a series of
|
||||||
Version
|
Version
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
|
||||||
1.1.1-SNAPSHOT (2020-04-09)
|
1.1.1-SNAPSHOT (2020-04-14)
|
||||||
|
|
||||||
Please see the file named "changelog.xml" in this directory for the release notes.
|
Please see the file named "changelog.xml" in this directory for the release notes.
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,7 @@ import org.gcube.common.storagehub.model.expressions.GenericSearchableItem;
|
||||||
import org.gcube.common.storagehub.model.expressions.date.Before;
|
import org.gcube.common.storagehub.model.expressions.date.Before;
|
||||||
import org.gcube.common.storagehub.model.expressions.logical.And;
|
import org.gcube.common.storagehub.model.expressions.logical.And;
|
||||||
import org.gcube.common.storagehub.model.expressions.text.Contains;
|
import org.gcube.common.storagehub.model.expressions.text.Contains;
|
||||||
|
import org.gcube.data.access.storagehub.Constants;
|
||||||
import org.gcube.data.access.storagehub.query.sql2.evaluators.Evaluators;
|
import org.gcube.data.access.storagehub.query.sql2.evaluators.Evaluators;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
|
@ -37,9 +38,13 @@ public class Expressions {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test2() {
|
public void test2() {
|
||||||
String groupId ="/gcube/devsec/devVre";
|
|
||||||
String title = groupId.substring(groupId.lastIndexOf("/")+1);
|
String workspace ="/Share/22228279-0793-4b68-b7c9-81489b68a355/Frosini - Resource Registry.MP4";
|
||||||
System.out.println(title);
|
|
||||||
|
String rpl1 = workspace.replaceAll("/Home/[^/]*/"+Constants.WORKSPACE_ROOT_FOLDER_NAME,"");
|
||||||
|
String rpl2 = workspace.replaceAll("/Share", "");
|
||||||
|
System.out.println(rpl1+" ---- "+rpl2 );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue