use of org.apache.atlas.model.typedef.AtlasEntityDef in project incubator-atlas by apache.
the class TypeDefSorter method addToResult.
private static <T extends AtlasStructDef> void addToResult(T type, List<T> result, Set<T> processed, Map<String, T> typesByName) {
if (processed.contains(type)) {
return;
}
processed.add(type);
Set<String> superTypeNames = new HashSet<>();
if (type.getClass().equals(AtlasClassificationDef.class)) {
try {
AtlasClassificationDef classificationDef = AtlasClassificationDef.class.cast(type);
superTypeNames.addAll(classificationDef.getSuperTypes());
} catch (ClassCastException ex) {
LOG.warn("Casting to ClassificationDef failed");
}
}
if (type.getClass().equals(AtlasEntityDef.class)) {
try {
AtlasEntityDef entityDef = AtlasEntityDef.class.cast(type);
superTypeNames.addAll(entityDef.getSuperTypes());
} catch (ClassCastException ex) {
LOG.warn("Casting to AtlasEntityDef failed");
}
}
for (String superTypeName : superTypeNames) {
// Recursively add any supertypes first to the result.
T superType = typesByName.get(superTypeName);
if (superType != null) {
addToResult(superType, result, processed, typesByName);
}
}
result.add(type);
}
use of org.apache.atlas.model.typedef.AtlasEntityDef in project incubator-atlas by apache.
the class EntityV2JerseyResourceIT method testUTF8.
@Test
public void testUTF8() throws Exception {
String classType = randomString();
String attrName = random();
String attrValue = random();
AtlasEntityDef classTypeDef = AtlasTypeUtil.createClassTypeDef(classType, ImmutableSet.<String>of(), AtlasTypeUtil.createUniqueRequiredAttrDef(attrName, "string"));
AtlasTypesDef atlasTypesDef = new AtlasTypesDef();
atlasTypesDef.getEntityDefs().add(classTypeDef);
createType(atlasTypesDef);
AtlasEntity instance = new AtlasEntity(classType);
instance.setAttribute(attrName, attrValue);
AtlasEntityHeader entity = createEntity(instance);
assertNotNull(entity);
assertNotNull(entity.getGuid());
AtlasEntity entityByGuid = getEntityByGuid(entity.getGuid());
assertEquals(entityByGuid.getAttribute(attrName), attrValue);
}
use of org.apache.atlas.model.typedef.AtlasEntityDef in project incubator-atlas by apache.
the class TypedefsJerseyResourceIT method createHiveTypesV2.
private AtlasTypesDef createHiveTypesV2() throws Exception {
AtlasTypesDef atlasTypesDef = new AtlasTypesDef();
AtlasEntityDef databaseTypeDefinition = createClassTypeDef("database", ImmutableSet.<String>of(), AtlasTypeUtil.createUniqueRequiredAttrDef("name", "string"), AtlasTypeUtil.createRequiredAttrDef("description", "string"));
atlasTypesDef.getEntityDefs().add(databaseTypeDefinition);
AtlasEntityDef tableTypeDefinition = createClassTypeDef("table", ImmutableSet.<String>of(), AtlasTypeUtil.createUniqueRequiredAttrDef("name", "string"), AtlasTypeUtil.createRequiredAttrDef("description", "string"), AtlasTypeUtil.createOptionalAttrDef("columnNames", DataTypes.arrayTypeName("string")), AtlasTypeUtil.createOptionalAttrDef("created", "date"), AtlasTypeUtil.createOptionalAttrDef("parameters", DataTypes.mapTypeName("string", "string")), AtlasTypeUtil.createRequiredAttrDef("type", "string"), new AtlasAttributeDef("database", "database", false, Cardinality.SINGLE, 1, 1, true, true, Collections.<AtlasConstraintDef>emptyList()));
atlasTypesDef.getEntityDefs().add(tableTypeDefinition);
AtlasClassificationDef fetlTypeDefinition = AtlasTypeUtil.createTraitTypeDef("fetl", ImmutableSet.<String>of(), AtlasTypeUtil.createRequiredAttrDef("level", "int"));
atlasTypesDef.getClassificationDefs().add(fetlTypeDefinition);
return atlasTypesDef;
}
use of org.apache.atlas.model.typedef.AtlasEntityDef in project incubator-atlas by apache.
the class TypedefsJerseyResourceIT method testCreate.
@Test
public void testCreate() throws Exception {
createType(typeDefinitions);
for (AtlasEnumDef enumDef : typeDefinitions.getEnumDefs()) {
AtlasEnumDef byName = atlasClientV2.getEnumDefByName(enumDef.getName());
assertNotNull(byName);
}
for (AtlasStructDef structDef : typeDefinitions.getStructDefs()) {
AtlasStructDef byName = atlasClientV2.getStructDefByName(structDef.getName());
assertNotNull(byName);
}
for (AtlasClassificationDef classificationDef : typeDefinitions.getClassificationDefs()) {
AtlasClassificationDef byName = atlasClientV2.getClassificationDefByName(classificationDef.getName());
assertNotNull(byName);
}
for (AtlasEntityDef entityDef : typeDefinitions.getEntityDefs()) {
AtlasEntityDef byName = atlasClientV2.getEntityDefByName(entityDef.getName());
assertNotNull(byName);
}
}
use of org.apache.atlas.model.typedef.AtlasEntityDef in project incubator-atlas by apache.
the class TypedefsJerseyResourceIT method testListTypesByFilter.
@Test
public void testListTypesByFilter() throws Exception {
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);
AtlasEntityDef classDefC = AtlasTypeUtil.createClassTypeDef("C" + randomString(), ImmutableSet.of(classDefB.getName(), classDefA.getName()), attr);
AtlasTypesDef atlasTypesDef = new AtlasTypesDef();
atlasTypesDef.getEntityDefs().add(classDefA);
atlasTypesDef.getEntityDefs().add(classDefA1);
atlasTypesDef.getEntityDefs().add(classDefB);
atlasTypesDef.getEntityDefs().add(classDefC);
AtlasTypesDef created = clientV2.createAtlasTypeDefs(atlasTypesDef);
assertNotNull(created);
assertEquals(created.getEntityDefs().size(), atlasTypesDef.getEntityDefs().size());
MultivaluedMap<String, String> searchParams = new MultivaluedMapImpl();
searchParams.add(SearchFilter.PARAM_TYPE, "CLASS");
searchParams.add(SearchFilter.PARAM_SUPERTYPE, classDefA.getName());
SearchFilter searchFilter = new SearchFilter(searchParams);
AtlasTypesDef searchDefs = clientV2.getAllTypeDefs(searchFilter);
assertNotNull(searchDefs);
assertEquals(searchDefs.getEntityDefs().size(), 2);
searchParams.add(SearchFilter.PARAM_NOT_SUPERTYPE, classDefB.getName());
searchFilter = new SearchFilter(searchParams);
searchDefs = clientV2.getAllTypeDefs(searchFilter);
assertNotNull(searchDefs);
assertEquals(searchDefs.getEntityDefs().size(), 1);
}
Aggregations