Skip to content

Commit

Permalink
(#2995) Detect instances where QC messages set without comments
Browse files Browse the repository at this point in the history
Includes lookups, which at some points seem to get set without a source in the QC message field.
  • Loading branch information
squaregoldfish committed Nov 7, 2024
1 parent 206b479 commit 7ce67d9
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,14 @@ public static void storeSensorValues(Connection conn,
}
}

if (value.getUserQCFlag().commentRequired()
&& StringUtils.isBlank(value.getUserQCMessage())) {
throw new InvalidSensorValueException(
"User QC message cannot be empty with flag "
+ value.getUserQCFlag().getFlagValue(),
value);
}

updateStmt.setString(3, userQCMessage);
updateStmt.setLong(4, value.getId());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import com.javadocmd.simplelatlng.LatLng;

import uk.ac.exeter.QuinCe.data.Dataset.QC.Flag;
import uk.ac.exeter.QuinCe.data.Dataset.QC.InvalidFlagException;
import uk.ac.exeter.QuinCe.data.Instrument.DiagnosticQCConfig;
import uk.ac.exeter.QuinCe.data.Instrument.FileDefinition;
import uk.ac.exeter.QuinCe.data.Instrument.Instrument;
Expand Down Expand Up @@ -681,9 +682,11 @@ public DatasetSensorValues subset(TreeSet<LocalDateTime> times,
* @return The {@link SensorValues} that have been changed as part of this
* cascade.
* @throws RecordNotFoundException
* @throws InvalidFlagException
*/
public Set<SensorValue> applyQCCascade(SensorValue source,
RunTypePeriods runTypePeriods) throws RecordNotFoundException {
RunTypePeriods runTypePeriods)
throws RecordNotFoundException, InvalidFlagException {

Set<SensorValue> changedValues = new HashSet<SensorValue>();

Expand Down
4 changes: 4 additions & 0 deletions WebApp/src/uk/ac/exeter/QuinCe/data/Dataset/QC/Flag.java
Original file line number Diff line number Diff line change
Expand Up @@ -745,4 +745,8 @@ public static Flag getMostSignificantFlag(Flag... flags) {

return result;
}

public boolean commentRequired() {
return flagValue == 3 || flagValue == 4 || flagValue == -200;
}
}
12 changes: 10 additions & 2 deletions WebApp/src/uk/ac/exeter/QuinCe/data/Dataset/SensorValue.java
Original file line number Diff line number Diff line change
Expand Up @@ -826,25 +826,33 @@ public static double getMinimumChange(List<SensorValue> values) {
*
* @param source
* The source of the QC flag
* @throws InvalidFlagException
*/
public void setCascadingQC(SensorValue source) {
public void setCascadingQC(SensorValue source) throws InvalidFlagException {
SortedSet<Long> sources = userQCFlag.equals(Flag.LOOKUP)
? StringUtils.delimitedToLongSet(userQCMessage)
: new TreeSet<Long>();

sources.add(source.getId());

userQCFlag = Flag.LOOKUP;
userQCMessage = StringUtils.collectionToDelimited(sources, ",");
dirty = true;
}

public void setCascadingQC(PlotPageTableValue source) {
public void setCascadingQC(PlotPageTableValue source)
throws InvalidFlagException {
SortedSet<Long> sources = userQCFlag.equals(Flag.LOOKUP)
? StringUtils.delimitedToLongSet(userQCMessage)
: new TreeSet<Long>();

sources.addAll(source.getSources());

if (sources.size() == 0) {
throw new InvalidFlagException(
"Attempted to set LOOKUP flag with no source");
}

userQCFlag = Flag.LOOKUP;
userQCMessage = StringUtils.collectionToDelimited(sources, ",");
dirty = true;
Expand Down

0 comments on commit 7ce67d9

Please sign in to comment.