Skip to content

Commit

Permalink
Merge branch 'develop' into bugfix/level_duplicates
Browse files Browse the repository at this point in the history
  • Loading branch information
rma-rripken authored May 17, 2024
2 parents 3afc27f + 6c919b1 commit 0d89122
Show file tree
Hide file tree
Showing 69 changed files with 5,703 additions and 1,638 deletions.
43 changes: 43 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
version: 2
updates:
- package-ecosystem: "gradle"
directory: "/"
schedule:
interval: "weekly"
groups:
alldependencies:
patterns:
- "*"
update-types:
- "minor"
- "patch"
reviewers:
- "@MikeNeilson"
- "@DanielTOsborne"
- package-ecosystem: "gradle"
directory: "/"
schedule:
interval: "weekly"
groups:
alldependencies:
patterns:
- "*"
update-types:
- "major"
reviewers:
- "@MikeNeilson"
- "@DanielTOsborne"
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"
groups:
alldependencies:
patterns:
- "*"
update-types:
- "minor"
- "patch"
reviewers:
- "@MikeNeilson"
- "@DanielTOsborne"
37 changes: 37 additions & 0 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: "CodeQL"
on:
push:
branches: [ develop ]
pull_request:
branches: [ develop ]
schedule:
- cron: '0 0 * * 0'


jobs:
analyze:
name: Analyze
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/[email protected]

- name: Initialize CodeQL
uses: github/codeql-action/[email protected]
with:
languages: 'java'
- name: setup java
uses: actions/[email protected]
with:
java-version: '8'
java-package: jdk
distribution: 'temurin'
- name: Setup Gradle
uses: gradle/[email protected]
with:
dependency-graph: generate-and-submit
- name: build and test
id: build
run: ./gradlew build --info --init-script init.gradle
- name: Perform CodeQL Analysis
uses: github/codeql-action/[email protected]
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ RUN apk add --no-cache bash

RUN mkdir /download && \
cd /download && \
wget https://dlcdn.apache.org/tomcat/tomcat-9/v9.0.85/bin/apache-tomcat-9.0.85.tar.gz && \
wget https://archive.apache.org/dist/tomcat/tomcat-9/v9.0.85/bin/apache-tomcat-9.0.85.tar.gz && \
echo "06e239d15ff7b72017c1d0752ddb1be4651374f7c1391631ec5619f4981cb2911267bc6b044d6c71a2a74738f70d433b96418951439848121f1d874862ddd3de *apache-tomcat-9.0.85.tar.gz" > checksum.txt && \
sha512sum -c checksum.txt && \
tar xzf apache-tomcat-*tar.gz && \
Expand Down
1 change: 1 addition & 0 deletions cwms-data-api/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ dependencies {
exclude group: "org.jooq", module: "jooq"
exclude group: "log4j", module: "log4j"
exclude group: "org.slf4j", module: "slf4j-log4j12"
exclude group: "org.jooq.pro-java-8", module: "jooq"
}

implementation(libs.slf4j)
Expand Down
40 changes: 33 additions & 7 deletions cwms-data-api/src/main/java/cwms/cda/ApiServlet.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@
import cwms.cda.api.ClobController;
import cwms.cda.api.Controllers;
import cwms.cda.api.CountyController;
import cwms.cda.api.ForecastFileController;
import cwms.cda.api.ForecastInstanceController;
import cwms.cda.api.ForecastSpecController;
import cwms.cda.api.LevelsAsTimeSeriesController;
import cwms.cda.api.LevelsController;
import cwms.cda.api.LocationCategoryController;
Expand Down Expand Up @@ -115,6 +118,7 @@
import java.time.DateTimeException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
Expand Down Expand Up @@ -157,6 +161,8 @@
"/clobs/*",
"/pools/*",
"/specified-levels/*",
"/forecast-spec/*",
"/forecast-instance/*",
"/standard-text-id/*"
})
public class ApiServlet extends HttpServlet {
Expand Down Expand Up @@ -267,7 +273,17 @@ public void init() {
ctx.status(HttpServletResponse.SC_BAD_REQUEST).json(re);
})
.exception(InvalidItemException.class, (e, ctx) -> {
CdaError re = new CdaError("Bad Request.");
CdaError re;
String message = e.getMessage();
if (message != null) {
Map<String, Object> details = new LinkedHashMap<>();
details.put("message", message);

re = new CdaError("Bad Request.", details);
} else {
re = new CdaError("Bad Request.");
}

logger.atInfo().withCause(e).log(re.toString());
ctx.status(HttpServletResponse.SC_BAD_REQUEST).json(re);
})
Expand All @@ -277,7 +293,8 @@ public void init() {
ctx.status(HttpServletResponse.SC_CONFLICT).json(re);
})
.exception(DeleteConflictException.class, (e, ctx) -> {
CdaError re = new CdaError("Cannot perform requested delete. Data is referenced elsewhere in CWMS.", e.getDetails());
CdaError re = new CdaError("Cannot perform requested delete. "
+ "Data is referenced elsewhere in CWMS.", e.getDetails());
logger.atInfo().withCause(e).log(re.toString(), e);
ctx.status(HttpServletResponse.SC_CONFLICT).json(re);
})
Expand Down Expand Up @@ -387,12 +404,13 @@ protected void configureRoutes() {
get(levelTsPath, new LevelsAsTimeSeriesController(metrics));
addCacheControl(levelTsPath, 5, TimeUnit.MINUTES);
TimeSeriesController tsController = new TimeSeriesController(metrics);
String recentPath = "/timeseries/recent/{group-id}";
get(recentPath, new TimeSeriesRecentController(metrics), requiredRoles);
String recentPath = "/timeseries/recent/";
get(recentPath, new TimeSeriesRecentController(metrics));
addCacheControl(recentPath, 5, TimeUnit.MINUTES);

cdaCrudCache(format("/standard-text-id/{%s}", Controllers.STANDARD_TEXT_ID),
new StandardTextController(metrics), requiredRoles,1, TimeUnit.DAYS);

String textTsPath = format("/timeseries/text/{%s}", NAME);
cdaCrudCache(textTsPath, new TextTimeSeriesController(metrics), requiredRoles,5, TimeUnit.MINUTES);
String textValuePath = textTsPath + "/value";
Expand Down Expand Up @@ -432,6 +450,14 @@ protected void configureRoutes() {
new PoolController(metrics), requiredRoles,5, TimeUnit.MINUTES);
cdaCrudCache("/specified-levels/{specified-level-id}",
new SpecifiedLevelController(metrics), requiredRoles,5, TimeUnit.MINUTES);
cdaCrudCache("/forecast-instance/{" + Controllers.NAME + "}",
new ForecastInstanceController(metrics), requiredRoles,5, TimeUnit.MINUTES);
cdaCrudCache("/forecast-spec/{" + Controllers.NAME + "}",
new ForecastSpecController(metrics), requiredRoles,5, TimeUnit.MINUTES);
String forecastFilePath = "/forecast-instance/{" + NAME + "}/file-data";
get(forecastFilePath, new ForecastFileController(metrics));
addCacheControl(forecastFilePath, 1, TimeUnit.DAYS);


}

