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

The following examples show how to use org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef#setIsOptional() . 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: TestUtilsV2.java    From atlas with Apache License 2.0 5 votes vote down vote up
public static AtlasEntityDef createPrimitiveEntityDef() {

        AtlasEntityDef newtestEntityDef = new AtlasEntityDef("newtest");
        AtlasAttributeDef attrName = new AtlasAttributeDef("name", AtlasBaseTypeDef.ATLAS_TYPE_STRING);

        AtlasAttributeDef attrDescription = new AtlasAttributeDef("description", AtlasBaseTypeDef.ATLAS_TYPE_STRING);
        attrDescription.setIsOptional(false);

        AtlasAttributeDef attrcheck = new AtlasAttributeDef("check", AtlasBaseTypeDef.ATLAS_TYPE_STRING);
        attrcheck.setIsOptional(true);

        AtlasAttributeDef attrSourceCode = new AtlasAttributeDef("sourcecode", AtlasBaseTypeDef.ATLAS_TYPE_STRING);
        attrSourceCode.setDefaultValue("Hello World");
        attrSourceCode.setIsOptional(true);

        AtlasAttributeDef attrCost = new AtlasAttributeDef("Cost", AtlasBaseTypeDef.ATLAS_TYPE_INT);
        attrCost.setIsOptional(true);
        attrCost.setDefaultValue("30");

        AtlasAttributeDef attrDiskUsage = new AtlasAttributeDef("diskUsage", AtlasBaseTypeDef.ATLAS_TYPE_FLOAT);
        attrDiskUsage.setIsOptional(true);
        attrDiskUsage.setDefaultValue("70.50");

        AtlasAttributeDef attrisStoreUse = new AtlasAttributeDef("isstoreUse", AtlasBaseTypeDef.ATLAS_TYPE_BOOLEAN);
        attrisStoreUse.setIsOptional(true);
        attrisStoreUse.setDefaultValue("true");

        newtestEntityDef.addAttribute(attrName);
        newtestEntityDef.addAttribute(attrDescription);
        newtestEntityDef.addAttribute(attrcheck);
        newtestEntityDef.addAttribute(attrSourceCode);
        newtestEntityDef.addAttribute(attrCost);
        newtestEntityDef.addAttribute(attrDiskUsage);
        newtestEntityDef.addAttribute(attrisStoreUse);

        populateSystemAttributes(newtestEntityDef);

        return newtestEntityDef;
    }
 
Example 2
Source File: TestUtilsV2.java    From incubator-atlas with Apache License 2.0 5 votes vote down vote up
public static AtlasEntityDef createPrimitiveEntityDef() {

        AtlasEntityDef newtestEntityDef = new AtlasEntityDef("newtest");
        AtlasAttributeDef attrName = new AtlasAttributeDef("name", AtlasBaseTypeDef.ATLAS_TYPE_STRING);

        AtlasAttributeDef attrDescription = new AtlasAttributeDef("description", AtlasBaseTypeDef.ATLAS_TYPE_STRING);
        attrDescription.setIsOptional(false);

        AtlasAttributeDef attrcheck = new AtlasAttributeDef("check", AtlasBaseTypeDef.ATLAS_TYPE_STRING);
        attrcheck.setIsOptional(true);

        AtlasAttributeDef attrSourceCode = new AtlasAttributeDef("sourcecode", AtlasBaseTypeDef.ATLAS_TYPE_STRING);
        attrSourceCode.setDefaultValue("Hello World");
        attrSourceCode.setIsOptional(true);

        AtlasAttributeDef attrCost = new AtlasAttributeDef("Cost", AtlasBaseTypeDef.ATLAS_TYPE_INT);
        attrCost.setIsOptional(true);
        attrCost.setDefaultValue("30");

        AtlasAttributeDef attrDiskUsage = new AtlasAttributeDef("diskUsage", AtlasBaseTypeDef.ATLAS_TYPE_FLOAT);
        attrDiskUsage.setIsOptional(true);
        attrDiskUsage.setDefaultValue("70.50");

        AtlasAttributeDef attrisStoreUse = new AtlasAttributeDef("isstoreUse", AtlasBaseTypeDef.ATLAS_TYPE_BOOLEAN);
        attrisStoreUse.setIsOptional(true);
        attrisStoreUse.setDefaultValue("true");

        newtestEntityDef.addAttribute(attrName);
        newtestEntityDef.addAttribute(attrDescription);
        newtestEntityDef.addAttribute(attrcheck);
        newtestEntityDef.addAttribute(attrSourceCode);
        newtestEntityDef.addAttribute(attrCost);
        newtestEntityDef.addAttribute(attrDiskUsage);
        newtestEntityDef.addAttribute(attrisStoreUse);

        return newtestEntityDef;
    }
 
Example 3
Source File: TypeConverterUtil.java    From atlas with Apache License 2.0 4 votes vote down vote up
public static AtlasAttributeDef toAtlasAttributeDef(final AttributeDefinition attrDefinition) {
    AtlasAttributeDef ret = new AtlasAttributeDef(attrDefinition.getName(),
                                                  attrDefinition.getDataTypeName(),
                                                  attrDefinition.getSearchWeight(),
                                                  attrDefinition.getIndexType());

    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;
}
 
