Fix TransientObjectException for distribution map #5357
authorAndreas Müller <a.mueller@bgbm.org>
Fri, 18 Dec 2015 10:09:58 +0000 (11:09 +0100)
committerAndreas Müller <a.mueller@bgbm.org>
Fri, 18 Dec 2015 10:12:24 +0000 (11:12 +0100)
Test do not yet work fully and are commented

cdmlib-ext/src/main/java/eu/etaxonomy/cdm/ext/geo/EditGeoService.java
cdmlib-ext/src/test/java/eu/etaxonomy/cdm/ext/geo/EditGeoServiceTest.java
cdmlib-ext/src/test/resources/eu/etaxonomy/cdm/ext/geo/EditGeoServiceTest.getDistributionServiceRequestParameterString.xml [new file with mode: 0644]

index f2a8a5ffd13b69b4e614098e2bc807d19ed623f6..331616f290ed3c394a6bb27abb59840645f0692f 100644 (file)
@@ -33,10 +33,12 @@ import eu.etaxonomy.cdm.api.service.dto.CondensedDistribution;
 import eu.etaxonomy.cdm.api.service.dto.DistributionInfoDTO;
 import eu.etaxonomy.cdm.api.service.dto.DistributionInfoDTO.InfoPart;
 import eu.etaxonomy.cdm.api.utility.DescriptionUtility;
 import eu.etaxonomy.cdm.api.service.dto.DistributionInfoDTO;
 import eu.etaxonomy.cdm.api.service.dto.DistributionInfoDTO.InfoPart;
 import eu.etaxonomy.cdm.api.utility.DescriptionUtility;
+import eu.etaxonomy.cdm.model.common.CdmBase;
 import eu.etaxonomy.cdm.model.common.DefinedTermBase;
 import eu.etaxonomy.cdm.model.common.Language;
 import eu.etaxonomy.cdm.model.common.MarkerType;
 import eu.etaxonomy.cdm.model.common.TermVocabulary;
 import eu.etaxonomy.cdm.model.common.DefinedTermBase;
 import eu.etaxonomy.cdm.model.common.Language;
 import eu.etaxonomy.cdm.model.common.MarkerType;
 import eu.etaxonomy.cdm.model.common.TermVocabulary;
+import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
 import eu.etaxonomy.cdm.model.description.Distribution;
 import eu.etaxonomy.cdm.model.description.Feature;
 import eu.etaxonomy.cdm.model.description.IndividualsAssociation;
 import eu.etaxonomy.cdm.model.description.Distribution;
 import eu.etaxonomy.cdm.model.description.Feature;
 import eu.etaxonomy.cdm.model.description.IndividualsAssociation;
