Author: ross.gardler
Date: Fri Sep 12 16:44:05 2008
New Revision: 1305

Modified:
    trunk/uk.ac.osswatch.simal.rest/src/documentation/content/xdocs/index.xml
     
trunk/uk.ac.osswatch.simal.rest/src/main/java/uk/ac/osswatch/simal/rest/PersonAPI.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/TestPersonAPI.java

Log:
Add a getAllPeople command (JSON only for now)

Modified:  
trunk/uk.ac.osswatch.simal.rest/src/documentation/content/xdocs/index.xml
==============================================================================
---  
trunk/uk.ac.osswatch.simal.rest/src/documentation/content/xdocs/index.xml       
 
(original)
+++  
trunk/uk.ac.osswatch.simal.rest/src/documentation/content/xdocs/index.xml       
 
Fri Sep 12 16:44:05 2008
@@ -224,7 +224,7 @@
          </section>

          <section>
-          <title>All Colleagues</title>
+          <title>All Colleagues of a Person</title>

            <p>
              A colleague is defined as someone who works on any of the
@@ -242,6 +242,14 @@
              Where PERSON_ID is replaced with the Simal ID of the person
              we are interested in.
            </p>
+        </section>
+
+        <section>
+          <title>Retrieve all People</title>
+
+          <p>To retrieve the details of all people use:</p>
+
+          <source>http://foo.com/simal-rest/allPeople/FORMAT</source>
          </section>
        </section>


Modified:  
trunk/uk.ac.osswatch.simal.rest/src/main/java/uk/ac/osswatch/simal/rest/PersonAPI.java
==============================================================================
---  
trunk/uk.ac.osswatch.simal.rest/src/main/java/uk/ac/osswatch/simal/rest/PersonAPI.java
   
(original)
+++  
trunk/uk.ac.osswatch.simal.rest/src/main/java/uk/ac/osswatch/simal/rest/PersonAPI.java
   
Fri Sep 12 16:44:05 2008
@@ -53,7 +53,9 @@
        return getPerson(command);
      } else if (command.isGetColleagues()) {
        return getAllColleagues(command);
-    } else {
+    } else if (command.isGetAllPeople()) {
+      return getAllPeople(command);
+    }  else {
        throw new SimalAPIException("Unkown command: " + command);
      }
    }
@@ -97,7 +99,7 @@
    }

    /**
-   * Get all the colleagues for this
+   * Get all the colleagues for an identified person.
     *
     * @param cmd
     * @return
@@ -157,5 +159,33 @@
      }
      response = result.toString();
      return response;
+  }
+
+  /**
+   * Get all the people in the repository.
+   * @param cmd
+   * @return
+   * @throws SimalAPIException
+   */
+  public String getAllPeople(final RESTCommand cmd)
+    throws SimalAPIException {
+    final String id = cmd.getPersonID();
+
+    StringBuffer response = new StringBuffer();
+    try {
+      Iterator<IPerson> itr = getRepository().getAllPeople().iterator();
+      if (cmd.isJSON()) {
+        while(itr.hasNext()) {
+          response.append("{ \"items\": [");
+          response.append(itr.next().toJSON(true));
+          response.append("]}");
+        }
+      } else {
+        throw new SimalAPIException("Unknown data format: " +  
cmd.getFormat());
+      }
+    } catch (SimalRepositoryException e) {
+      throw new SimalAPIException("Unable to get a person with id " + id,  
e);
+    }
+    return response.toString();
    }
  }

Modified:  
trunk/uk.ac.osswatch.simal.rest/src/main/java/uk/ac/osswatch/simal/rest/RESTCommand.java
==============================================================================
---  
trunk/uk.ac.osswatch.simal.rest/src/main/java/uk/ac/osswatch/simal/rest/RESTCommand.java
         
(original)
+++  
trunk/uk.ac.osswatch.simal.rest/src/main/java/uk/ac/osswatch/simal/rest/RESTCommand.java
         
Fri Sep 12 16:44:05 2008
@@ -32,6 +32,7 @@
    public static final String ALL_PROJECTS = "/allProjects";
    public static final String PROJECT = "/project";
    public static final String PROJECT_ADD = "/addProject";
+  public static final String ALL_PEOPLE = "/allPeople";
    public static final String PERSON = "/person";
    public static final String ALL_COLLEAGUES = "/allColleagues";

@@ -168,7 +169,19 @@
     * @return
     */
    public boolean isPersonCommand() {
-    if (isGetPerson() || isGetColleagues()) {
+    if (isGetPerson() || isGetColleagues() || isGetAllPeople()) {
+      return true;
+    }
+    return false;
+  }
+
+  /**
+   * Test to see if this command is a getAllPEople command.
+   *
+   * @return
+   */
+  public boolean isGetAllPeople() {
+    if (params.get(PARAM_METHOD).equals(ALL_PEOPLE)) {
        return true;
      }
      return false;

Modified:  
trunk/uk.ac.osswatch.simal.rest/src/test/java/uk/ac/osswatch/simal/rest/TestPersonAPI.java
==============================================================================
---  
trunk/uk.ac.osswatch.simal.rest/src/test/java/uk/ac/osswatch/simal/rest/TestPersonAPI.java
       
(original)
+++  
trunk/uk.ac.osswatch.simal.rest/src/test/java/uk/ac/osswatch/simal/rest/TestPersonAPI.java
       
Fri Sep 12 16:44:05 2008
@@ -59,4 +59,16 @@

      assertTrue("XML file does not appear to describe a person",  
result.contains("Person>"));
    }
+
+  @Test
+  public void testGetAllPeopleAsJSON() throws SimalAPIException {
+    RESTCommand command = RESTCommand.createCommand(RESTCommand.ALL_PEOPLE
+        + RESTCommand.FORMAT_JSON);
+    IAPIHandler handler = SimalHandlerFactory.createHandler(command,  
getRepo());
+    String result = handler.execute();
+    assertNotNull("No JSON Returned by getAllPeoplen", result);
+
+    assertTrue("JSON does not include person name: JSON = " + result,  
result
+        .contains("\"label\":\"Joe Blogs Maintainer\""));
+  }
  }

--~--~---------~--~----~------------~-------~--~----~
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