Skip to content

Add StatusResponse to last 5 remaining files #1186

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
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 @@ -41,13 +41,15 @@
import static cwms.cda.api.Controllers.SIZE;
import static cwms.cda.api.Controllers.STATION_UNIT;
import static cwms.cda.api.Controllers.STATUS_200;
import static cwms.cda.api.Controllers.STATUS_201;
import static cwms.cda.api.Controllers.STATUS_204;
import static cwms.cda.api.Controllers.STREAM_ID;
import static cwms.cda.api.Controllers.STREAM_ID_MASK;
import static cwms.cda.api.Controllers.UPDATE;
import static cwms.cda.api.Controllers.requiredParam;
import cwms.cda.data.dao.StreamLocationDao;
import cwms.cda.data.dao.StreamReachDao;
import cwms.cda.data.dto.StatusResponse;
import cwms.cda.data.dto.stream.StreamReach;
import cwms.cda.formatters.ContentType;
import cwms.cda.formatters.Formats;
Expand Down Expand Up @@ -182,7 +184,7 @@ public void getOne(@NotNull Context ctx, @NotNull String reachId) {
method = HttpMethod.POST,
tags = {TAG},
responses = {
@OpenApiResponse(status = STATUS_204, description = "Stream Reach successfully stored to CWMS.")
@OpenApiResponse(status = STATUS_201, description = "Stream Reach successfully stored to CWMS.")
}
)
@Override
Expand All @@ -195,7 +197,9 @@ public void create(@NotNull Context ctx) {
DSLContext dsl = getDslContext(ctx);
StreamReachDao dao = new StreamReachDao(dsl);
dao.storeStreamReach(streamReach, failIfExists);
ctx.status(HttpServletResponse.SC_CREATED).json("Created Stream Reach");
StatusResponse re = new StatusResponse(streamReach.getStreamId().getOfficeId(), "Stream Reach successfully stored to CWMS.",
streamReach.getStreamId().getName());
ctx.status(HttpServletResponse.SC_CREATED).json(re);
}
}

Expand All @@ -213,7 +217,7 @@ public void create(@NotNull Context ctx) {
method = HttpMethod.PATCH,
tags = {TAG},
responses = {
@OpenApiResponse(status = STATUS_204, description = "Stream Reach successfully renamed in CWMS.")
@OpenApiResponse(status = STATUS_200, description = "Stream Reach successfully renamed in CWMS.")
}
)
@Override
Expand All @@ -224,7 +228,8 @@ public void update(@NotNull Context ctx, @NotNull String reachId) {
DSLContext dsl = getDslContext(ctx);
StreamReachDao dao = new StreamReachDao(dsl);
dao.renameStreamReach(office, reachId, newReachId);
ctx.status(HttpServletResponse.SC_OK).json("Renamed Stream Reach");
StatusResponse re = new StatusResponse(office, "Stream Reach successfully renamed in CWMS.", newReachId);
ctx.status(HttpServletResponse.SC_OK).json(re);
}
}

