[Groonga-commit] groonga/gcs [master] Support XML SDF batches by gcs-post-sdf and gcs-configure-from-sdf

アーカイブの一覧に戻る

YUKI Hiroshi null+****@clear*****
Mon Dec 10 18:51:36 JST 2012


YUKI Hiroshi	2012-12-10 18:51:36 +0900 (Mon, 10 Dec 2012)

  New Revision: 9b2f65404995dccb42d9461497cfc280b8358d57
  https://github.com/groonga/gcs/commit/9b2f65404995dccb42d9461497cfc280b8358d57

  Log:
    Support XML SDF batches by gcs-post-sdf and gcs-configure-from-sdf

  Modified files:
    bin/gcs-configure-from-sdf
    bin/gcs-post-sdf
    test/gcs-commands.test.js

  Modified: bin/gcs-configure-from-sdf (+6 -4)
===================================================================
--- bin/gcs-configure-from-sdf    2012-12-10 18:45:11 +0900 (42f7a6d)
+++ bin/gcs-configure-from-sdf    2012-12-10 18:51:36 +0900 (e78dde7)
@@ -2,6 +2,7 @@
 
 var CLI = require(__dirname + '/../lib/command-line').CommandLineInterface;
 var Client = require(__dirname + '/../lib/client').Client;
+var xml = require(__dirname + '/../lib/batch/xml');
 var fs = require('fs');
 var path = require('path');
 
@@ -47,7 +48,11 @@ function listExistingFields(callback) {
 
 function collectFieldConfigurations(sourceFile, existingFieldNames) {
   var batches = fs.readFileSync(sourceFile, 'UTF-8');
-  batches = JSON.parse(batches);
+
+  if (/\.xml$/i.test(sourceFile))
+    batches = xml.toJSON(batches);
+  else
+    batches = JSON.parse(batches);
 
   var fields = {};
   batches.forEach(function(batch) {
@@ -178,9 +183,6 @@ client.getDomainStatus(function(error, domain) {
   format = format[1].toLowerCase();
   console.log('Detected source format for %s as %s', path.basename(sourceFile), format)
 
-  if (format != 'json')
-    client.raiseFatalError('Unsupported format: %s');
-
   console.log('Analyzing %s', sourceFile);
 
   var separator = '-----------------------------------------------------------------------------------';

  Modified: bin/gcs-post-sdf (+3 -3)
===================================================================
--- bin/gcs-post-sdf    2012-12-10 18:45:11 +0900 (792620a)
+++ bin/gcs-post-sdf    2012-12-10 18:51:36 +0900 (32e4e27)
@@ -2,6 +2,7 @@
 
 var CLI = require(__dirname + '/../lib/command-line').CommandLineInterface;
 var Client = require(__dirname + '/../lib/client').Client;
+var xml = require(__dirname + '/../lib/batch/xml');
 var fs = require('fs');
 var path = require('path');
 
@@ -42,11 +43,10 @@ client.assertDomainExists(function() {
   format = format[1].toLowerCase();
   console.log('Detected source format for %s as %s', path.basename(sourceFile), format)
 
-  if (format != 'json')
-    client.raiseFatalError('Unsupported format: %s');
-
   try {
     var batches = fs.readFileSync(sourceFile, 'UTF-8');
+    if (format == 'xml')
+      batches = xml.toJSON(batches);
 
     client.setupDocumentsAPI(function(documentsAPI) {
       documentsAPI.DocumentsBatch(

  Modified: test/gcs-commands.test.js (+49 -0)
===================================================================
--- test/gcs-commands.test.js    2012-12-10 18:45:11 +0900 (9327d48)
+++ test/gcs-commands.test.js    2012-12-10 18:51:36 +0900 (0fdf568)
@@ -575,6 +575,27 @@ suite('gcs-configure-from-sdf', function() {
       });
   });
 
+  test('create new, xml', function(done) {
+    var batchFile = path.join(fixturesDirectory, 'add.sdf.xml');
+    new Domain({ name: 'companies', context: context }).createSync();
+    utils
+      .run('gcs-configure-from-sdf',
+           '--domain-name', 'companies',
+           '--source', batchFile,
+           '--force',
+           '--endpoint', 'localhost:' + utils.testPort)
+      .next(function(result) {
+        assert.equal(0, result.code);
+        var domain = new Domain({ name: 'companies', context: context });
+        assertFieldsExist(domain,
+                          ['name', 'address', 'email_address', 'age', 'product']);
+        done();
+      })
+      .error(function(e) {
+        done(e);
+      });
+  });
+
   test('update (failed)', function(done) {
     new Domain({ name: 'companies', context: context }).createSync();
     utils
@@ -1032,6 +1053,34 @@ suite('gcs-post-sdf', function() {
       });
   });
 
+  test('post add sdf xml', function(done) {
+    setupDomain();
+    var batchFile = path.join(fixturesDirectory, 'add.sdf.xml');
+    utils
+      .run('gcs-post-sdf',
+           '--domain-name', 'companies',
+           '--source', batchFile,
+           '--document-endpoint', endpoint,
+           '--endpoint', 'localhost:' + utils.testPort)
+      .next(function(result) {
+        assert.deepEqual({ code:    result.code,
+                           message: result.output.stdout },
+                         { code:    0,
+                           message:
+                             'Processing: ' + batchFile + '\n' +
+                             'Detected source format for ' +
+                               'add.sdf.xml as xml\n' +
+                             'Status: success\n' +
+                             'Added: 10\n' +
+                             'Deleted: 0\n' },
+                         result.output.stderr);
+        done();
+      })
+      .error(function(e) {
+        done(e);
+      });
+  });
+
   test('post delete sdf json', function(done) {
     setupDomain();
     var addBatch = fs.readFileSync(path.join(fixturesDirectory, 'add.sdf.json'), 'UTF-8');
-------------- next part --------------
HTML����������������������������...
ダウンロード 



More information about the Groonga-commit mailing list
アーカイブの一覧に戻る