mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-07 01:54:22 +00:00
Item exposes its bitstreams
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
package org.dspace.rest;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.dspace.rest.common.Bitstream;
|
||||
|
||||
import javax.ws.rs.*;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import javax.ws.rs.core.Response;
|
||||
|
||||
/**
|
||||
* Created with IntelliJ IDEA.
|
||||
* User: peterdietz
|
||||
* Date: 10/2/13
|
||||
* Time: 5:56 PM
|
||||
* To change this template use File | Settings | File Templates.
|
||||
*/
|
||||
@Path("/bitstreams")
|
||||
public class BitstreamResource {
|
||||
Logger log = Logger.getLogger(BitstreamResource.class);
|
||||
private static org.dspace.core.Context context;
|
||||
|
||||
//BitstreamList - Not Implemented
|
||||
|
||||
@GET
|
||||
@Path("/{bitstream_id}")
|
||||
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
|
||||
public Bitstream getBitstream(@PathParam("bitstream_id") Integer bitstream_id, @QueryParam("expand") String expand) {
|
||||
return new org.dspace.rest.common.Bitstream(bitstream_id, expand);
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("/{bitstream_id}/retrieve")
|
||||
public javax.ws.rs.core.Response getFile(@PathParam("bitstream_id") final Integer bitstream_id) {
|
||||
try {
|
||||
|
||||
|
||||
if(context == null || !context.isValid() ) {
|
||||
context = new org.dspace.core.Context();
|
||||
}
|
||||
|
||||
org.dspace.content.Bitstream bitstream = org.dspace.content.Bitstream.find(context, bitstream_id);
|
||||
|
||||
return Response.ok(bitstream.retrieve()).type(bitstream.getFormat().getMIMEType()).build();
|
||||
|
||||
|
||||
} catch (Exception e) {
|
||||
return Response.serverError().build();
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,5 +1,13 @@
|
||||
package org.dspace.rest.common;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.dspace.authorize.AuthorizeException;
|
||||
import org.dspace.core.Context;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.sql.SQLException;
|
||||
|
||||
/**
|
||||
* Created with IntelliJ IDEA.
|
||||
* User: peterdietz
|
||||
@@ -8,6 +16,7 @@ package org.dspace.rest.common;
|
||||
* To change this template use File | Settings | File Templates.
|
||||
*/
|
||||
public class Bitstream {
|
||||
Logger log = Logger.getLogger(Bitstream.class);
|
||||
|
||||
String bundleName;
|
||||
String name;
|
||||
@@ -15,21 +24,55 @@ public class Bitstream {
|
||||
String format;
|
||||
String sizeBytes;
|
||||
|
||||
String retrieveLink;
|
||||
|
||||
final String type = "bitstream";
|
||||
Integer bitstreamID;
|
||||
|
||||
Context context;
|
||||
|
||||
public Bitstream() {
|
||||
|
||||
}
|
||||
|
||||
public Bitstream(org.dspace.content.Bitstream bitstream) {
|
||||
public Bitstream(Integer bitstreamID) {
|
||||
new Bitstream(bitstreamID, "");
|
||||
}
|
||||
|
||||
public Bitstream(Integer bitstreamID, String expand) {
|
||||
try {
|
||||
if(context == null || !context.isValid()) {
|
||||
context = new Context();
|
||||
}
|
||||
|
||||
org.dspace.content.Bitstream bitstream = org.dspace.content.Bitstream.find(context, bitstreamID);
|
||||
setup(bitstream, expand);
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public Bitstream(org.dspace.content.Bitstream bitstream, String expand) {
|
||||
setup(bitstream, expand);
|
||||
}
|
||||
|
||||
public void setup(org.dspace.content.Bitstream bitstream, String expand) {
|
||||
try {
|
||||
bitstreamID = bitstream.getID();
|
||||
bundleName = bitstream.getBundles()[0].getName();
|
||||
name = bitstream.getName();
|
||||
description = bitstream.getDescription();
|
||||
format = bitstream.getFormatDescription();
|
||||
sizeBytes = bitstream.getSize() + "";
|
||||
retrieveLink = "/bitstreams/" + bitstreamID + "/retrieve";
|
||||
} catch (Exception e) {
|
||||
//todo
|
||||
log.error(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public InputStream retrieve(org.dspace.content.Bitstream bitstream) throws SQLException, IOException, AuthorizeException {
|
||||
return bitstream.retrieve();
|
||||
}
|
||||
|
||||
public String getBundleName() {
|
||||
@@ -52,5 +95,17 @@ public class Bitstream {
|
||||
return sizeBytes;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public Integer getBitstreamID() {
|
||||
return bitstreamID;
|
||||
}
|
||||
|
||||
public String getRetrieveLink() {
|
||||
return retrieveLink;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@@ -99,7 +99,7 @@ public class Item {
|
||||
for(Bundle bundle : bundles) {
|
||||
org.dspace.content.Bitstream[] itemBitstreams = bundle.getBitstreams();
|
||||
for(org.dspace.content.Bitstream itemBitstream : itemBitstreams) {
|
||||
bitstreams.add(new Bitstream(itemBitstream));
|
||||
bitstreams.add(new Bitstream(itemBitstream, expand));
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user