Commit 5d8fae55 by kevalbhatt

ATLAS-1513: updated AtlasEntityType with methods to get foreign-key references;…

ATLAS-1513: updated AtlasEntityType with methods to get foreign-key references; added helper methods in AtlasAttribute
parent a7870cde
......@@ -470,6 +470,7 @@ public class AtlasStructDef extends AtlasBaseTypeDef implements Serializable {
public static final String CONSTRAINT_PARAM_REF_ATTRIBUTE = "refAttribute";
public static final String CONSTRAINT_PARAM_ON_DELETE = "onDelete";
public static final String CONSTRAINT_PARAM_VAL_CASCADE = "cascade";
public static final String CONSTRAINT_PARAM_VAL_UPDATE = "update";
private String type; // foreignKey/mappedFromRef/valueInRange
private Map<String, Object> params; // onDelete=cascade/refAttribute=attr2/min=0,max=23
......
......@@ -260,7 +260,7 @@ public class AtlasClassificationType extends AtlasStructType {
if (CollectionUtils.isNotEmpty(classificationDef.getAttributeDefs())) {
for (AtlasAttributeDef attributeDef : classificationDef.getAttributeDefs()) {
AtlasType type = typeRegistry.getType(attributeDef.getTypeName());
allAttributes.put(attributeDef.getName(), new AtlasAttribute(this, classificationDef, attributeDef, type));
allAttributes.put(attributeDef.getName(), new AtlasAttribute(this, attributeDef, type));
}
}
}
......
......@@ -29,6 +29,7 @@ import org.apache.atlas.model.typedef.AtlasEnumDef.AtlasEnumElementDef;
import org.apache.atlas.model.typedef.AtlasStructDef;
import org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef;
import org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef.Cardinality;
import org.apache.atlas.model.typedef.AtlasStructDef.AtlasConstraintDef;
import org.apache.atlas.model.typedef.AtlasTypeDefHeader;
import org.apache.atlas.model.typedef.AtlasTypesDef;
import org.apache.commons.collections.CollectionUtils;
......@@ -153,54 +154,54 @@ public class AtlasTypeUtil {
return new AtlasAttributeDef(name, dataType.getTypeName(), true,
Cardinality.SINGLE, 0, 1,
false, false,
Collections.<AtlasStructDef.AtlasConstraintDef>emptyList());
Collections.<AtlasConstraintDef>emptyList());
}
public static AtlasAttributeDef createOptionalAttrDef(String name, String dataType) {
return new AtlasAttributeDef(name, dataType, true,
Cardinality.SINGLE, 0, 1,
false, false,
Collections.<AtlasStructDef.AtlasConstraintDef>emptyList());
Collections.<AtlasConstraintDef>emptyList());
}
public static AtlasAttributeDef createRequiredAttrDef(String name, String dataType) {
return new AtlasAttributeDef(name, dataType, false,
Cardinality.SINGLE, 1, 1,
false, true,
Collections.<AtlasStructDef.AtlasConstraintDef>emptyList());
Collections.<AtlasConstraintDef>emptyList());
}
public static AtlasAttributeDef createListRequiredAttrDef(String name, String dataType) {
return new AtlasAttributeDef(name, dataType, false,
Cardinality.LIST, 1, Integer.MAX_VALUE,
false, true,
Collections.<AtlasStructDef.AtlasConstraintDef>emptyList());
Collections.<AtlasConstraintDef>emptyList());
}
public static AtlasAttributeDef createOptionalListAttrDef(String name, String dataType) {
return new AtlasAttributeDef(name, dataType, true,
Cardinality.LIST, 1, Integer.MAX_VALUE,
false, true,
Collections.<AtlasStructDef.AtlasConstraintDef>emptyList());
Collections.<AtlasConstraintDef>emptyList());
}
public static AtlasAttributeDef createRequiredListAttrDefWithConstraint(String name, String dataType, String type, Map param) {
AtlasAttributeDef ret = AtlasTypeUtil.createListRequiredAttrDef(name, dataType);
ret.addConstraint(new AtlasStructDef.AtlasConstraintDef(type, param));
ret.addConstraint(new AtlasConstraintDef(type, param));
return ret;
}
public static AtlasAttributeDef createRequiredAttrDefWithConstraint(String name, String typeName, String type, Map param) {
AtlasAttributeDef ret = AtlasTypeUtil.createRequiredAttrDef(name, typeName);
ret.addConstraint(new AtlasStructDef.AtlasConstraintDef(type, param));
ret.addConstraint(new AtlasConstraintDef(type, param));
return ret;
}
public static AtlasAttributeDef createOptionalAttrDefWithConstraint(String name, String typeName, String type, Map param) {
AtlasAttributeDef ret = AtlasTypeUtil.createOptionalAttrDef(name, typeName);
ret.addConstraint(new AtlasStructDef.AtlasConstraintDef(type, param));
ret.addConstraint(new AtlasConstraintDef(type, param));
return ret;
}
......@@ -209,21 +210,21 @@ public class AtlasTypeUtil {
return new AtlasAttributeDef(name, dataType.getTypeName(), false,
Cardinality.SINGLE, 1, 1,
true, true,
Collections.<AtlasStructDef.AtlasConstraintDef>emptyList());
Collections.<AtlasConstraintDef>emptyList());
}
public static AtlasAttributeDef createUniqueRequiredAttrDef(String name, String typeName) {
return new AtlasAttributeDef(name, typeName, false,
Cardinality.SINGLE, 1, 1,
true, true,
Collections.<AtlasStructDef.AtlasConstraintDef>emptyList());
Collections.<AtlasConstraintDef>emptyList());
}
public static AtlasAttributeDef createRequiredAttrDef(String name, AtlasType dataType) {
return new AtlasAttributeDef(name, dataType.getTypeName(), false,
Cardinality.SINGLE, 1, 1,
false, true,
Collections.<AtlasStructDef.AtlasConstraintDef>emptyList());
Collections.<AtlasConstraintDef>emptyList());
}
public static AtlasEnumDef createEnumTypeDef(String name, String description, AtlasEnumElementDef... enumValues) {
......
......@@ -31,7 +31,6 @@ import org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef;
import org.apache.atlas.type.AtlasClassificationType;
import org.apache.atlas.type.AtlasEntityType;
import org.apache.atlas.type.AtlasStructType;
import org.apache.atlas.type.AtlasType;
import org.apache.atlas.type.AtlasTypeRegistry;
import org.apache.atlas.type.AtlasTypeRegistry.AtlasTransientTypeRegistry;
import org.slf4j.Logger;
......
......@@ -31,12 +31,18 @@ import org.apache.atlas.model.typedef.AtlasEntityDef;
import org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef;
import org.apache.atlas.model.typedef.AtlasStructDef.AtlasConstraintDef;
import org.apache.atlas.type.AtlasTypeRegistry.AtlasTransientTypeRegistry;
import org.apache.atlas.type.AtlasEntityType.ForeignKeyReference;
import org.testng.annotations.Test;
import static org.testng.Assert.*;
public class TestAtlasEntityType {
private static final String TYPE_TABLE = "my_table";
private static final String TYPE_COLUMN = "my_column";
private static final String ATTR_TABLE = "table";
private static final String ATTR_COLUMNS = "columns";
private final AtlasEntityType entityType;
private final List<Object> validValues = new ArrayList<>();
private final List<Object> invalidValues = new ArrayList<>();
......@@ -138,13 +144,34 @@ public class TestAtlasEntityType {
ttr.addTypes(entityDefs);
AtlasEntityType typeTable = ttr.getEntityTypeByName(TYPE_TABLE);
AtlasEntityType typeColumn = ttr.getEntityTypeByName(TYPE_COLUMN);
assertEquals(typeTable.getForeignKeyReferences().size(), 1);
ForeignKeyReference fkRef = typeTable.getForeignKeyReferences().get(0);
assertEquals(fkRef.fromTypeName(), TYPE_COLUMN);
assertEquals(fkRef.fromAttributeName(), ATTR_TABLE);
assertEquals(fkRef.toTypeName(), TYPE_TABLE);
assertTrue(fkRef.isOnDeleteCascade());
assertFalse(fkRef.isOnDeleteUpdate());
assertEquals(typeTable.getForeignKeyAttributes().size(), 0);
assertEquals(typeTable.getMappedFromRefAttributes().size(), 1);
assertTrue(typeTable.getMappedFromRefAttributes().contains(ATTR_COLUMNS));
assertEquals(typeColumn.getForeignKeyReferences().size(), 0);
assertEquals(typeColumn.getForeignKeyAttributes().size(), 1);
assertTrue(typeColumn.getForeignKeyAttributes().contains(ATTR_TABLE));
assertEquals(typeColumn.getMappedFromRefAttributes().size(), 0);
commit = true;
} catch (AtlasBaseException excp) {
failureMsg = excp.getMessage();
} finally {
typeRegistry.releaseTypeRegistryForUpdate(ttr, commit);
}
assertNull(failureMsg, "failed to create types my_table and my_column");
assertNull(failureMsg, "failed to create types " + TYPE_TABLE + " and " + TYPE_COLUMN);
}
@Test
......@@ -230,12 +257,12 @@ public class TestAtlasEntityType {
}
private AtlasEntityDef createTableEntityDef() {
AtlasEntityDef table = new AtlasEntityDef("my_table");
AtlasAttributeDef attrColumns = new AtlasAttributeDef("columns",
AtlasBaseTypeDef.getArrayTypeName("my_column"));
AtlasEntityDef table = new AtlasEntityDef(TYPE_TABLE);
AtlasAttributeDef attrColumns = new AtlasAttributeDef(ATTR_COLUMNS,
AtlasBaseTypeDef.getArrayTypeName(TYPE_COLUMN));
Map<String, Object> params = new HashMap<>();
params.put(AtlasConstraintDef.CONSTRAINT_PARAM_REF_ATTRIBUTE, "table");
params.put(AtlasConstraintDef.CONSTRAINT_PARAM_REF_ATTRIBUTE, ATTR_TABLE);
attrColumns.addConstraint(new AtlasConstraintDef(AtlasConstraintDef.CONSTRAINT_TYPE_MAPPED_FROM_REF, params));
table.addAttribute(attrColumns);
......@@ -244,9 +271,9 @@ public class TestAtlasEntityType {
}
private AtlasEntityDef createTableEntityDefWithMissingRefAttribute() {
AtlasEntityDef table = new AtlasEntityDef("my_table");
AtlasAttributeDef attrColumns = new AtlasAttributeDef("columns",
AtlasBaseTypeDef.getArrayTypeName("my_column"));
AtlasEntityDef table = new AtlasEntityDef(TYPE_TABLE);
AtlasAttributeDef attrColumns = new AtlasAttributeDef(ATTR_COLUMNS,
AtlasBaseTypeDef.getArrayTypeName(TYPE_COLUMN));
attrColumns.addConstraint(new AtlasConstraintDef(AtlasConstraintDef.CONSTRAINT_TYPE_MAPPED_FROM_REF, null));
table.addAttribute(attrColumns);
......@@ -255,10 +282,13 @@ public class TestAtlasEntityType {
}
private AtlasEntityDef createColumnEntityDef() {
AtlasEntityDef column = new AtlasEntityDef("my_column");
AtlasAttributeDef attrTable = new AtlasAttributeDef("table", "my_table");
AtlasEntityDef column = new AtlasEntityDef(TYPE_COLUMN);
AtlasAttributeDef attrTable = new AtlasAttributeDef(ATTR_TABLE, TYPE_TABLE);
Map<String, Object> params = new HashMap<>();
params.put(AtlasConstraintDef.CONSTRAINT_PARAM_ON_DELETE, AtlasConstraintDef.CONSTRAINT_PARAM_VAL_CASCADE);
attrTable.addConstraint(new AtlasConstraintDef(AtlasConstraintDef.CONSTRAINT_TYPE_FOREIGN_KEY));
attrTable.addConstraint(new AtlasConstraintDef(AtlasConstraintDef.CONSTRAINT_TYPE_FOREIGN_KEY, params));
column.addAttribute(attrTable);
return column;
......
......@@ -9,6 +9,8 @@ ATLAS-1060 Add composite indexes for exact match performance improvements for al
ATLAS-1127 Modify creation and modification timestamps to Date instead of Long(sumasai)
ALL CHANGES:
ATLAS-1513: updated AtlasEntityType with methods to get foreign-key references; added helper methods in AtlasAttribute (mneethiraj via kevalbhatt)
ATLAS-1502: added configuration to restrict entity-types editable via UI (Kalyanikashikar via mneethiraj)
ATLAS-1507 fixed incorrect relationship specified in hive-model
ATLAS-1506 updated AtlasObjectId to support unqiueAttributes to identity the object
ATLAS-1378 Use .gitignore so git does not see binary files as changed (david_radley via dkantor)
......
......@@ -20,9 +20,8 @@ package org.apache.atlas.repository.store.graph.v1;
import com.google.common.base.Optional;
import com.google.inject.Inject;
import com.google.inject.Singleton;
import org.apache.atlas.aspect.Monitored;
import org.apache.atlas.exception.AtlasBaseException;
import org.apache.atlas.model.typedef.AtlasStructDef;
import org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef;
import org.apache.atlas.repository.graph.GraphHelper;
import org.apache.atlas.repository.graphdb.AtlasEdge;
import org.apache.atlas.repository.graphdb.AtlasVertex;
......@@ -111,7 +110,7 @@ public class ArrayVertexMapper implements InstanceGraphMapper<List> {
//Removes unused edges from the old collection, compared to the new collection
private List<AtlasEdge> removeUnusedArrayEntries(
AtlasStructType entityType,
AtlasStructDef.AtlasAttributeDef attributeDef,
AtlasAttributeDef attributeDef,
List<AtlasEdge> currentEntries,
List<AtlasEdge> newEntries,
AtlasType entryType) throws AtlasBaseException {
......
......@@ -25,7 +25,7 @@ import org.apache.atlas.model.TypeCategory;
import org.apache.atlas.model.instance.AtlasEntity;
import org.apache.atlas.model.instance.AtlasObjectId;
import org.apache.atlas.model.instance.AtlasStruct;
import org.apache.atlas.model.typedef.AtlasStructDef;
import org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef;
import org.apache.atlas.repository.store.graph.EntityGraphDiscoveryContext;
import org.apache.atlas.repository.store.graph.EntityGraphDiscovery;
import org.apache.atlas.repository.store.graph.EntityResolver;
......@@ -146,7 +146,7 @@ public class AtlasEntityGraphDiscoveryV1 implements EntityGraphDiscovery {
}
}
void visitAttribute(AtlasStructType parentType, AtlasType attrType, AtlasStructDef.AtlasAttributeDef attrDef, Object val) throws AtlasBaseException {
void visitAttribute(AtlasStructType parentType, AtlasType attrType, AtlasAttributeDef attrDef, Object val) throws AtlasBaseException {
if (val != null) {
if ( isPrimitive(attrType.getTypeCategory()) ) {
return;
......@@ -166,7 +166,8 @@ public class AtlasEntityGraphDiscoveryV1 implements EntityGraphDiscovery {
visitReference((AtlasEntityType) attrType, val, false);
} else if ( val instanceof AtlasEntity ) {
//TODO - Change this to foreign key checks after changes in the model
if ( parentType.isMappedFromRefAttribute(attrDef.getName())) {
if ((parentType instanceof AtlasEntityType) &&
((AtlasEntityType)parentType).isMappedFromRefAttribute(attrDef.getName())) {
visitReference((AtlasEntityType) attrType, val, true);
} else {
visitReference((AtlasEntityType) attrType, val, false);
......@@ -176,7 +177,7 @@ public class AtlasEntityGraphDiscoveryV1 implements EntityGraphDiscovery {
}
}
void visitMapReferences(AtlasStructType parentType, final AtlasType attrType, AtlasStructDef.AtlasAttributeDef attrDef, AtlasType keyType, AtlasType valueType, Object val) throws AtlasBaseException {
void visitMapReferences(AtlasStructType parentType, final AtlasType attrType, AtlasAttributeDef attrDef, AtlasType keyType, AtlasType valueType, Object val) throws AtlasBaseException {
if (isPrimitive(keyType.getTypeCategory()) && isPrimitive(valueType.getTypeCategory())) {
return;
}
......@@ -194,7 +195,7 @@ public class AtlasEntityGraphDiscoveryV1 implements EntityGraphDiscovery {
}
}
void visitCollectionReferences(final AtlasStructType parentType, final AtlasType attrType, final AtlasStructDef.AtlasAttributeDef attrDef, AtlasType elemType, Object val) throws AtlasBaseException {
void visitCollectionReferences(final AtlasStructType parentType, final AtlasType attrType, final AtlasAttributeDef attrDef, AtlasType elemType, Object val) throws AtlasBaseException {
if (isPrimitive(elemType.getTypeCategory())) {
return;
......@@ -228,7 +229,7 @@ public class AtlasEntityGraphDiscoveryV1 implements EntityGraphDiscovery {
for (AtlasStructType.AtlasAttribute attribute : structType.getAllAttributes().values()) {
AtlasType attrType = attribute.getAttributeType();
Object attrVal = ((AtlasStruct) val).getAttribute(attribute.getAttributeDef().getName());
Object attrVal = ((AtlasStruct) val).getAttribute(attribute.getName());
visitAttribute(structType, attrType, attribute.getAttributeDef(), attrVal);
}
}
......
......@@ -30,6 +30,7 @@ import org.apache.atlas.repository.graphdb.AtlasVertex;
import org.apache.atlas.repository.store.graph.AtlasStructDefStore;
import org.apache.atlas.repository.util.FilterUtil;
import org.apache.atlas.type.AtlasArrayType;
import org.apache.atlas.type.AtlasEntityType;
import org.apache.atlas.type.AtlasStructType;
import org.apache.atlas.type.AtlasType;
import org.apache.atlas.type.AtlasTypeRegistry;
......@@ -496,11 +497,18 @@ public class AtlasStructDefStoreV1 extends AtlasAbstractDefStoreV1 implements At
}
private static String toJsonFromAttributeDef(AtlasAttributeDef attributeDef, AtlasStructType structType) {
boolean isForeignKey = structType.isForeignKeyAttribute(attributeDef.getName());
boolean isMappedFromRef = structType.isMappedFromRefAttribute(attributeDef.getName());
boolean isComposite = false;
String reverseAttribName = null;
if (isForeignKey) { // check if the referenced entity has foreignKeyRef to this attribute
if (structType instanceof AtlasEntityType) {
AtlasEntityType entityType = (AtlasEntityType)structType;
isComposite = entityType.isMappedFromRefAttribute(attributeDef.getName()) ||
entityType.isForeignKeyOnDeleteActionUpdate(attributeDef.getName());
}
// find the attribute in the referenced entity that has mappedFromRef to this attribute
if (structType.isForeignKeyAttribute(attributeDef.getName())) {
AtlasType attribType = structType.getAttributeType(attributeDef.getName());
if (attribType.getTypeCategory() == org.apache.atlas.model.TypeCategory.ARRAY) {
......@@ -508,13 +516,13 @@ public class AtlasStructDefStoreV1 extends AtlasAbstractDefStoreV1 implements At
}
if (attribType.getTypeCategory() == org.apache.atlas.model.TypeCategory.ENTITY) {
reverseAttribName = ((AtlasStructType)attribType).getMappedFromRefAttribute(structType.getTypeName(),
AtlasEntityType attribEntityType = (AtlasEntityType)attribType;
reverseAttribName = attribEntityType.getMappedFromRefAttribute(structType.getTypeName(),
attributeDef.getName());
}
}
boolean isComposite = isMappedFromRef || (isForeignKey && StringUtils.isBlank(reverseAttribName));
Map<String, Object> attribInfo = new HashMap<>();
attribInfo.put("name", attributeDef.getName());
......
......@@ -24,7 +24,7 @@ import org.apache.atlas.RequestContextV1;
import org.apache.atlas.exception.AtlasBaseException;
import org.apache.atlas.model.TypeCategory;
import org.apache.atlas.model.instance.AtlasEntity;
import org.apache.atlas.model.typedef.AtlasStructDef;
import org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef;
import org.apache.atlas.repository.Constants;
import org.apache.atlas.repository.graph.AtlasEdgeLabel;
import org.apache.atlas.repository.graph.GraphHelper;
......@@ -137,11 +137,11 @@ public abstract class DeleteHandlerV1 {
}
for (AtlasStructType.AtlasAttribute attributeInfo : entityType.getAllAttributes().values()) {
if (!entityType.isMappedFromRefAttribute(attributeInfo.getAttributeDef().getName())) {
if (!entityType.isMappedFromRefAttribute(attributeInfo.getName())) {
continue;
}
String edgeLabel = AtlasGraphUtilsV1.getAttributeEdgeLabel(entityType, attributeInfo.getAttributeDef().getName());
AtlasType attrType = typeRegistry.getType(attributeInfo.getAttributeDef().getTypeName());
String edgeLabel = AtlasGraphUtilsV1.getAttributeEdgeLabel(entityType, attributeInfo.getName());
AtlasType attrType = typeRegistry.getType(attributeInfo.getTypeName());
switch (attrType.getTypeCategory()) {
case ENTITY:
AtlasEdge edge = graphHelper.getEdgeForLabel(vertex, edgeLabel);
......@@ -172,7 +172,7 @@ public abstract class DeleteHandlerV1 {
if (valueTypeCategory != TypeCategory.ENTITY) {
continue;
}
String propertyName = AtlasGraphUtilsV1.getQualifiedAttributePropertyKey(entityType, attributeInfo.getAttributeDef().getName());
String propertyName = AtlasGraphUtilsV1.getQualifiedAttributePropertyKey(entityType, attributeInfo.getName());
List<String> keys = vertex.getProperty(propertyName, List.class);
if (keys != null) {
for (String key : keys) {
......@@ -277,19 +277,21 @@ public abstract class DeleteHandlerV1 {
AtlasType parentType = typeRegistry.getType(typeName);
if (parentType instanceof AtlasStructType) {
AtlasStructType structType = (AtlasStructType) parentType;
boolean isEntityType = (parentType instanceof AtlasEntityType);
AtlasStructType entityType = (AtlasStructType) parentType;
for (AtlasStructType.AtlasAttribute attributeInfo : getAttributes(entityType)) {
LOG.debug("Deleting attribute {} for {}", attributeInfo.getAttributeDef().getName(), string(instanceVertex));
for (AtlasStructType.AtlasAttribute attributeInfo : getAttributes(structType)) {
LOG.debug("Deleting attribute {} for {}", attributeInfo.getName(), string(instanceVertex));
boolean isComposite = isEntityType && ((AtlasEntityType)structType).isMappedFromRefAttribute(attributeInfo.getName());
AtlasType attrType = typeRegistry.getType(attributeInfo.getAttributeType().getTypeName());
AtlasType attrType = typeRegistry.getType(attributeInfo.getTypeName());
String edgeLabel = AtlasGraphUtilsV1.getAttributeEdgeLabel(entityType, attributeInfo.getAttributeDef().getName());
String edgeLabel = AtlasGraphUtilsV1.getAttributeEdgeLabel(structType, attributeInfo.getName());
switch (attrType.getTypeCategory()) {
case ENTITY:
//If its class attribute, delete the reference
deleteEdgeReference(instanceVertex, edgeLabel, TypeCategory.ENTITY, entityType.isMappedFromRefAttribute(attributeInfo.getAttributeDef().getName()));
deleteEdgeReference(instanceVertex, edgeLabel, TypeCategory.ENTITY, isComposite);
break;
case STRUCT:
......@@ -306,7 +308,7 @@ public abstract class DeleteHandlerV1 {
if (edges != null) {
while (edges.hasNext()) {
AtlasEdge edge = edges.next();
deleteEdgeReference(edge, elemType.getTypeCategory(), entityType.isMappedFromRefAttribute(attributeInfo.getAttributeDef().getName()), false);
deleteEdgeReference(edge, elemType.getTypeCategory(), isComposite, false);
}
}
}
......@@ -317,14 +319,14 @@ public abstract class DeleteHandlerV1 {
AtlasMapType mapType = (AtlasMapType) attrType;
AtlasType keyType = mapType.getKeyType();
TypeCategory valueTypeCategory = mapType.getValueType().getTypeCategory();
String propertyName = AtlasGraphUtilsV1.getQualifiedAttributePropertyKey(entityType, attributeInfo.getAttributeDef().getName());
String propertyName = AtlasGraphUtilsV1.getQualifiedAttributePropertyKey(structType, attributeInfo.getName());
if (AtlasGraphUtilsV1.isReference(valueTypeCategory)) {
List<Object> keys = ArrayVertexMapper.getArrayElementsProperty(keyType, instanceVertex, propertyName);
if (keys != null) {
for (Object key : keys) {
String mapEdgeLabel = GraphHelper.getQualifiedNameForMapKey(edgeLabel, (String) key);
deleteEdgeReference(instanceVertex, mapEdgeLabel, valueTypeCategory, entityType.isMappedFromRefAttribute(attributeInfo.getAttributeDef().getName()));
deleteEdgeReference(instanceVertex, mapEdgeLabel, valueTypeCategory, isComposite);
}
}
}
......@@ -359,7 +361,7 @@ public abstract class DeleteHandlerV1 {
}
}
protected AtlasStructDef.AtlasAttributeDef getAttributeForEdge(String edgeLabel) throws AtlasBaseException {
protected AtlasAttributeDef getAttributeForEdge(String edgeLabel) throws AtlasBaseException {
AtlasEdgeLabel atlasEdgeLabel = new AtlasEdgeLabel(edgeLabel);
AtlasType parentType = typeRegistry.getType(atlasEdgeLabel.getTypeName());
......@@ -395,7 +397,7 @@ public abstract class DeleteHandlerV1 {
String edgeLabel = EDGE_LABEL_PREFIX + propertyName;
AtlasEdge edge = null;
AtlasStructDef.AtlasAttributeDef attrDef = parentType.getAttributeDef(attributeName);
AtlasAttributeDef attrDef = parentType.getAttributeDef(attributeName);
AtlasType attrType = typeRegistry.getType(attrDef.getTypeName());
switch (attrType.getTypeCategory()) {
......@@ -518,7 +520,7 @@ public abstract class DeleteHandlerV1 {
AtlasEntity.Status edgeState = AtlasGraphUtilsV1.getState(edge);
if (edgeState == AtlasEntity.Status.ACTIVE) {
//Delete only the active edge references
AtlasStructDef.AtlasAttributeDef attribute = getAttributeForEdge(edge.getLabel());
AtlasAttributeDef attribute = getAttributeForEdge(edge.getLabel());
//TODO use delete edge instead??
deleteEdgeBetweenVertices(edge.getOutVertex(), edge.getInVertex(), attribute.getName());
}
......
......@@ -20,7 +20,6 @@ package org.apache.atlas.repository.store.graph.v1;
import com.google.inject.Inject;
import org.apache.atlas.AtlasErrorCode;
import org.apache.atlas.RequestContextV1;
import org.apache.atlas.exception.AtlasBaseException;
import org.apache.atlas.model.TypeCategory;
import org.apache.atlas.model.instance.AtlasEntity;
......@@ -29,7 +28,7 @@ import org.apache.atlas.model.instance.AtlasObjectId;
import org.apache.atlas.model.instance.AtlasStruct;
import org.apache.atlas.model.instance.EntityMutationResponse;
import org.apache.atlas.model.instance.EntityMutations;
import org.apache.atlas.model.typedef.AtlasStructDef;
import org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef;
import org.apache.atlas.repository.Constants;
import org.apache.atlas.repository.RepositoryException;
import org.apache.atlas.repository.graph.GraphHelper;
......@@ -109,7 +108,7 @@ public class EntityGraphMapper implements InstanceGraphMapper<AtlasEdge> {
public void cleanUp() throws AtlasBaseException {
}
private AtlasEdge updateEdge(AtlasStructDef.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 {
LOG.debug("Updating entity reference {} for reference attribute {}", attributeDef.getName());
// Update edge if it exists
......@@ -180,7 +179,7 @@ public class EntityGraphMapper implements InstanceGraphMapper<AtlasEdge> {
final Map<String, AtlasStructType.AtlasAttribute> allAttributes = type.getAllAttributes();
for (String attribute : allAttributes.keySet()) {
AtlasType attributeType = allAttributes.get(attribute).getAttributeType();
AtlasStructDef.AtlasAttributeDef attributeDef = allAttributes.get(attribute).getAttributeDef();
AtlasAttributeDef attributeDef = allAttributes.get(attribute).getAttributeDef();
if ( header.getAttribute(attribute) == null && (TypeCategory.PRIMITIVE == attributeType.getTypeCategory())) {
if ( attributeDef.getIsOptional()) {
......
......@@ -21,6 +21,7 @@ package org.apache.atlas.repository.store.graph.v1;
import com.google.common.base.Optional;
import org.apache.atlas.model.instance.EntityMutations;
import org.apache.atlas.model.typedef.AtlasStructDef;
import org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef;
import org.apache.atlas.repository.graphdb.AtlasEdge;
import org.apache.atlas.repository.graphdb.AtlasVertex;
import org.apache.atlas.type.AtlasStructType;
......@@ -166,7 +167,7 @@ public class GraphMutationContext {
return attribute.getStructDef();
}
public AtlasStructDef.AtlasAttributeDef getAttributeDef() {
public AtlasAttributeDef getAttributeDef() {
return attribute.getAttributeDef();
}
......
......@@ -20,16 +20,13 @@ package org.apache.atlas.repository.store.graph.v1;
import com.google.common.base.Optional;
import com.google.inject.Inject;
import com.google.inject.Singleton;
import org.apache.atlas.AtlasErrorCode;
import org.apache.atlas.AtlasException;
import org.apache.atlas.exception.AtlasBaseException;
import org.apache.atlas.model.TypeCategory;
import org.apache.atlas.model.typedef.AtlasStructDef;
import org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef;
import org.apache.atlas.repository.graph.GraphHelper;
import org.apache.atlas.repository.graphdb.AtlasEdge;
import org.apache.atlas.repository.graphdb.AtlasVertex;
import org.apache.atlas.type.AtlasEntityType;
import org.apache.atlas.type.AtlasMapType;
import org.apache.atlas.type.AtlasStructType;
import org.apache.atlas.type.AtlasType;
......@@ -37,7 +34,6 @@ import org.apache.commons.collections.MapUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.inject.Provider;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
......@@ -158,7 +154,7 @@ public class MapVertexMapper implements InstanceGraphMapper<Map> {
//Remove unused entries from map
private Map<String, Object> removeUnusedMapEntries(
AtlasStructType entityType,
AtlasMapType mapType, AtlasStructDef.AtlasAttributeDef attributeDef,
AtlasMapType mapType, AtlasAttributeDef attributeDef,
AtlasVertex instanceVertex, String propertyName,
Map<String, Object> currentMap,
Map<String, Object> newMap)
......
......@@ -25,10 +25,9 @@ import org.apache.atlas.model.TypeCategory;
import org.apache.atlas.model.instance.AtlasEntity;
import org.apache.atlas.model.instance.AtlasStruct;
import org.apache.atlas.model.instance.EntityMutations;
import org.apache.atlas.model.typedef.AtlasStructDef;
import org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef;
import org.apache.atlas.repository.Constants;
import org.apache.atlas.repository.RepositoryException;
import org.apache.atlas.repository.graph.AtlasEdgeLabel;
import org.apache.atlas.repository.graph.AtlasGraphProvider;
import org.apache.atlas.repository.graph.GraphHelper;
import org.apache.atlas.repository.graphdb.AtlasEdge;
......@@ -86,7 +85,7 @@ public class StructVertexMapper implements InstanceGraphMapper<AtlasEdge> {
}
public static boolean shouldManageChildReferences(AtlasStructType type, String attributeName) {
return type.isMappedFromRefAttribute(attributeName);
return (type instanceof AtlasEntityType) && ((AtlasEntityType)type).isMappedFromRefAttribute(attributeName);
}
/**
......@@ -186,7 +185,7 @@ public class StructVertexMapper implements InstanceGraphMapper<AtlasEdge> {
return ctx.getValue();
}
private AtlasEdge createVertex(AtlasStructType parentType, AtlasStructType attrType, AtlasStructDef.AtlasAttributeDef attributeDef, AtlasStruct struct, AtlasVertex referringVertex, String edgeLabel) throws AtlasBaseException {
private AtlasEdge createVertex(AtlasStructType parentType, AtlasStructType attrType, AtlasAttributeDef attributeDef, AtlasStruct struct, AtlasVertex referringVertex, String edgeLabel) throws AtlasBaseException {
AtlasVertex vertex = createVertexTemplate(struct, attrType);
mapAttributestoVertex(EntityMutations.EntityOperation.CREATE, attrType, struct, vertex);
......@@ -198,7 +197,7 @@ public class StructVertexMapper implements InstanceGraphMapper<AtlasEdge> {
}
}
private void updateVertex(AtlasStructType parentType, AtlasStructType structAttributeType, AtlasStructDef.AtlasAttributeDef attributeDef, AtlasStruct value, AtlasVertex structVertex) throws AtlasBaseException {
private void updateVertex(AtlasStructType parentType, AtlasStructType structAttributeType, AtlasAttributeDef attributeDef, AtlasStruct value, AtlasVertex structVertex) throws AtlasBaseException {
mapAttributestoVertex(EntityMutations.EntityOperation.CREATE, structAttributeType, value, structVertex);
}
......
......@@ -107,7 +107,7 @@ public class UniqAttrBasedEntityResolver implements EntityResolver {
for (AtlasStructType.AtlasAttribute attr : entityType.getAllAttributes().values()) {
if (attr.getAttributeDef().getIsUnique()) {
Object attrVal = entity.getAttribute(attr.getAttributeDef().getName());
Object attrVal = entity.getAttribute(attr.getName());
if (attrVal != null) {
String qualifiedAttrName = attr.getQualifiedAttributeName();
AtlasVertex vertex = null;
......
......@@ -479,7 +479,7 @@ public final class RestUtils {
// 2. [ foreignKey(onDelete=cascade) -> reverseAttribute ]
AtlasStructType structType = (AtlasStructType) registry.getType(structDef.getName());
boolean isForeignKey = structType.isForeignKeyAttribute(attrDef.getName());
boolean isMappedFromRef = structType.isMappedFromRefAttribute(attrDef.getName());
boolean isMappedFromRef = (structType instanceof AtlasEntityType) && ((AtlasEntityType)structType).isMappedFromRefAttribute(attrDef.getName());
AtlasType attrType = structType.getAttributeType(attrDef.getName());
if (attrType != null && isForeignKey) {
......@@ -488,7 +488,7 @@ public final class RestUtils {
}
if (attrType.getTypeCategory() == TypeCategory.ENTITY) {
reverseAttribName = ((AtlasStructType) attrType).
reverseAttribName = ((AtlasEntityType) attrType).
getMappedFromRefAttribute(structType.getTypeName(), attrDef.getName());
}
}
......
......@@ -124,20 +124,20 @@ public class AtlasStructFormatConverter extends AtlasAbstractFormatConverter {
if (MapUtils.isNotEmpty(attributes)) {
ret = new HashMap<>();
for (AtlasStructType.AtlasAttribute attr : getAttributes(structType)) {
AtlasType attrType = structType.getAttributeType(attr.getAttributeDef().getName());
for (AtlasStructType.AtlasAttribute attr : structType.getAllAttributes().values()) {
AtlasType attrType = attr.getAttributeType();
if (attrType == null) {
LOG.warn("ignored attribute {}.{}: failed to find AtlasType", structType.getTypeName(), attr.getAttributeDef().getName());
LOG.warn("ignored attribute {}.{}: failed to find AtlasType", structType.getTypeName(), attr.getName());
continue;
}
AtlasFormatConverter attrConverter = converterRegistry.getConverter(attrType.getTypeCategory());
Object v2Value = attributes.get(attr.getAttributeDef().getName());
Object v2Value = attributes.get(attr.getName());
Object v1Value = attrConverter.fromV2ToV1(v2Value, attrType);
ret.put(attr.getAttributeDef().getName(), v1Value);
ret.put(attr.getName(), v1Value);
}
}
......@@ -150,11 +150,11 @@ public class AtlasStructFormatConverter extends AtlasAbstractFormatConverter {
if (MapUtils.isNotEmpty(attributes)) {
ret = new HashMap<>();
for (AtlasStructType.AtlasAttribute attr : getAttributes(structType)) {
AtlasType attrType = structType.getAttributeType(attr.getAttributeDef().getName());
for (AtlasStructType.AtlasAttribute attr : structType.getAllAttributes().values()) {
AtlasType attrType = attr.getAttributeType();
AtlasFormatConverter attrConverter = converterRegistry.getConverter(attrType.getTypeCategory());
Object v1Value = attributes.get(attr.getAttributeDef().getName());
Object v1Value = attributes.get(attr.getName());
Object v2Value = attrConverter.fromV1ToV2(v1Value, attrType);
ret.put(attr.getAttributeDef().getName(), v2Value);
......
......@@ -26,7 +26,7 @@ import org.apache.atlas.model.instance.AtlasClassification;
import org.apache.atlas.model.instance.AtlasEntity;
import org.apache.atlas.model.instance.AtlasEntityWithAssociations;
import org.apache.atlas.model.instance.EntityMutationResponse;
import org.apache.atlas.model.typedef.AtlasStructDef;
import org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef;
import org.apache.atlas.services.MetadataService;
import org.apache.atlas.type.AtlasEntityType;
import org.apache.atlas.type.AtlasType;
......@@ -390,8 +390,9 @@ public class EntityREST {
* @param attributeName the name of the attribute
*/
private void validateUniqueAttribute(AtlasEntityType entityType, String attributeName) throws AtlasBaseException {
AtlasStructDef.AtlasAttributeDef attribute = entityType.getAttributeDef(attributeName);
if (attribute != null && !attribute.getIsUnique()) {
AtlasAttributeDef attribute = entityType.getAttributeDef(attributeName);
if (attribute == null || !attribute.getIsUnique()) {
throw new AtlasBaseException(AtlasErrorCode.ATTRIBUTE_UNIQUE_INVALID, entityType.getTypeName(), attributeName);
}
}
......
......@@ -30,6 +30,7 @@ import org.apache.atlas.model.typedef.AtlasEntityDef;
import org.apache.atlas.model.typedef.AtlasEnumDef;
import org.apache.atlas.model.typedef.AtlasStructDef;
import org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef;
import org.apache.atlas.model.typedef.AtlasStructDef.AtlasConstraintDef;
import org.apache.atlas.model.typedef.AtlasTypesDef;
import org.apache.atlas.type.AtlasTypeUtil;
import org.apache.atlas.typesystem.types.DataTypes;
......@@ -243,7 +244,7 @@ public class TypedefsJerseyResourceIT extends BaseResourceIT {
@Test
public void testListTypesByFilter() throws Exception {
AtlasStructDef.AtlasAttributeDef attr = AtlasTypeUtil.createOptionalAttrDef("attr", "string");
AtlasAttributeDef attr = AtlasTypeUtil.createOptionalAttrDef("attr", "string");
AtlasEntityDef classDefA = AtlasTypeUtil.createClassTypeDef("A" + randomString(), ImmutableSet.<String>of(), attr);
AtlasEntityDef classDefA1 = AtlasTypeUtil.createClassTypeDef("A1" + randomString(), ImmutableSet.of(classDefA.getName()), attr);
AtlasEntityDef classDefB = AtlasTypeUtil.createClassTypeDef("B" + randomString(), ImmutableSet.<String>of(), attr);
......@@ -296,7 +297,7 @@ public class TypedefsJerseyResourceIT extends BaseResourceIT {
false,
Cardinality.SINGLE, 1, 1,
true, true,
Collections.<AtlasStructDef.AtlasConstraintDef>emptyList()));
Collections.<AtlasConstraintDef>emptyList()));
atlasTypesDef.getEntityDefs().add(tableTypeDefinition);
AtlasClassificationDef fetlTypeDefinition = AtlasTypeUtil
......
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