Java Code Examples for org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef#getValuesMaxCount()

The following examples show how to use org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef#getValuesMaxCount() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AtlasTypeUtil.java    From atlas with Apache License 2.0 6 votes vote down vote up
public static Multiplicity getMultiplicity(AtlasAttributeDef attributeDef) {
    int lower;
    int upper;
    if (attributeDef.getCardinality() == 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();
    }

    return new Multiplicity(lower, upper, Cardinality.SET.equals(attributeDef.getCardinality()));
}
 
Example 2
Source File: AtlasStructDefStoreV1.java    From incubator-atlas with Apache License 2.0 5 votes vote down vote up
@VisibleForTesting
public static String toJsonFromAttribute(AtlasAttribute attribute) {
    AtlasAttributeDef   attributeDef = attribute.getAttributeDef();
    Map<String, Object> attribInfo   = new HashMap<>();

    attribInfo.put("name", attributeDef.getName());
    attribInfo.put("dataType", attributeDef.getTypeName());
    attribInfo.put("isUnique", attributeDef.getIsUnique());
    attribInfo.put("isIndexable", attributeDef.getIsIndexable());
    attribInfo.put("isComposite", attribute.isOwnedRef());
    attribInfo.put("reverseAttributeName", attribute.getInverseRefAttributeName());
    attribInfo.put("defaultValue", attributeDef.getDefaultValue());

    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();
    }

    Map<String, Object> multiplicity = new HashMap<>();
    multiplicity.put("lower", lower);
    multiplicity.put("upper", upper);
    multiplicity.put("isUnique", AtlasAttributeDef.Cardinality.SET.equals(attributeDef.getCardinality()));

    attribInfo.put("multiplicity", AtlasType.toJson(multiplicity));

    return AtlasType.toJson(attribInfo);
}
 
Example 3
Source File: AtlasStructDefStoreV2.java    From atlas with Apache License 2.0 4 votes vote down vote up
@VisibleForTesting
public static String toJsonFromAttribute(AtlasAttribute attribute) {
    AtlasAttributeDef   attributeDef = attribute.getAttributeDef();
    Map<String, Object> attribInfo   = new HashMap<>();

    attribInfo.put("name", attributeDef.getName());
    attribInfo.put("dataType", attributeDef.getTypeName());
    attribInfo.put("isUnique", attributeDef.getIsUnique());
    attribInfo.put("isIndexable", attributeDef.getIsIndexable());
    attribInfo.put("includeInNotification", attributeDef.getIncludeInNotification());
    attribInfo.put("isComposite", attribute.isOwnedRef());
    attribInfo.put("reverseAttributeName", attribute.getInverseRefAttributeName());
    attribInfo.put("defaultValue", attributeDef.getDefaultValue());
    attribInfo.put("description", attributeDef.getDescription());
    attribInfo.put("searchWeight", attributeDef.getSearchWeight());
    attribInfo.put("indexType", attributeDef.getIndexType());

    if(attributeDef.getOptions() != null) {
        attribInfo.put("options", AtlasType.toJson(attributeDef.getOptions()));
    }

    attribInfo.put("displayName", attributeDef.getDisplayName());

    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();
    }

    Map<String, Object> multiplicity = new HashMap<>();
    multiplicity.put("lower", lower);
    multiplicity.put("upper", upper);
    multiplicity.put("isUnique", AtlasAttributeDef.Cardinality.SET.equals(attributeDef.getCardinality()));

    attribInfo.put("multiplicity", AtlasType.toJson(multiplicity));

    return AtlasType.toJson(attribInfo);
}