use of hec.data.cwmsRating.RatingSet in project cwms-radar-api by USACE.
the class RatingSetDao method deleteWithRatingSet.
private void deleteWithRatingSet(Connection c, String officeId, String specificationId, long[] effectiveDates) throws RatingException {
RatingSet ratingSet = RatingSet.fromDatabase(c, officeId, specificationId);
for (final long effectiveDate : effectiveDates) {
ratingSet.removeRating(effectiveDate);
}
final boolean overwriteExisting = true;
ratingSet.storeToDatabase(c, overwriteExisting);
}
use of hec.data.cwmsRating.RatingSet in project cwms-radar-api by USACE.
the class RatingSetDao method deleteWithRatingSet.
// This doesn't seem to work.
private void deleteWithRatingSet(Connection c, String officeId, String ratingSpecId) throws RatingException {
RatingSet ratingSet = RatingSet.fromDatabase(c, officeId, ratingSpecId);
ratingSet.removeAllRatings();
final boolean overwriteExisting = true;
// Does this actually delete?
ratingSet.storeToDatabase(c, overwriteExisting);
}
use of hec.data.cwmsRating.RatingSet in project cwms-radar-api by USACE.
the class RatingController method getRatingSet.
private RatingSet getRatingSet(Context ctx, String officeId, String rating) throws IOException, RatingException {
RatingSet ratingSet;
try (final Timer.Context timeContext = markAndTime("getRatingSet");
DSLContext dsl = getDslContext(ctx)) {
RatingDao ratingDao = getRatingDao(dsl);
ratingSet = ratingDao.retrieve(officeId, rating);
}
return ratingSet;
}
use of hec.data.cwmsRating.RatingSet in project cwms-radar-api by USACE.
the class RatingController method update.
@OpenApi(description = "Update a RatingSet", requestBody = @OpenApiRequestBody(content = { @OpenApiContent(type = Formats.XMLV2), @OpenApiContent(type = Formats.JSONV2) }, required = true), method = HttpMethod.PUT, path = "/ratings", tags = { "Ratings" })
public void update(Context ctx, String ratingId) {
try (final Timer.Context timeContext = markAndTime("update");
DSLContext dsl = getDslContext(ctx)) {
RatingDao ratingDao = getRatingDao(dsl);
// Retrieve the rating specified by ratingId and then somehow apply the update?
// RatingSet ratingSet = ratingDao.retrieve(officeId, ratingId);
// Or just store what they sent us?
RatingSet ratingSet = deserializeRatingSet(ctx);
ratingDao.store(ratingSet);
ctx.status(HttpServletResponse.SC_ACCEPTED).json("Updated RatingSet");
} catch (IOException | RatingException ex) {
RadarError re = new RadarError("Failed to process request to update RatingSet");
logger.log(Level.SEVERE, re.toString(), ex);
ctx.status(HttpServletResponse.SC_INTERNAL_SERVER_ERROR).json(re);
}
}
use of hec.data.cwmsRating.RatingSet in project cwms-radar-api by USACE.
the class RatingController method getRatingSetString.
@Nullable
private String getRatingSetString(Context ctx, String officeId, String rating) {
String retval = null;
try (final Timer.Context timeContext = markAndTime("getRatingSetString")) {
String acceptHeader = ctx.header(Header.ACCEPT);
if (Formats.JSONV2.equals(acceptHeader) || Formats.XMLV2.equals(acceptHeader)) {
try {
RatingSet ratingSet = getRatingSet(ctx, officeId, rating);
if (ratingSet != null) {
if (Formats.JSONV2.equals(acceptHeader)) {
retval = JsonRatingUtils.toJson(ratingSet);
} else if (Formats.XMLV2.equals(acceptHeader)) {
retval = ratingSet.toXmlString(" ");
}
} else {
ctx.status(HttpCode.NOT_FOUND);
}
} catch (RatingException e) {
RadarError re = new RadarError("Failed to process request to retrieve RatingSet");
logger.log(Level.SEVERE, re.toString(), e);
ctx.status(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
ctx.json(re);
} catch (IOException e) {
RadarError re = new RadarError("Failed to process request to retrieve RatingSet");
logger.log(Level.SEVERE, re.toString(), e);
ctx.status(HttpServletResponse.SC_INTERNAL_SERVER_ERROR).json(re);
}
} else {
RadarError re = new RadarError("Currently supporting only: " + Formats.JSONV2 + " and " + Formats.XMLV2);
logger.log(Level.WARNING, "Provided accept header not recognized:" + acceptHeader, re);
ctx.status(HttpServletResponse.SC_NOT_IMPLEMENTED);
ctx.json(RadarError.notImplemented());
}
}
return retval;
}
Aggregations