Merge branch 'master' of ssh://git.indexdata.com/home/git/private/mkjsf.git into...
[mkjsf-moved-to-github.git] / src / main / java / com / indexdata / pz2utils4jsf / errors / ErrorHelper.java
diff --git a/src/main/java/com/indexdata/pz2utils4jsf/errors/ErrorHelper.java b/src/main/java/com/indexdata/pz2utils4jsf/errors/ErrorHelper.java
deleted file mode 100644 (file)
index e78fb4d..0000000
+++ /dev/null
@@ -1,158 +0,0 @@
-package com.indexdata.pz2utils4jsf.errors;\r
-\r
-import static com.indexdata.pz2utils4jsf.utils.Utils.nl;\r
-\r
-import java.io.Serializable;\r
-import java.util.ArrayList;\r
-import java.util.regex.Matcher;\r
-import java.util.regex.Pattern;\r
-\r
-import org.apache.log4j.Logger;\r
-\r
-import com.indexdata.pz2utils4jsf.config.Pz2Configurator;\r
-import com.indexdata.pz2utils4jsf.utils.Utils;\r
-\r
-public class ErrorHelper implements Serializable {\r
-\r
-  public enum ErrorCode {PAZPAR2_404, \r
-                         PAZPAR2_UNEXPECTED_RESPONSE,\r
-                         PAZPAR2_ERRORS,\r
-                         LOCAL_SERVICE_DEF_FILE_NOT_FOUND,\r
-                         REMOTE_SERVICE_DEF_NOT_FOUND,\r
-                         LOCAL_SETTINGS_FILE_NOT_FOUND,\r
-                         MASTERKEY_CONFIG_FILE_NOT_FOUND,\r
-                         MISSING_MANDATORY_PROPERTY,\r
-                         MISSING_MK2_CONFIG_INIT_PARAMETER,\r
-                         MISSING_CONTEXT_PARAMETER,\r
-                         NOT_RESOLVED,\r
-                         SKIP_SUGGESTIONS};\r
-\r
-  private static final long serialVersionUID = 2860804561068279131L;\r
-  private static Pattern httpResponsePattern = Pattern.compile("Unexpected HTTP response code \\(([0-9]*)\\).*");\r
-  \r
-  private static Logger logger = Logger.getLogger(ErrorHelper.class);\r
-  \r
-  private Pz2Configurator configurator = null;\r
-  \r
-  public ErrorHelper(Pz2Configurator configurator) {\r
-    this.configurator = configurator;\r
-  }\r
-  \r
-  public ErrorHelper.ErrorCode getErrorCode(ErrorInterface appError) {\r
-    String errmsg = appError.getMessage();\r
-    if (appError.hasPazpar2Error()) {\r
-      if (appError.getPazpar2Error().getMsg().contains("target settings from file")) {\r
-        return ErrorCode.LOCAL_SETTINGS_FILE_NOT_FOUND;\r
-      } else {\r
-        return ErrorCode.PAZPAR2_ERRORS;\r
-      }\r
-    } else if (errmsg.startsWith("Unexpected HTTP response")) {\r
-      Matcher m = httpResponsePattern.matcher(appError.getMessage());\r
-      if (m.matches()) {\r
-        String errorCode = m.group(1);\r
-        if (errorCode.equals("404")) {\r
-          return ErrorCode.PAZPAR2_404;\r
-        } else {\r
-          return ErrorCode.PAZPAR2_UNEXPECTED_RESPONSE;\r
-        }\r
-      }       \r
-    } else if (errmsg.contains("Configuration file") & appError.getMessage().contains("properties")) {\r
-      return ErrorCode.MASTERKEY_CONFIG_FILE_NOT_FOUND; \r
-    } else if (errmsg.contains("Error reading service definition XML")) {\r
-      return ErrorCode.LOCAL_SERVICE_DEF_FILE_NOT_FOUND;    \r
-    } else if (errmsg.contains("Cannot query Pazpar2 while there are configuration errors")) {\r
-      return ErrorCode.SKIP_SUGGESTIONS;\r
-    } else if (errmsg.contains("Missing mandatory parameter")) {\r
-      return ErrorCode.MISSING_MANDATORY_PROPERTY;\r
-    } else if (errmsg.contains("Pz2ConfigureByMk2Config") && errmsg.contains("Init parameter") && (errmsg.contains("missing"))) {                   \r
-      return ErrorCode.MISSING_MK2_CONFIG_INIT_PARAMETER;\r
-    } else if (appError.getMessage().contains("Pz2ConfigureByWebXml could not find mandatory context-param")) {\r
-      return ErrorCode.MISSING_CONTEXT_PARAMETER;\r
-    }\r
-    return ErrorCode.NOT_RESOLVED;\r
-  }\r
-    \r
-  public ArrayList<String> getSuggestions(ErrorInterface error) {\r
-    ArrayList<String> suggestions = new ArrayList<String>();\r
-    ErrorCode code = getErrorCode(error);\r
-    switch (code) {\r
-      case MISSING_MK2_CONFIG_INIT_PARAMETER:\r
-        suggestions.add("A mandatory init parameter (context-param) was not found in the deployment descriptor (web.xml)." +\r
-          " Following init parameters must be present when using the MasterKey configuration scheme (Pz2ConfigureByMk2Config):" +\r
-          " MASTERKEY_ROOT_CONFIG_DIR (i.e. '/etc/masterkey'), MASTERKEY_COMPONENT_CONFIG_DIR (i.e. '/myapp'), " +\r
-          " MASTERKEY_CONFIG_FILE_NAME (i.e. 'myapp.properties'");      \r
-        break;\r
-      case MISSING_CONTEXT_PARAMETER:\r
-        suggestions.add("A mandatory init parameter (context-param) was not found in the deployment descriptor (web.xml)." +\r
-        " Following init parameters must be present when using Pz2ConfigureByWebXml:" +\r
-        " PAZPAR2_URL, PAZPAR2_SERVICE_ID");      \r
-        break;\r
-      case MISSING_MANDATORY_PROPERTY:\r
-        suggestions.add("A mandatory configuration parameter was not found in the MK2 config properties" +\r
-            " file used. Please check the property file for the parameter given in the error message ");\r
-        addConfigurationDocumentation(suggestions);\r
-        break;      \r
-      case MASTERKEY_CONFIG_FILE_NOT_FOUND: \r
-        suggestions.add("The main configuration file that is looked up using parameters" +\r
-                       " in web.xml (MASTERKEY_ROOT_CONFIG_DIR,MASTERKEY_COMPONENT_CONFIG_DIR,MASTERKEY_CONFIG_FILE_NAME)" +\r
-                       " could not be found. Please check the web.xml parameters and the expected file system location. ");      \r
-        break;\r
-      case LOCAL_SERVICE_DEF_FILE_NOT_FOUND:\r
-        suggestions.add("The service definition file could not be loaded.");\r
-        suggestions.add("Please check the configuration and verify that the file exists");\r
-        addConfigurationDocumentation(suggestions);     \r
-        break;\r
-      case REMOTE_SERVICE_DEF_NOT_FOUND:\r
-        break;\r
-      case LOCAL_SETTINGS_FILE_NOT_FOUND:\r
-        suggestions.add("A configuration using local target settings file was found, but " +\r
-                       " the file itself could not be found. Please check the configuration.");\r
-        addConfigurationDocumentation(suggestions);\r
-        break;\r
-      case PAZPAR2_404:\r
-        suggestions.add("Pazpar2 service not found (404). ");\r
-        suggestions.add("Please check the PAZPAR2_URL configuration and verify "\r
-            + "that a pazpar2 service is running at the given address.");\r
-        addConfigurationDocumentation(suggestions);      \r
-        break;\r
-      case PAZPAR2_UNEXPECTED_RESPONSE:\r
-        suggestions.add("Unexpected response code from Pazpar2. " + nl\r
-            + "Please check the PAZPAR2_URL configuration and verify "\r
-            + "that a pazpar2 service is running at the given address." + nl);\r
-        break;           \r
-      case PAZPAR2_ERRORS:\r
-        if (error.hasPazpar2Error()) {\r
-          String pz2code = error.getPazpar2Error().getCode();\r
-          switch (pz2code) {\r
-            case "3":\r
-              suggestions.add("Query terms not supported.");\r
-              break;\r
-            case "12":\r
-              suggestions.add("The Pazpar2 server does not have a service defined by the requested ID ");\r
-              suggestions.add("Please check the service ID set in the configuration and compare it with the " +\r
-                  " configuration on the Pazpar2 server-side.");\r
-              addConfigurationDocumentation(suggestions);    \r
-              break;          \r
-            default:\r
-              suggestions.add("Pazpar2 error: " + error.getPazpar2Error().getMsg() + " (Pazpar2 # "+error.getPazpar2Error().getCode()+")");\r
-          }\r
-          break;\r
-        } else {\r
-          logger.error("Programming problem. An application error was categorized as a Papzar2 error yet does not have Pazpar2 error information as expected.");\r
-        }\r
-        break;\r
-      case SKIP_SUGGESTIONS:\r
-        break;       \r
-      case NOT_RESOLVED:\r
-        suggestions.add("Sorry, no troubleshooting suggestions were written for this error scenario just yet.");\r
-        break;\r
-    }\r
-    return suggestions;\r
-  }\r
-  \r
-  private void addConfigurationDocumentation (ArrayList<String> suggestions) {\r
-    suggestions.add("The application was configured using the configurator " + Utils.baseObjectName(configurator));\r
-    suggestions.add("This configurator reports that following configuration was used: ");\r
-    suggestions.addAll(configurator.document());\r
-  }\r
-}\r