Skip to content

Commit

Permalink
Merge branch 'main' into dependabot/github_actions/alldependencies-c3…
Browse files Browse the repository at this point in the history
…b804ca35
  • Loading branch information
adamkorynta authored Nov 22, 2024
2 parents e26b9f7 + f7fd387 commit d5d9ca3
Show file tree
Hide file tree
Showing 32 changed files with 6,853 additions and 2,613 deletions.
2 changes: 1 addition & 1 deletion .github/coveragereport/badge_branchcoverage.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion .github/coveragereport/badge_linecoverage.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion .github/coveragereport/badge_methodcoverage.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,23 @@

public final class LocationGroupEndpointInput {

private LocationGroupEndpointInput() {
throw new AssertionError("factory class");
}

static final String OFFICE_QUERY_PARAMETER = "office";
static final String GROUP_ID_QUERY_PARAMETER = "group-id";
static final String CATEGORY_ID_LIKE_QUERY_PARAMETER = "location-category-like";
static final String CATEGORY_ID_QUERY_PARAMETER = "category-id";
static final String INCLUDE_ASSIGNED_QUERY_PARAMETER = "include-assigned";
static final String REPLACE_ASSIGNED_LOCS = "replace-assigned-locs";
static final String GROUP_OFFICE_ID_QUERY_PARAMETER = "group-office-id";
static final String LOCATION_OFFICE_ID_QUERY_PARAMETER = "location-office-id";
static final String CATEGORY_OFFICE_ID_QUERY_PARAMETER = "category-office-id";
static final String CASCADE_DELETE_QUERY_PARAMETER = "cascade-delete";

public static GetOne getOne(String categoryId, String groupId, String officeId) {
return new GetOne(categoryId, groupId, officeId);
public static GetOne getOne(String categoryId, String groupId, String officeId, String groupOfficeId, String categoryOfficeId) {
return new GetOne(categoryId, groupId, officeId, groupOfficeId, categoryOfficeId);
}

public static GetAll getAll() {
Expand All @@ -53,23 +61,27 @@ public static Post post(LocationGroup locationGroup) {
return new Post(locationGroup);
}

public static Patch patch(String originalGroupId, LocationGroup locationGroup) {
return new Patch(originalGroupId, locationGroup);
public static Patch patch(String groupOfficeId, String originalGroupId, LocationGroup locationGroup) {
return new Patch(groupOfficeId, originalGroupId, locationGroup);
}

public static Delete delete(String categoryId, String groupId, String officeId) {
return new Delete(categoryId, groupId, officeId);
public static Delete delete(String categoryId, String groupId, String groupOfficeId) {
return new Delete(categoryId, groupId, groupOfficeId);
}

public static final class GetOne extends EndpointInput {
private final String groupId;
private final String officeId;
private final String categoryId;
private final String groupOfficeId;
private final String categoryOfficeId;

private GetOne(String categoryId, String groupId, String officeId) {
private GetOne(String categoryId, String groupId, String officeId, String groupOfficeId, String categoryOfficeId) {
this.categoryId = Objects.requireNonNull(categoryId, "Cannot retrieve a location group without a category id");
this.groupId = Objects.requireNonNull(groupId, "Cannot retrieve a location group without a group id");
this.officeId = Objects.requireNonNull(officeId, "Cannot retrieve a location group without an office id");
this.groupOfficeId = Objects.requireNonNull(groupOfficeId, "Cannot retrieve a location group without a group office id");
this.categoryOfficeId = Objects.requireNonNull(categoryOfficeId, "Cannot retrieve a location group without a category office id");
}

String groupId() {
Expand All @@ -81,21 +93,25 @@ protected HttpRequestBuilder addInputParameters(HttpRequestBuilder httpRequestBu
return httpRequestBuilder.addQueryParameter(GROUP_ID_QUERY_PARAMETER, groupId)
.addQueryParameter(OFFICE_QUERY_PARAMETER, officeId)
.addQueryParameter(CATEGORY_ID_QUERY_PARAMETER, categoryId)
.addQueryParameter(GROUP_OFFICE_ID_QUERY_PARAMETER, groupOfficeId)
.addQueryParameter(CATEGORY_OFFICE_ID_QUERY_PARAMETER, categoryOfficeId)
.addQueryHeader(ACCEPT_QUERY_HEADER, ACCEPT_HEADER_JSON);
}
}

public static final class GetAll extends EndpointInput {
private String officeId;
private String locationOfficeId;
private String groupOfficeId;
private String categoryOfficeId;
private boolean includeAssigned = false;
private String categoryIdMask;

private GetAll() {

}

public GetAll officeId(String officeId) {
this.officeId = officeId;
public GetAll locationOfficeId(String locationOfficeId) {
this.locationOfficeId = locationOfficeId;
return this;
}

Expand All @@ -109,11 +125,24 @@ public GetAll categoryIdMask(String categoryIdMask) {
return this;
}

public GetAll groupOfficeId(String groupOfficeId) {
this.groupOfficeId = groupOfficeId;
return this;
}

public GetAll categoryOfficeId(String categoryOfficeId) {
this.categoryOfficeId = categoryOfficeId;
return this;
}

@Override
protected HttpRequestBuilder addInputParameters(HttpRequestBuilder httpRequestBuilder) {
return httpRequestBuilder.addQueryParameter(OFFICE_QUERY_PARAMETER, officeId)
return httpRequestBuilder.addQueryParameter(OFFICE_QUERY_PARAMETER, groupOfficeId)
.addQueryParameter(INCLUDE_ASSIGNED_QUERY_PARAMETER, Boolean.toString(includeAssigned))
.addQueryParameter(CATEGORY_OFFICE_ID_QUERY_PARAMETER, categoryOfficeId)
.addQueryParameter(LOCATION_OFFICE_ID_QUERY_PARAMETER, locationOfficeId)
.addQueryParameter(CATEGORY_ID_LIKE_QUERY_PARAMETER, categoryIdMask)
.addQueryParameter(CATEGORY_OFFICE_ID_QUERY_PARAMETER, categoryOfficeId)
.addQueryHeader(ACCEPT_QUERY_HEADER, ACCEPT_HEADER_JSON);
}

Expand Down Expand Up @@ -142,11 +171,13 @@ public static final class Patch extends EndpointInput {

private final LocationGroup locationGroup;
private final String originalGroupId;
private boolean replaceAssignedLocs;
private boolean replaceAssignedLocs = false;
private final String groupOfficeId;

private Patch(String originalGroupId, LocationGroup locationGroup) {
private Patch(String groupOfficeId, String originalGroupId, LocationGroup locationGroup) {
this.originalGroupId = Objects.requireNonNull(originalGroupId, "Cannot update a location group without an original group id");
this.locationGroup = Objects.requireNonNull(locationGroup, "Cannot update a location group without a data object");
this.groupOfficeId = Objects.requireNonNull(groupOfficeId, "Cannot update a location group without an operating office id");
}

String originalGroupId() {
Expand All @@ -165,6 +196,7 @@ public Patch replaceAssignedLocs(boolean replaceAssignedLocs) {
@Override
protected HttpRequestBuilder addInputParameters(HttpRequestBuilder httpRequestBuilder) {
return httpRequestBuilder.addQueryParameter(REPLACE_ASSIGNED_LOCS, Boolean.toString(replaceAssignedLocs))
.addQueryParameter(OFFICE_QUERY_PARAMETER, groupOfficeId)
.addQueryHeader(ACCEPT_QUERY_HEADER, ACCEPT_HEADER_JSON);
}

Expand All @@ -173,24 +205,31 @@ protected HttpRequestBuilder addInputParameters(HttpRequestBuilder httpRequestBu
public static final class Delete extends EndpointInput {

private final String groupId;
private final String officeId;
private final String groupOfficeId;
private final String categoryId;
private boolean cascadeDelete = false;

private Delete(String categoryId, String groupId, String officeId) {
private Delete(String categoryId, String groupId, String groupOfficeId) {
this.categoryId = Objects.requireNonNull(categoryId, "Cannot delete a location group without a category id");
this.groupId = Objects.requireNonNull(groupId, "Cannot delete a location group without a group id");
this.officeId = Objects.requireNonNull(officeId, "Cannot delete a location group without an office id");
this.groupOfficeId = Objects.requireNonNull(groupOfficeId, "Cannot delete a location group without an office id");
}

String groupId() {
return groupId;
}

public Delete cascadeDelete(boolean cascadeDelete) {
this.cascadeDelete = cascadeDelete;
return this;
}

@Override
protected HttpRequestBuilder addInputParameters(HttpRequestBuilder httpRequestBuilder) {
return httpRequestBuilder.addQueryParameter(GROUP_ID_QUERY_PARAMETER, groupId)
.addQueryParameter(OFFICE_QUERY_PARAMETER, officeId)
.addQueryParameter(OFFICE_QUERY_PARAMETER, groupOfficeId)
.addQueryParameter(CATEGORY_ID_QUERY_PARAMETER, categoryId)
.addQueryParameter(CASCADE_DELETE_QUERY_PARAMETER, Boolean.toString(cascadeDelete))
.addQueryHeader(ACCEPT_QUERY_HEADER, ACCEPT_HEADER_JSON);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package mil.army.usace.hec.cwms.radar.client.controllers;

import static mil.army.usace.hec.cwms.radar.client.controllers.RadarEndpointConstants.ACCEPT_HEADER_V1;
import static mil.army.usace.hec.cwms.radar.client.controllers.RadarEndpointConstants.ACCEPT_QUERY_HEADER;

import java.io.IOException;
import java.util.List;
import mil.army.usace.hec.cwms.http.client.ApiConnectionInfo;
import mil.army.usace.hec.cwms.http.client.HttpRequestBuilderImpl;
import mil.army.usace.hec.cwms.http.client.HttpRequestResponse;
import mil.army.usace.hec.cwms.http.client.request.HttpRequestExecutor;
import mil.army.usace.hec.cwms.radar.client.model.Lock;
import mil.army.usace.hec.cwms.radar.client.model.RadarObjectMapper;


public final class LockController {
private static final String LOCK_ENDPOINT = "projects/locks";

public Lock retrieveLock(ApiConnectionInfo apiConnectionInfo, LockEndpointInput.GetOne input) throws IOException {
HttpRequestExecutor executor = new HttpRequestBuilderImpl(apiConnectionInfo, LOCK_ENDPOINT + "/" + input.lockName())
.addQueryHeader(ACCEPT_QUERY_HEADER, ACCEPT_HEADER_V1)
.addEndpointInput(input)
.get()
.withMediaType(ACCEPT_HEADER_V1);
try (HttpRequestResponse response = executor.execute()) {
return RadarObjectMapper.mapJsonToObject(response.getBody(), Lock.class);
}
}

public void storeLock(ApiConnectionInfo apiConnectionInfo, LockEndpointInput.Post input) throws IOException {
String body = RadarObjectMapper.mapObjectToJson(input.lock());
new HttpRequestBuilderImpl(apiConnectionInfo, LOCK_ENDPOINT)
.addQueryHeader(ACCEPT_QUERY_HEADER, ACCEPT_HEADER_V1)
.addEndpointInput(input)
.post()
.withBody(body)
.withMediaType(ACCEPT_HEADER_V1)
.execute()
.close();
}

public void renameLock(ApiConnectionInfo apiConnectionInfo, LockEndpointInput.Patch input) throws IOException {
new HttpRequestBuilderImpl(apiConnectionInfo, LOCK_ENDPOINT + "/" + input.oldLockName())
.addQueryHeader(ACCEPT_QUERY_HEADER, ACCEPT_HEADER_V1)
.addEndpointInput(input)
.patch()
.withMediaType(ACCEPT_HEADER_V1)
.execute()
.close();
}

public void deleteLock(ApiConnectionInfo apiConnectionInfo, LockEndpointInput.Delete input) throws IOException {
new HttpRequestBuilderImpl(apiConnectionInfo, LOCK_ENDPOINT + "/" + input.lockName())
.addQueryHeader(ACCEPT_QUERY_HEADER, ACCEPT_HEADER_V1)
.addEndpointInput(input)
.delete()
.withMediaType(ACCEPT_HEADER_V1)
.execute()
.close();
}

public List<Lock> retrieveLocks(ApiConnectionInfo apiConnectionInfo, LockEndpointInput.GetAll input) throws IOException {
HttpRequestExecutor executor = new HttpRequestBuilderImpl(apiConnectionInfo, LOCK_ENDPOINT)
.addQueryHeader(ACCEPT_QUERY_HEADER, ACCEPT_HEADER_V1)
.addEndpointInput(input)
.get()
.withMediaType(ACCEPT_HEADER_V1);
try (HttpRequestResponse response = executor.execute()) {
return RadarObjectMapper.mapJsonToListOfObjects(response.getBody(), Lock.class);
}
}
}
Loading

0 comments on commit d5d9ca3

Please sign in to comment.