Expand Down Expand Up @@ -463,7 +489,7 @@ public static void cdaCrudCache(@NotNull String path, @NotNull CrudHandler crudH
}

private static void addCacheControl(@NotNull String path, long duration, TimeUnit timeUnit) {
if(timeUnit != null && duration > 0) {
if (timeUnit != null && duration > 0) {
staticInstance().after(path, ctx -> {
String method = ctx.req.getMethod(); // "GET"
if (ctx.status() == HttpServletResponse.SC_OK
Expand Down Expand Up @@ -509,7 +535,7 @@ public static void cdaCrud(@NotNull String path, @NotNull CrudHandler crudHandle
}

/**
* Given a path like "/location/category/{category-id}" this method returns "{category-id}"
* Given a path like "/location/category/{category-id}" this method returns "{category-id}".
* @param fullPath
* @return
*/
Expand Down Expand Up @@ -609,7 +635,7 @@ private static String getAccessManagerName() {
// If something is set in the environment, make that the new default.
// This is useful because Docker makes it easy to set environment variables.
String envProvider = System.getenv(PROVIDER_KEY_OLD);
if( envProvider == null) {
if (envProvider == null) {
envProvider = System.getenv(PROVIDER_KEY);
}
if (envProvider != null) {
Expand Down
24 changes: 14 additions & 10 deletions cwms-data-api/src/main/java/cwms/cda/api/BasinController.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,17 @@ private Timer.Context markAndTime(String subject) {

@OpenApi(
queryParams = {
@OpenApiParam(name = OFFICE, required = false, description = "Specifies the"
@OpenApiParam(name = OFFICE, description = "Specifies the"
+ " owning office of the basin whose data is to be included in the "
+ "response. If this field is not specified, matching basin "
+ "information from all offices shall be returned."),
@OpenApiParam(name = UNIT, required = false, description = "Specifies the "
@OpenApiParam(name = UNIT, description = "Specifies the "
+ "unit or unit system of the response. Valid values for the unit "
+ "field are:\r\n 1. EN. Specifies English unit system. Basin "
+ "field are: "
+ "\n* `EN` Specifies English unit system. Basin "
+ "values will be in the default English units for their parameters. "
+ "(This is default if no value is entered)\r\n2. SI. Specifies the"
+ "(This is default if no value is entered)"
+ "\n* `SI` Specifies the"
+ " SI unit system. Basin values will be in the default SI units for "
+ "their parameters."),
},
Expand Down Expand Up @@ -107,16 +109,18 @@ public void getAll(@NotNull Context ctx) {

@OpenApi(
queryParams = {
@OpenApiParam(name = OFFICE, required = false, description = "Specifies the"
@OpenApiParam(name = OFFICE, description = "Specifies the"
+ " owning office of the basin whose data is to be included in the "
+ "response. If this field is not specified, matching basin "
+ "information from all offices shall be returned."),
@OpenApiParam(name = UNIT, required = false, description = "Specifies the "
@OpenApiParam(name = UNIT, description = "Specifies the "
+ "unit or unit system of the response. Valid values for the unit "
+ "field are:\r\n 1. EN. Specifies English unit system. Basin "
+ "values will be in the default English units for their parameters. "
+ "(This is default if no value is entered)\r\n2. SI. Specifies the"
+ " SI unit system. Basin values will be in the default SI units for "
+ "field are:"
+ "\n* `EN` Specifies English unit system. Basin values will be in "
+ "the default English units for their parameters. "
+ "(This is default if no value is entered)"
+ "\n* `SI` Specifies the SI unit system. Basin values will be in "
+ "the default SI units for "
+ "their parameters."),
},
responses = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,13 @@ public void getAll(@NotNull Context ctx) {
ContentType contentType = Formats.parseHeaderAndQueryParm(formatHeader, "");
try (Timer.Context ignored = markAndTime(GET_ALL)) {
String dateToken = "{date_token}";
String path = ctx.path();
if(!path.endsWith("/")) {
path += "/";
}
path += tsId + "/value";
String url = new URIBuilder(ctx.fullUrl())
.setPath(ctx.path() + tsId + "/value")
.setPath(path)
.clearParameters()
.addParameter(OFFICE, office)
.addParameter(VERSION_DATE, ctx.queryParam(VERSION_DATE))
Expand Down
Loading

0 comments on commit 0d89122

Please sign in to comment.