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

The following examples show how to use org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef#addConstraint() . 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: TestAtlasEntityType.java    From atlas with Apache License 2.0 6 votes vote down vote up
private AtlasEntityDef createTableEntityDefWithOptions() {
    AtlasEntityDef    table       = new AtlasEntityDef(TYPE_TABLE);
    AtlasAttributeDef attrName    = new AtlasAttributeDef(ATTR_NAME, AtlasBaseTypeDef.ATLAS_TYPE_STRING);
    AtlasAttributeDef attrColumns = new AtlasAttributeDef(ATTR_COLUMNS, AtlasBaseTypeDef.getArrayTypeName(TYPE_COLUMN));
    AtlasAttributeDef attrOwner   = new AtlasAttributeDef(ATTR_OWNER, AtlasBaseTypeDef.ATLAS_TYPE_STRING);

    attrColumns.addConstraint(new AtlasConstraintDef(AtlasConstraintDef.CONSTRAINT_TYPE_OWNED_REF));

    table.addAttribute(attrName);
    table.addAttribute(attrColumns);
    table.addAttribute(attrOwner);

    Map<String,String> options = new HashMap<>();
    String             key     = "dynAttribute:" + ATTR_OWNER;
    String             value   = "{" + ATTR_NAME + "}";

    options.put(key,value);

    table.setOptions(options);

    return table;
}
 
Example 2
Source File: TestAtlasEntityType.java    From atlas with Apache License 2.0 5 votes vote down vote up
private AtlasEntityDef createColumnEntityDefWithNonExistingInverseAttribute() {
    AtlasEntityDef    column    = new AtlasEntityDef(TYPE_COLUMN);
    AtlasAttributeDef attrTable = new AtlasAttributeDef(ATTR_TABLE, TYPE_TABLE);

    Map<String, Object> params = new HashMap<>();
    params.put(AtlasConstraintDef.CONSTRAINT_PARAM_ATTRIBUTE, "non-existing:" + ATTR_COLUMNS);

    attrTable.addConstraint(new AtlasConstraintDef(AtlasConstraintDef.CONSTRAINT_TYPE_INVERSE_REF, params));
    column.addAttribute(attrTable);

    return column;
}
 
Example 3
Source File: TestAtlasEntityType.java    From incubator-atlas with Apache License 2.0 5 votes vote down vote up
private AtlasEntityDef createColumnEntityDefWithMissingInverseAttribute() {
    AtlasEntityDef    column    = new AtlasEntityDef(TYPE_COLUMN);
    AtlasAttributeDef attrTable = new AtlasAttributeDef(ATTR_TABLE, TYPE_TABLE);

    attrTable.addConstraint(new AtlasConstraintDef(AtlasConstraintDef.CONSTRAINT_TYPE_INVERSE_REF));
    column.addAttribute(attrTable);

    return column;
}
 
Example 4
Source File: TestAtlasEntityType.java    From incubator-atlas with Apache License 2.0 5 votes vote down vote up
private AtlasEntityDef createTableEntityDef() {
    AtlasEntityDef    table       = new AtlasEntityDef(TYPE_TABLE);
    AtlasAttributeDef attrName    = new AtlasAttributeDef(ATTR_NAME, AtlasBaseTypeDef.ATLAS_TYPE_STRING);
    AtlasAttributeDef attrColumns = new AtlasAttributeDef(ATTR_COLUMNS,
                                                          AtlasBaseTypeDef.getArrayTypeName(TYPE_COLUMN));

    attrColumns.addConstraint(new AtlasConstraintDef(AtlasConstraintDef.CONSTRAINT_TYPE_OWNED_REF));

    table.addAttribute(attrName);
    table.addAttribute(attrColumns);

    return table;
}
 
Example 5
Source File: TestAtlasEntityType.java    From atlas with Apache License 2.0 5 votes vote down vote up
private AtlasEntityDef createColumnEntityDef() {
    AtlasEntityDef    column    = new AtlasEntityDef(TYPE_COLUMN);
    AtlasAttributeDef attrTable = new AtlasAttributeDef(ATTR_TABLE, TYPE_TABLE);

    Map<String, Object> params = new HashMap<>();
    params.put(AtlasConstraintDef.CONSTRAINT_PARAM_ATTRIBUTE, ATTR_COLUMNS);

    attrTable.addConstraint(new AtlasConstraintDef(AtlasConstraintDef.CONSTRAINT_TYPE_INVERSE_REF, params));
    column.addAttribute(attrTable);

    return column;
}
 
