Author: jonathan
Date: Thu May  1 13:57:07 2008
New Revision: 16445

Log:

Updated and corrected upgradeChecker service.

Modified:
   trunk/mashup/java/modules/samples/upgradeChecker/upgradeChecker.js
   
trunk/mashup/java/modules/samples/upgradeChecker/upgradeChecker.resources/www/index.html

Modified: trunk/mashup/java/modules/samples/upgradeChecker/upgradeChecker.js
==============================================================================
--- trunk/mashup/java/modules/samples/upgradeChecker/upgradeChecker.js  
(original)
+++ trunk/mashup/java/modules/samples/upgradeChecker/upgradeChecker.js  Thu May 
 1 13:57:07 2008
@@ -12,11 +12,11 @@
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
- 
+
    Created 2007-10 Jonathan Marsh; [EMAIL PROTECTED]
 
    Recommendation algorithm:
-    
+
     Are there releases more current than the users? (1)
         yes -> Is there a nightly more current than the user's? (2)
             yes -> Recommend release, suggest nightly
@@ -26,7 +26,7 @@
                 yes -> Recommend nightly
                 no -> Suggest nightly
             no -> Recommend no action
-    
+
     (1) Requires date of latest release, and date of the user's build
     (2) Requires date of latest nightly, and date of the user's build
     (3) Requires whether the user is running a nightly or not
@@ -46,20 +46,24 @@
     var userBuildDate = version.buildDate();
     var userIsNightly = version.isNightly();
     var userVersionNumber = version.versionNumber();
-   
+
     // Fetch information about the latest release of the Mashup Server
-    var history = fetchHistory();
+    var history = 
system.getXML('http://wso2.org/repos/wso2/trunk/mashup/java/modules/samples/upgradeChecker/upgradeChecker.resources/history.xml');
+    if (history == null)
+        throw "Trouble contacting the Mashup Server project for release 
history.";
+
     var latestRelease = history.release[0];
     if (latestRelease.length() == 0)
         throw "Can't find release history for the mashup server.";
+
     var releaseBuildDate = new Date([EMAIL PROTECTED]);
 
     // Fetch information about the latest nightly build of the Mashup Server
     var nightlyBuildDate = fetchNightlyBuildDate();
-    
+
     var nightlyAge = Math.floor((userBuildDate.getTime() - 
nightlyBuildDate.getTime())/(1000*60*60));
-    var releaseAge = Math.floor((userBuildDate.getTime() - 
releaseBuildDate.getTime())/(1000*60*60));
-    
+    var releaseAge = Math.floor((releaseBuildDate.getTime() - 
nightlyBuildDate.getTime())/(1000*60*60));
+
     var build = new Object();
     build.product = "Mashup Server";
     build.current = {
@@ -69,11 +73,11 @@
     };
 
     build.nightly = {
-        "download" :  "http://dist.wso2.org/products/mashup/nightly-build/";, 
+        "download" :  "http://dist.wso2.org/products/mashup/nightly-build/";,
         "age" : nightlyAge,
         "date" : nightlyBuildDate
     };
-    
+
     build.release = {
         "version" : [EMAIL PROTECTED](),
         "download" : [EMAIL PROTECTED](),
@@ -81,14 +85,17 @@
         "date" : releaseBuildDate
     };
 
-    var newerRelease = releaseAge < 0;
-    var newerNightly = nightlyAge < 0;
+    var newerRelease = releaseAge > 0;
+    var newerNightly = nightlyAge > 0;
     if (newerRelease) {
         build.release.action = "recommended";
         if (newerNightly) {
             build.nightly.action = "suggested";
+        } else {
+            build.nightly.action = "none";
         }
     } else {
+        build.release.action = "none";
         if (newerNightly) {
             if (userIsNightly) {
                 build.nightly.action = "recommended";
@@ -96,10 +103,10 @@
                 build.nightly.action = "suggested";
             }
         } else {
-            // no recommendation - the user has the latest build available.
+            build.nightly.action = "none";
         }
     }
-        
+
     return build;
 }
 
@@ -116,34 +123,20 @@
                 nightly = {build.current.nightly}
                 version = {build.current.version}
                 date = {build.current.date} />
-             <nightly 
+             <nightly
                 download = {build.nightly.download}
-                       age = {build.nightly.age}
-                               date = {build.nightly.date} 
-                               action = {build.nightly.action} />
-             <release 
-                version = {build.release.version} 
-                       download = {build.release.download}
-                       age = {build.release.age}
-                       date = {build.release.date}
-                       action = {build.release.action} />
+                age = {build.nightly.age}
+                date = {build.nightly.date}
+                action = {build.nightly.action} />
+             <release
+                version = {build.release.version}
+                download = {build.release.download}
+                age = {build.release.age}
+                date = {build.release.date}
+                action = {build.release.action} />
            </build>;
 }
 
