Merge branch 'master' of ssh://git.indexdata.com/home/git/private/mkjsf.git into...
[mkjsf-moved-to-github.git] / src / main / java / com / indexdata / mkjsf / errors / ErrorCentral.java
diff --git a/src/main/java/com/indexdata/mkjsf/errors/ErrorCentral.java b/src/main/java/com/indexdata/mkjsf/errors/ErrorCentral.java
new file mode 100644 (file)
index 0000000..b6bbd47
--- /dev/null
@@ -0,0 +1,66 @@
+package com.indexdata.mkjsf.errors;\r
+\r
+import java.io.Serializable;\r
+import java.util.ArrayList;\r
+import java.util.List;\r
+\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.mkjsf.config.ConfigurationReader;\r
+import com.indexdata.mkjsf.pazpar2.Pz2Service;\r
+\r
+@SessionScoped @Named\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 ConfigurationReader configurator;  \r
+  \r
+  private List<ErrorInterface> configurationErrors = new ArrayList<ErrorInterface>();\r
+\r
+  public ErrorCentral() {\r
+    logger.info("Instantiating ErrorCentral "+this);\r
+    errorHelper = new ErrorHelper(configurator);       \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 Pz2Service.get().getPzresp().hasApplicationError();\r
+  }\r
+  \r
+  public ErrorInterface getCommandError () {\r
+    return Pz2Service.get().getPzresp().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
+  public ErrorHelper getHelper () {\r
+    return errorHelper;\r
+  }\r
+\r
+\r
+}\r