Commit c1646202 authored by Matija Obreza's avatar Matija Obreza

Merge branch '88-accession-source-habitat-type' into 'master'

Resolve "Accession source habitat type"

Closes #88

See merge request !93
parents 94582014 7618d537
......@@ -15,7 +15,6 @@
*/
package org.gringlobal.model;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
......@@ -40,89 +39,6 @@ import com.fasterxml.jackson.annotation.ObjectIdGenerators;
public class AccessionSource extends CooperatorOwnedModel implements Copyable<AccessionSource> {
private static final long serialVersionUID = 8820879032034410951L;
/**
* ACCESSION_SOURCE_HABITAT_TYPE code_group
*/
public static enum SourceHabitatType {
/** "10" Wild Habitat */
WILD(10),
/** "11" Forest / woodland */
WILD_FOREST(11),
/** "12" Shrubland */
WILD_SHRUBLAND(12),
/** "13" Grassland */
WILD_GRASSLAND(13),
/** "14" Desert / tundra */
WILD_DESERT(14),
/** "15" Aquatic habitat */
WILD_ACQUATIC(15),
/** "20" Farm */
FARM(20),
/** "21" Field */
FARM_FIELD(21),
/** "22" Orchard */
FARM_ORCHARD(22),
/** "23" Backyard */
FARM_BACKYARD(23),
/** "24" Fallow land */
FARM_FALLOW(24),
/** "25" Pasture */
FARM_PASTURE(25),
/** "26" Farm store */
FARM_STORE(26),
/** "27" Threshing floor */
FARM_THRESHING_FLOOR(27),
/** "28" Park */
FARM_PARK(28),
/** "30" Market or shop */
MARKET(30),
/** "40" Institute */
INSTITUTE(40),
/** "50" Seed company */
COMMERCIAL(50),
/** "60" Weedy, disturbed, or ruderal habitat */
RUDERAL(60),
/** "61" Roadside */
RUDERAL_ROADSIDE(61),
/** "62" Field margin */
RUDERAL_FIELD_MARGIN(62);
// /** "99" Other */
// 99,
// /** "ACT" Site grown in situ */
// ACT,
// /** "MKT" Market or store */
// MKT,
// /** "RES" Research station or other ex situ site */
// RES,
// /** "STR" Obtained from farmer's storage */
// STR,
// /** "UNK" Unknown source */
// UNK,
private int mcpd;
SourceHabitatType(int mcpdCode) {
this.mcpd = mcpdCode;
}
public int getMcpd() {
return mcpd;
}
/**
* Get from MCPD code.
*
* @param mcpd the MCPD code
* @return the accession source habitat type
*/
public static SourceHabitatType fromMCPD(Integer mcpd) {
if (mcpd == null) {
return null;
}
return Arrays.stream(SourceHabitatType.values()).filter((habitat) -> habitat.mcpd == mcpd).findFirst().orElse(null);
}
}
@Id
@JsonProperty
@GeneratedValue(strategy = GenerationType.IDENTITY)
......@@ -140,7 +56,7 @@ public class AccessionSource extends CooperatorOwnedModel implements Copyable<Ac
@Basic
@Column(name = "acquisition_source_code", length = 20)
@CodeValueField("ACCESSION_SOURCE_HABITAT_TYPE")
@CodeValueField(CommunityCodeValues.ACCESSION_SOURCE_HABITAT_TYPE)
private String acquisitionSource;
@Basic
......
......@@ -49,6 +49,29 @@ public abstract class CommunityCodeValues {
public static final String ACCESSION_RESTRICTION_TYPE = "ACCESSION_RESTRICTION_TYPE";
public static final CodeValueDef ACCESSION_RESTRICTION_TYPE_SMTA;
public static final String ACCESSION_SOURCE_HABITAT_TYPE = "ACCESSION_SOURCE_HABITAT_TYPE";
public static final CodeValueDef ACCESSION_SOURCE_HABITAT_TYPE_WILD;
public static final CodeValueDef ACCESSION_SOURCE_HABITAT_TYPE_WILD_FOREST;
public static final CodeValueDef ACCESSION_SOURCE_HABITAT_TYPE_WILD_SHRUBLAND;
public static final CodeValueDef ACCESSION_SOURCE_HABITAT_TYPE_WILD_GRASSLAND;
public static final CodeValueDef ACCESSION_SOURCE_HABITAT_TYPE_WILD_DESERT;
public static final CodeValueDef ACCESSION_SOURCE_HABITAT_TYPE_WILD_ACQUATIC;
public static final CodeValueDef ACCESSION_SOURCE_HABITAT_TYPE_FARM;
public static final CodeValueDef ACCESSION_SOURCE_HABITAT_TYPE_FARM_FIELD;
public static final CodeValueDef ACCESSION_SOURCE_HABITAT_TYPE_FARM_ORCHARD;
public static final CodeValueDef ACCESSION_SOURCE_HABITAT_TYPE_FARM_BACKYARD;
public static final CodeValueDef ACCESSION_SOURCE_HABITAT_TYPE_FARM_FALLOW;
public static final CodeValueDef ACCESSION_SOURCE_HABITAT_TYPE_FARM_PASTURE;
public static final CodeValueDef ACCESSION_SOURCE_HABITAT_TYPE_FARM_STORE;
public static final CodeValueDef ACCESSION_SOURCE_HABITAT_TYPE_FARM_THRESHING_FLOOR;
public static final CodeValueDef ACCESSION_SOURCE_HABITAT_TYPE_FARM_PARK;
public static final CodeValueDef ACCESSION_SOURCE_HABITAT_TYPE_MARKET;
public static final CodeValueDef ACCESSION_SOURCE_HABITAT_TYPE_INSTITUTE;
public static final CodeValueDef ACCESSION_SOURCE_HABITAT_TYPE_COMMERCIAL;
public static final CodeValueDef ACCESSION_SOURCE_HABITAT_TYPE_RUDERAL;
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 INVENTORY_AVAILABILITY_STATUS = "INVENTORY_AVAILABILITY_STATUS";
public static final CodeValueDef INVENTORY_AVAILABILITY_LOWINVENTORY;
public static final CodeValueDef INVENTORY_AVAILABILITY_AVAILABLE;
......@@ -60,6 +83,7 @@ public abstract class CommunityCodeValues {
public static final String DATE_FORMAT = "DATE_FORMAT";
public static final CodeValueDef DATE_FORMAT_DATETIME;
public static final CodeValueDef DATE_FORMAT_DATE;
public static final CodeValueDef DATE_FORMAT_YEARMONTH;
public static final String ORDER_REQUEST_ACTION = "ORDER_REQUEST_ACTION";
public static final CodeValueDef ORDER_REQUEST_ACTION_LOG;
......@@ -77,16 +101,40 @@ public abstract class CommunityCodeValues {
static {
// Unit
UNIT_OF_QUANTITY_SEED = new CodeValueDef(UNIT_OF_QUANTITY, "sd", "Seed", null);
// Date formats
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");
DATE_FORMAT_YEARMONTH = new CodeValueDef(DATE_FORMAT, "yyyy-MM", "Year and month", "yyyy-MM");
// 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 source Habitat type
ACCESSION_SOURCE_HABITAT_TYPE_WILD = new CodeValueDef(ACCESSION_SOURCE_HABITAT_TYPE, "10", "Wild habitat", null);
ACCESSION_SOURCE_HABITAT_TYPE_WILD_FOREST = new CodeValueDef(ACCESSION_SOURCE_HABITAT_TYPE, "11", "Forest / woodland", null);
ACCESSION_SOURCE_HABITAT_TYPE_WILD_SHRUBLAND = new CodeValueDef(ACCESSION_SOURCE_HABITAT_TYPE, "12", "Shrubland", null);
ACCESSION_SOURCE_HABITAT_TYPE_WILD_GRASSLAND = new CodeValueDef(ACCESSION_SOURCE_HABITAT_TYPE, "13", "Grassland", null);
ACCESSION_SOURCE_HABITAT_TYPE_WILD_DESERT = new CodeValueDef(ACCESSION_SOURCE_HABITAT_TYPE, "14", "Desert / tundra", null);
ACCESSION_SOURCE_HABITAT_TYPE_WILD_ACQUATIC = new CodeValueDef(ACCESSION_SOURCE_HABITAT_TYPE, "15", "Aquatic habitat", null);
ACCESSION_SOURCE_HABITAT_TYPE_FARM = new CodeValueDef(ACCESSION_SOURCE_HABITAT_TYPE, "20", "Farm or cultivated habitat", null);
ACCESSION_SOURCE_HABITAT_TYPE_FARM_FIELD = new CodeValueDef(ACCESSION_SOURCE_HABITAT_TYPE, "21", "Field", null);
ACCESSION_SOURCE_HABITAT_TYPE_FARM_ORCHARD = new CodeValueDef(ACCESSION_SOURCE_HABITAT_TYPE, "22", "Orchard", null);
ACCESSION_SOURCE_HABITAT_TYPE_FARM_BACKYARD = new CodeValueDef(ACCESSION_SOURCE_HABITAT_TYPE, "23", "Backyard, kitchen or home garden", null);
ACCESSION_SOURCE_HABITAT_TYPE_FARM_FALLOW = new CodeValueDef(ACCESSION_SOURCE_HABITAT_TYPE, "24", "Fallow land", null);
ACCESSION_SOURCE_HABITAT_TYPE_FARM_PASTURE = new CodeValueDef(ACCESSION_SOURCE_HABITAT_TYPE, "25", "Pasture", null);
ACCESSION_SOURCE_HABITAT_TYPE_FARM_STORE = new CodeValueDef(ACCESSION_SOURCE_HABITAT_TYPE, "26", "Farm store", null);
ACCESSION_SOURCE_HABITAT_TYPE_FARM_THRESHING_FLOOR = new CodeValueDef(ACCESSION_SOURCE_HABITAT_TYPE, "27", "Threshing floor", null);
ACCESSION_SOURCE_HABITAT_TYPE_FARM_PARK = new CodeValueDef(ACCESSION_SOURCE_HABITAT_TYPE, "28", "Park", null);
ACCESSION_SOURCE_HABITAT_TYPE_MARKET = new CodeValueDef(ACCESSION_SOURCE_HABITAT_TYPE, "30", "Market or shop", null);
ACCESSION_SOURCE_HABITAT_TYPE_INSTITUTE = new CodeValueDef(ACCESSION_SOURCE_HABITAT_TYPE, "40", "Institute", "Institute, Experimental station, Research organization, Genebank");
ACCESSION_SOURCE_HABITAT_TYPE_COMMERCIAL = new CodeValueDef(ACCESSION_SOURCE_HABITAT_TYPE, "50", "Seed company", null);
ACCESSION_SOURCE_HABITAT_TYPE_RUDERAL = new CodeValueDef(ACCESSION_SOURCE_HABITAT_TYPE, "60", "Weedy, disturbed, or ruderal habitat", null);
ACCESSION_SOURCE_HABITAT_TYPE_RUDERAL_ROADSIDE = new CodeValueDef(ACCESSION_SOURCE_HABITAT_TYPE, "61", "Roadside", null);
ACCESSION_SOURCE_HABITAT_TYPE_RUDERAL_FIELD_MARGIN = new CodeValueDef(ACCESSION_SOURCE_HABITAT_TYPE, "62", "Field margin", 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);
......@@ -103,12 +151,12 @@ public abstract class CommunityCodeValues {
// Inventory actions
INVENTORY_ACTION_QUANTITYSET = new CodeValueDef(INVENTORY_ACTION, "QUANTITYSET", "Quantity confirmed", "The amount of material was physically inspected.");
INVENTORY_ACTION_100SEEDWEIGHT = new CodeValueDef(INVENTORY_ACTION, "100SEEDWEIGHT", "100 seed weight set", null);
// Order request status
ORDER_REQUEST_ITEM_STATUS_NEW = new CodeValueDef(ORDER_REQUEST_ITEM_STATUS, "NEW", "Retrieve from storage", "Retrieve source inventory from storage for distribution.");
ORDER_REQUEST_ITEM_STATUS_PENDING = new CodeValueDef(ORDER_REQUEST_ITEM_STATUS, "PENDING", "Retrieve from storage", "Retrieve source inventory from storage for distribution.");
ORDER_REQUEST_ITEM_STATUS_SPLIT = new CodeValueDef(ORDER_REQUEST_ITEM_STATUS, "SPLIT", "Split out order item", null);
// Order request actions
ORDER_REQUEST_ACTION_LOG = new CodeValueDef(ORDER_REQUEST_ACTION, "LOG", "Information only", null);
ORDER_REQUEST_ACTION_RETRIEVE = new CodeValueDef(ORDER_REQUEST_ACTION, "RETRIEVE", "Retrieve from storage", "Retrieve source inventory from storage for distribution.");
......@@ -148,7 +196,7 @@ public abstract class CommunityCodeValues {
this.title = title;
this.description = description;
}
public boolean is(String actionCode) {
return value.equals(actionCode);
}
......
......@@ -15,6 +15,8 @@
*/
package org.gringlobal.service.worker;
import static org.gringlobal.model.community.CommunityCodeValues.listCommunityCodeValues;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
......@@ -79,8 +81,9 @@ import com.google.common.cache.CacheBuilder;
*/
@Component
public class GenesysDownloader implements InitializingBean {
private static final int DOWNLOAD_PAGE_SIZE = 200;
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<>();
@Autowired
private ThreadPoolTaskExecutor taskExecutor;
......@@ -96,6 +99,11 @@ public class GenesysDownloader implements InitializingBean {
private RestTemplate restTemplate;
static {
listCommunityCodeValues().stream().filter(cv -> cv.groupName.equals(CommunityCodeValues.ACCESSION_SOURCE_HABITAT_TYPE))
.forEach(cv -> mcpdAcqusitionSource.put(Integer.valueOf(cv.value), cv));
}
protected static class FilteredPage<T> {
public List<T> content;
public List<?> sort;
......@@ -451,7 +459,7 @@ public class GenesysDownloader implements InitializingBean {
collectingSource.setUncertainty(getInteger(nodeGeo, "uncertainty"));
collectingSource.setGeoreferenceDatum(getText(nodeGeo, "datum"));
collectingSource.setGeoreferenceAnnotation(getText(nodeGeo, "method"));
collectingSource.setAcquisitionSource(AccessionSource.SourceHabitatType.fromMCPD(getInteger(nodeCollecting, "collSrc")).name());
collectingSource.setAcquisitionSource(fromMCPD(getInteger(nodeCollecting, "collSrc")));
collectingSource.setIsOrigin("Y");
}
}
......@@ -608,4 +616,13 @@ public class GenesysDownloader implements InitializingBean {
JsonNode n = objectNode.get(prop);
return n == null || n instanceof NullNode ? null : n.asInt();
}
public static String fromMCPD(Integer mcpd) {
if (mcpd == null) {
return null;
}
CommunityCodeValues.CodeValueDef codeValue = mcpdAcqusitionSource.get(mcpd);
return codeValue != null ? codeValue.value : null;
}
}
......@@ -70,12 +70,12 @@ public abstract class MCPDDate {
cal.set(Calendar.MONTH, Integer.parseInt(month) - 1); // months are 0-based
if (StringUtils.isNotBlank(day) && !"--".equals(day) && !"00".equals(day)) {
cal.set(Calendar.DATE, Integer.parseInt(day));
actualDateFormat = "YYYY-MM-DD";
actualDateFormat = "yyyy-MM-dd";
} else {
actualDateFormat = "YYYY-MM";
actualDateFormat = "yyyy-MM";
}
} else {
actualDateFormat = "YYYY";
actualDateFormat = "yyyy";
}
parsedDate = cal.getTime();
parsedDateFormat = actualDateFormat;
......
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