use of cwms.radar.formatters.xml.adapters.ZonedDateTimeAdapter in project cwms-radar-api by USACE.
the class LocationLevelsDaoTest method buildExampleLevel.
LocationLevel buildExampleLevel(String locationName) throws Exception {
String dateString = "1999-12-05T10:15:30+01:00[UTC]";
List<SeasonalValueBean> seasonalValues = new ArrayList<>();
SeasonalValueBean seasonalVal = new SeasonalValueBean.Builder(10.0).withOffsetMinutes(BigInteger.valueOf(0)).withOffsetMonths(0).build();
seasonalValues.add(0, seasonalVal);
ZonedDateTimeAdapter zonedDateTimeAdapter = new ZonedDateTimeAdapter();
ZonedDateTime unmarshalledDateTime = zonedDateTimeAdapter.unmarshal(dateString);
LocationLevel retval = new LocationLevel.Builder(locationName + ".Elev.Inst.0.Bottom of Inlet", unmarshalledDateTime).withOfficeId(OFFICE_ID).withLevelComment("For testing").withLevelUnitsId(Unit.FEET.getValue()).withSeasonalValues(seasonalValues).withIntervalMonths(1).build();
return retval;
}
use of cwms.radar.formatters.xml.adapters.ZonedDateTimeAdapter in project cwms-radar-api by USACE.
the class LevelControllerTest method testDeserializeTimeSeriesLevelJSON.
@Test
void testDeserializeTimeSeriesLevelJSON() throws Exception {
ZonedDateTimeAdapter dateTimeAdapter = new ZonedDateTimeAdapter();
String json = loadResourceAsString("cwms/radar/api/levels_timeseries_create.json");
assertNotNull(json);
LocationLevel level = LevelsController.deserializeLocationLevel(json, Formats.JSON, OFFICE_ID);
assertNotNull(level);
assertEquals("LOC_TEST.Elev.Inst.0.Bottom of Inlet", level.getLocationLevelId());
assertEquals(OFFICE_ID, level.getOfficeId());
assertEquals("ft", level.getLevelUnitsId());
assertEquals(dateTimeAdapter.unmarshal("2008-12-03T10:15:30+01:00[UTC]"), level.getLevelDate());
assertEquals("RYAN3.Stage.Inst.5Minutes.0.ZSTORE_TS_TEST630", level.getSeasonalTimeSeriesId());
}
use of cwms.radar.formatters.xml.adapters.ZonedDateTimeAdapter in project cwms-radar-api by USACE.
the class LevelControllerTest method testDeserializeTimeSeriesLevelXml.
@Test
void testDeserializeTimeSeriesLevelXml() throws Exception {
ZonedDateTimeAdapter dateTimeAdapter = new ZonedDateTimeAdapter();
String xml = loadResourceAsString("cwms/radar/api/levels_timeseries_create.xml");
assertNotNull(xml);
LocationLevel level = LevelsController.deserializeLocationLevel(xml, Formats.XML, OFFICE_ID);
assertNotNull(level);
assertEquals("LOC_TEST.Elev.Inst.0.Bottom of Inlet", level.getLocationLevelId());
assertEquals(OFFICE_ID, level.getOfficeId());
assertEquals("ft", level.getLevelUnitsId());
assertEquals(dateTimeAdapter.unmarshal("2008-12-03T10:15:30+01:00[UTC]"), level.getLevelDate());
assertEquals("RYAN3.Stage.Inst.5Minutes.0.ZSTORE_TS_TEST630", level.getSeasonalTimeSeriesId());
}
use of cwms.radar.formatters.xml.adapters.ZonedDateTimeAdapter in project cwms-radar-api by USACE.
the class LevelControllerTest method testDeserializeSeasonalLevelXml.
@Test
void testDeserializeSeasonalLevelXml() throws Exception {
ZonedDateTimeAdapter dateTimeAdapter = new ZonedDateTimeAdapter();
String xml = loadResourceAsString("cwms/radar/api/levels_seasonal_create.xml");
assertNotNull(xml);
LocationLevel level = LevelsController.deserializeLocationLevel(xml, Formats.XML, OFFICE_ID);
assertNotNull(level);
assertEquals("LOC_TEST.Elev.Inst.0.Bottom of Inlet", level.getLocationLevelId());
assertEquals(OFFICE_ID, level.getOfficeId());
assertEquals("ft", level.getLevelUnitsId());
assertEquals(dateTimeAdapter.unmarshal("2008-12-03T10:15:30+01:00[UTC]"), level.getLevelDate());
assertEquals(10.0, level.getSeasonalValues().get(0).getValue());
}
use of cwms.radar.formatters.xml.adapters.ZonedDateTimeAdapter in project cwms-radar-api by USACE.
the class LevelsController method getUnmarshalledDateTime.
private ZonedDateTime getUnmarshalledDateTime(String body, String format) throws Exception {
ObjectMapper om = getObjectMapperForFormat(format);
JsonNode root = om.readTree(body);
String dateString = root.findValue("level-date").toString().replace("\"", "");
ZonedDateTimeAdapter zonedDateTimeAdapter = new ZonedDateTimeAdapter();
return zonedDateTimeAdapter.unmarshal(dateString);
}
Aggregations