Skip to content

Commit

Permalink
Adding Std text timeseries IT.
Browse files Browse the repository at this point in the history
  • Loading branch information
rma-rripken committed Dec 28, 2023
1 parent 9753b29 commit 58ecc9a
Show file tree
Hide file tree
Showing 2 changed files with 123 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.NavigableSet;
import java.util.TimeZone;
import java.util.TreeSet;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jooq.DSLContext;
Expand Down Expand Up @@ -114,7 +116,11 @@ private StandardTextValue retrieve(Connection c, StandardTextId standardTextId)
.build();
}


/**
* This is if you want to store a new standard text id -> value mapping.
* @param standardTextValue
* @param failIfExists
*/
public void store(StandardTextValue standardTextValue, boolean failIfExists) {

cwms.cda.data.dto.timeseriestext.StandardTextId standardTextId = standardTextValue.getId();
Expand All @@ -128,6 +134,28 @@ public void store(StandardTextValue standardTextValue, boolean failIfExists) {
});
}

public void store(String officeId, String tsId, StandardTextTimeSeriesRow stdRow,
boolean maxVersion, boolean replaceAll) {
TimeZone timeZone = OracleTypeMap.GMT_TIME_ZONE;

StandardTextId standardTextId = stdRow.getStandardTextId();
String textId = standardTextId.getId();

Date dateTime = stdRow.getDateTime();
Date versionDate = stdRow.getVersionDate();
Long attribute = stdRow.getAttribute();

NavigableSet<Date> dates = new TreeSet<>();
dates.add(dateTime);

connection(dsl, connection -> {
CwmsDbText dbText = CwmsDbServiceLookup.buildCwmsDb(CwmsDbText.class, connection);
dbText.storeTsStdText(connection, tsId, textId, dates,
versionDate, timeZone, maxVersion, replaceAll,
attribute, officeId);
});
}

/**
* Deletes standard text
*
Expand Down Expand Up @@ -211,7 +239,7 @@ public TextTimeSeries retrieveTextTimeSeries(
if (standardTextId != null) {
stdTextIdMask = standardTextId.getId();
} else {
stdTextIdMask = null;
stdTextIdMask = "*";
}
TimeZone timeZone = OracleTypeMap.GMT_TIME_ZONE;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
package cwms.cda.data.dao.texttimeseries;



import static cwms.cda.data.dao.DaoTest.getDslContext;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;

import com.google.common.flogger.FluentLogger;
import cwms.cda.api.DataApiTestIT;
import cwms.cda.data.dto.timeseriestext.RegularTextTimeSeriesRow;
import cwms.cda.data.dto.timeseriestext.StandardTextId;
import cwms.cda.data.dto.timeseriestext.StandardTextTimeSeriesRow;
import cwms.cda.data.dto.timeseriestext.StandardTextValue;
import cwms.cda.data.dto.timeseriestext.TextTimeSeries;
import fixtures.CwmsDataApiSetupCallback;
import java.sql.SQLException;
import java.time.ZonedDateTime;
import java.util.Collection;
import java.util.Date;
import mil.army.usace.hec.test.database.CwmsDatabaseContainer;
import org.jooq.DSLContext;
Expand All @@ -21,6 +28,7 @@

@Tag("integration")
class StandardTimeSeriesTextDaoTestIT extends DataApiTestIT {
private static final FluentLogger logger = FluentLogger.forEnclosingClass();
@BeforeAll
public static void load_data() throws Exception {
loadSqlDataFromResource("cwms/cda/data/sql/store_std_text_timeseries.sql");
Expand All @@ -31,6 +39,76 @@ public static void deload_data() throws Exception {
loadSqlDataFromResource("cwms/cda/data/sql/delete_std_text_timeseries.sql");
}

@Test
void testCreate() throws SQLException {
CwmsDatabaseContainer<?> databaseLink = CwmsDataApiSetupCallback.getDatabaseLink();
databaseLink.connection(c -> {//
DSLContext dsl = getDslContext(c, "SPK");
StandardTimeSeriesTextDao dao = new StandardTimeSeriesTextDao(dsl);

testCreate(dao);
}
);
}

private void testCreate(StandardTimeSeriesTextDao dao) {
String officeId = "SPK";
String tsId = "First519402.Flow.Inst.1Hour.0.1688755420497";

StandardTextId standardTextId = null;

// The delete script deletes from 2005-02-01 13:30:00 - 2005-02-02 17:00:00'

ZonedDateTime startZDT = ZonedDateTime.parse("2005-02-01T15:00:00Z");
ZonedDateTime endZDT = ZonedDateTime.parse("2005-02-01T23:00:00Z");

// make sure it doesn't exist

Date startDate = Date.from(startZDT.toInstant());
Date endDate = Date.from(endZDT.toInstant());
Date versionDate = null;
boolean maxVersion = false;
boolean retText = true;
Long minAttr = null;
Long maxAttr = null;

TextTimeSeries tts = dao.retrieveTextTimeSeries(officeId, tsId, standardTextId,
startDate, endDate, versionDate,
maxVersion, retText, minAttr, maxAttr);

assertNotNull(tts);
assertEquals(0, tts.getStdRows().size());

// create/store
StandardTextId textId = new StandardTextId.Builder()
.withId("A")
.withOfficeId("CWMS").build();
StandardTextValue stv = new StandardTextValue.Builder()
.withId(textId)
.build();

StandardTextTimeSeriesRow row = new StandardTextTimeSeriesRow.Builder()
.withDateTime(startDate)
.withStandardTextId(textId)
.withStandardTextValue(stv)
.build();
dao.store(officeId, tsId, row, true, true);

// retrieve and verify
tts = dao.retrieveTextTimeSeries(officeId, tsId, null,
startDate, endDate, versionDate,
maxVersion, retText, minAttr, maxAttr);

assertNotNull(tts);
Collection<StandardTextTimeSeriesRow> stdRows = tts.getStdRows();
assertFalse(stdRows.isEmpty());
assertEquals(1, stdRows.size());
// logger.atInfo().log("got %d rows", stdRows.size());
StandardTextTimeSeriesRow first = stdRows.iterator().next();
assertEquals( "A", first.getStandardTextId().getId());

}

@Test
void testRetrieve() throws SQLException {
CwmsDatabaseContainer<?> databaseLink = CwmsDataApiSetupCallback.getDatabaseLink();
Expand All @@ -40,8 +118,8 @@ void testRetrieve() throws SQLException {

testRetrieve(dao);
}
);
}
);
}

private static void testRetrieve(StandardTimeSeriesTextDao dao) {
String officeId = "SPK";
Expand All @@ -64,6 +142,18 @@ private static void testRetrieve(StandardTimeSeriesTextDao dao) {
maxVersion, retText, minAttr, maxAttr);

assertNotNull(tts);

Collection<StandardTextTimeSeriesRow> stdRows = tts.getStdRows();
assertNotNull(stdRows);
assertFalse(stdRows.isEmpty());

StandardTextTimeSeriesRow first = stdRows.iterator().next();
assertNotNull(first);
assertEquals("E", first.getStandardTextId());

Collection<RegularTextTimeSeriesRow> regRows = tts.getRegRows();
assertNull(regRows);

}

}

0 comments on commit 58ecc9a

Please sign in to comment.