Commit 6e2ea87c authored by Matija Obreza's avatar Matija Obreza

Fix: Accession API upsert fails for blank "remarks"

parent d178b343
......@@ -380,8 +380,8 @@ public class AccessionUploader implements InitializingBean {
if (remarks == null || remarks.isEmpty()) {
existing.clear();
} else {
List<AccessionRemark> toAdd = remarks.stream().filter(rem -> rem != null).filter(rem -> existing.stream().filter(ex -> rem.equalTo(ex)).count() == 0).collect(Collectors.toList());
List<AccessionRemark> toRemove = existing.stream().filter(ex -> remarks.stream().filter(rem -> ex.equalTo(rem)).count() == 0).collect(Collectors.toList());
List<AccessionRemark> toAdd = remarks.stream().filter(rem -> rem != null && ! rem.isEmpty()).filter(rem -> existing.stream().filter(ex -> rem.equalTo(ex)).count() == 0).collect(Collectors.toList());
List<AccessionRemark> toRemove = existing.stream().filter(ex -> ex == null || ex.isEmpty() || remarks.stream().filter(rem -> ex.equalTo(rem)).count() == 0).collect(Collectors.toList());
if (!toRemove.isEmpty() || !toAdd.isEmpty()) {
LOG.info("Removing: {} Adding: {}", toRemove, toAdd);
}
......@@ -394,7 +394,7 @@ public class AccessionUploader implements InitializingBean {
// Make sure we take current remarks!
if (accession.getRemarks() != null) {
accession.getRemarks().stream().forEach(remark -> remark.setAccession(accession));
accession.getRemarks().stream().filter(remark -> remark != null).forEach(remark -> remark.setAccession(accession));
}
}
......
......@@ -205,6 +205,52 @@ public class AccessionControllerTest extends AbstractApiTest {
}
@Test
public void updateRemarks() throws Exception {
ObjectNode accessionJson = setUpAccession();
upsert(accessionJson);
assertThat(accessionRepository.count(), is(1L));
ArrayNode remarks = accessionJson.putArray("remarks");
remarks.add("SAMPSTAT: Cultivated. Relation to parent is unknown");
/*@formatter:off*/
upsert(accessionJson)
.andExpect(jsonPath("$[0].result.action", equalTo("UPDATE")));
/*@formatter:on*/
assertThat(accessionRepository.count(), is(1L));
UUID uuid = accessionRepository.findAll().get(0).getUuid();
Accession result = fetch(uuid);
assertThat(result.getAccessionId().getRemarks().get(0), notNullValue());
assertThat(result.getAccessionId().getRemarks().get(0).getFieldName(), is("SAMPSTAT"));
assertThat(result.getAccessionId().getRemarks().get(0).getRemark(), is("Cultivated. Relation to parent is unknown"));
// Reset remarks
remarks.removeAll();
upsert(accessionJson);
result = fetch(uuid);
assertThat(result.getAccessionId().getRemarks().size(), is(0));
// Set weird remark
remarks.add("WEIRD:");
upsert(accessionJson);
result = fetch(uuid);
System.err.println(result.getAccessionId().getRemarks());
assertThat(result.getAccessionId().getRemarks().size(), is(1));
assertThat(result.getAccessionId().getRemarks().get(0).getRemark(), is("WEIRD:"));
// Set blank remark
remarks.removeAll();
remarks.add("FAIL: ");
upsert(accessionJson);
result = fetch(uuid);
System.err.println(result.getAccessionId().getRemarks());
assertThat(result.getAccessionId().getRemarks().size(), is(0));
}
@Test
public void testUpgradeToArray() throws Exception {
ObjectNode accessionJson = setUpAccession();
......
Markdown is supported
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