+ /**\r
+ * @param statusColorJson for example: {@code {"n":"#ff0000","p":"#ffff00"}}\r
+ * @return\r
+ * @throws IOException\r
+ * @throws JsonParseException\r
+ * @throws JsonMappingException\r
+ */\r
+ public static Map<PresenceAbsenceTerm, Color> buildStatusColorMap(String statusColorJson, ITermService termService) throws IOException, JsonParseException,\r
+ JsonMappingException {\r
+\r
+ Map<PresenceAbsenceTerm, Color> presenceAbsenceTermColors = null;\r
+ if(StringUtils.isNotEmpty(statusColorJson)){\r
+\r
+ ObjectMapper mapper = new ObjectMapper();\r
+ // TODO cache the color maps to speed this up?\r
+\r
+ TypeFactory typeFactory = mapper.getTypeFactory();\r
+ MapType mapType = typeFactory.constructMapType(HashMap.class, String.class, String.class);\r
+\r
+ Map<String,String> statusColorMap = mapper.readValue(statusColorJson, mapType);\r
+ UUID presenceTermVocabUuid = PresenceAbsenceTerm.NATIVE().getVocabulary().getUuid();\r
+ presenceAbsenceTermColors = new HashMap<PresenceAbsenceTerm, Color>();\r
+ PresenceAbsenceTerm paTerm = null;\r
+ for(String statusId : statusColorMap.keySet()){\r
+ try {\r
+ Color color = Color.decode(statusColorMap.get(statusId));\r
+ paTerm = termService.findByIdInVocabulary(statusId, presenceTermVocabUuid, PresenceAbsenceTerm.class);\r
+ if(paTerm != null){\r
+ presenceAbsenceTermColors.put(paTerm, color);\r
+ }\r
+ } catch (NumberFormatException e){\r
+ logger.error("Cannot decode color", e);\r
+ }\r
+ }\r
+ }\r
+ 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