geode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kl...@apache.org
Subject [16/32] geode git commit: GEODE-2950: Updated error messages
Date Wed, 31 May 2017 17:01:21 GMT
GEODE-2950: Updated error messages

	* Different error messages are displayed when validating region names versus indexes.
	* Added flexible enum allowing for expanded error messages and name validation.

	This closes #540


Project: http://git-wip-us.apache.org/repos/asf/geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/geode/commit/5ab4a693
Tree: http://git-wip-us.apache.org/repos/asf/geode/tree/5ab4a693
Diff: http://git-wip-us.apache.org/repos/asf/geode/diff/5ab4a693

Branch: refs/heads/feature/GEODE-1279
Commit: 5ab4a69378c697fdf050048165e2945a4b028eb7
Parents: 0fe0a10
Author: David Anuta <david.r.anuta@gmail.com>
Authored: Thu May 25 15:18:40 2017 -0700
Committer: nabarun <nnag@pivotal.io>
Committed: Thu May 25 16:14:30 2017 -0700

----------------------------------------------------------------------
 .../lucene/internal/LuceneServiceImpl.java      | 58 +++++++++++---------
 .../functions/LuceneCreateIndexFunction.java    |  7 ++-
 .../cli/LuceneIndexCommandsDUnitTest.java       | 10 ++--
 3 files changed, 43 insertions(+), 32 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/geode/blob/5ab4a693/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/LuceneServiceImpl.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/LuceneServiceImpl.java
b/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/LuceneServiceImpl.java
index c0d6266..23b6925 100644
--- a/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/LuceneServiceImpl.java
+++ b/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/LuceneServiceImpl.java
@@ -128,34 +128,42 @@ public class LuceneServiceImpl implements InternalLuceneService {
     return getUniqueIndexName(indexName, regionPath) + regionSuffix;
   }
 
-  public static void validateCreateIndexCommandParams(String name, boolean isRegionPath)
{
-    if (name == null) {
-      throw new IllegalArgumentException(
-          LocalizedStrings.LocalRegion_NAME_CANNOT_BE_NULL.toLocalizedString());
-    }
-    if (name.isEmpty()) {
-      throw new IllegalArgumentException(
-          LocalizedStrings.LocalRegion_NAME_CANNOT_BE_EMPTY.toLocalizedString());
-    }
+  public enum validateCommandParameters {
+    REGION_PATH, INDEX_NAME;
 
-    if (name.startsWith("__")) {
-      throw new IllegalArgumentException(
-          "Parameter names may not begin with a double-underscore: " + name);
-    }
+    public void validateName(String name) {
+      if (name == null) {
+        throw new IllegalArgumentException(
+            LocalizedStrings.LocalRegion_NAME_CANNOT_BE_NULL.toLocalizedString());
+      }
+      if (name.isEmpty()) {
+        throw new IllegalArgumentException(
+            LocalizedStrings.LocalRegion_NAME_CANNOT_BE_EMPTY.toLocalizedString());
+      }
 
-    final Pattern NAME_PATTERN;
-    if (isRegionPath) {
-      NAME_PATTERN = Pattern.compile("[aA-zZ0-9-_./]+");
-    } else {
-      NAME_PATTERN = Pattern.compile("[aA-zZ0-9-_.]+");
-    }
+      boolean iae = false;
+      String msg =
+          " names may only be alphanumeric, must not begin with double-underscores, but can
contain hyphens";
+      Matcher matcher = null;
+      switch (this) {
+        case REGION_PATH:
+          matcher = Pattern.compile("[aA-zZ0-9-_./]+").matcher(name);
+          msg = "Region" + msg + ", underscores, or forward slashes: ";
+          iae = name.startsWith("__") || !matcher.matches();
+          break;
+        case INDEX_NAME:
+          matcher = Pattern.compile("[aA-zZ0-9-_.]+").matcher(name);
+          msg = "Index" + msg + " or underscores: ";
+          iae = name.startsWith("__") || !matcher.matches();
+          break;
+        default:
+          throw new IllegalArgumentException("Illegal option for validateName function");
+      }
 
-    // Ensure the region only contains valid characters
-    Matcher matcher = NAME_PATTERN.matcher(name);
-    if (!matcher.matches()) {
-      throw new IllegalArgumentException(
-          "Parameter names may only be alphanumeric, though they can contain hyphens or underscores:
"
-              + name);
+      // Ensure the region only contains valid characters
+      if (iae) {
+        throw new IllegalArgumentException(msg + name);
+      }
     }
   }
 

http://git-wip-us.apache.org/repos/asf/geode/blob/5ab4a693/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/cli/functions/LuceneCreateIndexFunction.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/cli/functions/LuceneCreateIndexFunction.java
b/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/cli/functions/LuceneCreateIndexFunction.java
index 26ac0e2..d49f7f9 100644
--- a/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/cli/functions/LuceneCreateIndexFunction.java
+++ b/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/cli/functions/LuceneCreateIndexFunction.java
@@ -15,7 +15,8 @@
 
 package org.apache.geode.cache.lucene.internal.cli.functions;
 
-import static org.apache.geode.cache.lucene.internal.LuceneServiceImpl.validateCreateIndexCommandParams;
+import static org.apache.geode.cache.lucene.internal.LuceneServiceImpl.validateCommandParameters.INDEX_NAME;
+import static org.apache.geode.cache.lucene.internal.LuceneServiceImpl.validateCommandParameters.REGION_PATH;
 
 import org.apache.commons.lang.StringUtils;
 import org.apache.geode.cache.Cache;
@@ -67,7 +68,7 @@ public class LuceneCreateIndexFunction extends FunctionAdapter implements
Intern
       memberId = cache.getDistributedSystem().getDistributedMember().getId();
       LuceneService service = LuceneServiceProvider.get(cache);
 
-      validateCreateIndexCommandParams(indexInfo.getIndexName(), false);
+      INDEX_NAME.validateName(indexInfo.getIndexName());
 
       String[] fields = indexInfo.getSearchableFieldNames();
       String[] analyzerName = indexInfo.getFieldAnalyzers();
@@ -86,7 +87,7 @@ public class LuceneCreateIndexFunction extends FunctionAdapter implements
Intern
         }
       }
 
