Skip to content

Commit 1bdaf35

Browse files
adamkoryntabuilduser
andauthored
add in missing RSS query parameters (#289)
* add in missing RSS query parameters * Autogenerated JaCoCo coverage badge --------- Co-authored-by: builduser <builduser@rmanet.com>
1 parent 688b8a8 commit 1bdaf35

File tree

6 files changed

+58
-7
lines changed

6 files changed

+58
-7
lines changed

.github/coveragereport/badge_branchcoverage.svg

Lines changed: 1 addition & 1 deletion
Loading

cwms-data-api-client/build.gradle

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* MIT License
33
*
4-
* Copyright (c) 2024 Hydrologic Engineering Center
4+
* Copyright (c) 2025 Hydrologic Engineering Center
55
*
66
* Permission is hereby granted, free of charge, to any person obtaining a copy
77
* of this software and associated documentation files (the "Software"), to deal
@@ -32,6 +32,7 @@ dependencies {
3232
api(project(":cwms-http-client"))
3333
api(project(":cwbi-auth-http-client"))
3434
api(project(":cwms-data-api-model"))
35+
implementation(libs.okhttp)
3536

3637
implementation(libs.swagger.parser)
3738

cwms-data-api-client/src/main/java/mil/army/usace/hec/cwms/data/api/client/controllers/RssController.java

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,25 +24,46 @@
2424

2525
package mil.army.usace.hec.cwms.data.api.client.controllers;
2626

27+
import static mil.army.usace.hec.cwms.data.api.client.controllers.RssEndpointInput.CURSOR_QUERY_PARAMETER;
28+
2729
import java.io.IOException;
30+
import mil.army.usace.hec.cwms.data.api.client.model.AtomLink;
2831
import mil.army.usace.hec.cwms.data.api.client.model.RadarObjectMapper;
2932
import mil.army.usace.hec.cwms.data.api.client.model.RssFeed;
3033
import mil.army.usace.hec.cwms.http.client.ApiConnectionInfo;
3134
import mil.army.usace.hec.cwms.http.client.HttpRequestBuilderImpl;
3235
import mil.army.usace.hec.cwms.http.client.HttpRequestResponse;
3336
import mil.army.usace.hec.cwms.http.client.request.HttpRequestExecutor;
37+
import okhttp3.HttpUrl;
3438

3539
public final class RssController {
3640

37-
private static final String STANDARD_TEXT_ENDPOINT = "rss";
41+
private static final String RSS_ENDPOINT = "rss";
3842

3943
public RssFeed retrieveRssFeed(ApiConnectionInfo apiConnectionInfo, RssEndpointInput.GetAll input)
4044
throws IOException {
41-
HttpRequestExecutor executor = new HttpRequestBuilderImpl(apiConnectionInfo, STANDARD_TEXT_ENDPOINT + "/" + input.officeId() + "/" + input.name())
45+
HttpRequestExecutor executor = new HttpRequestBuilderImpl(apiConnectionInfo, RSS_ENDPOINT + "/" + input.officeId() + "/" + input.name())
4246
.addEndpointInput(input)
4347
.get();
4448
try (HttpRequestResponse response = executor.execute()) {
4549
return RadarObjectMapper.mapXmlToObject(response.getBody(), RssFeed.class);
4650
}
4751
}
52+
53+
public RssFeed retrieveRssFeedFromLink(ApiConnectionInfo apiConnectionInfo, RssEndpointInput.GetAll input, AtomLink link)
54+
throws IOException {
55+
String href = link.getHref();
56+
input.cursor(getCursor(href));
57+
HttpRequestExecutor executor = new HttpRequestBuilderImpl(apiConnectionInfo, RSS_ENDPOINT + "/" + input.officeId() + "/" + input.name())
58+
.addEndpointInput(input)
59+
.get();
60+
try (HttpRequestResponse response = executor.execute()) {
61+
return RadarObjectMapper.mapXmlToObject(response.getBody(), RssFeed.class);
62+
}
63+
}
64+
65+
private String getCursor(String href) {
66+
HttpUrl url = HttpUrl.parse(href);
67+
return (url != null) ? url.queryParameter(CURSOR_QUERY_PARAMETER) : null;
68+
}
4869
}

cwms-data-api-client/src/main/java/mil/army/usace/hec/cwms/data/api/client/controllers/RssEndpointInput.java

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,16 @@
2626

2727
import static mil.army.usace.hec.cwms.data.api.client.controllers.CdaEndpointConstants.ACCEPT_QUERY_HEADER;
2828

29+
import java.time.Instant;
2930
import java.util.Objects;
3031
import mil.army.usace.hec.cwms.http.client.EndpointInput;
3132
import mil.army.usace.hec.cwms.http.client.HttpRequestBuilder;
3233

3334
public final class RssEndpointInput {
3435

3536
static final String RSS_ACCEPT_HEADER = "application/rss+xml";
37+
static final String SINCE_QUERY_PARAMETER = "since";
38+
static final String CURSOR_QUERY_PARAMETER = "cursor";
3639

3740
public static GetAll getAll(String officeId, String name) {
3841
return new GetAll(officeId, name);
@@ -41,6 +44,8 @@ public static GetAll getAll(String officeId, String name) {
4144
public static final class GetAll extends EndpointInput {
4245
private final String officeId;
4346
private final String name;
47+
private Instant since;
48+
private String cursor;
4449

4550
private GetAll(String officeId, String name) {
4651
this.officeId = Objects.requireNonNull(officeId, "Office id required for getAll rss endpoint");
@@ -55,9 +60,21 @@ public String name() {
5560
return name;
5661
}
5762

63+
public GetAll since(Instant since) {
64+
this.since = since;
65+
return this;
66+
}
67+
68+
public GetAll cursor(String cursor) {
69+
this.cursor = cursor;
70+
return this;
71+
}
72+
5873
@Override
5974
protected HttpRequestBuilder addInputParameters(HttpRequestBuilder httpRequestBuilder) {
60-
return httpRequestBuilder.addQueryHeader(ACCEPT_QUERY_HEADER, RSS_ACCEPT_HEADER);
75+
return httpRequestBuilder.addQueryHeader(ACCEPT_QUERY_HEADER, RSS_ACCEPT_HEADER)
76+
.addQueryParameter(SINCE_QUERY_PARAMETER, since == null ? null : since.toString())
77+
.addQueryParameter(CURSOR_QUERY_PARAMETER, cursor);
6178
}
6279
}
6380
}

cwms-data-api-client/src/test/java/mil/army/usace/hec/cwms/data/api/client/controllers/TestRssController.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,10 @@
3737
class TestRssController extends TestController {
3838

3939
@Test
40-
void testRetrieveCatalog() throws IOException {
40+
void testRetrieveMessages() throws IOException {
4141
String collect = readJsonFile("radar/v1/xml/ts_stored.xml");
4242
mockHttpServer.enqueue(collect);
43+
mockHttpServer.enqueue(collect);
4344
mockHttpServer.start();
4445
RssEndpointInput.GetAll input = RssEndpointInput.getAll("SWT", "TS_STORED");
4546
RssFeed rssFeed = new RssController().retrieveRssFeed(buildConnectionInfo(), input);
@@ -54,5 +55,8 @@ void testRetrieveCatalog() throws IOException {
5455
assertNotNull(rssItem.getGuid());
5556
assertNotNull(rssItem.getPubDate());
5657
assertNotNull(rssItem.getDescription());
58+
59+
rssFeed = new RssController().retrieveRssFeedFromLink(buildConnectionInfo(), input, channel.getNextLink());
60+
assertNotNull(rssFeed);
5761
}
5862
}

cwms-data-api-client/src/test/java/mil/army/usace/hec/cwms/data/api/client/controllers/TestRssEndpointInput.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,13 @@
2525
package mil.army.usace.hec.cwms.data.api.client.controllers;
2626

2727
import static mil.army.usace.hec.cwms.data.api.client.controllers.CdaEndpointConstants.ACCEPT_QUERY_HEADER;
28+
import static mil.army.usace.hec.cwms.data.api.client.controllers.RssEndpointInput.CURSOR_QUERY_PARAMETER;
2829
import static mil.army.usace.hec.cwms.data.api.client.controllers.RssEndpointInput.RSS_ACCEPT_HEADER;
30+
import static mil.army.usace.hec.cwms.data.api.client.controllers.RssEndpointInput.SINCE_QUERY_PARAMETER;
2931
import static org.junit.jupiter.api.Assertions.assertEquals;
3032
import static org.junit.jupiter.api.Assertions.assertThrows;
3133

34+
import java.time.Instant;
3235
import org.junit.jupiter.api.Test;
3336

3437
class TestRssEndpointInput {
@@ -44,9 +47,14 @@ void testGetAllQueryRequest() {
4447
MockHttpRequestBuilder mockHttpRequestBuilder = new MockHttpRequestBuilder();
4548
String name = "TS_STORED";
4649
String office = "SPK";
47-
RssEndpointInput.GetAll input = RssEndpointInput.getAll(office, name);
50+
Instant now = Instant.now();
51+
RssEndpointInput.GetAll input = RssEndpointInput.getAll(office, name)
52+
.cursor("ABC")
53+
.since(now);
4854
input.addInputParameters(mockHttpRequestBuilder);
4955
assertEquals(RSS_ACCEPT_HEADER, mockHttpRequestBuilder.getQueryHeader(ACCEPT_QUERY_HEADER));
56+
assertEquals(now.toString(), mockHttpRequestBuilder.getQueryParameter(SINCE_QUERY_PARAMETER));
57+
assertEquals("ABC", mockHttpRequestBuilder.getQueryParameter(CURSOR_QUERY_PARAMETER));
5058
assertEquals(name, input.name());
5159
assertEquals(office, input.officeId());
5260
}

0 commit comments

Comments
 (0)