Search in sources :

Example 1 with LocationCategoryDao

use of cwms.radar.data.dao.LocationCategoryDao in project cwms-radar-api by USACE.

the class LocationCategoryController method getOne.

@OpenApi(pathParams = { @OpenApiParam(name = "category-id", required = true, description = "Specifies the Category whose data is to be included in the response.") }, queryParams = { @OpenApiParam(name = "office", required = true, description = "Specifies the owning office of the Location Category whose data is to be included in the response.") }, responses = { @OpenApiResponse(status = "200", content = { @OpenApiContent(from = LocationCategory.class, type = Formats.JSON) }) }, description = "Retrieves requested Location Category", tags = { TAG })
@Override
public void getOne(Context ctx, String categoryId) {
    getOneRequest.mark();
    try (final Timer.Context timeContext = getOneRequestTime.time();
        DSLContext dsl = getDslContext(ctx)) {
        LocationCategoryDao dao = new LocationCategoryDao(dsl);
        String office = ctx.queryParam("office");
        Optional<LocationCategory> grp = dao.getLocationCategory(office, categoryId);
        if (grp.isPresent()) {
            String formatHeader = ctx.header(Header.ACCEPT);
            ContentType contentType = Formats.parseHeaderAndQueryParm(formatHeader, null);
            String result = Formats.format(contentType, grp.get());
            ctx.result(result).contentType(contentType.toString());
            requestResultSize.update(result.length());
            ctx.status(HttpServletResponse.SC_OK);
        } else {
            final RadarError re = new RadarError("Cannot requested location category id");
            logger.info(() -> {
                StringBuilder builder = new StringBuilder(re.toString()).append("with url:").append(ctx.fullUrl());
                return builder.toString();
            });
            ctx.json(re).status(HttpServletResponse.SC_NOT_FOUND);
        }
    }
}
Also used : RadarError(cwms.radar.api.errors.RadarError) Timer(com.codahale.metrics.Timer) ContentType(cwms.radar.formatters.ContentType) LocationCategory(cwms.radar.data.dto.LocationCategory) DSLContext(org.jooq.DSLContext) LocationCategoryDao(cwms.radar.data.dao.LocationCategoryDao) OpenApi(io.javalin.plugin.openapi.annotations.OpenApi)

Example 2 with LocationCategoryDao

use of cwms.radar.data.dao.LocationCategoryDao in project cwms-radar-api by USACE.

the class LocationCategoryController method getAll.

@OpenApi(queryParams = { @OpenApiParam(name = "office", description = "Specifies the owning office of the location category(ies) whose data is to be included in the response. If this field is not specified, matching location category information from all offices shall be returned.") }, responses = { @OpenApiResponse(status = "200", content = { @OpenApiContent(isArray = true, from = LocationCategory.class, type = Formats.JSON) }) }, description = "Returns CWMS Location Category Data", tags = { TAG })
@Override
public void getAll(Context ctx) {
    getAllRequests.mark();
    try (final Timer.Context timeContext = getAllRequestsTime.time();
        DSLContext dsl = getDslContext(ctx)) {
        LocationCategoryDao dao = new LocationCategoryDao(dsl);
        String office = ctx.queryParam("office");
        List<LocationCategory> cats = dao.getLocationCategories(office);
        if (!cats.isEmpty()) {
            String formatHeader = ctx.header(Header.ACCEPT);
            ContentType contentType = Formats.parseHeaderAndQueryParm(formatHeader, null);
            String result = Formats.format(contentType, cats, LocationCategory.class);
            ctx.result(result).contentType(contentType.toString());
            requestResultSize.update(result.length());
            ctx.status(HttpServletResponse.SC_OK);
        } else {
            final RadarError re = new RadarError("Cannot requested location category for office provided");
            logger.info(() -> {
                StringBuilder builder = new StringBuilder(re.toString()).append("with url:").append(ctx.fullUrl());
                return builder.toString();
            });
            ctx.json(re).status(HttpServletResponse.SC_NOT_FOUND);
        }
    }
}
Also used : RadarError(cwms.radar.api.errors.RadarError) Timer(com.codahale.metrics.Timer) ContentType(cwms.radar.formatters.ContentType) LocationCategory(cwms.radar.data.dto.LocationCategory) DSLContext(org.jooq.DSLContext) LocationCategoryDao(cwms.radar.data.dao.LocationCategoryDao) OpenApi(io.javalin.plugin.openapi.annotations.OpenApi)

Aggregations

Timer (com.codahale.metrics.Timer)2 RadarError (cwms.radar.api.errors.RadarError)2 LocationCategoryDao (cwms.radar.data.dao.LocationCategoryDao)2 LocationCategory (cwms.radar.data.dto.LocationCategory)2 ContentType (cwms.radar.formatters.ContentType)2 OpenApi (io.javalin.plugin.openapi.annotations.OpenApi)2 DSLContext (org.jooq.DSLContext)2