Search in sources :

Example 36 with AtlasType

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

the class AtlasClassificationDefStoreV1 method updateByName.

@Override
public AtlasClassificationDef updateByName(String name, AtlasClassificationDef classificationDef) throws AtlasBaseException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> AtlasClassificationDefStoreV1.updateByName({}, {})", name, classificationDef);
    }
    validateType(classificationDef);
    AtlasType type = typeRegistry.getType(classificationDef.getName());
    if (type.getTypeCategory() != org.apache.atlas.model.TypeCategory.CLASSIFICATION) {
        throw new AtlasBaseException(AtlasErrorCode.TYPE_MATCH_FAILED, classificationDef.getName(), TypeCategory.TRAIT.name());
    }
    AtlasVertex vertex = typeDefStore.findTypeVertexByNameAndCategory(name, TypeCategory.TRAIT);
    if (vertex == null) {
        throw new AtlasBaseException(AtlasErrorCode.TYPE_NAME_NOT_FOUND, name);
    }
    updateVertexPreUpdate(classificationDef, (AtlasClassificationType) type, vertex);
    updateVertexAddReferences(classificationDef, vertex);
    AtlasClassificationDef ret = toClassificationDef(vertex);
    if (LOG.isDebugEnabled()) {
        LOG.debug("<== AtlasClassificationDefStoreV1.updateByName({}, {}): {}", name, classificationDef, ret);
    }
    return ret;
}
Also used : AtlasClassificationDef(org.apache.atlas.model.typedef.AtlasClassificationDef) AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasVertex(org.apache.atlas.repository.graphdb.AtlasVertex) AtlasType(org.apache.atlas.type.AtlasType)

Example 37 with AtlasType

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

the class AtlasClassificationDefStoreV1 method preCreate.

@Override
public AtlasVertex preCreate(AtlasClassificationDef classificationDef) throws AtlasBaseException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> AtlasClassificationDefStoreV1.preCreate({})", classificationDef);
    }
    validateType(classificationDef);
    AtlasType type = typeRegistry.getType(classificationDef.getName());
    if (type.getTypeCategory() != org.apache.atlas.model.TypeCategory.CLASSIFICATION) {
        throw new AtlasBaseException(AtlasErrorCode.TYPE_MATCH_FAILED, classificationDef.getName(), TypeCategory.TRAIT.name());
    }
    AtlasVertex ret = typeDefStore.findTypeVertexByName(classificationDef.getName());
    if (ret != null) {
        throw new AtlasBaseException(AtlasErrorCode.TYPE_ALREADY_EXISTS, classificationDef.getName());
    }
    ret = typeDefStore.createTypeVertex(classificationDef);
    updateVertexPreCreate(classificationDef, (AtlasClassificationType) type, ret);
    if (LOG.isDebugEnabled()) {
        LOG.debug("<== AtlasClassificationDefStoreV1.preCreate({}): {}", classificationDef, ret);
    }
    return ret;
}
Also used : AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasVertex(org.apache.atlas.repository.graphdb.AtlasVertex) AtlasType(org.apache.atlas.type.AtlasType)

Example 38 with AtlasType

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

the class AtlasEntityDefStoreV1 method preCreate.

@Override
public AtlasVertex preCreate(AtlasEntityDef entityDef) throws AtlasBaseException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> AtlasEntityDefStoreV1.preCreate({})", entityDef);
    }
    validateType(entityDef);
    AtlasType type = typeRegistry.getType(entityDef.getName());
    if (type.getTypeCategory() != org.apache.atlas.model.TypeCategory.ENTITY) {
        throw new AtlasBaseException(AtlasErrorCode.TYPE_MATCH_FAILED, entityDef.getName(), TypeCategory.CLASS.name());
    }
    AtlasVertex ret = typeDefStore.findTypeVertexByName(entityDef.getName());
    if (ret != null) {
        throw new AtlasBaseException(AtlasErrorCode.TYPE_ALREADY_EXISTS, entityDef.getName());
    }
    ret = typeDefStore.createTypeVertex(entityDef);
    updateVertexPreCreate(entityDef, (AtlasEntityType) type, ret);
    if (LOG.isDebugEnabled()) {
        LOG.debug("<== AtlasEntityDefStoreV1.preCreate({}): {}", entityDef, ret);
    }
    return ret;
}
Also used : AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasVertex(org.apache.atlas.repository.graphdb.AtlasVertex) AtlasType(org.apache.atlas.type.AtlasType)

Example 39 with AtlasType

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

the class AtlasEntityStoreV1Test method validateAttribute.

private void validateAttribute(AtlasEntityExtInfo entityExtInfo, Object actual, Object expected, AtlasType attributeType, String attrName) throws AtlasBaseException, AtlasException {
    switch(attributeType.getTypeCategory()) {
        case OBJECT_ID_TYPE:
            Assert.assertTrue(actual instanceof AtlasObjectId);
            String guid = ((AtlasObjectId) actual).getGuid();
            Assert.assertTrue(AtlasTypeUtil.isAssignedGuid(guid), "expected assigned guid. found " + guid);
            break;
        case PRIMITIVE:
        case ENUM:
            Assert.assertEquals(actual, expected);
            break;
        case MAP:
            AtlasMapType mapType = (AtlasMapType) attributeType;
            AtlasType valueType = mapType.getValueType();
            Map actualMap = (Map) actual;
            Map expectedMap = (Map) expected;
            if (MapUtils.isNotEmpty(expectedMap)) {
                Assert.assertTrue(MapUtils.isNotEmpty(actualMap));
                // deleted entries are included in the attribute; hence use >=
                Assert.assertTrue(actualMap.size() >= expectedMap.size());
                for (Object key : expectedMap.keySet()) {
                    validateAttribute(entityExtInfo, actualMap.get(key), expectedMap.get(key), valueType, attrName);
                }
            }
            break;
        case ARRAY:
            AtlasArrayType arrType = (AtlasArrayType) attributeType;
            AtlasType elemType = arrType.getElementType();
            List actualList = (List) actual;
            List expectedList = (List) expected;
            if (CollectionUtils.isNotEmpty(expectedList)) {
                Assert.assertTrue(CollectionUtils.isNotEmpty(actualList));
                // actual list could have deleted entities. Hence size may not match.
                Assert.assertTrue(actualList.size() >= expectedList.size());
                for (int i = 0; i < expectedList.size(); i++) {
                    validateAttribute(entityExtInfo, actualList.get(i), expectedList.get(i), elemType, attrName);
                }
            }
            break;
        case STRUCT:
            AtlasStruct expectedStruct = (AtlasStruct) expected;
            AtlasStruct actualStruct = (AtlasStruct) actual;
            validateEntity(entityExtInfo, actualStruct, expectedStruct);
            break;
        default:
            Assert.fail("Unknown type category");
    }
}
Also used : AtlasStruct(org.apache.atlas.model.instance.AtlasStruct) AtlasArrayType(org.apache.atlas.type.AtlasArrayType) AtlasType(org.apache.atlas.type.AtlasType) AtlasObjectId(org.apache.atlas.model.instance.AtlasObjectId) List(java.util.List) ArrayList(java.util.ArrayList) TestUtils.randomString(org.apache.atlas.TestUtils.randomString) Map(java.util.Map) HashMap(java.util.HashMap) AtlasMapType(org.apache.atlas.type.AtlasMapType)

Example 40 with AtlasType

use of org.apache.atlas.type.AtlasType 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

AtlasType (org.apache.atlas.type.AtlasType)95 AtlasBaseException (org.apache.atlas.exception.AtlasBaseException)51 AtlasVertex (org.apache.atlas.repository.graphdb.AtlasVertex)33 AtlasAttribute (org.apache.atlas.type.AtlasStructType.AtlasAttribute)23 AtlasArrayType (org.apache.atlas.type.AtlasArrayType)17 AtlasEntityType (org.apache.atlas.type.AtlasEntityType)17 AtlasStructType (org.apache.atlas.type.AtlasStructType)16 AtlasEdge (org.apache.atlas.repository.graphdb.AtlasEdge)15 AtlasMapType (org.apache.atlas.type.AtlasMapType)13 ArrayList (java.util.ArrayList)11 AtlasEntity (org.apache.atlas.model.instance.AtlasEntity)9 HashMap (java.util.HashMap)8 AtlasTypeAccessRequest (org.apache.atlas.authorize.AtlasTypeAccessRequest)8 AtlasObjectId (org.apache.atlas.model.instance.AtlasObjectId)8 AtlasStructDef (org.apache.atlas.model.typedef.AtlasStructDef)8 Map (java.util.Map)7 List (java.util.List)6 Collection (java.util.Collection)5 LinkedHashSet (java.util.LinkedHashSet)5 Set (java.util.Set)4