Example 6
Source File: TestAtlasEntityType.java    From incubator-atlas with Apache License 2.0 5 votes vote down vote up
private AtlasEntityDef createColumnEntityDefWithNonExistingInverseAttribute() {
    AtlasEntityDef    column    = new AtlasEntityDef(TYPE_COLUMN);
    AtlasAttributeDef attrTable = new AtlasAttributeDef(ATTR_TABLE, TYPE_TABLE);

    Map<String, Object> params = new HashMap<>();
    params.put(AtlasConstraintDef.CONSTRAINT_PARAM_ATTRIBUTE, "non-existing:" + ATTR_COLUMNS);

    attrTable.addConstraint(new AtlasConstraintDef(AtlasConstraintDef.CONSTRAINT_TYPE_INVERSE_REF, params));
    column.addAttribute(attrTable);

    return column;
}
 
Example 7
Source File: TestAtlasEntityType.java    From incubator-atlas with Apache License 2.0 5 votes vote down vote up
private AtlasEntityDef createColumnEntityDefWithInvalidInverseAttributeType() {
    AtlasEntityDef    column    = new AtlasEntityDef(TYPE_COLUMN);
    AtlasAttributeDef attrTable = new AtlasAttributeDef(ATTR_TABLE, TYPE_TABLE);

    Map<String, Object> params = new HashMap<>();
    params.put(AtlasConstraintDef.CONSTRAINT_PARAM_ATTRIBUTE, ATTR_NAME);

    attrTable.addConstraint(new AtlasConstraintDef(AtlasConstraintDef.CONSTRAINT_TYPE_INVERSE_REF, params));
    column.addAttribute(attrTable);

    return column;
}
 
Example 8
Source File: TestAtlasEntityType.java    From atlas with Apache License 2.0 5 votes vote down vote up
private AtlasEntityDef createColumnEntityDefWithInvaidAttributeTypeForInverseAttribute() {
    AtlasEntityDef    column    = new AtlasEntityDef(TYPE_COLUMN);
    AtlasAttributeDef attrTable = new AtlasAttributeDef(ATTR_NAME, AtlasBaseTypeDef.ATLAS_TYPE_STRING);

    Map<String, Object> params = new HashMap<>();
    params.put(AtlasConstraintDef.CONSTRAINT_PARAM_ATTRIBUTE, ATTR_NAME);

    attrTable.addConstraint(new AtlasConstraintDef(AtlasConstraintDef.CONSTRAINT_TYPE_INVERSE_REF, params));
    column.addAttribute(attrTable);

    return column;
}
 
Example 9
Source File: TestAtlasEntityType.java    From atlas with Apache License 2.0 5 votes vote down vote up
private AtlasEntityDef createColumnEntityDefWithMissingInverseAttribute() {
    AtlasEntityDef    column    = new AtlasEntityDef(TYPE_COLUMN);
    AtlasAttributeDef attrTable = new AtlasAttributeDef(ATTR_TABLE, TYPE_TABLE);

    attrTable.addConstraint(new AtlasConstraintDef(AtlasConstraintDef.CONSTRAINT_TYPE_INVERSE_REF));
    column.addAttribute(attrTable);

    return column;
}
 
Example 10
Source File: TestAtlasEntityType.java    From atlas with Apache License 2.0 5 votes vote down vote up
private AtlasEntityDef createTableEntityDef() {
    AtlasEntityDef    table       = new AtlasEntityDef(TYPE_TABLE);
    AtlasAttributeDef attrName    = new AtlasAttributeDef(ATTR_NAME, AtlasBaseTypeDef.ATLAS_TYPE_STRING);
    AtlasAttributeDef attrColumns = new AtlasAttributeDef(ATTR_COLUMNS,
                                                          AtlasBaseTypeDef.getArrayTypeName(TYPE_COLUMN));

    attrColumns.addConstraint(new AtlasConstraintDef(AtlasConstraintDef.CONSTRAINT_TYPE_OWNED_REF));

    table.addAttribute(attrName);
    table.addAttribute(attrColumns);

    return table;
}
 
