Browse Source

Add WorkUnit XML option for breaking out Exceptions by severity

Used initially to break out exceptions by severity when using "ecl run"
from command line.

Fixes gh-2221.

Signed-off-by: Anthony Fishbeck <Anthony.Fishbeck@lexisnexis.com>
Anthony Fishbeck 13 years ago
parent
commit
25e4f6fb39

+ 6 - 1
common/fileview2/fileview.hpp

@@ -231,7 +231,12 @@ extern "C" FILEVIEW_API unsigned getResultXml(IStringVal & ret, INewResultSet *
 
 extern "C" FILEVIEW_API unsigned getResultCursorBin(MemoryBuffer & ret, IResultSetCursor * cursor, unsigned start=0, unsigned count=0);
 extern "C" FILEVIEW_API unsigned getResultBin(MemoryBuffer & ret, INewResultSet * cursor, unsigned start=0, unsigned count=0);
-extern "C" FILEVIEW_API IStringVal& getFullWorkUnitResultsXML(const char *user, const char *pw, const IConstWorkUnit *wu, IStringVal &str, bool inclschema, WUExceptionSeverity minSeverity=ExceptionSeverityInformation, bool noroot=false);
+
+#define WorkUnitXML_InclSchema      0x0001
+#define WorkUnitXML_NoRoot          0x0002
+#define WorkUnitXML_SeverityTags    0x0004
+
+extern "C" FILEVIEW_API IStringVal& getFullWorkUnitResultsXML(const char *user, const char *pw, const IConstWorkUnit *wu, IStringVal &str, unsigned flags=0, WUExceptionSeverity minSeverity=ExceptionSeverityInformation);
 
 extern FILEVIEW_API void startRemoteDataSourceServer(const char * queue, const char * cluster);
 extern FILEVIEW_API void stopRemoteDataSourceServer();

+ 26 - 8
common/fileview2/fvresultset.cpp

@@ -3413,29 +3413,47 @@ extern "C" FILEVIEW_API unsigned getResultBin(MemoryBuffer & ret, INewResultSet
     return getResultCursorBin(ret, cursor, start, count);
 }
 
+inline const char *getSeverityTagname(WUExceptionSeverity severity, unsigned flags)
+{
+    if (flags & WorkUnitXML_SeverityTags)
+    {
+        switch (severity)
+        {
+        case ExceptionSeverityInformation:
+            return "Info";
+        case ExceptionSeverityWarning:
+            return "Warning";
+        case ExceptionSeverityError:
+        default:
+            break;
+        }
+    }
+    return "Exception";
+}
 
-extern "C" FILEVIEW_API IStringVal& getFullWorkUnitResultsXML(const char *username, const char *password, const IConstWorkUnit *cw, IStringVal &str, bool inclschema, WUExceptionSeverity minSeverity, bool noroot)
+extern "C" FILEVIEW_API IStringVal& getFullWorkUnitResultsXML(const char *username, const char *password, const IConstWorkUnit *cw, IStringVal &str, unsigned flags, WUExceptionSeverity minSeverity)
 {
     SCMStringBuffer wuid;
     cw->getWuid(wuid);
     StringBuffer result;
-    if (!noroot)
-        result.append("<Result>");
+    if (!(flags & WorkUnitXML_NoRoot))
+        result.append("<Result>").newline();
 
     Owned<IConstWUExceptionIterator> exceptions = &cw->getExceptions();
     ForEach(*exceptions)
     {
-        if (exceptions->query().getSeverity()>=minSeverity)
+        WUExceptionSeverity severity = exceptions->query().getSeverity();
+        if (severity>=minSeverity)
         {
             SCMStringBuffer x, y;
             exceptions->query().getExceptionSource(x);
             exceptions->query().getExceptionMessage(y);
             
-            result.append("<Exception><Source>");
+            result.appendf("<%s><Source>", getSeverityTagname(severity, flags));
             encodeUtf8XML(x.str(), result);
             result.append("</Source><Message>");
             encodeUtf8XML(y.str(), result);
-            result.append("</Message></Exception>");
+            result.appendf("</Message></%s>", getSeverityTagname(severity, flags)).newline();
         }
     }
 
@@ -3454,7 +3472,7 @@ extern "C" FILEVIEW_API IStringVal& getFullWorkUnitResultsXML(const char *userna
                     SCMStringBuffer resultXML, name;
                     ds.getResultName(name);
                     Owned<INewResultSet> nr = factory->createNewResultSet(&ds, wuid.str());
-                    getResultXml(resultXML, nr.get(), name.str(), 0, 0, inclschema ? name.str() : NULL);
+                    getResultXml(resultXML, nr.get(), name.str(), 0, 0, (flags & WorkUnitXML_InclSchema) ? name.str() : NULL);
                     result.append(resultXML);
                 }
             }
@@ -3465,7 +3483,7 @@ extern "C" FILEVIEW_API IStringVal& getFullWorkUnitResultsXML(const char *userna
             result.append("<Exception><Source>System</Source><Message>Query aborted by operator</Message></Exception>");
             break;
     }
-    if (!noroot)
+    if (!(flags & WorkUnitXML_NoRoot))
         result.append("</Result>");
     str.set(result.str());
     return str;

+ 3 - 3
common/wuwebview/wuwebview.cpp

@@ -72,7 +72,7 @@ public:
     void appendResults(IConstWorkUnit *wu, const char *username, const char *pw)
     {
         StringBufferAdaptor resultXML(buffer);
-        getFullWorkUnitResultsXML(username, pw, wu, resultXML, false, ExceptionSeverityError, true);
+        getFullWorkUnitResultsXML(username, pw, wu, resultXML, WorkUnitXML_NoRoot, ExceptionSeverityError);
     }
 
     void appendSingleResult(IConstWorkUnit *wu, const char *resultname, const char *username, const char *pw)
@@ -545,7 +545,7 @@ void WuWebView::expandResults(const char *xml, StringBuffer &out, unsigned flags
 void WuWebView::expandResults(StringBuffer &out, unsigned flags)
 {
     SCMStringBuffer xml;
-    getFullWorkUnitResultsXML(username.get(), pw.get(), cw, xml, false, ExceptionSeverityInformation);
+    getFullWorkUnitResultsXML(username.get(), pw.get(), cw, xml);
     expandResults(xml.str(), out, flags);
 }
 
@@ -569,7 +569,7 @@ void WuWebView::applyResultsXSLT(const char *filename, const char *xml, StringBu
 void WuWebView::applyResultsXSLT(const char *filename, StringBuffer &out)
 {
     SCMStringBuffer xml;
-    getFullWorkUnitResultsXML(username.get(), pw.get(), cw, xml, false, ExceptionSeverityInformation);
+    getFullWorkUnitResultsXML(username.get(), pw.get(), cw, xml);
     applyResultsXSLT(filename, xml.str(), out);
 }
 

+ 1 - 1
esp/services/ecldirect/EclDirectService.cpp

@@ -168,7 +168,7 @@ bool CEclDirectEx::onRunEcl(IEspContext &context, IEspRunEclRequest & req, IEspR
         Owned<IConstWorkUnit> cw = factory->openWorkUnit(wuid.str(), false);
 
         SCMStringBuffer resultXML;
-        getFullWorkUnitResultsXML(context.queryUserId(), context.queryPassword(), cw.get(), resultXML, false);
+        getFullWorkUnitResultsXML(context.queryUserId(), context.queryPassword(), cw.get(), resultXML);
         resp.setResults(resultXML.str());
 
         cw.clear();

+ 4 - 1
esp/services/ws_workunits/ws_workunitsService.cpp

@@ -1111,7 +1111,10 @@ bool CWsWorkunitsEx::onWURun(IEspContext &context, IEspWURunRequest &req, IEspWU
             case WUStateUnknown:
             {
                 SCMStringBuffer result;
-                getFullWorkUnitResultsXML(context.queryUserId(), context.queryPassword(), cw.get(), result, false, ExceptionSeverityInformation, req.getNoRootTag());
+                unsigned flags = WorkUnitXML_SeverityTags;
+                if (req.getNoRootTag())
+                    flags |= WorkUnitXML_NoRoot;
+                getFullWorkUnitResultsXML(context.queryUserId(), context.queryPassword(), cw.get(), result, flags);
                 resp.setResults(result.str());
                 break;
             }