Search in sources :

Example 11 with Office

use of cwms.radar.data.dto.Office in project cwms-radar-api by USACE.

the class OfficeController method getAll.

@OpenApi(queryParams = @OpenApiParam(name = "format", required = false, deprecated = true, description = "(Deprecated in favor of Accept header) Specifies the encoding format of the response. Valid value for the format field for this URI are:\r\n1. tab\r\n2. csv\r\n 3. xml\r\n4. json (default)"), responses = { @OpenApiResponse(status = "200", description = "A list of offices.", content = { @OpenApiContent(from = OfficeFormatV1.class, type = ""), @OpenApiContent(from = Office.class, isArray = true, type = Formats.JSONV2), @OpenApiContent(from = OfficeFormatV1.class, type = Formats.JSON), @OpenApiContent(from = TabV1Office.class, type = Formats.TAB), @OpenApiContent(from = CsvV1Office.class, type = Formats.CSV), @OpenApiContent(from = CsvV1Office.class, type = Formats.XML) }) }, tags = { "Offices" })
@Override
public void getAll(Context ctx) {
    getAllRequests.mark();
    try (final Timer.Context timeContext = getAllRequestsTime.time();
        DSLContext dsl = getDslContext(ctx)) {
        OfficeDao dao = new OfficeDao(dsl);
        List<Office> offices = dao.getOffices();
        String formatParm = ctx.queryParamAsClass("format", String.class).getOrDefault("");
        String formatHeader = ctx.header(Header.ACCEPT);
        ContentType contentType = Formats.parseHeaderAndQueryParm(formatHeader, formatParm);
        String result = Formats.format(contentType, offices, Office.class);
        ctx.result(result).contentType(contentType.toString());
        requestResultSize.update(result.length());
    }
}
Also used : CsvV1Office(cwms.radar.formatters.csv.CsvV1Office) Office(cwms.radar.data.dto.Office) TabV1Office(cwms.radar.formatters.tab.TabV1Office) Timer(com.codahale.metrics.Timer) ContentType(cwms.radar.formatters.ContentType) OfficeDao(cwms.radar.data.dao.OfficeDao) DSLContext(org.jooq.DSLContext) OpenApi(io.javalin.plugin.openapi.annotations.OpenApi)

Example 12 with Office

use of cwms.radar.data.dto.Office in project cwms-radar-api by USACE.

the class CatalogController method getOne.

@OpenApi(queryParams = { @OpenApiParam(name = "page", description = "This end point can return a lot of data, this identifies where in the request you are."), @OpenApiParam(name = "pageSize", type = Integer.class, description = "How many entires per page returned. Default 500."), @OpenApiParam(name = "unitSystem", type = UnitSystem.class, description = UnitSystem.DESCRIPTION), @OpenApiParam(name = "office", description = "3-4 letter office name representing the district you want to isolate data to."), @OpenApiParam(name = "like", description = "Posix regular expression matching against the id"), @OpenApiParam(name = "timeseriesCategoryLike", description = "Posix regular expression matching against the timeseries category id"), @OpenApiParam(name = "timeseriesGroupLike", description = "Posix regular expression matching against the timeseries group id"), @OpenApiParam(name = "locationCategoryLike", description = "Posix regular expression matching against the location category id"), @OpenApiParam(name = "locationGroupLike", description = "Posix regular expression matching against the location group id") }, pathParams = { @OpenApiParam(name = "dataSet", required = false, type = CatalogableEndpoint.class, description = "A list of what data? E.g. Timeseries, Locations, Ratings, etc") }, responses = { @OpenApiResponse(status = "200", description = "A list of elements the data set you've selected.", content = { @OpenApiContent(from = Catalog.class, type = Formats.JSONV2), @OpenApiContent(from = Catalog.class, type = Formats.XML) }) }, tags = { TAG })
@Override
public void getOne(Context ctx, String dataSet) {
    getOneRequest.mark();
    try (final Timer.Context timeContext = getOneRequestTime.time();
        DSLContext dsl = JooqDao.getDslContext(ctx)) {
        String valDataSet = ((PolicyFactory) ctx.appAttribute("PolicyFactory")).sanitize(dataSet);
        String cursor = ctx.queryParamAsClass("cursor", String.class).getOrDefault(ctx.queryParamAsClass("page", String.class).getOrDefault(""));
        int pageSize = ctx.queryParamAsClass("pageSize", Integer.class).getOrDefault(ctx.queryParamAsClass("pagesize", Integer.class).getOrDefault(defaultPageSize));
        String unitSystem = ctx.queryParamAsClass("unitSystem", String.class).getOrDefault(UnitSystem.SI.getValue());
        Optional<String> office = Optional.ofNullable(ctx.queryParamAsClass("office", String.class).allowNullable().check(Office::validOfficeCanNull, "Invalid office provided").get());
        String like = ctx.queryParamAsClass("like", String.class).getOrDefault(".*");
        String tsCategoryLike = ctx.queryParamAsClass("timeseriesCategoryLike", String.class).getOrDefault(null);
        String tsGroupLike = ctx.queryParamAsClass("timeseriesGroupLike", String.class).getOrDefault(null);
        String locCategoryLike = ctx.queryParamAsClass("locationCategoryLike", String.class).getOrDefault(null);
        String locGroupLike = ctx.queryParamAsClass("locationGroupLike", String.class).getOrDefault(null);
        String acceptHeader = ctx.header("Accept");
        ContentType contentType = Formats.parseHeaderAndQueryParm(acceptHeader, null);
        Catalog cat = null;
        if ("timeseries".equalsIgnoreCase(valDataSet)) {
            TimeSeriesDao tsDao = new TimeSeriesDaoImpl(dsl);
            cat = tsDao.getTimeSeriesCatalog(cursor, pageSize, office, like, locCategoryLike, locGroupLike, tsCategoryLike, tsGroupLike);
        } else if ("locations".equalsIgnoreCase(valDataSet)) {
            LocationsDao dao = new LocationsDaoImpl(dsl);
            cat = dao.getLocationCatalog(cursor, pageSize, unitSystem, office, like, locCategoryLike, locGroupLike);
        }
        if (cat != null) {
            String data = Formats.format(contentType, cat);
            ctx.result(data).contentType(contentType.toString());
            requestResultSize.update(data.length());
        } else {
            final RadarError re = new RadarError("Cannot create catalog of requested information");
            logger.info(() -> re.toString() + "with url:" + ctx.fullUrl());
            ctx.json(re).status(HttpCode.NOT_FOUND);
        }
    }
}
Also used : Office(cwms.radar.data.dto.Office) PolicyFactory(org.owasp.html.PolicyFactory) ContentType(cwms.radar.formatters.ContentType) DSLContext(org.jooq.DSLContext) LocationsDao(cwms.radar.data.dao.LocationsDao) Catalog(cwms.radar.data.dto.Catalog) LocationsDaoImpl(cwms.radar.data.dao.LocationsDaoImpl) RadarError(cwms.radar.api.errors.RadarError) Timer(com.codahale.metrics.Timer) TimeSeriesDaoImpl(cwms.radar.data.dao.TimeSeriesDaoImpl) TimeSeriesDao(cwms.radar.data.dao.TimeSeriesDao) OpenApi(io.javalin.plugin.openapi.annotations.OpenApi)

Example 13 with Office

use of cwms.radar.data.dto.Office in project cwms-radar-api by USACE.

the class ClobDao method getByUniqueName.

@Override
public Optional<Clob> getByUniqueName(String uniqueName, Optional<String> limitToOffice) {
    AV_CLOB ac = AV_CLOB.AV_CLOB;
    AV_OFFICE ao = AV_OFFICE.AV_OFFICE;
    Condition cond = ac.ID.eq(uniqueName);
    if (limitToOffice.isPresent()) {
        String office = limitToOffice.get();
        if (office != null && !office.isEmpty()) {
            cond = cond.and(ao.OFFICE_ID.eq(office));
        }
    }
    RecordMapper<Record, Clob> mapper = joinRecord -> new Clob(joinRecord.getValue(ao.OFFICE_ID), joinRecord.getValue(ac.ID), joinRecord.getValue(ac.DESCRIPTION), joinRecord.getValue(ac.VALUE));
    Clob avClob = dsl.select(ao.OFFICE_ID, ac.asterisk()).from(ac.join(ao).on(ac.OFFICE_CODE.eq(ao.OFFICE_CODE))).where(cond).fetchOne(mapper);
    return Optional.ofNullable(avClob);
}
Also used : Condition(org.jooq.Condition) SelectJoinStep(org.jooq.SelectJoinStep) Clob(cwms.radar.data.dto.Clob) DSL(org.jooq.impl.DSL) RecordMapper(org.jooq.RecordMapper) DSL.count(org.jooq.impl.DSL.count) Table(org.jooq.Table) Clobs(cwms.radar.data.dto.Clobs) ParamType(org.jooq.conf.ParamType) Condition(org.jooq.Condition) SelectLimitPercentStep(org.jooq.SelectLimitPercentStep) Record4(org.jooq.Record4) SelectConditionStep(org.jooq.SelectConditionStep) Record2(org.jooq.Record2) AV_OFFICE(usace.cwms.db.jooq.codegen.tables.AV_OFFICE) Record1(org.jooq.Record1) DSLContext(org.jooq.DSLContext) Select(org.jooq.Select) AV_CLOB(usace.cwms.db.jooq.codegen.tables.AV_CLOB) DSL.inline(org.jooq.impl.DSL.inline) Record(org.jooq.Record) DSL.asterisk(org.jooq.impl.DSL.asterisk) Logger(java.util.logging.Logger) List(java.util.List) Catalog(cwms.radar.data.dto.Catalog) TableField(org.jooq.TableField) SQLDataType(org.jooq.impl.SQLDataType) Optional(java.util.Optional) Office(cwms.radar.data.dto.Office) AV_CLOB(usace.cwms.db.jooq.codegen.tables.AV_CLOB) AV_OFFICE(usace.cwms.db.jooq.codegen.tables.AV_OFFICE) Record(org.jooq.Record) Clob(cwms.radar.data.dto.Clob)

