Adds distinction between pz2 and sp errors
[mkjsf-moved-to-github.git] / src / main / java / com / indexdata / mkjsf / pazpar2 / data / CommandError.java
index e3fd7b7..54aa8f6 100644 (file)
@@ -41,8 +41,8 @@ public class CommandError extends ResponseDataObject implements ErrorInterface {
   }\r
       \r
   public String getMessage() {\r
-    if (hasPazpar2Error()) {      \r
-      return getPazpar2Error().getMsg();\r
+    if (isServiceError()) {      \r
+      return getServiceError().getMsg();\r
     } else {      \r
       return getOneElementValue("errormessage");\r
     }\r
@@ -66,17 +66,20 @@ public class CommandError extends ResponseDataObject implements ErrorInterface {
    * Creates an XML string error message, embedded in an XML string document named by the command\r
    * This is the XML that ResponseParser will turn into a CommandError object. \r
    * @param commandName\r
-   * @param exceptionName\r
+   * @param exception\r
    * @param errorMessage\r
    * @return\r
    */\r
-  public static String createErrorXml (String commandName, String exceptionName, String errorMessage) {\r
+  public static String createErrorXml (String commandName, String statusCode, String exception, String errorMessage, String response) {\r
     StringBuilder errorXml = new StringBuilder("");\r
     errorXml.append("<" + commandName + ">"+nl);\r
     errorXml.append(" <applicationerror>"+nl);\r
     errorXml.append("  <commandname>" + commandName + "</commandname>"+nl);\r
-    errorXml.append("  <exception>" + (exceptionName != null ? XmlUtils.escape(exceptionName) : "") + "</exception>"+nl);    \r
-    errorXml.append("  <errormessage>" + (errorMessage != null  ? XmlUtils.escape(errorMessage) : "") + "</errormessage>"+nl);    \r
+    errorXml.append("  <status>FAIL</status>"+nl);\r
+    errorXml.append("  <statuscode>" + statusCode + "</statuscode>"+nl);\r
+    errorXml.append("  <exception>" + (exception != null ? XmlUtils.escape(exception) : "") + "</exception>"+nl);    \r
+    errorXml.append("  <errormessage>" + (errorMessage != null  ? XmlUtils.escape(errorMessage) : "") + "</errormessage>"+nl);\r
+    errorXml.append("  <response>" + response + "</response>" + nl);\r
     errorXml.append(" </applicationerror>"+nl);\r
     errorXml.append("</" + commandName + ">"+nl);\r
     return errorXml.toString(); \r
@@ -89,17 +92,18 @@ public class CommandError extends ResponseDataObject implements ErrorInterface {
    * \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 exception The (possibly loosely defined) name of the exception that was thrown\r
    * @param pazpar2ErrorXml The error document as created by Pazpar2, or the Service Proxy or \r
    *                        by the Pazpar2 client itself. \r
    * @return\r
    */\r
-  public static String insertPazpar2ErrorXml (String commandName, String exceptionName, String pazpar2ErrorXml) {\r
+  public static String insertErrorXml (String commandName, String statusCode, String exception, String pazpar2ErrorXml) {\r
     StringBuilder errorXml = new StringBuilder("");\r
     errorXml.append("<" + commandName + ">"+nl);\r
     errorXml.append(" <applicationerror>"+nl);\r
     errorXml.append("  <commandname>" + commandName + "</commandname>"+nl);\r
-    errorXml.append("  <exception>" + XmlUtils.escape(exceptionName) + "</exception>"+nl);    \r
+    errorXml.append("  <statuscode>" + statusCode + "</statuscode>"+nl);\r
+    errorXml.append("  <exception>" + XmlUtils.escape(exception) + "</exception>"+nl);    \r
     errorXml.append(xmlDeclaration.matcher(pazpar2ErrorXml).replaceAll("")+nl);    \r
     errorXml.append(" </applicationerror>"+nl);\r
     errorXml.append("</" + commandName + ">"+nl);\r
@@ -125,13 +129,21 @@ public class CommandError extends ResponseDataObject implements ErrorInterface {
     return applicationErrorCode;    \r
   }\r
   \r
-  public boolean hasPazpar2Error () {\r
-    return ( getOneElement("error") != null);            \r
+  public boolean isServiceError () {\r
+    ServiceError pz2err = (ServiceError) getOneElement("error");\r
+    return (pz2err != null);\r
   }\r
   \r
-  public Pazpar2Error getPazpar2Error() {\r
-    return (Pazpar2Error) getOneElement("error");\r
+  public ServiceError getServiceError() {\r
+    return (ServiceError) getOneElement("error");\r
+  }\r
+  \r
+  public boolean isServiceProxyError () {\r
+    return (isServiceError() && getServiceError().isServiceProxyError());\r
   }\r
 \r
+  public boolean isPazpar2Error () {\r
+    return (isServiceError() && getServiceError().isPazpar2Error());\r
+  }\r
 \r
 }\r