Search in sources :

Example 1 with AtlasAttribute

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);
    }
}
Also used : AtlasStruct(org.apache.atlas.model.instance.AtlasStruct) AtlasAttribute(org.apache.atlas.type.AtlasStructType.AtlasAttribute) AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasType(org.apache.atlas.type.AtlasType) Map(java.util.Map)

Example 2 with AtlasAttribute

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);
}
Also used : AtlasAttribute(org.apache.atlas.type.AtlasStructType.AtlasAttribute) AtlasTypeDefGraphStoreV1(org.apache.atlas.repository.store.graph.v1.AtlasTypeDefGraphStoreV1) AtlasStructType(org.apache.atlas.type.AtlasStructType) Map(java.util.Map)

Example 3 with AtlasAttribute

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;
}
Also used : AtlasAttribute(org.apache.atlas.type.AtlasStructType.AtlasAttribute) AtlasType(org.apache.atlas.type.AtlasType)

Example 4 with AtlasAttribute

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()]);
}
Also used : AtlasAttribute(org.apache.atlas.type.AtlasStructType.AtlasAttribute) AtlasAttributeDef(org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef) ArrayList(java.util.ArrayList) AttributeDefinition(org.apache.atlas.typesystem.types.AttributeDefinition)

Example 5 with AtlasAttribute

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;
}
Also used : AtlasAttribute(org.apache.atlas.type.AtlasStructType.AtlasAttribute) AtlasEntityHeader(org.apache.atlas.model.instance.AtlasEntityHeader)

Aggregations

AtlasAttribute (org.apache.atlas.type.AtlasStructType.AtlasAttribute)21 AtlasBaseException (org.apache.atlas.exception.AtlasBaseException)6 AtlasType (org.apache.atlas.type.AtlasType)5 HashMap (java.util.HashMap)4 Map (java.util.Map)4 ArrayList (java.util.ArrayList)3 AtlasEntityHeader (org.apache.atlas.model.instance.AtlasEntityHeader)3 AtlasStruct (org.apache.atlas.model.instance.AtlasStruct)3 AtlasAttributeDef (org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef)3 AtlasEdge (org.apache.atlas.repository.graphdb.AtlasEdge)3 AtlasVertex (org.apache.atlas.repository.graphdb.AtlasVertex)3 AtlasEntityType (org.apache.atlas.type.AtlasEntityType)3 List (java.util.List)2 AtlasEntity (org.apache.atlas.model.instance.AtlasEntity)2 AtlasTypeDefGraphStoreV1 (org.apache.atlas.repository.store.graph.v1.AtlasTypeDefGraphStoreV1)2 AtlasStructType (org.apache.atlas.type.AtlasStructType)2 ImmutableList (com.google.common.collect.ImmutableList)1 ScriptEngine (javax.script.ScriptEngine)1 ScriptException (javax.script.ScriptException)1 AtlasException (org.apache.atlas.AtlasException)1