From 4f50a35d4ffb1246adf12772811fd2479776f818 Mon Sep 17 00:00:00 2001
From: Dean Rasheed <dar17@cam.ac.uk>
Date: Mon, 4 Mar 2019 14:18:01 +0000
Subject: [PATCH] New API method to return all people (in batches, sorted by
 CRSid).

--
Imported using git-svn from
https://dev.csi.cam.ac.uk/svn/lookup/trunk@94
---
 src/application.wadl                          | 42 ++++++++++++++
 .../cam/ucs/ibis/methods/PersonMethods.java   | 49 +++++++++++++++++
 src/php/ibisclient/methods/PersonMethods.php  | 48 ++++++++++++++++
 src/python/ibisclient/methods.py              | 55 +++++++++++++++++++
 src/python3/ibisclient/methods.py             | 55 +++++++++++++++++++
 5 files changed, 249 insertions(+)

diff --git a/src/application.wadl b/src/application.wadl
index 95f271c..f3545eb 100644
--- a/src/application.wadl
+++ b/src/application.wadl
@@ -1071,6 +1071,48 @@
                     </response>
                 </method>
             </resource>
+            <resource path="all-people">
+                <method id="allPeople" name="GET" resultField="people:java.util.List&lt;IbisPerson&gt;">
+                    <doc>
+    /**
+     * Return a list of all people (in batches).
+     * &lt;p&gt;
+     * The results are sorted by identifier, starting with the first person
+     * after the person with the specified identifier. Thus, to iterate over
+     * all people, pass a {@code null} identifier to get the first batch of
+     * people, then pass the last identifier from the previous batch to get
+     * the next batch, and repeat until no more people are returned.
+     * &lt;p&gt;
+     * By default, only a few basic details about each person are returned,
+     * but the optional &lt;code&gt;fetch&lt;/code&gt; parameter may be used to fetch
+     * additional attributes or references.
+     *
+     * @param includeCancelled [optional] Flag to allow cancelled people to
+     * be included (people who are no longer members of the University).
+     * Defaults to {@code false}.
+     * @param identifier [optional] The identifier (CRSid) of the person to
+     * start after, or {@code null} to start from the first person.
+     * @param limit [optional] The maximum number of people to return.
+     * Defaults to 100.
+     * @param fetch [optional] A comma-separated list of any additional
+     * attributes or references to fetch.
+     *
+     * @return The requested people (in identifier order).
+     */</doc>
+                    <request>
+                        <param name="includeCancelled" style="query" type="xs:boolean" javaType="boolean" xmlns:xs="http://www.w3.org/2001/XMLSchema"/>
+                        <param name="identifier" style="query" type="xs:string" javaType="java.lang.String" xmlns:xs="http://www.w3.org/2001/XMLSchema"/>
+                        <param name="limit" style="query" type="xs:int" javaType="int" xmlns:xs="http://www.w3.org/2001/XMLSchema"/>
+                        <param name="fetch" style="query" type="xs:string" javaType="java.util.List" xmlns:xs="http://www.w3.org/2001/XMLSchema"/>
+                    </request>
+                    <response>
+                        <representation mediaType="application/xml"/>
+                        <representation mediaType="application/json"/>
+                        <representation mediaType="text/xml"/>
+                        <representation mediaType="text/x-json"/>
+                    </response>
+                </method>
+            </resource>
             <resource path="list">
                 <method id="listPeople" name="GET" resultField="people:java.util.List&lt;IbisPerson&gt;">
                     <doc>
diff --git a/src/java/uk/ac/cam/ucs/ibis/methods/PersonMethods.java b/src/java/uk/ac/cam/ucs/ibis/methods/PersonMethods.java
index 96022d6..4b18c78 100644
--- a/src/java/uk/ac/cam/ucs/ibis/methods/PersonMethods.java
+++ b/src/java/uk/ac/cam/ucs/ibis/methods/PersonMethods.java
@@ -175,6 +175,55 @@ public class PersonMethods
         return result.attributeSchemes;
     }
 
