Search in sources :

Example 51 with AtlasAttributeDef

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

the class RestUtilsTest method testV1toV2toV1Conversion.

private void testV1toV2toV1Conversion(List<HierarchicalTypeDefinition<ClassType>> typesToTest, boolean[] compositeExpected) throws AtlasBaseException {
    List<AtlasEntityDef> convertedEntityDefs = convertV1toV2(typesToTest);
    AtlasTypeRegistry registry = createRegistry(convertedEntityDefs);
    for (int i = 0; i < convertedEntityDefs.size(); i++) {
        AtlasEntityDef def = convertedEntityDefs.get(i);
        for (AtlasAttributeDef attrDef : def.getAttributeDefs()) {
            AtlasAttributeDef converted = convertToJsonAndBack(registry, def, attrDef, compositeExpected[i]);
            Assert.assertEquals(converted, attrDef);
        }
    }
    List<HierarchicalTypeDefinition<ClassType>> convertedBackTypeDefs = convertV2toV1(convertedEntityDefs);
    for (int i = 0; i < typesToTest.size(); i++) {
        HierarchicalTypeDefinition<ClassType> convertedBack = convertedBackTypeDefs.get(i);
        Assert.assertEquals(convertedBack, typesToTest.get(i));
        AttributeDefinition[] attributeDefinitions = convertedBack.attributeDefinitions;
        if (attributeDefinitions.length > 0) {
            Assert.assertEquals(attributeDefinitions[0].isComposite, compositeExpected[i]);
        }
    }
}
Also used : HierarchicalTypeDefinition(org.apache.atlas.typesystem.types.HierarchicalTypeDefinition) AtlasEntityDef(org.apache.atlas.model.typedef.AtlasEntityDef) AtlasAttributeDef(org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef) AtlasTypeRegistry(org.apache.atlas.type.AtlasTypeRegistry) AttributeDefinition(org.apache.atlas.typesystem.types.AttributeDefinition) ClassType(org.apache.atlas.typesystem.types.ClassType)

Example 52 with AtlasAttributeDef

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

the class AtlasTypeDefGraphStore method rectifyAttributesIfNeeded.

private void rectifyAttributesIfNeeded(final Set<String> entityNames, AtlasStructDef structDef) {
    List<AtlasAttributeDef> attributeDefs = structDef.getAttributeDefs();
    if (CollectionUtils.isNotEmpty(attributeDefs)) {
        for (AtlasAttributeDef attributeDef : attributeDefs) {
            if (!hasOwnedReferenceConstraint(attributeDef.getConstraints())) {
                continue;
            }
            Set<String> referencedTypeNames = AtlasTypeUtil.getReferencedTypeNames(attributeDef.getTypeName());
            boolean valid = false;
            for (String referencedTypeName : referencedTypeNames) {
                if (entityNames.contains(referencedTypeName)) {
                    valid = true;
                    break;
                }
            }
            if (!valid) {
                rectifyOwnedReferenceError(structDef, attributeDef);
            }
        }
    }
}
Also used : AtlasAttributeDef(org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef)

Aggregations

AtlasAttributeDef (org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef)52 AtlasConstraintDef (org.apache.atlas.model.typedef.AtlasStructDef.AtlasConstraintDef)19 AtlasEntityDef (org.apache.atlas.model.typedef.AtlasEntityDef)17 HashMap (java.util.HashMap)14 AtlasStructDef (org.apache.atlas.model.typedef.AtlasStructDef)13 AtlasBaseException (org.apache.atlas.exception.AtlasBaseException)12 ArrayList (java.util.ArrayList)11 Test (org.testng.annotations.Test)10 AtlasTypesDef (org.apache.atlas.model.typedef.AtlasTypesDef)9 AtlasClassificationDef (org.apache.atlas.model.typedef.AtlasClassificationDef)8 AtlasEnumDef (org.apache.atlas.model.typedef.AtlasEnumDef)7 AttributeDefinition (org.apache.atlas.typesystem.types.AttributeDefinition)5 AtlasEnumElementDef (org.apache.atlas.model.typedef.AtlasEnumDef.AtlasEnumElementDef)4 Map (java.util.Map)3 AtlasAttribute (org.apache.atlas.type.AtlasStructType.AtlasAttribute)3 AtlasTransientTypeRegistry (org.apache.atlas.type.AtlasTypeRegistry.AtlasTransientTypeRegistry)3 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 AtlasEntity (org.apache.atlas.model.instance.AtlasEntity)2 AtlasStruct (org.apache.atlas.model.instance.AtlasStruct)2 ClassType (org.apache.atlas.typesystem.types.ClassType)2