Search in sources :

Example 1 with GeoServiceArea

use of eu.etaxonomy.cdm.ext.geo.GeoServiceArea in project cdmlib by cybertaxonomy.

the class MarkupImportBase method makeArea.

/**
 * @param state
 * @param areaName
 * @param level
 * @return
 */
protected NamedArea makeArea(MarkupImportState state, String areaName, NamedAreaLevel level) {
    // TODO FM vocabulary
    TermVocabulary<NamedArea> voc = null;
    NamedAreaType areaType = null;
    NamedArea area = null;
    try {
        area = state.getTransformer().getNamedAreaByKey(areaName);
    } catch (UndefinedTransformerMethodException e) {
        throw new RuntimeException(e);
    }
    if (area == null) {
        boolean isNewInState = false;
        UUID uuid = state.getAreaUuid(areaName);
        if (uuid == null) {
            isNewInState = true;
            try {
                uuid = state.getTransformer().getNamedAreaUuid(areaName);
                if (uuid == null) {
                    uuid = UUID.randomUUID();
                    state.putAreaUuid(areaName, uuid);
                }
            } catch (UndefinedTransformerMethodException e) {
                throw new RuntimeException(e);
            }
        }
        CdmImportBase.TermMatchMode matchMode = CdmImportBase.TermMatchMode.UUID_LABEL;
        area = getNamedArea(state, uuid, areaName, areaName, areaName, areaType, level, voc, matchMode);
        if (isNewInState) {
            state.putAreaUuid(areaName, area.getUuid());
            // TODO just for testing -> make generic and move to better place
            String geoServiceLayer = "vmap0_as_bnd_political_boundary_a";
            String layerFieldName = "nam";
            if ("Bangka".equals(areaName)) {
                String areaValue = "PULAU BANGKA#SUMATERA SELATAN";
                GeoServiceArea geoServiceArea = new GeoServiceArea();
                geoServiceArea.add(geoServiceLayer, layerFieldName, areaValue);
                this.editGeoService.setMapping(area, geoServiceArea);
            // save(area, state);
            }
            if ("Luzon".equals(areaName)) {
                GeoServiceArea geoServiceArea = new GeoServiceArea();
                List<String> list = Arrays.asList("HERMANA MAYOR ISLAND#CENTRAL LUZON", "HERMANA MENOR ISLAND#CENTRAL LUZON", "CENTRAL LUZON");
                for (String areaValue : list) {
                    geoServiceArea.add(geoServiceLayer, layerFieldName, areaValue);
                }
                this.editGeoService.setMapping(area, geoServiceArea);
            // save(area, state);
            }
            if ("Mindanao".equals(areaName)) {
                GeoServiceArea geoServiceArea = new GeoServiceArea();
                List<String> list = Arrays.asList("NORTHERN MINDANAO", "SOUTHERN MINDANAO", "WESTERN MINDANAO");
                // TODO to be continued
                for (String areaValue : list) {
                    geoServiceArea.add(geoServiceLayer, layerFieldName, areaValue);
                }
                this.editGeoService.setMapping(area, geoServiceArea);
            // save(area, state);
            }
            if ("Palawan".equals(areaName)) {
                GeoServiceArea geoServiceArea = new GeoServiceArea();
                List<String> list = Arrays.asList("PALAWAN#SOUTHERN TAGALOG");
                for (String areaValue : list) {
                    geoServiceArea.add(geoServiceLayer, layerFieldName, areaValue);
                }
                this.editGeoService.setMapping(area, geoServiceArea);
            // save(area, state);
            }
        }
    }
    return area;
}
Also used : CdmImportBase(eu.etaxonomy.cdm.io.common.CdmImportBase) NamedArea(eu.etaxonomy.cdm.model.location.NamedArea) GeoServiceArea(eu.etaxonomy.cdm.ext.geo.GeoServiceArea) NamedAreaType(eu.etaxonomy.cdm.model.location.NamedAreaType) TermMatchMode(eu.etaxonomy.cdm.io.common.CdmImportBase.TermMatchMode) UUID(java.util.UUID) UndefinedTransformerMethodException(eu.etaxonomy.cdm.io.common.mapping.UndefinedTransformerMethodException)

Aggregations

GeoServiceArea (eu.etaxonomy.cdm.ext.geo.GeoServiceArea)1 CdmImportBase (eu.etaxonomy.cdm.io.common.CdmImportBase)1 TermMatchMode (eu.etaxonomy.cdm.io.common.CdmImportBase.TermMatchMode)1 UndefinedTransformerMethodException (eu.etaxonomy.cdm.io.common.mapping.UndefinedTransformerMethodException)1 NamedArea (eu.etaxonomy.cdm.model.location.NamedArea)1 NamedAreaType (eu.etaxonomy.cdm.model.location.NamedAreaType)1 UUID (java.util.UUID)1