Search in sources :

Example 6 with AtlasStructType

use of org.apache.atlas.type.AtlasStructType in project atlas by apache.

the class AtlasEntityStoreV1Test method validateEntity.

private void validateEntity(AtlasEntityExtInfo entityExtInfo, AtlasStruct actual, AtlasStruct expected) throws AtlasBaseException, AtlasException {
    if (expected == null) {
        Assert.assertNull(actual, "expected null instance. Found " + actual);
        return;
    }
    Assert.assertNotNull(actual, "found null instance");
    AtlasStructType entityType = (AtlasStructType) typeRegistry.getType(actual.getTypeName());
    for (String attrName : expected.getAttributes().keySet()) {
        Object expectedVal = expected.getAttribute(attrName);
        Object actualVal = actual.getAttribute(attrName);
        AtlasType attrType = entityType.getAttributeType(attrName);
        validateAttribute(entityExtInfo, actualVal, expectedVal, attrType, attrName);
    }
}
Also used : AtlasStructType(org.apache.atlas.type.AtlasStructType) AtlasType(org.apache.atlas.type.AtlasType) TestUtilsV2.randomString(org.apache.atlas.TestUtilsV2.randomString)

Example 7 with AtlasStructType

use of org.apache.atlas.type.AtlasStructType in project 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)

Example 8 with AtlasStructType

use of org.apache.atlas.type.AtlasStructType in project atlas by apache.

the class ModelTestUtil method newStruct.

public static AtlasStruct newStruct(AtlasStructDef structDef, AtlasTypeRegistry typesRegistry) {
    AtlasStruct ret = null;
    AtlasStructType structType = typesRegistry.getStructTypeByName(structDef.getName());
    if (structType != null) {
        ret = structType.createDefaultValue();
    } else {
        LOG.error("failed to get struct-type {}", structDef.getName());
    }
    return ret;
}
Also used : AtlasStruct(org.apache.atlas.model.instance.AtlasStruct) AtlasStructType(org.apache.atlas.type.AtlasStructType)

Example 9 with AtlasStructType

use of org.apache.atlas.type.AtlasStructType in project incubator-atlas by apache.

the class EntityGraphMapper method mapAttributes.

private void mapAttributes(AtlasStruct struct, AtlasVertex vertex, EntityOperation op, EntityMutationContext context) throws AtlasBaseException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> mapAttributes({}, {})", op, struct.getTypeName());
    }
    if (MapUtils.isNotEmpty(struct.getAttributes())) {
        AtlasStructType structType = getStructType(struct.getTypeName());
        if (op.equals(CREATE)) {
            for (AtlasAttribute attribute : structType.getAllAttributes().values()) {
                Object attrValue = struct.getAttribute(attribute.getName());
                mapAttribute(attribute, attrValue, vertex, op, context);
            }
        } else if (op.equals(UPDATE)) {
            for (String attrName : struct.getAttributes().keySet()) {
                AtlasAttribute attribute = structType.getAttribute(attrName);
                if (attribute != null) {
                    Object attrValue = struct.getAttribute(attrName);
                    mapAttribute(attribute, attrValue, vertex, op, context);
                } else {
                    LOG.warn("mapAttributes(): invalid attribute {}.{}. Ignored..", struct.getTypeName(), attrName);
                }
            }
        }
        updateModificationMetadata(vertex);
    }
    if (LOG.isDebugEnabled()) {
        LOG.debug("<== mapAttributes({}, {})", op, struct.getTypeName());
    }
}
Also used : AtlasAttribute(org.apache.atlas.type.AtlasStructType.AtlasAttribute) AtlasStructType(org.apache.atlas.type.AtlasStructType)

Example 10 with AtlasStructType

use of org.apache.atlas.type.AtlasStructType in project incubator-atlas by apache.

the class AtlasEntityStoreV1Test method validateEntity.

private void validateEntity(AtlasEntityExtInfo entityExtInfo, AtlasStruct actual, AtlasStruct expected) throws AtlasBaseException, AtlasException {
    if (expected == null) {
        Assert.assertNull(actual, "expected null instance. Found " + actual);
        return;
    }
    Assert.assertNotNull(actual, "found null instance");
    AtlasStructType entityType = (AtlasStructType) typeRegistry.getType(actual.getTypeName());
    for (String attrName : expected.getAttributes().keySet()) {
        Object expectedVal = expected.getAttribute(attrName);
        Object actualVal = actual.getAttribute(attrName);
        AtlasType attrType = entityType.getAttributeType(attrName);
        validateAttribute(entityExtInfo, actualVal, expectedVal, attrType, attrName);
    }
}
Also used : AtlasStructType(org.apache.atlas.type.AtlasStructType) AtlasType(org.apache.atlas.type.AtlasType) TestUtils.randomString(org.apache.atlas.TestUtils.randomString)

Aggregations

AtlasStructType (org.apache.atlas.type.AtlasStructType)27 AtlasType (org.apache.atlas.type.AtlasType)12 AtlasEdge (org.apache.atlas.repository.graphdb.AtlasEdge)10 AtlasEntityType (org.apache.atlas.type.AtlasEntityType)8 AtlasVertex (org.apache.atlas.repository.graphdb.AtlasVertex)7 AtlasAttribute (org.apache.atlas.type.AtlasStructType.AtlasAttribute)7 AtlasBaseException (org.apache.atlas.exception.AtlasBaseException)6 AtlasArrayType (org.apache.atlas.type.AtlasArrayType)5 AtlasStruct (org.apache.atlas.model.instance.AtlasStruct)4 AtlasMapType (org.apache.atlas.type.AtlasMapType)4 Map (java.util.Map)3 RequestContextV1 (org.apache.atlas.RequestContextV1)3 AtlasObjectId (org.apache.atlas.model.instance.AtlasObjectId)3 HashMap (java.util.HashMap)2 TypeCategory (org.apache.atlas.model.TypeCategory)2 AtlasEntity (org.apache.atlas.model.instance.AtlasEntity)2 AtlasAttributeDef (org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef)2 AtlasEdgeLabel (org.apache.atlas.repository.graph.AtlasEdgeLabel)2 AtlasTypeDefGraphStoreV1 (org.apache.atlas.repository.store.graph.v1.AtlasTypeDefGraphStoreV1)2 AtlasClassificationType (org.apache.atlas.type.AtlasClassificationType)2