Search in sources :

Example 1 with RatingSet

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);
}
Also used : RatingSet(hec.data.cwmsRating.RatingSet)

Example 2 with RatingSet

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);
}
Also used : RatingSet(hec.data.cwmsRating.RatingSet)

Example 3 with RatingSet

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;
}
Also used : Timer(com.codahale.metrics.Timer) DSLContext(org.jooq.DSLContext) RatingSet(hec.data.cwmsRating.RatingSet) RatingDao(cwms.radar.data.dao.RatingDao)

Example 4 with 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);
    }
}
Also used : RatingException(hec.data.RatingException) RadarError(cwms.radar.api.errors.RadarError) Timer(com.codahale.metrics.Timer) DSLContext(org.jooq.DSLContext) IOException(java.io.IOException) RatingDao(cwms.radar.data.dao.RatingDao) RatingSet(hec.data.cwmsRating.RatingSet) OpenApi(io.javalin.plugin.openapi.annotations.OpenApi)

Example 5 with RatingSet

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;
}
Also used : RatingException(hec.data.RatingException) RadarError(cwms.radar.api.errors.RadarError) Timer(com.codahale.metrics.Timer) IOException(java.io.IOException) RatingSet(hec.data.cwmsRating.RatingSet) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

RatingSet (hec.data.cwmsRating.RatingSet)9 Timer (com.codahale.metrics.Timer)4 RatingException (hec.data.RatingException)4 IOException (java.io.IOException)4 RadarError (cwms.radar.api.errors.RadarError)3 RatingDao (cwms.radar.data.dao.RatingDao)3 DSLContext (org.jooq.DSLContext)3 DaoTest (cwms.radar.data.dao.DaoTest)2 JsonRatingUtilsTest (cwms.radar.data.dao.JsonRatingUtilsTest)2 OpenApi (io.javalin.plugin.openapi.annotations.OpenApi)2 Response (io.restassured.response.Response)2 HttpServletResponse (javax.servlet.http.HttpServletResponse)2 DataSource (javax.sql.DataSource)2 Disabled (org.junit.jupiter.api.Disabled)2 Test (org.junit.jupiter.api.Test)2 Nullable (org.jetbrains.annotations.Nullable)1