@Test public void getFixedDataUrl() { assertNull("Null metadata returns null id", LayerJSONFormatter.getFixedDataUrl(null)); assertNull("Empty metadata returns null id", LayerJSONFormatter.getFixedDataUrl("")); assertEquals("Non http-starting metadata returns as is", "testing", LayerJSONFormatter.getFixedDataUrl("testing")); assertNull("Url without querystring returns null id", LayerJSONFormatter.getFixedDataUrl("http: assertNull("Url without id|uuid returns null id", LayerJSONFormatter.getFixedDataUrl("http: assertEquals("Url with id returns id value simple", "key", LayerJSONFormatter.getFixedDataUrl("http: Map<String, String> expected = new HashMap<>(); expected.put("http: expected.put("http: expected.put("http: expected.put("http: for (String url : expected.keySet()) { assertEquals("Url with id returns id value", expected.get(url), LayerJSONFormatter.getFixedDataUrl(url)); } }
public static String getFixedDataUrl(String metadataId) { if(metadataId == null || metadataId.isEmpty()) { return null; } if(!metadataId.toLowerCase().startsWith("http")) { return metadataId; } try { Map<String, List<String>> params = IOHelper.parseQuerystring(metadataId); String idParam = params.keySet().stream() .filter(key -> "uuid".equalsIgnoreCase(key) || KEY_ID.equalsIgnoreCase(key)) .findFirst() .orElse(null); if (idParam == null) { return null; } List<String> values = params.getOrDefault(idParam, Collections.emptyList()); if (values.isEmpty()) { return null; } return values.get(0); } catch (Exception ignored) { LOG.ignore("Unexpected error parsing metadataid", ignored); } LOG.debug("Couldn't parse uuid from metadata url:", metadataId); return null; }
LayerJSONFormatter { public static String getFixedDataUrl(String metadataId) { if(metadataId == null || metadataId.isEmpty()) { return null; } if(!metadataId.toLowerCase().startsWith("http")) { return metadataId; } try { Map<String, List<String>> params = IOHelper.parseQuerystring(metadataId); String idParam = params.keySet().stream() .filter(key -> "uuid".equalsIgnoreCase(key) || KEY_ID.equalsIgnoreCase(key)) .findFirst() .orElse(null); if (idParam == null) { return null; } List<String> values = params.getOrDefault(idParam, Collections.emptyList()); if (values.isEmpty()) { return null; } return values.get(0); } catch (Exception ignored) { LOG.ignore("Unexpected error parsing metadataid", ignored); } LOG.debug("Couldn't parse uuid from metadata url:", metadataId); return null; } }
LayerJSONFormatter { public static String getFixedDataUrl(String metadataId) { if(metadataId == null || metadataId.isEmpty()) { return null; } if(!metadataId.toLowerCase().startsWith("http")) { return metadataId; } try { Map<String, List<String>> params = IOHelper.parseQuerystring(metadataId); String idParam = params.keySet().stream() .filter(key -> "uuid".equalsIgnoreCase(key) || KEY_ID.equalsIgnoreCase(key)) .findFirst() .orElse(null); if (idParam == null) { return null; } List<String> values = params.getOrDefault(idParam, Collections.emptyList()); if (values.isEmpty()) { return null; } return values.get(0); } catch (Exception ignored) { LOG.ignore("Unexpected error parsing metadataid", ignored); } LOG.debug("Couldn't parse uuid from metadata url:", metadataId); return null; }  }
LayerJSONFormatter { public static String getFixedDataUrl(String metadataId) { if(metadataId == null || metadataId.isEmpty()) { return null; } if(!metadataId.toLowerCase().startsWith("http")) { return metadataId; } try { Map<String, List<String>> params = IOHelper.parseQuerystring(metadataId); String idParam = params.keySet().stream() .filter(key -> "uuid".equalsIgnoreCase(key) || KEY_ID.equalsIgnoreCase(key)) .findFirst() .orElse(null); if (idParam == null) { return null; } List<String> values = params.getOrDefault(idParam, Collections.emptyList()); if (values.isEmpty()) { return null; } return values.get(0); } catch (Exception ignored) { LOG.ignore("Unexpected error parsing metadataid", ignored); } LOG.debug("Couldn't parse uuid from metadata url:", metadataId); return null; }  static void addFormatter(final String type, final LayerJSONFormatter formatter); JSONObject getJSON(final OskariLayer layer,
                                     final String lang,
                                     final boolean isSecure,
                                     final String crs); JSONObject getBaseJSON(final OskariLayer layer,
                                     final String lang,
                                     final boolean isSecure,
                                     final String crs); void removeAdminInfo(final JSONObject layer); void addInfoForAdmin(final JSONObject layer, final String key, final Object value); String getProxyUrl(final OskariLayer layer); static JSONObject createStylesJSON(String name, String title, String legend); static String getFixedDataUrl(String metadataId); static JSONObject getFormatsJSON(final Collection<String> formats); static Set<String> getCRSsToStore(Set<String> systemCRSs,
            Set<String> capabilitiesCRSs); static void addLayerCoverageWKT(final JSONObject layerJSON, final String wktWGS84, final String mapSRS); }
LayerJSONFormatter { public static String getFixedDataUrl(String metadataId) { if(metadataId == null || metadataId.isEmpty()) { return null; } if(!metadataId.toLowerCase().startsWith("http")) { return metadataId; } try { Map<String, List<String>> params = IOHelper.parseQuerystring(metadataId); String idParam = params.keySet().stream() .filter(key -> "uuid".equalsIgnoreCase(key) || KEY_ID.equalsIgnoreCase(key)) .findFirst() .orElse(null); if (idParam == null) { return null; } List<String> values = params.getOrDefault(idParam, Collections.emptyList()); if (values.isEmpty()) { return null; } return values.get(0); } catch (Exception ignored) { LOG.ignore("Unexpected error parsing metadataid", ignored); } LOG.debug("Couldn't parse uuid from metadata url:", metadataId); return null; }  static void addFormatter(final String type, final LayerJSONFormatter formatter); JSONObject getJSON(final OskariLayer layer,
                                     final String lang,
                                     final boolean isSecure,
                                     final String crs); JSONObject getBaseJSON(final OskariLayer layer,
                                     final String lang,
                                     final boolean isSecure,
                                     final String crs); void removeAdminInfo(final JSONObject layer); void addInfoForAdmin(final JSONObject layer, final String key, final Object value); String getProxyUrl(final OskariLayer layer); static JSONObject createStylesJSON(String name, String title, String legend); static String getFixedDataUrl(String metadataId); static JSONObject getFormatsJSON(final Collection<String> formats); static Set<String> getCRSsToStore(Set<String> systemCRSs,
            Set<String> capabilitiesCRSs); static void addLayerCoverageWKT(final JSONObject layerJSON, final String wktWGS84, final String mapSRS); static final String PROPERTY_AJAXURL; static final String KEY_ATTRIBUTE_FORCED_SRS; static final String KEY_ATTRIBUTE_IGNORE_COVERAGE; static final String KEY_TYPE; }