Commit 75a6c5a283bc23a2e50a6acf8235652f4f6af7cb

Authored by Fernando Ribeiro
1 parent d5be0aa3af

DS-2936 REST-API /handle endpoint broken

DS-2946	Missing DSpaceWebapp in dspace-rest module
dspace-rest/src/main/java/org/dspace/rest/HandleResource.java
... ... @@ -34,7 +34,7 @@ import java.sql.SQLException;
34 34 @Path("/handle")
35 35 public class HandleResource extends Resource {
36 36 private static Logger log = Logger.getLogger(HandleResource.class);
37   - private static org.dspace.core.Context context;
  37 + //private static org.dspace.core.Context context;
38 38  
39 39 @GET
40 40 @Path("/{prefix}/{suffix}")
... ... @@ -42,7 +42,10 @@ public class HandleResource extends Resource {
42 42 public org.dspace.rest.common.DSpaceObject getObject(@PathParam("prefix") String prefix,
43 43 @PathParam("suffix") String suffix, @QueryParam("expand") String expand,
44 44 @Context HttpHeaders headers) throws WebApplicationException{
  45 +
45 46 org.dspace.core.Context context = null;
  47 + DSpaceObject result = null;
  48 +
46 49 try {
47 50 context = createContext(getUser(headers));
48 51  
... ... @@ -55,17 +58,23 @@ public class HandleResource extends Resource {
55 58 if(AuthorizeManager.authorizeActionBoolean(context, dso, org.dspace.core.Constants.READ)) {
56 59 switch(dso.getType()) {
57 60 case Constants.COMMUNITY:
58   - return new Community((org.dspace.content.Community) dso, expand, context);
  61 + result = new Community((org.dspace.content.Community) dso, expand, context);
  62 + break;
59 63 case Constants.COLLECTION:
60   - return new Collection((org.dspace.content.Collection) dso, expand, context, null, null);
  64 + result = new Collection((org.dspace.content.Collection) dso, expand, context, null, null);
  65 + break;
61 66 case Constants.ITEM:
62   - return new Item((org.dspace.content.Item) dso, expand, context);
  67 + result = new Item((org.dspace.content.Item) dso, expand, context);
  68 + break;
63 69 default:
64   - return new DSpaceObject(dso);
  70 + result = new DSpaceObject(dso);
65 71 }
66 72 } else {
67 73 throw new WebApplicationException(Response.Status.UNAUTHORIZED);
68 74 }
  75 +
  76 + context.complete();
  77 +
69 78 } catch (SQLException e) {
70 79 processException("Could not read handle(" + prefix + "/" + suffix + "), SQLException. Message: " + e.getMessage(), context);
71 80 } catch (ContextException e) {
... ... @@ -74,6 +83,6 @@ public class HandleResource extends Resource {
74 83 processFinally(context);
75 84 }
76 85  
77   - return null;
  86 + return result;
78 87 }
79 88 }
... ...
dspace-rest/src/main/java/org/dspace/utils/DSpaceWebapp.java
... ... @@ -0,0 +1,31 @@
  1 +/**
  2 + * The contents of this file are subject to the license and copyright
  3 + * detailed in the LICENSE and NOTICE files at the root of the source
  4 + * tree and available online at
  5 + *
  6 + * http://www.dspace.org/license/
  7 + */
  8 +
  9 +package org.dspace.utils;
  10 +
  11 +import org.dspace.app.util.AbstractDSpaceWebapp;
  12 +
  13 +/**
  14 + * An MBean to identify this web application.
  15 + *
  16 + * @author Bram Luyten <bram@atmire.com>
  17 + */
  18 +public class DSpaceWebapp
  19 + extends AbstractDSpaceWebapp
  20 +{
  21 + public DSpaceWebapp()
  22 + {
  23 + super("REST");
  24 + }
  25 +
  26 + @Override
  27 + public boolean isUI()
  28 + {
  29 + return false;
  30 + }
  31 +}
... ...