use of org.apache.atlas.type.AtlasStructType.AtlasAttribute in project incubator-atlas by apache.
the class TypeConverterUtil method getAttributes.
private static AttributeDefinition[] getAttributes(AtlasStructType structType, AtlasTypeRegistry registry) throws AtlasBaseException {
List<AttributeDefinition> ret = new ArrayList<>();
List<AtlasAttributeDef> attrDefs = structType.getStructDef().getAttributeDefs();
if (CollectionUtils.isNotEmpty(attrDefs)) {
for (AtlasAttributeDef attrDef : attrDefs) {
AtlasAttribute attribute = structType.getAttribute(attrDef.getName());
ret.add(AtlasStructDefStoreV1.toAttributeDefintion(attribute));
}
}
return ret.toArray(new AttributeDefinition[ret.size()]);
}
use of org.apache.atlas.type.AtlasStructType.AtlasAttribute in project incubator-atlas by apache.
the class AtlasEntityGraphDiscoveryV1 method visitStruct.
void visitStruct(AtlasStructType structType, Object val) throws AtlasBaseException {
if (structType == null || val == null) {
return;
}
AtlasStruct struct;
if (val instanceof AtlasStruct) {
struct = (AtlasStruct) val;
} else if (val instanceof Map) {
Map attributes = AtlasTypeUtil.toStructAttributes((Map) val);
struct = new AtlasStruct(structType.getTypeName(), attributes);
} else {
throw new AtlasBaseException(AtlasErrorCode.INVALID_STRUCT_VALUE, val.toString());
}
for (AtlasAttribute attribute : structType.getAllAttributes().values()) {
AtlasType attrType = attribute.getAttributeType();
Object attrVal = struct.getAttribute(attribute.getName());
visitAttribute(attrType, attrVal);
}
}
use of org.apache.atlas.type.AtlasStructType.AtlasAttribute in project incubator-atlas by apache.
the class RestUtilsTest method convertToJsonAndBack.
private AtlasAttributeDef convertToJsonAndBack(AtlasTypeRegistry registry, AtlasStructDef structDef, AtlasAttributeDef attributeDef, boolean compositeExpected) throws AtlasBaseException {
AtlasTypeDefGraphStoreV1 typeDefStore = makeTypeStore(registry);
AtlasStructType structType = (AtlasStructType) registry.getType(structDef.getName());
AtlasAttribute attribute = structType.getAttribute(attributeDef.getName());
String attribJson = AtlasStructDefStoreV1.toJsonFromAttribute(attribute);
Map attrInfo = AtlasType.fromJson(attribJson, Map.class);
Assert.assertEquals(attrInfo.get("isComposite"), compositeExpected);
return AtlasStructDefStoreV1.toAttributeDefFromJson(structDef, attrInfo, typeDefStore);
}
use of org.apache.atlas.type.AtlasStructType.AtlasAttribute in project incubator-atlas by apache.
the class AtlasStructType method validateValue.
@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;
}
use of org.apache.atlas.type.AtlasStructType.AtlasAttribute in project incubator-atlas by apache.
the class AtlasStructType method resolveReferencesPhase2.
@Override
public void resolveReferencesPhase2(AtlasTypeRegistry typeRegistry) throws AtlasBaseException {
super.resolveReferencesPhase2(typeRegistry);
for (AtlasAttribute attribute : allAttributes.values()) {
if (attribute.getInverseRefAttributeName() == null) {
continue;
}
// Set the inverse reference attribute.
AtlasType referencedType = typeRegistry.getType(attribute.getAttributeDef().getTypeName());
AtlasEntityType referencedEntityType = getReferencedEntityType(referencedType);
AtlasAttribute inverseReference = referencedEntityType.getAttribute(attribute.getInverseRefAttributeName());
attribute.setInverseRefAttribute(inverseReference);
}
}
Aggregations