Search in sources :

Example 11 with AttributeDefinition

use of org.apache.atlas.v1.model.typedef.AttributeDefinition in project atlas by apache.

the class TypeConverterUtil method toAtlasStructDefs.

private static List<AtlasStructDef> toAtlasStructDefs(List<StructTypeDefinition> structTypeDefinitions) {
    List<AtlasStructDef> ret = new ArrayList<>();
    for (StructTypeDefinition structType : structTypeDefinitions) {
        List<AtlasAttributeDef> attrDefs = new ArrayList<AtlasAttributeDef>();
        if (CollectionUtils.isNotEmpty(structType.getAttributeDefinitions())) {
            for (AttributeDefinition attrDefinition : structType.getAttributeDefinitions()) {
                attrDefs.add(toAtlasAttributeDef(attrDefinition));
            }
        }
        AtlasStructDef structDef = new AtlasStructDef(structType.getTypeName(), structType.getTypeDescription(), structType.getTypeVersion(), attrDefs);
        ret.add(structDef);
    }
    return ret;
}
Also used : AtlasStructDef(org.apache.atlas.model.typedef.AtlasStructDef) AtlasAttributeDef(org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef) AttributeDefinition(org.apache.atlas.v1.model.typedef.AttributeDefinition) StructTypeDefinition(org.apache.atlas.v1.model.typedef.StructTypeDefinition)

Example 12 with AttributeDefinition

use of org.apache.atlas.v1.model.typedef.AttributeDefinition in project atlas by apache.

the class AtlasTypeUtil method toV1AttributeDefinition.

public static AttributeDefinition toV1AttributeDefinition(AtlasStructType.AtlasAttribute attribute) {
    AtlasAttributeDef attributeDef = attribute.getAttributeDef();
    AttributeDefinition ret = new AttributeDefinition();
    ret.setName(attributeDef.getName());
    ret.setDataTypeName(attributeDef.getTypeName());
    ret.setIsUnique(attributeDef.getIsUnique());
    ret.setIsIndexable(attributeDef.getIsIndexable());
    ret.setIsComposite(attribute.isOwnedRef());
    ret.setReverseAttributeName(attribute.getInverseRefAttributeName());
    ret.setDefaultValue(attributeDef.getDefaultValue());
    ret.setDescription(attributeDef.getDescription());
    final int lower;
    final int upper;
    if (attributeDef.getCardinality() == AtlasAttributeDef.Cardinality.SINGLE) {
        lower = attributeDef.getIsOptional() ? 0 : 1;
        upper = 1;
    } else {
        if (attributeDef.getIsOptional()) {
            lower = 0;
        } else {
            lower = attributeDef.getValuesMinCount() < 1 ? 1 : attributeDef.getValuesMinCount();
        }
        upper = attributeDef.getValuesMaxCount() < 2 ? Integer.MAX_VALUE : attributeDef.getValuesMaxCount();
    }
    Multiplicity multiplicity = new Multiplicity();
    multiplicity.setLower(lower);
    multiplicity.setUpper(upper);
    multiplicity.setIsUnique(AtlasAttributeDef.Cardinality.SET.equals(attributeDef.getCardinality()));
    ret.setMultiplicity(multiplicity);
    return ret;
}
Also used : Multiplicity(org.apache.atlas.v1.model.typedef.Multiplicity) AtlasAttributeDef(org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef) AttributeDefinition(org.apache.atlas.v1.model.typedef.AttributeDefinition)

Example 13 with AttributeDefinition

use of org.apache.atlas.v1.model.typedef.AttributeDefinition in project atlas by apache.

the class AtlasTypeUtil method toClassTypeDefinition.

