Search in sources :

Example 1 with ClobController

use of cwms.radar.api.ClobController in project cwms-radar-api by USACE.

the class ApiServlet method configureRoutes.

protected void configureRoutes() {
    RouteRole[] requiredRoles = { new Role(CWMS_USERS_ROLE) };
    get("/", ctx -> ctx.result("Welcome to the CWMS REST API").contentType(Formats.PLAIN));
    radarCrud("/location/category/{category-id}", new LocationCategoryController(metrics), requiredRoles);
    radarCrud("/location/group/{group-id}", new LocationGroupController(metrics), requiredRoles);
    radarCrud("/locations/{location_code}", new LocationController(metrics), requiredRoles);
    radarCrud("/offices/{office}", new OfficeController(metrics), requiredRoles);
    radarCrud("/units/{unit_name}", new UnitsController(metrics), requiredRoles);
    radarCrud("/parameters/{param_name}", new ParametersController(metrics), requiredRoles);
    radarCrud("/timezones/{zone}", new TimeZoneController(metrics), requiredRoles);
    radarCrud("/levels/{location}", new LevelsController(metrics), requiredRoles);
    TimeSeriesController tsController = new TimeSeriesController(metrics);
    get("/timeseries/recent/{group-id}", tsController::getRecent);
    radarCrud("/timeseries/category/{category-id}", new TimeSeriesCategoryController(metrics), requiredRoles);
    radarCrud("/timeseries/group/{group-id}", new TimeSeriesGroupController(metrics), requiredRoles);
    radarCrud("/timeseries/{timeseries}", tsController, requiredRoles);
    radarCrud("/ratings/{rating}", new RatingController(metrics), requiredRoles);
    radarCrud("/catalog/{dataSet}", new CatalogController(metrics), requiredRoles);
    radarCrud("/basins/{basin-id}", new BasinController(metrics), requiredRoles);
    radarCrud("/blobs/{blob-id}", new BlobController(metrics), requiredRoles);
    radarCrud("/clobs/{clob-id}", new ClobController(metrics), requiredRoles);
    radarCrud("/pools/{pool-id}", new PoolController(metrics), requiredRoles);
}
Also used : BlobController(cwms.radar.api.BlobController) LevelsController(cwms.radar.api.LevelsController) CatalogController(cwms.radar.api.CatalogController) PoolController(cwms.radar.api.PoolController) LocationController(cwms.radar.api.LocationController) TimeZoneController(cwms.radar.api.TimeZoneController) LocationGroupController(cwms.radar.api.LocationGroupController) TimeSeriesCategoryController(cwms.radar.api.TimeSeriesCategoryController) ClobController(cwms.radar.api.ClobController) RouteRole(io.javalin.core.security.RouteRole) RouteRole(io.javalin.core.security.RouteRole) Role(cwms.radar.security.Role) UnitsController(cwms.radar.api.UnitsController) OfficeController(cwms.radar.api.OfficeController) LocationCategoryController(cwms.radar.api.LocationCategoryController) UnitsController(cwms.radar.api.UnitsController) TimeSeriesGroupController(cwms.radar.api.TimeSeriesGroupController) RatingController(cwms.radar.api.RatingController) ParametersController(cwms.radar.api.ParametersController) BasinController(cwms.radar.api.BasinController) TimeSeriesController(cwms.radar.api.TimeSeriesController)

Example 2 with ClobController

use of cwms.radar.api.ClobController in project cwms-radar-api by USACE.

the class ClobControllerTest method bad_format_returns_501.

@Test
public void bad_format_returns_501() throws Exception {
    final String testBody = "";
    ClobController controller = spy(new ClobController(new MetricRegistry()));
    HttpServletRequest request = mock(HttpServletRequest.class);
    HttpServletResponse response = mock(HttpServletResponse.class);
    HashMap<String, Object> attributes = new HashMap<>();
    attributes.put(ContextUtil.maxRequestSizeKey, Integer.MAX_VALUE);
    attributes.put(JsonMapperKt.JSON_MAPPER_KEY, new JavalinJackson());
    when(request.getInputStream()).thenReturn(new TestServletInputStream(testBody));
    Context context = ContextUtil.init(request, response, "*", new HashMap<String, String>(), HandlerType.GET, attributes);
    context.attribute("database", getTestConnection());
    when(request.getAttribute("database")).thenReturn(getTestConnection());
    assertNotNull(context.attribute("database"), "could not get the connection back as an attribute");
    when(request.getHeader(Header.ACCEPT)).thenReturn("BAD FORMAT");
    assertThrows(FormattingException.class, () -> {
        controller.getAll(context);
    });
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) Context(io.javalin.http.Context) HashMap(java.util.HashMap) JavalinJackson(io.javalin.plugin.json.JavalinJackson) MetricRegistry(com.codahale.metrics.MetricRegistry) HttpServletResponse(javax.servlet.http.HttpServletResponse) ClobController(cwms.radar.api.ClobController) TestServletInputStream(fixtures.TestServletInputStream) Test(org.junit.jupiter.api.Test)

Aggregations

ClobController (cwms.radar.api.ClobController)2 MetricRegistry (com.codahale.metrics.MetricRegistry)1 BasinController (cwms.radar.api.BasinController)1 BlobController (cwms.radar.api.BlobController)1 CatalogController (cwms.radar.api.CatalogController)1 LevelsController (cwms.radar.api.LevelsController)1 LocationCategoryController (cwms.radar.api.LocationCategoryController)1 LocationController (cwms.radar.api.LocationController)1 LocationGroupController (cwms.radar.api.LocationGroupController)1 OfficeController (cwms.radar.api.OfficeController)1 ParametersController (cwms.radar.api.ParametersController)1 PoolController (cwms.radar.api.PoolController)1 RatingController (cwms.radar.api.RatingController)1 TimeSeriesCategoryController (cwms.radar.api.TimeSeriesCategoryController)1 TimeSeriesController (cwms.radar.api.TimeSeriesController)1 TimeSeriesGroupController (cwms.radar.api.TimeSeriesGroupController)1 TimeZoneController (cwms.radar.api.TimeZoneController)1 UnitsController (cwms.radar.api.UnitsController)1 Role (cwms.radar.security.Role)1 TestServletInputStream (fixtures.TestServletInputStream)1