Added Checked out Items tab functions
authordrizea <danielrizea27@gmail.com>
Wed, 6 Jun 2012 10:25:37 +0000 (13:25 +0300)
committerdrizea <danielrizea27@gmail.com>
Wed, 6 Jun 2012 10:25:37 +0000 (13:25 +0300)
Open-ILS/src/Android/src/org/evergreen/android/accountAccess/AccountAccess.java

index ba0ca39..54192c8 100644 (file)
@@ -3,31 +3,78 @@ package org.evergreen.android.accountAccess;
 
 import java.security.MessageDigest;
 import java.security.NoSuchAlgorithmException;
+import java.util.ArrayList;
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 
 import org.opensrf.Method;
 import org.opensrf.net.http.GatewayRequest;
 import org.opensrf.net.http.HttpConnection;
 import org.opensrf.net.http.HttpRequest;
+import org.opensrf.util.OSRFObject;
 
 /**
  * The Class AuthenticateUser.
  */
 public class AccountAccess {
 
+       //Used for authentication purpose
+       
        /** The SERVICE. */
-       public static String SERVICE = "open-ils.auth";
-
-       /** The METHOD Auth init  */
+       public static String SERVICE_AUTH = "open-ils.auth";
+       
+       /** The METHOD Auth init. */
        public static String METHOD_AUTH_INIT = "open-ils.auth.authenticate.init";
 
-       /** The METHOD Auth complete */
+       /** The METHOD Auth complete. */
        public static String METHOD_AUTH_COMPLETE = "open-ils.auth.authenticate.complete";
        
-       /** The METHOD Auth session retrieve */
+       /** The METHOD Auth session retrieve. */
        public static String METHOD_AUTH_SESSION_RETRV = "open-ils.auth.session.retrieve";
 
+       // Used for the Checked out Items Tab
+       
+       /** The SERVIC e_ actor. */
+       public static String SERVICE_ACTOR = "open-ils.actor";
+       
+       /** The SERVIC e_ circ. */
+       public static String SERVICE_CIRC = "open-ils.circ";
+       
+       public static String SERVICE_SEARCH = "open-ils.search";
+       
+       /** The METHOD_FETCH_CHECKED_OUT_SUM
+        *  description : for a given user returns a a structure of circulation objects sorted by
+        *  out, overdue, lost, claims_returned, long_overdue; A list of ID's returned for each type : "out":[id1,id2,...]   
+        *  @param : authtoken , UserID 
+        *  @returns: { "out":[id's],"claims_returned":[],"long_overdue":[],"overdue":[],"lost":[]}
+        */
+       public static String METHOD_FETCH_CHECKED_OUT_SUM = "open-ils.actor.user.checked_out";
+
+       /** The METHOD_FETCH_NON_CAT_CIRCS  
+        * description : for a given user, returns an id-list of non-cataloged circulations that are considered open for now.
+        * A circ is open if circ time + circ duration (based on type) is > than now 
+        * @param : authtoken, UserID
+        * @returns: Array of non-catalogen circ IDs, event or error
+        */
+       public static String METHOD_FETCH_NON_CAT_CIRCS = "open-ils.circ.open_non_cataloged_circulation.user";
+       
+       /** The METHOD_FETCH_CIRC_BY_ID 
+        * description : Retrieves a circ object by ID
+        * @param : authtoken, circ_id
+        * @returns : "circ" class
+        */
+       public static String METHOD_FETCH_CIRC_BY_ID = "open-ils.circ.retrieve";
+       
+       /** The METHOD_FETCH_MODS_FROM_COPY
+        * description :
+        * @param : target_copy
+        * @returns : mvr class OSRF Object
+        */
+       public static String METHOD_FETCH_MODS_FROM_COPY = "open-ils.search.biblio.mods_from_copy";
+       
+       public static String METHOD_FETCH_COPY = "open-ils.search.asset.copy.retrieve";
+       
        /** The conn. */
        public HttpConnection conn;
 
@@ -42,11 +89,12 @@ public class AccountAccess {
         * */
        private String authToken = null;
        
+       /** The auth time. */
        private Integer authTime = null;
        
        //for demo purpose
        /** The user name. */
-       private String userName = "staff";
+       private String userName = "admin";
 
        /** The password. */
        private String password = "demo123";
@@ -127,12 +175,12 @@ public class AccountAccess {
                method.addParam(authToken);
 
                //sync request
-               HttpRequest req = new GatewayRequest(conn, SERVICE, method).send();
+               HttpRequest req = new GatewayRequest(conn, SERVICE_AUTH, method).send();
                Object resp;
 
                while ((resp = req.recv()) != null) {
                        System.out.println("Sync Response: " + resp);
-                       
+                        OSRFObject au = (OSRFObject) resp;
                }
        }
        /**
@@ -146,7 +194,7 @@ public class AccountAccess {
                method.addParam(userName);
 
                // sync test
-               HttpRequest req = new GatewayRequest(conn, SERVICE, method).send();
+               HttpRequest req = new GatewayRequest(conn, SERVICE_AUTH, method).send();
                Object resp;
                
                String seed = null;
@@ -188,7 +236,7 @@ public class AccountAccess {
                System.out.println("Compelx param " + complexParam);
                
                // sync test
-               HttpRequest req = new GatewayRequest(conn, SERVICE, method).send();
+               HttpRequest req = new GatewayRequest(conn, SERVICE_AUTH, method).send();
                Object resp;
 
                
@@ -217,5 +265,95 @@ public class AccountAccess {
        }
 
        
+       public void getItemsCheckedOut(){
+               
+               Method method = new Method(METHOD_FETCH_CHECKED_OUT_SUM);
+
+               method.addParam(authToken);
+               method.addParam(1);
+               
+               //sync request
+               HttpRequest req = new GatewayRequest(conn, SERVICE_ACTOR, method).send();
+               Object resp;
+
+               
+               ArrayList<OSRFObject> long_overdue = new ArrayList<OSRFObject>();
+               ArrayList<OSRFObject> claims_returned = new ArrayList<OSRFObject>();
+               ArrayList<OSRFObject> lost = new ArrayList<OSRFObject>();
+               ArrayList<OSRFObject> out = new ArrayList<OSRFObject>();
+               
+               List<String> long_overdue_id;
+               List<String> claims_returned_id;
+               List<String> lost_id;
+               List<String> out_id;
+               while ((resp = req.recv()) != null) {
+                       System.out.println("Sync Response: " + resp);
+                       
+                       long_overdue_id = (List<String>)((Map<String,?>)resp).get("long_overdue");
+                       claims_returned_id = (List<String>)((Map<String,?>)resp).get("claims_returned");
+                       lost_id = (List<String>)((Map<String,?>)resp).get("lost");
+                       out_id = (List<String>)((Map<String,?>)resp).get("out");
+                       
+                       //get all the record circ info
+                       for(int i=0;i<out_id.size();i++){
+                               //System.out.println(out.get(i));
+                               out.add(retrieveCircRecord(out_id.get(i)));
+
+                               System.out.println(out.get(i).get("target_copy"));
+                               fetchModsFromCopy((out.get(i).get("target_copy"))+"");
+                       }
+                       for(int i=0;i<lost_id.size();i++){
+                               //System.out.println(out.get(i));
+                               lost.add(retrieveCircRecord(lost_id.get(i)));
+                       }
+                       for(int i=0;i<claims_returned.size();i++){
+                               //System.out.println(out.get(i));
+                               claims_returned.add(retrieveCircRecord(claims_returned_id.get(i)));
+                       }
+                       for(int i=0;i<long_overdue_id.size();i++){
+                               //System.out.println(out.get(i));
+                               long_overdue.add(retrieveCircRecord(long_overdue_id.get(i)));
+                       }
+               }
+       }
+       /* Retreives the Circ record
+        * @param : target_copy from circ
+        * @returns : "circ" OSRFObject 
+        */
+       private OSRFObject retrieveCircRecord(String id){
+               
+               Method method = new Method(METHOD_FETCH_CIRC_BY_ID);
+
+               method.addParam(authToken);
+               method.addParam(id);
+               
+               //sync request
+               HttpRequest req = new GatewayRequest(conn, SERVICE_CIRC, method).send();
+               Object resp;
+
+               while ((resp = req.recv()) != null) {
+                       System.out.println("Sync Response: " + resp);
+                       OSRFObject circ = (OSRFObject) resp;
+                       return circ;
+               }
+               
+               return null;
+       }
+       
+       private void fetchModsFromCopy(String target_copy){
+               
+               Method method = new Method(METHOD_FETCH_MODS_FROM_COPY);
+
+               method.addParam(target_copy);
+               
+               //sync request
+               HttpRequest req = new GatewayRequest(conn, SERVICE_SEARCH, method).send();
+               Object resp;
+
+               while ((resp = req.recv()) != null) {
+                       System.out.println("Sync Response: " + resp);
+                       OSRFObject mvr = (OSRFObject) resp;
+               }
+       }
 
 }