Skip to content

Commit

Permalink
Added documentation to StoreRule usage and switched to using argument…
Browse files Browse the repository at this point in the history
…s with space ("DELETE INSERT" and not "DELETE_INSERT")
  • Loading branch information
rma-rripken committed Dec 29, 2023
1 parent 6fe5fff commit b227e73
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 7 deletions.
90 changes: 86 additions & 4 deletions cwms-data-api/src/main/java/cwms/cda/api/TimeSeriesController.java
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,49 @@ private Timer.Context markAndTime(String subject) {
@OpenApiParam(name = CREATE_AS_LRTS, type = Boolean.class, description = "Flag indicating if "
+ "timeseries should be created as Local Regular Time Series. "
+ "'True' or 'False', default is 'False'"),
@OpenApiParam(name = STORE_RULE, description = "The business rule to use "
+ "when merging the incoming with existing data", type = StoreRule.class),
@OpenApiParam(name = STORE_RULE, type = StoreRule.class, description = "The business rule to use "
+ "when merging the incoming with existing data\n" +
"<table border=\"1\" summary=\"\">\n"
+ "<tr><td colspan=2>Store Rules</td></tr>\n"
+ "<tr>\n"
+ " <td>Delete Insert</td>\n"
+ " <td>All existing data in the time window will be deleted and then replaced with the new dataset.</td>\n"
+ "</tr>\n"
+ "<tr>\n"
+ " <td>Replace All</td>\n"
+ " <td>\n"
+ " <ul>\n"
+ " <li>When the new dataset's date/time exactly matches the date/time of an existing data value, the new data value will replace the existing data.</li>\n"
+ " <li>When the new dataset's data/time does not match an existing data/time (i.e., a new data/time - data value pair) then an insert to the database will occur.</li>\n"
+ " <li>When there's an existing \"data/time - data value pair\" without a corresponding date/time value pair, no change will happen to the existing date/time value pair.</li>\n"
+ " </ul>\n"
+ " </td>\n"
+ "</tr>\n"
+ "<tr>\n"
+ " <td>Replace With Non Missing</td>\n"
+ " <td>\n"
+ " <ul>\n"
+ " <li>New data is always inserted, i.e., an existing date/time-value pair does not already exist for the record.</li>\n"
+ " <li>If date/time-value pair does exist, then only non-missing value will replace the existing data value*.</li>\n"
+ " </ul>\n"
+ " </td>\n"
+ "<tr>\n"
+ " <td>Replace Missing Values Only</td>\n"
+ " <td>\n"
+ " <ul>\n"
+ " <li>New data is always inserted, i.e., an existing date/time-value pair does not already exist for the record.</li>\n"
+ " <li>If date/time-value pair does exist, then only replace an existing data/time-value pair whose missing flag was set.</li>\n"
+ " </ul>\n"
+ " </td>\n"
+ "<tr>\n"
+ " <td>Do Not Replace</td>\n"
+ " <td>\n"
+ " Only inserts new data values if an existing date/time-value pair does not already exist.\n"
+ " Note: an existing date/time-value pair whose missing value quality bit is set will NOT be overwritten.\n"
+ " </td>\n"
+ "</tr>\n"
+ "</table>"
),
@OpenApiParam(name = OVERRIDE_PROTECTION, type = Boolean.class, description =
"A flag to ignore the protected data quality when storing data. "
+ "'True' or 'False'")
Expand Down Expand Up @@ -473,8 +514,49 @@ public void getOne(@NotNull Context ctx, @NotNull String id) {
+ "of UTC shall be used.\r\nIgnored if version-date was specified with "
+ "offset and timezone."),
@OpenApiParam(name = CREATE_AS_LRTS, type = Boolean.class, description = ""),
@OpenApiParam(name = STORE_RULE, description = "The business rule to use "
+ "when merging the incoming with existing data", type = StoreRule.class),
@OpenApiParam(name = STORE_RULE, type = StoreRule.class, description = "The business rule to use "
+ "when merging the incoming with existing data\n"
+ "<table border=\"1\" summary=\"\">\n"
+ "<tr><td colspan=2>Store Rules</td></tr>\n"
+ "<tr>\n"
+ " <td>Delete Insert</td>\n"
+ " <td>All existing data in the time window will be deleted and then replaced with the new dataset.</td>\n"
+ "</tr>\n"
+ "<tr>\n"
+ " <td>Replace All</td>\n"
+ " <td>\n"
+ " <ul>\n"
+ " <li>When the new dataset's date/time exactly matches the date/time of an existing data value, the new data value will replace the existing data.</li>\n"
+ " <li>When the new dataset's data/time does not match an existing data/time (i.e., a new data/time - data value pair) then an insert to the database will occur.</li>\n"
+ " <li>When there's an existing \"data/time - data value pair\" without a corresponding date/time value pair, no change will happen to the existing date/time value pair.</li>\n"
+ " </ul>\n"
+ " </td>\n"
+ "</tr>\n"
+ "<tr>\n"
+ " <td>Replace With Non Missing</td>\n"
+ " <td>\n"
+ " <ul>\n"
+ " <li>New data is always inserted, i.e., an existing date/time-value pair does not already exist for the record.</li>\n"
+ " <li>If date/time-value pair does exist, then only non-missing value will replace the existing data value*.</li>\n"
+ " </ul>\n"
+ " </td>\n"
+ "<tr>\n"
+ " <td>Replace Missing Values Only</td>\n"
+ " <td>\n"
+ " <ul>\n"
+ " <li>New data is always inserted, i.e., an existing date/time-value pair does not already exist for the record.</li>\n"
+ " <li>If date/time-value pair does exist, then only replace an existing data/time-value pair whose missing flag was set.</li>\n"
+ " </ul>\n"
+ " </td>\n"
+ "<tr>\n"
+ " <td>Do Not Replace</td>\n"
+ " <td>\n"
+ " Only inserts new data values if an existing date/time-value pair does not already exist.\n"
+ " Note: an existing date/time-value pair whose missing value quality bit is set will NOT be overwritten.\n"
+ " </td>\n"
+ "</tr>\n"
+ "</table>"
),
@OpenApiParam(name = OVERRIDE_PROTECTION, type = Boolean.class, description =
"A flag to ignore the protected data quality when storing data. \"'true' or 'false'\"")
},
Expand Down
10 changes: 7 additions & 3 deletions cwms-data-api/src/main/java/cwms/cda/data/dao/StoreRule.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package cwms.cda.data.dao;

