Search in sources :

Example 1 with LocationLevel

use of cwms.radar.data.dto.LocationLevel in project cwms-radar-api by USACE.

the class LocationLevelsDaoTest method testDeleteLocationLevel.

@Disabled
void testDeleteLocationLevel() throws Exception {
    LocationLevelsDao levelsDao = new LocationLevelsDaoImpl(getDslContext(getConnection(), "LRL"));
    LocationLevel levelToStore = buildExampleLevel("TEST_LOC5");
    LocationsDao locationsDao = new LocationsDaoImpl(getDslContext(getConnection(), OFFICE_ID));
    Location location = buildTestLocation("TEST_LOC5");
    locationsDao.storeLocation(location);
    levelsDao.storeLocationLevel(levelToStore, ZoneId.of("UTC"));
    LocationLevel retrievedLevel = levelsDao.retrieveLocationLevel(levelToStore.getLocationLevelId(), UnitSystem.EN.getValue(), levelToStore.getLevelDate(), OFFICE_ID);
    assertNotNull(retrievedLevel);
    levelsDao.deleteLocationLevel(levelToStore.getLocationLevelId(), levelToStore.getLevelDate(), OFFICE_ID, true);
    assertThrows(IOException.class, () -> levelsDao.retrieveLocationLevel(levelToStore.getLocationLevelId(), UnitSystem.EN.getValue(), levelToStore.getLevelDate(), OFFICE_ID));
}
Also used : LocationLevel(cwms.radar.data.dto.LocationLevel) Location(cwms.radar.data.dto.Location) Disabled(org.junit.jupiter.api.Disabled)

Example 2 with LocationLevel

use of cwms.radar.data.dto.LocationLevel in project cwms-radar-api by USACE.

the class LocationLevelsDaoTest method deserializeLocationLevel.

private LocationLevel deserializeLocationLevel(String body, String format, String office) throws IOException {
    ObjectMapper om = getObjectMapperForFormat(format);
    LocationLevel retVal;
    try {
        retVal = om.readValue(body, LocationLevel.class);
        retVal = new LocationLevel.Builder(retVal).withOfficeId(office).build();
    } catch (Exception e) {
        throw new IOException("Failed to deserialize level");
    }
    return retVal;
}
Also used : LocationLevel(cwms.radar.data.dto.LocationLevel) IOException(java.io.IOException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) IOException(java.io.IOException)

Example 3 with LocationLevel

use of cwms.radar.data.dto.LocationLevel 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 4 with LocationLevel

use of cwms.radar.data.dto.LocationLevel in project cwms-radar-api by USACE.

the class LocationLevelsDaoTest method testStore.

@Disabled
void testStore() throws Exception {
    LocationLevel levelToStore = null;
    Location location = null;
    try {
        levelToStore = buildExampleLevel("TEST_LOC");
        LocationsDao locationsDao = new LocationsDaoImpl(getDslContext(getConnection(), OFFICE_ID));
        location = buildTestLocation("TEST_LOC");
        locationsDao.storeLocation(location);
        LocationLevelsDao levelsDao = new LocationLevelsDaoImpl(getDslContext(getConnection(), OFFICE_ID));
        levelsDao.storeLocationLevel(levelToStore, ZoneId.of("UTC"));
        LocationLevel retrievedLevel = levelsDao.retrieveLocationLevel(levelToStore.getLocationLevelId(), UnitSystem.EN.getValue(), levelToStore.getLevelDate(), "LRL");
        assertNotNull(retrievedLevel);
        assertEquals(levelToStore.getLocationLevelId(), retrievedLevel.getLocationLevelId());
        assertEquals(levelToStore.getLevelDate(), retrievedLevel.getLevelDate());
    } finally {
        if (levelToStore != null) {
            deleteLevel(levelToStore);
        }
    }
}
Also used : LocationLevel(cwms.radar.data.dto.LocationLevel) Location(cwms.radar.data.dto.Location) Disabled(org.junit.jupiter.api.Disabled)

Example 5 with LocationLevel

use of cwms.radar.data.dto.LocationLevel 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)

Aggregations

LocationLevel (cwms.radar.data.dto.LocationLevel)19 ZonedDateTimeAdapter (cwms.radar.formatters.xml.adapters.ZonedDateTimeAdapter)8 Test (org.junit.jupiter.api.Test)6 ZonedDateTime (java.time.ZonedDateTime)5 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)4 IOException (java.io.IOException)4 Location (cwms.radar.data.dto.Location)3 SeasonalValueBean (cwms.radar.data.dto.SeasonalValueBean)3 Disabled (org.junit.jupiter.api.Disabled)3 Timer (com.codahale.metrics.Timer)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)2 BeanDescription (com.fasterxml.jackson.databind.BeanDescription)2 JavaType (com.fasterxml.jackson.databind.JavaType)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 BeanPropertyDefinition (com.fasterxml.jackson.databind.introspect.BeanPropertyDefinition)2 JsonFieldsException (cwms.radar.api.errors.JsonFieldsException)2 LocationLevelsDao (cwms.radar.data.dao.LocationLevelsDao)2 ContentType (cwms.radar.formatters.ContentType)2 FormattingException (cwms.radar.formatters.FormattingException)2 OpenApi (io.javalin.plugin.openapi.annotations.OpenApi)2