Skip to content

Commit

Permalink
Merge pull request #1 from LongsightGroup/rest-crud-cz
Browse files Browse the repository at this point in the history
Quick fixes for REST Read endpoints
  • Loading branch information
ctu-developers committed Oct 7, 2014
2 parents 52469fb + 6b83de1 commit 12b83b3
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 85 deletions.
19 changes: 7 additions & 12 deletions dspace-rest/src/main/java/org/dspace/rest/BitstreamResource.java
Expand Up @@ -37,7 +37,6 @@
import org.dspace.authorize.AuthorizeManager;
import org.dspace.content.BitstreamFormat;
import org.dspace.content.Bundle;
import org.dspace.core.Constants;
import org.dspace.eperson.Group;
import org.dspace.rest.common.Bitstream;
import org.dspace.rest.common.ResourcePolicy;
Expand Down Expand Up @@ -101,7 +100,7 @@ public Bitstream getBitstream(@PathParam("bitstream_id") Integer bitstreamId, @Q
context = createContext(getUser(headers));
org.dspace.content.Bitstream dspaceBitstream = findBitstream(context, bitstreamId, org.dspace.core.Constants.READ);

writeStats(Constants.BITSTREAM, dspaceBitstream, UsageEvent.Action.VIEW, user_ip, user_agent, xforwarderfor, headers,
writeStats(dspaceBitstream, UsageEvent.Action.VIEW, user_ip, user_agent, xforwarderfor, headers,
request);

bitstream = new Bitstream(dspaceBitstream, expand);
Expand Down Expand Up @@ -241,7 +240,7 @@ public Bitstream[] getBitstreams(@QueryParam("expand") String expand,
{ // To eliminate bitstreams which cause exception, because of
// reading under administrator permissions
bitstreams.add(new Bitstream(dspaceBitstreams[i], expand));
writeStats(Constants.BITSTREAM, dspaceBitstreams[i], UsageEvent.Action.VIEW, user_ip, user_agent,
writeStats(dspaceBitstreams[i], UsageEvent.Action.VIEW, user_ip, user_agent,
xforwarderfor, headers, request);
}
}
Expand Down Expand Up @@ -290,7 +289,7 @@ public Bitstream[] getBitstreams(@QueryParam("expand") String expand,
* data. Or was problem with database reading. Or was problem
* with creating context. Or problem with authorization.
*/
@POST
@GET
@Path("/{bitstream_id}/retrieve")
public javax.ws.rs.core.Response getBitstreamData(@PathParam("bitstream_id") Integer bitstreamId,
@QueryParam("userIP") String user_ip, @QueryParam("userAgent") String user_agent,
Expand All @@ -306,7 +305,7 @@ public javax.ws.rs.core.Response getBitstreamData(@PathParam("bitstream_id") Int
context = createContext(getUser(headers));
org.dspace.content.Bitstream dspaceBitstream = findBitstream(context, bitstreamId, org.dspace.core.Constants.READ);

writeStats(Constants.BITSTREAM, dspaceBitstream, UsageEvent.Action.VIEW, user_ip, user_agent, xforwarderfor, headers,
writeStats(dspaceBitstream, UsageEvent.Action.VIEW, user_ip, user_agent, xforwarderfor, headers,
request);

log.trace("Bitsream(id=" + bitstreamId + ") data was successfully read.");
Expand Down Expand Up @@ -464,7 +463,7 @@ public Response updateBitstream(@PathParam("bitstream_id") Integer bitstreamId,
context = createContext(getUser(headers));
org.dspace.content.Bitstream dspaceBitstream = findBitstream(context, bitstreamId, org.dspace.core.Constants.WRITE);

writeStats(Constants.BITSTREAM, dspaceBitstream, UsageEvent.Action.UPDATE, user_ip, user_agent, xforwarderfor,
writeStats(dspaceBitstream, UsageEvent.Action.UPDATE, user_ip, user_agent, xforwarderfor,
headers, request);

log.trace("Updating bitstream metadata.");
Expand Down Expand Up @@ -595,7 +594,7 @@ public Response updateBitstreamData(@PathParam("bitstream_id") Integer bitstream
context = createContext(getUser(headers));
org.dspace.content.Bitstream dspaceBitstream = findBitstream(context, bitstreamId, org.dspace.core.Constants.WRITE);

writeStats(Constants.BITSTREAM, dspaceBitstream, UsageEvent.Action.UPDATE, user_ip, user_agent, xforwarderfor,
writeStats(dspaceBitstream, UsageEvent.Action.UPDATE, user_ip, user_agent, xforwarderfor,
headers, request);

log.trace("Creating new bitstream.");
Expand Down Expand Up @@ -679,7 +678,7 @@ public Response deleteBitstream(@PathParam("bitstream_id") Integer bitstreamId,
context = createContext(getUser(headers));
org.dspace.content.Bitstream dspaceBitstream = findBitstream(context, bitstreamId, org.dspace.core.Constants.DELETE);

writeStats(Constants.BITSTREAM, dspaceBitstream, UsageEvent.Action.DELETE, user_ip, user_agent, xforwarderfor,
writeStats(dspaceBitstream, UsageEvent.Action.DELETE, user_ip, user_agent, xforwarderfor,
headers, request);

log.trace("Deleting bitstream from all bundles.");
Expand Down Expand Up @@ -851,10 +850,6 @@ else if (!AuthorizeManager.authorizeActionBoolean(context, bitstream, action))
{
processException("Something get wrong while finding bitstream. SQLException, Message:" + e, context);
}
finally
{
context.abort();
}
return bitstream;
}
}
23 changes: 9 additions & 14 deletions dspace-rest/src/main/java/org/dspace/rest/CollectionsResource.java
Expand Up @@ -33,7 +33,6 @@
import org.dspace.authorize.AuthorizeException;
import org.dspace.authorize.AuthorizeManager;
import org.dspace.browse.BrowseException;
import org.dspace.core.Constants;
import org.dspace.rest.common.Collection;
import org.dspace.rest.common.Item;
import org.dspace.rest.common.MetadataEntry;
Expand Down Expand Up @@ -99,7 +98,7 @@ public org.dspace.rest.common.Collection getCollection(@PathParam("collection_id
context = createContext(getUser(headers));

org.dspace.content.Collection dspaceCollection = findCollection(context, collectionId, org.dspace.core.Constants.READ);
writeStats(Constants.COLLECTION, dspaceCollection, UsageEvent.Action.VIEW, user_ip, user_agent, xforwarderfor,
writeStats(dspaceCollection, UsageEvent.Action.VIEW, user_ip, user_agent, xforwarderfor,
headers, request);

collection = new Collection(dspaceCollection, expand, context, limit, offset);
Expand Down Expand Up @@ -187,7 +186,7 @@ public org.dspace.rest.common.Collection[] getCollections(@QueryParam("expand")
Collection collection = new org.dspace.rest.common.Collection(dspaceCollections[i], null, context, limit,
offset);
collections.add(collection);
writeStats(Constants.COLLECTION, dspaceCollections[i], UsageEvent.Action.VIEW, user_ip, user_agent,
writeStats(dspaceCollections[i], UsageEvent.Action.VIEW, user_ip, user_agent,
xforwarderfor, headers, request);
}
}
Expand Down Expand Up @@ -260,7 +259,7 @@ public org.dspace.rest.common.Item[] getCollectionItems(@PathParam("collection_i
context = createContext(getUser(headers));

org.dspace.content.Collection dspaceCollection = findCollection(context, collectionId, org.dspace.core.Constants.READ);
writeStats(Constants.COLLECTION, dspaceCollection, UsageEvent.Action.VIEW, user_ip, user_agent, xforwarderfor,
writeStats(dspaceCollection, UsageEvent.Action.VIEW, user_ip, user_agent, xforwarderfor,
headers, request);

List<Item> items = new ArrayList<Item>();
Expand All @@ -273,7 +272,7 @@ public org.dspace.rest.common.Item[] getCollectionItems(@PathParam("collection_i
if (AuthorizeManager.authorizeActionBoolean(context, dspaceItem, org.dspace.core.Constants.READ))
{
items.add(new Item(dspaceItem, expand, context));
writeStats(Constants.ITEM, dspaceItem, UsageEvent.Action.VIEW, user_ip, user_agent, xforwarderfor,
writeStats(dspaceItem, UsageEvent.Action.VIEW, user_ip, user_agent, xforwarderfor,
headers, request);
}
}
Expand Down Expand Up @@ -343,7 +342,7 @@ public Item addCollectionItem(@PathParam("collection_id") Integer collectionId,
org.dspace.content.Collection dspaceCollection = findCollection(context, collectionId,
org.dspace.core.Constants.WRITE);

writeStats(Constants.COLLECTION, dspaceCollection, UsageEvent.Action.UPDATE, user_ip, user_agent, xforwarderfor,
writeStats(dspaceCollection, UsageEvent.Action.UPDATE, user_ip, user_agent, xforwarderfor,
headers, request);

log.trace("Creating item in collection(id=" + collectionId + ").");
Expand Down Expand Up @@ -443,7 +442,7 @@ public Response updateCollection(@PathParam("collection_id") Integer collectionI
org.dspace.content.Collection dspaceCollection = findCollection(context, collectionId,
org.dspace.core.Constants.WRITE);

writeStats(Constants.COLLECTION, dspaceCollection, UsageEvent.Action.UPDATE, user_ip, user_agent, xforwarderfor,
writeStats(dspaceCollection, UsageEvent.Action.UPDATE, user_ip, user_agent, xforwarderfor,
headers, request);

dspaceCollection.setMetadata("name", collection.getName());
Expand Down Expand Up @@ -515,7 +514,7 @@ public Response deleteCollection(@PathParam("collection_id") Integer collectionI
org.dspace.content.Collection dspaceCollection = findCollection(context, collectionId,
org.dspace.core.Constants.DELETE);

writeStats(Constants.COLLECTION, dspaceCollection, UsageEvent.Action.REMOVE, user_ip, user_agent, xforwarderfor,
writeStats(dspaceCollection, UsageEvent.Action.REMOVE, user_ip, user_agent, xforwarderfor,
headers, request);

org.dspace.content.Community community = (org.dspace.content.Community) dspaceCollection.getParentObject();
Expand Down Expand Up @@ -618,9 +617,9 @@ else if (!AuthorizeManager.authorizeActionBoolean(context, item, org.dspace.core
throw new WebApplicationException(Response.Status.UNAUTHORIZED);
}

writeStats(Constants.COLLECTION, dspaceCollection, UsageEvent.Action.UPDATE, user_ip, user_agent, xforwarderfor,
writeStats(dspaceCollection, UsageEvent.Action.UPDATE, user_ip, user_agent, xforwarderfor,
headers, request);
writeStats(Constants.ITEM, item, UsageEvent.Action.REMOVE, user_ip, user_agent, xforwarderfor, headers, request);
writeStats(item, UsageEvent.Action.REMOVE, user_ip, user_agent, xforwarderfor, headers, request);

dspaceCollection.removeItem(item);

Expand Down Expand Up @@ -777,10 +776,6 @@ else if (!AuthorizeManager.authorizeActionBoolean(context, collection, action))
{
processException("Something get wrong while finding collection(id=" + id + "). SQLException, Message: " + e, context);
}
finally
{
context.abort();
}
return collection;
}
}

0 comments on commit 12b83b3

Please sign in to comment.