ATLAS-2836: Remove redundant encoding of vertex property keys ATLAS-2838: Replace GraphHelper.encodeProperty() with AtlasGraphUtilsV1.encodeProperty()
(cherry picked from commit b6a664df305d18918ea84ec1351307fcefeec53c) (cherry picked from commit 0ed9f0e25d2b064bb7728b2d8481968ba4375ba2) Project: http://git-wip-us.apache.org/repos/asf/atlas/repo Commit: http://git-wip-us.apache.org/repos/asf/atlas/commit/250d9321 Tree: http://git-wip-us.apache.org/repos/asf/atlas/tree/250d9321 Diff: http://git-wip-us.apache.org/repos/asf/atlas/diff/250d9321 Branch: refs/heads/branch-0.8 Commit: 250d932172291fe8c9a9e07afb634042f67b09e5 Parents: 325859a Author: Madhan Neethiraj <mad...@apache.org> Authored: Sun Aug 26 13:29:00 2018 -0700 Committer: Madhan Neethiraj <mad...@apache.org> Committed: Sun Aug 26 23:08:26 2018 -0700 ---------------------------------------------------------------------- .../org/apache/atlas/repository/Constants.java | 42 ++-- .../org/apache/atlas/type/AtlasStructType.java | 8 + .../graph/DefaultGraphPersistenceStrategy.java | 7 +- .../graph/GraphBackedDiscoveryService.java | 5 +- .../atlas/repository/graph/DeleteHandler.java | 15 +- .../graph/GraphBackedMetadataRepository.java | 15 +- .../graph/GraphBackedSearchIndexer.java | 7 +- .../atlas/repository/graph/GraphHelper.java | 205 +++---------------- .../graph/GraphToTypedInstanceMapper.java | 35 ++-- .../repository/graph/SoftDeleteHandler.java | 14 +- .../graph/TypedInstanceToGraphMapper.java | 19 +- .../graph/v1/AtlasEntityChangeNotifier.java | 6 +- .../store/graph/v1/AtlasGraphUtilsV1.java | 29 ++- .../store/graph/v1/AtlasStructDefStoreV1.java | 2 +- .../store/graph/v1/DeleteHandlerV1.java | 14 +- .../store/graph/v1/EntityGraphMapper.java | 58 +++--- .../store/graph/v1/EntityGraphRetriever.java | 50 ++--- .../store/graph/v1/SoftDeleteHandlerV1.java | 14 +- .../typestore/GraphBackedTypeStore.java | 24 +-- .../typestore/TypePersistenceVisitor.java | 14 +- ...hBackedMetadataRepositoryDeleteTestBase.java | 9 +- .../GraphBackedMetadataRepositoryTest.java | 15 +- .../GraphBackedRepositorySoftDeleteTest.java | 3 +- .../atlas/repository/graph/GraphHelperTest.java | 5 +- .../graph/v1/AtlasDeleteHandlerV1Test.java | 8 +- .../store/graph/v1/SoftDeleteHandlerV1Test.java | 2 +- 26 files changed, 257 insertions(+), 368 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/atlas/blob/250d9321/common/src/main/java/org/apache/atlas/repository/Constants.java ---------------------------------------------------------------------- diff --git a/common/src/main/java/org/apache/atlas/repository/Constants.java b/common/src/main/java/org/apache/atlas/repository/Constants.java index 56f341d..2733583 100644 --- a/common/src/main/java/org/apache/atlas/repository/Constants.java +++ b/common/src/main/java/org/apache/atlas/repository/Constants.java @@ -18,6 +18,8 @@ package org.apache.atlas.repository; +import static org.apache.atlas.type.AtlasStructType.AtlasAttribute.encodePropertyKey; + /** * Repository Constants. * @@ -29,49 +31,45 @@ public final class Constants { */ public static final String INTERNAL_PROPERTY_KEY_PREFIX = "__"; - public static final String GUID_PROPERTY_KEY = INTERNAL_PROPERTY_KEY_PREFIX + "guid"; + public static final String GUID_PROPERTY_KEY = encodePropertyKey(INTERNAL_PROPERTY_KEY_PREFIX + "guid"); /** * Entity type name property key. */ - public static final String ENTITY_TYPE_PROPERTY_KEY = INTERNAL_PROPERTY_KEY_PREFIX + "typeName"; + public static final String ENTITY_TYPE_PROPERTY_KEY = encodePropertyKey(INTERNAL_PROPERTY_KEY_PREFIX + "typeName"); public static final String TYPE_NAME_INTERNAL = INTERNAL_PROPERTY_KEY_PREFIX + "internal"; /** * Entity type's super types property key. */ - public static final String SUPER_TYPES_PROPERTY_KEY = INTERNAL_PROPERTY_KEY_PREFIX + "superTypeNames"; + public static final String SUPER_TYPES_PROPERTY_KEY = encodePropertyKey(INTERNAL_PROPERTY_KEY_PREFIX + "superTypeNames"); /** * Full-text for the entity for enabling full-text search. */ //weird issue in TitanDB if __ added to this property key. Not adding it for now - public static final String ENTITY_TEXT_PROPERTY_KEY = "entityText"; + public static final String ENTITY_TEXT_PROPERTY_KEY = encodePropertyKey("entityText"); /** * Properties for type store graph. */ - 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 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 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 TYPE_CATEGORY_PROPERTY_KEY = encodePropertyKey(INTERNAL_PROPERTY_KEY_PREFIX + "type.category"); + public static final String VERTEX_TYPE_PROPERTY_KEY = encodePropertyKey(INTERNAL_PROPERTY_KEY_PREFIX + "type"); + public static final String TYPENAME_PROPERTY_KEY = encodePropertyKey(INTERNAL_PROPERTY_KEY_PREFIX + "type.name"); + public static final String TYPEDESCRIPTION_PROPERTY_KEY = encodePropertyKey(INTERNAL_PROPERTY_KEY_PREFIX + "type.description"); + public static final String TYPEVERSION_PROPERTY_KEY = encodePropertyKey(INTERNAL_PROPERTY_KEY_PREFIX + "type.version"); + public static final String TYPEOPTIONS_PROPERTY_KEY = encodePropertyKey(INTERNAL_PROPERTY_KEY_PREFIX + "type.options"); /** * Trait names property key and index name. */ - public static final String TRAIT_NAMES_PROPERTY_KEY = INTERNAL_PROPERTY_KEY_PREFIX + "traitNames"; - - 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 CREATED_BY_KEY = INTERNAL_PROPERTY_KEY_PREFIX + "createdBy"; - 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 MODIFICATION_TIMESTAMP_PROPERTY_KEY = - INTERNAL_PROPERTY_KEY_PREFIX + "modificationTimestamp"; + public static final String TRAIT_NAMES_PROPERTY_KEY = encodePropertyKey(INTERNAL_PROPERTY_KEY_PREFIX + "traitNames"); + public static final String VERSION_PROPERTY_KEY = encodePropertyKey(INTERNAL_PROPERTY_KEY_PREFIX + "version"); + public static final String STATE_PROPERTY_KEY = encodePropertyKey(INTERNAL_PROPERTY_KEY_PREFIX + "state"); + public static final String CREATED_BY_KEY = encodePropertyKey(INTERNAL_PROPERTY_KEY_PREFIX + "createdBy"); + public static final String MODIFIED_BY_KEY = encodePropertyKey(INTERNAL_PROPERTY_KEY_PREFIX + "modifiedBy"); + public static final String TIMESTAMP_PROPERTY_KEY = encodePropertyKey(INTERNAL_PROPERTY_KEY_PREFIX + "timestamp"); + public static final String MODIFICATION_TIMESTAMP_PROPERTY_KEY = encodePropertyKey(INTERNAL_PROPERTY_KEY_PREFIX + "modificationTimestamp"); /** * search backing index name. @@ -91,7 +89,7 @@ public final class Constants { public static final String FULLTEXT_INDEX = "fulltext_index"; 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 = encodePropertyKey(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_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"; http://git-wip-us.apache.org/repos/asf/atlas/blob/250d9321/intg/src/main/java/org/apache/atlas/type/AtlasStructType.java ---------------------------------------------------------------------- diff --git a/intg/src/main/java/org/apache/atlas/type/AtlasStructType.java b/intg/src/main/java/org/apache/atlas/type/AtlasStructType.java index 32cf08b..45c58bd 100644 --- a/intg/src/main/java/org/apache/atlas/type/AtlasStructType.java +++ b/intg/src/main/java/org/apache/atlas/type/AtlasStructType.java @@ -567,6 +567,14 @@ public class AtlasStructType extends AtlasType { throw new AtlasBaseException(AtlasErrorCode.UNKNOWN_ATTRIBUTE, attrName, structDef.getName()); } + public String getQualifiedAttributePropertyKey(String attrName) throws AtlasBaseException { + if ( allAttributes.containsKey(attrName)) { + return allAttributes.get(attrName).getVertexPropertyName(); + } + + throw new AtlasBaseException(AtlasErrorCode.UNKNOWN_ATTRIBUTE, attrName, structDef.getName()); + } + private AtlasEntityType getReferencedEntityType(AtlasType type) { if (type instanceof AtlasArrayType) { type = ((AtlasArrayType)type).getElementType(); http://git-wip-us.apache.org/repos/asf/atlas/blob/250d9321/repository/src/main/java/org/apache/atlas/discovery/graph/DefaultGraphPersistenceStrategy.java ---------------------------------------------------------------------- diff --git a/repository/src/main/java/org/apache/atlas/discovery/graph/DefaultGraphPersistenceStrategy.java b/repository/src/main/java/org/apache/atlas/discovery/graph/DefaultGraphPersistenceStrategy.java index 9b0aa4c..2223224 100755 --- a/repository/src/main/java/org/apache/atlas/discovery/graph/DefaultGraphPersistenceStrategy.java +++ b/repository/src/main/java/org/apache/atlas/discovery/graph/DefaultGraphPersistenceStrategy.java @@ -37,6 +37,7 @@ import org.apache.atlas.repository.graphdb.AtlasEdgeDirection; import org.apache.atlas.repository.graphdb.AtlasGraph; import org.apache.atlas.repository.graphdb.AtlasVertex; import org.apache.atlas.repository.graphdb.GremlinVersion; +import org.apache.atlas.repository.store.graph.v1.AtlasGraphUtilsV1; import org.apache.atlas.typesystem.ITypedReferenceableInstance; import org.apache.atlas.typesystem.ITypedStruct; import org.apache.atlas.typesystem.persistence.Id; @@ -154,9 +155,9 @@ public class DefaultGraphPersistenceStrategy implements GraphPersistenceStrategi TypeSystem.IdType idType = TypeSystem.getInstance().getIdType(); if (dataType.getName().equals(idType.getName())) { - structInstance.set(idType.typeNameAttrName(), GraphHelper.getSingleValuedProperty(structVertex, typeAttributeName(), String.class)); - structInstance.set(idType.idAttrName(), GraphHelper.getSingleValuedProperty(structVertex, idAttributeName(), String.class)); - String stateValue = GraphHelper.getSingleValuedProperty(structVertex, stateAttributeName(), String.class); + structInstance.set(idType.typeNameAttrName(), AtlasGraphUtilsV1.getProperty(structVertex, typeAttributeName(), String.class)); + structInstance.set(idType.idAttrName(), AtlasGraphUtilsV1.getProperty(structVertex, idAttributeName(), String.class)); + String stateValue = AtlasGraphUtilsV1.getProperty(structVertex, stateAttributeName(), String.class); if (stateValue != null) { structInstance.set(idType.stateAttrName(), stateValue); } http://git-wip-us.apache.org/repos/asf/atlas/blob/250d9321/repository/src/main/java/org/apache/atlas/discovery/graph/GraphBackedDiscoveryService.java ---------------------------------------------------------------------- diff --git a/repository/src/main/java/org/apache/atlas/discovery/graph/GraphBackedDiscoveryService.java b/repository/src/main/java/org/apache/atlas/discovery/graph/GraphBackedDiscoveryService.java index aed8659..bcb4030 100755 --- a/repository/src/main/java/org/apache/atlas/discovery/graph/GraphBackedDiscoveryService.java +++ b/repository/src/main/java/org/apache/atlas/discovery/graph/GraphBackedDiscoveryService.java @@ -38,6 +38,7 @@ import org.apache.atlas.repository.graphdb.AtlasEdge; import org.apache.atlas.repository.graphdb.AtlasGraph; import org.apache.atlas.repository.graphdb.AtlasIndexQuery; import org.apache.atlas.repository.graphdb.AtlasVertex; +import org.apache.atlas.repository.store.graph.v1.AtlasGraphUtilsV1; import org.apache.atlas.util.CompiledQueryCacheKey; import org.apache.atlas.util.NoopGremlinQuery; import org.codehaus.jettison.json.JSONArray; @@ -234,7 +235,7 @@ public class GraphBackedDiscoveryService implements DiscoveryService { } else if (value instanceof AtlasVertex) { AtlasVertex<?,?> vertex = (AtlasVertex<?,?>)value; for (String key : vertex.getPropertyKeys()) { - Object propertyValue = GraphHelper.getProperty(vertex, key); + Object propertyValue = AtlasGraphUtilsV1.getProperty(vertex, key); if (propertyValue != null) { oRow.put(key, propertyValue.toString()); } @@ -250,7 +251,7 @@ public class GraphBackedDiscoveryService implements DiscoveryService { oRow.put(GREMLIN_INVERTEX_KEY, edge.getInVertex().getId().toString()); oRow.put(GREMLIN_OUTVERTEX_KEY, edge.getOutVertex().getId().toString()); for (String propertyKey : edge.getPropertyKeys()) { - oRow.put(propertyKey, GraphHelper.getProperty(edge, propertyKey).toString()); + oRow.put(propertyKey, AtlasGraphUtilsV1.getProperty(edge, propertyKey).toString()); } } else { throw new DiscoveryException(String.format("Cannot process result %s", String.valueOf(value))); http://git-wip-us.apache.org/repos/asf/atlas/blob/250d9321/repository/src/main/java/org/apache/atlas/repository/graph/DeleteHandler.java ---------------------------------------------------------------------- diff --git a/repository/src/main/java/org/apache/atlas/repository/graph/DeleteHandler.java b/repository/src/main/java/org/apache/atlas/repository/graph/DeleteHandler.java index f5cbec9..4fe567f 100644 --- a/repository/src/main/java/org/apache/atlas/repository/graph/DeleteHandler.java +++ b/repository/src/main/java/org/apache/atlas/repository/graph/DeleteHandler.java @@ -36,6 +36,7 @@ import org.apache.atlas.repository.graph.GraphHelper.VertexInfo; import org.apache.atlas.repository.graphdb.AtlasEdge; import org.apache.atlas.repository.graphdb.AtlasEdgeDirection; import org.apache.atlas.repository.graphdb.AtlasVertex; +import org.apache.atlas.repository.store.graph.v1.AtlasGraphUtilsV1; import org.apache.atlas.typesystem.ITypedReferenceableInstance; import org.apache.atlas.typesystem.exception.NullRequiredAttributeException; import org.apache.atlas.typesystem.persistence.Id; @@ -331,7 +332,7 @@ public abstract class DeleteHandler { if (attributeInfo.multiplicity.nullAllowed()) { edge = graphHelper.getEdgeForLabel(outVertex, edgeLabel); if (shouldUpdateReverseAttribute) { - GraphHelper.setProperty(outVertex, propertyName, null); + AtlasGraphUtilsV1.setProperty(outVertex, propertyName, null); } } else { // Cannot unset a required attribute. @@ -378,7 +379,7 @@ public abstract class DeleteHandler { // This prevents dangling edge IDs (i.e. edge IDs for deleted edges) // from the remaining in the list if there are duplicates. elements.removeAll(Collections.singletonList(elementEdge.getId().toString())); - GraphHelper.setProperty(outVertex, propertyName, elements); + AtlasGraphUtilsV1.setProperty(outVertex, propertyName, elements); break; } @@ -394,7 +395,7 @@ public abstract class DeleteHandler { keys = new ArrayList<>(keys); //Make a copy, else list.remove reflects on titan.getProperty() for (String key : keys) { String keyPropertyName = GraphHelper.getQualifiedNameForMapKey(propertyName, key); - String mapEdgeId = GraphHelper.getSingleValuedProperty(outVertex, keyPropertyName, String.class); + String mapEdgeId = AtlasGraphUtilsV1.getProperty(outVertex, keyPropertyName, String.class); AtlasEdge mapEdge = graphHelper.getEdgeByEdgeId(outVertex, keyPropertyName, mapEdgeId); if(mapEdge != null) { AtlasVertex mapVertex = mapEdge.getInVertex(); @@ -417,8 +418,8 @@ public abstract class DeleteHandler { } keys.remove(key); - GraphHelper.setProperty(outVertex, propertyName, keys); - GraphHelper.setProperty(outVertex, keyPropertyName, null); + AtlasGraphUtilsV1.setProperty(outVertex, propertyName, keys); + AtlasGraphUtilsV1.setProperty(outVertex, keyPropertyName, null); } break; } @@ -439,9 +440,9 @@ public abstract class DeleteHandler { if (edge != null) { deleteEdge(edge, false); RequestContext requestContext = RequestContext.get(); - GraphHelper.setProperty(outVertex, Constants.MODIFICATION_TIMESTAMP_PROPERTY_KEY, + AtlasGraphUtilsV1.setEncodedProperty(outVertex, Constants.MODIFICATION_TIMESTAMP_PROPERTY_KEY, requestContext.getRequestTime()); - GraphHelper.setProperty(outVertex, Constants.MODIFIED_BY_KEY, requestContext.getUser()); + AtlasGraphUtilsV1.setEncodedProperty(outVertex, Constants.MODIFIED_BY_KEY, requestContext.getUser()); requestContext.recordEntityUpdate(outId); } } http://git-wip-us.apache.org/repos/asf/atlas/blob/250d9321/repository/src/main/java/org/apache/atlas/repository/graph/GraphBackedMetadataRepository.java ---------------------------------------------------------------------- diff --git a/repository/src/main/java/org/apache/atlas/repository/graph/GraphBackedMetadataRepository.java b/repository/src/main/java/org/apache/atlas/repository/graph/GraphBackedMetadataRepository.java index 74886b5..400a55e 100755 --- a/repository/src/main/java/org/apache/atlas/repository/graph/GraphBackedMetadataRepository.java +++ b/repository/src/main/java/org/apache/atlas/repository/graph/GraphBackedMetadataRepository.java @@ -33,6 +33,7 @@ import org.apache.atlas.repository.graphdb.AtlasEdge; import org.apache.atlas.repository.graphdb.AtlasGraph; import org.apache.atlas.repository.graphdb.AtlasGraphQuery; import org.apache.atlas.repository.graphdb.AtlasVertex; +import org.apache.atlas.repository.store.graph.v1.AtlasGraphUtilsV1; import org.apache.atlas.typesystem.ITypedReferenceableInstance; import org.apache.atlas.typesystem.ITypedStruct; import org.apache.atlas.typesystem.exception.EntityExistsException; @@ -122,7 +123,7 @@ public class GraphBackedMetadataRepository implements MetadataRepository { if (aInfo.name.startsWith(Constants.INTERNAL_PROPERTY_KEY_PREFIX)) { return aInfo.name; } - return GraphHelper.encodePropertyKey(GraphHelper.getQualifiedFieldName(dataType, aInfo.name)); + return AtlasGraphUtilsV1.encodePropertyKey(GraphHelper.getQualifiedFieldName(dataType, aInfo.name)); } public String getFieldNameInVertex(IDataType<?> dataType, String attrName) throws AtlasException { @@ -346,10 +347,10 @@ public class GraphBackedMetadataRepository implements MetadataRepository { // update the traits in entity once adding trait instance is successful - GraphHelper.addProperty(instanceVertex, Constants.TRAIT_NAMES_PROPERTY_KEY, traitName); - GraphHelper.setProperty(instanceVertex, Constants.MODIFICATION_TIMESTAMP_PROPERTY_KEY, + AtlasGraphUtilsV1.addEncodedProperty(instanceVertex, Constants.TRAIT_NAMES_PROPERTY_KEY, traitName); + AtlasGraphUtilsV1.setEncodedProperty(instanceVertex, Constants.MODIFICATION_TIMESTAMP_PROPERTY_KEY, RequestContext.get().getRequestTime()); - GraphHelper.setProperty(instanceVertex, Constants.MODIFIED_BY_KEY, RequestContext.get().getUser()); + AtlasGraphUtilsV1.setEncodedProperty(instanceVertex, Constants.MODIFIED_BY_KEY, RequestContext.get().getUser()); } catch (RepositoryException e) { throw e; @@ -402,11 +403,11 @@ public class GraphBackedMetadataRepository implements MetadataRepository { // add it back again for (String traitName : traitNames) { - GraphHelper.addProperty(instanceVertex, Constants.TRAIT_NAMES_PROPERTY_KEY, traitName); + AtlasGraphUtilsV1.addEncodedProperty(instanceVertex, Constants.TRAIT_NAMES_PROPERTY_KEY, traitName); } - GraphHelper.setProperty(instanceVertex, Constants.MODIFICATION_TIMESTAMP_PROPERTY_KEY, + AtlasGraphUtilsV1.setEncodedProperty(instanceVertex, Constants.MODIFICATION_TIMESTAMP_PROPERTY_KEY, RequestContext.get().getRequestTime()); - GraphHelper.setProperty(instanceVertex, Constants.MODIFIED_BY_KEY, RequestContext.get().getUser()); + AtlasGraphUtilsV1.setEncodedProperty(instanceVertex, Constants.MODIFIED_BY_KEY, RequestContext.get().getUser()); } @Override http://git-wip-us.apache.org/repos/asf/atlas/blob/250d9321/repository/src/main/java/org/apache/atlas/repository/graph/GraphBackedSearchIndexer.java ---------------------------------------------------------------------- diff --git a/repository/src/main/java/org/apache/atlas/repository/graph/GraphBackedSearchIndexer.java b/repository/src/main/java/org/apache/atlas/repository/graph/GraphBackedSearchIndexer.java index 6eee24b..eca6f41 100755 --- a/repository/src/main/java/org/apache/atlas/repository/graph/GraphBackedSearchIndexer.java +++ b/repository/src/main/java/org/apache/atlas/repository/graph/GraphBackedSearchIndexer.java @@ -42,6 +42,7 @@ import org.apache.atlas.repository.graphdb.AtlasGraph; import org.apache.atlas.repository.graphdb.AtlasGraphIndex; import org.apache.atlas.repository.graphdb.AtlasGraphManagement; import org.apache.atlas.repository.graphdb.AtlasPropertyKey; +import org.apache.atlas.repository.store.graph.v1.AtlasGraphUtilsV1; import org.apache.atlas.type.AtlasClassificationType; import org.apache.atlas.type.AtlasEntityType; import org.apache.atlas.type.AtlasEnumType; @@ -315,7 +316,7 @@ public class GraphBackedSearchIndexer implements SearchIndexer, ActiveStateChang private void createIndexForAttribute(AtlasGraphManagement management, String typeName, AtlasAttributeDef attributeDef) { - final String propertyName = GraphHelper.encodePropertyKey(typeName + "." + attributeDef.getName()); + final String propertyName = AtlasGraphUtilsV1.encodePropertyKey(typeName + "." + attributeDef.getName()); AtlasCardinality cardinality = toAtlasCardinality(attributeDef.getCardinality()); boolean isUnique = attributeDef.getIsUnique(); boolean isIndexable = attributeDef.getIsIndexable(); @@ -451,7 +452,7 @@ public class GraphBackedSearchIndexer implements SearchIndexer, ActiveStateChang } private void createIndexForAttribute(AtlasGraphManagement management, String typeName, AttributeInfo field) { - final String propertyName = GraphHelper.encodePropertyKey(typeName + "." + field.name); + final String propertyName = AtlasGraphUtilsV1.encodePropertyKey(typeName + "." + field.name); switch (field.dataType().getTypeCategory()) { case PRIMITIVE: AtlasCardinality cardinality = getCardinality(field.multiplicity); @@ -766,7 +767,7 @@ public class GraphBackedSearchIndexer implements SearchIndexer, ActiveStateChang } private void cleanupIndexForAttribute(AtlasGraphManagement management, String typeName, AtlasAttributeDef attributeDef) { - final String propertyName = GraphHelper.encodePropertyKey(typeName + "." + attributeDef.getName()); + final String propertyName = AtlasGraphUtilsV1.encodePropertyKey(typeName + "." + attributeDef.getName()); String attribTypeName = attributeDef.getTypeName(); boolean isBuiltInType = AtlasTypeUtil.isBuiltInType(attribTypeName); boolean isArrayType = AtlasTypeUtil.isArrayType(attribTypeName); http://git-wip-us.apache.org/repos/asf/atlas/blob/250d9321/repository/src/main/java/org/apache/atlas/repository/graph/GraphHelper.java ---------------------------------------------------------------------- diff --git a/repository/src/main/java/org/apache/atlas/repository/graph/GraphHelper.java b/repository/src/main/java/org/apache/atlas/repository/graph/GraphHelper.java index 0cdbc57..bd8b75e 100755 --- a/repository/src/main/java/org/apache/atlas/repository/graph/GraphHelper.java +++ b/repository/src/main/java/org/apache/atlas/repository/graph/GraphHelper.java @@ -19,8 +19,6 @@ package org.apache.atlas.repository.graph; import com.google.common.annotations.VisibleForTesting; -import com.google.common.collect.BiMap; -import com.google.common.collect.HashBiMap; import org.apache.atlas.ApplicationProperties; import org.apache.atlas.AtlasException; import org.apache.atlas.RequestContext; @@ -58,7 +56,6 @@ import org.apache.atlas.util.AttributeValueMap; import org.apache.atlas.util.IndexedInstance; import org.apache.atlas.utils.ParamChecker; import org.apache.commons.collections.CollectionUtils; -import org.apache.commons.lang.StringUtils; import org.codehaus.jettison.json.JSONArray; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -138,10 +135,10 @@ public final class GraphHelper { new Id(guid, 0, typedInstance.getTypeName()), superTypeNames); // add identity - setProperty(vertexWithIdentity, Constants.GUID_PROPERTY_KEY, guid); + AtlasGraphUtilsV1.setEncodedProperty(vertexWithIdentity, Constants.GUID_PROPERTY_KEY, guid); // add version information - setProperty(vertexWithIdentity, Constants.VERSION_PROPERTY_KEY, typedInstance.getId().version); + AtlasGraphUtilsV1.setEncodedProperty(vertexWithIdentity, Constants.VERSION_PROPERTY_KEY, typedInstance.getId().version); return vertexWithIdentity; } @@ -155,24 +152,23 @@ public final class GraphHelper { final AtlasVertex vertexWithoutIdentity = graph.addVertex(); // add type information - setProperty(vertexWithoutIdentity, Constants.ENTITY_TYPE_PROPERTY_KEY, typeName); + AtlasGraphUtilsV1.setEncodedProperty(vertexWithoutIdentity, Constants.ENTITY_TYPE_PROPERTY_KEY, typeName); // add super types for (String superTypeName : superTypeNames) { - addProperty(vertexWithoutIdentity, Constants.SUPER_TYPES_PROPERTY_KEY, superTypeName); + AtlasGraphUtilsV1.addEncodedProperty(vertexWithoutIdentity, Constants.SUPER_TYPES_PROPERTY_KEY, superTypeName); } // add state information - setProperty(vertexWithoutIdentity, Constants.STATE_PROPERTY_KEY, Id.EntityState.ACTIVE.name()); + AtlasGraphUtilsV1.setEncodedProperty(vertexWithoutIdentity, Constants.STATE_PROPERTY_KEY, Id.EntityState.ACTIVE.name()); // add timestamp information - setProperty(vertexWithoutIdentity, Constants.TIMESTAMP_PROPERTY_KEY, RequestContext.get().getRequestTime()); - setProperty(vertexWithoutIdentity, Constants.MODIFICATION_TIMESTAMP_PROPERTY_KEY, - RequestContext.get().getRequestTime()); + AtlasGraphUtilsV1.setEncodedProperty(vertexWithoutIdentity, Constants.TIMESTAMP_PROPERTY_KEY, RequestContext.get().getRequestTime()); + AtlasGraphUtilsV1.setEncodedProperty(vertexWithoutIdentity, Constants.MODIFICATION_TIMESTAMP_PROPERTY_KEY, RequestContext.get().getRequestTime()); + AtlasGraphUtilsV1.setEncodedProperty(vertexWithoutIdentity, Constants.CREATED_BY_KEY, RequestContext.get().getUser()); + AtlasGraphUtilsV1.setEncodedProperty(vertexWithoutIdentity, Constants.MODIFIED_BY_KEY, RequestContext.get().getUser()); - setProperty(vertexWithoutIdentity, Constants.CREATED_BY_KEY, RequestContext.get().getUser()); - setProperty(vertexWithoutIdentity, Constants.MODIFIED_BY_KEY, RequestContext.get().getUser()); return vertexWithoutIdentity; } @@ -183,11 +179,11 @@ public final class GraphHelper { AtlasEdge edge = graph.addEdge(fromVertex, toVertex, edgeLabel); - setProperty(edge, Constants.STATE_PROPERTY_KEY, Id.EntityState.ACTIVE.name()); - setProperty(edge, Constants.TIMESTAMP_PROPERTY_KEY, RequestContext.get().getRequestTime()); - setProperty(edge, Constants.MODIFICATION_TIMESTAMP_PROPERTY_KEY, RequestContext.get().getRequestTime()); - setProperty(edge, Constants.CREATED_BY_KEY, RequestContext.get().getUser()); - setProperty(edge, Constants.MODIFIED_BY_KEY, RequestContext.get().getUser()); + AtlasGraphUtilsV1.setEncodedProperty(edge, Constants.STATE_PROPERTY_KEY, Id.EntityState.ACTIVE.name()); + AtlasGraphUtilsV1.setEncodedProperty(edge, Constants.TIMESTAMP_PROPERTY_KEY, RequestContext.get().getRequestTime()); + AtlasGraphUtilsV1.setEncodedProperty(edge, Constants.MODIFICATION_TIMESTAMP_PROPERTY_KEY, RequestContext.get().getRequestTime()); + AtlasGraphUtilsV1.setEncodedProperty(edge, Constants.CREATED_BY_KEY, RequestContext.get().getUser()); + AtlasGraphUtilsV1.setEncodedProperty(edge, Constants.MODIFIED_BY_KEY, RequestContext.get().getUser()); if (LOG.isDebugEnabled()) { LOG.debug("Added {}", string(edge)); @@ -385,108 +381,6 @@ public final class GraphHelper { + edge.getInVertex() + "]"; } - public static <T extends AtlasElement> void setProperty(T element, String propertyName, Object value) { - String actualPropertyName = GraphHelper.encodePropertyKey(propertyName); - - String elementStr = null; - - if (LOG.isDebugEnabled()) { - elementStr = string(element); - - LOG.debug("Setting property {} = \"{}\" to {}", actualPropertyName, value, elementStr); - } - - Object existValue = element.getProperty(actualPropertyName, Object.class); - if(value == null || (value instanceof Collection && ((Collection) value).isEmpty())) { - if(existValue != null) { - if (LOG.isDebugEnabled()) { - LOG.debug("Removing property - {} value from {}", actualPropertyName, elementStr); - } - - element.removeProperty(actualPropertyName); - } - } else { - if (!value.equals(existValue)) { - element.setProperty(actualPropertyName, value); - - if (LOG.isDebugEnabled()) { - LOG.debug("Set property {} = \"{}\" to {}", actualPropertyName, value, elementStr); - } - } - } - } - - /** - * Gets the value of a property that is stored in the graph as a single property value. If - * a multi-property such as {@link Constants#TRAIT_NAMES_PROPERTY_KEY} or {@link Constants#SUPER_TYPES_PROPERTY_KEY} - * is used, an exception will be thrown. - * - * @param element - * @param propertyName - * @param clazz - * @return - */ - public static <T> T getSingleValuedProperty(AtlasElement element, String propertyName, Class<T> clazz) { - String actualPropertyName = GraphHelper.encodePropertyKey(propertyName); - - if (LOG.isDebugEnabled()) { - LOG.debug("Reading property {} from {}", actualPropertyName, string(element)); - } - - return element.getProperty(actualPropertyName, clazz); - } - - - public static Object getProperty(AtlasVertex<?,?> vertex, String propertyName) { - String actualPropertyName = GraphHelper.encodePropertyKey(propertyName); - - if (LOG.isDebugEnabled()) { - LOG.debug("Reading property {} from {}", actualPropertyName, string(vertex)); - } - - if(AtlasGraphProvider.getGraphInstance().isMultiProperty(actualPropertyName)) { - return vertex.getPropertyValues(actualPropertyName, String.class); - } - else { - return vertex.getProperty(actualPropertyName, Object.class); - } - } - - public static Object getProperty(AtlasEdge<?,?> edge, String propertyName) { - String actualPropertyName = GraphHelper.encodePropertyKey(propertyName); - - if (LOG.isDebugEnabled()) { - LOG.debug("Reading property {} from {}", actualPropertyName, string(edge)); - } - - return edge.getProperty(actualPropertyName, Object.class); - } - - private static <T extends AtlasElement> String string(T element) { - if (element instanceof AtlasVertex) { - return string((AtlasVertex) element); - } else if (element instanceof AtlasEdge) { - return string((AtlasEdge)element); - } - return element.toString(); - } - - /** - * Adds an additional value to a multi-property. - * - * @param vertex - * @param propertyName - * @param value - */ - public static void addProperty(AtlasVertex vertex, String propertyName, Object value) { - String actualPropertyName = GraphHelper.encodePropertyKey(propertyName); - - if (LOG.isDebugEnabled()) { - LOG.debug("Adding property {} = \"{}\" to vertex {}", actualPropertyName, value, string(vertex)); - } - - vertex.addProperty(actualPropertyName, value); - } /** * Remove the specified edge from the graph. @@ -1003,17 +897,17 @@ public final class GraphHelper { } public static void setArrayElementsProperty(IDataType elementType, AtlasVertex instanceVertex, String propertyName, List<Object> values) { - String actualPropertyName = GraphHelper.encodePropertyKey(propertyName); + String actualPropertyName = AtlasGraphUtilsV1.encodePropertyKey(propertyName); if(GraphHelper.isReference(elementType)) { setListPropertyFromElementIds(instanceVertex, actualPropertyName, (List)values); } else { - setProperty(instanceVertex, actualPropertyName, values); + AtlasGraphUtilsV1.setEncodedProperty(instanceVertex, actualPropertyName, values); } } public static void setMapValueProperty(IDataType elementType, AtlasVertex instanceVertex, String propertyName, Object value) { - String actualPropertyName = GraphHelper.encodePropertyKey(propertyName); + String actualPropertyName = AtlasGraphUtilsV1.encodePropertyKey(propertyName); if(GraphHelper.isReference(elementType)) { instanceVertex.setPropertyFromElementId(actualPropertyName, (AtlasEdge)value); } @@ -1023,7 +917,7 @@ public final class GraphHelper { } public static Object getMapValueProperty(IDataType elementType, AtlasVertex instanceVertex, String propertyName) { - String actualPropertyName = GraphHelper.encodePropertyKey(propertyName); + String actualPropertyName = AtlasGraphUtilsV1.encodePropertyKey(propertyName); if(GraphHelper.isReference(elementType)) { return instanceVertex.getProperty(actualPropertyName, AtlasEdge.class); } @@ -1033,7 +927,7 @@ public final class GraphHelper { } public static Object getMapValueProperty(AtlasType elementType, AtlasVertex instanceVertex, String propertyName) { - String vertexPropertyName = GraphHelper.encodePropertyKey(propertyName); + String vertexPropertyName = AtlasGraphUtilsV1.encodePropertyKey(propertyName); if (AtlasGraphUtilsV1.isReference(elementType)) { return instanceVertex.getProperty(vertexPropertyName, AtlasEdge.class); @@ -1044,7 +938,7 @@ public final class GraphHelper { // newly added public static List<Object> getArrayElementsProperty(AtlasType elementType, AtlasVertex instanceVertex, String propertyName) { - String encodedPropertyName = GraphHelper.encodePropertyKey(propertyName); + String encodedPropertyName = AtlasGraphUtilsV1.encodePropertyKey(propertyName); if(AtlasGraphUtilsV1.isReference(elementType)) { return (List)instanceVertex.getListProperty(encodedPropertyName, AtlasEdge.class); } @@ -1054,7 +948,7 @@ public final class GraphHelper { } public static List<Object> getArrayElementsProperty(IDataType elementType, AtlasVertex instanceVertex, String propertyName) { - String actualPropertyName = GraphHelper.encodePropertyKey(propertyName); + String actualPropertyName = AtlasGraphUtilsV1.encodePropertyKey(propertyName); if(GraphHelper.isReference(elementType)) { return (List)instanceVertex.getListProperty(actualPropertyName, AtlasEdge.class); } @@ -1118,40 +1012,6 @@ public final class GraphHelper { string(edge.getOutVertex()), string(edge.getInVertex())); } - @VisibleForTesting - //Keys copied from com.thinkaurelius.titan.graphdb.types.StandardRelationTypeMaker - //Titan checks that these chars are not part of any keys. So, encoding... - public static BiMap<String, String> RESERVED_CHARS_ENCODE_MAP = - HashBiMap.create(new HashMap<String, String>() {{ - put("{", "_o"); - put("}", "_c"); - put("\"", "_q"); - put("$", "_d"); - put("%", "_p"); - }}); - - - public static String encodePropertyKey(String key) { - if (StringUtils.isBlank(key)) { - return key; - } - - for (String str : RESERVED_CHARS_ENCODE_MAP.keySet()) { - key = key.replace(str, RESERVED_CHARS_ENCODE_MAP.get(str)); - } - return key; - } - - public static String decodePropertyKey(String key) { - if (StringUtils.isBlank(key)) { - return key; - } - - for (String encodedStr : RESERVED_CHARS_ENCODE_MAP.values()) { - key = key.replace(encodedStr, RESERVED_CHARS_ENCODE_MAP.inverse().get(encodedStr)); - } - return key; - } public Object getVertexId(String guid) throws EntityNotFoundException { AtlasVertex instanceVertex = getVertexForGUID(guid); @@ -1161,17 +1021,12 @@ public final class GraphHelper { } public static AttributeInfo getAttributeInfoForSystemAttributes(String field) { - switch (field) { - case Constants.STATE_PROPERTY_KEY: - case Constants.GUID_PROPERTY_KEY: - case Constants.CREATED_BY_KEY: - case Constants.MODIFIED_BY_KEY: - return TypesUtil.newAttributeInfo(field, DataTypes.STRING_TYPE); - - case Constants.TIMESTAMP_PROPERTY_KEY: - case Constants.MODIFICATION_TIMESTAMP_PROPERTY_KEY: + if (field.equals(Constants.STATE_PROPERTY_KEY) || field.equals(Constants.GUID_PROPERTY_KEY) || field.equals(Constants.CREATED_BY_KEY) || field.equals(Constants.MODIFIED_BY_KEY)) { + return TypesUtil.newAttributeInfo(field, DataTypes.STRING_TYPE); + } else if (field.equals(Constants.TIMESTAMP_PROPERTY_KEY) || field.equals(Constants.MODIFICATION_TIMESTAMP_PROPERTY_KEY)) { return TypesUtil.newAttributeInfo(field, DataTypes.DATE_TYPE); } + return null; } @@ -1181,25 +1036,23 @@ public final class GraphHelper { public static void setListPropertyFromElementIds(AtlasVertex<?, ?> instanceVertex, String propertyName, List<AtlasElement> elements) { - String actualPropertyName = GraphHelper.encodePropertyKey(propertyName); - instanceVertex.setPropertyFromElementsIds(actualPropertyName, elements); - + instanceVertex.setPropertyFromElementsIds(propertyName, elements); } public static void setPropertyFromElementId(AtlasVertex<?, ?> instanceVertex, String propertyName, AtlasElement value) { - String actualPropertyName = GraphHelper.encodePropertyKey(propertyName); + String actualPropertyName = AtlasGraphUtilsV1.encodePropertyKey(propertyName); instanceVertex.setPropertyFromElementId(actualPropertyName, value); } public static void setListProperty(AtlasVertex instanceVertex, String propertyName, ArrayList<String> value) throws AtlasException { - String actualPropertyName = GraphHelper.encodePropertyKey(propertyName); + String actualPropertyName = AtlasGraphUtilsV1.encodePropertyKey(propertyName); instanceVertex.setListProperty(actualPropertyName, value); } public static List<String> getListProperty(AtlasVertex instanceVertex, String propertyName) { - String actualPropertyName = GraphHelper.encodePropertyKey(propertyName); + String actualPropertyName = AtlasGraphUtilsV1.encodePropertyKey(propertyName); return instanceVertex.getListProperty(actualPropertyName); } http://git-wip-us.apache.org/repos/asf/atlas/blob/250d9321/repository/src/main/java/org/apache/atlas/repository/graph/GraphToTypedInstanceMapper.java ---------------------------------------------------------------------- diff --git a/repository/src/main/java/org/apache/atlas/repository/graph/GraphToTypedInstanceMapper.java b/repository/src/main/java/org/apache/atlas/repository/graph/GraphToTypedInstanceMapper.java index 78ea1c9..16a7537 100644 --- a/repository/src/main/java/org/apache/atlas/repository/graph/GraphToTypedInstanceMapper.java +++ b/repository/src/main/java/org/apache/atlas/repository/graph/GraphToTypedInstanceMapper.java @@ -25,6 +25,7 @@ import org.apache.atlas.repository.graphdb.AtlasEdge; import org.apache.atlas.repository.graphdb.AtlasEdgeDirection; import org.apache.atlas.repository.graphdb.AtlasGraph; import org.apache.atlas.repository.graphdb.AtlasVertex; +import org.apache.atlas.repository.store.graph.v1.AtlasGraphUtilsV1; import org.apache.atlas.typesystem.ITypedInstance; import org.apache.atlas.typesystem.ITypedReferenceableInstance; import org.apache.atlas.typesystem.ITypedStruct; @@ -82,7 +83,7 @@ public final class GraphToTypedInstanceMapper { LOG.debug("Mapping graph root vertex {} to typed instance for guid {}", instanceVertex, guid); } - String typeName = GraphHelper.getSingleValuedProperty(instanceVertex, Constants.ENTITY_TYPE_PROPERTY_KEY, String.class); + String typeName = AtlasGraphUtilsV1.getEncodedProperty(instanceVertex, Constants.ENTITY_TYPE_PROPERTY_KEY, String.class); List<String> traits = GraphHelper.getTraitNames(instanceVertex); String state = GraphHelper.getStateAsString(instanceVertex); String createdBy = GraphHelper.getCreatedByAsString(instanceVertex); @@ -95,7 +96,7 @@ public final class GraphToTypedInstanceMapper { LOG.debug("Found createdBy : {} modifiedBy : {} createdTime: {} modifedTime: {}", createdBy, modifiedBy, createdTime, modifiedTime); } - Id id = new Id(guid, Integer.parseInt(String.valueOf(GraphHelper.getProperty(instanceVertex, Constants.VERSION_PROPERTY_KEY))), + Id id = new Id(guid, Integer.parseInt(String.valueOf(AtlasGraphUtilsV1.getEncodedProperty(instanceVertex, Constants.VERSION_PROPERTY_KEY, Object.class))), typeName, state); if (LOG.isDebugEnabled()) { @@ -204,7 +205,7 @@ public final class GraphToTypedInstanceMapper { if (GraphHelper.elementExists(edge)) { final AtlasVertex referenceVertex = edge.getInVertex(); - final String guid = GraphHelper.getSingleValuedProperty(referenceVertex, Constants.GUID_PROPERTY_KEY, String.class); + final String guid = AtlasGraphUtilsV1.getEncodedProperty(referenceVertex, Constants.GUID_PROPERTY_KEY, String.class); if (LOG.isDebugEnabled()) { LOG.debug("Found vertex {} for label {} with guid {}", referenceVertex, relationshipLabel, guid); @@ -221,7 +222,7 @@ public final class GraphToTypedInstanceMapper { } else { String state = GraphHelper.getStateAsString(referenceVertex); Id referenceId = - new Id(guid, GraphHelper.getSingleValuedProperty(referenceVertex, Constants.VERSION_PROPERTY_KEY, Integer.class), + new Id(guid, AtlasGraphUtilsV1.getEncodedProperty(referenceVertex, Constants.VERSION_PROPERTY_KEY, Integer.class), dataType.getName(), state); if (LOG.isDebugEnabled()) { @@ -393,40 +394,40 @@ public final class GraphToTypedInstanceMapper { } final String vertexPropertyName = GraphHelper.getQualifiedFieldName(typedInstance, attributeInfo); - if (GraphHelper.getSingleValuedProperty(instanceVertex, vertexPropertyName, Object.class) == null) { + if (AtlasGraphUtilsV1.getProperty(instanceVertex, vertexPropertyName, Object.class) == null) { return; } if (attributeInfo.dataType() == DataTypes.STRING_TYPE) { - typedInstance.setString(attributeInfo.name, GraphHelper.getSingleValuedProperty(instanceVertex, vertexPropertyName, String.class)); + typedInstance.setString(attributeInfo.name, AtlasGraphUtilsV1.getProperty(instanceVertex, vertexPropertyName, String.class)); } else if (attributeInfo.dataType() == DataTypes.SHORT_TYPE) { - typedInstance.setShort(attributeInfo.name, GraphHelper.getSingleValuedProperty(instanceVertex, vertexPropertyName, Short.class)); + typedInstance.setShort(attributeInfo.name, AtlasGraphUtilsV1.getProperty(instanceVertex, vertexPropertyName, Short.class)); } else if (attributeInfo.dataType() == DataTypes.INT_TYPE) { - typedInstance.setInt(attributeInfo.name, GraphHelper.getSingleValuedProperty(instanceVertex, vertexPropertyName, Integer.class)); + typedInstance.setInt(attributeInfo.name, AtlasGraphUtilsV1.getProperty(instanceVertex, vertexPropertyName, Integer.class)); } else if (attributeInfo.dataType() == DataTypes.BIGINTEGER_TYPE) { - typedInstance.setBigInt(attributeInfo.name, GraphHelper.getSingleValuedProperty(instanceVertex, vertexPropertyName, BigInteger.class)); + typedInstance.setBigInt(attributeInfo.name, AtlasGraphUtilsV1.getProperty(instanceVertex, vertexPropertyName, BigInteger.class)); } else if (attributeInfo.dataType() == DataTypes.BOOLEAN_TYPE) { - typedInstance.setBoolean(attributeInfo.name, GraphHelper.getSingleValuedProperty(instanceVertex, vertexPropertyName, Boolean.class)); + typedInstance.setBoolean(attributeInfo.name, AtlasGraphUtilsV1.getProperty(instanceVertex, vertexPropertyName, Boolean.class)); } else if (attributeInfo.dataType() == DataTypes.BYTE_TYPE) { - typedInstance.setByte(attributeInfo.name, GraphHelper.getSingleValuedProperty(instanceVertex, vertexPropertyName, Byte.class)); + typedInstance.setByte(attributeInfo.name, AtlasGraphUtilsV1.getProperty(instanceVertex, vertexPropertyName, Byte.class)); } else if (attributeInfo.dataType() == DataTypes.LONG_TYPE) { - typedInstance.setLong(attributeInfo.name, GraphHelper.getSingleValuedProperty(instanceVertex, vertexPropertyName, Long.class)); + typedInstance.setLong(attributeInfo.name, AtlasGraphUtilsV1.getProperty(instanceVertex, vertexPropertyName, Long.class)); } else if (attributeInfo.dataType() == DataTypes.FLOAT_TYPE) { - typedInstance.setFloat(attributeInfo.name, GraphHelper.getSingleValuedProperty(instanceVertex, vertexPropertyName, Float.class)); + typedInstance.setFloat(attributeInfo.name, AtlasGraphUtilsV1.getProperty(instanceVertex, vertexPropertyName, Float.class)); } else if (attributeInfo.dataType() == DataTypes.DOUBLE_TYPE) { - typedInstance.setDouble(attributeInfo.name, GraphHelper.getSingleValuedProperty(instanceVertex, vertexPropertyName, Double.class)); + typedInstance.setDouble(attributeInfo.name, AtlasGraphUtilsV1.getProperty(instanceVertex, vertexPropertyName, Double.class)); } else if (attributeInfo.dataType() == DataTypes.BIGDECIMAL_TYPE) { typedInstance - .setBigDecimal(attributeInfo.name, GraphHelper.getSingleValuedProperty(instanceVertex, vertexPropertyName, BigDecimal.class)); + .setBigDecimal(attributeInfo.name, AtlasGraphUtilsV1.getProperty(instanceVertex, vertexPropertyName, BigDecimal.class)); } else if (attributeInfo.dataType() == DataTypes.DATE_TYPE) { - final Long dateVal = GraphHelper.getSingleValuedProperty(instanceVertex, vertexPropertyName, Long.class); + final Long dateVal = AtlasGraphUtilsV1.getProperty(instanceVertex, vertexPropertyName, Long.class); typedInstance.setDate(attributeInfo.name, new Date(dateVal)); } } public static void mapVertexToEnum(AtlasVertex<?,?> instanceVertex, ITypedInstance typedInstance, AttributeInfo attributeInfo) throws AtlasException { final String vertexPropertyName = GraphHelper.getQualifiedFieldName(typedInstance, attributeInfo); - final Object propertyValue = GraphHelper.getProperty(instanceVertex, vertexPropertyName); + final Object propertyValue = AtlasGraphUtilsV1.getProperty(instanceVertex, vertexPropertyName); if (propertyValue == null) { return; } http://git-wip-us.apache.org/repos/asf/atlas/blob/250d9321/repository/src/main/java/org/apache/atlas/repository/graph/SoftDeleteHandler.java ---------------------------------------------------------------------- diff --git a/repository/src/main/java/org/apache/atlas/repository/graph/SoftDeleteHandler.java b/repository/src/main/java/org/apache/atlas/repository/graph/SoftDeleteHandler.java index b37fe75..e3a92a4 100644 --- a/repository/src/main/java/org/apache/atlas/repository/graph/SoftDeleteHandler.java +++ b/repository/src/main/java/org/apache/atlas/repository/graph/SoftDeleteHandler.java @@ -23,6 +23,7 @@ import org.apache.atlas.RequestContext; import org.apache.atlas.annotation.ConditionalOnAtlasProperty; import org.apache.atlas.repository.graphdb.AtlasEdge; import org.apache.atlas.repository.graphdb.AtlasVertex; +import org.apache.atlas.repository.store.graph.v1.AtlasGraphUtilsV1; import org.apache.atlas.typesystem.persistence.Id; import org.apache.atlas.typesystem.types.TypeSystem; import org.springframework.stereotype.Component; @@ -49,10 +50,10 @@ public class SoftDeleteHandler extends DeleteHandler { } else { Id.EntityState state = GraphHelper.getState(instanceVertex); if (state != Id.EntityState.DELETED) { - GraphHelper.setProperty(instanceVertex, STATE_PROPERTY_KEY, Id.EntityState.DELETED.name()); - GraphHelper.setProperty(instanceVertex, MODIFICATION_TIMESTAMP_PROPERTY_KEY, + AtlasGraphUtilsV1.setEncodedProperty(instanceVertex, STATE_PROPERTY_KEY, Id.EntityState.DELETED.name()); + AtlasGraphUtilsV1.setEncodedProperty(instanceVertex, MODIFICATION_TIMESTAMP_PROPERTY_KEY, RequestContext.get().getRequestTime()); - GraphHelper.setProperty(instanceVertex, MODIFIED_BY_KEY, RequestContext.get().getUser()); + AtlasGraphUtilsV1.setEncodedProperty(instanceVertex, MODIFIED_BY_KEY, RequestContext.get().getUser()); } } } @@ -64,10 +65,9 @@ public class SoftDeleteHandler extends DeleteHandler { } else { Id.EntityState state = GraphHelper.getState(edge); if (state != Id.EntityState.DELETED) { - GraphHelper.setProperty(edge, STATE_PROPERTY_KEY, Id.EntityState.DELETED.name()); - GraphHelper - .setProperty(edge, MODIFICATION_TIMESTAMP_PROPERTY_KEY, RequestContext.get().getRequestTime()); - GraphHelper.setProperty(edge, MODIFIED_BY_KEY, RequestContext.get().getUser()); + AtlasGraphUtilsV1.setEncodedProperty(edge, STATE_PROPERTY_KEY, Id.EntityState.DELETED.name()); + AtlasGraphUtilsV1.setEncodedProperty(edge, MODIFICATION_TIMESTAMP_PROPERTY_KEY, RequestContext.get().getRequestTime()); + AtlasGraphUtilsV1.setEncodedProperty(edge, MODIFIED_BY_KEY, RequestContext.get().getUser()); } } } http://git-wip-us.apache.org/repos/asf/atlas/blob/250d9321/repository/src/main/java/org/apache/atlas/repository/graph/TypedInstanceToGraphMapper.java ---------------------------------------------------------------------- diff --git a/repository/src/main/java/org/apache/atlas/repository/graph/TypedInstanceToGraphMapper.java b/repository/src/main/java/org/apache/atlas/repository/graph/TypedInstanceToGraphMapper.java index 1fb4ee9..7075b53 100644 --- a/repository/src/main/java/org/apache/atlas/repository/graph/TypedInstanceToGraphMapper.java +++ b/repository/src/main/java/org/apache/atlas/repository/graph/TypedInstanceToGraphMapper.java @@ -27,6 +27,7 @@ import org.apache.atlas.repository.RepositoryException; import org.apache.atlas.repository.graphdb.AtlasEdge; import org.apache.atlas.repository.graphdb.AtlasSchemaViolationException; import org.apache.atlas.repository.graphdb.AtlasVertex; +import org.apache.atlas.repository.store.graph.v1.AtlasGraphUtilsV1; import org.apache.atlas.typesystem.IReferenceableInstance; import org.apache.atlas.typesystem.ITypedInstance; import org.apache.atlas.typesystem.ITypedReferenceableInstance; @@ -198,9 +199,9 @@ public final class TypedInstanceToGraphMapper { } mapAttributeToVertex(typedInstance, instanceVertex, attributeInfo, operation); } - GraphHelper.setProperty(instanceVertex, Constants.MODIFICATION_TIMESTAMP_PROPERTY_KEY, + AtlasGraphUtilsV1.setEncodedProperty(instanceVertex, Constants.MODIFICATION_TIMESTAMP_PROPERTY_KEY, RequestContext.get().getRequestTime()); - GraphHelper.setProperty(instanceVertex, Constants.MODIFIED_BY_KEY, RequestContext.get().getUser()); + AtlasGraphUtilsV1.setEncodedProperty(instanceVertex, Constants.MODIFIED_BY_KEY, RequestContext.get().getUser()); if (LOG.isDebugEnabled()) { LOG.debug("Setting modifiedBy: {} and modifiedTime: {}", RequestContext.get().getUser(), RequestContext.get().getRequestTime()); @@ -380,7 +381,7 @@ public final class TypedInstanceToGraphMapper { for (ITypedReferenceableInstance typedInstance : instances) { // Traverse AtlasVertex instanceVertex = getClassVertex(typedInstance); String fullText = fulltextMapper.mapRecursive(instanceVertex, true); - GraphHelper.setProperty(instanceVertex, Constants.ENTITY_TEXT_PROPERTY_KEY, fullText); + AtlasGraphUtilsV1.setEncodedProperty(instanceVertex, Constants.ENTITY_TEXT_PROPERTY_KEY, fullText); } } @@ -391,7 +392,7 @@ public final class TypedInstanceToGraphMapper { LOG.debug("mapping trait {}", traitName); } - GraphHelper.addProperty(instanceVertex, Constants.TRAIT_NAMES_PROPERTY_KEY, traitName); + AtlasGraphUtilsV1.addEncodedProperty(instanceVertex, Constants.TRAIT_NAMES_PROPERTY_KEY, traitName); ITypedStruct traitInstance = (ITypedStruct) typedInstance.getTrait(traitName); // add the attributes for the trait instance @@ -576,7 +577,7 @@ public final class TypedInstanceToGraphMapper { if (shouldDeleteKey) { String propertyNameForKey = GraphHelper.getQualifiedNameForMapKey(propertyName, currentKey); - GraphHelper.setProperty(instanceVertex, propertyNameForKey, null); + AtlasGraphUtilsV1.setProperty(instanceVertex, propertyNameForKey, null); } } return additionalMap; @@ -677,7 +678,7 @@ public final class TypedInstanceToGraphMapper { // Update attributes final MessageDigest digester = SHA256Utils.getDigester(); String newSignature = newAttributeValue.getSignatureHash(digester); - String curSignature = GraphHelper.getSingleValuedProperty(structInstanceVertex, SIGNATURE_HASH_PROPERTY_KEY, String.class); + String curSignature = AtlasGraphUtilsV1.getEncodedProperty(structInstanceVertex, SIGNATURE_HASH_PROPERTY_KEY, String.class); if (!newSignature.equals(curSignature)) { //Update struct vertex instance only if there is a change @@ -686,7 +687,7 @@ public final class TypedInstanceToGraphMapper { } mapInstanceToVertex(newAttributeValue, structInstanceVertex, newAttributeValue.fieldMapping().fields, false, operation); - GraphHelper.setProperty(structInstanceVertex, SIGNATURE_HASH_PROPERTY_KEY, String.valueOf(newSignature)); + AtlasGraphUtilsV1.setEncodedProperty(structInstanceVertex, SIGNATURE_HASH_PROPERTY_KEY, String.valueOf(newSignature)); } } @@ -838,7 +839,7 @@ public final class TypedInstanceToGraphMapper { } } - GraphHelper.setProperty(instanceVertex, vertexPropertyName, propertyValue); + AtlasGraphUtilsV1.setProperty(instanceVertex, vertexPropertyName, propertyValue); } public AtlasVertex lookupVertex(Id refId) { @@ -934,7 +935,7 @@ public final class TypedInstanceToGraphMapper { } RequestContext requestContext = RequestContext.get(); - GraphHelper.setProperty(reverseVertex, Constants.MODIFICATION_TIMESTAMP_PROPERTY_KEY, + AtlasGraphUtilsV1.setEncodedProperty(reverseVertex, Constants.MODIFICATION_TIMESTAMP_PROPERTY_KEY, requestContext.getRequestTime()); requestContext.recordEntityUpdate(reverseId._getId()); } http://git-wip-us.apache.org/repos/asf/atlas/blob/250d9321/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasEntityChangeNotifier.java ---------------------------------------------------------------------- diff --git a/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasEntityChangeNotifier.java b/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasEntityChangeNotifier.java index 2b07ae6..92d95f9 100644 --- a/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasEntityChangeNotifier.java +++ b/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasEntityChangeNotifier.java @@ -253,7 +253,7 @@ public class AtlasEntityChangeNotifier { try { String fullText = fullTextMapperV2.getIndexTextForEntity(guid); - GraphHelper.setProperty(atlasVertex, Constants.ENTITY_TEXT_PROPERTY_KEY, fullText); + AtlasGraphUtilsV1.setEncodedProperty(atlasVertex, Constants.ENTITY_TEXT_PROPERTY_KEY, fullText); } catch (AtlasBaseException e) { LOG.error("FullText mapping failed for Vertex[ guid = {} ]", guid, e); } @@ -282,10 +282,10 @@ public class AtlasEntityChangeNotifier { try { String classificationFullText = fullTextMapperV2.getIndexTextForClassifications(entityId, classifications); - String existingFullText = (String) GraphHelper.getProperty(atlasVertex, Constants.ENTITY_TEXT_PROPERTY_KEY); + String existingFullText = AtlasGraphUtilsV1.getEncodedProperty(atlasVertex, Constants.ENTITY_TEXT_PROPERTY_KEY, String.class); String newFullText = existingFullText + " " + classificationFullText; - GraphHelper.setProperty(atlasVertex, Constants.ENTITY_TEXT_PROPERTY_KEY, newFullText); + AtlasGraphUtilsV1.setEncodedProperty(atlasVertex, Constants.ENTITY_TEXT_PROPERTY_KEY, newFullText); } catch (AtlasBaseException e) { LOG.error("FullText mapping failed for Vertex[ guid = {} ]", entityId, e); } http://git-wip-us.apache.org/repos/asf/atlas/blob/250d9321/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasGraphUtilsV1.java ---------------------------------------------------------------------- diff --git a/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasGraphUtilsV1.java b/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasGraphUtilsV1.java index d1fd16f..65c5d41 100644 --- a/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasGraphUtilsV1.java +++ b/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasGraphUtilsV1.java @@ -153,16 +153,21 @@ public class AtlasGraphUtilsV1 { * @param propertyName * @param value */ - public static AtlasVertex addProperty(AtlasVertex vertex, String propertyName, Object value) { + public static AtlasVertex addEncodedProperty(AtlasVertex vertex, String propertyName, Object value) { if (LOG.isDebugEnabled()) { LOG.debug("==> addProperty({}, {}, {})", toString(vertex), propertyName, value); } - propertyName = encodePropertyKey(propertyName); + vertex.addProperty(propertyName, value); + return vertex; } public static <T extends AtlasElement> void setProperty(T element, String propertyName, Object value) { + setEncodedProperty(element, encodePropertyKey(propertyName), value); + } + + public static <T extends AtlasElement> void setEncodedProperty(T element, String propertyName, Object value) { if (LOG.isDebugEnabled()) { LOG.debug("==> setProperty({}, {}, {})", toString(element), propertyName, value); } @@ -195,8 +200,26 @@ public class AtlasGraphUtilsV1 { } } + public static <T extends AtlasVertex> Object getProperty(T vertex, String propertyName) { + String encodePropertyName = encodePropertyKey(propertyName); + + if(AtlasGraphProvider.getGraphInstance().isMultiProperty(encodePropertyName)) { + return vertex.getPropertyValues(encodePropertyName, String.class); + } + + return vertex.getProperty(encodePropertyKey(propertyName), Object.class); + } + + public static <T extends AtlasElement> Object getProperty(T element, String propertyName) { + return element.getProperty(encodePropertyKey(propertyName), Object.class); + } + public static <T extends AtlasElement, O> O getProperty(T element, String propertyName, Class<O> returnType) { - Object property = element.getProperty(encodePropertyKey(propertyName), returnType); + return getEncodedProperty(element, encodePropertyKey(propertyName), returnType); + } + + public static <T extends AtlasElement, O> O getEncodedProperty(T element, String propertyName, Class<O> returnType) { + Object property = element.getProperty(propertyName, returnType); if (LOG.isDebugEnabled()) { LOG.debug("getProperty({}, {}) ==> {}", toString(element), propertyName, returnType.cast(property)); http://git-wip-us.apache.org/repos/asf/atlas/blob/250d9321/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasStructDefStoreV1.java ---------------------------------------------------------------------- diff --git a/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasStructDefStoreV1.java b/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasStructDefStoreV1.java index e59c389..9b2350d 100644 --- a/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasStructDefStoreV1.java +++ b/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasStructDefStoreV1.java @@ -419,7 +419,7 @@ public class AtlasStructDefStoreV1 extends AtlasAbstractDefStoreV1<AtlasStructDe if (CollectionUtils.isNotEmpty(attrNames)) { for (String attrName : attrNames) { String propertyKey = AtlasGraphUtilsV1.getTypeDefPropertyKey(ret, attrName); - String attribJson = vertex.getProperty(GraphHelper.encodePropertyKey(propertyKey), String.class); + String attribJson = vertex.getProperty(AtlasGraphUtilsV1.encodePropertyKey(propertyKey), String.class); attributeDefs.add(toAttributeDefFromJson(structDef, AtlasType.fromJson(attribJson, Map.class), typeDefStore)); http://git-wip-us.apache.org/repos/asf/atlas/blob/250d9321/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/DeleteHandlerV1.java ---------------------------------------------------------------------- diff --git a/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/DeleteHandlerV1.java b/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/DeleteHandlerV1.java index d9fa2c5..8024302 100644 --- a/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/DeleteHandlerV1.java +++ b/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/DeleteHandlerV1.java @@ -460,7 +460,7 @@ public abstract class DeleteHandlerV1 { if (attrDef.getIsOptional()) { edge = graphHelper.getEdgeForLabel(outVertex, edgeLabel); if (shouldUpdateInverseReferences) { - GraphHelper.setProperty(outVertex, propertyName, null); + AtlasGraphUtilsV1.setProperty(outVertex, propertyName, null); } } else { // Cannot unset a required attribute. @@ -504,7 +504,7 @@ public abstract class DeleteHandlerV1 { // This prevents dangling edge IDs (i.e. edge IDs for deleted edges) // from the remaining in the list if there are duplicates. elements.removeAll(Collections.singletonList(elementEdge.getId().toString())); - GraphHelper.setProperty(outVertex, propertyName, elements); + AtlasGraphUtilsV1.setProperty(outVertex, propertyName, elements); break; } @@ -520,7 +520,7 @@ public abstract class DeleteHandlerV1 { keys = new ArrayList<>(keys); //Make a copy, else list.remove reflects on titan.getProperty() for (String key : keys) { String keyPropertyName = GraphHelper.getQualifiedNameForMapKey(propertyName, key); - String mapEdgeId = GraphHelper.getSingleValuedProperty(outVertex, keyPropertyName, String.class); + String mapEdgeId = AtlasGraphUtilsV1.getProperty(outVertex, keyPropertyName, String.class); AtlasEdge mapEdge = graphHelper.getEdgeByEdgeId(outVertex, keyPropertyName, mapEdgeId); if(mapEdge != null) { AtlasVertex mapVertex = mapEdge.getInVertex(); @@ -540,8 +540,8 @@ public abstract class DeleteHandlerV1 { LOG.debug("Removing edge {}, key {} from the map attribute {}", string(mapEdge), key, attribute.getName()); keys.remove(key); - GraphHelper.setProperty(outVertex, propertyName, keys); - GraphHelper.setProperty(outVertex, keyPropertyName, null); + AtlasGraphUtilsV1.setProperty(outVertex, propertyName, keys); + AtlasGraphUtilsV1.setProperty(outVertex, keyPropertyName, null); } break; } @@ -562,9 +562,9 @@ public abstract class DeleteHandlerV1 { if (edge != null) { deleteEdge(edge, false); RequestContextV1 requestContext = RequestContextV1.get(); - GraphHelper.setProperty(outVertex, Constants.MODIFICATION_TIMESTAMP_PROPERTY_KEY, + AtlasGraphUtilsV1.setEncodedProperty(outVertex, Constants.MODIFICATION_TIMESTAMP_PROPERTY_KEY, requestContext.getRequestTime()); - GraphHelper.setProperty(outVertex, Constants.MODIFIED_BY_KEY, requestContext.getUser()); + AtlasGraphUtilsV1.setEncodedProperty(outVertex, Constants.MODIFIED_BY_KEY, requestContext.getUser()); requestContext.recordEntityUpdate(new AtlasObjectId(outId, typeName)); } } http://git-wip-us.apache.org/repos/asf/atlas/blob/250d9321/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/EntityGraphMapper.java ---------------------------------------------------------------------- diff --git a/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/EntityGraphMapper.java b/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/EntityGraphMapper.java index 47960f3..a085ca5 100644 --- a/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/EntityGraphMapper.java +++ b/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/EntityGraphMapper.java @@ -101,34 +101,34 @@ public class EntityGraphMapper { AtlasVertex ret = createStructVertex(entity); for (String superTypeName : entityType.getAllSuperTypes()) { - AtlasGraphUtilsV1.addProperty(ret, Constants.SUPER_TYPES_PROPERTY_KEY, superTypeName); + AtlasGraphUtilsV1.addEncodedProperty(ret, Constants.SUPER_TYPES_PROPERTY_KEY, superTypeName); } - AtlasGraphUtilsV1.setProperty(ret, Constants.GUID_PROPERTY_KEY, guid); - AtlasGraphUtilsV1.setProperty(ret, Constants.VERSION_PROPERTY_KEY, getEntityVersion(entity)); + AtlasGraphUtilsV1.setEncodedProperty(ret, Constants.GUID_PROPERTY_KEY, guid); + AtlasGraphUtilsV1.setEncodedProperty(ret, Constants.VERSION_PROPERTY_KEY, getEntityVersion(entity)); return ret; } public void updateSystemAttributes(AtlasVertex vertex, AtlasEntity entity) { if (entity.getStatus() != null) { - AtlasGraphUtilsV1.setProperty(vertex, Constants.STATE_PROPERTY_KEY, entity.getStatus().name()); + AtlasGraphUtilsV1.setEncodedProperty(vertex, Constants.STATE_PROPERTY_KEY, entity.getStatus().name()); } if (entity.getCreateTime() != null) { - AtlasGraphUtilsV1.setProperty(vertex, Constants.TIMESTAMP_PROPERTY_KEY, entity.getCreateTime().getTime()); + AtlasGraphUtilsV1.setEncodedProperty(vertex, Constants.TIMESTAMP_PROPERTY_KEY, entity.getCreateTime().getTime()); } if (entity.getUpdateTime() != null) { - AtlasGraphUtilsV1.setProperty(vertex, Constants.MODIFICATION_TIMESTAMP_PROPERTY_KEY, entity.getUpdateTime().getTime()); + AtlasGraphUtilsV1.setEncodedProperty(vertex, Constants.MODIFICATION_TIMESTAMP_PROPERTY_KEY, entity.getUpdateTime().getTime()); } if (StringUtils.isNotEmpty(entity.getCreatedBy())) { - AtlasGraphUtilsV1.setProperty(vertex, Constants.CREATED_BY_KEY, entity.getCreatedBy()); + AtlasGraphUtilsV1.setEncodedProperty(vertex, Constants.CREATED_BY_KEY, entity.getCreatedBy()); } if (StringUtils.isNotEmpty(entity.getUpdatedBy())) { - AtlasGraphUtilsV1.setProperty(vertex, Constants.MODIFIED_BY_KEY, entity.getUpdatedBy()); + AtlasGraphUtilsV1.setEncodedProperty(vertex, Constants.MODIFIED_BY_KEY, entity.getUpdatedBy()); } } @@ -197,12 +197,12 @@ public class EntityGraphMapper { final AtlasVertex ret = graph.addVertex(); - AtlasGraphUtilsV1.setProperty(ret, Constants.ENTITY_TYPE_PROPERTY_KEY, struct.getTypeName()); - AtlasGraphUtilsV1.setProperty(ret, Constants.STATE_PROPERTY_KEY, AtlasEntity.Status.ACTIVE.name()); - AtlasGraphUtilsV1.setProperty(ret, Constants.TIMESTAMP_PROPERTY_KEY, RequestContextV1.get().getRequestTime()); - AtlasGraphUtilsV1.setProperty(ret, Constants.MODIFICATION_TIMESTAMP_PROPERTY_KEY, RequestContextV1.get().getRequestTime()); - AtlasGraphUtilsV1.setProperty(ret, Constants.CREATED_BY_KEY, RequestContextV1.get().getUser()); - GraphHelper.setProperty(ret, Constants.MODIFIED_BY_KEY, RequestContextV1.get().getUser()); + AtlasGraphUtilsV1.setEncodedProperty(ret, Constants.ENTITY_TYPE_PROPERTY_KEY, struct.getTypeName()); + AtlasGraphUtilsV1.setEncodedProperty(ret, Constants.STATE_PROPERTY_KEY, AtlasEntity.Status.ACTIVE.name()); + AtlasGraphUtilsV1.setEncodedProperty(ret, Constants.TIMESTAMP_PROPERTY_KEY, RequestContextV1.get().getRequestTime()); + AtlasGraphUtilsV1.setEncodedProperty(ret, Constants.MODIFICATION_TIMESTAMP_PROPERTY_KEY, RequestContextV1.get().getRequestTime()); + AtlasGraphUtilsV1.setEncodedProperty(ret, Constants.CREATED_BY_KEY, RequestContextV1.get().getUser()); + AtlasGraphUtilsV1.setEncodedProperty(ret, Constants.MODIFIED_BY_KEY, RequestContextV1.get().getUser()); if (LOG.isDebugEnabled()) { LOG.debug("<== createStructVertex({})", struct.getTypeName()); @@ -220,7 +220,7 @@ public class EntityGraphMapper { AtlasVertex ret = createStructVertex(classification); - AtlasGraphUtilsV1.addProperty(ret, Constants.SUPER_TYPES_PROPERTY_KEY, classificationType.getAllSuperTypes()); + AtlasGraphUtilsV1.addEncodedProperty(ret, Constants.SUPER_TYPES_PROPERTY_KEY, classificationType.getAllSuperTypes()); return ret; } @@ -362,7 +362,7 @@ public class EntityGraphMapper { softRefValue = String.format(SOFT_REF_FORMAT, objectId.getTypeName(), resolvedGuid); } - AtlasGraphUtilsV1.setProperty(ctx.getReferringVertex(), ctx.getVertexProperty(), softRefValue); + AtlasGraphUtilsV1.setEncodedProperty(ctx.getReferringVertex(), ctx.getVertexProperty(), softRefValue); return softRefValue; } @@ -447,7 +447,7 @@ public class EntityGraphMapper { } } - AtlasGraphUtilsV1.setProperty(ctx.getReferringVertex(), ctx.getVertexProperty(), ret); + AtlasGraphUtilsV1.setEncodedProperty(ctx.getReferringVertex(), ctx.getVertexProperty(), ret); return ret; } @@ -553,7 +553,7 @@ public class EntityGraphMapper { if (CollectionUtils.isNotEmpty(currentKeys)) { for (String key : currentKeys) { - String propertyNameForKey = GraphHelper.getQualifiedNameForMapKey(ctx.getVertexProperty(), GraphHelper.encodePropertyKey(key)); + String propertyNameForKey = GraphHelper.getQualifiedNameForMapKey(ctx.getVertexProperty(), AtlasGraphUtilsV1.encodePropertyKey(key)); Object propertyValueForKey = getMapValueProperty(mapType.getValueType(), ctx.getReferringVertex(), propertyNameForKey); currentMap.put(key, propertyValueForKey); @@ -566,7 +566,7 @@ public class EntityGraphMapper { AtlasAttribute inverseRefAttribute = attribute.getInverseRefAttribute(); for (Map.Entry<Object, Object> entry : newVal.entrySet()) { String key = entry.getKey().toString(); - String propertyName = GraphHelper.getQualifiedNameForMapKey(ctx.getVertexProperty(), GraphHelper.encodePropertyKey(key)); + String propertyName = GraphHelper.getQualifiedNameForMapKey(ctx.getVertexProperty(), AtlasGraphUtilsV1.encodePropertyKey(key)); AtlasEdge existingEdge = isSoftReference ? null : getEdgeIfExists(mapType, currentMap, key); AttributeMutationContext mapCtx = new AttributeMutationContext(ctx.getOp(), ctx.getReferringVertex(), attribute, entry.getValue(), propertyName, mapType.getValueType(), existingEdge); @@ -677,8 +677,8 @@ public class EntityGraphMapper { } private void updateModificationMetadata(AtlasVertex vertex) { - AtlasGraphUtilsV1.setProperty(vertex, Constants.MODIFICATION_TIMESTAMP_PROPERTY_KEY, RequestContextV1.get().getRequestTime()); - GraphHelper.setProperty(vertex, Constants.MODIFIED_BY_KEY, RequestContextV1.get().getUser()); + AtlasGraphUtilsV1.setEncodedProperty(vertex, Constants.MODIFICATION_TIMESTAMP_PROPERTY_KEY, RequestContextV1.get().getRequestTime()); + AtlasGraphUtilsV1.setEncodedProperty(vertex, Constants.MODIFIED_BY_KEY, RequestContextV1.get().getUser()); } private int getEntityVersion(AtlasEntity entity) { @@ -829,8 +829,8 @@ public class EntityGraphMapper { } if (shouldDeleteKey) { - String propertyNameForKey = GraphHelper.getQualifiedNameForMapKey(propertyName, GraphHelper.encodePropertyKey(currentKey)); - GraphHelper.setProperty(vertex, propertyNameForKey, null); + String propertyNameForKey = GraphHelper.getQualifiedNameForMapKey(propertyName, AtlasGraphUtilsV1.encodePropertyKey(currentKey)); + AtlasGraphUtilsV1.setEncodedProperty(vertex, propertyNameForKey, null); } } @@ -926,10 +926,10 @@ public class EntityGraphMapper { private void setArrayElementsProperty(AtlasType elementType, boolean isSoftReference, AtlasVertex vertex, String vertexPropertyName, List<Object> values) { if (AtlasGraphUtilsV1.isReference(elementType) && !isSoftReference) { - GraphHelper.setListPropertyFromElementIds(vertex, vertexPropertyName, (List) values); + vertex.setPropertyFromElementsIds(vertexPropertyName, (List) values); } else { - GraphHelper.setProperty(vertex, vertexPropertyName, values); + AtlasGraphUtilsV1.setEncodedProperty(vertex, vertexPropertyName, values); } } @@ -957,8 +957,8 @@ public class EntityGraphMapper { GraphHelper.getStatus(edge) == AtlasEntity.Status.DELETED && GraphHelper.getStatus(edge.getInVertex()) == AtlasEntity.Status.DELETED) { //Resurrect the vertex and edge to ACTIVE state - GraphHelper.setProperty(edge, STATE_PROPERTY_KEY, AtlasEntity.Status.ACTIVE.name()); - GraphHelper.setProperty(edge.getInVertex(), STATE_PROPERTY_KEY, AtlasEntity.Status.ACTIVE.name()); + AtlasGraphUtilsV1.setEncodedProperty(edge, STATE_PROPERTY_KEY, AtlasEntity.Status.ACTIVE.name()); + AtlasGraphUtilsV1.setEncodedProperty(edge.getInVertex(), STATE_PROPERTY_KEY, AtlasEntity.Status.ACTIVE.name()); } } } @@ -990,7 +990,7 @@ public class EntityGraphMapper { LOG.debug("mapping classification {}", classification); } - GraphHelper.addProperty(instanceVertex, Constants.TRAIT_NAMES_PROPERTY_KEY, classification.getTypeName()); + AtlasGraphUtilsV1.addEncodedProperty(instanceVertex, Constants.TRAIT_NAMES_PROPERTY_KEY, classification.getTypeName()); // add a new AtlasVertex for the struct or trait instance AtlasVertex classificationVertex = createClassificationVertex(classification); if (LOG.isDebugEnabled()) { @@ -1091,7 +1091,7 @@ public class EntityGraphMapper { // add it back again for (String traitName : traitNames) { - GraphHelper.addProperty(instanceVertex, Constants.TRAIT_NAMES_PROPERTY_KEY, traitName); + AtlasGraphUtilsV1.addEncodedProperty(instanceVertex, Constants.TRAIT_NAMES_PROPERTY_KEY, traitName); } updateModificationMetadata(instanceVertex); } http://git-wip-us.apache.org/repos/asf/atlas/blob/250d9321/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/EntityGraphRetriever.java ---------------------------------------------------------------------- diff --git a/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/EntityGraphRetriever.java b/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/EntityGraphRetriever.java index f99b4a9..5395b7a 100644 --- a/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/EntityGraphRetriever.java +++ b/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/EntityGraphRetriever.java @@ -429,11 +429,11 @@ public final class EntityGraphRetriever { } private Object mapVertexToAttribute(AtlasVertex entityVertex, AtlasAttribute attribute, AtlasEntityExtInfo entityExtInfo, boolean isMinExtInfo) throws AtlasBaseException { - Object ret = null; - AtlasType attrType = attribute.getAttributeType(); - String vertexPropertyName = attribute.getQualifiedName(); - String edgeLabel = EDGE_LABEL_PREFIX + vertexPropertyName; - boolean isOwnedAttribute = attribute.isOwnedRef(); + Object ret = null; + AtlasType attrType = attribute.getAttributeType(); + String qualifiedName = attribute.getQualifiedName(); + String edgeLabel = EDGE_LABEL_PREFIX + qualifiedName; + boolean isOwnedAttribute = attribute.isOwnedRef(); if (LOG.isDebugEnabled()) { LOG.debug("Mapping vertex {} to atlas entity {}.{}", entityVertex, attribute.getDefinedInDef().getName(), attribute.getName()); @@ -441,33 +441,33 @@ public final class EntityGraphRetriever { switch (attrType.getTypeCategory()) { case PRIMITIVE: - ret = mapVertexToPrimitive(entityVertex, vertexPropertyName, attribute.getAttributeDef()); + ret = mapVertexToPrimitive(entityVertex, attribute.getVertexPropertyName(), attribute.getAttributeDef()); break; case ENUM: - ret = GraphHelper.getProperty(entityVertex, vertexPropertyName); + ret = AtlasGraphUtilsV1.getEncodedProperty(entityVertex, attribute.getVertexPropertyName(), Object.class); break; case STRUCT: ret = mapVertexToStruct(entityVertex, edgeLabel, null, entityExtInfo, isMinExtInfo); break; case OBJECT_ID_TYPE: if(attribute.getAttributeDef().isSoftReferenced()) { - ret = mapVertexToObjectIdForSoftRef(entityVertex, vertexPropertyName); + ret = mapVertexToObjectIdForSoftRef(entityVertex, attribute.getVertexPropertyName()); } else { ret = mapVertexToObjectId(entityVertex, edgeLabel, null, entityExtInfo, isOwnedAttribute, isMinExtInfo); } break; case ARRAY: if(attribute.getAttributeDef().isSoftReferenced()) { - ret = mapVertexToArrayForSoftRef(entityVertex, vertexPropertyName); + ret = mapVertexToArrayForSoftRef(entityVertex, attribute.getVertexPropertyName()); } else { - ret = mapVertexToArray(entityVertex, (AtlasArrayType) attrType, vertexPropertyName, entityExtInfo, isOwnedAttribute, isMinExtInfo); + ret = mapVertexToArray(entityVertex, (AtlasArrayType) attrType, qualifiedName, entityExtInfo, isOwnedAttribute, isMinExtInfo); } break; case MAP: if(attribute.getAttributeDef().isSoftReferenced()) { - ret = mapVertexToMapForSoftRef(entityVertex, vertexPropertyName); + ret = mapVertexToMapForSoftRef(entityVertex, attribute.getVertexPropertyName()); } else { - ret = mapVertexToMap(entityVertex, (AtlasMapType) attrType, vertexPropertyName, entityExtInfo, isOwnedAttribute, isMinExtInfo); + ret = mapVertexToMap(entityVertex, (AtlasMapType) attrType, qualifiedName, entityExtInfo, isOwnedAttribute, isMinExtInfo); } break; case CLASSIFICATION: @@ -526,7 +526,7 @@ public final class EntityGraphRetriever { } private AtlasObjectId mapVertexToObjectIdForSoftRef(AtlasVertex entityVertex, String vertexPropertyName) { - String rawValue = GraphHelper.getSingleValuedProperty(entityVertex, vertexPropertyName, String.class); + String rawValue = AtlasGraphUtilsV1.getEncodedProperty(entityVertex, vertexPropertyName, String.class); if(StringUtils.isEmpty(rawValue)) { return null; } @@ -639,43 +639,43 @@ public final class EntityGraphRetriever { private Object mapVertexToPrimitive(AtlasVertex entityVertex, final String vertexPropertyName, AtlasAttributeDef attrDef) { Object ret = null; - if (GraphHelper.getSingleValuedProperty(entityVertex, vertexPropertyName, Object.class) == null) { + if (AtlasGraphUtilsV1.getEncodedProperty(entityVertex, vertexPropertyName, Object.class) == null) { return null; } switch (attrDef.getTypeName().toLowerCase()) { case ATLAS_TYPE_STRING: - ret = GraphHelper.getSingleValuedProperty(entityVertex, vertexPropertyName, String.class); + ret = AtlasGraphUtilsV1.getEncodedProperty(entityVertex, vertexPropertyName, String.class); break; case ATLAS_TYPE_SHORT: - ret = GraphHelper.getSingleValuedProperty(entityVertex, vertexPropertyName, Short.class); + ret = AtlasGraphUtilsV1.getEncodedProperty(entityVertex, vertexPropertyName, Short.class); break; case ATLAS_TYPE_INT: - ret = GraphHelper.getSingleValuedProperty(entityVertex, vertexPropertyName, Integer.class); + ret = AtlasGraphUtilsV1.getEncodedProperty(entityVertex, vertexPropertyName, Integer.class); break; case ATLAS_TYPE_BIGINTEGER: - ret = GraphHelper.getSingleValuedProperty(entityVertex, vertexPropertyName, BigInteger.class); + ret = AtlasGraphUtilsV1.getEncodedProperty(entityVertex, vertexPropertyName, BigInteger.class); break; case ATLAS_TYPE_BOOLEAN: - ret = GraphHelper.getSingleValuedProperty(entityVertex, vertexPropertyName, Boolean.class); + ret = AtlasGraphUtilsV1.getEncodedProperty(entityVertex, vertexPropertyName, Boolean.class); break; case ATLAS_TYPE_BYTE: - ret = GraphHelper.getSingleValuedProperty(entityVertex, vertexPropertyName, Byte.class); + ret = AtlasGraphUtilsV1.getEncodedProperty(entityVertex, vertexPropertyName, Byte.class); break; case ATLAS_TYPE_LONG: - ret = GraphHelper.getSingleValuedProperty(entityVertex, vertexPropertyName, Long.class); + ret = AtlasGraphUtilsV1.getEncodedProperty(entityVertex, vertexPropertyName, Long.class); break; case ATLAS_TYPE_FLOAT: - ret = GraphHelper.getSingleValuedProperty(entityVertex, vertexPropertyName, Float.class); + ret = AtlasGraphUtilsV1.getEncodedProperty(entityVertex, vertexPropertyName, Float.class); break; case ATLAS_TYPE_DOUBLE: - ret = GraphHelper.getSingleValuedProperty(entityVertex, vertexPropertyName, Double.class); + ret = AtlasGraphUtilsV1.getEncodedProperty(entityVertex, vertexPropertyName, Double.class); break; case ATLAS_TYPE_BIGDECIMAL: - ret = GraphHelper.getSingleValuedProperty(entityVertex, vertexPropertyName, BigDecimal.class); + ret = AtlasGraphUtilsV1.getEncodedProperty(entityVertex, vertexPropertyName, BigDecimal.class); break; case ATLAS_TYPE_DATE: - ret = new Date(GraphHelper.getSingleValuedProperty(entityVertex, vertexPropertyName, Long.class)); + ret = new Date(AtlasGraphUtilsV1.getEncodedProperty(entityVertex, vertexPropertyName, Long.class)); break; default: break;