Skip to content

Commit

Permalink
CWDB-225 - Added a override property for checking for existing measur…
Browse files Browse the repository at this point in the history
…ements for bulk update
  • Loading branch information
rma-bryson committed Oct 17, 2024
1 parent 561e3a0 commit 4f75f87
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.Date;
import java.util.TimeZone;
import java.util.stream.Collectors;
Expand All @@ -78,6 +77,7 @@

public final class MeasurementDao extends JooqDao<Measurement> {
static final XmlMapper XML_MAPPER = buildXmlMapper();
public static final String IGNORE_EXISTING_CHECK_FOR_BULK_UPDATE_PROPERTY = "measurement.ignoreExistingCheckForBulkUpdate";

public MeasurementDao(DSLContext dsl) {
super(dsl);
Expand Down Expand Up @@ -251,11 +251,14 @@ private void verifyMeasurementsExists(Connection conn, String officeId, String l
.collect(Collectors.toList());

// Retrieve existing measurements from the database
List<String> existingNumbers = getExistingMeasurementNumbers(conn, officeId, locationId, measurementNumbers);

// Find missing numbers
List<String> missingNumbers = new ArrayList<>(measurementNumbers);
missingNumbers.removeAll(existingNumbers);
List<String> missingNumbers = new ArrayList<>();
if(!Boolean.getBoolean(IGNORE_EXISTING_CHECK_FOR_BULK_UPDATE_PROPERTY))
{
List<String> existingNumbers = getExistingMeasurementNumbers(conn, officeId, locationId, measurementNumbers);
missingNumbers = new ArrayList<>(measurementNumbers);
// Find missing numbers
missingNumbers.removeAll(existingNumbers);
}

if (!missingNumbers.isEmpty()) {
throw new NotFoundException("Could not find measurements " + String.join(",", missingNumbers) +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ static void createAndStoreTestStream(String testLoc) throws SQLException {

@AfterAll
public static void tearDown() {
System.clearProperty(MeasurementDao.IGNORE_EXISTING_CHECK_FOR_BULK_UPDATE_PROPERTY);
for (Stream stream : TEST_STREAMS) {
try {
CwmsDatabaseContainer<?> db = CwmsDataApiSetupCallback.getDatabaseLink();
Expand Down Expand Up @@ -336,6 +337,7 @@ void test_create_retrieve_delete_measurement() throws IOException {
@Test
@MinimumSchema(MINIMUM_SCHEMA)
void test_create_retrieve_delete_measurement_multiple() throws IOException {
System.setProperty(MeasurementDao.IGNORE_EXISTING_CHECK_FOR_BULK_UPDATE_PROPERTY, String.valueOf(true));
InputStream resource = this.getClass().getResourceAsStream("/cwms/cda/api/measurements.json");
assertNotNull(resource);
String json = IOUtils.toString(resource, StandardCharsets.UTF_8);
Expand Down Expand Up @@ -612,6 +614,7 @@ void test_create_retrieve_delete_measurement_multiple() throws IOException {
@Test
@MinimumSchema(MINIMUM_SCHEMA)
void test_update_does_not_exist() throws Exception {
System.clearProperty(MeasurementDao.IGNORE_EXISTING_CHECK_FOR_BULK_UPDATE_PROPERTY);
TestAccounts.KeyUser user = TestAccounts.KeyUser.SPK_NORMAL;

InputStream resourceUpdated = this.getClass().getResourceAsStream("/cwms/cda/api/measurements_updated.json");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ void testRoundTripMultipleStore() throws Exception {
StreamLocation streamLocation2 = StreamLocationDaoTestIT.buildTestStreamLocation("TEST_STREAM_123", streamLocId2, OFFICE_ID,11.0, Bank.RIGHT);

try {
System.setProperty(MeasurementDao.IGNORE_EXISTING_CHECK_FOR_BULK_UPDATE_PROPERTY, String.valueOf(true));
//store stream locations
streamLocationDao.storeStreamLocation(streamLocation, false);
streamLocationDao.storeStreamLocation(streamLocation2, false);
Expand Down Expand Up @@ -231,6 +232,8 @@ void testRoundTripMultipleStore() throws Exception {
updatedMeasurements.add(meas1B);
measurementDao.updateMeasurements(updatedMeasurements);

System.clearProperty(MeasurementDao.IGNORE_EXISTING_CHECK_FOR_BULK_UPDATE_PROPERTY);

retrievedMeasurements = measurementDao.retrieveMeasurements(OFFICE_ID, streamLocId, null, null, UnitSystem.EN.getValue(),
null, null, null, null, null, null, null, null);

Expand Down Expand Up @@ -264,6 +267,7 @@ void testRoundTripMultipleStore() throws Exception {
assertThrows(NotFoundException.class, () -> measurementDao.retrieveMeasurements(meas2F.getId().getOfficeId(), meas2F.getId().getName(),
null, null, UnitSystem.EN.getValue(), null, null, null, null, null, null, null, null));
} finally {
System.clearProperty(MeasurementDao.IGNORE_EXISTING_CHECK_FOR_BULK_UPDATE_PROPERTY);
//delete stream locations
streamLocationDao.deleteStreamLocation(
streamLocation.getStreamLocationNode().getId().getOfficeId(),
Expand Down

0 comments on commit 4f75f87

Please sign in to comment.