Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -882,8 +882,19 @@ private void validateObservations(ValidationErrors validationErrors,
// had been saved prior to import
} else if (existingObsByObsHash.containsKey(importHash) && !isObservationMatched(importHash, importObsValue, phenoCol, rowNum)) {

// different data means validations still need to happen
// TODO consider moving these two calls into a separate method since called twice together
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this referring to validateObservationValue and validateTimeStampValue?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, since we have validation in two places in the method (one for the overwrite case and one for the non-overwrite case, it feels like it should be cleaned up in some manner)

validateObservationValue(colVarMap.get(phenoCol.name()), phenoCol.getString(rowNum), phenoCol.name(), validationErrors, rowNum);

//Timestamp validation
if(timeStampColByPheno.containsKey(phenoCol.name())) {
Column<?> timeStampCol = timeStampColByPheno.get(phenoCol.name());
validateTimeStampValue(timeStampCol.getString(rowNum), timeStampCol.name(), validationErrors, rowNum);
}

// add a change log entry when updating the value of an observation
if (commit) {
// only will update and thereby need change log entry if no error
if (commit && (!validationErrors.hasErrors())) {
BrAPIObservation pendingObservation = observationByHash.get(importHash).getBrAPIObject();
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd:hh-mm-ssZ");
String timestamp = formatter.format(OffsetDateTime.now());
Expand Down Expand Up @@ -1182,7 +1193,14 @@ boolean isTimestampMatched(String observationHash, String timeStamp) {
if (priorStamp == null) {
return timeStamp == null;
}
return priorStamp.isEqual(OffsetDateTime.parse(timeStamp));
boolean isMatched = false;
try {
isMatched = priorStamp.isEqual(OffsetDateTime.parse(timeStamp));
} catch(DateTimeParseException e){
//if timestamp is invalid DateTime not equal to validated priorStamp
log.error(e.getMessage(), e);
}
return isMatched;
}

boolean isValueMatched(String observationHash, String value) {
Expand Down Expand Up @@ -1232,7 +1250,7 @@ private void fetchOrCreateObservationPIO(Program program,
newObservation = gson.fromJson(gson.toJson(existingObsByObsHash.get(key)), BrAPIObservation.class);
if (!isValueMatched(key, value)){
newObservation.setValue(value);
} else if (!isTimestampMatched(key, timeStampValue)) {
} else if (!StringUtils.isBlank(timeStampValue) && !isTimestampMatched(key, timeStampValue)) {
DateTimeFormatter formatter = DateTimeFormatter.ISO_INSTANT;
String formattedTimeStampValue = formatter.format(OffsetDateTime.parse(timeStampValue));
newObservation.setObservationTimeStamp(OffsetDateTime.parse(formattedTimeStampValue));
Expand Down