Example 4
Source File: AtlasStructDefStoreV2.java    From atlas with Apache License 2.0 4 votes vote down vote up
@VisibleForTesting
public static AtlasAttributeDef toAttributeDefFromJson(AtlasStructDef           structDef,
                                                       Map                      attribInfo,
                                                       AtlasTypeDefGraphStoreV2 typeDefStore)
    throws AtlasBaseException {
    AtlasAttributeDef ret = new AtlasAttributeDef();

    ret.setName((String) attribInfo.get("name"));
    ret.setTypeName((String) attribInfo.get("dataType"));
    ret.setIsUnique((Boolean) attribInfo.get("isUnique"));
    ret.setIsIndexable((Boolean) attribInfo.get("isIndexable"));
    ret.setIncludeInNotification((Boolean) attribInfo.get("includeInNotification"));
    ret.setDefaultValue((String) attribInfo.get("defaultValue"));
    ret.setDescription((String) attribInfo.get("description"));

    if(attribInfo.get("options") != null) {
        ret.setOptions(AtlasType.fromJson((String) attribInfo.get("options"), Map.class));
    }

    ret.setDisplayName((String) attribInfo.get("displayName"));

    if ((Boolean)attribInfo.get("isComposite")) {
        ret.addConstraint(new AtlasConstraintDef(AtlasConstraintDef.CONSTRAINT_TYPE_OWNED_REF));
    }

    final String reverseAttributeName = (String) attribInfo.get("reverseAttributeName");
    if (StringUtils.isNotBlank(reverseAttributeName)) {
        ret.addConstraint(new AtlasConstraintDef(AtlasConstraintDef.CONSTRAINT_TYPE_INVERSE_REF,
                new HashMap<String, Object>() {{
                    put(AtlasConstraintDef.CONSTRAINT_PARAM_ATTRIBUTE, reverseAttributeName);
                }}));
    }

    Map     multiplicity = AtlasType.fromJson((String) attribInfo.get("multiplicity"), Map.class);
    Number  minCount     = (Number) multiplicity.get("lower");
    Number  maxCount     = (Number) multiplicity.get("upper");
    Boolean isUnique     = (Boolean) multiplicity.get("isUnique");

    if (minCount == null || minCount.intValue() == 0) {
        ret.setIsOptional(true);
        ret.setValuesMinCount(0);
    } else {
        ret.setIsOptional(false);
        ret.setValuesMinCount(minCount.intValue());
    }

    if (maxCount == null || maxCount.intValue() < 2) {
        ret.setCardinality(AtlasAttributeDef.Cardinality.SINGLE);
        ret.setValuesMaxCount(1);
    } else {
        if (isUnique == null || isUnique == Boolean.FALSE) {
            ret.setCardinality(AtlasAttributeDef.Cardinality.LIST);
        } else {
            ret.setCardinality(AtlasAttributeDef.Cardinality.SET);
        }

        ret.setValuesMaxCount(maxCount.intValue());
    }

    Number searchWeight = (Number) attribInfo.get("searchWeight");
    if( searchWeight != null ) {
        ret.setSearchWeight(searchWeight.intValue());
    } else {
        ret.setSearchWeight(-1);
    }

    String indexType = (String) attribInfo.get("indexType");
    if(!StringUtils.isEmpty(indexType)) {
        ret.setIndexType(AtlasAttributeDef.IndexType.valueOf(indexType));
    }
    return ret;
}
 
Example 5
Source File: AtlasStructDefStoreV1.java    From incubator-atlas with Apache License 2.0 4 votes vote down vote up
@VisibleForTesting
public static AtlasAttributeDef toAttributeDefFromJson(AtlasStructDef           structDef,
                                                        Map                      attribInfo,
                                                        AtlasTypeDefGraphStoreV1 typeDefStore)
    throws AtlasBaseException {
    AtlasAttributeDef ret = new AtlasAttributeDef();

    ret.setName((String) attribInfo.get("name"));
    ret.setTypeName((String) attribInfo.get("dataType"));
    ret.setIsUnique((Boolean) attribInfo.get("isUnique"));
    ret.setIsIndexable((Boolean) attribInfo.get("isIndexable"));
    ret.setDefaultValue((String) attribInfo.get("defaultValue"));

    if ((Boolean)attribInfo.get("isComposite")) {
        ret.addConstraint(new AtlasConstraintDef(AtlasConstraintDef.CONSTRAINT_TYPE_OWNED_REF));
    }

    final String reverseAttributeName = (String) attribInfo.get("reverseAttributeName");
    if (StringUtils.isNotBlank(reverseAttributeName)) {
        ret.addConstraint(new AtlasConstraintDef(AtlasConstraintDef.CONSTRAINT_TYPE_INVERSE_REF,
                new HashMap<String, Object>() {{
                    put(AtlasConstraintDef.CONSTRAINT_PARAM_ATTRIBUTE, reverseAttributeName);
                }}));
    }

    Map     multiplicity = AtlasType.fromJson((String) attribInfo.get("multiplicity"), Map.class);
    Number  minCount     = (Number) multiplicity.get("lower");
    Number  maxCount     = (Number) multiplicity.get("upper");
    Boolean isUnique     = (Boolean) multiplicity.get("isUnique");

    if (minCount == null || minCount.intValue() == 0) {
        ret.setIsOptional(true);
        ret.setValuesMinCount(0);
    } else {
        ret.setIsOptional(false);
        ret.setValuesMinCount(minCount.intValue());
    }

    if (maxCount == null || maxCount.intValue() < 2) {
        ret.setCardinality(AtlasAttributeDef.Cardinality.SINGLE);
        ret.setValuesMaxCount(1);
    } else {
        if (isUnique == null || isUnique == Boolean.FALSE) {
            ret.setCardinality(AtlasAttributeDef.Cardinality.LIST);
        } else {
            ret.setCardinality(AtlasAttributeDef.Cardinality.SET);
        }

        ret.setValuesMaxCount(maxCount.intValue());
    }

    return ret;
}