Index: Dev/branches/rest-dojo-ui/server/couchdb-admin/bootstrap.js
===================================================================
--- Dev/branches/rest-dojo-ui/server/couchdb-admin/bootstrap.js	(revision 415)
+++ Dev/branches/rest-dojo-ui/server/couchdb-admin/bootstrap.js	(revision 415)
@@ -0,0 +1,15 @@
+dojoConfig = {
+    packagePaths:{
+        '../../client':[
+            'dojo',
+            'dijit',
+            'dojox',
+            'rft'
+        ],
+        '.':[
+            'config',
+            'check'
+        ]
+    }
+};
+require('../../client/dojo/dojo');
Index: Dev/branches/rest-dojo-ui/server/couchdb-admin/config.bat
===================================================================
--- Dev/branches/rest-dojo-ui/client/config/config.bat	(revision 411)
+++ 	(revision )
@@ -1,1 +1,0 @@
-node ../dojo/dojo.js load=config/db
Index: Dev/branches/rest-dojo-ui/server/couchdb-admin/config.sh
===================================================================
--- Dev/branches/rest-dojo-ui/client/config/config.sh	(revision 411)
+++ 	(revision )
@@ -1,2 +1,0 @@
-#!/bin/sh
-node ../dojo/dojo.js load=config/db
Index: Dev/branches/rest-dojo-ui/server/couchdb-admin/config/check.js
===================================================================
--- Dev/branches/rest-dojo-ui/server/couchdb-admin/config/check.js	(revision 415)
+++ Dev/branches/rest-dojo-ui/server/couchdb-admin/config/check.js	(revision 415)
@@ -0,0 +1,39 @@
+define([
+     'dojo/_base/array',
+     'dojox/json/schema',
+     './util/async',
+     './util/db',
+     'rft/schema'
+],function(array,jsonSchema,async,db,schema){
+
+    async.seq([
+        function(){
+            console.log("Validating documents for QED:");
+            console.log("NOTE: referential integrity is not checked.");
+        },
+        function(){
+            console.log("Getting list of documents.");
+            return db.req('get','qed/_all_docs')
+            .then(function(docs){
+                return array.filter(docs.rows,function(doc){
+                    return doc.id.indexOf('_design/') !== 0;
+                });
+            });
+        },
+        function(docs){
+            console.log("Validating documents.");
+            return async.forEach(docs,function(doc){
+                var id = doc.id;
+                return db.req('get','qed/'+id)
+                .then(function(actualDoc){
+                    var result = jsonSchema.validate(actualDoc,schema);
+                    console.log("Document '"+id+"' is "+(result.valid ? "valid" : "invalid")+".");
+                });
+            });
+        },function(){
+            console.log("Done!");
+        }
+    ]);
+
+
+});
Index: Dev/branches/rest-dojo-ui/server/couchdb-admin/config/config.js
===================================================================
--- Dev/branches/rest-dojo-ui/server/couchdb-admin/config/config.js	(revision 415)
+++ Dev/branches/rest-dojo-ui/server/couchdb-admin/config/config.js	(revision 415)
@@ -0,0 +1,90 @@
+define([
+     'dojo/_base/json',
+     'dojo/_base/lang',
+     'dojox/lang/functional',
+     './util/async',
+     './util/db',
+     './data/design-docs'
+],function(json,lang,func,async,db,docs){
+
+    function serializeFunctions(value) {
+        if ( value === null ) {
+            return null;
+        } else if ( lang.isArray(value) ) {
+            return value;
+        } else if ( lang.isFunction(value) ) {
+            return value.toString();
+        } else if ( lang.isObject(value) ) {
+            return func.mapIn(value,serializeFunctions);
+        } else {
+            return value;
+        }
+    }
+
+    async.seq([
+        function(){
+            console.log("Configuring CouchDB for QED:");
+        },
+        function(){
+            console.log("Checking CouchDB version");
+            return db.req('get','')
+            .then(function(res){
+                if (res.version !== "1.2.0" ) {
+                    console.log("Found "+res.version+", only tested with CouchDB 1.2.0")
+                } else {
+                    console.log("CouchDB 1.2.0 found");
+                }
+            });
+        },function(){
+            console.log("Checking database 'qed'");
+            return db.req('get','qed')
+            .then(function(res){
+                if (res.error) {
+                    console.log("Creating database 'qed'");
+                    return db.req('put','/qed');
+                } else {
+                    console.log("Database 'qed' found.");
+                }
+            },function(res){
+                console.log("Creating database 'qed'");
+                return db.req('put','/qed');
+            });
+        },function(){
+            return serializeFunctions(docs);
+        },function(docs){
+            console.log("Putting documents in database.");
+            return async.forEach(func.keys(docs),function(docUrl){
+                var doc = docs[docUrl];
+                var configAction = doc.__configAction;
+                delete doc.__configAction;
+                switch (configAction) {
+                    case "ignore":
+                        console.log(docUrl+" ignored.");
+                    case "update":
+                        console.log(docUrl+" updating.");
+                        return db.req('get',docUrl)
+                        .then(function(oldDoc){
+                            lang.mixin(oldDoc,doc);
+                            return db.req('put',docUrl,oldDoc);
+                        },function(){
+                            return db.req('put',docUrl,doc);
+                        });
+                    case "replace":
+                    default:
+                        console.log(docUrl+" replacing.");
+                        return db.req('get',docUrl)
+                        .then(function(oldDoc){
+                            doc['_rev'] = oldDoc['_rev'];
+                            return db.req('put',docUrl,doc);
+                        },function(){
+                            return db.req('put',docUrl,doc);
+                        });
+                }
+            });
+        },function(){
+            console.log("Done!");
+        }
+    ]);
+
+
+});
Index: Dev/branches/rest-dojo-ui/server/couchdb-admin/config/data/design-docs.js
===================================================================
--- Dev/branches/rest-dojo-ui/server/couchdb-admin/config/data/design-docs.js	(revision 415)
+++ Dev/branches/rest-dojo-ui/server/couchdb-admin/config/data/design-docs.js	(revision 415)
@@ -0,0 +1,104 @@
+define([],function(){
+    return {
+        "_users/qed_admin": {
+            __configAction: "ignore",
+            _id: "org.couchdb.user:qed_admin",
+            name: "qed_admin",
+            password: "Welkom01",
+            roles: [ "qed_admin" ],
+            type: "user"
+        },
+        "qed/_security": {
+            __configAction: "ignore",
+            admins: {
+                names: [],
+                roles: ["qed_admin"]
+            },
+            readers: {
+                names: [],
+                roles: ["qed_user"]
+            }
+        },
+        "qed/_design/default": {
+            __configAction: "replace",
+            _id: "_design/default",
+            language: "javascript",
+            validate_doc_update: function(newDoc, oldDoc, userCtx, secObj) {
+                if ( oldDoc && oldDoc.publicationDate ) { throw({forbidden:'Published documents cannot be modified.'}); }
+            },
+            views: {
+                by_type: {
+                    map: function(doc){
+                        emit(doc.type, doc);
+                    }
+                }
+            }
+        },
+        "qed/_design/questions": {
+            __configAction: "replace",
+            _id: "_design/questions",
+            language: "javascript",
+            views: {
+                all: {
+                    map: function(doc){
+                        if ( doc.type !== 'Question' ) { return; }
+                        if ( doc.categories && doc.categories.length > 0 ) {
+                            for ( var i = 0; i < doc.categories.length; i++ ) { 
+                                emit([doc.categories[i],doc.topic||null],1);
+                            } 
+                        } else { 
+                            emit([null,null],1); 
+                        } 
+                    },
+                    reduce: function(keys,values){ return sum(values); }
+                },
+                published: {
+                    map: function(doc){
+                        if ( doc.type!=='Question' || !doc.publicationDate ) { return; }
+                        if ( doc.categories && doc.categories.length > 0 ) {
+                            for ( var i = 0; i < doc.categories.length; i++ ) {
+                                emit([doc.categories[i],doc.topic||null],1);
+                            }
+                        } else {
+                            emit([null,null],1);
+                        }
+                    },
+                    reduce: function(keys,values){ return sum(values); }
+                },
+                all_topics: {
+                    map: function(doc){
+                        if( doc.type !== 'Question' ){ return; }
+                        emit(doc.topic);
+                    },
+                    reduce: function(key, values, rereduce) { return null; }
+                },
+                published_topics: {
+                    map: function(doc){
+                        if ( doc.type !== 'Question' || !doc.publicationDate ) { return; }
+                        emit(doc.topic);
+                    },
+                    reduce: function(key, values, rereduce) { return null; }
+                }
+            }
+        },
+        "qed/_design/surveys": {
+            __configAction: "replace",
+            _id: "_design/surveys",
+            language: "javascript",
+            views: {
+                drafts: {
+                    map: function(doc){
+                        if ( doc.type !== 'Survey' || doc.publicationDate ) { return; }
+                        emit(doc._id,doc);
+                    }
+                },
+                published: {
+                    map: function(doc){
+                        if ( doc.type !== 'Survey' || !doc.publicationDate ) { return; }
+                        emit(doc._id,doc);
+                    }
+                }
+            }
+        }
+    };
+});
Index: Dev/branches/rest-dojo-ui/server/couchdb-admin/config/util/async.js
===================================================================
--- Dev/branches/rest-dojo-ui/server/couchdb-admin/config/util/async.js	(revision 415)
+++ Dev/branches/rest-dojo-ui/server/couchdb-admin/config/util/async.js	(revision 415)
@@ -0,0 +1,54 @@
+define([
+     'dojo/Deferred',
+],function(Deferred){
+
+    function seq(functions) {
+        var d = new Deferred();
+        (function stepper(fs,arg) {
+            if ( fs.length > 0 ) {
+                try {
+                    var f = fs.shift();
+                    var ret = f(arg);
+                    if ( ret && ret.then ) {
+                        ret.then(function(ret){
+                            stepper(fs,ret);
+                        });
+                    } else {
+                        stepper(fs,ret);
+                    }
+                } catch(err) {
+                    d.reject(err);
+                }
+            } else {
+                d.resolve();
+            }
+        })(functions);
+        return d.promise;
+    }
+
+    function forEach(list,callback,ctx) {
+        var d = new Deferred();
+        (function stepper(list,idx){
+            if ( list.length > 0 ) {
+                var el = list.shift();
+                var ret = callback.call(ctx,el,idx);
+                if ( ret && ret.then ) {
+                    ret.then(function(){
+                        stepper(list,idx+1);
+                    });
+                } else {
+                    stepper(list,idx+1);
+                }
+            } else {
+                d.resolve();
+            }
+        })(list,0);
+        return d.promise;
+    }
+
+    return {
+        seq: seq,
+        forEach: forEach
+    };
+
+});
Index: Dev/branches/rest-dojo-ui/server/couchdb-admin/config/util/db.js
===================================================================
--- Dev/branches/rest-dojo-ui/server/couchdb-admin/config/util/db.js	(revision 415)
+++ Dev/branches/rest-dojo-ui/server/couchdb-admin/config/util/db.js	(revision 415)
@@ -0,0 +1,20 @@
+define([
+     'dojo/_base/json',
+     'dojo/request'
+],function(json,request){
+    var dbUrl = "http://localhost:5984/";
+
+    function req(method,path,body) {
+        var args = {
+            contentType: 'application/json',
+            handleAs: 'json',
+            data: json.toJson(body || {})
+        };
+        return request[method](dbUrl+path,args);
+    }
+
+    return {
+        req:req
+    };
+
+});
Index: Dev/branches/rest-dojo-ui/server/couchdb-admin/db.js
===================================================================
--- Dev/branches/rest-dojo-ui/client/config/db.js	(revision 411)
+++ 	(revision )
@@ -1,139 +1,0 @@
-define([
-     'dojo/_base/json',
-     'dojo/_base/lang',
-     'dojo/Deferred',
-     'dojo/request',
-     'dojox/lang/functional',
-     './docs'
-],function(json,lang,Deferred,request,func,docs){
-    var dbUrl = "http://localhost:5984/";
-
-    function serializeFunctions(value) {
-        if ( value === null ) {
-            return null;
-        } else if ( lang.isArray(value) ) {
-            return value;
-        } else if ( lang.isFunction(value) ) {
-            return value.toString();
-        } else if ( lang.isObject(value) ) {
-            return func.mapIn(value,serializeFunctions);
-        } else {
-            return value;
-        }
-    }
-
-    function req(method,path,body) {
-        var args = {
-            contentType: 'application/json',
-            handleAs: 'json',
-            data: json.toJson(body || {})
-        };
-        return request[method](dbUrl+path,args);
-    }
-
-    function asyncSeq(functions) {
-        var d = new Deferred();
-        (function stepper(fs,arg) {
-            if ( fs.length > 0 ) {
-                try {
-                    var f = fs.shift();
-                    var ret = f(arg);
-                    if ( ret && ret.then ) {
-                        ret.then(function(ret){
-                            stepper(fs,ret);
-                        });
-                    } else {
-                        stepper(fs,ret);
-                    }
-                } catch(err) {
-                    d.reject(err);
-                }
-            } else {
-                d.resolve();
-            }
-        })(functions);
-        return d.promise;
-    }
-
-    function asyncFor(list,callback,ctx) {
-        var d = new Deferred();
-        (function stepper(list,idx){
-            if ( list.length > 0 ) {
-                var el = list.shift();
-                var ret = callback.call(ctx,el,idx);
-                if ( ret && ret.then ) {
-                    ret.then(function(){
-                        stepper(list,idx+1);
-                    });
-                } else {
-                    stepper(list,idx+1);
-                }
-            } else {
-                d.resolve();
-            }
-        })(list,0);
-        return d.promise;
-    }
-
-    asyncSeq([
-        function(){
-            console.log("Configuring CouchDB for RFT:");
-        },
-        function(){
-            console.log("Checking CouchDB version");
-            return req('get','')
-            .then(function(res){
-                if (res.version !== "1.2.0" ) {
-                    console.log("Found "+res.version+", only tested with CouchDB 1.2.0")
-                } else {
-                    console.log("CouchDB 1.2.0 found");
-                }
-            });
-        },function(){
-            console.log("Checking database 'rft'");
-            return req('get','rft')
-            .then(function(){
-                console.log("Database 'rft' found.");
-            },function(){
-                console.log("Creating database 'rft'");
-                return req('put','/rft');
-            });
-        },function(){
-            return serializeFunctions(docs);
-        },function(docs){
-            console.log("Putting documents in database.");
-            return asyncFor(func.keys(docs),function(docUrl){
-                var doc = docs[docUrl];
-                var configAction = doc.__configAction;
-                delete doc.__configAction;
-                switch (configAction) {
-                    case "ignore":
-                        console.log(docUrl+" ignored.");
-                    case "update":
-                        console.log(docUrl+" updating.");
-                        return req('get',docUrl)
-                        .then(function(oldDoc){
-                            lang.mixin(oldDoc,doc);
-                            return req('put',docUrl,oldDoc);
-                        },function(){
-                            return req('put',docUrl,doc);
-                        });
-                    case "replace":
-                    default:
-                        console.log(docUrl+" replacing.");
-                        return req('get',docUrl)
-                        .then(function(oldDoc){
-                            doc['_rev'] = oldDoc['_rev'];
-                            return req('put',docUrl,doc);
-                        },function(){
-                            return req('put',docUrl,doc);
-                        });
-                }
-            });
-        },function(){
-            console.log("Done!");
-        }
-    ]);
-
-
-});
Index: Dev/branches/rest-dojo-ui/server/couchdb-admin/docs.js
===================================================================
--- Dev/branches/rest-dojo-ui/client/config/docs.js	(revision 411)
+++ 	(revision )
@@ -1,107 +1,0 @@
-define([],function(){
-    return {
-        "_users/rft_admin": {
-            __configAction: "ignore",
-            _id: "org.couchdb.user:rft_admin",
-            name: "rft_admin",
-            password: "Welkom01",
-            roles: [ "rft_admin" ],
-            type: "user"
-        },
-        "rft/_security": {
-            __configAction: "ignore",
-            admins: {
-                names: [],
-                roles: ["rft_admin"]
-            },
-            readers: {
-                names: [],
-                roles: ["rft_user"]
-            }
-        },
-        "rft/_design/default": {
-            __configAction: "replace",
-            _id: "_design/default",
-            language: "javascript",
-            validate_doc_update: function(newDoc, oldDoc, userCtx, secObj) {
-                if ( oldDoc && oldDoc.publicationDate ) { throw({forbidden:'Published documents cannot be modified.'}); }
-                if ( !newDoc._deleted && !newDoc.type ) { throw({forbidden:'Documents must have a type field.'}); }
-            },
-            views: {
-                by_type: {
-                    map: function(doc){
-                        emit(doc.type, doc);
-                    }
-                }
-            }
-        },
-        "rft/_design/questions": {
-            __configAction: "replace",
-            _id: "_design/questions",
-            language: "javascript",
-            validate_doc_update: function(newDoc, oldDoc, userCtx, secObj) {
-                if( newDoc._deleted || newDoc.type!=='Question' ){ return; }
-                if( !newDoc.code ){ throw({forbidden:'Question must have a code field.'});}
-            },
-            views: {
-                all: {
-                    map: function(doc){
-                        if ( doc.type !== 'Question' ) { return; }
-                        if ( doc.categories && doc.categories.length > 0 ) {
-                            for ( var i = 0; i < doc.categories.length; i++ ) { 
-                                emit([doc.categories[i],doc.topic||null],1);
-                            } 
-                        } else { 
-                            emit([null,null],1); 
-                        } 
-                    },
-                    reduce: function(keys,values){ return sum(values); }
-                },
-                published: {
-                    map: function(doc){
-                        if ( doc.type!=='Question' || !doc.publicationDate ) { return; }
-                        if ( doc.categories && doc.categories.length > 0 ) {
-                            for ( var i = 0; i < doc.categories.length; i++ ) {
-                                emit([doc.categories[i],doc.topic||null],1);
-                            }
-                        } else {
-                            emit([null,null],1);
-                        }
-                    },
-                    reduce: function(keys,values){ return sum(values); }
-                },
-                all_topics: {
-                    map: function(doc){
-                        if( doc.type !== 'Question' ){ return; }
-                        emit(doc.topic);
-                    }
-                },
-                published_topics: {
-                    map: function(doc){
-                        if ( doc.type !== 'Question' || !doc.publicationDate ) { return; }
-                        emit(doc.topic);
-                    }
-                }
-            }
-        },
-        "rft/_design/surveys": {
-            __configAction: "replace",
-            _id: "_design/surveys",
-            language: "javascript",
-            views: {
-                drafts: {
-                    map: function(doc){
-                        if ( doc.type !== 'Survey' || doc.publicationDate ) { return; }
-                        emit(doc._id,doc);
-                    }
-                },
-                published: {
-                    map: function(doc){
-                        if ( doc.type !== 'Survey' || !doc.publicationDate ) { return; }
-                        emit(doc._id,doc);
-                    }
-                }
-            }
-        }
-    };
-});
Index: Dev/branches/rest-dojo-ui/server/couchdb-admin/package.js
===================================================================
--- Dev/branches/rest-dojo-ui/client/config/package.js	(revision 411)
+++ 	(revision )
@@ -1,12 +1,0 @@
-var profile = (function(){
-    return {
-        resourceTags: {
-            amd: function (filename, mid) {
-                return /\.js$/.test(filename);
-            },
-            declarative: function(filename,mid) {
-                return /\.html$/.test(filename);
-            }
-        }
-    };
-})();
Index: Dev/branches/rest-dojo-ui/server/couchdb-admin/package.json
===================================================================
--- Dev/branches/rest-dojo-ui/client/config/package.json	(revision 411)
+++ 	(revision )
@@ -1,9 +1,0 @@
-{
-    "name": "config",
-    "description": "RFT CouchDB Configuration Tool",
-    "dependencies": {
-        "dojo": "~1.8.0",
-        "dijit": "~1.8.0"
-    },
-    "dojoBuild": "package.js"
-}
Index: Dev/branches/rest-dojo-ui/server/couchdb-admin/run.bat
===================================================================
--- Dev/branches/rest-dojo-ui/server/couchdb-admin/run.bat	(revision 415)
+++ Dev/branches/rest-dojo-ui/server/couchdb-admin/run.bat	(revision 415)
@@ -0,0 +1,1 @@
+nodejs bootstrap.js load=$1
Index: Dev/branches/rest-dojo-ui/server/couchdb-admin/run.sh
===================================================================
--- Dev/branches/rest-dojo-ui/server/couchdb-admin/run.sh	(revision 415)
+++ Dev/branches/rest-dojo-ui/server/couchdb-admin/run.sh	(revision 415)
@@ -0,0 +1,2 @@
+#!/bin/sh
+nodejs bootstrap.js load=$1
