Commit 0dad9529 by apoorvnaik Committed by Madhan Neethiraj

ATLAS-2534: Glossary REST API implementation

Change-Id: I47210446be9e38c274bae0ee4a688187ba6e4fd0 Signed-off-by: 's avatarMadhan Neethiraj <madhan@apache.org>
parent 15967a93
...@@ -6,9 +6,9 @@ ...@@ -6,9 +6,9 @@
* to you under the Apache License, Version 2.0 (the * to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance * "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at * with the License. You may obtain a copy of the License at
* * <p>
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* * <p>
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
...@@ -28,10 +28,10 @@ public final class Constants { ...@@ -28,10 +28,10 @@ public final class Constants {
* Globally Unique identifier property key. * Globally Unique identifier property key.
*/ */
public static final String INTERNAL_PROPERTY_KEY_PREFIX = "__"; public static final String INTERNAL_PROPERTY_KEY_PREFIX = "__";
public static final String RELATIONSHIP_PROPERTY_KEY_PREFIX = "_r"; public static final String RELATIONSHIP_PROPERTY_KEY_PREFIX = "_r";
public static final String GUID_PROPERTY_KEY = INTERNAL_PROPERTY_KEY_PREFIX + "guid"; public static final String GUID_PROPERTY_KEY = INTERNAL_PROPERTY_KEY_PREFIX + "guid";
public static final String RELATIONSHIP_GUID_PROPERTY_KEY = RELATIONSHIP_PROPERTY_KEY_PREFIX + GUID_PROPERTY_KEY; public static final String RELATIONSHIP_GUID_PROPERTY_KEY = RELATIONSHIP_PROPERTY_KEY_PREFIX + GUID_PROPERTY_KEY;
/** /**
* Entity type name property key. * Entity type name property key.
...@@ -53,35 +53,35 @@ public final class Constants { ...@@ -53,35 +53,35 @@ public final class Constants {
/** /**
* Properties for type store graph. * Properties for type store graph.
*/ */
public static final String TYPE_CATEGORY_PROPERTY_KEY = INTERNAL_PROPERTY_KEY_PREFIX + "type.category"; public static final String TYPE_CATEGORY_PROPERTY_KEY = INTERNAL_PROPERTY_KEY_PREFIX + "type.category";
public static final String VERTEX_TYPE_PROPERTY_KEY = INTERNAL_PROPERTY_KEY_PREFIX + "type"; public static final String VERTEX_TYPE_PROPERTY_KEY = INTERNAL_PROPERTY_KEY_PREFIX + "type";
public static final String TYPENAME_PROPERTY_KEY = INTERNAL_PROPERTY_KEY_PREFIX + "type.name"; public static final String TYPENAME_PROPERTY_KEY = INTERNAL_PROPERTY_KEY_PREFIX + "type.name";
public static final String TYPEDESCRIPTION_PROPERTY_KEY = INTERNAL_PROPERTY_KEY_PREFIX + "type.description"; public static final String TYPEDESCRIPTION_PROPERTY_KEY = INTERNAL_PROPERTY_KEY_PREFIX + "type.description";
public static final String TYPEVERSION_PROPERTY_KEY = INTERNAL_PROPERTY_KEY_PREFIX + "type.version"; public static final String TYPEVERSION_PROPERTY_KEY = INTERNAL_PROPERTY_KEY_PREFIX + "type.version";
public static final String TYPEOPTIONS_PROPERTY_KEY = INTERNAL_PROPERTY_KEY_PREFIX + "type.options"; public static final String TYPEOPTIONS_PROPERTY_KEY = INTERNAL_PROPERTY_KEY_PREFIX + "type.options";
// relationship def constants // relationship def constants
public static final String RELATIONSHIPTYPE_END1_KEY = "endDef1"; public static final String RELATIONSHIPTYPE_END1_KEY = "endDef1";
public static final String RELATIONSHIPTYPE_END2_KEY = "endDef2"; public static final String RELATIONSHIPTYPE_END2_KEY = "endDef2";
public static final String RELATIONSHIPTYPE_CATEGORY_KEY = "relationshipCategory"; public static final String RELATIONSHIPTYPE_CATEGORY_KEY = "relationshipCategory";
public static final String RELATIONSHIPTYPE_TAG_PROPAGATION_KEY = "tagPropagation"; public static final String RELATIONSHIPTYPE_TAG_PROPAGATION_KEY = "tagPropagation";
public static final String RELATIONSHIPTYPE_BLOCKED_PROPAGATED_CLASSIFICATIONS_KEY = "blockedPropagatedClassifications"; public static final String RELATIONSHIPTYPE_BLOCKED_PROPAGATED_CLASSIFICATIONS_KEY = "blockedPropagatedClassifications";
/** /**
* Trait names property key and index name. * Trait names property key and index name.
*/ */
public static final String TRAIT_NAMES_PROPERTY_KEY = INTERNAL_PROPERTY_KEY_PREFIX + "traitNames"; public static final String TRAIT_NAMES_PROPERTY_KEY = INTERNAL_PROPERTY_KEY_PREFIX + "traitNames";
public static final String PROPAGATED_TRAIT_NAMES_PROPERTY_KEY = INTERNAL_PROPERTY_KEY_PREFIX + "propagatedTraitNames"; public static final String PROPAGATED_TRAIT_NAMES_PROPERTY_KEY = INTERNAL_PROPERTY_KEY_PREFIX + "propagatedTraitNames";
public static final String VERSION_PROPERTY_KEY = INTERNAL_PROPERTY_KEY_PREFIX + "version"; public static final String VERSION_PROPERTY_KEY = INTERNAL_PROPERTY_KEY_PREFIX + "version";
public static final String STATE_PROPERTY_KEY = INTERNAL_PROPERTY_KEY_PREFIX + "state"; public static final String STATE_PROPERTY_KEY = INTERNAL_PROPERTY_KEY_PREFIX + "state";
public static final String CREATED_BY_KEY = INTERNAL_PROPERTY_KEY_PREFIX + "createdBy"; public static final String CREATED_BY_KEY = INTERNAL_PROPERTY_KEY_PREFIX + "createdBy";
public static final String MODIFIED_BY_KEY = INTERNAL_PROPERTY_KEY_PREFIX + "modifiedBy"; public static final String MODIFIED_BY_KEY = INTERNAL_PROPERTY_KEY_PREFIX + "modifiedBy";
public static final String TIMESTAMP_PROPERTY_KEY = INTERNAL_PROPERTY_KEY_PREFIX + "timestamp"; public static final String TIMESTAMP_PROPERTY_KEY = INTERNAL_PROPERTY_KEY_PREFIX + "timestamp";
public static final String MODIFICATION_TIMESTAMP_PROPERTY_KEY = public static final String MODIFICATION_TIMESTAMP_PROPERTY_KEY =
INTERNAL_PROPERTY_KEY_PREFIX + "modificationTimestamp"; INTERNAL_PROPERTY_KEY_PREFIX + "modificationTimestamp";
/** /**
* search backing index name. * search backing index name.
...@@ -100,23 +100,23 @@ public final class Constants { ...@@ -100,23 +100,23 @@ public final class Constants {
public static final String FULLTEXT_INDEX = "fulltext_index"; public static final String FULLTEXT_INDEX = "fulltext_index";
public static final String QUALIFIED_NAME = "Referenceable.qualifiedName"; public static final String QUALIFIED_NAME = "Referenceable.qualifiedName";
public static final String TYPE_NAME_PROPERTY_KEY = INTERNAL_PROPERTY_KEY_PREFIX + "typeName"; public static final String TYPE_NAME_PROPERTY_KEY = INTERNAL_PROPERTY_KEY_PREFIX + "typeName";
public static final String INDEX_SEARCH_MAX_RESULT_SET_SIZE = "atlas.graph.index.search.max-result-set-size"; public static final String INDEX_SEARCH_MAX_RESULT_SET_SIZE = "atlas.graph.index.search.max-result-set-size";
public static final String INDEX_SEARCH_TYPES_MAX_QUERY_STR_LENGTH = "atlas.graph.index.search.types.max-query-str-length"; public static final String INDEX_SEARCH_TYPES_MAX_QUERY_STR_LENGTH = "atlas.graph.index.search.types.max-query-str-length";
public static final String INDEX_SEARCH_TAGS_MAX_QUERY_STR_LENGTH = "atlas.graph.index.search.tags.max-query-str-length"; public static final String INDEX_SEARCH_TAGS_MAX_QUERY_STR_LENGTH = "atlas.graph.index.search.tags.max-query-str-length";
public static final String INDEX_SEARCH_VERTEX_PREFIX_PROPERTY = "atlas.graph.index.search.vertex.prefix"; public static final String INDEX_SEARCH_VERTEX_PREFIX_PROPERTY = "atlas.graph.index.search.vertex.prefix";
public static final String INDEX_SEARCH_VERTEX_PREFIX_DEFAULT = "$v$"; public static final String INDEX_SEARCH_VERTEX_PREFIX_DEFAULT = "$v$";
public static final String MAX_FULLTEXT_QUERY_STR_LENGTH = "atlas.graph.fulltext-max-query-str-length"; public static final String MAX_FULLTEXT_QUERY_STR_LENGTH = "atlas.graph.fulltext-max-query-str-length";
public static final String MAX_DSL_QUERY_STR_LENGTH = "atlas.graph.dsl-max-query-str-length"; public static final String MAX_DSL_QUERY_STR_LENGTH = "atlas.graph.dsl-max-query-str-length";
public static final String ATTRIBUTE_NAME_GUID = "guid"; public static final String ATTRIBUTE_NAME_GUID = "guid";
public static final String ATTRIBUTE_NAME_TYPENAME = "typeName"; public static final String ATTRIBUTE_NAME_TYPENAME = "typeName";
public static final String ATTRIBUTE_NAME_SUPERTYPENAMES = "superTypeNames"; public static final String ATTRIBUTE_NAME_SUPERTYPENAMES = "superTypeNames";
public static final String ATTRIBUTE_NAME_STATE = "state"; public static final String ATTRIBUTE_NAME_STATE = "state";
public static final String ATTRIBUTE_NAME_VERSION = "version"; public static final String ATTRIBUTE_NAME_VERSION = "version";
public static final String TEMP_STRUCT_NAME_PREFIX = "__tempQueryResultStruct"; public static final String TEMP_STRUCT_NAME_PREFIX = "__tempQueryResultStruct";
public static final String CLASSIFICATION_ENTITY_GUID = INTERNAL_PROPERTY_KEY_PREFIX + "entityGuid"; public static final String CLASSIFICATION_ENTITY_GUID = INTERNAL_PROPERTY_KEY_PREFIX + "entityGuid";
public static final String CLASSIFICATION_VALIDITY_PERIODS_KEY = INTERNAL_PROPERTY_KEY_PREFIX + "validityPeriods"; public static final String CLASSIFICATION_VALIDITY_PERIODS_KEY = INTERNAL_PROPERTY_KEY_PREFIX + "validityPeriods";
...@@ -126,9 +126,10 @@ public final class Constants { ...@@ -126,9 +126,10 @@ public final class Constants {
public static final String CLASSIFICATION_EDGE_IS_PROPAGATED_PROPERTY_KEY = INTERNAL_PROPERTY_KEY_PREFIX + "isPropagated"; public static final String CLASSIFICATION_EDGE_IS_PROPAGATED_PROPERTY_KEY = INTERNAL_PROPERTY_KEY_PREFIX + "isPropagated";
public static final String CLASSIFICATION_EDGE_STATE_PROPERTY_KEY = STATE_PROPERTY_KEY; public static final String CLASSIFICATION_EDGE_STATE_PROPERTY_KEY = STATE_PROPERTY_KEY;
public static final String CLASSIFICATION_LABEL = "classifiedAs"; public static final String CLASSIFICATION_LABEL = "classifiedAs";
public static final String TERM_ASSIGNMENT_LABEL = "r:__AtlasGlossarySemanticAssignment";
public static final String VERTEX_ID_IN_IMPORT_KEY = "__vIdInImport"; public static final String VERTEX_ID_IN_IMPORT_KEY = "__vIdInImport";
public static final String EDGE_ID_IN_IMPORT_KEY = "__eIdInImport"; public static final String EDGE_ID_IN_IMPORT_KEY = "__eIdInImport";
private Constants() { private Constants() {
} }
......
...@@ -128,9 +128,16 @@ public enum AtlasErrorCode { ...@@ -128,9 +128,16 @@ public enum AtlasErrorCode {
NO_CLASSIFICATIONS_FOUND_FOR_ENTITY(400, "ATLAS-400-00-06E", "No classifications associated with entity: {0}"), NO_CLASSIFICATIONS_FOUND_FOR_ENTITY(400, "ATLAS-400-00-06E", "No classifications associated with entity: {0}"),
INVALID_CLASSIFICATION_PARAMS(400, "ATLAS-400-00-06F", "Invalid classification parameters passed for {0} operation for entity: {1}"), INVALID_CLASSIFICATION_PARAMS(400, "ATLAS-400-00-06F", "Invalid classification parameters passed for {0} operation for entity: {1}"),
PROPAGATED_CLASSIFICATION_NOT_ASSOCIATED_WITH_ENTITY(400, "ATLAS-400-00-070", "Propagated classification {0} is not associated with entity"), PROPAGATED_CLASSIFICATION_NOT_ASSOCIATED_WITH_ENTITY(400, "ATLAS-400-00-070", "Propagated classification {0} is not associated with entity"),
INVALID_PARTIAL_UPDATE_ATTR_VAL(400, "ATLAS-400-00-071", "Invalid attrVal for partial update of {0}, expected = {1} found {2}"), 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_ANCHOR(400, "ATLAS-400-00-072", "Mandatory anchor attribute is missing"),
INVALID_BLOCKED_PROPAGATED_CLASSIFICATION(400, "ATLAS-400-00-073", "Invalid propagated classification: {0} with entityGuid: {1} added to blocked propagated classifications."), 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"),
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}"),
......
...@@ -23,7 +23,7 @@ import org.apache.atlas.model.annotation.AtlasJSON; ...@@ -23,7 +23,7 @@ import org.apache.atlas.model.annotation.AtlasJSON;
import org.apache.atlas.model.glossary.relations.AtlasGlossaryHeader; import org.apache.atlas.model.glossary.relations.AtlasGlossaryHeader;
import org.apache.atlas.model.glossary.relations.AtlasRelatedTermHeader; import org.apache.atlas.model.glossary.relations.AtlasRelatedTermHeader;
import org.apache.atlas.model.glossary.relations.AtlasTermCategorizationHeader; import org.apache.atlas.model.glossary.relations.AtlasTermCategorizationHeader;
import org.apache.atlas.model.instance.AtlasEntityHeader; import org.apache.atlas.model.instance.AtlasRelatedObjectId;
import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.CollectionUtils;
import java.util.HashMap; import java.util.HashMap;
...@@ -42,7 +42,7 @@ public class AtlasGlossaryTerm extends AtlasGlossaryBaseObject { ...@@ -42,7 +42,7 @@ public class AtlasGlossaryTerm extends AtlasGlossaryBaseObject {
// Attributes derived from relationships // Attributes derived from relationships
private AtlasGlossaryHeader anchor; private AtlasGlossaryHeader anchor;
private Set<AtlasEntityHeader> assignedEntities; private Set<AtlasRelatedObjectId> assignedEntities;
private Set<AtlasTermCategorizationHeader> categories; private Set<AtlasTermCategorizationHeader> categories;
// Related Terms // Related Terms
...@@ -128,21 +128,21 @@ public class AtlasGlossaryTerm extends AtlasGlossaryBaseObject { ...@@ -128,21 +128,21 @@ public class AtlasGlossaryTerm extends AtlasGlossaryBaseObject {
setCategories(categories); setCategories(categories);
} }
public Set<AtlasEntityHeader> getAssignedEntities() { public Set<AtlasRelatedObjectId> getAssignedEntities() {
return assignedEntities; return assignedEntities;
} }
public void setAssignedEntities(final Set<AtlasEntityHeader> assignedEntities) { public void setAssignedEntities(final Set<AtlasRelatedObjectId> assignedEntities) {
this.assignedEntities = assignedEntities; this.assignedEntities = assignedEntities;
} }
public void addAssignedEntity(final AtlasEntityHeader entityHeader) { public void addAssignedEntity(final AtlasRelatedObjectId atlasObjectId) {
Set<AtlasEntityHeader> entityHeaders = this.assignedEntities; Set<AtlasRelatedObjectId> assignedEntities = this.assignedEntities;
if (entityHeaders == null) { if (assignedEntities == null) {
entityHeaders = new HashSet<>(); assignedEntities = new HashSet<>();
} }
entityHeaders.add(entityHeader); assignedEntities.add(atlasObjectId);
setAssignedEntities(entityHeaders); setAssignedEntities(assignedEntities);
} }
public Set<AtlasRelatedTermHeader> getSeeAlso() { public Set<AtlasRelatedTermHeader> getSeeAlso() {
......
...@@ -24,6 +24,7 @@ import java.util.Objects; ...@@ -24,6 +24,7 @@ import java.util.Objects;
@AtlasJSON @AtlasJSON
public class AtlasRelatedCategoryHeader { public class AtlasRelatedCategoryHeader {
private String categoryGuid; private String categoryGuid;
private String parentCategoryGuid;
private String relationGuid; private String relationGuid;
private String displayText; private String displayText;
private String description; private String description;
...@@ -61,6 +62,7 @@ public class AtlasRelatedCategoryHeader { ...@@ -61,6 +62,7 @@ public class AtlasRelatedCategoryHeader {
if (!(o instanceof AtlasRelatedCategoryHeader)) return false; if (!(o instanceof AtlasRelatedCategoryHeader)) return false;
final AtlasRelatedCategoryHeader that = (AtlasRelatedCategoryHeader) o; final AtlasRelatedCategoryHeader that = (AtlasRelatedCategoryHeader) o;
return Objects.equals(categoryGuid, that.categoryGuid) && return Objects.equals(categoryGuid, that.categoryGuid) &&
Objects.equals(parentCategoryGuid, that.parentCategoryGuid) &&
Objects.equals(displayText, that.displayText) && Objects.equals(displayText, that.displayText) &&
Objects.equals(description, that.description); Objects.equals(description, that.description);
} }
...@@ -68,13 +70,14 @@ public class AtlasRelatedCategoryHeader { ...@@ -68,13 +70,14 @@ public class AtlasRelatedCategoryHeader {
@Override @Override
public int hashCode() { public int hashCode() {
return Objects.hash(categoryGuid, displayText, description); return Objects.hash(categoryGuid, parentCategoryGuid, displayText, description);
} }
@Override @Override
public String toString() { public String toString() {
final StringBuilder sb = new StringBuilder("AtlasRelatedCategoryId{"); final StringBuilder sb = new StringBuilder("AtlasRelatedCategoryId{");
sb.append("categoryGuid='").append(categoryGuid).append('\''); sb.append("categoryGuid='").append(categoryGuid).append('\'');
sb.append(", parentCategoryGuid='").append(parentCategoryGuid).append('\'');
sb.append(", relationGuid='").append(relationGuid).append('\''); sb.append(", relationGuid='").append(relationGuid).append('\'');
sb.append(", displayText='").append(displayText).append('\''); sb.append(", displayText='").append(displayText).append('\'');
sb.append(", description='").append(description).append('\''); sb.append(", description='").append(description).append('\'');
...@@ -90,4 +93,12 @@ public class AtlasRelatedCategoryHeader { ...@@ -90,4 +93,12 @@ public class AtlasRelatedCategoryHeader {
public void setRelationGuid(final String relationGuid) { public void setRelationGuid(final String relationGuid) {
this.relationGuid = relationGuid; this.relationGuid = relationGuid;
} }
public String getParentCategoryGuid() {
return parentCategoryGuid;
}
public void setParentCategoryGuid(final String parentCategoryGuid) {
this.parentCategoryGuid = parentCategoryGuid;
}
} }
...@@ -475,7 +475,7 @@ public class EntityDiscoveryService implements AtlasDiscoveryService { ...@@ -475,7 +475,7 @@ public class EntityDiscoveryService implements AtlasDiscoveryService {
AtlasObjectId objId = (AtlasObjectId) attrValue; AtlasObjectId objId = (AtlasObjectId) attrValue;
if (ret.getReferredEntities() == null) { if (ret.getReferredEntities() == null) {
ret.setReferredEntities(new HashMap<String, AtlasEntityHeader>()); ret.setReferredEntities(new HashMap<>());
} }
if (!ret.getReferredEntities().containsKey(objId.getGuid())) { if (!ret.getReferredEntities().containsKey(objId.getGuid())) {
...@@ -489,7 +489,7 @@ public class EntityDiscoveryService implements AtlasDiscoveryService { ...@@ -489,7 +489,7 @@ public class EntityDiscoveryService implements AtlasDiscoveryService {
AtlasObjectId objId = (AtlasObjectId) obj; AtlasObjectId objId = (AtlasObjectId) obj;
if (ret.getReferredEntities() == null) { if (ret.getReferredEntities() == null) {
ret.setReferredEntities(new HashMap<String, AtlasEntityHeader>()); ret.setReferredEntities(new HashMap<>());
} }
if (!ret.getReferredEntities().containsKey(objId.getGuid())) { if (!ret.getReferredEntities().containsKey(objId.getGuid())) {
......
/**
* 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
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* 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.glossary;
import org.apache.atlas.AtlasErrorCode;
import org.apache.atlas.exception.AtlasBaseException;
import org.apache.atlas.model.glossary.relations.AtlasRelatedTermHeader;
import org.apache.atlas.model.instance.AtlasRelationship;
import org.apache.atlas.repository.store.graph.AtlasRelationshipStore;
import org.apache.atlas.type.AtlasTypeRegistry;
import java.util.Objects;
public abstract class GlossaryUtils {
public static final String TERM_ASSIGNMENT_ATTR_DESCRIPTION = "description";
public static final String TERM_ASSIGNMENT_ATTR_EXPRESSION = "expression";
public static final String TERM_ASSIGNMENT_ATTR_STATUS = "status";
public static final String TERM_ASSIGNMENT_ATTR_CONFIDENCE = "confidence";
public static final String TERM_ASSIGNMENT_ATTR_CREATED_BY = "createdBy";
public static final String TERM_ASSIGNMENT_ATTR_STEWARD = "steward";
public static final String TERM_ASSIGNMENT_ATTR_SOURCE = "source";
static final String ATLAS_GLOSSARY_PREFIX = "__AtlasGlossary";
// Relation name constants
protected static final String TERM_ANCHOR = ATLAS_GLOSSARY_PREFIX + "TermAnchor";
protected static final String CATEGORY_ANCHOR = ATLAS_GLOSSARY_PREFIX + "CategoryAnchor";
protected static final String CATEGORY_HIERARCHY = ATLAS_GLOSSARY_PREFIX + "CategoryHierarchyLink";
protected static final String TERM_CATEGORIZATION = ATLAS_GLOSSARY_PREFIX + "TermCategorization";
protected static final String TERM_ASSIGNMENT = ATLAS_GLOSSARY_PREFIX + "SemanticAssignment";
protected static final String TERM_RELATION_ATTR_EXPRESSION = "expression";
protected static final String TERM_RELATION_ATTR_DESCRIPTION = "description";
protected static final String TERM_RELATION_ATTR_STEWARD = "steward";
protected static final String TERM_RELATION_ATTR_SOURCE = "source";
protected static final String TERM_RELATION_ATTR_STATUS = "status";
protected final AtlasRelationshipStore relationshipStore;
protected final AtlasTypeRegistry typeRegistry;
protected GlossaryUtils(final AtlasRelationshipStore relationshipStore, final AtlasTypeRegistry typeRegistry) {
this.relationshipStore = relationshipStore;
this.typeRegistry = typeRegistry;
}
protected void createRelationship(AtlasRelationship relationship) throws AtlasBaseException {
try {
relationshipStore.create(relationship);
} catch (AtlasBaseException e) {
if (!e.getAtlasErrorCode().equals(AtlasErrorCode.RELATIONSHIP_ALREADY_EXISTS)) {
throw e;
}
}
}
protected void updateRelationshipAttributes(AtlasRelationship relationship, AtlasRelatedTermHeader relatedTermHeader) {
if (Objects.nonNull(relationship)) {
relationship.setAttribute(TERM_RELATION_ATTR_EXPRESSION, relatedTermHeader.getExpression());
relationship.setAttribute(TERM_RELATION_ATTR_DESCRIPTION, relatedTermHeader.getDescription());
relationship.setAttribute(TERM_RELATION_ATTR_STEWARD, relatedTermHeader.getSteward());
relationship.setAttribute(TERM_RELATION_ATTR_SOURCE, relatedTermHeader.getSource());
if (Objects.nonNull(relatedTermHeader.getStatus())) {
relationship.setAttribute(TERM_RELATION_ATTR_STATUS, relatedTermHeader.getStatus().name());
}
}
}
enum RelationshipOperation {
CREATE, UPDATE, DELETE
}
}
...@@ -113,7 +113,13 @@ public class DataAccess { ...@@ -113,7 +113,13 @@ public class DataAccess {
List<AtlasBaseModelObject> ret = new ArrayList<>(); List<AtlasBaseModelObject> ret = new ArrayList<>();
for (T object : objects) { for (T object : objects) {
ret.add(load(object)); try {
ret.add(load(object));
} catch (AtlasBaseException e) {
// In case of bulk load, some entities might be in deleted state causing an exception to be thrown
// by the single load API call
LOG.warn("Bulk load encountered an error.", e);
}
} }
return (Iterable<T>) ret; return (Iterable<T>) ret;
......
...@@ -20,7 +20,6 @@ package org.apache.atlas.repository.ogm.glossary; ...@@ -20,7 +20,6 @@ package org.apache.atlas.repository.ogm.glossary;
import org.apache.atlas.exception.AtlasBaseException; import org.apache.atlas.exception.AtlasBaseException;
import org.apache.atlas.model.glossary.AtlasGlossaryTerm; import org.apache.atlas.model.glossary.AtlasGlossaryTerm;
import org.apache.atlas.model.instance.AtlasEntity; import org.apache.atlas.model.instance.AtlasEntity;
import org.apache.atlas.model.instance.AtlasEntityHeader;
import org.apache.atlas.model.instance.AtlasRelatedObjectId; import org.apache.atlas.model.instance.AtlasRelatedObjectId;
import org.apache.atlas.model.instance.AtlasRelationship; import org.apache.atlas.model.instance.AtlasRelationship;
import org.apache.atlas.type.AtlasTypeRegistry; import org.apache.atlas.type.AtlasTypeRegistry;
...@@ -92,12 +91,7 @@ public class AtlasGlossaryTermDTO extends AbstractGlossaryDTO<AtlasGlossaryTerm> ...@@ -92,12 +91,7 @@ public class AtlasGlossaryTermDTO extends AbstractGlossaryDTO<AtlasGlossaryTerm>
if (assignedEntity instanceof AtlasRelatedObjectId) { if (assignedEntity instanceof AtlasRelatedObjectId) {
AtlasRelatedObjectId id = (AtlasRelatedObjectId) assignedEntity; AtlasRelatedObjectId id = (AtlasRelatedObjectId) assignedEntity;
if (id.getRelationshipStatus() == AtlasRelationship.Status.ACTIVE) { if (id.getRelationshipStatus() == AtlasRelationship.Status.ACTIVE) {
AtlasEntityHeader entityHeader = new AtlasEntityHeader(id.getTypeName(), id.getGuid(), id.getUniqueAttributes()); ret.addAssignedEntity(id);
if (entityHeader.getAttributes() == null) {
entityHeader.setAttributes(new HashMap<>());
}
entityHeader.getAttributes().put("relationGuid", id.getRelationshipGuid());
ret.addAssignedEntity(entityHeader);
} }
} }
} }
......
/** /**
* Licensed to the Apache Software Foundation (ASF) under one * Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file * or more contributor license agreements. See the NOTICE file
......
...@@ -21,6 +21,7 @@ import com.fasterxml.jackson.core.type.TypeReference; ...@@ -21,6 +21,7 @@ import com.fasterxml.jackson.core.type.TypeReference;
import org.apache.atlas.AtlasErrorCode; import org.apache.atlas.AtlasErrorCode;
import org.apache.atlas.exception.AtlasBaseException; import org.apache.atlas.exception.AtlasBaseException;
import org.apache.atlas.model.TimeBoundary; import org.apache.atlas.model.TimeBoundary;
import org.apache.atlas.model.glossary.enums.AtlasTermAssignmentStatus;
import org.apache.atlas.model.glossary.relations.AtlasTermAssignmentHeader; import org.apache.atlas.model.glossary.relations.AtlasTermAssignmentHeader;
import org.apache.atlas.model.instance.AtlasClassification; import org.apache.atlas.model.instance.AtlasClassification;
import org.apache.atlas.model.instance.AtlasClassification.PropagationState; import org.apache.atlas.model.instance.AtlasClassification.PropagationState;
...@@ -71,30 +72,16 @@ import java.util.Map; ...@@ -71,30 +72,16 @@ import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import static org.apache.atlas.glossary.GlossaryUtils.*;
import static org.apache.atlas.model.instance.AtlasClassification.PropagationState.ACTIVE; import static org.apache.atlas.model.instance.AtlasClassification.PropagationState.ACTIVE;
import static org.apache.atlas.model.instance.AtlasClassification.PropagationState.DELETED; import static org.apache.atlas.model.instance.AtlasClassification.PropagationState.DELETED;
import static org.apache.atlas.model.typedef.AtlasBaseTypeDef.*; import static org.apache.atlas.model.typedef.AtlasBaseTypeDef.*;
import static org.apache.atlas.model.typedef.AtlasRelationshipDef.PropagateTags.ONE_TO_TWO; import static org.apache.atlas.model.typedef.AtlasRelationshipDef.PropagateTags.ONE_TO_TWO;
import static org.apache.atlas.repository.Constants.*; import static org.apache.atlas.repository.Constants.CLASSIFICATION_ENTITY_GUID;
import static org.apache.atlas.repository.graph.GraphHelper.EDGE_LABEL_PREFIX; import static org.apache.atlas.repository.Constants.CLASSIFICATION_LABEL;
import static org.apache.atlas.repository.graph.GraphHelper.addToPropagatedTraitNames; import static org.apache.atlas.repository.Constants.CLASSIFICATION_VALIDITY_PERIODS_KEY;
import static org.apache.atlas.repository.graph.GraphHelper.getAdjacentEdgesByLabel; import static org.apache.atlas.repository.Constants.TERM_ASSIGNMENT_LABEL;
import static org.apache.atlas.repository.graph.GraphHelper.getAllClassificationEdges; import static org.apache.atlas.repository.graph.GraphHelper.*;
import static org.apache.atlas.repository.graph.GraphHelper.getAllTraitNames;
import static org.apache.atlas.repository.graph.GraphHelper.getAssociatedEntityVertex;
import static org.apache.atlas.repository.graph.GraphHelper.getBlockedClassificationIds;
import static org.apache.atlas.repository.graph.GraphHelper.getClassificationEdge;
import static org.apache.atlas.repository.graph.GraphHelper.getClassificationEdgeState;
import static org.apache.atlas.repository.graph.GraphHelper.getGuid;
import static org.apache.atlas.repository.graph.GraphHelper.getIncomingEdgesByLabel;
import static org.apache.atlas.repository.graph.GraphHelper.getOutGoingEdgesByLabel;
import static org.apache.atlas.repository.graph.GraphHelper.getPropagateTags;
import static org.apache.atlas.repository.graph.GraphHelper.getPropagatedClassificationEdge;
import static org.apache.atlas.repository.graph.GraphHelper.getRelationshipGuid;
import static org.apache.atlas.repository.graph.GraphHelper.getTypeName;
import static org.apache.atlas.repository.graph.GraphHelper.isPropagatedClassificationEdge;
import static org.apache.atlas.repository.graph.GraphHelper.isPropagationEnabled;
import static org.apache.atlas.repository.graph.GraphHelper.removeFromPropagatedTraitNames;
import static org.apache.atlas.repository.store.graph.v1.AtlasGraphUtilsV1.getIdFromVertex; import static org.apache.atlas.repository.store.graph.v1.AtlasGraphUtilsV1.getIdFromVertex;
import static org.apache.atlas.type.AtlasStructType.AtlasAttribute.AtlasRelationshipEdgeDirection; import static org.apache.atlas.type.AtlasStructType.AtlasAttribute.AtlasRelationshipEdgeDirection;
import static org.apache.atlas.type.AtlasStructType.AtlasAttribute.AtlasRelationshipEdgeDirection.BOTH; import static org.apache.atlas.type.AtlasStructType.AtlasAttribute.AtlasRelationshipEdgeDirection.BOTH;
...@@ -105,7 +92,11 @@ import static org.apache.atlas.type.AtlasStructType.AtlasAttribute.AtlasRelation ...@@ -105,7 +92,11 @@ import static org.apache.atlas.type.AtlasStructType.AtlasAttribute.AtlasRelation
public final class EntityGraphRetriever { public final class EntityGraphRetriever {
private static final Logger LOG = LoggerFactory.getLogger(EntityGraphRetriever.class); private static final Logger LOG = LoggerFactory.getLogger(EntityGraphRetriever.class);
private static final String TERM_RELATION_NAME = "__AtlasGlossarySemanticAssignment";
private static final String GLOSSARY_TERM_DISPLAY_NAME_ATTR = "__AtlasGlossaryTerm.displayName";
private final String NAME = "name"; private final String NAME = "name";
private final String DISPLAY_NAME = "displayName";
private final String DESCRIPTION = "description"; private final String DESCRIPTION = "description";
private final String OWNER = "owner"; private final String OWNER = "owner";
private final String CREATE_TIME = "createTime"; private final String CREATE_TIME = "createTime";
...@@ -368,7 +359,9 @@ public final class EntityGraphRetriever { ...@@ -368,7 +359,9 @@ public final class EntityGraphRetriever {
ret.setStatus(GraphHelper.getStatus(entityVertex)); ret.setStatus(GraphHelper.getStatus(entityVertex));
ret.setClassificationNames(getAllTraitNames(entityVertex)); ret.setClassificationNames(getAllTraitNames(entityVertex));
// TODO: Add the term mapping here List<AtlasTermAssignmentHeader> termAssignmentHeaders = mapAssignedTerms(entityVertex);
ret.setMeanings(termAssignmentHeaders);
ret.setMeaningNames(termAssignmentHeaders.stream().map(AtlasTermAssignmentHeader::getDisplayText).collect(Collectors.toList()));
AtlasEntityType entityType = typeRegistry.getEntityTypeByName(typeName); AtlasEntityType entityType = typeRegistry.getEntityTypeByName(typeName);
...@@ -410,6 +403,7 @@ public final class EntityGraphRetriever { ...@@ -410,6 +403,7 @@ public final class EntityGraphRetriever {
} }
} }
} }
} }
return ret; return ret;
...@@ -503,6 +497,85 @@ public final class EntityGraphRetriever { ...@@ -503,6 +497,85 @@ public final class EntityGraphRetriever {
return ret; return ret;
} }
public List<AtlasTermAssignmentHeader> mapAssignedTerms(AtlasVertex entityVertex) throws AtlasBaseException {
List<AtlasTermAssignmentHeader> ret = new ArrayList<>();
Iterable edges = entityVertex.query().direction(AtlasEdgeDirection.IN).label(TERM_ASSIGNMENT_LABEL).edges();
if (edges != null) {
Iterator<AtlasEdge> iterator = edges.iterator();
while (iterator.hasNext()) {
AtlasEdge edge = iterator.next();
if (edge != null) {
ret.add(toTermAssignmentHeader(edge));
}
}
}
return ret;
}
private AtlasTermAssignmentHeader toTermAssignmentHeader(final AtlasEdge edge) {
AtlasTermAssignmentHeader ret = new AtlasTermAssignmentHeader();
AtlasVertex termVertex = edge.getOutVertex();
String guid = GraphHelper.getGuid(termVertex);
if (guid != null) {
ret.setTermGuid(guid);
}
String relationGuid = edge.getProperty(Constants.RELATIONSHIP_GUID_PROPERTY_KEY, String.class);
if (relationGuid != null) {
ret.setRelationGuid(relationGuid);
}
Object displayName = GraphHelper.getProperty(termVertex, GLOSSARY_TERM_DISPLAY_NAME_ATTR);
if (displayName instanceof String) {
ret.setDisplayText((String) displayName);
}
String description = edge.getProperty(TERM_ASSIGNMENT_ATTR_DESCRIPTION, String.class);
if (description != null) {
ret.setDescription(description);
}
String expression = edge.getProperty(TERM_ASSIGNMENT_ATTR_EXPRESSION, String.class);
if (expression != null) {
ret.setExpression(expression);
}
String status = edge.getProperty(TERM_ASSIGNMENT_ATTR_STATUS, String.class);
if (status != null) {
AtlasTermAssignmentStatus assignmentStatus = AtlasTermAssignmentStatus.valueOf(status);
ret.setStatus(assignmentStatus);
}
Integer confidence = edge.getProperty(TERM_ASSIGNMENT_ATTR_CONFIDENCE, Integer.class);
if (confidence != null) {
ret.setConfidence(confidence);
}
String createdBy = edge.getProperty(TERM_ASSIGNMENT_ATTR_CREATED_BY, String.class);
if (createdBy != null) {
ret.setCreatedBy(createdBy);
}
String steward = edge.getProperty(TERM_ASSIGNMENT_ATTR_STEWARD, String.class);
if (steward != null) {
ret.setSteward(steward);
}
String source = edge.getProperty(TERM_ASSIGNMENT_ATTR_SOURCE, String.class);
if (source != null) {
ret.setSource(source);
}
return ret;
}
private void mapClassifications(AtlasVertex entityVertex, AtlasEntity entity) throws AtlasBaseException { private void mapClassifications(AtlasVertex entityVertex, AtlasEntity entity) throws AtlasBaseException {
List<AtlasEdge> edges = getAllClassificationEdges(entityVertex); List<AtlasEdge> edges = getAllClassificationEdges(entityVertex);
...@@ -881,6 +954,10 @@ public final class EntityGraphRetriever { ...@@ -881,6 +954,10 @@ public final class EntityGraphRetriever {
ret = getVertexAttribute(entityVertex, entityType.getAttribute(NAME)); ret = getVertexAttribute(entityVertex, entityType.getAttribute(NAME));
if (ret == null) { if (ret == null) {
ret = getVertexAttribute(entityVertex, entityType.getAttribute(DISPLAY_NAME));
}
if (ret == null) {
ret = getVertexAttribute(entityVertex, entityType.getAttribute(QUALIFIED_NAME)); ret = getVertexAttribute(entityVertex, entityType.getAttribute(QUALIFIED_NAME));
} }
} }
......
...@@ -26,7 +26,7 @@ import org.apache.atlas.model.glossary.AtlasGlossaryCategory; ...@@ -26,7 +26,7 @@ import org.apache.atlas.model.glossary.AtlasGlossaryCategory;
import org.apache.atlas.model.glossary.AtlasGlossaryTerm; import org.apache.atlas.model.glossary.AtlasGlossaryTerm;
import org.apache.atlas.model.glossary.relations.AtlasRelatedCategoryHeader; import org.apache.atlas.model.glossary.relations.AtlasRelatedCategoryHeader;
import org.apache.atlas.model.glossary.relations.AtlasRelatedTermHeader; import org.apache.atlas.model.glossary.relations.AtlasRelatedTermHeader;
import org.apache.atlas.model.instance.AtlasEntityHeader; import org.apache.atlas.model.instance.AtlasRelatedObjectId;
import org.apache.atlas.utils.AtlasPerfTracer; import org.apache.atlas.utils.AtlasPerfTracer;
import org.apache.atlas.web.util.Servlets; import org.apache.atlas.web.util.Servlets;
import org.apache.commons.collections.MapUtils; import org.apache.commons.collections.MapUtils;
...@@ -723,10 +723,10 @@ public class GlossaryREST { ...@@ -723,10 +723,10 @@ public class GlossaryREST {
*/ */
@GET @GET
@Path("/terms/{termGuid}/assignedEntities") @Path("/terms/{termGuid}/assignedEntities")
public List<AtlasEntityHeader> getEntitiesAssignedWithTerm(@PathParam("termGuid") String termGuid, public List<AtlasRelatedObjectId> getEntitiesAssignedWithTerm(@PathParam("termGuid") String termGuid,
@DefaultValue("-1") @QueryParam("limit") String limit, @DefaultValue("-1") @QueryParam("limit") String limit,
@DefaultValue("0") @QueryParam("offset") String offset, @DefaultValue("0") @QueryParam("offset") String offset,
@DefaultValue("ASC") @QueryParam("sort") final String sort) throws AtlasBaseException { @DefaultValue("ASC") @QueryParam("sort") final String sort) throws AtlasBaseException {
Servlets.validateQueryParamLength("termGuid", termGuid); Servlets.validateQueryParamLength("termGuid", termGuid);
AtlasPerfTracer perf = null; AtlasPerfTracer perf = null;
...@@ -746,7 +746,7 @@ public class GlossaryREST { ...@@ -746,7 +746,7 @@ public class GlossaryREST {
/** /**
* Assign the given term to the provided list of entity headers * Assign the given term to the provided list of entity headers
* @param termGuid Glossary term GUID * @param termGuid Glossary term GUID
* @param entityHeaders Entity headers for which the term has to be associated * @param relatedObjectIds Related Entity IDs to which the term has to be associated
* @throws AtlasBaseException * @throws AtlasBaseException
* @HTTP 204 If the term assignment was successful * @HTTP 204 If the term assignment was successful
* @HTTP 400 If ANY of the entity header is invalid * @HTTP 400 If ANY of the entity header is invalid
...@@ -754,7 +754,7 @@ public class GlossaryREST { ...@@ -754,7 +754,7 @@ public class GlossaryREST {
*/ */
@POST @POST
@Path("/terms/{termGuid}/assignedEntities") @Path("/terms/{termGuid}/assignedEntities")
public void assignTermToEntities(@PathParam("termGuid") String termGuid, List<AtlasEntityHeader> entityHeaders) throws AtlasBaseException { public void assignTermToEntities(@PathParam("termGuid") String termGuid, List<AtlasRelatedObjectId> relatedObjectIds) throws AtlasBaseException {
Servlets.validateQueryParamLength("termGuid", termGuid); Servlets.validateQueryParamLength("termGuid", termGuid);
AtlasPerfTracer perf = null; AtlasPerfTracer perf = null;
...@@ -763,7 +763,7 @@ public class GlossaryREST { ...@@ -763,7 +763,7 @@ public class GlossaryREST {
perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "GlossaryREST.assignTermToEntities(" + termGuid + ")"); perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "GlossaryREST.assignTermToEntities(" + termGuid + ")");
} }
glossaryService.assignTermToEntities(termGuid, entityHeaders); glossaryService.assignTermToEntities(termGuid, relatedObjectIds);
} finally { } finally {
AtlasPerfTracer.log(perf); AtlasPerfTracer.log(perf);
} }
...@@ -772,7 +772,7 @@ public class GlossaryREST { ...@@ -772,7 +772,7 @@ public class GlossaryREST {
/** /**
* Remove the term assignment for the given list of entity headers * Remove the term assignment for the given list of entity headers
* @param termGuid Glossary term GUID * @param termGuid Glossary term GUID
* @param entityHeaders List of entity headers from which the term has to be dissociated * @param relatedObjectIds List of related entity IDs from which the term has to be dissociated
* @throws AtlasBaseException * @throws AtlasBaseException
* @HTTP 204 If glossary term dissociation was successful * @HTTP 204 If glossary term dissociation was successful
* @HTTP 400 If ANY of the entity header is invalid * @HTTP 400 If ANY of the entity header is invalid
...@@ -780,7 +780,7 @@ public class GlossaryREST { ...@@ -780,7 +780,7 @@ public class GlossaryREST {
*/ */
@DELETE @DELETE
@Path("/terms/{termGuid}/assignedEntities") @Path("/terms/{termGuid}/assignedEntities")
public void removeTermAssignmentFromEntities(@PathParam("termGuid") String termGuid, List<AtlasEntityHeader> entityHeaders) throws AtlasBaseException { public void removeTermAssignmentFromEntities(@PathParam("termGuid") String termGuid, List<AtlasRelatedObjectId> relatedObjectIds) throws AtlasBaseException {
Servlets.validateQueryParamLength("termGuid", termGuid); Servlets.validateQueryParamLength("termGuid", termGuid);
AtlasPerfTracer perf = null; AtlasPerfTracer perf = null;
...@@ -789,7 +789,7 @@ public class GlossaryREST { ...@@ -789,7 +789,7 @@ public class GlossaryREST {
perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "GlossaryREST.removeTermAssignmentFromEntities(" + termGuid + ")"); perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "GlossaryREST.removeTermAssignmentFromEntities(" + termGuid + ")");
} }
glossaryService.removeTermFromEntities(termGuid, entityHeaders); glossaryService.removeTermFromEntities(termGuid, relatedObjectIds);
} finally { } finally {
AtlasPerfTracer.log(perf); AtlasPerfTracer.log(perf);
} }
......
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