diff --git a/dspace-rest/pom.xml b/dspace-rest/pom.xml
index 15f2c59902..5e460fbb4a 100644
--- a/dspace-rest/pom.xml
+++ b/dspace-rest/pom.xml
@@ -61,6 +61,11 @@
javax.servlet-api
3.0.1
+
+ org.atteo
+ evo-inflector
+ 1.0.1
+
diff --git a/dspace-rest/src/main/java/org/dspace/rest/CollectionsResource.java b/dspace-rest/src/main/java/org/dspace/rest/CollectionsResource.java
index d474b706fc..d0a4fd7caa 100644
--- a/dspace-rest/src/main/java/org/dspace/rest/CollectionsResource.java
+++ b/dspace-rest/src/main/java/org/dspace/rest/CollectionsResource.java
@@ -1,6 +1,7 @@
package org.dspace.rest;
+import org.apache.log4j.Logger;
import org.dspace.authorize.AuthorizeManager;
import org.dspace.core.Context;
@@ -20,6 +21,8 @@ http://localhost:8080//collections
*/
@Path("/collections")
public class CollectionsResource {
+ private static Logger log = Logger.getLogger(CollectionsResource.class);
+
@javax.ws.rs.core.Context ServletContext servletContext;
private static org.dspace.core.Context context;
@@ -43,6 +46,7 @@ public class CollectionsResource {
}
} catch (SQLException e) {
+ log.error(e.getMessage());
return "ERROR: " + e.getMessage();
}
@@ -70,6 +74,7 @@ public class CollectionsResource {
return collectionArrayList.toArray(new org.dspace.rest.common.Collection[0]);
} catch (SQLException e) {
+ e.getMessage();
throw new WebApplicationException(Response.Status.INTERNAL_SERVER_ERROR);
}
}
@@ -90,6 +95,7 @@ public class CollectionsResource {
throw new WebApplicationException(Response.Status.UNAUTHORIZED);
}
} catch (SQLException e) {
+ log.error(e.getMessage());
throw new WebApplicationException(Response.Status.INTERNAL_SERVER_ERROR);
}
}
diff --git a/dspace-rest/src/main/java/org/dspace/rest/CommunitiesResource.java b/dspace-rest/src/main/java/org/dspace/rest/CommunitiesResource.java
index edbd8af162..86d3a34a9b 100644
--- a/dspace-rest/src/main/java/org/dspace/rest/CommunitiesResource.java
+++ b/dspace-rest/src/main/java/org/dspace/rest/CommunitiesResource.java
@@ -1,5 +1,6 @@
package org.dspace.rest;
+import org.apache.log4j.Logger;
import org.dspace.authorize.AuthorizeManager;
import org.dspace.core.Context;
@@ -18,6 +19,8 @@ http://localhost:8080//communities
*/
@Path("/communities")
public class CommunitiesResource {
+ private static Logger log = Logger.getLogger(CommunitiesResource.class);
+
private static Context context;
/*
@@ -38,6 +41,7 @@ public class CommunitiesResource {
}
} catch (SQLException e) {
+ log.error(e.getMessage());
return "ERROR: " + e.getMessage();
}
@@ -68,6 +72,7 @@ public class CommunitiesResource {
return communityArrayList.toArray(new org.dspace.rest.common.Community[0]);
} catch (SQLException e) {
+ log.error(e.getMessage());
throw new WebApplicationException(Response.Status.INTERNAL_SERVER_ERROR);
}
}
@@ -88,6 +93,7 @@ public class CommunitiesResource {
throw new WebApplicationException(Response.Status.UNAUTHORIZED);
}
} catch (SQLException e) {
+ log.error(e.getMessage());
throw new WebApplicationException(Response.Status.INTERNAL_SERVER_ERROR);
}
}
diff --git a/dspace-rest/src/main/java/org/dspace/rest/HandleResource.java b/dspace-rest/src/main/java/org/dspace/rest/HandleResource.java
new file mode 100644
index 0000000000..2ca209958d
--- /dev/null
+++ b/dspace-rest/src/main/java/org/dspace/rest/HandleResource.java
@@ -0,0 +1,11 @@
+package org.dspace.rest;
+
+/**
+ * Created with IntelliJ IDEA.
+ * User: peterdietz
+ * Date: 10/7/13
+ * Time: 1:54 PM
+ * To change this template use File | Settings | File Templates.
+ */
+public class HandleResource {
+}
diff --git a/dspace-rest/src/main/java/org/dspace/rest/common/Collection.java b/dspace-rest/src/main/java/org/dspace/rest/common/Collection.java
index 531552c378..aa80c31bdf 100644
--- a/dspace-rest/src/main/java/org/dspace/rest/common/Collection.java
+++ b/dspace-rest/src/main/java/org/dspace/rest/common/Collection.java
@@ -21,29 +21,20 @@ import java.util.List;
* To change this template use File | Settings | File Templates.
*/
@XmlRootElement(name = "collection")
-public class Collection {
+public class Collection extends DSpaceObject {
Logger log = Logger.getLogger(Collection.class);
- //Internal value
- private Integer collectionID;
-
//Relationships to other objects
private Integer logoID;
- @XmlElement(name = "type", required = true)
- final String type = "collection";
-
//Exandable relationships
private Integer parentCommunityID;
private List parentCommunityIDList = new ArrayList();
private List itemIDList = new ArrayList();
@XmlElement(name = "items")
- private List items = new ArrayList();
+ private List items = new ArrayList();
- //Internal metadata
- private String name;
- private String handle;
private String license;
//unused-metadata
@@ -53,25 +44,6 @@ public class Collection {
//String copyright_text;
//String side_bar_text;
- @XmlElement(name = "link", required = true)
- private String link;
-
- public String getName() {
- return name;
- }
-
- public void setName(String name) {
- this.name = name;
- }
-
- public String getHandle() {
- return handle;
- }
-
- public void setHandle(String handle) {
- this.handle = handle;
- }
-
public String getLicense() {
return license;
}
@@ -80,16 +52,13 @@ public class Collection {
this.license = license;
}
-
- private List expand = new ArrayList();
-
-
//Calculated
private Integer numberItems;
public Collection(){}
public Collection(org.dspace.content.Collection collection, String expand, Context context) throws SQLException, WebApplicationException{
+ super(collection);
setup(collection, expand, context);
}
@@ -99,10 +68,6 @@ public class Collection {
expandFields = Arrays.asList(expand.split(","));
}
- setCollectionID(collection.getID());
- setName(collection.getName());
- setHandle(collection.getHandle());
-
if(expandFields.contains("parentCommunityIDList") || expandFields.contains("all")) {
org.dspace.content.Community[] parentCommunities = collection.getCommunities();
for(org.dspace.content.Community parentCommunity : parentCommunities) {
@@ -122,11 +87,11 @@ public class Collection {
//TODO: Item paging. limit, offset/page
if(expandFields.contains("items") || expandFields.contains("all")) {
ItemIterator childItems = collection.getItems();
- items = new ArrayList();
+ items = new ArrayList();
while(childItems.hasNext()) {
org.dspace.content.Item item = childItems.next();
if(AuthorizeManager.authorizeActionBoolean(context, item, org.dspace.core.Constants.READ)) {
- items.add(new LiteItem(item));
+ items.add(new DSpaceObject(item));
}
}
} else {
@@ -148,15 +113,6 @@ public class Collection {
}
this.setNumberItems(collection.countItems());
- //collection.getMetadata()
- }
-
- public Integer getCollectionID() {
- return collectionID;
- }
-
- public void setCollectionID(Integer id) {
- this.collectionID = id;
}
public Integer getLogoID() {
@@ -195,7 +151,6 @@ public class Collection {
this.parentCommunityIDList.add(communityParentID);
}
-
public List getItemIDList() {
return itemIDList;
}
@@ -207,22 +162,4 @@ public class Collection {
public void addItemIDToList(Integer itemID) {
this.itemIDList.add(itemID);
}
-
- public List getExpand() {
- return expand;
- }
-
- public void setExpand(List expand) {
- this.expand = expand;
- }
-
- public void addExpand(String expandableAttribute) {
- this.expand.add(expandableAttribute);
- }
-
- public String getLink() {
- return link;
- }
-
-
}
diff --git a/dspace-rest/src/main/java/org/dspace/rest/common/Community.java b/dspace-rest/src/main/java/org/dspace/rest/common/Community.java
index da90b86da6..859ba2f6f7 100644
--- a/dspace-rest/src/main/java/org/dspace/rest/common/Community.java
+++ b/dspace-rest/src/main/java/org/dspace/rest/common/Community.java
@@ -20,41 +20,26 @@ import java.util.List;
* To change this template use File | Settings | File Templates.
*/
@XmlRootElement(name = "community")
-public class Community {
+public class Community extends DSpaceObject{
private static Logger log = Logger.getLogger(Community.class);
- //Internal value
- private Integer communityID;
-
- @XmlElement(name = "type", required = true)
- final String type = "community";
-
//Exandable relationships
@XmlElement(name = "parentCommunity")
- private LiteCommunity parentCommunity;
-
-
- private List expand = new ArrayList();
-
- //Metadata
- private String name;
- private String handle;
+ private DSpaceObject parentCommunity;
private String copyrightText, introductoryText, shortDescription, sidebarText;
private Integer countItems;
- @XmlElement(name = "link", required = true)
- private String link;
-
@XmlElement(name = "subcommunities", required = true)
- private List subCommunities = new ArrayList();
+ private List subCommunities = new ArrayList();
@XmlElement(name = "collections")
- private List collections = new ArrayList();
+ private List collections = new ArrayList();
public Community(){}
public Community(org.dspace.content.Community community, String expand, Context context) throws SQLException, WebApplicationException{
+ super(community);
setup(community, expand, context);
}
@@ -64,20 +49,15 @@ public class Community {
expandFields = Arrays.asList(expand.split(","));
}
- this.setCommunityID(community.getID());
- this.setName(community.getName());
- this.setHandle(community.getHandle());
this.setCopyrightText(community.getMetadata(org.dspace.content.Community.COPYRIGHT_TEXT));
this.setIntroductoryText(community.getMetadata(org.dspace.content.Community.INTRODUCTORY_TEXT));
this.setSidebarText(community.getMetadata(org.dspace.content.Community.SIDEBAR_TEXT));
this.setCountItems(community.countItems());
- this.link = "/communities/" + this.communityID;
-
if(expandFields.contains("parentCommunityID") || expandFields.contains("all")) {
org.dspace.content.Community parentCommunity = community.getParentCommunity();
if(parentCommunity != null) {
- setParentCommunity(new LiteCommunity(parentCommunity));
+ setParentCommunity(new DSpaceObject(parentCommunity));
}
} else {
this.addExpand("parentCommunityID");
@@ -85,10 +65,10 @@ public class Community {
if(expandFields.contains("subCollections") || expandFields.contains("all")) {
org.dspace.content.Collection[] collectionArray = community.getCollections();
- collections = new ArrayList();
+ collections = new ArrayList();
for(org.dspace.content.Collection collection : collectionArray) {
if(AuthorizeManager.authorizeActionBoolean(context, collection, org.dspace.core.Constants.READ)) {
- collections.add(new LiteCollection(collection));
+ collections.add(new DSpaceObject(collection));
} else {
log.info("Omitted restricted collection: " + collection.getID() + " _ " + collection.getName());
}
@@ -99,10 +79,10 @@ public class Community {
if(expandFields.contains("subCommunities") || expandFields.contains("all")) {
org.dspace.content.Community[] communityArray = community.getSubcommunities();
- subCommunities = new ArrayList();
+ subCommunities = new ArrayList();
for(org.dspace.content.Community subCommunity : communityArray) {
if(AuthorizeManager.authorizeActionBoolean(context, subCommunity, org.dspace.core.Constants.READ)) {
- subCommunities.add(new LiteCommunity(subCommunity));
+ subCommunities.add(new DSpaceObject(subCommunity));
} else {
log.info("Omitted restricted subCommunity: " + subCommunity.getID() + " _ " + subCommunity.getName());
}
@@ -116,47 +96,11 @@ public class Community {
}
}
- public List getExpand() {
- return expand;
- }
-
- public void setExpand(List expand) {
- this.expand = expand;
- }
-
- public void addExpand(String expandableAttribute) {
- this.expand.add(expandableAttribute);
- }
-
- public Integer getCommunityID() {
- return communityID;
- }
-
- public void setCommunityID(Integer communityID) {
- this.communityID = communityID;
- }
-
- public String getName() {
- return name;
- }
-
- public void setName(String name) {
- this.name = name;
- }
-
- public String getHandle() {
- return handle;
- }
-
- public void setHandle(String handle) {
- this.handle = handle;
- }
-
- public List getCollections() {
+ public List getCollections() {
return collections;
}
- public void setCollections(List collections) {
+ public void setCollections(List collections) {
this.collections = collections;
}
@@ -200,19 +144,11 @@ public class Community {
this.copyrightText = copyrightText;
}
- public String getType() {
- return type;
- }
-
- public LiteCommunity getParentCommunity() {
+ public DSpaceObject getParentCommunity() {
return parentCommunity;
}
- public void setParentCommunity(LiteCommunity parentCommunity) {
+ public void setParentCommunity(DSpaceObject parentCommunity) {
this.parentCommunity = parentCommunity;
}
-
- public String getLink() {
- return link;
- }
}
diff --git a/dspace-rest/src/main/java/org/dspace/rest/common/DSpaceObject.java b/dspace-rest/src/main/java/org/dspace/rest/common/DSpaceObject.java
new file mode 100644
index 0000000000..e9f8a03281
--- /dev/null
+++ b/dspace-rest/src/main/java/org/dspace/rest/common/DSpaceObject.java
@@ -0,0 +1,98 @@
+package org.dspace.rest.common;
+
+import org.atteo.evo.inflector.English;
+
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Created with IntelliJ IDEA.
+ * User: peterdietz
+ * Date: 10/7/13
+ * Time: 12:11 PM
+ * To change this template use File | Settings | File Templates.
+ */
+@XmlRootElement(name = "DSpaceObject")
+public class DSpaceObject {
+ @XmlElement(name = "ID", required = true)
+ public Integer ID;
+
+ @XmlElement(name = "name", required = true)
+ public String name;
+
+ @XmlElement(name = "handle")
+ public String handle;
+
+ @XmlElement(name = "type", required = true)
+ public String type;
+
+ @XmlElement(name = "link", required = true)
+ public String link;
+
+ @XmlElement(name = "expand")
+ public List expand = new ArrayList();
+
+ public DSpaceObject() {
+
+ }
+
+ public DSpaceObject(org.dspace.content.DSpaceObject dso) {
+ setID(dso.getID());
+ setName(dso.getName());
+ setHandle(dso.getHandle());
+ setType(dso.getTypeText().toLowerCase());
+ }
+
+ public Integer getID() {
+ return ID;
+ }
+
+ public void setID(Integer ID) {
+ this.ID = ID;
+ }
+
+ public String getName(){
+ return this.name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getHandle() {
+ return handle;
+ }
+
+ public void setHandle(String handle) {
+ this.handle = handle;
+ }
+
+ public String getLink() {
+ //TODO, I'm not 100% sure this pluralizer will work...
+ //How to get actual contextPath of /rest/
+ return "/rest/" + English.plural(getType()) + "/" + getID();
+ }
+
+ public String getType() {
+ return this.type;
+ }
+
+ public void setType(String type) {
+ this.type = type;
+ }
+
+
+ public List getExpand() {
+ return expand;
+ }
+
+ public void setExpand(List expand) {
+ this.expand = expand;
+ }
+
+ public void addExpand(String expandableAttribute) {
+ this.expand.add(expandableAttribute);
+ }
+}
diff --git a/dspace-rest/src/main/java/org/dspace/rest/common/Item.java b/dspace-rest/src/main/java/org/dspace/rest/common/Item.java
index ff967982b0..35a142d4cc 100644
--- a/dspace-rest/src/main/java/org/dspace/rest/common/Item.java
+++ b/dspace-rest/src/main/java/org/dspace/rest/common/Item.java
@@ -23,18 +23,11 @@ import java.util.List;
* To change this template use File | Settings | File Templates.
*/
@XmlRootElement(name = "item")
-public class Item {
+public class Item extends DSpaceObject {
Logger log = Logger.getLogger(Item.class);
- Integer itemID;
-
- String handle;
-
- String name;
-
String isArchived;
String isWithdrawn;
-
String lastModified;
@@ -50,14 +43,12 @@ public class Item {
List parentCollections;
- @XmlElement(name = "link", required = true)
- private String link;
-
//Bitstreams
public Item(){}
public Item(org.dspace.content.Item item, String expand, Context context) throws SQLException, WebApplicationException{
+ super(item);
setup(item, expand, context);
}
@@ -67,8 +58,6 @@ public class Item {
expandFields = Arrays.asList(expand.split(","));
}
- this.setItemID(item.getID());
-
//Add Item metadata, omit restricted metadata fields (i.e. provenance).
metadata = new Metadata();
@@ -79,14 +68,11 @@ public class Item {
}
}
- this.setHandle(item.getHandle());
-
- this.setName(item.getName());
-
this.setArchived(Boolean.toString(item.isArchived()));
this.setWithdrawn(Boolean.toString(item.isWithdrawn()));
this.setLastModified(item.getLastModified().toString());
+ //TODO make optional, and set to object
this.setOwningCollectionID(item.getOwningCollection().getID());
this.setOwningCollectionName(item.getOwningCollection().getName());
@@ -105,31 +91,6 @@ public class Item {
}
}
-
- public Integer getItemID() {
- return itemID;
- }
-
- public void setItemID(Integer itemID) {
- this.itemID = itemID;
- }
-
- public String getHandle() {
- return handle;
- }
-
- public void setHandle(String handle) {
- this.handle = handle;
- }
-
- public String getName() {
- return name;
- }
-
- public void setName(String name) {
- this.name = name;
- }
-
public String getArchived() {
return isArchived;
}
@@ -169,9 +130,4 @@ public class Item {
public void setOwningCollectionName(String owningCollectionName) {
this.owningCollectionName = owningCollectionName;
}
-
- public String getLink() {
- return link;
- }
-
}
diff --git a/dspace-rest/src/main/java/org/dspace/rest/common/LiteCollection.java b/dspace-rest/src/main/java/org/dspace/rest/common/LiteCollection.java
deleted file mode 100644
index 6020edd5ae..0000000000
--- a/dspace-rest/src/main/java/org/dspace/rest/common/LiteCollection.java
+++ /dev/null
@@ -1,70 +0,0 @@
-package org.dspace.rest.common;
-
-import javax.xml.bind.annotation.XmlElement;
-
-/**
- * Created with IntelliJ IDEA.
- * User: peterdietz
- * Date: 9/29/13
- * Time: 11:28 AM
- * To change this template use File | Settings | File Templates.
- */
-public class LiteCollection {
- //Internal value
- private Integer collectionID;
-
- @XmlElement(name = "type", required = true)
- final String type = "collection";
-
- @XmlElement(name = "link", required = true)
- private String link;
-
- //Internal metadata
- private String name;
- private String handle;
-
- public LiteCollection() {
-
- }
-
- public LiteCollection(org.dspace.content.Collection collection){
- this.collectionID = collection.getID();
- this.name = collection.getName();
- this.handle = collection.getHandle();
-
- link = "/collections/" + this.collectionID;
- }
-
-
- public Integer getCollectionID() {
- return collectionID;
- }
-
- public void setCollectionID(Integer collectionID) {
- this.collectionID = collectionID;
- }
-
- public String getType() {
- return type;
- }
-
- public String getName() {
- return name;
- }
-
- public void setName(String name) {
- this.name = name;
- }
-
- public String getHandle() {
- return handle;
- }
-
- public void setHandle(String handle) {
- this.handle = handle;
- }
-
- public String getLink() {
- return link;
- }
-}
diff --git a/dspace-rest/src/main/java/org/dspace/rest/common/LiteCommunity.java b/dspace-rest/src/main/java/org/dspace/rest/common/LiteCommunity.java
deleted file mode 100644
index bd85fe4dd1..0000000000
--- a/dspace-rest/src/main/java/org/dspace/rest/common/LiteCommunity.java
+++ /dev/null
@@ -1,74 +0,0 @@
-package org.dspace.rest.common;
-
-import javax.xml.bind.annotation.XmlElement;
-import javax.xml.bind.annotation.XmlRootElement;
-
-/**
- * Created with IntelliJ IDEA.
- * User: peterdietz
- * Date: 9/29/13
- * Time: 11:27 AM
- * To change this template use File | Settings | File Templates.
- */
-@XmlRootElement(name = "community")
-public class LiteCommunity {
- @XmlElement(name = "type", required = true)
- final String type = "community";
-
- @XmlElement(name = "communityID", required = true)
- Integer communityID;
-
- @XmlElement(name = "handle", required = true)
- String handle;
-
- @XmlElement(name = "name", required = true)
- String name;
-
- @XmlElement(name = "link", required = true)
- private String link;
-
-
- public LiteCommunity() {
-
- }
-
- public LiteCommunity(org.dspace.content.Community community) {
- this.communityID = community.getID();
- this.handle = community.getHandle();
- this.name = community.getName();
- this.link = "/communities/" + this.communityID;
- }
-
-
- String getType() {
- return type;
- }
-
- String getHandle() {
- return handle;
- }
-
- void setHandle(String handle) {
- this.handle = handle;
- }
-
- Integer getCommunityID() {
- return communityID;
- }
-
- void setCommunityID(Integer communityID) {
- this.communityID = communityID;
- }
-
- String getName() {
- return name;
- }
-
- void setName(String name) {
- this.name = name;
- }
-
- public String getLink() {
- return link;
- }
-}
diff --git a/dspace-rest/src/main/java/org/dspace/rest/common/LiteItem.java b/dspace-rest/src/main/java/org/dspace/rest/common/LiteItem.java
deleted file mode 100644
index f86e059548..0000000000
--- a/dspace-rest/src/main/java/org/dspace/rest/common/LiteItem.java
+++ /dev/null
@@ -1,70 +0,0 @@
-package org.dspace.rest.common;
-
-import javax.xml.bind.annotation.XmlElement;
-
-/**
- * Created with IntelliJ IDEA.
- * User: peterdietz
- * Date: 9/29/13
- * Time: 11:28 AM
- * To change this template use File | Settings | File Templates.
- */
-public class LiteItem {
- //Internal value
- private Integer itemID;
-
- @XmlElement(name = "type", required = true)
- final String type = "item";
-
- @XmlElement(name = "link", required = true)
- private String link;
-
- //Internal metadata
- private String name;
- private String handle;
-
- public LiteItem() {
-
- }
-
- public LiteItem(org.dspace.content.Item item) {
- this.itemID = item.getID();
- this.name = item.getName();
- this.handle = item.getHandle();
-
- link = "/items/" + this.itemID;
- }
-
-
- public Integer getItemID() {
- return itemID;
- }
-
- public void setItemID(Integer itemID) {
- this.itemID = itemID;
- }
-
- public String getType() {
- return type;
- }
-
- public String getName() {
- return name;
- }
-
- public void setName(String name) {
- this.name = name;
- }
-
- public String getHandle() {
- return handle;
- }
-
- public void setHandle(String handle) {
- this.handle = handle;
- }
-
- public String getLink() {
- return link;
- }
-}