Renames Pz2Bean to Pz2Service
[mkjsf-moved-to-github.git] / src / main / java / com / indexdata / mkjsf / errors / ErrorCentral.java
1 package com.indexdata.mkjsf.errors;\r
2 \r
3 import java.io.Serializable;\r
4 import java.util.ArrayList;\r
5 import java.util.List;\r
6 \r
7 import javax.enterprise.context.SessionScoped;\r
8 import javax.inject.Inject;\r
9 import javax.inject.Named;\r
10 \r
11 import org.apache.log4j.Logger;\r
12 \r
13 import com.indexdata.mkjsf.config.ConfigurationReader;\r
14 import com.indexdata.mkjsf.pazpar2.Pz2Service;\r
15 \r
16 @SessionScoped @Named\r
17 public class ErrorCentral implements Serializable {\r
18 \r
19   private static final long serialVersionUID = -1658192041068396628L;\r
20   private static Logger logger = Logger.getLogger(ErrorCentral.class);  \r
21   private ErrorHelper errorHelper = null;\r
22     \r
23   @Inject ConfigurationReader configurator;  \r
24   \r
25   private List<ErrorInterface> configurationErrors = new ArrayList<ErrorInterface>();\r
26 \r
27   public ErrorCentral() {\r
28     logger.info("Instantiating ErrorCentral "+this);\r
29     errorHelper = new ErrorHelper(configurator);       \r
30   }\r
31       \r
32   public void addConfigurationError (ErrorInterface configError) {\r
33     configError.setErrorHelper(errorHelper);\r
34     configurationErrors.add(configError);\r
35   }\r
36   \r
37   public boolean hasConfigurationErrors () {\r
38     return (configurationErrors.size()>0);      \r
39   }\r
40 \r
41   public boolean hasCommandErrors () {\r
42     return Pz2Service.get().getPzresp().hasApplicationError();\r
43   }\r
44   \r
45   public ErrorInterface getCommandError () {\r
46     return Pz2Service.get().getPzresp().getCommandError();\r
47   }\r
48 \r
49   /**\r
50    * Returns true if application error found in any response data objects \r
51    */\r
52   public boolean hasErrors () {\r
53     logger.debug("Checking for configuration errors or command errors.");\r
54     return hasConfigurationErrors() || hasCommandErrors();\r
55   }\r
56   \r
57   public List<ErrorInterface> getConfigurationErrors() {    \r
58     return configurationErrors;\r
59   }\r
60   \r
61   public ErrorHelper getHelper () {\r
62     return errorHelper;\r
63   }\r
64 \r
65 \r
66 }\r