Search in sources :

Example 1 with ClobDao

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

the class ClobController method getAll.

@OpenApi(queryParams = { @OpenApiParam(name = "office", required = false, description = "Specifies the owning office. If this field is not specified, matching information from all offices shall be returned."), @OpenApiParam(name = "page", required = false, description = "This end point can return a lot of data, this identifies where in the request you are. This is an opaque value, and can be obtained from the 'next-page' value in the response."), @OpenApiParam(name = "pageSize", required = false, type = Integer.class, description = "How many entries per page returned. Default " + defaultPageSize + "."), @OpenApiParam(name = "includeValues", required = false, type = Boolean.class, description = "Do you want the value associated with this particular clob (default: false)"), @OpenApiParam(name = "like", required = false, type = String.class, description = "Posix regular expression matching against the id") }, responses = { @OpenApiResponse(status = "200", description = "A list of clobs.", content = { @OpenApiContent(type = Formats.JSONV2, from = Clobs.class), @OpenApiContent(type = Formats.XMLV2, from = Clobs.class) }) }, tags = { "Clob" })
@Override
public void getAll(Context ctx) {
    getAllRequests.mark();
    try (final Timer.Context timeContext = getAllRequestsTime.time();
        DSLContext dsl = getDslContext(ctx)) {
        String office = ctx.queryParam("office");
        Optional<String> officeOpt = Optional.ofNullable(office);
        String formatParm = ctx.queryParamAsClass("format", String.class).getOrDefault("");
        String formatHeader = ctx.header(Header.ACCEPT);
        ContentType contentType = Formats.parseHeaderAndQueryParm(formatHeader, formatParm);
        String cursor = ctx.queryParamAsClass("cursor", String.class).allowNullable().get();
        cursor = cursor != null ? cursor : ctx.queryParamAsClass("page", String.class).getOrDefault("");
        if (!CwmsDTOPaginated.CURSOR_CHECK.invoke(cursor)) {
            ctx.json(new RadarError("cursor or page passed in but failed validation")).status(HttpCode.BAD_REQUEST);
            return;
        }
        int pageSize = ctx.queryParamAsClass("pageSize", Integer.class).getOrDefault(ctx.queryParamAsClass("pagesize", Integer.class).getOrDefault(defaultPageSize));
        boolean includeValues = ctx.queryParamAsClass("includeValues", Boolean.class).getOrDefault(false);
        String like = ctx.queryParamAsClass("like", String.class).getOrDefault(".*");
        ClobDao dao = new ClobDao(dsl);
        Clobs clobs = dao.getClobs(cursor, pageSize, officeOpt, includeValues, like);
        String result = Formats.format(contentType, clobs);
        ctx.result(result);
        ctx.contentType(contentType.toString());
        requestResultSize.update(result.length());
    }
}
Also used : ClobDao(cwms.radar.data.dao.ClobDao) ContentType(cwms.radar.formatters.ContentType) DSLContext(org.jooq.DSLContext) RadarError(cwms.radar.api.errors.RadarError) Timer(com.codahale.metrics.Timer) Clobs(cwms.radar.data.dto.Clobs) OpenApi(io.javalin.plugin.openapi.annotations.OpenApi)

Example 2 with ClobDao

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

the class ClobController method getOne.

@OpenApi(queryParams = { @OpenApiParam(name = "office", description = "Specifies the owning office.") }, responses = { @OpenApiResponse(status = "200", description = "Returns requested clob.", content = { @OpenApiContent(type = Formats.JSON, from = Clob.class) }) }, tags = { "Clob" })
@Override
public void getOne(Context ctx, String clobId) {
    getOneRequest.mark();
    try (final Timer.Context timeContext = getOneRequestTime.time();
        DSLContext dsl = getDslContext(ctx)) {
        ClobDao dao = new ClobDao(dsl);
        Optional<String> office = Optional.ofNullable(ctx.queryParam("office"));
        Optional<Clob> optAc = dao.getByUniqueName(clobId, office);
        if (optAc.isPresent()) {
            String formatHeader = ctx.header(Header.ACCEPT);
            ContentType contentType = Formats.parseHeaderAndQueryParm(formatHeader, "");
            String result = Formats.format(contentType, optAc.get());
            ctx.contentType(contentType.toString());
            ctx.result(result);
            requestResultSize.update(result.length());
        } else {
            ctx.status(HttpServletResponse.SC_NOT_FOUND).json(new RadarError("Unable to find clob based on given parameters"));
        }
    }
}
Also used : ClobDao(cwms.radar.data.dao.ClobDao) RadarError(cwms.radar.api.errors.RadarError) Timer(com.codahale.metrics.Timer) ContentType(cwms.radar.formatters.ContentType) DSLContext(org.jooq.DSLContext) Clob(cwms.radar.data.dto.Clob) OpenApi(io.javalin.plugin.openapi.annotations.OpenApi)

Aggregations

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