Sanitary
[mkjsf-moved-to-github.git] / src / main / java / com / indexdata / pz2utils4jsf / pazpar2 / Pz2Session.java
index 886a0b8..17f8545 100644 (file)
@@ -1,5 +1,6 @@
 package com.indexdata.pz2utils4jsf.pazpar2;\r
 \r
+import java.io.ByteArrayOutputStream;\r
 import java.io.IOException;\r
 import java.util.ArrayList;\r
 import java.util.List;\r
@@ -12,17 +13,20 @@ import javax.inject.Named;
 \r
 import org.apache.log4j.Logger;\r
 \r
+import com.indexdata.masterkey.pazpar2.client.ClientCommand;\r
 import com.indexdata.masterkey.pazpar2.client.Pazpar2Client;\r
 import com.indexdata.masterkey.pazpar2.client.Pazpar2ClientConfiguration;\r
 import com.indexdata.masterkey.pazpar2.client.Pazpar2ClientGeneric;\r
+import com.indexdata.masterkey.pazpar2.client.exceptions.Pazpar2ErrorException;\r
 import com.indexdata.masterkey.pazpar2.client.exceptions.ProxyErrorException;\r
 import com.indexdata.pz2utils4jsf.config.Pz2Configurator;\r
 import com.indexdata.pz2utils4jsf.controls.ResultsPager;\r
-import com.indexdata.pz2utils4jsf.errors.ApplicationError;\r
-import com.indexdata.pz2utils4jsf.errors.ErrorHelper;\r
 import com.indexdata.pz2utils4jsf.errors.ConfigurationError;\r
-import com.indexdata.pz2utils4jsf.pazpar2.data.CommandError;\r
+import com.indexdata.pz2utils4jsf.errors.ConfigurationException;\r
+import com.indexdata.pz2utils4jsf.errors.ErrorHelper;\r
+import com.indexdata.pz2utils4jsf.errors.ErrorInterface;\r
 import com.indexdata.pz2utils4jsf.pazpar2.data.ByTarget;\r
+import com.indexdata.pz2utils4jsf.pazpar2.data.CommandError;\r
 import com.indexdata.pz2utils4jsf.pazpar2.data.Pazpar2ResponseData;\r
 import com.indexdata.pz2utils4jsf.pazpar2.data.Pazpar2ResponseParser;\r
 import com.indexdata.pz2utils4jsf.pazpar2.data.RecordResponse;\r
@@ -48,7 +52,7 @@ public class Pz2Session implements Pz2Interface {
   private TargetFilter targetFilter = null;  \r
   private ResultsPager pager = null; \r
   private ErrorHelper errorHelper = null;\r
-  private List<ApplicationError> configurationErrors = null;\r
+  private List<ErrorInterface> configurationErrors = null;\r
   \r
   public Pz2Session () {\r
     logger.info("Instantiating pz2 session object [" + Utils.objectId(this) + "]");      \r
@@ -56,7 +60,7 @@ public class Pz2Session implements Pz2Interface {
     \r
   public void init(Pz2Configurator pz2conf) {\r
     if (client==null) {\r
-      configurationErrors = new ArrayList<ApplicationError>();\r
+      configurationErrors = new ArrayList<ErrorInterface>();\r
       errorHelper = new ErrorHelper(pz2conf);\r
       logger.info(Utils.objectId(this) + " is configuring itself using the provided " + Utils.objectId(pz2conf));\r
       try {\r
@@ -64,18 +68,20 @@ public class Pz2Session implements Pz2Interface {
       } catch (ProxyErrorException pe) {\r
         logger.error("Could not configure Pazpar2 client: " + pe.getMessage());\r
         configurationErrors.add(new ConfigurationError("Pz2Client Config","ProxyError","Could not configure Pazpar2 client: " + pe.getMessage(),errorHelper));\r
-      } catch (IOException io) {\r
+      } catch (ConfigurationException io) {\r
         logger.error("Could not configure Pazpar2 client: " + io.getMessage());\r
         configurationErrors.add(new ConfigurationError("Pz2Client Config","ProxyError","Could not configure Pazpar2 client: " + io.getMessage(),errorHelper));\r
       }\r
       if (cfg != null) {\r
         try {\r
-          client = new Pazpar2ClientGeneric(cfg);     \r
+          client = new Pazpar2ClientGeneric(cfg);  \r
         } catch (ProxyErrorException pe) {\r
           logger.error("Could not instantiate Pazpar2 client: " + pe.getMessage());\r
           configurationErrors.add(new ConfigurationError("Pz2Client error","ProxyError","Could not create Pazpar2 client: " +pe.getMessage(),errorHelper));                \r
         } \r
-        logger.info("Got " + configurationErrors.size() + " configuration errors");        \r
+        if (hasConfigurationErrors()) {\r
+          logger.info("Found " + configurationErrors.size() + " configuration errors");\r
+        }\r
       }\r
       resetDataObjects();\r
     } else {\r
@@ -144,11 +150,7 @@ public class Pz2Session implements Pz2Interface {
         return "0";\r
       }\r
     } else {\r
-      configurationErrors.add(\r
-          new ConfigurationError("Querying while errors",\r
-                                 "App halted",\r
-                                 "Cannot query Pazpar2 while there are configuration errors.",\r
-                                 errorHelper));\r
+      logger.error("Did not attempt to execute query since there are configuration errors.");\r
       return "0";\r
     }\r
     \r
@@ -324,7 +326,7 @@ public class Pz2Session implements Pz2Interface {
     return hasConfigurationErrors() || hasCommandErrors();\r
   }\r
 \r
-  public List<ApplicationError> getConfigurationErrors() {    \r
+  public List<ErrorInterface> getConfigurationErrors() {    \r
     return configurationErrors;\r
   }\r
   \r
@@ -333,7 +335,7 @@ public class Pz2Session implements Pz2Interface {
    * error found for an arbitrary command, if any, otherwise\r
    * an empty dummy error. \r
    */    \r
-  public ApplicationError getCommandError() {\r
+  public ErrorInterface getCommandError() {\r
     CommandError error = new CommandError();    \r
     if (dataObjects.get("search").hasApplicationError()) {\r
       error = dataObjects.get("search").getApplicationError();                        \r