@Test public void importSingleLine() throws IOException, StudyImporterException { final Map<String, String> parsedProperties = new HashMap<String, String>(); String predOneLine = "DATA_ID,PRED_ID,DATA_AGGR_CODE,PRED_SOURCE_NAME,PRED_DATABASE_NAME,PRED_TOT_STOM_EXAM,TOT_W_FD,PCT_W_FD,TOT_WO_FD,PCT_WO_FD,PRED_DEN,PRED_SEX,PRED_SEX_RATIO,PRED_LIFE_HIST_STAGE,PRED_LEN_TYPE_1,PRED_MIN_LEN_1,PRED_MAX_LEN_1,PRED_MN_LEN_1,PRED_LEN_TYPE_2,PRED_MIN_LEN_2,PRED_MAX_LEN_2,PRED_MN_LEN_2,PRED_LEN_TYPE_3,PRED_MIN_LEN_3,PRED_MAX_LEN_3,PRED_MN_LEN_3,PRED_MIN_AGE,PRED_MAX_AGE,PRED_MN_AGE,PRED_MIN_WT,PRED_MAX_WT,PRED_MN_WT,PRED_TOT_WT,BIOMASS_DEN,STOM_PCT_FULL,STOM_COND_INDEX,TOT_FD_BIOMASS,TOT_FD_VOL,PREDATOR_NOTES,POP_TOT_PRED,POP_PRED_DEN,POP_SEX_RATIO,POP_LIFE_HIST_STAGE,POP_LEN_TYPE,POP_MIN_LEN,POP_MAX_LEN,POP_MN_LEN,POP_MIN_AGE,POP_MAX_AGE,POP_MN_AGE,POP_MIN_WT,POP_MAX_WT,POP_MN_WT,POP_TOT_WT,POP_BIOMASS_DEN,ENTRY_DATE,ENTRY_PERSON,EDITED_DATE,DATA_EDITOR,MODIFY_DATE,DATA_MODIFIER\n" + "ACT_16R,Cchr.1,complete,Chloroscombrus chrysurus,Chloroscombrus chrysurus,66,61,0.9242,5,0.0758,NA,NA,NA,adult,SL,101,150,125.5,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,8.3,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,Jim Simons,NA,Jim Simons,27/06/2016,Theresa Mitchell\n"; DatasetImporterForGoMexSI2.parseSpecimen(URI.create("test.txt"), "PRED_", new ParseEventHandler() { @Override public void onSpecimen(String predatorUID, Map<String, String> properties) { parsedProperties.putAll(properties); } }, CSVTSVUtil.createLabeledCSVParser(CSVTSVUtil.createExcelCSVParse(new StringReader(predOneLine)))); assertThat(parsedProperties.get("name"), is("Chloroscombrus chrysurus")); assertThat(parsedProperties.get("GOMEXSI:PRED_DATABASE_NAME"), is("Chloroscombrus chrysurus")); assertThat(parsedProperties.get("GOMEXSI:DATA_AGGR_CODE"), is("complete")); assertThat(parsedProperties.get("GOMEXSI:DATA_ID"), is("ACT_16R")); }
protected static void parseSpecimen(URI datafile, String columnNamePrefix, ParseEventHandler specimenListener, LabeledCSVParser parser) throws IOException, StudyImporterException { while (parser.getLine() != null) { Map<String, String> properties = new HashMap<String, String>(); addOptionalProperty(parser, "TOT_WO_FD", STOMACH_COUNT_WITHOUT_FOOD, properties); addOptionalProperty(parser, "TOT_W_FD", STOMACH_COUNT_WITH_FOOD, properties); addOptionalProperty(parser, "TOT_PRED_STOM_EXAM", STOMACH_COUNT_TOTAL, properties); addOptionalProperty(parser, columnNamePrefix + "MN_LEN", SpecimenConstant.LENGTH_IN_MM, properties); addOptionalProperty(parser, columnNamePrefix + "LIFE_HIST_STAGE", SpecimenConstant.LIFE_STAGE_LABEL, properties); addOptionalProperty(parser, "PHYSIOLOG_STATE", SpecimenConstant.PHYSIOLOGICAL_STATE_LABEL, properties); addOptionalProperty(parser, columnNamePrefix + "PARTS", SpecimenConstant.BODY_PART_LABEL, properties); addOptionalProperty(parser, "N_CONS", SpecimenConstant.TOTAL_COUNT, properties); addOptionalProperty(parser, "PCT_N_CONS", SpecimenConstant.TOTAL_COUNT_PERCENT, properties); addOptionalProperty(parser, "VOL_CONS", SpecimenConstant.TOTAL_VOLUME_IN_ML, properties); addOptionalProperty(parser, "PCT_VOL_CONS", SpecimenConstant.TOTAL_VOLUME_PERCENT, properties); addOptionalProperty(parser, "FREQ_OCC", SpecimenConstant.FREQUENCY_OF_OCCURRENCE, properties); addOptionalProperty(parser, "PCT_FREQ_OCC", SpecimenConstant.FREQUENCY_OF_OCCURRENCE_PERCENT, properties); String taxonName = getMandatoryValue(datafile, parser, columnNamePrefix + "DATABASE_NAME"); if (isBlank(taxonName)) { taxonName = getMandatoryValue(datafile, parser, columnNamePrefix + "SOURCE_NAME"); } properties.put(PropertyAndValueDictionary.NAME, taxonName); String refId = getMandatoryValue(datafile, parser, "DATA_ID"); String specimenId = getMandatoryValue(datafile, parser, "PRED_ID"); String predatorUID = refId + specimenId; String[] labels = parser.getLabels(); for (String label : labels) { properties.put(GOMEXSI_NAMESPACE + label, parser.getValueByLabel(label)); } specimenListener.onSpecimen(predatorUID, properties); } }
DatasetImporterForGoMexSI2 extends NodeBasedImporter { protected static void parseSpecimen(URI datafile, String columnNamePrefix, ParseEventHandler specimenListener, LabeledCSVParser parser) throws IOException, StudyImporterException { while (parser.getLine() != null) { Map<String, String> properties = new HashMap<String, String>(); addOptionalProperty(parser, "TOT_WO_FD", STOMACH_COUNT_WITHOUT_FOOD, properties); addOptionalProperty(parser, "TOT_W_FD", STOMACH_COUNT_WITH_FOOD, properties); addOptionalProperty(parser, "TOT_PRED_STOM_EXAM", STOMACH_COUNT_TOTAL, properties); addOptionalProperty(parser, columnNamePrefix + "MN_LEN", SpecimenConstant.LENGTH_IN_MM, properties); addOptionalProperty(parser, columnNamePrefix + "LIFE_HIST_STAGE", SpecimenConstant.LIFE_STAGE_LABEL, properties); addOptionalProperty(parser, "PHYSIOLOG_STATE", SpecimenConstant.PHYSIOLOGICAL_STATE_LABEL, properties); addOptionalProperty(parser, columnNamePrefix + "PARTS", SpecimenConstant.BODY_PART_LABEL, properties); addOptionalProperty(parser, "N_CONS", SpecimenConstant.TOTAL_COUNT, properties); addOptionalProperty(parser, "PCT_N_CONS", SpecimenConstant.TOTAL_COUNT_PERCENT, properties); addOptionalProperty(parser, "VOL_CONS", SpecimenConstant.TOTAL_VOLUME_IN_ML, properties); addOptionalProperty(parser, "PCT_VOL_CONS", SpecimenConstant.TOTAL_VOLUME_PERCENT, properties); addOptionalProperty(parser, "FREQ_OCC", SpecimenConstant.FREQUENCY_OF_OCCURRENCE, properties); addOptionalProperty(parser, "PCT_FREQ_OCC", SpecimenConstant.FREQUENCY_OF_OCCURRENCE_PERCENT, properties); String taxonName = getMandatoryValue(datafile, parser, columnNamePrefix + "DATABASE_NAME"); if (isBlank(taxonName)) { taxonName = getMandatoryValue(datafile, parser, columnNamePrefix + "SOURCE_NAME"); } properties.put(PropertyAndValueDictionary.NAME, taxonName); String refId = getMandatoryValue(datafile, parser, "DATA_ID"); String specimenId = getMandatoryValue(datafile, parser, "PRED_ID"); String predatorUID = refId + specimenId; String[] labels = parser.getLabels(); for (String label : labels) { properties.put(GOMEXSI_NAMESPACE + label, parser.getValueByLabel(label)); } specimenListener.onSpecimen(predatorUID, properties); } } }
DatasetImporterForGoMexSI2 extends NodeBasedImporter { protected static void parseSpecimen(URI datafile, String columnNamePrefix, ParseEventHandler specimenListener, LabeledCSVParser parser) throws IOException, StudyImporterException { while (parser.getLine() != null) { Map<String, String> properties = new HashMap<String, String>(); addOptionalProperty(parser, "TOT_WO_FD", STOMACH_COUNT_WITHOUT_FOOD, properties); addOptionalProperty(parser, "TOT_W_FD", STOMACH_COUNT_WITH_FOOD, properties); addOptionalProperty(parser, "TOT_PRED_STOM_EXAM", STOMACH_COUNT_TOTAL, properties); addOptionalProperty(parser, columnNamePrefix + "MN_LEN", SpecimenConstant.LENGTH_IN_MM, properties); addOptionalProperty(parser, columnNamePrefix + "LIFE_HIST_STAGE", SpecimenConstant.LIFE_STAGE_LABEL, properties); addOptionalProperty(parser, "PHYSIOLOG_STATE", SpecimenConstant.PHYSIOLOGICAL_STATE_LABEL, properties); addOptionalProperty(parser, columnNamePrefix + "PARTS", SpecimenConstant.BODY_PART_LABEL, properties); addOptionalProperty(parser, "N_CONS", SpecimenConstant.TOTAL_COUNT, properties); addOptionalProperty(parser, "PCT_N_CONS", SpecimenConstant.TOTAL_COUNT_PERCENT, properties); addOptionalProperty(parser, "VOL_CONS", SpecimenConstant.TOTAL_VOLUME_IN_ML, properties); addOptionalProperty(parser, "PCT_VOL_CONS", SpecimenConstant.TOTAL_VOLUME_PERCENT, properties); addOptionalProperty(parser, "FREQ_OCC", SpecimenConstant.FREQUENCY_OF_OCCURRENCE, properties); addOptionalProperty(parser, "PCT_FREQ_OCC", SpecimenConstant.FREQUENCY_OF_OCCURRENCE_PERCENT, properties); String taxonName = getMandatoryValue(datafile, parser, columnNamePrefix + "DATABASE_NAME"); if (isBlank(taxonName)) { taxonName = getMandatoryValue(datafile, parser, columnNamePrefix + "SOURCE_NAME"); } properties.put(PropertyAndValueDictionary.NAME, taxonName); String refId = getMandatoryValue(datafile, parser, "DATA_ID"); String specimenId = getMandatoryValue(datafile, parser, "PRED_ID"); String predatorUID = refId + specimenId; String[] labels = parser.getLabels(); for (String label : labels) { properties.put(GOMEXSI_NAMESPACE + label, parser.getValueByLabel(label)); } specimenListener.onSpecimen(predatorUID, properties); } } DatasetImporterForGoMexSI2(ParserFactory parserFactory, NodeFactory nodeFactory); }
DatasetImporterForGoMexSI2 extends NodeBasedImporter { protected static void parseSpecimen(URI datafile, String columnNamePrefix, ParseEventHandler specimenListener, LabeledCSVParser parser) throws IOException, StudyImporterException { while (parser.getLine() != null) { Map<String, String> properties = new HashMap<String, String>(); addOptionalProperty(parser, "TOT_WO_FD", STOMACH_COUNT_WITHOUT_FOOD, properties); addOptionalProperty(parser, "TOT_W_FD", STOMACH_COUNT_WITH_FOOD, properties); addOptionalProperty(parser, "TOT_PRED_STOM_EXAM", STOMACH_COUNT_TOTAL, properties); addOptionalProperty(parser, columnNamePrefix + "MN_LEN", SpecimenConstant.LENGTH_IN_MM, properties); addOptionalProperty(parser, columnNamePrefix + "LIFE_HIST_STAGE", SpecimenConstant.LIFE_STAGE_LABEL, properties); addOptionalProperty(parser, "PHYSIOLOG_STATE", SpecimenConstant.PHYSIOLOGICAL_STATE_LABEL, properties); addOptionalProperty(parser, columnNamePrefix + "PARTS", SpecimenConstant.BODY_PART_LABEL, properties); addOptionalProperty(parser, "N_CONS", SpecimenConstant.TOTAL_COUNT, properties); addOptionalProperty(parser, "PCT_N_CONS", SpecimenConstant.TOTAL_COUNT_PERCENT, properties); addOptionalProperty(parser, "VOL_CONS", SpecimenConstant.TOTAL_VOLUME_IN_ML, properties); addOptionalProperty(parser, "PCT_VOL_CONS", SpecimenConstant.TOTAL_VOLUME_PERCENT, properties); addOptionalProperty(parser, "FREQ_OCC", SpecimenConstant.FREQUENCY_OF_OCCURRENCE, properties); addOptionalProperty(parser, "PCT_FREQ_OCC", SpecimenConstant.FREQUENCY_OF_OCCURRENCE_PERCENT, properties); String taxonName = getMandatoryValue(datafile, parser, columnNamePrefix + "DATABASE_NAME"); if (isBlank(taxonName)) { taxonName = getMandatoryValue(datafile, parser, columnNamePrefix + "SOURCE_NAME"); } properties.put(PropertyAndValueDictionary.NAME, taxonName); String refId = getMandatoryValue(datafile, parser, "DATA_ID"); String specimenId = getMandatoryValue(datafile, parser, "PRED_ID"); String predatorUID = refId + specimenId; String[] labels = parser.getLabels(); for (String label : labels) { properties.put(GOMEXSI_NAMESPACE + label, parser.getValueByLabel(label)); } specimenListener.onSpecimen(predatorUID, properties); } } DatasetImporterForGoMexSI2(ParserFactory parserFactory, NodeFactory nodeFactory); @Override void importStudy(); }
DatasetImporterForGoMexSI2 extends NodeBasedImporter { protected static void parseSpecimen(URI datafile, String columnNamePrefix, ParseEventHandler specimenListener, LabeledCSVParser parser) throws IOException, StudyImporterException { while (parser.getLine() != null) { Map<String, String> properties = new HashMap<String, String>(); addOptionalProperty(parser, "TOT_WO_FD", STOMACH_COUNT_WITHOUT_FOOD, properties); addOptionalProperty(parser, "TOT_W_FD", STOMACH_COUNT_WITH_FOOD, properties); addOptionalProperty(parser, "TOT_PRED_STOM_EXAM", STOMACH_COUNT_TOTAL, properties); addOptionalProperty(parser, columnNamePrefix + "MN_LEN", SpecimenConstant.LENGTH_IN_MM, properties); addOptionalProperty(parser, columnNamePrefix + "LIFE_HIST_STAGE", SpecimenConstant.LIFE_STAGE_LABEL, properties); addOptionalProperty(parser, "PHYSIOLOG_STATE", SpecimenConstant.PHYSIOLOGICAL_STATE_LABEL, properties); addOptionalProperty(parser, columnNamePrefix + "PARTS", SpecimenConstant.BODY_PART_LABEL, properties); addOptionalProperty(parser, "N_CONS", SpecimenConstant.TOTAL_COUNT, properties); addOptionalProperty(parser, "PCT_N_CONS", SpecimenConstant.TOTAL_COUNT_PERCENT, properties); addOptionalProperty(parser, "VOL_CONS", SpecimenConstant.TOTAL_VOLUME_IN_ML, properties); addOptionalProperty(parser, "PCT_VOL_CONS", SpecimenConstant.TOTAL_VOLUME_PERCENT, properties); addOptionalProperty(parser, "FREQ_OCC", SpecimenConstant.FREQUENCY_OF_OCCURRENCE, properties); addOptionalProperty(parser, "PCT_FREQ_OCC", SpecimenConstant.FREQUENCY_OF_OCCURRENCE_PERCENT, properties); String taxonName = getMandatoryValue(datafile, parser, columnNamePrefix + "DATABASE_NAME"); if (isBlank(taxonName)) { taxonName = getMandatoryValue(datafile, parser, columnNamePrefix + "SOURCE_NAME"); } properties.put(PropertyAndValueDictionary.NAME, taxonName); String refId = getMandatoryValue(datafile, parser, "DATA_ID"); String specimenId = getMandatoryValue(datafile, parser, "PRED_ID"); String predatorUID = refId + specimenId; String[] labels = parser.getLabels(); for (String label : labels) { properties.put(GOMEXSI_NAMESPACE + label, parser.getValueByLabel(label)); } specimenListener.onSpecimen(predatorUID, properties); } } DatasetImporterForGoMexSI2(ParserFactory parserFactory, NodeFactory nodeFactory); @Override void importStudy(); static final String GOMEXI_SOURCE_DESCRIPTION; static final String STOMACH_COUNT_TOTAL; static final String STOMACH_COUNT_WITH_FOOD; static final String STOMACH_COUNT_WITHOUT_FOOD; static final String GOMEXSI_NAMESPACE; }