import usace.cwms.db.jooq.codegen.packages.CWMS_UTIL_PACKAGE;

public enum StoreRule {
// This class makes it obvious which of the constants in CWMS_UTIL_PACKAGE are store rules.
// These constants used to be available from jooq'd CWMS_UTIL_PACKAGE via:
Expand All @@ -14,7 +12,7 @@ public enum StoreRule {
private final String rule;

StoreRule(String rule) {
String parts[] = rule.split("\\.");
String parts[] = rule.split("\\."); // split on a literal period.
this.rule = parts[parts.length - 1].replace("_", " ").replace("\"", "");
}

Expand All @@ -26,9 +24,15 @@ public static StoreRule getStoreRule(String input) {
StoreRule retval = null;

if (input != null) {
input = input.replace(" ", "_"); // "REPLACE ALL" instead of "REPLACE_ALL"
retval = StoreRule.valueOf(input.toUpperCase());
}
return retval;
}

@Override
public String toString() {
return rule;
}

}
15 changes: 15 additions & 0 deletions cwms-data-api/src/test/java/cwms/cda/data/dao/StoreRuleTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,19 @@ public void testGetStoreRule() {
assertEquals("REPLACE ALL", rule.getRule());
}

@Test
public void testGetStoreRuleSpace() {
StoreRule rule = StoreRule.getStoreRule("REPLACE ALL");
assertNotNull(rule);
assertEquals(StoreRule.REPLACE_ALL, rule);
assertEquals("REPLACE ALL", rule.getRule());
}

@Test
public void testToStringSpaces() {
String replaceAllStr = StoreRule.REPLACE_ALL.toString();

assertEquals("REPLACE ALL", replaceAllStr);
}

}

0 comments on commit b227e73

Please sign in to comment.