Search in sources :

Example 1 with Multiplicity

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

the class AtlasStructDefStoreV1 method getMultiplicity.

public static Multiplicity getMultiplicity(AtlasAttributeDef attributeDef) {
    final int lower;
    final int upper;
    final boolean isUnique = AtlasAttributeDef.Cardinality.SET.equals(attributeDef.getCardinality());
    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 ret = new Multiplicity(lower, upper, isUnique);
    return ret;
}
Also used : Multiplicity(org.apache.atlas.v1.model.typedef.Multiplicity)

Example 2 with Multiplicity

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

the class TypeConverterUtil method toAtlasAttributeDef.

public static AtlasAttributeDef toAtlasAttributeDef(final AttributeDefinition attrDefinition) {
    AtlasAttributeDef ret = new AtlasAttributeDef(attrDefinition.getName(), attrDefinition.getDataTypeName());
    ret.setIsIndexable(attrDefinition.getIsIndexable());
    ret.setIsUnique(attrDefinition.getIsUnique());
    if (attrDefinition.getIsComposite()) {
        ret.addConstraint(new AtlasConstraintDef(CONSTRAINT_TYPE_OWNED_REF));
    }
    if (StringUtils.isNotBlank(attrDefinition.getReverseAttributeName())) {
        ret.addConstraint(new AtlasConstraintDef(CONSTRAINT_TYPE_INVERSE_REF, new HashMap<String, Object>() {

            {
                put(CONSTRAINT_PARAM_ATTRIBUTE, attrDefinition.getReverseAttributeName());
            }
        }));
    }
    // Multiplicity attribute mapping
    Multiplicity multiplicity = attrDefinition.getMultiplicity();
    int minCount = multiplicity.getLower();
    int maxCount = multiplicity.getUpper();
    boolean isUnique = multiplicity.getIsUnique();
    if (minCount == 0) {
        ret.setIsOptional(true);
        ret.setValuesMinCount(0);
    } else {
        ret.setIsOptional(false);
        ret.setValuesMinCount(minCount);
    }
    if (maxCount < 2) {
        ret.setCardinality(Cardinality.SINGLE);
        ret.setValuesMaxCount(1);
    } else {
        if (!isUnique) {
            ret.setCardinality(Cardinality.LIST);
        } else {
            ret.setCardinality(Cardinality.SET);
        }
        ret.setValuesMaxCount(maxCount);
    }
    return ret;
}
Also used : Multiplicity(org.apache.atlas.v1.model.typedef.Multiplicity) AtlasAttributeDef(org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef) AtlasConstraintDef(org.apache.atlas.model.typedef.AtlasStructDef.AtlasConstraintDef)

Example 3 with Multiplicity

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

the class TypeConverterUtil method getAttributes.

private static List<AttributeDefinition> getAttributes(AtlasStructType structType, AtlasTypeRegistry registry) {
    List<AttributeDefinition> ret = new ArrayList<>();
    List<AtlasAttributeDef> attrDefs = structType.getStructDef().getAttributeDefs();
    if (CollectionUtils.isNotEmpty(attrDefs)) {
        for (AtlasAttributeDef attrDef : attrDefs) {
            AtlasAttribute attribute = structType.getAttribute(attrDef.getName());
            AttributeDefinition oldAttrDef = AtlasStructDefStoreV1.toAttributeDefinition(attribute);
            ret.add(new AttributeDefinition(oldAttrDef.getName(), oldAttrDef.getDataTypeName(), new Multiplicity(oldAttrDef.getMultiplicity()), oldAttrDef.getIsComposite(), oldAttrDef.getIsUnique(), oldAttrDef.getIsIndexable(), oldAttrDef.getReverseAttributeName()));
        }
    }
    return ret;
}
Also used : AtlasAttribute(org.apache.atlas.type.AtlasStructType.AtlasAttribute) 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 4 with Multiplicity

use of org.apache.atlas.v1.model.typedef.Multiplicity 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)

Aggregations

Multiplicity (org.apache.atlas.v1.model.typedef.Multiplicity)4 AtlasAttributeDef (org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef)3 AttributeDefinition (org.apache.atlas.v1.model.typedef.AttributeDefinition)2 AtlasConstraintDef (org.apache.atlas.model.typedef.AtlasStructDef.AtlasConstraintDef)1 AtlasAttribute (org.apache.atlas.type.AtlasStructType.AtlasAttribute)1