use of io.javalin.plugin.openapi.annotations.OpenApi in project cwms-radar-api by USACE.
the class BlobController 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 = "like", required = false, type = String.class, description = "Posix regular expression describing the blob id's you want") }, responses = { @OpenApiResponse(status = "200", description = "A list of blobs.", content = { @OpenApiContent(type = Formats.JSONV2, from = Blobs.class), @OpenApiContent(type = Formats.XMLV2, from = Blobs.class) }) }, tags = { "Blob" })
@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 cursor = ctx.queryParamAsClass("cursor", String.class).allowNullable().get();
cursor = cursor != null ? cursor : ctx.queryParamAsClass("page", String.class).getOrDefault("");
if (CwmsDTOPaginated.CURSOR_CHECK.invoke(cursor) != true) {
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));
String like = ctx.queryParamAsClass("like", String.class).getOrDefault(".*");
String formatParm = ctx.queryParamAsClass("format", String.class).getOrDefault("");
String formatHeader = ctx.header(Header.ACCEPT);
ContentType contentType = Formats.parseHeaderAndQueryParm(formatHeader, formatParm);
BlobDao dao = new BlobDao(dsl);
List<Blob> blobList = dao.getAll(officeOpt, like);
Blobs blobs = new Blobs.Builder(cursor, pageSize, 0).addAll(blobList).build();
String result = Formats.format(contentType, blobs);
ctx.result(result);
ctx.contentType(contentType.toString());
requestResultSize.update(result.length());
}
}
use of io.javalin.plugin.openapi.annotations.OpenApi 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);
}
}
}
use of io.javalin.plugin.openapi.annotations.OpenApi in project cwms-radar-api by USACE.
the class LocationGroupController method getAll.
@OpenApi(queryParams = { @OpenApiParam(name = "office", description = "Specifies the owning office of the location group(s) whose data is to be included in the response. If this field is not specified, matching location groups information from all offices shall be returned."), @OpenApiParam(name = "includeAssigned", type = Boolean.class, description = "Include the assigned locations in the returned location groups. (default: false)") }, responses = { @OpenApiResponse(status = "200", content = { @OpenApiContent(isArray = true, from = LocationGroup.class, type = Formats.JSON), @OpenApiContent(isArray = true, from = CsvV1LocationGroup.class, type = Formats.CSV) }) }, description = "Returns CWMS Location Groups Data", tags = { TAG })
@Override
public void getAll(Context ctx) {
getAllRequests.mark();
try (final Timer.Context timeContext = getAllRequestsTime.time();
DSLContext dsl = getDslContext(ctx)) {
LocationGroupDao cdm = new LocationGroupDao(dsl);
String office = ctx.queryParam("office");
boolean includeValues = ctx.queryParamAsClass("includeAssigned", Boolean.class).getOrDefault(false);
List<LocationGroup> grps = cdm.getLocationGroups(office, includeValues);
if (!grps.isEmpty()) {
String formatHeader = ctx.header(Header.ACCEPT);
ContentType contentType = Formats.parseHeaderAndQueryParm(formatHeader, "");
String result = Formats.format(contentType, grps, LocationGroup.class);
ctx.result(result);
ctx.contentType(contentType.toString());
requestResultSize.update(result.length());
ctx.status(HttpServletResponse.SC_OK);
} else {
RadarError re = new RadarError("No location groups for office provided");
logger.info(() -> {
return new StringBuilder().append(re.toString()).append(System.lineSeparator()).append("for request ").append(ctx.fullUrl()).toString();
});
ctx.status(HttpServletResponse.SC_NOT_FOUND).json(re);
}
}
}
use of io.javalin.plugin.openapi.annotations.OpenApi in project cwms-radar-api by USACE.
the class LocationGroupController method getOne.
@OpenApi(pathParams = { @OpenApiParam(name = "group-id", required = true, description = "Specifies the location_group whose data is to be included in the response") }, queryParams = { @OpenApiParam(name = "office", required = true, description = "Specifies the owning office of the location group whose data is to be included in the response."), @OpenApiParam(name = "category-id", required = true, description = "Specifies the category containing the location group whose data is to be included in the response.") }, responses = { @OpenApiResponse(status = "200", content = { @OpenApiContent(from = LocationGroup.class, type = Formats.JSON), @OpenApiContent(from = CsvV1LocationGroup.class, type = Formats.CSV), @OpenApiContent(type = Formats.GEOJSON) }) }, description = "Retrieves requested Location Group", tags = { TAG })
@Override
public void getOne(Context ctx, String groupId) {
getOneRequest.mark();
try (final Timer.Context timeContext = getOneRequestTime.time();
DSLContext dsl = getDslContext(ctx)) {
LocationGroupDao cdm = new LocationGroupDao(dsl);
String office = ctx.queryParam("office");
String categoryId = ctx.queryParam("category-id");
String formatHeader = ctx.header(Header.ACCEPT);
ContentType contentType = Formats.parseHeaderAndQueryParm(formatHeader, "");
String result;
if (Formats.GEOJSON.equals(contentType.getType())) {
FeatureCollection fc = cdm.buildFeatureCollectionForLocationGroup(office, categoryId, groupId, "EN");
ObjectMapper mapper = ctx.appAttribute("ObjectMapper");
result = mapper.writeValueAsString(fc);
} else {
Optional<LocationGroup> grp = cdm.getLocationGroup(office, categoryId, groupId);
if (grp.isPresent()) {
result = Formats.format(contentType, grp.get());
} else {
RadarError re = new RadarError("Unable to find location group based on parameters given");
logger.info(() -> {
return new StringBuilder().append(re.toString()).append(System.lineSeparator()).append("for request ").append(ctx.fullUrl()).toString();
});
ctx.status(HttpServletResponse.SC_NOT_FOUND).json(re);
return;
}
}
ctx.result(result);
ctx.contentType(contentType.toString());
requestResultSize.update(result.length());
ctx.status(HttpServletResponse.SC_OK);
} catch (JsonProcessingException e) {
RadarError re = new RadarError("Failed to process request");
logger.log(Level.SEVERE, re.toString(), e);
ctx.status(HttpServletResponse.SC_INTERNAL_SERVER_ERROR).json(re);
}
}
use of io.javalin.plugin.openapi.annotations.OpenApi in project cwms-radar-api by USACE.
the class OfficeController method getOne.
@OpenApi(pathParams = @OpenApiParam(name = "office", description = "The 3 letter office ID you want more information for", type = String.class), 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 getOne(Context ctx, String officeId) {
getOneRequest.mark();
try (final Timer.Context timeContext = getOneRequestTime.time();
DSLContext dsl = getDslContext(ctx)) {
OfficeDao dao = new OfficeDao(dsl);
Optional<Office> office = dao.getOfficeById(officeId);
if (office.isPresent()) {
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, office.get());
ctx.result(result).contentType(contentType.toString());
requestResultSize.update(result.length());
} else {
RadarError re = new RadarError("Not Found", new HashMap<String, String>() {
{
put("office", "An office with that name does not exist");
}
});
ctx.status(HttpServletResponse.SC_NOT_FOUND).json(re);
}
}
}
Aggregations