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