Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@

package cwms.cda.api.location.kind;

import static cwms.cda.api.Controllers.CREATE;
import static cwms.cda.api.Controllers.FAIL_IF_EXISTS;
import static cwms.cda.api.Controllers.STATUS_201;

import com.codahale.metrics.MetricRegistry;
import com.codahale.metrics.Timer;
import cwms.cda.api.BaseHandler;
Expand All @@ -44,6 +40,7 @@
import javax.servlet.http.HttpServletResponse;
import org.jetbrains.annotations.NotNull;
import org.jooq.DSLContext;
import static cwms.cda.api.Controllers.*;


public class GateChangeCreateController extends BaseHandler {
Expand All @@ -60,8 +57,13 @@ public GateChangeCreateController(MetricRegistry metrics) {
},
required = true),
queryParams = {
@OpenApiParam(name = FAIL_IF_EXISTS, type = Boolean.class,
description = "Create will fail if provided Gate Changes already exist. Default: true")
@OpenApiParam(name = OVERRIDE_PROTECTION, type = Boolean.class,
description = "A flag ('True'/'False') specifying whether to delete protected data. "
+ "Default is True"),
@OpenApiParam(name = FAIL_IF_EXISTS, type = Boolean.class, deprecated = true,
description = "A flag ('True'/'False') specifying whether to delete protected data. "
+ "Default is True"
+ " Deprecated, use " + OVERRIDE_PROTECTION)
},
description = "Create CWMS Gate Changes",
method = HttpMethod.POST,
Expand All @@ -72,7 +74,7 @@ public GateChangeCreateController(MetricRegistry metrics) {
)
@Override
public void handle(@NotNull Context context) throws Exception {
boolean failIfExists = context.queryParamAsClass(FAIL_IF_EXISTS, Boolean.class).getOrDefault(true);
boolean overrideProtection = queryParamAsClass(context, new String[] { OVERRIDE_PROTECTION, FAIL_IF_EXISTS }, Boolean.class, true);
String formatHeader = context.header(Header.ACCEPT) != null ? context.header(Header.ACCEPT) : Formats.JSONV1;
ContentType contentType = Formats.parseHeader(formatHeader, GateChange.class);
List<GateChange> changes = Formats.parseContentList(contentType, context.body(), GateChange.class);
Expand All @@ -83,7 +85,7 @@ public void handle(@NotNull Context context) throws Exception {
try (Timer.Context ignored = markAndTime(CREATE)) {
DSLContext dsl = JooqDao.getDslContext(context);
OutletDao dao = new OutletDao(dsl);
dao.storeOperationalChanges(changes, failIfExists);
dao.storeOperationalChanges(changes, overrideProtection);
context.status(HttpServletResponse.SC_CREATED);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ void test_changes_crud() {
.contentType(Formats.JSONV1)
.body(json)
.header(AUTH_HEADER, USER.toHeaderValue())
.queryParam(FAIL_IF_EXISTS, "false")
.queryParam(OVERRIDE_PROTECTION, "false")

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps include a test to verify the old query parameter can still be used for the time being

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Integration test implementation will come in a second PR. The problem right now is that it's still updating the record, in spite of a protected flag on the record and an override protection flag of false. Might require a DB change to resolve that issue.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR Created for this here: #1997

.when()
.redirects().follow(true)
.redirects().max(3)
Expand Down Expand Up @@ -212,7 +212,7 @@ void test_changes_crud() {
.contentType(Formats.JSONV1)
.body(json)
.header(AUTH_HEADER, USER.toHeaderValue())
.queryParam(FAIL_IF_EXISTS, "false")
.queryParam(OVERRIDE_PROTECTION, "false")
.when()
.redirects().follow(true)
.redirects().max(3)
Expand Down Expand Up @@ -320,7 +320,7 @@ void test_changes_create_from_file() throws Exception {
.contentType(Formats.JSONV1)
.body(json)
.header(AUTH_HEADER, USER.toHeaderValue())
.queryParam(FAIL_IF_EXISTS, false)
.queryParam(OVERRIDE_PROTECTION, false)
.when()
.redirects().follow(true)
.redirects().max(3)
Expand Down
Loading