Commit b6a664df by Sarath Subramanian

ATLAS-2836: Remove redundant encoding of vertex property keys

parent 70e10cc0
...@@ -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)) {
......
...@@ -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);
......
...@@ -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