From: Niels Erik G. Nielsen Date: Mon, 15 Apr 2013 22:14:11 +0000 (-0400) Subject: Sets up error central. Lets page author decide to show. X-Git-Tag: v0.0.7~155 X-Git-Url: http://lists.indexdata.dk/?a=commitdiff_plain;h=130dfe23d607762588d449967bd6b074542a36fd;p=mkjsf-moved-to-github.git Sets up error central. Lets page author decide to show. 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. --- diff --git a/src/META-INF/resources/pz2utils/commanderrors.xhtml b/src/META-INF/resources/pz2utils/commanderrors.xhtml new file mode 100644 index 0000000..1a3ccb5 --- /dev/null +++ b/src/META-INF/resources/pz2utils/commanderrors.xhtml @@ -0,0 +1,31 @@ + + + + + + + + + + + + + + + + + + + + #{suggestion} + + + + + + + \ 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 index 0000000..531c7b5 --- /dev/null +++ b/src/META-INF/resources/pz2utils/configerrors.xhtml @@ -0,0 +1,33 @@ + + + + + + + + + + + + + + + + + + + + #{suggestion} + + + + + + + + + \ No newline at end of file diff --git a/src/META-INF/resources/pz2utils/listeners.js b/src/META-INF/resources/pz2utils/listeners.js index 8c1f466..19be26a 100644 --- a/src/META-INF/resources/pz2utils/listeners.js +++ b/src/META-INF/resources/pz2utils/listeners.js @@ -7,7 +7,7 @@ { //console.log('rendering ' + renderWhileActiveclients); var sourcecomp = document.getElementById("pz2watch:activeclientsField"); - jsf.ajax.request(sourcecomp, null,{render: renderWhileActiveclients + " pz2watch:errorMessages"}); + jsf.ajax.request(sourcecomp, null,{render: renderWhileActiveclients}); if (doRefresh) { //console.log('Will do another ajax request after a timeout in order to render: pz2watch:activeclientsField'); renderTargetsReqVar=setTimeout( diff --git a/src/META-INF/resources/pz2utils/pz2watch.xhtml b/src/META-INF/resources/pz2utils/pz2watch.xhtml index e0f5b82..aafdbef 100644 --- a/src/META-INF/resources/pz2utils/pz2watch.xhtml +++ b/src/META-INF/resources/pz2utils/pz2watch.xhtml @@ -38,30 +38,7 @@ - - - - - - - - - #{suggestion} - - - - - - - - - - - #{suggestion} - - - - + diff --git a/src/META-INF/resources/pz2widgets/login.xhtml b/src/META-INF/resources/pz2widgets/login.xhtml new file mode 100644 index 0000000..a4838c9 --- /dev/null +++ b/src/META-INF/resources/pz2widgets/login.xhtml @@ -0,0 +1,32 @@ + + + + + + + + + + + + + + + + #{cc.attrs.namePrompt} + + + #{cc.attrs.passwordPrompt} + + +

+ +

