Search in sources :

Example 56 with AtlasEntityDef

use of org.apache.atlas.model.typedef.AtlasEntityDef in project incubator-atlas by apache.

the class TestRelationshipUtilsV2 method getInverseReferenceTestTypes.

public static AtlasTypesDef getInverseReferenceTestTypes() throws AtlasBaseException {
    AtlasEntityDef aType = createClassTypeDef(TYPE_A, superType(null), createUniqueRequiredAttrDef("name", "string"));
    AtlasEntityDef bType = createClassTypeDef(TYPE_B, superType(null), createUniqueRequiredAttrDef("name", "string"));
    AtlasRelationshipDef relationshipType1 = new AtlasRelationshipDef("TypeA_to_TypeB_on_b", description("TypeA_to_TypeB_on_b"), DEFAULT_VERSION, ASSOCIATION, ONE_TO_TWO, new AtlasRelationshipEndDef(TYPE_A, "b", SINGLE), new AtlasRelationshipEndDef(TYPE_B, "a", SINGLE));
    AtlasRelationshipDef relationshipType2 = new AtlasRelationshipDef("TypeA_to_TypeB_on_oneB", description("TypeA_to_TypeB_on_oneB"), DEFAULT_VERSION, ASSOCIATION, ONE_TO_TWO, new AtlasRelationshipEndDef(TYPE_A, "oneB", SINGLE), new AtlasRelationshipEndDef(TYPE_B, "manyA", SET));
    AtlasRelationshipDef relationshipType3 = new AtlasRelationshipDef("TypeA_to_TypeB_on_manyB", description("TypeA_to_TypeB_on_manyB"), DEFAULT_VERSION, ASSOCIATION, ONE_TO_TWO, new AtlasRelationshipEndDef(TYPE_A, "manyB", SET), new AtlasRelationshipEndDef(TYPE_B, "manyToManyA", SET));
    AtlasRelationshipDef relationshipType4 = new AtlasRelationshipDef("TypeB_to_TypeA_on_mappedFromA", description("TypeB_to_TypeA_on_mappedFromA"), DEFAULT_VERSION, ASSOCIATION, ONE_TO_TWO, new AtlasRelationshipEndDef(TYPE_B, "mappedFromA", SINGLE), new AtlasRelationshipEndDef(TYPE_A, "mapToB", SET));
    return new AtlasTypesDef(ImmutableList.<AtlasEnumDef>of(), ImmutableList.<AtlasStructDef>of(), ImmutableList.<AtlasClassificationDef>of(), ImmutableList.of(aType, bType), ImmutableList.of(relationshipType1, relationshipType2, relationshipType3, relationshipType4));
}
Also used : AtlasEntityDef(org.apache.atlas.model.typedef.AtlasEntityDef) AtlasRelationshipDef(org.apache.atlas.model.typedef.AtlasRelationshipDef) AtlasRelationshipEndDef(org.apache.atlas.model.typedef.AtlasRelationshipEndDef) AtlasTypesDef(org.apache.atlas.model.typedef.AtlasTypesDef)

Example 57 with AtlasEntityDef

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);
}
Also used : AtlasClassificationDef(org.apache.atlas.model.typedef.AtlasClassificationDef) AtlasEntityDef(org.apache.atlas.model.typedef.AtlasEntityDef) HashSet(java.util.HashSet)

Example 58 with AtlasEntityDef

use of org.apache.atlas.model.typedef.AtlasEntityDef in project incubator-atlas by apache.

the class ExportService method processTypesDef.

private void processTypesDef(ExportContext context) {
    AtlasTypesDef typesDef = context.result.getData().getTypesDef();
    for (String entityType : context.entityTypes) {
        AtlasEntityDef entityDef = typeRegistry.getEntityDefByName(entityType);
        typesDef.getEntityDefs().add(entityDef);
    }
    for (String classificationType : context.classificationTypes) {
        AtlasClassificationDef classificationDef = typeRegistry.getClassificationDefByName(classificationType);
        typesDef.getClassificationDefs().add(classificationDef);
    }
    for (String structType : context.structTypes) {
        AtlasStructDef structDef = typeRegistry.getStructDefByName(structType);
        typesDef.getStructDefs().add(structDef);
    }
    for (String enumType : context.enumTypes) {
        AtlasEnumDef enumDef = typeRegistry.getEnumDefByName(enumType);
        typesDef.getEnumDefs().add(enumDef);
    }
}
Also used : AtlasClassificationDef(org.apache.atlas.model.typedef.AtlasClassificationDef) AtlasStructDef(org.apache.atlas.model.typedef.AtlasStructDef) AtlasEntityDef(org.apache.atlas.model.typedef.AtlasEntityDef) AtlasEnumDef(org.apache.atlas.model.typedef.AtlasEnumDef) AtlasTypesDef(org.apache.atlas.model.typedef.AtlasTypesDef)

Example 59 with AtlasEntityDef

use of org.apache.atlas.model.typedef.AtlasEntityDef in project incubator-atlas by apache.

the class TypeConverterUtil method toAtlasEntityDefs.

