Skip to content

[BI-1830] Overwrite entity dataset#305

Merged
dmeidlin merged 22 commits intodevelopfrom
feature/BI-1830
Dec 6, 2023
Merged

[BI-1830] Overwrite entity dataset#305
dmeidlin merged 22 commits intodevelopfrom
feature/BI-1830

Conversation

@dmeidlin
Copy link
Contributor

@dmeidlin dmeidlin commented Oct 23, 2023

Description

Story: BI-1830

The expected behavior of a user-supplied observation unit dbid superseding experiment, environment, and unit import values has apparently regressed. Fixing this regression will be handled in a separate card, and the parts of ExperimentProcessor involved commented out with TODOs. For this feature, observations are updated by filling out the complete import row with the ObsUnitID value blank.

  1. Fields overwrite and overwriteReason added to ExperimentObservation
  2. validation of existing observations updated
  3. a changeLog entry is added to additionalInfo when committing updates to existing observations
  4. postBrapiData was updated to both post new observations and put updates to existing observations

Dependencies

bi-web feature/BI-1265

Testing

  1. import germplasm, observation variables, and a new experiment
  2. alter some of the rows of the experiment import file
  • change the values of a prior observation
  • leave the rest (environment, experiment, unit #, etc.)of the import row the same
  1. import the new file
  2. view details of the experiment and verify any changes to observation values.

Checklist:

  • I have performed a self-review of my own code
  • I have tested my code and ensured it meets the acceptance criteria of the story
  • I have tested that my code works with both the brapi-java-server and BreedBase
  • I have create/modified unit tests to cover this change
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to documentation
  • I have run TAF: <please include a link to TAF run>

@dmeidlin dmeidlin requested review from a team, nickpalladino and timparsons and removed request for a team November 10, 2023 15:29
@dmeidlin dmeidlin requested a review from davedrp November 13, 2023 19:31
@dmeidlin dmeidlin assigned davedrp and unassigned timparsons Nov 13, 2023
@dmeidlin dmeidlin removed the request for review from timparsons November 13, 2023 19:32
Copy link
Contributor

@davedrp davedrp left a comment

Choose a reason for hiding this comment

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

Developer test passed

return brAPIDAOUtil.post(brAPIObservationList, upload, api::observationsPost, importDAO::update);
}

