Merge branch 'akotynski-DS-2784-jersey2'

This commit is contained in:
Peter Dietz
2016-02-02 12:43:38 -05:00
25 changed files with 149 additions and 146 deletions

View File

@@ -48,22 +48,21 @@
<dependencies>
<!-- Jersey, for RESTful web services -->
<dependency>
<groupId>com.sun.jersey</groupId>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-server</artifactId>
<version>1.17.1</version>
<version>2.22.1</version>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-servlet</artifactId>
<version>1.17.1</version>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet</artifactId>
<version>2.22.1</version>
</dependency>
<!-- JSON serialization, should I use jackson?-->
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-json</artifactId>
<version>1.17.1</version>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-json-jackson</artifactId>
<version>2.22.1</version>
</dependency>
<!-- Spring 3 dependencies -->
<dependency>
<groupId>org.springframework</groupId>
@@ -82,9 +81,9 @@
<!-- Jersey + Spring -->
<dependency>
<groupId>com.sun.jersey.contribs</groupId>
<artifactId>jersey-spring</artifactId>
<version>1.8</version>
<groupId>org.glassfish.jersey.ext</groupId>
<artifactId>jersey-spring3</artifactId>
<version>2.22.1</version>
<exclusions>
<exclusion>
<groupId>org.springframework</groupId>

View File