Example 14 with Office

use of cwms.radar.data.dto.Office in project cwms-radar-api by USACE.

the class ClobDao method getClobsLike.

public List<Clob> getClobsLike(String office, String idLike) {
    AV_CLOB ac = AV_CLOB.AV_CLOB;
    AV_OFFICE ao = AV_OFFICE.AV_OFFICE;
    Condition cond = ac.ID.upper().like(idLike.toUpperCase());
    if (office != null && !office.isEmpty()) {
        cond = cond.and(ao.OFFICE_ID.upper().eq(office.toUpperCase()));
    }
    RecordMapper<Record, Clob> mapper = joinRecord -> new Clob(joinRecord.get(ao.OFFICE_ID), joinRecord.get(ac.ID), joinRecord.get(ac.DESCRIPTION), joinRecord.get(ac.VALUE));
    return dsl.select(ac.asterisk(), ao.OFFICE_ID).from(ac.join(ao).on(ac.OFFICE_CODE.eq(ao.OFFICE_CODE))).where(cond).fetch(mapper);
}
Also used : Condition(org.jooq.Condition) SelectJoinStep(org.jooq.SelectJoinStep) Clob(cwms.radar.data.dto.Clob) DSL(org.jooq.impl.DSL) RecordMapper(org.jooq.RecordMapper) DSL.count(org.jooq.impl.DSL.count) Table(org.jooq.Table) Clobs(cwms.radar.data.dto.Clobs) ParamType(org.jooq.conf.ParamType) Condition(org.jooq.Condition) SelectLimitPercentStep(org.jooq.SelectLimitPercentStep) Record4(org.jooq.Record4) SelectConditionStep(org.jooq.SelectConditionStep) Record2(org.jooq.Record2) AV_OFFICE(usace.cwms.db.jooq.codegen.tables.AV_OFFICE) Record1(org.jooq.Record1) DSLContext(org.jooq.DSLContext) Select(org.jooq.Select) AV_CLOB(usace.cwms.db.jooq.codegen.tables.AV_CLOB) DSL.inline(org.jooq.impl.DSL.inline) Record(org.jooq.Record) DSL.asterisk(org.jooq.impl.DSL.asterisk) Logger(java.util.logging.Logger) List(java.util.List) Catalog(cwms.radar.data.dto.Catalog) TableField(org.jooq.TableField) SQLDataType(org.jooq.impl.SQLDataType) Optional(java.util.Optional) Office(cwms.radar.data.dto.Office) AV_CLOB(usace.cwms.db.jooq.codegen.tables.AV_CLOB) AV_OFFICE(usace.cwms.db.jooq.codegen.tables.AV_OFFICE) Record(org.jooq.Record) Clob(cwms.radar.data.dto.Clob)

Example 15 with Office

use of cwms.radar.data.dto.Office in project cwms-radar-api by USACE.

the class TabV1Office method format.

@Override
// for the daoList conversion
@SuppressWarnings("unchecked")
public String format(List<? extends CwmsDTO> dtoList) {
    List<Office> offices = (List<Office>) dtoList;
    StringBuilder builder = new StringBuilder();
    builder.append(getOfficeTabHeader()).append("\r\n");
    for (Office office : offices) {
        builder.append(officeRow(office)).append("\r\n");
    }
    return builder.toString();
}
Also used : Office(cwms.radar.data.dto.Office) List(java.util.List)

Aggregations

Office (cwms.radar.data.dto.Office)19 DSLContext (org.jooq.DSLContext)7 List (java.util.List)6 Catalog (cwms.radar.data.dto.Catalog)4 AV_OFFICE (usace.cwms.db.jooq.codegen.tables.AV_OFFICE)4 Timer (com.codahale.metrics.Timer)3 Clob (cwms.radar.data.dto.Clob)3 Clobs (cwms.radar.data.dto.Clobs)3 ContentType (cwms.radar.formatters.ContentType)3 OpenApi (io.javalin.plugin.openapi.annotations.OpenApi)3 Optional (java.util.Optional)3 Logger (java.util.logging.Logger)3 Condition (org.jooq.Condition)3 Record (org.jooq.Record)3 Record1 (org.jooq.Record1)3 Record2 (org.jooq.Record2)3 Record4 (org.jooq.Record4)3 RecordMapper (org.jooq.RecordMapper)3 Select (org.jooq.Select)3 SelectConditionStep (org.jooq.SelectConditionStep)3