Revision: 1785
Author: [email protected]
Date: Tue Dec 15 16:42:26 2009
Log: Allow retrieval of a featured project via the getProject API call.
http://code.google.com/p/simal/source/detail?r=1785

Modified:
   
/trunk/uk.ac.osswatch.simal.rest/src/documentation/content/xdocs/user/api.xml
   
/trunk/uk.ac.osswatch.simal.rest/src/main/java/uk/ac/osswatch/simal/rest/ProjectAPI.java
   
/trunk/uk.ac.osswatch.simal.rest/src/main/java/uk/ac/osswatch/simal/rest/RESTCommand.java
   
/trunk/uk.ac.osswatch.simal.rest/src/test/java/uk/ac/osswatch/simal/rest/TestProjectAPI.java

=======================================
---  
/trunk/uk.ac.osswatch.simal.rest/src/documentation/content/xdocs/user/api.xml   
 
Thu May 21 13:48:18 2009
+++  
/trunk/uk.ac.osswatch.simal.rest/src/documentation/content/xdocs/user/api.xml   
 
Tue Dec 15 16:42:26 2009
@@ -90,6 +90,9 @@
          <p>To retrieve the details of a single project use:</p>

           
<source>http://foo.com/simal-rest/project/project-ID/FORMAT</source>
+
+        <p>If you use "featured" as the project-ID you will be given a  
featured
+        project.</p>
        </section>

        <section>
=======================================
---  
/trunk/uk.ac.osswatch.simal.rest/src/main/java/uk/ac/osswatch/simal/rest/ProjectAPI.java
         
Wed Nov 18 15:09:07 2009
+++  
/trunk/uk.ac.osswatch.simal.rest/src/main/java/uk/ac/osswatch/simal/rest/ProjectAPI.java
         
Tue Dec 15 16:42:26 2009
@@ -58,7 +58,7 @@
      }
    }

-  /**
+/**
     * Get all the projects from the repository.
     *
     * @param req
@@ -89,31 +89,35 @@
     */
    private String getProject(RESTCommand command) throws SimalAPIException {
      String id = command.getProjectID();
-
-    if (command.isXML()) {
-      try {
-        IProject project =  
SimalRepositoryFactory.getProjectService().getProjectById(
-            getRepository().getUniqueSimalID(id));
-        if (project == null) {
-          throw new SimalAPIException("Project with Simal ID " + id
-              + " does not exist");
-        }
-        return project.toXML();
-      } catch (SimalRepositoryException e) {
-        throw new SimalAPIException(
-            "Unable to get XML representation of project from the  
repository",
-            e);
-      }
-    } else if (command.isJSON()) {
-      try {
-        return  
SimalRepositoryFactory.getProjectService().getProjectById(id).toJSON();
-      } catch (SimalRepositoryException e) {
-        throw new SimalAPIException(
-            "Unable to get JSON representation of project from the  
repository",
-            e);
-      }
-    } else {
-      throw new SimalAPIException("Unkown format requested - " + command);
+    IProject project;
+
+    try {
+           if (id.equals("featured")) {
+             project = getRepository().getFeaturedProject();
+           } else {
+             project = 
SimalRepositoryFactory.getProjectService().getProjectById(
+               getRepository().getUniqueSimalID(id));
+           }
+           if (project == null) {
+             throw new SimalAPIException("Project with Simal ID " + id
+                 + " does not exist");
+           }
+    } catch (SimalRepositoryException e) {
+      throw new SimalAPIException(
+        "Unable to get XML representation of project from the repository",
+        e);
+    }
+
+    try {
+           if (command.isXML()) {
+               return project.toXML();
+           } else if (command.isJSON()) {
+               return project.toJSON();
+           } else {
+               throw new SimalAPIException("Unkown format requested - " + 
command);
+           }
+    } catch (SimalRepositoryException e) {
+       throw new SimalAPIException("Unable to convert project to the chosen  
format", e);
      }
    }

=======================================
---  
/trunk/uk.ac.osswatch.simal.rest/src/main/java/uk/ac/osswatch/simal/rest/RESTCommand.java
        
Tue Nov 24 16:21:30 2009
+++  
/trunk/uk.ac.osswatch.simal.rest/src/main/java/uk/ac/osswatch/simal/rest/RESTCommand.java
        
Tue Dec 15 16:42:26 2009
@@ -483,7 +483,7 @@
      }
      return false;
    }
-
+
    /**
     * Return the path info part of the URI that represents this command.
     *
@@ -588,4 +588,5 @@
    public boolean isGet() {
      return !isPost();
    }
-}
+
+}
=======================================
---  
/trunk/uk.ac.osswatch.simal.rest/src/test/java/uk/ac/osswatch/simal/rest/TestProjectAPI.java
     
Wed Nov 18 15:59:09 2009
+++  
/trunk/uk.ac.osswatch.simal.rest/src/test/java/uk/ac/osswatch/simal/rest/TestProjectAPI.java
     
Tue Dec 15 16:42:26 2009
@@ -74,6 +74,32 @@
      assertTrue("XML file does not appear to describe a project", result
          .contains("Project>"));
    }
+
+  @Test
+  public void testgetFeaturedProjectAsXML() throws SimalAPIException {
+    RESTCommand cmd = RESTCommand.createGetProject("featured",
+            RESTCommand.TYPE_SIMAL, RESTCommand.FORMAT_XML);
+
+    IAPIHandler handler = SimalHandlerFactory.createHandler(cmd,  
getRepo());
+    String result = handler.execute();
+
+    assertNotNull("No XML Returned by getProject", result);
+    assertTrue("XML file does not appear to describe a project", result
+        .contains("Project>"));
+  }
+
+  @Test
+  public void testgetFeaturedProjectAsJSON() throws SimalAPIException {
+    RESTCommand cmd = RESTCommand.createGetProject("featured",
+            RESTCommand.TYPE_SIMAL, RESTCommand.FORMAT_JSON);
+
+    IAPIHandler handler = SimalHandlerFactory.createHandler(cmd,  
getRepo());
+    String result = handler.execute();
+
+    assertNotNull("No JSON Returned by getProject", result);
+    assertTrue("JSON file does not appear to describe a project", result
+        .contains("simalID"));
+  }

    @Test
    public void testGetProjectByURL() throws SimalAPIException {

--

You received this message because you are subscribed to the Google Groups 
"Simal Commits" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/simal-commits?hl=en.


Reply via email to