private static List<AtlasEntityDef> toAtlasEntityDefs(List<HierarchicalTypeDefinition<ClassType>> classTypeDefinitions, AtlasTypeRegistry registry) throws AtlasBaseException {
    List<AtlasEntityDef> atlasEntityDefs = new ArrayList<AtlasEntityDef>();
    for (HierarchicalTypeDefinition<ClassType> classType : classTypeDefinitions) {
        List<AtlasAttributeDef> attrDefs = new ArrayList<AtlasAttributeDef>();
        AtlasEntityDef atlasEntityDef = new AtlasEntityDef();
        String classTypeDefName = classType.typeName;
        atlasEntityDef.setName(classTypeDefName);
        atlasEntityDef.setDescription(classType.typeDescription);
        atlasEntityDef.setTypeVersion(classType.typeVersion);
        atlasEntityDef.setSuperTypes(classType.superTypes);
        AttributeDefinition[] attrDefinitions = classType.attributeDefinitions;
        for (AttributeDefinition oldAttr : attrDefinitions) {
            AtlasAttributeDef newAttr = toAtlasAttributeDef(oldAttr);
            attrDefs.add(newAttr);
        }
        atlasEntityDef.setAttributeDefs(attrDefs);
        atlasEntityDefs.add(atlasEntityDef);
    }
    return atlasEntityDefs;
}
Also used : AtlasEntityDef(org.apache.atlas.model.typedef.AtlasEntityDef) AtlasAttributeDef(org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef) ArrayList(java.util.ArrayList) AttributeDefinition(org.apache.atlas.typesystem.types.AttributeDefinition) ClassType(org.apache.atlas.typesystem.types.ClassType)

Example 60 with AtlasEntityDef

use of org.apache.atlas.model.typedef.AtlasEntityDef in project incubator-atlas by apache.

the class EntityV2JerseyResourceIT method testEntityDefinitionAcrossTypeUpdate.

@Test
public void testEntityDefinitionAcrossTypeUpdate() throws Exception {
    // create type
    AtlasEntityDef entityDef = AtlasTypeUtil.createClassTypeDef(randomString(), ImmutableSet.<String>of(), AtlasTypeUtil.createUniqueRequiredAttrDef("name", "string"));
    AtlasTypesDef typesDef = new AtlasTypesDef();
    typesDef.getEntityDefs().add(entityDef);
    AtlasTypesDef created = atlasClientV2.createAtlasTypeDefs(typesDef);
    assertNotNull(created);
    assertNotNull(created.getEntityDefs());
    assertEquals(created.getEntityDefs().size(), 1);
    // create entity for the type
    AtlasEntity instance = new AtlasEntity(entityDef.getName());
    instance.setAttribute("name", randomString());
    EntityMutationResponse mutationResponse = atlasClientV2.createEntity(new AtlasEntityWithExtInfo(instance));
    assertNotNull(mutationResponse);
    assertNotNull(mutationResponse.getEntitiesByOperation(EntityMutations.EntityOperation.CREATE));
    assertEquals(mutationResponse.getEntitiesByOperation(EntityMutations.EntityOperation.CREATE).size(), 1);
    String guid = mutationResponse.getEntitiesByOperation(EntityMutations.EntityOperation.CREATE).get(0).getGuid();
    // update type - add attribute
    entityDef = AtlasTypeUtil.createClassTypeDef(entityDef.getName(), ImmutableSet.<String>of(), AtlasTypeUtil.createUniqueRequiredAttrDef("name", "string"), AtlasTypeUtil.createOptionalAttrDef("description", "string"));
    typesDef = new AtlasTypesDef();
    typesDef.getEntityDefs().add(entityDef);
    AtlasTypesDef updated = atlasClientV2.updateAtlasTypeDefs(typesDef);
    assertNotNull(updated);
    assertNotNull(updated.getEntityDefs());
    assertEquals(updated.getEntityDefs().size(), 1);
    // Get definition after type update - new attributes should be null
    AtlasEntity entityByGuid = getEntityByGuid(guid);
    assertNull(entityByGuid.getAttribute("description"));
    assertEquals(entityByGuid.getAttribute("name"), instance.getAttribute("name"));
}
Also used : AtlasEntityDef(org.apache.atlas.model.typedef.AtlasEntityDef) AtlasEntityWithExtInfo(org.apache.atlas.model.instance.AtlasEntity.AtlasEntityWithExtInfo) AtlasEntity(org.apache.atlas.model.instance.AtlasEntity) EntityMutationResponse(org.apache.atlas.model.instance.EntityMutationResponse) AtlasTypesDef(org.apache.atlas.model.typedef.AtlasTypesDef) Test(org.testng.annotations.Test)

Aggregations

AtlasEntityDef (org.apache.atlas.model.typedef.AtlasEntityDef)141 AtlasTypesDef (org.apache.atlas.model.typedef.AtlasTypesDef)55 Test (org.testng.annotations.Test)51 AtlasAttributeDef (org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef)40 AtlasClassificationDef (org.apache.atlas.model.typedef.AtlasClassificationDef)37 AtlasStructDef (org.apache.atlas.model.typedef.AtlasStructDef)35 AtlasBaseException (org.apache.atlas.exception.AtlasBaseException)31 AtlasConstraintDef (org.apache.atlas.model.typedef.AtlasStructDef.AtlasConstraintDef)31 AtlasEnumDef (org.apache.atlas.model.typedef.AtlasEnumDef)30 ArrayList (java.util.ArrayList)29 HashMap (java.util.HashMap)21 AtlasVertex (org.apache.atlas.repository.graphdb.AtlasVertex)14 AtlasEnumElementDef (org.apache.atlas.model.typedef.AtlasEnumDef.AtlasEnumElementDef)13 AtlasTypeRegistry (org.apache.atlas.type.AtlasTypeRegistry)13 AtlasTransientTypeRegistry (org.apache.atlas.type.AtlasTypeRegistry.AtlasTransientTypeRegistry)13 AtlasEntity (org.apache.atlas.model.instance.AtlasEntity)12 AtlasErrorCode (org.apache.atlas.AtlasErrorCode)11 AtlasEntityType (org.apache.atlas.type.AtlasEntityType)9 AtlasEntityHeader (org.apache.atlas.model.instance.AtlasEntityHeader)8 EntityMutationResponse (org.apache.atlas.model.instance.EntityMutationResponse)8