AtlasStructType extends AtlasType { @Override public boolean validateValue(Object obj, String objName, List<String> messages) { boolean ret = true; if (obj != null) { if (obj instanceof AtlasStruct) { AtlasStruct structObj = (AtlasStruct) obj; for (AtlasAttributeDef attributeDef : structDef.getAttributeDefs()) { String attrName = attributeDef.getName(); AtlasAttribute attribute = allAttributes.get(attributeDef.getName()); if (attribute != null) { AtlasType dataType = attribute.getAttributeType(); Object value = structObj.getAttribute(attrName); String fieldName = objName + "." + attrName; if (value != null) { ret = dataType.validateValue(value, fieldName, messages) && ret; } else if (!attributeDef.getIsOptional()) { ret = false; messages.add(fieldName + ": mandatory attribute value missing in type " + getTypeName()); } } } } else if (obj instanceof Map) { Map attributes = AtlasTypeUtil.toStructAttributes((Map)obj); for (AtlasAttributeDef attributeDef : structDef.getAttributeDefs()) { String attrName = attributeDef.getName(); AtlasAttribute attribute = allAttributes.get(attributeDef.getName()); if (attribute != null) { AtlasType dataType = attribute.getAttributeType(); Object value = attributes.get(attrName); String fieldName = objName + "." + attrName; if (value != null) { ret = dataType.validateValue(value, fieldName, messages) && ret; } else if (!attributeDef.getIsOptional()) { ret = false; messages.add(fieldName + ": mandatory attribute value missing in type " + getTypeName()); } } } } else { ret = false; messages.add(objName + "=" + obj + ": invalid value for type " + getTypeName()); } } return ret; } AtlasStructType(AtlasStructDef structDef);  AtlasStructType(AtlasStructDef structDef, AtlasTypeRegistry typeRegistry); AtlasStructDef getStructDef(); AtlasType getAttributeType(String attributeName); AtlasAttributeDef getAttributeDef(String attributeName); @Override void resolveReferences(AtlasTypeRegistry typeRegistry); @Override void resolveReferencesPhase2(AtlasTypeRegistry typeRegistry); @Override AtlasStruct createDefaultValue(); @Override Object createDefaultValue(Object defaultValue); Map<String, AtlasAttribute> getAllAttributes(); Map<String, AtlasAttribute> getUniqAttributes(); AtlasAttribute getAttribute(String attributeName); @Override boolean isValidValue(Object obj); @Override boolean isValidValueForUpdate(Object obj); @Override Object getNormalizedValue(Object obj); @Override Object getNormalizedValueForUpdate(Object obj); @Override boolean validateValue(Object obj, String objName, List<String> messages); @Override boolean validateValueForUpdate(Object obj, String objName, List<String> messages); void normalizeAttributeValues(AtlasStruct obj); void normalizeAttributeValuesForUpdate(AtlasStruct obj); void normalizeAttributeValues(Map<String, Object> obj); void normalizeAttributeValuesForUpdate(Map<String, Object> obj); void populateDefaultValues(AtlasStruct obj); String getQualifiedAttributeName(String attrName);  }
@Test public void testStructTypeValidateValue() { List<String> messages = new ArrayList<>(); for (Object value : validValues) { assertTrue(structType.validateValue(value, "testObj", messages)); assertEquals(messages.size(), 0, "value=" + value); } for (Object value : invalidValues) { assertFalse(structType.validateValue(value, "testObj", messages)); assertTrue(messages.size() > 0, "value=" + value); messages.clear(); } }