Commit b6a664df by Sarath Subramanian

ATLAS-2836: Remove redundant encoding of vertex property keys

parent 70e10cc0
...@@ -22,6 +22,8 @@ import org.apache.atlas.ApplicationProperties; ...@@ -22,6 +22,8 @@ import org.apache.atlas.ApplicationProperties;
import org.apache.atlas.AtlasException; import org.apache.atlas.AtlasException;
import org.apache.commons.configuration.Configuration; import org.apache.commons.configuration.Configuration;
import static org.apache.atlas.type.AtlasStructType.AtlasAttribute.encodePropertyKey;
/** /**
* Repository Constants. * Repository Constants.
* *
...@@ -34,52 +36,52 @@ public final class Constants { ...@@ -34,52 +36,52 @@ public final class Constants {
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 = encodePropertyKey(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 = encodePropertyKey(RELATIONSHIP_PROPERTY_KEY_PREFIX + GUID_PROPERTY_KEY);
/** /**
* Entity type name property key. * 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"; public static final String TYPE_NAME_INTERNAL = INTERNAL_PROPERTY_KEY_PREFIX + "internal";
/** /**
* Entity type's super types property key. * 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. * Full-text for the entity for enabling full-text search.
*/ */
public static final String ENTITY_TEXT_PROPERTY_KEY = "entityText"; public static final String ENTITY_TEXT_PROPERTY_KEY = encodePropertyKey("entityText");
/** /**
* Properties for type store graph. * Properties for type store graph.
*/ */
public static final String TYPE_CATEGORY_PROPERTY_KEY = getTypePropertyKey(INTERNAL_PROPERTY_KEY_PREFIX + "type.category"); public static final String TYPE_CATEGORY_PROPERTY_KEY = getEncodedTypePropertyKey(INTERNAL_PROPERTY_KEY_PREFIX + "type.category");
public static final String VERTEX_TYPE_PROPERTY_KEY = getTypePropertyKey(INTERNAL_PROPERTY_KEY_PREFIX + "type"); public static final String VERTEX_TYPE_PROPERTY_KEY = getEncodedTypePropertyKey(INTERNAL_PROPERTY_KEY_PREFIX + "type");
public static final String TYPENAME_PROPERTY_KEY = getTypePropertyKey(INTERNAL_PROPERTY_KEY_PREFIX + "type.name"); public static final String TYPENAME_PROPERTY_KEY = getEncodedTypePropertyKey(INTERNAL_PROPERTY_KEY_PREFIX + "type.name");
public static final String TYPEDESCRIPTION_PROPERTY_KEY = getTypePropertyKey(INTERNAL_PROPERTY_KEY_PREFIX + "type.description"); public static final String TYPEDESCRIPTION_PROPERTY_KEY = getEncodedTypePropertyKey(INTERNAL_PROPERTY_KEY_PREFIX + "type.description");
public static final String TYPEVERSION_PROPERTY_KEY = getTypePropertyKey(INTERNAL_PROPERTY_KEY_PREFIX + "type.version"); public static final String TYPEVERSION_PROPERTY_KEY = getEncodedTypePropertyKey(INTERNAL_PROPERTY_KEY_PREFIX + "type.version");
public static final String TYPEOPTIONS_PROPERTY_KEY = getTypePropertyKey(INTERNAL_PROPERTY_KEY_PREFIX + "type.options"); public static final String TYPEOPTIONS_PROPERTY_KEY = getEncodedTypePropertyKey(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 = encodePropertyKey("tagPropagation");
public static final String RELATIONSHIPTYPE_BLOCKED_PROPAGATED_CLASSIFICATIONS_KEY = "blockedPropagatedClassifications"; public static final String RELATIONSHIPTYPE_BLOCKED_PROPAGATED_CLASSIFICATIONS_KEY = encodePropertyKey("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 = encodePropertyKey(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 = encodePropertyKey(INTERNAL_PROPERTY_KEY_PREFIX + "propagatedTraitNames");
public static final String VERSION_PROPERTY_KEY = INTERNAL_PROPERTY_KEY_PREFIX + "version"; public static final String VERSION_PROPERTY_KEY = encodePropertyKey(INTERNAL_PROPERTY_KEY_PREFIX + "version");
public static final String STATE_PROPERTY_KEY = INTERNAL_PROPERTY_KEY_PREFIX + "state"; public static final String STATE_PROPERTY_KEY = encodePropertyKey(INTERNAL_PROPERTY_KEY_PREFIX + "state");
public static final String CREATED_BY_KEY = INTERNAL_PROPERTY_KEY_PREFIX + "createdBy"; public static final String CREATED_BY_KEY = encodePropertyKey(INTERNAL_PROPERTY_KEY_PREFIX + "createdBy");
public static final String MODIFIED_BY_KEY = INTERNAL_PROPERTY_KEY_PREFIX + "modifiedBy"; public static final String MODIFIED_BY_KEY = encodePropertyKey(INTERNAL_PROPERTY_KEY_PREFIX + "modifiedBy");
/** /**
* The homeId field is used when saving into Atlas a copy of an object that is being imported from another * The homeId field is used when saving into Atlas a copy of an object that is being imported from another
...@@ -91,7 +93,7 @@ public final class Constants { ...@@ -91,7 +93,7 @@ public final class Constants {
* An object with a non-null homeId is a copy of an object mastered by a different repository and the object * An object with a non-null homeId is a copy of an object mastered by a different repository and the object
* should only be updated via the notifications and calls from Open Metadata Repository Services. * should only be updated via the notifications and calls from Open Metadata Repository Services.
*/ */
public static final String HOME_ID_KEY = INTERNAL_PROPERTY_KEY_PREFIX + "homeId"; public static final String HOME_ID_KEY = encodePropertyKey(INTERNAL_PROPERTY_KEY_PREFIX + "homeId");
/** /**
* The isProxy field is used when saving into Atlas a proxy of an entity - i.e. it is not a whole entity, but * The isProxy field is used when saving into Atlas a proxy of an entity - i.e. it is not a whole entity, but
...@@ -99,12 +101,11 @@ public final class Constants { ...@@ -99,12 +101,11 @@ public final class Constants {
* The isProxy field will be set to true if the entity is a proxy. The field is used during retrieval of an * The isProxy field will be set to true if the entity is a proxy. The field is used during retrieval of an
* entity (proxy) from Atlas to indicate that the entity does not contain full entity detail. * entity (proxy) from Atlas to indicate that the entity does not contain full entity detail.
*/ */
public static final String IS_PROXY_KEY = INTERNAL_PROPERTY_KEY_PREFIX + "isProxy"; public static final String IS_PROXY_KEY = encodePropertyKey(INTERNAL_PROPERTY_KEY_PREFIX + "isProxy");
public static final String TIMESTAMP_PROPERTY_KEY = INTERNAL_PROPERTY_KEY_PREFIX + "timestamp"; public static final String TIMESTAMP_PROPERTY_KEY = encodePropertyKey(INTERNAL_PROPERTY_KEY_PREFIX + "timestamp");
public static final String MODIFICATION_TIMESTAMP_PROPERTY_KEY = public static final String MODIFICATION_TIMESTAMP_PROPERTY_KEY = encodePropertyKey(INTERNAL_PROPERTY_KEY_PREFIX + "modificationTimestamp");
INTERNAL_PROPERTY_KEY_PREFIX + "modificationTimestamp";
/** /**
* search backing index name. * search backing index name.
...@@ -141,19 +142,19 @@ public final class Constants { ...@@ -141,19 +142,19 @@ public final class Constants {
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 = encodePropertyKey(INTERNAL_PROPERTY_KEY_PREFIX + "entityGuid");
public static final String CLASSIFICATION_ENTITY_STATUS = INTERNAL_PROPERTY_KEY_PREFIX + "entityStatus"; public static final String CLASSIFICATION_ENTITY_STATUS = encodePropertyKey(INTERNAL_PROPERTY_KEY_PREFIX + "entityStatus");
public static final String CLASSIFICATION_VALIDITY_PERIODS_KEY = INTERNAL_PROPERTY_KEY_PREFIX + "validityPeriods"; public static final String CLASSIFICATION_VALIDITY_PERIODS_KEY = encodePropertyKey(INTERNAL_PROPERTY_KEY_PREFIX + "validityPeriods");
public static final String CLASSIFICATION_VERTEX_PROPAGATE_KEY = INTERNAL_PROPERTY_KEY_PREFIX + "propagate"; public static final String CLASSIFICATION_VERTEX_PROPAGATE_KEY = encodePropertyKey(INTERNAL_PROPERTY_KEY_PREFIX + "propagate");
public static final String CLASSIFICATION_VERTEX_REMOVE_PROPAGATIONS_KEY = INTERNAL_PROPERTY_KEY_PREFIX + "removePropagations"; public static final String CLASSIFICATION_VERTEX_REMOVE_PROPAGATIONS_KEY = encodePropertyKey(INTERNAL_PROPERTY_KEY_PREFIX + "removePropagations");
public static final String CLASSIFICATION_VERTEX_NAME_KEY = TYPE_NAME_PROPERTY_KEY; public static final String CLASSIFICATION_VERTEX_NAME_KEY = encodePropertyKey(TYPE_NAME_PROPERTY_KEY);
public static final String CLASSIFICATION_EDGE_NAME_PROPERTY_KEY = INTERNAL_PROPERTY_KEY_PREFIX + "name"; public static final String CLASSIFICATION_EDGE_NAME_PROPERTY_KEY = encodePropertyKey(INTERNAL_PROPERTY_KEY_PREFIX + "name");
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 = encodePropertyKey(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 TERM_ASSIGNMENT_LABEL = "r:AtlasGlossarySemanticAssignment";
public static final String ATTRIBUTE_INDEX_PROPERTY_KEY = INTERNAL_PROPERTY_KEY_PREFIX + "index"; public static final String ATTRIBUTE_INDEX_PROPERTY_KEY = encodePropertyKey(INTERNAL_PROPERTY_KEY_PREFIX + "index");
public static final String ATTRIBUTE_KEY_PROPERTY_KEY = INTERNAL_PROPERTY_KEY_PREFIX + "key"; public static final String ATTRIBUTE_KEY_PROPERTY_KEY = encodePropertyKey(INTERNAL_PROPERTY_KEY_PREFIX + "key");
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";
...@@ -161,7 +162,7 @@ public final class Constants { ...@@ -161,7 +162,7 @@ public final class Constants {
private Constants() { private Constants() {
} }
private static String getTypePropertyKey(String defaultKey) { private static String getEncodedTypePropertyKey(String defaultKey) {
try { try {
Configuration configuration = ApplicationProperties.get(); Configuration configuration = ApplicationProperties.get();
...@@ -171,9 +172,9 @@ public final class Constants { ...@@ -171,9 +172,9 @@ public final class Constants {
return defaultKey.replaceAll("\\.", "_"); return defaultKey.replaceAll("\\.", "_");
} }
return defaultKey; return encodePropertyKey(defaultKey);
} catch (AtlasException e) { } catch (AtlasException e) {
return defaultKey; return encodePropertyKey(defaultKey);
} }
} }
} }
...@@ -642,6 +642,14 @@ public class AtlasStructType extends AtlasType { ...@@ -642,6 +642,14 @@ public class AtlasStructType extends AtlasType {
throw new AtlasBaseException(AtlasErrorCode.UNKNOWN_ATTRIBUTE, attrName, structDef.getName()); 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());
}
AtlasEntityType getReferencedEntityType(AtlasType type) { AtlasEntityType getReferencedEntityType(AtlasType type) {
if (type instanceof AtlasArrayType) { if (type instanceof AtlasArrayType) {
type = ((AtlasArrayType)type).getElementType(); type = ((AtlasArrayType)type).getElementType();
...@@ -853,12 +861,12 @@ public class AtlasStructType extends AtlasType { ...@@ -853,12 +861,12 @@ public class AtlasStructType extends AtlasType {
return attrName.contains(".") ? attrName : String.format("%s.%s", typeName, attrName); return attrName.contains(".") ? attrName : String.format("%s.%s", typeName, attrName);
} }
// Keys copied from org.janusgraph.graphdb.types.system.SystemTypeManager.RESERVED_CHARS
// JanusGraph checks that these chars are not part of any keys hence encoding
private static String[][] RESERVED_CHAR_ENCODE_MAP = new String[][] { private static String[][] RESERVED_CHAR_ENCODE_MAP = new String[][] {
new String[] { "{", "_o" }, new String[] { "{", "_o" },
new String[] { "}", "_c" }, new String[] { "}", "_c" },
new String[] { "\"", "_q" }, new String[] { "\"", "_q" },
new String[] { "$", "_d" },
new String[] { "%", "_p" },
}; };
private static final char[] IDX_QRY_OFFENDING_CHARS = { '@', '/', ' ', '-' }; private static final char[] IDX_QRY_OFFENDING_CHARS = { '@', '/', ' ', '-' };
......
...@@ -61,6 +61,8 @@ import java.util.Map; ...@@ -61,6 +61,8 @@ 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.repository.Constants.RELATIONSHIP_GUID_PROPERTY_KEY;
@Service @Service
public class EntityLineageService implements AtlasLineageService { public class EntityLineageService implements AtlasLineageService {
private static final Logger LOG = LoggerFactory.getLogger(EntityLineageService.class); private static final Logger LOG = LoggerFactory.getLogger(EntityLineageService.class);
...@@ -222,7 +224,7 @@ public class EntityLineageService implements AtlasLineageService { ...@@ -222,7 +224,7 @@ public class EntityLineageService implements AtlasLineageService {
AtlasVertex outVertex = edge.getOutVertex(); AtlasVertex outVertex = edge.getOutVertex();
String inGuid = AtlasGraphUtilsV2.getIdFromVertex(inVertex); String inGuid = AtlasGraphUtilsV2.getIdFromVertex(inVertex);
String outGuid = AtlasGraphUtilsV2.getIdFromVertex(outVertex); String outGuid = AtlasGraphUtilsV2.getIdFromVertex(outVertex);
String relationGuid = AtlasGraphUtilsV2.getProperty(edge, Constants.RELATIONSHIP_GUID_PROPERTY_KEY, String.class); String relationGuid = AtlasGraphUtilsV2.getEncodedProperty(edge, RELATIONSHIP_GUID_PROPERTY_KEY, String.class);
boolean isInputEdge = edge.getLabel().equalsIgnoreCase(PROCESS_INPUTS_EDGE); boolean isInputEdge = edge.getLabel().equalsIgnoreCase(PROCESS_INPUTS_EDGE);
if (!entities.containsKey(inGuid)) { if (!entities.containsKey(inGuid)) {
......
...@@ -83,12 +83,22 @@ import static org.apache.atlas.repository.Constants.ATTRIBUTE_INDEX_PROPERTY_KEY ...@@ -83,12 +83,22 @@ import static org.apache.atlas.repository.Constants.ATTRIBUTE_INDEX_PROPERTY_KEY
import static org.apache.atlas.repository.Constants.ATTRIBUTE_KEY_PROPERTY_KEY; import static org.apache.atlas.repository.Constants.ATTRIBUTE_KEY_PROPERTY_KEY;
import static org.apache.atlas.repository.Constants.CLASSIFICATION_EDGE_IS_PROPAGATED_PROPERTY_KEY; import static org.apache.atlas.repository.Constants.CLASSIFICATION_EDGE_IS_PROPAGATED_PROPERTY_KEY;
import static org.apache.atlas.repository.Constants.CLASSIFICATION_ENTITY_GUID; import static org.apache.atlas.repository.Constants.CLASSIFICATION_ENTITY_GUID;
import static org.apache.atlas.repository.Constants.CLASSIFICATION_ENTITY_STATUS;
import static org.apache.atlas.repository.Constants.CLASSIFICATION_LABEL; import static org.apache.atlas.repository.Constants.CLASSIFICATION_LABEL;
import static org.apache.atlas.repository.Constants.CLASSIFICATION_EDGE_NAME_PROPERTY_KEY; import static org.apache.atlas.repository.Constants.CLASSIFICATION_EDGE_NAME_PROPERTY_KEY;
import static org.apache.atlas.repository.Constants.CLASSIFICATION_VERTEX_NAME_KEY; import static org.apache.atlas.repository.Constants.CLASSIFICATION_VERTEX_NAME_KEY;
import static org.apache.atlas.repository.Constants.CLASSIFICATION_VERTEX_PROPAGATE_KEY; import static org.apache.atlas.repository.Constants.CLASSIFICATION_VERTEX_PROPAGATE_KEY;
import static org.apache.atlas.repository.Constants.CLASSIFICATION_VERTEX_REMOVE_PROPAGATIONS_KEY; import static org.apache.atlas.repository.Constants.CLASSIFICATION_VERTEX_REMOVE_PROPAGATIONS_KEY;
import static org.apache.atlas.repository.Constants.CREATED_BY_KEY;
import static org.apache.atlas.repository.Constants.ENTITY_TYPE_PROPERTY_KEY;
import static org.apache.atlas.repository.Constants.MODIFICATION_TIMESTAMP_PROPERTY_KEY;
import static org.apache.atlas.repository.Constants.MODIFIED_BY_KEY;
import static org.apache.atlas.repository.Constants.PROPAGATED_TRAIT_NAMES_PROPERTY_KEY; import static org.apache.atlas.repository.Constants.PROPAGATED_TRAIT_NAMES_PROPERTY_KEY;
import static org.apache.atlas.repository.Constants.RELATIONSHIPTYPE_BLOCKED_PROPAGATED_CLASSIFICATIONS_KEY;
import static org.apache.atlas.repository.Constants.RELATIONSHIPTYPE_TAG_PROPAGATION_KEY;
import static org.apache.atlas.repository.Constants.STATE_PROPERTY_KEY;
import static org.apache.atlas.repository.Constants.SUPER_TYPES_PROPERTY_KEY;
import static org.apache.atlas.repository.Constants.TIMESTAMP_PROPERTY_KEY;
import static org.apache.atlas.repository.store.graph.v2.AtlasGraphUtilsV2.isReference; import static org.apache.atlas.repository.store.graph.v2.AtlasGraphUtilsV2.isReference;
import static org.apache.atlas.type.AtlasStructType.AtlasAttribute.AtlasRelationshipEdgeDirection.BOTH; import static org.apache.atlas.type.AtlasStructType.AtlasAttribute.AtlasRelationshipEdgeDirection.BOTH;
import static org.apache.atlas.type.AtlasStructType.AtlasAttribute.AtlasRelationshipEdgeDirection.IN; import static org.apache.atlas.type.AtlasStructType.AtlasAttribute.AtlasRelationshipEdgeDirection.IN;
...@@ -163,50 +173,41 @@ public final class GraphHelper { ...@@ -163,50 +173,41 @@ public final class GraphHelper {
new Id(guid, 0, typedInstance.getTypeName()), superTypeNames); new Id(guid, 0, typedInstance.getTypeName()), superTypeNames);
// add identity // add identity
setProperty(vertexWithIdentity, Constants.GUID_PROPERTY_KEY, guid); AtlasGraphUtilsV2.setEncodedProperty(vertexWithIdentity, Constants.GUID_PROPERTY_KEY, guid);
// add version information // add version information
setProperty(vertexWithIdentity, Constants.VERSION_PROPERTY_KEY, Long.valueOf(typedInstance.getId().getVersion())); AtlasGraphUtilsV2.setEncodedProperty(vertexWithIdentity, Constants.VERSION_PROPERTY_KEY, Long.valueOf(typedInstance.getId().getVersion()));
return vertexWithIdentity; return vertexWithIdentity;
} }
public AtlasVertex createVertexWithoutIdentity(String typeName, Id typedInstanceId, Set<String> superTypeNames) { public AtlasVertex createVertexWithoutIdentity(String typeName, Id typedInstanceId, Set<String> superTypeNames) {
if (LOG.isDebugEnabled()) { if (LOG.isDebugEnabled()) {
LOG.debug("Creating AtlasVertex for type {} id {}", typeName, LOG.debug("Creating AtlasVertex for type {} id {}", typeName, typedInstanceId != null ? typedInstanceId._getId() : null);
typedInstanceId != null ? typedInstanceId._getId() : null);
} }
final AtlasVertex vertexWithoutIdentity = graph.addVertex(); final AtlasVertex ret = graph.addVertex();
// add type information AtlasGraphUtilsV2.setEncodedProperty(ret, ENTITY_TYPE_PROPERTY_KEY, typeName);
setProperty(vertexWithoutIdentity, Constants.ENTITY_TYPE_PROPERTY_KEY, typeName); AtlasGraphUtilsV2.setEncodedProperty(ret, STATE_PROPERTY_KEY, ACTIVE.name());
AtlasGraphUtilsV2.setEncodedProperty(ret, TIMESTAMP_PROPERTY_KEY, RequestContext.get().getRequestTime());
AtlasGraphUtilsV2.setEncodedProperty(ret, MODIFICATION_TIMESTAMP_PROPERTY_KEY, RequestContext.get().getRequestTime());
AtlasGraphUtilsV2.setEncodedProperty(ret, CREATED_BY_KEY, RequestContext.get().getUser());
AtlasGraphUtilsV2.setEncodedProperty(ret, MODIFIED_BY_KEY, RequestContext.get().getUser());
// add super types
for (String superTypeName : superTypeNames) { for (String superTypeName : superTypeNames) {
addProperty(vertexWithoutIdentity, Constants.SUPER_TYPES_PROPERTY_KEY, superTypeName); AtlasGraphUtilsV2.addEncodedProperty(ret, SUPER_TYPES_PROPERTY_KEY, superTypeName);
} }
// add state information return ret;
setProperty(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());
setProperty(vertexWithoutIdentity, Constants.CREATED_BY_KEY, RequestContext.get().getUser());
setProperty(vertexWithoutIdentity, Constants.MODIFIED_BY_KEY, RequestContext.get().getUser());
return vertexWithoutIdentity;
} }
public AtlasEdge addClassificationEdge(AtlasVertex entityVertex, AtlasVertex classificationVertex, boolean isPropagated) { public AtlasEdge addClassificationEdge(AtlasVertex entityVertex, AtlasVertex classificationVertex, boolean isPropagated) {
AtlasEdge ret = addEdge(entityVertex, classificationVertex, CLASSIFICATION_LABEL); AtlasEdge ret = addEdge(entityVertex, classificationVertex, CLASSIFICATION_LABEL);
if (ret != null) { if (ret != null) {
AtlasGraphUtilsV2.setProperty(ret, CLASSIFICATION_EDGE_NAME_PROPERTY_KEY, getTypeName(classificationVertex)); AtlasGraphUtilsV2.setEncodedProperty(ret, CLASSIFICATION_EDGE_NAME_PROPERTY_KEY, getTypeName(classificationVertex));
AtlasGraphUtilsV2.setProperty(ret, CLASSIFICATION_EDGE_IS_PROPAGATED_PROPERTY_KEY, isPropagated); AtlasGraphUtilsV2.setEncodedProperty(ret, CLASSIFICATION_EDGE_IS_PROPAGATED_PROPERTY_KEY, isPropagated);
} }
return ret; return ret;
...@@ -222,11 +223,11 @@ public final class GraphHelper { ...@@ -222,11 +223,11 @@ public final class GraphHelper {
ret = graph.addEdge(fromVertex, toVertex, edgeLabel); ret = graph.addEdge(fromVertex, toVertex, edgeLabel);
if (ret != null) { if (ret != null) {
setProperty(ret, Constants.STATE_PROPERTY_KEY, Id.EntityState.ACTIVE.name()); AtlasGraphUtilsV2.setEncodedProperty(ret, STATE_PROPERTY_KEY, ACTIVE.name());
setProperty(ret, Constants.TIMESTAMP_PROPERTY_KEY, RequestContext.get().getRequestTime()); AtlasGraphUtilsV2.setEncodedProperty(ret, TIMESTAMP_PROPERTY_KEY, RequestContext.get().getRequestTime());
setProperty(ret, Constants.MODIFICATION_TIMESTAMP_PROPERTY_KEY, RequestContext.get().getRequestTime()); AtlasGraphUtilsV2.setEncodedProperty(ret, MODIFICATION_TIMESTAMP_PROPERTY_KEY, RequestContext.get().getRequestTime());
setProperty(ret, Constants.CREATED_BY_KEY, RequestContext.get().getUser()); AtlasGraphUtilsV2.setEncodedProperty(ret, CREATED_BY_KEY, RequestContext.get().getUser());
setProperty(ret, Constants.MODIFIED_BY_KEY, RequestContext.get().getUser()); AtlasGraphUtilsV2.setEncodedProperty(ret, MODIFIED_BY_KEY, RequestContext.get().getUser());
if (LOG.isDebugEnabled()) { if (LOG.isDebugEnabled()) {
LOG.debug("Added {}", string(ret)); LOG.debug("Added {}", string(ret));
...@@ -383,7 +384,7 @@ public final class GraphHelper { ...@@ -383,7 +384,7 @@ public final class GraphHelper {
boolean ret = false; boolean ret = false;
if (classificationVertex != null) { if (classificationVertex != null) {
Boolean enabled = AtlasGraphUtilsV2.getProperty(classificationVertex, CLASSIFICATION_VERTEX_PROPAGATE_KEY, Boolean.class); Boolean enabled = AtlasGraphUtilsV2.getEncodedProperty(classificationVertex, CLASSIFICATION_VERTEX_PROPAGATE_KEY, Boolean.class);
ret = (enabled == null) ? true : enabled; ret = (enabled == null) ? true : enabled;
} }
...@@ -395,7 +396,7 @@ public final class GraphHelper { ...@@ -395,7 +396,7 @@ public final class GraphHelper {
boolean ret = false; boolean ret = false;
if (classificationVertex != null) { if (classificationVertex != null) {
Boolean enabled = AtlasGraphUtilsV2.getProperty(classificationVertex, CLASSIFICATION_VERTEX_REMOVE_PROPAGATIONS_KEY, Boolean.class); Boolean enabled = AtlasGraphUtilsV2.getEncodedProperty(classificationVertex, CLASSIFICATION_VERTEX_REMOVE_PROPAGATIONS_KEY, Boolean.class);
ret = (enabled == null) ? true : enabled; ret = (enabled == null) ? true : enabled;
} }
...@@ -452,7 +453,7 @@ public final class GraphHelper { ...@@ -452,7 +453,7 @@ public final class GraphHelper {
AtlasVertex classificationVertex = (edge != null) ? edge.getInVertex() : null; AtlasVertex classificationVertex = (edge != null) ? edge.getInVertex() : null;
if (classificationVertex != null) { if (classificationVertex != null) {
String guid = AtlasGraphUtilsV2.getProperty(classificationVertex, CLASSIFICATION_ENTITY_GUID, String.class); String guid = AtlasGraphUtilsV2.getEncodedProperty(classificationVertex, CLASSIFICATION_ENTITY_GUID, String.class);
if (StringUtils.equals(guid, associatedEntityGuid)) { if (StringUtils.equals(guid, associatedEntityGuid)) {
ret = edge; ret = edge;
...@@ -614,7 +615,7 @@ public final class GraphHelper { ...@@ -614,7 +615,7 @@ public final class GraphHelper {
return edge; return edge;
} else { } else {
Long modificationTime = edge.getProperty(Constants.MODIFICATION_TIMESTAMP_PROPERTY_KEY, Long.class); Long modificationTime = edge.getProperty(MODIFICATION_TIMESTAMP_PROPERTY_KEY, Long.class);
if (modificationTime != null && modificationTime >= latestDeletedEdgeTime) { if (modificationTime != null && modificationTime >= latestDeletedEdgeTime) {
latestDeletedEdgeTime = modificationTime; latestDeletedEdgeTime = modificationTime;
latestDeletedEdge = edge; latestDeletedEdge = edge;
...@@ -749,13 +750,11 @@ public final class GraphHelper { ...@@ -749,13 +750,11 @@ public final class GraphHelper {
} }
public static void addToPropagatedTraitNames(AtlasVertex entityVertex, String classificationName) { public static void addToPropagatedTraitNames(AtlasVertex entityVertex, String classificationName) {
String actualPropertyName = GraphHelper.encodePropertyKey(PROPAGATED_TRAIT_NAMES_PROPERTY_KEY);
if (LOG.isDebugEnabled()) { if (LOG.isDebugEnabled()) {
LOG.debug("Adding property {} = \"{}\" to vertex {}", actualPropertyName, classificationName, string(entityVertex)); LOG.debug("Adding property {} = \"{}\" to vertex {}", PROPAGATED_TRAIT_NAMES_PROPERTY_KEY, classificationName, string(entityVertex));
} }
entityVertex.addListProperty(actualPropertyName, classificationName); entityVertex.addListProperty(PROPAGATED_TRAIT_NAMES_PROPERTY_KEY, classificationName);
} }
public static void removeFromPropagatedTraitNames(AtlasVertex entityVertex, String classificationName) { public static void removeFromPropagatedTraitNames(AtlasVertex entityVertex, String classificationName) {
...@@ -997,8 +996,8 @@ public final class GraphHelper { ...@@ -997,8 +996,8 @@ public final class GraphHelper {
} }
public static void updateModificationMetadata(AtlasVertex vertex) { public static void updateModificationMetadata(AtlasVertex vertex) {
AtlasGraphUtilsV2.setProperty(vertex, Constants.MODIFICATION_TIMESTAMP_PROPERTY_KEY, RequestContext.get().getRequestTime()); AtlasGraphUtilsV2.setEncodedProperty(vertex, MODIFICATION_TIMESTAMP_PROPERTY_KEY, RequestContext.get().getRequestTime());
AtlasGraphUtilsV2.setProperty(vertex, Constants.MODIFIED_BY_KEY, RequestContext.get().getUser()); AtlasGraphUtilsV2.setEncodedProperty(vertex, MODIFIED_BY_KEY, RequestContext.get().getUser());
} }
public static String getQualifiedNameForMapKey(String prefix, String key) { public static String getQualifiedNameForMapKey(String prefix, String key) {
...@@ -1041,7 +1040,7 @@ public final class GraphHelper { ...@@ -1041,7 +1040,7 @@ public final class GraphHelper {
while (iterator.hasNext()) { while (iterator.hasNext()) {
AtlasEdge edge = iterator.next(); AtlasEdge edge = iterator.next();
ret.add(AtlasGraphUtilsV2.getProperty(edge, CLASSIFICATION_EDGE_NAME_PROPERTY_KEY, String.class)); ret.add(AtlasGraphUtilsV2.getEncodedProperty(edge, CLASSIFICATION_EDGE_NAME_PROPERTY_KEY, String.class));
} }
} }
...@@ -1150,7 +1149,7 @@ public final class GraphHelper { ...@@ -1150,7 +1149,7 @@ public final class GraphHelper {
public static List<String> getSuperTypeNames(AtlasVertex<?,?> entityVertex) { public static List<String> getSuperTypeNames(AtlasVertex<?,?> entityVertex) {
ArrayList<String> superTypes = new ArrayList<>(); ArrayList<String> superTypes = new ArrayList<>();
Collection<String> propertyValues = entityVertex.getPropertyValues(Constants.SUPER_TYPES_PROPERTY_KEY, String.class); Collection<String> propertyValues = entityVertex.getPropertyValues(SUPER_TYPES_PROPERTY_KEY, String.class);
if (CollectionUtils.isNotEmpty(propertyValues)) { if (CollectionUtils.isNotEmpty(propertyValues)) {
for(String value : propertyValues) { for(String value : propertyValues) {
...@@ -1192,7 +1191,7 @@ public final class GraphHelper { ...@@ -1192,7 +1191,7 @@ public final class GraphHelper {
} }
public static String getTypeName(AtlasElement element) { public static String getTypeName(AtlasElement element) {
return element.getProperty(Constants.ENTITY_TYPE_PROPERTY_KEY, String.class); return element.getProperty(ENTITY_TYPE_PROPERTY_KEY, String.class);
} }
public static Id.EntityState getState(AtlasElement element) { public static Id.EntityState getState(AtlasElement element) {
...@@ -1205,7 +1204,7 @@ public final class GraphHelper { ...@@ -1205,7 +1204,7 @@ public final class GraphHelper {
} }
public static String getStateAsString(AtlasElement element) { public static String getStateAsString(AtlasElement element) {
return element.getProperty(Constants.STATE_PROPERTY_KEY, String.class); return element.getProperty(STATE_PROPERTY_KEY, String.class);
} }
public static Status getStatus(AtlasElement element) { public static Status getStatus(AtlasElement element) {
...@@ -1217,11 +1216,11 @@ public final class GraphHelper { ...@@ -1217,11 +1216,11 @@ public final class GraphHelper {
} }
public static String getClassificationName(AtlasVertex classificationVertex) { public static String getClassificationName(AtlasVertex classificationVertex) {
return AtlasGraphUtilsV2.getProperty(classificationVertex, CLASSIFICATION_VERTEX_NAME_KEY, String.class); return AtlasGraphUtilsV2.getEncodedProperty(classificationVertex, CLASSIFICATION_VERTEX_NAME_KEY, String.class);
} }
public static String getClassificationEntityGuid(AtlasVertex classificationVertex) { public static String getClassificationEntityGuid(AtlasVertex classificationVertex) {
return AtlasGraphUtilsV2.getProperty(classificationVertex, CLASSIFICATION_ENTITY_GUID, String.class); return AtlasGraphUtilsV2.getEncodedProperty(classificationVertex, CLASSIFICATION_ENTITY_GUID, String.class);
} }
public static Integer getIndexValue(AtlasEdge edge) { public static Integer getIndexValue(AtlasEdge edge) {
...@@ -1262,7 +1261,7 @@ public final class GraphHelper { ...@@ -1262,7 +1261,7 @@ public final class GraphHelper {
List<String> ret = null; List<String> ret = null;
if (edge != null) { if (edge != null) {
List<String> classificationIds = AtlasGraphUtilsV2.getProperty(edge, Constants.RELATIONSHIPTYPE_BLOCKED_PROPAGATED_CLASSIFICATIONS_KEY, List.class); List<String> classificationIds = AtlasGraphUtilsV2.getEncodedProperty(edge, RELATIONSHIPTYPE_BLOCKED_PROPAGATED_CLASSIFICATIONS_KEY, List.class);
ret = CollectionUtils.isNotEmpty(classificationIds) ? classificationIds : Collections.emptyList(); ret = CollectionUtils.isNotEmpty(classificationIds) ? classificationIds : Collections.emptyList();
} }
...@@ -1271,32 +1270,32 @@ public final class GraphHelper { ...@@ -1271,32 +1270,32 @@ public final class GraphHelper {
} }
public static PropagateTags getPropagateTags(AtlasElement element) { public static PropagateTags getPropagateTags(AtlasElement element) {
String propagateTags = element.getProperty(Constants.RELATIONSHIPTYPE_TAG_PROPAGATION_KEY, String.class); String propagateTags = element.getProperty(RELATIONSHIPTYPE_TAG_PROPAGATION_KEY, String.class);
return (propagateTags == null) ? null : PropagateTags.valueOf(propagateTags); return (propagateTags == null) ? null : PropagateTags.valueOf(propagateTags);
} }
public static Status getClassificationEntityStatus(AtlasElement element) { public static Status getClassificationEntityStatus(AtlasElement element) {
String status = element.getProperty(Constants.CLASSIFICATION_ENTITY_STATUS, String.class); String status = element.getProperty(CLASSIFICATION_ENTITY_STATUS, String.class);
return (status == null) ? null : Status.valueOf(status); return (status == null) ? null : Status.valueOf(status);
} }
//Added conditions in fetching system attributes to handle test failures in GremlinTest where these properties are not set //Added conditions in fetching system attributes to handle test failures in GremlinTest where these properties are not set
public static String getCreatedByAsString(AtlasElement element){ public static String getCreatedByAsString(AtlasElement element){
return element.getProperty(Constants.CREATED_BY_KEY, String.class); return element.getProperty(CREATED_BY_KEY, String.class);
} }
public static String getModifiedByAsString(AtlasElement element){ public static String getModifiedByAsString(AtlasElement element){
return element.getProperty(Constants.MODIFIED_BY_KEY, String.class); return element.getProperty(MODIFIED_BY_KEY, String.class);
} }
public static long getCreatedTime(AtlasElement element){ public static long getCreatedTime(AtlasElement element){
return element.getProperty(Constants.TIMESTAMP_PROPERTY_KEY, Long.class); return element.getProperty(TIMESTAMP_PROPERTY_KEY, Long.class);
} }
public static long getModifiedTime(AtlasElement element){ public static long getModifiedTime(AtlasElement element){
return element.getProperty(Constants.MODIFICATION_TIMESTAMP_PROPERTY_KEY, Long.class); return element.getProperty(MODIFICATION_TIMESTAMP_PROPERTY_KEY, Long.class);
} }
public static boolean isActive(AtlasEntity entity) { public static boolean isActive(AtlasEntity entity) {
...@@ -1323,8 +1322,8 @@ public final class GraphHelper { ...@@ -1323,8 +1322,8 @@ public final class GraphHelper {
String propertyKey = attributeInfo.getQualifiedName(); String propertyKey = attributeInfo.getQualifiedName();
try { try {
result = findVertex(propertyKey, instance.get(attributeInfo.getName()), result = findVertex(propertyKey, instance.get(attributeInfo.getName()),
Constants.ENTITY_TYPE_PROPERTY_KEY, classType.getTypeName(), ENTITY_TYPE_PROPERTY_KEY, classType.getTypeName(),
Constants.STATE_PROPERTY_KEY, Id.EntityState.ACTIVE.name()); STATE_PROPERTY_KEY, Id.EntityState.ACTIVE.name());
if (LOG.isDebugEnabled()) { if (LOG.isDebugEnabled()) {
LOG.debug("Found vertex by unique attribute : {}={}", propertyKey, instance.get(attributeInfo.getName())); LOG.debug("Found vertex by unique attribute : {}={}", propertyKey, instance.get(attributeInfo.getName()));
} }
...@@ -1373,8 +1372,8 @@ public final class GraphHelper { ...@@ -1373,8 +1372,8 @@ public final class GraphHelper {
//construct gremlin query //construct gremlin query
AtlasGraphQuery query = graph.query(); AtlasGraphQuery query = graph.query();
query.has(Constants.ENTITY_TYPE_PROPERTY_KEY, classType.getTypeName()); query.has(ENTITY_TYPE_PROPERTY_KEY, classType.getTypeName());
query.has(Constants.STATE_PROPERTY_KEY,Id.EntityState.ACTIVE.name()); query.has(STATE_PROPERTY_KEY,Id.EntityState.ACTIVE.name());
List<AtlasGraphQuery> orChildren = new ArrayList<AtlasGraphQuery>(); List<AtlasGraphQuery> orChildren = new ArrayList<AtlasGraphQuery>();
...@@ -1446,7 +1445,7 @@ public final class GraphHelper { ...@@ -1446,7 +1445,7 @@ public final class GraphHelper {
if (CollectionUtils.isNotEmpty(vertices)) { if (CollectionUtils.isNotEmpty(vertices)) {
for (AtlasVertex vertex : vertices) { for (AtlasVertex vertex : vertices) {
String entityTypeProperty = vertex.getProperty(Constants.ENTITY_TYPE_PROPERTY_KEY, String.class); String entityTypeProperty = vertex.getProperty(ENTITY_TYPE_PROPERTY_KEY, String.class);
if (entityTypeProperty != null) { if (entityTypeProperty != null) {
ret.add(getTypeName(vertex)); ret.add(getTypeName(vertex));
......
...@@ -61,6 +61,8 @@ import static org.apache.atlas.model.typedef.AtlasRelationshipDef.PropagateTags. ...@@ -61,6 +61,8 @@ import static org.apache.atlas.model.typedef.AtlasRelationshipDef.PropagateTags.
import static org.apache.atlas.repository.Constants.CLASSIFICATION_EDGE_NAME_PROPERTY_KEY; import static org.apache.atlas.repository.Constants.CLASSIFICATION_EDGE_NAME_PROPERTY_KEY;
import static org.apache.atlas.repository.Constants.CLASSIFICATION_ENTITY_STATUS; import static org.apache.atlas.repository.Constants.CLASSIFICATION_ENTITY_STATUS;
import static org.apache.atlas.repository.Constants.CLASSIFICATION_LABEL; import static org.apache.atlas.repository.Constants.CLASSIFICATION_LABEL;
import static org.apache.atlas.repository.Constants.MODIFICATION_TIMESTAMP_PROPERTY_KEY;
import static org.apache.atlas.repository.Constants.MODIFIED_BY_KEY;
import static org.apache.atlas.repository.Constants.PROPAGATED_TRAIT_NAMES_PROPERTY_KEY; import static org.apache.atlas.repository.Constants.PROPAGATED_TRAIT_NAMES_PROPERTY_KEY;
import static org.apache.atlas.repository.Constants.RELATIONSHIP_GUID_PROPERTY_KEY; import static org.apache.atlas.repository.Constants.RELATIONSHIP_GUID_PROPERTY_KEY;
import static org.apache.atlas.repository.graph.GraphHelper.*; import static org.apache.atlas.repository.graph.GraphHelper.*;
...@@ -270,8 +272,7 @@ public abstract class DeleteHandlerV1 { ...@@ -270,8 +272,7 @@ public abstract class DeleteHandlerV1 {
} }
boolean isInternalType = isInternalType(entityVertex); boolean isInternalType = isInternalType(entityVertex);
boolean forceDelete = (typeCategory == STRUCT || typeCategory == CLASSIFICATION) boolean forceDelete = (typeCategory == STRUCT || typeCategory == CLASSIFICATION) && (forceDeleteStructTrait || isInternalType);
&& (forceDeleteStructTrait || isInternalType);
if (LOG.isDebugEnabled()) { if (LOG.isDebugEnabled()) {
LOG.debug("isInternal = {}, forceDelete = {}", isInternalType, forceDelete); LOG.debug("isInternal = {}, forceDelete = {}", isInternalType, forceDelete);
...@@ -305,8 +306,8 @@ public abstract class DeleteHandlerV1 { ...@@ -305,8 +306,8 @@ public abstract class DeleteHandlerV1 {
RequestContext requestContext = RequestContext.get(); RequestContext requestContext = RequestContext.get();
if (!requestContext.isUpdatedEntity(GraphHelper.getGuid(referencedVertex))) { if (!requestContext.isUpdatedEntity(GraphHelper.getGuid(referencedVertex))) {
GraphHelper.setProperty(referencedVertex, Constants.MODIFICATION_TIMESTAMP_PROPERTY_KEY, requestContext.getRequestTime()); AtlasGraphUtilsV2.setEncodedProperty(referencedVertex, MODIFICATION_TIMESTAMP_PROPERTY_KEY, requestContext.getRequestTime());
GraphHelper.setProperty(referencedVertex, Constants.MODIFIED_BY_KEY, requestContext.getUser()); AtlasGraphUtilsV2.setEncodedProperty(referencedVertex, MODIFIED_BY_KEY, requestContext.getUser());
requestContext.recordEntityUpdate(entityRetriever.toAtlasObjectId(referencedVertex)); requestContext.recordEntityUpdate(entityRetriever.toAtlasObjectId(referencedVertex));
} }
...@@ -613,7 +614,7 @@ public abstract class DeleteHandlerV1 { ...@@ -613,7 +614,7 @@ public abstract class DeleteHandlerV1 {
} }
public void deletePropagatedEdge(AtlasEdge edge) throws AtlasBaseException { public void deletePropagatedEdge(AtlasEdge edge) throws AtlasBaseException {
String classificationName = AtlasGraphUtilsV2.getProperty(edge, CLASSIFICATION_EDGE_NAME_PROPERTY_KEY, String.class); String classificationName = AtlasGraphUtilsV2.getEncodedProperty(edge, CLASSIFICATION_EDGE_NAME_PROPERTY_KEY, String.class);
AtlasVertex entityVertex = edge.getOutVertex(); AtlasVertex entityVertex = edge.getOutVertex();
if (LOG.isDebugEnabled()) { if (LOG.isDebugEnabled()) {
...@@ -655,7 +656,7 @@ public abstract class DeleteHandlerV1 { ...@@ -655,7 +656,7 @@ public abstract class DeleteHandlerV1 {
if (isClassificationEdge(edge)) { if (isClassificationEdge(edge)) {
AtlasVertex classificationVertex = edge.getInVertex(); AtlasVertex classificationVertex = edge.getInVertex();
AtlasGraphUtilsV2.setProperty(classificationVertex, CLASSIFICATION_ENTITY_STATUS, DELETED.name()); AtlasGraphUtilsV2.setEncodedProperty(classificationVertex, CLASSIFICATION_ENTITY_STATUS, DELETED.name());
} }
deleteEdge(edge, force); deleteEdge(edge, force);
...@@ -801,7 +802,7 @@ public abstract class DeleteHandlerV1 { ...@@ -801,7 +802,7 @@ public abstract class DeleteHandlerV1 {
edge = graphHelper.getEdgeForLabel(outVertex, edgeLabel); edge = graphHelper.getEdgeForLabel(outVertex, edgeLabel);
if (shouldUpdateInverseReferences) { if (shouldUpdateInverseReferences) {
GraphHelper.setProperty(outVertex, propertyName, null); AtlasGraphUtilsV2.setEncodedProperty(outVertex, propertyName, null);
} }
} else { } else {
// Cannot unset a required attribute. // Cannot unset a required attribute.
...@@ -879,8 +880,8 @@ public abstract class DeleteHandlerV1 { ...@@ -879,8 +880,8 @@ public abstract class DeleteHandlerV1 {
RequestContext requestContext = RequestContext.get(); RequestContext requestContext = RequestContext.get();
if (! requestContext.isUpdatedEntity(outId)) { if (! requestContext.isUpdatedEntity(outId)) {
GraphHelper.setProperty(outVertex, Constants.MODIFICATION_TIMESTAMP_PROPERTY_KEY, requestContext.getRequestTime()); AtlasGraphUtilsV2.setEncodedProperty(outVertex, MODIFICATION_TIMESTAMP_PROPERTY_KEY, requestContext.getRequestTime());
GraphHelper.setProperty(outVertex, Constants.MODIFIED_BY_KEY, requestContext.getUser()); AtlasGraphUtilsV2.setEncodedProperty(outVertex, MODIFIED_BY_KEY, requestContext.getUser());
requestContext.recordEntityUpdate(entityRetriever.toAtlasObjectId(outVertex)); requestContext.recordEntityUpdate(entityRetriever.toAtlasObjectId(outVertex));
} }
......
...@@ -20,8 +20,7 @@ package org.apache.atlas.repository.store.graph.v1; ...@@ -20,8 +20,7 @@ package org.apache.atlas.repository.store.graph.v1;
import org.apache.atlas.RequestContext; import org.apache.atlas.RequestContext;
import org.apache.atlas.annotation.ConditionalOnAtlasProperty; import org.apache.atlas.annotation.ConditionalOnAtlasProperty;
import org.apache.atlas.exception.AtlasBaseException; import org.apache.atlas.model.instance.AtlasEntity.Status;
import org.apache.atlas.model.instance.AtlasEntity;
import org.apache.atlas.repository.graph.GraphHelper; import org.apache.atlas.repository.graph.GraphHelper;
import org.apache.atlas.repository.graphdb.AtlasEdge; import org.apache.atlas.repository.graphdb.AtlasEdge;
import org.apache.atlas.repository.graphdb.AtlasVertex; import org.apache.atlas.repository.graphdb.AtlasVertex;
...@@ -31,6 +30,7 @@ import org.springframework.stereotype.Component; ...@@ -31,6 +30,7 @@ import org.springframework.stereotype.Component;
import javax.inject.Inject; import javax.inject.Inject;
import static org.apache.atlas.model.instance.AtlasEntity.Status.DELETED;
import static org.apache.atlas.repository.Constants.MODIFICATION_TIMESTAMP_PROPERTY_KEY; import static org.apache.atlas.repository.Constants.MODIFICATION_TIMESTAMP_PROPERTY_KEY;
import static org.apache.atlas.repository.Constants.MODIFIED_BY_KEY; import static org.apache.atlas.repository.Constants.MODIFIED_BY_KEY;
import static org.apache.atlas.repository.Constants.STATE_PROPERTY_KEY; import static org.apache.atlas.repository.Constants.STATE_PROPERTY_KEY;
...@@ -53,18 +53,18 @@ public class SoftDeleteHandlerV1 extends DeleteHandlerV1 { ...@@ -53,18 +53,18 @@ public class SoftDeleteHandlerV1 extends DeleteHandlerV1 {
if (force) { if (force) {
graphHelper.removeVertex(instanceVertex); graphHelper.removeVertex(instanceVertex);
} else { } else {
AtlasEntity.Status state = AtlasGraphUtilsV2.getState(instanceVertex); Status state = AtlasGraphUtilsV2.getState(instanceVertex);
if (state != AtlasEntity.Status.DELETED) { if (state != DELETED) {
GraphHelper.setProperty(instanceVertex, STATE_PROPERTY_KEY, AtlasEntity.Status.DELETED.name()); AtlasGraphUtilsV2.setEncodedProperty(instanceVertex, STATE_PROPERTY_KEY, DELETED.name());
GraphHelper.setProperty(instanceVertex, MODIFICATION_TIMESTAMP_PROPERTY_KEY, RequestContext.get().getRequestTime()); AtlasGraphUtilsV2.setEncodedProperty(instanceVertex, MODIFICATION_TIMESTAMP_PROPERTY_KEY, RequestContext.get().getRequestTime());
GraphHelper.setProperty(instanceVertex, MODIFIED_BY_KEY, RequestContext.get().getUser()); AtlasGraphUtilsV2.setEncodedProperty(instanceVertex, MODIFIED_BY_KEY, RequestContext.get().getUser());
} }
} }
} }
@Override @Override
protected void deleteEdge(AtlasEdge edge, boolean force) throws AtlasBaseException { protected void deleteEdge(AtlasEdge edge, boolean force) {
if (LOG.isDebugEnabled()) { if (LOG.isDebugEnabled()) {
LOG.debug("==> SoftDeleteHandlerV1.deleteEdge({}, {})",GraphHelper.string(edge), force); LOG.debug("==> SoftDeleteHandlerV1.deleteEdge({}, {})",GraphHelper.string(edge), force);
} }
...@@ -72,12 +72,12 @@ public class SoftDeleteHandlerV1 extends DeleteHandlerV1 { ...@@ -72,12 +72,12 @@ public class SoftDeleteHandlerV1 extends DeleteHandlerV1 {
if (force) { if (force) {
graphHelper.removeEdge(edge); graphHelper.removeEdge(edge);
} else { } else {
AtlasEntity.Status state = AtlasGraphUtilsV2.getState(edge); Status state = AtlasGraphUtilsV2.getState(edge);
if (state != AtlasEntity.Status.DELETED) { if (state != DELETED) {
GraphHelper.setProperty(edge, STATE_PROPERTY_KEY, AtlasEntity.Status.DELETED.name()); AtlasGraphUtilsV2.setEncodedProperty(edge, STATE_PROPERTY_KEY, DELETED.name());
GraphHelper.setProperty(edge, MODIFICATION_TIMESTAMP_PROPERTY_KEY, RequestContext.get().getRequestTime()); AtlasGraphUtilsV2.setEncodedProperty(edge, MODIFICATION_TIMESTAMP_PROPERTY_KEY, RequestContext.get().getRequestTime());
GraphHelper.setProperty(edge, MODIFIED_BY_KEY, RequestContext.get().getUser()); AtlasGraphUtilsV2.setEncodedProperty(edge, MODIFIED_BY_KEY, RequestContext.get().getUser());
} }
} }
} }
......
...@@ -40,6 +40,8 @@ import java.util.List; ...@@ -40,6 +40,8 @@ import java.util.List;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import static org.apache.atlas.repository.Constants.TYPENAME_PROPERTY_KEY;
/** /**
* ClassificationDef store in v1 format. * ClassificationDef store in v1 format.
*/ */
...@@ -301,7 +303,7 @@ class AtlasClassificationDefStoreV2 extends AtlasAbstractDefStoreV2<AtlasClassif ...@@ -301,7 +303,7 @@ class AtlasClassificationDefStoreV2 extends AtlasAbstractDefStoreV2<AtlasClassif
AtlasVertex ret = typeDefStore.findTypeVertexByGuidAndCategory(guid, TypeCategory.TRAIT); AtlasVertex ret = typeDefStore.findTypeVertexByGuidAndCategory(guid, TypeCategory.TRAIT);
String typeName = AtlasGraphUtilsV2.getProperty(ret, Constants.TYPENAME_PROPERTY_KEY, String.class); String typeName = AtlasGraphUtilsV2.getEncodedProperty(ret, TYPENAME_PROPERTY_KEY, String.class);
if (AtlasGraphUtilsV2.typeHasInstanceVertex(typeName)) { if (AtlasGraphUtilsV2.typeHasInstanceVertex(typeName)) {
throw new AtlasBaseException(AtlasErrorCode.TYPE_HAS_REFERENCES, typeName); throw new AtlasBaseException(AtlasErrorCode.TYPE_HAS_REFERENCES, typeName);
......
...@@ -61,6 +61,7 @@ import java.util.Set; ...@@ -61,6 +61,7 @@ import java.util.Set;
import static org.apache.atlas.model.audit.EntityAuditEventV2.EntityAuditActionV2.PROPAGATED_CLASSIFICATION_ADD; import static org.apache.atlas.model.audit.EntityAuditEventV2.EntityAuditActionV2.PROPAGATED_CLASSIFICATION_ADD;
import static org.apache.atlas.model.audit.EntityAuditEventV2.EntityAuditActionV2.PROPAGATED_CLASSIFICATION_DELETE; import static org.apache.atlas.model.audit.EntityAuditEventV2.EntityAuditActionV2.PROPAGATED_CLASSIFICATION_DELETE;
import static org.apache.atlas.repository.Constants.ENTITY_TEXT_PROPERTY_KEY;
import static org.apache.atlas.util.AtlasRepositoryConfiguration.isV2EntityNotificationEnabled; import static org.apache.atlas.util.AtlasRepositoryConfiguration.isV2EntityNotificationEnabled;
...@@ -455,7 +456,7 @@ public class AtlasEntityChangeNotifier { ...@@ -455,7 +456,7 @@ public class AtlasEntityChangeNotifier {
try { try {
String fullText = fullTextMapperV2.getIndexTextForEntity(guid); String fullText = fullTextMapperV2.getIndexTextForEntity(guid);
GraphHelper.setProperty(vertex, Constants.ENTITY_TEXT_PROPERTY_KEY, fullText); AtlasGraphUtilsV2.setEncodedProperty(vertex, ENTITY_TEXT_PROPERTY_KEY, fullText);
} catch (AtlasBaseException e) { } catch (AtlasBaseException e) {
LOG.error("FullText mapping failed for Vertex[ guid = {} ]", guid, e); LOG.error("FullText mapping failed for Vertex[ guid = {} ]", guid, e);
} }
...@@ -482,10 +483,10 @@ public class AtlasEntityChangeNotifier { ...@@ -482,10 +483,10 @@ public class AtlasEntityChangeNotifier {
try { try {
String classificationFullText = fullTextMapperV2.getIndexTextForClassifications(entityId, classifications); String classificationFullText = fullTextMapperV2.getIndexTextForClassifications(entityId, classifications);
String existingFullText = (String) GraphHelper.getProperty(atlasVertex, Constants.ENTITY_TEXT_PROPERTY_KEY); String existingFullText = AtlasGraphUtilsV2.getEncodedProperty(atlasVertex, ENTITY_TEXT_PROPERTY_KEY, String.class);
String newFullText = existingFullText + " " + classificationFullText; String newFullText = existingFullText + " " + classificationFullText;
GraphHelper.setProperty(atlasVertex, Constants.ENTITY_TEXT_PROPERTY_KEY, newFullText);
AtlasGraphUtilsV2.setEncodedProperty(atlasVertex, ENTITY_TEXT_PROPERTY_KEY, newFullText);
} catch (AtlasBaseException e) { } catch (AtlasBaseException e) {
LOG.error("FullText mapping failed for Vertex[ guid = {} ]", entityId, e); LOG.error("FullText mapping failed for Vertex[ guid = {} ]", entityId, e);
} }
......
...@@ -303,7 +303,7 @@ public class AtlasEntityDefStoreV2 extends AtlasAbstractDefStoreV2<AtlasEntityDe ...@@ -303,7 +303,7 @@ public class AtlasEntityDefStoreV2 extends AtlasAbstractDefStoreV2<AtlasEntityDe
AtlasVertex ret = typeDefStore.findTypeVertexByGuidAndCategory(guid, TypeCategory.CLASS); AtlasVertex ret = typeDefStore.findTypeVertexByGuidAndCategory(guid, TypeCategory.CLASS);
String typeName = AtlasGraphUtilsV2.getProperty(ret, Constants.TYPENAME_PROPERTY_KEY, String.class); String typeName = AtlasGraphUtilsV2.getEncodedProperty(ret, Constants.TYPENAME_PROPERTY_KEY, String.class);
if (AtlasGraphUtilsV2.typeHasInstanceVertex(typeName)) { if (AtlasGraphUtilsV2.typeHasInstanceVertex(typeName)) {
throw new AtlasBaseException(AtlasErrorCode.TYPE_HAS_REFERENCES, typeName); throw new AtlasBaseException(AtlasErrorCode.TYPE_HAS_REFERENCES, typeName);
......
...@@ -130,7 +130,7 @@ public class AtlasGraphUtilsV2 { ...@@ -130,7 +130,7 @@ public class AtlasGraphUtilsV2 {
case ENTITY: case ENTITY:
case STRUCT: case STRUCT:
case CLASSIFICATION: case CLASSIFICATION:
return fromType.getQualifiedAttributeName(attributeName); return fromType.getQualifiedAttributePropertyKey(attributeName);
default: default:
throw new AtlasBaseException(AtlasErrorCode.UNKNOWN_TYPE, fromType.getTypeCategory().name()); throw new AtlasBaseException(AtlasErrorCode.UNKNOWN_TYPE, fromType.getTypeCategory().name());
} }
...@@ -169,20 +169,43 @@ public class AtlasGraphUtilsV2 { ...@@ -169,20 +169,43 @@ public class AtlasGraphUtilsV2 {
* @param value * @param value
*/ */
public static AtlasVertex addProperty(AtlasVertex vertex, String propertyName, Object value) { public static AtlasVertex addProperty(AtlasVertex vertex, String propertyName, Object value) {
return addProperty(vertex, propertyName, value, false);
}
public static AtlasVertex addEncodedProperty(AtlasVertex vertex, String propertyName, Object value) {
return addProperty(vertex, propertyName, value, true);
}
public static AtlasVertex addProperty(AtlasVertex vertex, String propertyName, Object value, boolean isEncoded) {
if (LOG.isDebugEnabled()) { if (LOG.isDebugEnabled()) {
LOG.debug("==> addProperty({}, {}, {})", toString(vertex), propertyName, value); LOG.debug("==> addProperty({}, {}, {})", toString(vertex), propertyName, value);
} }
if (!isEncoded) {
propertyName = encodePropertyKey(propertyName); propertyName = encodePropertyKey(propertyName);
}
vertex.addProperty(propertyName, value); vertex.addProperty(propertyName, value);
return vertex; return vertex;
} }
public static <T extends AtlasElement> void setProperty(T element, String propertyName, Object value) { public static <T extends AtlasElement> void setProperty(T element, String propertyName, Object value) {
setProperty(element, propertyName, value, false);
}
public static <T extends AtlasElement> void setEncodedProperty(T element, String propertyName, Object value) {
setProperty(element, propertyName, value, true);
}
public static <T extends AtlasElement> void setProperty(T element, String propertyName, Object value, boolean isEncoded) {
if (LOG.isDebugEnabled()) { if (LOG.isDebugEnabled()) {
LOG.debug("==> setProperty({}, {}, {})", toString(element), propertyName, value); LOG.debug("==> setProperty({}, {}, {})", toString(element), propertyName, value);
} }
if (!isEncoded) {
propertyName = encodePropertyKey(propertyName); propertyName = encodePropertyKey(propertyName);
}
Object existingValue = element.getProperty(propertyName, Object.class); Object existingValue = element.getProperty(propertyName, Object.class);
...@@ -211,7 +234,19 @@ public class AtlasGraphUtilsV2 { ...@@ -211,7 +234,19 @@ public class AtlasGraphUtilsV2 {
} }
public static <T extends AtlasElement, O> O getProperty(T element, String propertyName, Class<O> returnType) { public static <T extends AtlasElement, O> O getProperty(T element, String propertyName, Class<O> returnType) {
Object property = element.getProperty(encodePropertyKey(propertyName), returnType); return getProperty(element, propertyName, returnType, false);
}
public static <T extends AtlasElement, O> O getEncodedProperty(T element, String propertyName, Class<O> returnType) {
return getProperty(element, propertyName, returnType, true);
}
public static <T extends AtlasElement, O> O getProperty(T element, String propertyName, Class<O> returnType, boolean isEncoded) {
if (!isEncoded) {
propertyName = encodePropertyKey(propertyName);
}
Object property = element.getProperty(propertyName, returnType);
if (LOG.isDebugEnabled()) { if (LOG.isDebugEnabled()) {
LOG.debug("getProperty({}, {}) ==> {}", toString(element), propertyName, returnType.cast(property)); LOG.debug("getProperty({}, {}) ==> {}", toString(element), propertyName, returnType.cast(property));
......
...@@ -345,7 +345,7 @@ public class AtlasRelationshipDefStoreV2 extends AtlasAbstractDefStoreV2<AtlasRe ...@@ -345,7 +345,7 @@ public class AtlasRelationshipDefStoreV2 extends AtlasAbstractDefStoreV2<AtlasRe
throw new AtlasBaseException(AtlasErrorCode.TYPE_GUID_NOT_FOUND, guid); throw new AtlasBaseException(AtlasErrorCode.TYPE_GUID_NOT_FOUND, guid);
} }
String typeName = AtlasGraphUtilsV2.getProperty(ret, Constants.TYPENAME_PROPERTY_KEY, String.class); String typeName = AtlasGraphUtilsV2.getEncodedProperty(ret, Constants.TYPENAME_PROPERTY_KEY, String.class);
if (AtlasGraphUtilsV2.relationshipTypeHasInstanceEdges(typeName)) { if (AtlasGraphUtilsV2.relationshipTypeHasInstanceEdges(typeName)) {
throw new AtlasBaseException(AtlasErrorCode.TYPE_HAS_REFERENCES, typeName); throw new AtlasBaseException(AtlasErrorCode.TYPE_HAS_REFERENCES, typeName);
......
...@@ -70,6 +70,10 @@ import static org.apache.atlas.model.instance.AtlasEntity.Status.ACTIVE; ...@@ -70,6 +70,10 @@ import static org.apache.atlas.model.instance.AtlasEntity.Status.ACTIVE;
import static org.apache.atlas.model.instance.AtlasEntity.Status.DELETED; import static org.apache.atlas.model.instance.AtlasEntity.Status.DELETED;
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.model.typedef.AtlasRelationshipDef.PropagateTags.TWO_TO_ONE; import static org.apache.atlas.model.typedef.AtlasRelationshipDef.PropagateTags.TWO_TO_ONE;
import static org.apache.atlas.repository.Constants.ENTITY_TYPE_PROPERTY_KEY;
import static org.apache.atlas.repository.Constants.RELATIONSHIPTYPE_TAG_PROPAGATION_KEY;
import static org.apache.atlas.repository.Constants.RELATIONSHIP_GUID_PROPERTY_KEY;
import static org.apache.atlas.repository.Constants.VERSION_PROPERTY_KEY;
import static org.apache.atlas.repository.graph.GraphHelper.getBlockedClassificationIds; import static org.apache.atlas.repository.graph.GraphHelper.getBlockedClassificationIds;
import static org.apache.atlas.repository.graph.GraphHelper.getClassificationEntityGuid; import static org.apache.atlas.repository.graph.GraphHelper.getClassificationEntityGuid;
import static org.apache.atlas.repository.graph.GraphHelper.getClassificationName; import static org.apache.atlas.repository.graph.GraphHelper.getClassificationName;
...@@ -353,7 +357,7 @@ public class AtlasRelationshipStoreV2 implements AtlasRelationshipStore { ...@@ -353,7 +357,7 @@ public class AtlasRelationshipStoreV2 implements AtlasRelationshipStore {
String attrVertexProperty = attr.getVertexPropertyName(); String attrVertexProperty = attr.getVertexPropertyName();
Object attrValue = relationship.getAttribute(attrName); Object attrValue = relationship.getAttribute(attrName);
AtlasGraphUtilsV2.setProperty(ret, attrVertexProperty, attrValue); AtlasGraphUtilsV2.setEncodedProperty(ret, attrVertexProperty, attrValue);
} }
} }
} catch (RepositoryException e) { } catch (RepositoryException e) {
...@@ -380,7 +384,7 @@ public class AtlasRelationshipStoreV2 implements AtlasRelationshipStore { ...@@ -380,7 +384,7 @@ public class AtlasRelationshipStoreV2 implements AtlasRelationshipStore {
String attrVertexProperty = attr.getVertexPropertyName(); String attrVertexProperty = attr.getVertexPropertyName();
if (relationship.hasAttribute(attrName)) { if (relationship.hasAttribute(attrName)) {
AtlasGraphUtilsV2.setProperty(relationshipEdge, attrVertexProperty, relationship.getAttribute(attrName)); AtlasGraphUtilsV2.setEncodedProperty(relationshipEdge, attrVertexProperty, relationship.getAttribute(attrName));
} }
} }
} }
...@@ -485,7 +489,7 @@ public class AtlasRelationshipStoreV2 implements AtlasRelationshipStore { ...@@ -485,7 +489,7 @@ public class AtlasRelationshipStoreV2 implements AtlasRelationshipStore {
Map<AtlasVertex, List<AtlasVertex>> currentClassificationsMap = graphHelper.getClassificationPropagatedEntitiesMapping(currentClassificationVertices); Map<AtlasVertex, List<AtlasVertex>> currentClassificationsMap = graphHelper.getClassificationPropagatedEntitiesMapping(currentClassificationVertices);
// Update propagation edge // Update propagation edge
AtlasGraphUtilsV2.setProperty(edge, Constants.RELATIONSHIPTYPE_TAG_PROPAGATION_KEY, newTagPropagation.name()); AtlasGraphUtilsV2.setEncodedProperty(edge, RELATIONSHIPTYPE_TAG_PROPAGATION_KEY, newTagPropagation.name());
List<AtlasVertex> updatedClassificationVertices = getClassificationVertices(edge); List<AtlasVertex> updatedClassificationVertices = getClassificationVertices(edge);
List<AtlasVertex> classificationVerticesUnion = (List<AtlasVertex>) CollectionUtils.union(currentClassificationVertices, updatedClassificationVertices); List<AtlasVertex> classificationVerticesUnion = (List<AtlasVertex>) CollectionUtils.union(currentClassificationVertices, updatedClassificationVertices);
...@@ -741,10 +745,10 @@ public class AtlasRelationshipStoreV2 implements AtlasRelationshipStore { ...@@ -741,10 +745,10 @@ public class AtlasRelationshipStoreV2 implements AtlasRelationshipStore {
String relationshipGuid = relationship.getGuid(); String relationshipGuid = relationship.getGuid();
final String guid = AtlasTypeUtil.isAssignedGuid(relationshipGuid) ? relationshipGuid : UUID.randomUUID().toString(); final String guid = AtlasTypeUtil.isAssignedGuid(relationshipGuid) ? relationshipGuid : UUID.randomUUID().toString();
AtlasGraphUtilsV2.setProperty(ret, Constants.ENTITY_TYPE_PROPERTY_KEY, relationship.getTypeName()); AtlasGraphUtilsV2.setEncodedProperty(ret, ENTITY_TYPE_PROPERTY_KEY, relationship.getTypeName());
AtlasGraphUtilsV2.setProperty(ret, Constants.RELATIONSHIP_GUID_PROPERTY_KEY, guid); AtlasGraphUtilsV2.setEncodedProperty(ret, RELATIONSHIP_GUID_PROPERTY_KEY, guid);
AtlasGraphUtilsV2.setProperty(ret, Constants.VERSION_PROPERTY_KEY, getRelationshipVersion(relationship)); AtlasGraphUtilsV2.setEncodedProperty(ret, VERSION_PROPERTY_KEY, getRelationshipVersion(relationship));
AtlasGraphUtilsV2.setProperty(ret, Constants.RELATIONSHIPTYPE_TAG_PROPAGATION_KEY, tagPropagation.name()); AtlasGraphUtilsV2.setEncodedProperty(ret, RELATIONSHIPTYPE_TAG_PROPAGATION_KEY, tagPropagation.name());
// blocked propagated classifications // blocked propagated classifications
handleBlockedClassifications(ret, relationship.getBlockedPropagatedClassifications()); handleBlockedClassifications(ret, relationship.getBlockedPropagatedClassifications());
......
...@@ -309,7 +309,7 @@ public class AtlasStructDefStoreV2 extends AtlasAbstractDefStoreV2<AtlasStructDe ...@@ -309,7 +309,7 @@ public class AtlasStructDefStoreV2 extends AtlasAbstractDefStoreV2<AtlasStructDe
AtlasVertex ret = typeDefStore.findTypeVertexByGuidAndCategory(guid, TypeCategory.STRUCT); AtlasVertex ret = typeDefStore.findTypeVertexByGuidAndCategory(guid, TypeCategory.STRUCT);
String typeName = AtlasGraphUtilsV2.getProperty(ret, Constants.TYPENAME_PROPERTY_KEY, String.class); String typeName = AtlasGraphUtilsV2.getEncodedProperty(ret, Constants.TYPENAME_PROPERTY_KEY, String.class);
if (AtlasGraphUtilsV2.typeHasInstanceVertex(typeName)) { if (AtlasGraphUtilsV2.typeHasInstanceVertex(typeName)) {
throw new AtlasBaseException(AtlasErrorCode.TYPE_HAS_REFERENCES, typeName); throw new AtlasBaseException(AtlasErrorCode.TYPE_HAS_REFERENCES, typeName);
......
...@@ -126,42 +126,42 @@ public class EntityGraphMapper { ...@@ -126,42 +126,42 @@ public class EntityGraphMapper {
AtlasVertex ret = createStructVertex(entity); AtlasVertex ret = createStructVertex(entity);
for (String superTypeName : entityType.getAllSuperTypes()) { for (String superTypeName : entityType.getAllSuperTypes()) {
AtlasGraphUtilsV2.addProperty(ret, Constants.SUPER_TYPES_PROPERTY_KEY, superTypeName); AtlasGraphUtilsV2.addEncodedProperty(ret, SUPER_TYPES_PROPERTY_KEY, superTypeName);
} }
AtlasGraphUtilsV2.setProperty(ret, Constants.GUID_PROPERTY_KEY, guid); AtlasGraphUtilsV2.setEncodedProperty(ret, GUID_PROPERTY_KEY, guid);
AtlasGraphUtilsV2.setProperty(ret, Constants.VERSION_PROPERTY_KEY, getEntityVersion(entity)); AtlasGraphUtilsV2.setEncodedProperty(ret, VERSION_PROPERTY_KEY, getEntityVersion(entity));
return ret; return ret;
} }
public void updateSystemAttributes(AtlasVertex vertex, AtlasEntity entity) { public void updateSystemAttributes(AtlasVertex vertex, AtlasEntity entity) {
if (entity.getStatus() != null) { if (entity.getStatus() != null) {
AtlasGraphUtilsV2.setProperty(vertex, Constants.STATE_PROPERTY_KEY, entity.getStatus().name()); AtlasGraphUtilsV2.setEncodedProperty(vertex, STATE_PROPERTY_KEY, entity.getStatus().name());
} }
if (entity.getCreateTime() != null) { if (entity.getCreateTime() != null) {
AtlasGraphUtilsV2.setProperty(vertex, Constants.TIMESTAMP_PROPERTY_KEY, entity.getCreateTime().getTime()); AtlasGraphUtilsV2.setEncodedProperty(vertex, TIMESTAMP_PROPERTY_KEY, entity.getCreateTime().getTime());
} }
if (entity.getUpdateTime() != null) { if (entity.getUpdateTime() != null) {
AtlasGraphUtilsV2.setProperty(vertex, Constants.MODIFICATION_TIMESTAMP_PROPERTY_KEY, entity.getUpdateTime().getTime()); AtlasGraphUtilsV2.setEncodedProperty(vertex, MODIFICATION_TIMESTAMP_PROPERTY_KEY, entity.getUpdateTime().getTime());
} }
if (StringUtils.isNotEmpty(entity.getCreatedBy())) { if (StringUtils.isNotEmpty(entity.getCreatedBy())) {
AtlasGraphUtilsV2.setProperty(vertex, Constants.CREATED_BY_KEY, entity.getCreatedBy()); AtlasGraphUtilsV2.setEncodedProperty(vertex, CREATED_BY_KEY, entity.getCreatedBy());
} }
if (StringUtils.isNotEmpty(entity.getUpdatedBy())) { if (StringUtils.isNotEmpty(entity.getUpdatedBy())) {
AtlasGraphUtilsV2.setProperty(vertex, Constants.MODIFIED_BY_KEY, entity.getUpdatedBy()); AtlasGraphUtilsV2.setEncodedProperty(vertex, MODIFIED_BY_KEY, entity.getUpdatedBy());
} }
if (StringUtils.isNotEmpty(entity.getHomeId())) { if (StringUtils.isNotEmpty(entity.getHomeId())) {
AtlasGraphUtilsV2.setProperty(vertex, Constants.HOME_ID_KEY, entity.getHomeId()); AtlasGraphUtilsV2.setEncodedProperty(vertex, HOME_ID_KEY, entity.getHomeId());
} }
if (entity.isProxy() != null) { if (entity.isProxy() != null) {
AtlasGraphUtilsV2.setProperty(vertex, Constants.IS_PROXY_KEY, entity.isProxy()); AtlasGraphUtilsV2.setEncodedProperty(vertex, IS_PROXY_KEY, entity.isProxy());
} }
} }
...@@ -238,12 +238,12 @@ public class EntityGraphMapper { ...@@ -238,12 +238,12 @@ public class EntityGraphMapper {
final AtlasVertex ret = graph.addVertex(); final AtlasVertex ret = graph.addVertex();
AtlasGraphUtilsV2.setProperty(ret, Constants.ENTITY_TYPE_PROPERTY_KEY, struct.getTypeName()); AtlasGraphUtilsV2.setEncodedProperty(ret, ENTITY_TYPE_PROPERTY_KEY, struct.getTypeName());
AtlasGraphUtilsV2.setProperty(ret, Constants.STATE_PROPERTY_KEY, AtlasEntity.Status.ACTIVE.name()); AtlasGraphUtilsV2.setEncodedProperty(ret, STATE_PROPERTY_KEY, AtlasEntity.Status.ACTIVE.name());
AtlasGraphUtilsV2.setProperty(ret, Constants.TIMESTAMP_PROPERTY_KEY, RequestContext.get().getRequestTime()); AtlasGraphUtilsV2.setEncodedProperty(ret, TIMESTAMP_PROPERTY_KEY, RequestContext.get().getRequestTime());
AtlasGraphUtilsV2.setProperty(ret, Constants.MODIFICATION_TIMESTAMP_PROPERTY_KEY, RequestContext.get().getRequestTime()); AtlasGraphUtilsV2.setEncodedProperty(ret, MODIFICATION_TIMESTAMP_PROPERTY_KEY, RequestContext.get().getRequestTime());
AtlasGraphUtilsV2.setProperty(ret, Constants.CREATED_BY_KEY, RequestContext.get().getUser()); AtlasGraphUtilsV2.setEncodedProperty(ret, CREATED_BY_KEY, RequestContext.get().getUser());
GraphHelper.setProperty(ret, Constants.MODIFIED_BY_KEY, RequestContext.get().getUser()); AtlasGraphUtilsV2.setEncodedProperty(ret, MODIFIED_BY_KEY, RequestContext.get().getUser());
if (LOG.isDebugEnabled()) { if (LOG.isDebugEnabled()) {
LOG.debug("<== createStructVertex({})", struct.getTypeName()); LOG.debug("<== createStructVertex({})", struct.getTypeName());
...@@ -261,9 +261,9 @@ public class EntityGraphMapper { ...@@ -261,9 +261,9 @@ public class EntityGraphMapper {
AtlasVertex ret = createStructVertex(classification); AtlasVertex ret = createStructVertex(classification);
AtlasGraphUtilsV2.addProperty(ret, Constants.SUPER_TYPES_PROPERTY_KEY, classificationType.getAllSuperTypes()); AtlasGraphUtilsV2.addEncodedProperty(ret, SUPER_TYPES_PROPERTY_KEY, classificationType.getAllSuperTypes());
AtlasGraphUtilsV2.setProperty(ret, Constants.CLASSIFICATION_ENTITY_GUID, classification.getEntityGuid()); AtlasGraphUtilsV2.setEncodedProperty(ret, CLASSIFICATION_ENTITY_GUID, classification.getEntityGuid());
AtlasGraphUtilsV2.setProperty(ret, Constants.CLASSIFICATION_ENTITY_STATUS, classification.getEntityStatus().name()); AtlasGraphUtilsV2.setEncodedProperty(ret, CLASSIFICATION_ENTITY_STATUS, classification.getEntityStatus().name());
return ret; return ret;
} }
...@@ -345,6 +345,7 @@ public class EntityGraphMapper { ...@@ -345,6 +345,7 @@ public class EntityGraphMapper {
if (attrValue == null) { if (attrValue == null) {
AtlasAttributeDef attributeDef = attribute.getAttributeDef(); AtlasAttributeDef attributeDef = attribute.getAttributeDef();
AtlasType attrType = attribute.getAttributeType(); AtlasType attrType = attribute.getAttributeType();
if (attrType.getTypeCategory() == TypeCategory.PRIMITIVE) { if (attrType.getTypeCategory() == TypeCategory.PRIMITIVE) {
if (attributeDef.getDefaultValue() != null) { if (attributeDef.getDefaultValue() != null) {
attrValue = attrType.createDefaultValue(attributeDef.getDefaultValue()); attrValue = attrType.createDefaultValue(attributeDef.getDefaultValue());
...@@ -589,7 +590,7 @@ public class EntityGraphMapper { ...@@ -589,7 +590,7 @@ public class EntityGraphMapper {
return; return;
} }
AtlasGraphUtilsV2.setProperty(edge, Constants.RELATIONSHIP_GUID_PROPERTY_KEY, parentRelationshipGuid); AtlasGraphUtilsV2.setEncodedProperty(edge, RELATIONSHIP_GUID_PROPERTY_KEY, parentRelationshipGuid);
} }
// legacy method to create edges for inverse reference // legacy method to create edges for inverse reference
...@@ -628,7 +629,7 @@ public class EntityGraphMapper { ...@@ -628,7 +629,7 @@ public class EntityGraphMapper {
} }
} }
AtlasGraphUtilsV2.setProperty(ctx.getReferringVertex(), ctx.getVertexProperty(), ret); AtlasGraphUtilsV2.setEncodedProperty(ctx.getReferringVertex(), ctx.getVertexProperty(), ret);
return ret; return ret;
} }
...@@ -776,8 +777,9 @@ public class EntityGraphMapper { ...@@ -776,8 +777,9 @@ public class EntityGraphMapper {
// for import use the relationship guid provided // for import use the relationship guid provided
if (context.isImport()) { if (context.isImport()) {
String relationshipGuid = getRelationshipGuid(ctx.getValue()); String relationshipGuid = getRelationshipGuid(ctx.getValue());
if(!StringUtils.isEmpty(relationshipGuid)) { if(!StringUtils.isEmpty(relationshipGuid)) {
AtlasGraphUtilsV2.setProperty(ret, Constants.RELATIONSHIP_GUID_PROPERTY_KEY, relationshipGuid); AtlasGraphUtilsV2.setEncodedProperty(ret, RELATIONSHIP_GUID_PROPERTY_KEY, relationshipGuid);
} }
} }
...@@ -1126,26 +1128,23 @@ public class EntityGraphMapper { ...@@ -1126,26 +1128,23 @@ public class EntityGraphMapper {
} }
private AtlasEdge updateEdge(AtlasAttributeDef attributeDef, Object value, AtlasEdge currentEdge, final AtlasVertex entityVertex) throws AtlasBaseException { private AtlasEdge updateEdge(AtlasAttributeDef attributeDef, Object value, AtlasEdge currentEdge, final AtlasVertex entityVertex) throws AtlasBaseException {
if (LOG.isDebugEnabled()) {
LOG.debug("Updating entity reference {} for reference attribute {}", attributeDef.getName()); LOG.debug("Updating entity reference {} for reference attribute {}", attributeDef.getName());
// Update edge if it exists }
AtlasVertex currentVertex = currentEdge.getInVertex(); AtlasVertex currentVertex = currentEdge.getInVertex();
String currentEntityId = getIdFromVertex(currentVertex); String currentEntityId = getIdFromVertex(currentVertex);
String newEntityId = getIdFromVertex(entityVertex); String newEntityId = getIdFromVertex(entityVertex);
AtlasEdge newEdge = currentEdge; AtlasEdge newEdge = currentEdge;
if (!currentEntityId.equals(newEntityId)) {
// add an edge to the class vertex from the instance if (!currentEntityId.equals(newEntityId) && entityVertex != null) {
if (entityVertex != null) {
try { try {
newEdge = graphHelper.getOrCreateEdge(currentEdge.getOutVertex(), entityVertex, currentEdge.getLabel()); newEdge = graphHelper.getOrCreateEdge(currentEdge.getOutVertex(), entityVertex, currentEdge.getLabel());
} catch (RepositoryException e) { } catch (RepositoryException e) {
throw new AtlasBaseException(AtlasErrorCode.INTERNAL_ERROR, e); throw new AtlasBaseException(AtlasErrorCode.INTERNAL_ERROR, e);
} }
}
} }
return newEdge; return newEdge;
} }
...@@ -1250,7 +1249,7 @@ public class EntityGraphMapper { ...@@ -1250,7 +1249,7 @@ public class EntityGraphMapper {
} }
private void setArrayElementsProperty(AtlasType elementType, AtlasVertex vertex, String vertexPropertyName, List<Object> values) { private void setArrayElementsProperty(AtlasType elementType, AtlasVertex vertex, String vertexPropertyName, List<Object> values) {
if (!isReference(elementType)) { if (!isReference(elementType)) {
GraphHelper.setProperty(vertex, vertexPropertyName, values); AtlasGraphUtilsV2.setEncodedProperty(vertex, vertexPropertyName, values);
} }
} }
...@@ -1277,8 +1276,8 @@ public class EntityGraphMapper { ...@@ -1277,8 +1276,8 @@ public class EntityGraphMapper {
if (ctx.getAttribute().isOwnedRef() && getStatus(edge) == DELETED && getStatus(edge.getInVertex()) == DELETED) { if (ctx.getAttribute().isOwnedRef() && getStatus(edge) == DELETED && getStatus(edge.getInVertex()) == DELETED) {
//Resurrect the vertex and edge to ACTIVE state //Resurrect the vertex and edge to ACTIVE state
GraphHelper.setProperty(edge, STATE_PROPERTY_KEY, AtlasEntity.Status.ACTIVE.name()); AtlasGraphUtilsV2.setEncodedProperty(edge, STATE_PROPERTY_KEY, ACTIVE.name());
GraphHelper.setProperty(edge.getInVertex(), STATE_PROPERTY_KEY, AtlasEntity.Status.ACTIVE.name()); AtlasGraphUtilsV2.setEncodedProperty(edge.getInVertex(), STATE_PROPERTY_KEY, ACTIVE.name());
} }
} }
} }
...@@ -1340,7 +1339,7 @@ public class EntityGraphMapper { ...@@ -1340,7 +1339,7 @@ public class EntityGraphMapper {
LOG.debug("Adding classification [{}] to [{}] using edge label: [{}]", classificationName, entityTypeName, getTraitLabel(classificationName)); LOG.debug("Adding classification [{}] to [{}] using edge label: [{}]", classificationName, entityTypeName, getTraitLabel(classificationName));
} }
GraphHelper.addProperty(entityVertex, TRAIT_NAMES_PROPERTY_KEY, classificationName); AtlasGraphUtilsV2.addEncodedProperty(entityVertex, TRAIT_NAMES_PROPERTY_KEY, classificationName);
// add a new AtlasVertex for the struct or trait instance // add a new AtlasVertex for the struct or trait instance
AtlasVertex classificationVertex = createClassificationVertex(classification); AtlasVertex classificationVertex = createClassificationVertex(classification);
...@@ -1589,7 +1588,7 @@ public class EntityGraphMapper { ...@@ -1589,7 +1588,7 @@ public class EntityGraphMapper {
Boolean updatedRemovePropagations = classification.getRemovePropagationsOnEntityDelete(); Boolean updatedRemovePropagations = classification.getRemovePropagationsOnEntityDelete();
if (updatedRemovePropagations != null && (updatedRemovePropagations != currentRemovePropagations)) { if (updatedRemovePropagations != null && (updatedRemovePropagations != currentRemovePropagations)) {
AtlasGraphUtilsV2.setProperty(classificationVertex, CLASSIFICATION_VERTEX_REMOVE_PROPAGATIONS_KEY, updatedRemovePropagations); AtlasGraphUtilsV2.setEncodedProperty(classificationVertex, CLASSIFICATION_VERTEX_REMOVE_PROPAGATIONS_KEY, updatedRemovePropagations);
isClassificationUpdated = true; isClassificationUpdated = true;
} }
...@@ -1695,18 +1694,17 @@ public class EntityGraphMapper { ...@@ -1695,18 +1694,17 @@ public class EntityGraphMapper {
if (classification.getValidityPeriods() != null) { if (classification.getValidityPeriods() != null) {
String strValidityPeriods = AtlasJson.toJson(classification.getValidityPeriods()); String strValidityPeriods = AtlasJson.toJson(classification.getValidityPeriods());
AtlasGraphUtilsV2.setProperty(traitInstanceVertex, Constants.CLASSIFICATION_VALIDITY_PERIODS_KEY, strValidityPeriods); AtlasGraphUtilsV2.setEncodedProperty(traitInstanceVertex, CLASSIFICATION_VALIDITY_PERIODS_KEY, strValidityPeriods);
} else { } else {
// if 'null', don't update existing value in the classification // if 'null', don't update existing value in the classification
} }
if (classification.isPropagate() != null) { if (classification.isPropagate() != null) {
AtlasGraphUtilsV2.setProperty(traitInstanceVertex, Constants.CLASSIFICATION_VERTEX_PROPAGATE_KEY, classification.isPropagate()); AtlasGraphUtilsV2.setEncodedProperty(traitInstanceVertex, CLASSIFICATION_VERTEX_PROPAGATE_KEY, classification.isPropagate());
} }
if (classification.getRemovePropagationsOnEntityDelete() != null) { if (classification.getRemovePropagationsOnEntityDelete() != null) {
AtlasGraphUtilsV2.setProperty(traitInstanceVertex, CLASSIFICATION_VERTEX_REMOVE_PROPAGATIONS_KEY, AtlasGraphUtilsV2.setEncodedProperty(traitInstanceVertex, CLASSIFICATION_VERTEX_REMOVE_PROPAGATIONS_KEY, classification.getRemovePropagationsOnEntityDelete());
classification.getRemovePropagationsOnEntityDelete());
} }
// map all the attributes to this newly created AtlasVertex // map all the attributes to this newly created AtlasVertex
...@@ -1742,7 +1740,7 @@ public class EntityGraphMapper { ...@@ -1742,7 +1740,7 @@ public class EntityGraphMapper {
entityVertex.removeProperty(TRAIT_NAMES_PROPERTY_KEY); entityVertex.removeProperty(TRAIT_NAMES_PROPERTY_KEY);
for (String traitName : traitNames) { for (String traitName : traitNames) {
GraphHelper.addProperty(entityVertex, TRAIT_NAMES_PROPERTY_KEY, traitName); AtlasGraphUtilsV2.addEncodedProperty(entityVertex, TRAIT_NAMES_PROPERTY_KEY, traitName);
} }
} }
} }
......
...@@ -284,12 +284,12 @@ public final class EntityGraphRetriever { ...@@ -284,12 +284,12 @@ public final class EntityGraphRetriever {
public AtlasClassification toAtlasClassification(AtlasVertex classificationVertex) throws AtlasBaseException { public AtlasClassification toAtlasClassification(AtlasVertex classificationVertex) throws AtlasBaseException {
AtlasClassification ret = new AtlasClassification(getTypeName(classificationVertex)); AtlasClassification ret = new AtlasClassification(getTypeName(classificationVertex));
ret.setEntityGuid(AtlasGraphUtilsV2.getProperty(classificationVertex, CLASSIFICATION_ENTITY_GUID, String.class)); ret.setEntityGuid(AtlasGraphUtilsV2.getEncodedProperty(classificationVertex, CLASSIFICATION_ENTITY_GUID, String.class));
ret.setEntityStatus(getClassificationEntityStatus(classificationVertex)); ret.setEntityStatus(getClassificationEntityStatus(classificationVertex));
ret.setPropagate(isPropagationEnabled(classificationVertex)); ret.setPropagate(isPropagationEnabled(classificationVertex));
ret.setRemovePropagationsOnEntityDelete(getRemovePropagations(classificationVertex)); ret.setRemovePropagationsOnEntityDelete(getRemovePropagations(classificationVertex));
String strValidityPeriods = AtlasGraphUtilsV2.getProperty(classificationVertex, CLASSIFICATION_VALIDITY_PERIODS_KEY, String.class); String strValidityPeriods = AtlasGraphUtilsV2.getEncodedProperty(classificationVertex, CLASSIFICATION_VALIDITY_PERIODS_KEY, String.class);
if (strValidityPeriods != null) { if (strValidityPeriods != null) {
ret.setValidityPeriods(AtlasJson.fromJson(strValidityPeriods, TIME_BOUNDARIES_LIST_TYPE)); ret.setValidityPeriods(AtlasJson.fromJson(strValidityPeriods, TIME_BOUNDARIES_LIST_TYPE));
......
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