From b279496026e5818058b482ce6046284d7fbd9020 Mon Sep 17 00:00:00 2001 From: Lucio Lelii Date: Tue, 26 Mar 2019 16:09:26 +0000 Subject: [PATCH] added code errors to return git-svn-id: https://svn.d4science-ii.research-infrastructures.eu/gcube/branches/data-access/storagehub-webapp/1.0@178696 82a268e6-3cf1-43bd-a215-b396298e98cf --- .classpath | 3 + .project | 14 +++ .settings/.jsdtscope | 12 ++ .settings/org.eclipse.jdt.core.prefs | 1 + .settings/org.eclipse.wst.common.component | 13 +++ ...se.wst.common.project.facet.core.prefs.xml | 7 ++ ....eclipse.wst.common.project.facet.core.xml | 8 ++ ...rg.eclipse.wst.jsdt.ui.superType.container | 1 + .../org.eclipse.wst.jsdt.ui.superType.name | 1 + .settings/org.eclipse.wst.validation.prefs | 2 + .../storagehub/services/ACLManager.java | 10 +- .../storagehub/services/GroupManager.java | 1 - .../storagehub/services/ItemSharing.java | 11 +- .../storagehub/services/ItemsCreator.java | 20 ++-- .../storagehub/services/ItemsManager.java | 109 ++++++++++-------- .../storagehub/services/UserManager.java | 27 ++--- .../storagehub/services/WorkspaceManager.java | 46 ++++---- src/test/resources/META-INF/beans.xml | 3 +- 18 files changed, 174 insertions(+), 115 deletions(-) create mode 100644 .settings/.jsdtscope create mode 100644 .settings/org.eclipse.wst.common.component create mode 100644 .settings/org.eclipse.wst.common.project.facet.core.prefs.xml create mode 100644 .settings/org.eclipse.wst.common.project.facet.core.xml create mode 100644 .settings/org.eclipse.wst.jsdt.ui.superType.container create mode 100644 .settings/org.eclipse.wst.jsdt.ui.superType.name create mode 100644 .settings/org.eclipse.wst.validation.prefs diff --git a/.classpath b/.classpath index ace8266..11def0e 100644 --- a/.classpath +++ b/.classpath @@ -15,16 +15,19 @@ + + + diff --git a/.project b/.project index cf3d13f..6f033c9 100644 --- a/.project +++ b/.project @@ -5,6 +5,11 @@ + + org.eclipse.wst.common.project.facet.core.builder + + + org.eclipse.jdt.core.javabuilder @@ -15,9 +20,18 @@ + + org.eclipse.wst.validation.validationbuilder + + + + org.eclipse.jem.workbench.JavaEMFNature + org.eclipse.wst.common.modulecore.ModuleCoreNature org.eclipse.jdt.core.javanature org.eclipse.m2e.core.maven2Nature + org.eclipse.wst.common.project.facet.core.nature + org.eclipse.wst.jsdt.core.jsNature diff --git a/.settings/.jsdtscope b/.settings/.jsdtscope new file mode 100644 index 0000000..81672d4 --- /dev/null +++ b/.settings/.jsdtscope @@ -0,0 +1,12 @@ + + + + + + + + + + + + diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs index 13b3428..91ca62e 100644 --- a/.settings/org.eclipse.jdt.core.prefs +++ b/.settings/org.eclipse.jdt.core.prefs @@ -10,4 +10,5 @@ org.eclipse.jdt.core.compiler.debug.sourceFile=generate org.eclipse.jdt.core.compiler.problem.assertIdentifier=error org.eclipse.jdt.core.compiler.problem.enumIdentifier=error org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning +org.eclipse.jdt.core.compiler.release=disabled org.eclipse.jdt.core.compiler.source=1.8 diff --git a/.settings/org.eclipse.wst.common.component b/.settings/org.eclipse.wst.common.component new file mode 100644 index 0000000..7603bb0 --- /dev/null +++ b/.settings/org.eclipse.wst.common.component @@ -0,0 +1,13 @@ + + + + + + + + uses + + + + + diff --git a/.settings/org.eclipse.wst.common.project.facet.core.prefs.xml b/.settings/org.eclipse.wst.common.project.facet.core.prefs.xml new file mode 100644 index 0000000..cc81385 --- /dev/null +++ b/.settings/org.eclipse.wst.common.project.facet.core.prefs.xml @@ -0,0 +1,7 @@ + + + + + + + diff --git a/.settings/org.eclipse.wst.common.project.facet.core.xml b/.settings/org.eclipse.wst.common.project.facet.core.xml new file mode 100644 index 0000000..fac1799 --- /dev/null +++ b/.settings/org.eclipse.wst.common.project.facet.core.xml @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/.settings/org.eclipse.wst.jsdt.ui.superType.container b/.settings/org.eclipse.wst.jsdt.ui.superType.container new file mode 100644 index 0000000..3bd5d0a --- /dev/null +++ b/.settings/org.eclipse.wst.jsdt.ui.superType.container @@ -0,0 +1 @@ +org.eclipse.wst.jsdt.launching.baseBrowserLibrary \ No newline at end of file diff --git a/.settings/org.eclipse.wst.jsdt.ui.superType.name b/.settings/org.eclipse.wst.jsdt.ui.superType.name new file mode 100644 index 0000000..05bd71b --- /dev/null +++ b/.settings/org.eclipse.wst.jsdt.ui.superType.name @@ -0,0 +1 @@ +Window \ No newline at end of file diff --git a/.settings/org.eclipse.wst.validation.prefs b/.settings/org.eclipse.wst.validation.prefs new file mode 100644 index 0000000..04cad8c --- /dev/null +++ b/.settings/org.eclipse.wst.validation.prefs @@ -0,0 +1,2 @@ +disabled=06target +eclipse.preferences.version=1 diff --git a/src/main/java/org/gcube/data/access/storagehub/services/ACLManager.java b/src/main/java/org/gcube/data/access/storagehub/services/ACLManager.java index cfcc619..66eee5d 100644 --- a/src/main/java/org/gcube/data/access/storagehub/services/ACLManager.java +++ b/src/main/java/org/gcube/data/access/storagehub/services/ACLManager.java @@ -21,6 +21,7 @@ import javax.ws.rs.PathParam; import javax.ws.rs.Produces; import javax.ws.rs.core.Context; import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; import org.apache.jackrabbit.api.security.JackrabbitAccessControlList; import org.apache.jackrabbit.commons.jackrabbit.authorization.AccessControlUtils; @@ -69,7 +70,6 @@ public class ACLManager { * @exception {@link RepositoryException} when a generic jcr error occurs * @exception {@link UserNotAuthorizedException} when the caller is not authorized to access to the shared folder */ - @Produces(MediaType.APPLICATION_JSON) @GET @Path("{id}/acls") public ACLList getACL() { @@ -100,8 +100,8 @@ public class ACLManager { log.error("jcr error getting acl", re); GXOutboundErrorResponse.throwException(new BackendGenericError("jcr error getting acl", re)); }catch(StorageHubException she ){ - log.error("error getting acl", she); - GXOutboundErrorResponse.throwException(she); + log.error(she.getErrorMessage(), she); + GXOutboundErrorResponse.throwException(she, Response.Status.fromStatusCode(she.getStatus())); }finally{ if (ses!=null) ses.logout(); @@ -167,8 +167,8 @@ public class ACLManager { log.error("jcr error extracting archive", re); GXOutboundErrorResponse.throwException(new BackendGenericError("jcr error setting acl", re)); }catch(StorageHubException she ){ - log.error("error setting acl", she); - GXOutboundErrorResponse.throwException(she); + log.error(she.getErrorMessage(), she); + GXOutboundErrorResponse.throwException(she, Response.Status.fromStatusCode(she.getStatus())); }finally{ if (ses!=null) ses.logout(); diff --git a/src/main/java/org/gcube/data/access/storagehub/services/GroupManager.java b/src/main/java/org/gcube/data/access/storagehub/services/GroupManager.java index 209d1ed..edc5d96 100644 --- a/src/main/java/org/gcube/data/access/storagehub/services/GroupManager.java +++ b/src/main/java/org/gcube/data/access/storagehub/services/GroupManager.java @@ -55,7 +55,6 @@ public class GroupManager { @GET @Path("") - @Produces(MediaType.APPLICATION_JSON) @AuthorizationControl(allowed={"lucio.lelii"}, exception=MyAuthException.class) public List getGroups(){ diff --git a/src/main/java/org/gcube/data/access/storagehub/services/ItemSharing.java b/src/main/java/org/gcube/data/access/storagehub/services/ItemSharing.java index 4865afd..0dbdd35 100644 --- a/src/main/java/org/gcube/data/access/storagehub/services/ItemSharing.java +++ b/src/main/java/org/gcube/data/access/storagehub/services/ItemSharing.java @@ -17,6 +17,7 @@ import javax.ws.rs.PathParam; import javax.ws.rs.Produces; import javax.ws.rs.core.Context; import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; import org.apache.jackrabbit.api.security.JackrabbitAccessControlList; import org.apache.jackrabbit.commons.jackrabbit.authorization.AccessControlUtils; @@ -76,7 +77,6 @@ public class ItemSharing { @PUT @Path("{id}/share") - @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.MULTIPART_FORM_DATA) public String share(@FormDataParam("users") Set users, @FormDataParam("defaultAccessType") AccessType accessType){ InnerMethodName.instance.set("shareFolder"); @@ -146,8 +146,8 @@ public class ItemSharing { log.error("jcr sharing", re); GXOutboundErrorResponse.throwException(new BackendGenericError("jcr error extracting archive", re)); }catch(StorageHubException she ){ - log.error("error sharing", she); - GXOutboundErrorResponse.throwException(she); + log.error(she.getErrorMessage(), she); + GXOutboundErrorResponse.throwException(she, Response.Status.fromStatusCode(she.getStatus())); }finally{ if (ses!=null) ses.logout(); @@ -207,7 +207,6 @@ public class ItemSharing { @PUT @Path("{id}/unshare") - @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.MULTIPART_FORM_DATA) public String unshare(@FormDataParam("users") Set users){ InnerMethodName.instance.set("unshareFolder"); @@ -223,8 +222,8 @@ public class ItemSharing { log.error("jcr unsharing", re); GXOutboundErrorResponse.throwException(new BackendGenericError("jcr error extracting archive", re)); }catch(StorageHubException she ){ - log.error("error unsharing", she); - GXOutboundErrorResponse.throwException(she); + log.error(she.getErrorMessage(), she); + GXOutboundErrorResponse.throwException(she, Response.Status.fromStatusCode(she.getStatus())); }finally{ if (ses!=null) diff --git a/src/main/java/org/gcube/data/access/storagehub/services/ItemsCreator.java b/src/main/java/org/gcube/data/access/storagehub/services/ItemsCreator.java index eaff9f8..52dce9b 100644 --- a/src/main/java/org/gcube/data/access/storagehub/services/ItemsCreator.java +++ b/src/main/java/org/gcube/data/access/storagehub/services/ItemsCreator.java @@ -31,6 +31,7 @@ import javax.ws.rs.PathParam; import javax.ws.rs.Produces; import javax.ws.rs.core.Context; import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; import org.apache.commons.compress.archivers.ArchiveEntry; import org.apache.commons.compress.archivers.ArchiveException; @@ -105,7 +106,6 @@ public class ItemsCreator { //@Path("/{id}/create/{type:(?!FILE)[^/?$]*}") @POST - @Produces(MediaType.TEXT_PLAIN) @Consumes(MediaType.APPLICATION_FORM_URLENCODED) @Path("/{id}/create/FOLDER") public String createFolder(@PathParam("id") String id, @FormParam("name") String name, @FormParam("description") String description, @FormParam("hidden") boolean hidden) { @@ -146,8 +146,8 @@ public class ItemsCreator { log.info("item with id {} correctly created",newNode.getIdentifier()); toReturn = newNode.getIdentifier(); }catch(StorageHubException she ){ - log.error("error creating item", she); - GXOutboundErrorResponse.throwException(she); + log.error(she.getErrorMessage(), she); + GXOutboundErrorResponse.throwException(she, Response.Status.fromStatusCode(she.getStatus())); }catch(RepositoryException re ){ log.error("jcr error creating item", re); GXOutboundErrorResponse.throwException(new BackendGenericError("jcr error creating item", re)); @@ -160,7 +160,6 @@ public class ItemsCreator { } @POST - @Produces(MediaType.TEXT_PLAIN) @Consumes(MediaType.APPLICATION_JSON) @Path("/{id}/create/GCUBEITEM") public String createGcubeItem(@PathParam("id") String id, GCubeItem item) { @@ -198,8 +197,8 @@ public class ItemsCreator { log.info("item with id {} correctly created",newNode.getIdentifier()); toReturn = newNode.getIdentifier(); }catch(StorageHubException she ){ - log.error("error creating item", she); - GXOutboundErrorResponse.throwException(she); + log.error(she.getErrorMessage(), she); + GXOutboundErrorResponse.throwException(she, Response.Status.fromStatusCode(she.getStatus())); }catch(RepositoryException re ){ log.error("jcr error creating item", re); GXOutboundErrorResponse.throwException(new BackendGenericError("jcr error creating item", re)); @@ -248,8 +247,8 @@ public class ItemsCreator { log.error("jcr error creating file item", re); GXOutboundErrorResponse.throwException(new BackendGenericError("jcr error creating file item", re)); }catch(StorageHubException she ){ - log.error("error creating file item", she); - GXOutboundErrorResponse.throwException(she); + log.error(she.getErrorMessage(), she); + GXOutboundErrorResponse.throwException(she, Response.Status.fromStatusCode(she.getStatus())); }catch(Throwable e ){ log.error("unexpected error", e); GXOutboundErrorResponse.throwException(new BackendGenericError(e)); @@ -299,7 +298,6 @@ public class ItemsCreator { @POST @Consumes(MediaType.MULTIPART_FORM_DATA) - @Produces(MediaType.APPLICATION_JSON) @Path("/{id}/create/ARCHIVE") public String uploadArchive(@PathParam("id") String id, @FormDataParam("parentFolderName") String parentFolderName, @FormDataParam("file") InputStream stream, @@ -391,8 +389,8 @@ public class ItemsCreator { log.error("jcr error extracting archive", re); GXOutboundErrorResponse.throwException(new BackendGenericError("jcr error extracting archive", re)); }catch(StorageHubException she ){ - log.error("error creating file item", she); - GXOutboundErrorResponse.throwException(she); + log.error(she.getErrorMessage(), she); + GXOutboundErrorResponse.throwException(she, Response.Status.fromStatusCode(she.getStatus())); } finally{ if (ses!=null) ses.logout(); 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 c45e8bf..28d852f 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 @@ -20,6 +20,7 @@ import java.util.zip.ZipOutputStream; import javax.enterprise.context.RequestScoped; import javax.inject.Inject; +import javax.jcr.ItemNotFoundException; import javax.jcr.Node; import javax.jcr.NodeIterator; import javax.jcr.RepositoryException; @@ -38,6 +39,7 @@ import javax.ws.rs.QueryParam; import javax.ws.rs.core.Context; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; +import javax.ws.rs.core.Response.Status; import javax.ws.rs.core.StreamingOutput; import org.apache.commons.io.FilenameUtils; @@ -52,6 +54,7 @@ import org.gcube.common.storagehub.model.Excludes; import org.gcube.common.storagehub.model.NodeConstants; import org.gcube.common.storagehub.model.Paths; import org.gcube.common.storagehub.model.exceptions.BackendGenericError; +import org.gcube.common.storagehub.model.exceptions.IdNotFoundException; import org.gcube.common.storagehub.model.exceptions.InvalidCallParameters; import org.gcube.common.storagehub.model.exceptions.InvalidItemException; import org.gcube.common.storagehub.model.exceptions.StorageHubException; @@ -116,21 +119,24 @@ public class ItemsManager { @GET @Path("{id}") - @Produces(MediaType.APPLICATION_JSON) public ItemWrapper getById(@QueryParam("exclude") List excludes){ InnerMethodName.instance.set("getById"); Session ses = null; Item toReturn = null; try{ ses = repository.getRepository().login(CredentialHandler.getAdminCredentials(context)); + Node node = ses.getNodeByIdentifier(id); authChecker.checkReadAuthorizationControl(ses, id); - toReturn = node2Item.getItem(ses.getNodeByIdentifier(id), excludes); + toReturn = node2Item.getItem(node, excludes); + }catch (ItemNotFoundException e) { + log.error("id {} not found",id,e); + GXOutboundErrorResponse.throwException(new IdNotFoundException("id not found", e), Status.NOT_FOUND); }catch(RepositoryException re){ log.error("jcr error getting item", re); GXOutboundErrorResponse.throwException(new BackendGenericError("jcr error searching item", re)); }catch(StorageHubException she ){ - log.error("error getting item", she); - GXOutboundErrorResponse.throwException(she); + log.error(she.getErrorMessage(), she); + GXOutboundErrorResponse.throwException(she, Response.Status.fromStatusCode(she.getStatus())); }finally{ if (ses!=null) ses.logout(); @@ -141,7 +147,6 @@ public class ItemsManager { @GET @Path("{id}/items/{name}") - @Produces(MediaType.APPLICATION_JSON) public ItemList findChildrenByNamePattern(@QueryParam("exclude") List excludes, @PathParam("name") String name){ InnerMethodName.instance.set("findChildrenByNamePattern"); Session ses = null; @@ -166,13 +171,15 @@ public class ItemsManager { || (nodeName.equals(cleanedName) || title.equals(cleanedName))) toReturn.add(node2Item.getItem(child, excludes)); } - + }catch (ItemNotFoundException e) { + log.error("id {} not found",id,e); + GXOutboundErrorResponse.throwException(new IdNotFoundException("id not found", e), Status.NOT_FOUND); }catch(RepositoryException re){ log.error("jcr error searching item", re); GXOutboundErrorResponse.throwException(new BackendGenericError("jcr error searching item", re)); }catch(StorageHubException she ){ - log.error("error searching item", she); - GXOutboundErrorResponse.throwException(she); + log.error(she.getErrorMessage(), she); + GXOutboundErrorResponse.throwException(she, Response.Status.fromStatusCode(she.getStatus())); }finally{ if (ses!=null) ses.logout(); @@ -184,23 +191,24 @@ public class ItemsManager { @GET @Path("{id}/children/count") - @Produces(MediaType.APPLICATION_JSON) public Long countById(@QueryParam("showHidden") Boolean showHidden, @QueryParam("exclude") List excludes, @QueryParam("onlyType") String nodeType){ InnerMethodName.instance.set("countById"); Session ses = null; Long toReturn = null; try{ - ses = repository.getRepository().login(CredentialHandler.getAdminCredentials(context)); authChecker.checkReadAuthorizationControl(ses, id); toReturn = Utils.getItemCount(ses.getNodeByIdentifier(id), showHidden==null?false:showHidden, nodeType!=null ? ClassHandler.instance().get(nodeType) : null); + }catch (ItemNotFoundException e) { + log.error("id {} not found",id,e); + GXOutboundErrorResponse.throwException(new IdNotFoundException("id not found", e), Status.NOT_FOUND); }catch(RuntimeException | RepositoryException re){ log.error("jcr error counting item", re); GXOutboundErrorResponse.throwException(new BackendGenericError(re)); }catch(StorageHubException she ){ - log.error("error counting item", she); - GXOutboundErrorResponse.throwException(she); + log.error(she.getErrorMessage(), she); + GXOutboundErrorResponse.throwException(she, Response.Status.fromStatusCode(she.getStatus())); }finally{ if (ses!=null) ses.logout(); @@ -210,7 +218,6 @@ public class ItemsManager { @GET @Path("{id}/children") - @Produces(MediaType.APPLICATION_JSON) public ItemList listById(@QueryParam("showHidden") Boolean showHidden, @QueryParam("exclude") List excludes, @QueryParam("onlyType") String nodeType){ InnerMethodName.instance.set("listById"); Session ses = null; @@ -219,12 +226,15 @@ public class ItemsManager { ses = repository.getRepository().login(CredentialHandler.getAdminCredentials(context)); authChecker.checkReadAuthorizationControl(ses, id); toReturn = Utils.getItemList(ses.getNodeByIdentifier(id), excludes, null, showHidden==null?false:showHidden, nodeType!=null ? ClassHandler.instance().get(nodeType) : null); + }catch (ItemNotFoundException e) { + log.error("id {} not found",id,e); + GXOutboundErrorResponse.throwException(new IdNotFoundException("id not found", e), Status.NOT_FOUND); }catch(RepositoryException re){ log.error("jcr error getting children", re); GXOutboundErrorResponse.throwException(new BackendGenericError(re)); }catch(StorageHubException she ){ - log.error("error getting children", she); - GXOutboundErrorResponse.throwException(she); + log.error(she.getErrorMessage(), she); + GXOutboundErrorResponse.throwException(she, Response.Status.fromStatusCode(she.getStatus())); }finally{ if (ses!=null) ses.logout(); @@ -235,7 +245,6 @@ public class ItemsManager { @GET @Path("{id}/children/paged") - @Produces(MediaType.APPLICATION_JSON) public ItemList listByIdPaged(@QueryParam("showHidden") Boolean showHidden, @QueryParam("start") Integer start, @QueryParam("limit") Integer limit, @QueryParam("exclude") List excludes, @QueryParam("onlyType") String nodeType){ InnerMethodName.instance.set("listByIdPaged"); Session ses = null; @@ -244,12 +253,15 @@ public class ItemsManager { ses = repository.getRepository().login(CredentialHandler.getAdminCredentials(context)); authChecker.checkReadAuthorizationControl(ses, id); toReturn = Utils.getItemList(ses.getNodeByIdentifier(id), excludes, new Range(start, limit),showHidden==null?false:showHidden, nodeType!=null ? ClassHandler.instance().get(nodeType) : null); + }catch (ItemNotFoundException e) { + log.error("id {} not found",id,e); + GXOutboundErrorResponse.throwException(new IdNotFoundException("id not found", e), Status.NOT_FOUND); }catch(RepositoryException re){ log.error("jcr error getting paged children", re); GXOutboundErrorResponse.throwException(new BackendGenericError(re)); }catch(StorageHubException she ){ - log.error("error getting paged children", she); - GXOutboundErrorResponse.throwException(she); + log.error(she.getErrorMessage(), she); + GXOutboundErrorResponse.throwException(she, Response.Status.fromStatusCode(she.getStatus())); }finally{ if (ses!=null) ses.logout(); @@ -259,7 +271,6 @@ public class ItemsManager { } @GET - @Produces(MediaType.APPLICATION_JSON) @Path("publiclink/{id}") @AuthorizationControl(allowed={"URIResolver"}, exception=MyAuthException.class) public Response resolvePublicLink() { @@ -318,8 +329,8 @@ public class ItemsManager { log.error("jcr error getting public link", re); GXOutboundErrorResponse.throwException(new BackendGenericError(re)); }catch(StorageHubException she ){ - log.error("error getting public link", she); - GXOutboundErrorResponse.throwException(she); + log.error(she.getErrorMessage(), she); + GXOutboundErrorResponse.throwException(she, Response.Status.fromStatusCode(she.getStatus())); }finally{ if (ses!=null) ses.logout(); @@ -328,7 +339,6 @@ public class ItemsManager { } @GET - @Produces(MediaType.APPLICATION_JSON) @Path("{id}/publiclink") public URL getPublicLink(@QueryParam("version") String version) { InnerMethodName.instance.set("getPubliclink"); @@ -393,8 +403,8 @@ public class ItemsManager { log.error("jcr error getting public link", re); GXOutboundErrorResponse.throwException(new BackendGenericError(re)); }catch(StorageHubException she ){ - log.error("error getting public link", she); - GXOutboundErrorResponse.throwException(she); + log.error(she.getErrorMessage(), she); + GXOutboundErrorResponse.throwException(she, Response.Status.fromStatusCode(she.getStatus())); }finally{ if (ses!=null) ses.logout(); @@ -412,7 +422,6 @@ public class ItemsManager { @GET @Path("{id}/rootSharedFolder") - @Produces(MediaType.APPLICATION_JSON) public ItemWrapper getRootSharedFolder(@QueryParam("exclude") List excludes){ InnerMethodName.instance.set("getRootSharedFolder"); Session ses = null; @@ -434,8 +443,8 @@ public class ItemsManager { log.error("jcr error getting rootSharedFolder", re); GXOutboundErrorResponse.throwException(new BackendGenericError(re)); }catch(StorageHubException she ){ - log.error("error getting rootSharedFolder", she); - GXOutboundErrorResponse.throwException(she); + log.error(she.getErrorMessage(), she); + GXOutboundErrorResponse.throwException(she, Response.Status.fromStatusCode(she.getStatus())); }finally{ if (ses!=null) ses.logout(); @@ -455,7 +464,6 @@ public class ItemsManager { @GET @Path("{id}/versions") - @Produces(MediaType.APPLICATION_JSON) public VersionList getVersions(){ InnerMethodName.instance.set("getVersions"); Session ses = null; @@ -481,8 +489,8 @@ public class ItemsManager { log.error("jcr error retrieving versions", re); GXOutboundErrorResponse.throwException(new BackendGenericError(re)); }catch(StorageHubException she ){ - log.error("error retrieving versions", she); - GXOutboundErrorResponse.throwException(she); + log.error(she.getErrorMessage(), she); + GXOutboundErrorResponse.throwException(she, Response.Status.fromStatusCode(she.getStatus())); }finally{ if (ses!=null) ses.logout(); @@ -506,8 +514,8 @@ public class ItemsManager { log.error("jcr error downloading version", re); GXOutboundErrorResponse.throwException(new BackendGenericError(re)); }catch(StorageHubException she ){ - log.error("error downloading version", she); - GXOutboundErrorResponse.throwException(she); + log.error(she.getErrorMessage(), she); + GXOutboundErrorResponse.throwException(she, Response.Status.fromStatusCode(she.getStatus())); }finally{ if (ses!=null) ses.logout(); @@ -555,7 +563,6 @@ public class ItemsManager { @GET @Path("{id}/anchestors") - @Produces(MediaType.APPLICATION_JSON) public ItemList getAnchestors(@QueryParam("exclude") List excludes){ InnerMethodName.instance.set("getAnchestors"); org.gcube.common.storagehub.model.Path absolutePath = Utils.getWorkspacePath(); @@ -589,8 +596,8 @@ public class ItemsManager { log.error("jcr error getting anchestors", re); GXOutboundErrorResponse.throwException(new BackendGenericError(re)); }catch(StorageHubException she ){ - log.error("error getting anchestors", she); - GXOutboundErrorResponse.throwException(she); + log.error(she.getErrorMessage(), she); + GXOutboundErrorResponse.throwException(she, Response.Status.fromStatusCode(she.getStatus())); }finally{ if (ses!=null) ses.logout(); @@ -658,8 +665,8 @@ public class ItemsManager { log.error("jcr error download", re); GXOutboundErrorResponse.throwException(new BackendGenericError(re)); }catch(StorageHubException she ){ - log.error("error download", she); - GXOutboundErrorResponse.throwException(she); + log.error(she.getErrorMessage(), she); + GXOutboundErrorResponse.throwException(she, Response.Status.fromStatusCode(she.getStatus())); } finally{ if (ses!=null) ses.logout(); } @@ -746,8 +753,8 @@ public class ItemsManager { log.error("jcr error moving item", re); GXOutboundErrorResponse.throwException(new BackendGenericError(re)); }catch(StorageHubException she ){ - log.error("error moving item", she); - GXOutboundErrorResponse.throwException(she); + log.error(she.getErrorMessage(), she); + GXOutboundErrorResponse.throwException(she, Response.Status.fromStatusCode(she.getStatus())); } finally{ if (ses!=null) { ses.logout(); @@ -820,9 +827,9 @@ public class ItemsManager { log.error("jcr error moving item", re); GXOutboundErrorResponse.throwException(new BackendGenericError(re)); }catch(StorageHubException she ){ - log.error("error moving item", she); - GXOutboundErrorResponse.throwException(she); - } finally{ + log.error(she.getErrorMessage(), she); + GXOutboundErrorResponse.throwException(she, Response.Status.fromStatusCode(she.getStatus())); + }finally{ if (ses!=null) { ses.logout(); } @@ -875,9 +882,9 @@ public class ItemsManager { log.error("jcr error moving item", re); GXOutboundErrorResponse.throwException(new BackendGenericError(re)); }catch(StorageHubException she ){ - log.error("error moving item", she); - GXOutboundErrorResponse.throwException(she); - } finally{ + log.error(she.getErrorMessage(), she); + GXOutboundErrorResponse.throwException(she, Response.Status.fromStatusCode(she.getStatus())); + }finally{ if (ses!=null) { ses.logout(); } @@ -917,9 +924,9 @@ public class ItemsManager { log.error("jcr error moving item", re); GXOutboundErrorResponse.throwException(new BackendGenericError(re)); }catch(StorageHubException she ){ - log.error("error moving item", she); - GXOutboundErrorResponse.throwException(she); - } finally{ + log.error(she.getErrorMessage(), she); + GXOutboundErrorResponse.throwException(she, Response.Status.fromStatusCode(she.getStatus())); + }finally{ if (ses!=null) { ses.logout(); } @@ -964,9 +971,9 @@ public class ItemsManager { log.error("jcr error moving item", re); GXOutboundErrorResponse.throwException(new BackendGenericError(re)); }catch(StorageHubException she ){ - log.error("error moving item", she); - GXOutboundErrorResponse.throwException(she); - } finally{ + log.error(she.getErrorMessage(), she); + GXOutboundErrorResponse.throwException(she, Response.Status.fromStatusCode(she.getStatus())); + }finally{ if (ses!=null) { ses.logout(); } diff --git a/src/main/java/org/gcube/data/access/storagehub/services/UserManager.java b/src/main/java/org/gcube/data/access/storagehub/services/UserManager.java index 59c902b..3c8ce2f 100644 --- a/src/main/java/org/gcube/data/access/storagehub/services/UserManager.java +++ b/src/main/java/org/gcube/data/access/storagehub/services/UserManager.java @@ -50,7 +50,7 @@ public class UserManager { @Inject UnshareHandler unshareHandler; - + @GET @Path("") @Produces(MediaType.APPLICATION_JSON) @@ -99,17 +99,17 @@ public class UserManager { User createdUser = usrManager.createUser(user, password); userId = createdUser.getID(); - + Node homeNode = session.getNode("/Home"); Node userHome = homeNode.addNode(user, "nthl:home"); - + //creating workspace folder Node workspaceFolder = Utils.createFolderInternally(session, userHome, Constants.WORKSPACE_ROOT_FOLDER_NAME, "workspace of "+user, false, user, null); //creating thrash folder Utils.createFolderInternally(session, workspaceFolder, Constants.TRASH_ROOT_FOLDER_NAME, "trash of "+user, false, user, null); //creating Vre container folder Utils.createFolderInternally(session, workspaceFolder, Constants.VRE_FOLDER_PARENT_NAME, "special folder container of "+user, false, user, null); - + session.save(); }catch(Exception e) { log.error("jcr error creating user {}", user, e); @@ -118,10 +118,11 @@ public class UserManager { if (session!=null) session.logout(); } - + return userId; } - + + @DELETE @Path("{id}") @AuthorizationControl(allowed={"lucio.lelii"}, exception=MyAuthException.class) @@ -133,17 +134,17 @@ public class UserManager { session = (JackrabbitSession) repository.getRepository().login(CredentialHandler.getAdminCredentials(context)); org.apache.jackrabbit.api.security.user.UserManager usrManager = session.getUserManager(); - + org.gcube.common.storagehub.model.Path path = Utils.getWorkspacePath(id); - - + + String sql2Query = String.format("SELECT * FROM [nthl:workspaceSharedItem] AS node WHERE ISDESCENDANTNODE('%s')", path.toPath()); log.info("query sent is {}",sql2Query); - + javax.jcr.query.Query jcrQuery = session.getWorkspace().getQueryManager().createQuery(sql2Query, Constants.QUERY_LANGUAGE); - + QueryResult result = jcrQuery.execute(); NodeIterator nodeIt = result.getNodes(); while (nodeIt.hasNext()) { @@ -152,7 +153,7 @@ public class UserManager { log.debug("removing sharing for folder name {} with title {} and path {} ",rNode.getName(), title, rNode.getPath()); unshareHandler.unshare(session, Collections.singleton(id), rNode, id); } - + Authorizable authorizable = usrManager.getAuthorizable(new PrincipalImpl(id)); if (!authorizable.isGroup()) { log.info("removing user {}", id); @@ -166,7 +167,7 @@ public class UserManager { if (session!=null) session.logout(); } - + return userId; } diff --git a/src/main/java/org/gcube/data/access/storagehub/services/WorkspaceManager.java b/src/main/java/org/gcube/data/access/storagehub/services/WorkspaceManager.java index 605a864..f0d1b00 100644 --- a/src/main/java/org/gcube/data/access/storagehub/services/WorkspaceManager.java +++ b/src/main/java/org/gcube/data/access/storagehub/services/WorkspaceManager.java @@ -23,6 +23,7 @@ import javax.ws.rs.Path; import javax.ws.rs.Produces; import javax.ws.rs.QueryParam; import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; import org.gcube.common.authorization.library.provider.AuthorizationProvider; import org.gcube.common.gxrest.response.outbound.GXOutboundErrorResponse; @@ -92,7 +93,6 @@ public class WorkspaceManager { @Path("") @GET - @Produces(MediaType.APPLICATION_JSON) public ItemWrapper getWorkspace(@QueryParam("relPath") String relPath){ InnerMethodName.instance.set("getWorkspace"); Session ses = null; @@ -121,8 +121,8 @@ public class WorkspaceManager { log.error("jcr error getting workspace item", re); GXOutboundErrorResponse.throwException(new BackendGenericError(re)); }catch(StorageHubException she ){ - log.error("error getting workspace item", she); - GXOutboundErrorResponse.throwException(she); + log.error(she.getErrorMessage(), she); + GXOutboundErrorResponse.throwException(she, Response.Status.fromStatusCode(she.getStatus())); }finally{ if (ses!=null) ses.logout(); @@ -155,7 +155,6 @@ public class WorkspaceManager { @Path("vrefolder") @GET - @Produces(MediaType.APPLICATION_JSON) public ItemWrapper getVreRootFolder(){ InnerMethodName.instance.set("getVreRootFolder"); Session ses = null; @@ -167,8 +166,8 @@ public class WorkspaceManager { log.error("jcr error getting vrefolder", re); GXOutboundErrorResponse.throwException(new BackendGenericError(re)); }catch(StorageHubException she ){ - log.error("error getting vrefolder", she); - GXOutboundErrorResponse.throwException(she); + log.error(she.getErrorMessage(), she); + GXOutboundErrorResponse.throwException(she, Response.Status.fromStatusCode(she.getStatus())); }finally{ if (ses!=null) ses.logout(); @@ -178,7 +177,6 @@ public class WorkspaceManager { @Path("vrefolder/recents") @GET - @Produces(MediaType.APPLICATION_JSON) public ItemList getVreFolderRecentsDocument(){ InnerMethodName.instance.set("getVreFolderRecents"); Session ses = null; @@ -196,8 +194,8 @@ public class WorkspaceManager { log.error("jcr error getting recents", re); GXOutboundErrorResponse.throwException(new BackendGenericError(re)); }catch(StorageHubException she ){ - log.error("error getting recents", she); - GXOutboundErrorResponse.throwException(she); + log.error(she.getErrorMessage(), she); + GXOutboundErrorResponse.throwException(she, Response.Status.fromStatusCode(she.getStatus())); }finally{ if (ses!=null) ses.logout(); @@ -211,7 +209,6 @@ public class WorkspaceManager { @Path("trash") @GET - @Produces(MediaType.APPLICATION_JSON) public ItemWrapper getTrashRootFolder(){ InnerMethodName.instance.set("getTrashRootFolder"); Session ses = null; @@ -229,8 +226,8 @@ public class WorkspaceManager { log.error("jcr error getting trash", re); GXOutboundErrorResponse.throwException(new BackendGenericError(re)); }catch(StorageHubException she ){ - log.error("error getting trash", she); - GXOutboundErrorResponse.throwException(she); + log.error(she.getErrorMessage(), she); + GXOutboundErrorResponse.throwException(she, Response.Status.fromStatusCode(she.getStatus())); }finally{ if (ses!=null) ses.logout(); @@ -257,8 +254,8 @@ public class WorkspaceManager { log.error("jcr error emptying trash", re); GXOutboundErrorResponse.throwException(new BackendGenericError(re)); }catch(StorageHubException she ){ - log.error("error emptying trash", she); - GXOutboundErrorResponse.throwException(she); + log.error(she.getErrorMessage(), she); + GXOutboundErrorResponse.throwException(she, Response.Status.fromStatusCode(she.getStatus())); }finally{ if (ses!=null) ses.logout(); @@ -296,9 +293,9 @@ public class WorkspaceManager { log.error("error restoring item with id {}",identifier, re); GXOutboundErrorResponse.throwException(new BackendGenericError(re)); }catch(StorageHubException she ){ - log.error("error restoring item with id {}",identifier, she); - GXOutboundErrorResponse.throwException(she); - } finally{ + log.error(she.getErrorMessage(), she); + GXOutboundErrorResponse.throwException(she, Response.Status.fromStatusCode(she.getStatus())); + }finally{ if (ses!=null) { ses.logout(); } @@ -310,7 +307,6 @@ public class WorkspaceManager { @Path("vrefolders") @GET - @Produces(MediaType.APPLICATION_JSON) public ItemList getVreFolders(){ InnerMethodName.instance.set("getVreFolders"); Session ses = null; @@ -325,8 +321,8 @@ public class WorkspaceManager { log.error("error reading the node children of {}",vrePath, re); GXOutboundErrorResponse.throwException(new BackendGenericError(re)); }catch(StorageHubException she ){ - log.error("error reading the node children of {}",vrePath, she); - GXOutboundErrorResponse.throwException(she); + log.error(she.getErrorMessage(), she); + GXOutboundErrorResponse.throwException(she, Response.Status.fromStatusCode(she.getStatus())); }finally{ if (ses!=null) ses.logout(); @@ -337,7 +333,6 @@ public class WorkspaceManager { @Path("vrefolders/paged") @GET - @Produces(MediaType.APPLICATION_JSON) public ItemList getVreFoldersPaged(@QueryParam("start") Integer start, @QueryParam("limit") Integer limit){ InnerMethodName.instance.set("getVreFoldersPaged"); Session ses = null; @@ -350,8 +345,8 @@ public class WorkspaceManager { log.error("(paged) error reading the node children of {}",vrePath, re); GXOutboundErrorResponse.throwException(new BackendGenericError(re)); }catch(StorageHubException she ){ - log.error("(paged) error reading the node children of {}",vrePath, she); - GXOutboundErrorResponse.throwException(she); + log.error(she.getErrorMessage(), she); + GXOutboundErrorResponse.throwException(she, Response.Status.fromStatusCode(she.getStatus())); }finally{ if (ses!=null) ses.logout(); @@ -364,7 +359,6 @@ public class WorkspaceManager { @Path("query") @GET - @Produces(MediaType.APPLICATION_JSON) public ItemList searchItems(@QueryParam("n") String node, @QueryParam("e") String jsonExpr, @QueryParam("o") List orderField, @QueryParam("l") Integer limit, @QueryParam("f") Integer offset){ InnerMethodName.instance.set("searchItems"); Session ses = null; @@ -405,8 +399,8 @@ public class WorkspaceManager { log.error("error executing the query", re); GXOutboundErrorResponse.throwException(new BackendGenericError(re)); }catch(StorageHubException she ){ - log.error("error executing the query", she); - GXOutboundErrorResponse.throwException(she); + log.error(she.getErrorMessage(), she); + GXOutboundErrorResponse.throwException(she, Response.Status.fromStatusCode(she.getStatus())); }finally{ if (ses!=null) ses.logout(); diff --git a/src/test/resources/META-INF/beans.xml b/src/test/resources/META-INF/beans.xml index 7c7e8db..7e968ba 100644 --- a/src/test/resources/META-INF/beans.xml +++ b/src/test/resources/META-INF/beans.xml @@ -1,5 +1,4 @@ + xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee/beans_1_1.xsd"> \ No newline at end of file