Skip to content

Commit 053eae0

Browse files
authored
Fix for Entity Controller setup causing build fails. (#1509)
Refactored and cleaned Entity Controller to address clean runner build fail PR #1507. - Fixed entity controller integration tests to incorporate unique data per test - Added test utility helpers for cleanup and unique entityJson test values - Cleaned up global variables to remove hard coded param values - Fixed teardown method to ensure all test entities cleaned up after testing. - Added check in Entity Controller to fix unused documented query param errors and check for required params
1 parent c500e48 commit 053eae0

File tree

4 files changed

+306
-113
lines changed

4 files changed

+306
-113
lines changed

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

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ private Timer.Context markAndTime(String subject) {
5555
},
5656
responses = {
5757
@OpenApiResponse(status = STATUS_200, content = {
58-
@OpenApiContent(isArray = true, from = Entity.class, type = Formats.JSONV2)
58+
@OpenApiContent(isArray = true, from = Entity.class, type = Formats.JSONV1)
5959
})
6060
},
6161
tags = {TAG}
@@ -69,8 +69,14 @@ public void getAll(@NotNull Context ctx) {
6969
String officeId = ctx.queryParam(OFFICE);
7070
String entityId = ctx.queryParam(ENTITY_ID);
7171
String parentId = ctx.queryParam(PARENT_ENTITY_ID);
72-
Boolean matchNullParents = ctx.queryParamAsClass(MATCH_NULL_PARENTS, Boolean.class)
73-
.getOrDefault(true);
72+
Boolean matchNullParents;
73+
if (parentId != null) {
74+
matchNullParents = false;
75+
} else {
76+
matchNullParents = ctx.queryParamAsClass(MATCH_NULL_PARENTS, Boolean.class)
77+
.getOrDefault(true);
78+
}
79+
7480
String categoryId = ctx.queryParam(CATEGORY_ID);
7581
String entityName = ctx.queryParam(LONG_NAME);
7682

@@ -100,7 +106,7 @@ public void getAll(@NotNull Context ctx) {
100106
},
101107
responses = {
102108
@OpenApiResponse(status = STATUS_200, content = {
103-
@OpenApiContent(from = Entity.class, type = Formats.JSONV2)
109+
@OpenApiContent(from = Entity.class, type = Formats.JSONV1)
104110
})
105111
},
106112
tags = {TAG}
@@ -133,7 +139,7 @@ public void getOne(@NotNull Context ctx, @NotNull String entityId) {
133139
description = "Create CWMS Entity",
134140
requestBody = @OpenApiRequestBody(
135141
content = {
136-
@OpenApiContent(from = Entity.class, type = Formats.JSONV2)
142+
@OpenApiContent(from = Entity.class, type = Formats.JSONV1)
137143
},
138144
required = true),
139145
responses = {
@@ -161,16 +167,12 @@ public void create(@NotNull Context ctx) {
161167
@OpenApi(
162168
description = "Update an existing Entity.",
163169
requestBody = @OpenApiRequestBody(
164-
content = {@OpenApiContent(from = Entity.class, type = Formats.JSONV2)},
170+
content = {@OpenApiContent(from = Entity.class, type = Formats.JSONV1)},
165171
required = true),
166172
pathParams = {
167173
@OpenApiParam(name = ENTITY_ID, required = true, description = "Specifies the entity ID of the " +
168174
" Entity to be updated. (e.g., NWS)")
169175
},
170-
queryParams = {
171-
@OpenApiParam(name = OFFICE, required = true, description = "Specifies the owning office "+
172-
" of the entity to be updated. (e.g., SPK)")
173-
},
174176
method = HttpMethod.PATCH,
175177
tags = {TAG},
176178
responses = {
@@ -185,9 +187,12 @@ public void update(@NotNull Context ctx, @NotNull String entityId) {
185187
String formatHeader = ctx.req.getContentType();
186188
ContentType contentType = Formats.parseHeader(formatHeader, Entity.class);
187189
Entity entity = Formats.parseContent(contentType, ctx.bodyAsInputStream(), Entity.class);
188-
if (entity.getId() == null || entity.getId().getOfficeId() == null || entity.getId().getName() == null) {
189-
ctx.status(HttpServletResponse.SC_BAD_REQUEST);
190-
ctx.result("Entity ID and Office ID must be provided in the request body.");
190+
// Validate the office ID and entity ID are provided.
191+
entity.validate();
192+
193+
if (!entityId.equalsIgnoreCase(entity.getId().getName())) {
194+
ctx.status(HttpServletResponse.SC_NOT_FOUND);
195+
ctx.result("Entity ID in path parameter must match the Entity ID in the request body.");
191196
return;
192197
}
193198
EntityDao dao = new EntityDao(dsl);
@@ -196,7 +201,8 @@ public void update(@NotNull Context ctx, @NotNull String entityId) {
196201
}
197202
}
198203

199-
@OpenApi(
204+
205+
@OpenApi(
200206
description = "Delete CWMS Entity.",
201207
pathParams = {
202208
@OpenApiParam(name = ENTITY_ID, required = true, description = "Specifies the entity ID " +

cwms-data-api/src/main/java/cwms/cda/data/dto/Entity.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
import com.fasterxml.jackson.databind.annotation.JsonNaming;
88
import cwms.cda.formatters.Formats;
99
import cwms.cda.formatters.annotations.FormattableWith;
10-
import cwms.cda.formatters.json.JsonV2;
10+
import cwms.cda.formatters.json.JsonV1;
1111

12-
@FormattableWith(contentType = Formats.JSONV2, formatter = JsonV2.class, aliases = {Formats.DEFAULT, Formats.JSON})
12+
@FormattableWith(contentType = Formats.JSONV1, formatter = JsonV1.class, aliases = {Formats.DEFAULT, Formats.JSON})
1313
@JsonDeserialize(builder = Entity.Builder.class)
1414
@JsonInclude(JsonInclude.Include.NON_NULL)
1515
@JsonNaming(PropertyNamingStrategies.KebabCaseStrategy.class)

0 commit comments

Comments
 (0)