Sets up error central. Lets page author decide to show.
authorNiels Erik G. Nielsen <nielserik@indexdata.com>
Mon, 15 Apr 2013 22:14:11 +0000 (18:14 -0400)
committerNiels Erik G. Nielsen <nielserik@indexdata.com>
Mon, 15 Apr 2013 22:14:11 +0000 (18:14 -0400)
Creates a separate error container, exposed to the Faces pages as 'errors'.

The page author decides whether and where to show errors, which so
far come in two categories: configuration errors and request errors.

src/META-INF/resources/pz2utils/commanderrors.xhtml [new file with mode: 0644]
src/META-INF/resources/pz2utils/configerrors.xhtml [new file with mode: 0644]
src/META-INF/resources/pz2utils/listeners.js
src/META-INF/resources/pz2utils/pz2watch.xhtml
src/META-INF/resources/pz2widgets/login.xhtml [new file with mode: 0644]
src/main/java/com/indexdata/pz2utils4jsf/errors/ConfigurationError.java
src/main/java/com/indexdata/pz2utils4jsf/errors/ErrorCentral.java [new file with mode: 0644]
src/main/java/com/indexdata/pz2utils4jsf/errors/ErrorHelper.java
src/main/java/com/indexdata/pz2utils4jsf/pazpar2/Pz2Bean.java
src/main/java/com/indexdata/pz2utils4jsf/pazpar2/Pz2Interface.java
src/main/java/com/indexdata/pz2utils4jsf/pazpar2/data/Pazpar2Responses.java