Example 11
Source File: TestAtlasEntityType.java    From incubator-atlas with Apache License 2.0 5 votes vote down vote up
private AtlasEntityDef createColumnEntityDefWithInvaidAttributeTypeForInverseAttribute() {
    AtlasEntityDef    column    = new AtlasEntityDef(TYPE_COLUMN);
    AtlasAttributeDef attrTable = new AtlasAttributeDef(ATTR_NAME, AtlasBaseTypeDef.ATLAS_TYPE_STRING);

    Map<String, Object> params = new HashMap<>();
    params.put(AtlasConstraintDef.CONSTRAINT_PARAM_ATTRIBUTE, ATTR_NAME);

    attrTable.addConstraint(new AtlasConstraintDef(AtlasConstraintDef.CONSTRAINT_TYPE_INVERSE_REF, params));
    column.addAttribute(attrTable);

    return column;
}
 
Example 12
Source File: AtlasTypeUtil.java    From atlas with Apache License 2.0 4 votes vote down vote up
public static AtlasAttributeDef createOptionalAttrDefWithConstraint(String name, String typeName, String type, Map param) {
    AtlasAttributeDef ret = AtlasTypeUtil.createOptionalAttrDef(name, typeName);
    ret.addConstraint(new AtlasConstraintDef(type, param));

    return ret;
}
 
Example 13
Source File: AtlasTypeUtil.java    From atlas with Apache License 2.0 4 votes vote down vote up
public static AtlasAttributeDef createRequiredAttrDefWithConstraint(String name, String typeName, String type, Map param) {
    AtlasAttributeDef ret = AtlasTypeUtil.createRequiredAttrDef(name, typeName);
    ret.addConstraint(new AtlasConstraintDef(type, param));

    return ret;
}
 
Example 14
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;
}
 
Example 15
Source File: AtlasTypeUtil.java    From incubator-atlas with Apache License 2.0 4 votes vote down vote up
public static AtlasAttributeDef createRequiredListAttrDefWithConstraint(String name, String dataType, String type, Map param) {
    AtlasAttributeDef ret = AtlasTypeUtil.createListRequiredAttrDef(name, dataType);
    ret.addConstraint(new AtlasConstraintDef(type, param));

    return ret;
}
 
Example 16
Source File: AtlasTypeUtil.java    From incubator-atlas with Apache License 2.0 4 votes vote down vote up
public static AtlasAttributeDef createRequiredAttrDefWithConstraint(String name, String typeName, String type, Map param) {
    AtlasAttributeDef ret = AtlasTypeUtil.createRequiredAttrDef(name, typeName);
    ret.addConstraint(new AtlasConstraintDef(type, param));

    return ret;
}
 
Example 17
Source File: AtlasTypeUtil.java    From incubator-atlas with Apache License 2.0 4 votes vote down vote up
public static AtlasAttributeDef createOptionalAttrDefWithConstraint(String name, String typeName, String type, Map param) {
    AtlasAttributeDef ret = AtlasTypeUtil.createOptionalAttrDef(name, typeName);
    ret.addConstraint(new AtlasConstraintDef(type, param));

    return ret;
}
 
Example 18
Source File: AtlasTypeUtil.java    From atlas with Apache License 2.0 4 votes vote down vote up
public static AtlasAttributeDef createRequiredListAttrDefWithConstraint(String name, String dataType, String type, Map param) {
    AtlasAttributeDef ret = AtlasTypeUtil.createListRequiredAttrDef(name, dataType);
    ret.addConstraint(new AtlasConstraintDef(type, param));

    return ret;
}
 
Example 19
Source File: TestAtlasEntityType.java    From atlas with Apache License 2.0 3 votes vote down vote up
private AtlasEntityDef createTableEntityDefWithOwnedRefOnInvalidType() {
    AtlasEntityDef    table    = new AtlasEntityDef(TYPE_TABLE);
    AtlasAttributeDef attrName = new AtlasAttributeDef(ATTR_NAME, AtlasBaseTypeDef.ATLAS_TYPE_STRING);

    attrName.addConstraint(new AtlasConstraintDef(AtlasConstraintDef.CONSTRAINT_TYPE_OWNED_REF));

    table.addAttribute(attrName);

    return table;
}
 
Example 20
Source File: TestAtlasEntityType.java    From incubator-atlas with Apache License 2.0 3 votes vote down vote up
private AtlasEntityDef createTableEntityDefWithOwnedRefOnInvalidType() {
    AtlasEntityDef    table    = new AtlasEntityDef(TYPE_TABLE);
    AtlasAttributeDef attrName = new AtlasAttributeDef(ATTR_NAME, AtlasBaseTypeDef.ATLAS_TYPE_STRING);

    attrName.addConstraint(new AtlasConstraintDef(AtlasConstraintDef.CONSTRAINT_TYPE_OWNED_REF));

    table.addAttribute(attrName);

    return table;
}