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