Search in sources :

Example 1 with ZonedDateTimeAdapter

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;
}
Also used : SeasonalValueBean(cwms.radar.data.dto.SeasonalValueBean) ZonedDateTime(java.time.ZonedDateTime) ArrayList(java.util.ArrayList) ZonedDateTimeAdapter(cwms.radar.formatters.xml.adapters.ZonedDateTimeAdapter) LocationLevel(cwms.radar.data.dto.LocationLevel)

Example 2 with ZonedDateTimeAdapter

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());
}
Also used : ZonedDateTimeAdapter(cwms.radar.formatters.xml.adapters.ZonedDateTimeAdapter) LocationLevel(cwms.radar.data.dto.LocationLevel) Test(org.junit.jupiter.api.Test)

Example 3 with ZonedDateTimeAdapter

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());
}
Also used : ZonedDateTimeAdapter(cwms.radar.formatters.xml.adapters.ZonedDateTimeAdapter) LocationLevel(cwms.radar.data.dto.LocationLevel) Test(org.junit.jupiter.api.Test)

Example 4 with ZonedDateTimeAdapter

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());
}
Also used : ZonedDateTimeAdapter(cwms.radar.formatters.xml.adapters.ZonedDateTimeAdapter) LocationLevel(cwms.radar.data.dto.LocationLevel) Test(org.junit.jupiter.api.Test)

Example 5 with ZonedDateTimeAdapter

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);
}
Also used : ZonedDateTimeAdapter(cwms.radar.formatters.xml.adapters.ZonedDateTimeAdapter) JsonNode(com.fasterxml.jackson.databind.JsonNode) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Aggregations

ZonedDateTimeAdapter (cwms.radar.formatters.xml.adapters.ZonedDateTimeAdapter)10 LocationLevel (cwms.radar.data.dto.LocationLevel)8 Test (org.junit.jupiter.api.Test)6 ZonedDateTime (java.time.ZonedDateTime)3 Timer (com.codahale.metrics.Timer)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)2 JsonFieldsException (cwms.radar.api.errors.JsonFieldsException)2 RadarError (cwms.radar.api.errors.RadarError)2 LocationLevelsDao (cwms.radar.data.dao.LocationLevelsDao)2 FormattingException (cwms.radar.formatters.FormattingException)2 OpenApi (io.javalin.plugin.openapi.annotations.OpenApi)2 IOException (java.io.IOException)2 DSLContext (org.jooq.DSLContext)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 SeasonalValueBean (cwms.radar.data.dto.SeasonalValueBean)1 ContentType (cwms.radar.formatters.ContentType)1 ZoneId (java.time.ZoneId)1 ArrayList (java.util.ArrayList)1