-      validateCreateIndexCommandParams(indexInfo.getRegionPath(), true);
+      REGION_PATH.validateName(indexInfo.getRegionPath());
       indexFactory.create(indexInfo.getIndexName(), indexInfo.getRegionPath());
 
       // TODO - update cluster configuration by returning a valid XmlEntity

http://git-wip-us.apache.org/repos/asf/geode/blob/5ab4a693/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/cli/LuceneIndexCommandsDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/cli/LuceneIndexCommandsDUnitTest.java
b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/cli/LuceneIndexCommandsDUnitTest.java
index 5e9c4f9..5cbe31c 100755
--- a/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/cli/LuceneIndexCommandsDUnitTest.java
+++ b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/cli/LuceneIndexCommandsDUnitTest.java
@@ -210,7 +210,8 @@ public class LuceneIndexCommandsDUnitTest extends CliCommandTestBase {
     csb.addOption(LuceneCliStrings.LUCENE_CREATE_INDEX__FIELD, "field1,field2,field3");
 
     String resultAsString = executeCommandAndLogResult(csb);
-    assertTrue(resultAsString.contains("Parameter names may not begin with a double-underscore:"));
+    assertTrue(resultAsString.contains(
+        "Region names may only be alphanumeric, must not begin with double-underscores, but
can contain hyphens, underscores, or forward slashes:"));
 
     csb = new CommandStringBuilder(LuceneCliStrings.LUCENE_CREATE_INDEX);
     csb.addOption(LuceneCliStrings.LUCENE__INDEX_NAME, INDEX_NAME);
@@ -219,7 +220,7 @@ public class LuceneIndexCommandsDUnitTest extends CliCommandTestBase {
 
     resultAsString = executeCommandAndLogResult(csb);
     assertTrue(resultAsString.contains(
-        "Parameter names may only be alphanumeric, though they can contain hyphens or underscores:"));
+        "Region names may only be alphanumeric, must not begin with double-underscores, but
can contain hyphens, underscores, or forward slashes:"));
 
     csb = new CommandStringBuilder(LuceneCliStrings.LUCENE_CREATE_INDEX);
     csb.addOption(LuceneCliStrings.LUCENE__INDEX_NAME, "\'__\'");
@@ -227,7 +228,8 @@ public class LuceneIndexCommandsDUnitTest extends CliCommandTestBase {
     csb.addOption(LuceneCliStrings.LUCENE_CREATE_INDEX__FIELD, "field1,field2,field3");
 
     resultAsString = executeCommandAndLogResult(csb);
-    assertTrue(resultAsString.contains("Parameter names may not begin with a double-underscore:"));
+    assertTrue(resultAsString.contains(
+        "Index names may only be alphanumeric, must not begin with double-underscores, but
can contain hyphens or underscores:"));
 
     csb = new CommandStringBuilder(LuceneCliStrings.LUCENE_CREATE_INDEX);
     csb.addOption(LuceneCliStrings.LUCENE__INDEX_NAME, "\' @@@*%\'");
@@ -236,7 +238,7 @@ public class LuceneIndexCommandsDUnitTest extends CliCommandTestBase {
 
     resultAsString = executeCommandAndLogResult(csb);
     assertTrue(resultAsString.contains(
-        "Parameter names may only be alphanumeric, though they can contain hyphens or underscores:"));
+        "Index names may only be alphanumeric, must not begin with double-underscores, but
can contain hyphens or underscores:"));
   }
 
   @Test


Mime
View raw message