Bitstream extends DSpaceObject. Also adding the mimeType to response

This commit is contained in:
Peter Dietz
2013-10-07 23:23:35 -04:00
parent 153c4cbdda
commit 3337434c85

View File

@@ -8,7 +8,8 @@
package org.dspace.rest.common; package org.dspace.rest.common;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.dspace.core.Context;
import javax.xml.bind.annotation.XmlRootElement;
/** /**
* Created with IntelliJ IDEA. * Created with IntelliJ IDEA.
@@ -17,58 +18,35 @@ import org.dspace.core.Context;
* Time: 12:54 AM * Time: 12:54 AM
* To change this template use File | Settings | File Templates. * To change this template use File | Settings | File Templates.
*/ */
public class Bitstream { @XmlRootElement(name = "bitstream")
public class Bitstream extends DSpaceObject {
Logger log = Logger.getLogger(Bitstream.class); Logger log = Logger.getLogger(Bitstream.class);
String bundleName; String bundleName;
String name;
String description; String description;
String format; String format;
String mimeType;
String sizeBytes; String sizeBytes;
String retrieveLink; String retrieveLink;
final String type = "bitstream";
Integer bitstreamID;
Context context;
public Bitstream() { public Bitstream() {
} }
public Bitstream(Integer bitstreamID) {
new Bitstream(bitstreamID, "");
}
public Bitstream(Integer bitstreamID, String expand) {
try {
if(context == null || !context.isValid()) {
context = new Context();
}
//TODO Auth check?
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) { public Bitstream(org.dspace.content.Bitstream bitstream, String expand) {
super(bitstream);
setup(bitstream, expand); setup(bitstream, expand);
} }
public void setup(org.dspace.content.Bitstream bitstream, String expand) { public void setup(org.dspace.content.Bitstream bitstream, String expand) {
try { try {
bitstreamID = bitstream.getID();
bundleName = bitstream.getBundles()[0].getName(); bundleName = bitstream.getBundles()[0].getName();
name = bitstream.getName();
description = bitstream.getDescription(); description = bitstream.getDescription();
format = bitstream.getFormatDescription(); format = bitstream.getFormatDescription();
sizeBytes = bitstream.getSize() + ""; sizeBytes = bitstream.getSize() + "";
retrieveLink = "/bitstreams/" + bitstreamID + "/retrieve"; retrieveLink = "/bitstreams/" + bitstream.getID() + "/retrieve";
mimeType = bitstream.getFormat().getMIMEType();
} catch (Exception e) { } catch (Exception e) {
log.error(e.getMessage()); log.error(e.getMessage());
} }
@@ -78,10 +56,6 @@ public class Bitstream {
return bundleName; return bundleName;
} }
public String getName() {
return name;
}
public String getDescription() { public String getDescription() {
return description; return description;
} }
@@ -90,21 +64,15 @@ public class Bitstream {
return format; return format;
} }
public String getMimeType() {
return mimeType;
}
public String getSizeBytes() { public String getSizeBytes() {
return sizeBytes; return sizeBytes;
} }
public String getType() {
return type;
}
public Integer getBitstreamID() {
return bitstreamID;
}
public String getRetrieveLink() { public String getRetrieveLink() {
return retrieveLink; return retrieveLink;
} }
} }