-fetchHistory.visible = false;
-function fetchHistory() {
-
-    var config =
-        <config>
-            <var-def name='response'>
-                <http method='get' 
url='http://wso2.org/repos/wso2/trunk/mashup/java/modules/samples/upgradeChecker/upgradeChecker.resources/history.xml'/>
-            </var-def>
-        </config>;
-    var history = new Scraper(config);
-
-    return new XML(history.response);
-}
-
 fetchNightlyBuildDate.visible = false;
 function fetchNightlyBuildDate() {
     var name="mashup";
@@ -157,18 +150,18 @@
                     </html-to-xml>
                 </xpath>
             </var-def>
-        </config>;             
+        </config>;
 
     var scraper = new Scraper(config);
     var d = scraper.response;
-    
-    var nightlyBuildDate = 
+
+    var nightlyBuildDate =
         new Date(d.substring(0, 2) + " " +
                  d.substring(3, 6) + " " +
                  d.substring(7) + " GMT-08:00");  // Builder is located in 
California.
     return nightlyBuildDate;
 }
-    
+
 testXML.documentation = <div>Simulates various scenarios for UI testing 
purposes.</div>;
 
 testXML.safe = true;
@@ -177,7 +170,7 @@
 
 function testXML(id) {
     // running 0.2 release, newer nightly
-    if (id == "release-new-nightly") 
+    if (id == "release-new-nightly")
         return <build product="Mashup Server">
             <current nightly="false" version="0.2" date="Thu Oct 04 2007 
04:21:00 GMT-0700 (PDT)" />
             <nightly 
download="http://dist.wso2.org/products/mashup/nightly-build/"; age="73" 
date="Fri Oct 26 2007 11:13:00 GMT-0700 (PDT)" action="recommended" />
@@ -185,7 +178,7 @@
         </build>;
 
     // running 0.2 release, no nightly
-    if (id == "release-no-nightly") 
+    if (id == "release-no-nightly")
         return <build product="Mashup Server">
             <current nightly="false" version="0.2" date="Thu Oct 04 2007 
04:21:00 GMT-0700 (PDT)" />
             <nightly 
download="http://dist.wso2.org/products/mashup/nightly-build/"; age="0" 
date="Thu Oct 04 2007 04:21:00 GMT-0700 (PDT)" />
@@ -193,7 +186,7 @@
         </build>;
 
     // running 0.1 release, newer nightly
-    if (id == "old-release-new-nightly") 
+    if (id == "old-release-new-nightly")
         return <build product="Mashup Server">
             <current nightly="false" version="0.1" date="July 6, 2007 04:14 PM 
GMT" />
             <nightly 
download="http://dist.wso2.org/products/mashup/nightly-build/"; age={111*24} 
date="Fri Oct 26 2007 11:13:00 GMT-0700 (PDT)" action="suggested" />
@@ -201,12 +194,12 @@
         </build>;
 
     // running 0.1 release, no nightly
-    if (id == "old-release-no-nightly") 
+    if (id == "old-release-no-nightly")
         return <build product="Mashup Server">
             <current nightly="false" version="0.1" date="July 6, 2007 04:14 PM 
GMT" />
             <nightly 
download="http://dist.wso2.org/products/mashup/nightly-build/"; age={90*24} 
date="Fri Oct 26 2007 11:13:00 GMT-0700 (PDT)" />
             <release version="0.2" 
download="http://dist.wso2.org/products/mashup/0.2/"; age={90*24} date="Thu Oct 
04 2007 04:21:00 GMT-0700 (PDT)"  action="recommended" />
         </build>;
-    
+
     return <build/>;
 }
\ No newline at end of file

Modified: 
trunk/mashup/java/modules/samples/upgradeChecker/upgradeChecker.resources/www/index.html
==============================================================================
--- 
trunk/mashup/java/modules/samples/upgradeChecker/upgradeChecker.resources/www/index.html
    (original)
+++ 
trunk/mashup/java/modules/samples/upgradeChecker/upgradeChecker.resources/www/index.html
    Thu May  1 13:57:07 2008
@@ -19,8 +19,8 @@
 <META http-equiv="Content-Type" content="text/html; charset=UTF-8">
 <title>Upgrade Checker</title>
 <style type="text/css">
