OSDN Git Service

[Develop and Test] toExecArray() v0.3.0p0040
authorhimetani_cafe <fumifumi@yasunaga-lab.bio.kyutech.ac.jp>
Mon, 8 Feb 2016 01:13:05 +0000 (10:13 +0900)
committerhimetani_cafe <fumifumi@yasunaga-lab.bio.kyutech.ac.jp>
Mon, 8 Feb 2016 01:13:05 +0000 (10:13 +0900)
modified:   server/class/Eos.js
modified:   test/mocha/Eos.test.js

server/class/Eos.js
test/mocha/Eos.test.js

index f1857d2..03519b2 100644 (file)
@@ -235,6 +235,61 @@ function toExecString(command, options, workspaceId) {
     return execStr;
 }
 
+/**
+ * toExecArray
+ *
+ * @param {fileId} 
+ * @returns {string}
+ */
+function toExecArray(command, options, workspaceId) {
+    return new Promise(function(resolve, reject) {
+        var ocf = ocfReference[command]; // Array
+        var finalOptions = {};
+        var ocfObj = {};
+        ocf.forEach(function(o) {
+            ocfObj[o.option] = o;
+        });
+
+        // set default parameters
+        ocf.forEach(function(o) {
+            o.arg.forEach(function(arg) {
+                if(!(arg.initialValue === "") && arg.initialValue) {
+                    if(!(finalOptions[o.option])) {
+                        finalOptions[o.option] = [];
+                        finalOptions[o.option].push(arg.initialValue);
+                    } else {
+                        finalOptions[o.option].push(arg.initialValue);
+                    }
+                }
+            });
+        });
+
+        getUUIDs(workspaceId)
+        .then(function(uuids) {
+            // set user setting parameters
+            options.forEach(function(o) {
+                var s = [];
+                var outRegExp = /out|append/;
+                o.arguments.forEach(function(arg, i) {
+                    if(ocfObj[o.name].arg[i].formType === 'select') {
+                        s.push(uuids[arg]);
+                    } else {
+                        s.push(arg);
+                    }
+                });
+                finalOptions[o.name] = s;
+            });
+            var array = Object.keys(finalOptions).reduce(function(a,b) {
+                a.push(b);
+                finalOptions[b].forEach(function(v) {
+                    a.push(v);
+                });
+                return a;
+            },[]);
+            resolve(array);
+        });
+    });
+}
 
 /**
  * execute
@@ -299,7 +354,8 @@ var eos = {
     toExecString: toExecString,
     execute: execute,
     getFiles: getFiles,
-    getUUIDs: getUUIDs
+    getUUIDs: getUUIDs,
+    toExecArray: toExecArray
 }
 
 module.exports = { instance: eos };
index 16e2843..e189015 100644 (file)
 
         });
 
+        var test2 = `
+        /**
+        * 実行時文字列への変換 
+        *
+        * @param command
+        * @param options
+        * @returns {string}
+        * function toExecString(command, params) {
+        */
+        `;
+
         describe(test2, function() {
             it('should return true when all options is proper.', function() {
                 var result = eos.toExecString('dcdFilePrint', [{name: '-r', arguments: [1,2,3]}, { name: '-i', arguments: ['file1.txt']}, { name: '-o', arguments: ['file3.txt']} ], "1f83f620-c1ed-11e5-9657-7942989daa00");
             });
         });
 
-        var test2 = `
+        var toExecArray = `
         /**
-        * 実行時文字列への変換 
+        * 実行時列への変換 
         *
         * @param command
-        * @param options
         * @returns {string}
         * function toExecString(command, params) {
         */
         `;
 
+        describe(toExecArray, function() {
+            before(function() {
+                process.env.NODE_ENV = '';
+                return db.init()
+                .then(function() {
+                    return Promise.all([db.test1(), db.test2(), db.testRest()])
+                });
+            });
+
+            it('should be resolved with length 4', function() {
+                var command = testCommand.command;
+                var options = testCommand.options;
+                var workspace = testCommand.workspace;
+                return eos.toExecArray(command, options, '1f83f620-c1ed-11e5-9657-7942989daa00').should.be.eventually.length(16);
+            });
+
+        });
         
         describe('execute', function() {
             before(function() {