[Groonga-commit] groonga/gcs [master] * Change name of place holders * Fill place holders in the API layer

Back to archive index

YUKI Hiroshi null+****@clear*****
Thu Nov 15 17:37:19 JST 2012


YUKI Hiroshi	2012-11-15 17:37:19 +0900 (Thu, 15 Nov 2012)

  New Revision: 27ce55f7685b1f8512c5cda2f2ed6b4971fc06ec
  https://github.com/groonga/gcs/commit/27ce55f7685b1f8512c5cda2f2ed6b4971fc06ec

  Log:
    * Change name of place holders * Fill place holders in the API layer

  Modified files:
    lib/api/2011-02-01/configuration.js
    lib/database/domain.js
    lib/database/index-field.js
    test/database-domain.test.js
    test/database-index-field.test.js

  Modified: lib/api/2011-02-01/configuration.js (+51 -22)
===================================================================
--- lib/api/2011-02-01/configuration.js    2012-11-15 17:22:38 +0900 (af8a5d8)
+++ lib/api/2011-02-01/configuration.js    2012-11-15 17:37:19 +0900 (7648db0)
@@ -9,6 +9,37 @@ var uuid = require('node-uuid');
 
 exports.version = path.basename(__dirname);
 
+function handleDomanValidationError(process, variables) {
+  try {
+    return process();
+  } catch(error) {
+    if (error.isValidationError) {
+      variables = variables || {
+                    NAME_FIELD: 'domainName'
+                  };
+      error.message = error.message.replace(/%NAME_FIELD%/g, variables.NAME_FIELD);
+      throw error;
+    }
+  }
+}
+
+function handleIndexFieldValidationError(process, variables) {
+  try {
+    return process();
+  } catch(error) {
+    if (error.isValidationError) {
+      variables = variables || {
+                    NAME_FIELD: 'indexField.indexFieldName',
+                    TYPE_FIELD: 'indexField.indexFieldType'
+                  };
+      error.message = error.message
+                        .replace(/%NAME_FIELD%/g, variables.NAME_FIELD)
+                        .replace(/%TYPE_FIELD%/g, variables.TYPE_FIELD);
+      throw error;
+    }
+  }
+}
+
 var XMLNS = 'http://cloudsearch.amazonaws.com/doc/2011-02-01';
 var PRETTY_PRINT_OPTIONS = {
       pretty: true
@@ -123,15 +154,9 @@ function createDomainStatus(options) {
 }
 
 handlers.CreateDomain = function(context, request, response, config) {
-  var domain;
-  try {
-    domain = new Domain(request.query.DomainName || '', context);
-  } catch(error) {
-    if (error.isValidationError) {
-      error.message = error.message.replace(/%VALIDATED_FIELD_NAME%/g, 'domainName');
-      throw error;
-    }
-  }
+  var domain = handleDomanValidationError(function() {
+        return new Domain(request.query.DomainName || '', context);
+      });
   if (!domain.exists())
     domain.createSync();
   var result = createDomainStatus({
@@ -144,15 +169,9 @@ handlers.CreateDomain = function(context, request, response, config) {
 };
 
 handlers.DeleteDomain = function(context, request, response, config) {
-  var domain;
-  try {
-    domain = new Domain(request.query.DomainName || '', context);
-  } catch(error) {
-    if (error.isValidationError) {
-      error.message = error.message.replace(/%VALIDATED_FIELD_NAME%/g, 'domainName');
-      throw error;
-    }
-  }
+  var domain = handleDomanValidationError(function() {
+        return new Domain(request.query.DomainName || '', context);
+      });
   var result;
   if (domain.exists()) {
     domain.deleteSync();
@@ -271,11 +290,15 @@ function getFieldOption(option, request, type) {
 }
 
 handlers.DefineIndexField = function(context, request, response, config) {
-  var domain = new Domain(request.query.DomainName, context);
+  var domain = handleDomanValidationError(function() {
+        return new Domain(request.query.DomainName || '', context);
+      });
 
   var fieldName = request.query['IndexField.IndexFieldName'] || '';
   var fieldType = request.query['IndexField.IndexFieldType'] || 'text';
-  var field = domain.getIndexField(fieldName);
+  var field = handleIndexFieldValidationError(function() {
+        return domain.getIndexField(fieldName);
+      });
 
   var createdAt = new Date();
 
@@ -309,10 +332,16 @@ handlers.DefineIndexField = function(context, request, response, config) {
 };
 
 handlers.DeleteIndexField = function(context, request, response, config) {
-  var domain = new Domain(request.query.DomainName, context);
+  var domain = handleDomanValidationError(function() {
+        return new Domain(request.query.DomainName || '', context);
+      });
 
   var fieldName = request.query['IndexFieldName'] || '';
-  var field = domain.getIndexField(fieldName);
+  var field = handleIndexFieldValidationError(function() {
+        return domain.getIndexField(fieldName);
+      }, {
+        NAME_FIELD: 'indexFieldName'
+      });
   field.deleteSync();
   response.contentType('application/xml');
   response.send(createGenericResponse('DeleteIndexField', null, request.id));

  Modified: lib/database/domain.js (+1 -1)
===================================================================
--- lib/database/domain.js    2012-11-15 17:22:38 +0900 (3e8af6c)
+++ lib/database/domain.js    2012-11-15 17:37:19 +0900 (e63f7dc)
@@ -61,7 +61,7 @@ function assertValidDomainName(domain) {
   }
 
   var errors = [];
-  var commonPrefix = 'Value \'' + domain + '\' at \'%VALIDATED_FIELD_NAME%\' failed ' +
+  var commonPrefix = 'Value \'' + domain + '\' at \'%NAME_FIELD%\' failed ' +
                      'to satisfy constraint: ';
 
   if (!domain.match(VALID_NAME_MATCHER)) {

  Modified: lib/database/index-field.js (+1 -1)
===================================================================
--- lib/database/index-field.js    2012-11-15 17:22:38 +0900 (bfe2213)
+++ lib/database/index-field.js    2012-11-15 17:37:19 +0900 (3b19cb5)
@@ -34,7 +34,7 @@ function assertValidFieldName(field) {
   }
 
   var errors = [];
-  var commonPrefix = 'Value \'' + field + '\' at \'%VALIDATED_FIELD_NAME%\' failed ' +
+  var commonPrefix = 'Value \'' + field + '\' at \'%NAME_FIELD%\' failed ' +
                      'to satisfy constraint: ';
 
   if (!field.match(VALID_NAME_MATCHER)) {

  Modified: test/database-domain.test.js (+11 -11)
===================================================================
--- test/database-domain.test.js    2012-11-15 17:22:38 +0900 (11e9a04)
+++ test/database-domain.test.js    2012-11-15 17:37:19 +0900 (f34b859)
@@ -41,10 +41,10 @@ suite('database', function() {
       assert.throw(function() {
         var domain = new Domain('');
       }, '2 validation errors detected: ' +
-           'Value \'\' at \'%VALIDATED_FIELD_NAME%\' failed to satisfy constraint: ' +
+           'Value \'\' at \'%NAME_FIELD%\' failed to satisfy constraint: ' +
              'Member must satisfy regular expression pattern: ' +
                Domain.VALID_NAME_PATTERN + '; ' +
-           'Value \'\' at \'%VALIDATED_FIELD_NAME%\' failed to satisfy constraint: ' +
+           'Value \'\' at \'%NAME_FIELD%\' failed to satisfy constraint: ' +
              'Member must have length greater than or equal to ' +
                Domain.MINIMUM_NAME_LENGTH);
     });
@@ -53,10 +53,10 @@ suite('database', function() {
       assert.throw(function() {
         var domain = new Domain('v');
       }, '2 validation errors detected: ' +
-           'Value \'v\' at \'%VALIDATED_FIELD_NAME%\' failed to satisfy constraint: ' +
+           'Value \'v\' at \'%NAME_FIELD%\' failed to satisfy constraint: ' +
              'Member must satisfy regular expression pattern: ' +
                Domain.VALID_NAME_PATTERN + '; ' +
-           'Value \'v\' at \'%VALIDATED_FIELD_NAME%\' failed to satisfy constraint: ' +
+           'Value \'v\' at \'%NAME_FIELD%\' failed to satisfy constraint: ' +
              'Member must have length greater than or equal to ' +
                Domain.MINIMUM_NAME_LENGTH);
     });
@@ -65,7 +65,7 @@ suite('database', function() {
       assert.throw(function() {
         var domain = new Domain('va');
       }, '1 validation error detected: ' +
-           'Value \'va\' at \'%VALIDATED_FIELD_NAME%\' failed to satisfy constraint: ' +
+           'Value \'va\' at \'%NAME_FIELD%\' failed to satisfy constraint: ' +
              'Member must have length greater than or equal to ' +
                Domain.MINIMUM_NAME_LENGTH);
     });
@@ -75,7 +75,7 @@ suite('database', function() {
       assert.throw(function() {
         var domain = new Domain(name);
       }, '1 validation error detected: ' +
-           'Value \'' + name + '\' at \'%VALIDATED_FIELD_NAME%\' failed to satisfy constraint: ' +
+           'Value \'' + name + '\' at \'%NAME_FIELD%\' failed to satisfy constraint: ' +
              'Member must have length less than or equal to ' +
                Domain.MAXIMUM_NAME_LENGTH);
     });
@@ -84,7 +84,7 @@ suite('database', function() {
       assert.throw(function() {
         var domain = new Domain('domain-name');
       }, '1 validation error detected: ' +
-           'Value \'domain_name\' at \'%VALIDATED_FIELD_NAME%\' failed to satisfy constraint: ' +
+           'Value \'domain_name\' at \'%NAME_FIELD%\' failed to satisfy constraint: ' +
              'Member cannot include these characters: \'-\'');
     });
 
@@ -92,7 +92,7 @@ suite('database', function() {
       assert.throw(function() {
         var domain = new Domain('domain_name');
       }, '1 validation error detected: ' +
-           'Value \'domain_name\' at \'%VALIDATED_FIELD_NAME%\' failed to satisfy constraint: ' +
+           'Value \'domain_name\' at \'%NAME_FIELD%\' failed to satisfy constraint: ' +
              'Member must satisfy regular expression pattern: ' +
                Domain.VALID_NAME_PATTERN);
     });
@@ -101,7 +101,7 @@ suite('database', function() {
       assert.throw(function() {
         var domain = new Domain('DomainName');
       }, '1 validation error detected: ' +
-           'Value \'%VALIDATED_FIELD_NAME%\' at \'%VALIDATED_FIELD_NAME%\' failed to satisfy constraint: ' +
+           'Value \'%NAME_FIELD%\' at \'%NAME_FIELD%\' failed to satisfy constraint: ' +
              'Member must satisfy regular expression pattern: ' +
                Domain.VALID_NAME_PATTERN);
     });
@@ -195,7 +195,7 @@ suite('database', function() {
           var request = { headers: { host: host } };
           var domain = new Domain(request);
         }, '1 validation error detected: ' +
-             'Value \'domain_name\' at \'%VALIDATED_FIELD_NAME%\' failed to satisfy constraint: ' +
+             'Value \'domain_name\' at \'%NAME_FIELD%\' failed to satisfy constraint: ' +
                'Member must satisfy regular expression pattern: ' +
                  Domain.VALID_NAME_PATTERN);
       });
@@ -216,7 +216,7 @@ suite('database', function() {
                         url: '/gcs/test_0123-id0123' };
           var domain = new Domain(request);
         }, '1 validation error detected: ' +
-             'Value \'domain_name\' at \'%VALIDATED_FIELD_NAME%\' failed to satisfy constraint: ' +
+             'Value \'domain_name\' at \'%NAME_FIELD%\' failed to satisfy constraint: ' +
                'Member must satisfy regular expression pattern: ' +
                  Domain.VALID_NAME_PATTERN);
       });

  Modified: test/database-index-field.test.js (+6 -6)
===================================================================
--- test/database-index-field.test.js    2012-11-15 17:22:38 +0900 (85f0acf)
+++ test/database-index-field.test.js    2012-11-15 17:37:19 +0900 (7908e2c)
@@ -45,10 +45,10 @@ suite('database', function() {
       assert.throw(function() {
         var field = new IndexField('v', domain);
       }, '2 validation errors detected: ' +
-           'Value \'v\' at \'%VALIDATED_FIELD_NAME%\' failed to satisfy constraint: ' +
+           'Value \'v\' at \'%NAME_FIELD%\' failed to satisfy constraint: ' +
              'Member must satisfy regular expression pattern: ' +
                IndexField.VALID_NAME_PATTERN + '; ' +
-           'Value \'v\' at \'%VALIDATED_FIELD_NAME%\' failed to satisfy constraint: ' +
+           'Value \'v\' at \'%NAME_FIELD%\' failed to satisfy constraint: ' +
              'Member must have length greater than or equal to ' +
                IndexField.MINIMUM_NAME_LENGTH);
     });
@@ -57,7 +57,7 @@ suite('database', function() {
       assert.throw(function() {
         var field = new IndexField('va', domain);
       }, '1 validation error detected: ' +
-           'Value \'va\' at \'%VALIDATED_FIELD_NAME%\' failed to satisfy constraint: ' +
+           'Value \'va\' at \'%NAME_FIELD%\' failed to satisfy constraint: ' +
              'Member must have length greater than or equal to ' +
                IndexField.MINIMUM_NAME_LENGTH);
     });
@@ -67,7 +67,7 @@ suite('database', function() {
       assert.throw(function() {
         var field = new IndexField(name, domain);
       }, '1 validation error detected: ' +
-           'Value \'' + name + '\' at \'%VALIDATED_FIELD_NAME%\' failed to satisfy constraint: ' +
+           'Value \'' + name + '\' at \'%NAME_FIELD%\' failed to satisfy constraint: ' +
              'Member must have length less than or equal to ' +
                IndexField.MAXIMUM_NAME_LENGTH);
     });
@@ -76,7 +76,7 @@ suite('database', function() {
       assert.throw(function() {
         var field = new IndexField('field-name', domain);
       }, '1 validation error detected: ' +
-           'Value \'field-name\' at \'%VALIDATED_FIELD_NAME%\' failed to satisfy constraint: ' +
+           'Value \'field-name\' at \'%NAME_FIELD%\' failed to satisfy constraint: ' +
              'Member cannot include these characters: \'-\'');
     });
 
@@ -89,7 +89,7 @@ suite('database', function() {
       assert.throw(function() {
         var field = new IndexField('FieldName');
       }, '1 validation error detected: ' +
-           'Value \'FieldName\' at \'%VALIDATED_FIELD_NAME%\' failed to satisfy constraint: ' +
+           'Value \'FieldName\' at \'%NAME_FIELD%\' failed to satisfy constraint: ' +
              'Member must satisfy regular expression pattern: ' +
                IndexField.VALID_NAME_PATTERN);
     });
-------------- next part --------------
HTML����������������������������...
Download 



More information about the Groonga-commit mailing list
Back to archive index