Commit e48a4864 by apoorvnaik

ATLAS-2685: Impose displayName restrictions for Glossary, term and category.

Change-Id: I4cddcfe76eabcf7ee705b60848521158bb33a8a5
parent 2ff71e30
...@@ -146,6 +146,7 @@ public enum AtlasErrorCode { ...@@ -146,6 +146,7 @@ public enum AtlasErrorCode {
INVALID_TERM_DISSOCIATION(400, "ATLAS-400-00-080", "Given term (guid={0}) is not associated to entity(guid={1})"), INVALID_TERM_DISSOCIATION(400, "ATLAS-400-00-080", "Given term (guid={0}) is not associated to entity(guid={1})"),
ATTRIBUTE_TYPE_INVALID(400, "ATLAS-400-00-081", "{0}.{1}: invalid attribute type. Attribute cannot be of type classification"), ATTRIBUTE_TYPE_INVALID(400, "ATLAS-400-00-081", "{0}.{1}: invalid attribute type. Attribute cannot be of type classification"),
MISSING_CATEGORY_DISPLAY_NAME(400, "ATLAS-400-00-082", "Category displayName is empty/null"), MISSING_CATEGORY_DISPLAY_NAME(400, "ATLAS-400-00-082", "Category displayName is empty/null"),
INVALID_DISPLAY_NAME(400, "ATLAS-400-00-083", "displayName cannot contain following special chars ('@', '.')"),
TERM_HAS_ENTITY_ASSOCIATION(400, "ATLAS-400-00-086", "Term (guid={}) can't be deleted as it has been assigned to {} entities."), TERM_HAS_ENTITY_ASSOCIATION(400, "ATLAS-400-00-086", "Term (guid={}) can't be deleted as it has been assigned to {} entities."),
UNAUTHORIZED_ACCESS(403, "ATLAS-403-00-001", "{0} is not authorized to perform {1}"), UNAUTHORIZED_ACCESS(403, "ATLAS-403-00-001", "{0} is not authorized to perform {1}"),
......
...@@ -66,6 +66,8 @@ public class GlossaryService { ...@@ -66,6 +66,8 @@ public class GlossaryService {
private final GlossaryCategoryUtils glossaryCategoryUtils; private final GlossaryCategoryUtils glossaryCategoryUtils;
private final AtlasTypeRegistry atlasTypeRegistry; private final AtlasTypeRegistry atlasTypeRegistry;
private final char[] invalidNameChars = {'@', '.'};
@Inject @Inject
public GlossaryService(DataAccess dataAccess, final AtlasRelationshipStore relationshipStore, final AtlasTypeRegistry typeRegistry) { public GlossaryService(DataAccess dataAccess, final AtlasRelationshipStore relationshipStore, final AtlasTypeRegistry typeRegistry) {
this.dataAccess = dataAccess; this.dataAccess = dataAccess;
...@@ -134,6 +136,8 @@ public class GlossaryService { ...@@ -134,6 +136,8 @@ public class GlossaryService {
if (StringUtils.isEmpty(atlasGlossary.getQualifiedName())) { if (StringUtils.isEmpty(atlasGlossary.getQualifiedName())) {
if (StringUtils.isEmpty(atlasGlossary.getDisplayName())) { if (StringUtils.isEmpty(atlasGlossary.getDisplayName())) {
throw new AtlasBaseException(AtlasErrorCode.GLOSSARY_QUALIFIED_NAME_CANT_BE_DERIVED); throw new AtlasBaseException(AtlasErrorCode.GLOSSARY_QUALIFIED_NAME_CANT_BE_DERIVED);
} else if (isNameInvalid(atlasGlossary.getDisplayName())){
throw new AtlasBaseException(AtlasErrorCode.INVALID_DISPLAY_NAME);
} else { } else {
atlasGlossary.setQualifiedName(atlasGlossary.getDisplayName()); atlasGlossary.setQualifiedName(atlasGlossary.getDisplayName());
} }
...@@ -242,6 +246,10 @@ public class GlossaryService { ...@@ -242,6 +246,10 @@ public class GlossaryService {
throw new AtlasBaseException(AtlasErrorCode.BAD_REQUEST, "DisplayName can't be null/empty"); throw new AtlasBaseException(AtlasErrorCode.BAD_REQUEST, "DisplayName can't be null/empty");
} }
if (isNameInvalid(atlasGlossary.getDisplayName())) {
throw new AtlasBaseException(AtlasErrorCode.INVALID_DISPLAY_NAME);
}
AtlasGlossary storeObject = dataAccess.load(atlasGlossary); AtlasGlossary storeObject = dataAccess.load(atlasGlossary);
if (!storeObject.equals(atlasGlossary)) { if (!storeObject.equals(atlasGlossary)) {
...@@ -321,6 +329,9 @@ public class GlossaryService { ...@@ -321,6 +329,9 @@ public class GlossaryService {
if (StringUtils.isEmpty(glossaryTerm.getDisplayName())) { if (StringUtils.isEmpty(glossaryTerm.getDisplayName())) {
throw new AtlasBaseException(AtlasErrorCode.GLOSSARY_TERM_QUALIFIED_NAME_CANT_BE_DERIVED); throw new AtlasBaseException(AtlasErrorCode.GLOSSARY_TERM_QUALIFIED_NAME_CANT_BE_DERIVED);
} }
if (isNameInvalid(glossaryTerm.getDisplayName())) {
throw new AtlasBaseException(AtlasErrorCode.INVALID_DISPLAY_NAME);
}
// This might fail for the case when the term's qualifiedName has been updated and the duplicate request comes in with old name // This might fail for the case when the term's qualifiedName has been updated and the duplicate request comes in with old name
if (termExists(glossaryTerm)) { if (termExists(glossaryTerm)) {
...@@ -377,6 +388,10 @@ public class GlossaryService { ...@@ -377,6 +388,10 @@ public class GlossaryService {
throw new AtlasBaseException(AtlasErrorCode.BAD_REQUEST, "DisplayName can't be null/empty"); throw new AtlasBaseException(AtlasErrorCode.BAD_REQUEST, "DisplayName can't be null/empty");
} }
if (isNameInvalid(atlasGlossaryTerm.getDisplayName())) {
throw new AtlasBaseException(AtlasErrorCode.INVALID_DISPLAY_NAME);
}
AtlasGlossaryTerm storeObject = dataAccess.load(atlasGlossaryTerm); AtlasGlossaryTerm storeObject = dataAccess.load(atlasGlossaryTerm);
if (!storeObject.equals(atlasGlossaryTerm)) { if (!storeObject.equals(atlasGlossaryTerm)) {
try { try {
...@@ -495,6 +510,10 @@ public class GlossaryService { ...@@ -495,6 +510,10 @@ public class GlossaryService {
if (Objects.isNull(glossaryCategory.getDisplayName())) { if (Objects.isNull(glossaryCategory.getDisplayName())) {
throw new AtlasBaseException(AtlasErrorCode.MISSING_CATEGORY_DISPLAY_NAME); throw new AtlasBaseException(AtlasErrorCode.MISSING_CATEGORY_DISPLAY_NAME);
} }
if (isNameInvalid(glossaryCategory.getDisplayName())) {
throw new AtlasBaseException(AtlasErrorCode.INVALID_DISPLAY_NAME);
}
// This might fail for the case when the category's qualifiedName has been updated during a hierarchy change // This might fail for the case when the category's qualifiedName has been updated during a hierarchy change
// and the duplicate request comes in with old name // and the duplicate request comes in with old name
...@@ -561,6 +580,10 @@ public class GlossaryService { ...@@ -561,6 +580,10 @@ public class GlossaryService {
throw new AtlasBaseException(AtlasErrorCode.BAD_REQUEST, "DisplayName can't be null/empty"); throw new AtlasBaseException(AtlasErrorCode.BAD_REQUEST, "DisplayName can't be null/empty");
} }
if (isNameInvalid(glossaryCategory.getDisplayName())) {
throw new AtlasBaseException(AtlasErrorCode.INVALID_DISPLAY_NAME);
}
AtlasGlossaryCategory storeObject = dataAccess.load(glossaryCategory); AtlasGlossaryCategory storeObject = dataAccess.load(glossaryCategory);
if (!storeObject.equals(glossaryCategory)) { if (!storeObject.equals(glossaryCategory)) {
...@@ -952,6 +975,10 @@ public class GlossaryService { ...@@ -952,6 +975,10 @@ public class GlossaryService {
termHeaders.forEach(t -> t.setDisplayText(termMap.get(t.getTermGuid()).getDisplayName())); termHeaders.forEach(t -> t.setDisplayText(termMap.get(t.getTermGuid()).getDisplayName()));
} }
private boolean isNameInvalid(String name) {
return StringUtils.containsAny(name, invalidNameChars);
}
static class PaginationHelper<T> { static class PaginationHelper<T> {
private int pageStart; private int pageStart;
private int pageEnd; private int pageEnd;
......
...@@ -164,7 +164,7 @@ public class GlossaryServiceTest { ...@@ -164,7 +164,7 @@ public class GlossaryServiceTest {
fixedRateMortgage = new AtlasGlossaryTerm(); fixedRateMortgage = new AtlasGlossaryTerm();
fixedRateMortgage.setQualifiedName("fixed_mtg@testBankingGlossary"); fixedRateMortgage.setQualifiedName("fixed_mtg@testBankingGlossary");
fixedRateMortgage.setDisplayName("15/30 yr mortgage"); fixedRateMortgage.setDisplayName("Conventional mortgage");
fixedRateMortgage.setShortDescription("Short description"); fixedRateMortgage.setShortDescription("Short description");
fixedRateMortgage.setLongDescription("Long description"); fixedRateMortgage.setLongDescription("Long description");
fixedRateMortgage.setAbbreviation("FMTG"); fixedRateMortgage.setAbbreviation("FMTG");
......
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