From f2742ce0e08d9839c536c5ec85c195506a7380e0 Mon Sep 17 00:00:00 2001 From: lucio Date: Fri, 17 Apr 2020 17:03:06 +0200 Subject: [PATCH] solved bug with getAnchestors and public folders --- .../data/access/storagehub/StorageHub.java | 2 + .../storagehub/services/ItemsManager.java | 5 +- .../services/admin/ItemManagerAdmin.java | 64 ++++++++++++++++++- src/main/webapp/WEB-INF/README | 2 +- 4 files changed, 68 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/gcube/data/access/storagehub/StorageHub.java b/src/main/java/org/gcube/data/access/storagehub/StorageHub.java index 53ba0be..ba3499d 100644 --- a/src/main/java/org/gcube/data/access/storagehub/StorageHub.java +++ b/src/main/java/org/gcube/data/access/storagehub/StorageHub.java @@ -14,6 +14,7 @@ import org.gcube.data.access.storagehub.services.ItemsCreator; import org.gcube.data.access.storagehub.services.ItemsManager; import org.gcube.data.access.storagehub.services.UserManager; import org.gcube.data.access.storagehub.services.WorkspaceManager; +import org.gcube.data.access.storagehub.services.admin.ItemManagerAdmin; import org.glassfish.jersey.media.multipart.MultiPartFeature; @Path("workspace") @@ -31,6 +32,7 @@ public class StorageHub extends Application { classes.add(ItemSharing.class); classes.add(UserManager.class); classes.add(GroupManager.class); + classes.add(ItemManagerAdmin.class); classes.add(SerializableErrorEntityTextWriter.class); classes.add(MyApplicationListener.class); return classes; diff --git a/src/main/java/org/gcube/data/access/storagehub/services/ItemsManager.java b/src/main/java/org/gcube/data/access/storagehub/services/ItemsManager.java index 334cc52..3b8367b 100644 --- a/src/main/java/org/gcube/data/access/storagehub/services/ItemsManager.java +++ b/src/main/java/org/gcube/data/access/storagehub/services/ItemsManager.java @@ -716,16 +716,19 @@ public class ItemsManager { Node currentNode = ses.getNodeByIdentifier(id); Item currentItem = node2Item.getItem(currentNode, excludes); log.trace("current node is {}",currentNode.getPath()); - while (!(currentNode.getPath()+"/").equals(absolutePath.toPath())) { + while (!(currentNode.getPath().matches("/Home/[^/]{1,}/Workspace"))) { if (currentItem instanceof SharedFolder){ NodeIterator sharedSetIterator = currentNode.getSharedSet(); + boolean found = false; while (sharedSetIterator.hasNext()) { Node sharedNode = sharedSetIterator.nextNode(); if (sharedNode.getPath().startsWith(Utils.getWorkspacePath(login).toPath())) { currentNode = sharedNode.getParent(); + found=true; break; } } + if (!found) break; currentItem = node2Item.getItem(currentNode, excludes); }else { currentNode = currentNode.getParent(); diff --git a/src/main/java/org/gcube/data/access/storagehub/services/admin/ItemManagerAdmin.java b/src/main/java/org/gcube/data/access/storagehub/services/admin/ItemManagerAdmin.java index ff21a33..ebb6eb1 100644 --- a/src/main/java/org/gcube/data/access/storagehub/services/admin/ItemManagerAdmin.java +++ b/src/main/java/org/gcube/data/access/storagehub/services/admin/ItemManagerAdmin.java @@ -13,6 +13,7 @@ import javax.servlet.ServletContext; import javax.ws.rs.Consumes; import javax.ws.rs.GET; import javax.ws.rs.POST; +import javax.ws.rs.PUT; import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.Produces; @@ -26,6 +27,7 @@ import org.gcube.common.gxrest.response.outbound.GXOutboundErrorResponse; 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.service.ItemList; import org.gcube.common.storagehub.model.service.ItemWrapper; import org.gcube.data.access.storagehub.StorageHubAppllicationManager; import org.gcube.data.access.storagehub.Utils; @@ -54,6 +56,7 @@ public class ItemManagerAdmin { @Path("items/{id}") @AuthorizationControl(allowedRoles = {INFRASTRUCTURE_MANAGER_ROLE},exception=MyAuthException.class) public String createItem(@PathParam("id") String id, Item item) { + InnerMethodName.instance.set("creteItemAdmin)"); //TODO: implement this method return null; } @@ -63,7 +66,7 @@ public class ItemManagerAdmin { @Path("{user}") @AuthorizationControl(allowedRoles = {INFRASTRUCTURE_MANAGER_ROLE},exception=MyAuthException.class) public ItemWrapper getWorkspace(@PathParam("user") String user) { - InnerMethodName.instance.set("move"); + InnerMethodName.instance.set("getWorkspaceAdmin"); Item item =null; Session session = null; @@ -87,12 +90,41 @@ public class ItemManagerAdmin { return new ItemWrapper(item); } + @GET + @Produces(MediaType.APPLICATION_JSON) + @Path("items/{id}") + @AuthorizationControl(allowedRoles = {INFRASTRUCTURE_MANAGER_ROLE},exception=MyAuthException.class) + public ItemWrapper getItem(@PathParam("id") String id) { + InnerMethodName.instance.set("getChildrenAdmin"); + + Item item =null; + Session session = null; + try{ + session = (JackrabbitSession) repository.getRepository().login(CredentialHandler.getAdminCredentials(context)); + Node node = session.getNodeByIdentifier(id); + + item = node2Item.getItem(node, Collections.emptyList()); + + }catch(RepositoryException re ){ + log.error("jcr error moving item", re); + GXOutboundErrorResponse.throwException(new BackendGenericError(re)); + }catch(StorageHubException she ){ + log.error(she.getErrorMessage(), she); + GXOutboundErrorResponse.throwException(she, Response.Status.fromStatusCode(she.getStatus())); + } finally{ + if (session!=null) { + session.logout(); + } + } + return new ItemWrapper(item); + } + @GET @Produces(MediaType.APPLICATION_JSON) @Path("items/{id}/children") @AuthorizationControl(allowedRoles = {INFRASTRUCTURE_MANAGER_ROLE},exception=MyAuthException.class) - public List getChildren(@PathParam("id") String id) { - InnerMethodName.instance.set("move"); + public ItemList getChildren(@PathParam("id") String id) { + InnerMethodName.instance.set("getChildrenAdmin"); List items =null; Session session = null; @@ -113,6 +145,32 @@ public class ItemManagerAdmin { session.logout(); } } + return new ItemList(items); + } + + @PUT + @Consumes(MediaType.TEXT_PLAIN) + @Path("items/{id}/{propertyName}") + @AuthorizationControl(allowedRoles = {INFRASTRUCTURE_MANAGER_ROLE},exception=MyAuthException.class) + public List setProperty(@PathParam("id") String id, @PathParam("propertyName") String propertyName, String value) { + InnerMethodName.instance.set("setPropertyAdmin"); + + List items =null; + Session session = null; + try{ + session = (JackrabbitSession) repository.getRepository().login(CredentialHandler.getAdminCredentials(context)); + Node node = session.getNodeByIdentifier(id); + node.setProperty(propertyName, value); + session.save(); + + }catch(RepositoryException re ){ + log.error("jcr error moving item", re); + GXOutboundErrorResponse.throwException(new BackendGenericError(re)); + } finally{ + if (session!=null) { + session.logout(); + } + } return items; } diff --git a/src/main/webapp/WEB-INF/README b/src/main/webapp/WEB-INF/README index 1cd450f..0e1f6c3 100644 --- a/src/main/webapp/WEB-INF/README +++ b/src/main/webapp/WEB-INF/README @@ -25,7 +25,7 @@ The projects leading to this software have received funding from a series of Version -------------------------------------------------- -1.2.0-SNAPSHOT (2020-04-15) +1.2.0-SNAPSHOT (2020-04-17) Please see the file named "changelog.xml" in this directory for the release notes.