mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-12 12:33:18 +00:00
Formated source and better method for finding item.
All source is formated by DSpace code formater. Better method for searching item by metadata field. Changed to SQL select, because is more faster.
This commit is contained in:
@@ -50,9 +50,11 @@ import org.dspace.usage.UsageEvent;
|
|||||||
/**
|
/**
|
||||||
* @author Rostislav Novak (Computing and Information Centre, CTU in Prague)
|
* @author Rostislav Novak (Computing and Information Centre, CTU in Prague)
|
||||||
*/
|
*/
|
||||||
//Every DSpace class used without namespace is from package org.dspace.rest.common.*. Otherwise namespace is defined.
|
// Every DSpace class used without namespace is from package
|
||||||
|
// org.dspace.rest.common.*. Otherwise namespace is defined.
|
||||||
@Path("/bitstreams")
|
@Path("/bitstreams")
|
||||||
public class BitstreamResource extends Resource{
|
public class BitstreamResource extends Resource
|
||||||
|
{
|
||||||
|
|
||||||
private static Logger log = Logger.getLogger(BitstreamResource.class);
|
private static Logger log = Logger.getLogger(BitstreamResource.class);
|
||||||
|
|
||||||
@@ -83,32 +85,42 @@ public class BitstreamResource extends Resource{
|
|||||||
*/
|
*/
|
||||||
@GET
|
@GET
|
||||||
@Path("/{bitstream_id}")
|
@Path("/{bitstream_id}")
|
||||||
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
|
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
|
||||||
public Bitstream getBitstream(
|
public Bitstream getBitstream(@PathParam("bitstream_id") Integer bitstreamId, @QueryParam("expand") String expand,
|
||||||
@PathParam("bitstream_id") Integer bitstreamId, @QueryParam("expand") String expand,
|
|
||||||
@QueryParam("userIP") String user_ip, @QueryParam("userAgent") String user_agent,
|
@QueryParam("userIP") String user_ip, @QueryParam("userAgent") String user_agent,
|
||||||
@QueryParam("xforwarderfor") String xforwarderfor, @Context HttpHeaders headers,
|
@QueryParam("xforwarderfor") String xforwarderfor, @Context HttpHeaders headers, @Context HttpServletRequest request)
|
||||||
@Context HttpServletRequest request) throws WebApplicationException {
|
throws WebApplicationException
|
||||||
|
{
|
||||||
|
|
||||||
log.info("Reading bitstream(id=" + bitstreamId + ") metadata.");
|
log.info("Reading bitstream(id=" + bitstreamId + ") metadata.");
|
||||||
org.dspace.core.Context context = null;
|
org.dspace.core.Context context = null;
|
||||||
Bitstream bitstream = null;
|
Bitstream bitstream = null;
|
||||||
|
|
||||||
try {
|
try
|
||||||
|
{
|
||||||
context = createContext(getUser(headers));
|
context = createContext(getUser(headers));
|
||||||
org.dspace.content.Bitstream dspaceBitstream = findBitstream(context, bitstreamId, org.dspace.core.Constants.READ);
|
org.dspace.content.Bitstream dspaceBitstream = findBitstream(context, bitstreamId, org.dspace.core.Constants.READ);
|
||||||
|
|
||||||
writeStats(Constants.BITSTREAM, dspaceBitstream, UsageEvent.Action.VIEW, user_ip, user_agent, xforwarderfor, headers, request);
|
writeStats(Constants.BITSTREAM, dspaceBitstream, UsageEvent.Action.VIEW, user_ip, user_agent, xforwarderfor, headers,
|
||||||
|
request);
|
||||||
|
|
||||||
bitstream = new Bitstream(dspaceBitstream, expand);
|
bitstream = new Bitstream(dspaceBitstream, expand);
|
||||||
context.complete();
|
context.complete();
|
||||||
log.trace("Bitsream(id=" + bitstreamId + ") was successfully read.");
|
log.trace("Bitsream(id=" + bitstreamId + ") was successfully read.");
|
||||||
|
|
||||||
} catch (SQLException e) {
|
}
|
||||||
processException("Someting went wrong while reading bitstream(id=" + bitstreamId + ") from database! Message: " + e,context);
|
catch (SQLException e)
|
||||||
} catch (ContextException e) {
|
{
|
||||||
processException("Someting went wrong while reading bitstream(id=" + bitstreamId + "), ContextException. Message: " + e.getMessage(), context);
|
processException("Someting went wrong while reading bitstream(id=" + bitstreamId + ") from database! Message: " + e,
|
||||||
} finally {
|
context);
|
||||||
|
}
|
||||||
|
catch (ContextException e)
|
||||||
|
{
|
||||||
|
processException("Someting went wrong while reading bitstream(id=" + bitstreamId + "), ContextException. Message: "
|
||||||
|
+ e.getMessage(), context);
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
context.abort();
|
context.abort();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -130,21 +142,26 @@ public class BitstreamResource extends Resource{
|
|||||||
@GET
|
@GET
|
||||||
@Path("/{bitstream_id}/policy")
|
@Path("/{bitstream_id}/policy")
|
||||||
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
|
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
|
||||||
public ResourcePolicy[] getBitstreamPolicies(@PathParam("bitstream_id") Integer bitstreamId, @Context HttpHeaders headers) {
|
public ResourcePolicy[] getBitstreamPolicies(@PathParam("bitstream_id") Integer bitstreamId, @Context HttpHeaders headers)
|
||||||
|
{
|
||||||
|
|
||||||
log.info("Reading bitstream(id=" + bitstreamId + ") policies.");
|
log.info("Reading bitstream(id=" + bitstreamId + ") policies.");
|
||||||
org.dspace.core.Context context = null;
|
org.dspace.core.Context context = null;
|
||||||
List<ResourcePolicy> policies = new ArrayList<ResourcePolicy>();
|
List<ResourcePolicy> policies = new ArrayList<ResourcePolicy>();
|
||||||
|
|
||||||
try {
|
try
|
||||||
|
{
|
||||||
context = createContext(getUser(headers));
|
context = createContext(getUser(headers));
|
||||||
org.dspace.content.Bitstream dspaceBitstream = findBitstream(context, bitstreamId, org.dspace.core.Constants.READ);
|
org.dspace.content.Bitstream dspaceBitstream = findBitstream(context, bitstreamId, org.dspace.core.Constants.READ);
|
||||||
|
|
||||||
Bundle[] bundles = dspaceBitstream.getBundles();
|
Bundle[] bundles = dspaceBitstream.getBundles();
|
||||||
for (Bundle bundle : bundles) {
|
for (Bundle bundle : bundles)
|
||||||
|
{
|
||||||
List<org.dspace.authorize.ResourcePolicy> bitstreamsPolicies = bundle.getBitstreamPolicies();
|
List<org.dspace.authorize.ResourcePolicy> bitstreamsPolicies = bundle.getBitstreamPolicies();
|
||||||
for (org.dspace.authorize.ResourcePolicy policy : bitstreamsPolicies) {
|
for (org.dspace.authorize.ResourcePolicy policy : bitstreamsPolicies)
|
||||||
if (policy.getResourceID() == bitstreamId) {
|
{
|
||||||
|
if (policy.getResourceID() == bitstreamId)
|
||||||
|
{
|
||||||
policies.add(new ResourcePolicy(policy));
|
policies.add(new ResourcePolicy(policy));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -152,11 +169,19 @@ public class BitstreamResource extends Resource{
|
|||||||
context.complete();
|
context.complete();
|
||||||
log.trace("Policies for bitsream(id=" + bitstreamId + ") was successfully read.");
|
log.trace("Policies for bitsream(id=" + bitstreamId + ") was successfully read.");
|
||||||
|
|
||||||
} catch (SQLException e) {
|
}
|
||||||
processException("Someting went wrong while reading policies of bitstream(id=" + bitstreamId + "), SQLException! Message: " + e, context);
|
catch (SQLException e)
|
||||||
} catch (ContextException e) {
|
{
|
||||||
processException("Someting went wrong while reading policies of bitstream(id=" + bitstreamId + "), ContextException. Message: " + e.getMessage(), context);
|
processException("Someting went wrong while reading policies of bitstream(id=" + bitstreamId
|
||||||
} finally {
|
+ "), SQLException! Message: " + e, context);
|
||||||
|
}
|
||||||
|
catch (ContextException e)
|
||||||
|
{
|
||||||
|
processException("Someting went wrong while reading policies of bitstream(id=" + bitstreamId
|
||||||
|
+ "), ContextException. Message: " + e.getMessage(), context);
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
context.abort();
|
context.abort();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -183,35 +208,41 @@ public class BitstreamResource extends Resource{
|
|||||||
* creating context.
|
* creating context.
|
||||||
*/
|
*/
|
||||||
@GET
|
@GET
|
||||||
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
|
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
|
||||||
public Bitstream[] getBitstreams(
|
public Bitstream[] getBitstreams(@QueryParam("expand") String expand,
|
||||||
@QueryParam("expand") String expand,
|
@QueryParam("limit") @DefaultValue("100") Integer limit, @QueryParam("offset") @DefaultValue("0") Integer offset,
|
||||||
@QueryParam("limit") @DefaultValue("100") Integer limit,
|
|
||||||
@QueryParam("offset") @DefaultValue("0") Integer offset,
|
|
||||||
@QueryParam("userIP") String user_ip, @QueryParam("userAgent") String user_agent,
|
@QueryParam("userIP") String user_ip, @QueryParam("userAgent") String user_agent,
|
||||||
@QueryParam("xforwarderfor") String xforwarderfor, @Context HttpHeaders headers,
|
@QueryParam("xforwarderfor") String xforwarderfor, @Context HttpHeaders headers, @Context HttpServletRequest request)
|
||||||
@Context HttpServletRequest request) throws WebApplicationException {
|
throws WebApplicationException
|
||||||
|
{
|
||||||
|
|
||||||
log.info("Reading bitstreams.(offset=" + offset + ",limit=" + limit + ")");
|
log.info("Reading bitstreams.(offset=" + offset + ",limit=" + limit + ")");
|
||||||
org.dspace.core.Context context = null;
|
org.dspace.core.Context context = null;
|
||||||
List<Bitstream> bitstreams = new ArrayList<Bitstream>();
|
List<Bitstream> bitstreams = new ArrayList<Bitstream>();
|
||||||
|
|
||||||
try {
|
try
|
||||||
|
{
|
||||||
context = createContext(getUser(headers));
|
context = createContext(getUser(headers));
|
||||||
org.dspace.content.Bitstream[] dspaceBitstreams = org.dspace.content.Bitstream.findAll(context);
|
org.dspace.content.Bitstream[] dspaceBitstreams = org.dspace.content.Bitstream.findAll(context);
|
||||||
|
|
||||||
if (!((limit != null) && (limit >= 0) && (offset != null) && (offset >= 0))) {
|
if (!((limit != null) && (limit >= 0) && (offset != null) && (offset >= 0)))
|
||||||
|
{
|
||||||
log.warn("Pagging was badly set.");
|
log.warn("Pagging was badly set.");
|
||||||
limit = 100;
|
limit = 100;
|
||||||
offset = 0;
|
offset = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO If bitsream doesnt not exist it throw exception.
|
// TODO If bitsream doesnt not exist it throw exception.
|
||||||
for (int i = offset; (i < (offset+limit)) && (i < dspaceBitstreams.length); i++) {
|
for (int i = offset; (i < (offset + limit)) && (i < dspaceBitstreams.length); i++)
|
||||||
if (AuthorizeManager.authorizeActionBoolean(context, dspaceBitstreams[i], org.dspace.core.Constants.READ)) {
|
{
|
||||||
if (dspaceBitstreams[i].getParentObject() != null) { // To eliminate bitstreams which cause exception, because reading under administrator permissions
|
if (AuthorizeManager.authorizeActionBoolean(context, dspaceBitstreams[i], org.dspace.core.Constants.READ))
|
||||||
|
{
|
||||||
|
if (dspaceBitstreams[i].getParentObject() != null)
|
||||||
|
{ // To eliminate bitstreams which cause exception, because of
|
||||||
|
// reading under administrator permissions
|
||||||
bitstreams.add(new Bitstream(dspaceBitstreams[i], expand));
|
bitstreams.add(new Bitstream(dspaceBitstreams[i], expand));
|
||||||
writeStats(Constants.BITSTREAM, dspaceBitstreams[i], UsageEvent.Action.VIEW, user_ip, user_agent, xforwarderfor, headers, request);
|
writeStats(Constants.BITSTREAM, dspaceBitstreams[i], UsageEvent.Action.VIEW, user_ip, user_agent,
|
||||||
|
xforwarderfor, headers, request);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -219,11 +250,18 @@ public class BitstreamResource extends Resource{
|
|||||||
context.complete();
|
context.complete();
|
||||||
log.trace("Bitstreams were successfully read.");
|
log.trace("Bitstreams were successfully read.");
|
||||||
|
|
||||||
} catch (SQLException e) {
|
}
|
||||||
|
catch (SQLException e)
|
||||||
|
{
|
||||||
processException("Something get wrong while reading bitstreams from database!. Message: " + e, context);
|
processException("Something get wrong while reading bitstreams from database!. Message: " + e, context);
|
||||||
} catch (ContextException e) {
|
}
|
||||||
processException("Something get wrong while reading bitstreams, ContextException. Message: " + e.getMessage(), context);
|
catch (ContextException e)
|
||||||
} finally {
|
{
|
||||||
|
processException("Something get wrong while reading bitstreams, ContextException. Message: " + e.getMessage(),
|
||||||
|
context);
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
context.abort();
|
context.abort();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -254,20 +292,22 @@ public class BitstreamResource extends Resource{
|
|||||||
*/
|
*/
|
||||||
@POST
|
@POST
|
||||||
@Path("/{bitstream_id}/retrieve")
|
@Path("/{bitstream_id}/retrieve")
|
||||||
public javax.ws.rs.core.Response getBitstreamData(
|
public javax.ws.rs.core.Response getBitstreamData(@PathParam("bitstream_id") Integer bitstreamId,
|
||||||
@PathParam("bitstream_id") Integer bitstreamId,
|
|
||||||
@QueryParam("userIP") String user_ip, @QueryParam("userAgent") String user_agent,
|
@QueryParam("userIP") String user_ip, @QueryParam("userAgent") String user_agent,
|
||||||
@QueryParam("xforwarderfor") String xforwarderfor, @Context HttpHeaders headers,
|
@QueryParam("xforwarderfor") String xforwarderfor, @Context HttpHeaders headers, @Context HttpServletRequest request)
|
||||||
@Context HttpServletRequest request) throws WebApplicationException {
|
throws WebApplicationException
|
||||||
|
{
|
||||||
|
|
||||||
log.info("Reading data of bitstream(id=" + bitstreamId + ").");
|
log.info("Reading data of bitstream(id=" + bitstreamId + ").");
|
||||||
org.dspace.core.Context context = null;
|
org.dspace.core.Context context = null;
|
||||||
|
|
||||||
try {
|
try
|
||||||
|
{
|
||||||
context = createContext(getUser(headers));
|
context = createContext(getUser(headers));
|
||||||
org.dspace.content.Bitstream dspaceBitstream = findBitstream(context, bitstreamId, org.dspace.core.Constants.READ);
|
org.dspace.content.Bitstream dspaceBitstream = findBitstream(context, bitstreamId, org.dspace.core.Constants.READ);
|
||||||
|
|
||||||
writeStats(Constants.BITSTREAM, dspaceBitstream, UsageEvent.Action.VIEW, user_ip, user_agent, xforwarderfor, headers, request);
|
writeStats(Constants.BITSTREAM, dspaceBitstream, UsageEvent.Action.VIEW, user_ip, user_agent, xforwarderfor, headers,
|
||||||
|
request);
|
||||||
|
|
||||||
log.trace("Bitsream(id=" + bitstreamId + ") data was successfully read.");
|
log.trace("Bitsream(id=" + bitstreamId + ") data was successfully read.");
|
||||||
InputStream inputStream = dspaceBitstream.retrieve();
|
InputStream inputStream = dspaceBitstream.retrieve();
|
||||||
@@ -277,15 +317,29 @@ public class BitstreamResource extends Resource{
|
|||||||
|
|
||||||
return Response.ok(inputStream).type(type).build();
|
return Response.ok(inputStream).type(type).build();
|
||||||
|
|
||||||
} catch (IOException e) {
|
}
|
||||||
processException("Could not read file of bitstream(id="+ bitstreamId + ")! Message: " + e, context);
|
catch (IOException e)
|
||||||
} catch (SQLException e) {
|
{
|
||||||
processException("Something get wrong while reading bitsream(id=" + bitstreamId + ") from database! Message: " + e, context);
|
processException("Could not read file of bitstream(id=" + bitstreamId + ")! Message: " + e, context);
|
||||||
} catch (AuthorizeException e) {
|
}
|
||||||
processException("Could not retrieve file of bitstream(id=" + bitstreamId + "), AuthorizeException! Message: " + e, context);
|
catch (SQLException e)
|
||||||
} catch (ContextException e) {
|
{
|
||||||
processException("Could not retrieve file of bitstream(id=" + bitstreamId + "), ContextException! Message: " + e.getMessage(), context);
|
processException("Something get wrong while reading bitsream(id=" + bitstreamId + ") from database! Message: " + e,
|
||||||
} finally {
|
context);
|
||||||
|
}
|
||||||
|
catch (AuthorizeException e)
|
||||||
|
{
|
||||||
|
processException("Could not retrieve file of bitstream(id=" + bitstreamId + "), AuthorizeException! Message: " + e,
|
||||||
|
context);
|
||||||
|
}
|
||||||
|
catch (ContextException e)
|
||||||
|
{
|
||||||
|
processException(
|
||||||
|
"Could not retrieve file of bitstream(id=" + bitstreamId + "), ContextException! Message: " + e.getMessage(),
|
||||||
|
context);
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
context.abort();
|
context.abort();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -308,18 +362,23 @@ public class BitstreamResource extends Resource{
|
|||||||
*/
|
*/
|
||||||
@POST
|
@POST
|
||||||
@Path("/{bitstream_id}/policy")
|
@Path("/{bitstream_id}/policy")
|
||||||
public javax.ws.rs.core.Response addBitstreamPolicy(@PathParam("bitstream_id") Integer bitstreamId, ResourcePolicy policy, @Context HttpHeaders headers) {
|
public javax.ws.rs.core.Response addBitstreamPolicy(@PathParam("bitstream_id") Integer bitstreamId, ResourcePolicy policy,
|
||||||
|
@Context HttpHeaders headers)
|
||||||
|
{
|
||||||
|
|
||||||
log.info("Adding bitstream(id=" + bitstreamId + ") READ policy with permission for group(id=" + policy.getGroupId() + ").");
|
log.info("Adding bitstream(id=" + bitstreamId + ") READ policy with permission for group(id=" + policy.getGroupId()
|
||||||
|
+ ").");
|
||||||
org.dspace.core.Context context = null;
|
org.dspace.core.Context context = null;
|
||||||
|
|
||||||
try {
|
try
|
||||||
|
{
|
||||||
context = createContext(getUser(headers));
|
context = createContext(getUser(headers));
|
||||||
org.dspace.content.Bitstream dspaceBitstream = findBitstream(context, bitstreamId, org.dspace.core.Constants.READ);
|
org.dspace.content.Bitstream dspaceBitstream = findBitstream(context, bitstreamId, org.dspace.core.Constants.READ);
|
||||||
|
|
||||||
Bundle[] bundles = dspaceBitstream.getBundles();
|
Bundle[] bundles = dspaceBitstream.getBundles();
|
||||||
|
|
||||||
for (Bundle bundle : bundles) {
|
for (Bundle bundle : bundles)
|
||||||
|
{
|
||||||
List<org.dspace.authorize.ResourcePolicy> bitstreamsPolicies = bundle.getBitstreamPolicies();
|
List<org.dspace.authorize.ResourcePolicy> bitstreamsPolicies = bundle.getBitstreamPolicies();
|
||||||
|
|
||||||
org.dspace.authorize.ResourcePolicy dspacePolicy = org.dspace.authorize.ResourcePolicy.create(context);
|
org.dspace.authorize.ResourcePolicy dspacePolicy = org.dspace.authorize.ResourcePolicy.create(context);
|
||||||
@@ -333,7 +392,7 @@ public class BitstreamResource extends Resource{
|
|||||||
dspacePolicy.setRpDescription(policy.getRpDescription());
|
dspacePolicy.setRpDescription(policy.getRpDescription());
|
||||||
dspacePolicy.setRpName(policy.getRpName());
|
dspacePolicy.setRpName(policy.getRpName());
|
||||||
dspacePolicy.update();
|
dspacePolicy.update();
|
||||||
//dspacePolicy.setRpType(org.dspace.authorize.ResourcePolicy.TYPE_CUSTOM);
|
// dspacePolicy.setRpType(org.dspace.authorize.ResourcePolicy.TYPE_CUSTOM);
|
||||||
bitstreamsPolicies.add(dspacePolicy);
|
bitstreamsPolicies.add(dspacePolicy);
|
||||||
|
|
||||||
bundle.replaceAllBitstreamPolicies(bitstreamsPolicies);
|
bundle.replaceAllBitstreamPolicies(bitstreamsPolicies);
|
||||||
@@ -343,13 +402,24 @@ public class BitstreamResource extends Resource{
|
|||||||
context.complete();
|
context.complete();
|
||||||
log.trace("Policy for bitsream(id=" + bitstreamId + ") was successfully added.");
|
log.trace("Policy for bitsream(id=" + bitstreamId + ") was successfully added.");
|
||||||
|
|
||||||
} catch (SQLException e) {
|
}
|
||||||
processException("Someting went wrong while adding policy to bitstream(id=" + bitstreamId + "), SQLException! Message: " + e, context);
|
catch (SQLException e)
|
||||||
} catch (ContextException e) {
|
{
|
||||||
processException("Someting went wrong while adding policy to bitstream(id=" + bitstreamId + "), ContextException. Message: " + e.getMessage(), context);
|
processException("Someting went wrong while adding policy to bitstream(id=" + bitstreamId
|
||||||
} catch (AuthorizeException e) {
|
+ "), SQLException! Message: " + e, context);
|
||||||
processException("Someting went wrong while adding policy to bitstream(id=" + bitstreamId + "), AuthorizeException! Message: " + e, context);
|
}
|
||||||
} finally {
|
catch (ContextException e)
|
||||||
|
{
|
||||||
|
processException("Someting went wrong while adding policy to bitstream(id=" + bitstreamId
|
||||||
|
+ "), ContextException. Message: " + e.getMessage(), context);
|
||||||
|
}
|
||||||
|
catch (AuthorizeException e)
|
||||||
|
{
|
||||||
|
processException("Someting went wrong while adding policy to bitstream(id=" + bitstreamId
|
||||||
|
+ "), AuthorizeException! Message: " + e, context);
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
context.abort();
|
context.abort();
|
||||||
}
|
}
|
||||||
return Response.status(Status.OK).build();
|
return Response.status(Status.OK).build();
|
||||||
@@ -370,64 +440,76 @@ public class BitstreamResource extends Resource{
|
|||||||
* If you want to access to item under logged user into context.
|
* If you want to access to item under logged user into context.
|
||||||
* In headers must be set header "rest-dspace-token" with passed
|
* In headers must be set header "rest-dspace-token" with passed
|
||||||
* token from login method.
|
* token from login method.
|
||||||
* @return Return response codes: OK(200), NOT_FOUND(404) if bitstream
|
* @return Return response codes: OK(200), NOT_FOUND(404) if bitstream does
|
||||||
* does not exist and UNAUTHORIZED(401) if user is not allowed to
|
* not exist and UNAUTHORIZED(401) if user is not allowed to write
|
||||||
* write to bitstream.
|
* to bitstream.
|
||||||
* @throws WebApplicationException
|
* @throws WebApplicationException
|
||||||
* It can be thrown by: Error in reading from database. Or
|
* It can be thrown by: Error in reading from database. Or
|
||||||
* creating context or with authorization to bitstream.
|
* creating context or with authorization to bitstream.
|
||||||
*/
|
*/
|
||||||
@PUT
|
@PUT
|
||||||
@Path("/{bitstream_id}")
|
@Path("/{bitstream_id}")
|
||||||
@Consumes({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
|
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
|
||||||
public Response updateBitstream(
|
public Response updateBitstream(@PathParam("bitstream_id") Integer bitstreamId, Bitstream bitstream,
|
||||||
@PathParam("bitstream_id") Integer bitstreamId, Bitstream bitstream,
|
|
||||||
@QueryParam("userIP") String user_ip, @QueryParam("userAgent") String user_agent,
|
@QueryParam("userIP") String user_ip, @QueryParam("userAgent") String user_agent,
|
||||||
@QueryParam("xforwarderfor") String xforwarderfor, @Context HttpHeaders headers,
|
@QueryParam("xforwarderfor") String xforwarderfor, @Context HttpHeaders headers, @Context HttpServletRequest request)
|
||||||
@Context HttpServletRequest request) throws WebApplicationException {
|
throws WebApplicationException
|
||||||
|
{
|
||||||
|
|
||||||
log.info("Updating bitstream(id=" + bitstreamId + ") metadata.");
|
log.info("Updating bitstream(id=" + bitstreamId + ") metadata.");
|
||||||
org.dspace.core.Context context = null;
|
org.dspace.core.Context context = null;
|
||||||
|
|
||||||
try {
|
try
|
||||||
|
{
|
||||||
context = createContext(getUser(headers));
|
context = createContext(getUser(headers));
|
||||||
org.dspace.content.Bitstream dspaceBitstream = findBitstream(context, bitstreamId, org.dspace.core.Constants.WRITE);
|
org.dspace.content.Bitstream dspaceBitstream = findBitstream(context, bitstreamId, org.dspace.core.Constants.WRITE);
|
||||||
|
|
||||||
writeStats(Constants.BITSTREAM, dspaceBitstream, UsageEvent.Action.UPDATE, user_ip, user_agent, xforwarderfor, headers, request);
|
writeStats(Constants.BITSTREAM, dspaceBitstream, UsageEvent.Action.UPDATE, user_ip, user_agent, xforwarderfor,
|
||||||
|
headers, request);
|
||||||
|
|
||||||
log.trace("Updating bitstream metadata.");
|
log.trace("Updating bitstream metadata.");
|
||||||
dspaceBitstream.setDescription(bitstream.getDescription());
|
dspaceBitstream.setDescription(bitstream.getDescription());
|
||||||
if (getMimeType(bitstream.getName()) == null) {
|
if (getMimeType(bitstream.getName()) == null)
|
||||||
|
{
|
||||||
dspaceBitstream.setFormat(BitstreamFormat.findUnknown(context));
|
dspaceBitstream.setFormat(BitstreamFormat.findUnknown(context));
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
dspaceBitstream.setFormat(BitstreamFormat.findByMIMEType(context, getMimeType(bitstream.getName())));
|
dspaceBitstream.setFormat(BitstreamFormat.findByMIMEType(context, getMimeType(bitstream.getName())));
|
||||||
}
|
}
|
||||||
dspaceBitstream.setName(bitstream.getName());
|
dspaceBitstream.setName(bitstream.getName());
|
||||||
Integer sequenceId = bitstream.getSequenceId();
|
Integer sequenceId = bitstream.getSequenceId();
|
||||||
if(sequenceId != null && sequenceId.intValue() != -1){
|
if (sequenceId != null && sequenceId.intValue() != -1)
|
||||||
|
{
|
||||||
dspaceBitstream.setSequenceID(sequenceId);
|
dspaceBitstream.setSequenceID(sequenceId);
|
||||||
}
|
}
|
||||||
|
|
||||||
dspaceBitstream.update();
|
dspaceBitstream.update();
|
||||||
|
|
||||||
if (bitstream.getPolicies() != null) {
|
if (bitstream.getPolicies() != null)
|
||||||
|
{
|
||||||
Bundle[] bundles = dspaceBitstream.getBundles();
|
Bundle[] bundles = dspaceBitstream.getBundles();
|
||||||
ResourcePolicy[] policies = bitstream.getPolicies();
|
ResourcePolicy[] policies = bitstream.getPolicies();
|
||||||
for (Bundle bundle : bundles) {
|
for (Bundle bundle : bundles)
|
||||||
|
{
|
||||||
List<org.dspace.authorize.ResourcePolicy> bitstreamsPolicies = bundle.getBitstreamPolicies();
|
List<org.dspace.authorize.ResourcePolicy> bitstreamsPolicies = bundle.getBitstreamPolicies();
|
||||||
// Remove old bitstream policies
|
// Remove old 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.getResourceID() == dspaceBitstream.getID()) {
|
{
|
||||||
|
if (policy.getResourceID() == dspaceBitstream.getID())
|
||||||
|
{
|
||||||
policiesToRemove.add(policy);
|
policiesToRemove.add(policy);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (org.dspace.authorize.ResourcePolicy policy : policiesToRemove) {
|
for (org.dspace.authorize.ResourcePolicy policy : policiesToRemove)
|
||||||
|
{
|
||||||
bitstreamsPolicies.remove(policy);
|
bitstreamsPolicies.remove(policy);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add all new bitstream policies
|
// Add all new bitstream policies
|
||||||
for (ResourcePolicy policy : policies) {
|
for (ResourcePolicy policy : policies)
|
||||||
|
{
|
||||||
org.dspace.authorize.ResourcePolicy dspacePolicy = org.dspace.authorize.ResourcePolicy.create(context);
|
org.dspace.authorize.ResourcePolicy dspacePolicy = org.dspace.authorize.ResourcePolicy.create(context);
|
||||||
dspacePolicy.setAction(policy.getActionInt());
|
dspacePolicy.setAction(policy.getActionInt());
|
||||||
dspacePolicy.setGroup(Group.find(context, policy.getGroupId()));
|
dspacePolicy.setGroup(Group.find(context, policy.getGroupId()));
|
||||||
@@ -448,13 +530,24 @@ public class BitstreamResource extends Resource{
|
|||||||
|
|
||||||
context.complete();
|
context.complete();
|
||||||
|
|
||||||
} catch(SQLException e) {
|
}
|
||||||
|
catch (SQLException e)
|
||||||
|
{
|
||||||
processException("Could not update bitstream(id=" + bitstreamId + ") metadata, SQLException. Message: " + e, context);
|
processException("Could not update bitstream(id=" + bitstreamId + ") metadata, SQLException. Message: " + e, context);
|
||||||
} catch (AuthorizeException e) {
|
}
|
||||||
processException("Could not update bitstream(id=" + bitstreamId + ") metadata, AuthorizeException. Message: " + e, context);
|
catch (AuthorizeException e)
|
||||||
} catch (ContextException e) {
|
{
|
||||||
processException("Could not update bitstream(id=" + bitstreamId + ") metadata, ContextException. Message: " + e.getMessage(), context);
|
processException("Could not update bitstream(id=" + bitstreamId + ") metadata, AuthorizeException. Message: " + e,
|
||||||
} finally {
|
context);
|
||||||
|
}
|
||||||
|
catch (ContextException e)
|
||||||
|
{
|
||||||
|
processException(
|
||||||
|
"Could not update bitstream(id=" + bitstreamId + ") metadata, ContextException. Message: " + e.getMessage(),
|
||||||
|
context);
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
context.abort();
|
context.abort();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -488,20 +581,22 @@ public class BitstreamResource extends Resource{
|
|||||||
// TODO Change to better logic, without editing database.
|
// TODO Change to better logic, without editing database.
|
||||||
@PUT
|
@PUT
|
||||||
@Path("/{bitstream_id}/data")
|
@Path("/{bitstream_id}/data")
|
||||||
public Response updateBitstreamData(
|
public Response updateBitstreamData(@PathParam("bitstream_id") Integer bitstreamId, InputStream is,
|
||||||
@PathParam("bitstream_id") Integer bitstreamId, InputStream is,
|
|
||||||
@QueryParam("userIP") String user_ip, @QueryParam("userAgent") String user_agent,
|
@QueryParam("userIP") String user_ip, @QueryParam("userAgent") String user_agent,
|
||||||
@QueryParam("xforwarderfor") String xforwarderfor, @Context HttpHeaders headers,
|
@QueryParam("xforwarderfor") String xforwarderfor, @Context HttpHeaders headers, @Context HttpServletRequest request)
|
||||||
@Context HttpServletRequest request) throws WebApplicationException {
|
throws WebApplicationException
|
||||||
|
{
|
||||||
|
|
||||||
log.info("Updating bitstream(id=" + bitstreamId + ") data.");
|
log.info("Updating bitstream(id=" + bitstreamId + ") data.");
|
||||||
org.dspace.core.Context context = null;
|
org.dspace.core.Context context = null;
|
||||||
|
|
||||||
try{
|
try
|
||||||
|
{
|
||||||
context = createContext(getUser(headers));
|
context = createContext(getUser(headers));
|
||||||
org.dspace.content.Bitstream dspaceBitstream = findBitstream(context, bitstreamId, org.dspace.core.Constants.WRITE);
|
org.dspace.content.Bitstream dspaceBitstream = findBitstream(context, bitstreamId, org.dspace.core.Constants.WRITE);
|
||||||
|
|
||||||
writeStats(Constants.BITSTREAM, dspaceBitstream, UsageEvent.Action.UPDATE, user_ip, user_agent, xforwarderfor, headers, request);
|
writeStats(Constants.BITSTREAM, dspaceBitstream, UsageEvent.Action.UPDATE, user_ip, user_agent, xforwarderfor,
|
||||||
|
headers, request);
|
||||||
|
|
||||||
log.trace("Creating new bitstream.");
|
log.trace("Creating new bitstream.");
|
||||||
int newBitstreamId = BitstreamStorageManager.store(context, is);
|
int newBitstreamId = BitstreamStorageManager.store(context, is);
|
||||||
@@ -523,13 +618,23 @@ public class BitstreamResource extends Resource{
|
|||||||
|
|
||||||
context.complete();
|
context.complete();
|
||||||
|
|
||||||
} catch(SQLException e) {
|
}
|
||||||
|
catch (SQLException e)
|
||||||
|
{
|
||||||
processException("Could not update bitstream(id=" + bitstreamId + ") data, SQLException. Message: " + e, context);
|
processException("Could not update bitstream(id=" + bitstreamId + ") data, SQLException. Message: " + e, context);
|
||||||
} catch (IOException e) {
|
}
|
||||||
|
catch (IOException e)
|
||||||
|
{
|
||||||
processException("Could not update bitstream(id=" + bitstreamId + ") data, IOException. Message: " + e, context);
|
processException("Could not update bitstream(id=" + bitstreamId + ") data, IOException. Message: " + e, context);
|
||||||
} catch (ContextException e) {
|
}
|
||||||
processException("Could not update bitstream(id=" + bitstreamId + ") data, ContextException. Message: " + e.getMessage(), context);
|
catch (ContextException e)
|
||||||
} finally {
|
{
|
||||||
|
processException(
|
||||||
|
"Could not update bitstream(id=" + bitstreamId + ") data, ContextException. Message: " + e.getMessage(),
|
||||||
|
context);
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
context.abort();
|
context.abort();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -561,37 +666,50 @@ public class BitstreamResource extends Resource{
|
|||||||
*/
|
*/
|
||||||
@DELETE
|
@DELETE
|
||||||
@Path("/{bitstream_id}")
|
@Path("/{bitstream_id}")
|
||||||
public Response deleteBitstream(
|
public Response deleteBitstream(@PathParam("bitstream_id") Integer bitstreamId, @QueryParam("userIP") String user_ip,
|
||||||
@PathParam("bitstream_id") Integer bitstreamId,
|
@QueryParam("userAgent") String user_agent, @QueryParam("xforwarderfor") String xforwarderfor,
|
||||||
@QueryParam("userIP") String user_ip, @QueryParam("userAgent") String user_agent,
|
@Context HttpHeaders headers, @Context HttpServletRequest request) throws WebApplicationException
|
||||||
@QueryParam("xforwarderfor") String xforwarderfor, @Context HttpHeaders headers,
|
{
|
||||||
@Context HttpServletRequest request) throws WebApplicationException {
|
|
||||||
|
|
||||||
log.info("Deleting bitstream(id=" + bitstreamId + ").");
|
log.info("Deleting bitstream(id=" + bitstreamId + ").");
|
||||||
org.dspace.core.Context context = null;
|
org.dspace.core.Context context = null;
|
||||||
|
|
||||||
try {
|
try
|
||||||
|
{
|
||||||
context = createContext(getUser(headers));
|
context = createContext(getUser(headers));
|
||||||
org.dspace.content.Bitstream dspaceBitstream = findBitstream(context, bitstreamId, org.dspace.core.Constants.DELETE);
|
org.dspace.content.Bitstream dspaceBitstream = findBitstream(context, bitstreamId, org.dspace.core.Constants.DELETE);
|
||||||
|
|
||||||
writeStats(Constants.BITSTREAM, dspaceBitstream, UsageEvent.Action.DELETE, user_ip, user_agent, xforwarderfor, headers, request);
|
writeStats(Constants.BITSTREAM, dspaceBitstream, UsageEvent.Action.DELETE, user_ip, user_agent, xforwarderfor,
|
||||||
|
headers, request);
|
||||||
|
|
||||||
log.trace("Deleting bitstream from all bundles.");
|
log.trace("Deleting bitstream from all bundles.");
|
||||||
for (org.dspace.content.Bundle bundle : dspaceBitstream.getBundles()) {
|
for (org.dspace.content.Bundle bundle : dspaceBitstream.getBundles())
|
||||||
|
{
|
||||||
org.dspace.content.Bundle.find(context, bundle.getID()).removeBitstream(dspaceBitstream);
|
org.dspace.content.Bundle.find(context, bundle.getID()).removeBitstream(dspaceBitstream);
|
||||||
}
|
}
|
||||||
|
|
||||||
context.complete();
|
context.complete();
|
||||||
|
|
||||||
} catch(SQLException e) {
|
}
|
||||||
|
catch (SQLException e)
|
||||||
|
{
|
||||||
processException("Could not delete bitstream(id=" + bitstreamId + "), SQLException. Message: " + e, context);
|
processException("Could not delete bitstream(id=" + bitstreamId + "), SQLException. Message: " + e, context);
|
||||||
} catch (AuthorizeException e) {
|
}
|
||||||
|
catch (AuthorizeException e)
|
||||||
|
{
|
||||||
processException("Could not delete bitstream(id=" + bitstreamId + "), AuthorizeException. Message: " + e, context);
|
processException("Could not delete bitstream(id=" + bitstreamId + "), AuthorizeException. Message: " + e, context);
|
||||||
} catch (IOException e) {
|
}
|
||||||
|
catch (IOException e)
|
||||||
|
{
|
||||||
processException("Could not delete bitstream(id=" + bitstreamId + "), IOException. Message: " + e, context);
|
processException("Could not delete bitstream(id=" + bitstreamId + "), IOException. Message: " + e, context);
|
||||||
} catch (ContextException e) {
|
}
|
||||||
processException("Could not delete bitstream(id=" + bitstreamId + "), ContextException. Message:" + e.getMessage(), context);
|
catch (ContextException e)
|
||||||
} finally {
|
{
|
||||||
|
processException("Could not delete bitstream(id=" + bitstreamId + "), ContextException. Message:" + e.getMessage(),
|
||||||
|
context);
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
context.abort();
|
context.abort();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -614,22 +732,28 @@ public class BitstreamResource extends Resource{
|
|||||||
*/
|
*/
|
||||||
@DELETE
|
@DELETE
|
||||||
@Path("/{bitstream_id}/policy/{policy_id}")
|
@Path("/{bitstream_id}/policy/{policy_id}")
|
||||||
public javax.ws.rs.core.Response deleteBitstreamPolicy(@PathParam("bitstream_id") Integer bitstreamId, @PathParam("policy_id") Integer policyId, @Context HttpHeaders headers) {
|
public javax.ws.rs.core.Response deleteBitstreamPolicy(@PathParam("bitstream_id") Integer bitstreamId,
|
||||||
|
@PathParam("policy_id") Integer policyId, @Context HttpHeaders headers)
|
||||||
|
{
|
||||||
|
|
||||||
log.info("Deleting bitstream(id=" + bitstreamId + ") READ policy(id=" + policyId + ").");
|
log.info("Deleting bitstream(id=" + bitstreamId + ") READ policy(id=" + policyId + ").");
|
||||||
org.dspace.core.Context context = null;
|
org.dspace.core.Context context = null;
|
||||||
|
|
||||||
try {
|
try
|
||||||
|
{
|
||||||
context = createContext(getUser(headers));
|
context = createContext(getUser(headers));
|
||||||
org.dspace.content.Bitstream dspaceBitstream = findBitstream(context, bitstreamId, org.dspace.core.Constants.READ);
|
org.dspace.content.Bitstream dspaceBitstream = findBitstream(context, bitstreamId, org.dspace.core.Constants.READ);
|
||||||
|
|
||||||
Bundle[] bundles = dspaceBitstream.getBundles();
|
Bundle[] bundles = dspaceBitstream.getBundles();
|
||||||
|
|
||||||
for (Bundle bundle : bundles) {
|
for (Bundle bundle : bundles)
|
||||||
|
{
|
||||||
List<org.dspace.authorize.ResourcePolicy> bitstreamsPolicies = bundle.getBitstreamPolicies();
|
List<org.dspace.authorize.ResourcePolicy> bitstreamsPolicies = bundle.getBitstreamPolicies();
|
||||||
|
|
||||||
for (org.dspace.authorize.ResourcePolicy policy : bitstreamsPolicies) {
|
for (org.dspace.authorize.ResourcePolicy policy : bitstreamsPolicies)
|
||||||
if (policy.getID() == policyId.intValue()) {
|
{
|
||||||
|
if (policy.getID() == policyId.intValue())
|
||||||
|
{
|
||||||
bitstreamsPolicies.remove(policy);
|
bitstreamsPolicies.remove(policy);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -642,13 +766,24 @@ public class BitstreamResource extends Resource{
|
|||||||
context.complete();
|
context.complete();
|
||||||
log.trace("Policy for bitsream(id=" + bitstreamId + ") was successfully added.");
|
log.trace("Policy for bitsream(id=" + bitstreamId + ") was successfully added.");
|
||||||
|
|
||||||
} catch (SQLException e) {
|
}
|
||||||
processException("Someting went wrong while deleting READ policy(id=" + policyId + ") to bitstream(id=" + bitstreamId + "), SQLException! Message: " + e, context);
|
catch (SQLException e)
|
||||||
} catch (ContextException e) {
|
{
|
||||||
processException("Someting went wrong while deleting READ policy(id=" + policyId + ") to bitstream(id=" + bitstreamId + "), ContextException. Message: " + e.getMessage(), context);
|
processException("Someting went wrong while deleting READ policy(id=" + policyId + ") to bitstream(id=" + bitstreamId
|
||||||
} catch (AuthorizeException e) {
|
+ "), SQLException! Message: " + e, context);
|
||||||
processException("Someting went wrong while deleting READ policy(id=" + policyId + ") to bitstream(id=" + bitstreamId + "), AuthorizeException! Message: " + e, context);
|
}
|
||||||
} finally {
|
catch (ContextException e)
|
||||||
|
{
|
||||||
|
processException("Someting went wrong while deleting READ policy(id=" + policyId + ") to bitstream(id=" + bitstreamId
|
||||||
|
+ "), ContextException. Message: " + e.getMessage(), context);
|
||||||
|
}
|
||||||
|
catch (AuthorizeException e)
|
||||||
|
{
|
||||||
|
processException("Someting went wrong while deleting READ policy(id=" + policyId + ") to bitstream(id=" + bitstreamId
|
||||||
|
+ "), AuthorizeException! Message: " + e, context);
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
context.abort();
|
context.abort();
|
||||||
}
|
}
|
||||||
return Response.status(Status.OK).build();
|
return Response.status(Status.OK).build();
|
||||||
@@ -661,7 +796,8 @@ public class BitstreamResource extends Resource{
|
|||||||
* Name of file.
|
* Name of file.
|
||||||
* @return String filled with type of file in MIME style.
|
* @return String filled with type of file in MIME style.
|
||||||
*/
|
*/
|
||||||
static String getMimeType(String name) {
|
static String getMimeType(String name)
|
||||||
|
{
|
||||||
return URLConnection.guessContentTypeFromName(name);
|
return URLConnection.guessContentTypeFromName(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -681,28 +817,42 @@ public class BitstreamResource extends Resource{
|
|||||||
* Is thrown when item with passed id is not exists and if user
|
* Is thrown when item with passed id is not exists and if user
|
||||||
* has no permission to do passed action.
|
* has no permission to do passed action.
|
||||||
*/
|
*/
|
||||||
private org.dspace.content.Bitstream findBitstream(org.dspace.core.Context context, int id, int action) throws WebApplicationException {
|
private org.dspace.content.Bitstream findBitstream(org.dspace.core.Context context, int id, int action)
|
||||||
|
throws WebApplicationException
|
||||||
|
{
|
||||||
org.dspace.content.Bitstream bitstream = null;
|
org.dspace.content.Bitstream bitstream = null;
|
||||||
try {
|
try
|
||||||
|
{
|
||||||
bitstream = org.dspace.content.Bitstream.find(context, id);
|
bitstream = org.dspace.content.Bitstream.find(context, id);
|
||||||
|
|
||||||
if ((bitstream == null) || (bitstream.getParentObject() == null)) {
|
if ((bitstream == null) || (bitstream.getParentObject() == null))
|
||||||
|
{
|
||||||
context.abort();
|
context.abort();
|
||||||
log.warn("Bitstream(id=" + id + ") was not found!");
|
log.warn("Bitstream(id=" + id + ") was not found!");
|
||||||
throw new WebApplicationException(Response.Status.NOT_FOUND);
|
throw new WebApplicationException(Response.Status.NOT_FOUND);
|
||||||
} else if (!AuthorizeManager.authorizeActionBoolean(context, bitstream, action)) {
|
}
|
||||||
|
else if (!AuthorizeManager.authorizeActionBoolean(context, bitstream, action))
|
||||||
|
{
|
||||||
context.abort();
|
context.abort();
|
||||||
if (context.getCurrentUser() != null ) {
|
if (context.getCurrentUser() != null)
|
||||||
log.error("User(" + context.getCurrentUser().getEmail() + ") has not permission to " + getActionString(action) + " bitstream!");
|
{
|
||||||
} else {
|
log.error("User(" + context.getCurrentUser().getEmail() + ") has not permission to "
|
||||||
|
+ getActionString(action) + " bitstream!");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
log.error("User(anonymous) has not permission to " + getActionString(action) + " bitsteam!");
|
log.error("User(anonymous) has not permission to " + getActionString(action) + " bitsteam!");
|
||||||
}
|
}
|
||||||
throw new WebApplicationException(Response.Status.UNAUTHORIZED);
|
throw new WebApplicationException(Response.Status.UNAUTHORIZED);
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (SQLException e) {
|
}
|
||||||
|
catch (SQLException e)
|
||||||
|
{
|
||||||
processException("Something get wrong while finding bitstream. SQLException, Message:" + e, context);
|
processException("Something get wrong while finding bitstream. SQLException, Message:" + e, context);
|
||||||
} finally {
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
context.abort();
|
context.abort();
|
||||||
}
|
}
|
||||||
return bitstream;
|
return bitstream;
|
||||||
|
@@ -175,10 +175,9 @@ public class CollectionsResource extends Resource
|
|||||||
offset = 0;
|
offset = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// dspaceCollections =
|
// TODO Repair it in DSpace api
|
||||||
// org.dspace.content.Collection.findAll(context, limit, offset); //
|
// dspaceCollections = org.dspace.content.Collection.findAll(context, limit, offset);
|
||||||
// Message:java.sql.SQLSyntaxErrorException: ORA-00933: SQL command
|
// Message:java.sql.SQLSyntaxErrorException: ORA-00933: SQL command not properly ended
|
||||||
// not properly ended
|
|
||||||
dspaceCollections = org.dspace.content.Collection.findAll(context);
|
dspaceCollections = org.dspace.content.Collection.findAll(context);
|
||||||
|
|
||||||
for (int i = offset; i < limit + offset; i++)
|
for (int i = offset; i < limit + offset; i++)
|
||||||
@@ -312,10 +311,10 @@ public class CollectionsResource extends Resource
|
|||||||
* If you want to access to collection under logged user into
|
* If you want to access to collection under logged user into
|
||||||
* context. In headers must be set header "rest-dspace-token"
|
* context. In headers must be set header "rest-dspace-token"
|
||||||
* with passed token from login method.
|
* with passed token from login method.
|
||||||
* @return Return status code with item. Return status
|
* @return Return status code with item. Return status (OK)200 if item was
|
||||||
* (OK)200 if item was created. NOT_FOUND(404) if id of collection
|
* created. NOT_FOUND(404) if id of collection does not exists.
|
||||||
* does not exists. UNAUTHORIZED(401) if user have not permission to
|
* UNAUTHORIZED(401) if user have not permission to write items in
|
||||||
* write items in collection.
|
* collection.
|
||||||
* @throws WebApplicationException
|
* @throws WebApplicationException
|
||||||
* It is thrown when was problem with database reading or
|
* It is thrown when was problem with database reading or
|
||||||
* writing (SQLException) or problem with creating
|
* writing (SQLException) or problem with creating
|
||||||
@@ -449,8 +448,7 @@ public class CollectionsResource extends Resource
|
|||||||
|
|
||||||
dspaceCollection.setMetadata("name", collection.getName());
|
dspaceCollection.setMetadata("name", collection.getName());
|
||||||
dspaceCollection.setLicense(collection.getLicense());
|
dspaceCollection.setLicense(collection.getLicense());
|
||||||
// dspaceCollection.setLogo(collection.getLogo()); // TODO Add this
|
// dspaceCollection.setLogo(collection.getLogo()); // TODO Add this option.
|
||||||
// option.
|
|
||||||
dspaceCollection.setMetadata(org.dspace.content.Collection.COPYRIGHT_TEXT, collection.getCopyrightText());
|
dspaceCollection.setMetadata(org.dspace.content.Collection.COPYRIGHT_TEXT, collection.getCopyrightText());
|
||||||
dspaceCollection.setMetadata(org.dspace.content.Collection.INTRODUCTORY_TEXT, collection.getIntroductoryText());
|
dspaceCollection.setMetadata(org.dspace.content.Collection.INTRODUCTORY_TEXT, collection.getIntroductoryText());
|
||||||
dspaceCollection.setMetadata(org.dspace.content.Collection.SHORT_DESCRIPTION, collection.getShortDescription());
|
dspaceCollection.setMetadata(org.dspace.content.Collection.SHORT_DESCRIPTION, collection.getShortDescription());
|
||||||
@@ -660,32 +658,40 @@ public class CollectionsResource extends Resource
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Search for first collection with passed name.
|
* Search for first collection with passed name.
|
||||||
* @param name Name of collection.
|
*
|
||||||
|
* @param name
|
||||||
|
* Name of collection.
|
||||||
* @param headers
|
* @param headers
|
||||||
* If you want to access to collection under logged user into
|
* If you want to access to collection under logged user into
|
||||||
* context. In headers must be set header "rest-dspace-token"
|
* context. In headers must be set header "rest-dspace-token"
|
||||||
* with passed token from login method.
|
* with passed token from login method.
|
||||||
* @return It returns null if collection was not found. Otherwise returns first founded collection.
|
* @return It returns null if collection was not found. Otherwise returns
|
||||||
|
* first founded collection.
|
||||||
* @throws WebApplicationException
|
* @throws WebApplicationException
|
||||||
*/
|
*/
|
||||||
@POST
|
@POST
|
||||||
@Path("/find-collection")
|
@Path("/find-collection")
|
||||||
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
|
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
|
||||||
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
|
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
|
||||||
public Collection findCollectionByName(String name, @Context HttpHeaders headers) throws WebApplicationException {
|
public Collection findCollectionByName(String name, @Context HttpHeaders headers) throws WebApplicationException
|
||||||
|
{
|
||||||
log.info("Searching for first collection with name=" + name + ".");
|
log.info("Searching for first collection with name=" + name + ".");
|
||||||
org.dspace.core.Context context = null;
|
org.dspace.core.Context context = null;
|
||||||
Collection collection = null;
|
Collection collection = null;
|
||||||
|
|
||||||
try {
|
try
|
||||||
|
{
|
||||||
context = createContext(getUser(headers));
|
context = createContext(getUser(headers));
|
||||||
org.dspace.content.Collection[] dspaceCollections;
|
org.dspace.content.Collection[] dspaceCollections;
|
||||||
|
|
||||||
dspaceCollections = org.dspace.content.Collection.findAll(context);
|
dspaceCollections = org.dspace.content.Collection.findAll(context);
|
||||||
|
|
||||||
for (org.dspace.content.Collection dspaceCollection : dspaceCollections) {
|
for (org.dspace.content.Collection dspaceCollection : dspaceCollections)
|
||||||
if (AuthorizeManager.authorizeActionBoolean(context, dspaceCollection, org.dspace.core.Constants.READ)) {
|
{
|
||||||
if (dspaceCollection.getName().equals(name)) {
|
if (AuthorizeManager.authorizeActionBoolean(context, dspaceCollection, org.dspace.core.Constants.READ))
|
||||||
|
{
|
||||||
|
if (dspaceCollection.getName().equals(name))
|
||||||
|
{
|
||||||
collection = new Collection(dspaceCollection, "", context, 100, 0);
|
collection = new Collection(dspaceCollection, "", context, 100, 0);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -694,19 +700,28 @@ public class CollectionsResource extends Resource
|
|||||||
|
|
||||||
context.complete();
|
context.complete();
|
||||||
|
|
||||||
} catch (SQLException e) {
|
}
|
||||||
processException("Something went wrong while searching for collection(name=" + name + ") from database. Message: " + e, context);
|
catch (SQLException e)
|
||||||
} catch (ContextException e) {
|
{
|
||||||
processException("Something went wrong while searching for collection(name=" + name + "), ContextError. Message: " + e.getMessage(), context);
|
processException("Something went wrong while searching for collection(name=" + name + ") from database. Message: "
|
||||||
|
+ e, context);
|
||||||
|
}
|
||||||
|
catch (ContextException e)
|
||||||
|
{
|
||||||
|
processException("Something went wrong while searching for collection(name=" + name + "), ContextError. Message: "
|
||||||
|
+ e.getMessage(), context);
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
context.abort();
|
context.abort();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (collection == null) {
|
if (collection == null)
|
||||||
|
{
|
||||||
log.info("Collection was not found.");
|
log.info("Collection was not found.");
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
log.info("Collection was found with id(" + collection.getId() + ").");
|
log.info("Collection was found with id(" + collection.getId() + ").");
|
||||||
}
|
}
|
||||||
return collection;
|
return collection;
|
||||||
|
@@ -10,7 +10,6 @@ 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.List;
|
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.ws.rs.Consumes;
|
import javax.ws.rs.Consumes;
|
||||||
@@ -36,8 +35,6 @@ import org.dspace.core.Constants;
|
|||||||
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.storage.rdbms.TableRow;
|
|
||||||
import org.dspace.storage.rdbms.TableRowIterator;
|
|
||||||
import org.dspace.usage.UsageEvent;
|
import org.dspace.usage.UsageEvent;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -612,7 +609,8 @@ public class CommunitiesResource extends Resource
|
|||||||
context.abort();
|
context.abort();
|
||||||
}
|
}
|
||||||
|
|
||||||
log.info("Collection was successfully added into community(id=" + communityId + "). Collection handle=" + retCollection.getHandle());
|
log.info("Collection was successfully added into community(id=" + communityId + "). Collection handle="
|
||||||
|
+ retCollection.getHandle());
|
||||||
return retCollection;
|
return retCollection;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -45,6 +45,8 @@ import org.dspace.rest.common.Bitstream;
|
|||||||
import org.dspace.rest.common.Item;
|
import org.dspace.rest.common.Item;
|
||||||
import org.dspace.rest.common.MetadataEntry;
|
import org.dspace.rest.common.MetadataEntry;
|
||||||
import org.dspace.rest.exceptions.ContextException;
|
import org.dspace.rest.exceptions.ContextException;
|
||||||
|
import org.dspace.storage.rdbms.TableRow;
|
||||||
|
import org.dspace.storage.rdbms.TableRowIterator;
|
||||||
import org.dspace.usage.UsageEvent;
|
import org.dspace.usage.UsageEvent;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -53,8 +55,7 @@ import org.dspace.usage.UsageEvent;
|
|||||||
* @author Rostislav Novak (Computing and Information Centre, CTU in Prague)
|
* @author Rostislav Novak (Computing and Information Centre, CTU in Prague)
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
// Every DSpace class used without namespace is from package
|
// Every DSpace class used without namespace is from package org.dspace.rest.common.*. Otherwise namespace is defined.
|
||||||
// org.dspace.rest.common.*. Otherwise namespace is defined.
|
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
@Path("/items")
|
@Path("/items")
|
||||||
public class ItemsResource extends Resource
|
public class ItemsResource extends Resource
|
||||||
@@ -383,10 +384,8 @@ public class ItemsResource extends Resource
|
|||||||
|
|
||||||
for (MetadataEntry entry : metadata)
|
for (MetadataEntry entry : metadata)
|
||||||
{
|
{
|
||||||
String data[] = mySplit(entry.getKey()); // Done by my split,
|
// TODO Test with Java split
|
||||||
// because of java
|
String data[] = mySplit(entry.getKey()); // Done by my split, because of java split was not function.
|
||||||
// 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());
|
dspaceItem.addMetadata(data[0], data[1], data[2], entry.getLanguage(), entry.getValue());
|
||||||
@@ -429,9 +428,9 @@ public class ItemsResource extends Resource
|
|||||||
* If you want to access to item under logged user into context.
|
* If you want to access to item under logged user into context.
|
||||||
* In headers must be set header "rest-dspace-token" with passed
|
* In headers must be set header "rest-dspace-token" with passed
|
||||||
* token from login method.
|
* token from login method.
|
||||||
* @return Returns bitstream with status code OK(200). If id of item
|
* @return Returns bitstream with status code OK(200). If id of item is
|
||||||
* is invalid , it returns status code NOT_FOUND(404). If user is
|
* invalid , it returns status code NOT_FOUND(404). If user is not
|
||||||
* not allowed to write to item, UNAUTHORIZED(401).
|
* allowed to write to item, UNAUTHORIZED(401).
|
||||||
* @throws WebApplicationException
|
* @throws WebApplicationException
|
||||||
* It is thrown by these exceptions: SQLException, when was
|
* It is thrown by these exceptions: SQLException, when was
|
||||||
* problem with reading/writing from/to database.
|
* problem with reading/writing from/to database.
|
||||||
@@ -444,19 +443,20 @@ public class ItemsResource extends Resource
|
|||||||
// TODO Add option to add bitsream by URI.(for very big files)
|
// TODO Add option to add bitsream by URI.(for very big files)
|
||||||
@POST
|
@POST
|
||||||
@Path("/{item_id}/bitstreams")
|
@Path("/{item_id}/bitstreams")
|
||||||
public Bitstream addItemBitstream(
|
public Bitstream addItemBitstream(@PathParam("item_id") Integer itemId, InputStream inputStream,
|
||||||
@PathParam("item_id") Integer itemId, InputStream inputStream,
|
|
||||||
@QueryParam("name") String name, @QueryParam("description") String description,
|
@QueryParam("name") String name, @QueryParam("description") String description,
|
||||||
@QueryParam("groupId") Integer groupId, @QueryParam("year") Integer year, @QueryParam("month") Integer month,
|
@QueryParam("groupId") Integer groupId, @QueryParam("year") Integer year, @QueryParam("month") Integer month,
|
||||||
@QueryParam("day") Integer day, @QueryParam("userIP") String user_ip, @QueryParam("userAgent") String user_agent,
|
@QueryParam("day") Integer day, @QueryParam("userIP") String user_ip, @QueryParam("userAgent") String user_agent,
|
||||||
@QueryParam("xforwarderfor") String xforwarderfor, @Context HttpHeaders headers, @Context HttpServletRequest request)
|
@QueryParam("xforwarderfor") String xforwarderfor, @Context HttpHeaders headers, @Context HttpServletRequest request)
|
||||||
throws WebApplicationException {
|
throws WebApplicationException
|
||||||
|
{
|
||||||
|
|
||||||
log.info("Adding bitstream to item(id=" + itemId + ").");
|
log.info("Adding bitstream to item(id=" + itemId + ").");
|
||||||
org.dspace.core.Context context = null;
|
org.dspace.core.Context context = null;
|
||||||
Bitstream bitstream = null;
|
Bitstream bitstream = null;
|
||||||
|
|
||||||
try {
|
try
|
||||||
|
{
|
||||||
context = createContext(getUser(headers));
|
context = createContext(getUser(headers));
|
||||||
org.dspace.content.Item dspaceItem = findItem(context, itemId, org.dspace.core.Constants.WRITE);
|
org.dspace.content.Item dspaceItem = findItem(context, itemId, org.dspace.core.Constants.WRITE);
|
||||||
|
|
||||||
@@ -466,13 +466,13 @@ 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;
|
||||||
if ((dspaceItem.getBundles().length == 0) || (dspaceItem.getBundles() == null)) {
|
if ((dspaceItem.getBundles().length == 0) || (dspaceItem.getBundles() == null))
|
||||||
|
{
|
||||||
log.trace("Creating bundle in item.");
|
log.trace("Creating bundle in item.");
|
||||||
dspaceBitstream = dspaceItem.createSingleBitstream(inputStream);
|
dspaceBitstream = dspaceItem.createSingleBitstream(inputStream);
|
||||||
//bundle = dspaceItem.getBundles()[0];
|
}
|
||||||
//bundle.setName(dspaceItem.getID() + "-bundle");
|
else
|
||||||
//bundle.update();
|
{
|
||||||
} else {
|
|
||||||
log.trace("Getting bundle from item.");
|
log.trace("Getting bundle from item.");
|
||||||
bundle = dspaceItem.getBundles()[0];
|
bundle = dspaceItem.getBundles()[0];
|
||||||
dspaceBitstream = bundle.createBitstream(inputStream);
|
dspaceBitstream = bundle.createBitstream(inputStream);
|
||||||
@@ -481,34 +481,44 @@ public class ItemsResource extends Resource
|
|||||||
dspaceBitstream.setSource("DSpace Rest api");
|
dspaceBitstream.setSource("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(BitstreamFormat.findUnknown(context));
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
dspaceBitstream.setFormat(BitstreamFormat.findByMIMEType(context, BitstreamResource.getMimeType(name)));
|
dspaceBitstream.setFormat(BitstreamFormat.findByMIMEType(context, BitstreamResource.getMimeType(name)));
|
||||||
}
|
}
|
||||||
dspaceBitstream.setName(name);
|
dspaceBitstream.setName(name);
|
||||||
}
|
}
|
||||||
if (description != null) {
|
if (description != null)
|
||||||
|
{
|
||||||
dspaceBitstream.setDescription(description);
|
dspaceBitstream.setDescription(description);
|
||||||
}
|
}
|
||||||
|
|
||||||
dspaceBitstream.update();
|
dspaceBitstream.update();
|
||||||
|
|
||||||
// Create policy for bitstream
|
// Create policy for bitstream
|
||||||
if (groupId != null) {
|
if (groupId != null)
|
||||||
|
{
|
||||||
Bundle[] bundles = dspaceBitstream.getBundles();
|
Bundle[] bundles = dspaceBitstream.getBundles();
|
||||||
for (Bundle dspaceBundle : bundles) {
|
for (Bundle dspaceBundle : bundles)
|
||||||
|
{
|
||||||
List<org.dspace.authorize.ResourcePolicy> bitstreamsPolicies = dspaceBundle.getBitstreamPolicies();
|
List<org.dspace.authorize.ResourcePolicy> bitstreamsPolicies = dspaceBundle.getBitstreamPolicies();
|
||||||
|
|
||||||
// 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.getResourceID() == dspaceBitstream.getID()) {
|
{
|
||||||
|
if (policy.getResourceID() == dspaceBitstream.getID())
|
||||||
|
{
|
||||||
policiesToRemove.add(policy);
|
policiesToRemove.add(policy);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (org.dspace.authorize.ResourcePolicy policy : policiesToRemove) {
|
for (org.dspace.authorize.ResourcePolicy policy : policiesToRemove)
|
||||||
|
{
|
||||||
bitstreamsPolicies.remove(policy);
|
bitstreamsPolicies.remove(policy);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -518,15 +528,19 @@ public class ItemsResource extends Resource
|
|||||||
dspacePolicy.setResourceID(dspaceBitstream.getID());
|
dspacePolicy.setResourceID(dspaceBitstream.getID());
|
||||||
dspacePolicy.setResource(dspaceBitstream);
|
dspacePolicy.setResource(dspaceBitstream);
|
||||||
dspacePolicy.setResourceType(org.dspace.core.Constants.BITSTREAM);
|
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();
|
||||||
if (year != null) {
|
if (year != null)
|
||||||
date.setYear(year-1900);
|
{
|
||||||
|
date.setYear(year - 1900);
|
||||||
}
|
}
|
||||||
if (month != null) {
|
if (month != null)
|
||||||
date.setMonth(month-1);
|
{
|
||||||
|
date.setMonth(month - 1);
|
||||||
}
|
}
|
||||||
if (day != null) {
|
if (day != null)
|
||||||
|
{
|
||||||
date.setDate(day);
|
date.setDate(day);
|
||||||
}
|
}
|
||||||
date.setHours(0);
|
date.setHours(0);
|
||||||
@@ -547,14 +561,23 @@ public class ItemsResource extends Resource
|
|||||||
|
|
||||||
context.complete();
|
context.complete();
|
||||||
|
|
||||||
} catch (SQLException e) {
|
}
|
||||||
|
catch (SQLException e)
|
||||||
|
{
|
||||||
processException("Could not create bitstream in item(id=" + itemId + "), SQLException. Message: " + e, context);
|
processException("Could not create bitstream in item(id=" + itemId + "), SQLException. Message: " + e, context);
|
||||||
} catch (AuthorizeException e) {
|
}
|
||||||
|
catch (AuthorizeException e)
|
||||||
|
{
|
||||||
processException("Could not create bitstream in item(id=" + itemId + "), AuthorizeException. Message: " + e, context);
|
processException("Could not create bitstream in item(id=" + itemId + "), AuthorizeException. Message: " + e, context);
|
||||||
} catch (IOException e) {
|
}
|
||||||
|
catch (IOException e)
|
||||||
|
{
|
||||||
processException("Could not create bitstream in item(id=" + itemId + "), IOException Message: " + e, context);
|
processException("Could not create bitstream in item(id=" + itemId + "), IOException Message: " + e, context);
|
||||||
} catch (ContextException e) {
|
}
|
||||||
processException("Could not create bitstream in item(id=" + itemId + "), ContextException Message: " + e.getMessage(), context);
|
catch (ContextException e)
|
||||||
|
{
|
||||||
|
processException(
|
||||||
|
"Could not create bitstream in item(id=" + itemId + "), ContextException Message: " + e.getMessage(), context);
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
@@ -757,8 +780,7 @@ public class ItemsResource extends Resource
|
|||||||
writeStats(Constants.ITEM, dspaceItem, UsageEvent.Action.UPDATE, user_ip, user_agent, xforwarderfor, headers, request);
|
writeStats(Constants.ITEM, dspaceItem, UsageEvent.Action.UPDATE, user_ip, user_agent, xforwarderfor, headers, request);
|
||||||
|
|
||||||
log.trace("Deleting metadata.");
|
log.trace("Deleting metadata.");
|
||||||
// TODO Rewrite without deprecated object.
|
// TODO Rewrite without deprecated object. Leave there only generated metadata.
|
||||||
// Leave there only generated metadata.
|
|
||||||
DCValue[] value = dspaceItem.getMetadata("dc", "date", "accessioned", org.dspace.content.Item.ANY);
|
DCValue[] value = dspaceItem.getMetadata("dc", "date", "accessioned", org.dspace.content.Item.ANY);
|
||||||
DCValue[] value2 = dspaceItem.getMetadata("dc", "date", "available", org.dspace.content.Item.ANY);
|
DCValue[] value2 = dspaceItem.getMetadata("dc", "date", "available", org.dspace.content.Item.ANY);
|
||||||
DCValue[] value3 = dspaceItem.getMetadata("dc", "identifier", "uri", org.dspace.content.Item.ANY);
|
DCValue[] value3 = dspaceItem.getMetadata("dc", "identifier", "uri", org.dspace.content.Item.ANY);
|
||||||
@@ -930,7 +952,6 @@ public class ItemsResource extends Resource
|
|||||||
org.dspace.core.Context context = null;
|
org.dspace.core.Context context = null;
|
||||||
|
|
||||||
List<Item> items = new ArrayList<Item>();
|
List<Item> items = new ArrayList<Item>();
|
||||||
ItemIterator itemIterator = null;
|
|
||||||
String[] metadata = mySplit(metadataEntry.getKey());
|
String[] metadata = mySplit(metadataEntry.getKey());
|
||||||
|
|
||||||
try
|
try
|
||||||
@@ -940,17 +961,21 @@ public class ItemsResource extends Resource
|
|||||||
// TODO Repair, it ends by error:
|
// TODO Repair, it ends by error:
|
||||||
// "java.sql.SQLSyntaxErrorException: ORA-00932: inconsistent datatypes: expected - got CLOB"
|
// "java.sql.SQLSyntaxErrorException: ORA-00932: inconsistent datatypes: expected - got CLOB"
|
||||||
/*
|
/*
|
||||||
* if (metadata.length == 3) { itemIterator =
|
* if (metadata.length == 3){
|
||||||
* org.dspace.content.Item.findByMetadataField(context, metadata[0],
|
* itemIterator = org.dspace.content.Item.findByMetadataField(context, metadata[0],
|
||||||
* metadata[1], metadata[2], value); } else if (metadata.length ==
|
* metadata[1], metadata[2], value);
|
||||||
* 2) { itemIterator =
|
* } else if (metadata.length == 2){
|
||||||
* org.dspace.content.Item.findByMetadataField(context, metadata[0],
|
* itemIterator = org.dspace.content.Item.findByMetadataField(context, metadata[0],
|
||||||
* metadata[1], null, value); } else { context.abort();
|
* metadata[1], null, value);
|
||||||
* log.error("Finding failed, bad metadata key."); throw new
|
* } else {
|
||||||
* WebApplicationException(Response.Status.NOT_FOUND); }
|
* context.abort();
|
||||||
|
* log.error("Finding failed, bad metadata key.");
|
||||||
|
* throw new WebApplicationException(Response.Status.NOT_FOUND);
|
||||||
|
* }
|
||||||
*
|
*
|
||||||
* if (itemIterator.hasNext()) { item = new
|
* if (itemIterator.hasNext()) {
|
||||||
* Item(itemIterator.next(), "", context); }
|
* item = new Item(itemIterator.next(), "", context);
|
||||||
|
* }
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// Must used own style.
|
// Must used own style.
|
||||||
@@ -961,25 +986,37 @@ public class ItemsResource extends Resource
|
|||||||
throw new WebApplicationException(Response.Status.NOT_FOUND);
|
throw new WebApplicationException(Response.Status.NOT_FOUND);
|
||||||
}
|
}
|
||||||
|
|
||||||
org.dspace.content.Item dspaceItem = null;
|
String sql = "SELECT ITEM_ID, TEXT_VALUE, TEXT_LANG, SHORT_ID, ELEMENT, QUALIFIER " +
|
||||||
itemIterator = org.dspace.content.Item.findAll(context);
|
"FROM METADATAVALUE " +
|
||||||
org.dspace.content.DCValue[] dspaceValue = null;
|
"JOIN METADATAFIELDREGISTRY ON METADATAVALUE.METADATA_FIELD_ID = METADATAFIELDREGISTRY.METADATA_FIELD_ID " +
|
||||||
while (itemIterator.hasNext())
|
"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)
|
||||||
{
|
{
|
||||||
dspaceItem = itemIterator.next();
|
sql += "QUALIFIER='" + metadata[2] + "' AND ";
|
||||||
|
|
||||||
dspaceValue = dspaceItem.getMetadata(metadata[0], metadata[1], metadata[2], org.dspace.content.Item.ANY);
|
|
||||||
|
|
||||||
for (DCValue dcvalue : dspaceValue)
|
|
||||||
{
|
|
||||||
if (dcvalue.value.equals(metadataEntry.getValue()))
|
|
||||||
{
|
|
||||||
items.add(new Item(dspaceItem, expnad, context));
|
|
||||||
writeStats(Constants.ITEM, dspaceItem, UsageEvent.Action.VIEW, user_ip, user_agent, xforwarderfor,
|
|
||||||
headers, request);
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
sql += "dbms_lob.substr(TEXT_VALUE, 40)='" + 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("ITEM_ID"),
|
||||||
|
org.dspace.core.Constants.READ);
|
||||||
|
Item item = new Item(dspaceItem, "", context);
|
||||||
|
writeStats(Constants.ITEM, dspaceItem, UsageEvent.Action.VIEW, user_ip, user_agent, xforwarderfor, headers,
|
||||||
|
request);
|
||||||
|
items.add(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
context.complete();
|
context.complete();
|
||||||
@@ -988,13 +1025,7 @@ public class ItemsResource extends Resource
|
|||||||
catch (SQLException e)
|
catch (SQLException e)
|
||||||
{
|
{
|
||||||
processException("Something get wrong while finding item. SQLException, Message: " + e, context);
|
processException("Something get wrong while finding item. SQLException, Message: " + e, context);
|
||||||
}/*
|
}
|
||||||
* catch (AuthorizeException e) { processException(
|
|
||||||
* "Something get wrong while finding item. AuthorizeException, Message:"
|
|
||||||
* + e, context); } catch (IOException e) { processException(
|
|
||||||
* "Something get wrong while finding item. IOEception Message:" + e,
|
|
||||||
* context); }
|
|
||||||
*/
|
|
||||||
catch (ContextException e)
|
catch (ContextException e)
|
||||||
{
|
{
|
||||||
processException("Context error:" + e.getMessage(), context);
|
processException("Context error:" + e.getMessage(), context);
|
||||||
|
@@ -75,6 +75,7 @@ public class RestIndex {
|
|||||||
"<li>GET /collections/{collectionId} - Return collection with id.</li>" +
|
"<li>GET /collections/{collectionId} - Return collection with id.</li>" +
|
||||||
"<li>GET /collections/{collectionId}/items - Return all items of collection.</li>" +
|
"<li>GET /collections/{collectionId}/items - Return all items of collection.</li>" +
|
||||||
"<li>POST /collections/{collectionId}/items - Create posted item in collection.</li>" +
|
"<li>POST /collections/{collectionId}/items - Create posted item in collection.</li>" +
|
||||||
|
"<li>POST /collections/find-collection - Find collection by passed name.</li>" +
|
||||||
"<li>PUT /collections/{collectionId} </li> - Update collection. You muset post collection." +
|
"<li>PUT /collections/{collectionId} </li> - Update collection. You muset post collection." +
|
||||||
"<li>DELETE /collections/{collectionId} - Delete collection from DSpace.</li>" +
|
"<li>DELETE /collections/{collectionId} - Delete collection from DSpace.</li>" +
|
||||||
"<li>DELETE /collections/{collectionId}/items/{itemId} - Delete item in collection. </li>" +
|
"<li>DELETE /collections/{collectionId}/items/{itemId} - Delete item in collection. </li>" +
|
||||||
@@ -97,10 +98,13 @@ public class RestIndex {
|
|||||||
"<ul>" +
|
"<ul>" +
|
||||||
"<li>GET /bitstreams - Return all bitstreams in DSpace.</li>" +
|
"<li>GET /bitstreams - Return all bitstreams in DSpace.</li>" +
|
||||||
"<li>GET /bitstreams/{bitstream id} - Return bitstream.</li>" +
|
"<li>GET /bitstreams/{bitstream id} - Return bitstream.</li>" +
|
||||||
|
"<li>GET /bitstreams/{bitstream id}/policy - Return bitstream policies.</li>" +
|
||||||
"<li>POST /bitstreams/{bitstream id}/retrieve - Return data of bitstream.</li>" +
|
"<li>POST /bitstreams/{bitstream id}/retrieve - Return data of bitstream.</li>" +
|
||||||
|
"<li>POST /bitstreams/{bitstream id}/policy - Add policy to item.</li>" +
|
||||||
"<li>PUT /bitstreams/{bitstream id}/data - Update data of bitstream.</li>" +
|
"<li>PUT /bitstreams/{bitstream id}/data - Update data of bitstream.</li>" +
|
||||||
"<li>PUT /bitstreams/{bitstream id} - Update metadata of bitstream.</li>" +
|
"<li>PUT /bitstreams/{bitstream id} - Update metadata of bitstream.</li>" +
|
||||||
"<li>DELETE /bitstreams/{bitstream id} - Delete bitstream from DSpace.</li>" +
|
"<li>DELETE /bitstreams/{bitstream id} - Delete bitstream from DSpace.</li>" +
|
||||||
|
"<li>DELETE /bitstreams/{bitstream id}/policy/{policy_id} - Delete bitstream policy.</li>" +
|
||||||
"</ul>" +
|
"</ul>" +
|
||||||
"</body></html> ";
|
"</body></html> ";
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user