use of cwms.radar.data.dto.basinconnectivity.Basin in project cwms-radar-api by USACE.
the class NamedPgJsonFormatter method format.
@Override
public String format(CwmsDTO dto) {
String retVal;
try {
if (dto instanceof Basin) {
Basin basin = (Basin) dto;
Graph graph = new BasinConnectivityGraph.Builder(basin).build();
String name = basin.getBasinName();
retVal = formatNamedGraph(name, graph);
} else {
throw new FormattingException(dto.getClass().getSimpleName() + " is not currently supported for Named-PG-JSON format.");
}
} catch (JsonProcessingException e) {
throw new FormattingException(e.getMessage());
}
return retVal;
}
use of cwms.radar.data.dto.basinconnectivity.Basin in project cwms-radar-api by USACE.
the class PgJsonFormatter method format.
@Override
public String format(CwmsDTO dto) {
String retVal;
Graph graph;
if (dto instanceof Basin) {
Basin basin = (Basin) dto;
graph = new BasinConnectivityGraph.Builder(basin).build();
} else {
throw new FormattingException(dto.getClass().getSimpleName() + " is not currently supported for PG-JSON format.");
}
try {
retVal = formatGraph(graph);
} catch (JsonProcessingException e) {
throw new FormattingException(e.getMessage());
}
return retVal;
}
use of cwms.radar.data.dto.basinconnectivity.Basin in project cwms-radar-api by USACE.
the class BasinController method getAll.
@OpenApi(queryParams = { @OpenApiParam(name = "office", required = false, description = "Specifies the owning office of the basin whose data is to be included in the response. If this field is not specified, matching basin information from all offices shall be returned."), @OpenApiParam(name = "unit", required = false, description = "Specifies the unit or unit system of the response. Valid values for the unit field are:\r\n 1. EN. Specifies English unit system. Basin values will be in the default English units for their parameters. (This is default if no value is entered)\r\n2. SI. Specifies the SI unit system. Basin values will be in the default SI units for their parameters.") }, responses = { @OpenApiResponse(status = "200", content = { @OpenApiContent(from = Basin.class, type = Formats.NAMED_PGJSON) }), @OpenApiResponse(status = "404", description = "The provided combination of parameters did not find a basin."), @OpenApiResponse(status = "501", description = "Requested format is not implemented") }, description = "Returns CWMS Basin Data", tags = { TAG })
@Override
public void getAll(@NotNull Context ctx) {
getAllRequests.mark();
try (final Timer.Context timeContext = getAllRequestsTime.time();
DSLContext dsl = getDslContext(ctx)) {
String units = ctx.queryParamAsClass("unit", String.class).getOrDefault(UnitSystem.EN.value());
String office = ctx.queryParam("office");
String formatHeader = ctx.header(Header.ACCEPT) != null ? ctx.header(Header.ACCEPT) : Formats.NAMED_PGJSON;
ContentType contentType = Formats.parseHeader(formatHeader);
ctx.contentType(contentType.toString());
BasinDao basinDao = new BasinDao(dsl);
List<Basin> basins = basinDao.getAllBasins(units, office);
if (contentType.getType().equals(Formats.NAMED_PGJSON)) {
NamedPgJsonFormatter basinPgJsonFormatter = new NamedPgJsonFormatter();
String result = basinPgJsonFormatter.format(basins);
ctx.result(result);
}
} catch (SQLException ex) {
LOGGER.log(Level.SEVERE, "Error retrieving all basins", ex);
}
}
use of cwms.radar.data.dto.basinconnectivity.Basin in project cwms-radar-api by USACE.
the class BasinController method getOne.
@OpenApi(queryParams = { @OpenApiParam(name = "office", required = false, description = "Specifies the owning office of the basin whose data is to be included in the response. If this field is not specified, matching basin information from all offices shall be returned."), @OpenApiParam(name = "unit", required = false, description = "Specifies the unit or unit system of the response. Valid values for the unit field are:\r\n 1. EN. Specifies English unit system. Basin values will be in the default English units for their parameters. (This is default if no value is entered)\r\n2. SI. Specifies the SI unit system. Basin values will be in the default SI units for their parameters.") }, responses = { @OpenApiResponse(status = "200", content = { @OpenApiContent(from = Basin.class, type = Formats.NAMED_PGJSON) }), @OpenApiResponse(status = "404", description = "The provided combination of parameters did not find a basin."), @OpenApiResponse(status = "501", description = "Requested format is not implemented") }, description = "Returns CWMS Basin Data", tags = { TAG })
@Override
public void getOne(@NotNull Context ctx, @NotNull String basinId) {
getOneRequest.mark();
try (final Timer.Context timeContext = getAllRequestsTime.time();
DSLContext dsl = getDslContext(ctx)) {
String units = ctx.queryParamAsClass("unit", String.class).getOrDefault(UnitSystem.EN.value());
String office = ctx.queryParam("office");
String formatHeader = ctx.header(Header.ACCEPT) != null ? ctx.header(Header.ACCEPT) : Formats.NAMED_PGJSON;
ContentType contentType = Formats.parseHeader(formatHeader);
ctx.contentType(contentType.toString());
BasinDao basinDao = new BasinDao(dsl);
Basin basin = basinDao.getBasin(basinId, units, office);
if (contentType.getType().equals(Formats.NAMED_PGJSON)) {
NamedPgJsonFormatter basinPgJsonFormatter = new NamedPgJsonFormatter();
String result = basinPgJsonFormatter.format(basin);
ctx.result(result);
} else {
ctx.status(HttpServletResponse.SC_NOT_FOUND).json(new RadarError("Unsupported format for basins"));
}
} catch (SQLException ex) {
String errorMsg = "Error retrieving " + basinId;
LOGGER.log(Level.SEVERE, errorMsg, ex);
}
}
use of cwms.radar.data.dto.basinconnectivity.Basin in project cwms-radar-api by USACE.
the class BasinDao method buildBasinsFromResultSet.
private List<Basin> buildBasinsFromResultSet(ResultSet rs, String unitSystem) throws SQLException {
List<Basin> retval = new ArrayList<>();
while (rs.next()) {
String officeId = rs.getString("OFFICE_ID");
String basinId = rs.getString("BASIN_ID");
String parentBasinId = rs.getString("PARENT_BASIN_ID");
Double sortOrder = rs.getDouble("SORT_ORDER");
String primaryStreamId = rs.getString("PRIMARY_STREAM_ID");
Double basinArea = rs.getDouble("TOTAL_DRAINAGE_AREA");
Double contributingArea = rs.getDouble("CONTRIBUTING_DRAINAGE_AREA");
Basin basin = new Basin.Builder(basinId, officeId).withBasinArea(basinArea).withContributingArea(contributingArea).withParentBasinId(parentBasinId).withSortOrder(sortOrder).build();
if (primaryStreamId != null) {
StreamDao streamDao = new StreamDao(dsl);
Stream primaryStream = streamDao.getStream(primaryStreamId, unitSystem, officeId);
basin = new Basin.Builder(basin).withPrimaryStream(primaryStream).build();
}
retval.add(basin);
}
return retval;
}
Aggregations