Commit e316fcd1 authored by Matija Obreza's avatar Matija Obreza

Merge branch '463-add-aegis-status' into 'master'

Resolve "Add AEGIS status"

Closes #463

See merge request genesys-pgr/genesys-server!445
parents 5f289395 d7628d99
......@@ -121,7 +121,7 @@ public class AccessionController {
private String[] cdnServers;
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 })
public UUID uuidFromId(@PathVariable("id") final long id) {
......@@ -198,7 +198,7 @@ public class AccessionController {
* @param filter the filter
* @return the page
* @throws IOException
* @throws SearchException
* @throws SearchException
*/
@JsonView({ JsonViews.Root.class }) // same as getAccessionDetails so we get imageGallery!
@PostMapping(value = "/images", produces = { MediaType.APPLICATION_JSON_VALUE })
......@@ -271,7 +271,7 @@ public class AccessionController {
/**
* Gets accessions by list of uuid-s
*
*
* @param uuids accession identifi`ers to lookup in DB
* @return list of Accessions
*/
......
......@@ -159,6 +159,9 @@ public abstract class AccessionData extends AuditedVersionedModel implements IdU
@NotNull
@Column(name = "historic", nullable = false)
private boolean historic = false;
@Column(name = "aegis")
private Boolean aegis = false;
@Column(name = "mlsStat")
private Boolean mlsStatus;
......@@ -500,6 +503,14 @@ public abstract class AccessionData extends AuditedVersionedModel implements IdU
this.donorNumb = donorNumb;
}
public Boolean isAegis() {
return aegis;
}
public void setAegis(Boolean aegis) {
this.aegis = aegis;
}
@JsonGetter
public String getAccessionName() {
return this.accessionId.getAliases() != null && this.accessionId.getAliases().size() > 0
......
......@@ -54,10 +54,12 @@ import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldIndex;
import org.springframework.data.elasticsearch.annotations.FieldType;
import com.fasterxml.jackson.annotation.JsonIdentityInfo;
import com.fasterxml.jackson.annotation.JsonIdentityReference;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonView;
import com.fasterxml.jackson.annotation.ObjectIdGenerators;
import cz.jirutka.validator.collection.constraints.EachPattern;
import cz.jirutka.validator.collection.constraints.EachSize;
......@@ -90,6 +92,7 @@ public class AccessionId extends AuditedVersionedModel implements IdUUID {
@JoinTable(name = "accession_listitem", joinColumns = @JoinColumn(name = "acceid"), inverseJoinColumns = @JoinColumn(name = "listid"))
@JsonView({ JsonViews.Indexed.class })
@JsonIdentityReference(alwaysAsId = true)
@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "uuid", scope = AccessionList.class)
@Field(index = FieldIndex.not_analyzed, type = FieldType.String)
private Set<AccessionList> lists;
......
......@@ -52,6 +52,9 @@ public class AccessionFilter extends UuidModelFilter<AccessionFilter, Accession>
/** The historic. */
public Boolean historic;
/** The aegis. */
public Boolean aegis;
/** The mls status. */
public Boolean mlsStatus;
......@@ -168,6 +171,9 @@ public class AccessionFilter extends UuidModelFilter<AccessionFilter, Accession>
if (historic != null) {
and.and(accession.historic.eq(historic));
}
if (aegis != null) {
and.and(accession.aegis.eq(aegis));
}
if (cropName != null) {
and.and(cropName.buildQuery(accession.cropName));
}
......@@ -241,6 +247,9 @@ public class AccessionFilter extends UuidModelFilter<AccessionFilter, Accession>
if (historic != null) {
and.and(accession.historic.eq(historic));
}
if (aegis != null) {
and.and(accession.aegis.eq(aegis));
}
if (crop != null && !crop.isEmpty()) {
and.and(accession.crop.shortName.in(crop));
}
......
......@@ -83,7 +83,7 @@ public class AccessionServiceImpl implements AccessionService {
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. */
@Autowired
......@@ -293,7 +293,7 @@ public class AccessionServiceImpl implements AccessionService {
/**
* Converts list of accession IDs to respective accession UUIDs in batches of
* 100.
*
*
* @see org.genesys2.server.service.AccessionService#uuidsFromIds(java.util.List)
*/
@Override
......
......@@ -17,11 +17,11 @@ package org.genesys2.server.service.impl;
import static org.elasticsearch.index.query.QueryBuilders.*;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap;
......@@ -89,6 +89,7 @@ import org.genesys2.server.service.AccessionService.IBatchAction;
import org.genesys2.server.service.ElasticsearchService;
import org.genesys2.server.service.filter.IFullTextFilter;
import org.genesys2.spring.config.ElasticsearchConfig;
import org.genesys2.spring.config.ElasticsearchConfig.GenesysEntityMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.InitializingBean;
......@@ -172,6 +173,8 @@ public class ElasticsearchServiceImpl implements ElasticsearchService, Initializ
/// Size of database batch scan for IDs
private int batchSize = 1000;
private final GenesysEntityMapper mapper = new ElasticsearchConfig.GenesysEntityMapper();
@Override
public void afterPropertiesSet() throws Exception {
if (withElasticsearch()) {
......@@ -193,8 +196,7 @@ public class ElasticsearchServiceImpl implements ElasticsearchService, Initializ
LOG.warn("Elasticsearch not accessible, not updating mappings");
}
ObjectMapper mapper = new ElasticsearchConfig.GenesysEntityMapper().getObjectMapper();
JsonSchemaGenerator schemaGen = new JsonSchemaGenerator(mapper);
JsonSchemaGenerator schemaGen = new JsonSchemaGenerator(mapper.getObjectMapper());
for (Class<? extends BasicModel> clazz: indexedEntities) {
try {
JsonSchema schema = schemaGen.generateSchema(clazz);
......@@ -480,21 +482,17 @@ public class ElasticsearchServiceImpl implements ElasticsearchService, Initializ
List<IndexQuery> queries = new ArrayList<IndexQuery>();
// ObjectMapper om = new ObjectMapper();
// om.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS);
// om.disable(SerializationFeature.EAGER_SERIALIZER_FETCH);
// ObjectWriter pp = om.writerWithDefaultPrettyPrinter();
Map<String, String> jsons = new HashMap<>();
for (R x : results) {
LOG.trace("Indexing {} {}", clazz.getName(), x);
BasicModel bm = (BasicModel) x;
// try {
//// LOG.debug(om.writeValueAsString(bm));
// } catch (JsonProcessingException e) {
// LOG.error(e.getMessage(), e);
// }
try {
jsons.put(bm.getId().toString(), mapper.mapToString(bm));
} catch (IOException e) {
e.printStackTrace();
}
// is found
notFoundIds.remove(bm.getId());
......@@ -517,7 +515,7 @@ public class ElasticsearchServiceImpl implements ElasticsearchService, Initializ
Map<String, String> failedDocs = e.getFailedDocuments();
if (failedDocs != null) {
for (String key : failedDocs.keySet()) {
LOG.error("{} {}", key, failedDocs.get(key));
LOG.error("{} {}\n{}", key, failedDocs.get(key), jsons.get(key));
}
}
} catch (ElasticsearchException e) {
......
......@@ -262,7 +262,7 @@ public class AccessionUploader implements InitializingBean {
/**
* Check incoming JSON and update values accordingly
*
*
* @param update JSON node
* @param updateA Received accession data
* @param accession Genesys accession data
......@@ -513,7 +513,7 @@ public class AccessionUploader implements InitializingBean {
updated.setSubtAuthor(null);
}
if (! updated.equalTo(taxonomy)) {
if (! updated.equalTo(taxonomy)) {
LOG.trace("Ensuring taxonomy {}", updated);
updated = taxonomyService.ensureTaxonomy(updated);
accession.setTaxonomy(updated);
......
......@@ -5860,3 +5860,29 @@ databaseChangeLog:
type: boolean
defaultValue: false
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 {
@Test
public void createAccessionTest() throws Exception {
ObjectNode accessionJson = setUpAccession();
ObjectNode accessionJson = setUpAccession(true);
final String s = "[" + verboseMapper.writeValueAsString(accessionJson) + "]";
/*@formatter:off*/
......@@ -158,6 +158,7 @@ public class AccessionControllerTest extends AbstractApiTest {
/*@formatter:on*/
assertThat(accessionRepository.count(), is(1L));
assertThat(accessionRepository.findAll().get(0).isAegis(), is(true));
}
@Test
......@@ -211,6 +212,59 @@ public class AccessionControllerTest extends AbstractApiTest {
/*@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
public void getAccessionsTest() throws Exception {
......@@ -562,13 +616,15 @@ public class AccessionControllerTest extends AbstractApiTest {
final List<Accession> accessions = new ArrayList<>(amount);
for (int i = 0; i < amount; i++) {
accessions.add(addAccessionInDB());
accessions.add(addAccessionInDB(false));
}
return accessionRepository.save(accessions);
}
private Accession addAccessionInDB() {
private Accession addAccessionInDB(Boolean aegis) {
Accession a = new Accession();
a.setAegis(aegis);
a.setAccessionId(new AccessionId());
a.setAccessionId(new AccessionId());
AccessionGeo accessionGeo = new AccessionGeo();
accessionGeo.setLongitude(75d);
......@@ -585,6 +641,17 @@ public class AccessionControllerTest extends AbstractApiTest {
private ObjectNode setUpAccession() {
ObjectNode accession = objectMapper.createObjectNode();
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());
ObjectNode taxa = accession.putObject("taxonomy");
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