diff --git a/cwms-data-api/src/main/java/cwms/cda/api/location/kind/GateChangeCreateController.java b/cwms-data-api/src/main/java/cwms/cda/api/location/kind/GateChangeCreateController.java index c9c92b09f..05f132965 100644 --- a/cwms-data-api/src/main/java/cwms/cda/api/location/kind/GateChangeCreateController.java +++ b/cwms-data-api/src/main/java/cwms/cda/api/location/kind/GateChangeCreateController.java @@ -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; @@ -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 { @@ -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, @@ -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 changes = Formats.parseContentList(contentType, context.body(), GateChange.class); @@ -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); } } diff --git a/cwms-data-api/src/test/java/cwms/cda/api/location/kind/GateChangeControllerTestIT.java b/cwms-data-api/src/test/java/cwms/cda/api/location/kind/GateChangeControllerTestIT.java index 65262fa31..15359bf36 100644 --- a/cwms-data-api/src/test/java/cwms/cda/api/location/kind/GateChangeControllerTestIT.java +++ b/cwms-data-api/src/test/java/cwms/cda/api/location/kind/GateChangeControllerTestIT.java @@ -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") .when() .redirects().follow(true) .redirects().max(3) @@ -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) @@ -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)