Commit e21f569f by Yu-Hsin Shih Committed by Sarath Subramanian

ATLAS-2901: Change classification name rule - Support multiple languages (unicode)

parent 64c7a3be
......@@ -52,7 +52,7 @@ public enum AtlasErrorCode {
PATCH_NOT_APPLICABLE_FOR_TYPE(400, "ATLAS-400-00-016", "{0} - invalid patch for type {1}"),
PATCH_FOR_UNKNOWN_TYPE(400, "ATLAS-400-00-017", "{0} - patch references unknown type {1}"),
PATCH_INVALID_DATA(400, "ATLAS-400-00-018", "{0} - patch data is invalid for type {1}"),
TYPE_NAME_INVALID_FORMAT(400, "ATLAS-400-00-019", "{0}: invalid name for {1}. Names must consist of a letter followed by a sequence of letter, number, or '_' characters"),
TYPE_NAME_INVALID_FORMAT(400, "ATLAS-400-00-019", "{0}: invalid name for {1}. Names must consist of a letter followed by a sequence of letter, number, space, or '_' characters"),
ATTRIBUTE_NAME_INVALID(400, "ATLAS-400-00-020", "{0}: invalid name. Attribute name must not contain query keywords"),
INVALID_PARAMETERS(400, "ATLAS-400-00-01A", "invalid parameters: {0}"),
CLASSIFICATION_ALREADY_ASSOCIATED(400, "ATLAS-400-00-01B", "instance {0} already is associated with classification {1}"),
......
......@@ -48,7 +48,7 @@ import static org.apache.atlas.repository.Constants.TYPENAME_PROPERTY_KEY;
class AtlasClassificationDefStoreV2 extends AtlasAbstractDefStoreV2<AtlasClassificationDef> {
private static final Logger LOG = LoggerFactory.getLogger(AtlasClassificationDefStoreV2.class);
private static final String TRAIT_NAME_REGEX = "[a-zA-Z][a-zA-Z0-9_ .]*";
private static final String TRAIT_NAME_REGEX = "[a-zA-Z[^\\p{ASCII}]][a-zA-Z0-9[^\\p{ASCII}]_ .]*";
private static final Pattern TRAIT_NAME_PATTERN = Pattern.compile(TRAIT_NAME_REGEX);
......
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.atlas.repository.store.graph.v2;
import static org.testng.Assert.assertEquals;
import com.google.inject.Inject;
import org.apache.atlas.TestModules;
import org.apache.atlas.type.AtlasTypeRegistry;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Guice;
import org.testng.annotations.Test;
/**
* Tests for AtlasClassificationDefStoreV2
*/
@Guice(modules = TestModules.TestOnlyModule.class)
public class AtlasClassificationDefStoreV2Test {
private AtlasClassificationDefStoreV2 classificationDefStore;
@Inject
AtlasTypeRegistry atlasTypeRegistry;
@Inject
AtlasTypeDefGraphStoreV2 typeDefStore;
@BeforeClass
public void setUp() {
classificationDefStore = new AtlasClassificationDefStoreV2(typeDefStore, atlasTypeRegistry);
}
@DataProvider
public Object[][] traitRegexString() {
// Test unicode regex for classification
return new Object[][] {
{"test1", true},
{"\u597D", true},
{"\u597D\u597D", true},
{"\u597D \u597D", true},
{"\u597D_\u597D", true},
{"\u597D.\u597D", true},
{"class1.attr1", true},
{"1test", false},
{"_test1", false},
};
}
@Test(dataProvider = "traitRegexString")
public void testIsValidName(String data, boolean expected) {
assertEquals(classificationDefStore.isValidName(data), expected);
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment