Commit 9031a15d authored by Matija Obreza's avatar Matija Obreza

Merge branch '94-drop-accession-improvementlevel-enum' into 'master'

Resolve "Drop Accession.ImprovementLevel enum"

Closes #94

See merge request !103
parents 3ec5cb8d 2bd1b509
......@@ -51,54 +51,6 @@ import com.fasterxml.jackson.annotation.ObjectIdGenerators;
public class Accession extends CooperatorOwnedModel implements ElasticLoader, ElasticTrigger {
private static final long serialVersionUID = 211254440212800409L;
public static enum ImprovementLevel {
/** "BREEDING" Breeding material */
BREEDING,
/** "CLONE" Clone */
CLONE,
/** "CULTIVAR" Cultivar */
CULTIVAR,
/** "CULTIVATED" Cultivated material */
CULTIVATED,
/** "GENETIC" Genetic material */
GENETIC,
/** "LANDRACE" Landrace */
LANDRACE,
/** "ROOTSTOCK" Rootstock */
ROOTSTOCK,
/** "UNCERTAIN" Uncertain improvement status */
UNCERTAIN,
/** "WILD" Wild material */
WILD;
public static ImprovementLevel fromMcpd(int sampStat) {
switch (sampStat) {
case 110:
case 120:
case 130:
case 100:
return WILD; // Wild
case 300:
return LANDRACE; // Traditional cultivar/landrace
case 416:
return CLONE; // Clonal selection
case 420:
return GENETIC; // Genetic stock
case 400:
return BREEDING; // Breeding/research material
case 500:
return CULTIVAR; // Advanced or improved cultivar (conventional breeding methods)
default:
return UNCERTAIN;
}
}
}
@Id
@JsonProperty
@GeneratedValue(strategy = GenerationType.IDENTITY)
......
......@@ -72,6 +72,17 @@ public abstract class CommunityCodeValues {
public static final CodeValueDef ACCESSION_SOURCE_HABITAT_TYPE_RUDERAL_ROADSIDE;
public static final CodeValueDef ACCESSION_SOURCE_HABITAT_TYPE_RUDERAL_FIELD_MARGIN;
public static final String IMPROVEMENT_LEVEL = "IMPROVEMENT_LEVEL";
public static final CodeValueDef IMPROVEMENT_LEVEL_BREEDING;
public static final CodeValueDef IMPROVEMENT_LEVEL_CLONE;
public static final CodeValueDef IMPROVEMENT_LEVEL_CULTIVAR;
public static final CodeValueDef IMPROVEMENT_LEVEL_CULTIVATED;
public static final CodeValueDef IMPROVEMENT_LEVEL_GENETIC;
public static final CodeValueDef IMPROVEMENT_LEVEL_LANDRACE;
public static final CodeValueDef IMPROVEMENT_LEVEL_ROOTSTOCK;
public static final CodeValueDef IMPROVEMENT_LEVEL_UNCERTAIN;
public static final CodeValueDef IMPROVEMENT_LEVEL_WILD;
public static final String INVENTORY_AVAILABILITY_STATUS = "INVENTORY_AVAILABILITY_STATUS";
public static final CodeValueDef INVENTORY_AVAILABILITY_LOWINVENTORY;
public static final CodeValueDef INVENTORY_AVAILABILITY_AVAILABLE;
......@@ -154,6 +165,17 @@ public abstract class CommunityCodeValues {
// Accession IPR types
ACCESSION_RESTRICTION_TYPE_SMTA = new CodeValueDef(ACCESSION_RESTRICTION_TYPE, "MTA-SMTA", "FAO Standard Material Transfer Agreement", null);
// Improvement level
IMPROVEMENT_LEVEL_BREEDING = new CodeValueDef(IMPROVEMENT_LEVEL, "BREEDING", "Breeding material", null);
IMPROVEMENT_LEVEL_CLONE = new CodeValueDef(IMPROVEMENT_LEVEL, "CLONE", "Clone", null);
IMPROVEMENT_LEVEL_CULTIVAR = new CodeValueDef(IMPROVEMENT_LEVEL, "CULTIVAR", "Cultivar", "Advanced or improved cultivar (conventional breeding methods)");
IMPROVEMENT_LEVEL_CULTIVATED = new CodeValueDef(IMPROVEMENT_LEVEL, "CULTIVATED", "Cultivated material", null);
IMPROVEMENT_LEVEL_GENETIC = new CodeValueDef(IMPROVEMENT_LEVEL, "GENETIC", "Genetic material", null);
IMPROVEMENT_LEVEL_LANDRACE = new CodeValueDef(IMPROVEMENT_LEVEL, "LANDRACE", "Landrace", null);
IMPROVEMENT_LEVEL_ROOTSTOCK = new CodeValueDef(IMPROVEMENT_LEVEL, "ROOTSTOCK", "Rootstock", null);
IMPROVEMENT_LEVEL_UNCERTAIN = new CodeValueDef(IMPROVEMENT_LEVEL, "UNCERTAIN", "Uncertain improvement status", null);
IMPROVEMENT_LEVEL_WILD = new CodeValueDef(IMPROVEMENT_LEVEL, "WILD", "Wild material", 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);
......
......@@ -30,7 +30,6 @@ import java.util.concurrent.TimeoutException;
import org.apache.commons.lang3.StringUtils;
import org.gringlobal.model.Accession;
import org.gringlobal.model.Accession.ImprovementLevel;
import org.gringlobal.model.AccessionSource;
import org.gringlobal.model.Crop;
import org.gringlobal.model.Geography;
......@@ -84,6 +83,7 @@ public class GenesysDownloader implements InitializingBean {
public static final Logger LOG = LoggerFactory.getLogger(GenesysDownloader.class);
private static final int DOWNLOAD_PAGE_SIZE = 200;
private static final Map<Integer, CommunityCodeValues.CodeValueDef> mcpdAcqusitionSource = new HashMap<>();
private static final Map<Integer, CommunityCodeValues.CodeValueDef> mcpdImprovementLevel = new HashMap<>();
@Autowired
private ThreadPoolTaskExecutor taskExecutor;
......@@ -102,6 +102,26 @@ public class GenesysDownloader implements InitializingBean {
static {
listCommunityCodeValues().stream().filter(cv -> cv.groupName.equals(CommunityCodeValues.ACCESSION_SOURCE_HABITAT_TYPE))
.forEach(cv -> mcpdAcqusitionSource.put(Integer.valueOf(cv.value), cv));
// Improvement level
mcpdImprovementLevel.put(100, CommunityCodeValues.IMPROVEMENT_LEVEL_WILD);
mcpdImprovementLevel.put(110, CommunityCodeValues.IMPROVEMENT_LEVEL_WILD);
mcpdImprovementLevel.put(120, CommunityCodeValues.IMPROVEMENT_LEVEL_WILD);
mcpdImprovementLevel.put(130, CommunityCodeValues.IMPROVEMENT_LEVEL_WILD);
mcpdImprovementLevel.put(300, CommunityCodeValues.IMPROVEMENT_LEVEL_LANDRACE);
mcpdImprovementLevel.put(400, CommunityCodeValues.IMPROVEMENT_LEVEL_BREEDING);
mcpdImprovementLevel.put(410, CommunityCodeValues.IMPROVEMENT_LEVEL_BREEDING);
mcpdImprovementLevel.put(411, CommunityCodeValues.IMPROVEMENT_LEVEL_BREEDING);
mcpdImprovementLevel.put(412, CommunityCodeValues.IMPROVEMENT_LEVEL_BREEDING);
mcpdImprovementLevel.put(413, CommunityCodeValues.IMPROVEMENT_LEVEL_BREEDING);
mcpdImprovementLevel.put(414, CommunityCodeValues.IMPROVEMENT_LEVEL_BREEDING);
mcpdImprovementLevel.put(415, CommunityCodeValues.IMPROVEMENT_LEVEL_BREEDING);
mcpdImprovementLevel.put(416, CommunityCodeValues.IMPROVEMENT_LEVEL_CLONE);
mcpdImprovementLevel.put(420, CommunityCodeValues.IMPROVEMENT_LEVEL_GENETIC);
mcpdImprovementLevel.put(421, CommunityCodeValues.IMPROVEMENT_LEVEL_BREEDING);
mcpdImprovementLevel.put(422, CommunityCodeValues.IMPROVEMENT_LEVEL_BREEDING);
mcpdImprovementLevel.put(423, CommunityCodeValues.IMPROVEMENT_LEVEL_BREEDING);
mcpdImprovementLevel.put(500, CommunityCodeValues.IMPROVEMENT_LEVEL_CULTIVAR);
}
protected static class FilteredPage<T> {
......@@ -327,10 +347,7 @@ public class GenesysDownloader implements InitializingBean {
if (cropName != null && cropName.isTextual()) {
ensureTaxonomyCropMap(a.getTaxonomySpecies(), cropName.asText());
}
Integer sampStat = acce.get("sampStat") == null ? null : acce.get("sampStat").intValue();
ImprovementLevel improvementLevel = ImprovementLevel.fromMcpd(sampStat.intValue());
a.setImprovementStatusCode(improvementLevel == null ? null : improvementLevel.name());
a.setImprovementStatusCode(improvementStatusFromMCPD(getInteger(acce, "sampStat")));
String mcpdAcqDate = getText(acce, "acquisitionDate");
MCPDDate.convert(mcpdAcqDate, a::setInitialReceivedDate, a::setInitialReceivedDateCode);
......@@ -625,4 +642,13 @@ public class GenesysDownloader implements InitializingBean {
CommunityCodeValues.CodeValueDef codeValue = mcpdAcqusitionSource.get(mcpd);
return codeValue != null ? codeValue.value : null;
}
public static String improvementStatusFromMCPD(Integer mcpd) {
if (mcpd == null || mcpd == 999) { // 999 - Other (Elaborate in REMARKS field)
return null;
}
CommunityCodeValues.CodeValueDef codeValue = mcpdImprovementLevel.get(mcpd);
return codeValue != null ? codeValue.value : CommunityCodeValues.IMPROVEMENT_LEVEL_UNCERTAIN.value;
}
}
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