some bugfixes in CondensedDistribution composition code - #3907
[cdmlib.git] / cdmlib-ext / src / main / java / eu / etaxonomy / cdm / ext / geo / EditGeoServiceUtilities.java
index be4c5fce468bcfed6e52cb2f4ea9851a616f61d9..47d01471c75dee9c97190a9b1c980f1a9e2b9d73 100644 (file)
@@ -37,11 +37,10 @@ import org.codehaus.jackson.map.type.MapType;
 import org.codehaus.jackson.map.type.TypeFactory;\r
 \r
 import eu.etaxonomy.cdm.api.service.ITermService;\r
+import eu.etaxonomy.cdm.api.service.dto.CondensedDistribution;\r
 import eu.etaxonomy.cdm.api.utility.DescriptionUtility;\r
 import eu.etaxonomy.cdm.common.CdmUtils;\r
 import eu.etaxonomy.cdm.model.common.Language;\r
-import eu.etaxonomy.cdm.model.common.Marker;\r
-import eu.etaxonomy.cdm.model.common.MarkerType;\r
 import eu.etaxonomy.cdm.model.common.Representation;\r
 import eu.etaxonomy.cdm.model.common.TermVocabulary;\r
 import eu.etaxonomy.cdm.model.description.Distribution;\r
@@ -175,61 +174,45 @@ public class EditGeoServiceUtilities {
     static final String VALUE_SUPER_LIST_ENTRY_SEPARATOR = "||";\r
 \r
 \r
-\r
-    //preliminary implementation for TDWG areas\r
     /**\r
      * Returns the parameter String for the EDIT geo webservice to create a\r
-     * dsitribution map.\r
+     * distribution map.\r
      *\r
      * @param distributions\r
      *            A set of distributions that should be shown on the map\r
-     * @param subAreaPreference\r
-     *            enables the <b>Sub area preference rule</b> if set to true,\r
-     *            see {@link DescriptionUtility#filterDistributions(Collection,\r
-     *            boolean, boolean}\r
+     *            The {@link DescriptionUtility} class provides a method for\r
+     *            filtering a set of Distributions :\r
      *\r
-     * @param statusOrderPreference\r
-     *            enables the <b>Status order preference rule</b> if set to\r
-     *            true, see {@link\r
-     *            DescriptionUtility#filterDistributions(Collection, boolean,\r
-     *            boolean}\r
-     * @param hideMarkedAreas\r
-     *            distributions where the area has a {@link Marker} with one of\r
-     *            the specified {@link MarkerType}s will be skipped, see\r
-     *            {@link DescriptionUtility#filterDistributions(Collection, boolean, boolean, Set)}\r
+     *            {@code\r
+     *            Collection<Distribution> filteredDistributions =\r
+     *            DescriptionUtility.filterDistributions(distributions,\r
+     *            subAreaPreference, statusOrderPreference, hideMarkedAreas);\r
+     *            }\r
+     * @param mapping\r
+     *            Data regarding the mapping of NamedAreas to shape file\r
+     *            attribute tables\r
      * @param presenceAbsenceTermColors\r
      *            A map that defines the colors of PresenceAbsenceTerms. The\r
      *            PresenceAbsenceTerms are defined by their uuid. If a\r
      *            PresenceAbsenceTerm is not included in this map, it's default\r
      *            color is taken instead. If the map == null all terms are\r
      *            colored by their default color.\r
-     * @param width\r
-     *            The maps width\r
-     * @param height\r
-     *            The maps height\r
-     * @param bbox\r
-     *            The maps bounding box (e.g. "-180,-90,180,90" for the whole\r
-     *            world)\r
      * @param projectToLayer\r
      *            name of a layer which is representing a specific\r
      *            {@link NamedAreaLevel} Supply this parameter if you to project\r
      *            all other distribution area levels to this layer.\r
-     * @param layer\r
-     *            The layer that is responsible for background borders and\r
-     *            colors. Use the name for the layer. If null 'earth' is taken\r
-     *            as default.\r
+     * @param languages\r
+     *\r
      * @return the parameter string or an empty string if the\r
      *         <code>distributions</code> set was null or empty.\r
      */\r
     @Transient\r
     public static String getDistributionServiceRequestParameterString(\r
-            Set<Distribution> distributions,\r
-            boolean subAreaPreference,\r
-            boolean statusOrderPreference,\r
-            Set<MarkerType> hideMarkedAreas,\r
+            Collection<Distribution> filteredDistributions,\r
             IGeoServiceAreaMapping mapping,\r
             Map<PresenceAbsenceTerm,Color> presenceAbsenceTermColors,\r
-            String projectToLayer, List<Language> languages){\r
+            String projectToLayer,\r
+            List<Language> languages){\r
 \r
 \r
         /*\r
@@ -258,14 +241,12 @@ public class EditGeoServiceUtilities {
 \r
 \r
         //handle empty set\r
-        if(distributions == null || distributions.size() == 0){\r
+        if(filteredDistributions == null || filteredDistributions.size() == 0){\r
             return "";\r
         }\r
 \r
         presenceAbsenceTermColors = mergeMaps(getDefaultPresenceAbsenceTermBaseColors(), presenceAbsenceTermColors);\r
 \r
-        Collection<Distribution> filteredDistributions = DescriptionUtility.filterDistributions(distributions, subAreaPreference, statusOrderPreference, hideMarkedAreas);\r
-\r
         Map<String, Map<Integer, Set<Distribution>>> layerMap = new HashMap<String, Map<Integer, Set<Distribution>>>();\r
         List<PresenceAbsenceTerm> statusList = new ArrayList<PresenceAbsenceTerm>();\r
 \r
@@ -788,4 +769,30 @@ public class EditGeoServiceUtilities {
         return presenceAbsenceTermColors;\r
     }\r
 \r
+\r
+    /**\r
+     * @param filteredDistributions\r
+     * @param recipe\r
+     * @param hideMarkedAreas\r
+     * @param langs\r
+     * @return\r
+     */\r
+    public static CondensedDistribution getCondensedDistribution(Collection<Distribution> filteredDistributions,\r
+            CondensedDistributionRecipe recipe, List<Language> langs) {\r
+        ICondensedDistributionComposer composer;\r
+        if(recipe == null) {\r
+            throw new NullPointerException("parameter recipe must not be null");\r
+        }\r
+        try {\r
+            composer = recipe.newCondensedDistributionComposerInstance();\r
+        } catch (InstantiationException e) {\r
+            throw new RuntimeException(e);\r
+        } catch (IllegalAccessException e) {\r
+            throw new RuntimeException(e);\r
+        }\r
+        CondensedDistribution condensedDistribution = composer.createCondensedDistribution(\r
+                filteredDistributions,  langs);\r
+        return condensedDistribution;\r
+    }\r
+\r
 }\r