@Test public void importSinglePreyMissingDatabaseName() throws IOException, StudyImporterException { final Map<String, String> parsedProperties = new HashMap<String, String>(); String predOneLine = "DATA_ID,PRED_ID,PREY_SOURCE_NAME,PREY_DATABASE_NAME,PHYSIOLOG_STATE,SED_ORIGIN,PREY_PARTS,PREY_LIFE_HIST_STAGE,PREY_COND_INDEX,PREY_SEX,PREY_SEX_RATIO,PREY_LEN_TYPE,PREY_MIN_LEN,PREY_MAX_LEN,PREY_MN_LEN,PREY_MIN_WIDTH,PREY_MAX_WIDTH,PREY_MN_WIDTH,BIOMASS,BIOMASS_QUALIFIER,PCT_BIOMASS,PCT_BIOMASS_QUALIFIER,N_CONS,N_CONS_QUALIFIER,PCT_N_CONS,PCT_N_CONS_QUALIFIER,VOL_CONS,VOL_CONS_QUALIFIER,PCT_VOL_CONS,PCT_VOL_CONS_QUALIFIER,FREQ_OCC,FREQ_OCC_QUALIFIER,PCT_FREQ_OCC,PCT_FREQ_OCC_QUALIFIER,IRI,PCT_IRI,IRIa,IIR,E,PREY_NOTES,ENTRY_DATE,ENTRY_PERSON,EDITED_DATE,DATA_EDITOR,MODIFY_DATE,DATA_MODIFIER\n" + "ACT_16R,Cchr.1,Crustacea,,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,1.245,NA,0.15,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"), "PREY_", 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("Crustacea")); assertThat(parsedProperties.get("GOMEXSI:PREY_SOURCE_NAME"), is("Crustacea")); assertThat(parsedProperties.get("GOMEXSI:PREY_DATABASE_NAME"), is("")); }
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; }