+ /**
+ * @param desc
+ * @param string
+ * @param uuidUserDefinedAnnotationTypeVocabulary
+ */
+ private void handleDistribution(SimpleExcelTaxonImportState<CONFIG> state,
+ TaxonDescription desc, String key, UUID uuid, String line, String id) {
+ HashMap<String, String> record = state.getOriginalRecord();
+ String value = getValue(record, key);
+ if (value == null || value.matches("[x\\.\\?]")){
+ NamedArea area = getNamedArea(state, uuid, null, null, null, null, null);
+ Distribution dist;
+ if (".".equals(value)){
+ logger.warn(line + "'.' Should not exist anmore as a distribution status: '" + value + "' for " + key);
+ dist = Distribution.NewInstance(area, PresenceAbsenceTerm.ABSENT());
+ }else if (value == null){
+ //TODO is absent wanted
+ dist = Distribution.NewInstance(area, PresenceAbsenceTerm.ABSENT());
+ }else if ("x".equals(value)){
+ dist = Distribution.NewInstance(area, PresenceAbsenceTerm.PRESENT());
+ }else if ("?".equals(value)){
+ dist = Distribution.NewInstance(area, PresenceAbsenceTerm.PRESENT_DOUBTFULLY());
+ }else {
+ logger.warn(line + "Not matching status. THis should not happpen '" + value + "' for " + key);
+ return;
+ }
+ desc.addElement(dist);
+ dist.addImportSource(id, getWorksheetName(), getSourceCitation(state), line);
+ }else {
+ logger.warn(line + "Unrecognized distribution status '" + value + "' for " + key);
+ }
+ }
+
+ private void handleStatus(SimpleExcelTaxonImportState<CONFIG> state,
+ TaxonDescription desc, String key, UUID uuid, String line, String id) {
+ HashMap<String, String> record = state.getOriginalRecord();
+ String value = getValue(record, key);
+ if (value != null){
+ NamedArea area = getNamedArea(state, uuid, null, null, null, null, null);
+ Distribution dist;
+ if (".".equals(value)){
+ dist = Distribution.NewInstance(area, PresenceAbsenceTerm.ABSENT());
+ logger.warn(line + "'.' Should not exist anmore as a distribution status: '" + value + "' for " + key);
+ }else if ("Range-restricted".equals(value)){
+ dist = Distribution.NewInstance(area, PresenceAbsenceTerm.ENDEMIC_FOR_THE_RELEVANT_AREA());
+ }else if ("?Range-restricted".equals(value)){
+ dist = Distribution.NewInstance(area, PresenceAbsenceTerm.ENDEMIC_FOR_THE_RELEVANT_AREA());
+ }else if ("Xenophyte".equals(value)){
+ dist = Distribution.NewInstance(area, PresenceAbsenceTerm.INTRODUCED());
+ }else if ("?Xenophyte".equals(value)){
+ dist = Distribution.NewInstance(area, PresenceAbsenceTerm.INTRODUCED_DOUBTFULLY_INTRODUCED());
+ }else {
+ logger.warn(line + "Not matching status. This should not happpen '" + value + "' for " + key);
+ return;
+ }
+ desc.addElement(dist);
+ dist.addImportSource(id, getWorksheetName(), getSourceCitation(state), line);
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ private void initAreaVocabulary(SimpleExcelTaxonImportState<CONFIG> state) {
+ if (areasVoc == null){
+ areasVoc = (OrderedTermVocabulary<NamedArea>)this.getVocabularyService().find(FloraHellenicaTransformer.uuidFloraHellenicaAreasVoc);
+ if (areasVoc == null){
+ createAreasVoc(state);
+ }
+ }
+ }
+
+
+ /**
+ * @param state
+ */
+ private void initChorologicalVocabulary(SimpleExcelTaxonImportState<CONFIG> state) {
+ if (chorologicalVoc == null){
+ UUID uuid = FloraHellenicaTransformer.uuidFloraHellenicaChorologicalVoc;
+ chorologicalVoc = (OrderedTermVocabulary<State>)this.getVocabularyService().find(uuid);
+ if (chorologicalVoc == null){
+ createChorologicalVoc(state, uuid);
+ }
+ }
+
+ }
+
+
+ @SuppressWarnings("unchecked")
+ private void initLifeformVocabulary(SimpleExcelTaxonImportState<CONFIG> state) {
+ if (lifeformVoc == null){
+ UUID uuid = FloraHellenicaTransformer.uuidFloraHellenicaLifeformVoc;
+ lifeformVoc = (OrderedTermVocabulary<State>)this.getVocabularyService().find(uuid);
+ if (lifeformVoc == null){
+ createLifeformVoc(state, uuid);
+ }
+ }
+ }
+
+ /**
+ * @param state
+ * @param vocUuid
+ */
+ private void createLifeformVoc(SimpleExcelTaxonImportState<CONFIG> state, UUID vocUuid) {
+ //voc
+ URI termSourceUri = null;
+ String label = "Checklist of Greece Lifeforms";
+ String description = "Lifeforms as used in the Checklist of Greece";
+ lifeformVoc = OrderedTermVocabulary.NewInstance(TermType.State,
+ description, label, null, termSourceUri);
+ lifeformVoc.setUuid(vocUuid);
+
+ addLifeform(state, "A", "Aquatics", FloraHellenicaTransformer.uuidLifeformA);
+ addLifeform(state, "C", "Chamaephytes", FloraHellenicaTransformer.uuidLifeformC);
+ addLifeform(state, "G", "Geophytes (Cryptophytes)", FloraHellenicaTransformer.uuidLifeformG);
+ addLifeform(state, "H", "Hemicryptophytes", FloraHellenicaTransformer.uuidLifeformH);
+ addLifeform(state, "P", "Phanerophytes", FloraHellenicaTransformer.uuidLifeformP);
+ addLifeform(state, "T", "Therophytes", FloraHellenicaTransformer.uuidLifeformT);
+ this.getVocabularyService().save(lifeformVoc);
+ return;
+ }
+
+
+ /**
+ * @param state
+ * @param uuid
+ */
+ private void createChorologicalVoc(SimpleExcelTaxonImportState<CONFIG> state, UUID vocUuid) {
+ //voc
+ URI termSourceUri = null;
+ String label = "Checklist of Greece Chorological Categories";
+ String description = "Chorological Categories as used in the Checklist of Greece";
+ chorologicalVoc = OrderedTermVocabulary.NewInstance(TermType.State,
+ description, label, null, termSourceUri);
+ chorologicalVoc.setUuid(vocUuid);
+
+ addChorological(state, "Bk", "Balkan", "", FloraHellenicaTransformer.uuidChorologicalBk);
+ addChorological(state, "BI", "Balkan-Italy", "", FloraHellenicaTransformer.uuidChorologicalBI);
+ addChorological(state, "BA", "Balkan-Anatolia", "", FloraHellenicaTransformer.uuidChorologicalBA);
+ addChorological(state, "BC", "Balkan-Central Europe", "", FloraHellenicaTransformer.uuidChorologicalBC);
+ addChorological(state, "EM", "East Mediterranean", "", FloraHellenicaTransformer.uuidChorologicalEM);
+ addChorological(state, "Me", "Mediterranean", "", FloraHellenicaTransformer.uuidChorologicalMe);
+ addChorological(state, "MA", "Mediterranean-Atlantic", "", FloraHellenicaTransformer.uuidChorologicalMA);
+ addChorological(state, "ME", "Mediterranean-European", "", FloraHellenicaTransformer.uuidChorologicalME);
+ addChorological(state, "MS", "Mediterranean-SW Asian", "", FloraHellenicaTransformer.uuidChorologicalMS);
+ addChorological(state, "EA", "European-SW Asian", "", FloraHellenicaTransformer.uuidChorologicalEA);
+ addChorological(state, "ES", "Euro-Siberian", "", FloraHellenicaTransformer.uuidChorologicalES);
+ addChorological(state, "Eu", "European", "", FloraHellenicaTransformer.uuidChorologicalEu);
+ addChorological(state, "Pt", "Paleotemperate", "", FloraHellenicaTransformer.uuidChorologicalPt);
+ addChorological(state, "Ct", "Circumtemperate", "", FloraHellenicaTransformer.uuidChorologicalCt);
+ addChorological(state, "IT", "Irano-Turanian", "", FloraHellenicaTransformer.uuidChorologicalIT);
+ addChorological(state, "SS", "Saharo-Sindian", "", FloraHellenicaTransformer.uuidChorologicalSS);
+ addChorological(state, "ST", "Subtropical-tropical", "", FloraHellenicaTransformer.uuidChorologicalST);
+ addChorological(state, "Bo", "(Circum-) Boreal", "", FloraHellenicaTransformer.uuidChorologicalBo);
+ addChorological(state, "AA", "Arctic-Alpine", "", FloraHellenicaTransformer.uuidChorologicalAA);
+ addChorological(state, "Co", "Cosmopolitan", "", FloraHellenicaTransformer.uuidChorologicalCo);
+ addChorological(state, "*", "Greek endemic", "Greek endemics (incl. single-island and single-mountain endemics)", FloraHellenicaTransformer.uuidChorologicalStar);
+
+ this.getVocabularyService().save(chorologicalVoc);
+ return;
+
+ }
+
+
+ /**
+ * @param state
+ * @param string
+ * @param string2
+ * @param string3
+ * @param uuidchorologicalstar
+ */
+ private void addChorological(SimpleExcelTaxonImportState<CONFIG> state, String abbrevLabel, String label,
+ String string3, UUID uuidChorological) {
+ State chorological = addState(state, abbrevLabel, label, label, uuidChorological, chorologicalVoc);
+
+
+ }
+
+ /**
+ * @param state
+ * @param string
+ * @param uuidlifeformt
+ */
+ private void addLifeform(SimpleExcelTaxonImportState<CONFIG> state, String abbrevLabel, String label, UUID uuidlifeform) {
+ State lifeForm = addState(state, abbrevLabel, label, label, uuidlifeform, lifeformVoc);
+ lifeformMap.put(abbrevLabel, lifeForm);
+ }
+
+ private State addState(SimpleExcelTaxonImportState<CONFIG> state,
+ String abbrev, String stateLabel, String description, UUID uuid, OrderedTermVocabulary<State> voc) {
+ State newState = State.NewInstance(
+ description, stateLabel, abbrev);
+ newState.setUuid(uuid);
+ newState.setIdInVocabulary(abbrev);
+ newState.setIdInVocabulary(abbrev);
+ voc.addTerm(newState);
+ return newState;
+ }
+
+ private void initHabitatVocabulary(SimpleExcelTaxonImportState<CONFIG> state) {
+ if (habitatVoc == null){
+ UUID uuid = FloraHellenicaTransformer.uuidFloraHellenicaHabitatVoc;
+ habitatVoc = (OrderedTermVocabulary<State>)this.getVocabularyService().find(uuid);
+ if (habitatVoc == null){
+ createHabitatVoc(state, uuid);
+ }
+ }
+ }
+
+
+ /**
+ * @param state
+ */
+ private void createHabitatVoc(SimpleExcelTaxonImportState<CONFIG> state, UUID vocUuid) {
+ //voc
+ URI termSourceUri = null;
+ String label = "Checklist of Greece Habitats";
+ String description = "Habitats as used in the Checklist of Greece";
+ habitatVoc = OrderedTermVocabulary.NewInstance(TermType.State,
+ description, label, null, termSourceUri);
+ habitatVoc.setUuid(vocUuid);
+
+ addHabitat(state, "A", "Freshwater habitats", "Freshwater habitats (Aquatic habitats, springs and fens, reedbeds and damp tall herb vegetation, seasonally flooded depressions, damp and seepage meadows, streambanks, river and lake shores)", FloraHellenicaTransformer.uuidHabitatA);
+ addHabitat(state, "C", "Cliffs, rocks, walls, ravines, boulders", "Cliffs, rocks, walls, ravines, boulders", FloraHellenicaTransformer.uuidHabitatC);
+ addHabitat(state, "G", "Temperate and submediterranean Grasslands", "Temperate and submediterranean Grasslands (lowland to montane dry and mesic meadows and pastures, rock outcrops and stony ground, grassy non-ruderal verges and forest edges)", FloraHellenicaTransformer.uuidHabitatG);
+ addHabitat(state, "H", "High mountain vegetation", "High mountain vegetation (subalpine and alpine grasslands, screes and rocks, scrub above the treeline)", FloraHellenicaTransformer.uuidHabitatH);
+ addHabitat(state, "M", "Coastal habitats", "Coastal habitats (Marine waters and mudflats, salt marshes, sand dunes, littoral rocks, halo-nitrophilous scrub)", FloraHellenicaTransformer.uuidHabitatM);
+ addHabitat(state, "P", "Xeric Mediterranean Phrygana and grasslands", "Xeric Mediterranean Phrygana and grasslands (Mediterranean dwarf shrub formations, annual-rich pastures and lowland screes)", FloraHellenicaTransformer.uuidHabitatP);
+ addHabitat(state, "R", "Agricultural and Ruderal habitats", "Agricultural and Ruderal habitats (fields, gardens and plantations, roadsides and trampled sites, frequently disturbed and pioneer habitats)", FloraHellenicaTransformer.uuidHabitatR);
+ addHabitat(state, "W", "Woodlands and scrub", "Woodlands and scrub (broadleaved and coniferous forest, riparian and mountain forest and scrub, hedges, shady woodland margins)", FloraHellenicaTransformer.uuidHabitatW);
+
+ this.getVocabularyService().save(habitatVoc);
+ return;
+ }
+
+ /**
+ * @param state
+ * @param string
+ * @param uuidlifeformt
+ */
+ private void addHabitat(SimpleExcelTaxonImportState<CONFIG> state, String abbrev, String label, String desc, UUID uuidHabitat) {
+ addState(state, abbrev, label, desc, uuidHabitat, habitatVoc);
+ }
+
+ /**
+ * @param state
+ * @return
+ */
+ @SuppressWarnings("unchecked")
+ private void createAreasVoc(SimpleExcelTaxonImportState<CONFIG> state) {
+ //voc
+ URI termSourceUri = null;
+ String label = "Checklist of Greece Areas";
+ String description = "Areas as used in the Checklist of Greece";
+ areasVoc = OrderedTermVocabulary.NewInstance(TermType.NamedArea,
+ description, label, null, termSourceUri);
+ areasVoc.setUuid(FloraHellenicaTransformer.uuidFloraHellenicaAreasVoc);
+// Representation rep = Representation.NewInstance("Estados Méxicanos", "Estados Méxicanos", null, Language.SPANISH_CASTILIAN());
+// areasVoc.addRepresentation(rep);
+
+ //greece country
+ String countryLabel = "Greece";
+ greece = NamedArea.NewInstance(
+ countryLabel, countryLabel, null);
+ greece.setUuid(FloraHellenicaTransformer.uuidAreaGreece);
+ areasVoc.addTerm(greece);
+ //FIXME
+// addMapping(greece, xx "mex_adm0", "iso", "MEX");
+
+ addArea(state, "IoI", "Ionian Islands", FloraHellenicaTransformer.uuidAreaIoI);
+ addArea(state, "NPi", "North Pindos", FloraHellenicaTransformer.uuidAreaNPi);
+ addArea(state, "SPi", "South Pindos", FloraHellenicaTransformer.uuidAreaSPi);
+ addArea(state, "Pe", "Peloponnisos", FloraHellenicaTransformer.uuidAreaPe);
+ addArea(state, "StE", "Sterea Ellas", FloraHellenicaTransformer.uuidAreaStE);
+ addArea(state, "EC", "East Central Greece", FloraHellenicaTransformer.uuidAreaEC);
+ addArea(state, "NC", "North Central Greece", FloraHellenicaTransformer.uuidAreaNC);
+ addArea(state, "NE", "North-East Greece", FloraHellenicaTransformer.uuidAreaNE);
+ addArea(state, "NAe", "North Aegean islands", FloraHellenicaTransformer.uuidAreaNAe);
+ addArea(state, "WAe", "West Aegean islands", FloraHellenicaTransformer.uuidAreaWAe);
+ addArea(state, "Kik", "Kiklades", FloraHellenicaTransformer.uuidAreaKik);
+ addArea(state, "KK", "Kriti and Karpathos", FloraHellenicaTransformer.uuidAreaKK);
+ addArea(state, "EAe", "East Aegean islands", FloraHellenicaTransformer.uuidAreaEAe);
+
+ this.getVocabularyService().save(areasVoc);
+ return;
+ }
+
+ private void addArea(SimpleExcelTaxonImportState<CONFIG> state, String abbrevLabel, String areaLabel, UUID uuid) {
+ addArea(state, abbrevLabel, areaLabel, uuid, areaLabel); //short cut if label and mapping label are equal
+ }
+
+ private void addArea(SimpleExcelTaxonImportState<CONFIG> state, String abbrevLabel, String areaLabel,
+ UUID uuid, String mappingLabel) {
+ addArea(state, abbrevLabel, areaLabel, uuid, mappingLabel, null); //short cut if label and mapping label are equal
+ }
+
+
+ /**
+ * @param state
+ * @param string
+ * @param uuidaguascalientes
+ */
+ private void addArea(SimpleExcelTaxonImportState<CONFIG> state, String abbrevLabel, String areaLabel, UUID uuid, String mappingLabel, Integer id1) {
+ NamedArea newArea = NamedArea.NewInstance(
+ areaLabel, areaLabel, abbrevLabel);
+ newArea.setIdInVocabulary(abbrevLabel);
+ newArea.setUuid(uuid);
+ newArea.setPartOf(greece);
+ newArea.setLevel(null);
+ newArea.setType(NamedAreaType.NATURAL_AREA());
+ areasVoc.addTerm(newArea);
+ //FIXME
+ if (id1 != null){
+ addMapping(newArea, "mex_adm1", "id_1", String.valueOf(id1));
+ }else if (mappingLabel != null){
+ addMapping(newArea, "mex_adm1", "name_1", mappingLabel);
+ }
+ }
+
+ private void addMapping(NamedArea area, String mapping_layer, String mapping_field, String abbrev) {
+ GeoServiceAreaAnnotatedMapping mapping = (GeoServiceAreaAnnotatedMapping)this.getBean("geoServiceAreaAnnotatedMapping");
+ GeoServiceArea geoServiceArea = new GeoServiceArea();
+ geoServiceArea.add(mapping_layer, mapping_field, abbrev);
+ mapping.set(area, geoServiceArea);
+ }