public BrAPIObservation updateBrAPIObservation(String dbId, BrAPIObservation observation, UUID programId) throws ApiException {
Copy link
Contributor

Choose a reason for hiding this comment

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

IntellaJ says: "Return value of the method is never used". Does this need a return value

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, I put a check in place that will compare the requested value and timestamp to the updated values returned from the brapi service, throwing an exception if they don't match.

Copy link
Contributor

Choose a reason for hiding this comment

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

The following import statements are no longer needed;
import org.brapi.client.v2.model.exceptions.ApiException;
import org.breedinginsight.services.exceptions.DoesNotExistException;
import org.breedinginsight.services.exceptions.MissingRequiredInfoException;
import org.breedinginsight.services.exceptions.UnprocessableEntityException;
import org.breedinginsight.services.exceptions.ValidatorException;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

optimized

Copy link
Contributor

Choose a reason for hiding this comment

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

The following Import statements are no loner needed:
import org.brapi.client.v2.model.exceptions.ApiException;
import org.breedinginsight.brapps.importer.model.imports.germplasm.GermplasmImport;
import org.breedinginsight.services.exceptions.MissingRequiredInfoException;
import org.breedinginsight.services.exceptions.UnprocessableEntityException;
import org.breedinginsight.services.exceptions.ValidatorException;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

optimized

Copy link
Contributor

Choose a reason for hiding this comment

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

The following import statements are no longer used:
import org.brapi.client.v2.model.exceptions.ApiException;
import org.breedinginsight.services.exceptions.DoesNotExistException;
import org.breedinginsight.services.exceptions.MissingRequiredInfoException;
import org.breedinginsight.services.exceptions.UnprocessableEntityException;
import org.breedinginsight.services.exceptions.ValidatorException;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

optimized

public static String missingColumn = "Column name \"%s\" does not exist in file";
public static String missingUserInput = "User input, \"%s\" is required";
public static String wrongUserInputDataType = "User input, \"%s\" must be an %s";

Copy link
Contributor

Choose a reason for hiding this comment

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

The above 5-fields are never used

import java.util.function.Supplier;
import java.util.stream.Collectors;

import static org.breedinginsight.brapps.importer.services.FileMappingUtil.EXPERIMENT_TEMPLATE_NAME;
Copy link
Contributor

Choose a reason for hiding this comment

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

Import not used

Copy link
Contributor Author

Choose a reason for hiding this comment

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

optimized

"If you’re trying to add these units to the experiment, please create a new environment" +
" with all appropriate experiment units (NOTE: this will generate new Observation Unit Ids " +
"for each experiment unit).";
private static final String MISSING_OBS_UNIT_ID_ERROR = "Experiment Units are missing Observation Unit Id.<br/><br/>" +
Copy link
Contributor

Choose a reason for hiding this comment

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

MISSING_OBS_UNIT_ID_ERROR is no longer used

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm going to keep this in for now since it will likely be used again in the near future once the functionality of specifying by OU id is restored.

@@ -90,6 +104,9 @@ public class ExperimentProcessor implements Processor {
private static final String TIMESTAMP_REGEX = "^"+TIMESTAMP_PREFIX+"\\s*";
private static final String COMMA_DELIMITER = ",";
private static final String BLANK_FIELD = "Required field is blank";
Copy link
Contributor

Choose a reason for hiding this comment

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

'BLANK_FIELD' is never used

Copy link
Contributor Author

Choose a reason for hiding this comment

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

optimized

Copy link
Contributor

Choose a reason for hiding this comment

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

import org.breedinginsight.services.exceptions.MissingRequiredInfoException no longer used

Copy link
Contributor Author

Choose a reason for hiding this comment

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

optimized

import org.apache.commons.lang3.StringUtils;
import org.brapi.client.v2.model.exceptions.ApiException;
import org.brapi.v2.model.BrAPIExternalReference;
import org.brapi.v2.model.pheno.BrAPIObservationUnit;
Copy link
Contributor

Choose a reason for hiding this comment

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

Import unused

Copy link
Contributor Author

Choose a reason for hiding this comment

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

optimized

int rowNum,
ExperimentObservation importRow,
List<Column<?>> phenotypeCols,
Map<String, Trait> colVarMap,
Copy link
Member

Choose a reason for hiding this comment

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

Why was this changed from CaseInsensitiveMap to Map?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think that was deliberate. I reverted it back to CaseInsensitiveMap.

pendingObservation.getAdditionalInfo().add(BrAPIAdditionalInfoFields.CHANGELOG, new JsonArray());
}

if (pendingObservation.getAdditionalInfo() != null && !pendingObservation.getAdditionalInfo().has(BrAPIAdditionalInfoFields.CHANGELOG)) {
Copy link
Member

Choose a reason for hiding this comment

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

Does this work with multiple edits? Will it add entries to the array or create a new one?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It does work with multiple edits. The changelog field in additional info stores an array, and each edit to an observation will add a new entry to that array. I've added some comments in the code here to help clarify.

existingObsByObsHash = fetchExistingObservations(referencedTraits, program);
if (existingObsByObsHash.containsKey(key)) {
if (StringUtils.isNotBlank(value) &&
!existingObsByObsHash.get(key).getValue().equals(value)) {
Copy link
Member

Choose a reason for hiding this comment

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

Mutated is set based on the observation value changing. Not sure if timestamp should be included here or not as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I made changes here and throughout to enable updating timestamps. So, now an observation PIO will have a MUTATED state if either or both value and timestamp differ from what is stored in the brapi service.

@dmeidlin dmeidlin merged commit dadbcf3 into develop Dec 6, 2023
@dmeidlin dmeidlin deleted the feature/BI-1830 branch December 6, 2023 21:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants