update for libraries changes
This commit is contained in:
parent
b805869feb
commit
98ee8ea8e9
|
@ -35,7 +35,6 @@ import org.gcube.common.storagehub.model.items.ExternalLink;
|
|||
import org.gcube.common.storagehub.model.items.FolderItem;
|
||||
import org.gcube.common.storagehub.model.items.GCubeItem;
|
||||
import org.gcube.common.storagehub.model.items.Item;
|
||||
import org.gcube.common.storagehub.model.items.RootItem;
|
||||
import org.gcube.common.storagehub.model.items.SharedFolder;
|
||||
import org.gcube.common.storagehub.model.storages.MetaInfo;
|
||||
import org.gcube.common.storagehub.model.types.ItemAction;
|
||||
|
@ -45,6 +44,7 @@ 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.items.builders.FolderCreationParameters;
|
||||
import org.gcube.data.access.storagehub.handlers.plugins.StorageBackendHandler;
|
||||
import org.gcube.data.access.storagehub.predicates.ItemTypePredicate;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
@ -75,8 +75,8 @@ public class Utils {
|
|||
return digest;
|
||||
}
|
||||
|
||||
public static long getItemCount(Node parent, boolean showHidden, Class<? extends RootItem> nodeType) throws RepositoryException, BackendGenericError{
|
||||
return getItemList(parent, Excludes.ALL, null, showHidden, nodeType).size();
|
||||
public static long getItemCount(Node parent, boolean showHidden, ItemTypePredicate itemTypePredicate) throws RepositoryException, BackendGenericError{
|
||||
return getItemList(parent, Excludes.ALL, null, showHidden, itemTypePredicate).size();
|
||||
}
|
||||
|
||||
|
||||
|
@ -104,7 +104,7 @@ public class Utils {
|
|||
}
|
||||
|
||||
|
||||
public static <T extends Item> List<T> searchByNameOnFolder(Session ses, String user, AuthorizationChecker authChecker, Node parent, List<String> excludes, Range range, boolean showHidden, boolean excludeTrashed, Class<? extends RootItem> nodeTypeToInclude, String nameParam) throws RepositoryException, BackendGenericError{
|
||||
public static <T extends Item> List<T> searchByNameOnFolder(Session ses, String user, AuthorizationChecker authChecker, Node parent, List<String> excludes, Range range, boolean showHidden, boolean excludeTrashed, ItemTypePredicate itemTypePredicate, String nameParam) throws RepositoryException, BackendGenericError{
|
||||
String xpath = String.format("/jcr:root%s//element(*,nthl:workspaceItem)[jcr:like(fn:lower-case(@jcr:title), '%s')]",ISO9075.encodePath(parent.getPath()), nameParam.toLowerCase());
|
||||
|
||||
//String query = String.format("SELECT * FROM [nthl:workspaceLeafItem] AS node WHERE ISDESCENDANTNODE('%s') ORDER BY node.[jcr:lastModified] DESC ",vreFolder.getPath());
|
||||
|
@ -128,27 +128,26 @@ public class Utils {
|
|||
|
||||
};
|
||||
|
||||
return getItemListFromNodeIterator(checker, iterator , excludes, range, showHidden, excludeTrashed, nodeTypeToInclude);
|
||||
return getItemListFromNodeIterator(checker, iterator , excludes, range, showHidden, excludeTrashed, itemTypePredicate);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static <T extends Item> List<T> getItemList(Node parent, List<String> excludes, Range range, boolean showHidden, Class<? extends RootItem> nodeTypeToInclude) throws RepositoryException, BackendGenericError{
|
||||
return getItemList(null, parent, excludes, range, showHidden, nodeTypeToInclude);
|
||||
public static <T extends Item> List<T> getItemList(Node parent, List<String> excludes, Range range, boolean showHidden, ItemTypePredicate itemTypePredicate) throws RepositoryException, BackendGenericError{
|
||||
return getItemList(null, parent, excludes, range, showHidden, itemTypePredicate);
|
||||
}
|
||||
|
||||
public static <T extends Item> List<T> getItemList(Predicate<Node> checker, Node parent, List<String> excludes, Range range, boolean showHidden, Class<? extends RootItem> nodeTypeToInclude) throws RepositoryException, BackendGenericError{
|
||||
public static <T extends Item> List<T> getItemList(Predicate<Node> checker, Node parent, List<String> excludes, Range range, boolean showHidden, ItemTypePredicate itemTypePredicate) throws RepositoryException, BackendGenericError{
|
||||
logger.trace("getting children of node {}", parent.getIdentifier());
|
||||
long start = System.currentTimeMillis();
|
||||
NodeChildrenFilterIterator iterator = new NodeChildrenFilterIterator(parent);
|
||||
logger.trace("time to get iterator {}",(System.currentTimeMillis()-start));
|
||||
return getItemListFromNodeIterator(checker, iterator, excludes, range, showHidden, false, nodeTypeToInclude);
|
||||
return getItemListFromNodeIterator(checker, iterator, excludes, range, showHidden, false, itemTypePredicate);
|
||||
}
|
||||
|
||||
private static <T extends Item> List<T> getItemListFromNodeIterator(Predicate<Node> checker, NodeChildrenFilterIterator iterator, List<String> excludes, Range range, boolean showHidden, boolean excludeTrashed, Class<? extends RootItem> nodeTypeToInclude) throws RepositoryException, BackendGenericError{
|
||||
private static <T extends Item> List<T> getItemListFromNodeIterator(Predicate<Node> checker, NodeChildrenFilterIterator iterator, List<String> excludes, Range range, boolean showHidden, boolean excludeTrashed, ItemTypePredicate itemTypePredicate) throws RepositoryException, BackendGenericError{
|
||||
List<T> returnList = new ArrayList<T>();
|
||||
|
||||
logger.trace("nodeType is {}",nodeTypeToInclude);
|
||||
int count =0;
|
||||
logger.trace("selected range is {}", range);
|
||||
Node2ItemConverter node2Item= new Node2ItemConverter();
|
||||
|
@ -175,7 +174,7 @@ public class Utils {
|
|||
logger.trace("[SEARCH] current node not excluded {} ",current.hasProperty(NodeProperty.TITLE.toString())? current.getProperty(NodeProperty.TITLE.toString()):current.getName());
|
||||
|
||||
if (range==null || (count>=range.getStart() && returnList.size()<range.getLimit())) {
|
||||
T item = node2Item.getFilteredItem(current, excludes, nodeTypeToInclude);
|
||||
T item = node2Item.getFilteredItem(current, excludes, itemTypePredicate);
|
||||
if (item==null || (item.isTrashed() && excludeTrashed)) continue;
|
||||
returnList.add(item);
|
||||
}
|
||||
|
|
|
@ -13,7 +13,6 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import jakarta.inject.Singleton;
|
||||
import javax.jcr.Node;
|
||||
import javax.jcr.NodeIterator;
|
||||
import javax.jcr.PathNotFoundException;
|
||||
|
@ -42,12 +41,15 @@ import org.gcube.common.storagehub.model.items.nodes.Content;
|
|||
import org.gcube.common.storagehub.model.messages.Message;
|
||||
import org.gcube.data.access.storagehub.Constants;
|
||||
import org.gcube.data.access.storagehub.handlers.ClassHandler;
|
||||
import org.gcube.data.access.storagehub.predicates.ItemTypePredicate;
|
||||
import org.reflections.Configuration;
|
||||
import org.reflections.Reflections;
|
||||
import org.reflections.util.ConfigurationBuilder;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import jakarta.inject.Singleton;
|
||||
|
||||
@Singleton
|
||||
@SuppressWarnings("rawtypes")
|
||||
public class Node2ItemConverter {
|
||||
|
@ -57,11 +59,11 @@ public class Node2ItemConverter {
|
|||
|
||||
private static HashMap<Class<?>, Map<String, Class>> typeToSubtypeMap = new HashMap<>();
|
||||
|
||||
public <T extends Item> T getFilteredItem(Node node, List<String> excludes, Class<? extends RootItem> nodeTypeToInclude) throws RepositoryException, BackendGenericError{
|
||||
public <T extends Item> T getFilteredItem(Node node, List<String> excludes, ItemTypePredicate itemTypePredicate) throws RepositoryException, BackendGenericError{
|
||||
@SuppressWarnings("unchecked")
|
||||
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 (itemTypePredicate != null && !itemTypePredicate.test(classToHandle)) return null;
|
||||
else return retrieveItem(node, excludes, classToHandle);
|
||||
}
|
||||
|
||||
|
|
|
@ -53,6 +53,8 @@ import org.gcube.data.access.storagehub.handlers.VersionHandler;
|
|||
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.StorageOperationMediator;
|
||||
import org.gcube.data.access.storagehub.predicates.IncludeTypePredicate;
|
||||
import org.gcube.data.access.storagehub.predicates.ItemTypePredicate;
|
||||
import org.gcube.data.access.storagehub.repository.StoragehubRepository;
|
||||
import org.gcube.data.access.storagehub.types.PublicLink;
|
||||
import org.gcube.smartgears.annotations.ManagedBy;
|
||||
|
@ -285,7 +287,9 @@ public class ItemsManager extends Impersonable{
|
|||
try{
|
||||
ses = repository.getRepository().login(Constants.JCR_CREDENTIALS);
|
||||
authChecker.checkReadAuthorizationControl(ses, currentUser, id);
|
||||
toReturn = Utils.getItemCount(ses.getNodeByIdentifier(id), showHidden==null?false:showHidden, nodeType!=null ? ClassHandler.instance().get(nodeType) : null);
|
||||
ItemTypePredicate itemPredicate = nodeType!=null ? new IncludeTypePredicate(ClassHandler.instance().get(nodeType)) : null;
|
||||
Node node = ses.getNodeByIdentifier(id);
|
||||
toReturn = Utils.getItemCount(node, showHidden==null?false:showHidden, itemPredicate );
|
||||
}catch (ItemNotFoundException e) {
|
||||
log.error("id {} not found",id,e);
|
||||
GXOutboundErrorResponse.throwException(new IdNotFoundException(id, e), Status.NOT_FOUND);
|
||||
|
@ -312,7 +316,9 @@ public class ItemsManager extends Impersonable{
|
|||
try{
|
||||
ses = repository.getRepository().login(Constants.JCR_CREDENTIALS);
|
||||
authChecker.checkReadAuthorizationControl(ses, currentUser, id);
|
||||
toReturn = Utils.getItemList(ses.getNodeByIdentifier(id), excludes, null, showHidden==null?false:showHidden, nodeType!=null ? ClassHandler.instance().get(nodeType) : null);
|
||||
ItemTypePredicate itemPredicate = nodeType!=null ? new IncludeTypePredicate(ClassHandler.instance().get(nodeType)) : null;
|
||||
Node node = ses.getNodeByIdentifier(id);
|
||||
toReturn = Utils.getItemList(node, excludes, null, showHidden==null?false:showHidden, itemPredicate);
|
||||
}catch (ItemNotFoundException e) {
|
||||
log.error("id {} not found",id,e);
|
||||
GXOutboundErrorResponse.throwException(new IdNotFoundException(id, e), Status.NOT_FOUND);
|
||||
|
@ -341,7 +347,9 @@ public class ItemsManager extends Impersonable{
|
|||
log.debug("search for node {}",name);
|
||||
ses = repository.getRepository().login(Constants.JCR_CREDENTIALS);
|
||||
authChecker.checkReadAuthorizationControl(ses, currentUser, id);
|
||||
toReturn = Utils.searchByNameOnFolder(ses, currentUser, authChecker, ses.getNodeByIdentifier(id), excludes, null, showHidden==null?false:showHidden,excludeTrashed==true?false:excludeTrashed , nodeType!=null ? ClassHandler.instance().get(nodeType) : null, name);
|
||||
ItemTypePredicate itemPredicate = nodeType!=null ? new IncludeTypePredicate(ClassHandler.instance().get(nodeType)) : null;
|
||||
Node node = ses.getNodeByIdentifier(id);
|
||||
toReturn = Utils.searchByNameOnFolder(ses, currentUser, authChecker, node, excludes, null, showHidden==null?false:showHidden, excludeTrashed==true?false:excludeTrashed, itemPredicate, name);
|
||||
log.debug("search retrieved {} elements",toReturn.size());
|
||||
}catch (ItemNotFoundException e) {
|
||||
log.error("id {} not found",id,e);
|
||||
|
@ -370,7 +378,9 @@ public class ItemsManager extends Impersonable{
|
|||
try{
|
||||
ses = repository.getRepository().login(Constants.JCR_CREDENTIALS);
|
||||
authChecker.checkReadAuthorizationControl(ses, currentUser, id);
|
||||
toReturn = Utils.getItemList(ses.getNodeByIdentifier(id), excludes, new Range(start, limit),showHidden==null?false:showHidden, nodeType!=null ? ClassHandler.instance().get(nodeType) : null);
|
||||
ItemTypePredicate itemPredicate = nodeType!=null ? new IncludeTypePredicate(ClassHandler.instance().get(nodeType)) : null;
|
||||
Node node = ses.getNodeByIdentifier(id);
|
||||
toReturn = Utils.getItemList(node, excludes, new Range(start, limit),showHidden==null?false:showHidden, itemPredicate);
|
||||
}catch (ItemNotFoundException e) {
|
||||
log.error("id {} not found",id,e);
|
||||
GXOutboundErrorResponse.throwException(new IdNotFoundException(id, e), Status.NOT_FOUND);
|
||||
|
|
|
@ -43,6 +43,8 @@ import org.gcube.data.access.storagehub.handlers.items.Item2NodeConverter;
|
|||
import org.gcube.data.access.storagehub.handlers.items.Item2NodeConverter.Values;
|
||||
import org.gcube.data.access.storagehub.handlers.items.Node2ItemConverter;
|
||||
import org.gcube.data.access.storagehub.handlers.plugins.StorageBackendHandler;
|
||||
import org.gcube.data.access.storagehub.predicates.IncludeTypePredicate;
|
||||
import org.gcube.data.access.storagehub.predicates.ItemTypePredicate;
|
||||
import org.gcube.data.access.storagehub.repository.StoragehubRepository;
|
||||
import org.gcube.data.access.storagehub.types.MessageSharable;
|
||||
import org.gcube.smartgears.annotations.ManagedBy;
|
||||
|
@ -143,7 +145,8 @@ public class MessageManager extends Impersonable{
|
|||
}else {
|
||||
if (message.isWithAttachments()) {
|
||||
Node attachmentNode = messageNode.getNode(Constants.ATTACHMENTNODE_NAME);
|
||||
List<Item> attachments = Utils.getItemList(attachmentNode, Excludes.GET_ONLY_CONTENT, null, true, AbstractFileItem.class);
|
||||
ItemTypePredicate itemPredicate = new IncludeTypePredicate(AbstractFileItem.class);
|
||||
List<Item> attachments = Utils.getItemList(attachmentNode, Excludes.GET_ONLY_CONTENT, null, true, itemPredicate);
|
||||
trashHandler.removeOnlyNodesContent(ses, attachments);
|
||||
}
|
||||
messageNode.removeSharedSet();
|
||||
|
@ -178,7 +181,8 @@ public class MessageManager extends Impersonable{
|
|||
Message messageItem = node2Item.getMessageItem(messageNode);
|
||||
checkRights(currentUser, messageItem);
|
||||
Node attachmentNode = messageNode.getNode(Constants.ATTACHMENTNODE_NAME);
|
||||
attachments = Utils.getItemList(attachmentNode, Excludes.GET_ONLY_CONTENT, null, true, AbstractFileItem.class);
|
||||
ItemTypePredicate itemPredicate = new IncludeTypePredicate(AbstractFileItem.class);
|
||||
attachments = Utils.getItemList(attachmentNode, Excludes.GET_ONLY_CONTENT, null, true, itemPredicate);
|
||||
}catch (ItemNotFoundException e) {
|
||||
log.error("id {} not found",id,e);
|
||||
GXOutboundErrorResponse.throwException(new IdNotFoundException(id, e), Status.NOT_FOUND);
|
||||
|
|
|
@ -43,6 +43,8 @@ import org.gcube.data.access.storagehub.handlers.items.builders.FolderCreationPa
|
|||
import org.gcube.data.access.storagehub.handlers.plugins.StorageBackendHandler;
|
||||
import org.gcube.data.access.storagehub.handlers.vres.VRE;
|
||||
import org.gcube.data.access.storagehub.handlers.vres.VREManager;
|
||||
import org.gcube.data.access.storagehub.predicates.IncludeTypePredicate;
|
||||
import org.gcube.data.access.storagehub.predicates.ItemTypePredicate;
|
||||
import org.gcube.data.access.storagehub.query.sql2.evaluators.Evaluators;
|
||||
import org.gcube.data.access.storagehub.repository.StoragehubRepository;
|
||||
import org.gcube.data.access.storagehub.services.delegates.UserManagerDelegate;
|
||||
|
@ -471,8 +473,8 @@ public class WorkspaceManager extends Impersonable {
|
|||
ses = repository.getRepository().login(Constants.JCR_CREDENTIALS);
|
||||
sharedPath = pathUtil.getSharedWithMePath(currentUser);
|
||||
log.info("shared With Me folder path is {}", sharedPath.toPath());
|
||||
|
||||
toReturn = Utils.getItemList(ses.getNode(sharedPath.toPath()), excludes, null, false, SharedFolder.class);
|
||||
ItemTypePredicate itemPredicate = new IncludeTypePredicate(SharedFolder.class);
|
||||
toReturn = Utils.getItemList(ses.getNode(sharedPath.toPath()), excludes, null, false, itemPredicate);
|
||||
} catch (RepositoryException re) {
|
||||
log.error("error reading shared with me folder ({})", sharedPath, re);
|
||||
GXOutboundErrorResponse.throwException(new BackendGenericError(re));
|
||||
|
|
|
@ -37,6 +37,8 @@ import org.gcube.data.access.storagehub.Utils;
|
|||
import org.gcube.data.access.storagehub.handlers.TrashHandler;
|
||||
import org.gcube.data.access.storagehub.handlers.UnshareHandler;
|
||||
import org.gcube.data.access.storagehub.handlers.items.builders.FolderCreationParameters;
|
||||
import org.gcube.data.access.storagehub.predicates.IncludeTypePredicate;
|
||||
import org.gcube.data.access.storagehub.predicates.ItemTypePredicate;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
@ -330,8 +332,9 @@ public class UserManagerDelegate {
|
|||
}
|
||||
};
|
||||
|
||||
ItemTypePredicate itemPredicate = new IncludeTypePredicate(SharedFolder.class);
|
||||
List<SharedFolder> items = Utils.getItemList(sharedWithUserChecker, sharedFolderNode, Excludes.ALL, null,
|
||||
false, SharedFolder.class);
|
||||
false,itemPredicate);
|
||||
|
||||
log.debug(" Shared folder to unshare found are {}", items.size());
|
||||
|
||||
|
|
|
@ -132,6 +132,8 @@ public class S3Backend extends StorageBackend{
|
|||
public MetaInfo upload(InputStream stream, String relativePath, String name, String storageId, Long size, String user) {
|
||||
try {
|
||||
|
||||
long start = System.currentTimeMillis();
|
||||
|
||||
ObjectMetadata objMeta = new ObjectMetadata();
|
||||
objMeta.addUserMetadata("user", user);
|
||||
objMeta.addUserMetadata("title", name);
|
||||
|
@ -153,7 +155,7 @@ public class S3Backend extends StorageBackend{
|
|||
fileSize = client.getObjectMetadata(bucketName, storageId).getContentLength();
|
||||
|
||||
IOUtils.drainInputStream(stream);
|
||||
|
||||
log.info("uploading file {} in {} seconds",name, (System.currentTimeMillis()-start)/1000);
|
||||
return new MetaInfo(fileSize,storageId, null, getPayloadConfiguration());
|
||||
} catch (Exception e) {
|
||||
log.error("error uploading file on s3",e);
|
||||
|
|
Loading…
Reference in New Issue