use of hec.data.RatingException in project cwms-radar-api by USACE.
the class RatingSetDao method create.
@Override
public void create(RatingSet ratingSet) throws IOException, RatingException {
try {
dsl.connection(c -> {
// can't exist if we are creating, if it exists use store
boolean overwriteExisting = false;
ratingSet.storeToDatabase(c, overwriteExisting);
});
} catch (DataAccessException ex) {
Throwable cause = ex.getCause();
if (cause instanceof RatingException) {
throw (RatingException) cause;
}
throw new IOException("Failed to create Rating", ex);
}
}
use of hec.data.RatingException in project cwms-radar-api by USACE.
the class RatingController method delete.
@OpenApi(queryParams = { @OpenApiParam(name = "office", required = true, description = "Specifies the owning office of the rating to be deleted.") }, method = HttpMethod.DELETE, tags = { "Ratings" })
@Override
public void delete(Context ctx, String ratingSpecId) {
String office = ctx.queryParam("office");
try (final Timer.Context timeContext = markAndTime("delete");
DSLContext dsl = getDslContext(ctx)) {
RatingDao ratingDao = getRatingDao(dsl);
ratingDao.delete(office, ratingSpecId);
ctx.status(HttpServletResponse.SC_ACCEPTED);
ctx.json("Deleted RatingSet");
} catch (IOException | RatingException ex) {
RadarError re = new RadarError("Failed to process delete request");
logger.log(Level.SEVERE, re.toString(), ex);
ctx.status(HttpServletResponse.SC_INTERNAL_SERVER_ERROR).json(re);
}
}
use of hec.data.RatingException 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.RatingException 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;
}
use of hec.data.RatingException in project cwms-radar-api by USACE.
the class RatingController method create.
@OpenApi(description = "Create new RatingSet", requestBody = @OpenApiRequestBody(content = { @OpenApiContent(type = Formats.XMLV2), @OpenApiContent(type = Formats.JSONV2) }, required = true), method = HttpMethod.POST, path = "/ratings", tags = { "Ratings" })
public void create(Context ctx) {
try (final Timer.Context timeContext = markAndTime("create");
DSLContext dsl = getDslContext(ctx)) {
RatingDao ratingDao = getRatingDao(dsl);
RatingSet ratingSet = deserializeRatingSet(ctx);
ratingDao.create(ratingSet);
ctx.status(HttpServletResponse.SC_ACCEPTED).json("Created RatingSet");
} catch (IOException | RatingException ex) {
RadarError re = new RadarError("Failed to process create request");
logger.log(Level.SEVERE, re.toString(), ex);
ctx.status(HttpServletResponse.SC_INTERNAL_SERVER_ERROR).json(re);
}
}
Aggregations