@@ -98,20 +100,34 @@ public class EditGeoService implements IEditGeoService {
      * @return
      */
     private Set<Distribution> getDistributionsOf(List<TaxonDescription> taxonDescriptions) {
      * @return
      */
     private Set<Distribution> getDistributionsOf(List<TaxonDescription> taxonDescriptions) {
-        Set<Distribution> distributions = new HashSet<Distribution>();
+        Set<Distribution> result = new HashSet<Distribution>();
 
 
+        Set<Feature> features = getDistributionFeatures();
         for (TaxonDescription taxonDescription : taxonDescriptions) {
         for (TaxonDescription taxonDescription : taxonDescriptions) {
-            List<Distribution> result = dao.getDescriptionElements(
-                    taxonDescription,
-                    null,
-                    getDistributionFeatures(),
-                    Distribution.class,
-                    null,
-                    null,
-                    null);
-            distributions.addAll(result);
+            List<Distribution> distributions;
+            if (taxonDescription.getId() > 0){
+                distributions = dao.getDescriptionElements(
+                        taxonDescription,
+                        null,
+                        null /*features*/,
+                        Distribution.class,
+                        null,
+                        null,
+                        null);
+            }else{
+                distributions = new ArrayList<Distribution>();
+                for (DescriptionElementBase deb : taxonDescription.getElements()){
+                    if (deb.isInstanceOf(Distribution.class)){
+                        if (features == null || features.isEmpty()
+                                || features.contains(deb.getFeature())) {
+                            distributions.add(CdmBase.deproxy(deb, Distribution.class));
+                        }
+                    }
+                }
+            }
+            result.addAll(distributions);
         }
         }
-        return distributions;
+        return result;
     }
 
     /**
     }
 
     /**
index 80e4e2f1bc854a5eef3febe4cfc8cc318b1b1c3b..e6c8a041fbb6f313f3990329d9c8b585b9a4a6ad 100644 (file)
-// $Id$\r
-/**\r
-* Copyright (C) 2007 EDIT\r
-* European Distributed Institute of Taxonomy\r
-* http://www.e-taxonomy.eu\r
-*\r
-* The contents of this file are subject to the Mozilla Public License Version 1.1\r
-* See LICENSE.TXT at the top of this package for the full license terms.\r
-*/\r
-\r
-package eu.etaxonomy.cdm.ext.geo;\r
-\r
-import static org.junit.Assert.assertTrue;\r
-\r
-import java.awt.Color;\r
-import java.io.FileNotFoundException;\r
-import java.io.IOException;\r
-import java.io.InputStream;\r
-import java.io.InputStreamReader;\r
-import java.net.HttpURLConnection;\r
-import java.net.MalformedURLException;\r
-import java.net.URI;\r
-import java.net.URISyntaxException;\r
-import java.net.URL;\r
-import java.util.ArrayList;\r
-import java.util.Collection;\r
-import java.util.HashMap;\r
-import java.util.HashSet;\r
-import java.util.List;\r
-import java.util.Map;\r
-import java.util.Set;\r
-import java.util.UUID;\r
-\r
-import org.apache.commons.lang.StringUtils;\r
-import org.apache.http.client.ClientProtocolException;\r
-import org.apache.log4j.Logger;\r
-import org.junit.Assert;\r
-import org.junit.Before;\r
-import org.junit.Test;\r
-import org.unitils.spring.annotation.SpringBeanByType;\r
-\r
-import eu.etaxonomy.cdm.api.service.ITermService;\r
-import eu.etaxonomy.cdm.api.service.IVocabularyService;\r
-import eu.etaxonomy.cdm.api.service.dto.CondensedDistribution;\r
-import eu.etaxonomy.cdm.api.utility.DescriptionUtility;\r
-import eu.etaxonomy.cdm.common.StreamUtils;\r
-import eu.etaxonomy.cdm.common.UriUtils;\r
-import eu.etaxonomy.cdm.model.common.DefinedTermBase;\r
-import eu.etaxonomy.cdm.model.common.Language;\r
-import eu.etaxonomy.cdm.model.common.TermType;\r
-import eu.etaxonomy.cdm.model.common.TermVocabulary;\r
-import eu.etaxonomy.cdm.model.description.Distribution;\r
-import eu.etaxonomy.cdm.model.description.PresenceAbsenceTerm;\r
-import eu.etaxonomy.cdm.model.location.Country;\r
-import eu.etaxonomy.cdm.model.location.NamedArea;\r
-import eu.etaxonomy.cdm.model.location.NamedAreaLevel;\r
-import eu.etaxonomy.cdm.model.location.NamedAreaType;\r
-import eu.etaxonomy.cdm.persistence.dao.common.IDefinedTermDao;\r
-import eu.etaxonomy.cdm.test.integration.CdmTransactionalIntegrationTest;\r
-\r
-/**\r
- * @author a.mueller\r
- * @created 08.10.2008\r
- */\r
-public class EditGeoServiceTest extends CdmTransactionalIntegrationTest {\r
-    private static final Logger logger = Logger.getLogger(EditGeoServiceTest.class);\r
-\r
-    private static final String EDIT_MAPSERVICE_URI_STING = "http://edit.africamuseum.be/edit_wp5/v1.2/rest_gen.php";\r
-    private static URI editMapServiceUri;\r
-\r
-    //@SpringBeanByType\r
-    private IDefinedTermDao termDao;\r
-\r
-    @SpringBeanByType\r
-    private ITermService termService;\r
-\r
-    @SpringBeanByType\r
-    private IVocabularyService vocabService;\r
-\r
-    @SpringBeanByType\r
-    private GeoServiceAreaAnnotatedMapping mapping;\r
-\r
-    @SpringBeanByType\r
-    private IEditGeoService editGeoService;\r
-//\r
-//     /**\r
-//      * @throws java.lang.Exception\r
-//      */\r
-//     @BeforeClass\r
-//     public static void setUpBeforeClass() throws Exception {\r
-//             DefaultTermInitializer initializer = new DefaultTermInitializer();\r
-//             initializer.initialize();\r
-//     }\r
-\r
-    /**\r
-     * @throws java.lang.Exception\r
-     */\r
-    @Before\r
-    public void setUp() throws Exception {\r
-        EditGeoServiceUtilities.setTermDao(termDao);\r
-        System.setProperty("ONLY-A-TEST", "TRUE"); // allows EditGeoServiceUtilities to skip some line of code\r
-        editMapServiceUri = new URI(EDIT_MAPSERVICE_URI_STING);\r
-    }\r
-\r
-\r
-//******************************************** TESTS**************\r
-\r
-    @Test\r
-    public void testGetWebServiceUrlCountry() throws MalformedURLException, IOException {\r
-        Set<Distribution> distributions = new HashSet<Distribution>();\r
-        Country germany = termService.findByIdInVocabulary("DEU", Country.uuidCountryVocabulary, Country.class);\r
-//        germany = (Country)termService.find(665);\r
-//        germany = (Country)termService.find(UUID.fromString("cbe7ce69-2952-4309-85dd-0d7d4a4830a1"));\r
-\r
-//        germany = Country.GERMANY();\r
-\r
-        distributions.add(Distribution.NewInstance(germany, PresenceAbsenceTerm.PRESENT()));\r
-        distributions.add(Distribution.NewInstance(termService.findByIdInVocabulary("DE", Country.uuidCountryVocabulary, Country.class), PresenceAbsenceTerm.INTRODUCED()));\r
-        Map<PresenceAbsenceTerm, Color> presenceAbsenceColorMap = new HashMap<PresenceAbsenceTerm, Color>();\r
-        presenceAbsenceColorMap.put(PresenceAbsenceTerm.PRESENT(), Color.BLUE);\r
-        presenceAbsenceColorMap.put(PresenceAbsenceTerm.INTRODUCED(), Color.BLACK);\r
-        List<Language> languages = new ArrayList<Language>();\r
-\r
-        boolean subAreaPreference = false;\r
-        boolean statusOrderPreference = false;\r
-\r
-\r
-        Collection<Distribution> filteredDistributions = DescriptionUtility.filterDistributions(\r
-                distributions, null, true, statusOrderPreference, subAreaPreference);\r
-\r
-        String result = EditGeoServiceUtilities.getDistributionServiceRequestParameterString(filteredDistributions,\r
-                mapping, null, null, languages );\r
-        logger.warn(result);\r
-        Assert.assertTrue("WebServiceUrl must contain country part for Germany", result.matches(".*ad=country_earth(%3A|:)gmi_cntry:.:DEU.*"));\r
-    }\r
-\r
-    @Test\r
-    public void testGetWebServiceUrlTdwg() throws MalformedURLException, IOException {\r
-        //String webServiceUrl = "http://www.test.de/webservice";\r
-        Set<Distribution> distributions = new HashSet<Distribution>();\r
-        distributions.add(Distribution.NewInstance(termService.getAreaByTdwgAbbreviation("SPA"), PresenceAbsenceTerm.PRESENT()));\r
-        distributions.add(Distribution.NewInstance(termService.getAreaByTdwgAbbreviation("GER"), PresenceAbsenceTerm.INTRODUCED()));\r
-        distributions.add(Distribution.NewInstance(termService.getAreaByTdwgAbbreviation("14"), PresenceAbsenceTerm.CULTIVATED()));\r
-        distributions.add(Distribution.NewInstance(termService.getAreaByTdwgAbbreviation("BGM"), PresenceAbsenceTerm.ABSENT()));\r
-        distributions.add(Distribution.NewInstance(termService.getAreaByTdwgAbbreviation("FRA"), PresenceAbsenceTerm.ABSENT()));\r
-        distributions.add(Distribution.NewInstance(termService.getAreaByTdwgAbbreviation("IND-AP"), PresenceAbsenceTerm.PRESENT()));\r
-\r
-        Map<PresenceAbsenceTerm, Color> presenceAbsenceColorMap = new HashMap<PresenceAbsenceTerm, Color>();\r
-        presenceAbsenceColorMap.put(PresenceAbsenceTerm.PRESENT(), Color.BLUE);\r
-        presenceAbsenceColorMap.put(PresenceAbsenceTerm.INTRODUCED(), Color.BLACK);\r
-        presenceAbsenceColorMap.put(PresenceAbsenceTerm.CULTIVATED(), Color.YELLOW);\r
-        presenceAbsenceColorMap.put(PresenceAbsenceTerm.ABSENT(), Color.DARK_GRAY);\r
-        String backLayer ="";\r
-        presenceAbsenceColorMap = null;\r
-        String bbox="-20,0,120,70";\r
-        List<Language> languages = new ArrayList<Language>();\r
-\r
-        boolean subAreaPreference = false;\r
-        boolean statusOrderPreference = false;\r
-        String result = EditGeoServiceUtilities.getDistributionServiceRequestParameterString(\r
-                distributions,\r
-                mapping,\r
-                null, // presenceAbsenceTermColors\r
-                null, // projectToLayer\r
-                languages );\r
-        //TODO Set semantics is not determined\r
-        //String expected = "http://www.test.de/webservice?l=tdwg3&ad=tdwg3:a:GER|b:OKL|c:BGM|b:SPA|d:FRA&as=a:005500|b:00FF00|c:FFFFFF|d:001100&bbox=-20,40,40,40&ms=400x300";\r
-        logger.debug(result);\r
-        assertTrue(result.matches(".*ad=tdwg[1-4].*"));\r
-        assertTrue(result.matches(".*tdwg2:[a-d]:14[\\|&].*") );\r
-        assertTrue(result.matches(".*[a-d]:FRA,BGM[\\|&].*") || result.matches(".*[a-d]:BGM,FRA[\\|&].*") );\r
-        assertTrue(result.matches(".*[a-d]:GER[\\|&].*") );\r
-        assertTrue(result.matches(".*[a-d]:SPA[\\|&].*") );\r
-        assertTrue(result.matches(".*tdwg4:[a-d]:INDAP[\\|&].*") );\r
-        //assertTrue(result.matches("0000ff"));\r
-        //TODO continue\r
-\r
-        // request map image from webservice\r
-        subTestWithEditMapService(result);\r
-    }\r
-\r
-    @Test\r
-    public void testGetWebServiceUrlCyprus() throws ClientProtocolException, IOException, URISyntaxException {\r
-        makeCyprusAreas();\r
-        Set<Distribution> distributions = new HashSet<Distribution>();\r
-        distributions.add(Distribution.NewInstance(divisions.get("1"), PresenceAbsenceTerm.PRESENT()));\r
-        distributions.add(Distribution.NewInstance(divisions.get("2"), PresenceAbsenceTerm.INTRODUCED()));\r
-        distributions.add(Distribution.NewInstance(divisions.get("3"), PresenceAbsenceTerm.CULTIVATED()));\r
-        distributions.add(Distribution.NewInstance(divisions.get("4"), PresenceAbsenceTerm.ABSENT()));\r
-        distributions.add(Distribution.NewInstance(divisions.get("5"), PresenceAbsenceTerm.ABSENT()));\r
-        distributions.add(Distribution.NewInstance(divisions.get("6"), PresenceAbsenceTerm.PRESENT()));\r
-\r
-        Map<PresenceAbsenceTerm, Color> presenceAbsenceColorMap = new HashMap<PresenceAbsenceTerm, Color>();\r
-        presenceAbsenceColorMap.put(PresenceAbsenceTerm.PRESENT(), Color.BLUE);\r
-        presenceAbsenceColorMap.put(PresenceAbsenceTerm.INTRODUCED(), Color.BLACK);\r
-        presenceAbsenceColorMap.put(PresenceAbsenceTerm.CULTIVATED(), Color.YELLOW);\r
-        presenceAbsenceColorMap.put(PresenceAbsenceTerm.ABSENT(), Color.DARK_GRAY);\r
-        String backLayer ="";\r
-        presenceAbsenceColorMap = null;\r
-        String bbox="-20,0,120,70";\r
-        List<Language> languages = new ArrayList<Language>();\r
-\r
-        boolean subAreaPreference = false;\r
-        boolean statusOrderPreference = false;\r
-        String result = EditGeoServiceUtilities.getDistributionServiceRequestParameterString(\r
-                distributions,\r
-                mapping,\r
-                null, null, languages );\r
-        //TODO Set semantics is not determined\r
-        //String expected = "http://www.test.de/webservice?l=tdwg3&ad=tdwg3:a:GER|b:OKL|c:BGM|b:SPA|d:FRA&as=a:005500|b:00FF00|c:FFFFFF|d:001100&bbox=-20,40,40,40&ms=400x300";\r
-        assertTrue(result.matches(".*ad=cyprusdivs%3Abdcode:.*"));\r
-        assertTrue(result.matches(".*[a-d]:5,4[\\|&].*") || result.matches(".*[a-d]:4,5[\\|&].*") );\r
-        assertTrue(result.matches(".*[a-d]:1,6[\\|&].*") || result.matches(".*[a-d]:6,1[\\|&].*") );\r
-        assertTrue(result.matches(".*[a-d]:2[\\|&].*") );\r
-        assertTrue(result.matches(".*[a-d]:3[\\|&].*") );\r
-\r
-        // request map image from webservice\r
-        subTestWithEditMapService(result);\r
-    }\r
-\r
-    private void subTestWithEditMapService(String queryString)throws MalformedURLException, IOException {\r
-        if(UriUtils.isServiceAvailable(editMapServiceUri)){\r
-            URL requestUrl = new URL(editMapServiceUri.toString() + "?img=false&bbox=-180,-90,180,90&ms=1000&" + queryString);\r
-            logger.debug("editMapServiceUri: " + requestUrl);\r
-            HttpURLConnection connection = (HttpURLConnection) requestUrl.openConnection();\r
-            connection.connect();\r
-//            connection.setReadTimeout(10000);  //timeout after 10 sec, does not seem to work\r
-            assertTrue(connection.getResponseCode() == 200);\r
-            InputStream contentStream = connection.getInputStream();\r
-            String content = StreamUtils.readToString(contentStream);\r
-            logger.debug("EditMapService response body:\n" + content);\r
-            assertTrue(content.startsWith("[{"));\r
-            assertTrue(content.endsWith("}]"));\r
-            assertTrue(content.matches(".*\"bbox\":.*"));\r
-            assertTrue(content.matches(".*\"legend\":.*"));\r
-            assertTrue(content.matches(".*\"layers\":.*"));\r
-            assertTrue(content.matches(".*\"sld\":.*"));\r
-            assertTrue(content.matches(".*\"geoserver\":.*"));\r
-        }\r
-    }\r
-\r
-    public static final UUID uuidCyprusDivisionsVocabulary = UUID.fromString("2119f610-1f93-4d87-af28-40aeefaca100");\r
-    private final Map<String, NamedArea> divisions = new HashMap<String, NamedArea>();\r
-\r
-    private boolean makeCyprusAreas() throws IOException {\r
-        //divisions\r
-\r
-\r
-        NamedAreaType areaType = NamedAreaType.NATURAL_AREA();\r
-        NamedAreaLevel areaLevel = NamedAreaLevel.NewInstance("Cyprus Division", "Cyprus Division", null);\r
-\r
-        termService.saveOrUpdate(areaLevel);\r
-\r
-        TermVocabulary<NamedArea> areaVocabulary = TermVocabulary.NewInstance(TermType.NamedArea, "Cyprus devisions", "Cyprus divisions", null, null);\r
-        areaVocabulary.setUuid(uuidCyprusDivisionsVocabulary);\r
-\r
-\r
-        for(int i = 1; i <= 8; i++){\r
-            UUID divisionUuid = getNamedAreaUuid(String.valueOf(i));\r
-            NamedArea division = this.newNamedArea(\r
-                    divisionUuid,\r
-                    "Division " + i,\r
-                    "Cyprus: Division " + i,\r
-                    String.valueOf(i), // id in vocab\r
-                    areaType,\r
-                    areaLevel,\r
-                    areaVocabulary);\r
-            divisions.put(String.valueOf(i), division);\r
-        }\r
-\r
-        vocabService.saveOrUpdate(areaVocabulary);\r
-        commitAndStartNewTransaction(null);\r
-\r
-\r
-        // import and map shapefile attributes from csv\r
-        InputStream is = getClass().getClassLoader().getResourceAsStream("eu/etaxonomy/cdm/ext/geo/cyprusdivs.csv");\r
-        List<String> idSearchFields = new ArrayList<String>();\r
-        idSearchFields.add("bdcode");\r
-        String wmsLayerName = "cyprusdivs";\r
-        editGeoService.mapShapeFileToNamedAreas(new InputStreamReader(is), idSearchFields, wmsLayerName, uuidCyprusDivisionsVocabulary, null);\r
-\r
-        divisions.clear();\r
-        Set<DefinedTermBase> terms = vocabService.load(uuidCyprusDivisionsVocabulary).getTerms();\r
-        for(DefinedTermBase dtb : terms){\r
-            divisions.put(dtb.getIdInVocabulary(), (NamedArea) dtb);\r
-        }\r
-\r
-\r
-//             indigenousStatus = (PresenceTerm)getTermService().find(CyprusTransformer.indigenousUuid);\r
-//             casualStatus = (PresenceTerm)getTermService().find(CyprusTransformer.casualUuid);\r
-//             nonInvasiveStatus = (PresenceTerm)getTermService().find(CyprusTransformer.nonInvasiveUuid);\r
-//             invasiveStatus = (PresenceTerm)getTermService().find(CyprusTransformer.invasiveUuid);\r
-//             questionableStatus = (PresenceTerm)getTermService().find(CyprusTransformer.questionableUuid);\r
-\r
-        return true;\r
-\r
-\r
-    }\r
-\r
-    public static final UUID uuidDivision1 = UUID.fromString("ab17eee9-1abb-4ce9-a9a2-563f840cdbfc");\r
-    public static final UUID uuidDivision2 = UUID.fromString("c3606165-efb7-4224-a168-63e009eb4aa5");\r
-    public static final UUID uuidDivision3 = UUID.fromString("750d4e07-e34b-491f-a7b7-09723afdc960");\r
-    public static final UUID uuidDivision4 = UUID.fromString("8a858922-e8e5-4791-ad53-906e50633ec7");\r
-    public static final UUID uuidDivision5 = UUID.fromString("16057133-d541-4ebd-81d4-cb92265ec54c");\r
-    public static final UUID uuidDivision6 = UUID.fromString("fbf21230-4a42-4f4c-9af8-5da52123c264");\r
-    public static final UUID uuidDivision7 = UUID.fromString("d31dd96a-36ea-4428-871c-d8552a9565ca");\r
-    public static final UUID uuidDivision8 = UUID.fromString("236ea447-c3ab-486d-9e06-cc5907861acc");\r
-\r
-\r
-    public UUID getNamedAreaUuid(String key) {\r
-        if (StringUtils.isBlank(key)){return null;\r
-        }else if (key.equalsIgnoreCase("1")){return uuidDivision1;\r
-        }else if (key.equalsIgnoreCase("2")){return uuidDivision2;\r
-        }else if (key.equalsIgnoreCase("3")){return uuidDivision3;\r
-        }else if (key.equalsIgnoreCase("4")){return uuidDivision4;\r
-        }else if (key.equalsIgnoreCase("5")){return uuidDivision5;\r
-        }else if (key.equalsIgnoreCase("6")){return uuidDivision6;\r
-        }else if (key.equalsIgnoreCase("7")){return uuidDivision7;\r
-        }else if (key.equalsIgnoreCase("8")){return uuidDivision8;\r
-        }else{\r
-            return null;\r
-        }\r
-    }\r
-\r
-    protected NamedArea newNamedArea(UUID uuid, String label, String text, String IdInVocabulary, NamedAreaType areaType, NamedAreaLevel level, TermVocabulary<NamedArea> voc){\r
-        NamedArea namedArea = NamedArea.NewInstance(text, label, null);\r
-        voc.addTerm(namedArea);\r
-        namedArea.setType(areaType);\r
-        namedArea.setLevel(level);\r
-        namedArea.setUuid(uuid);\r
-        namedArea.setIdInVocabulary(IdInVocabulary);\r
-        return namedArea;\r
-    }\r
-\r
-    @Test\r
-    public void testGetWebServiceUrlBangka() throws ClientProtocolException, IOException, URISyntaxException {\r
-        NamedArea areaBangka = NamedArea.NewInstance("Bangka", "Bangka", null);\r
-        TermVocabulary<NamedArea> voc = TermVocabulary.NewInstance(TermType.NamedArea, "test Voc", "test voc", null, null);\r
-        voc.addTerm(areaBangka);\r
-\r
-        GeoServiceArea geoServiceArea = new GeoServiceArea();\r
-        String geoServiceLayer="vmap0_as_bnd_political_boundary_a";\r
-        String layerFieldName ="nam";\r
-        String areaValue = "PULAU BANGKA#SUMATERA SELATAN";\r
-        geoServiceArea.add(geoServiceLayer, layerFieldName, areaValue);\r
-        geoServiceArea.add(geoServiceLayer, layerFieldName, "BALI");\r
-\r
-        mapping.set(areaBangka, geoServiceArea);\r
-        Set<Distribution> distributions = new HashSet<Distribution>();\r
-        distributions.add(Distribution.NewInstance(areaBangka, PresenceAbsenceTerm.PRESENT()));\r
-\r
-        Map<PresenceAbsenceTerm, Color> presenceAbsenceColorMap = new HashMap<PresenceAbsenceTerm, Color>();\r
-        presenceAbsenceColorMap.put(PresenceAbsenceTerm.PRESENT(), Color.BLUE);\r
-\r
-        presenceAbsenceColorMap = null;\r
-        List<Language> languages = new ArrayList<Language>();\r
-\r
-        boolean subAreaPreference = false;\r
-        boolean statusOrderPreference = false;\r
-        String result = EditGeoServiceUtilities.getDistributionServiceRequestParameterString(distributions,\r
-                mapping,\r
-                null, null, languages );\r
-        //TODO Set semantics is not determined\r
-        //String expected = "http://www.test.de/webservice?l=tdwg3&ad=tdwg3:a:GER|b:OKL|c:BGM|b:SPA|d:FRA&as=a:005500|b:00FF00|c:FFFFFF|d:001100&bbox=-20,40,40,40&ms=400x300";\r
-\r
-        logger.debug(result);\r
-        assertTrue(result.matches(".*ad=vmap0_as_bnd_political_boundary_a%3Anam:.*"));\r
-        assertTrue(result.matches(".*(PULAU\\+BANGKA%23SUMATERA\\+SELATAN).*") );\r
-        assertTrue(result.matches(".*(BALI).*") );\r
-\r
-        // request map image from webservice\r
-        subTestWithEditMapService(result);\r
-    }\r
-\r
-    @Test\r
-    public void testGetCondensedDistribution() {\r
-\r
-        NamedArea germany = NamedArea.NewInstance("Germany", "", "GER");\r
-        NamedArea berlin = NamedArea.NewInstance("Berlin", "", "GER(B)");\r
-        berlin.setPartOf(germany);\r
-        NamedArea bawue = NamedArea.NewInstance("Baden Württemberg", "", "GER(BW)");\r
-        bawue.setPartOf(germany);\r
-        NamedArea france = NamedArea.NewInstance("France", "", "FR");\r
-        NamedArea ileDeFrance = NamedArea.NewInstance("Ile-de-France", "", "FR(J)");\r
-        ileDeFrance.setPartOf(france);\r
-        NamedArea italy = NamedArea.NewInstance("Italy", "", "IT");\r
-        NamedArea spain = NamedArea.NewInstance("Spain", "", "S");\r
-\r
-        Set<Distribution> distributions = new HashSet<Distribution>();\r
-        distributions.add(Distribution.NewInstance(germany, PresenceAbsenceTerm.NATIVE()));\r
-        distributions.add(Distribution.NewInstance(bawue, PresenceAbsenceTerm.NATIVE()));\r
-        distributions.add(Distribution.NewInstance(berlin, PresenceAbsenceTerm.NATIVE()));\r
-        distributions.add(Distribution.NewInstance(italy, PresenceAbsenceTerm.PRESENT_DOUBTFULLY()));\r
-\r
-        distributions.add(Distribution.NewInstance(france, PresenceAbsenceTerm.INTRODUCED_ADVENTITIOUS()));\r
-        distributions.add(Distribution.NewInstance(ileDeFrance, PresenceAbsenceTerm.CULTIVATED()));\r
-        distributions.add(Distribution.NewInstance(spain, PresenceAbsenceTerm.NATURALISED()));\r
-\r
-        List<Language> languages = new ArrayList<Language>();\r
-\r
-        CondensedDistribution condensedDistribution = EditGeoServiceUtilities.getCondensedDistribution(\r
-                distributions,\r
-                CondensedDistributionRecipe.EuroPlusMed,\r
-                languages);\r
-\r
-        Assert.assertEquals("GER(B BW) ?IT [aFR cFR(J) nS]", condensedDistribution.toString());\r
-    }\r
-\r
-\r
-    /* (non-Javadoc)\r
-     * @see eu.etaxonomy.cdm.test.integration.CdmIntegrationTest#createTestData()\r
-     */\r
-    @Override\r
-    public void createTestDataSet() throws FileNotFoundException {\r
-        // TODO Auto-generated method stub\r
-\r
-    }\r
-\r
-\r
+// $Id$
+/**
+* Copyright (C) 2007 EDIT
+* European Distributed Institute of Taxonomy
+* http://www.e-taxonomy.eu
+*
+* The contents of this file are subject to the Mozilla Public License Version 1.1
+* See LICENSE.TXT at the top of this package for the full license terms.
+*/
+
+package eu.etaxonomy.cdm.ext.geo;
+
+import static org.junit.Assert.assertTrue;
+
+import java.awt.Color;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.net.HttpURLConnection;
+import java.net.MalformedURLException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.UUID;
+
+import org.apache.commons.lang.StringUtils;
+import org.apache.http.client.ClientProtocolException;
+import org.apache.log4j.Logger;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.unitils.dbunit.annotation.DataSet;
+import org.unitils.spring.annotation.SpringBeanByType;
+
+import eu.etaxonomy.cdm.api.service.ITaxonService;
+import eu.etaxonomy.cdm.api.service.ITermService;
+import eu.etaxonomy.cdm.api.service.IVocabularyService;
+import eu.etaxonomy.cdm.api.service.dto.CondensedDistribution;
+import eu.etaxonomy.cdm.api.utility.DescriptionUtility;
+import eu.etaxonomy.cdm.common.StreamUtils;
+import eu.etaxonomy.cdm.common.UriUtils;
+import eu.etaxonomy.cdm.model.common.CdmBase;
+import eu.etaxonomy.cdm.model.common.DefinedTermBase;
+import eu.etaxonomy.cdm.model.common.Language;
+import eu.etaxonomy.cdm.model.common.MarkerType;
+import eu.etaxonomy.cdm.model.common.TermType;
+import eu.etaxonomy.cdm.model.common.TermVocabulary;
+import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
+import eu.etaxonomy.cdm.model.description.Distribution;
+import eu.etaxonomy.cdm.model.description.Feature;
+import eu.etaxonomy.cdm.model.description.PresenceAbsenceTerm;
+import eu.etaxonomy.cdm.model.description.TaxonDescription;
+import eu.etaxonomy.cdm.model.location.Country;
+import eu.etaxonomy.cdm.model.location.NamedArea;
+import eu.etaxonomy.cdm.model.location.NamedAreaLevel;
+import eu.etaxonomy.cdm.model.location.NamedAreaType;
+import eu.etaxonomy.cdm.model.taxon.Taxon;
+import eu.etaxonomy.cdm.persistence.dao.common.IDefinedTermDao;
+import eu.etaxonomy.cdm.test.integration.CdmTransactionalIntegrationTest;
+
+/**
+ * @author a.mueller
+ * @created 08.10.2008
+ */
+public class EditGeoServiceTest extends CdmTransactionalIntegrationTest {
+    private static final Logger logger = Logger.getLogger(EditGeoServiceTest.class);
+
+    private static final String EDIT_MAPSERVICE_URI_STING = "http://edit.africamuseum.be/edit_wp5/v1.2/rest_gen.php";
+    private static URI editMapServiceUri;
+
+    @SpringBeanByType
+    private IDefinedTermDao termDao;
+
+    @SpringBeanByType
+    private ITermService termService;
+
+    @SpringBeanByType
+    private IVocabularyService vocabService;
+
+    @SpringBeanByType
+    private GeoServiceAreaAnnotatedMapping mapping;
+
+    @SpringBeanByType
+    private IEditGeoService editGeoService;
+
+    @SpringBeanByType
+    private ITaxonService taxonService ;
+
+
+    /**
+     * @throws java.lang.Exception
+     */
+    @Before
+    public void setUp() throws Exception {
+        EditGeoServiceUtilities.setTermDao(termDao);
+        System.setProperty("ONLY-A-TEST", "TRUE"); // allows EditGeoServiceUtilities to skip some line of code
+        editMapServiceUri = new URI(EDIT_MAPSERVICE_URI_STING);
+    }
+
+
+//******************************************** TESTS**************
+
+    @Test
+    public void testGetWebServiceUrlCountry() throws MalformedURLException, IOException {
+        Set<Distribution> distributions = new HashSet<Distribution>();
+        Country germany = termService.findByIdInVocabulary("DEU", Country.uuidCountryVocabulary, Country.class);
+//        germany = (Country)termService.find(665);
+//        germany = (Country)termService.find(UUID.fromString("cbe7ce69-2952-4309-85dd-0d7d4a4830a1"));
+
+//        germany = Country.GERMANY();
+
+        distributions.add(Distribution.NewInstance(germany, PresenceAbsenceTerm.PRESENT()));
+        distributions.add(Distribution.NewInstance(termService.findByIdInVocabulary("DE", Country.uuidCountryVocabulary, Country.class), PresenceAbsenceTerm.INTRODUCED()));
+        Map<PresenceAbsenceTerm, Color> presenceAbsenceColorMap = new HashMap<PresenceAbsenceTerm, Color>();
+        presenceAbsenceColorMap.put(PresenceAbsenceTerm.PRESENT(), Color.BLUE);
+        presenceAbsenceColorMap.put(PresenceAbsenceTerm.INTRODUCED(), Color.BLACK);
+        List<Language> languages = new ArrayList<Language>();
+
+        boolean subAreaPreference = false;
+        boolean statusOrderPreference = false;
+
+
+        Collection<Distribution> filteredDistributions = DescriptionUtility.filterDistributions(
+                distributions, null, true, statusOrderPreference, subAreaPreference);
+
+        String result = EditGeoServiceUtilities.getDistributionServiceRequestParameterString(filteredDistributions,
+                mapping, null, null, languages );
+        logger.warn(result);
+        Assert.assertTrue("WebServiceUrl must contain country part for Germany", result.matches(".*ad=country_earth(%3A|:)gmi_cntry:.:DEU.*"));
+    }
+
+    @Test
+    public void testGetWebServiceUrlTdwg() throws MalformedURLException, IOException {
+        //String webServiceUrl = "http://www.test.de/webservice";
+        Set<Distribution> distributions = new HashSet<Distribution>();
+        distributions.add(Distribution.NewInstance(termService.getAreaByTdwgAbbreviation("SPA"), PresenceAbsenceTerm.PRESENT()));
+        distributions.add(Distribution.NewInstance(termService.getAreaByTdwgAbbreviation("GER"), PresenceAbsenceTerm.INTRODUCED()));
+        distributions.add(Distribution.NewInstance(termService.getAreaByTdwgAbbreviation("14"), PresenceAbsenceTerm.CULTIVATED()));
+        distributions.add(Distribution.NewInstance(termService.getAreaByTdwgAbbreviation("BGM"), PresenceAbsenceTerm.ABSENT()));
+        distributions.add(Distribution.NewInstance(termService.getAreaByTdwgAbbreviation("FRA"), PresenceAbsenceTerm.ABSENT()));
+        distributions.add(Distribution.NewInstance(termService.getAreaByTdwgAbbreviation("IND-AP"), PresenceAbsenceTerm.PRESENT()));
+
+        Map<PresenceAbsenceTerm, Color> presenceAbsenceColorMap = new HashMap<PresenceAbsenceTerm, Color>();
+        presenceAbsenceColorMap.put(PresenceAbsenceTerm.PRESENT(), Color.BLUE);
+        presenceAbsenceColorMap.put(PresenceAbsenceTerm.INTRODUCED(), Color.BLACK);
+        presenceAbsenceColorMap.put(PresenceAbsenceTerm.CULTIVATED(), Color.YELLOW);
+        presenceAbsenceColorMap.put(PresenceAbsenceTerm.ABSENT(), Color.DARK_GRAY);
+        String backLayer ="";
+        presenceAbsenceColorMap = null;
+        String bbox="-20,0,120,70";
+        List<Language> languages = new ArrayList<Language>();
+
+        boolean subAreaPreference = false;
+        boolean statusOrderPreference = false;
+        String result = EditGeoServiceUtilities.getDistributionServiceRequestParameterString(
+                distributions,
+                mapping,
+                null, // presenceAbsenceTermColors
+                null, // projectToLayer
+                languages );
+        //TODO Set semantics is not determined
+        //String expected = "http://www.test.de/webservice?l=tdwg3&ad=tdwg3:a:GER|b:OKL|c:BGM|b:SPA|d:FRA&as=a:005500|b:00FF00|c:FFFFFF|d:001100&bbox=-20,40,40,40&ms=400x300";
+        logger.debug(result);
+        assertTrue(result.matches(".*ad=tdwg[1-4].*"));
+        assertTrue(result.matches(".*tdwg2:[a-d]:14[\\|&].*") );
+        assertTrue(result.matches(".*[a-d]:FRA,BGM[\\|&].*") || result.matches(".*[a-d]:BGM,FRA[\\|&].*") );
+        assertTrue(result.matches(".*[a-d]:GER[\\|&].*") );
+        assertTrue(result.matches(".*[a-d]:SPA[\\|&].*") );
+        assertTrue(result.matches(".*tdwg4:[a-d]:INDAP[\\|&].*") );
+        //assertTrue(result.matches("0000ff"));
+        //TODO continue
+
+        // request map image from webservice
+        subTestWithEditMapService(result);
+    }
+
+    @Test
+    public void testGetWebServiceUrlCyprus() throws ClientProtocolException, IOException, URISyntaxException {
+        makeCyprusAreas();
+        Set<Distribution> distributions = new HashSet<Distribution>();
+        distributions.add(Distribution.NewInstance(divisions.get("1"), PresenceAbsenceTerm.PRESENT()));
+        distributions.add(Distribution.NewInstance(divisions.get("2"), PresenceAbsenceTerm.INTRODUCED()));
+        distributions.add(Distribution.NewInstance(divisions.get("3"), PresenceAbsenceTerm.CULTIVATED()));
+        distributions.add(Distribution.NewInstance(divisions.get("4"), PresenceAbsenceTerm.ABSENT()));
+        distributions.add(Distribution.NewInstance(divisions.get("5"), PresenceAbsenceTerm.ABSENT()));
+        distributions.add(Distribution.NewInstance(divisions.get("6"), PresenceAbsenceTerm.PRESENT()));
+
+        Map<PresenceAbsenceTerm, Color> presenceAbsenceColorMap = new HashMap<PresenceAbsenceTerm, Color>();
+        presenceAbsenceColorMap.put(PresenceAbsenceTerm.PRESENT(), Color.BLUE);
+        presenceAbsenceColorMap.put(PresenceAbsenceTerm.INTRODUCED(), Color.BLACK);
+        presenceAbsenceColorMap.put(PresenceAbsenceTerm.CULTIVATED(), Color.YELLOW);
+        presenceAbsenceColorMap.put(PresenceAbsenceTerm.ABSENT(), Color.DARK_GRAY);
+        String backLayer ="";
+        presenceAbsenceColorMap = null;
+        String bbox="-20,0,120,70";
+        List<Language> languages = new ArrayList<Language>();
+
+        boolean subAreaPreference = false;
+        boolean statusOrderPreference = false;
+        String result = EditGeoServiceUtilities.getDistributionServiceRequestParameterString(
+                distributions,
+                mapping,
+                null, null, languages );
+        //TODO Set semantics is not determined
+        //String expected = "http://www.test.de/webservice?l=tdwg3&ad=tdwg3:a:GER|b:OKL|c:BGM|b:SPA|d:FRA&as=a:005500|b:00FF00|c:FFFFFF|d:001100&bbox=-20,40,40,40&ms=400x300";
+        assertTrue(result.matches(".*ad=cyprusdivs%3Abdcode:.*"));
+        assertTrue(result.matches(".*[a-d]:5,4[\\|&].*") || result.matches(".*[a-d]:4,5[\\|&].*") );
+        assertTrue(result.matches(".*[a-d]:1,6[\\|&].*") || result.matches(".*[a-d]:6,1[\\|&].*") );
+        assertTrue(result.matches(".*[a-d]:2[\\|&].*") );
+        assertTrue(result.matches(".*[a-d]:3[\\|&].*") );
+
+        // request map image from webservice
+        subTestWithEditMapService(result);
+    }
+
+    private void subTestWithEditMapService(String queryString)throws MalformedURLException, IOException {
+        if(UriUtils.isServiceAvailable(editMapServiceUri)){
+            URL requestUrl = new URL(editMapServiceUri.toString() + "?img=false&bbox=-180,-90,180,90&ms=1000&" + queryString);
+            logger.debug("editMapServiceUri: " + requestUrl);
+            HttpURLConnection connection = (HttpURLConnection) requestUrl.openConnection();
+            connection.connect();
+//            connection.setReadTimeout(10000);  //timeout after 10 sec, does not seem to work
+            assertTrue(connection.getResponseCode() == 200);
+            InputStream contentStream = connection.getInputStream();
+            String content = StreamUtils.readToString(contentStream);
+            logger.debug("EditMapService response body:\n" + content);
+            assertTrue(content.startsWith("[{"));
+            assertTrue(content.endsWith("}]"));
+            assertTrue(content.matches(".*\"bbox\":.*"));
+            assertTrue(content.matches(".*\"legend\":.*"));
+            assertTrue(content.matches(".*\"layers\":.*"));
+            assertTrue(content.matches(".*\"sld\":.*"));
+            assertTrue(content.matches(".*\"geoserver\":.*"));
+        }
+    }
+
+    public static final UUID uuidCyprusDivisionsVocabulary = UUID.fromString("2119f610-1f93-4d87-af28-40aeefaca100");
+    private final Map<String, NamedArea> divisions = new HashMap<String, NamedArea>();
+
+    private boolean makeCyprusAreas() throws IOException {
+        //divisions
+
+
+        NamedAreaType areaType = NamedAreaType.NATURAL_AREA();
+        NamedAreaLevel areaLevel = NamedAreaLevel.NewInstance("Cyprus Division", "Cyprus Division", null);
+
+        termService.saveOrUpdate(areaLevel);
+
+        TermVocabulary<NamedArea> areaVocabulary = TermVocabulary.NewInstance(TermType.NamedArea, "Cyprus devisions", "Cyprus divisions", null, null);
+        areaVocabulary.setUuid(uuidCyprusDivisionsVocabulary);
+
+
+        for(int i = 1; i <= 8; i++){
+            UUID divisionUuid = getNamedAreaUuid(String.valueOf(i));
+            NamedArea division = this.newNamedArea(
+                    divisionUuid,
+                    "Division " + i,
+                    "Cyprus: Division " + i,
+                    String.valueOf(i), // id in vocab
+                    areaType,
+                    areaLevel,
+                    areaVocabulary);
+            divisions.put(String.valueOf(i), division);
+        }
+
+        vocabService.saveOrUpdate(areaVocabulary);
+        commitAndStartNewTransaction(null);
+
+
+        // import and map shapefile attributes from csv
+        InputStream is = getClass().getClassLoader().getResourceAsStream("eu/etaxonomy/cdm/ext/geo/cyprusdivs.csv");
+        List<String> idSearchFields = new ArrayList<String>();
+        idSearchFields.add("bdcode");
+        String wmsLayerName = "cyprusdivs";
+        editGeoService.mapShapeFileToNamedAreas(new InputStreamReader(is), idSearchFields, wmsLayerName, uuidCyprusDivisionsVocabulary, null);
+
+        divisions.clear();
+        Set<DefinedTermBase> terms = vocabService.load(uuidCyprusDivisionsVocabulary).getTerms();
+        for(DefinedTermBase dtb : terms){
+            divisions.put(dtb.getIdInVocabulary(), (NamedArea) dtb);
+        }
+
+
+//             indigenousStatus = (PresenceTerm)getTermService().find(CyprusTransformer.indigenousUuid);
+//             casualStatus = (PresenceTerm)getTermService().find(CyprusTransformer.casualUuid);
+//             nonInvasiveStatus = (PresenceTerm)getTermService().find(CyprusTransformer.nonInvasiveUuid);
+//             invasiveStatus = (PresenceTerm)getTermService().find(CyprusTransformer.invasiveUuid);
+//             questionableStatus = (PresenceTerm)getTermService().find(CyprusTransformer.questionableUuid);
+
+        return true;
+
+
+    }
+
+    public static final UUID uuidDivision1 = UUID.fromString("ab17eee9-1abb-4ce9-a9a2-563f840cdbfc");
+    public static final UUID uuidDivision2 = UUID.fromString("c3606165-efb7-4224-a168-63e009eb4aa5");
+    public static final UUID uuidDivision3 = UUID.fromString("750d4e07-e34b-491f-a7b7-09723afdc960");
+    public static final UUID uuidDivision4 = UUID.fromString("8a858922-e8e5-4791-ad53-906e50633ec7");
+    public static final UUID uuidDivision5 = UUID.fromString("16057133-d541-4ebd-81d4-cb92265ec54c");
+    public static final UUID uuidDivision6 = UUID.fromString("fbf21230-4a42-4f4c-9af8-5da52123c264");
+    public static final UUID uuidDivision7 = UUID.fromString("d31dd96a-36ea-4428-871c-d8552a9565ca");
+    public static final UUID uuidDivision8 = UUID.fromString("236ea447-c3ab-486d-9e06-cc5907861acc");
+
+
+    public UUID getNamedAreaUuid(String key) {
+        if (StringUtils.isBlank(key)){return null;
+        }else if (key.equalsIgnoreCase("1")){return uuidDivision1;
+        }else if (key.equalsIgnoreCase("2")){return uuidDivision2;
+        }else if (key.equalsIgnoreCase("3")){return uuidDivision3;
+        }else if (key.equalsIgnoreCase("4")){return uuidDivision4;
+        }else if (key.equalsIgnoreCase("5")){return uuidDivision5;
+        }else if (key.equalsIgnoreCase("6")){return uuidDivision6;
+        }else if (key.equalsIgnoreCase("7")){return uuidDivision7;
+        }else if (key.equalsIgnoreCase("8")){return uuidDivision8;
+        }else{
+            return null;
+        }
+    }
+
+    protected NamedArea newNamedArea(UUID uuid, String label, String text, String IdInVocabulary, NamedAreaType areaType, NamedAreaLevel level, TermVocabulary<NamedArea> voc){
+        NamedArea namedArea = NamedArea.NewInstance(text, label, null);
+        voc.addTerm(namedArea);
+        namedArea.setType(areaType);
+        namedArea.setLevel(level);
+        namedArea.setUuid(uuid);
+        namedArea.setIdInVocabulary(IdInVocabulary);
+        return namedArea;
+    }
+
+    @Test
+    public void testGetWebServiceUrlBangka() throws ClientProtocolException, IOException, URISyntaxException {
+        NamedArea areaBangka = NamedArea.NewInstance("Bangka", "Bangka", null);
+        TermVocabulary<NamedArea> voc = TermVocabulary.NewInstance(TermType.NamedArea, "test Voc", "test voc", null, null);
+        voc.addTerm(areaBangka);
+
+        GeoServiceArea geoServiceArea = new GeoServiceArea();
+        String geoServiceLayer="vmap0_as_bnd_political_boundary_a";
+        String layerFieldName ="nam";
+        String areaValue = "PULAU BANGKA#SUMATERA SELATAN";
+        geoServiceArea.add(geoServiceLayer, layerFieldName, areaValue);
+        geoServiceArea.add(geoServiceLayer, layerFieldName, "BALI");
+
+        mapping.set(areaBangka, geoServiceArea);
+        Set<Distribution> distributions = new HashSet<Distribution>();
+        distributions.add(Distribution.NewInstance(areaBangka, PresenceAbsenceTerm.PRESENT()));
+
+        Map<PresenceAbsenceTerm, Color> presenceAbsenceColorMap = new HashMap<PresenceAbsenceTerm, Color>();
+        presenceAbsenceColorMap.put(PresenceAbsenceTerm.PRESENT(), Color.BLUE);
+
+        presenceAbsenceColorMap = null;
+        List<Language> languages = new ArrayList<Language>();
+
+        boolean subAreaPreference = false;
+        boolean statusOrderPreference = false;
+        String result = EditGeoServiceUtilities.getDistributionServiceRequestParameterString(distributions,
+                mapping,
+                null, null, languages );
+        //TODO Set semantics is not determined
+        //String expected = "http://www.test.de/webservice?l=tdwg3&ad=tdwg3:a:GER|b:OKL|c:BGM|b:SPA|d:FRA&as=a:005500|b:00FF00|c:FFFFFF|d:001100&bbox=-20,40,40,40&ms=400x300";
+
+        logger.debug(result);
+        assertTrue(result.matches(".*ad=vmap0_as_bnd_political_boundary_a%3Anam:.*"));
+        assertTrue(result.matches(".*(PULAU\\+BANGKA%23SUMATERA\\+SELATAN).*") );
+        assertTrue(result.matches(".*(BALI).*") );
+
+        // request map image from webservice
+        subTestWithEditMapService(result);
+    }
+
+    @Test
+    public void testGetCondensedDistribution() {
+
+        NamedArea germany = NamedArea.NewInstance("Germany", "", "GER");
+        NamedArea berlin = NamedArea.NewInstance("Berlin", "", "GER(B)");
+        berlin.setPartOf(germany);
+        NamedArea bawue = NamedArea.NewInstance("Baden Württemberg", "", "GER(BW)");
+        bawue.setPartOf(germany);
+        NamedArea france = NamedArea.NewInstance("France", "", "FR");
+        NamedArea ileDeFrance = NamedArea.NewInstance("Ile-de-France", "", "FR(J)");
+        ileDeFrance.setPartOf(france);
+        NamedArea italy = NamedArea.NewInstance("Italy", "", "IT");
+        NamedArea spain = NamedArea.NewInstance("Spain", "", "S");
+
+        Set<Distribution> distributions = new HashSet<Distribution>();
+        distributions.add(Distribution.NewInstance(germany, PresenceAbsenceTerm.NATIVE()));
+        distributions.add(Distribution.NewInstance(bawue, PresenceAbsenceTerm.NATIVE()));
+        distributions.add(Distribution.NewInstance(berlin, PresenceAbsenceTerm.NATIVE()));
+        distributions.add(Distribution.NewInstance(italy, PresenceAbsenceTerm.PRESENT_DOUBTFULLY()));
+
+        distributions.add(Distribution.NewInstance(france, PresenceAbsenceTerm.INTRODUCED_ADVENTITIOUS()));
+        distributions.add(Distribution.NewInstance(ileDeFrance, PresenceAbsenceTerm.CULTIVATED()));
+        distributions.add(Distribution.NewInstance(spain, PresenceAbsenceTerm.NATURALISED()));
+
+        List<Language> languages = new ArrayList<Language>();
+
+        CondensedDistribution condensedDistribution = EditGeoServiceUtilities.getCondensedDistribution(
+                distributions,
+                CondensedDistributionRecipe.EuroPlusMed,
+                languages);
+
+        Assert.assertEquals("GER(B BW) ?IT [aFR cFR(J) nS]", condensedDistribution.toString());
+    }
+
+    @SuppressWarnings("deprecation")
+//    @Test
+    @DataSet( value="EditGeoServiceTest.getDistributionServiceRequestParameterString.xml")
+//    @DataSets({
+//        @DataSet(loadStrategy=CleanSweepInsertLoadStrategy.class, value="../../database/ClearDB_with_Terms_DataSet.xml"),
+//        @DataSet("../../database/TermsDataSet-with_auditing_info.xml"),
+//        @DataSet( value="EditGeoServiceTest.getDistributionServiceRequestParameterString.xml")
+//    })
+    public void getDistributionServiceRequestParameterString(){
+        boolean subAreaPreference = false;
+        boolean statusOrderPreference = false;
+        Set<MarkerType> hideMarkedAreas = null;
+        Map<PresenceAbsenceTerm, Color> presenceAbsenceTermColors = null;
+        List<Language> langs = null;
+
+        List<TaxonDescription> taxonDescriptions = new ArrayList<TaxonDescription>();
+        TaxonDescription description1 = TaxonDescription.NewInstance();
+        taxonDescriptions.add(description1);
+        Distribution distribution1 = Distribution.NewInstance(Country.GERMANY(), null);
+        description1.addElement(distribution1);
+        Distribution distribution2 = Distribution.NewInstance(Country.FRANCEFRENCHREPUBLIC(), null);
+        distribution2.setFeature(Feature.COMMON_NAME());
+        description1.addElement(distribution2);
+
+        Taxon taxon = (Taxon)taxonService.find(UUID.fromString("7598f5d4-1cf2-4269-ae99-2adb79ae167c"));
+        TaxonDescription taxDesc = taxon.getDescriptions().iterator().next();
+        for (DescriptionElementBase deb : taxDesc.getElements()){
+            Distribution distribution = CdmBase.deproxy(deb, Distribution.class);
+            NamedArea area = distribution.getArea();
+            System.out.println(area.getTitleCache());
+        }
+        taxonDescriptions.addAll(taxon.getDescriptions());
+
+        String distributions = editGeoService.getDistributionServiceRequestParameterString(taxonDescriptions,
+                subAreaPreference, statusOrderPreference, hideMarkedAreas, presenceAbsenceTermColors, langs);
+        System.out.println(distributions);
+        Assert.assertTrue("Distribution string should contain the non-persited distribution Germany", distributions.contains("DEU"));
+        Assert.assertFalse("Distribution string should contain France as it has a non-distribution feature", distributions.contains("FRA"));
+
+//        CHE,POL
+    }
+
+    @Override
+//    @Test
+    public void createTestDataSet() throws FileNotFoundException {
+
+        List<TaxonDescription> taxonDescriptions = new ArrayList<TaxonDescription>();
+        TaxonDescription description1 = TaxonDescription.NewInstance();
+        taxonDescriptions.add(description1);
+        Distribution distribution1 = Distribution.NewInstance(Country.POLANDPOLISHPEOPLESREPUBLIC(), null);
+        description1.addElement(distribution1);
+        Distribution distribution2 = Distribution.NewInstance(Country.SWITZERLANDSWISSCONFEDERATION(), null);
+//        distribution2.setFeature(Feature.COMMON_NAME());
+        description1.addElement(distribution2);
+        Taxon taxon = Taxon.NewInstance(null, null);
+        taxon.setTitleCache("Dummy taxon", true);
+        taxon.addDescription(description1);
+        taxon.setUuid(UUID.fromString("7598f5d4-1cf2-4269-ae99-2adb79ae167c"));
+
+        taxonService.save(taxon);
+
+
+        setComplete();
+        endTransaction();
+
+        writeDbUnitDataSetFile(new String[] {
+                "TAXONBASE",
+                "DESCRIPTIONBASE", "DESCRIPTIONELEMENTBASE",
+                "HIBERNATE_SEQUENCES" // IMPORTANT!!!
+                },
+                "getDistributionServiceRequestParameterString" );
+
+    }
+
+
 }
\ No newline at end of file
 }
\ No newline at end of file
diff --git a/cdmlib-ext/src/test/resources/eu/etaxonomy/cdm/ext/geo/EditGeoServiceTest.getDistributionServiceRequestParameterString.xml b/cdmlib-ext/src/test/resources/eu/etaxonomy/cdm/ext/geo/EditGeoServiceTest.getDistributionServiceRequestParameterString.xml
new file mode 100644 (file)
index 0000000..684ea7f
--- /dev/null
@@ -0,0 +1,17 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<dataset>
+  <TAXONBASE DTYPE="Taxon" ID="10" CREATED="2015-12-18 09:29:42.0" UUID="7598f5d4-1cf2-4269-ae99-2adb79ae167c" UPDATED="[null]" LSID_AUTHORITY="[null]" LSID_LSID="[null]" LSID_NAMESPACE="[null]" LSID_OBJECT="[null]" LSID_REVISION="[null]" PROTECTEDTITLECACHE="true" TITLECACHE="Dummy taxon" APPENDEDPHRASE="[null]" DOUBTFUL="false" PUBLISH="true" USENAMECACHE="false" EXCLUDED="false" TAXONSTATUSUNKNOWN="false" TAXONOMICCHILDRENCOUNT="0" UNPLACED="false" CREATEDBY_ID="[null]" UPDATEDBY_ID="[null]" NAME_ID="[null]" SEC_ID="[null]" TAXONOMICPARENTCACHE_ID="[null]"/>
+  <DESCRIPTIONBASE DTYPE="TaxonDescription" ID="10" CREATED="2015-12-18 09:29:42.0" UUID="9c362630-08ef-4e2f-95d8-57b1cebd1197" UPDATED="[null]" LSID_AUTHORITY="[null]" LSID_LSID="[null]" LSID_NAMESPACE="[null]" LSID_OBJECT="[null]" LSID_REVISION="[null]" PROTECTEDTITLECACHE="false" TITLECACHE="Taxon description for Dummy taxon" IMAGEGALLERY="false" CREATEDBY_ID="[null]" UPDATEDBY_ID="[null]" SPECIMEN_ID="[null]" TAXON_ID="10" TAXONNAME_ID="[null]"/>
+  <DESCRIPTIONELEMENTBASE DTYPE="Distribution" ID="10" CREATED="2015-12-18 09:29:42.0" UUID="43b69cdb-ef08-41b2-9f25-32dce86e260d" UPDATED="[null]" NAME="[null]" TIMEPERIOD_START="[null]" TIMEPERIOD_END="[null]" TIMEPERIOD_FREETEXT="[null]" ORDERRELEVANT="[null]" UNKNOWNDATA="[null]" CREATEDBY_ID="[null]" UPDATEDBY_ID="[null]" FEATURE_ID="986" INDESCRIPTION_ID="10" AREA_ID="572" LANGUAGE_ID="[null]" STATUS_ID="[null]" ASSOCIATEDSPECIMENOROBSERVATION_ID="[null]" UNIT_ID="[null]" TAXON2_ID="[null]" FORMAT_ID="[null]"/>
+  <DESCRIPTIONELEMENTBASE DTYPE="Distribution" ID="11" CREATED="2015-12-18 09:29:42.0" UUID="285562d2-0fd3-4e6e-a83c-c65bb2eb9085" UPDATED="[null]" NAME="[null]" TIMEPERIOD_START="[null]" TIMEPERIOD_END="[null]" TIMEPERIOD_FREETEXT="[null]" ORDERRELEVANT="[null]" UNKNOWNDATA="[null]" CREATEDBY_ID="[null]" UPDATEDBY_ID="[null]" FEATURE_ID="986" INDESCRIPTION_ID="10" AREA_ID="537" LANGUAGE_ID="[null]" STATUS_ID="[null]" ASSOCIATEDSPECIMENOROBSERVATION_ID="[null]" UNIT_ID="[null]" TAXON2_ID="[null]" FORMAT_ID="[null]"/>
+  <HIBERNATE_SEQUENCES SEQUENCE_NAME="CdmMetaData" NEXT_VAL="30"/>
+  <HIBERNATE_SEQUENCES SEQUENCE_NAME="DefinedTermBase" NEXT_VAL="2190"/>
+  <HIBERNATE_SEQUENCES SEQUENCE_NAME="DescriptionBase" NEXT_VAL="30"/>
+  <HIBERNATE_SEQUENCES SEQUENCE_NAME="DescriptionElementBase" NEXT_VAL="30"/>
+  <HIBERNATE_SEQUENCES SEQUENCE_NAME="GrantedAuthorityImpl" NEXT_VAL="40"/>
+  <HIBERNATE_SEQUENCES SEQUENCE_NAME="PermissionGroup" NEXT_VAL="30"/>
+  <HIBERNATE_SEQUENCES SEQUENCE_NAME="Representation" NEXT_VAL="2290"/>
+  <HIBERNATE_SEQUENCES SEQUENCE_NAME="TaxonBase" NEXT_VAL="30"/>
+  <HIBERNATE_SEQUENCES SEQUENCE_NAME="TermVocabulary" NEXT_VAL="70"/>
+  <HIBERNATE_SEQUENCES SEQUENCE_NAME="UserAccount" NEXT_VAL="30"/>
+</dataset>