Commit d8d9b127 by apoorvnaik

Glossary Bugfixes for ATLAS-2612, ATLAS-2613, ATLAS-2614, ATLAS-2616,…

Glossary Bugfixes for ATLAS-2612, ATLAS-2613, ATLAS-2614, ATLAS-2616, ATLAS-2625, ATLAS-2626, ATLAS-2627, ATLAS-2628, ATLAS-2629 Change-Id: I5452ee90584b077d58b9fc24392b02f54d8c5ce1
parent db0f6766
......@@ -131,14 +131,16 @@ public enum AtlasErrorCode {
INVALID_BLOCKED_PROPAGATED_CLASSIFICATION(400, "ATLAS-400-00-071", "Invalid propagated classification: {0} with entityGuid: {1} added to blocked propagated classifications."),
MISSING_MANDATORY_ANCHOR(400, "ATLAS-400-00-072", "Mandatory anchor attribute is missing"),
MISSING_MANDATORY_QUALIFIED_NAME(400, "ATLAS-400-00-073", "Mandatory qualifiedName attribute is missing"),
INVALID_PARTIAL_UPDATE_ATTR_VAL(400, "ATLAS-400-00-074", "Invalid attrVal for partial update of {0}, expected = {1} found {2}"),
MISSING_TERM_ID_FOR_CATEGORIZATION(400, "ATLAS-400-00-075", "Term guid can't be empty/null when adding to a category"),
INVALID_NEW_ANCHOR_GUID(400, "ATLAS-400-00-076", "New Anchor guid can't be empty/null"),
TERM_DISSOCIATION_MISSING_RELATION_GUID(400, "ATLAS-400-00-077", "Missing mandatory attribute, TermAssignment relationship guid"),
GLOSSARY_QUALIFIED_NAME_CANT_BE_DERIVED(400, "ATLAS-400-00-078", "Attributes qualifiedName and displayName are missing. Failed to derive a unique name for Glossary"),
GLOSSARY_TERM_QUALIFIED_NAME_CANT_BE_DERIVED(400, "ATLAS-400-00-079", "Attributes qualifiedName, displayName & glossary name are missing. Failed to derive a unique name for Glossary term"),
GLOSSARY_CATEGORY_QUALIFIED_NAME_CANT_BE_DERIVED(400, "ATLAS-400-00-07A", "Attributes qualifiedName, displayName & glossary name are missing. Failed to derive a unique name for Glossary category"),
UNKNOWN_GLOSSARY_TERM(400, "ATLAS-400-00-07B", "{0}: Unknown/invalid glossary term"),
INVALID_PARTIAL_UPDATE_ATTR(400, "ATLAS-400-00-074", "Invalid attribute {0} for partial update of {1}"),
INVALID_PARTIAL_UPDATE_ATTR_VAL(400, "ATLAS-400-00-075", "Invalid attrVal for partial update of {0}, expected = {1} found {2}"),
MISSING_TERM_ID_FOR_CATEGORIZATION(400, "ATLAS-400-00-076", "Term guid can't be empty/null when adding to a category"),
INVALID_NEW_ANCHOR_GUID(400, "ATLAS-400-00-077", "New Anchor guid can't be empty/null"),
TERM_DISSOCIATION_MISSING_RELATION_GUID(400, "ATLAS-400-00-078", "Missing mandatory attribute, TermAssignment relationship guid"),
GLOSSARY_QUALIFIED_NAME_CANT_BE_DERIVED(400, "ATLAS-400-00-079", "Attributes qualifiedName and displayName are missing. Failed to derive a unique name for Glossary"),
GLOSSARY_TERM_QUALIFIED_NAME_CANT_BE_DERIVED(400, "ATLAS-400-00-07A", "Attributes qualifiedName, displayName & glossary name are missing. Failed to derive a unique name for Glossary term"),
GLOSSARY_CATEGORY_QUALIFIED_NAME_CANT_BE_DERIVED(400, "ATLAS-400-00-07B", "Attributes qualifiedName, displayName & glossary name are missing. Failed to derive a unique name for Glossary category"),
UNKNOWN_GLOSSARY_TERM(400, "ATLAS-400-00-07C", "{0}: Unknown/invalid glossary term"),
RELATIONSHIP_END_IS_NULL(400, "ATLAS-400-00-07D", "Relationship end is invalid. Expected {0} but is NULL"),
UNAUTHORIZED_ACCESS(403, "ATLAS-403-00-001", "{0} is not authorized to perform {1}"),
......
......@@ -17,18 +17,29 @@
*/
package org.apache.atlas.model;
import com.fasterxml.jackson.annotation.JsonIgnore;
import org.apache.atlas.model.annotation.AtlasJSON;
import java.io.Serializable;
import java.util.Objects;
import java.util.concurrent.atomic.AtomicLong;
@AtlasJSON
public abstract class AtlasBaseModelObject implements Serializable {
private static final long serialVersionUID = 1L;
@JsonIgnore
private static AtomicLong s_nextId = new AtomicLong(System.nanoTime());
private String guid;
protected AtlasBaseModelObject() {}
protected void init() {
setGuid("-" + Long.toString(s_nextId.incrementAndGet()));
}
protected AtlasBaseModelObject() {
init();
}
public String getGuid() {
return this.guid;
......@@ -38,9 +49,14 @@ public abstract class AtlasBaseModelObject implements Serializable {
this.guid = guid;
}
public AtlasBaseModelObject(final AtlasBaseModelObject other) {
this.guid = other.guid;
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append(this.getClass().getSimpleName());
sb.append("{");
sb.append("guid=").append(guid);
toString(sb);
......
......@@ -31,8 +31,8 @@ import java.util.Set;
@AtlasJSON
public class AtlasGlossary extends AtlasGlossaryBaseObject {
private String language;
private String usage;
private String language;
private String usage;
private Set<AtlasRelatedTermHeader> terms;
private Set<AtlasRelatedCategoryHeader> categories;
......@@ -41,6 +41,7 @@ public class AtlasGlossary extends AtlasGlossaryBaseObject {
}
public AtlasGlossary(final AtlasGlossary other) {
super(other);
super.setQualifiedName(other.getQualifiedName());
super.setGuid(other.getGuid());
super.setDisplayName(other.displayName);
......@@ -145,9 +146,33 @@ public class AtlasGlossary extends AtlasGlossaryBaseObject {
@Override
protected StringBuilder toString(final StringBuilder sb) {
return sb == null ? new StringBuilder(toString()) : sb.append(toString());
sb.append("{");
sb.append("language='").append(language).append('\'');
sb.append(", usage='").append(usage).append('\'');
sb.append(", terms=").append(terms);
sb.append(", categories=").append(categories);
sb.append('}');
return sb;
}
@Override
public boolean equals(final Object o) {
if (this == o) return true;
if (!(o instanceof AtlasGlossary)) return false;
if (!super.equals(o)) return false;
final AtlasGlossary glossary = (AtlasGlossary) o;
return Objects.equals(language, glossary.language) &&
Objects.equals(usage, glossary.usage) &&
Objects.equals(terms, glossary.terms) &&
Objects.equals(categories, glossary.categories);
}
@Override
public int hashCode() {
return Objects.hash(super.hashCode(), language, usage, terms, categories);
}
@AtlasJSON
public static class AtlasGlossaryExtInfo extends AtlasGlossary {
......@@ -208,13 +233,14 @@ public class AtlasGlossary extends AtlasGlossaryBaseObject {
}
@Override
public String toString() {
final StringBuilder sb = new StringBuilder("AtlasGlossaryExtInfo{");
sb.append(super.toString());
public StringBuilder toString(StringBuilder sb) {
sb.append("{");
super.toString(sb);
sb.append(", termInfo=").append(termInfo);
sb.append(", categoryInfo=").append(categoryInfo);
sb.append('}');
return sb.toString();
return sb;
}
......
......@@ -27,15 +27,28 @@ import java.util.List;
import java.util.Objects;
public abstract class AtlasGlossaryBaseObject extends AtlasBaseModelObject {
// Core attributes
protected String displayName;
protected String shortDescription;
protected String longDescription;
protected String displayName;
protected String shortDescription;
protected String longDescription;
// Classifications
protected List<AtlasClassification> classifications;
private String qualifiedName;
public AtlasGlossaryBaseObject() {
}
public AtlasGlossaryBaseObject(final AtlasGlossaryBaseObject other) {
super(other);
this.displayName = other.displayName;
this.shortDescription = other.shortDescription;
this.longDescription = other.longDescription;
this.classifications = other.classifications;
this.qualifiedName = other.qualifiedName;
}
public String getQualifiedName() {
return qualifiedName;
}
......@@ -115,15 +128,15 @@ public abstract class AtlasGlossaryBaseObject extends AtlasBaseModelObject {
}
@Override
public String toString() {
final StringBuilder sb = new StringBuilder("AtlasGlossaryBaseObject{");
protected StringBuilder toString(final StringBuilder sb) {
sb.append("{");
sb.append("displayName='").append(displayName).append('\'');
sb.append(", shortDescription='").append(shortDescription).append('\'');
sb.append(", longDescription='").append(longDescription).append('\'');
sb.append(", classifications=").append(classifications);
sb.append(", qualifiedName='").append(qualifiedName).append('\'');
sb.append('}');
return sb.toString();
}
return sb;
}
}
......@@ -43,6 +43,14 @@ public class AtlasGlossaryCategory extends AtlasGlossaryBaseObject {
public AtlasGlossaryCategory() {
}
public AtlasGlossaryCategory(final AtlasGlossaryCategory other) {
super(other);
this.anchor = other.anchor;
this.parentCategory = other.parentCategory;
this.childrenCategories = other.childrenCategories;
this.terms = other.terms;
}
public AtlasGlossaryHeader getAnchor() {
return anchor;
}
......@@ -129,8 +137,8 @@ public class AtlasGlossaryCategory extends AtlasGlossaryBaseObject {
}
@Override
public String toString() {
final StringBuffer sb = new StringBuffer("AtlasGlossaryCategory{");
protected StringBuilder toString(final StringBuilder sb) {
sb.append("{");
sb.append("displayName='").append(getDisplayName()).append('\'');
sb.append(", shortDescription='").append(getShortDescription()).append('\'');
sb.append(", longDescription='").append(getLongDescription()).append('\'');
......@@ -140,12 +148,8 @@ public class AtlasGlossaryCategory extends AtlasGlossaryBaseObject {
sb.append(", terms=").append(terms);
sb.append(", classifications=").append(getClassifications());
sb.append('}');
return sb.toString();
}
@Override
protected StringBuilder toString(final StringBuilder sb) {
return sb == null ? new StringBuilder(toString()) : sb.append(toString());
return sb;
}
@Override
......@@ -154,21 +158,15 @@ public class AtlasGlossaryCategory extends AtlasGlossaryBaseObject {
if (!(o instanceof AtlasGlossaryCategory)) return false;
if (!super.equals(o)) return false;
final AtlasGlossaryCategory category = (AtlasGlossaryCategory) o;
return Objects.equals(getDisplayName(), category.getDisplayName()) &&
Objects.equals(getShortDescription(), category.getShortDescription()) &&
Objects.equals(getLongDescription(), category.getLongDescription()) &&
Objects.equals(anchor, category.anchor) &&
return Objects.equals(anchor, category.anchor) &&
Objects.equals(parentCategory, category.parentCategory) &&
Objects.equals(childrenCategories, category.childrenCategories) &&
Objects.equals(terms, category.terms) &&
Objects.equals(getClassifications(), category.getClassifications());
Objects.equals(terms, category.terms);
}
@Override
public int hashCode() {
return Objects.hash(super.hashCode(), getDisplayName(), getShortDescription(), getLongDescription(),
anchor, parentCategory, childrenCategories,
terms, getClassifications());
return Objects.hash(super.hashCode(), anchor, parentCategory, childrenCategories, terms);
}
}
......@@ -79,6 +79,30 @@ public class AtlasGlossaryTerm extends AtlasGlossaryBaseObject {
public AtlasGlossaryTerm() {
}
public AtlasGlossaryTerm(final AtlasGlossaryTerm other) {
super(other);
this.examples = other.examples;
this.abbreviation = other.abbreviation;
this.usage = other.usage;
this.anchor = other.anchor;
this.assignedEntities = other.assignedEntities;
this.categories = other.categories;
this.seeAlso = other.seeAlso;
this.synonyms = other.synonyms;
this.antonyms = other.antonyms;
this.preferredTerms = other.preferredTerms;
this.preferredToTerms = other.preferredToTerms;
this.replacementTerms = other.replacementTerms;
this.replacedBy = other.replacedBy;
this.translationTerms = other.translationTerms;
this.translatedTerms = other.translatedTerms;
this.isA = other.isA;
this.classifies = other.classifies;
this.validValues = other.validValues;
this.validValuesFor = other.validValuesFor;
this.hasTerms = other.hasTerms;
}
public List<String> getExamples() {
return examples;
}
......@@ -291,33 +315,6 @@ public class AtlasGlossaryTerm extends AtlasGlossaryBaseObject {
}
}
@Override
public String toString() {
final StringBuilder sb = new StringBuilder("AtlasGlossaryTerm{");
sb.append("examples=").append(examples);
sb.append(", abbreviation='").append(abbreviation).append('\'');
sb.append(", usage='").append(usage).append('\'');
sb.append(", anchor=").append(anchor);
sb.append(", assignedEntities=").append(assignedEntities);
sb.append(", categories=").append(categories);
sb.append(", seeAlso=").append(seeAlso);
sb.append(", synonyms=").append(synonyms);
sb.append(", antonyms=").append(antonyms);
sb.append(", preferredTerms=").append(preferredTerms);
sb.append(", preferredToTerms=").append(preferredToTerms);
sb.append(", replacementTerms=").append(replacementTerms);
sb.append(", replacedBy=").append(replacedBy);
sb.append(", translationTerms=").append(translationTerms);
sb.append(", translatedTerms=").append(translatedTerms);
sb.append(", isA=").append(isA);
sb.append(", classifies=").append(classifies);
sb.append(", validValues=").append(validValues);
sb.append(", validValuesFor=").append(validValuesFor);
sb.append(", hasTerms=").append(hasTerms);
sb.append('}');
return sb.toString();
}
@JsonIgnore
public Map<Relation, Set<AtlasRelatedTermHeader>> getRelatedTerms() {
Map<Relation, Set<AtlasRelatedTermHeader>> ret = new HashMap<>();
......@@ -379,7 +376,29 @@ public class AtlasGlossaryTerm extends AtlasGlossaryBaseObject {
@Override
protected StringBuilder toString(final StringBuilder sb) {
return sb == null ? new StringBuilder(toString()) : sb.append(toString());
sb.append("{");
sb.append("examples=").append(examples);
sb.append(", abbreviation='").append(abbreviation).append('\'');
sb.append(", usage='").append(usage).append('\'');
sb.append(", anchor=").append(anchor);
sb.append(", assignedEntities=").append(assignedEntities);
sb.append(", categories=").append(categories);
sb.append(", seeAlso=").append(seeAlso);
sb.append(", synonyms=").append(synonyms);
sb.append(", antonyms=").append(antonyms);
sb.append(", preferredTerms=").append(preferredTerms);
sb.append(", preferredToTerms=").append(preferredToTerms);
sb.append(", replacementTerms=").append(replacementTerms);
sb.append(", replacedBy=").append(replacedBy);
sb.append(", translationTerms=").append(translationTerms);
sb.append(", translatedTerms=").append(translatedTerms);
sb.append(", isA=").append(isA);
sb.append(", classifies=").append(classifies);
sb.append(", validValues=").append(validValues);
sb.append(", validValuesFor=").append(validValuesFor);
sb.append('}');
return sb;
}
@Override
......
......@@ -49,14 +49,13 @@ public class AtlasGlossaryHeader {
if (!(o instanceof AtlasGlossaryHeader)) return false;
final AtlasGlossaryHeader that = (AtlasGlossaryHeader) o;
return Objects.equals(glossaryGuid, that.glossaryGuid) &&
Objects.equals(relationGuid, that.relationGuid) &&
Objects.equals(displayText, that.displayText);
Objects.equals(relationGuid, that.relationGuid);
}
@Override
public int hashCode() {
return Objects.hash(glossaryGuid, displayText);
return Objects.hash(glossaryGuid, relationGuid);
}
@Override
......
......@@ -63,14 +63,14 @@ public class AtlasRelatedCategoryHeader {
final AtlasRelatedCategoryHeader that = (AtlasRelatedCategoryHeader) o;
return Objects.equals(categoryGuid, that.categoryGuid) &&
Objects.equals(parentCategoryGuid, that.parentCategoryGuid) &&
Objects.equals(displayText, that.displayText) &&
Objects.equals(relationGuid, that.relationGuid) &&
Objects.equals(description, that.description);
}
@Override
public int hashCode() {
return Objects.hash(categoryGuid, parentCategoryGuid, displayText, description);
return Objects.hash(categoryGuid, parentCategoryGuid, relationGuid, description);
}
@Override
......
......@@ -86,12 +86,6 @@ public class AtlasRelatedTermHeader {
}
@Override
public int hashCode() {
return Objects.hash(termGuid, displayText, description, expression, steward, source, status);
}
@Override
public boolean equals(final Object o) {
if (this == o) return true;
if (!(o instanceof AtlasRelatedTermHeader)) return false;
......@@ -99,7 +93,6 @@ public class AtlasRelatedTermHeader {
return Objects.equals(termGuid, that.termGuid) &&
Objects.equals(relationGuid, that.relationGuid) &&
Objects.equals(description, that.description) &&
Objects.equals(displayText, that.displayText) &&
Objects.equals(expression, that.expression) &&
Objects.equals(steward, that.steward) &&
Objects.equals(source, that.source) &&
......@@ -107,6 +100,12 @@ public class AtlasRelatedTermHeader {
}
@Override
public int hashCode() {
return Objects.hash(termGuid, relationGuid, description, expression, steward, source, status);
}
@Override
public String toString() {
final StringBuffer sb = new StringBuffer("AtlasRelatedTermId{");
sb.append("termGuid='").append(termGuid).append('\'');
......
......@@ -112,12 +112,6 @@ public class AtlasTermAssignmentHeader {
}
@Override
public int hashCode() {
return Objects.hash(termGuid, description, displayText, expression, createdBy, steward, source, confidence, status);
}
@Override
public boolean equals(final Object o) {
if (this == o) return true;
if (!(o instanceof AtlasTermAssignmentHeader)) return false;
......@@ -126,7 +120,6 @@ public class AtlasTermAssignmentHeader {
Objects.equals(termGuid, that.termGuid) &&
Objects.equals(relationGuid, that.relationGuid) &&
Objects.equals(description, that.description) &&
Objects.equals(displayText, that.displayText) &&
Objects.equals(expression, that.expression) &&
Objects.equals(createdBy, that.createdBy) &&
Objects.equals(steward, that.steward) &&
......@@ -135,6 +128,12 @@ public class AtlasTermAssignmentHeader {
}
@Override
public int hashCode() {
return Objects.hash(termGuid, relationGuid, description, expression, createdBy, steward, source, confidence, status);
}
@Override
public String toString() {
final StringBuilder sb = new StringBuilder("AtlasTermAssignmentId{");
sb.append("termGuid='").append(termGuid).append('\'');
......
......@@ -74,14 +74,13 @@ public class AtlasTermCategorizationHeader {
return Objects.equals(categoryGuid, that.categoryGuid) &&
Objects.equals(relationGuid, that.relationGuid) &&
Objects.equals(description, that.description) &&
Objects.equals(displayText, that.displayText) &&
status == that.status;
}
@Override
public int hashCode() {
return Objects.hash(categoryGuid, relationGuid, description, displayText, status);
return Objects.hash(categoryGuid, relationGuid, description, status);
}
@Override
......
......@@ -30,11 +30,13 @@ import org.apache.atlas.type.AtlasRelationshipType;
import org.apache.atlas.type.AtlasTypeRegistry;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
......@@ -218,11 +220,19 @@ public class GlossaryCategoryUtils extends GlossaryUtils {
}
private Map<String, AtlasRelatedTermHeader> getTerms(final AtlasGlossaryCategory category) {
return Objects.nonNull(category.getTerms()) ?
category.getTerms()
.stream()
.collect(Collectors.toMap(AtlasRelatedTermHeader::getTermGuid, t -> t)) :
Collections.EMPTY_MAP;
if (Objects.nonNull(category.getTerms())) {
Map<String, AtlasRelatedTermHeader> map = new HashMap<>();
for (AtlasRelatedTermHeader t : category.getTerms()) {
AtlasRelatedTermHeader header = map.get(t.getTermGuid());
if (header == null) {
map.put(t.getTermGuid(), t);
} else if (StringUtils.isEmpty(header.getRelationGuid()) && StringUtils.isNotEmpty(t.getRelationGuid())) {
map.put(t.getTermGuid(), t);
}
}
return map;
}
else return Collections.emptyMap();
}
private void createTermCategorizationRelationships(AtlasGlossaryCategory existing, Collection<AtlasRelatedTermHeader> terms) throws AtlasBaseException {
......@@ -333,11 +343,19 @@ public class GlossaryCategoryUtils extends GlossaryUtils {
}
private Map<String, AtlasRelatedCategoryHeader> getChildren(final AtlasGlossaryCategory category) {
return Objects.nonNull(category.getChildrenCategories()) ?
category.getChildrenCategories()
.stream()
.collect(Collectors.toMap(AtlasRelatedCategoryHeader::getCategoryGuid, c -> c)) :
Collections.EMPTY_MAP;
if (Objects.nonNull(category.getChildrenCategories())) {
Map<String, AtlasRelatedCategoryHeader> map = new HashMap<>();
for (AtlasRelatedCategoryHeader c : category.getChildrenCategories()) {
AtlasRelatedCategoryHeader header = map.get(c.getCategoryGuid());
if (header == null) {
map.put(c.getCategoryGuid(), c);
} else if (StringUtils.isEmpty(header.getRelationGuid()) && StringUtils.isNotEmpty(c.getRelationGuid())) {
map.put(c.getCategoryGuid(), c);
}
}
return map;
}
else return Collections.emptyMap();
}
private void createCategoryRelationships(AtlasGlossaryCategory existing, Collection<AtlasRelatedCategoryHeader> newChildren) throws AtlasBaseException {
......
......@@ -19,6 +19,7 @@ package org.apache.atlas.glossary;
import org.apache.atlas.AtlasErrorCode;
import org.apache.atlas.SortOrder;
import org.apache.atlas.annotation.GraphTransaction;
import org.apache.atlas.exception.AtlasBaseException;
import org.apache.atlas.model.glossary.AtlasGlossary;
import org.apache.atlas.model.glossary.AtlasGlossaryCategory;
......@@ -54,7 +55,7 @@ public class GlossaryService {
private static final Logger LOG = LoggerFactory.getLogger(GlossaryService.class);
private static final boolean DEBUG_ENABLED = LOG.isDebugEnabled();
private static final String QUALIFIED_NAME_ATTR = "qualifiedName";
private static final String QUALIFIED_NAME_ATTR = "qualifiedName";
private final DataAccess dataAccess;
private final GlossaryTermUtils glossaryTermUtils;
......@@ -78,6 +79,7 @@ public class GlossaryService {
* @return List of all glossaries
* @throws AtlasBaseException
*/
@GraphTransaction
public List<AtlasGlossary> getGlossaries(int limit, int offset, SortOrder sortOrder) throws AtlasBaseException {
if (DEBUG_ENABLED) {
LOG.debug("==> GlossaryService.getGlossaries({}, {}, {})", limit, offset, sortOrder);
......@@ -115,6 +117,7 @@ public class GlossaryService {
* @return Glossary definition
* @throws AtlasBaseException
*/
@GraphTransaction
public AtlasGlossary createGlossary(AtlasGlossary atlasGlossary) throws AtlasBaseException {
if (DEBUG_ENABLED) {
LOG.debug("==> GlossaryService.createGlossary({})", atlasGlossary);
......@@ -152,6 +155,7 @@ public class GlossaryService {
* @return Glossary corresponding to specified glossaryGuid
* @throws AtlasBaseException
*/
@GraphTransaction
public AtlasGlossary getGlossary(String glossaryGuid) throws AtlasBaseException {
if (DEBUG_ENABLED) {
LOG.debug("==> GlossaryService.getGlossary({})", glossaryGuid);
......@@ -179,6 +183,7 @@ public class GlossaryService {
* @return Glossary corresponding to specified glossaryGuid
* @throws AtlasBaseException
*/
@GraphTransaction
public AtlasGlossary.AtlasGlossaryExtInfo getDetailedGlossary(String glossaryGuid) throws AtlasBaseException {
if (DEBUG_ENABLED) {
LOG.debug("==> GlossaryService.getGlossary({})", glossaryGuid);
......@@ -219,18 +224,25 @@ public class GlossaryService {
return ret;
}
@GraphTransaction
public AtlasGlossary updateGlossary(AtlasGlossary atlasGlossary) throws AtlasBaseException {
if (DEBUG_ENABLED) {
LOG.debug("==> GlossaryService.updateGlossary({})", atlasGlossary);
}
if (Objects.isNull(atlasGlossary)) {
throw new AtlasBaseException(AtlasErrorCode.BAD_REQUEST, "Glossary is null/empty");
}
if (StringUtils.isEmpty(atlasGlossary.getDisplayName())) {
throw new AtlasBaseException(AtlasErrorCode.BAD_REQUEST, "DisplayName can't be null/empty");
}
AtlasGlossary ret = dataAccess.load(atlasGlossary);
if (!ret.equals(atlasGlossary)) {
atlasGlossary.setGuid(ret.getGuid());
atlasGlossary.setQualifiedName(ret.getQualifiedName());
ret = dataAccess.save(atlasGlossary);
setInfoForRelations(ret);
......@@ -242,6 +254,7 @@ public class GlossaryService {
return ret;
}
@GraphTransaction
public void deleteGlossary(String glossaryGuid) throws AtlasBaseException {
if (DEBUG_ENABLED) {
LOG.debug("==> GlossaryService.deleteGlossary({})", glossaryGuid);
......@@ -269,6 +282,7 @@ public class GlossaryService {
/*
* GlossaryTerms related operations
* */
@GraphTransaction
public AtlasGlossaryTerm getTerm(String termGuid) throws AtlasBaseException {
if (DEBUG_ENABLED) {
LOG.debug("==> GlossaryService.getTerm({})", termGuid);
......@@ -289,6 +303,7 @@ public class GlossaryService {
return ret;
}
@GraphTransaction
public AtlasGlossaryTerm createTerm(AtlasGlossaryTerm glossaryTerm) throws AtlasBaseException {
if (DEBUG_ENABLED) {
LOG.debug("==> GlossaryService.create({})", glossaryTerm);
......@@ -326,6 +341,7 @@ public class GlossaryService {
return existing;
}
@GraphTransaction
public List<AtlasGlossaryTerm> createTerms(List<AtlasGlossaryTerm> glossaryTerm) throws AtlasBaseException {
if (DEBUG_ENABLED) {
LOG.debug("==> GlossaryService.create({})", glossaryTerm);
......@@ -348,14 +364,19 @@ public class GlossaryService {
return ret;
}
@GraphTransaction
public AtlasGlossaryTerm updateTerm(AtlasGlossaryTerm atlasGlossaryTerm) throws AtlasBaseException {
if (DEBUG_ENABLED) {
LOG.debug("==> GlossaryService.updateTerm({})", atlasGlossaryTerm);
}
if (Objects.isNull(atlasGlossaryTerm)) {
throw new AtlasBaseException(AtlasErrorCode.BAD_REQUEST, "atlasGlossaryTerm is null/empty");
}
if (StringUtils.isEmpty(atlasGlossaryTerm.getDisplayName())) {
throw new AtlasBaseException(AtlasErrorCode.BAD_REQUEST, "DisplayName can't be null/empty");
}
AtlasGlossaryTerm existing = dataAccess.load(atlasGlossaryTerm);
AtlasGlossaryTerm updated = atlasGlossaryTerm;
......@@ -381,6 +402,7 @@ public class GlossaryService {
return updated;
}
@GraphTransaction
public void deleteTerm(String termGuid) throws AtlasBaseException {
if (DEBUG_ENABLED) {
LOG.debug("==> GlossaryService.deleteTerm({})", termGuid);
......@@ -405,6 +427,7 @@ public class GlossaryService {
}
}
@GraphTransaction
public void assignTermToEntities(String termGuid, List<AtlasRelatedObjectId> relatedObjectIds) throws AtlasBaseException {
if (DEBUG_ENABLED) {
LOG.debug("==> GlossaryService.assignTermToEntities({}, {})", termGuid, relatedObjectIds);
......@@ -417,6 +440,7 @@ public class GlossaryService {
}
}
@GraphTransaction
public void removeTermFromEntities(String termGuid, List<AtlasRelatedObjectId> relatedObjectIds) throws AtlasBaseException {
if (LOG.isDebugEnabled()) {
LOG.debug("==> GlossaryService.removeTermFromEntities({}, {})", termGuid, relatedObjectIds);
......@@ -433,6 +457,7 @@ public class GlossaryService {
/*
* GlossaryCategory related operations
* */
@GraphTransaction
public AtlasGlossaryCategory getCategory(String categoryGuid) throws AtlasBaseException {
if (DEBUG_ENABLED) {
LOG.debug("==> GlossaryService.getCategory({})", categoryGuid);
......@@ -452,6 +477,7 @@ public class GlossaryService {
return ret;
}
@GraphTransaction
public AtlasGlossaryCategory createCategory(AtlasGlossaryCategory glossaryCategory) throws AtlasBaseException {
if (DEBUG_ENABLED) {
LOG.debug("==> GlossaryService.createCategory({})", glossaryCategory);
......@@ -492,6 +518,7 @@ public class GlossaryService {
return saved;
}
@GraphTransaction
public List<AtlasGlossaryCategory> createCategories(List<AtlasGlossaryCategory> glossaryCategory) throws AtlasBaseException {
if (DEBUG_ENABLED) {
LOG.debug("==> GlossaryService.createCategories({})", glossaryCategory);
......@@ -511,14 +538,20 @@ public class GlossaryService {
return ret;
}
@GraphTransaction
public AtlasGlossaryCategory updateCategory(AtlasGlossaryCategory glossaryCategory) throws AtlasBaseException {
if (DEBUG_ENABLED) {
LOG.debug("==> GlossaryService.updateCategory({})", glossaryCategory);
}
if (Objects.isNull(glossaryCategory)) {
throw new AtlasBaseException(AtlasErrorCode.BAD_REQUEST, "GlossaryCategory is null/empty");
}
if (StringUtils.isEmpty(glossaryCategory.getDisplayName())) {
throw new AtlasBaseException(AtlasErrorCode.BAD_REQUEST, "DisplayName can't be null/empty");
}
AtlasGlossaryCategory existing = dataAccess.load(glossaryCategory);
AtlasGlossaryCategory ret = glossaryCategory;
......@@ -545,6 +578,7 @@ public class GlossaryService {
return ret;
}
@GraphTransaction
public void deleteCategory(String categoryGuid) throws AtlasBaseException {
if (DEBUG_ENABLED) {
LOG.debug("==> GlossaryService.deleteCategory({})", categoryGuid);
......@@ -566,57 +600,78 @@ public class GlossaryService {
}
}
public List<AtlasGlossaryTerm> getGlossaryTerms(String glossaryGuid, int offset, int limit, SortOrder sortOrder) throws AtlasBaseException {
@GraphTransaction
public List<AtlasRelatedTermHeader> getGlossaryTermsHeaders(String glossaryGuid, int offset, int limit, SortOrder sortOrder) throws AtlasBaseException {
if (Objects.isNull(glossaryGuid)) {
throw new AtlasBaseException(AtlasErrorCode.BAD_REQUEST, "glossaryGuid is null/empty");
}
if (DEBUG_ENABLED) {
LOG.debug("==> GlossaryService.getGlossaryTerms({}, {}, {}, {})", glossaryGuid, offset, limit, sortOrder);
LOG.debug("==> GlossaryService.getGlossaryTermsHeaders({}, {}, {}, {})", glossaryGuid, offset, limit, sortOrder);
}
AtlasGlossary glossary = getGlossary(glossaryGuid);
List<AtlasGlossaryTerm> ret;
List<AtlasRelatedTermHeader> ret;
if (CollectionUtils.isNotEmpty(glossary.getTerms())) {
List<AtlasGlossaryTerm> toLoad = glossary.getTerms().stream()
.map(t -> getAtlasGlossaryTermSkeleton(t.getTermGuid()))
.collect(Collectors.toList());
Iterable<AtlasGlossaryTerm> terms = dataAccess.load(toLoad);
toLoad.clear();
terms.forEach(toLoad::add);
List<AtlasRelatedTermHeader> terms = new ArrayList<>(glossary.getTerms());
if (sortOrder != null) {
toLoad.sort((o1, o2) -> sortOrder == SortOrder.ASCENDING ?
o1.getDisplayName().compareTo(o2.getDisplayName()) :
o2.getDisplayName().compareTo(o1.getDisplayName()));
terms.sort((o1, o2) -> sortOrder == SortOrder.ASCENDING ?
o1.getDisplayText().compareTo(o2.getDisplayText()) :
o2.getDisplayText().compareTo(o1.getDisplayText()));
}
ret = new PaginationHelper<>(toLoad, offset, limit).getPaginatedList();
ret = new PaginationHelper<>(terms, offset, limit).getPaginatedList();
} else {
ret = Collections.emptyList();
}
if (DEBUG_ENABLED) {
LOG.debug("<== GlossaryService.getGlossaryTerms() : {}", ret);
LOG.debug("<== GlossaryService.getGlossaryTermsHeaders() : {}", ret);
}
return ret;
}
public List<AtlasRelatedCategoryHeader> getGlossaryCategories(String glossaryGuid, int offset, int limit, SortOrder sortOrder) throws AtlasBaseException {
@GraphTransaction
public List<AtlasGlossaryTerm> getGlossaryTerms(String glossaryGuid, int offset, int limit, SortOrder sortOrder) throws AtlasBaseException {
if (Objects.isNull(glossaryGuid)) {
throw new AtlasBaseException(AtlasErrorCode.BAD_REQUEST, "glossaryGuid is null/empty");
}
if (DEBUG_ENABLED) {
LOG.debug("==> GlossaryService.getGlossaryCategories({}, {}, {}, {})", glossaryGuid, offset, limit, sortOrder);
LOG.debug("==> GlossaryService.getGlossaryTerms({}, {}, {}, {})", glossaryGuid, offset, limit, sortOrder);
}
AtlasGlossary glossary = getGlossary(glossaryGuid);
List<AtlasGlossaryTerm> ret = new ArrayList<>();
List<AtlasRelatedTermHeader> termHeaders = getGlossaryTermsHeaders(glossaryGuid, offset, limit, sortOrder);
for (AtlasRelatedTermHeader header : termHeaders) {
ret.add(dataAccess.load(getAtlasGlossaryTermSkeleton(header.getTermGuid())));
}
if (DEBUG_ENABLED) {
LOG.debug("<== GlossaryService.getGlossaryTerms() : {}", ret);
}
return ret;
}
@GraphTransaction
public List<AtlasRelatedCategoryHeader> getGlossaryCategoriesHeaders(String glossaryGuid, int offset, int limit, SortOrder sortOrder) throws AtlasBaseException {
if (Objects.isNull(glossaryGuid)) {
throw new AtlasBaseException(AtlasErrorCode.BAD_REQUEST, "glossaryGuid is null/empty");
}
if (DEBUG_ENABLED) {
LOG.debug("==> GlossaryService.getGlossaryCategoriesHeaders({}, {}, {}, {})", glossaryGuid, offset, limit, sortOrder);
}
List<AtlasRelatedCategoryHeader> ret;
List<AtlasRelatedCategoryHeader> categories = new ArrayList<>(glossary.getCategories());
if (CollectionUtils.isNotEmpty(categories)) {
AtlasGlossary glossary = getGlossary(glossaryGuid);
if (CollectionUtils.isNotEmpty(glossary.getCategories())) {
List<AtlasRelatedCategoryHeader> categories = new ArrayList<>(glossary.getCategories());
if (sortOrder != null) {
categories.sort((o1, o2) -> sortOrder == SortOrder.ASCENDING ?
o1.getDisplayText().compareTo(o2.getDisplayText()) :
......@@ -628,12 +683,37 @@ public class GlossaryService {
}
if (DEBUG_ENABLED) {
LOG.debug("<== GlossaryService.getGlossaryCategoriesHeaders() : {}", ret);
}
return ret;
}
@GraphTransaction
public List<AtlasGlossaryCategory> getGlossaryCategories(String glossaryGuid, int offset, int limit, SortOrder sortOrder) throws AtlasBaseException {
if (Objects.isNull(glossaryGuid)) {
throw new AtlasBaseException(AtlasErrorCode.BAD_REQUEST, "glossaryGuid is null/empty");
}
if (DEBUG_ENABLED) {
LOG.debug("==> GlossaryService.getGlossaryCategories({}, {}, {}, {})", glossaryGuid, offset, limit, sortOrder);
}
List<AtlasGlossaryCategory> ret = new ArrayList<>();
List<AtlasRelatedCategoryHeader> categoryHeaders = getGlossaryCategoriesHeaders(glossaryGuid, offset, limit, sortOrder);
for (AtlasRelatedCategoryHeader header : categoryHeaders) {
ret.add(dataAccess.load(getAtlasGlossaryCategorySkeleton(header.getCategoryGuid())));
}
if (DEBUG_ENABLED) {
LOG.debug("<== GlossaryService.getGlossaryCategories() : {}", ret);
}
return ret;
}
@GraphTransaction
public List<AtlasRelatedTermHeader> getCategoryTerms(String categoryGuid, int offset, int limit, SortOrder sortOrder) throws AtlasBaseException {
if (Objects.isNull(categoryGuid)) {
throw new AtlasBaseException(AtlasErrorCode.BAD_REQUEST, "categoryGuid is null/empty");
......@@ -642,11 +722,13 @@ public class GlossaryService {
if (DEBUG_ENABLED) {
LOG.debug("==> GlossaryService.getCategoryTerms({}, {}, {}, {})", categoryGuid, offset, limit, sortOrder);
}
AtlasGlossaryCategory glossaryCategory = getCategory(categoryGuid);
List<AtlasRelatedTermHeader> ret;
List<AtlasRelatedTermHeader> terms = new ArrayList<>(glossaryCategory.getTerms());
AtlasGlossaryCategory glossaryCategory = getCategory(categoryGuid);
if (CollectionUtils.isNotEmpty(glossaryCategory.getTerms())) {
List<AtlasRelatedTermHeader> terms = new ArrayList<>(glossaryCategory.getTerms());
if (sortOrder != null) {
terms.sort((o1, o2) -> sortOrder == SortOrder.ASCENDING ?
o1.getDisplayText().compareTo(o2.getDisplayText()) :
......@@ -663,6 +745,7 @@ public class GlossaryService {
return ret;
}
@GraphTransaction
public Map<AtlasGlossaryTerm.Relation, Set<AtlasRelatedTermHeader>> getRelatedTerms(String termGuid, int offset, int limit, SortOrder sortOrder) throws AtlasBaseException {
if (Objects.isNull(termGuid)) {
throw new AtlasBaseException(AtlasErrorCode.BAD_REQUEST, "termGuid is null/empty");
......@@ -687,6 +770,7 @@ public class GlossaryService {
return ret;
}
@GraphTransaction
public Map<String, List<AtlasRelatedCategoryHeader>> getRelatedCategories(String categoryGuid, int offset, int limit, SortOrder sortOrder) throws AtlasBaseException {
if (Objects.isNull(categoryGuid)) {
throw new AtlasBaseException(AtlasErrorCode.BAD_REQUEST, "categoryGuid is null/empty");
......@@ -716,6 +800,7 @@ public class GlossaryService {
return ret;
}
@GraphTransaction
public List<AtlasRelatedObjectId> getAssignedEntities(final String termGuid, int offset, int limit, SortOrder sortOrder) throws AtlasBaseException {
if (Objects.isNull(termGuid)) {
throw new AtlasBaseException(AtlasErrorCode.BAD_REQUEST, "termGuid is null/empty");
......@@ -767,7 +852,7 @@ public class GlossaryService {
return Objects.nonNull(vertex);
}
private void deleteCategories(final AtlasGlossary existing, final Set<AtlasRelatedCategoryHeader> categories) throws AtlasBaseException {
private void deleteCategories(final AtlasGlossary existing, final Collection<AtlasRelatedCategoryHeader> categories) throws AtlasBaseException {
if (CollectionUtils.isNotEmpty(categories)) {
if (DEBUG_ENABLED) {
LOG.debug("Deleting categories within glossary guid = {}", existing.getGuid());
......@@ -779,7 +864,7 @@ public class GlossaryService {
}
}
private void deleteTerms(final AtlasGlossary existing, final Set<AtlasRelatedTermHeader> terms) throws AtlasBaseException {
private void deleteTerms(final AtlasGlossary existing, final Collection<AtlasRelatedTermHeader> terms) throws AtlasBaseException {
if (CollectionUtils.isNotEmpty(terms)) {
if (DEBUG_ENABLED) {
LOG.debug("Deleting terms within glossary guid = {}", existing.getGuid());
......@@ -843,7 +928,7 @@ public class GlossaryService {
categorizationHeaders.forEach(c -> c.setDisplayText(categoryMap.get(c.getCategoryGuid()).getDisplayName()));
}
private void setInfoForRelatedCategories(final Set<AtlasRelatedCategoryHeader> categoryHeaders) throws AtlasBaseException {
private void setInfoForRelatedCategories(final Collection<AtlasRelatedCategoryHeader> categoryHeaders) throws AtlasBaseException {
List<AtlasGlossaryCategory> categories = categoryHeaders
.stream()
.map(id -> getAtlasGlossaryCategorySkeleton(id.getCategoryGuid()))
......@@ -859,7 +944,7 @@ public class GlossaryService {
}
}
private void setInfoForTerms(final Set<AtlasRelatedTermHeader> termHeaders) throws AtlasBaseException {
private void setInfoForTerms(final Collection<AtlasRelatedTermHeader> termHeaders) throws AtlasBaseException {
List<AtlasGlossaryTerm> terms = termHeaders
.stream()
.map(id -> getAtlasGlossaryTermSkeleton(id.getTermGuid()))
......
......@@ -71,6 +71,14 @@ public class DataAccess {
throw new AtlasBaseException(AtlasErrorCode.DATA_ACCESS_SAVE_FAILED, obj.toString());
}
// Update GUID assignment for newly created entity
if (CollectionUtils.isNotEmpty(entityMutationResponse.getCreatedEntities())) {
String assignedGuid = entityMutationResponse.getGuidAssignments().get(obj.getGuid());
if (!obj.getGuid().equals(assignedGuid)) {
obj.setGuid(assignedGuid);
}
}
return this.load(obj);
} finally {
......@@ -147,11 +155,13 @@ public class DataAccess {
AtlasEntityWithExtInfo entityWithExtInfo;
if (StringUtils.isNotEmpty(obj.getGuid())) {
String guid = obj.getGuid();
// GUID can be null/empty/-ve
if (StringUtils.isNotEmpty(guid) && guid.charAt(0) != '-') {
if (LOG.isDebugEnabled()) {
LOG.debug("Load using GUID");
}
entityWithExtInfo = entityStore.getById(obj.getGuid());
entityWithExtInfo = entityStore.getById(guid);
} else {
if (LOG.isDebugEnabled()) {
LOG.debug("Load using unique attributes");
......@@ -159,8 +169,15 @@ public class DataAccess {
entityWithExtInfo = entityStore.getByUniqueAttributes(dto.getEntityType(), dto.getUniqueAttributes(obj));
}
// Since GUID alone can't be used to determine what ENTITY TYPE is loaded from the graph
String actualTypeName = entityWithExtInfo.getEntity().getTypeName();
String expectedTypeName = dto.getEntityType().getTypeName();
if (!actualTypeName.equals(expectedTypeName)) {
throw new AtlasBaseException(AtlasErrorCode.UNEXPECTED_TYPE, expectedTypeName, actualTypeName);
}
if (!loadDeleted && entityWithExtInfo.getEntity().getStatus() == AtlasEntity.Status.DELETED) {
throw new AtlasBaseException(AtlasErrorCode.INSTANCE_GUID_DELETED, obj.getGuid());
throw new AtlasBaseException(AtlasErrorCode.INSTANCE_GUID_DELETED, guid);
}
return dto.from(entityWithExtInfo);
......@@ -170,6 +187,7 @@ public class DataAccess {
}
}
public void delete(String guid) throws AtlasBaseException {
Objects.requireNonNull(guid, "guid");
AtlasPerfTracer perf = null;
......
......@@ -255,14 +255,14 @@ public class AtlasRelationshipStoreV1 implements AtlasRelationshipStore {
// remove tag propagations
List<AtlasVertex> propagatedClassificationVertices = getClassificationVertices(edge);
deleteHandler.deleteRelationships(Collections.singleton(edge));
for (AtlasVertex classificationVertex : propagatedClassificationVertices) {
List<AtlasVertex> removePropagationFromVertices = graphHelper.getPropagatedEntityVertices(classificationVertex);
deleteHandler.removeTagPropagation(classificationVertex, removePropagationFromVertices);
}
deleteHandler.deleteRelationships(Collections.singleton(edge));
// notify entities for added/removed classification propagation
entityChangeNotifier.notifyPropagatedEntities();
......@@ -562,14 +562,23 @@ public class AtlasRelationshipStoreV1 implements AtlasRelationshipStore {
}
private void validateRelationship(AtlasVertex end1Vertex, AtlasVertex end2Vertex, String relationshipName, Map<String, Object> attributes) throws AtlasBaseException {
String end1TypeName = AtlasGraphUtilsV1.getTypeName(end1Vertex);
String end2TypeName = AtlasGraphUtilsV1.getTypeName(end2Vertex);
AtlasRelationshipType relationshipType = typeRegistry.getRelationshipTypeByName(relationshipName);
if (relationshipType == null) {
throw new AtlasBaseException(AtlasErrorCode.INVALID_VALUE, "unknown relationship type'" + relationshipName + "'");
}
if (end1Vertex == null) {
throw new AtlasBaseException(AtlasErrorCode.RELATIONSHIP_END_IS_NULL, relationshipType.getEnd1Type().getTypeName());
}
if (end2Vertex == null) {
throw new AtlasBaseException(AtlasErrorCode.RELATIONSHIP_END_IS_NULL, relationshipType.getEnd2Type().getTypeName());
}
String end1TypeName = AtlasGraphUtilsV1.getTypeName(end1Vertex);
String end2TypeName = AtlasGraphUtilsV1.getTypeName(end2Vertex);
boolean validEndTypes = false;
if (relationshipType.getEnd1Type().isTypeOrSuperTypeOf(end1TypeName)) {
......
......@@ -208,6 +208,32 @@ public class GlossaryServiceTest {
assertEquals(e.getAtlasErrorCode(), AtlasErrorCode.GLOSSARY_ALREADY_EXISTS);
}
// Retrieve the glossary and see ensure no terms or categories are linked
try {
List<AtlasRelatedCategoryHeader> glossaryCategories = glossaryService.getGlossaryCategoriesHeaders(bankGlossary.getGuid(), 0, 10, SortOrder.ASCENDING);
assertNotNull(glossaryCategories);
assertEquals(glossaryCategories.size(), 0);
glossaryCategories = glossaryService.getGlossaryCategoriesHeaders(creditUnionGlossary.getGuid(), 0, 10, SortOrder.ASCENDING);
assertNotNull(glossaryCategories);
assertEquals(glossaryCategories.size(), 0);
} catch (AtlasBaseException e) {
fail("Get glossary categories calls should've succeeded", e);
}
try {
List<AtlasRelatedTermHeader> glossaryCategories = glossaryService.getGlossaryTermsHeaders(bankGlossary.getGuid(), 0, 10, SortOrder.ASCENDING);
assertNotNull(glossaryCategories);
assertEquals(glossaryCategories.size(), 0);
glossaryCategories = glossaryService.getGlossaryTermsHeaders(creditUnionGlossary.getGuid(), 0, 10, SortOrder.ASCENDING);
assertNotNull(glossaryCategories);
assertEquals(glossaryCategories.size(), 0);
} catch (AtlasBaseException e) {
fail("Get glossary categories calls should've succeeded", e);
}
// Glossary anchor
AtlasGlossaryHeader glossaryId = new AtlasGlossaryHeader();
glossaryId.setGlossaryGuid(bankGlossary.getGuid());
......@@ -331,13 +357,41 @@ public class GlossaryServiceTest {
AtlasGlossary updatedGlossary = glossaryService.updateGlossary(bankGlossary);
assertNotNull(updatedGlossary);
assertEquals(updatedGlossary.getGuid(), bankGlossary.getGuid());
assertEquals(updatedGlossary, bankGlossary);
// assertEquals(updatedGlossary.getCategories(), bankGlossary.getCategories());
// assertEquals(updatedGlossary.getTerms(), bankGlossary.getTerms());
// assertEquals(updatedGlossary, bankGlossary);
// There's some weirdness around the equality check of HashSet, hence the conversion to ArrayList
ArrayList<AtlasRelatedCategoryHeader> a = new ArrayList<>(updatedGlossary.getCategories());
ArrayList<AtlasRelatedCategoryHeader> b = new ArrayList<>(bankGlossary.getCategories());
assertEquals(a, b);
} catch (AtlasBaseException e) {
fail("Glossary fetch/update should've succeeded", e);
}
}
@Test(dependsOnGroups = {"Glossary.MIGRATE"}) // Should be the last test
@Test(dependsOnGroups = {"Glossary.MIGRATE"})
public void testInvalidFetches() {
try {
glossaryService.getGlossary(mortgageCategory.getGuid());
} catch (AtlasBaseException e) {
assertEquals(e.getAtlasErrorCode(), AtlasErrorCode.UNEXPECTED_TYPE);
}
try {
glossaryService.getTerm(bankGlossary.getGuid());
} catch (AtlasBaseException e) {
assertEquals(e.getAtlasErrorCode(), AtlasErrorCode.UNEXPECTED_TYPE);
}
try {
glossaryService.getCategory(savingsAccount.getGuid());
} catch (AtlasBaseException e) {
assertEquals(e.getAtlasErrorCode(), AtlasErrorCode.UNEXPECTED_TYPE);
}
}
@Test(dependsOnMethods = "testInvalidFetches") // Should be the last test
public void testDeleteGlossary() {
try {
glossaryService.deleteGlossary(bankGlossary.getGuid());
......@@ -448,7 +502,7 @@ public class GlossaryServiceTest {
}
try {
List<AtlasGlossaryTerm> terms = glossaryService.getGlossaryTerms(creditUnionGlossary.getGuid(), 0, 5, SortOrder.ASCENDING);
List<AtlasRelatedTermHeader> terms = glossaryService.getGlossaryTermsHeaders(creditUnionGlossary.getGuid(), 0, 5, SortOrder.ASCENDING);
assertNotNull(terms);
assertEquals(terms.size(), 2);
} catch (AtlasBaseException e) {
......@@ -480,7 +534,7 @@ public class GlossaryServiceTest {
}
try {
List<AtlasRelatedCategoryHeader> categories = glossaryService.getGlossaryCategories(creditUnionGlossary.getGuid(), 0, 5, SortOrder.ASCENDING);
List<AtlasRelatedCategoryHeader> categories = glossaryService.getGlossaryCategoriesHeaders(creditUnionGlossary.getGuid(), 0, 5, SortOrder.ASCENDING);
assertNotNull(categories);
assertEquals(categories.size(), 1);
} catch (AtlasBaseException e) {
......@@ -563,8 +617,6 @@ public class GlossaryServiceTest {
try {
customerCategory = glossaryService.getCategory(customerCategory.getGuid());
assertNull(customerCategory.getParentCategory());
assertNotNull(customerCategory.getChildrenCategories());
assertEquals(customerCategory.getChildrenCategories().size(), 1); // Only account category
} catch (AtlasBaseException e) {
fail("Fetch of accountCategory should've succeeded", e);
}
......@@ -578,7 +630,6 @@ public class GlossaryServiceTest {
AtlasGlossaryCategory updateGlossaryCategory = glossaryService.updateCategory(customerCategory);
assertNull(updateGlossaryCategory.getParentCategory());
assertNotNull(updateGlossaryCategory.getChildrenCategories());
assertEquals(updateGlossaryCategory.getChildrenCategories().size(), 2);
LOG.debug(AtlasJson.toJson(updateGlossaryCategory));
} catch (AtlasBaseException e) {
fail("Sub category addition should've succeeded", e);
......@@ -694,7 +745,7 @@ public class GlossaryServiceTest {
SortOrder sortOrder = SortOrder.ASCENDING;
try {
List<AtlasGlossaryTerm> glossaryTerms = glossaryService.getGlossaryTerms(guid, offset, limit, sortOrder);
List<AtlasRelatedTermHeader> glossaryTerms = glossaryService.getGlossaryTermsHeaders(guid, offset, limit, sortOrder);
assertNotNull(glossaryTerms);
assertEquals(glossaryTerms.size(), expected);
} catch (AtlasBaseException e) {
......@@ -718,7 +769,7 @@ public class GlossaryServiceTest {
SortOrder sortOrder = SortOrder.ASCENDING;
try {
List<AtlasRelatedCategoryHeader> glossaryCategories = glossaryService.getGlossaryCategories(guid, offset, limit, sortOrder);
List<AtlasRelatedCategoryHeader> glossaryCategories = glossaryService.getGlossaryCategoriesHeaders(guid, offset, limit, sortOrder);
assertNotNull(glossaryCategories);
assertEquals(glossaryCategories.size(), expected);
} catch (AtlasBaseException e) {
......
......@@ -78,11 +78,8 @@ public class UserProfileServiceTest {
@Test
public void filterInternalType() throws AtlasBaseException {
SearchFilter searchFilter = new SearchFilter();
AtlasTypesDef filteredTypeDefs = typeDefStore.searchTypesDef(searchFilter);
int maxTypeDefs = filteredTypeDefs.getEntityDefs().size();
FilterUtil.addParamsToHideInternalType(searchFilter);
filteredTypeDefs = typeDefStore.searchTypesDef(searchFilter);
AtlasTypesDef filteredTypeDefs = typeDefStore.searchTypesDef(searchFilter);
assertNotNull(filteredTypeDefs);
Optional<AtlasEntityDef> anyInternal = filteredTypeDefs.getEntityDefs().stream().filter(e -> e.getSuperTypes().contains("__internal")).findAny();
......
......@@ -391,7 +391,11 @@ public class GlossaryREST {
AtlasGlossary glossary = glossaryService.getGlossary(glossaryGuid);
for (Map.Entry<String, String> entry : partialUpdates.entrySet()) {
glossary.setAttribute(entry.getKey(), entry.getValue());
try {
glossary.setAttribute(entry.getKey(), entry.getValue());
} catch (IllegalArgumentException e) {
throw new AtlasBaseException(AtlasErrorCode.INVALID_PARTIAL_UPDATE_ATTR, "Glossary", entry.getKey());
}
}
return glossaryService.updateGlossary(glossary);
} finally {
......@@ -452,7 +456,11 @@ public class GlossaryREST {
AtlasGlossaryTerm glossaryTerm = glossaryService.getTerm(termGuid);
for (Map.Entry<String, String> entry : partialUpdates.entrySet()) {
glossaryTerm.setAttribute(entry.getKey(), entry.getValue());
try {
glossaryTerm.setAttribute(entry.getKey(), entry.getValue());
} catch (IllegalArgumentException e) {
throw new AtlasBaseException(AtlasErrorCode.INVALID_PARTIAL_UPDATE_ATTR, "Glossary Term", entry.getKey());
}
}
return glossaryService.updateTerm(glossaryTerm);
} finally {
......@@ -513,7 +521,11 @@ public class GlossaryREST {
AtlasGlossaryCategory glossaryCategory = glossaryService.getCategory(categoryGuid);
for (Map.Entry<String, String> entry : partialUpdates.entrySet()) {
glossaryCategory.setAttribute(entry.getKey(), entry.getValue());
try {
glossaryCategory.setAttribute(entry.getKey(), entry.getValue());
} catch (IllegalArgumentException e) {
throw new AtlasBaseException(AtlasErrorCode.INVALID_PARTIAL_UPDATE_ATTR, "Glossary Category", entry.getKey());
}
}
return glossaryService.updateCategory(glossaryCategory);
} finally {
......@@ -601,9 +613,9 @@ public class GlossaryREST {
@GET
@Path("/{glossaryGuid}/terms")
public List<AtlasGlossaryTerm> getGlossaryTerms(@PathParam("glossaryGuid") String glossaryGuid,
@DefaultValue("-1") @QueryParam("limit") String limit,
@DefaultValue("0") @QueryParam("offset") String offset,
@DefaultValue("ASC") @QueryParam("sort") final String sort) throws AtlasBaseException {
@DefaultValue("-1") @QueryParam("limit") String limit,
@DefaultValue("0") @QueryParam("offset") String offset,
@DefaultValue("ASC") @QueryParam("sort") final String sort) throws AtlasBaseException {
Servlets.validateQueryParamLength("glossaryGuid", glossaryGuid);
AtlasPerfTracer perf = null;
try {
......@@ -619,6 +631,37 @@ public class GlossaryREST {
}
/**
* Get term headers belonging to a specific glossary
* @param glossaryGuid unique identifier for glossary
* @param limit page size - by default there is no paging
* @param offset starting offset for loading terms
* @param sort ASC(default) or DESC
* @return List of terms associated with the glossary
* @throws AtlasBaseException
* @HTTP 200 List of glossary terms for the given glossary or an empty list
* @HTTP 404 If glossary guid in invalid
*/
@GET
@Path("/{glossaryGuid}/terms/headers")
public List<AtlasRelatedTermHeader> getGlossaryTermHeaders(@PathParam("glossaryGuid") String glossaryGuid,
@DefaultValue("-1") @QueryParam("limit") String limit,
@DefaultValue("0") @QueryParam("offset") String offset,
@DefaultValue("ASC") @QueryParam("sort") final String sort) throws AtlasBaseException {
Servlets.validateQueryParamLength("glossaryGuid", glossaryGuid);
AtlasPerfTracer perf = null;
try {
if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "GlossaryREST.getGlossaryTermHeaders(" + glossaryGuid + ")");
}
return glossaryService.getGlossaryTermsHeaders(glossaryGuid, Integer.parseInt(offset), Integer.parseInt(limit), toSortOrder(sort));
} finally {
AtlasPerfTracer.log(perf);
}
}
/**
* Get the categories belonging to a specific glossary
* @param glossaryGuid unique identifier for glossary term
* @param limit page size - by default there is no paging
......@@ -631,7 +674,7 @@ public class GlossaryREST {
*/
@GET
@Path("/{glossaryGuid}/categories")
public List<AtlasRelatedCategoryHeader> getGlossaryCategories(@PathParam("glossaryGuid") String glossaryGuid,
public List<AtlasGlossaryCategory> getGlossaryCategories(@PathParam("glossaryGuid") String glossaryGuid,
@DefaultValue("-1") @QueryParam("limit") String limit,
@DefaultValue("0") @QueryParam("offset") String offset,
@DefaultValue("ASC") @QueryParam("sort") final String sort) throws AtlasBaseException {
......@@ -650,6 +693,37 @@ public class GlossaryREST {
}
/**
* Get the categories belonging to a specific glossary
* @param glossaryGuid unique identifier for glossary term
* @param limit page size - by default there is no paging
* @param offset offset for pagination purpose
* @param sort ASC (default) or DESC
* @return List of associated categories
* @throws AtlasBaseException
* @HTTP 200 List of glossary categories for the given glossary or an empty list
* @HTTP 404 If glossary guid in invalid
*/
@GET
@Path("/{glossaryGuid}/categories/headers")
public List<AtlasRelatedCategoryHeader> getGlossaryCategoriesHeaders(@PathParam("glossaryGuid") String glossaryGuid,
@DefaultValue("-1") @QueryParam("limit") String limit,
@DefaultValue("0") @QueryParam("offset") String offset,
@DefaultValue("ASC") @QueryParam("sort") final String sort) throws AtlasBaseException {
Servlets.validateQueryParamLength("glossaryGuid", glossaryGuid);
AtlasPerfTracer perf = null;
try {
if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "GlossaryREST.getGlossaryCategoriesHeaders(" + glossaryGuid + ")");
}
return glossaryService.getGlossaryCategoriesHeaders(glossaryGuid, Integer.parseInt(offset), Integer.parseInt(limit), toSortOrder(sort));
} finally {
AtlasPerfTracer.log(perf);
}
}
/**
* Get all terms associated with the specific category
* @param categoryGuid unique identifier for glossary category
* @param limit page size - by default there is no paging
......
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