Search in sources :

Example 1 with ResourceNotFoundException

use of org.apache.atlas.catalog.exception.ResourceNotFoundException in project incubator-atlas by apache.

the class DefaultTypeSystem method deleteEntity.

@Override
public void deleteEntity(ResourceDefinition definition, Request request) throws ResourceNotFoundException {
    String typeName = definition.getTypeName();
    String cleanIdPropName = definition.getIdPropertyName();
    String idValue = request.getProperty(cleanIdPropName);
    try {
        // transaction handled by atlas repository
        metadataService.deleteEntityByUniqueAttribute(typeName, cleanIdPropName, idValue);
    } catch (EntityNotFoundException e) {
        throw new ResourceNotFoundException(String.format("The specified entity doesn't exist: type=%s, %s=%s", typeName, cleanIdPropName, idValue));
    } catch (AtlasException e) {
        throw new CatalogRuntimeException(String.format("An unexpected error occurred while attempting to delete entity: type=%s, %s=%s : %s", typeName, cleanIdPropName, idValue, e), e);
    }
}
Also used : CatalogRuntimeException(org.apache.atlas.catalog.exception.CatalogRuntimeException) EntityNotFoundException(org.apache.atlas.typesystem.exception.EntityNotFoundException) ResourceNotFoundException(org.apache.atlas.catalog.exception.ResourceNotFoundException) AtlasException(org.apache.atlas.AtlasException)

Example 2 with ResourceNotFoundException

use of org.apache.atlas.catalog.exception.ResourceNotFoundException in project incubator-atlas by apache.

the class TaxonomyResourceProviderTest method testDeleteResourceById_404.

@Test(expectedExceptions = ResourceNotFoundException.class)
public void testDeleteResourceById_404() throws Exception {
    AtlasTypeSystem typeSystem = createStrictMock(AtlasTypeSystem.class);
    QueryFactory queryFactory = createStrictMock(QueryFactory.class);
    AtlasQuery query = createStrictMock(AtlasQuery.class);
    Capture<Request> getRequestCapture = newCapture();
    // mock expectations
    expect(queryFactory.createTaxonomyQuery(capture(getRequestCapture))).andReturn(query);
    expect(query.execute()).andThrow(new ResourceNotFoundException("test msg"));
    replay(typeSystem, queryFactory, query);
    TaxonomyResourceProvider provider = new TestTaxonomyResourceProvider(typeSystem, null);
    provider.setQueryFactory(queryFactory);
    Map<String, Object> requestProperties = new HashMap<>();
    requestProperties.put("name", "badName");
    Request userRequest = new InstanceRequest(requestProperties);
    // invoke method being tested
    provider.deleteResourceById(userRequest);
}
Also used : QueryFactory(org.apache.atlas.catalog.query.QueryFactory) AtlasQuery(org.apache.atlas.catalog.query.AtlasQuery) ResourceNotFoundException(org.apache.atlas.catalog.exception.ResourceNotFoundException) Test(org.testng.annotations.Test)

Aggregations

ResourceNotFoundException (org.apache.atlas.catalog.exception.ResourceNotFoundException)2 AtlasException (org.apache.atlas.AtlasException)1 CatalogRuntimeException (org.apache.atlas.catalog.exception.CatalogRuntimeException)1 AtlasQuery (org.apache.atlas.catalog.query.AtlasQuery)1 QueryFactory (org.apache.atlas.catalog.query.QueryFactory)1 EntityNotFoundException (org.apache.atlas.typesystem.exception.EntityNotFoundException)1 Test (org.testng.annotations.Test)1