mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-18 15:33:09 +00:00
Remaining refactor of REST API methods to use DSpace Services
REST compiles now. However, DSpace still doesn't boot, so its hard to verify
This commit is contained in:
@@ -10,6 +10,7 @@ package org.dspace.rest;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
@@ -31,10 +32,15 @@ import javax.ws.rs.core.Response;
|
|||||||
|
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
import org.dspace.authorize.AuthorizeException;
|
import org.dspace.authorize.AuthorizeException;
|
||||||
import org.dspace.authorize.AuthorizeServiceImpl;
|
import org.dspace.authorize.factory.AuthorizeServiceFactory;
|
||||||
|
import org.dspace.authorize.service.AuthorizeService;
|
||||||
import org.dspace.browse.BrowseException;
|
import org.dspace.browse.BrowseException;
|
||||||
import org.dspace.content.InstallItemServiceImpl;
|
import org.dspace.content.factory.ContentServiceFactory;
|
||||||
|
import org.dspace.content.service.CollectionService;
|
||||||
|
import org.dspace.content.service.InstallItemService;
|
||||||
import org.dspace.content.service.ItemService;
|
import org.dspace.content.service.ItemService;
|
||||||
|
import org.dspace.content.service.WorkspaceItemService;
|
||||||
|
import org.dspace.core.Constants;
|
||||||
import org.dspace.rest.common.Collection;
|
import org.dspace.rest.common.Collection;
|
||||||
import org.dspace.rest.common.Item;
|
import org.dspace.rest.common.Item;
|
||||||
import org.dspace.rest.common.MetadataEntry;
|
import org.dspace.rest.common.MetadataEntry;
|
||||||
@@ -49,6 +55,12 @@ import org.dspace.usage.UsageEvent;
|
|||||||
@Path("/collections")
|
@Path("/collections")
|
||||||
public class CollectionsResource extends Resource
|
public class CollectionsResource extends Resource
|
||||||
{
|
{
|
||||||
|
protected CollectionService collectionService = ContentServiceFactory.getInstance().getCollectionService();
|
||||||
|
protected ItemService itemService = ContentServiceFactory.getInstance().getItemService();
|
||||||
|
protected AuthorizeService authorizeService = AuthorizeServiceFactory.getInstance().getAuthorizeService();
|
||||||
|
protected WorkspaceItemService workspaceItemService = ContentServiceFactory.getInstance().getWorkspaceItemService();
|
||||||
|
protected InstallItemService installItemService = ContentServiceFactory.getInstance().getInstallItemService();
|
||||||
|
|
||||||
private static Logger log = Logger.getLogger(CollectionsResource.class);
|
private static Logger log = Logger.getLogger(CollectionsResource.class);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -175,10 +187,10 @@ public class CollectionsResource extends Resource
|
|||||||
offset = 0;
|
offset = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
org.dspace.content.Collection[] dspaceCollections = org.dspace.content.Collection.findAll(context, limit, offset);
|
List<org.dspace.content.Collection> dspaceCollections = collectionService.findAll(context, limit, offset);
|
||||||
for(org.dspace.content.Collection dspaceCollection : dspaceCollections)
|
for(org.dspace.content.Collection dspaceCollection : dspaceCollections)
|
||||||
{
|
{
|
||||||
if (AuthorizeServiceImpl.authorizeActionBoolean(context, dspaceCollection, org.dspace.core.Constants.READ))
|
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, null, context, limit,
|
||||||
offset);
|
offset);
|
||||||
@@ -259,13 +271,13 @@ public class CollectionsResource extends Resource
|
|||||||
headers, request, context);
|
headers, request, context);
|
||||||
|
|
||||||
items = new ArrayList<Item>();
|
items = new ArrayList<Item>();
|
||||||
org.dspace.content.ItemIterator dspaceItems = dspaceCollection.getItems();
|
Iterator<org.dspace.content.Item> dspaceItems = itemService.findByCollection(context, dspaceCollection);
|
||||||
for (int i = 0; (dspaceItems.hasNext()) && (i < (limit + offset)); i++)
|
for (int i = 0; (dspaceItems.hasNext()) && (i < (limit + offset)); i++)
|
||||||
{
|
{
|
||||||
if (i >= offset)
|
if (i >= offset)
|
||||||
{
|
{
|
||||||
org.dspace.content.Item dspaceItem = dspaceItems.next();
|
org.dspace.content.Item dspaceItem = dspaceItems.next();
|
||||||
if (ItemService.isItemListedForUser(context, dspaceItem))
|
if (itemService.isItemListedForUser(context, dspaceItem))
|
||||||
{
|
{
|
||||||
items.add(new Item(dspaceItem, expand, context));
|
items.add(new Item(dspaceItem, expand, context));
|
||||||
writeStats(dspaceItem, UsageEvent.Action.VIEW, user_ip, user_agent, xforwardedfor,
|
writeStats(dspaceItem, UsageEvent.Action.VIEW, user_ip, user_agent, xforwardedfor,
|
||||||
@@ -340,8 +352,7 @@ public class CollectionsResource extends Resource
|
|||||||
headers, request, context);
|
headers, request, context);
|
||||||
|
|
||||||
log.trace("Creating item in collection(id=" + collectionId + ").");
|
log.trace("Creating item in collection(id=" + collectionId + ").");
|
||||||
org.dspace.content.WorkspaceItem workspaceItem = org.dspace.content.WorkspaceItem.create(context, dspaceCollection,
|
org.dspace.content.WorkspaceItem workspaceItem = workspaceItemService.create(context, dspaceCollection, false);
|
||||||
false);
|
|
||||||
org.dspace.content.Item dspaceItem = workspaceItem.getItem();
|
org.dspace.content.Item dspaceItem = workspaceItem.getItem();
|
||||||
|
|
||||||
log.trace("Adding metadata to item(id=" + dspaceItem.getID() + ").");
|
log.trace("Adding metadata to item(id=" + dspaceItem.getID() + ").");
|
||||||
@@ -350,17 +361,16 @@ public class CollectionsResource extends Resource
|
|||||||
for (MetadataEntry entry : item.getMetadata())
|
for (MetadataEntry entry : item.getMetadata())
|
||||||
{
|
{
|
||||||
String data[] = mySplit(entry.getKey());
|
String data[] = mySplit(entry.getKey());
|
||||||
dspaceItem.addMetadata(data[0], data[1], data[2], entry.getLanguage(), entry.getValue());
|
itemService.addMetadata(context, dspaceItem, data[0], data[1], data[2], entry.getLanguage(), entry.getValue());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
workspaceItem.update();
|
|
||||||
|
|
||||||
// Index item to browse.
|
// Index item to browse.
|
||||||
org.dspace.browse.IndexBrowse browse = new org.dspace.browse.IndexBrowse();
|
org.dspace.browse.IndexBrowse browse = new org.dspace.browse.IndexBrowse();
|
||||||
browse.indexItem(dspaceItem);
|
browse.indexItem(dspaceItem);
|
||||||
|
|
||||||
log.trace("Installing item to collection(id=" + collectionId + ").");
|
log.trace("Installing item to collection(id=" + collectionId + ").");
|
||||||
dspaceItem = InstallItemServiceImpl.installItem(context, workspaceItem);
|
dspaceItem = installItemService.installItem(context, workspaceItem);
|
||||||
|
|
||||||
returnItem = new Item(dspaceItem, "", context);
|
returnItem = new Item(dspaceItem, "", context);
|
||||||
|
|
||||||
@@ -376,10 +386,6 @@ public class CollectionsResource extends Resource
|
|||||||
processException("Could not add item into collection(id=" + collectionId + "), AuthorizeException. Message: " + e,
|
processException("Could not add item into collection(id=" + collectionId + "), AuthorizeException. Message: " + e,
|
||||||
context);
|
context);
|
||||||
}
|
}
|
||||||
catch (IOException e)
|
|
||||||
{
|
|
||||||
processException("Could not add item into collection(id=" + collectionId + "), IOException. Message: " + e, context);
|
|
||||||
}
|
|
||||||
catch (BrowseException e)
|
catch (BrowseException e)
|
||||||
{
|
{
|
||||||
processException("Could not add item into browse index, BrowseException. Message: " + e, context);
|
processException("Could not add item into browse index, BrowseException. Message: " + e, context);
|
||||||
@@ -439,14 +445,14 @@ public class CollectionsResource extends Resource
|
|||||||
writeStats(dspaceCollection, UsageEvent.Action.UPDATE, user_ip, user_agent, xforwardedfor,
|
writeStats(dspaceCollection, UsageEvent.Action.UPDATE, user_ip, user_agent, xforwardedfor,
|
||||||
headers, request, context);
|
headers, request, context);
|
||||||
|
|
||||||
dspaceCollection.setMetadata("name", collection.getName());
|
collectionService.setMetadata(context, dspaceCollection, "name", collection.getName());
|
||||||
dspaceCollection.setLicense(collection.getLicense());
|
collectionService.setMetadata(context, dspaceCollection, "license", collection.getLicense());
|
||||||
|
|
||||||
// dspaceCollection.setLogo(collection.getLogo()); // TODO Add this option.
|
// dspaceCollection.setLogo(collection.getLogo()); // TODO Add this option.
|
||||||
dspaceCollection.setMetadata(org.dspace.content.Collection.COPYRIGHT_TEXT, collection.getCopyrightText());
|
collectionService.setMetadata(context, dspaceCollection, org.dspace.content.Collection.COPYRIGHT_TEXT, collection.getCopyrightText());
|
||||||
dspaceCollection.setMetadata(org.dspace.content.Collection.INTRODUCTORY_TEXT, collection.getIntroductoryText());
|
collectionService.setMetadata(context, dspaceCollection, org.dspace.content.Collection.INTRODUCTORY_TEXT, collection.getIntroductoryText());
|
||||||
dspaceCollection.setMetadata(org.dspace.content.Collection.SHORT_DESCRIPTION, collection.getShortDescription());
|
collectionService.setMetadata(context, dspaceCollection, org.dspace.content.Collection.SHORT_DESCRIPTION, collection.getShortDescription());
|
||||||
dspaceCollection.setMetadata(org.dspace.content.Collection.SIDEBAR_TEXT, collection.getSidebarText());
|
collectionService.setMetadata(context, dspaceCollection, org.dspace.content.Collection.SIDEBAR_TEXT, collection.getSidebarText());
|
||||||
dspaceCollection.update();
|
|
||||||
|
|
||||||
context.complete();
|
context.complete();
|
||||||
|
|
||||||
@@ -460,10 +466,6 @@ public class CollectionsResource extends Resource
|
|||||||
{
|
{
|
||||||
processException("Could not update collection(id=" + collectionId + "), SQLException. Message: " + e, context);
|
processException("Could not update collection(id=" + collectionId + "), SQLException. Message: " + e, context);
|
||||||
}
|
}
|
||||||
catch (AuthorizeException e)
|
|
||||||
{
|
|
||||||
processException("Could not update collection(id=" + collectionId + "), AuthorizeException. Message: " + e, context);
|
|
||||||
}
|
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
processFinally(context);
|
processFinally(context);
|
||||||
@@ -511,16 +513,12 @@ public class CollectionsResource extends Resource
|
|||||||
writeStats(dspaceCollection, UsageEvent.Action.REMOVE, user_ip, user_agent, xforwardedfor,
|
writeStats(dspaceCollection, UsageEvent.Action.REMOVE, user_ip, user_agent, xforwardedfor,
|
||||||
headers, request, context);
|
headers, request, context);
|
||||||
|
|
||||||
org.dspace.content.Community community = (org.dspace.content.Community) dspaceCollection.getParentObject();
|
collectionService.delete(context, dspaceCollection);
|
||||||
community.removeCollection(dspaceCollection);
|
|
||||||
|
|
||||||
context.complete();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
catch (ContextException e)
|
catch (ContextException e)
|
||||||
{
|
{
|
||||||
processException(
|
processException(
|
||||||
"Could not delete collection(id=" + collectionId + "), ContextExcpetion. Message: " + e.getMessage(), context);
|
"Could not delete collection(id=" + collectionId + "), ContextException. Message: " + e.getMessage(), context);
|
||||||
}
|
}
|
||||||
catch (SQLException e)
|
catch (SQLException e)
|
||||||
{
|
{
|
||||||
@@ -577,32 +575,29 @@ public class CollectionsResource extends Resource
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
context = createContext(getUser(headers));
|
context = createContext(getUser(headers));
|
||||||
org.dspace.content.Collection dspaceCollection = findCollection(context, collectionId,
|
|
||||||
org.dspace.core.Constants.WRITE);
|
|
||||||
|
|
||||||
org.dspace.content.Item item = null;
|
org.dspace.content.Collection dspaceCollection = collectionService.findByLegacyId(context, collectionId);
|
||||||
org.dspace.content.ItemIterator dspaceItems = dspaceCollection.getItems();
|
org.dspace.content.Item item = itemService.findByLegacyId(context, itemId);
|
||||||
while (dspaceItems.hasNext())
|
|
||||||
{
|
|
||||||
org.dspace.content.Item dspaceItem = dspaceItems.next();
|
if(dspaceCollection == null) {
|
||||||
if (dspaceItem.getID() == itemId)
|
//throw collection not exist
|
||||||
{
|
log.warn("Collection(id=" + itemId + ") was not found!");
|
||||||
item = dspaceItem;
|
throw new WebApplicationException(Response.Status.NOT_FOUND);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (item == null)
|
if(item == null) {
|
||||||
{
|
//throw item not exist
|
||||||
context.abort();
|
|
||||||
log.warn("Item(id=" + itemId + ") was not found!");
|
log.warn("Item(id=" + itemId + ") was not found!");
|
||||||
throw new WebApplicationException(Response.Status.NOT_FOUND);
|
throw new WebApplicationException(Response.Status.NOT_FOUND);
|
||||||
}
|
}
|
||||||
else if (!AuthorizeServiceImpl.authorizeActionBoolean(context, item, org.dspace.core.Constants.REMOVE))
|
|
||||||
{
|
if(!authorizeService.authorizeActionBoolean(context, item, Constants.REMOVE)
|
||||||
context.abort();
|
|| !authorizeService.authorizeActionBoolean(context, dspaceCollection, Constants.REMOVE)) {
|
||||||
|
//throw auth
|
||||||
if (context.getCurrentUser() != null)
|
if (context.getCurrentUser() != null)
|
||||||
{
|
{
|
||||||
log.error("User(" + context.getCurrentUser().getEmail() + ") has not permission to delete item!");
|
log.error("User(" + context.getCurrentUser().getEmail() + ") does not have permission to delete item!");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -611,12 +606,12 @@ public class CollectionsResource extends Resource
|
|||||||
throw new WebApplicationException(Response.Status.UNAUTHORIZED);
|
throw new WebApplicationException(Response.Status.UNAUTHORIZED);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
collectionService.removeItem(context, dspaceCollection, item);
|
||||||
|
|
||||||
writeStats(dspaceCollection, UsageEvent.Action.UPDATE, user_ip, user_agent, xforwardedfor,
|
writeStats(dspaceCollection, UsageEvent.Action.UPDATE, user_ip, user_agent, xforwardedfor,
|
||||||
headers, request, context);
|
headers, request, context);
|
||||||
writeStats(item, UsageEvent.Action.REMOVE, user_ip, user_agent, xforwardedfor, headers, request, context);
|
writeStats(item, UsageEvent.Action.REMOVE, user_ip, user_agent, xforwardedfor, headers, request, context);
|
||||||
|
|
||||||
dspaceCollection.removeItem(item);
|
|
||||||
|
|
||||||
context.complete();
|
context.complete();
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -675,13 +670,13 @@ public class CollectionsResource extends Resource
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
context = createContext(getUser(headers));
|
context = createContext(getUser(headers));
|
||||||
org.dspace.content.Collection[] dspaceCollections;
|
|
||||||
|
|
||||||
dspaceCollections = org.dspace.content.Collection.findAll(context);
|
List<org.dspace.content.Collection> dspaceCollections = collectionService.findAll(context);
|
||||||
|
//TODO, this would be more efficient with a findByName query
|
||||||
|
|
||||||
for (org.dspace.content.Collection dspaceCollection : dspaceCollections)
|
for (org.dspace.content.Collection dspaceCollection : dspaceCollections)
|
||||||
{
|
{
|
||||||
if (AuthorizeServiceImpl.authorizeActionBoolean(context, dspaceCollection, org.dspace.core.Constants.READ))
|
if (authorizeService.authorizeActionBoolean(context, dspaceCollection, org.dspace.core.Constants.READ))
|
||||||
{
|
{
|
||||||
if (dspaceCollection.getName().equals(name))
|
if (dspaceCollection.getName().equals(name))
|
||||||
{
|
{
|
||||||
@@ -742,7 +737,7 @@ public class CollectionsResource extends Resource
|
|||||||
org.dspace.content.Collection collection = null;
|
org.dspace.content.Collection collection = null;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
collection = org.dspace.content.Collection.find(context, id);
|
collection = collectionService.findByLegacyId(context, id);
|
||||||
|
|
||||||
if (collection == null)
|
if (collection == null)
|
||||||
{
|
{
|
||||||
@@ -750,7 +745,7 @@ public class CollectionsResource extends Resource
|
|||||||
log.warn("Collection(id=" + id + ") was not found!");
|
log.warn("Collection(id=" + id + ") was not found!");
|
||||||
throw new WebApplicationException(Response.Status.NOT_FOUND);
|
throw new WebApplicationException(Response.Status.NOT_FOUND);
|
||||||
}
|
}
|
||||||
else if (!AuthorizeServiceImpl.authorizeActionBoolean(context, collection, action))
|
else if (!authorizeService.authorizeActionBoolean(context, collection, action))
|
||||||
{
|
{
|
||||||
context.abort();
|
context.abort();
|
||||||
if (context.getCurrentUser() != null)
|
if (context.getCurrentUser() != null)
|
||||||
|
@@ -7,35 +7,29 @@
|
|||||||
*/
|
*/
|
||||||
package org.dspace.rest;
|
package org.dspace.rest;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.sql.SQLException;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
|
||||||
import javax.ws.rs.Consumes;
|
|
||||||
import javax.ws.rs.DELETE;
|
|
||||||
import javax.ws.rs.DefaultValue;
|
|
||||||
import javax.ws.rs.GET;
|
|
||||||
import javax.ws.rs.POST;
|
|
||||||
import javax.ws.rs.PUT;
|
|
||||||
import javax.ws.rs.Path;
|
|
||||||
import javax.ws.rs.PathParam;
|
|
||||||
import javax.ws.rs.Produces;
|
|
||||||
import javax.ws.rs.QueryParam;
|
|
||||||
import javax.ws.rs.WebApplicationException;
|
|
||||||
import javax.ws.rs.core.Context;
|
|
||||||
import javax.ws.rs.core.HttpHeaders;
|
|
||||||
import javax.ws.rs.core.MediaType;
|
|
||||||
import javax.ws.rs.core.Response;
|
|
||||||
|
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
import org.dspace.authorize.AuthorizeException;
|
import org.dspace.authorize.AuthorizeException;
|
||||||
import org.dspace.authorize.AuthorizeServiceImpl;
|
import org.dspace.authorize.factory.AuthorizeServiceFactory;
|
||||||
|
import org.dspace.authorize.service.AuthorizeService;
|
||||||
|
import org.dspace.content.factory.ContentServiceFactory;
|
||||||
|
import org.dspace.content.service.CollectionService;
|
||||||
|
import org.dspace.content.service.CommunityService;
|
||||||
import org.dspace.rest.common.Collection;
|
import org.dspace.rest.common.Collection;
|
||||||
import org.dspace.rest.common.Community;
|
import org.dspace.rest.common.Community;
|
||||||
import org.dspace.rest.exceptions.ContextException;
|
import org.dspace.rest.exceptions.ContextException;
|
||||||
import org.dspace.usage.UsageEvent;
|
import org.dspace.usage.UsageEvent;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.ws.rs.*;
|
||||||
|
import javax.ws.rs.core.Context;
|
||||||
|
import javax.ws.rs.core.HttpHeaders;
|
||||||
|
import javax.ws.rs.core.MediaType;
|
||||||
|
import javax.ws.rs.core.Response;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class which provides CRUD methods over communities.
|
* Class which provides CRUD methods over communities.
|
||||||
*
|
*
|
||||||
@@ -45,6 +39,10 @@ import org.dspace.usage.UsageEvent;
|
|||||||
@Path("/communities")
|
@Path("/communities")
|
||||||
public class CommunitiesResource extends Resource
|
public class CommunitiesResource extends Resource
|
||||||
{
|
{
|
||||||
|
protected CommunityService communityService = ContentServiceFactory.getInstance().getCommunityService();
|
||||||
|
protected CollectionService collectionService = ContentServiceFactory.getInstance().getCollectionService();
|
||||||
|
protected AuthorizeService authorizeService = AuthorizeServiceFactory.getInstance().getAuthorizeService();
|
||||||
|
|
||||||
private static Logger log = Logger.getLogger(CommunitiesResource.class);
|
private static Logger log = Logger.getLogger(CommunitiesResource.class);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -151,7 +149,7 @@ public class CommunitiesResource extends Resource
|
|||||||
{
|
{
|
||||||
context = createContext(getUser(headers));
|
context = createContext(getUser(headers));
|
||||||
|
|
||||||
org.dspace.content.Community[] dspaceCommunities = org.dspace.content.Community.findAll(context);
|
List<org.dspace.content.Community> dspaceCommunities = communityService.findAll(context);
|
||||||
communities = new ArrayList<Community>();
|
communities = new ArrayList<Community>();
|
||||||
|
|
||||||
if (!((limit != null) && (limit >= 0) && (offset != null) && (offset >= 0)))
|
if (!((limit != null) && (limit >= 0) && (offset != null) && (offset >= 0)))
|
||||||
@@ -161,12 +159,12 @@ public class CommunitiesResource extends Resource
|
|||||||
offset = 0;
|
offset = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = offset; (i < (offset + limit)) && i < dspaceCommunities.length; i++)
|
for (int i = offset; (i < (offset + limit)) && i < dspaceCommunities.size(); i++)
|
||||||
{
|
{
|
||||||
if (AuthorizeServiceImpl.authorizeActionBoolean(context, dspaceCommunities[i], org.dspace.core.Constants.READ))
|
if (authorizeService.authorizeActionBoolean(context, dspaceCommunities.get(i), org.dspace.core.Constants.READ))
|
||||||
{
|
{
|
||||||
Community community = new Community(dspaceCommunities[i], expand, context);
|
Community community = new Community(dspaceCommunities.get(i), expand, context);
|
||||||
writeStats(dspaceCommunities[i], UsageEvent.Action.VIEW, user_ip, user_agent,
|
writeStats(dspaceCommunities.get(i), UsageEvent.Action.VIEW, user_ip, user_agent,
|
||||||
xforwardedfor, headers, request, context);
|
xforwardedfor, headers, request, context);
|
||||||
communities.add(community);
|
communities.add(community);
|
||||||
}
|
}
|
||||||
@@ -233,22 +231,22 @@ public class CommunitiesResource extends Resource
|
|||||||
{
|
{
|
||||||
context = createContext(getUser(headers));
|
context = createContext(getUser(headers));
|
||||||
|
|
||||||
org.dspace.content.Community[] dspaceCommunities = org.dspace.content.Community.findAllTop(context);
|
List<org.dspace.content.Community> dspaceCommunities = communityService.findAllTop(context);
|
||||||
communities = new ArrayList<Community>();
|
communities = new ArrayList<Community>();
|
||||||
|
|
||||||
if (!((limit != null) && (limit >= 0) && (offset != null) && (offset >= 0)))
|
if (!((limit != null) && (limit >= 0) && (offset != null) && (offset >= 0)))
|
||||||
{
|
{
|
||||||
log.warn("Pagging was badly set, using default values.");
|
log.warn("Paging was badly set, using default values.");
|
||||||
limit = 100;
|
limit = 100;
|
||||||
offset = 0;
|
offset = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = offset; (i < (offset + limit)) && i < dspaceCommunities.length; i++)
|
for (int i = offset; (i < (offset + limit)) && i < dspaceCommunities.size(); i++)
|
||||||
{
|
{
|
||||||
if (AuthorizeServiceImpl.authorizeActionBoolean(context, dspaceCommunities[i], org.dspace.core.Constants.READ))
|
if (authorizeService.authorizeActionBoolean(context, dspaceCommunities.get(i), org.dspace.core.Constants.READ))
|
||||||
{
|
{
|
||||||
Community community = new Community(dspaceCommunities[i], expand, context);
|
Community community = new Community(dspaceCommunities.get(i), expand, context);
|
||||||
writeStats(dspaceCommunities[i], UsageEvent.Action.VIEW, user_ip, user_agent,
|
writeStats(dspaceCommunities.get(i), UsageEvent.Action.VIEW, user_ip, user_agent,
|
||||||
xforwardedfor, headers, request, context);
|
xforwardedfor, headers, request, context);
|
||||||
communities.add(community);
|
communities.add(community);
|
||||||
}
|
}
|
||||||
@@ -327,13 +325,13 @@ public class CommunitiesResource extends Resource
|
|||||||
}
|
}
|
||||||
|
|
||||||
collections = new ArrayList<Collection>();
|
collections = new ArrayList<Collection>();
|
||||||
org.dspace.content.Collection[] dspaceCollections = dspaceCommunity.getCollections();
|
List<org.dspace.content.Collection> dspaceCollections = dspaceCommunity.getCollections();
|
||||||
for (int i = offset; (i < (offset + limit)) && (i < dspaceCollections.length); i++)
|
for (int i = offset; (i < (offset + limit)) && (i < dspaceCollections.size()); i++)
|
||||||
{
|
{
|
||||||
if (AuthorizeServiceImpl.authorizeActionBoolean(context, dspaceCollections[i], org.dspace.core.Constants.READ))
|
if (authorizeService.authorizeActionBoolean(context, dspaceCollections.get(i), org.dspace.core.Constants.READ))
|
||||||
{
|
{
|
||||||
collections.add(new Collection(dspaceCollections[i], expand, context, 20, 0));
|
collections.add(new Collection(dspaceCollections.get(i), expand, context, 20, 0));
|
||||||
writeStats(dspaceCollections[i], UsageEvent.Action.VIEW, user_ip, user_agent,
|
writeStats(dspaceCollections.get(i), UsageEvent.Action.VIEW, user_ip, user_agent,
|
||||||
xforwardedfor, headers, request, context);
|
xforwardedfor, headers, request, context);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -413,13 +411,13 @@ public class CommunitiesResource extends Resource
|
|||||||
}
|
}
|
||||||
|
|
||||||
communities = new ArrayList<Community>();
|
communities = new ArrayList<Community>();
|
||||||
org.dspace.content.Community[] dspaceCommunities = dspaceCommunity.getSubcommunities();
|
List<org.dspace.content.Community> dspaceCommunities = dspaceCommunity.getSubcommunities();
|
||||||
for (int i = offset; (i < (offset + limit)) && (i < dspaceCommunities.length); i++)
|
for (int i = offset; (i < (offset + limit)) && (i < dspaceCommunities.size()); i++)
|
||||||
{
|
{
|
||||||
if (AuthorizeServiceImpl.authorizeActionBoolean(context, dspaceCommunities[i], org.dspace.core.Constants.READ))
|
if (authorizeService.authorizeActionBoolean(context, dspaceCommunities.get(i), org.dspace.core.Constants.READ))
|
||||||
{
|
{
|
||||||
communities.add(new Community(dspaceCommunities[i], expand, context));
|
communities.add(new Community(dspaceCommunities.get(i), expand, context));
|
||||||
writeStats(dspaceCommunities[i], UsageEvent.Action.VIEW, user_ip, user_agent,
|
writeStats(dspaceCommunities.get(i), UsageEvent.Action.VIEW, user_ip, user_agent,
|
||||||
xforwardedfor, headers, request, context);
|
xforwardedfor, headers, request, context);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -476,7 +474,7 @@ public class CommunitiesResource extends Resource
|
|||||||
{
|
{
|
||||||
context = createContext(getUser(headers));
|
context = createContext(getUser(headers));
|
||||||
|
|
||||||
if (!AuthorizeServiceImpl.isAdmin(context))
|
if (!authorizeService.isAdmin(context))
|
||||||
{
|
{
|
||||||
context.abort();
|
context.abort();
|
||||||
String user = "anonymous";
|
String user = "anonymous";
|
||||||
@@ -488,16 +486,15 @@ public class CommunitiesResource extends Resource
|
|||||||
throw new WebApplicationException(Response.Status.UNAUTHORIZED);
|
throw new WebApplicationException(Response.Status.UNAUTHORIZED);
|
||||||
}
|
}
|
||||||
|
|
||||||
org.dspace.content.Community dspaceCommunity = org.dspace.content.Community.create(null, context);
|
org.dspace.content.Community dspaceCommunity = communityService.create(null, context);
|
||||||
writeStats(dspaceCommunity, UsageEvent.Action.CREATE, user_ip, user_agent, xforwardedfor,
|
writeStats(dspaceCommunity, UsageEvent.Action.CREATE, user_ip, user_agent, xforwardedfor,
|
||||||
headers, request, context);
|
headers, request, context);
|
||||||
|
|
||||||
dspaceCommunity.setMetadata("name", community.getName());
|
communityService.setMetadata(context, dspaceCommunity, "name", community.getName());
|
||||||
dspaceCommunity.setMetadata(org.dspace.content.Community.COPYRIGHT_TEXT, community.getCopyrightText());
|
communityService.setMetadata(context, dspaceCommunity, org.dspace.content.Community.COPYRIGHT_TEXT, community.getCopyrightText());
|
||||||
dspaceCommunity.setMetadata(org.dspace.content.Community.INTRODUCTORY_TEXT, community.getIntroductoryText());
|
communityService.setMetadata(context, dspaceCommunity, org.dspace.content.Community.INTRODUCTORY_TEXT, community.getIntroductoryText());
|
||||||
dspaceCommunity.setMetadata(org.dspace.content.Community.SHORT_DESCRIPTION, community.getShortDescription());
|
communityService.setMetadata(context, dspaceCommunity, org.dspace.content.Community.SHORT_DESCRIPTION, community.getShortDescription());
|
||||||
dspaceCommunity.setMetadata(org.dspace.content.Community.SIDEBAR_TEXT, community.getSidebarText());
|
communityService.setMetadata(context, dspaceCommunity, org.dspace.content.Community.SIDEBAR_TEXT, community.getSidebarText());
|
||||||
dspaceCommunity.update();
|
|
||||||
|
|
||||||
retCommunity = new Community(dspaceCommunity, "", context);
|
retCommunity = new Community(dspaceCommunity, "", context);
|
||||||
context.complete();
|
context.complete();
|
||||||
@@ -565,17 +562,15 @@ public class CommunitiesResource extends Resource
|
|||||||
writeStats(dspaceCommunity, UsageEvent.Action.UPDATE, user_ip, user_agent, xforwardedfor,
|
writeStats(dspaceCommunity, UsageEvent.Action.UPDATE, user_ip, user_agent, xforwardedfor,
|
||||||
headers, request, context);
|
headers, request, context);
|
||||||
|
|
||||||
org.dspace.content.Collection dspaceCollection = dspaceCommunity.createCollection();
|
org.dspace.content.Collection dspaceCollection = collectionService.create(context, dspaceCommunity);
|
||||||
dspaceCollection.setLicense(collection.getLicense());
|
|
||||||
|
collectionService.setMetadata(context, dspaceCollection, "license", collection.getLicense());
|
||||||
// dspaceCollection.setLogo(collection.getLogo()); // TODO Add this option.
|
// dspaceCollection.setLogo(collection.getLogo()); // TODO Add this option.
|
||||||
dspaceCollection.setMetadata("name", collection.getName());
|
collectionService.setMetadata(context, dspaceCollection, "name", collection.getName());
|
||||||
dspaceCollection.setMetadata(org.dspace.content.Collection.COPYRIGHT_TEXT, collection.getCopyrightText());
|
collectionService.setMetadata(context, dspaceCollection, org.dspace.content.Collection.COPYRIGHT_TEXT, collection.getCopyrightText());
|
||||||
dspaceCollection.setMetadata(org.dspace.content.Collection.INTRODUCTORY_TEXT, collection.getIntroductoryText());
|
collectionService.setMetadata(context, dspaceCollection, org.dspace.content.Collection.INTRODUCTORY_TEXT, collection.getIntroductoryText());
|
||||||
dspaceCollection.setMetadata(org.dspace.content.Collection.SHORT_DESCRIPTION, collection.getShortDescription());
|
collectionService.setMetadata(context, dspaceCollection, org.dspace.content.Collection.SHORT_DESCRIPTION, collection.getShortDescription());
|
||||||
dspaceCollection.setMetadata(org.dspace.content.Collection.SIDEBAR_TEXT, collection.getSidebarText());
|
collectionService.setMetadata(context, dspaceCollection, org.dspace.content.Collection.SIDEBAR_TEXT, collection.getSidebarText());
|
||||||
dspaceCollection.setLicense(collection.getLicense());
|
|
||||||
dspaceCollection.update();
|
|
||||||
dspaceCommunity.update();
|
|
||||||
|
|
||||||
retCollection = new Collection(dspaceCollection, "", context, 100, 0);
|
retCollection = new Collection(dspaceCollection, "", context, 100, 0);
|
||||||
context.complete();
|
context.complete();
|
||||||
@@ -650,14 +645,12 @@ public class CommunitiesResource extends Resource
|
|||||||
writeStats(dspaceParentCommunity, UsageEvent.Action.UPDATE, user_ip, user_agent, xforwardedfor,
|
writeStats(dspaceParentCommunity, UsageEvent.Action.UPDATE, user_ip, user_agent, xforwardedfor,
|
||||||
headers, request, context);
|
headers, request, context);
|
||||||
|
|
||||||
org.dspace.content.Community dspaceCommunity = org.dspace.content.Community.create(dspaceParentCommunity, context);
|
org.dspace.content.Community dspaceCommunity = communityService.createSubcommunity(context, dspaceParentCommunity);
|
||||||
dspaceCommunity.setMetadata("name", community.getName());
|
communityService.setMetadata(context, dspaceCommunity, "name", community.getName());
|
||||||
dspaceCommunity.setMetadata(org.dspace.content.Community.COPYRIGHT_TEXT, community.getCopyrightText());
|
communityService.setMetadata(context, dspaceCommunity, org.dspace.content.Community.COPYRIGHT_TEXT, community.getCopyrightText());
|
||||||
dspaceCommunity.setMetadata(org.dspace.content.Community.INTRODUCTORY_TEXT, community.getIntroductoryText());
|
communityService.setMetadata(context, dspaceCommunity, org.dspace.content.Community.INTRODUCTORY_TEXT, community.getIntroductoryText());
|
||||||
dspaceCommunity.setMetadata(org.dspace.content.Community.SHORT_DESCRIPTION, community.getShortDescription());
|
communityService.setMetadata(context, dspaceCommunity, org.dspace.content.Community.SHORT_DESCRIPTION, community.getShortDescription());
|
||||||
dspaceCommunity.setMetadata(org.dspace.content.Community.SIDEBAR_TEXT, community.getSidebarText());
|
communityService.setMetadata(context, dspaceCommunity, org.dspace.content.Community.SIDEBAR_TEXT, community.getSidebarText());
|
||||||
dspaceCommunity.update();
|
|
||||||
dspaceParentCommunity.update();
|
|
||||||
|
|
||||||
retCommunity = new Community(dspaceCommunity, "", context);
|
retCommunity = new Community(dspaceCommunity, "", context);
|
||||||
context.complete();
|
context.complete();
|
||||||
@@ -729,12 +722,11 @@ public class CommunitiesResource extends Resource
|
|||||||
headers, request, context);
|
headers, request, context);
|
||||||
|
|
||||||
// dspaceCommunity.setLogo(arg0); // TODO Add this option.
|
// dspaceCommunity.setLogo(arg0); // TODO Add this option.
|
||||||
dspaceCommunity.setMetadata("name", community.getName());
|
communityService.setMetadata(context, dspaceCommunity, "name", community.getName());
|
||||||
dspaceCommunity.setMetadata(org.dspace.content.Community.COPYRIGHT_TEXT, community.getCopyrightText());
|
communityService.setMetadata(context, dspaceCommunity, org.dspace.content.Community.COPYRIGHT_TEXT, community.getCopyrightText());
|
||||||
dspaceCommunity.setMetadata(org.dspace.content.Community.INTRODUCTORY_TEXT, community.getIntroductoryText());
|
communityService.setMetadata(context, dspaceCommunity, org.dspace.content.Community.INTRODUCTORY_TEXT, community.getIntroductoryText());
|
||||||
dspaceCommunity.setMetadata(org.dspace.content.Community.SHORT_DESCRIPTION, community.getShortDescription());
|
communityService.setMetadata(context, dspaceCommunity, org.dspace.content.Community.SHORT_DESCRIPTION, community.getShortDescription());
|
||||||
dspaceCommunity.setMetadata(org.dspace.content.Community.SIDEBAR_TEXT, community.getSidebarText());
|
communityService.setMetadata(context, dspaceCommunity, org.dspace.content.Community.SIDEBAR_TEXT, community.getSidebarText());
|
||||||
dspaceCommunity.update();
|
|
||||||
|
|
||||||
context.complete();
|
context.complete();
|
||||||
|
|
||||||
@@ -747,10 +739,6 @@ public class CommunitiesResource extends Resource
|
|||||||
{
|
{
|
||||||
processException("Could not update community(id=" + communityId + "), ContextException Message:" + e, context);
|
processException("Could not update community(id=" + communityId + "), ContextException Message:" + e, context);
|
||||||
}
|
}
|
||||||
catch (AuthorizeException e)
|
|
||||||
{
|
|
||||||
processException("Could not update community(id=" + communityId + "), AuthorizeException. Message:" + e, context);
|
|
||||||
}
|
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
processFinally(context);
|
processFinally(context);
|
||||||
@@ -795,7 +783,7 @@ public class CommunitiesResource extends Resource
|
|||||||
writeStats(community, UsageEvent.Action.DELETE, user_ip, user_agent, xforwardedfor, headers,
|
writeStats(community, UsageEvent.Action.DELETE, user_ip, user_agent, xforwardedfor, headers,
|
||||||
request, context);
|
request, context);
|
||||||
|
|
||||||
community.delete();
|
communityService.delete(context, community);
|
||||||
context.complete();
|
context.complete();
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -862,15 +850,7 @@ public class CommunitiesResource extends Resource
|
|||||||
context = createContext(getUser(headers));
|
context = createContext(getUser(headers));
|
||||||
|
|
||||||
org.dspace.content.Community community = findCommunity(context, communityId, org.dspace.core.Constants.WRITE);
|
org.dspace.content.Community community = findCommunity(context, communityId, org.dspace.core.Constants.WRITE);
|
||||||
org.dspace.content.Collection collection = null;
|
org.dspace.content.Collection collection = collectionService.findByLegacyId(context, collectionId);
|
||||||
for (org.dspace.content.Collection dspaceCollection : community.getAllCollections())
|
|
||||||
{
|
|
||||||
if (dspaceCollection.getID() == collectionId)
|
|
||||||
{
|
|
||||||
collection = dspaceCollection;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (collection == null)
|
if (collection == null)
|
||||||
{
|
{
|
||||||
@@ -878,7 +858,7 @@ public class CommunitiesResource extends Resource
|
|||||||
log.warn("Collection(id=" + collectionId + ") was not found!");
|
log.warn("Collection(id=" + collectionId + ") was not found!");
|
||||||
throw new WebApplicationException(Response.Status.NOT_FOUND);
|
throw new WebApplicationException(Response.Status.NOT_FOUND);
|
||||||
}
|
}
|
||||||
else if (!AuthorizeServiceImpl.authorizeActionBoolean(context, collection, org.dspace.core.Constants.REMOVE))
|
else if (!authorizeService.authorizeActionBoolean(context, collection, org.dspace.core.Constants.REMOVE))
|
||||||
{
|
{
|
||||||
context.abort();
|
context.abort();
|
||||||
if (context.getCurrentUser() != null)
|
if (context.getCurrentUser() != null)
|
||||||
@@ -892,13 +872,13 @@ public class CommunitiesResource extends Resource
|
|||||||
throw new WebApplicationException(Response.Status.UNAUTHORIZED);
|
throw new WebApplicationException(Response.Status.UNAUTHORIZED);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
communityService.removeCollection(context, community, collection);
|
||||||
|
|
||||||
writeStats(community, UsageEvent.Action.UPDATE, user_ip, user_agent, xforwardedfor, headers,
|
writeStats(community, UsageEvent.Action.UPDATE, user_ip, user_agent, xforwardedfor, headers,
|
||||||
request, context);
|
request, context);
|
||||||
writeStats(collection, UsageEvent.Action.DELETE, user_ip, user_agent, xforwardedfor, headers,
|
writeStats(collection, UsageEvent.Action.DELETE, user_ip, user_agent, xforwardedfor, headers,
|
||||||
request, context);
|
request, context);
|
||||||
|
|
||||||
community.removeCollection(collection);
|
|
||||||
|
|
||||||
context.complete();
|
context.complete();
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -969,15 +949,7 @@ public class CommunitiesResource extends Resource
|
|||||||
|
|
||||||
org.dspace.content.Community parentCommunity = findCommunity(context, parentCommunityId,
|
org.dspace.content.Community parentCommunity = findCommunity(context, parentCommunityId,
|
||||||
org.dspace.core.Constants.WRITE);
|
org.dspace.core.Constants.WRITE);
|
||||||
org.dspace.content.Community subcommunity = null;
|
org.dspace.content.Community subcommunity = communityService.findByLegacyId(context, subcommunityId);
|
||||||
for (org.dspace.content.Community dspaceCommunity : parentCommunity.getSubcommunities())
|
|
||||||
{
|
|
||||||
if (dspaceCommunity.getID() == subcommunityId)
|
|
||||||
{
|
|
||||||
subcommunity = dspaceCommunity;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (subcommunity == null)
|
if (subcommunity == null)
|
||||||
{
|
{
|
||||||
@@ -985,7 +957,7 @@ public class CommunitiesResource extends Resource
|
|||||||
log.warn("Subcommunity(id=" + subcommunityId + ") in community(id=" + ") was not found!");
|
log.warn("Subcommunity(id=" + subcommunityId + ") in community(id=" + ") was not found!");
|
||||||
throw new WebApplicationException(Response.Status.NOT_FOUND);
|
throw new WebApplicationException(Response.Status.NOT_FOUND);
|
||||||
}
|
}
|
||||||
else if (!AuthorizeServiceImpl.authorizeActionBoolean(context, subcommunity, org.dspace.core.Constants.REMOVE))
|
else if (!authorizeService.authorizeActionBoolean(context, subcommunity, org.dspace.core.Constants.REMOVE))
|
||||||
{
|
{
|
||||||
context.abort();
|
context.abort();
|
||||||
if (context.getCurrentUser() != null)
|
if (context.getCurrentUser() != null)
|
||||||
@@ -999,12 +971,13 @@ public class CommunitiesResource extends Resource
|
|||||||
throw new WebApplicationException(Response.Status.UNAUTHORIZED);
|
throw new WebApplicationException(Response.Status.UNAUTHORIZED);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
communityService.removeSubcommunity(context, parentCommunity, subcommunity);
|
||||||
|
|
||||||
writeStats(parentCommunity, UsageEvent.Action.UPDATE, user_ip, user_agent, xforwardedfor,
|
writeStats(parentCommunity, UsageEvent.Action.UPDATE, user_ip, user_agent, xforwardedfor,
|
||||||
headers, request, context);
|
headers, request, context);
|
||||||
writeStats(subcommunity, UsageEvent.Action.DELETE, user_ip, user_agent, xforwardedfor, headers,
|
writeStats(subcommunity, UsageEvent.Action.DELETE, user_ip, user_agent, xforwardedfor, headers,
|
||||||
request, context);
|
request, context);
|
||||||
|
|
||||||
parentCommunity.removeSubcommunity(subcommunity);
|
|
||||||
context.complete();
|
context.complete();
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1060,7 +1033,7 @@ public class CommunitiesResource extends Resource
|
|||||||
org.dspace.content.Community community = null;
|
org.dspace.content.Community community = null;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
community = org.dspace.content.Community.find(context, id);
|
community = communityService.findByLegacyId(context, id);
|
||||||
|
|
||||||
if (community == null)
|
if (community == null)
|
||||||
{
|
{
|
||||||
@@ -1068,7 +1041,7 @@ public class CommunitiesResource extends Resource
|
|||||||
log.warn("Community(id=" + id + ") was not found!");
|
log.warn("Community(id=" + id + ") was not found!");
|
||||||
throw new WebApplicationException(Response.Status.NOT_FOUND);
|
throw new WebApplicationException(Response.Status.NOT_FOUND);
|
||||||
}
|
}
|
||||||
else if (!AuthorizeServiceImpl.authorizeActionBoolean(context, community, action))
|
else if (!authorizeService.authorizeActionBoolean(context, community, action))
|
||||||
{
|
{
|
||||||
context.abort();
|
context.abort();
|
||||||
if (context.getCurrentUser() != null)
|
if (context.getCurrentUser() != null)
|
||||||
|
@@ -8,16 +8,21 @@
|
|||||||
package org.dspace.rest;
|
package org.dspace.rest;
|
||||||
|
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
import org.dspace.authorize.AuthorizeServiceImpl;
|
import org.dspace.authorize.factory.AuthorizeServiceFactory;
|
||||||
|
import org.dspace.authorize.service.AuthorizeService;
|
||||||
|
import org.dspace.content.factory.ContentServiceFactory;
|
||||||
|
import org.dspace.content.service.DSpaceObjectService;
|
||||||
import org.dspace.core.Constants;
|
import org.dspace.core.Constants;
|
||||||
import org.dspace.core.Context;
|
import org.dspace.handle.factory.HandleServiceFactory;
|
||||||
import org.dspace.handle.HandleServiceImpl;
|
import org.dspace.handle.service.HandleService;
|
||||||
import org.dspace.rest.common.Collection;
|
import org.dspace.rest.common.Collection;
|
||||||
import org.dspace.rest.common.Community;
|
import org.dspace.rest.common.Community;
|
||||||
import org.dspace.rest.common.DSpaceObject;
|
import org.dspace.rest.common.DSpaceObject;
|
||||||
import org.dspace.rest.common.Item;
|
import org.dspace.rest.common.Item;
|
||||||
|
import org.dspace.rest.exceptions.ContextException;
|
||||||
|
|
||||||
import javax.ws.rs.*;
|
import javax.ws.rs.*;
|
||||||
|
import javax.ws.rs.core.HttpHeaders;
|
||||||
import javax.ws.rs.core.MediaType;
|
import javax.ws.rs.core.MediaType;
|
||||||
import javax.ws.rs.core.Response;
|
import javax.ws.rs.core.Response;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
@@ -30,37 +35,43 @@ import java.sql.SQLException;
|
|||||||
* To change this template use File | Settings | File Templates.
|
* To change this template use File | Settings | File Templates.
|
||||||
*/
|
*/
|
||||||
@Path("/handle")
|
@Path("/handle")
|
||||||
public class HandleResource {
|
public class HandleResource extends Resource {
|
||||||
|
protected HandleService handleService = HandleServiceFactory.getInstance().getHandleService();
|
||||||
|
protected AuthorizeService authorizeService = AuthorizeServiceFactory.getInstance().getAuthorizeService();
|
||||||
|
|
||||||
private static Logger log = Logger.getLogger(HandleResource.class);
|
private static Logger log = Logger.getLogger(HandleResource.class);
|
||||||
private static org.dspace.core.Context context;
|
private static org.dspace.core.Context context;
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
@Path("/{prefix}/{suffix}")
|
@Path("/{prefix}/{suffix}")
|
||||||
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
|
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
|
||||||
public org.dspace.rest.common.DSpaceObject getObject(@PathParam("prefix") String prefix, @PathParam("suffix") String suffix, @QueryParam("expand") String expand) {
|
public org.dspace.rest.common.DSpaceObject getObject(@PathParam("prefix") String prefix, @PathParam("suffix") String suffix, @QueryParam("expand") String expand, @javax.ws.rs.core.Context HttpHeaders headers) {
|
||||||
|
DSpaceObject dSpaceObject = new DSpaceObject();
|
||||||
try {
|
try {
|
||||||
if(context == null || !context.isValid() ) {
|
context = createContext(getUser(headers));
|
||||||
context = new Context();
|
|
||||||
//Failed SQL is ignored as a failed SQL statement, prevent: current transaction is aborted, commands ignored until end of transaction block
|
org.dspace.content.DSpaceObject dso = handleService.resolveToObject(context, prefix + "/" + suffix);
|
||||||
context.getDBConnection().setAutoCommit(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
org.dspace.content.DSpaceObject dso = HandleServiceImpl.resolveToObject(context, prefix + "/" + suffix);
|
|
||||||
if(dso == null) {
|
if(dso == null) {
|
||||||
throw new WebApplicationException(Response.Status.NOT_FOUND);
|
throw new WebApplicationException(Response.Status.NOT_FOUND);
|
||||||
}
|
}
|
||||||
log.info("DSO Lookup by handle: [" + prefix + "] / [" + suffix + "] got result of: " + dso.getTypeText() + "_" + dso.getID());
|
DSpaceObjectService dSpaceObjectService = ContentServiceFactory.getInstance().getDSpaceObjectService(dso);
|
||||||
|
log.info("DSO Lookup by handle: [" + prefix + "] / [" + suffix + "] got result of: " + dSpaceObjectService.getTypeText(dso) + "_" + dso.getID());
|
||||||
|
|
||||||
if(AuthorizeServiceImpl.authorizeActionBoolean(context, dso, org.dspace.core.Constants.READ)) {
|
if(authorizeService.authorizeActionBoolean(context, dso, org.dspace.core.Constants.READ)) {
|
||||||
switch(dso.getType()) {
|
switch(dso.getType()) {
|
||||||
case Constants.COMMUNITY:
|
case Constants.COMMUNITY:
|
||||||
return new Community((org.dspace.content.Community) dso, expand, context);
|
dSpaceObject = new Community((org.dspace.content.Community) dso, expand, context);
|
||||||
|
return dSpaceObject;
|
||||||
case Constants.COLLECTION:
|
case Constants.COLLECTION:
|
||||||
return new Collection((org.dspace.content.Collection) dso, expand, context, null, null);
|
dSpaceObject = new Collection((org.dspace.content.Collection) dso, expand, context, null, null);
|
||||||
|
return dSpaceObject;
|
||||||
case Constants.ITEM:
|
case Constants.ITEM:
|
||||||
return new Item((org.dspace.content.Item) dso, expand, context);
|
dSpaceObject = new Item((org.dspace.content.Item) dso, expand, context);
|
||||||
|
return dSpaceObject;
|
||||||
default:
|
default:
|
||||||
return new DSpaceObject(dso);
|
dSpaceObject = new DSpaceObject(dso);
|
||||||
|
return dSpaceObject;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
throw new WebApplicationException(Response.Status.UNAUTHORIZED);
|
throw new WebApplicationException(Response.Status.UNAUTHORIZED);
|
||||||
@@ -68,6 +79,16 @@ public class HandleResource {
|
|||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
log.error(e.getMessage());
|
log.error(e.getMessage());
|
||||||
throw new WebApplicationException(Response.Status.INTERNAL_SERVER_ERROR);
|
throw new WebApplicationException(Response.Status.INTERNAL_SERVER_ERROR);
|
||||||
|
} catch (ContextException e)
|
||||||
|
{
|
||||||
|
processException("Could not read handle(prefix=" + prefix + "), (suffix=" + suffix + ") ContextException. Message:" + e.getMessage(),
|
||||||
|
context);
|
||||||
|
} finally
|
||||||
|
{
|
||||||
|
processFinally(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Not sure where I was missing a return..
|
||||||
|
return dSpaceObject;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -7,47 +7,37 @@
|
|||||||
*/
|
*/
|
||||||
package org.dspace.rest;
|
package org.dspace.rest;
|
||||||
|
|
||||||
import java.io.IOException;
|
import org.apache.log4j.Logger;
|
||||||
import java.io.InputStream;
|
import org.dspace.authorize.AuthorizeException;
|
||||||
import java.util.Date;
|
import org.dspace.authorize.factory.AuthorizeServiceFactory;
|
||||||
import java.sql.SQLException;
|
import org.dspace.authorize.service.AuthorizeService;
|
||||||
import java.util.ArrayList;
|
import org.dspace.authorize.service.ResourcePolicyService;
|
||||||
import java.util.List;
|
import org.dspace.content.Bundle;
|
||||||
|
import org.dspace.content.BundleBitstream;
|
||||||
|
import org.dspace.content.factory.ContentServiceFactory;
|
||||||
|
import org.dspace.content.service.*;
|
||||||
|
import org.dspace.eperson.factory.EPersonServiceFactory;
|
||||||
|
import org.dspace.eperson.service.GroupService;
|
||||||
|
import org.dspace.rest.common.Bitstream;
|
||||||
|
import org.dspace.rest.common.Item;
|
||||||
|
import org.dspace.rest.common.MetadataEntry;
|
||||||
|
import org.dspace.rest.exceptions.ContextException;
|
||||||
|
import org.dspace.usage.UsageEvent;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.ws.rs.Consumes;
|
import javax.ws.rs.*;
|
||||||
import javax.ws.rs.DELETE;
|
|
||||||
import javax.ws.rs.DefaultValue;
|
|
||||||
import javax.ws.rs.GET;
|
|
||||||
import javax.ws.rs.POST;
|
|
||||||
import javax.ws.rs.PUT;
|
|
||||||
import javax.ws.rs.Path;
|
|
||||||
import javax.ws.rs.PathParam;
|
|
||||||
import javax.ws.rs.Produces;
|
|
||||||
import javax.ws.rs.QueryParam;
|
|
||||||
import javax.ws.rs.WebApplicationException;
|
|
||||||
import javax.ws.rs.core.Context;
|
import javax.ws.rs.core.Context;
|
||||||
import javax.ws.rs.core.HttpHeaders;
|
import javax.ws.rs.core.HttpHeaders;
|
||||||
import javax.ws.rs.core.MediaType;
|
import javax.ws.rs.core.MediaType;
|
||||||
import javax.ws.rs.core.Response;
|
import javax.ws.rs.core.Response;
|
||||||
import javax.ws.rs.core.Response.Status;
|
import javax.ws.rs.core.Response.Status;
|
||||||
|
import java.io.IOException;
|
||||||
import org.apache.log4j.Logger;
|
import java.io.InputStream;
|
||||||
import org.dspace.authorize.AuthorizeException;
|
import java.sql.SQLException;
|
||||||
import org.dspace.authorize.AuthorizeServiceImpl;
|
import java.util.ArrayList;
|
||||||
import org.dspace.content.BitstreamFormat;
|
import java.util.Date;
|
||||||
import org.dspace.content.Bundle;
|
import java.util.Iterator;
|
||||||
import org.dspace.content.ItemIterator;
|
import java.util.List;
|
||||||
import org.dspace.content.Metadatum;
|
|
||||||
import org.dspace.content.service.ItemService;
|
|
||||||
import org.dspace.eperson.Group;
|
|
||||||
import org.dspace.rest.common.Bitstream;
|
|
||||||
import org.dspace.rest.common.Item;
|
|
||||||
import org.dspace.rest.common.MetadataEntry;
|
|
||||||
import org.dspace.rest.exceptions.ContextException;
|
|
||||||
import org.dspace.storage.rdbms.TableRow;
|
|
||||||
import org.dspace.storage.rdbms.TableRowIterator;
|
|
||||||
import org.dspace.usage.UsageEvent;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class which provide all CRUD methods over items.
|
* Class which provide all CRUD methods over items.
|
||||||
@@ -60,6 +50,14 @@ import org.dspace.usage.UsageEvent;
|
|||||||
@Path("/items")
|
@Path("/items")
|
||||||
public class ItemsResource extends Resource
|
public class ItemsResource extends Resource
|
||||||
{
|
{
|
||||||
|
protected CollectionService collectionService = ContentServiceFactory.getInstance().getCollectionService();
|
||||||
|
protected ItemService itemService = ContentServiceFactory.getInstance().getItemService();
|
||||||
|
protected AuthorizeService authorizeService = AuthorizeServiceFactory.getInstance().getAuthorizeService();
|
||||||
|
protected BitstreamService bitstreamService = ContentServiceFactory.getInstance().getBitstreamService();
|
||||||
|
protected BitstreamFormatService bitstreamFormatService = ContentServiceFactory.getInstance().getBitstreamFormatService();
|
||||||
|
protected BundleService bundleService = ContentServiceFactory.getInstance().getBundleService();
|
||||||
|
protected ResourcePolicyService resourcePolicyService = AuthorizeServiceFactory.getInstance().getResourcePolicyService();
|
||||||
|
protected GroupService groupService = EPersonServiceFactory.getInstance().getGroupService();
|
||||||
|
|
||||||
private static final Logger log = Logger.getLogger(ItemsResource.class);
|
private static final Logger log = Logger.getLogger(ItemsResource.class);
|
||||||
|
|
||||||
@@ -164,12 +162,12 @@ public class ItemsResource extends Resource
|
|||||||
{
|
{
|
||||||
context = createContext(getUser(headers));
|
context = createContext(getUser(headers));
|
||||||
|
|
||||||
ItemIterator dspaceItems = org.dspace.content.Item.findAllUnfiltered(context);
|
Iterator<org.dspace.content.Item> dspaceItems = itemService.findAllUnfiltered(context);
|
||||||
items = new ArrayList<Item>();
|
items = new ArrayList<Item>();
|
||||||
|
|
||||||
if (!((limit != null) && (limit >= 0) && (offset != null) && (offset >= 0)))
|
if (!((limit != null) && (limit >= 0) && (offset != null) && (offset >= 0)))
|
||||||
{
|
{
|
||||||
log.warn("Pagging was badly set, using default values.");
|
log.warn("Paging was badly set, using default values.");
|
||||||
limit = 100;
|
limit = 100;
|
||||||
offset = 0;
|
offset = 0;
|
||||||
}
|
}
|
||||||
@@ -179,7 +177,7 @@ public class ItemsResource extends Resource
|
|||||||
org.dspace.content.Item dspaceItem = dspaceItems.next();
|
org.dspace.content.Item dspaceItem = dspaceItems.next();
|
||||||
if (i >= offset)
|
if (i >= offset)
|
||||||
{
|
{
|
||||||
if (ItemService.isItemListedForUser(context, dspaceItem))
|
if (itemService.isItemListedForUser(context, dspaceItem))
|
||||||
{
|
{
|
||||||
items.add(new Item(dspaceItem, expand, context));
|
items.add(new Item(dspaceItem, expand, context));
|
||||||
writeStats(dspaceItem, UsageEvent.Action.VIEW, user_ip, user_agent, xforwardedfor,
|
writeStats(dspaceItem, UsageEvent.Action.VIEW, user_ip, user_agent, xforwardedfor,
|
||||||
@@ -379,10 +377,9 @@ public class ItemsResource extends Resource
|
|||||||
String data[] = mySplit(entry.getKey()); // Done by my split, because of java split was not function.
|
String data[] = mySplit(entry.getKey()); // Done by my split, because of java split was not function.
|
||||||
if ((data.length >= 2) && (data.length <= 3))
|
if ((data.length >= 2) && (data.length <= 3))
|
||||||
{
|
{
|
||||||
dspaceItem.addMetadata(data[0], data[1], data[2], entry.getLanguage(), entry.getValue());
|
itemService.addMetadata(context, dspaceItem, data[0], data[1], data[2], entry.getLanguage(), entry.getValue());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
dspaceItem.update();
|
|
||||||
context.complete();
|
context.complete();
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -390,10 +387,6 @@ public class ItemsResource extends Resource
|
|||||||
{
|
{
|
||||||
processException("Could not write metadata to item(id=" + itemId + "), SQLException. Message: " + e, context);
|
processException("Could not write metadata to item(id=" + itemId + "), SQLException. Message: " + e, context);
|
||||||
}
|
}
|
||||||
catch (AuthorizeException e)
|
|
||||||
{
|
|
||||||
processException("Could not write metadata to item(id=" + itemId + "), AuthorizeException. Message: " + e, context);
|
|
||||||
}
|
|
||||||
catch (ContextException e)
|
catch (ContextException e)
|
||||||
{
|
{
|
||||||
processException("Could not write metadata to item(id=" + itemId + "), ContextException. Message: " + e.getMessage(),
|
processException("Could not write metadata to item(id=" + itemId + "), ContextException. Message: " + e.getMessage(),
|
||||||
@@ -457,57 +450,56 @@ public class ItemsResource extends Resource
|
|||||||
log.trace("Creating bitstream in item.");
|
log.trace("Creating bitstream in item.");
|
||||||
org.dspace.content.Bundle bundle = null;
|
org.dspace.content.Bundle bundle = null;
|
||||||
org.dspace.content.Bitstream dspaceBitstream = null;
|
org.dspace.content.Bitstream dspaceBitstream = null;
|
||||||
Bundle[] bundles = dspaceItem.getBundles("ORIGINAL");
|
List<Bundle> bundles = itemService.getBundles(dspaceItem, org.dspace.core.Constants.CONTENT_BUNDLE_NAME);
|
||||||
if(bundles != null && bundles.length != 0)
|
|
||||||
|
if(bundles != null && bundles.size() != 0)
|
||||||
{
|
{
|
||||||
bundle = bundles[0]; // There should be only one bundle ORIGINAL.
|
bundle = bundles.get(0); // There should be only one bundle ORIGINAL.
|
||||||
}
|
}
|
||||||
if (bundle == null)
|
if (bundle == null)
|
||||||
{
|
{
|
||||||
log.trace("Creating bundle in item.");
|
log.trace("Creating bundle in item.");
|
||||||
dspaceBitstream = dspaceItem.createSingleBitstream(inputStream);
|
dspaceBitstream = itemService.createSingleBitstream(context, inputStream, dspaceItem);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
log.trace("Getting bundle from item.");
|
log.trace("Getting bundle from item.");
|
||||||
dspaceBitstream = bundle.createBitstream(inputStream);
|
dspaceBitstream = bitstreamService.create(context, bundle, inputStream);
|
||||||
}
|
}
|
||||||
|
|
||||||
dspaceBitstream.setSource("DSpace Rest api");
|
dspaceBitstream.setSource(context, "DSpace REST API");
|
||||||
|
|
||||||
// Set bitstream name and description
|
// Set bitstream name and description
|
||||||
if (name != null)
|
if (name != null)
|
||||||
{
|
{
|
||||||
if (BitstreamResource.getMimeType(name) == null)
|
if (BitstreamResource.getMimeType(name) == null)
|
||||||
{
|
{
|
||||||
dspaceBitstream.setFormat(BitstreamFormat.findUnknown(context));
|
dspaceBitstream.setFormat(context, bitstreamFormatService.findUnknown(context));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
dspaceBitstream.setFormat(BitstreamFormat.findByMIMEType(context, BitstreamResource.getMimeType(name)));
|
bitstreamService.setFormat(context, dspaceBitstream, bitstreamFormatService.findByMIMEType(context, BitstreamResource.getMimeType(name)));
|
||||||
}
|
}
|
||||||
dspaceBitstream.setName(name);
|
|
||||||
|
dspaceBitstream.setName(context, name);
|
||||||
}
|
}
|
||||||
if (description != null)
|
if (description != null)
|
||||||
{
|
{
|
||||||
dspaceBitstream.setDescription(description);
|
dspaceBitstream.setDescription(context, description);
|
||||||
}
|
}
|
||||||
|
|
||||||
dspaceBitstream.update();
|
|
||||||
|
|
||||||
// Create policy for bitstream
|
// Create policy for bitstream
|
||||||
if (groupId != null)
|
if (groupId != null)
|
||||||
{
|
{
|
||||||
bundles = dspaceBitstream.getBundles();
|
List<BundleBitstream> bundleBitstreams = dspaceBitstream.getBundles();
|
||||||
for (Bundle dspaceBundle : bundles)
|
for (Bundle dspaceBundle : bundles)
|
||||||
{
|
{
|
||||||
List<org.dspace.authorize.ResourcePolicy> bitstreamsPolicies = dspaceBundle.getBitstreamPolicies();
|
List<org.dspace.authorize.ResourcePolicy> bitstreamsPolicies = bundleService.getBitstreamPolicies(context, dspaceBundle);
|
||||||
|
|
||||||
// Remove default bitstream policies
|
// Remove default bitstream policies
|
||||||
List<org.dspace.authorize.ResourcePolicy> policiesToRemove = new ArrayList<org.dspace.authorize.ResourcePolicy>();
|
List<org.dspace.authorize.ResourcePolicy> policiesToRemove = new ArrayList<org.dspace.authorize.ResourcePolicy>();
|
||||||
for (org.dspace.authorize.ResourcePolicy policy : bitstreamsPolicies)
|
for (org.dspace.authorize.ResourcePolicy policy : bitstreamsPolicies) {
|
||||||
{
|
if (policy.getdSpaceObject() == dspaceBitstream)
|
||||||
if (policy.getResourceID() == dspaceBitstream.getID())
|
|
||||||
{
|
{
|
||||||
policiesToRemove.add(policy);
|
policiesToRemove.add(policy);
|
||||||
}
|
}
|
||||||
@@ -517,12 +509,10 @@ public class ItemsResource extends Resource
|
|||||||
bitstreamsPolicies.remove(policy);
|
bitstreamsPolicies.remove(policy);
|
||||||
}
|
}
|
||||||
|
|
||||||
org.dspace.authorize.ResourcePolicy dspacePolicy = org.dspace.authorize.ResourcePolicy.create(context);
|
org.dspace.authorize.ResourcePolicy dspacePolicy = resourcePolicyService.create(context);
|
||||||
dspacePolicy.setAction(org.dspace.core.Constants.READ);
|
dspacePolicy.setAction(org.dspace.core.Constants.READ);
|
||||||
dspacePolicy.setGroup(Group.find(context, groupId));
|
dspacePolicy.setGroup(groupService.findByLegacyId(context, groupId));
|
||||||
dspacePolicy.setResourceID(dspaceBitstream.getID());
|
dspacePolicy.setdSpaceObject(dspaceBitstream);
|
||||||
dspacePolicy.setResource(dspaceBitstream);
|
|
||||||
dspacePolicy.setResourceType(org.dspace.core.Constants.BITSTREAM);
|
|
||||||
if ((year != null) || (month != null) || (day != null))
|
if ((year != null) || (month != null) || (day != null))
|
||||||
{
|
{
|
||||||
Date date = new Date();
|
Date date = new Date();
|
||||||
@@ -544,12 +534,11 @@ public class ItemsResource extends Resource
|
|||||||
dspacePolicy.setStartDate(date);
|
dspacePolicy.setStartDate(date);
|
||||||
}
|
}
|
||||||
|
|
||||||
dspacePolicy.update();
|
bitstreamService.updateLastModified(context, dspaceBitstream);
|
||||||
dspaceBitstream.updateLastModified();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dspaceBitstream = org.dspace.content.Bitstream.find(context, dspaceBitstream.getID());
|
dspaceBitstream = bitstreamService.findByLegacyId(context, dspaceBitstream.getLegacyId());
|
||||||
bitstream = new Bitstream(dspaceBitstream, "", context);
|
bitstream = new Bitstream(dspaceBitstream, "", context);
|
||||||
|
|
||||||
context.complete();
|
context.complete();
|
||||||
@@ -627,7 +616,7 @@ public class ItemsResource extends Resource
|
|||||||
String data[] = mySplit(entry.getKey());
|
String data[] = mySplit(entry.getKey());
|
||||||
if ((data.length >= 2) && (data.length <= 3))
|
if ((data.length >= 2) && (data.length <= 3))
|
||||||
{
|
{
|
||||||
dspaceItem.clearMetadata(data[0], data[1], data[2], org.dspace.content.Item.ANY);
|
itemService.clearMetadata(context, dspaceItem, data[0], data[1], data[2], org.dspace.content.Item.ANY);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -637,11 +626,10 @@ public class ItemsResource extends Resource
|
|||||||
String data[] = mySplit(entry.getKey());
|
String data[] = mySplit(entry.getKey());
|
||||||
if ((data.length >= 2) && (data.length <= 3))
|
if ((data.length >= 2) && (data.length <= 3))
|
||||||
{
|
{
|
||||||
dspaceItem.addMetadata(data[0], data[1], data[2], entry.getLanguage(), entry.getValue());
|
itemService.addMetadata(context, dspaceItem, data[0], data[1], data[2], entry.getLanguage(), entry.getValue());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dspaceItem.update();
|
|
||||||
context.complete();
|
context.complete();
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -649,10 +637,6 @@ public class ItemsResource extends Resource
|
|||||||
{
|
{
|
||||||
processException("Could not update metadata in item(id=" + itemId + "), SQLException. Message: " + e, context);
|
processException("Could not update metadata in item(id=" + itemId + "), SQLException. Message: " + e, context);
|
||||||
}
|
}
|
||||||
catch (AuthorizeException e)
|
|
||||||
{
|
|
||||||
processException("Could not update metadata in item(id=" + itemId + "), AuthorizeException. Message: " + e, context);
|
|
||||||
}
|
|
||||||
catch (ContextException e)
|
catch (ContextException e)
|
||||||
{
|
{
|
||||||
processException(
|
processException(
|
||||||
@@ -704,9 +688,8 @@ public class ItemsResource extends Resource
|
|||||||
writeStats(dspaceItem, UsageEvent.Action.REMOVE, user_ip, user_agent, xforwardedfor, headers, request, context);
|
writeStats(dspaceItem, UsageEvent.Action.REMOVE, user_ip, user_agent, xforwardedfor, headers, request, context);
|
||||||
|
|
||||||
log.trace("Deleting item.");
|
log.trace("Deleting item.");
|
||||||
org.dspace.content.Collection collection = org.dspace.content.Collection.find(context,
|
org.dspace.content.Collection collection = collectionService.findByLegacyId(context, dspaceItem.getCollections().get(0).getLegacyId());
|
||||||
dspaceItem.getCollections()[0].getID());
|
collectionService.removeItem(context, collection, dspaceItem);
|
||||||
collection.removeItem(dspaceItem);
|
|
||||||
context.complete();
|
context.complete();
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -774,33 +757,27 @@ public class ItemsResource extends Resource
|
|||||||
|
|
||||||
log.trace("Deleting metadata.");
|
log.trace("Deleting metadata.");
|
||||||
// TODO Rewrite without deprecated object. Leave there only generated metadata.
|
// TODO Rewrite without deprecated object. Leave there only generated metadata.
|
||||||
Metadatum[] value = dspaceItem.getMetadata("dc", "date", "accessioned", org.dspace.content.Item.ANY);
|
|
||||||
Metadatum[] value2 = dspaceItem.getMetadata("dc", "date", "available", org.dspace.content.Item.ANY);
|
String valueAccessioned = itemService.getMetadataFirstValue(dspaceItem, "dc", "date", "accessioned", org.dspace.content.Item.ANY);
|
||||||
Metadatum[] value3 = dspaceItem.getMetadata("dc", "identifier", "uri", org.dspace.content.Item.ANY);
|
String valueAvailable = itemService.getMetadataFirstValue(dspaceItem, "dc", "date", "available", org.dspace.content.Item.ANY);
|
||||||
Metadatum[] value4 = dspaceItem.getMetadata("dc", "description", "provenance", org.dspace.content.Item.ANY);
|
String valueURI = itemService.getMetadataFirstValue(dspaceItem, "dc", "identifier", "uri", org.dspace.content.Item.ANY);
|
||||||
|
String valueProvenance = itemService.getMetadataFirstValue(dspaceItem, "dc", "description", "provenance", org.dspace.content.Item.ANY);
|
||||||
|
|
||||||
dspaceItem.clearMetadata(org.dspace.content.Item.ANY, org.dspace.content.Item.ANY, org.dspace.content.Item.ANY,
|
itemService.clearMetadata(context, dspaceItem, org.dspace.content.Item.ANY, org.dspace.content.Item.ANY, org.dspace.content.Item.ANY,
|
||||||
org.dspace.content.Item.ANY);
|
org.dspace.content.Item.ANY);
|
||||||
dspaceItem.update();
|
|
||||||
|
|
||||||
// Add there generated metadata
|
// Add their generated metadata
|
||||||
dspaceItem.addMetadata(value[0].schema, value[0].element, value[0].qualifier, null, value[0].value);
|
itemService.addMetadata(context, dspaceItem, "dc", "date", "accessioned", null, valueAccessioned);
|
||||||
dspaceItem.addMetadata(value2[0].schema, value2[0].element, value2[0].qualifier, null, value2[0].value);
|
itemService.addMetadata(context, dspaceItem, "dc", "date", "available", null, valueAvailable);
|
||||||
dspaceItem.addMetadata(value3[0].schema, value3[0].element, value3[0].qualifier, null, value3[0].value);
|
itemService.addMetadata(context, dspaceItem, "dc", "identifier", "uri", null, valueURI);
|
||||||
dspaceItem.addMetadata(value4[0].schema, value4[0].element, value4[0].qualifier, null, value4[0].value);
|
itemService.addMetadata(context, dspaceItem, "dc", "description", "provenance", null, valueProvenance);
|
||||||
|
|
||||||
dspaceItem.update();
|
|
||||||
context.complete();
|
context.complete();
|
||||||
|
|
||||||
}
|
}
|
||||||
catch (SQLException e)
|
catch (SQLException e)
|
||||||
{
|
{
|
||||||
processException("Could not delete item(id=" + itemId + "), SQLException. Message: " + e, context);
|
processException("Could not delete item(id=" + itemId + "), SQLException. Message: " + e, context);
|
||||||
}
|
}
|
||||||
catch (AuthorizeException e)
|
|
||||||
{
|
|
||||||
processException("Could not delete item(id=" + itemId + "), AuthorizeExcpetion. Message: " + e, context);
|
|
||||||
}
|
|
||||||
catch (ContextException e)
|
catch (ContextException e)
|
||||||
{
|
{
|
||||||
processException("Could not delete item(id=" + itemId + "), ContextException. Message:" + e.getMessage(), context);
|
processException("Could not delete item(id=" + itemId + "), ContextException. Message:" + e.getMessage(), context);
|
||||||
@@ -851,14 +828,14 @@ public class ItemsResource extends Resource
|
|||||||
context = createContext(getUser(headers));
|
context = createContext(getUser(headers));
|
||||||
org.dspace.content.Item item = findItem(context, itemId, org.dspace.core.Constants.WRITE);
|
org.dspace.content.Item item = findItem(context, itemId, org.dspace.core.Constants.WRITE);
|
||||||
|
|
||||||
org.dspace.content.Bitstream bitstream = org.dspace.content.Bitstream.find(context, bitstreamId);
|
org.dspace.content.Bitstream bitstream = bitstreamService.findByLegacyId(context, bitstreamId);
|
||||||
if (bitstream == null)
|
if (bitstream == null)
|
||||||
{
|
{
|
||||||
context.abort();
|
context.abort();
|
||||||
log.warn("Bitstream(id=" + bitstreamId + ") was not found.");
|
log.warn("Bitstream(id=" + bitstreamId + ") was not found.");
|
||||||
return Response.status(Status.NOT_FOUND).build();
|
return Response.status(Status.NOT_FOUND).build();
|
||||||
}
|
}
|
||||||
else if (!AuthorizeServiceImpl.authorizeActionBoolean(context, bitstream, org.dspace.core.Constants.DELETE))
|
else if (!authorizeService.authorizeActionBoolean(context, bitstream, org.dspace.core.Constants.DELETE))
|
||||||
{
|
{
|
||||||
context.abort();
|
context.abort();
|
||||||
log.error("User(" + getUser(headers).getEmail() + ") is not allowed to delete bitstream(id=" + bitstreamId + ").");
|
log.error("User(" + getUser(headers).getEmail() + ") is not allowed to delete bitstream(id=" + bitstreamId + ").");
|
||||||
@@ -872,11 +849,11 @@ public class ItemsResource extends Resource
|
|||||||
log.trace("Deleting bitstream...");
|
log.trace("Deleting bitstream...");
|
||||||
for (org.dspace.content.Bundle bundle : item.getBundles())
|
for (org.dspace.content.Bundle bundle : item.getBundles())
|
||||||
{
|
{
|
||||||
for (org.dspace.content.Bitstream bit : bundle.getBitstreams())
|
for (org.dspace.content.BundleBitstream bit : bundle.getBitstreams())
|
||||||
{
|
{
|
||||||
if (bit == bitstream)
|
if (bit.getBitstream() == bitstream)
|
||||||
{
|
{
|
||||||
bundle.removeBitstream(bitstream);
|
bundleService.removeBitstream(context, bundle, bitstream);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -915,10 +892,6 @@ public class ItemsResource extends Resource
|
|||||||
*
|
*
|
||||||
* @param metadataEntry
|
* @param metadataEntry
|
||||||
* Metadata field to search by.
|
* Metadata field to search by.
|
||||||
* @param scheme
|
|
||||||
* Scheme of metadata(key).
|
|
||||||
* @param value
|
|
||||||
* Value of metadata field.
|
|
||||||
* @param headers
|
* @param headers
|
||||||
* If you want to access the item as the user logged into context,
|
* If you want to access the item as the user logged into context,
|
||||||
* header "rest-dspace-token" must be set to token value retrieved
|
* header "rest-dspace-token" must be set to token value retrieved
|
||||||
@@ -947,72 +920,23 @@ public class ItemsResource extends Resource
|
|||||||
List<Item> items = new ArrayList<Item>();
|
List<Item> items = new ArrayList<Item>();
|
||||||
String[] metadata = mySplit(metadataEntry.getKey());
|
String[] metadata = mySplit(metadataEntry.getKey());
|
||||||
|
|
||||||
|
// Must used own style.
|
||||||
|
if ((metadata.length < 2) || (metadata.length > 3))
|
||||||
|
{
|
||||||
|
context.abort();
|
||||||
|
log.error("Finding failed, bad metadata key.");
|
||||||
|
throw new WebApplicationException(Response.Status.NOT_FOUND);
|
||||||
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
context = createContext(getUser(headers));
|
context = createContext(getUser(headers));
|
||||||
|
|
||||||
// TODO Repair, it ends by error:
|
Iterator<org.dspace.content.Item> itemIterator = itemService.findByMetadataField(context, metadataEntry.getSchema(), metadataEntry.getElement(), metadataEntry.getQualifier(), metadataEntry.getValue());
|
||||||
// "java.sql.SQLSyntaxErrorException: ORA-00932: inconsistent datatypes: expected - got CLOB"
|
|
||||||
/*
|
|
||||||
* if (metadata.length == 3){
|
|
||||||
* itemIterator = org.dspace.content.Item.findByMetadataField(context, metadata[0],
|
|
||||||
* metadata[1], metadata[2], value);
|
|
||||||
* } else if (metadata.length == 2){
|
|
||||||
* itemIterator = org.dspace.content.Item.findByMetadataField(context, metadata[0],
|
|
||||||
* metadata[1], null, value);
|
|
||||||
* } else {
|
|
||||||
* context.abort();
|
|
||||||
* log.error("Finding failed, bad metadata key.");
|
|
||||||
* throw new WebApplicationException(Response.Status.NOT_FOUND);
|
|
||||||
* }
|
|
||||||
*
|
|
||||||
* if (itemIterator.hasNext()) {
|
|
||||||
* item = new Item(itemIterator.next(), "", context);
|
|
||||||
* }
|
|
||||||
*/
|
|
||||||
|
|
||||||
// Must used own style.
|
while (itemIterator.hasNext())
|
||||||
if ((metadata.length < 2) || (metadata.length > 3))
|
|
||||||
{
|
{
|
||||||
context.abort();
|
org.dspace.content.Item dspaceItem = itemIterator.next();
|
||||||
log.error("Finding failed, bad metadata key.");
|
|
||||||
throw new WebApplicationException(Response.Status.NOT_FOUND);
|
|
||||||
}
|
|
||||||
|
|
||||||
String sql = "SELECT RESOURCE_ID, TEXT_VALUE, TEXT_LANG, SHORT_ID, ELEMENT, QUALIFIER " +
|
|
||||||
"FROM METADATAVALUE " +
|
|
||||||
"JOIN METADATAFIELDREGISTRY ON METADATAVALUE.METADATA_FIELD_ID = METADATAFIELDREGISTRY.METADATA_FIELD_ID " +
|
|
||||||
"JOIN METADATASCHEMAREGISTRY ON METADATAFIELDREGISTRY.METADATA_SCHEMA_ID = METADATASCHEMAREGISTRY.METADATA_SCHEMA_ID " +
|
|
||||||
"WHERE " +
|
|
||||||
"SHORT_ID='" + metadata[0] + "' AND " +
|
|
||||||
"ELEMENT='" + metadata[1] + "' AND ";
|
|
||||||
if (metadata.length > 3)
|
|
||||||
{
|
|
||||||
sql += "QUALIFIER='" + metadata[2] + "' AND ";
|
|
||||||
}
|
|
||||||
if (org.dspace.storage.rdbms.DatabaseManager.isOracle())
|
|
||||||
{
|
|
||||||
sql += "dbms_lob.compare(TEXT_VALUE, '" + metadataEntry.getValue() + "') = 0 AND ";
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
sql += "TEXT_VALUE='" + metadataEntry.getValue() + "' AND ";
|
|
||||||
}
|
|
||||||
if (metadataEntry.getLanguage() != null)
|
|
||||||
{
|
|
||||||
sql += "TEXT_LANG='" + metadataEntry.getLanguage() + "'";
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
sql += "TEXT_LANG is null";
|
|
||||||
}
|
|
||||||
|
|
||||||
TableRowIterator iterator = org.dspace.storage.rdbms.DatabaseManager.query(context, sql);
|
|
||||||
while (iterator.hasNext())
|
|
||||||
{
|
|
||||||
TableRow row = iterator.next();
|
|
||||||
org.dspace.content.Item dspaceItem = this.findItem(context, row.getIntColumn("RESOURCE_ID"),
|
|
||||||
org.dspace.core.Constants.READ);
|
|
||||||
Item item = new Item(dspaceItem, "", context);
|
Item item = new Item(dspaceItem, "", context);
|
||||||
writeStats(dspaceItem, UsageEvent.Action.VIEW, user_ip, user_agent, xforwardedfor, headers,
|
writeStats(dspaceItem, UsageEvent.Action.VIEW, user_ip, user_agent, xforwardedfor, headers,
|
||||||
request, context);
|
request, context);
|
||||||
@@ -1020,7 +944,6 @@ public class ItemsResource extends Resource
|
|||||||
}
|
}
|
||||||
|
|
||||||
context.complete();
|
context.complete();
|
||||||
|
|
||||||
}
|
}
|
||||||
catch (SQLException e)
|
catch (SQLException e)
|
||||||
{
|
{
|
||||||
@@ -1029,8 +952,11 @@ public class ItemsResource extends Resource
|
|||||||
catch (ContextException e)
|
catch (ContextException e)
|
||||||
{
|
{
|
||||||
processException("Context error:" + e.getMessage(), context);
|
processException("Context error:" + e.getMessage(), context);
|
||||||
}
|
} catch (AuthorizeException e) {
|
||||||
finally
|
processException("Authorize error:" + e.getMessage(), context);
|
||||||
|
} catch (IOException e) {
|
||||||
|
processException("IO error:" + e.getMessage(), context);
|
||||||
|
} finally
|
||||||
{
|
{
|
||||||
processFinally(context);
|
processFinally(context);
|
||||||
}
|
}
|
||||||
@@ -1068,7 +994,7 @@ public class ItemsResource extends Resource
|
|||||||
org.dspace.content.Item item = null;
|
org.dspace.content.Item item = null;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
item = org.dspace.content.Item.find(context, id);
|
item = itemService.findByLegacyId(context, id);
|
||||||
|
|
||||||
if (item == null)
|
if (item == null)
|
||||||
{
|
{
|
||||||
@@ -1076,7 +1002,7 @@ public class ItemsResource extends Resource
|
|||||||
log.warn("Item(id=" + id + ") was not found!");
|
log.warn("Item(id=" + id + ") was not found!");
|
||||||
throw new WebApplicationException(Response.Status.NOT_FOUND);
|
throw new WebApplicationException(Response.Status.NOT_FOUND);
|
||||||
}
|
}
|
||||||
else if (!AuthorizeServiceImpl.authorizeActionBoolean(context, item, action))
|
else if (!authorizeService.authorizeActionBoolean(context, item, action))
|
||||||
{
|
{
|
||||||
context.abort();
|
context.abort();
|
||||||
if (context.getCurrentUser() != null)
|
if (context.getCurrentUser() != null)
|
||||||
|
@@ -7,7 +7,6 @@
|
|||||||
*/
|
*/
|
||||||
package org.dspace.rest;
|
package org.dspace.rest;
|
||||||
|
|
||||||
import java.sql.SQLException;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -71,29 +70,15 @@ public class Resource
|
|||||||
*/
|
*/
|
||||||
protected static org.dspace.core.Context createContext(EPerson person) throws ContextException
|
protected static org.dspace.core.Context createContext(EPerson person) throws ContextException
|
||||||
{
|
{
|
||||||
|
org.dspace.core.Context context = new org.dspace.core.Context();
|
||||||
|
//context.getDBConnection().setAutoCommit(false); // Disable autocommit.
|
||||||
|
|
||||||
org.dspace.core.Context context = null;
|
if (person != null)
|
||||||
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
context = new org.dspace.core.Context();
|
context.setCurrentUser(person);
|
||||||
context.getDBConnection().setAutoCommit(false); // Disable autocommit.
|
|
||||||
|
|
||||||
if (person != null)
|
|
||||||
{
|
|
||||||
context.setCurrentUser(person);
|
|
||||||
}
|
|
||||||
|
|
||||||
return context;
|
|
||||||
}
|
|
||||||
catch (SQLException e)
|
|
||||||
{
|
|
||||||
if ((context != null) && (context.isValid()))
|
|
||||||
{
|
|
||||||
context.abort();
|
|
||||||
}
|
|
||||||
throw new ContextException("Could not create context, SQLException. Message: " + e, e);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return context;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -23,8 +23,9 @@ import javax.ws.rs.core.MediaType;
|
|||||||
import javax.ws.rs.core.Response;
|
import javax.ws.rs.core.Response;
|
||||||
|
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
import org.dspace.authorize.AuthorizeException;
|
|
||||||
import org.dspace.eperson.EPerson;
|
import org.dspace.eperson.EPerson;
|
||||||
|
import org.dspace.eperson.factory.EPersonServiceFactory;
|
||||||
|
import org.dspace.eperson.service.EPersonService;
|
||||||
import org.dspace.rest.common.Status;
|
import org.dspace.rest.common.Status;
|
||||||
import org.dspace.rest.common.User;
|
import org.dspace.rest.common.User;
|
||||||
import org.dspace.rest.exceptions.ContextException;
|
import org.dspace.rest.exceptions.ContextException;
|
||||||
@@ -38,6 +39,7 @@ import org.dspace.rest.exceptions.ContextException;
|
|||||||
*/
|
*/
|
||||||
@Path("/")
|
@Path("/")
|
||||||
public class RestIndex {
|
public class RestIndex {
|
||||||
|
protected EPersonService epersonService = EPersonServiceFactory.getInstance().getEPersonService();
|
||||||
private static Logger log = Logger.getLogger(RestIndex.class);
|
private static Logger log = Logger.getLogger(RestIndex.class);
|
||||||
|
|
||||||
@javax.ws.rs.core.Context public static ServletContext servletContext;
|
@javax.ws.rs.core.Context public static ServletContext servletContext;
|
||||||
@@ -212,7 +214,7 @@ public class RestIndex {
|
|||||||
|
|
||||||
if(ePerson != null) {
|
if(ePerson != null) {
|
||||||
//DB EPerson needed since token won't have full info, need context
|
//DB EPerson needed since token won't have full info, need context
|
||||||
EPerson dbEPerson = EPerson.findByEmail(context, ePerson.getEmail());
|
EPerson dbEPerson = epersonService.findByEmail(context, ePerson.getEmail());
|
||||||
String token = Resource.getToken(headers);
|
String token = Resource.getToken(headers);
|
||||||
Status status = new Status(dbEPerson.getEmail(), dbEPerson.getFullName(), token);
|
Status status = new Status(dbEPerson.getEmail(), dbEPerson.getFullName(), token);
|
||||||
return status;
|
return status;
|
||||||
@@ -223,8 +225,6 @@ public class RestIndex {
|
|||||||
Resource.processException("Status context error: " + e.getMessage(), context);
|
Resource.processException("Status context error: " + e.getMessage(), context);
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
Resource.processException("Status eperson db lookup error: " + e.getMessage(), context);
|
Resource.processException("Status eperson db lookup error: " + e.getMessage(), context);
|
||||||
} catch (AuthorizeException e) {
|
|
||||||
Resource.processException("Status eperson authorize exception: " + e.getMessage(), context);
|
|
||||||
} finally {
|
} finally {
|
||||||
context.abort();
|
context.abort();
|
||||||
}
|
}
|
||||||
|
@@ -16,8 +16,13 @@ import javax.ws.rs.WebApplicationException;
|
|||||||
import javax.ws.rs.core.Response;
|
import javax.ws.rs.core.Response;
|
||||||
|
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
|
import org.dspace.authenticate.AuthenticationMethod;
|
||||||
|
import org.dspace.authenticate.factory.AuthenticateServiceFactory;
|
||||||
|
import org.dspace.authenticate.service.AuthenticationService;
|
||||||
import org.dspace.authorize.AuthorizeException;
|
import org.dspace.authorize.AuthorizeException;
|
||||||
import org.dspace.eperson.EPerson;
|
import org.dspace.eperson.EPerson;
|
||||||
|
import org.dspace.eperson.factory.EPersonServiceFactory;
|
||||||
|
import org.dspace.eperson.service.EPersonService;
|
||||||
import org.dspace.rest.common.User;
|
import org.dspace.rest.common.User;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -30,6 +35,7 @@ import org.dspace.rest.common.User;
|
|||||||
public class TokenHolder
|
public class TokenHolder
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
private static final Logger log = Logger.getLogger(TokenHolder.class);
|
private static final Logger log = Logger.getLogger(TokenHolder.class);
|
||||||
|
|
||||||
public static String TOKEN_HEADER = "rest-dspace-token";
|
public static String TOKEN_HEADER = "rest-dspace-token";
|
||||||
@@ -53,32 +59,31 @@ public class TokenHolder
|
|||||||
*/
|
*/
|
||||||
public static String login(User user) throws WebApplicationException
|
public static String login(User user) throws WebApplicationException
|
||||||
{
|
{
|
||||||
|
AuthenticationService authenticationService = AuthenticateServiceFactory.getInstance().getAuthenticationService();
|
||||||
|
EPersonService epersonService = EPersonServiceFactory.getInstance().getEPersonService();
|
||||||
|
|
||||||
org.dspace.core.Context context = null;
|
org.dspace.core.Context context = null;
|
||||||
String token = null;
|
String token = null;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
context = new org.dspace.core.Context();
|
context = new org.dspace.core.Context();
|
||||||
EPerson dspaceUser = EPerson.findByEmail(context, user.getEmail());
|
|
||||||
|
|
||||||
if ((dspaceUser == null) || (!dspaceUser.checkPassword(user.getPassword())))
|
int status = authenticationService.authenticate(context, user.getEmail(), user.getPassword(), null, null);
|
||||||
|
if (status == AuthenticationMethod.SUCCESS)
|
||||||
{
|
{
|
||||||
token = null;
|
EPerson ePerson = epersonService.findByEmail(context, user.getEmail());
|
||||||
}
|
if(tokens.containsKey(ePerson.getEmail())) {
|
||||||
else if (tokens.containsKey(user.getEmail()))
|
token = tokens.get(ePerson.getEmail());
|
||||||
{
|
} else {
|
||||||
token = tokens.get(user.getEmail());
|
token = generateToken();
|
||||||
}
|
persons.put(token, ePerson);
|
||||||
else
|
tokens.put(ePerson.getEmail(), token);
|
||||||
{
|
}
|
||||||
token = generateToken();
|
|
||||||
persons.put(token, dspaceUser);
|
|
||||||
tokens.put(user.getEmail(), token);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
log.trace("User(" + user.getEmail() + ") has been logged.");
|
log.trace("User(" + user.getEmail() + ") has been logged in.");
|
||||||
context.complete();
|
context.complete();
|
||||||
|
|
||||||
}
|
}
|
||||||
catch (SQLException e)
|
catch (SQLException e)
|
||||||
{
|
{
|
||||||
@@ -86,12 +91,6 @@ public class TokenHolder
|
|||||||
log.error("Could not read user from database. Message:" + e);
|
log.error("Could not read user from database. Message:" + e);
|
||||||
throw new WebApplicationException(Response.Status.INTERNAL_SERVER_ERROR);
|
throw new WebApplicationException(Response.Status.INTERNAL_SERVER_ERROR);
|
||||||
}
|
}
|
||||||
catch (AuthorizeException e)
|
|
||||||
{
|
|
||||||
context.abort();
|
|
||||||
log.error("Could not find user, AuthorizeException. Message:" + e);
|
|
||||||
throw new WebApplicationException(Response.Status.INTERNAL_SERVER_ERROR);
|
|
||||||
}
|
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
if ((context != null) && (context.isValid()))
|
if ((context != null) && (context.isValid()))
|
||||||
|
@@ -16,9 +16,6 @@ import org.dspace.content.Bundle;
|
|||||||
import org.dspace.content.MetadataField;
|
import org.dspace.content.MetadataField;
|
||||||
import org.dspace.content.MetadataValue;
|
import org.dspace.content.MetadataValue;
|
||||||
import org.dspace.content.factory.ContentServiceFactory;
|
import org.dspace.content.factory.ContentServiceFactory;
|
||||||
import org.dspace.content.service.BitstreamService;
|
|
||||||
import org.dspace.content.service.BundleService;
|
|
||||||
import org.dspace.content.service.CollectionService;
|
|
||||||
import org.dspace.content.service.ItemService;
|
import org.dspace.content.service.ItemService;
|
||||||
import org.dspace.core.Context;
|
import org.dspace.core.Context;
|
||||||
|
|
||||||
|
@@ -8,6 +8,7 @@
|
|||||||
package org.dspace.rest.common;
|
package org.dspace.rest.common;
|
||||||
|
|
||||||
import javax.xml.bind.annotation.XmlRootElement;
|
import javax.xml.bind.annotation.XmlRootElement;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author peterdietz, Rostislav Novak (Computing and Information Centre, CTU in
|
* @author peterdietz, Rostislav Novak (Computing and Information Centre, CTU in
|
||||||
@@ -64,4 +65,23 @@ public class MetadataEntry
|
|||||||
this.language = language;
|
this.language = language;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getSchema() {
|
||||||
|
String[] fieldPieces = key.split(Pattern.quote("."));
|
||||||
|
return fieldPieces[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getElement() {
|
||||||
|
String[] fieldPieces = key.split(Pattern.quote("."));
|
||||||
|
return fieldPieces[1];
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getQualifier() {
|
||||||
|
String[] fieldPieces = key.split(Pattern.quote("."));
|
||||||
|
if(fieldPieces.length == 3) {
|
||||||
|
return fieldPieces[2];
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user