faster search method
authordrizea <danielrizea27@gmail.com>
Thu, 2 Aug 2012 16:22:23 +0000 (19:22 +0300)
committerdrizea <danielrizea27@gmail.com>
Thu, 2 Aug 2012 16:22:23 +0000 (19:22 +0300)
for multiple consecutive commands for a search just verify for the top one
if there is network access and connectivity to server

Open-ILS/src/Android/res/layout/record_details_basic_fragment.xml
Open-ILS/src/Android/src/org/evergreen/android/globals/GlobalConfigs.java
Open-ILS/src/Android/src/org/evergreen/android/globals/Utils.java
Open-ILS/src/Android/src/org/evergreen/android/searchCatalog/SearchCatalog.java

index 5b001cf..df9b537 100644 (file)
                     android:layout_width="140dip"
                     android:layout_height="180dip"
                     android:src="@drawable/no_image"
-                    android:layout_marginRight="5dip"
-                    android:layout_marginBottom="5dip"
                     android:padding="5dip"
                     android:background="@color/white"
+                    android:layout_margin="10dip"
                     />
                 
             </LinearLayout>
index 18aab14..9052655 100644 (file)
@@ -272,21 +272,16 @@ public class GlobalConfigs {
                
                try {
                        search.getCopyStatuses();
-               } catch (NoNetworkAccessException e) {
-                       // TODO Auto-generated catch block
-                       e.printStackTrace();
-               } catch (NoAccessToServer e) {
+               } catch (Exception e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                }
-       
        }
        
        public void getOrgHiddentDepth(){
                
                // logic can be found in the opac_utils.js file in web/opac/common/js
-               
-               
+
                for(int i=0; i<organisations.size();i++){
                        
                        AccountAccess ac = AccountAccess.getAccountAccess();
index 3e514f8..bf9028f 100644 (file)
@@ -288,8 +288,6 @@ public class Utils {
                //check to see if EG http server is reachable
                checkIfNetAddressIsReachable(GlobalConfigs.httpAddress);
                
-               
-               //TODO check params and throw errors
                Method method = new Method(methodName);
                
                System.out.println("Method :" + methodName + " param:");
@@ -314,8 +312,31 @@ public class Utils {
                return null;
                
        }
+       // does not throw exception
+       // is fast than with checks for multiple method invocations like in search
+       public static Object doRequestSimple(HttpConnection conn, String service, String methodName, Object[] params){
+               Method method = new Method(methodName);
+               System.out.println("Method :" + methodName + " param:");
+               for(int i=0;i<params.length;i++){
+                       method.addParam(params[i]);
+                       System.out.print("Param "+i+":" + params[i]);
+               }
+               //need space
+               System.out.println();
+               
+               //sync request
+               HttpRequest req = new GatewayRequest(conn, service, method).send();
+               Object resp;
 
-       
+               while ((resp = req.recv()) != null) {
+                       System.out.println("Sync Response: " + resp);
+                       Object response = (Object) resp;
+
+                       return response;
+                       
+               }
+               return null;
+       }
        
        public static ShowServerNotAvailableRunnable showServerNotAvailableDialog(Context context){
                
index a3565ae..17da005 100644 (file)
@@ -167,7 +167,7 @@ public class SearchCatalog {
                        System.out.println("Exception in JSON " + e.getMessage());
                }
 
-               
+               //do request and check for connectivity
                Object resp = Utils.doRequest(conn, SERVICE, METHOD_MULTICASS_SEARCH, cm, new Object[]{complexParm,searchWords,1});
 
                ArrayList<String> ids = new ArrayList<String>();
@@ -275,9 +275,9 @@ public class SearchCatalog {
        }
 
        
-       public Object getCopyStatuses() throws NoNetworkAccessException, NoAccessToServer{
+       public Object getCopyStatuses() {
                
-               List<OSRFObject> ccs_list = (List<OSRFObject>)Utils.doRequest(conn, SERVICE, METHOD_COPY_STATUS_ALL, cm, new Object[]{});
+               List<OSRFObject> ccs_list = (List<OSRFObject>)Utils.doRequestSimple(conn, SERVICE, METHOD_COPY_STATUS_ALL, new Object[]{});
                
                CopyInformation.availableOrgStatuses = new LinkedHashMap<String,String>();
                
@@ -295,9 +295,9 @@ public class SearchCatalog {
                return ccs_list;
        }
        
-       public Object getLocationCount(Integer recordID, Integer orgID, Integer orgDepth) throws NoNetworkAccessException, NoAccessToServer{
+       public Object getLocationCount(Integer recordID, Integer orgID, Integer orgDepth){
                
-               List<?> list = (List<?>)Utils.doRequest(conn, SERVICE, METHOD_COPY_LOCATION_COUNTS, cm, new Object[]{recordID, orgID, orgDepth});
+               List<?> list = (List<?>)Utils.doRequestSimple(conn, SERVICE, METHOD_COPY_LOCATION_COUNTS, new Object[]{recordID, orgID, orgDepth});
                return list;
                
        }
@@ -327,9 +327,9 @@ public class SearchCatalog {
                
        }
        
-       public ArrayList<CopyCountInformation> getCopyCount(Integer recordID, Integer orgID) throws NoNetworkAccessException, NoAccessToServer{
+       public ArrayList<CopyCountInformation> getCopyCount(Integer recordID, Integer orgID){
                
-               List<?> list = (List<?>)Utils.doRequest(conn, SERVICE, METHOD_GET_COPY_COUNT, cm, new Object[]{orgID, recordID, ""});
+               List<?> list = (List<?>)Utils.doRequestSimple(conn, SERVICE, METHOD_GET_COPY_COUNT, new Object[]{orgID, recordID, ""});
                
                ArrayList<CopyCountInformation> copyInfoList = new ArrayList<CopyCountInformation>();