Index: citations-servlet/servlet/pom.xml
===================================================================
--- citations-servlet/servlet/pom.xml (revision 107431)
+++ citations-servlet/servlet/pom.xml (working copy)
@@ -9,7 +9,7 @@
savecite
org.sakaiproject
- savecite
+ sakai-citations-servlet
University of Michigan
http://sakaiproject.org/
@@ -74,6 +74,7 @@
+ savecite
${basedir}/src/webapp
Index: citations-tool/tool/src/java/org/sakaiproject/citation/entity/CitationEntityProvider.java
===================================================================
--- citations-tool/tool/src/java/org/sakaiproject/citation/entity/CitationEntityProvider.java (revision 0)
+++ citations-tool/tool/src/java/org/sakaiproject/citation/entity/CitationEntityProvider.java (revision 0)
@@ -0,0 +1,190 @@
+package org.sakaiproject.citation.entity;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import org.sakaiproject.citation.api.Citation;
+import org.sakaiproject.citation.api.CitationCollection;
+import org.sakaiproject.citation.api.CitationService;
+import org.sakaiproject.content.api.ContentHostingService;
+import org.sakaiproject.content.api.ContentResource;
+import org.sakaiproject.entity.api.ResourceProperties;
+import org.sakaiproject.entitybroker.EntityView;
+import org.sakaiproject.entitybroker.entityprovider.annotations.EntityCustomAction;
+import org.sakaiproject.entitybroker.entityprovider.capabilities.ActionsExecutable;
+import org.sakaiproject.entitybroker.entityprovider.capabilities.AutoRegisterEntityProvider;
+import org.sakaiproject.entitybroker.entityprovider.capabilities.Outputable;
+import org.sakaiproject.entitybroker.exception.EntityException;
+import org.sakaiproject.entitybroker.exception.EntityNotFoundException;
+import org.sakaiproject.entitybroker.util.AbstractEntityProvider;
+import org.sakaiproject.exception.IdUnusedException;
+import org.sakaiproject.exception.PermissionException;
+import org.sakaiproject.exception.ServerOverloadException;
+import org.sakaiproject.exception.TypeException;
+import org.sakaiproject.user.api.UserDirectoryService;
+
+/**
+ * Citations service is built on top of resources. All permissions checks are
+ * handled by resources (ContentHostingService). Nothing that accepts the
+ * Citations List ID should be exposed as it would allow security checks to be
+ * bypassed.
+ *
+ */
+public class CitationEntityProvider extends AbstractEntityProvider implements
+ AutoRegisterEntityProvider, ActionsExecutable, Outputable {
+
+ private CitationService citationService;
+ private ContentHostingService contentHostingService;
+ private UserDirectoryService userDirectoryService;
+
+ public void setCitationService(CitationService citationService) {
+ this.citationService = citationService;
+ }
+
+ public void setContentHostingService(
+ ContentHostingService contentHostingService) {
+ this.contentHostingService = contentHostingService;
+ }
+
+ public void setUserDirectoryService(UserDirectoryService userDirectoryService) {
+ this.userDirectoryService = userDirectoryService;
+ }
+
+ public String getEntityPrefix() {
+ return "citation";
+ }
+
+ @EntityCustomAction(action = "list", viewKey = EntityView.VIEW_LIST)
+ public DecoratedCitationCollection getCitationList(EntityView view,
+ Map params) {
+ StringBuilder resourceId = new StringBuilder();
+ String[] segments = view.getPathSegments();
+ for (int i = 2; i < segments.length; i++) {
+ resourceId.append("/");
+ resourceId.append(segments[i]);
+ }
+ if (resourceId.length() == 0) {
+ throw new EntityNotFoundException(
+ "You must supply a path to the citation list.", null);
+ }
+ try {
+ ContentResource resource = contentHostingService
+ .getResource(resourceId.toString());
+
+ if (!CitationService.CITATION_LIST_ID.equals(resource
+ .getResourceType())) {
+ throw new EntityException("Not a citation list",
+ resourceId.toString(), 400);
+ }
+ if (resource.getContentLength() > 1024) {
+ throw new EntityException("Bad citation list",
+ resourceId.toString(), 400);
+ }
+ String citationCollectionId = new String(resource.getContent());
+ CitationCollection collection = citationService
+ .getCollection(citationCollectionId);
+
+ ResourceProperties properties = resource.getProperties();
+
+ String title = properties
+ .getProperty(ResourceProperties.PROP_DISPLAY_NAME);
+ String description = properties
+ .getProperty(ResourceProperties.PROP_DESCRIPTION);
+
+ DecoratedCitationCollection dCollection = new DecoratedCitationCollection(
+ collection.getId(), title, description);
+
+ for (Citation citation : (List) collection.getCitations()) {
+ dCollection.addCitation(new DecoratedCitation(
+ citation.getId(), citation.getSchema().getIdentifier(),
+ citation.getCitationProperties()));
+ }
+ return dCollection;
+ } catch (PermissionException e) {
+ if (userDirectoryService.getAnonymousUser().equals(userDirectoryService.getCurrentUser())) {
+ throw new EntityException("Login required", resourceId.toString(), 401);
+ } else {
+ throw new EntityException("Permission denied", resourceId.toString(), 403);
+ }
+ } catch (IdUnusedException e) {
+ throw new EntityException("Not found", resourceId.toString(), 404);
+ } catch (TypeException e) {
+ throw new EntityException("Wrong type", resourceId.toString(), 400);
+ } catch (ServerOverloadException e) {
+ throw new EntityException("Server Overloaded",
+ resourceId.toString(), 500);
+ }
+
+ }
+
+ //
+ /**
+ * This wraps fields from a citation for entity broker.
+ *
+ * @author buckett
+ *
+ */
+ public class DecoratedCitation {
+ private String type;
+ private Map values;
+ private String id;
+
+ public DecoratedCitation(String id, String type, Map values) {
+ this.id = id;
+ this.type = type;
+ this.values = values;
+ }
+
+ public String getId() {
+ return id;
+ }
+
+ public String getType() {
+ return type;
+ }
+
+ public Map getValues() {
+ return values;
+ }
+ }
+
+ public class DecoratedCitationCollection {
+ private String id;
+ private String name;
+ private String description;
+ private List citations;
+
+ public DecoratedCitationCollection(String id, String name, String description) {
+ this.id = id;
+ this.name = name;
+ this.description = description;
+ this.citations = new ArrayList();
+ }
+
+ public void addCitation(DecoratedCitation citation) {
+ citations.add(citation);
+ }
+
+ public String getId() {
+ return id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public String getDescription() {
+ return description;
+ }
+
+ public List getCitations() {
+ return citations;
+ }
+ }
+
+ public String[] getHandledOutputFormats() {
+ return new String[] { JSON, FORM, HTML, XML, TXT };
+ }
+
+}
Property changes on: citations-tool/tool/src/java/org/sakaiproject/citation/entity/CitationEntityProvider.java
___________________________________________________________________
Added: svn:keywords
+ Date Revision Author HeadURL Id
Added: svn:eol-style
+ native
Index: citations-tool/tool/src/webapp/WEB-INF/applicationContext.xml
===================================================================
--- citations-tool/tool/src/webapp/WEB-INF/applicationContext.xml (revision 0)
+++ citations-tool/tool/src/webapp/WEB-INF/applicationContext.xml (revision 0)
@@ -0,0 +1,11 @@
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
Property changes on: citations-tool/tool/src/webapp/WEB-INF/applicationContext.xml
___________________________________________________________________
Added: svn:eol-style
+ native
Index: citations-tool/tool/src/webapp/WEB-INF/web.xml
===================================================================
--- citations-tool/tool/src/webapp/WEB-INF/web.xml (revision 107431)
+++ citations-tool/tool/src/webapp/WEB-INF/web.xml (working copy)
@@ -73,5 +73,9 @@
org.sakaiproject.util.ToolListener
+
+
+ org.sakaiproject.util.ContextLoaderListener
+
Index: citations-tool/tool/pom.xml
===================================================================
--- citations-tool/tool/pom.xml (revision 107431)
+++ citations-tool/tool/pom.xml (working copy)
@@ -58,6 +58,19 @@
+ org.sakaiproject.entitybroker
+ entitybroker-api
+ provided
+
+
+ org.sakaiproject.entitybroker
+ entitybroker-utils
+
+
+ org.springframework
+ spring
+
+
org.sakaiproject.velocity
sakai-velocity-tool-api