+    /**
+     * Return a list of all people (in batches).
+     * <p>
+     * The results are sorted by identifier, starting with the first person
+     * after the person with the specified identifier. Thus, to iterate over
+     * all people, pass a {@code null} identifier to get the first batch of
+     * people, then pass the last identifier from the previous batch to get
+     * the next batch, and repeat until no more people are returned.
+     * <p>
+     * By default, only a few basic details about each person are returned,
+     * but the optional <code>fetch</code> parameter may be used to fetch
+     * additional attributes or references.
+     * <p>
+     * <code style="background-color: #eec;">[ HTTP: GET /api/v1/person/all-people ]</code>
+     *
+     * @param includeCancelled [optional] Flag to allow cancelled people to
+     * be included (people who are no longer members of the University).
+     * Defaults to {@code false}.
+     * @param identifier [optional] The identifier (CRSid) of the person to
+     * start after, or {@code null} to start from the first person.
+     * @param limit [optional] The maximum number of people to return.
+     * Defaults to 100.
+     * @param fetch [optional] A comma-separated list of any additional
+     * attributes or references to fetch.
+     *
+     * @return The requested people (in identifier order).
+     */
+    public java.util.List<IbisPerson> allPeople(boolean includeCancelled,
+                                                String  identifier,
+                                                int     limit,
+                                                String  fetch)
+        throws IbisException, IOException, JAXBException
+    {
+        String[] pathParams = {  };
+        Object[] queryParams = { "includeCancelled", includeCancelled,
+                                 "identifier", identifier,
+                                 "limit", limit,
+                                 "fetch", fetch };
+        Object[] formParams = {  };
+        IbisResult result = conn.invokeMethod(Method.GET,
+                                              "api/v1/person/all-people",
+                                              pathParams,
+                                              queryParams,
+                                              formParams);
+        if (result.error != null)
+            throw new IbisException(result.error);
+        return result.people;
+    }
+
     /**
      * Get the people with the specified identifiers (typically CRSids).
      * <p>
diff --git a/src/php/ibisclient/methods/PersonMethods.php b/src/php/ibisclient/methods/PersonMethods.php
index 42b7a6a..d8fbe78 100644
--- a/src/php/ibisclient/methods/PersonMethods.php
+++ b/src/php/ibisclient/methods/PersonMethods.php
@@ -155,6 +155,54 @@ class PersonMethods
         return $result->attributeSchemes;
     }
 
+    /**
+     * Return a list of all people (in batches).
+     *
+     * The results are sorted by identifier, starting with the first person
+     * after the person with the specified identifier. Thus, to iterate over
+     * all people, pass a ``null`` identifier to get the first batch of
+     * people, then pass the last identifier from the previous batch to get
+     * the next batch, and repeat until no more people are returned.
+     *
+     * By default, only a few basic details about each person are returned,
+     * but the optional ``fetch`` parameter may be used to fetch
+     * additional attributes or references.
+     *
+     * ``[ HTTP: GET /api/v1/person/all-people ]``
+     *
+     * @param boolean $includeCancelled [optional] Flag to allow cancelled people to
+     * be included (people who are no longer members of the University).
+     * Defaults to ``false``.
+     * @param string $identifier [optional] The identifier (CRSid) of the person to
+     * start after, or ``null`` to start from the first person.
+     * @param int $limit [optional] The maximum number of people to return.
+     * Defaults to 100.
+     * @param string $fetch [optional] A comma-separated list of any additional
+     * attributes or references to fetch.
+     *
+     * @return IbisPerson[] The requested people (in identifier order).
+     */
+    public function allPeople($includeCancelled,
+                              $identifier=null,
+                              $limit=null,
+                              $fetch=null)
+    {
+        $pathParams = array();
+        $queryParams = array("includeCancelled" => $includeCancelled,
+                             "identifier"       => $identifier,
+                             "limit"            => $limit,
+                             "fetch"            => $fetch);
+        $formParams = array();
+        $result = $this->conn->invokeMethod("GET",
+                                            'api/v1/person/all-people',
+                                            $pathParams,
+                                            $queryParams,
+                                            $formParams);
+        if (isset($result->error))
+            throw new IbisException($result->error);
+        return $result->people;
+    }
+
     /**
      * Get the people with the specified identifiers (typically CRSids).
      *
diff --git a/src/python/ibisclient/methods.py b/src/python/ibisclient/methods.py
index 5b8d1de..fbcf345 100644
--- a/src/python/ibisclient/methods.py
+++ b/src/python/ibisclient/methods.py
@@ -1340,6 +1340,61 @@ class PersonMethods:
             raise IbisException(result.error)
         return result.attributeSchemes
 
+    def allPeople(self,
+                  includeCancelled,
+                  identifier=None,
+                  limit=None,
+                  fetch=None):
+        """
+        Return a list of all people (in batches).
+
+        The results are sorted by identifier, starting with the first person
+        after the person with the specified identifier. Thus, to iterate over
+        all people, pass a :any:`None` identifier to get the first batch of
+        people, then pass the last identifier from the previous batch to get
+        the next batch, and repeat until no more people are returned.
+
+        By default, only a few basic details about each person are returned,
+        but the optional `fetch` parameter may be used to fetch
+        additional attributes or references.
+
+        ``[ HTTP: GET /api/v1/person/all-people ]``
+
+        **Parameters**
+          `includeCancelled` : bool
+            [optional] Flag to allow cancelled people to
+            be included (people who are no longer members of the University).
+            Defaults to :any:`False`.
+
+          `identifier` : str
+            [optional] The identifier (CRSid) of the person to
+            start after, or :any:`None` to start from the first person.
+
+          `limit` : int
+            [optional] The maximum number of people to return.
+            Defaults to 100.
+
+          `fetch` : str
+            [optional] A comma-separated list of any additional
+            attributes or references to fetch.
+
+        **Returns**
+          list of :any:`IbisPerson`
+            The requested people (in identifier order).
+        """
+        path = "api/v1/person/all-people"
+        path_params = {}
+        query_params = {"includeCancelled": includeCancelled,
+                        "identifier": identifier,
+                        "limit": limit,
+                        "fetch": fetch}
+        form_params = {}
+        result = self.conn.invoke_method("GET", path, path_params,
+                                         query_params, form_params)
+        if result.error:
+            raise IbisException(result.error)
+        return result.people
+
     def listPeople(self,
                    crsids,
                    fetch=None):
diff --git a/src/python3/ibisclient/methods.py b/src/python3/ibisclient/methods.py
index 3b4569a..724f8ad 100644
--- a/src/python3/ibisclient/methods.py
+++ b/src/python3/ibisclient/methods.py
@@ -1340,6 +1340,61 @@ class PersonMethods:
             raise IbisException(result.error)
         return result.attributeSchemes
 
+    def allPeople(self,
+                  includeCancelled,
+                  identifier=None,
+                  limit=None,
+                  fetch=None):
+        """
+        Return a list of all people (in batches).
+
+        The results are sorted by identifier, starting with the first person
+        after the person with the specified identifier. Thus, to iterate over
+        all people, pass a :any:`None` identifier to get the first batch of
+        people, then pass the last identifier from the previous batch to get
+        the next batch, and repeat until no more people are returned.
+
+        By default, only a few basic details about each person are returned,
+        but the optional `fetch` parameter may be used to fetch
+        additional attributes or references.
+
+        ``[ HTTP: GET /api/v1/person/all-people ]``
+
+        **Parameters**
+          `includeCancelled` : bool
+            [optional] Flag to allow cancelled people to
+            be included (people who are no longer members of the University).
+            Defaults to :any:`False`.
+
+          `identifier` : str
+            [optional] The identifier (CRSid) of the person to
+            start after, or :any:`None` to start from the first person.
+
+          `limit` : int
+            [optional] The maximum number of people to return.
+            Defaults to 100.
+
+          `fetch` : str
+            [optional] A comma-separated list of any additional
+            attributes or references to fetch.
+
+        **Returns**
+          list of :any:`IbisPerson`
+            The requested people (in identifier order).
+        """
+        path = "api/v1/person/all-people"
+        path_params = {}
+        query_params = {"includeCancelled": includeCancelled,
+                        "identifier": identifier,
+                        "limit": limit,
+                        "fetch": fetch}
+        form_params = {}
+        result = self.conn.invoke_method("GET", path, path_params,
+                                         query_params, form_params)
+        if result.error:
+            raise IbisException(result.error)
+        return result.people
+
     def listPeople(self,
                    crsids,
                    fetch=None):
-- 
GitLab