tuscany-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ajbor...@apache.org
Subject svn commit: r512969 - /incubator/tuscany/cpp/sca/samples/AlertAggregator/sample.display/HTMLDisplayImpl.py
Date Wed, 28 Feb 2007 21:06:16 GMT
Author: ajborley
Date: Wed Feb 28 13:06:15 2007
New Revision: 512969

URL: http://svn.apache.org/viewvc?view=rev&rev=512969
Log:
Persist AlertAggregator alert data in a file, rather than in memory

Modified:
    incubator/tuscany/cpp/sca/samples/AlertAggregator/sample.display/HTMLDisplayImpl.py

Modified: incubator/tuscany/cpp/sca/samples/AlertAggregator/sample.display/HTMLDisplayImpl.py
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/sca/samples/AlertAggregator/sample.display/HTMLDisplayImpl.py?view=diff&rev=512969&r1=512968&r2=512969
==============================================================================
--- incubator/tuscany/cpp/sca/samples/AlertAggregator/sample.display/HTMLDisplayImpl.py (original)
+++ incubator/tuscany/cpp/sca/samples/AlertAggregator/sample.display/HTMLDisplayImpl.py Wed
Feb 28 13:06:15 2007
@@ -18,33 +18,61 @@
 #
 
 
-import xml.etree.ElementTree, datetime
+import xml.etree.ElementTree, datetime, os.path, os
 
-# Data structure to hold the alerts
-alertsElem = xml.etree.ElementTree.XML("<alerts xmlns=\"http://tuscany.apache.org/samples/alerter\"/>")
+ns = "./{http://tuscany.apache.org/samples/alerter}"
 
-# Data structure to map source_ids to source types
-sourceTypeMap = {}
+def getSavedAlerts():
 
-ns = "./{http://tuscany.apache.org/samples/alerter}"
+    # Set up some default config data
+    alertsData = "<alerts xmlns=\"http://tuscany.apache.org/samples/alerter\">\n</alerts>"
+
+    if os.path.isfile(os.environ['TUSCANY_SCACPP_ROOT']+"/sample.display/alerts.xml"):
+        # Retrieve the configuration from a file
+        f = open(os.environ['TUSCANY_SCACPP_ROOT']+"/sample.display/alerts.xml")
+        try:
+            alertsData = f.read()
+        finally:
+            f.close()
+   
+    alertsElem = xml.etree.ElementTree.XML(alertsData)
+
+    return alertsElem
+
+def saveAlerts(alertsElem):
+    alertsData = xml.etree.ElementTree.tostring(alertsElem)
+
+    # Save the configuration to a file
+    f = open(os.environ['TUSCANY_SCACPP_ROOT']+"/sample.display/alerts.xml", "w")
+
+    if not f:
+        print "Failed to open alerts file for writing"
+    try:
+        f.write(alertsData)
+    finally:
+        f.close()
 
 
 def updateAllAlertsHTMLTable ():
 
+    alertsElem = getSavedAlerts()
+
     # Use the alertService reference
-    newAlertsElem = alertService.getAllNewAlerts();
+    newAlertsElem = alertService.getAllNewAlerts()
     #newAlertsElem = getAllNewAlerts(); # For testing
 
     for alert in newAlertsElem.findall(ns+"alert"):
 
         alert.attrib["unread"]="True"
-        alertsElem.append(alert)        
+        alertsElem.append(alert)          
 
-    return generateHTMLTable()
+    return generateHTMLTable(alertsElem)
 
 
 def updateSourceAlertsHTMLTable (sourceId):
 
+    alertsElem = getSavedAlerts()
+
     # Use the alertService reference
     newAlertsElem = alertService.getNewAlerts(sourceId);
     #newAlertsElem = getAllNewAlerts(); # For testing
@@ -54,11 +82,11 @@
         alert.attrib["unread"]="True"
         alertsElem.append(alert)        
 
-    return generateHTMLTable()
+    return generateHTMLTable(alertsElem)
 
 
 
-def generateHTMLTable ():
+def generateHTMLTable (alertsElem):
 
     returnData = "<TABLE border=\"0\">"    
 
@@ -107,18 +135,24 @@
 
     returnData += "</TABLE>" 
 
+    saveAlerts(alertsElem)
     #print xml.etree.ElementTree.tostring(alertsElem)
     return returnData
 
 def readAlert (alertID):
 
+    alertsElem = getSavedAlerts()
+
     returnData = ""
     for alert in alertsElem.findall(ns+"alert"):
 
         if alert.attrib["id"]==alertID:
             alert.attrib["unread"] = "False"
 
-            srcType = sourceTypeMap[alert.attrib["sourceid"]]
+            saveAlerts(alertsElem)
+
+            srcType = getSourceType(alert.attrib["sourceid"])
+
             if srcType=="pop":
                 returnData += "<PRE>"
                 returnData += alert.find(ns+"summary").text
@@ -127,6 +161,19 @@
 
     return
 
+def getSourceType(sourceid):
+    # Use the alertService reference
+    alertSources = alertService.getAlertSources()
+    #alertSources = getAlertSources() #testing
+
+    for source in alertSources.findall(ns+"source"):
+
+        if sourceid == source.attrib["id"]:
+            return source.attrib["type"]
+
+    return "none"
+
+
 def getAlertSourcesHTMLTable():
 
     returnData = "<TABLE border=\"0\">\n"    
@@ -141,9 +188,7 @@
 
         srcId = source.attrib["id"]
         srcIdList.append(srcId)
-        srcType = source.attrib["type"]
-
-        sourceTypeMap[srcId]=srcType
+        srcType = source.attrib["type"]        
 
         # Write out the source data row
         returnData += "<TR CLASS=\"source_"



---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-commits-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-commits-help@ws.apache.org


Mime
View raw message