Commit 5a3a1df0 authored by Maxym Borodenko's avatar Maxym Borodenko
Browse files

Add mls_status to Accession

parent ba91ed0c
......@@ -15,6 +15,8 @@
*/
package org.gringlobal.model;
import static org.gringlobal.model.community.CommunityCodeValues.ACCESSION_MLS_STATUS;
import java.util.Date;
import java.util.List;
......@@ -49,7 +51,6 @@ import org.gringlobal.custom.elasticsearch.SearchField;
import org.gringlobal.custom.validation.javax.CodeValueField;
import org.gringlobal.custom.validation.javax.OneLine;
import org.gringlobal.model.community.IWebVisible;
import org.hibernate.Hibernate;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldType;
......@@ -86,6 +87,11 @@ public class Accession extends CooperatorOwnedModel implements IWebVisible, Copy
@Column(name = "accession_number", length = 128)
private String accessionNumber;
@Size(max = 50)
@Column(name = "mls_status", length = 50)
@CodeValueField(value = ACCESSION_MLS_STATUS, indexed = true)
private String mlsStatus;
@Basic
@OneLine
@NotNull
......@@ -264,6 +270,14 @@ public class Accession extends CooperatorOwnedModel implements IWebVisible, Copy
this.accessionNumberPart1 = accessionNumberPart1;
}
public String getMlsStatus() {
return mlsStatus;
}
public void setMlsStatus(final String mlsStatus) {
this.mlsStatus = mlsStatus;
}
public Long getAccessionNumberPart2() {
return accessionNumberPart2;
}
......
......@@ -162,6 +162,14 @@ public abstract class CommunityCodeValues {
public static final String ACCESSION_ACTION = "ACCESSION_ACTION";
public static final CodeValueDef ACCESSION_ACTION_ACCNUMBERD = new CodeValueDef(ACCESSION_ACTION, "ACCNUMBERD", "ACCNUMBERD", "Date on which a change occurred to the accession number. See note field in the action for the original number and what it was changed to.");
public static final String ACCESSION_MLS_STATUS = "ACCESSION_MLS_STATUS";
public static final CodeValueDef ACCESSION_MLS_STATUS_N = new CodeValueDef(ACCESSION_MLS_STATUS, "N", "Not in MLS", "Not available under the MLS");
public static final CodeValueDef ACCESSION_MLS_STATUS_Y = new CodeValueDef(ACCESSION_MLS_STATUS, "Y", "In MLS", "Available under the MLS");
public static final CodeValueDef ACCESSION_MLS_STATUS_ANNEX1 = new CodeValueDef(ACCESSION_MLS_STATUS, "ANNEX1", "In MLS (Annex I)", "The PGRFA belongs to a crop listed in Annex I and is under the management and control of a Contracting Party to the Treaty and declared to be in the public domain");
public static final CodeValueDef ACCESSION_MLS_STATUS_ARTICLE15 = new CodeValueDef(ACCESSION_MLS_STATUS, "ARTICLE15", "In MLS (Article 15)", "The sample is in a collection subject to an agreement concluded under Article 15 of the Treaty");
public static final CodeValueDef ACCESSION_MLS_STATUS_SMTA_SOURCE = new CodeValueDef(ACCESSION_MLS_STATUS, "SMTA_SOURCE", "In MLS (Received with SMTA)", "The holder received the sample with SMTA");
public static final CodeValueDef ACCESSION_MLS_STATUS_MLS_DEVELOP = new CodeValueDef(ACCESSION_MLS_STATUS, "MLS_DEVELOP", "In MLS (Under development)", "The PGRFA is derived from, and distinct from, material previously received from the MLS, is still under development and not yet ready for commercialization, and may be made available at the discretion of the developer");
public static final String ANNOTATION_TYPE = "ANNOTATION_TYPE";
public static final CodeValueDef ANNOTATION_TYPE_RECEIVED = new CodeValueDef(ANNOTATION_TYPE, "RECEIVED", "The taxonomic name of the accession when it was received", null);
public static final CodeValueDef ANNOTATION_TYPE_RE_IDENT = new CodeValueDef(ANNOTATION_TYPE, "RE-IDENT", "Taxonomic Re-Identification", null);
......
......@@ -60,6 +60,9 @@ public class AccessionFilter extends CooperatorOwnedModelFilter<AccessionFilter,
/** The improvement status code. */
public Set<String> improvementStatusCode;
/** The MLS status. */
public Set<String> mlsStatus;
/** The initial received date. */
public DateFilter initialReceivedDate;
......@@ -148,6 +151,9 @@ public class AccessionFilter extends CooperatorOwnedModelFilter<AccessionFilter,
if (CollectionUtils.isNotEmpty(improvementStatusCode)) {
predicates.add(accession.improvementStatusCode.in(improvementStatusCode));
}
if (CollectionUtils.isNotEmpty(mlsStatus)) {
predicates.add(accession.mlsStatus.in(mlsStatus));
}
if (initialReceivedDate != null) {
predicates.add(initialReceivedDate.buildQuery(accession.initialReceivedDate));
}
......
......@@ -8306,3 +8306,14 @@ databaseChangeLog:
columnName: redirect
newDataType: varchar(2000)
tableName: oauthclient
- changeSet:
id: 1624977790584-1
author: mborodenko
changes:
- addColumn:
columns:
- column:
name: mls_status
type: varchar(50)
tableName: accession
......@@ -486,4 +486,46 @@ public class AccessionControllerTest extends AbstractApiV1Test {
;
/*@formatter:on*/
}
@Test
public void testCreateAccessionWithMlsStatus() throws Exception {
// build accession
Accession a = new Accession();
a.setAccessionNumberPart1("TVu");
a.setAccessionNumberPart2(1L);
a.setIsBackedUp(TRUE);
a.setIsCore(TRUE);
a.setIsWebVisible(TRUE);
a.setStatusCode(ACCESSION_STATUS_CODE);
a.setTaxonomySpecies(addTaxonomySpeciesToDB());
a.setSite(DEFAULT_SITE);
a.setMlsStatus("InvalidMLS");
/*@formatter:off*/
mockMvc
.perform(post(AccessionController.API_URL)
.content(verboseMapper.writeValueAsString(a))
.contentType(MediaType.APPLICATION_JSON)
)
// .andDo(org.springframework.test.web.servlet.result.MockMvcResultHandlers.print())
.andExpect(status().isBadRequest())
;
/*@formatter:on*/
a.setMlsStatus(CommunityCodeValues.ACCESSION_MLS_STATUS_Y.value);
/*@formatter:off*/
mockMvc
.perform(post(AccessionController.API_URL)
.content(verboseMapper.writeValueAsString(a))
.contentType(MediaType.APPLICATION_JSON)
)
// .andDo(org.springframework.test.web.servlet.result.MockMvcResultHandlers.print())
.andExpect(status().isOk())
.andExpect(jsonPath("$", notNullValue()))
.andExpect(jsonPath("$.id", is(greaterThan(0))))
.andExpect(jsonPath("$.mlsStatus", is(CommunityCodeValues.ACCESSION_MLS_STATUS_Y.value)))
;
/*@formatter:on*/
}
}
......@@ -74,6 +74,7 @@ import org.junit.After;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataIntegrityViolationException;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.security.test.context.support.WithUserDetails;
import org.springframework.transaction.annotation.Transactional;
......@@ -506,6 +507,35 @@ public class AccessionServiceTest extends AbstractServicesTest {
assertThat(accessionSourceRepository.count(), is(1L));
}
@Test
public void filterByMLSTest() throws Exception {
// build accession
Accession a = new Accession();
a.setAccessionNumberPart1("AccessionNumberPart1");
a.setIsBackedUp(TRUE);
a.setIsCore(TRUE);
a.setIsWebVisible(TRUE);
a.setStatusCode(ACCESSION_STATUS_CODE);
a.setTaxonomySpecies(addTaxonomySpeciesToDB());
a.setSite(DEFAULT_SITE);
a.setMlsStatus(CommunityCodeValues.ACCESSION_MLS_STATUS_Y.value);
// add accession to DB
Accession savedAccession = accessionService.create(a);
assertThat(savedAccession, is(notNullValue()));
var filter = new AccessionFilter();
filter.mlsStatus = Set.of(CommunityCodeValues.ACCESSION_MLS_STATUS_N.value);
Page<Accession> res = accessionService.list(filter, PageRequest.of(0, 5));
assertThat(res.getTotalElements(), is(0L));
filter.mlsStatus = Set.of(CommunityCodeValues.ACCESSION_MLS_STATUS_Y.value);
res = accessionService.list(filter, PageRequest.of(0, 5));
assertThat(res.getTotalElements(), is(1L));
assertThat(res.getContent().get(0).getId(), is(savedAccession.getId()));
}
@Test
public void getAccessionDetailsTest() {
// build accession
......
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