Skip to content

Commit

Permalink
Merge branch 'develop' into release/3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeNeilson committed Nov 20, 2023
2 parents ec3ff7e + bdcd5e9 commit 95890ad
Show file tree
Hide file tree
Showing 15 changed files with 391 additions and 114 deletions.
6 changes: 6 additions & 0 deletions cwms-data-api/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ dependencies {
tomcatLibs "org.apache.tomcat.embed:tomcat-embed-jasper:$tomcatVersion"
tomcatLibs "org.apache.tomcat:tomcat-juli:$tomcatVersion"
tomcatLibs "org.apache.tomcat:tomcat-jdbc:$tomcatVersion"
tomcatLibs "com.google.flogger:flogger:0.7.4"
tomcatLibs "com.google.flogger:flogger-system-backend:0.7.4"

testImplementation "com.github.h-thurow:tomcat8jndi:1.0.0"

Expand Down Expand Up @@ -180,6 +182,10 @@ war {
from "$buildDir/extra"
from "src/resources/"

manifest {
attributes "build-version": project.version
}

doLast {
println(war.archiveFileName.toString())
println("::set-output name=WARFILE::${project.name}-${project.version}.war")
Expand Down
221 changes: 149 additions & 72 deletions cwms-data-api/src/main/java/cwms/cda/ApiServlet.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

public class BasinController implements CrudHandler {
private static final Logger LOGGER = Logger.getLogger(BasinController.class.getName());
public static final String TAG = "Basins-Beta";
public static final String TAG = "Basins";


private final MetricRegistry metrics;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
public class CatalogController implements CrudHandler {

private static final Logger logger = Logger.getLogger(CatalogController.class.getName());
private static final String TAG = "Catalog-Beta";
private static final String TAG = "Catalog";


private final MetricRegistry metrics;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,13 @@
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.servlet.http.HttpServletResponse;
import org.jetbrains.annotations.NotNull;
import org.jooq.DSLContext;

public class LocationCategoryController implements CrudHandler {
public static final Logger logger =
Logger.getLogger(LocationCategoryController.class.getName());
private static final String TAG = "Location Categories-Beta";
private static final String TAG = "Location Categories";

private final MetricRegistry metrics;

Expand Down Expand Up @@ -147,7 +148,7 @@ public void getAll(Context ctx) {
description = "Retrieves requested Location Category",
tags = {TAG})
@Override
public void getOne(Context ctx, String categoryId) {
public void getOne(Context ctx, @NotNull String categoryId) {

try (final Timer.Context timeContext = markAndTime(GET_ONE);
DSLContext dsl = getDslContext(ctx)) {
Expand Down Expand Up @@ -222,7 +223,7 @@ private LocationCategory deserialize(String body, String format) throws JsonProc

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

Expand All @@ -241,7 +242,7 @@ public void update(Context ctx, String categoryId) {
tags = {TAG}
)
@Override
public void delete(Context ctx, String categoryId) {
public void delete(Context ctx, @NotNull String categoryId) {
try (Timer.Context ignored = markAndTime(UPDATE);
DSLContext dsl = getDslContext(ctx)) {
LocationCategoryDao dao = new LocationCategoryDao(dsl);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
public class LocationGroupController implements CrudHandler {
public static final Logger logger = Logger.getLogger(LocationGroupController.class.getName());

public static final String TAG = "Location Groups-Beta";
public static final String TAG = "Location Groups";
private final MetricRegistry metrics;

private final Histogram requestResultSize;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,13 @@
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.servlet.http.HttpServletResponse;
import org.jetbrains.annotations.NotNull;
import org.jooq.DSLContext;

public class TimeSeriesCategoryController implements CrudHandler {
public static final Logger logger =
Logger.getLogger(TimeSeriesCategoryController.class.getName());
public static final String TAG = "TimeSeries Categories-Beta";
public static final String TAG = "TimeSeries Categories";

private final MetricRegistry metrics;

Expand Down Expand Up @@ -134,7 +135,7 @@ public void getAll(Context ctx) {
+ "implemented")},
description = "Retrieves requested timeseries category", tags = {TAG})
@Override
public void getOne(Context ctx, String categoryId) {
public void getOne(Context ctx, @NotNull String categoryId) {
try (final Timer.Context timeContext = markAndTime(GET_ONE);
DSLContext dsl = getDslContext(ctx)) {
TimeSeriesCategoryDao dao = new TimeSeriesCategoryDao(dsl);
Expand Down Expand Up @@ -207,7 +208,7 @@ private TimeSeriesCategory deserialize(String body, String format) throws JsonPr

@OpenApi(ignore = true)
@Override
public void update(Context ctx, String locationCode) {
public void update(@NotNull Context ctx, @NotNull String locationCode) {
throw new UnsupportedOperationException(NOT_SUPPORTED_YET);
}

Expand All @@ -226,7 +227,7 @@ public void update(Context ctx, String locationCode) {
tags = {TAG}
)
@Override
public void delete(Context ctx, String categoryId) {
public void delete(Context ctx, @NotNull String categoryId) {
try (Timer.Context ignored = markAndTime(UPDATE);
DSLContext dsl = getDslContext(ctx)) {
TimeSeriesCategoryDao dao = new TimeSeriesCategoryDao(dsl);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@

public class TimeSeriesGroupController implements CrudHandler {
public static final Logger logger = Logger.getLogger(TimeSeriesGroupController.class.getName());
public static final String TAG = "Timeseries Groups-Beta";
public static final String TAG = "Timeseries Groups";

private final MetricRegistry metrics;

Expand Down Expand Up @@ -256,10 +256,10 @@ public void update(Context ctx, String oldGroupId) {
TimeSeriesGroup deserialize = deserialize(body, formatHeader);
boolean replaceAssignedTs = ctx.queryParamAsClass(REPLACE_ASSIGNED_TS, Boolean.class).getOrDefault(false);
TimeSeriesGroupDao timeSeriesGroupDao = new TimeSeriesGroupDao(dsl);
if(!oldGroupId.equals(deserialize.getId())) {
if (!oldGroupId.equals(deserialize.getId())) {
timeSeriesGroupDao.renameTimeSeriesGroup(oldGroupId, deserialize);
}
if(replaceAssignedTs){
if (replaceAssignedTs) {
timeSeriesGroupDao.unassignAllTs(deserialize);
}
timeSeriesGroupDao.assignTs(deserialize);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@

public class TimeSeriesIdentifierDescriptorController implements CrudHandler {
public static final Logger logger = Logger.getLogger(TimeSeriesIdentifierDescriptorController.class.getName());
public static final String TAG = "TimeSeries Identifier-Beta";
public static final String TAG = "TimeSeries Identifier";

private static final int DEFAULT_PAGE_SIZE = 500;

Expand Down
7 changes: 3 additions & 4 deletions cwms-data-api/src/main/webapp/swagger-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@ info:
version: '1.0.0'
title: CWMS Data API
description: CWMS Data API is a generalized web service API that allows clients to retrieve data from Corps Water Management System (CWMS) databases.
termsOfService: http://10.10.10.180/terms/
termsOfService: https://cwms-data.usace.army.mil/cwms-data
contact:
name: Support
email: [email protected]
url: https://www.hec.usace.army.mil
host: 10.10.10.180
url: https://github.com/usace/cwms-data-api
host: https://cmws-data.usace.army.mil
url: /cwms-data/swagger-docs
basePath: /cwms-data
schemes:
Expand Down
7 changes: 2 additions & 5 deletions cwms-data-api/src/main/webapp/swagger-ui.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,15 @@
// Begin Swagger UI call region
const ui = SwaggerUIBundle({
url: "./swagger-docs",
//basePath: "/cwms-data",
dom_id: "#swagger-ui",
configUrl: "./swagger-config.yaml",
deepLinking: false,
presets: [
SwaggerUIBundle.presets.apis,
SwaggerUIStandalonePreset
SwaggerUIBundle.presets.apis
],
plugins: [
SwaggerUIBundle.plugins.DownloadUrl
],
layout: "StandaloneLayout"
]
}
);
// End Swagger UI call region
Expand Down
107 changes: 97 additions & 10 deletions cwms-data-api/src/test/java/cwms/cda/ApiServletTest.java
Original file line number Diff line number Diff line change
@@ -1,33 +1,120 @@
package cwms.cda;


import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;

import io.javalin.http.Handler;
import io.javalin.http.HandlerEntry;
import io.javalin.http.HandlerType;
import io.javalin.http.PathMatcher;
import java.util.List;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;
import org.junit.jupiter.params.provider.ValueSource;

import static org.junit.jupiter.api.Assertions.*;

public class ApiServletTest {

@Test
public void test_office_from_context_hq(){
String office = null;
String office;

office = ApiServlet.officeFromContext("/cwms-data");
assertTrue("HQ".equals(office),"failed to get HQ result cwms-data context");

assertEquals("HQ", office, "failed to get HQ result cwms-data context");

office = null;
office = ApiServlet.officeFromContext("");
assertTrue("HQ".equals(office),"failed to get HQ result on root context");

assertEquals("HQ", office, "failed to get HQ result on root context");
}

@ParameterizedTest
@CsvSource( value = { "/spk-data,SPK", "/nwdm-data,NWDM", "/nww-data,NWW", "/swt-data,SWT"} )
void test_office_from_context_district(String context, String office) {
String returnedOffice = ApiServlet.officeFromContext(context);
assertTrue(office.equals(returnedOffice), "failed to process an office context correctly");
assertEquals(office, returnedOffice, "failed to process an office context correctly");
}

@Test
public void test_adding_two_matchers_matches_both() {

PathMatcher matcher = new PathMatcher();
Handler handler = (ctx) -> {};
matcher.add(new HandlerEntry(HandlerType.AFTER, "/offices/{office}", true, handler, handler));
matcher.add(new HandlerEntry(HandlerType.AFTER, "/offices", true, handler, handler));

String[] testPaths = new String[]{ "/offices", "/offices/", "/offices/SPK", "/offices/SPK/"};

for (String testPath : testPaths) {
List<HandlerEntry> matches = matcher.findEntries(HandlerType.AFTER, testPath);
assertNotNull(matches, "did not find match " + testPath);
assertFalse(matches.isEmpty(), testPath+" should have matched");
}


}

@Test
@Disabled ("can't figure out a way to have one pattern match getOne and getAll style paths")
public void test_with_pattern() {
// This is how ApiServlet might make afterPath
// String crudPath = "/offices/{office}";
// // Lets see if we can use a regex to make something that matches
// String regex = "(.*)(\\{.*})?"; //"(.*)(\\{.*\\})";
// String afterPath = crudPath.replaceAll(regex,"$1*");

// skip trying to build the pattern from the input in the test
// and just see what inputs to javalin will match
String afterPath;
// afterPath= "/offices/{office}"; // does not match /offices or /offices/
// afterPath= "/offices/*"; // does not match /offices
// afterPath= "/offices/{office}*"; // does not match /offices or /offices/
// afterPath= "/offices/{office}**"; // this pattern triggers an exception
afterPath= "/offices/*"; // does not match /offices


PathMatcher matcher = new PathMatcher();
Handler handler = (ctx) -> {};
matcher.add(new HandlerEntry(HandlerType.AFTER, afterPath, true, handler, handler));

String[] testPaths = new String[]{
"/offices",
"/offices/", "/offices/SPK", "/offices/SPK/"};

for (String testPath : testPaths) {
List<HandlerEntry> matches = matcher.findEntries(HandlerType.AFTER, testPath);
assertNotNull(matches, "did not find match " + testPath);
assertFalse(matches.isEmpty(), testPath+" should have matched");
}

}


@Test
public void test_match_with_internal_resource() {
PathMatcher matcher = new PathMatcher();
Handler handler = (ctx) -> {};
matcher.add(new HandlerEntry(HandlerType.AFTER, "/levels/{level-id}/timeseries", true, handler, handler));

List<HandlerEntry> matches = matcher.findEntries(HandlerType.AFTER, "/levels/doesthismatch/timeseries");
assertNotNull(matches);
assertFalse(matches.isEmpty());

}

@Test
public void test_match_with_internal_star() {
PathMatcher matcher = new PathMatcher();
Handler handler = (ctx) -> {};
matcher.add(new HandlerEntry(HandlerType.AFTER, "/levels/*/timeseries", true, handler, handler));

List<HandlerEntry> matches = matcher.findEntries(HandlerType.AFTER, "/levels/doesthismatch/timeseries");
assertNotNull(matches);
assertFalse(matches.isEmpty());

}


}


Loading

0 comments on commit 95890ad

Please sign in to comment.