if (properties.containsKey(key)) {\r
return properties.get(key);\r
} \r
- throw new Error("Missing mandatory parameter: " + key); \r
+ throw new MissingMandatoryParameterException("Missing mandatory parameter: " + key); \r
}\r
\r
@Override\r
+++ /dev/null
-package com.indexdata.pz2utils4jsf.errors;\r
-\r
-import java.io.Serializable;\r
-import java.util.List;\r
-\r
-import com.indexdata.pz2utils4jsf.errors.ErrorHelper.ErrorCode;\r
-import com.indexdata.pz2utils4jsf.pazpar2.data.Pazpar2Error;\r
-\r
-\r
-public interface ApplicationError extends Serializable {\r
- \r
- public String getLabel();\r
- public String getMessage(); \r
- public String getException();\r
- public void setApplicationErrorCode(ErrorCode code);\r
- public ErrorCode getApplicationErrorCode();\r
- public List<String> getSuggestions();\r
- public void setErrorHelper(ErrorHelper helper);\r
- public boolean hasPazpar2Error();\r
- public Pazpar2Error getPazpar2Error();\r
- \r
-}\r
import com.indexdata.pz2utils4jsf.pazpar2.data.Pazpar2Error;\r
\r
\r
-public class ConfigurationError implements ApplicationError {\r
+public class ConfigurationError implements ErrorInterface {\r
\r
private static final long serialVersionUID = -6599667223782130838L;\r
private String label;\r
import org.apache.log4j.Logger;\r
\r
import com.indexdata.pz2utils4jsf.config.Pz2Configurator;\r
-import com.indexdata.pz2utils4jsf.config.Pz2ConfigureByMk2Config;\r
import com.indexdata.pz2utils4jsf.pazpar2.data.Pazpar2Error;\r
import com.indexdata.pz2utils4jsf.utils.Utils;\r
\r
REMOTE_SERVICE_DEF_NOT_FOUND,\r
LOCAL_SETTINGS_FILE_NOT_FOUND,\r
MASTERKEY_CONFIG_FILE_NOT_FOUND,\r
+ MISSING_MANDATORY_PARAMETER,\r
NOT_RESOLVED,\r
SKIP_SUGGESTIONS};\r
\r
this.configurator = configurator;\r
}\r
\r
- public ErrorHelper.ErrorCode getErrorCode(ApplicationError appError) {\r
+ public ErrorHelper.ErrorCode getErrorCode(ErrorInterface appError) {\r
if (appError.hasPazpar2Error()) {\r
Pazpar2Error pz2err = appError.getPazpar2Error();\r
String pz2errcode = pz2err.getCode();\r
return ErrorCode.LOCAL_SERVICE_DEF_FILE_NOT_FOUND; \r
} else if (appError.getMessage().contains("Cannot query Pazpar2 while there are configuration errors")) {\r
return ErrorCode.SKIP_SUGGESTIONS;\r
+ } else if (appError.getMessage().contains("Missing mandatory parameter")) {\r
+ return ErrorCode.MISSING_MANDATORY_PARAMETER;\r
}\r
return ErrorCode.NOT_RESOLVED;\r
}\r
\r
- public ArrayList<String> getSuggestions(ApplicationError error) {\r
+ public ArrayList<String> getSuggestions(ErrorInterface error) {\r
ArrayList<String> suggestions = new ArrayList<String>();\r
ErrorCode code = getErrorCode(error);\r
switch (code) {\r
" the file itself could not be found. Please check the configuration.");\r
addConfigurationDocumentation(suggestions);\r
break;\r
+ case MISSING_MANDATORY_PARAMETER:\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 NOT_RESOLVED:\r
suggestions.add("Unforeseen error situation. No suggestions prepared.");\r
break;\r
--- /dev/null
+package com.indexdata.pz2utils4jsf.errors;\r
+\r
+import java.io.Serializable;\r
+import java.util.List;\r
+\r
+import com.indexdata.pz2utils4jsf.errors.ErrorHelper.ErrorCode;\r
+import com.indexdata.pz2utils4jsf.pazpar2.data.Pazpar2Error;\r
+\r
+\r
+public interface ErrorInterface extends Serializable {\r
+ \r
+ public String getLabel();\r
+ public String getMessage(); \r
+ public String getException();\r
+ public void setApplicationErrorCode(ErrorCode code);\r
+ public ErrorCode getApplicationErrorCode();\r
+ public List<String> getSuggestions();\r
+ public void setErrorHelper(ErrorHelper helper);\r
+ public boolean hasPazpar2Error();\r
+ public Pazpar2Error getPazpar2Error();\r
+ \r
+}\r
\r
import com.indexdata.pz2utils4jsf.config.Pz2Configurator;\r
import com.indexdata.pz2utils4jsf.controls.ResultsPager;\r
-import com.indexdata.pz2utils4jsf.errors.ApplicationError;\r
+import com.indexdata.pz2utils4jsf.errors.ErrorInterface;\r
import com.indexdata.pz2utils4jsf.pazpar2.data.ByTarget;\r
import com.indexdata.pz2utils4jsf.pazpar2.data.RecordResponse;\r
import com.indexdata.pz2utils4jsf.pazpar2.data.ShowResponse;\r
return pz2.hasErrors();\r
}\r
\r
- public ApplicationError getCommandError() {\r
+ public ErrorInterface getCommandError() {\r
return pz2.getCommandError();\r
}\r
\r
- public List<ApplicationError> getConfigurationErrors () {\r
+ public List<ErrorInterface> getConfigurationErrors () {\r
return pz2.getConfigurationErrors();\r
}\r
\r
import java.util.List;\r
\r
import com.indexdata.pz2utils4jsf.controls.ResultsPager;\r
-import com.indexdata.pz2utils4jsf.errors.ApplicationError;\r
+import com.indexdata.pz2utils4jsf.errors.ErrorInterface;\r
import com.indexdata.pz2utils4jsf.pazpar2.data.ByTarget;\r
import com.indexdata.pz2utils4jsf.pazpar2.data.RecordResponse;\r
import com.indexdata.pz2utils4jsf.pazpar2.data.ShowResponse;\r
* \r
* @return\r
*/\r
- public ApplicationError getCommandError();\r
+ public ErrorInterface getCommandError();\r
\r
/**\r
* Returns all errors encountered during configuration of the application, in particular\r
* \r
* @return\r
*/\r
- public List<ApplicationError> getConfigurationErrors();\r
+ public List<ErrorInterface> getConfigurationErrors();\r
\r
}\r
import com.indexdata.masterkey.pazpar2.client.exceptions.ProxyErrorException;\r
import com.indexdata.pz2utils4jsf.config.Pz2Configurator;\r
import com.indexdata.pz2utils4jsf.controls.ResultsPager;\r
-import com.indexdata.pz2utils4jsf.errors.ApplicationError;\r
+import com.indexdata.pz2utils4jsf.errors.ErrorInterface;\r
import com.indexdata.pz2utils4jsf.errors.ErrorHelper;\r
import com.indexdata.pz2utils4jsf.errors.ConfigurationError;\r
import com.indexdata.pz2utils4jsf.pazpar2.data.CommandError;\r
private TargetFilter targetFilter = null; \r
private ResultsPager pager = null; \r
private ErrorHelper errorHelper = null;\r
- private List<ApplicationError> configurationErrors = null;\r
+ private List<ErrorInterface> configurationErrors = null;\r
\r
public Pz2Session () {\r
logger.info("Instantiating pz2 session object [" + Utils.objectId(this) + "]"); \r
\r
public void init(Pz2Configurator pz2conf) {\r
if (client==null) {\r
- configurationErrors = new ArrayList<ApplicationError>();\r
+ configurationErrors = new ArrayList<ErrorInterface>();\r
errorHelper = new ErrorHelper(pz2conf);\r
logger.info(Utils.objectId(this) + " is configuring itself using the provided " + Utils.objectId(pz2conf));\r
try {\r
return "0";\r
}\r
} else {\r
- configurationErrors.add(\r
- new ConfigurationError("Querying while errors",\r
- "App halted",\r
- "Cannot query Pazpar2 while there are configuration errors.",\r
- errorHelper));\r
+ logger.error("Did not attempt to execute query since there are configuration errors.");\r
return "0";\r
}\r
\r
return hasConfigurationErrors() || hasCommandErrors();\r
}\r
\r
- public List<ApplicationError> getConfigurationErrors() { \r
+ public List<ErrorInterface> getConfigurationErrors() { \r
return configurationErrors;\r
}\r
\r
* error found for an arbitrary command, if any, otherwise\r
* an empty dummy error. \r
*/ \r
- public ApplicationError getCommandError() {\r
+ public ErrorInterface getCommandError() {\r
CommandError error = new CommandError(); \r
if (dataObjects.get("search").hasApplicationError()) {\r
error = dataObjects.get("search").getApplicationError(); \r
import java.util.ArrayList;\r
import java.util.List;\r
\r
-import com.indexdata.pz2utils4jsf.errors.ApplicationError;\r
+import com.indexdata.pz2utils4jsf.errors.ErrorInterface;\r
import com.indexdata.pz2utils4jsf.errors.ErrorHelper;\r
import com.indexdata.pz2utils4jsf.errors.ErrorHelper.ErrorCode;\r
import com.indexdata.utils.XmlUtils;\r
\r
/**\r
- * Captures errors encountered during the execution of a command. \r
- * Is parsed by Pazpar2ResponseParser, piggybacked in a (seemingly)\r
- * regular command respond.\r
+ * Holds an error encountered during the execution of a command.\r
+ * \r
+ * An error can be received by a command thread as an exception message \r
+ * or as an error XML. In both cases the error (string or xml) will be embedded\r
+ * in a new 'applicationerror' element which in turn will be embedded in a\r
+ * command XML (i.e. a 'search' or a 'show' response XML) \r
+ * \r
+ * The command response XML is subsequently parsed by Pazpar2ResponseParser, \r
+ * which will then create the CommandError object.\r
* \r
* @author Niels Erik\r
*\r
*/\r
-public class CommandError extends Pazpar2ResponseData implements ApplicationError {\r
+public class CommandError extends Pazpar2ResponseData implements ErrorInterface {\r
\r
private static final long serialVersionUID = 8878776025779714122L;\r
private ErrorCode applicationErrorCode;\r
\r
/**\r
* Creates an XML string error message, embedded in an XML string document named by the command\r
+ * This is the XML that Pazpar2ResponseParser will turn into a CommandError object. \r
* @param commandName\r
* @param exceptionName\r
* @param errorMessage\r
return errorXml.toString(); \r
}\r
\r
+ /**\r
+ * Embeds a Pazpar2 (or Pazpar2 client) error response document as a child element of\r
+ * a command response document (like 'search' or 'show').\r
+ * This is the XML that Pazpar2ResponseParser will turn into a CommandError object.\r
+ * \r
+ * \r
+ * @param commandName The name of the command during which's execution the error was encountered\r
+ * @param exceptionName The (possibly loosely defined) name of the exception that was thrown\r
+ * @param pazpar2ErrorXml The error document as created by Pazpar2 -- or, for some errors, by the \r
+ * Pazpar2 client. \r
+ * @return\r
+ */\r
public static String insertPazpar2ErrorXml (String commandName, String exceptionName, String pazpar2ErrorXml) {\r
StringBuilder errorXml = new StringBuilder("");\r
errorXml.append("<" + commandName + ">"+nl);\r
return errorXml.toString(); \r
\r
}\r
- \r
+ \r
+ /**\r
+ * Sets the object that should be used to analyze the error\r
+ * \r
+ */\r
public void setErrorHelper (ErrorHelper errorHelper) {\r
this.errorHelper = errorHelper; \r
}\r