solved bug with getAnchestors and public folders

This commit is contained in:
Lucio Lelii 2020-04-17 17:03:06 +02:00
parent 7ed01ecc4e
commit f2742ce0e0
4 changed files with 68 additions and 5 deletions

View File

@ -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;

View File

@ -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();

View File

@ -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<Item> 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>(item);
}
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("items/{id}")
@AuthorizationControl(allowedRoles = {INFRASTRUCTURE_MANAGER_ROLE},exception=MyAuthException.class)
public ItemWrapper<Item> 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>(item);
}
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("items/{id}/children")
@AuthorizationControl(allowedRoles = {INFRASTRUCTURE_MANAGER_ROLE},exception=MyAuthException.class)
public List<Item> getChildren(@PathParam("id") String id) {
InnerMethodName.instance.set("move");
public ItemList getChildren(@PathParam("id") String id) {
InnerMethodName.instance.set("getChildrenAdmin");
List<Item> 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<Item> setProperty(@PathParam("id") String id, @PathParam("propertyName") String propertyName, String value) {
InnerMethodName.instance.set("setPropertyAdmin");
List<Item> 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;
}

View File

@ -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.