...
 
Commits (3)
......@@ -19,6 +19,7 @@ import javax.persistence.*;
import org.genesys.blocks.model.Copyable;
import org.gringlobal.component.elastic.ElasticTrigger;
import org.gringlobal.custom.validation.javax.CodeValueField;
import com.fasterxml.jackson.annotation.JsonIdentityInfo;
import com.fasterxml.jackson.annotation.JsonProperty;
......@@ -46,6 +47,7 @@ public class AccessionInvName extends CooperatorOwnedModel implements ElasticTri
@Basic
@Column(name = "category_code", nullable = false, length = 20)
@CodeValueField("ACCESSION_NAME_TYPE")
private String categoryCode;
@Basic
......
......@@ -22,6 +22,8 @@ import java.util.List;
import javax.persistence.*;
import org.genesys.blocks.model.Copyable;
import org.gringlobal.custom.validation.javax.CodeValueField;
import org.gringlobal.model.community.CommunityCodeValues;
import com.fasterxml.jackson.annotation.JsonIdentityInfo;
import com.fasterxml.jackson.annotation.JsonIgnore;
......@@ -38,18 +40,6 @@ import com.fasterxml.jackson.annotation.ObjectIdGenerators;
public class AccessionSource extends CooperatorOwnedModel implements Copyable<AccessionSource> {
private static final long serialVersionUID = 8820879032034410951L;
/**
* ACCESSION_SOURCE_TYPE code_group
*/
public static enum SourceType {
/** "COLLECTED" Collection source event */
COLLECTED,
/** "DEVELOPED" Developer source event */
DEVELOPED,
/** "DONATED" Donor source event */
DONATED,
}
/**
* ACCESSION_SOURCE_HABITAT_TYPE code_group
*/
......@@ -145,10 +135,12 @@ public class AccessionSource extends CooperatorOwnedModel implements Copyable<Ac
@Basic
@Column(name = "source_type_code", nullable = false, length = 20)
@CodeValueField(CommunityCodeValues.ACCESSION_SOURCE_TYPE)
private String sourceTypeCode;
@Basic
@Column(name = "acquisition_source_code", length = 20)
@CodeValueField("ACCESSION_SOURCE_HABITAT_TYPE")
private String acquisitionSource;
@Basic
......@@ -158,6 +150,7 @@ public class AccessionSource extends CooperatorOwnedModel implements Copyable<Ac
@Basic
@Column(name = "collected_form_code", length = 20)
@CodeValueField(CommunityCodeValues.GERMPLASM_FORM)
private String collectedFormCode;
@Basic
......@@ -194,6 +187,7 @@ public class AccessionSource extends CooperatorOwnedModel implements Copyable<Ac
@Basic
@Column(name = "georeference_protocol_code", length = 20)
@CodeValueField("GEOREFERENCE_PROTOCOL")
private String georeferenceProtocolCode;
@Basic
......@@ -229,6 +223,7 @@ public class AccessionSource extends CooperatorOwnedModel implements Copyable<Ac
@Basic
@Column(name = "source_date_code", length = 20)
@CodeValueField(CommunityCodeValues.DATE_FORMAT)
private String sourceDateCode;
@Basic
......@@ -236,6 +231,7 @@ public class AccessionSource extends CooperatorOwnedModel implements Copyable<Ac
@Basic
@Column(name = "unit_quantity_collected_code", length = 20)
@CodeValueField(CommunityCodeValues.UNIT_OF_QUANTITY)
private String unitQuantityCollectedCode;
@JsonIgnore
......
......@@ -35,6 +35,20 @@ public abstract class CommunityCodeValues {
public static final String UNIT_OF_QUANTITY = "UNIT_OF_QUANTITY";
public static final CodeValueDef UNIT_OF_QUANTITY_SEED;
public static final String ACCESSION_SOURCE_TYPE = "ACCESSION_SOURCE_TYPE";
public static final CodeValueDef ACCESSION_SOURCE_TYPE_COLLECTED;
public static final CodeValueDef ACCESSION_SOURCE_TYPE_DEVELOPED;
public static final CodeValueDef ACCESSION_SOURCE_TYPE_DONATED;
public static final String ACCESSION_NAME_TYPE = "ACCESSION_NAME_TYPE";
public static final CodeValueDef ACCESSION_NAME_TYPE_COLLECTOR;
public static final CodeValueDef ACCESSION_NAME_TYPE_CULTIVAR;
public static final CodeValueDef ACCESSION_NAME_TYPE_DONOR;
public static final CodeValueDef ACCESSION_NAME_TYPE_DEVELOPER;
public static final String ACCESSION_RESTRICTION_TYPE = "ACCESSION_RESTRICTION_TYPE";
public static final CodeValueDef ACCESSION_RESTRICTION_TYPE_SMTA;
public static final String INVENTORY_AVAILABILITY_STATUS = "INVENTORY_AVAILABILITY_STATUS";
public static final CodeValueDef INVENTORY_AVAILABILITY_LOWINVENTORY;
public static final CodeValueDef INVENTORY_AVAILABILITY_AVAILABLE;
......@@ -68,6 +82,20 @@ public abstract class CommunityCodeValues {
DATE_FORMAT_DATETIME = new CodeValueDef(DATE_FORMAT, "yyyy-MM-dd HH:mm", "Date and time", "yyyy-MM-dd HH:mm");
DATE_FORMAT_DATE = new CodeValueDef(DATE_FORMAT, "yyyy-MM-dd", "Date", "yyyy-MM-dd");
// Accession source type
ACCESSION_SOURCE_TYPE_COLLECTED = new CodeValueDef(ACCESSION_SOURCE_TYPE, "COLLECTED", "Collection source event", null);
ACCESSION_SOURCE_TYPE_DEVELOPED = new CodeValueDef(ACCESSION_SOURCE_TYPE, "DEVELOPED", "Developer source event", null);
ACCESSION_SOURCE_TYPE_DONATED = new CodeValueDef(ACCESSION_SOURCE_TYPE, "DONATED", "Donor source event", null);
// Accession name types
ACCESSION_NAME_TYPE_COLLECTOR = new CodeValueDef(ACCESSION_NAME_TYPE, "COLLECTOR", "Collector identifier", null);
ACCESSION_NAME_TYPE_CULTIVAR = new CodeValueDef(ACCESSION_NAME_TYPE, "CULTIVAR", "Cultivar name", null);
ACCESSION_NAME_TYPE_DONOR = new CodeValueDef(ACCESSION_NAME_TYPE, "DONOR", "Donor identifier", null);
ACCESSION_NAME_TYPE_DEVELOPER = new CodeValueDef(ACCESSION_NAME_TYPE, "DEVELOPER", "Developer identifier", null);
// Accession IPR types
ACCESSION_RESTRICTION_TYPE_SMTA = new CodeValueDef(ACCESSION_RESTRICTION_TYPE, "MTA-SMTA", "FAO Standard Material Transfer Agreement", null);
// Inventory availability
INVENTORY_AVAILABILITY_LOWINVENTORY = new CodeValueDef(INVENTORY_AVAILABILITY_STATUS, "LOW", "Low inventory", null);
INVENTORY_AVAILABILITY_AVAILABLE = new CodeValueDef(INVENTORY_AVAILABILITY_STATUS, "AVAIL", "Available", null);
......
......@@ -37,6 +37,7 @@ import org.gringlobal.model.TaxonomyCropMap;
import org.gringlobal.model.TaxonomyFamily;
import org.gringlobal.model.TaxonomyGenus;
import org.gringlobal.model.TaxonomySpecies;
import org.gringlobal.model.community.CommunityCodeValues;
import org.gringlobal.persistence.AccessionRepository;
import org.gringlobal.persistence.GeographyRepository;
import org.gringlobal.persistence.SiteRepository;
......@@ -398,10 +399,10 @@ public class GenesysDownloader implements InitializingBean {
if (donorWiews != null || donorName != null) {
sources = getOrCreateAccessionSources(a);
AccessionSource donorSource = sources.stream().filter((source) -> source.getSourceTypeCode() == AccessionSource.SourceType.DONATED.name()).findFirst().orElse(null);
AccessionSource donorSource = sources.stream().filter((source) -> source.getSourceTypeCode() == CommunityCodeValues.ACCESSION_SOURCE_TYPE_DONATED.value).findFirst().orElse(null);
if (donorSource == null) {
donorSource = new AccessionSource();
donorSource.setSourceTypeCode(AccessionSource.SourceType.DONATED.name());
donorSource.setSourceTypeCode(CommunityCodeValues.ACCESSION_SOURCE_TYPE_DONATED.value);
donorSource.setAccession(a);
sources.add(donorSource);
}
......@@ -419,10 +420,10 @@ public class GenesysDownloader implements InitializingBean {
ObjectNode nodeGeo = acce.hasNonNull("geo") ? (ObjectNode) acce.get("geo") : null;
if (origCty != null || nodeGeo != null || nodeCollecting != null) {
sources = getOrCreateAccessionSources(a);
AccessionSource collectingSource = sources.stream().filter((source) -> source.getSourceTypeCode() == AccessionSource.SourceType.COLLECTED.name()).findFirst().orElse(null);
AccessionSource collectingSource = sources.stream().filter((source) -> source.getSourceTypeCode() == CommunityCodeValues.ACCESSION_SOURCE_TYPE_COLLECTED.value).findFirst().orElse(null);
if (collectingSource == null) {
collectingSource = new AccessionSource();
collectingSource.setSourceTypeCode(AccessionSource.SourceType.COLLECTED.name());
collectingSource.setSourceTypeCode(CommunityCodeValues.ACCESSION_SOURCE_TYPE_COLLECTED.value);
collectingSource.setAccession(a);
sources.add(collectingSource);
}
......
......@@ -168,7 +168,7 @@ public class InventoryControllerTest extends AbstractApiV1Test {
.contentType(MediaType.APPLICATION_JSON)
.content(verboseMapper.writeValueAsString(quantity))
)
.andDo(org.springframework.test.web.servlet.result.MockMvcResultHandlers.print())
// .andDo(org.springframework.test.web.servlet.result.MockMvcResultHandlers.print())
.andExpect(status().isOk())
;
/*@formatter:on*/
......@@ -226,7 +226,7 @@ public class InventoryControllerTest extends AbstractApiV1Test {
.contentType(MediaType.APPLICATION_JSON)
.content(verboseMapper.writeValueAsString(quantity))
)
.andDo(org.springframework.test.web.servlet.result.MockMvcResultHandlers.print())
// .andDo(org.springframework.test.web.servlet.result.MockMvcResultHandlers.print())
.andExpect(status().isOk())
;
/*@formatter:on*/
......
......@@ -15,22 +15,13 @@
*/
package org.gringlobal.test.api.v1;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.containsInAnyOrder;
import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.MatcherAssert.*;
import static org.hamcrest.Matchers.*;
import static org.hamcrest.Matchers.nullValue;
import static org.hamcrest.core.IsNull.notNullValue;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.put;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
import com.google.common.collect.Sets;
import org.genesys.blocks.oauth.model.OAuthClient;
import org.genesys.blocks.oauth.persistence.OAuthClientRepository;
import org.genesys.blocks.oauth.service.OAuthClientDetailsService;
......@@ -43,9 +34,10 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.security.test.context.support.WithUserDetails;
import org.springframework.test.web.servlet.result.MockMvcResultHandlers;
import org.springframework.transaction.annotation.Transactional;
import com.google.common.collect.Sets;
/**
* @author Maxym Borodenko
*/
......@@ -87,8 +79,7 @@ public class OAuthManagementControllerTest extends AbstractApiV1Test {
.perform(post(OAuthManagementController.API_URL + "/filter")
.contentType(MediaType.APPLICATION_JSON)
.content(verboseMapper.writeValueAsString(filter)))
.andDo(MockMvcResultHandlers.print())
.andDo(MockMvcResultHandlers.print())
// .andDo(org.springframework.test.web.servlet.result.MockMvcResultHandlers.print())
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
.andExpect(jsonPath("$.content", hasSize(1)))
......@@ -108,7 +99,7 @@ public class OAuthManagementControllerTest extends AbstractApiV1Test {
.perform(post(OAuthManagementController.API_URL)
.contentType(MediaType.APPLICATION_JSON)
.content(verboseMapper.writeValueAsString(client)))
// .andDo(MockMvcResultHandlers.print())
// .andDo(org.springframework.test.web.servlet.result.MockMvcResultHandlers.print())
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
.andExpect(jsonPath("$", notNullValue()))
......@@ -141,7 +132,7 @@ public class OAuthManagementControllerTest extends AbstractApiV1Test {
.perform(put(OAuthManagementController.API_URL)
.contentType(MediaType.APPLICATION_JSON)
.content(verboseMapper.writeValueAsString(client)))
// .andDo(MockMvcResultHandlers.print())
// .andDo(org.springframework.test.web.servlet.result.MockMvcResultHandlers.print())
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
.andExpect(jsonPath("$", notNullValue()))
......@@ -167,7 +158,7 @@ public class OAuthManagementControllerTest extends AbstractApiV1Test {
mockMvc
.perform(delete(OAuthManagementController.API_URL + OAuthManagementController.ENDPOINT_CLIENT_ID, client.getClientId())
.contentType(MediaType.APPLICATION_JSON))
// .andDo(MockMvcResultHandlers.print())
// .andDo(org.springframework.test.web.servlet.result.MockMvcResultHandlers.print())
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
;
......@@ -185,7 +176,7 @@ public class OAuthManagementControllerTest extends AbstractApiV1Test {
mockMvc
.perform(post(OAuthManagementController.API_URL + "/{clientId}/secret", client.getClientId())
.contentType(MediaType.APPLICATION_JSON))
// .andDo(MockMvcResultHandlers.print())
// .andDo(org.springframework.test.web.servlet.result.MockMvcResultHandlers.print())
.andExpect(status().isOk())
.andExpect(jsonPath("$").exists())
.andExpect(jsonPath("$").isString())
......@@ -203,7 +194,7 @@ public class OAuthManagementControllerTest extends AbstractApiV1Test {
mockMvc
.perform(delete(OAuthManagementController.API_URL + "/{clientId}/secret", client.getClientId())
.contentType(MediaType.APPLICATION_JSON))
// .andDo(MockMvcResultHandlers.print())
// .andDo(org.springframework.test.web.servlet.result.MockMvcResultHandlers.print())
.andExpect(status().isOk())
.andExpect(jsonPath("$", notNullValue()))
.andExpect(jsonPath("$.clientSecret", nullValue()))
......@@ -222,7 +213,7 @@ public class OAuthManagementControllerTest extends AbstractApiV1Test {
mockMvc
.perform(get(OAuthManagementController.API_URL + OAuthManagementController.ENDPOINT_CLIENT_ID, client.getClientId())
.contentType(MediaType.APPLICATION_JSON))
// .andDo(MockMvcResultHandlers.print())
// .andDo(org.springframework.test.web.servlet.result.MockMvcResultHandlers.print())
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
.andExpect(jsonPath("$", notNullValue()))
......@@ -243,7 +234,7 @@ public class OAuthManagementControllerTest extends AbstractApiV1Test {
mockMvc
.perform(get(OAuthManagementController.API_URL + OAuthManagementController.ENDPOINT_CLIENT_ID, "notExistingClientId")
.contentType(MediaType.APPLICATION_JSON))
// .andDo(MockMvcResultHandlers.print())
// .andDo(org.springframework.test.web.servlet.result.MockMvcResultHandlers.print())
.andExpect(status().isNotFound())
;
/*@formatter:on*/
......
......@@ -179,12 +179,12 @@ public abstract class AbstractServicesTest extends AbstractServiceTest {
}
protected AccessionSource addAccessionSourceToDB(Accession accession) {
return addAccessionSourceToDB(accession, AccessionSource.SourceType.COLLECTED);
return addAccessionSourceToDB(accession, CommunityCodeValues.ACCESSION_SOURCE_TYPE_COLLECTED.value);
}
protected AccessionSource addAccessionSourceToDB(Accession accession, AccessionSource.SourceType type) {
protected AccessionSource addAccessionSourceToDB(Accession accession, String sourceTypeCode) {
AccessionSource source = new AccessionSource();
source.setSourceTypeCode(type.name());
source.setSourceTypeCode(sourceTypeCode);
source.setAccession(accession);
return accessionSourceRepository.save(source);
......@@ -211,7 +211,7 @@ public abstract class AbstractServicesTest extends AbstractServiceTest {
protected AccessionIpr addAccessionIprToDB(Accession accession) {
AccessionIpr ipr = new AccessionIpr();
ipr.setAccession(accession);
ipr.setTypeCode("TypeCode");
ipr.setTypeCode(CommunityCodeValues.ACCESSION_RESTRICTION_TYPE_SMTA.value);
return accessionIprRepository.save(ipr);
}
......@@ -297,7 +297,7 @@ public abstract class AbstractServicesTest extends AbstractServiceTest {
AccessionInvName invName = new AccessionInvName();
invName.setPlantName(plantName);
invName.setIsWebVisible(TRUE);
invName.setCategoryCode("Category code");
invName.setCategoryCode(CommunityCodeValues.ACCESSION_NAME_TYPE_DEVELOPER.value);
invName.setInventory(inventory);
return accessionInvNameRepository.save(invName);
......
......@@ -26,6 +26,7 @@ import org.apache.commons.lang3.RandomUtils;
import org.gringlobal.api.InvalidApiUsageException;
import org.gringlobal.custom.elasticsearch.SearchException;
import org.gringlobal.model.*;
import org.gringlobal.model.community.CommunityCodeValues;
import org.gringlobal.persistence.AccessionInvGroupMapRepository;
import org.gringlobal.persistence.AccessionInvGroupRepository;
import org.gringlobal.service.AccessionInvGroupService;
......@@ -137,7 +138,7 @@ public class AccessionServiceTest extends AbstractServicesTest {
// create AccessionSource
AccessionSource source = new AccessionSource();
source.setSourceTypeCode(AccessionSource.SourceType.COLLECTED.name());
source.setSourceTypeCode(CommunityCodeValues.ACCESSION_SOURCE_TYPE_COLLECTED.value);
source.setAccession(accession);
// add AccessionSource to accession
......@@ -162,7 +163,7 @@ public class AccessionServiceTest extends AbstractServicesTest {
// create AccessionSource
AccessionSource source = new AccessionSource();
source.setSourceTypeCode(AccessionSource.SourceType.COLLECTED.name());
source.setSourceTypeCode(CommunityCodeValues.ACCESSION_SOURCE_TYPE_COLLECTED.value);
source.setAccession(a);
// add AccessionSource to accession
......@@ -308,7 +309,7 @@ public class AccessionServiceTest extends AbstractServicesTest {
acquisitionBatch.inventoryNumberPart1 = "INTRO";
acquisitionBatch.siteId = 1;
acquisitionBatch.inventoryMaintenancePolicyId = maintPolicy.getId();
acquisitionBatch.availabilityStatusCode = "AVAIL";
acquisitionBatch.availabilityStatusCode = CommunityCodeValues.INVENTORY_AVAILABILITY_AVAILABLE.value;
acquisitionBatch.accessions = new ArrayList<>();
for (int i = 0; i < 10; i++) {
......@@ -319,11 +320,11 @@ public class AccessionServiceTest extends AbstractServicesTest {
accession.setTaxonomySpecies(new TaxonomySpecies(taxonomySpecies.getId()));
List<AccessionInvName> names = Lists.newArrayList(new AccessionInvName(), new AccessionInvName(), new AccessionInvName());
names.get(0).setCategoryCode("DEVELOPER");
names.get(0).setCategoryCode(CommunityCodeValues.ACCESSION_NAME_TYPE_DEVELOPER.value);
names.get(0).setPlantName("Developed " + (i+1));
names.get(1).setCategoryCode("COLLECTOR");
names.get(1).setCategoryCode(CommunityCodeValues.ACCESSION_NAME_TYPE_COLLECTOR.value);
names.get(1).setPlantName("COLL " + (RandomUtils.nextInt(100, 99999)));
names.get(2).setCategoryCode("DONOR");
names.get(2).setCategoryCode(CommunityCodeValues.ACCESSION_NAME_TYPE_DONOR.value);
names.get(2).setPlantName("TZm-" + (RandomUtils.nextInt(100, 99999)));
accession.setNames(names);
......@@ -332,7 +333,7 @@ public class AccessionServiceTest extends AbstractServicesTest {
acquisitionBatch.sources = new ArrayList<>();
AccessionSource source = new AccessionSource();
source.setSourceTypeCode("DONATED");
source.setSourceTypeCode(CommunityCodeValues.ACCESSION_SOURCE_TYPE_DONATED.value);
source.setSourceDate(new Date());
source.setSourceDateCode("YYYY-MM-DD");
List<Cooperator> cooperators = Lists.newArrayList(new Cooperator(1l), new Cooperator(2l));
......@@ -341,7 +342,7 @@ public class AccessionServiceTest extends AbstractServicesTest {
// Source 2
source = new AccessionSource();
source.setSourceTypeCode("DEVELOPED");
source.setSourceTypeCode(CommunityCodeValues.ACCESSION_SOURCE_TYPE_DEVELOPED.value);
source.setSourceDate(new Date());
source.setSourceDateCode("YYYY-MM-DD");
cooperators = Lists.newArrayList(new Cooperator(3l));
......
......@@ -33,6 +33,7 @@ log4j.category.org.gringlobal=info
#log4j.category.org.gringlobal.spring=trace
log4j.category.org.gringlobal.custom.elasticsearch=warn
log4j.category.org.gringlobal.service.impl.ElasticsearchServiceImpl=warn
log4j.category.org.gringlobal.service.impl.CodeValueServiceImpl=warn
log4j.category.org.springframework.web.client=trace
log4j.category.org.elasticsearch.client=error
......