@@ -116,7 +116,7 @@ public class BitstreamResource extends Resource
writeStats(dspaceBitstream, UsageEvent.Action.VIEW, user_ip, user_agent, xforwardedfor, headers,
request, context);
bitstream = new Bitstream(dspaceBitstream, expand, context);
bitstream = new Bitstream(dspaceBitstream, servletContext, expand, context);
context.complete();
log.trace("Bitsream(id=" + bitstreamId + ") was successfully read.");
@@ -165,7 +165,7 @@ public class BitstreamResource extends Resource
{
context = createContext(getUser(headers));
org.dspace.content.Bitstream dspaceBitstream = findBitstream(context, bitstreamId, org.dspace.core.Constants.READ);
policies = new Bitstream(dspaceBitstream,"policies", context).getPolicies();
policies = new Bitstream(dspaceBitstream, servletContext, "policies", context).getPolicies();
context.complete();
log.trace("Policies for bitstream(id=" + bitstreamId + ") was successfully read.");
@@ -241,7 +241,7 @@ public class BitstreamResource extends Resource
if (bitstreamService.getParentObject(context, dspaceBitstreams.get(i)) != null)
{ // To eliminate bitstreams which cause exception, because of
// reading under administrator permissions
bitstreams.add(new Bitstream(dspaceBitstreams.get(i), expand, context));
bitstreams.add(new Bitstream(dspaceBitstreams.get(i), servletContext, expand, context));
writeStats(dspaceBitstreams.get(i), UsageEvent.Action.VIEW, user_ip, user_agent,
xforwardedfor, headers, request, context);
}

View File

@@ -115,7 +115,7 @@ public class CollectionsResource extends Resource
writeStats(dspaceCollection, UsageEvent.Action.VIEW, user_ip, user_agent, xforwardedfor,
headers, request, context);
collection = new Collection(dspaceCollection, expand, context, limit, offset);
collection = new Collection(dspaceCollection, servletContext, expand, context, limit, offset);
context.complete();
}
@@ -192,7 +192,7 @@ public class CollectionsResource extends Resource
{
if (authorizeService.authorizeActionBoolean(context, dspaceCollection, org.dspace.core.Constants.READ))
{
Collection collection = new org.dspace.rest.common.Collection(dspaceCollection, null, context, limit,
Collection collection = new org.dspace.rest.common.Collection(dspaceCollection, servletContext, null, context, limit,
offset);
collections.add(collection);
writeStats(dspaceCollection, UsageEvent.Action.VIEW, user_ip, user_agent,
@@ -280,7 +280,7 @@ public class CollectionsResource extends Resource
{
if (itemService.isItemListedForUser(context, dspaceItem))
{
items.add(new Item(dspaceItem, expand, context));
items.add(new Item(dspaceItem, servletContext, expand, context));
writeStats(dspaceItem, UsageEvent.Action.VIEW, user_ip, user_agent, xforwardedfor,
headers, request, context);
}
@@ -374,7 +374,7 @@ public class CollectionsResource extends Resource
dspaceItem = installItemService.installItem(context, workspaceItem);
workspaceItemService.update(context, workspaceItem);
returnItem = new Item(dspaceItem, "", context);
returnItem = new Item(dspaceItem, servletContext, "", context);
context.complete();
@@ -687,7 +687,7 @@ public class CollectionsResource extends Resource
{
if (dspaceCollection.getName().equals(name))
{
collection = new Collection(dspaceCollection, "", context, 100, 0);
collection = new Collection(dspaceCollection, servletContext, "", context, 100, 0);
break;
}
}
@@ -717,7 +717,7 @@ public class CollectionsResource extends Resource
}
else
{
log.info("Collection was found with id(" + collection.getId() + ").");
log.info("Collection was found with id(" + collection.getUUID() + ").");
}
return collection;
}

View File

@@ -88,7 +88,7 @@ public class CommunitiesResource extends Resource
writeStats(dspaceCommunity, UsageEvent.Action.VIEW, user_ip, user_agent, xforwardedfor, headers,
request, context);
community = new Community(dspaceCommunity, expand, context);
community = new Community(dspaceCommunity, servletContext, expand, context);
context.complete();
}
@@ -164,7 +164,7 @@ public class CommunitiesResource extends Resource
{
if (authorizeService.authorizeActionBoolean(context, dspaceCommunities.get(i), org.dspace.core.Constants.READ))
{
Community community = new Community(dspaceCommunities.get(i), expand, context);
Community community = new Community(dspaceCommunities.get(i), servletContext, expand, context);
writeStats(dspaceCommunities.get(i), UsageEvent.Action.VIEW, user_ip, user_agent,
xforwardedfor, headers, request, context);
communities.add(community);
@@ -246,7 +246,7 @@ public class CommunitiesResource extends Resource
{
if (authorizeService.authorizeActionBoolean(context, dspaceCommunities.get(i), org.dspace.core.Constants.READ))
{
Community community = new Community(dspaceCommunities.get(i), expand, context);
Community community = new Community(dspaceCommunities.get(i), servletContext, expand, context);
writeStats(dspaceCommunities.get(i), UsageEvent.Action.VIEW, user_ip, user_agent,
xforwardedfor, headers, request, context);
communities.add(community);
@@ -331,7 +331,7 @@ public class CommunitiesResource extends Resource
{
if (authorizeService.authorizeActionBoolean(context, dspaceCollections.get(i), org.dspace.core.Constants.READ))
{
collections.add(new Collection(dspaceCollections.get(i), expand, context, 20, 0));
collections.add(new Collection(dspaceCollections.get(i), servletContext, expand, context, 20, 0));
writeStats(dspaceCollections.get(i), UsageEvent.Action.VIEW, user_ip, user_agent,
xforwardedfor, headers, request, context);
}
@@ -417,7 +417,7 @@ public class CommunitiesResource extends Resource
{
if (authorizeService.authorizeActionBoolean(context, dspaceCommunities.get(i), org.dspace.core.Constants.READ))
{
communities.add(new Community(dspaceCommunities.get(i), expand, context));
communities.add(new Community(dspaceCommunities.get(i), servletContext, expand, context));
writeStats(dspaceCommunities.get(i), UsageEvent.Action.VIEW, user_ip, user_agent,
xforwardedfor, headers, request, context);
}
@@ -498,7 +498,7 @@ public class CommunitiesResource extends Resource
communityService.setMetadata(context, dspaceCommunity, org.dspace.content.Community.SIDEBAR_TEXT, community.getSidebarText());
communityService.update(context, dspaceCommunity);
retCommunity = new Community(dspaceCommunity, "", context);
retCommunity = new Community(dspaceCommunity, servletContext, "", context);
context.complete();
}
catch (SQLException e)
@@ -572,7 +572,7 @@ public class CommunitiesResource extends Resource
collectionService.setMetadata(context, dspaceCollection, org.dspace.content.Collection.SIDEBAR_TEXT, collection.getSidebarText());
collectionService.update(context, dspaceCollection);
communityService.update(context, dspaceCommunity);
retCollection = new Collection(dspaceCollection, "", context, 100, 0);
retCollection = new Collection(dspaceCollection, servletContext, "", context, 100, 0);
context.complete();
}
@@ -654,7 +654,7 @@ public class CommunitiesResource extends Resource
communityService.update(context, dspaceCommunity);
communityService.update(context, dspaceParentCommunity);
retCommunity = new Community(dspaceCommunity, "", context);
retCommunity = new Community(dspaceCommunity, servletContext, "", context);
context.complete();
}

View File

@@ -0,0 +1,20 @@
/**
* The contents of this file are subject to the license and copyright
* detailed in the LICENSE and NOTICE files at the root of the source
* tree and available online at
*
* http://www.dspace.org/license/
*/
package org.dspace.rest;
import org.glassfish.jersey.jackson.JacksonFeature;
import org.glassfish.jersey.server.ResourceConfig;
import org.springframework.web.filter.RequestContextFilter;
public class DSpaceRestApplication extends ResourceConfig {
public DSpaceRestApplication() {
register(JacksonFeature.class);
packages("org.dspace.rest");
}
}

View File

@@ -19,6 +19,7 @@ import org.dspace.services.ConfigurationService;
import org.dspace.services.factory.DSpaceServicesFactory;
import org.dspace.usage.UsageEvent;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;
@@ -72,8 +73,8 @@ public class FilteredCollectionsResource extends Resource {
public org.dspace.rest.common.FilteredCollection[] getCollections(@QueryParam("expand") String expand,
@QueryParam("limit") @DefaultValue("100") Integer limit, @QueryParam("offset") @DefaultValue("0") Integer offset,
@QueryParam("userIP") String user_ip, @QueryParam("userAgent") String user_agent,
@QueryParam("filters") @DefaultValue("is_item") String filters,
@QueryParam("xforwardedfor") String xforwardedfor, @Context HttpHeaders headers, @Context HttpServletRequest request)
@QueryParam("filters") @DefaultValue("is_item") String filters, @QueryParam("xforwardedfor") String xforwardedfor,
@Context ServletContext servletContext, @Context HttpHeaders headers, @Context HttpServletRequest request)
throws WebApplicationException
{
@@ -100,7 +101,7 @@ public class FilteredCollectionsResource extends Resource {
{
if (authorizeService.authorizeActionBoolean(context, dspaceCollection, org.dspace.core.Constants.READ))
{
FilteredCollection collection = new org.dspace.rest.common.FilteredCollection(dspaceCollection, filters, expand, context, limit,
FilteredCollection collection = new org.dspace.rest.common.FilteredCollection(dspaceCollection, servletContext, filters, expand, context, limit,
offset);
collections.add(collection);
writeStats(dspaceCollection, UsageEvent.Action.VIEW, user_ip, user_agent,
@@ -129,7 +130,7 @@ public class FilteredCollectionsResource extends Resource {
* Return instance of collection with passed id. You can add more properties
* through expand parameter.
*
* @param collectionId
* @param collection_id
* Id of collection in DSpace.
* @param expand
* String in which is what you want to add to returned instance
@@ -165,7 +166,7 @@ public class FilteredCollectionsResource extends Resource {
@QueryParam("limit") @DefaultValue("1000") Integer limit, @QueryParam("offset") @DefaultValue("0") Integer offset,
@QueryParam("userIP") String user_ip, @QueryParam("userAgent") String user_agent, @QueryParam("xforwarderfor") String xforwarderfor,
@QueryParam("filters") @DefaultValue("is_item") String filters,
@Context HttpHeaders headers, @Context HttpServletRequest request) {
@Context HttpHeaders headers, @Context HttpServletRequest request, @Context ServletContext servletContext) {
org.dspace.core.Context context = null;
FilteredCollection retColl = new org.dspace.rest.common.FilteredCollection();
try {
@@ -177,7 +178,7 @@ public class FilteredCollectionsResource extends Resource {
org.dspace.content.Collection collection = collectionService.findByIdOrLegacyId(context, collection_id);
if(authorizeService.authorizeActionBoolean(context, collection, org.dspace.core.Constants.READ)) {
writeStats(collection, UsageEvent.Action.VIEW, user_ip, user_agent, xforwarderfor, headers, request, context);
retColl = new org.dspace.rest.common.FilteredCollection(collection, filters, expand, context, limit, offset);
retColl = new org.dspace.rest.common.FilteredCollection(collection, servletContext, filters, expand, context, limit, offset);
} else {
throw new WebApplicationException(Response.Status.UNAUTHORIZED);
}

View File

@@ -26,6 +26,7 @@ import org.dspace.services.ConfigurationService;
import org.dspace.services.factory.DSpaceServicesFactory;
import org.dspace.usage.UsageEvent;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.*;
import javax.ws.rs.core.Context;
@@ -107,7 +108,7 @@ public class FilteredItemsResource extends Resource {
@QueryParam("query_op[]") @DefaultValue("exists") List<String> query_op,
@QueryParam("query_val[]") @DefaultValue("") List<String> query_val,
@QueryParam("collSel[]") @DefaultValue("") List<String> collSel,
@Context HttpHeaders headers, @Context HttpServletRequest request) {
@Context HttpHeaders headers, @Context HttpServletRequest request, @Context ServletContext servletContext) {
org.dspace.core.Context context = null;
ItemFilterSet itemFilterSet = new ItemFilterSet(filters, true);
ItemFilter result = itemFilterSet.getAllFiltersFilter();
@@ -133,7 +134,7 @@ public class FilteredItemsResource extends Resource {
Iterator<org.dspace.content.Item> childItems = itemService.findByMetadataQuery(context, listFieldList, query_op, query_val, uuids, regexClause, offset, limit);
int count = itemFilterSet.processSaveItems(context, childItems, true, expand);
int count = itemFilterSet.processSaveItems(context, servletContext, childItems, true, expand);
writeStats(siteService.findSite(context), UsageEvent.Action.VIEW, user_ip, user_agent, xforwarderfor, headers, request, context);
result.annotateQuery(query_field, query_op, query_val);
result.setUnfilteredItemCount(count);

View File

@@ -62,16 +62,16 @@ public class HandleResource extends Resource {
if(authorizeService.authorizeActionBoolean(context, dso, org.dspace.core.Constants.READ)) {
switch(dso.getType()) {
case Constants.COMMUNITY:
dSpaceObject = new Community((org.dspace.content.Community) dso, expand, context);
dSpaceObject = new Community((org.dspace.content.Community) dso, servletContext, expand, context);
break;
case Constants.COLLECTION:
dSpaceObject = new Collection((org.dspace.content.Collection) dso, expand, context, null, null);
dSpaceObject = new Collection((org.dspace.content.Collection) dso, servletContext, expand, context, null, null);
break;
case Constants.ITEM:
dSpaceObject = new Item((org.dspace.content.Item) dso, expand, context);
dSpaceObject = new Item((org.dspace.content.Item) dso, servletContext, expand, context);
break;
default:
dSpaceObject = new DSpaceObject(dso);
dSpaceObject = new DSpaceObject(dso, servletContext);
break;
}
} else {

View File

@@ -104,7 +104,7 @@ public class ItemsResource extends Resource
writeStats(dspaceItem, UsageEvent.Action.VIEW, user_ip, user_agent, xforwardedfor, headers, request, context);
item = new Item(dspaceItem, expand, context);
item = new Item(dspaceItem, servletContext, expand, context);
context.complete();
log.trace("Item(id=" + itemId + ") was successfully read.");
@@ -178,7 +178,7 @@ public class ItemsResource extends Resource
{
if (itemService.isItemListedForUser(context, dspaceItem))
{
items.add(new Item(dspaceItem, expand, context));
items.add(new Item(dspaceItem, servletContext, expand, context));
writeStats(dspaceItem, UsageEvent.Action.VIEW, user_ip, user_agent, xforwardedfor,
headers, request, context);
}
@@ -240,7 +240,7 @@ public class ItemsResource extends Resource
writeStats(dspaceItem, UsageEvent.Action.VIEW, user_ip, user_agent, xforwardedfor, headers, request, context);
metadata = new org.dspace.rest.common.Item(dspaceItem, "metadata", context).getMetadata();
metadata = new org.dspace.rest.common.Item(dspaceItem, servletContext, "metadata", context).getMetadata();
context.complete();
}
catch (SQLException e)
@@ -299,7 +299,7 @@ public class ItemsResource extends Resource
writeStats(dspaceItem, UsageEvent.Action.VIEW, user_ip, user_agent, xforwardedfor, headers, request, context);
List<Bitstream> itemBitstreams = new Item(dspaceItem, "bitstreams", context).getBitstreams();
List<Bitstream> itemBitstreams = new Item(dspaceItem, servletContext, "bitstreams", context).getBitstreams();
if ((offset + limit) > (itemBitstreams.size() - offset))
{
@@ -540,7 +540,7 @@ public class ItemsResource extends Resource
}
dspaceBitstream = bitstreamService.find(context, dspaceBitstream.getID());
bitstream = new Bitstream(dspaceBitstream, "", context);
bitstream = new Bitstream(dspaceBitstream, servletContext, "", context);
context.complete();
@@ -567,7 +567,7 @@ public class ItemsResource extends Resource
processFinally(context);
}
log.info("Bitstream(id=" + bitstream.getId() + ") was successfully added into item(id=" + itemId + ").");
log.info("Bitstream(id=" + bitstream.getUUID() + ") was successfully added into item(id=" + itemId + ").");
return bitstream;
}
@@ -932,7 +932,7 @@ public class ItemsResource extends Resource
while (itemIterator.hasNext())
{
org.dspace.content.Item dspaceItem = itemIterator.next();
Item item = new Item(dspaceItem, "", context);
Item item = new Item(dspaceItem, servletContext, "", context);
writeStats(dspaceItem, UsageEvent.Action.VIEW, user_ip, user_agent, xforwardedfor, headers,
request, context);
items.add(item);

View File

@@ -188,7 +188,7 @@ public class MetadataRegistryResource extends Resource
/**
* Returns metadata field with basic properties.
*
* @param schemaPreix
* @param schemaPrefix
* Prefix for schema in DSpace.
* @param element
* Unqualified element name for field in the metadata registry.
@@ -221,7 +221,7 @@ public class MetadataRegistryResource extends Resource
/**
* Returns metadata field with basic properties.
*
* @param schemaPreix
* @param schemaPrefix
* Prefix for schema in DSpace.
* @param element
* Element name for field in the metadata registry.

View File

@@ -36,7 +36,7 @@ import org.dspace.usage.UsageEvent;
public class Resource
{
@javax.ws.rs.core.Context public static ServletContext servletContext;
@javax.ws.rs.core.Context public ServletContext servletContext;
private static Logger log = Logger.getLogger(Resource.class);
@@ -46,9 +46,6 @@ public class Resource
writeStatistics = DSpaceServicesFactory.getInstance().getConfigurationService().getBooleanProperty("rest.stats", false);
}
static public String getServletContextPath() {
return servletContext.getContextPath();
}
/**
* Create context to work with DSpace database. It can create context
* with or without a logged in user (parameter user is null). Throws

View File

@@ -42,8 +42,6 @@ public class RestIndex {
protected EPersonService epersonService = EPersonServiceFactory.getInstance().getEPersonService();
private static Logger log = Logger.getLogger(RestIndex.class);
@javax.ws.rs.core.Context public static ServletContext servletContext;
/**
* Return html page with information about REST api. It contains methods all
* methods provide by REST api.
@@ -52,7 +50,7 @@ public class RestIndex {
*/
@GET
@Produces(MediaType.TEXT_HTML)
public String sayHtmlHello() {
public String sayHtmlHello(@Context ServletContext servletContext) {
// TODO Better graphics, add arguments to all methods. (limit, offset, item and so on)
return "<html><title>DSpace REST - index</title>" +
"<body>"

View File

@@ -12,6 +12,7 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import javax.servlet.ServletContext;
import javax.xml.bind.annotation.XmlRootElement;
import org.apache.log4j.Logger;
@@ -52,12 +53,12 @@ public class Bitstream extends DSpaceObject {
}
public Bitstream(org.dspace.content.Bitstream bitstream, String expand, Context context) throws SQLException{
super(bitstream);
setup(bitstream, expand, context);
public Bitstream(org.dspace.content.Bitstream bitstream, ServletContext servletContext, String expand, Context context) throws SQLException{
super(bitstream, servletContext);
setup(bitstream, servletContext, expand, context);
}
public void setup(org.dspace.content.Bitstream bitstream, String expand, Context context) throws SQLException{
public void setup(org.dspace.content.Bitstream bitstream, ServletContext servletContext, String expand, Context context) throws SQLException{
List<String> expandFields = new ArrayList<String>();
if(expand != null) {
expandFields = Arrays.asList(expand.split(","));
@@ -82,7 +83,7 @@ public class Bitstream extends DSpaceObject {
this.setCheckSum(checkSum);
if(expandFields.contains("parent") || expandFields.contains("all")) {
parentObject = new DSpaceObject(bitstreamService.getParentObject(context, bitstream));
parentObject = new DSpaceObject(bitstreamService.getParentObject(context, bitstream), servletContext);
} else {
this.addExpand("parent");
}

View File

@@ -13,6 +13,7 @@ import org.dspace.content.service.CollectionService;
import org.dspace.content.service.ItemService;
import org.dspace.core.Context;
import javax.servlet.ServletContext;
import javax.ws.rs.WebApplicationException;
import javax.xml.bind.annotation.XmlRootElement;
import java.sql.SQLException;
@@ -51,12 +52,12 @@ public class Collection extends DSpaceObject {
public Collection(){}
public Collection(org.dspace.content.Collection collection, String expand, Context context, Integer limit, Integer offset) throws SQLException, WebApplicationException{
super(collection);
setup(collection, expand, context, limit, offset);
public Collection(org.dspace.content.Collection collection, ServletContext servletContext, String expand, Context context, Integer limit, Integer offset) throws SQLException, WebApplicationException{
super(collection, servletContext);
setup(collection, servletContext, expand, context, limit, offset);
}
private void setup(org.dspace.content.Collection collection, String expand, Context context, Integer limit, Integer offset) throws SQLException{
private void setup(org.dspace.content.Collection collection, ServletContext servletContext, String expand, Context context, Integer limit, Integer offset) throws SQLException{
List<String> expandFields = new ArrayList<String>();
if(expand != null) {
expandFields = Arrays.asList(expand.split(","));
@@ -70,7 +71,7 @@ public class Collection extends DSpaceObject {
if(expandFields.contains("parentCommunityList") || expandFields.contains("all")) {
List<org.dspace.content.Community> parentCommunities = collection.getCommunities();
for(org.dspace.content.Community parentCommunity : parentCommunities) {
this.addParentCommunityList(new Community(parentCommunity, null, context));
this.addParentCommunityList(new Community(parentCommunity, servletContext, null, context));
}
} else {
this.addExpand("parentCommunityList");
@@ -78,7 +79,7 @@ public class Collection extends DSpaceObject {
if(expandFields.contains("parentCommunity") | expandFields.contains("all")) {
org.dspace.content.Community parentCommunity = (org.dspace.content.Community) collectionService.getParentObject(context, collection);
this.setParentCommunity(new Community(parentCommunity, null, context));
this.setParentCommunity(new Community(parentCommunity, servletContext, null, context));
} else {
this.addExpand("parentCommunity");
}
@@ -92,7 +93,7 @@ public class Collection extends DSpaceObject {
org.dspace.content.Item item = childItems.next();
if(itemService.isItemListedForUser(context, item)) {
items.add(new Item(item, null, context));
items.add(new Item(item, servletContext, null, context));
}
}
} else {
@@ -107,7 +108,7 @@ public class Collection extends DSpaceObject {
if(expandFields.contains("logo") || expandFields.contains("all")) {
if(collection.getLogo() != null) {
this.logo = new Bitstream(collection.getLogo(), null, context);
this.logo = new Bitstream(collection.getLogo(), servletContext, null, context);
}
}
else {

View File

@@ -15,6 +15,7 @@ import org.dspace.content.service.CommunityService;
import org.dspace.content.service.ItemService;
import org.dspace.core.Context;
import javax.servlet.ServletContext;
import javax.ws.rs.WebApplicationException;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
@@ -52,12 +53,12 @@ public class Community extends DSpaceObject{
public Community(){}
public Community(org.dspace.content.Community community, String expand, Context context) throws SQLException, WebApplicationException{
super(community);
setup(community, expand, context);
public Community(org.dspace.content.Community community, ServletContext servletContext, String expand, Context context) throws SQLException, WebApplicationException{
super(community, servletContext);
setup(community,servletContext, expand, context);
}
private void setup(org.dspace.content.Community community, String expand, Context context) throws SQLException{
private void setup(org.dspace.content.Community community, ServletContext servletContext, String expand, Context context) throws SQLException{
List<String> expandFields = new ArrayList<String>();
if(expand != null) {
expandFields = Arrays.asList(expand.split(","));
@@ -72,7 +73,7 @@ public class Community extends DSpaceObject{
if(expandFields.contains("parentCommunity") || expandFields.contains("all")) {
org.dspace.content.Community parentCommunity = (org.dspace.content.Community) communityService.getParentObject(context, community);
if(parentCommunity != null) {
setParentCommunity(new Community(parentCommunity, null, context));
setParentCommunity(new Community(parentCommunity,servletContext, null, context));
}
} else {
this.addExpand("parentCommunity");
@@ -84,7 +85,7 @@ public class Community extends DSpaceObject{
for(org.dspace.content.Collection collection : collections) {
if(authorizeService.authorizeActionBoolean(context, collection, org.dspace.core.Constants.READ)) {
restCollections.add(new Collection(collection, null, context, null, null));
restCollections.add(new Collection(collection,servletContext, null, context, null, null));
} else {
log.info("Omitted restricted collection: " + collection.getID() + " _ " + collection.getName());
}
@@ -99,7 +100,7 @@ public class Community extends DSpaceObject{
subcommunities = new ArrayList<Community>();
for(org.dspace.content.Community subCommunity : communities) {
if(authorizeService.authorizeActionBoolean(context, subCommunity, org.dspace.core.Constants.READ)) {
subcommunities.add(new Community(subCommunity, null, context));
subcommunities.add(new Community(subCommunity, servletContext, null, context));
} else {
log.info("Omitted restricted subCommunity: " + subCommunity.getID() + " _ " + subCommunity.getName());
}
@@ -110,7 +111,7 @@ public class Community extends DSpaceObject{
if(expandFields.contains("logo") || expandFields.contains("all")) {
if(community.getLogo() != null) {
logo = new Bitstream(community.getLogo(), null, context);
logo = new Bitstream(community.getLogo(),servletContext, null, context);
}
} else {
this.addExpand("logo");

View File

@@ -12,6 +12,7 @@ import org.dspace.content.factory.ContentServiceFactory;
import org.dspace.content.service.DSpaceObjectService;
import org.dspace.rest.Resource;
import javax.servlet.ServletContext;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
@@ -28,8 +29,6 @@ import java.util.UUID;
*/
@XmlRootElement(name = "dspaceobject")
public class DSpaceObject {
//legacyID
private Integer id;
private String uuid;
@@ -47,21 +46,13 @@ public class DSpaceObject {
}
public DSpaceObject(org.dspace.content.DSpaceObject dso) {
//setId(); legacyID
public DSpaceObject(org.dspace.content.DSpaceObject dso, ServletContext servletContext) {
setUUID(dso.getID().toString());
setName(dso.getName());
setHandle(dso.getHandle());
DSpaceObjectService dspaceObjectService = ContentServiceFactory.getInstance().getDSpaceObjectService(dso);
setType(dspaceObjectService.getTypeText(dso).toLowerCase());
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
link = createLink(servletContext);
}
public String getName(){
@@ -81,7 +72,7 @@ public class DSpaceObject {
}
public String getLink() {
return Resource.getServletContextPath() + "/" + English.plural(getType()) + "/" + getId();
return link;
}
public String getType() {
@@ -112,4 +103,8 @@ public class DSpaceObject {
public void setUUID(String uuid) {
this.uuid = uuid;
}
private String createLink(ServletContext context){
return context.getContextPath() + "/" + English.plural(getType()) + "/" + getUUID();
}
}

View File

@@ -8,6 +8,7 @@
package org.dspace.rest.common;
import org.apache.log4j.Logger;
import org.dspace.content.*;
import org.dspace.content.factory.ContentServiceFactory;
import org.dspace.content.service.CollectionService;
import org.dspace.content.service.CommunityService;
@@ -15,6 +16,7 @@ import org.dspace.content.service.ItemService;
import org.dspace.core.Context;
import org.dspace.rest.filter.ItemFilterSet;
import javax.servlet.ServletContext;
import javax.ws.rs.WebApplicationException;
import javax.xml.bind.annotation.XmlRootElement;
import java.sql.SQLException;
@@ -63,12 +65,12 @@ public class FilteredCollection extends DSpaceObject {
* @throws SQLException
* @throws WebApplicationException
*/
public FilteredCollection(org.dspace.content.Collection collection, String filters, String expand, Context context, Integer limit, Integer offset) throws SQLException, WebApplicationException{
super(collection);
setup(collection, expand, context, limit, offset, filters);
public FilteredCollection(org.dspace.content.Collection collection, ServletContext servletContext, String filters, String expand, Context context, Integer limit, Integer offset) throws SQLException, WebApplicationException{
super(collection, servletContext);
setup(collection, servletContext, expand, context, limit, offset, filters);
}
private void setup(org.dspace.content.Collection collection, String expand, Context context, Integer limit, Integer offset, String filters) throws SQLException{
private void setup(org.dspace.content.Collection collection, ServletContext servletContext, String expand, Context context, Integer limit, Integer offset, String filters) throws SQLException{
List<String> expandFields = new ArrayList<String>();
if(expand != null) {
expandFields = Arrays.asList(expand.split(","));
@@ -78,7 +80,7 @@ public class FilteredCollection extends DSpaceObject {
List<org.dspace.content.Community> parentCommunities = collection.getCommunities();
List<Community> parentCommunityList = new ArrayList<Community>();
for(org.dspace.content.Community parentCommunity : parentCommunities) {
parentCommunityList.add(new Community(parentCommunity, null, context));
parentCommunityList.add(new Community(parentCommunity, servletContext, null, context));
}
this.setParentCommunityList(parentCommunityList);
} else {
@@ -87,7 +89,7 @@ public class FilteredCollection extends DSpaceObject {
if(expandFields.contains("parentCommunity") | expandFields.contains("all")) {
org.dspace.content.Community parentCommunity = collection.getCommunities().get(0);
this.setParentCommunity(new Community(parentCommunity, null, context));
this.setParentCommunity(new Community(parentCommunity, servletContext, null, context));
} else {
this.addExpand("parentCommunity");
}
@@ -96,7 +98,7 @@ public class FilteredCollection extends DSpaceObject {
List<org.dspace.content.Community> parentCommunities = collection.getCommunities();
if (parentCommunities.size() > 0) {
org.dspace.content.Community topCommunity = parentCommunities.get(parentCommunities.size()-1);
this.setTopCommunity(new Community(topCommunity, null, context));
this.setTopCommunity(new Community(topCommunity, servletContext, null, context));
}
} else {
this.addExpand("topCommunity");
@@ -110,7 +112,7 @@ public class FilteredCollection extends DSpaceObject {
this.setNumberItemsProcessed(0);
if (itemFilters.size() > 0) {
Iterator<org.dspace.content.Item> childItems = itemService.findByCollection(context, collection, limit, offset);
int numProc = itemFilterSet.processSaveItems(context, childItems, items, reportItems, expand);
int numProc = itemFilterSet.processSaveItems(context, servletContext, childItems, items, reportItems, expand);
this.setNumberItemsProcessed(numProc);
}

View File

@@ -13,8 +13,6 @@ import java.util.List;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import org.codehaus.jackson.annotate.JsonProperty;
@XmlRootElement(name = "community")
public class HierarchyCommunity extends HierarchyObject
{

View File

@@ -19,6 +19,7 @@ import org.dspace.content.factory.ContentServiceFactory;
import org.dspace.content.service.ItemService;
import org.dspace.core.Context;
import javax.servlet.ServletContext;
import javax.ws.rs.WebApplicationException;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
@@ -56,12 +57,12 @@ public class Item extends DSpaceObject {
public Item(){}
public Item(org.dspace.content.Item item, String expand, Context context) throws SQLException, WebApplicationException{
super(item);
setup(item, expand, context);
public Item(org.dspace.content.Item item, ServletContext servletContext, String expand, Context context) throws SQLException, WebApplicationException{
super(item, servletContext);
setup(item, servletContext, expand, context);
}
private void setup(org.dspace.content.Item item, String expand, Context context) throws SQLException{
private void setup(org.dspace.content.Item item, ServletContext servletContext, String expand, Context context) throws SQLException{
List<String> expandFields = new ArrayList<String>();
if(expand != null) {
expandFields = Arrays.asList(expand.split(","));
@@ -87,10 +88,10 @@ public class Item extends DSpaceObject {
if(expandFields.contains("parentCollection") || expandFields.contains("all")) {
if (item.getOwningCollection() != null) {
this.parentCollection = new Collection(item.getOwningCollection(), null, context, null, null);
} else {
this.addExpand("parentCollection");
}
this.parentCollection = new Collection(item.getOwningCollection(), servletContext, null, context, null, null);
} else {
this.addExpand("parentCollection");
}
} else {
this.addExpand("parentCollection");
}
@@ -99,7 +100,7 @@ public class Item extends DSpaceObject {
this.parentCollectionList = new ArrayList<Collection>();
List<org.dspace.content.Collection> collections = item.getCollections();
for(org.dspace.content.Collection collection : collections) {
this.parentCollectionList.add(new Collection(collection, null, context, null, null));
this.parentCollectionList.add(new Collection(collection, servletContext, null, context, null, null));
}
} else {
this.addExpand("parentCollectionList");
@@ -110,7 +111,7 @@ public class Item extends DSpaceObject {
List<org.dspace.content.Community> communities = itemService.getCommunities(context, item);
for(org.dspace.content.Community community : communities) {
this.parentCommunityList.add(new Community(community, null, context));
this.parentCommunityList.add(new Community(community, servletContext, null, context));
}
} else {
this.addExpand("parentCommunityList");
@@ -126,7 +127,7 @@ public class Item extends DSpaceObject {
List<org.dspace.content.Bitstream> itemBitstreams = bundle.getBitstreams();
for(org.dspace.content.Bitstream itemBitstream : itemBitstreams) {
if(authorizeService.authorizeActionBoolean(context, itemBitstream, org.dspace.core.Constants.READ)) {
bitstreams.add(new Bitstream(itemBitstream, null, context));
bitstreams.add(new Bitstream(itemBitstream, servletContext, null, context));
}
}
}

View File

@@ -7,9 +7,9 @@
*/
package org.dspace.rest.common;
import java.util.Date;
import com.fasterxml.jackson.annotation.JsonIgnore;
import org.codehaus.jackson.annotate.JsonIgnore;
import java.util.Date;
import javax.xml.bind.annotation.XmlRootElement;

View File

@@ -7,8 +7,7 @@
*/
package org.dspace.rest.common;
import org.codehaus.jackson.annotate.JsonProperty;
import org.dspace.core.Context;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.dspace.eperson.EPerson;
import javax.xml.bind.annotation.XmlRootElement;

View File

@@ -12,6 +12,7 @@ import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import javax.servlet.ServletContext;
import javax.ws.rs.WebApplicationException;
import org.apache.log4j.Logger;
@@ -106,8 +107,8 @@ public class ItemFilterSet {
* @throws WebApplicationException
* @throws SQLException
*/
public int processSaveItems(Context context, Iterator<org.dspace.content.Item> childItems, boolean save, String expand) throws WebApplicationException, SQLException {
return processSaveItems(context, childItems, new ArrayList<Item>(), save, expand);
public int processSaveItems(Context context, ServletContext servletContext, Iterator<org.dspace.content.Item> childItems, boolean save, String expand) throws WebApplicationException, SQLException {
return processSaveItems(context, servletContext, childItems, new ArrayList<Item>(), save, expand);
}
/**
@@ -126,14 +127,14 @@ public class ItemFilterSet {
* @throws WebApplicationException
* @throws SQLException
*/
public int processSaveItems(Context context, Iterator<org.dspace.content.Item> childItems, List<Item> items, boolean save, String expand) throws WebApplicationException, SQLException {
public int processSaveItems(Context context, ServletContext servletContext, Iterator<org.dspace.content.Item> childItems, List<Item> items, boolean save, String expand) throws WebApplicationException, SQLException {
int count = 0;
while(childItems.hasNext()) {
count++;
org.dspace.content.Item item = childItems.next();
log.debug(item.getHandle() + " evaluate.");
if(authorizeService.authorizeActionBoolean(context, item, org.dspace.core.Constants.READ)) {
Item restItem = new Item(item, expand, context);
Item restItem = new Item(item, servletContext, expand, context);
if(save) {
items.add(restItem);
}

View File

@@ -8,13 +8,13 @@
http://www.dspace.org/license/
-->
<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.1.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd">
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<!-- Acquires the DSpace Utility Class with initialized Service Manager -->
<bean id="dspace" class="org.dspace.utils.DSpace"/>

View File

@@ -13,27 +13,16 @@
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
id="WebApp_ID" version="2.5">
<servlet>
<servlet-name>DSpace REST API</servlet-name>
<servlet-class>com.sun.jersey.spi.spring.container.servlet.SpringServlet</servlet-class>
<servlet-class>
org.glassfish.jersey.servlet.ServletContainer
</servlet-class>
<init-param>
<!--
The jersey ServletContainer will look for our Root Resource Class
(i.e. our HelloWorld class) in the foo.bar package
There are other ways to register this; see the jersey documentation for
more details
-->
<param-name>com.sun.jersey.config.property.packages</param-name>
<param-value>org.dspace.rest</param-value>
<param-name>javax.ws.rs.Application</param-name>
<param-value>org.dspace.rest.DSpaceRestApplication</param-value>
</init-param>
<init-param>
<param-name>com.sun.jersey.api.json.POJOMappingFeature</param-name>
<param-value>true</param-value>
</init-param>
<!--
Load the ServletContainer at startup. A value of 1 indicates the ServletContainer
is a high priority servlet to load
-->
<load-on-startup>1</load-on-startup>
</servlet>

View File

@@ -43,7 +43,6 @@
<xs:element name="link" type="xs:string"/>
<xs:element name="expand" type="xs:string" maxOccurs="unbounded"/>
<xs:element name="handle" type="xs:string" minOccurs="0"/>
<xs:element name="id" type="xs:int" minOccurs="0"/>
<xs:element name="name" type="xs:string" minOccurs="0"/>
<xs:element name="type" type="xs:string" minOccurs="0"/>
<xs:element name="UUID" type="xs:string" minOccurs="0"/>