Search in sources :

Example 21 with AtlasStruct

use of org.apache.atlas.model.instance.AtlasStruct in project incubator-atlas by apache.

the class AtlasStructType method validateValueForUpdate.

@Override
public boolean validateValueForUpdate(Object obj, String objName, List<String> messages) {
    boolean ret = true;
    Map<String, Object> attributes = null;
    if (obj != null) {
        if (obj instanceof AtlasStruct) {
            AtlasStruct structObj = (AtlasStruct) obj;
            attributes = structObj.getAttributes();
        } else if (obj instanceof Map) {
            attributes = AtlasTypeUtil.toStructAttributes((Map) obj);
        } else {
            ret = false;
            messages.add(objName + "=" + obj + ": invalid value for type " + getTypeName());
        }
        if (MapUtils.isNotEmpty(attributes)) {
            for (Map.Entry<String, Object> e : attributes.entrySet()) {
                String attrName = e.getKey();
                Object attrValue = e.getValue();
                AtlasAttribute attribute = allAttributes.get(attrName);
                if (attrValue == null) {
                    continue;
                }
                if (attribute != null) {
                    AtlasType dataType = attribute.getAttributeType();
                    String fieldName = objName + "." + attrName;
                    ret = dataType.validateValueForUpdate(attrValue, fieldName, messages) && ret;
                }
            }
        }
    }
    return ret;
}
Also used : AtlasStruct(org.apache.atlas.model.instance.AtlasStruct) AtlasAttribute(org.apache.atlas.type.AtlasStructType.AtlasAttribute) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

AtlasStruct (org.apache.atlas.model.instance.AtlasStruct)21 Map (java.util.Map)9 AtlasEntity (org.apache.atlas.model.instance.AtlasEntity)9 HashMap (java.util.HashMap)8 AtlasObjectId (org.apache.atlas.model.instance.AtlasObjectId)6 Test (org.testng.annotations.Test)5 AtlasEntitiesWithExtInfo (org.apache.atlas.model.instance.AtlasEntity.AtlasEntitiesWithExtInfo)4 EntityMutationResponse (org.apache.atlas.model.instance.EntityMutationResponse)4 BeforeTest (org.testng.annotations.BeforeTest)4 ArrayList (java.util.ArrayList)3 Date (java.util.Date)3 List (java.util.List)3 AtlasBaseException (org.apache.atlas.exception.AtlasBaseException)3 AtlasEntityHeader (org.apache.atlas.model.instance.AtlasEntityHeader)3 AtlasStructType (org.apache.atlas.type.AtlasStructType)3 AtlasAttribute (org.apache.atlas.type.AtlasStructType.AtlasAttribute)3 IStruct (org.apache.atlas.typesystem.IStruct)3 TestUtils.randomString (org.apache.atlas.TestUtils.randomString)2 AtlasEntityWithExtInfo (org.apache.atlas.model.instance.AtlasEntity.AtlasEntityWithExtInfo)2 AtlasAttributeDef (org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef)2