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

The following examples show how to use org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef#getIsOptional() . 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: AtlasStructType.java    From atlas with Apache License 2.0 6 votes vote down vote up
public void populateDefaultValues(AtlasStruct obj) {
    if (obj != null) {
        Map<String, Object> attributes = obj.getAttributes();

        if (attributes == null) {
            attributes = new HashMap<>();
        }

        for (AtlasAttributeDef attributeDef : structDef.getAttributeDefs()) {
            if (!attributeDef.getIsOptional()) {
                attributes.put(attributeDef.getName(), createDefaultValue(attributeDef));
            }
        }

        obj.setAttributes(attributes);
    }
}
 
Example 2
Source File: AtlasStructType.java    From atlas with Apache License 2.0 6 votes vote down vote up
private boolean isAssignableValue(Object value, AtlasAttributeDef attributeDef) {
    boolean ret = true;

    if (value != null) {
        AtlasAttribute attribute = allAttributes.get(attributeDef.getName());

        if (attribute != null) {
            AtlasType attrType = attribute.getAttributeType();

                if (!attrType.isValidValue(value)) {
                    ret = false; // invalid value
                }
        }
    } else if (!attributeDef.getIsOptional()) {
        ret = false; // mandatory attribute not present
    }

    return ret;
}
 
Example 3
Source File: AtlasStructType.java    From atlas with Apache License 2.0 6 votes vote down vote up
private Object getNormalizedValue(Object value, AtlasAttributeDef attributeDef) {
    AtlasAttribute attribute = allAttributes.get(attributeDef.getName());

    if (attribute != null) {
        AtlasType attrType = attribute.getAttributeType();

        if (value == null) {
            if (!attributeDef.getIsOptional()) {
                return attrType.createDefaultValue();
            }
        } else {
            return attrType.getNormalizedValue(value);
        }
    }

    return null;
}
 
Example 4
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 5
Source File: AtlasStructType.java    From incubator-atlas with Apache License 2.0 6 votes vote down vote up
public void populateDefaultValues(AtlasStruct obj) {
    if (obj != null) {
        Map<String, Object> attributes = obj.getAttributes();

        if (attributes == null) {
            attributes = new HashMap<>();
        }

        for (AtlasAttributeDef attributeDef : structDef.getAttributeDefs()) {
            if (!attributeDef.getIsOptional()) {
                attributes.put(attributeDef.getName(), createDefaultValue(attributeDef));
            }
        }

        obj.setAttributes(attributes);
    }
}
 
Example 6
Source File: AtlasStructType.java    From incubator-atlas with Apache License 2.0 6 votes vote down vote up
private boolean isAssignableValue(Object value, AtlasAttributeDef attributeDef) {
    boolean ret = true;

    if (value != null) {
        AtlasAttribute attribute = allAttributes.get(attributeDef.getName());

        if (attribute != null) {
            AtlasType attrType = attribute.getAttributeType();

                if (!attrType.isValidValue(value)) {
                    ret = false; // invalid value
                }
        }
    } else if (!attributeDef.getIsOptional()) {
        ret = false; // mandatory attribute not present
    }

    return ret;
}
 
Example 7
Source File: AtlasStructType.java    From incubator-atlas with Apache License 2.0 6 votes vote down vote up
private Object getNormalizedValue(Object value, AtlasAttributeDef attributeDef) {
    AtlasAttribute attribute = allAttributes.get(attributeDef.getName());

    if (attribute != null) {
        AtlasType attrType = attribute.getAttributeType();

        if (value == null) {
            if (!attributeDef.getIsOptional()) {
                return attrType.createDefaultValue();
            }
        } else {
            return attrType.getNormalizedValue(value);
        }
    }

    return null;
}
 
Example 8
Source File: AtlasStructType.java    From atlas with Apache License 2.0 5 votes vote down vote up
public void normalizeAttributeValues(AtlasStruct obj) {
    if (obj != null) {
        for (AtlasAttributeDef attributeDef : structDef.getAttributeDefs()) {
            String attributeName = attributeDef.getName();

            if (obj.hasAttribute(attributeName)) {
                Object attributeValue = getNormalizedValue(obj.getAttribute(attributeName), attributeDef);

                obj.setAttribute(attributeName, attributeValue);
            } else if (!attributeDef.getIsOptional()) {
                obj.setAttribute(attributeName, createDefaultValue(attributeDef));
            }
        }
    }
}
 
Example 9
Source File: AtlasStructType.java    From atlas with Apache License 2.0 5 votes vote down vote up
public void normalizeAttributeValues(Map<String, Object> obj) {
    if (obj != null) {
        for (AtlasAttributeDef attributeDef : structDef.getAttributeDefs()) {
            String attributeName = attributeDef.getName();

            if (obj.containsKey(attributeName)) {
                Object attributeValue = getNormalizedValue(obj.get(attributeName), attributeDef);

                obj.put(attributeName, attributeValue);
            } else if (!attributeDef.getIsOptional()) {
                obj.put(attributeName, createDefaultValue(attributeDef));
            }
        }
    }
}
 
Example 10
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 11
Source File: AtlasStructType.java    From incubator-atlas with Apache License 2.0 5 votes vote down vote up
public void normalizeAttributeValues(AtlasStruct obj) {
    if (obj != null) {
        for (AtlasAttributeDef attributeDef : structDef.getAttributeDefs()) {
            String attributeName = attributeDef.getName();

            if (obj.hasAttribute(attributeName)) {
                Object attributeValue = getNormalizedValue(obj.getAttribute(attributeName), attributeDef);

                obj.setAttribute(attributeName, attributeValue);
            } else if (!attributeDef.getIsOptional()) {
                obj.setAttribute(attributeName, createDefaultValue(attributeDef));
            }
        }
    }
}
 
Example 12
Source File: AtlasStructType.java    From incubator-atlas with Apache License 2.0 5 votes vote down vote up
public void normalizeAttributeValues(Map<String, Object> obj) {
    if (obj != null) {
        for (AtlasAttributeDef attributeDef : structDef.getAttributeDefs()) {
            String attributeName = attributeDef.getName();

            if (obj.containsKey(attributeName)) {
                Object attributeValue = getNormalizedValue(obj.get(attributeName), attributeDef);

                obj.put(attributeName, attributeValue);
            } else if (!attributeDef.getIsOptional()) {
                obj.put(attributeName, createDefaultValue(attributeDef));
            }
        }
    }
}
 
Example 13
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);
}