Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 29 additions & 16 deletions cwms-data-api/src/main/java/cwms/cda/api/LocationController.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,27 @@
package cwms.cda.api;

import static com.codahale.metrics.MetricRegistry.name;
import static cwms.cda.api.Controllers.*;
import static cwms.cda.api.Controllers.CASCADE_DELETE;
import static cwms.cda.api.Controllers.CREATE;
import static cwms.cda.api.Controllers.DATUM;
import static cwms.cda.api.Controllers.DELETE;
import static cwms.cda.api.Controllers.FAIL_IF_EXISTS;
import static cwms.cda.api.Controllers.FORMAT;
import static cwms.cda.api.Controllers.GET_ALL;
import static cwms.cda.api.Controllers.GET_ONE;
import static cwms.cda.api.Controllers.INCLUDE_ALIASES;
import static cwms.cda.api.Controllers.LOCATION_ID;
import static cwms.cda.api.Controllers.NAMES;
import static cwms.cda.api.Controllers.OFFICE;
import static cwms.cda.api.Controllers.RESULTS;
import static cwms.cda.api.Controllers.SIZE;
import static cwms.cda.api.Controllers.STATUS_200;
import static cwms.cda.api.Controllers.STATUS_404;
import static cwms.cda.api.Controllers.UNIT;
import static cwms.cda.api.Controllers.UPDATE;
import static cwms.cda.api.Controllers.VERSION;
import static cwms.cda.api.Controllers.addDeprecatedContentTypeWarning;
import static cwms.cda.api.Controllers.requiredParam;
import static cwms.cda.data.dao.JooqDao.getDslContext;

import com.codahale.metrics.Histogram;
Expand All @@ -39,6 +58,7 @@
import com.fasterxml.jackson.databind.introspect.BeanPropertyDefinition;
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import com.google.common.flogger.FluentLogger;
import cwms.cda.api.enums.Nation;
import cwms.cda.api.enums.UnitSystem;
import cwms.cda.api.errors.CdaError;
Expand All @@ -63,7 +83,6 @@
import java.io.IOException;
import java.sql.SQLException;
import java.util.List;
import com.google.common.flogger.FluentLogger;
import javax.servlet.http.HttpServletResponse;
import org.geojson.FeatureCollection;
import org.jetbrains.annotations.NotNull;
Expand Down Expand Up @@ -151,7 +170,6 @@ private Timer.Context markAndTime(String subject) {
)
@Override
public void getAll(@NotNull Context ctx) {

try (final Timer.Context ignored = markAndTime(GET_ALL)) {
DSLContext dsl = getDslContext(ctx);

Expand Down Expand Up @@ -199,17 +217,12 @@ public void getAll(@NotNull Context ctx) {
addDeprecatedContentTypeWarning(ctx, contentType);

ctx.status(HttpServletResponse.SC_OK);

} catch (Exception ex) {
CdaError re = new CdaError("failed to process request");
logger.atSevere().withCause(ex).log("%s", re.toString());
ctx.status(HttpServletResponse.SC_INTERNAL_SERVER_ERROR).json(re);
}
}

@OpenApi(
pathParams = {
@OpenApiParam(name = LOCATION_ID, description = "The ID of the location to get")
@OpenApiParam(name = LOCATION_ID, description = "The ID of the location to get")
},
queryParams = {
@OpenApiParam(name = OFFICE, required = true, description = "Specifies the "
Expand Down Expand Up @@ -311,14 +324,14 @@ public void create(@NotNull Context ctx) {

@OpenApi(
pathParams = {
@OpenApiParam(name = LOCATION_ID, description = "The ID of the location to update")
@OpenApiParam(name = LOCATION_ID, description = "The ID of the location to update")
},
requestBody = @OpenApiRequestBody(
content = {
@OpenApiContent(from = Location.class, type = Formats.XML),
@OpenApiContent(from = Location.class, type = Formats.JSON)
},
required = true),
content = {
@OpenApiContent(from = Location.class, type = Formats.XML),
@OpenApiContent(from = Location.class, type = Formats.JSON)
},
required = true),
description = "Update CWMS Location",
method = HttpMethod.PATCH,
path = "/locations",
Expand Down Expand Up @@ -367,7 +380,7 @@ public void update(@NotNull Context ctx, @NotNull String locationId) {

@OpenApi(
pathParams = {
@OpenApiParam(name = LOCATION_ID, description = "The ID of the location to delete")
@OpenApiParam(name = LOCATION_ID, description = "The ID of the location to delete")
},
queryParams = {
@OpenApiParam(name = OFFICE, description = "Specifies the owning office of "
Expand Down
60 changes: 27 additions & 33 deletions cwms-data-api/src/main/java/cwms/cda/api/ParametersController.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import static cwms.cda.api.Controllers.ACCEPT;
import static cwms.cda.api.Controllers.FORMAT;
import static cwms.cda.api.Controllers.GET_ALL;
import static cwms.cda.api.Controllers.GET_ONE;
import static cwms.cda.api.Controllers.OFFICE;
import static cwms.cda.api.Controllers.RESULTS;
import static cwms.cda.api.Controllers.SIZE;
Expand All @@ -28,12 +27,11 @@
import io.javalin.plugin.openapi.annotations.OpenApiParam;
import io.javalin.plugin.openapi.annotations.OpenApiResponse;
import java.util.List;
import com.google.common.flogger.FluentLogger;
import javax.servlet.http.HttpServletResponse;
import org.jetbrains.annotations.NotNull;
import org.jooq.DSLContext;

public class ParametersController implements CrudHandler {
private static final FluentLogger logger = FluentLogger.forEnclosingClass();
private final MetricRegistry metrics;

private final Histogram requestResultSize;
Expand All @@ -51,42 +49,42 @@ private Timer.Context markAndTime(String subject) {

@OpenApi(ignore = true)
@Override
public void create(Context ctx) {
public void create(@NotNull Context ctx) {
ctx.status(HttpServletResponse.SC_NOT_IMPLEMENTED).json(CdaError.notImplemented());
}

@OpenApi(ignore = true)
@Override
public void delete(Context ctx, String id) {
public void delete(@NotNull Context ctx, @NotNull String id) {
ctx.status(HttpServletResponse.SC_NOT_IMPLEMENTED).json(CdaError.notImplemented());

}

@OpenApi(
queryParams = {
@OpenApiParam(name = FORMAT, deprecated = true, description = "Specifies the"
+ " encoding format of the response. Valid value for the format field"
+ " for this URI are:"
+ "\n* `tab` (deprecated)"
+ "\n* `csv` (deprecated)"
+ "\n* `xml`"
+ "\n* `json` (default)"
+ "\n\nSee <a href=\"legacy-format/\">this page</a> for more information about accept header usage."),
@OpenApiParam(name = OFFICE, description = "Specifies the"
+ " owning office of the parameters whose data is to be included in the "
+ "response. If this field is not specified, the session user's default office will be"
+ " used."),
},
responses = {
@OpenApiResponse(status = STATUS_200, content = {
@OpenApiContent(isArray = true, from = Parameter.class, type = Formats.JSONV2),
@OpenApiContent(isArray = true, from = Parameter.class, type = Formats.JSON)
}),
},
tags = {"Parameters"}
queryParams = {
@OpenApiParam(name = FORMAT, deprecated = true, description = "Specifies the"
+ " encoding format of the response. Valid value for the format field"
+ " for this URI are:"
+ "\n* `tab` (deprecated)"
+ "\n* `csv` (deprecated)"
+ "\n* `xml`"
+ "\n* `json` (default)"
+ "\n\nSee <a href=\"legacy-format/\">this page</a> for more information about accept header usage."),
@OpenApiParam(name = OFFICE, description = "Specifies the"
+ " owning office of the parameters whose data is to be included in the "
+ "response. If this field is not specified, the session user's default office will be"
+ " used."),
},
responses = {
@OpenApiResponse(status = STATUS_200, content = {
@OpenApiContent(isArray = true, from = Parameter.class, type = Formats.JSONV2),
@OpenApiContent(isArray = true, from = Parameter.class, type = Formats.JSON)
}),
},
tags = {"Parameters"}
)
@Override
public void getAll(Context ctx) {
public void getAll(@NotNull Context ctx) {
try (final Timer.Context timeContext = markAndTime(GET_ALL)) {
DSLContext dsl = getDslContext(ctx);
ParameterDao dao = new ParameterDao(dsl);
Expand Down Expand Up @@ -121,22 +119,18 @@ public void getAll(Context ctx) {
ctx.result(results);
addDeprecatedContentTypeWarning(ctx, contentType);
requestResultSize.update(results.length());
} catch (Exception ex) {
CdaError re = new CdaError("Failed to process request");
logger.atSevere().withCause(ex).log("%s", re);
ctx.status(HttpServletResponse.SC_INTERNAL_SERVER_ERROR).json(re);
}
}

@OpenApi(ignore = true)
@Override
public void getOne(Context ctx, String id) {
public void getOne(@NotNull Context ctx, @NotNull String id) {
ctx.status(HttpServletResponse.SC_NOT_IMPLEMENTED).json(CdaError.notImplemented());
}

@OpenApi(ignore = true)
@Override
public void update(Context ctx, String id) {
public void update(@NotNull Context ctx, @NotNull String id) {
ctx.status(HttpServletResponse.SC_NOT_IMPLEMENTED).json(CdaError.notImplemented());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,20 @@

package cwms.cda.api;

import static com.codahale.metrics.MetricRegistry.name;
import static cwms.cda.api.Controllers.CREATE;
import static cwms.cda.api.Controllers.FAIL_IF_EXISTS;
import static cwms.cda.api.Controllers.GET_ALL;
import static cwms.cda.api.Controllers.OFFICE;
import static cwms.cda.api.Controllers.RESULTS;
import static cwms.cda.api.Controllers.SIZE;
import static cwms.cda.api.Controllers.SPECIFIED_LEVEL_ID;
import static cwms.cda.api.Controllers.STATUS_200;
import static cwms.cda.api.Controllers.TEMPLATE_ID_MASK;
import static cwms.cda.api.Controllers.UPDATE;
import static cwms.cda.api.Controllers.requiredParam;
import static cwms.cda.data.dao.JooqDao.getDslContext;

import com.codahale.metrics.Histogram;
import com.codahale.metrics.MetricRegistry;
import com.codahale.metrics.Timer;
Expand All @@ -35,21 +49,19 @@
import io.javalin.apibuilder.CrudHandler;
import io.javalin.core.util.Header;
import io.javalin.http.Context;
import io.javalin.plugin.openapi.annotations.*;
import io.javalin.plugin.openapi.annotations.HttpMethod;
import io.javalin.plugin.openapi.annotations.OpenApi;
import io.javalin.plugin.openapi.annotations.OpenApiContent;
import io.javalin.plugin.openapi.annotations.OpenApiParam;
import io.javalin.plugin.openapi.annotations.OpenApiRequestBody;
import io.javalin.plugin.openapi.annotations.OpenApiResponse;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.jetbrains.annotations.NotNull;
import org.jooq.DSLContext;

import javax.servlet.http.HttpServletResponse;
import java.util.List;
import com.google.common.flogger.FluentLogger;

import static com.codahale.metrics.MetricRegistry.name;
import static cwms.cda.api.Controllers.*;
import static cwms.cda.data.dao.JooqDao.getDslContext;


public class SpecifiedLevelController implements CrudHandler {
private static final FluentLogger logger = FluentLogger.forEnclosingClass();
private static final String TAG = "Levels";
private final MetricRegistry metrics;

Expand All @@ -73,23 +85,24 @@ private Timer.Context markAndTime(String subject) {


@OpenApi(
queryParams = {
@OpenApiParam(name = OFFICE, description = "Specifies the owning office of "
+ "the Specified Levels whose data is to be included in the response."
+ " If this field is not specified, matching rating information from "
+ "all offices shall be returned."),
@OpenApiParam(name = TEMPLATE_ID_MASK, description = "Mask that specifies "
+ "the IDs to be included in the response. If this field is not "
+ "specified, all specified levels shall be returned."),
},
responses = {
@OpenApiResponse(status = STATUS_200,
content = {
@OpenApiContent(type = Formats.JSONV2, from =
SpecifiedLevel.class)
}
)},
tags = {TAG}
queryParams = {
@OpenApiParam(name = OFFICE, description = "Specifies the owning office of "
+ "the Specified Levels whose data is to be included in the response."
+ " If this field is not specified, matching rating information from "
+ "all offices shall be returned."),
@OpenApiParam(name = TEMPLATE_ID_MASK, description = "Mask that specifies "
+ "the IDs to be included in the response. If this field is not "
+ "specified, all specified levels shall be returned."),
},
responses = {
@OpenApiResponse(status = STATUS_200,
content = {
@OpenApiContent(type = Formats.JSONV2, from =
SpecifiedLevel.class)
}
)
},
tags = {TAG}
)
@Override
public void getAll(Context ctx) {
Expand All @@ -98,7 +111,7 @@ public void getAll(Context ctx) {

String formatHeader = ctx.header(Header.ACCEPT);
ContentType contentType = Formats.parseHeader(formatHeader, SpecifiedLevel.class);
try (Timer.Context timeContext = markAndTime(GET_ALL)){
try (Timer.Context timeContext = markAndTime(GET_ALL)) {
DSLContext dsl = getDslContext(ctx);

SpecifiedLevelDao dao = getDao(dsl);
Expand All @@ -110,18 +123,13 @@ public void getAll(Context ctx) {
ctx.result(result);
requestResultSize.update(result.length());
ctx.status(HttpServletResponse.SC_OK);
} catch (Exception ex) {
CdaError re =
new CdaError("Failed to process request: " + ex.getLocalizedMessage());
logger.atSevere().withCause(ex).log("%s", re);
ctx.status(HttpServletResponse.SC_INTERNAL_SERVER_ERROR).json(re);
}

}

@OpenApi(ignore = true)
@Override
public void getOne(Context ctx, String templateId) {
public void getOne(@NotNull Context ctx, @NotNull String templateId) {
ctx.status(HttpServletResponse.SC_NOT_IMPLEMENTED).json(CdaError.notImplemented());
}

Expand All @@ -140,8 +148,8 @@ public void getOne(Context ctx, String templateId) {
tags = {TAG}
)
@Override
public void create(Context ctx) {
try (Timer.Context ignored = markAndTime(CREATE)){
public void create(@NotNull Context ctx) {
try (Timer.Context ignored = markAndTime(CREATE)) {
DSLContext dsl = getDslContext(ctx);

String formatHeader = ctx.req.getContentType();
Expand Down Expand Up @@ -169,8 +177,8 @@ public void create(Context ctx) {
tags = {TAG}
)
@Override
public void update(Context ctx, @NotNull String oldSpecifiedLevelId) {
try (Timer.Context ignored = markAndTime(UPDATE)){
public void update(@NotNull Context ctx, @NotNull String oldSpecifiedLevelId) {
try (Timer.Context ignored = markAndTime(UPDATE)) {
DSLContext dsl = getDslContext(ctx);

SpecifiedLevelDao dao = getDao(dsl);
Expand All @@ -196,8 +204,8 @@ public void update(Context ctx, @NotNull String oldSpecifiedLevelId) {
tags = {TAG}
)
@Override
public void delete(Context ctx, String specifiedLevelId) {
try (Timer.Context ignored = markAndTime(UPDATE)){
public void delete(@NotNull Context ctx, @NotNull String specifiedLevelId) {
try (Timer.Context ignored = markAndTime(UPDATE)) {
DSLContext dsl = getDslContext(ctx);

SpecifiedLevelDao dao = getDao(dsl);
Expand Down
Loading
Loading