-    body {
-       font: 90%/1.5 "Lucida Grande","Lucida Sans","Microsoft Sans Serif", 
"Lucida Sans Unicode",verdana,sans-serif,"trebuchet ms";
+       body {
+               font: 90%/1.5 "Lucida Grande","Lucida Sans","Microsoft Sans 
Serif", "Lucida Sans Unicode",verdana,sans-serif,"trebuchet ms";
                color: #111;
                text-align:center;
        }
@@ -31,30 +31,31 @@
     table {margin: 1em}
        th {background-color:red}
        h1 {font-size:150%; margin:0.25em}
-    td {text-align:center}
-    .build_date {font-size:70%}
+       td {text-align:center}
+       .build_date {font-size:70%}
        #console {color:red; font-weight:bold; text-align:left}
        .footer {font-size:75%}
 </style>
 <script type="text/javascript" src="/js/wso2/WSRequest.js"></script>
 <script type="text/javascript" src="../upgradeChecker?stub"></script>
 <script type="text/javascript">
-    function load() {
-        // Fetch recommendation for upgrading
-        upgradeChecker.getRecommendation.callback = display;
-        upgradeChecker.getRecommendation.onError = handleError;
+       function load() {
+               // Fetch recommendation for upgrading
+               upgradeChecker.getRecommendation.callback = display;
+               upgradeChecker.getRecommendation.onError = handleError;
                upgradeChecker.getRecommendation();
     }
-    
-    function display(build) {
-       stuff("rec_user_type", build.current.nightly ? "Nightly Build" : 
build.current.version + " Release");
-               stuff("sug_user_type", build.current.nightly ? "Nightly Build" 
: build.current.version + " Release");
-               stuff("norec_type", build.current.nightly ? "nightly build" : 
build.current.version + " release");
-               stuff("norec_type2", build.current.nightly ? "Nightly Build" : 
build.current.version + " Release");
+
+       function display(build) {
+               var buildName = build.current.nightly ? (build.nightly.age > 0 
? "Nightly Build" : "Custom Build") : build.current.version + " Release";
+               stuff("rec_user_type", buildName);
+               stuff("sug_user_type", buildName);
+               stuff("norec_type", buildName);
+               stuff("norec_type2", buildName);
                stuff("rec_user_build_date", 
build.current.date.toLocaleDateString());
                stuff("sug_user_build_date", 
build.current.date.toLocaleDateString());
                stuff("norec_user_build_date", 
build.current.date.toLocaleDateString());
-               
+
                if (build.release.action == 'recommended') {
                        stuff("rec_type", build.release.version + " release");
                        stuff("rec_type2", build.release.version + " Release");
@@ -74,8 +75,6 @@
 
                        document.getElementById("recommendation").style.display 
= "block";
                } else {
-                       stuff("norec_type", build.current.nightly ? "nightly 
build" : "release");
-
                        
document.getElementById("norecommendation").style.display = "block";
                }
 
@@ -100,37 +99,35 @@
                }
                document.getElementById("checking").style.display = "none";
        }
-       
+
        function stuff(id, value) {
-       document.getElementById(id).innerHTML = value;
-    }
-    
-    function ageToString(age) {
-       var ageString;
-               
-       if (age < 0) {
-               ageString = age + " in the future (error someplace!)";
-       } else if (age < 48) {
+               document.getElementById(id).innerHTML = value;
+       }
+
+       function ageToString(age) {
+               var ageString;
+
+               if (age < 48) {
                        ageString = age + " hours";
-       } else if (age < 24*14) {
+               } else if (age < 24*14) {
                        ageString = Math.floor(age/24) + " days";
-               } else {
+               } else {
                        ageString = Math.floor(age/(24*7)) + " weeks";
-               }
-               return ageString;
-    }
-    
+               }
+               return ageString;
+       }
+
        function handleError(error) {
-        log (document.getElementById('console'), "Fault: " + error.reason + 
"\n\n" + error.detail);
-    };
-    
-    function log(console, data) {
-        var browser = WSRequest.util._getBrowser();
-        if (browser == "ie" || browser == "ie7")
-            console.innerText = data;
-        else
-            console.textContent = data;
-    }
+               log (document.getElementById('console'), "Fault: " + 
error.reason + "\n\n" + error.detail);
+       };
+
+       function log(console, data) {
+               var browser = WSRequest.util._getBrowser();
+               if (browser == "ie" || browser == "ie7")
+                       console.innerText = data;
+               else
+                       console.textContent = data;
+       }
 </script>
 </head>
 <body onload="load()">
@@ -142,7 +139,7 @@
 </div>
 <div id="norecommendation" style="display:none">
        <h1>Your <span id="norec_type">---</span> is current.</h1>
-       <div class="normal">No new releases or nightly builds are 
available.</div>
+       <div class="normal">No newer releases or nightly builds are 
available.</div>
        <table style="margin-left:auto; margin-right:auto;">
                <tr>
                        <td>

_______________________________________________
Mashup-dev mailing list
[email protected]
http://www.wso2.org/cgi-bin/mailman/listinfo/mashup-dev

Reply via email to