Commit 82557b7c authored by Matija Obreza's avatar Matija Obreza
Browse files

AccessionUploader: Don't change `accession.crop` if CROPNAME does not correspond to a Crop

This prevents clearing a previous crop selection by CROPCODE.
parent 0fdf55f7
......@@ -496,9 +496,13 @@ public class AccessionUploader implements InitializingBean {
accession.setCropName(null);
accession.setCrop(null);
} else if (jsonNode.isTextual()) {
// Update cropName and crop (if matching)
// Update cropName
accession.setCropName(StringUtils.abbreviate(jsonNode.asText(), 100));
accession.setCrop(cropService.getCrop(accession.getCropName()));
var autoCrop = cropService.getCrop(accession.getCropName());
if (autoCrop != null) {
// Update Crop if found by name, otherwise don't change
accession.setCrop(autoCrop);
}
}
// Then check for Genesys "cropCode"
......
......@@ -1014,6 +1014,20 @@ public class AccessionUploaderTest extends AbstractServicesTest {
assertThat(saved, notNullValue());
assertThat(saved.getCropName(), nullValue());
assertThat(saved.getCrop(), nullValue());
// Set crop to "maize"
a1.put(Api1Constants.Accession.CROPCODE, "maize");
op = accessionUploader.upsertAccessions(institute2, batch);;
assertThat(op.get(1).getResult().getAction(), is(UpsertResult.Type.UPDATE));
// Set cropName to "wheat" (not registered), this must keep the existing "maize" crop!
a1.put(Api1Constants.Accession.CROPNAME, "wheat");
op = accessionUploader.upsertAccessions(institute2, batch);;
assertThat(op.get(1).getResult().getAction(), is(UpsertResult.Type.UPDATE));
// Assert that cropName is "wheat" and crop is "maize"
saved = accessionService.getByUuid(accessionRepository.findByInstituteCodeAndAccessionNumber(institute2.getCode(), ACCENUMB_1).getUuid());
assertThat(saved, notNullValue());
assertThat(saved.getCropName(), is("wheat"));
assertThat(saved.getCrop().getShortName(), is("maize"));
}
/**
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment