Search in sources :

Example 46 with NotFoundException

use of org.eclipse.che.api.core.NotFoundException in project che by eclipse.

the class JpaSnapshotDao method doRemove.

@Transactional
protected void doRemove(String snapshotId) throws NotFoundException {
    final EntityManager manager = managerProvider.get();
    final SnapshotImpl snapshot = manager.find(SnapshotImpl.class, snapshotId);
    if (snapshot == null) {
        throw new NotFoundException(format("Snapshot with id '%s' doesn't exist", snapshotId));
    }
    manager.remove(snapshot);
}
Also used : EntityManager(javax.persistence.EntityManager) SnapshotImpl(org.eclipse.che.api.machine.server.model.impl.SnapshotImpl) NotFoundException(org.eclipse.che.api.core.NotFoundException) Transactional(com.google.inject.persist.Transactional)

Example 47 with NotFoundException

use of org.eclipse.che.api.core.NotFoundException in project che by eclipse.

the class JpaSnapshotDao method getSnapshot.

@Override
@Transactional
public SnapshotImpl getSnapshot(String workspaceId, String envName, String machineName) throws NotFoundException, SnapshotException {
    requireNonNull(workspaceId, "Required non-null workspace id");
    requireNonNull(envName, "Required non-null environment name");
    requireNonNull(machineName, "Required non-null machine name");
    try {
        return managerProvider.get().createNamedQuery("Snapshot.getByMachine", SnapshotImpl.class).setParameter("workspaceId", workspaceId).setParameter("envName", envName).setParameter("machineName", machineName).getSingleResult();
    } catch (NoResultException x) {
        throw new NotFoundException(format("Snapshot for machine '%s:%s:%s' doesn't exist", workspaceId, envName, machineName));
    } catch (RuntimeException x) {
        throw new SnapshotException(x.getLocalizedMessage(), x);
    }
}
Also used : NotFoundException(org.eclipse.che.api.core.NotFoundException) NoResultException(javax.persistence.NoResultException) SnapshotException(org.eclipse.che.api.machine.server.exception.SnapshotException) Transactional(com.google.inject.persist.Transactional)

Example 48 with NotFoundException

use of org.eclipse.che.api.core.NotFoundException in project che by eclipse.

the class FactoryServiceTest method shouldThrowNotFoundExceptionWhenFactoryIsNotExist.

@Test
public void shouldThrowNotFoundExceptionWhenFactoryIsNotExist() throws Exception {
    final String errMessage = format("Factory with id %s is not found", FACTORY_ID);
    doThrow(new NotFoundException(errMessage)).when(factoryManager).getById(anyString());
    final Response response = given().expect().statusCode(404).when().get(SERVICE_PATH + "/" + FACTORY_ID);
    assertEquals(getFromResponse(response, ServiceError.class).getMessage(), errMessage);
}
Also used : Response(com.jayway.restassured.response.Response) NotFoundException(org.eclipse.che.api.core.NotFoundException) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.testng.annotations.Test)

Example 49 with NotFoundException

use of org.eclipse.che.api.core.NotFoundException in project che by eclipse.

the class FactoryServiceTest method shouldThrowNotFoundExceptionWhenFactoryImageWithGivenIdentifierIsNotExist.

@Test
public void shouldThrowNotFoundExceptionWhenFactoryImageWithGivenIdentifierIsNotExist() throws Exception {
    final String errMessage = "Image with name " + IMAGE_NAME + " is not found";
    when(factoryManager.getFactoryImages(FACTORY_ID, IMAGE_NAME)).thenThrow(new NotFoundException(errMessage));
    final Response response = given().expect().statusCode(404).when().get(SERVICE_PATH + "/" + FACTORY_ID + "/image?imgId=" + IMAGE_NAME);
    assertEquals(getFromResponse(response, ServiceError.class).getMessage(), errMessage);
}
Also used : Response(com.jayway.restassured.response.Response) NotFoundException(org.eclipse.che.api.core.NotFoundException) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.testng.annotations.Test)

Example 50 with NotFoundException

use of org.eclipse.che.api.core.NotFoundException in project che by eclipse.

the class FactoryServiceTest method shouldResponse404OnGetSnippetIfFactoryDoesNotExist.

@Test
public void shouldResponse404OnGetSnippetIfFactoryDoesNotExist() throws Exception {
    // given
    doThrow(new NotFoundException("Factory URL with id " + FACTORY_ID + " is not found.")).when(factoryManager).getFactorySnippet(anyString(), anyString(), any());
    // when, then
    final Response response = given().expect().statusCode(404).when().get(SERVICE_PATH + "/" + FACTORY_ID + "/snippet?type=url");
    assertEquals(getFromResponse(response, ServiceError.class).getMessage(), "Factory URL with id " + FACTORY_ID + " is not found.");
}
Also used : Response(com.jayway.restassured.response.Response) NotFoundException(org.eclipse.che.api.core.NotFoundException) Test(org.testng.annotations.Test)

Aggregations

NotFoundException (org.eclipse.che.api.core.NotFoundException)72 ServerException (org.eclipse.che.api.core.ServerException)29 ConflictException (org.eclipse.che.api.core.ConflictException)19 Transactional (com.google.inject.persist.Transactional)16 IOException (java.io.IOException)13 EntityManager (javax.persistence.EntityManager)13 Path (javax.ws.rs.Path)13 Test (org.testng.annotations.Test)12 ForbiddenException (org.eclipse.che.api.core.ForbiddenException)11 Produces (javax.ws.rs.Produces)10 ApiOperation (io.swagger.annotations.ApiOperation)9 ApiResponses (io.swagger.annotations.ApiResponses)9 ArrayList (java.util.ArrayList)9 BadRequestException (org.eclipse.che.api.core.BadRequestException)9 Instance (org.eclipse.che.api.machine.server.spi.Instance)9 GET (javax.ws.rs.GET)7 WorkspaceImpl (org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl)7 SourceNotFoundException (org.eclipse.che.api.machine.server.exception.SourceNotFoundException)6 MachineImpl (org.eclipse.che.api.machine.server.model.impl.MachineImpl)6 SnapshotImpl (org.eclipse.che.api.machine.server.model.impl.SnapshotImpl)6