diff --git a/src/META-INF/resources/pz2utils/commanderrors.xhtml b/src/META-INF/resources/pz2utils/commanderrors.xhtml
new file mode 100644 (file)
index 0000000..1a3ccb5
--- /dev/null
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="UTF-8" ?>\r
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">\r
+<h:html xmlns="http://www.w3.org/1999/xhtml"\r
+      xmlns:f="http://java.sun.com/jsf/core"\r
+      xmlns:h="http://java.sun.com/jsf/html"\r
+      xmlns:ui="http://java.sun.com/jsf/facelets"\r
+      xmlns:cc="http://java.sun.com/jsf/composite">\r
+\r
+<head>\r
+<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />\r
+</head>\r
+<body>\r
+\r
+  <cc:interface>\r
+  </cc:interface>\r
+  \r
+  <cc:implementation>\r
+    <h:panelGrid id="commandErrorMessagesAndSuggestions" rendered="${errors.hasCommandErrors()}" columns="2">\r
+      <h:column>\r
+        <h:outputText id="messages" value="#{errors.commandError.message}" style="color: red;"/>\r
+      </h:column>\r
+      <h:dataTable value="#{errors.commandError.suggestions}" var="suggestion" cellspacing="0" cellpadding="0">                  \r
+       <h:column>\r
+         #{suggestion}        \r
+       </h:column>      \r
+      </h:dataTable>\r
+    </h:panelGrid>                  \r
+  </cc:implementation>\r
+    \r
+</body>\r
+</h:html>
\ No newline at end of file
diff --git a/src/META-INF/resources/pz2utils/configerrors.xhtml b/src/META-INF/resources/pz2utils/configerrors.xhtml
new file mode 100644 (file)
index 0000000..531c7b5
--- /dev/null
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="UTF-8" ?>\r
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">\r
+<h:html xmlns="http://www.w3.org/1999/xhtml"\r
+      xmlns:f="http://java.sun.com/jsf/core"\r
+      xmlns:h="http://java.sun.com/jsf/html"\r
+      xmlns:ui="http://java.sun.com/jsf/facelets"\r
+      xmlns:cc="http://java.sun.com/jsf/composite">\r
+\r
+<head>\r
+<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />\r
+</head>\r
+<body>\r
+\r
+  <cc:interface>\r
+  </cc:interface>\r
+  \r
+  <cc:implementation>\r
+      <h:panelGrid id="configErrorMessagesAndSuggestions" rendered="${errors.hasConfigurationErrors()}">\r
+        <h:dataTable value="#{errors.configurationErrors}" var="error" cellspace="0" cellpadding="0" style="${errors.hasConfigurationErrors() ? 'display: block; vertical-align: top;' : 'display: none;'}">\r
+          <h:column valign="top">\r
+            <h:outputText value="#{error.message}" style="color: red;"/>\r
+            <h:dataTable value="#{error.suggestions}" var="suggestion" cellspacing="0" cellpadding="0">\r
+             <h:column>\r
+               #{suggestion}        \r
+             </h:column>      \r
+            </h:dataTable>                                        \r
+          </h:column>\r
+        </h:dataTable>\r
+      </h:panelGrid>                      \r
+  </cc:implementation>\r
+    \r
+</body>\r
+</h:html>
\ No newline at end of file
index 8c1f466..19be26a 100644 (file)
@@ -7,7 +7,7 @@
   {\r
        //console.log('rendering ' + renderWhileActiveclients);\r
        var sourcecomp = document.getElementById("pz2watch:activeclientsField");\r
-    jsf.ajax.request(sourcecomp, null,{render: renderWhileActiveclients + " pz2watch:errorMessages"});\r
+    jsf.ajax.request(sourcecomp, null,{render: renderWhileActiveclients});\r
     if (doRefresh) {\r
                //console.log('Will do another ajax request after a timeout in order to render: pz2watch:activeclientsField');  \r
            renderTargetsReqVar=setTimeout(\r
index e0f5b82..aafdbef 100644 (file)
       <h:outputText id="activeClientsLabel" value="Active clients: " style="${cc.attrs.debug == 'true' ? '' : 'display:none;'}"/> \r
       <h:outputText id="activeclientsField" value="${pz2.update()}"  style="${cc.attrs.debug == 'true' ? '' : 'display:none;'}"/>\r
       <h:outputText id="space" value=" - " style="${cc.attrs.debug == 'true' ? '' : 'display:none;'}"/>\r
-      <h:outputText id="activeclientsFieldRecord" value="${pz2.update('record')}" style="${cc.attrs.debug == 'true' ? '' : 'display:none;'}"/>\r
-      \r
-      <h:panelGrid id="errorMessages" style="${pz2.hasErrors() ? 'display: block;' : 'display: none;'}">\r
-        <h:dataTable value="#{pz2.configurationErrors}" var="error" cellspace="0" cellpadding="0" style="${pz2.hasConfigurationErrors() ? 'display: block; vertical-align: top;' : 'display: none;'}">\r
-          <h:column valign="top">\r
-            <h:outputText value="#{error.message}" style="color: red;"/>\r
-            <h:dataTable value="#{error.suggestions}" var="suggestion" cellspacing="0" cellpadding="0">\r
-             <h:column>\r
-               #{suggestion}        \r
-             </h:column>      \r
-            </h:dataTable>                                        \r
-          </h:column>\r
-        </h:dataTable>\r
-        <h:panelGrid  style="${pz2.hasCommandErrors() ? 'display: block;' : 'display: none;'}">\r
-          <h:column>\r
-            <h:outputText id="messages" value="#{pzresp.commandError.message}" style="color: red;"/>\r
-          </h:column>\r
-          <h:dataTable value="#{pzresp.commandError.suggestions}" var="suggestion" cellspacing="0" cellpadding="0">                  \r
-           <h:column>\r
-             #{suggestion}        \r
-           </h:column>      \r
-          </h:dataTable>\r
-        </h:panelGrid>                \r
-      </h:panelGrid>                      \r
+      <h:outputText id="activeclientsFieldRecord" value="${pz2.update('record')}" style="${cc.attrs.debug == 'true' ? '' : 'display:none;'}"/>      \r
     </h:form>\r
 \r
     <h:form id="stateForm" prependId="false" rendered="${cc.attrs.trackHistory == 'true'}" style="${cc.attrs.debug == 'true' ? '' : 'display:none;'}">\r
diff --git a/src/META-INF/resources/pz2widgets/login.xhtml b/src/META-INF/resources/pz2widgets/login.xhtml
new file mode 100644 (file)
index 0000000..a4838c9
--- /dev/null
@@ -0,0 +1,32 @@
+<html xmlns="http://www.w3.org/1999/xhtml"\r
+    xmlns:h="http://java.sun.com/jsf/html"\r
+    xmlns:ui="http://java.sun.com/jsf/facelets"\r
+    xmlns:composite="http://java.sun.com/jsf/composite">\r
+\r
+    <composite:interface>\r
+       <composite:attribute name="user"/>\r
+\r
+       <composite:attribute name="namePrompt"/>\r
+       <composite:attribute name="passwordPrompt"/>\r
+\r
+       <composite:attribute name="loginButtonText"/>\r
+       <composite:attribute name="loginAction"\r
+          method-signature="java.lang.String action()"/>\r
+    </composite:interface>\r
+\r
+    <composite:implementation>\r
+       <h:form id="form">\r
+          <h:panelGrid columns="2">\r
+             #{cc.attrs.namePrompt}\r
+             <h:inputText id="name" value="#{cc.attrs.user.name}"/>\r
+\r
+             #{cc.attrs.passwordPrompt}\r
+             <h:inputSecret id="password" value="#{cc.attrs.user.password}"/>\r
+          </h:panelGrid>\r
+          <p>\r
+             <h:commandButton id="loginButton" value="#{cc.attrs.loginButtonText}"\r
+                action="#{cc.attrs.loginAction}"/>\r
+          </p>\r
+      </h:form>\r
+   </composite:implementation>\r
+</html>
\ No newline at end of file
index 7d3f7ba..ef2969d 100644 (file)
@@ -15,10 +15,9 @@ public class ConfigurationError implements ErrorInterface {
   private ErrorHelper helper;\r
   private ErrorCode applicationErrorCode;\r
   \r
-  public ConfigurationError(String label, String exception, String message, ErrorHelper helper) {\r
+  public ConfigurationError(String label, String exception, String message) {\r
     this.label = label;\r
-    this.message = message;\r
-    this.helper = helper;  \r
+    this.message = message;    \r
     this.exception = exception;\r
   }\r
   \r
diff --git a/src/main/java/com/indexdata/pz2utils4jsf/errors/ErrorCentral.java b/src/main/java/com/indexdata/pz2utils4jsf/errors/ErrorCentral.java
new file mode 100644 (file)
index 0000000..a143517
--- /dev/null
@@ -0,0 +1,67 @@
+package com.indexdata.pz2utils4jsf.errors;\r
+\r
+import java.io.Serializable;\r
+import java.util.ArrayList;\r
+import java.util.List;\r
+\r
+import javax.annotation.PostConstruct;\r
+import javax.enterprise.context.SessionScoped;\r
+import javax.inject.Inject;\r
+import javax.inject.Named;\r
+\r
+import org.apache.log4j.Logger;\r
+\r
+import com.indexdata.pz2utils4jsf.config.ConfigurationReader;\r
+import com.indexdata.pz2utils4jsf.pazpar2.data.Pazpar2Responses;\r
+\r
+@Named("errors") @SessionScoped\r
+public class ErrorCentral implements Serializable {\r
+\r
+  private static final long serialVersionUID = -1658192041068396628L;\r
+  private static Logger logger = Logger.getLogger(ErrorCentral.class);  \r
+  private ErrorHelper errorHelper = null;\r
+  \r
+  @Inject Pazpar2Responses pzresp;\r
+  @Inject ConfigurationReader configurator;\r
+  \r
+  private List<ErrorInterface> configurationErrors = new ArrayList<ErrorInterface>();\r
+\r
+  public ErrorCentral() {}\r
+  \r
+  @PostConstruct \r
+  public void postConstruct() {\r
+    errorHelper = new ErrorHelper(configurator);\r
+    pzresp.setErrorHelper(errorHelper);    \r
+  }\r
+    \r
+  public void addConfigurationError (ErrorInterface configError) {\r
+    configError.setErrorHelper(errorHelper);\r
+    configurationErrors.add(configError);\r
+  }\r
+  \r
+  public boolean hasConfigurationErrors () {\r
+    return (configurationErrors.size()>0);      \r
+  }\r
+\r
+  public boolean hasCommandErrors () {\r
+    return pzresp.hasApplicationError();\r
+  }\r
+  \r
+  public ErrorInterface getCommandError () {\r
+    return pzresp.getCommandError();\r
+  }\r
+\r
+  /**\r
+   * Returns true if application error found in any response data objects \r
+   */\r
+  public boolean hasErrors () {\r
+    logger.debug("Checking for configuration errors or command errors.");\r
+    return hasConfigurationErrors() || hasCommandErrors();\r
+  }\r
+  \r
+  public List<ErrorInterface> getConfigurationErrors() {    \r
+    return configurationErrors;\r
+  }\r
+\r
+\r
+}\r
index 0664f20..086cd84 100644 (file)
@@ -125,7 +125,7 @@ public class ErrorHelper implements Serializable {
           int pz2code = Integer.parseInt(error.getPazpar2Error().getCode());\r
           switch (pz2code) {\r
             case 3:\r
-              suggestions.add("Query terms not supported.");\r
+              suggestions.add("The search experienced a problem with the query terms.");\r
               break;\r
             case 12:\r
               suggestions.add("The Pazpar2 server does not have a service defined by the requested ID ");\r
index 5a07794..b12082b 100644 (file)
@@ -18,7 +18,7 @@ import com.indexdata.pz2utils4jsf.controls.ResultsPager;
 import com.indexdata.pz2utils4jsf.errors.ConfigurationError;\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.errors.ErrorCentral;\r
 import com.indexdata.pz2utils4jsf.pazpar2.commands.CommandParameter;\r
 import com.indexdata.pz2utils4jsf.pazpar2.commands.Pazpar2Commands;\r
 import com.indexdata.pz2utils4jsf.pazpar2.data.Pazpar2ResponseData;\r
@@ -42,10 +42,11 @@ public class Pz2Bean implements Pz2Interface, StateListener, Serializable {
   @Inject StateManager stateMgr;\r
   @Inject Pazpar2Commands pzreq;\r
   @Inject Pazpar2Responses pzresp;\r
+  @Inject ErrorCentral errors;\r
   \r
   protected ResultsPager pager = null; \r
 \r
-  protected List<ErrorInterface> configurationErrors = null;\r
+  \r
   protected ErrorHelper errorHelper = null;\r
               \r
   public Pz2Bean () {\r
@@ -64,15 +65,12 @@ public class Pz2Bean implements Pz2Interface, StateListener, Serializable {
   }  \r
   \r
   public void configureClient(SearchClient searchClient, ConfigurationReader configReader) {\r
-    errorHelper = new ErrorHelper(configurator);\r
-    logger.info("pz2 " + Utils.objectId(this) + " sets error helper " + Utils.objectId(errorHelper) + " on pzresp " + Utils.objectId(pzresp));\r
-    pzresp.setErrorHelper(errorHelper);\r
-    configurationErrors = new ArrayList<ErrorInterface>();        \r
     logger.debug(Utils.objectId(this) + " will configure search client for the session");\r
     try {\r
       searchClient.configure(configReader);            \r
     } catch (ConfigurationException e) {\r
-      configurationErrors.add(new ConfigurationError("Search Client","Configuration",e.getMessage(),new ErrorHelper(configReader)));          \r
+      logger.debug("Pz2Bean adding configuration error");\r
+      errors.addConfigurationError(new ConfigurationError("Search Client","Configuration",e.getMessage()));                \r
     } \r
     logger.info(configReader.document());\r
     pzresp.reset();    \r
@@ -112,7 +110,7 @@ public class Pz2Bean implements Pz2Interface, StateListener, Serializable {
    * @return Number of activeclients at the time of the 'show' command\r
    */\r
   public String update (String commands) {\r
-    if (! hasConfigurationErrors()) {\r
+    if (! errors.hasConfigurationErrors()) {\r
       if (commandsAreValid(commands)) {\r
         if (hasQuery()) {\r
           handleQueryStateChanges(commands);\r
@@ -195,25 +193,6 @@ public class Pz2Bean implements Pz2Interface, StateListener, Serializable {
     stateMgr.setCurrentStateKey(key);\r
   }\r
   \r
-  public boolean hasConfigurationErrors () {\r
-      return (configurationErrors.size()>0);      \r
-  }\r
-  \r
-  public boolean hasCommandErrors () {\r
-    return pzresp.hasApplicationError();\r
-  }\r
-  \r
-  /**\r
-   * Returns true if application error found in any response data objects \r
-   */\r
-  public boolean hasErrors () {\r
-    logger.debug("Checking for configuration errors or command errors.");\r
-    return hasConfigurationErrors() || hasCommandErrors();\r
-  }\r
-\r
-  public List<ErrorInterface> getConfigurationErrors() {    \r
-    return configurationErrors;\r
-  }\r
   \r
   \r
   protected boolean hasQuery() {        \r
index b403d8d..f0cd6d4 100644 (file)
@@ -1,10 +1,8 @@
 package com.indexdata.pz2utils4jsf.pazpar2;\r
 \r
 import java.io.Serializable;\r
-import java.util.List;\r
 \r
 import com.indexdata.pz2utils4jsf.controls.ResultsPager;\r
-import com.indexdata.pz2utils4jsf.errors.ErrorInterface;\r
 \r
 public interface Pz2Interface extends Serializable {\r
 \r
@@ -98,31 +96,6 @@ public interface Pz2Interface extends Serializable {
    */\r
   public void setCurrentStateKey(String key);\r
   \r
-  /** \r
-   * @return true if any errors encountered so far\r
-   */\r
-  public boolean hasErrors();\r
-  \r
-  /**\r
-   * \r
-   * @return true if errors encountered during execution of commands\r
-   */\r
-  public boolean hasCommandErrors();\r
-  \r
-  /**\r
-   * \r
-   * @return true if errors encountered when configuring the service\r
-   */\r
-  public boolean hasConfigurationErrors();\r
-  \r
-  \r
-  /**\r
-   * Returns all errors encountered during configuration of the application, in particular\r
-   * the Pazpar2 client. \r
-   * \r
-   * @return\r
-   */\r
-  public List<ErrorInterface> getConfigurationErrors();\r
 \r
      \r
 }\r
index b9da841..e18d22a 100644 (file)
@@ -12,7 +12,6 @@ import org.apache.log4j.Logger;
 \r
 import com.indexdata.pz2utils4jsf.errors.ErrorHelper;\r
 import com.indexdata.pz2utils4jsf.errors.ErrorInterface;\r
-import com.indexdata.pz2utils4jsf.utils.Utils;\r
 \r
 @Named("pzresp") @SessionScoped\r
 public class Pazpar2Responses implements Serializable {\r