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());
}
}
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);
}
}
}
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);
}
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);
}
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();
}
Aggregations