+
+
+ \ No newline at end of file diff --git a/src/main/java/com/indexdata/pz2utils4jsf/errors/ConfigurationError.java b/src/main/java/com/indexdata/pz2utils4jsf/errors/ConfigurationError.java index 7d3f7ba..ef2969d 100644 --- a/src/main/java/com/indexdata/pz2utils4jsf/errors/ConfigurationError.java +++ b/src/main/java/com/indexdata/pz2utils4jsf/errors/ConfigurationError.java @@ -15,10 +15,9 @@ public class ConfigurationError implements ErrorInterface { private ErrorHelper helper; private ErrorCode applicationErrorCode; - public ConfigurationError(String label, String exception, String message, ErrorHelper helper) { + public ConfigurationError(String label, String exception, String message) { this.label = label; - this.message = message; - this.helper = helper; + this.message = message; this.exception = exception; } 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 index 0000000..a143517 --- /dev/null +++ b/src/main/java/com/indexdata/pz2utils4jsf/errors/ErrorCentral.java @@ -0,0 +1,67 @@ +package com.indexdata.pz2utils4jsf.errors; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; + +import javax.annotation.PostConstruct; +import javax.enterprise.context.SessionScoped; +import javax.inject.Inject; +import javax.inject.Named; + +import org.apache.log4j.Logger; + +import com.indexdata.pz2utils4jsf.config.ConfigurationReader; +import com.indexdata.pz2utils4jsf.pazpar2.data.Pazpar2Responses; + +@Named("errors") @SessionScoped +public class ErrorCentral implements Serializable { + + private static final long serialVersionUID = -1658192041068396628L; + private static Logger logger = Logger.getLogger(ErrorCentral.class); + private ErrorHelper errorHelper = null; + + @Inject Pazpar2Responses pzresp; + @Inject ConfigurationReader configurator; + + private List configurationErrors = new ArrayList(); + + public ErrorCentral() {} + + @PostConstruct + public void postConstruct() { + errorHelper = new ErrorHelper(configurator); + pzresp.setErrorHelper(errorHelper); + } + + public void addConfigurationError (ErrorInterface configError) { + configError.setErrorHelper(errorHelper); + configurationErrors.add(configError); + } + + public boolean hasConfigurationErrors () { + return (configurationErrors.size()>0); + } + + public boolean hasCommandErrors () { + return pzresp.hasApplicationError(); + } + + public ErrorInterface getCommandError () { + return pzresp.getCommandError(); + } + + /** + * Returns true if application error found in any response data objects + */ + public boolean hasErrors () { + logger.debug("Checking for configuration errors or command errors."); + return hasConfigurationErrors() || hasCommandErrors(); + } + + public List getConfigurationErrors() { + return configurationErrors; + } + + +} diff --git a/src/main/java/com/indexdata/pz2utils4jsf/errors/ErrorHelper.java b/src/main/java/com/indexdata/pz2utils4jsf/errors/ErrorHelper.java index 0664f20..086cd84 100644 --- a/src/main/java/com/indexdata/pz2utils4jsf/errors/ErrorHelper.java +++ b/src/main/java/com/indexdata/pz2utils4jsf/errors/ErrorHelper.java @@ -125,7 +125,7 @@ public class ErrorHelper implements Serializable { int pz2code = Integer.parseInt(error.getPazpar2Error().getCode()); switch (pz2code) { case 3: - suggestions.add("Query terms not supported."); + suggestions.add("The search experienced a problem with the query terms."); break; case 12: suggestions.add("The Pazpar2 server does not have a service defined by the requested ID "); diff --git a/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/Pz2Bean.java b/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/Pz2Bean.java index 5a07794..b12082b 100644 --- a/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/Pz2Bean.java +++ b/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/Pz2Bean.java @@ -18,7 +18,7 @@ import com.indexdata.pz2utils4jsf.controls.ResultsPager; import com.indexdata.pz2utils4jsf.errors.ConfigurationError; import com.indexdata.pz2utils4jsf.errors.ConfigurationException; import com.indexdata.pz2utils4jsf.errors.ErrorHelper; -import com.indexdata.pz2utils4jsf.errors.ErrorInterface; +import com.indexdata.pz2utils4jsf.errors.ErrorCentral; import com.indexdata.pz2utils4jsf.pazpar2.commands.CommandParameter; import com.indexdata.pz2utils4jsf.pazpar2.commands.Pazpar2Commands; import com.indexdata.pz2utils4jsf.pazpar2.data.Pazpar2ResponseData; @@ -42,10 +42,11 @@ public class Pz2Bean implements Pz2Interface, StateListener, Serializable { @Inject StateManager stateMgr; @Inject Pazpar2Commands pzreq; @Inject Pazpar2Responses pzresp; + @Inject ErrorCentral errors; protected ResultsPager pager = null; - protected List configurationErrors = null; + protected ErrorHelper errorHelper = null; public Pz2Bean () { @@ -64,15 +65,12 @@ public class Pz2Bean implements Pz2Interface, StateListener, Serializable { } public void configureClient(SearchClient searchClient, ConfigurationReader configReader) { - errorHelper = new ErrorHelper(configurator); - logger.info("pz2 " + Utils.objectId(this) + " sets error helper " + Utils.objectId(errorHelper) + " on pzresp " + Utils.objectId(pzresp)); - pzresp.setErrorHelper(errorHelper); - configurationErrors = new ArrayList(); logger.debug(Utils.objectId(this) + " will configure search client for the session"); try { searchClient.configure(configReader); } catch (ConfigurationException e) { - configurationErrors.add(new ConfigurationError("Search Client","Configuration",e.getMessage(),new ErrorHelper(configReader))); + logger.debug("Pz2Bean adding configuration error"); + errors.addConfigurationError(new ConfigurationError("Search Client","Configuration",e.getMessage())); } logger.info(configReader.document()); pzresp.reset(); @@ -112,7 +110,7 @@ public class Pz2Bean implements Pz2Interface, StateListener, Serializable { * @return Number of activeclients at the time of the 'show' command */ public String update (String commands) { - if (! hasConfigurationErrors()) { + if (! errors.hasConfigurationErrors()) { if (commandsAreValid(commands)) { if (hasQuery()) { handleQueryStateChanges(commands); @@ -195,25 +193,6 @@ public class Pz2Bean implements Pz2Interface, StateListener, Serializable { stateMgr.setCurrentStateKey(key); } - public boolean hasConfigurationErrors () { - return (configurationErrors.size()>0); - } - - public boolean hasCommandErrors () { - return pzresp.hasApplicationError(); - } - - /** - * Returns true if application error found in any response data objects - */ - public boolean hasErrors () { - logger.debug("Checking for configuration errors or command errors."); - return hasConfigurationErrors() || hasCommandErrors(); - } - - public List getConfigurationErrors() { - return configurationErrors; - } protected boolean hasQuery() { diff --git a/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/Pz2Interface.java b/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/Pz2Interface.java index b403d8d..f0cd6d4 100644 --- a/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/Pz2Interface.java +++ b/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/Pz2Interface.java @@ -1,10 +1,8 @@ package com.indexdata.pz2utils4jsf.pazpar2; import java.io.Serializable; -import java.util.List; import com.indexdata.pz2utils4jsf.controls.ResultsPager; -import com.indexdata.pz2utils4jsf.errors.ErrorInterface; public interface Pz2Interface extends Serializable { @@ -98,31 +96,6 @@ public interface Pz2Interface extends Serializable { */ public void setCurrentStateKey(String key); - /** - * @return true if any errors encountered so far - */ - public boolean hasErrors(); - - /** - * - * @return true if errors encountered during execution of commands - */ - public boolean hasCommandErrors(); - - /** - * - * @return true if errors encountered when configuring the service - */ - public boolean hasConfigurationErrors(); - - - /** - * Returns all errors encountered during configuration of the application, in particular - * the Pazpar2 client. - * - * @return - */ - public List getConfigurationErrors(); } diff --git a/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/data/Pazpar2Responses.java b/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/data/Pazpar2Responses.java index b9da841..e18d22a 100644 --- a/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/data/Pazpar2Responses.java +++ b/src/main/java/com/indexdata/pz2utils4jsf/pazpar2/data/Pazpar2Responses.java @@ -12,7 +12,6 @@ import org.apache.log4j.Logger; import com.indexdata.pz2utils4jsf.errors.ErrorHelper; import com.indexdata.pz2utils4jsf.errors.ErrorInterface; -import com.indexdata.pz2utils4jsf.utils.Utils; @Named("pzresp") @SessionScoped public class Pazpar2Responses implements Serializable {