Commit 83fc688b authored by Viacheslav Pavlov's avatar Viacheslav Pavlov Committed by Matija Obreza

Add AEGIS status

added test
removed aegis from AccessionOpResponse

added aegis column to accession_historic table

fixed tests, added aegis to overview
parent 5f289395
...@@ -121,7 +121,7 @@ public class AccessionController { ...@@ -121,7 +121,7 @@ public class AccessionController {
private String[] cdnServers; private String[] cdnServers;
private final Set<String> terms = Sets.newHashSet("institute.code", "institute.country.code3", "cropName", "crop.shortName", "taxonomy.genus", "taxonomy.species", private final Set<String> terms = Sets.newHashSet("institute.code", "institute.country.code3", "cropName", "crop.shortName", "taxonomy.genus", "taxonomy.species",
"taxonomy.genusSpecies", "countryOfOrigin.code3", "sampStat", "available", "mlsStatus", "donorCode", "sgsv", "storage", "duplSite", "breederCode"); "taxonomy.genusSpecies", "countryOfOrigin.code3", "sampStat", "available", "mlsStatus", "donorCode", "sgsv", "storage", "duplSite", "breederCode", "aegis");
@GetMapping(value = "/id/{id}", produces = { MediaType.APPLICATION_JSON_VALUE }) @GetMapping(value = "/id/{id}", produces = { MediaType.APPLICATION_JSON_VALUE })
public UUID uuidFromId(@PathVariable("id") final long id) { public UUID uuidFromId(@PathVariable("id") final long id) {
...@@ -198,7 +198,7 @@ public class AccessionController { ...@@ -198,7 +198,7 @@ public class AccessionController {
* @param filter the filter * @param filter the filter
* @return the page * @return the page
* @throws IOException * @throws IOException
* @throws SearchException * @throws SearchException
*/ */
@JsonView({ JsonViews.Root.class }) // same as getAccessionDetails so we get imageGallery! @JsonView({ JsonViews.Root.class }) // same as getAccessionDetails so we get imageGallery!
@PostMapping(value = "/images", produces = { MediaType.APPLICATION_JSON_VALUE }) @PostMapping(value = "/images", produces = { MediaType.APPLICATION_JSON_VALUE })
...@@ -271,7 +271,7 @@ public class AccessionController { ...@@ -271,7 +271,7 @@ public class AccessionController {
/** /**
* Gets accessions by list of uuid-s * Gets accessions by list of uuid-s
* *
* @param uuids accession identifi`ers to lookup in DB * @param uuids accession identifi`ers to lookup in DB
* @return list of Accessions * @return list of Accessions
*/ */
......
...@@ -159,6 +159,9 @@ public abstract class AccessionData extends AuditedVersionedModel implements IdU ...@@ -159,6 +159,9 @@ public abstract class AccessionData extends AuditedVersionedModel implements IdU
@NotNull @NotNull
@Column(name = "historic", nullable = false) @Column(name = "historic", nullable = false)
private boolean historic = false; private boolean historic = false;
@Column(name = "aegis")
private Boolean aegis = false;
@Column(name = "mlsStat") @Column(name = "mlsStat")
private Boolean mlsStatus; private Boolean mlsStatus;
...@@ -500,6 +503,14 @@ public abstract class AccessionData extends AuditedVersionedModel implements IdU ...@@ -500,6 +503,14 @@ public abstract class AccessionData extends AuditedVersionedModel implements IdU
this.donorNumb = donorNumb; this.donorNumb = donorNumb;
} }
public Boolean isAegis() {
return aegis;
}
public void setAegis(Boolean aegis) {
this.aegis = aegis;
}
@JsonGetter @JsonGetter
public String getAccessionName() { public String getAccessionName() {
return this.accessionId.getAliases() != null && this.accessionId.getAliases().size() > 0 return this.accessionId.getAliases() != null && this.accessionId.getAliases().size() > 0
......
...@@ -52,6 +52,9 @@ public class AccessionFilter extends UuidModelFilter<AccessionFilter, Accession> ...@@ -52,6 +52,9 @@ public class AccessionFilter extends UuidModelFilter<AccessionFilter, Accession>
/** The historic. */ /** The historic. */
public Boolean historic; public Boolean historic;
/** The aegis. */
public Boolean aegis;
/** The mls status. */ /** The mls status. */
public Boolean mlsStatus; public Boolean mlsStatus;
...@@ -168,6 +171,9 @@ public class AccessionFilter extends UuidModelFilter<AccessionFilter, Accession> ...@@ -168,6 +171,9 @@ public class AccessionFilter extends UuidModelFilter<AccessionFilter, Accession>
if (historic != null) { if (historic != null) {
and.and(accession.historic.eq(historic)); and.and(accession.historic.eq(historic));
} }
if (aegis != null) {
and.and(accession.aegis.eq(aegis));
}
if (cropName != null) { if (cropName != null) {
and.and(cropName.buildQuery(accession.cropName)); and.and(cropName.buildQuery(accession.cropName));
} }
...@@ -241,6 +247,9 @@ public class AccessionFilter extends UuidModelFilter<AccessionFilter, Accession> ...@@ -241,6 +247,9 @@ public class AccessionFilter extends UuidModelFilter<AccessionFilter, Accession>
if (historic != null) { if (historic != null) {
and.and(accession.historic.eq(historic)); and.and(accession.historic.eq(historic));
} }
if (aegis != null) {
and.and(accession.aegis.eq(aegis));
}
if (crop != null && !crop.isEmpty()) { if (crop != null && !crop.isEmpty()) {
and.and(accession.crop.shortName.in(crop)); and.and(accession.crop.shortName.in(crop));
} }
......
...@@ -83,7 +83,7 @@ public class AccessionServiceImpl implements AccessionService { ...@@ -83,7 +83,7 @@ public class AccessionServiceImpl implements AccessionService {
public static final Logger LOG = LoggerFactory.getLogger(AccessionServiceImpl.class); public static final Logger LOG = LoggerFactory.getLogger(AccessionServiceImpl.class);
private final Set<String> suggestions = Sets.newHashSet("crop.shortName", "institute.code", "taxonomy.genus", "taxonomy.genusSpecies", "taxonomy.species", "countryOfOrigin.code3", "historic", "sampStat", "available", "mlsStatus", "sgsv", "storage"); private final Set<String> suggestions = Sets.newHashSet("aegis", "crop.shortName", "institute.code", "taxonomy.genus", "taxonomy.genusSpecies", "taxonomy.species", "countryOfOrigin.code3", "historic", "sampStat", "available", "mlsStatus", "sgsv", "storage");
/** The accession repository. */ /** The accession repository. */
@Autowired @Autowired
...@@ -293,7 +293,7 @@ public class AccessionServiceImpl implements AccessionService { ...@@ -293,7 +293,7 @@ public class AccessionServiceImpl implements AccessionService {
/** /**
* Converts list of accession IDs to respective accession UUIDs in batches of * Converts list of accession IDs to respective accession UUIDs in batches of
* 100. * 100.
* *
* @see org.genesys2.server.service.AccessionService#uuidsFromIds(java.util.List) * @see org.genesys2.server.service.AccessionService#uuidsFromIds(java.util.List)
*/ */
@Override @Override
......
...@@ -262,7 +262,7 @@ public class AccessionUploader implements InitializingBean { ...@@ -262,7 +262,7 @@ public class AccessionUploader implements InitializingBean {
/** /**
* Check incoming JSON and update values accordingly * Check incoming JSON and update values accordingly
* *
* @param update JSON node * @param update JSON node
* @param updateA Received accession data * @param updateA Received accession data
* @param accession Genesys accession data * @param accession Genesys accession data
...@@ -513,7 +513,7 @@ public class AccessionUploader implements InitializingBean { ...@@ -513,7 +513,7 @@ public class AccessionUploader implements InitializingBean {
updated.setSubtAuthor(null); updated.setSubtAuthor(null);
} }
if (! updated.equalTo(taxonomy)) { if (! updated.equalTo(taxonomy)) {
LOG.trace("Ensuring taxonomy {}", updated); LOG.trace("Ensuring taxonomy {}", updated);
updated = taxonomyService.ensureTaxonomy(updated); updated = taxonomyService.ensureTaxonomy(updated);
accession.setTaxonomy(updated); accession.setTaxonomy(updated);
......
...@@ -5860,3 +5860,29 @@ databaseChangeLog: ...@@ -5860,3 +5860,29 @@ databaseChangeLog:
type: boolean type: boolean
defaultValue: false defaultValue: false
tableName: request tableName: request
- changeSet:
id: 1565780550908-1
author: vpavlov
comment: Add column `aegis` to Accession
changes:
- addColumn:
columns:
- column:
name: aegis
type: boolean
defaultValue: false
tableName: accession
- changeSet:
id: 1565780550908-2
author: vpavlov
comment: Add column `aegis` to AccessionHistoric
changes:
- addColumn:
columns:
- column:
name: aegis
type: boolean
defaultValue: false
tableName: accession_historic
...@@ -139,7 +139,7 @@ public class AccessionControllerTest extends AbstractApiTest { ...@@ -139,7 +139,7 @@ public class AccessionControllerTest extends AbstractApiTest {
@Test @Test
public void createAccessionTest() throws Exception { public void createAccessionTest() throws Exception {
ObjectNode accessionJson = setUpAccession(); ObjectNode accessionJson = setUpAccession(true);
final String s = "[" + verboseMapper.writeValueAsString(accessionJson) + "]"; final String s = "[" + verboseMapper.writeValueAsString(accessionJson) + "]";
/*@formatter:off*/ /*@formatter:off*/
...@@ -158,6 +158,7 @@ public class AccessionControllerTest extends AbstractApiTest { ...@@ -158,6 +158,7 @@ public class AccessionControllerTest extends AbstractApiTest {
/*@formatter:on*/ /*@formatter:on*/
assertThat(accessionRepository.count(), is(1L)); assertThat(accessionRepository.count(), is(1L));
assertThat(accessionRepository.findAll().get(0).isAegis(), is(true));
} }
@Test @Test
...@@ -211,6 +212,59 @@ public class AccessionControllerTest extends AbstractApiTest { ...@@ -211,6 +212,59 @@ public class AccessionControllerTest extends AbstractApiTest {
/*@formatter:on*/ /*@formatter:on*/
} }
@Test
public void aegisFilterTest() throws Exception {
Accession withAegis = addAccessionInDB(true);
Accession withoutAegis = addAccessionInDB(false);
Accession nullAegis = addAccessionInDB(null);
accessionRepository.save(withAegis);
accessionRepository.save(withoutAegis);
accessionRepository.save(nullAegis);
AccessionFilter filter = new AccessionFilter();
filter.aegis = true;
/*@formatter:off*/
mockMvc
.perform(post(AccessionUploadController.CONTROLLER_URL + "/list")
.contentType(MediaType.APPLICATION_JSON)
.content(verboseMapper.writeValueAsString(filter)))
// .andDo(MockMvcResultHandlers.print())
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8))
.andExpect(jsonPath("$.totalElements", is(1)))
.andExpect(jsonPath("$.content[0].aegis", is(true)))
.andExpect(jsonPath("$.content[0].uuid", is(withAegis.getUuid().toString())));
/*@formatter:on*/
filter.aegis = false;
mockMvc
.perform(post(AccessionUploadController.CONTROLLER_URL + "/list")
.contentType(MediaType.APPLICATION_JSON)
.content(verboseMapper.writeValueAsString(filter)))
// .andDo(MockMvcResultHandlers.print())
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8))
.andExpect(jsonPath("$.totalElements", is(1)))
.andExpect(jsonPath("$.content[0].aegis", is(false)))
.andExpect(jsonPath("$.content[0].uuid", is(withoutAegis.getUuid().toString())));
/*@formatter:on*/
filter.aegis = null;
filter.isNull().add("aegis");
mockMvc
.perform(post(AccessionUploadController.CONTROLLER_URL + "/list")
.contentType(MediaType.APPLICATION_JSON)
.content(verboseMapper.writeValueAsString(filter)))
// .andDo(MockMvcResultHandlers.print())
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8))
.andExpect(jsonPath("$.totalElements", is(1)))
.andExpect(jsonPath("$.content[0].aegis", isEmptyOrNullString()))
.andExpect(jsonPath("$.content[0].uuid", is(nullAegis.getUuid().toString())));
/*@formatter:on*/
}
@Test @Test
public void getAccessionsTest() throws Exception { public void getAccessionsTest() throws Exception {
...@@ -562,13 +616,15 @@ public class AccessionControllerTest extends AbstractApiTest { ...@@ -562,13 +616,15 @@ public class AccessionControllerTest extends AbstractApiTest {
final List<Accession> accessions = new ArrayList<>(amount); final List<Accession> accessions = new ArrayList<>(amount);
for (int i = 0; i < amount; i++) { for (int i = 0; i < amount; i++) {
accessions.add(addAccessionInDB()); accessions.add(addAccessionInDB(false));
} }
return accessionRepository.save(accessions); return accessionRepository.save(accessions);
} }
private Accession addAccessionInDB() { private Accession addAccessionInDB(Boolean aegis) {
Accession a = new Accession(); Accession a = new Accession();
a.setAegis(aegis);
a.setAccessionId(new AccessionId());
a.setAccessionId(new AccessionId()); a.setAccessionId(new AccessionId());
AccessionGeo accessionGeo = new AccessionGeo(); AccessionGeo accessionGeo = new AccessionGeo();
accessionGeo.setLongitude(75d); accessionGeo.setLongitude(75d);
...@@ -585,6 +641,17 @@ public class AccessionControllerTest extends AbstractApiTest { ...@@ -585,6 +641,17 @@ public class AccessionControllerTest extends AbstractApiTest {
private ObjectNode setUpAccession() { private ObjectNode setUpAccession() {
ObjectNode accession = objectMapper.createObjectNode(); ObjectNode accession = objectMapper.createObjectNode();
accession.put("instituteCode", institute.getCode()); accession.put("instituteCode", institute.getCode());
accession.put("aegis", false);
accession.put("accessionNumber", "A" + acceNumb.incrementAndGet());
ObjectNode taxa = accession.putObject("taxonomy");
taxa.put("genus", "Manihot");
return accession;
}
private ObjectNode setUpAccession(Boolean aegis) {
ObjectNode accession = objectMapper.createObjectNode();
accession.put("instituteCode", institute.getCode());
accession.put("aegis", aegis);
accession.put("accessionNumber", "A" + acceNumb.incrementAndGet()); accession.put("accessionNumber", "A" + acceNumb.incrementAndGet());
ObjectNode taxa = accession.putObject("taxonomy"); ObjectNode taxa = accession.putObject("taxonomy");
taxa.put("genus", "Manihot"); taxa.put("genus", "Manihot");
......
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