Search in sources :

Example 41 with AtlasEntityType

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

the class RestUtilsTest method makeTypeStore.

private AtlasTypeDefGraphStoreV1 makeTypeStore(AtlasTypeRegistry reg) {
    AtlasTypeDefGraphStoreV1 result = mock(AtlasTypeDefGraphStoreV1.class);
    for (AtlasEntityType type : reg.getAllEntityTypes()) {
        String typeName = type.getTypeName();
        AtlasVertex typeVertex = mock(AtlasVertex.class);
        when(result.isTypeVertex(eq(typeVertex), any(TypeCategory.class))).thenReturn(true);
        when(typeVertex.getProperty(eq(Constants.TYPE_CATEGORY_PROPERTY_KEY), eq(TypeCategory.class))).thenReturn(TypeCategory.CLASS);
        String attributeListPropertyKey = AtlasGraphUtilsV1.getTypeDefPropertyKey(typeName);
        when(typeVertex.getProperty(eq(attributeListPropertyKey), eq(List.class))).thenReturn(new ArrayList<>(type.getAllAttributes().keySet()));
        for (AtlasAttribute attribute : type.getAllAttributes().values()) {
            String attributeDefPropertyKey = AtlasGraphUtilsV1.getTypeDefPropertyKey(typeName, attribute.getName());
            String attributeJson = AtlasStructDefStoreV1.toJsonFromAttribute(attribute);
            when(typeVertex.getProperty(eq(attributeDefPropertyKey), eq(String.class))).thenReturn(attributeJson);
        }
        when(result.findTypeVertexByName(eq(typeName))).thenReturn(typeVertex);
    }
    return result;
}
Also used : AtlasAttribute(org.apache.atlas.type.AtlasStructType.AtlasAttribute) AtlasTypeDefGraphStoreV1(org.apache.atlas.repository.store.graph.v1.AtlasTypeDefGraphStoreV1) AtlasVertex(org.apache.atlas.repository.graphdb.AtlasVertex) TypeCategory(org.apache.atlas.typesystem.types.DataTypes.TypeCategory) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) AtlasEntityType(org.apache.atlas.type.AtlasEntityType)

Example 42 with AtlasEntityType

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

the class AtlasTypeDefGraphStore method searchTypesDef.

@Override
public AtlasTypesDef searchTypesDef(SearchFilter searchFilter) throws AtlasBaseException {
    final AtlasTypesDef typesDef = new AtlasTypesDef();
    Predicate searchPredicates = FilterUtil.getPredicateFromSearchFilter(searchFilter);
    for (AtlasEnumType enumType : typeRegistry.getAllEnumTypes()) {
        if (searchPredicates.evaluate(enumType)) {
            typesDef.getEnumDefs().add(enumType.getEnumDef());
        }
    }
    for (AtlasStructType structType : typeRegistry.getAllStructTypes()) {
        if (searchPredicates.evaluate(structType)) {
            typesDef.getStructDefs().add(structType.getStructDef());
        }
    }
    for (AtlasClassificationType classificationType : typeRegistry.getAllClassificationTypes()) {
        if (searchPredicates.evaluate(classificationType)) {
            typesDef.getClassificationDefs().add(classificationType.getClassificationDef());
        }
    }
    for (AtlasEntityType entityType : typeRegistry.getAllEntityTypes()) {
        if (searchPredicates.evaluate(entityType)) {
            typesDef.getEntityDefs().add(entityType.getEntityDef());
        }
    }
    return typesDef;
}
Also used : AtlasEnumType(org.apache.atlas.type.AtlasEnumType) AtlasStructType(org.apache.atlas.type.AtlasStructType) AtlasClassificationType(org.apache.atlas.type.AtlasClassificationType) AtlasEntityType(org.apache.atlas.type.AtlasEntityType) AtlasTypesDef(org.apache.atlas.model.typedef.AtlasTypesDef) Predicate(org.apache.commons.collections.Predicate)

Example 43 with AtlasEntityType

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

the class AtlasEntityGraphDiscoveryV1 method walkEntityGraph.

void walkEntityGraph(AtlasEntity entity) throws AtlasBaseException {
    if (entity == null) {
        return;
    }
    AtlasEntityType type = typeRegistry.getEntityTypeByName(entity.getTypeName());
    recordObjectReference(entity.getGuid());
    visitStruct(type, entity);
}
Also used : AtlasEntityType(org.apache.atlas.type.AtlasEntityType)

Example 44 with AtlasEntityType

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

the class AtlasEntityGraphDiscoveryV1 method validateAndNormalize.

@Override
public void validateAndNormalize(AtlasEntity entity) throws AtlasBaseException {
    List<String> messages = new ArrayList<>();
    if (!AtlasTypeUtil.isValidGuid(entity.getGuid())) {
        throw new AtlasBaseException(AtlasErrorCode.INVALID_OBJECT_ID, "invalid guid " + entity.getGuid());
    }
    AtlasEntityType type = typeRegistry.getEntityTypeByName(entity.getTypeName());
    if (type == null) {
        throw new AtlasBaseException(AtlasErrorCode.TYPE_NAME_INVALID, TypeCategory.ENTITY.name(), entity.getTypeName());
    }
    type.validateValue(entity, entity.getTypeName(), messages);
    if (!messages.isEmpty()) {
        throw new AtlasBaseException(AtlasErrorCode.INSTANCE_CRUD_INVALID_PARAMS, messages);
    }
    type.getNormalizedValue(entity);
}
Also used : AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) ArrayList(java.util.ArrayList) AtlasEntityType(org.apache.atlas.type.AtlasEntityType)

Example 45 with AtlasEntityType

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

the class EntityREST method partialUpdateEntityByUniqueAttrs.

/*******
     * Entity Partial Update - Allows a subset of attributes to be updated on
     * an entity which is identified by its type and unique attribute  eg: Referenceable.qualifiedName.
     * Null updates are not possible
     *******/
@PUT
@Consumes(Servlets.JSON_MEDIA_TYPE)
@Produces(Servlets.JSON_MEDIA_TYPE)
@Path("/uniqueAttribute/type/{typeName}")
public EntityMutationResponse partialUpdateEntityByUniqueAttrs(@PathParam("typeName") String typeName, @Context HttpServletRequest servletRequest, AtlasEntityWithExtInfo entityInfo) throws Exception {
    AtlasPerfTracer perf = null;
    try {
        Map<String, Object> uniqueAttributes = getAttributes(servletRequest);
        if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
            perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "EntityREST.partialUpdateEntityByUniqueAttrs(" + typeName + "," + uniqueAttributes + ")");
        }
        AtlasEntityType entityType = ensureEntityType(typeName);
        validateUniqueAttribute(entityType, uniqueAttributes);
        return entitiesStore.updateByUniqueAttributes(entityType, uniqueAttributes, entityInfo);
    } finally {
        AtlasPerfTracer.log(perf);
    }
}
Also used : AtlasPerfTracer(org.apache.atlas.utils.AtlasPerfTracer) AtlasEntityType(org.apache.atlas.type.AtlasEntityType) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) PUT(javax.ws.rs.PUT)

Aggregations

AtlasEntityType (org.apache.atlas.type.AtlasEntityType)45 AtlasEntity (org.apache.atlas.model.instance.AtlasEntity)18 AtlasBaseException (org.apache.atlas.exception.AtlasBaseException)16 AtlasVertex (org.apache.atlas.repository.graphdb.AtlasVertex)12 AtlasObjectId (org.apache.atlas.model.instance.AtlasObjectId)10 Test (org.testng.annotations.Test)10 ArrayList (java.util.ArrayList)8 AtlasEntityHeader (org.apache.atlas.model.instance.AtlasEntityHeader)8 EntityMutationResponse (org.apache.atlas.model.instance.EntityMutationResponse)7 AtlasEntitiesWithExtInfo (org.apache.atlas.model.instance.AtlasEntity.AtlasEntitiesWithExtInfo)6 AtlasEntityWithExtInfo (org.apache.atlas.model.instance.AtlasEntity.AtlasEntityWithExtInfo)6 AtlasAttribute (org.apache.atlas.type.AtlasStructType.AtlasAttribute)6 AtlasType (org.apache.atlas.type.AtlasType)6 AtlasEntityDef (org.apache.atlas.model.typedef.AtlasEntityDef)5 AtlasStructType (org.apache.atlas.type.AtlasStructType)5 HashMap (java.util.HashMap)4 IReferenceableInstance (org.apache.atlas.typesystem.IReferenceableInstance)4 List (java.util.List)3 Map (java.util.Map)3 Consumes (javax.ws.rs.Consumes)3