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)
|
||||
*/
|
||||
//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")
|
||||
public class BitstreamResource extends Resource{
|
||||
public class BitstreamResource extends Resource
|
||||
{
|
||||
|
||||
private static Logger log = Logger.getLogger(BitstreamResource.class);
|
||||
|
||||
@@ -84,31 +86,41 @@ public class BitstreamResource extends Resource{
|
||||
@GET
|
||||
@Path("/{bitstream_id}")
|
||||
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
|
||||
public Bitstream getBitstream(
|
||||
@PathParam("bitstream_id") Integer bitstreamId, @QueryParam("expand") String expand,
|
||||
public Bitstream getBitstream(@PathParam("bitstream_id") Integer bitstreamId, @QueryParam("expand") String expand,
|
||||
@QueryParam("userIP") String user_ip, @QueryParam("userAgent") String user_agent,
|
||||
@QueryParam("xforwarderfor") String xforwarderfor, @Context HttpHeaders headers,
|
||||
@Context HttpServletRequest request) throws WebApplicationException {
|
||||
@QueryParam("xforwarderfor") String xforwarderfor, @Context HttpHeaders headers, @Context HttpServletRequest request)
|
||||
throws WebApplicationException
|
||||
{
|
||||
|
||||
log.info("Reading bitstream(id=" + bitstreamId + ") metadata.");
|
||||
org.dspace.core.Context context = null;
|
||||
Bitstream bitstream = null;
|
||||
|
||||
try {
|
||||
try
|
||||
{
|
||||
context = createContext(getUser(headers));
|
||||
org.dspace.content.Bitstream dspaceBitstream = findBitstream(context, bitstreamId, org.dspace.core.Constants.READ);
|
||||
|
||||
writeStats(Constants.BITSTREAM, dspaceBitstream, UsageEvent.Action.VIEW, user_ip, user_agent, xforwarderfor, headers, request);
|
||||
writeStats(Constants.BITSTREAM, dspaceBitstream, UsageEvent.Action.VIEW, user_ip, user_agent, xforwarderfor, headers,
|
||||
request);
|
||||
|
||||
bitstream = new Bitstream(dspaceBitstream, expand);
|
||||
context.complete();
|
||||
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 (ContextException e) {
|
||||
processException("Someting went wrong while reading bitstream(id=" + bitstreamId + "), ContextException. Message: " + e.getMessage(), context);
|
||||
} finally {
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
processException("Someting went wrong while reading bitstream(id=" + bitstreamId + ") from database! Message: " + e,
|
||||
context);
|
||||
}
|
||||
catch (ContextException e)
|
||||
{
|
||||
processException("Someting went wrong while reading bitstream(id=" + bitstreamId + "), ContextException. Message: "
|
||||
+ e.getMessage(), context);
|
||||
}
|
||||
finally
|
||||
{
|
||||
context.abort();
|
||||
}
|
||||
|
||||
@@ -130,21 +142,26 @@ public class BitstreamResource extends Resource{
|
||||
@GET
|
||||
@Path("/{bitstream_id}/policy")
|
||||
@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.");
|
||||
org.dspace.core.Context context = null;
|
||||
List<ResourcePolicy> policies = new ArrayList<ResourcePolicy>();
|
||||
|
||||
try {
|
||||
try
|
||||
{
|
||||
context = createContext(getUser(headers));
|
||||
org.dspace.content.Bitstream dspaceBitstream = findBitstream(context, bitstreamId, org.dspace.core.Constants.READ);
|
||||
|
||||
Bundle[] bundles = dspaceBitstream.getBundles();
|
||||
for (Bundle bundle : bundles) {
|
||||
for (Bundle bundle : bundles)
|
||||
{
|
||||
List<org.dspace.authorize.ResourcePolicy> bitstreamsPolicies = bundle.getBitstreamPolicies();
|
||||
for (org.dspace.authorize.ResourcePolicy policy : bitstreamsPolicies) {
|
||||
if (policy.getResourceID() == bitstreamId) {
|
||||
for (org.dspace.authorize.ResourcePolicy policy : bitstreamsPolicies)
|
||||
{
|
||||
if (policy.getResourceID() == bitstreamId)
|
||||
{
|
||||
policies.add(new ResourcePolicy(policy));
|
||||
}
|
||||
}
|
||||
@@ -152,11 +169,19 @@ public class BitstreamResource extends Resource{
|
||||
context.complete();
|
||||
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 (ContextException e) {
|
||||
processException("Someting went wrong while reading policies of bitstream(id=" + bitstreamId + "), ContextException. Message: " + e.getMessage(), context);
|
||||
} finally {
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
processException("Someting went wrong while reading policies of bitstream(id=" + bitstreamId
|
||||
+ "), 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();
|
||||
}
|
||||
|
||||
@@ -184,34 +209,40 @@ public class BitstreamResource extends Resource{
|
||||
*/
|
||||
@GET
|
||||
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
|
||||
public Bitstream[] getBitstreams(
|
||||
@QueryParam("expand") String expand,
|
||||
@QueryParam("limit") @DefaultValue("100") Integer limit,
|
||||
@QueryParam("offset") @DefaultValue("0") Integer offset,
|
||||
public Bitstream[] getBitstreams(@QueryParam("expand") String expand,
|
||||
@QueryParam("limit") @DefaultValue("100") Integer limit, @QueryParam("offset") @DefaultValue("0") Integer offset,
|
||||
@QueryParam("userIP") String user_ip, @QueryParam("userAgent") String user_agent,
|
||||
@QueryParam("xforwarderfor") String xforwarderfor, @Context HttpHeaders headers,
|
||||
@Context HttpServletRequest request) throws WebApplicationException {
|
||||
@QueryParam("xforwarderfor") String xforwarderfor, @Context HttpHeaders headers, @Context HttpServletRequest request)
|
||||
throws WebApplicationException
|
||||
{
|
||||
|
||||
log.info("Reading bitstreams.(offset=" + offset + ",limit=" + limit + ")");
|
||||
org.dspace.core.Context context = null;
|
||||
List<Bitstream> bitstreams = new ArrayList<Bitstream>();
|
||||
|
||||
try {
|
||||
try
|
||||
{
|
||||
context = createContext(getUser(headers));
|
||||
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.");
|
||||
limit = 100;
|
||||
offset = 0;
|
||||
}
|
||||
|
||||
// TODO If bitsream doesnt not exist it throw exception.
|
||||
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
|
||||
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 of
|
||||
// reading under administrator permissions
|
||||
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();
|
||||
log.trace("Bitstreams were successfully read.");
|
||||
|
||||
} catch (SQLException e) {
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
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);
|
||||
} finally {
|
||||
}
|
||||
catch (ContextException e)
|
||||
{
|
||||
processException("Something get wrong while reading bitstreams, ContextException. Message: " + e.getMessage(),
|
||||
context);
|
||||
}
|
||||
finally
|
||||
{
|
||||
context.abort();
|
||||
}
|
||||
|
||||
@@ -254,20 +292,22 @@ public class BitstreamResource extends Resource{
|
||||
*/
|
||||
@POST
|
||||
@Path("/{bitstream_id}/retrieve")
|
||||
public javax.ws.rs.core.Response getBitstreamData(
|
||||
@PathParam("bitstream_id") Integer bitstreamId,
|
||||
public javax.ws.rs.core.Response getBitstreamData(@PathParam("bitstream_id") Integer bitstreamId,
|
||||
@QueryParam("userIP") String user_ip, @QueryParam("userAgent") String user_agent,
|
||||
@QueryParam("xforwarderfor") String xforwarderfor, @Context HttpHeaders headers,
|
||||
@Context HttpServletRequest request) throws WebApplicationException {
|
||||
@QueryParam("xforwarderfor") String xforwarderfor, @Context HttpHeaders headers, @Context HttpServletRequest request)
|
||||
throws WebApplicationException
|
||||
{
|
||||
|
||||
log.info("Reading data of bitstream(id=" + bitstreamId + ").");
|
||||
org.dspace.core.Context context = null;
|
||||
|
||||
try {
|
||||
try
|
||||
{
|
||||
context = createContext(getUser(headers));
|
||||
org.dspace.content.Bitstream dspaceBitstream = findBitstream(context, bitstreamId, org.dspace.core.Constants.READ);
|
||||
|
||||
writeStats(Constants.BITSTREAM, dspaceBitstream, UsageEvent.Action.VIEW, user_ip, user_agent, xforwarderfor, headers, request);
|
||||
writeStats(Constants.BITSTREAM, dspaceBitstream, UsageEvent.Action.VIEW, user_ip, user_agent, xforwarderfor, headers,
|
||||
request);
|
||||
|
||||
log.trace("Bitsream(id=" + bitstreamId + ") data was successfully read.");
|
||||
InputStream inputStream = dspaceBitstream.retrieve();
|
||||
@@ -277,15 +317,29 @@ public class BitstreamResource extends Resource{
|
||||
|
||||
return Response.ok(inputStream).type(type).build();
|
||||
|
||||
} catch (IOException e) {
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
processException("Could not read file of bitstream(id=" + bitstreamId + ")! Message: " + e, context);
|
||||
} catch (SQLException e) {
|
||||
processException("Something get wrong while reading bitsream(id=" + bitstreamId + ") from database! Message: " + e, 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 {
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
processException("Something get wrong while reading bitsream(id=" + bitstreamId + ") from database! Message: " + e,
|
||||
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();
|
||||
}
|
||||
|
||||
@@ -308,18 +362,23 @@ public class BitstreamResource extends Resource{
|
||||
*/
|
||||
@POST
|
||||
@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;
|
||||
|
||||
try {
|
||||
try
|
||||
{
|
||||
context = createContext(getUser(headers));
|
||||
org.dspace.content.Bitstream dspaceBitstream = findBitstream(context, bitstreamId, org.dspace.core.Constants.READ);
|
||||
|
||||
Bundle[] bundles = dspaceBitstream.getBundles();
|
||||
|
||||
for (Bundle bundle : bundles) {
|
||||
for (Bundle bundle : bundles)
|
||||
{
|
||||
List<org.dspace.authorize.ResourcePolicy> bitstreamsPolicies = bundle.getBitstreamPolicies();
|
||||
|
||||
org.dspace.authorize.ResourcePolicy dspacePolicy = org.dspace.authorize.ResourcePolicy.create(context);
|
||||
@@ -343,13 +402,24 @@ public class BitstreamResource extends Resource{
|
||||
context.complete();
|
||||
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 (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 {
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
processException("Someting went wrong while adding policy to bitstream(id=" + bitstreamId
|
||||
+ "), SQLException! Message: " + e, context);
|
||||
}
|
||||
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();
|
||||
}
|
||||
return Response.status(Status.OK).build();
|
||||
@@ -370,9 +440,9 @@ public class BitstreamResource extends Resource{
|
||||
* If you want to access to item under logged user into context.
|
||||
* In headers must be set header "rest-dspace-token" with passed
|
||||
* token from login method.
|
||||
* @return Return response codes: OK(200), NOT_FOUND(404) if bitstream
|
||||
* does not exist and UNAUTHORIZED(401) if user is not allowed to
|
||||
* write to bitstream.
|
||||
* @return Return response codes: OK(200), NOT_FOUND(404) if bitstream does
|
||||
* not exist and UNAUTHORIZED(401) if user is not allowed to write
|
||||
* to bitstream.
|
||||
* @throws WebApplicationException
|
||||
* It can be thrown by: Error in reading from database. Or
|
||||
* creating context or with authorization to bitstream.
|
||||
@@ -380,54 +450,66 @@ public class BitstreamResource extends Resource{
|
||||
@PUT
|
||||
@Path("/{bitstream_id}")
|
||||
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
|
||||
public Response updateBitstream(
|
||||
@PathParam("bitstream_id") Integer bitstreamId, Bitstream bitstream,
|
||||
public Response updateBitstream(@PathParam("bitstream_id") Integer bitstreamId, Bitstream bitstream,
|
||||
@QueryParam("userIP") String user_ip, @QueryParam("userAgent") String user_agent,
|
||||
@QueryParam("xforwarderfor") String xforwarderfor, @Context HttpHeaders headers,
|
||||
@Context HttpServletRequest request) throws WebApplicationException {
|
||||
@QueryParam("xforwarderfor") String xforwarderfor, @Context HttpHeaders headers, @Context HttpServletRequest request)
|
||||
throws WebApplicationException
|
||||
{
|
||||
|
||||
log.info("Updating bitstream(id=" + bitstreamId + ") metadata.");
|
||||
org.dspace.core.Context context = null;
|
||||
|
||||
try {
|
||||
try
|
||||
{
|
||||
context = createContext(getUser(headers));
|
||||
org.dspace.content.Bitstream dspaceBitstream = findBitstream(context, bitstreamId, org.dspace.core.Constants.WRITE);
|
||||
|
||||
writeStats(Constants.BITSTREAM, dspaceBitstream, UsageEvent.Action.UPDATE, user_ip, user_agent, xforwarderfor, headers, request);
|
||||
writeStats(Constants.BITSTREAM, dspaceBitstream, UsageEvent.Action.UPDATE, user_ip, user_agent, xforwarderfor,
|
||||
headers, request);
|
||||
|
||||
log.trace("Updating bitstream metadata.");
|
||||
dspaceBitstream.setDescription(bitstream.getDescription());
|
||||
if (getMimeType(bitstream.getName()) == null) {
|
||||
if (getMimeType(bitstream.getName()) == null)
|
||||
{
|
||||
dspaceBitstream.setFormat(BitstreamFormat.findUnknown(context));
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
dspaceBitstream.setFormat(BitstreamFormat.findByMIMEType(context, getMimeType(bitstream.getName())));
|
||||
}
|
||||
dspaceBitstream.setName(bitstream.getName());
|
||||
Integer sequenceId = bitstream.getSequenceId();
|
||||
if(sequenceId != null && sequenceId.intValue() != -1){
|
||||
if (sequenceId != null && sequenceId.intValue() != -1)
|
||||
{
|
||||
dspaceBitstream.setSequenceID(sequenceId);
|
||||
}
|
||||
|
||||
dspaceBitstream.update();
|
||||
|
||||
if (bitstream.getPolicies() != null) {
|
||||
if (bitstream.getPolicies() != null)
|
||||
{
|
||||
Bundle[] bundles = dspaceBitstream.getBundles();
|
||||
ResourcePolicy[] policies = bitstream.getPolicies();
|
||||
for (Bundle bundle : bundles) {
|
||||
for (Bundle bundle : bundles)
|
||||
{
|
||||
List<org.dspace.authorize.ResourcePolicy> bitstreamsPolicies = bundle.getBitstreamPolicies();
|
||||
// Remove old bitstream policies
|
||||
List<org.dspace.authorize.ResourcePolicy> policiesToRemove = new ArrayList<org.dspace.authorize.ResourcePolicy>();
|
||||
for (org.dspace.authorize.ResourcePolicy policy : bitstreamsPolicies) {
|
||||
if (policy.getResourceID() == dspaceBitstream.getID()) {
|
||||
for (org.dspace.authorize.ResourcePolicy policy : bitstreamsPolicies)
|
||||
{
|
||||
if (policy.getResourceID() == dspaceBitstream.getID())
|
||||
{
|
||||
policiesToRemove.add(policy);
|
||||
}
|
||||
}
|
||||
for (org.dspace.authorize.ResourcePolicy policy : policiesToRemove) {
|
||||
for (org.dspace.authorize.ResourcePolicy policy : policiesToRemove)
|
||||
{
|
||||
bitstreamsPolicies.remove(policy);
|
||||
}
|
||||
|
||||
// Add all new bitstream policies
|
||||
for (ResourcePolicy policy : policies) {
|
||||
for (ResourcePolicy policy : policies)
|
||||
{
|
||||
org.dspace.authorize.ResourcePolicy dspacePolicy = org.dspace.authorize.ResourcePolicy.create(context);
|
||||
dspacePolicy.setAction(policy.getActionInt());
|
||||
dspacePolicy.setGroup(Group.find(context, policy.getGroupId()));
|
||||
@@ -448,13 +530,24 @@ public class BitstreamResource extends Resource{
|
||||
|
||||
context.complete();
|
||||
|
||||
} catch(SQLException e) {
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
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 (ContextException e) {
|
||||
processException("Could not update bitstream(id=" + bitstreamId + ") metadata, ContextException. Message: " + e.getMessage(), context);
|
||||
} finally {
|
||||
}
|
||||
catch (AuthorizeException e)
|
||||
{
|
||||
processException("Could not update bitstream(id=" + bitstreamId + ") metadata, AuthorizeException. Message: " + e,
|
||||
context);
|
||||
}
|
||||
catch (ContextException e)
|
||||
{
|
||||
processException(
|
||||
"Could not update bitstream(id=" + bitstreamId + ") metadata, ContextException. Message: " + e.getMessage(),
|
||||
context);
|
||||
}
|
||||
finally
|
||||
{
|
||||
context.abort();
|
||||
}
|
||||
|
||||
@@ -488,20 +581,22 @@ public class BitstreamResource extends Resource{
|
||||
// TODO Change to better logic, without editing database.
|
||||
@PUT
|
||||
@Path("/{bitstream_id}/data")
|
||||
public Response updateBitstreamData(
|
||||
@PathParam("bitstream_id") Integer bitstreamId, InputStream is,
|
||||
public Response updateBitstreamData(@PathParam("bitstream_id") Integer bitstreamId, InputStream is,
|
||||
@QueryParam("userIP") String user_ip, @QueryParam("userAgent") String user_agent,
|
||||
@QueryParam("xforwarderfor") String xforwarderfor, @Context HttpHeaders headers,
|
||||
@Context HttpServletRequest request) throws WebApplicationException {
|
||||
@QueryParam("xforwarderfor") String xforwarderfor, @Context HttpHeaders headers, @Context HttpServletRequest request)
|
||||
throws WebApplicationException
|
||||
{
|
||||
|
||||
log.info("Updating bitstream(id=" + bitstreamId + ") data.");
|
||||
org.dspace.core.Context context = null;
|
||||
|
||||
try{
|
||||
try
|
||||
{
|
||||
context = createContext(getUser(headers));
|
||||
org.dspace.content.Bitstream dspaceBitstream = findBitstream(context, bitstreamId, org.dspace.core.Constants.WRITE);
|
||||
|
||||
writeStats(Constants.BITSTREAM, dspaceBitstream, UsageEvent.Action.UPDATE, user_ip, user_agent, xforwarderfor, headers, request);
|
||||
writeStats(Constants.BITSTREAM, dspaceBitstream, UsageEvent.Action.UPDATE, user_ip, user_agent, xforwarderfor,
|
||||
headers, request);
|
||||
|
||||
log.trace("Creating new bitstream.");
|
||||
int newBitstreamId = BitstreamStorageManager.store(context, is);
|
||||
@@ -523,13 +618,23 @@ public class BitstreamResource extends Resource{
|
||||
|
||||
context.complete();
|
||||
|
||||
} catch(SQLException e) {
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
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);
|
||||
} catch (ContextException e) {
|
||||
processException("Could not update bitstream(id=" + bitstreamId + ") data, ContextException. Message: " + e.getMessage(), context);
|
||||
} finally {
|
||||
}
|
||||
catch (ContextException e)
|
||||
{
|
||||
processException(
|
||||
"Could not update bitstream(id=" + bitstreamId + ") data, ContextException. Message: " + e.getMessage(),
|
||||
context);
|
||||
}
|
||||
finally
|
||||
{
|
||||
context.abort();
|
||||
}
|
||||
|
||||
@@ -561,37 +666,50 @@ public class BitstreamResource extends Resource{
|
||||
*/
|
||||
@DELETE
|
||||
@Path("/{bitstream_id}")
|
||||
public Response deleteBitstream(
|
||||
@PathParam("bitstream_id") Integer bitstreamId,
|
||||
@QueryParam("userIP") String user_ip, @QueryParam("userAgent") String user_agent,
|
||||
@QueryParam("xforwarderfor") String xforwarderfor, @Context HttpHeaders headers,
|
||||
@Context HttpServletRequest request) throws WebApplicationException {
|
||||
public Response deleteBitstream(@PathParam("bitstream_id") Integer bitstreamId, @QueryParam("userIP") String user_ip,
|
||||
@QueryParam("userAgent") String user_agent, @QueryParam("xforwarderfor") String xforwarderfor,
|
||||
@Context HttpHeaders headers, @Context HttpServletRequest request) throws WebApplicationException
|
||||
{
|
||||
|
||||
log.info("Deleting bitstream(id=" + bitstreamId + ").");
|
||||
org.dspace.core.Context context = null;
|
||||
|
||||
try {
|
||||
try
|
||||
{
|
||||
context = createContext(getUser(headers));
|
||||
org.dspace.content.Bitstream dspaceBitstream = findBitstream(context, bitstreamId, org.dspace.core.Constants.DELETE);
|
||||
|
||||
writeStats(Constants.BITSTREAM, dspaceBitstream, UsageEvent.Action.DELETE, user_ip, user_agent, xforwarderfor, headers, request);
|
||||
writeStats(Constants.BITSTREAM, dspaceBitstream, UsageEvent.Action.DELETE, user_ip, user_agent, xforwarderfor,
|
||||
headers, request);
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
context.complete();
|
||||
|
||||
} catch(SQLException e) {
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
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);
|
||||
} catch (IOException e) {
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
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);
|
||||
} finally {
|
||||
}
|
||||
catch (ContextException e)
|
||||
{
|
||||
processException("Could not delete bitstream(id=" + bitstreamId + "), ContextException. Message:" + e.getMessage(),
|
||||
context);
|
||||
}
|
||||
finally
|
||||
{
|
||||
context.abort();
|
||||
}
|
||||
|
||||
@@ -614,22 +732,28 @@ public class BitstreamResource extends Resource{
|
||||
*/
|
||||
@DELETE
|
||||
@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 + ").");
|
||||
org.dspace.core.Context context = null;
|
||||
|
||||
try {
|
||||
try
|
||||
{
|
||||
context = createContext(getUser(headers));
|
||||
org.dspace.content.Bitstream dspaceBitstream = findBitstream(context, bitstreamId, org.dspace.core.Constants.READ);
|
||||
|
||||
Bundle[] bundles = dspaceBitstream.getBundles();
|
||||
|
||||
for (Bundle bundle : bundles) {
|
||||
for (Bundle bundle : bundles)
|
||||
{
|
||||
List<org.dspace.authorize.ResourcePolicy> bitstreamsPolicies = bundle.getBitstreamPolicies();
|
||||
|
||||
for (org.dspace.authorize.ResourcePolicy policy : bitstreamsPolicies) {
|
||||
if (policy.getID() == policyId.intValue()) {
|
||||
for (org.dspace.authorize.ResourcePolicy policy : bitstreamsPolicies)
|
||||
{
|
||||
if (policy.getID() == policyId.intValue())
|
||||
{
|
||||
bitstreamsPolicies.remove(policy);
|
||||
break;
|
||||
}
|
||||
@@ -642,13 +766,24 @@ public class BitstreamResource extends Resource{
|
||||
context.complete();
|
||||
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 (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 {
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
processException("Someting went wrong while deleting READ policy(id=" + policyId + ") to bitstream(id=" + bitstreamId
|
||||
+ "), SQLException! Message: " + e, context);
|
||||
}
|
||||
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();
|
||||
}
|
||||
return Response.status(Status.OK).build();
|
||||
@@ -661,7 +796,8 @@ public class BitstreamResource extends Resource{
|
||||
* Name of file.
|
||||
* @return String filled with type of file in MIME style.
|
||||
*/
|
||||
static String getMimeType(String name) {
|
||||
static String getMimeType(String 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
|
||||
* 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;
|
||||
try {
|
||||
try
|
||||
{
|
||||
bitstream = org.dspace.content.Bitstream.find(context, id);
|
||||
|
||||
if ((bitstream == null) || (bitstream.getParentObject() == null)) {
|
||||
if ((bitstream == null) || (bitstream.getParentObject() == null))
|
||||
{
|
||||
context.abort();
|
||||
log.warn("Bitstream(id=" + id + ") was 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();
|
||||
if (context.getCurrentUser() != null ) {
|
||||
log.error("User(" + context.getCurrentUser().getEmail() + ") has not permission to " + getActionString(action) + " bitstream!");
|
||||
} else {
|
||||
if (context.getCurrentUser() != null)
|
||||
{
|
||||
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!");
|
||||
}
|
||||
throw new WebApplicationException(Response.Status.UNAUTHORIZED);
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
processException("Something get wrong while finding bitstream. SQLException, Message:" + e, context);
|
||||
} finally {
|
||||
}
|
||||
finally
|
||||
{
|
||||
context.abort();
|
||||
}
|
||||
return bitstream;
|
||||
|
@@ -175,10 +175,9 @@ public class CollectionsResource extends Resource
|
||||
offset = 0;
|
||||
}
|
||||
|
||||
// dspaceCollections =
|
||||
// org.dspace.content.Collection.findAll(context, limit, offset); //
|
||||
// Message:java.sql.SQLSyntaxErrorException: ORA-00933: SQL command
|
||||
// not properly ended
|
||||
// TODO Repair it in DSpace api
|
||||
// dspaceCollections = org.dspace.content.Collection.findAll(context, limit, offset);
|
||||
// Message:java.sql.SQLSyntaxErrorException: ORA-00933: SQL command not properly ended
|
||||
dspaceCollections = org.dspace.content.Collection.findAll(context);
|
||||
|
||||
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
|
||||
* context. In headers must be set header "rest-dspace-token"
|
||||
* with passed token from login method.
|
||||
* @return Return status code with item. Return status
|
||||
* (OK)200 if item was created. NOT_FOUND(404) if id of collection
|
||||
* does not exists. UNAUTHORIZED(401) if user have not permission to
|
||||
* write items in collection.
|
||||
* @return Return status code with item. Return status (OK)200 if item was
|
||||
* created. NOT_FOUND(404) if id of collection does not exists.
|
||||
* UNAUTHORIZED(401) if user have not permission to write items in
|
||||
* collection.
|
||||
* @throws WebApplicationException
|
||||
* It is thrown when was problem with database reading or
|
||||
* writing (SQLException) or problem with creating
|
||||
@@ -449,8 +448,7 @@ public class CollectionsResource extends Resource
|
||||
|
||||
dspaceCollection.setMetadata("name", collection.getName());
|
||||
dspaceCollection.setLicense(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());
|
||||
dspaceCollection.setMetadata(org.dspace.content.Collection.INTRODUCTORY_TEXT, collection.getIntroductoryText());
|
||||
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.
|
||||
* @param name Name of collection.
|
||||
*
|
||||
* @param name
|
||||
* Name of collection.
|
||||
* @param headers
|
||||
* If you want to access to collection under logged user into
|
||||
* context. In headers must be set header "rest-dspace-token"
|
||||
* 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
|
||||
*/
|
||||
@POST
|
||||
@Path("/find-collection")
|
||||
@Consumes({ 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 + ".");
|
||||
org.dspace.core.Context context = null;
|
||||
Collection collection = null;
|
||||
|
||||
try {
|
||||
try
|
||||
{
|
||||
context = createContext(getUser(headers));
|
||||
org.dspace.content.Collection[] dspaceCollections;
|
||||
|
||||
dspaceCollections = org.dspace.content.Collection.findAll(context);
|
||||
|
||||
for (org.dspace.content.Collection dspaceCollection : dspaceCollections) {
|
||||
if (AuthorizeManager.authorizeActionBoolean(context, dspaceCollection, org.dspace.core.Constants.READ)) {
|
||||
if (dspaceCollection.getName().equals(name)) {
|
||||
for (org.dspace.content.Collection dspaceCollection : dspaceCollections)
|
||||
{
|
||||
if (AuthorizeManager.authorizeActionBoolean(context, dspaceCollection, org.dspace.core.Constants.READ))
|
||||
{
|
||||
if (dspaceCollection.getName().equals(name))
|
||||
{
|
||||
collection = new Collection(dspaceCollection, "", context, 100, 0);
|
||||
break;
|
||||
}
|
||||
@@ -694,19 +700,28 @@ public class CollectionsResource extends Resource
|
||||
|
||||
context.complete();
|
||||
|
||||
} catch (SQLException e) {
|
||||
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);
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
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
|
||||
{
|
||||
context.abort();
|
||||
}
|
||||
|
||||
if (collection == null) {
|
||||
if (collection == null)
|
||||
{
|
||||
log.info("Collection was not found.");
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
log.info("Collection was found with id(" + collection.getId() + ").");
|
||||
}
|
||||
return collection;
|
||||
|
@@ -10,7 +10,6 @@ package org.dspace.rest;
|
||||
import java.io.IOException;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
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.Community;
|
||||
import org.dspace.rest.exceptions.ContextException;
|
||||
import org.dspace.storage.rdbms.TableRow;
|
||||
import org.dspace.storage.rdbms.TableRowIterator;
|
||||
import org.dspace.usage.UsageEvent;
|
||||
|
||||
/**
|
||||
@@ -612,7 +609,8 @@ public class CommunitiesResource extends Resource
|
||||
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;
|
||||
}
|
||||
|
||||
|
@@ -45,6 +45,8 @@ 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;
|
||||
|
||||
/**
|
||||
@@ -53,8 +55,7 @@ import org.dspace.usage.UsageEvent;
|
||||
* @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.
|
||||
@SuppressWarnings("deprecation")
|
||||
@Path("/items")
|
||||
public class ItemsResource extends Resource
|
||||
@@ -383,10 +384,8 @@ public class ItemsResource extends Resource
|
||||
|
||||
for (MetadataEntry entry : metadata)
|
||||
{
|
||||
String data[] = mySplit(entry.getKey()); // Done by my split,
|
||||
// because of java
|
||||
// split was not
|
||||
// function.
|
||||
// TODO Test with Java split
|
||||
String data[] = mySplit(entry.getKey()); // Done by my split, because of java split was not function.
|
||||
if ((data.length >= 2) && (data.length <= 3))
|
||||
{
|
||||
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.
|
||||
* In headers must be set header "rest-dspace-token" with passed
|
||||
* token from login method.
|
||||
* @return Returns bitstream with status code OK(200). If id of item
|
||||
* is invalid , it returns status code NOT_FOUND(404). If user is
|
||||
* not allowed to write to item, UNAUTHORIZED(401).
|
||||
* @return Returns bitstream with status code OK(200). If id of item is
|
||||
* invalid , it returns status code NOT_FOUND(404). If user is not
|
||||
* allowed to write to item, UNAUTHORIZED(401).
|
||||
* @throws WebApplicationException
|
||||
* It is thrown by these exceptions: SQLException, when was
|
||||
* 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)
|
||||
@POST
|
||||
@Path("/{item_id}/bitstreams")
|
||||
public Bitstream addItemBitstream(
|
||||
@PathParam("item_id") Integer itemId, InputStream inputStream,
|
||||
public Bitstream addItemBitstream(@PathParam("item_id") Integer itemId, InputStream inputStream,
|
||||
@QueryParam("name") String name, @QueryParam("description") String description,
|
||||
@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("xforwarderfor") String xforwarderfor, @Context HttpHeaders headers, @Context HttpServletRequest request)
|
||||
throws WebApplicationException {
|
||||
throws WebApplicationException
|
||||
{
|
||||
|
||||
log.info("Adding bitstream to item(id=" + itemId + ").");
|
||||
org.dspace.core.Context context = null;
|
||||
Bitstream bitstream = null;
|
||||
|
||||
try {
|
||||
try
|
||||
{
|
||||
context = createContext(getUser(headers));
|
||||
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.");
|
||||
org.dspace.content.Bundle bundle = 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.");
|
||||
dspaceBitstream = dspaceItem.createSingleBitstream(inputStream);
|
||||
//bundle = dspaceItem.getBundles()[0];
|
||||
//bundle.setName(dspaceItem.getID() + "-bundle");
|
||||
//bundle.update();
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
log.trace("Getting bundle from item.");
|
||||
bundle = dspaceItem.getBundles()[0];
|
||||
dspaceBitstream = bundle.createBitstream(inputStream);
|
||||
@@ -481,34 +481,44 @@ public class ItemsResource extends Resource
|
||||
dspaceBitstream.setSource("DSpace Rest api");
|
||||
|
||||
// Set bitstream name and description
|
||||
if (name != null) {
|
||||
if (BitstreamResource.getMimeType(name) == null) {
|
||||
if (name != null)
|
||||
{
|
||||
if (BitstreamResource.getMimeType(name) == null)
|
||||
{
|
||||
dspaceBitstream.setFormat(BitstreamFormat.findUnknown(context));
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
dspaceBitstream.setFormat(BitstreamFormat.findByMIMEType(context, BitstreamResource.getMimeType(name)));
|
||||
}
|
||||
dspaceBitstream.setName(name);
|
||||
}
|
||||
if (description != null) {
|
||||
if (description != null)
|
||||
{
|
||||
dspaceBitstream.setDescription(description);
|
||||
}
|
||||
|
||||
dspaceBitstream.update();
|
||||
|
||||
// Create policy for bitstream
|
||||
if (groupId != null) {
|
||||
if (groupId != null)
|
||||
{
|
||||
Bundle[] bundles = dspaceBitstream.getBundles();
|
||||
for (Bundle dspaceBundle : bundles) {
|
||||
for (Bundle dspaceBundle : bundles)
|
||||
{
|
||||
List<org.dspace.authorize.ResourcePolicy> bitstreamsPolicies = dspaceBundle.getBitstreamPolicies();
|
||||
|
||||
// Remove default bitstream policies
|
||||
List<org.dspace.authorize.ResourcePolicy> policiesToRemove = new ArrayList<org.dspace.authorize.ResourcePolicy>();
|
||||
for (org.dspace.authorize.ResourcePolicy policy : bitstreamsPolicies) {
|
||||
if (policy.getResourceID() == dspaceBitstream.getID()) {
|
||||
for (org.dspace.authorize.ResourcePolicy policy : bitstreamsPolicies)
|
||||
{
|
||||
if (policy.getResourceID() == dspaceBitstream.getID())
|
||||
{
|
||||
policiesToRemove.add(policy);
|
||||
}
|
||||
}
|
||||
for (org.dspace.authorize.ResourcePolicy policy : policiesToRemove) {
|
||||
for (org.dspace.authorize.ResourcePolicy policy : policiesToRemove)
|
||||
{
|
||||
bitstreamsPolicies.remove(policy);
|
||||
}
|
||||
|
||||
@@ -518,15 +528,19 @@ public class ItemsResource extends Resource
|
||||
dspacePolicy.setResourceID(dspaceBitstream.getID());
|
||||
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();
|
||||
if (year != null) {
|
||||
if (year != null)
|
||||
{
|
||||
date.setYear(year - 1900);
|
||||
}
|
||||
if (month != null) {
|
||||
if (month != null)
|
||||
{
|
||||
date.setMonth(month - 1);
|
||||
}
|
||||
if (day != null) {
|
||||
if (day != null)
|
||||
{
|
||||
date.setDate(day);
|
||||
}
|
||||
date.setHours(0);
|
||||
@@ -547,14 +561,23 @@ public class ItemsResource extends Resource
|
||||
|
||||
context.complete();
|
||||
|
||||
} catch (SQLException e) {
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
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);
|
||||
} catch (IOException e) {
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
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
|
||||
{
|
||||
@@ -757,8 +780,7 @@ public class ItemsResource extends Resource
|
||||
writeStats(Constants.ITEM, dspaceItem, UsageEvent.Action.UPDATE, user_ip, user_agent, xforwarderfor, headers, request);
|
||||
|
||||
log.trace("Deleting metadata.");
|
||||
// TODO Rewrite without deprecated object.
|
||||
// Leave there only generated metadata.
|
||||
// TODO Rewrite without deprecated object. Leave there only generated metadata.
|
||||
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[] 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;
|
||||
|
||||
List<Item> items = new ArrayList<Item>();
|
||||
ItemIterator itemIterator = null;
|
||||
String[] metadata = mySplit(metadataEntry.getKey());
|
||||
|
||||
try
|
||||
@@ -940,17 +961,21 @@ public class ItemsResource extends Resource
|
||||
// TODO Repair, it ends by error:
|
||||
// "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 (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); }
|
||||
* if (itemIterator.hasNext()) {
|
||||
* item = new Item(itemIterator.next(), "", context);
|
||||
* }
|
||||
*/
|
||||
|
||||
// Must used own style.
|
||||
@@ -961,25 +986,37 @@ public class ItemsResource extends Resource
|
||||
throw new WebApplicationException(Response.Status.NOT_FOUND);
|
||||
}
|
||||
|
||||
org.dspace.content.Item dspaceItem = null;
|
||||
itemIterator = org.dspace.content.Item.findAll(context);
|
||||
org.dspace.content.DCValue[] dspaceValue = null;
|
||||
while (itemIterator.hasNext())
|
||||
String sql = "SELECT ITEM_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)
|
||||
{
|
||||
dspaceItem = itemIterator.next();
|
||||
|
||||
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 += "QUALIFIER='" + metadata[2] + "' AND ";
|
||||
}
|
||||
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();
|
||||
@@ -988,13 +1025,7 @@ public class ItemsResource extends Resource
|
||||
catch (SQLException e)
|
||||
{
|
||||
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)
|
||||
{
|
||||
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}/items - Return all items of 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>DELETE /collections/{collectionId} - Delete collection from DSpace.</li>" +
|
||||
"<li>DELETE /collections/{collectionId}/items/{itemId} - Delete item in collection. </li>" +
|
||||
@@ -97,10 +98,13 @@ public class RestIndex {
|
||||
"<ul>" +
|
||||
"<li>GET /bitstreams - Return all bitstreams in DSpace.</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}/policy - Add policy to item.</li>" +
|
||||
"<li>PUT /bitstreams/{bitstream id}/data - Update data 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}/policy/{policy_id} - Delete bitstream policy.</li>" +
|
||||
"</ul>" +
|
||||
"</body></html> ";
|
||||
}
|
||||
|
Reference in New Issue
Block a user