Skip to content

Commit

Permalink
fixing delete routine to utilize the time zone
Browse files Browse the repository at this point in the history
clean up the error handling allowing no data found exceptions to correctly return 404 error codes
  • Loading branch information
adamkorynta committed Feb 10, 2024
1 parent 23881b5 commit 9e03f60
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 22 deletions.
21 changes: 1 addition & 20 deletions cwms-data-api/src/main/java/cwms/cda/api/LevelsController.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
import cwms.cda.api.enums.UnitSystem;
import cwms.cda.api.errors.CdaError;
import cwms.cda.api.errors.JsonFieldsException;
import cwms.cda.api.errors.NotFoundException;
import cwms.cda.data.dao.LocationLevelsDao;
import cwms.cda.data.dao.LocationLevelsDaoImpl;
import cwms.cda.data.dto.LocationLevel;
Expand Down Expand Up @@ -73,16 +72,12 @@
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

import static com.codahale.metrics.MetricRegistry.name;
import static cwms.cda.api.Controllers.*;
import static cwms.cda.data.dao.JooqDao.getDslContext;

public class LevelsController implements CrudHandler {
private static final Logger logger = Logger.getLogger(LevelsController.class.getName());

private final MetricRegistry metrics;

private final Histogram requestResultSize;
Expand Down Expand Up @@ -185,10 +180,6 @@ public void delete(@NotNull Context ctx, @NotNull String levelId) {
LocationLevelsDao levelsDao = getLevelsDao(dsl);
levelsDao.deleteLocationLevel(levelId, unmarshalledDateTime, office, cascadeDelete);
ctx.status(HttpServletResponse.SC_ACCEPTED).json(levelId + " Deleted");
} catch (Exception ex) {
CdaError re = new CdaError("Failed to delete location level");
logger.log(Level.SEVERE, re.toString(), ex);
ctx.status(HttpServletResponse.SC_INTERNAL_SERVER_ERROR).json(re);
}
}

Expand Down Expand Up @@ -386,13 +377,6 @@ String.class, null, metrics, name(LevelsController.class.getName(),
units, unmarshalledDateTime, office);
ctx.json(locationLevel);
ctx.status(HttpServletResponse.SC_OK);
} catch (NotFoundException e) {
throw e;
} catch (Exception ex) {
CdaError re = new CdaError("Failed to retrieve Location Level request: "
+ ex.getLocalizedMessage());
logger.log(Level.SEVERE, re.toString(), ex);
ctx.status(HttpServletResponse.SC_INTERNAL_SERVER_ERROR).json(re);
}
}

Expand Down Expand Up @@ -462,10 +446,7 @@ public void update(@NotNull Context ctx, @NotNull String oldLevelId) {
ctx.status(HttpServletResponse.SC_ACCEPTED).json("Updated Location Level");
}
} catch (JsonProcessingException ex) {
CdaError re =
new CdaError("Failed to process request: " + ex.getLocalizedMessage());
logger.log(Level.SEVERE, re.toString(), ex);
ctx.status(HttpServletResponse.SC_INTERNAL_SERVER_ERROR).json(re);
throw new FormattingException("Failed to format location level update request", ex);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ public void deleteLocationLevel(String locationLevelName, ZonedDateTime zonedDat
try {
Timestamp date;
if (zonedDateTime != null) {
date = Timestamp.from(zonedDateTime.toLocalDateTime().atZone(zonedDateTime.getZone()).toInstant());
date = Timestamp.from(zonedDateTime.toInstant());
} else {
date = null;
}
Expand All @@ -226,7 +226,7 @@ public void deleteLocationLevel(String locationLevelName, ZonedDateTime zonedDat
cascade = "T";
}
CWMS_LEVEL_PACKAGE.call_DELETE_LOCATION_LEVEL(getDslContext(c, officeId).configuration(),
locationLevelName, date, null, null,
locationLevelName, date, "UTC", null,
null, null, cascade, officeId, "VN");
});
} else {
Expand Down

0 comments on commit 9e03f60

Please sign in to comment.