Expand All @@ -251,7 +256,9 @@ public void delete(@NotNull Context ctx, @NotNull String reachId) {
DSLContext dsl = getDslContext(ctx);
StreamReachDao dao = new StreamReachDao(dsl);
dao.deleteStreamReach(office, reachId);
ctx.status(HttpServletResponse.SC_OK).json("Deleted Stream Reach");
StatusResponse re = new StatusResponse(office, "Stream Reach successfully deleted from CWMS.",
reachId);
ctx.status(HttpServletResponse.SC_OK).json(re);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
import cwms.cda.api.enums.UnitSystem;
import cwms.cda.data.dao.location.kind.TurbineDao;
import cwms.cda.data.dto.CwmsId;
import cwms.cda.data.dto.StatusResponse;
import cwms.cda.data.dto.location.kind.TurbineChange;
import cwms.cda.formatters.ContentType;
import cwms.cda.formatters.Formats;
Expand Down Expand Up @@ -105,7 +106,7 @@ private Timer.Context markAndTime(String subject) {
method = HttpMethod.DELETE,
tags = {TurbineController.TAG},
responses = {
@OpenApiResponse(status = STATUS_204, description = "Turbine successfully deleted from CWMS."),
@OpenApiResponse(status = STATUS_200, description = "Turbine successfully deleted from CWMS."),
@OpenApiResponse(status = STATUS_404, description = "Based on the combination of "
+ "inputs provided the project was not found.")
}
Expand All @@ -125,7 +126,8 @@ public void handle(@NotNull Context ctx) throws Exception {
.withOfficeId(office)
.build();
dao.deleteOperationalChanges(cwmsId, begin, end, overrideProtection);
ctx.status(HttpServletResponse.SC_NO_CONTENT).json(projectId + " Deleted");
StatusResponse re = new StatusResponse(office, "Turbine successfully deleted from CWMS.", projectId);
ctx.status(HttpServletResponse.SC_OK).json(re);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import static cwms.cda.api.Controllers.SIZE;
import static cwms.cda.api.Controllers.START_TIME_INCLUSIVE;
import static cwms.cda.api.Controllers.STATUS_200;
import static cwms.cda.api.Controllers.STATUS_201;
import static cwms.cda.api.Controllers.STATUS_204;
import static cwms.cda.api.Controllers.STATUS_404;
import static cwms.cda.api.Controllers.UNIT_SYSTEM;
Expand All @@ -54,6 +55,7 @@
import cwms.cda.api.errors.CdaError;
import cwms.cda.data.dao.location.kind.TurbineDao;
import cwms.cda.data.dto.CwmsId;
import cwms.cda.data.dto.StatusResponse;
import cwms.cda.data.dto.location.kind.TurbineChange;
import cwms.cda.formatters.ContentType;
import cwms.cda.formatters.Formats;
Expand Down Expand Up @@ -107,7 +109,7 @@ private Timer.Context markAndTime(String subject) {
method = HttpMethod.POST,
tags = {TurbineController.TAG},
responses = {
@OpenApiResponse(status = STATUS_204, description = "Turbine successfully stored to CWMS."),
@OpenApiResponse(status = STATUS_201, description = "Turbine successfully stored to CWMS."),
@OpenApiResponse(status = STATUS_404, description = "Project Id or Turbine location Ids not found.")
}
)
Expand All @@ -122,7 +124,8 @@ public void handle(@NotNull Context ctx) throws Exception {
DSLContext dsl = getDslContext(ctx);
TurbineDao dao = new TurbineDao(dsl);
dao.storeOperationalChanges(turbine, overrideProtection);
ctx.status(HttpServletResponse.SC_CREATED).json("Created Turbine Changes");
StatusResponse re = new StatusResponse(turbine.get(0).getProjectId().getOfficeId(), "Created Turbine Changes");
ctx.status(HttpServletResponse.SC_CREATED).json(re);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import cwms.cda.api.errors.CdaError;
import cwms.cda.data.dao.JooqDao;
import cwms.cda.data.dao.location.kind.OutletDao;
import cwms.cda.data.dto.StatusResponse;
import cwms.cda.data.dto.location.kind.VirtualOutlet;
import cwms.cda.formatters.ContentType;
import cwms.cda.formatters.Formats;
Expand Down Expand Up @@ -155,7 +156,7 @@ public void update(@NotNull Context ctx, @NotNull String s) {
method = HttpMethod.DELETE,
tags = {OutletController.TAG},
responses = {
@OpenApiResponse(status = STATUS_204, description = "Virtual Outlet successfully deleted from CWMS."),
@OpenApiResponse(status = STATUS_200, description = "Virtual Outlet successfully deleted from CWMS."),
@OpenApiResponse(status = STATUS_404, description = "Based on the combination of "
+ "inputs provided the virtual outlet was not found.")
}
Expand All @@ -170,7 +171,8 @@ public void delete(@NotNull Context ctx, @NotNull String name) {
DSLContext dsl = getDslContext(ctx);
OutletDao dao = new OutletDao(dsl);
dao.deleteVirtualOutlet(office, projectId, name, deleteMethod.getRule());
ctx.status(HttpServletResponse.SC_NO_CONTENT).json(name + " Deleted");
StatusResponse re = new StatusResponse(office, "Virtual Outlet successfully deleted from CWMS.", name);
ctx.status(HttpServletResponse.SC_OK).json(re);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import com.codahale.metrics.Timer;
import cwms.cda.api.BaseHandler;
import cwms.cda.data.dao.location.kind.OutletDao;
import cwms.cda.data.dto.StatusResponse;
import cwms.cda.data.dto.location.kind.VirtualOutlet;
import cwms.cda.formatters.ContentType;
import cwms.cda.formatters.Formats;
Expand Down Expand Up @@ -74,7 +75,9 @@ public void handle(@NotNull Context ctx) throws Exception {
DSLContext dsl = getDslContext(ctx);
OutletDao dao = new OutletDao(dsl);
dao.storeVirtualOutlet(virtualOutlet, failIfExists);
ctx.status(HttpServletResponse.SC_CREATED).json("Created Outlet");
StatusResponse re = new StatusResponse(virtualOutlet.getVirtualOutletId().getOfficeId(),
"Virtual Outlet successfully stored to CWMS.", virtualOutlet.getVirtualOutletId().getName());
ctx.status(HttpServletResponse.SC_CREATED).json(re);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
import cwms.cda.data.dao.RatingDao;
import cwms.cda.data.dao.RatingSetDao;
import cwms.cda.data.dto.CwmsDTOBase;
import cwms.cda.data.dto.StatusResponse;
import cwms.cda.formatters.ContentType;
import cwms.cda.formatters.Formats;
import cwms.cda.formatters.annotations.FormattableWith;
Expand Down Expand Up @@ -147,7 +148,8 @@ public void create(@NotNull Context ctx) {
boolean storeTemplate = ctx.queryParamAsClass(STORE_TEMPLATE, Boolean.class).getOrDefault(true);
String ratingSet = deserializeRatingSet(ctx, storeTemplate);
ratingDao.create(ratingSet, false);
ctx.status(HttpServletResponse.SC_OK).json("Created RatingSet");
StatusResponse re = new StatusResponse(RatingDao.extractOfficeFromXml(ratingSet), "Created RatingSet");
ctx.status(HttpServletResponse.SC_OK).json(re);
} catch (IOException ex) {
CdaError re = new CdaError("Failed to process request to update RatingSet");
logger.log(Level.SEVERE, re.toString(), ex);
Expand Down Expand Up @@ -500,7 +502,8 @@ public void update(@NotNull Context ctx, @NotNull String ratingId) {
.getOrDefault(false);
String ratingSet = deserializeRatingSet(ctx, storeTemplate);
ratingDao.store(ratingSet, replaceBaseCurve);
ctx.status(HttpServletResponse.SC_OK).json("Updated RatingSet");
StatusResponse re = new StatusResponse(RatingDao.extractOfficeFromXml(ratingSet), "Updated RatingSet");
ctx.status(HttpServletResponse.SC_OK).json(re);
} catch (IOException ex) {
CdaError re = new CdaError("Failed to process request to update RatingSet");
logger.log(Level.SEVERE, re.toString(), ex);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import static cwms.cda.api.Controllers.CONTRACT_NAME;
import static cwms.cda.api.Controllers.CREATE;
import static cwms.cda.api.Controllers.OFFICE;
import static cwms.cda.api.Controllers.STATUS_204;
import static cwms.cda.api.Controllers.STATUS_200;
import static cwms.cda.api.Controllers.STATUS_501;
import static cwms.cda.api.Controllers.WATER_USER;
import static cwms.cda.data.dao.JooqDao.getDslContext;
Expand All @@ -40,6 +40,7 @@
import cwms.cda.data.dao.LookupTypeDao;
import cwms.cda.data.dao.watersupply.WaterSupplyAccountingDao;
import cwms.cda.data.dto.LookupType;
import cwms.cda.data.dto.StatusResponse;
import cwms.cda.data.dto.watersupply.PumpTransfer;
import cwms.cda.data.dto.watersupply.WaterSupplyAccounting;
import cwms.cda.formatters.ContentType;
Expand Down Expand Up @@ -93,7 +94,7 @@ protected WaterSupplyAccountingDao getWaterSupplyAccountingDao(DSLContext dsl) {
+ "accounting.", required = true),
},
responses = {
@OpenApiResponse(status = STATUS_204, description = "The pump accounting entry was created."),
@OpenApiResponse(status = STATUS_200, description = "The pump accounting entry was created."),
@OpenApiResponse(status = STATUS_501, description = "Requested format is not implemented")
},
description = "Create a new pump accounting entry associated with a water supply contract.",
Expand Down Expand Up @@ -132,7 +133,8 @@ public void handle(@NotNull Context ctx) {
}

waterSupplyAccountingDao.storeAccounting(accounting);
ctx.status(HttpServletResponse.SC_CREATED).json(contractId + " created successfully");
StatusResponse re = new StatusResponse(office, "The pump accounting entry was created.", contractId);
ctx.status(HttpServletResponse.SC_CREATED).json(re);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@
import java.util.List;
import mil.army.usace.hec.test.database.CwmsDatabaseContainer;
import org.apache.commons.io.IOUtils;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.is;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Tag;
Expand All @@ -61,6 +59,7 @@

import static cwms.cda.security.ApiKeyIdentityProvider.AUTH_HEADER;
import static io.restassured.RestAssured.given;
import static org.hamcrest.Matchers.*;
import static org.junit.jupiter.api.Assertions.assertNotNull;

@Tag("integration")
Expand All @@ -69,6 +68,9 @@ final class StreamReachControllerTestIT extends DataApiTestIT {
private static final String OFFICE_ID = TestAccounts.KeyUser.SPK_NORMAL.getOperatingOffice();
private static final List<Stream> STREAMS_CREATED = new ArrayList<>();
private static final List<StreamLocation> STREAM_LOCATIONS_CREATED = new ArrayList<>();
private static final String OFFICE_ID_TEXT = "office-id";
private static final String MESSAGE = "message";
private static final String IDENTIFIER = "identifier";

@BeforeAll
public static void setup() throws SQLException {
Expand Down Expand Up @@ -196,7 +198,10 @@ void test_get_create_delete() throws IOException {
.then()
.log().ifValidationFails(LogDetail.ALL, true)
.assertThat()
.statusCode(is(HttpServletResponse.SC_CREATED));
.statusCode(is(HttpServletResponse.SC_CREATED))
.body(OFFICE_ID, equalTo(streamReach.getStreamId().getOfficeId()))
.body(MESSAGE, equalTo("Stream Reach successfully stored to CWMS."))
.body(IDENTIFIER, equalTo(streamReach.getStreamId().getName()));

String streamReachId = streamReach.getId().getName();

Expand Down Expand Up @@ -251,7 +256,10 @@ void test_get_create_delete() throws IOException {
.then()
.log().ifValidationFails(LogDetail.ALL, true)
.assertThat()
.statusCode(is(HttpServletResponse.SC_OK));
.statusCode(is(HttpServletResponse.SC_OK))
.body(OFFICE_ID, equalTo(streamReach.getStreamId().getOfficeId()))
.body(MESSAGE, equalTo("Stream Reach successfully deleted from CWMS."))
.body(IDENTIFIER, equalTo(streamReach.getStreamId().getName()));

// Retrieve the StreamReach and assert that it does not exist
given()
Expand Down Expand Up @@ -335,7 +343,10 @@ void test_get_all() throws IOException {
.then()
.log().ifValidationFails(LogDetail.ALL, true)
.assertThat()
.statusCode(is(HttpServletResponse.SC_CREATED));
.statusCode(is(HttpServletResponse.SC_CREATED))
.body(OFFICE_ID, equalTo(streamReach.getStreamId().getOfficeId()))
.body(MESSAGE, equalTo("Stream Reach successfully stored to CWMS."))
.body(IDENTIFIER, equalTo(streamReach.getStreamId().getName()));

String office = streamReach.getId().getOfficeId();
String streamReachId = streamReach.getId().getName();
Expand Down Expand Up @@ -391,7 +402,10 @@ void test_get_all() throws IOException {
.then()
.log().ifValidationFails(LogDetail.ALL, true)
.assertThat()
.statusCode(is(HttpServletResponse.SC_OK));
.statusCode(is(HttpServletResponse.SC_OK))
.body(OFFICE_ID, equalTo(streamReach.getStreamId().getOfficeId()))
.body(MESSAGE, equalTo("Stream Reach successfully deleted from CWMS."))
.body(IDENTIFIER, equalTo(streamReach.getStreamId().getName()));

//verify deletion
given()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import static io.restassured.RestAssured.given;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.isEmptyString;
import static org.hamcrest.Matchers.not;
import static org.hamcrest.Matchers.nullValue;

Expand Down Expand Up @@ -75,6 +76,9 @@ final class TurbineChangesControllerIT extends DataApiTestIT {
private static final Location TURBINE_LOC;
private static final Turbine TURBINE;
private static final List<TurbineChange> TURBINE_CHANGES;
private static final String OFFICE_ID = "office-id";
private static final String MESSAGE = "message";
private static final String IDENTIFIER = "identifier";

static {
Class<TurbineChangesControllerIT> c = TurbineChangesControllerIT.class;
Expand Down Expand Up @@ -156,6 +160,9 @@ void test_get_create_delete() {
.log().ifValidationFails(LogDetail.ALL, true)
.assertThat()
.statusCode(is(HttpServletResponse.SC_CREATED))
.body(OFFICE_ID, equalTo(PROJECT_LOC.getOfficeId()))
.body(MESSAGE, equalTo("Created Turbine Changes"))
.body(IDENTIFIER, isEmptyString())
;
String office = TURBINE.getLocation().getOfficeId();

Expand Down Expand Up @@ -198,7 +205,10 @@ void test_get_create_delete() {
.then()
.log().ifValidationFails(LogDetail.ALL,true)
.assertThat()
.statusCode(is(HttpServletResponse.SC_NO_CONTENT))
.statusCode(is(HttpServletResponse.SC_OK))
.body(OFFICE_ID, equalTo(PROJECT_LOC.getOfficeId()))
.body(MESSAGE, equalTo("Turbine successfully deleted from CWMS."))
.body(IDENTIFIER, equalTo(PROJECT_LOC.getName()))
;


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ class WaterSupplyAccountingControllerIT extends DataApiTestIT {
private static Location pump1;
private static Location pump2;
private static Location pump3;
private static final String OFFICE_ID_TEXT = "office-id";
private static final String MESSAGE = "message";
private static final String IDENTIFIER = "identifier";

static {
try (InputStream accountStream = WaterSupplyAccounting.class
Expand Down Expand Up @@ -292,6 +295,9 @@ void testCreateRetrieveWaterAccounting() throws Exception {
.log().ifValidationFails(LogDetail.ALL, true)
.assertThat()
.statusCode(is(HttpServletResponse.SC_CREATED))
.body(OFFICE_ID_TEXT, equalTo(OFFICE_ID))
.body(MESSAGE, equalTo("The pump accounting entry was created."))
.body(IDENTIFIER, equalTo(contract.getContractId().getName()))
;

// retrieve pump accounting
Expand Down Expand Up @@ -354,6 +360,9 @@ void testRetrieveNotFoundOutsideTimeWindow() throws Exception {
.log().ifValidationFails(LogDetail.ALL, true)
.assertThat()
.statusCode(is(HttpServletResponse.SC_CREATED))
.body(OFFICE_ID_TEXT, equalTo(OFFICE_ID))
.body(MESSAGE, equalTo("The pump accounting entry was created."))
.body(IDENTIFIER, equalTo(contract.getContractId().getName()))
;

// retrieve pump accounting
Expand Down
Loading