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 AtlasStructFormatConverter method fromV1ToV2.
protected Map<String, Object> fromV1ToV2(AtlasStructType structType, Map attributes, ConverterContext context) throws AtlasBaseException {
Map<String, Object> ret = null;
if (MapUtils.isNotEmpty(attributes)) {
ret = new HashMap<>();
// Only process the requested/set attributes
for (Object attribKey : attributes.keySet()) {
String attrName = attribKey.toString();
AtlasAttribute attr = structType.getAttribute(attrName);
if (attr == null) {
LOG.warn("ignored unknown attribute {}.{}", structType.getTypeName(), attrName);
continue;
}
AtlasType attrType = attr.getAttributeType();
AtlasFormatConverter attrConverter = converterRegistry.getConverter(attrType.getTypeCategory());
Object v1Value = attributes.get(attr.getName());
Object v2Value = attrConverter.fromV1ToV2(v1Value, attrType, context);
ret.put(attr.getAttributeDef().getName(), v2Value);
}
}
return ret;
}
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 EntityGraphRetriever method mapVertexToAtlasEntityHeader.
private AtlasEntityHeader mapVertexToAtlasEntityHeader(AtlasVertex entityVertex) throws AtlasBaseException {
AtlasEntityHeader ret = new AtlasEntityHeader();
String typeName = entityVertex.getProperty(Constants.TYPE_NAME_PROPERTY_KEY, String.class);
String guid = entityVertex.getProperty(Constants.GUID_PROPERTY_KEY, String.class);
ret.setTypeName(typeName);
ret.setGuid(guid);
ret.setStatus(GraphHelper.getStatus(entityVertex));
ret.setClassificationNames(GraphHelper.getTraitNames(entityVertex));
AtlasEntityType entityType = typeRegistry.getEntityTypeByName(typeName);
if (entityType != null) {
for (AtlasAttribute uniqueAttribute : entityType.getUniqAttributes().values()) {
Object attrValue = getVertexAttribute(entityVertex, uniqueAttribute);
if (attrValue != null) {
ret.setAttribute(uniqueAttribute.getName(), attrValue);
}
}
Object name = getVertexAttribute(entityVertex, entityType.getAttribute(AtlasClient.NAME));
Object description = getVertexAttribute(entityVertex, entityType.getAttribute(AtlasClient.DESCRIPTION));
Object owner = getVertexAttribute(entityVertex, entityType.getAttribute(AtlasClient.OWNER));
Object displayText = name != null ? name : ret.getAttribute(AtlasClient.QUALIFIED_NAME);
ret.setAttribute(AtlasClient.NAME, name);
ret.setAttribute(AtlasClient.DESCRIPTION, description);
ret.setAttribute(AtlasClient.OWNER, owner);
if (displayText != null) {
ret.setDisplayText(displayText.toString());
}
}
return ret;
}
Aggregations