public static ClassTypeDefinition toClassTypeDefinition(final AtlasEntityType entityType) {
    ClassTypeDefinition ret = null;
    if (entityType != null) {
        AtlasEntityDef entityDef = entityType.getEntityDef();
        ret = new ClassTypeDefinition();
        ret.setTypeName(entityDef.getName());
        ret.setTypeDescription(entityDef.getDescription());
        ret.setTypeVersion(entityDef.getTypeVersion());
        ret.setSuperTypes(entityDef.getSuperTypes());
        if (MapUtils.isNotEmpty(entityType.getAllAttributes())) {
            List<AttributeDefinition> attributeDefinitions = entityType.getAllAttributes().entrySet().stream().map(e -> toV1AttributeDefinition(e.getValue())).collect(Collectors.toList());
            ret.setAttributeDefinitions(attributeDefinitions);
        }
    }
    return ret;
}
Also used : AtlasAttributeDef(org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef) AtlasStruct(org.apache.atlas.model.instance.AtlasStruct) StringUtils(org.apache.commons.lang.StringUtils) java.util(java.util) Multiplicity(org.apache.atlas.v1.model.typedef.Multiplicity) AtlasEnumElementDef(org.apache.atlas.model.typedef.AtlasEnumDef.AtlasEnumElementDef) AtlasTypeDefHeader(org.apache.atlas.model.typedef.AtlasTypeDefHeader) AttributeDefinition(org.apache.atlas.v1.model.typedef.AttributeDefinition) Matcher(java.util.regex.Matcher) CollectionUtils(org.apache.commons.collections.CollectionUtils) AtlasObjectId(org.apache.atlas.model.instance.AtlasObjectId) AtlasTypesDef(org.apache.atlas.model.typedef.AtlasTypesDef) AtlasEntityHeader(org.apache.atlas.model.instance.AtlasEntityHeader) AtlasEntity(org.apache.atlas.model.instance.AtlasEntity) AtlasEntityDef(org.apache.atlas.model.typedef.AtlasEntityDef) AtlasStructDef(org.apache.atlas.model.typedef.AtlasStructDef) AtlasRelationshipDef(org.apache.atlas.model.typedef.AtlasRelationshipDef) PropagateTags(org.apache.atlas.model.typedef.AtlasRelationshipDef.PropagateTags) MapUtils(org.apache.commons.collections.MapUtils) Collectors(java.util.stream.Collectors) AtlasBaseTypeDef(org.apache.atlas.model.typedef.AtlasBaseTypeDef) AtlasRelationshipEndDef(org.apache.atlas.model.typedef.AtlasRelationshipEndDef) AtlasConstraintDef(org.apache.atlas.model.typedef.AtlasStructDef.AtlasConstraintDef) Cardinality(org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef.Cardinality) AtlasEnumDef(org.apache.atlas.model.typedef.AtlasEnumDef) ClassTypeDefinition(org.apache.atlas.v1.model.typedef.ClassTypeDefinition) AtlasClassification(org.apache.atlas.model.instance.AtlasClassification) Pattern(java.util.regex.Pattern) RelationshipCategory(org.apache.atlas.model.typedef.AtlasRelationshipDef.RelationshipCategory) AtlasClassificationDef(org.apache.atlas.model.typedef.AtlasClassificationDef) AtlasEntityDef(org.apache.atlas.model.typedef.AtlasEntityDef) AttributeDefinition(org.apache.atlas.v1.model.typedef.AttributeDefinition) ClassTypeDefinition(org.apache.atlas.v1.model.typedef.ClassTypeDefinition)

Aggregations

AttributeDefinition (org.apache.atlas.v1.model.typedef.AttributeDefinition)10 AtlasAttributeDef (org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef)8 AtlasTypesDef (org.apache.atlas.model.typedef.AtlasTypesDef)4 Multiplicity (org.apache.atlas.v1.model.typedef.Multiplicity)4 TypesDef (org.apache.atlas.v1.model.typedef.TypesDef)4 ClassTypeDefinition (org.apache.atlas.v1.model.typedef.ClassTypeDefinition)3 TraitTypeDefinition (org.apache.atlas.v1.model.typedef.TraitTypeDefinition)3 AtlasClassificationDef (org.apache.atlas.model.typedef.AtlasClassificationDef)2 AtlasEntityDef (org.apache.atlas.model.typedef.AtlasEntityDef)2 AtlasStructDef (org.apache.atlas.model.typedef.AtlasStructDef)2 AtlasConstraintDef (org.apache.atlas.model.typedef.AtlasStructDef.AtlasConstraintDef)2 StructTypeDefinition (org.apache.atlas.v1.model.typedef.StructTypeDefinition)2 java.util (java.util)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 Collectors (java.util.stream.Collectors)1 AtlasClassification (org.apache.atlas.model.instance.AtlasClassification)1 AtlasEntity (org.apache.atlas.model.instance.AtlasEntity)1 AtlasEntityHeader (org.apache.atlas.model.instance.AtlasEntityHeader)1 AtlasObjectId (org.apache.atlas.model.instance.AtlasObjectId)1