Skip to content

Commit 5c4c7f2

Browse files
authored
Merge branch 'develop' into cda-gui/review-and-improvements
2 parents 5a18824 + 032e798 commit 5c4c7f2

7 files changed

Lines changed: 79 additions & 65 deletions

File tree

cwms-data-api/src/main/java/cwms/cda/api/LocationController.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@
7373

7474
public class LocationController implements CrudHandler {
7575
private static final FluentLogger logger = FluentLogger.forEnclosingClass();
76+
77+
public static final String LOCATIONS_TAG = "Locations";
78+
7679
private final MetricRegistry metrics;
7780

7881
private final Histogram requestResultSize;
@@ -144,7 +147,7 @@ private Timer.Context markAndTime(String subject) {
144147
},
145148
description = "Returns CWMS Location Data. The Catalog end-point is also capable of "
146149
+ "retrieving lists of locations and can filter on additional fields.",
147-
tags = {"Locations"}
150+
tags = {LOCATIONS_TAG}
148151
)
149152
@Override
150153
public void getAll(@NotNull Context ctx) {
@@ -234,7 +237,7 @@ public void getAll(@NotNull Context ctx) {
234237
+ "inputs provided the location was not found.")
235238
},
236239
description = "Returns CWMS Location Data",
237-
tags = {"Locations"}
240+
tags = {LOCATIONS_TAG}
238241
)
239242
@Override
240243
public void getOne(@NotNull Context ctx, @NotNull String locationId) {
@@ -281,7 +284,7 @@ public void getOne(@NotNull Context ctx, @NotNull String locationId) {
281284
description = "Create new CWMS Location",
282285
method = HttpMethod.POST,
283286
path = "/locations",
284-
tags = {"Locations"}
287+
tags = {LOCATIONS_TAG}
285288
)
286289
@Override
287290
public void create(@NotNull Context ctx) {
@@ -319,7 +322,7 @@ public void create(@NotNull Context ctx) {
319322
description = "Update CWMS Location",
320323
method = HttpMethod.PATCH,
321324
path = "/locations",
322-
tags = {"Locations"},
325+
tags = {LOCATIONS_TAG},
323326
responses = {
324327
@OpenApiResponse(status = STATUS_404, description = "Based on the combination of "
325328
+ "inputs provided the location was not found.")
@@ -377,7 +380,7 @@ public void update(@NotNull Context ctx, @NotNull String locationId) {
377380
description = "Delete CWMS Location",
378381
method = HttpMethod.DELETE,
379382
path = "/locations",
380-
tags = {"Locations"},
383+
tags = {LOCATIONS_TAG},
381384
responses = {
382385
@OpenApiResponse(status = STATUS_200, description = "Location successfully deleted from CWMS."),
383386
@OpenApiResponse(status = STATUS_404, description = "Based on the combination of "

cwms-data-api/src/main/java/cwms/cda/api/VerticalDatumController.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,13 @@
5959
import org.jetbrains.annotations.NotNull;
6060
import org.jooq.DSLContext;
6161

62+
import static cwms.cda.api.LocationController.LOCATIONS_TAG;
63+
6264
public final class VerticalDatumController implements CrudHandler {
6365

6466
private static final FluentLogger logger = FluentLogger.forEnclosingClass();
67+
// NOTE: manually expanded due to limits of OpenApi Annotations.
68+
private static final String VDI_PATH = "/location/{location-id}/vertical-datum";
6569
private final MetricRegistry metrics;
6670
private final Histogram requestResultSize;
6771

@@ -96,7 +100,8 @@ public void getAll(@NotNull Context ctx) {
96100
@OpenApiContent(type = Formats.XML, from = VerticalDatumInfo.class)})
97101
},
98102
description = "Returns Vertical Datum Info for the specified location.",
99-
tags = {"Locations"}
103+
path = VDI_PATH,
104+
tags = {LOCATIONS_TAG}
100105
)
101106
@Override
102107
public void getOne(@NotNull Context ctx, @NotNull String locationId) {
@@ -129,7 +134,8 @@ public void getOne(@NotNull Context ctx, @NotNull String locationId) {
129134
},
130135
description = "Create Vertical Datum Info for a Location",
131136
method = HttpMethod.POST,
132-
tags = {"Locations"},
137+
path = VDI_PATH,
138+
tags = {LOCATIONS_TAG},
133139
responses = {
134140
@OpenApiResponse(status = Controllers.STATUS_201, description = "Vertical Datum Info successfully stored to CWMS.")
135141
}
@@ -173,7 +179,8 @@ public void create(@NotNull Context ctx) {
173179
},
174180
description = "Update Vertical Datum Info for a Location",
175181
method = HttpMethod.PATCH,
176-
tags = {"Locations"},
182+
path = VDI_PATH,
183+
tags = {LOCATIONS_TAG},
177184
responses = {
178185
@OpenApiResponse(status = Controllers.STATUS_200, description = "Updated Vertical Datum Info")
179186
}
@@ -207,7 +214,8 @@ public void update(@NotNull Context ctx, @NotNull String locationId) {
207214
},
208215
description = "Delete Vertical Datum Info for a Location",
209216
method = HttpMethod.DELETE,
210-
tags = {"Locations"},
217+
path = VDI_PATH,
218+
tags = {LOCATIONS_TAG},
211219
responses = {
212220
@OpenApiResponse(status = Controllers.STATUS_200, description = "Vertical Datum Info successfully deleted from CWMS."),
213221
@OpenApiResponse(status = Controllers.STATUS_404, description = "Vertical Datum Info not found.")
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package cwms.cda.api.enums;
2+
3+
import io.swagger.v3.oas.annotations.media.Schema;
4+
5+
@Schema(
6+
name = "Message Queue",
7+
description = "Desired set of status messages. Must be one of the named options."
8+
+ " Letter casing is ignored."
9+
)
10+
public enum MessageQueue {
11+
TS_STORED("TS_STORED", " CWMS messages about time series operations, such as data stored and deleted"),
12+
STATUS("STATUS", " CWMS general system and application status messages"),
13+
REALTIME_OPS("REALTIME_OPS", " CWMS application operational messages");
14+
15+
private String queue;
16+
private String description;
17+
18+
MessageQueue(String queue, String description) {
19+
this.queue = queue;
20+
this.description = description;
21+
}
22+
23+
public String value() {
24+
return queue;
25+
}
26+
27+
public String description() {
28+
return description;
29+
}
30+
31+
public static MessageQueue queueFor(String queue) {
32+
if (TS_STORED.value().equalsIgnoreCase(queue)) {
33+
return TS_STORED;
34+
} else if (STATUS.value().equalsIgnoreCase(queue)) {
35+
return STATUS;
36+
} else if (REALTIME_OPS.value().equalsIgnoreCase(queue)) {
37+
return REALTIME_OPS;
38+
} else {
39+
return null;
40+
}
41+
}
42+
}

cwms-data-api/src/main/java/cwms/cda/api/rss/RssHandler.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import com.codahale.metrics.MetricRegistry;
3131
import com.codahale.metrics.Timer;
3232
import cwms.cda.api.BaseHandler;
33+
import cwms.cda.api.enums.MessageQueue;
3334
import cwms.cda.api.errors.CdaError;
3435
import cwms.cda.data.dao.rss.MessageDao;
3536
import cwms.cda.data.dto.CwmsDTOPaginated;
@@ -66,7 +67,9 @@ public RssHandler(MetricRegistry metrics) {
6667
@OpenApi(
6768
pathParams = {
6869
@OpenApiParam(name = OFFICE, required = true, description = "Office id for feed."),
69-
@OpenApiParam(name = NAME, required = true, description = "Specifies the name of the feed. " +
70+
@OpenApiParam(name = NAME, required = true,
71+
type = MessageQueue.class,
72+
description = "Specifies the name of the feed. " +
7073
"eg TS_STORED, STATUS, REALTIME_OPS")
7174
},
7275
queryParams = {

cwms-data-api/src/main/java/cwms/cda/data/dao/rss/AqTable.java

Lines changed: 0 additions & 31 deletions
This file was deleted.

cwms-data-api/src/main/java/cwms/cda/data/dao/rss/MessageDao.java

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import static org.jooq.impl.DSL.select;
3434
import static org.jooq.impl.DSL.table;
3535

36+
import cwms.cda.api.enums.MessageQueue;
3637
import cwms.cda.api.errors.NotFoundException;
3738
import cwms.cda.data.dao.JooqDao;
3839
import cwms.cda.data.dto.CwmsDTOPaginated;
@@ -44,7 +45,6 @@
4445
import java.time.Instant;
4546
import java.time.ZoneOffset;
4647
import java.time.ZonedDateTime;
47-
import java.time.temporal.ChronoUnit;
4848
import java.util.Optional;
4949
import java.util.function.UnaryOperator;
5050
import org.jooq.DSLContext;
@@ -62,7 +62,7 @@ public MessageDao(DSLContext dsl) {
6262

6363
public RssFeed retrieveFeed(String cursor, int pageSize, String office, String name,
6464
Instant since, UnaryOperator<String> urlBuilder) {
65-
AqTable aqTable = getAqTable(name);
65+
MessageQueue aqTable = getAqTable(name);
6666
String[] cursorSplit = CwmsDTOPaginated.decodeCursor(cursor);
6767
int offset = 0;
6868
if(cursorSplit.length == 2) {
@@ -83,30 +83,18 @@ public RssFeed retrieveFeed(String cursor, int pageSize, String office, String n
8383
String nextCursor = CwmsDTOPaginated.encodeCursor(items.size() + offset, pageSize);
8484
nextLink = new AtomLink("next", urlBuilder.apply(nextCursor));
8585
}
86-
String description;
87-
switch(aqTable) {
88-
case TS_STORED:
89-
description = " CWMS messages about time series operations, such as data stored and deleted";
90-
break;
91-
case STATUS:
92-
description = " CWMS general system and application status messages";
93-
break;
94-
case REALTIME_OPS:
95-
description = " CWMS application operational messages";
96-
break;
97-
default:
98-
description = null;
99-
}
86+
String description = aqTable.description();
10087
RssChannel channel = new RssChannel(name, nextLink, description, items);
10188
return new RssFeed(channel);
10289
}
10390

104-
private static AqTable getAqTable(String name) {
105-
try {
106-
return AqTable.valueOf(name.toUpperCase());
107-
} catch (IllegalArgumentException e) {
108-
throw new NotFoundException(e);
91+
@SuppressWarnings("unused") // MessageQueue.valueOf can return null. environment is being over zealous.
92+
private static MessageQueue getAqTable(String name) {
93+
MessageQueue ret = MessageQueue.queueFor(name.toUpperCase());
94+
if (ret == null) {
95+
throw new NotFoundException("No queue named '" + name + "'");
10996
}
97+
return ret;
11098
}
11199

112100
private static RssItem rssItem(Record record, String p) {
@@ -116,7 +104,7 @@ private static RssItem rssItem(Record record, String p) {
116104
return new RssItem(p, enqTimestamp, msgId);
117105
}
118106

119-
private Result<?> retrieveMessages(int offset, int pageSize, Instant since, String office, AqTable name) {
107+
private Result<?> retrieveMessages(int offset, int pageSize, Instant since, String office, MessageQueue name) {
120108
Timestamp sinceTimestamp = since == null ? null : Timestamp.from(since);
121109
Table<?> t = table(name("CWMS_20", "AQ$" + office + "_" + name.name() + "_TABLE")).as("t");
122110

cwms-data-api/src/test/java/cwms/cda/api/rss/RssHandlerIT.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737

3838
import com.google.common.flogger.FluentLogger;
3939
import cwms.cda.api.DataApiTestIT;
40+
import cwms.cda.api.enums.MessageQueue;
4041
import cwms.cda.formatters.Formats;
4142
import fixtures.CwmsDataApiSetupCallback;
4243
import fixtures.TestAccounts;
@@ -89,7 +90,7 @@ void test_rss_feed_with_pagination() {
8990
.when()
9091
.redirects().follow(true)
9192
.redirects().max(3)
92-
.get("/rss/" + OFFICE_ID + "/status")
93+
.get("/rss/{office}/{name}", OFFICE_ID, MessageQueue.STATUS.value())
9394
.then()
9495
.log().ifValidationFails(LogDetail.ALL, true)
9596
.assertThat()
@@ -157,7 +158,7 @@ void test_rss_feed_unknown_queue() {
157158
.when()
158159
.redirects().follow(true)
159160
.redirects().max(3)
160-
.get("/rss/" + OFFICE_ID + "/answering-machine")
161+
.get("/rss/{office}/{name}", OFFICE_ID, "answering-machine")
161162
.then()
162163
.log().ifValidationFails(LogDetail.ALL, true)
163164
.assertThat()

0 commit comments

Comments
 (0)