use of org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef in project incubator-atlas by apache.
the class TestAtlasStructDef method testStructDefAddAttribute.
@Test
public void testStructDefAddAttribute() {
AtlasStructDef structDef = ModelTestUtil.newStructDef();
structDef.addAttribute(new AtlasAttributeDef("newAttribute", AtlasBaseTypeDef.ATLAS_TYPE_INT));
assertTrue(structDef.hasAttribute("newAttribute"));
}
use of org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef in project incubator-atlas by apache.
the class TestAtlasEntityType method createColumnEntityDefWithMissingInverseAttribute.
private AtlasEntityDef createColumnEntityDefWithMissingInverseAttribute() {
AtlasEntityDef column = new AtlasEntityDef(TYPE_COLUMN);
AtlasAttributeDef attrTable = new AtlasAttributeDef(ATTR_TABLE, TYPE_TABLE);
attrTable.addConstraint(new AtlasConstraintDef(AtlasConstraintDef.CONSTRAINT_TYPE_INVERSE_REF));
column.addAttribute(attrTable);
return column;
}
use of org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef in project incubator-atlas by apache.
the class GraphBackedSearchIndexer method cleanupIndices.
private void cleanupIndices(AtlasGraphManagement management, AtlasBaseTypeDef typeDef) {
Preconditions.checkNotNull(typeDef, "Cannot process null typedef");
if (LOG.isDebugEnabled()) {
LOG.debug("Cleaning up index for {}", typeDef);
}
if (typeDef instanceof AtlasEnumDef) {
// Only handle complex types like Struct, Classification and Entity
return;
}
if (typeDef instanceof AtlasStructDef) {
AtlasStructDef structDef = (AtlasStructDef) typeDef;
List<AtlasAttributeDef> attributeDefs = structDef.getAttributeDefs();
if (CollectionUtils.isNotEmpty(attributeDefs)) {
for (AtlasAttributeDef attributeDef : attributeDefs) {
cleanupIndexForAttribute(management, typeDef.getName(), attributeDef);
}
}
} else if (!AtlasTypeUtil.isBuiltInType(typeDef.getName())) {
throw new IllegalArgumentException("bad data type" + typeDef.getName());
}
}
use of org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef in project incubator-atlas by apache.
the class GraphBackedSearchIndexer method addIndexForType.
private void addIndexForType(AtlasGraphManagement management, AtlasBaseTypeDef typeDef) {
if (typeDef instanceof AtlasEnumDef) {
// Only handle complex types like Struct, Classification and Entity
return;
}
if (typeDef instanceof AtlasStructDef) {
AtlasStructDef structDef = (AtlasStructDef) typeDef;
List<AtlasAttributeDef> attributeDefs = structDef.getAttributeDefs();
if (CollectionUtils.isNotEmpty(attributeDefs)) {
for (AtlasAttributeDef attributeDef : attributeDefs) {
createIndexForAttribute(management, typeDef.getName(), attributeDef);
}
}
} else if (!AtlasTypeUtil.isBuiltInType(typeDef.getName())) {
throw new IllegalArgumentException("bad data type" + typeDef.getName());
}
}
use of org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef in project incubator-atlas by apache.
the class AtlasEntityStoreV1Test method testTagAssociationAfterRedefinition.
@Test
public void testTagAssociationAfterRedefinition() {
AtlasClassificationDef aTag = new AtlasClassificationDef("testTag");
AtlasAttributeDef attributeDef = new AtlasAttributeDef("testAttribute", "int", true, AtlasAttributeDef.Cardinality.SINGLE, 0, 1, false, true, Collections.<AtlasStructDef.AtlasConstraintDef>emptyList());
aTag.addAttribute(attributeDef);
AtlasTypesDef typesDef = new AtlasTypesDef();
typesDef.setClassificationDefs(Arrays.asList(aTag));
try {
typeDefStore.createTypesDef(typesDef);
} catch (AtlasBaseException e) {
fail("Tag creation should've succeeded");
}
try {
typeDefStore.deleteTypesDef(typesDef);
} catch (AtlasBaseException e) {
fail("Tag deletion should've succeeded");
}
aTag = new AtlasClassificationDef("testTag");
attributeDef = new AtlasAttributeDef("testAttribute", "string", true, AtlasAttributeDef.Cardinality.SINGLE, 0, 1, false, true, Collections.<AtlasStructDef.AtlasConstraintDef>emptyList());
aTag.addAttribute(attributeDef);
typesDef.setClassificationDefs(Arrays.asList(aTag));
try {
typeDefStore.createTypesDef(typesDef);
} catch (AtlasBaseException e) {
fail("Tag re-creation should've succeeded");
}
final AtlasEntity dbEntity = TestUtilsV2.createDBEntity();
try {
EntityMutationResponse response = entityStore.createOrUpdate(new AtlasEntityStream(dbEntity), false);
List<AtlasEntityHeader> createdEntity = response.getCreatedEntities();
assertTrue(CollectionUtils.isNotEmpty(createdEntity));
String guid = createdEntity.get(0).getGuid();
entityStore.addClassification(Arrays.asList(guid), new AtlasClassification(aTag.getName(), "testAttribute", "test-string"));
} catch (AtlasBaseException e) {
fail("DB entity creation should've succeeded");
}
}
Aggregations