{"action":"created","comment":{"url":"https://api.github.com/repos/codice/ddf/pulls/comments/81269412","pull_request_review_id":2259211,"id":81269412,"diff_hunk":"@@ -0,0 +1,106 @@\n+/**\n+ * Copyright (c) Codice Foundation\n+ * <p>\n+ * This is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser\n+ * General Public License as published by the Free Software Foundation, either version 3 of the\n+ * License, or any later version.\n+ * <p>\n+ * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without\n+ * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n+ * Lesser General Public License for more details. A copy of the GNU Lesser General Public License\n+ * is distributed along with this program and can be found at\n+ * <http://www.gnu.org/licenses/lgpl.html>.\n+ */\n+package org.codice.ddf.libs.location;\n+\n+import java.util.ArrayList;\n+import java.util.Arrays;\n+import java.util.List;\n+import java.util.Locale;\n+import java.util.Map;\n+import java.util.Objects;\n+\n+import org.apache.commons.lang.StringUtils;\n+import org.slf4j.Logger;\n+import org.slf4j.LoggerFactory;\n+\n+import ddf.security.PropertiesLoader;\n+\n+/**\n+ * Utility to convert country codes into various formats.\n+ */\n+public class CountryCodeConverter {\n+\n+    private static final Logger LOGGER = LoggerFactory.getLogger(CountryCodeConverter.class);\n+\n+    private static final String FIPS_TO_ISO3 = \"FIPS10-4toISO3.properties\";\n+\n+    public static final String ENGLISH_LANG = \"en\";\n+\n+    private static Map<String, String> countryCodesMap;\n+\n+    static {\n+        countryCodesMap = PropertiesLoader.toMap(PropertiesLoader.loadProperties(FIPS_TO_ISO3));\n+    }\n+\n+    /**\n+     * Converts FIPS 10-4 into ISO 3166-1 alpha 3.\n+     *\n+     * @param fipsCountryCode a FIPS 10-4 country code\n+     * @return an ISO 3166-1 alpha-3 country code or null if there isn't a valid conversion.\n+     */\n+    public static String convertFipsToIso3(String fipsCountryCode) {\n+        String iso3CountryCode = countryCodesMap.get(fipsCountryCode);\n+        if (StringUtils.isBlank(iso3CountryCode)) {\n+            LOGGER.debug(\n+                    \"Could not find a corresponding ISO 3166-1 alpha 3 country code given the FIPS\"\n+                            + \" 10-4 country code: {}\",\n+                    fipsCountryCode);\n+        }\n+        return iso3CountryCode;\n+    }\n+\n+    /**\n+     * Converts ISO 3166-1 alpha 3 into FIPS 10-4.\n+     * <p>\n+     * Special case:\n+     * ISO 3166-1 alpha 3 country: \"PSE\" corresponds to FIPS 10-4 countries: \"WE\" and \"GZ\",\n+     * in this case, the returned list will contain those two countries. In all other cases,\n+     * the returned list will contain one country.\n+     *\n+     * @param iso3alphaCountryCode a FIPS 10-4 country code\n+     * @return an ISO 3166-1 country code in a List<String> or an empty list if there isn't a valid\n+     * conversion.\n+     */\n+    public static List<String> convertIso3ToFips(String iso3alphaCountryCode) {\n+        if (\"PSE\".equals(iso3alphaCountryCode)) {\n+            return Arrays.asList(\"WE\", \"GZ\");\n+        }\n+        String fipsCountryCode = countryCodesMap.entrySet()\n+                .stream()\n+                .filter(entry -> Objects.equals(entry.getValue(), iso3alphaCountryCode))\n+                .map(Map.Entry::getKey)\n+                .findFirst()\n+                .orElse(null);\n+        if (StringUtils.isBlank(fipsCountryCode)) {\n+            LOGGER.debug(\n+                    \"Could not find a corresponding FIPS 10-4 country code given the ISO 3166-1\"\n+                            + \" alpha 3 country code: {}\" + iso3alphaCountryCode);\n+            return new ArrayList<>();","path":"libs/geospatial/src/main/java/org/codice/ddf/libs/location/CountryCodeConverter.java","position":89,"original_position":89,"commit_id":"98cdd95ffefdc7e568a961b1e8315093ad941b69","original_commit_id":"98cdd95ffefdc7e568a961b1e8315093ad941b69","user":{"login":"lessarderic","id":11377558,"avatar_url":"https://avatars.githubusercontent.com/u/11377558?v=3","gravatar_id":"","url":"https://api.github.com/users/lessarderic","html_url":"https://github.com/lessarderic","followers_url":"https://api.github.com/users/lessarderic/followers","following_url":"https://api.github.com/users/lessarderic/following{/other_user}","gists_url":"https://api.github.com/users/lessarderic/gists{/gist_id}","starred_url":"https://api.github.com/users/lessarderic/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lessarderic/subscriptions","organizations_url":"https://api.github.com/users/lessarderic/orgs","repos_url":"https://api.github.com/users/lessarderic/repos","events_url":"https://api.github.com/users/lessarderic/events{/privacy}","received_events_url":"https://api.github.com/users/lessarderic/received_events","type":"User","site_admin":false},"body":"We should use `Collections.emptyList()` instead.","created_at":"2016-09-30T02:12:20Z","updated_at":"2016-09-30T02:12:20Z","html_url":"https://github.com/codice/ddf/pull/1292#discussion_r81269412","pull_request_url":"https://api.github.com/repos/codice/ddf/pulls/1292","_links":{"self":{"href":"https://api.github.com/repos/codice/ddf/pulls/comments/81269412"},"html":{"href":"https://github.com/codice/ddf/pull/1292#discussion_r81269412"},"pull_request":{"href":"https://api.github.com/repos/codice/ddf/pulls/1292"}}},"pull_request":{"url":"https://api.github.com/repos/codice/ddf/pulls/1292","id":86071375,"html_url":"https://github.com/codice/ddf/pull/1292","diff_url":"https://github.com/codice/ddf/pull/1292.diff","patch_url":"https://github.com/codice/ddf/pull/1292.patch","issue_url":"https://api.github.com/repos/codice/ddf/issues/1292","number":1292,"state":"open","locked":false,"title":"DDF-2478 Add utility to convert country codes from FIPS 10-4 into ISO 3166-1 alpha 3 and vice versa","user":{"login":"roelens8","id":5935039,"avatar_url":"https://avatars.githubusercontent.com/u/5935039?v=3","gravatar_id":"","url":"https://api.github.com/users/roelens8","html_url":"https://github.com/roelens8","followers_url":"https://api.github.com/users/roelens8/followers","following_url":"https://api.github.com/users/roelens8/following{/other_user}","gists_url":"https://api.github.com/users/roelens8/gists{/gist_id}","starred_url":"https://api.github.com/users/roelens8/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/roelens8/subscriptions","organizations_url":"https://api.github.com/users/roelens8/orgs","repos_url":"https://api.github.com/users/roelens8/repos","events_url":"https://api.github.com/users/roelens8/events{/privacy}","received_events_url":"https://api.github.com/users/roelens8/received_events","type":"User","site_admin":false},"body":"#### What does this PR do?\r\n-Adds a utility: CountryCodeConverter.java, to convert country codes from FIPS 10-4 into ISO 3166-1 alpha and vice versa.\r\n-Combines the ISOFormatConverter into the CountryCodeConverter.\r\n#### Who is reviewing it (please choose AT LEAST two reviewers that need to approve the PR before it can get merged; if a component team is listed, at least one of its members needs to approve)?\r\n@dcruver \r\n@ryeats \r\n@jlcsmith \r\n@harrison-tarr \r\n@peterhuffer \r\n#### Choose 2 committers to review/merge the PR (please choose ONLY two committers from below, delete the rest).\r\n@jaymcnallie\r\n@pklinef\r\n#### How should this be tested?\r\nRun a full build. Make sure unit tests pass.\r\n\r\nVerify the country mappings from this link are the same as the mappings from the \"FIPS10-4toISO3.properties\" file from this PR. I did not include the countries that did not have a FIPS 10-4 to ISO 3166-1 alpha 3 mapping. http://www.opengeocode.org/download/fips2iso.txt\r\n#### Any background context you want to provide?\r\nThis utility is meant to normalize country codes from inputs eg. NITFs, that contain a 2 letter country code (FIPS 10-4), into a common format DDF uses (ISO 3166-1 alpha 3) so that when a user wants to query a metacard by country, he would search by the normalized country code and still retrieve metacards from inputs that have a country code in FIPS 10-4.\r\n#### What are the relevant tickets?\r\nDDF-2478\r\n#### Screenshots (if appropriate)\r\n#### Checklist:\r\n- [ ] Documentation Updated\r\n- [X] Update / Add Unit Tests\r\n- [ ] Update / Add Integration Tests","created_at":"2016-09-20T22:59:20Z","updated_at":"2016-09-30T02:24:38Z","closed_at":null,"merged_at":null,"merge_commit_sha":"e3110e8c2d0a158d0eac708b13f7092c627b8419","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/codice/ddf/pulls/1292/commits","review_comments_url":"https://api.github.com/repos/codice/ddf/pulls/1292/comments","review_comment_url":"https://api.github.com/repos/codice/ddf/pulls/comments{/number}","comments_url":"https://api.github.com/repos/codice/ddf/issues/1292/comments","statuses_url":"https://api.github.com/repos/codice/ddf/statuses/98cdd95ffefdc7e568a961b1e8315093ad941b69","head":{"label":"roelens8:DDF-2478","ref":"DDF-2478","sha":"98cdd95ffefdc7e568a961b1e8315093ad941b69","user":{"login":"roelens8","id":5935039,"avatar_url":"https://avatars.githubusercontent.com/u/5935039?v=3","gravatar_id":"","url":"https://api.github.com/users/roelens8","html_url":"https://github.com/roelens8","followers_url":"https://api.github.com/users/roelens8/followers","following_url":"https://api.github.com/users/roelens8/following{/other_user}","gists_url":"https://api.github.com/users/roelens8/gists{/gist_id}","starred_url":"https://api.github.com/users/roelens8/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/roelens8/subscriptions","organizations_url":"https://api.github.com/users/roelens8/orgs","repos_url":"https://api.github.com/users/roelens8/repos","events_url":"https://api.github.com/users/roelens8/events{/privacy}","received_events_url":"https://api.github.com/users/roelens8/received_events","type":"User","site_admin":false},"repo":{"id":37481426,"name":"ddf","full_name":"roelens8/ddf","owner":{"login":"roelens8","id":5935039,"avatar_url":"https://avatars.githubusercontent.com/u/5935039?v=3","gravatar_id":"","url":"https://api.github.com/users/roelens8","html_url":"https://github.com/roelens8","followers_url":"https://api.github.com/users/roelens8/followers","following_url":"https://api.github.com/users/roelens8/following{/other_user}","gists_url":"https://api.github.com/users/roelens8/gists{/gist_id}","starred_url":"https://api.github.com/users/roelens8/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/roelens8/subscriptions","organizations_url":"https://api.github.com/users/roelens8/orgs","repos_url":"https://api.github.com/users/roelens8/repos","events_url":"https://api.github.com/users/roelens8/events{/privacy}","received_events_url":"https://api.github.com/users/roelens8/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/roelens8/ddf","description":"The Distributed Data Framework - Distribution, SDK, and Test","fork":true,"url":"https://api.github.com/repos/roelens8/ddf","forks_url":"https://api.github.com/repos/roelens8/ddf/forks","keys_url":"https://api.github.com/repos/roelens8/ddf/keys{/key_id}","collaborators_url":"https://api.github.com/repos/roelens8/ddf/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/roelens8/ddf/teams","hooks_url":"https://api.github.com/repos/roelens8/ddf/hooks","issue_events_url":"https://api.github.com/repos/roelens8/ddf/issues/events{/number}","events_url":"https://api.github.com/repos/roelens8/ddf/events","assignees_url":"https://api.github.com/repos/roelens8/ddf/assignees{/user}","branches_url":"https://api.github.com/repos/roelens8/ddf/branches{/branch}","tags_url":"https://api.github.com/repos/roelens8/ddf/tags","blobs_url":"https://api.github.com/repos/roelens8/ddf/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/roelens8/ddf/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/roelens8/ddf/git/refs{/sha}","trees_url":"https://api.github.com/repos/roelens8/ddf/git/trees{/sha}","statuses_url":"https://api.github.com/repos/roelens8/ddf/statuses/{sha}","languages_url":"https://api.github.com/repos/roelens8/ddf/languages","stargazers_url":"https://api.github.com/repos/roelens8/ddf/stargazers","contributors_url":"https://api.github.com/repos/roelens8/ddf/contributors","subscribers_url":"https://api.github.com/repos/roelens8/ddf/subscribers","subscription_url":"https://api.github.com/repos/roelens8/ddf/subscription","commits_url":"https://api.github.com/repos/roelens8/ddf/commits{/sha}","git_commits_url":"https://api.github.com/repos/roelens8/ddf/git/commits{/sha}","comments_url":"https://api.github.com/repos/roelens8/ddf/comments{/number}","issue_comment_url":"https://api.github.com/repos/roelens8/ddf/issues/comments{/number}","contents_url":"https://api.github.com/repos/roelens8/ddf/contents/{+path}","compare_url":"https://api.github.com/repos/roelens8/ddf/compare/{base}...{head}","merges_url":"https://api.github.com/repos/roelens8/ddf/merges","archive_url":"https://api.github.com/repos/roelens8/ddf/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/roelens8/ddf/downloads","issues_url":"https://api.github.com/repos/roelens8/ddf/issues{/number}","pulls_url":"https://api.github.com/repos/roelens8/ddf/pulls{/number}","milestones_url":"https://api.github.com/repos/roelens8/ddf/milestones{/number}","notifications_url":"https://api.github.com/repos/roelens8/ddf/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/roelens8/ddf/labels{/name}","releases_url":"https://api.github.com/repos/roelens8/ddf/releases{/id}","deployments_url":"https://api.github.com/repos/roelens8/ddf/deployments","created_at":"2015-06-15T17:55:32Z","updated_at":"2015-06-15T17:55:33Z","pushed_at":"2016-09-29T16:26:36Z","git_url":"git://github.com/roelens8/ddf.git","ssh_url":"git@github.com:roelens8/ddf.git","clone_url":"https://github.com/roelens8/ddf.git","svn_url":"https://github.com/roelens8/ddf","homepage":"","size":148714,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"codice:master","ref":"master","sha":"ac5bf7db254e3de062692d886b89d0f3e2c83919","user":{"login":"codice","id":2386734,"avatar_url":"https://avatars.githubusercontent.com/u/2386734?v=3","gravatar_id":"","url":"https://api.github.com/users/codice","html_url":"https://github.com/codice","followers_url":"https://api.github.com/users/codice/followers","following_url":"https://api.github.com/users/codice/following{/other_user}","gists_url":"https://api.github.com/users/codice/gists{/gist_id}","starred_url":"https://api.github.com/users/codice/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/codice/subscriptions","organizations_url":"https://api.github.com/users/codice/orgs","repos_url":"https://api.github.com/users/codice/repos","events_url":"https://api.github.com/users/codice/events{/privacy}","received_events_url":"https://api.github.com/users/codice/received_events","type":"Organization","site_admin":false},"repo":{"id":15173563,"name":"ddf","full_name":"codice/ddf","owner":{"login":"codice","id":2386734,"avatar_url":"https://avatars.githubusercontent.com/u/2386734?v=3","gravatar_id":"","url":"https://api.github.com/users/codice","html_url":"https://github.com/codice","followers_url":"https://api.github.com/users/codice/followers","following_url":"https://api.github.com/users/codice/following{/other_user}","gists_url":"https://api.github.com/users/codice/gists{/gist_id}","starred_url":"https://api.github.com/users/codice/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/codice/subscriptions","organizations_url":"https://api.github.com/users/codice/orgs","repos_url":"https://api.github.com/users/codice/repos","events_url":"https://api.github.com/users/codice/events{/privacy}","received_events_url":"https://api.github.com/users/codice/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/codice/ddf","description":"Distributed Data Framework - an open source, modular integration framework.","fork":false,"url":"https://api.github.com/repos/codice/ddf","forks_url":"https://api.github.com/repos/codice/ddf/forks","keys_url":"https://api.github.com/repos/codice/ddf/keys{/key_id}","collaborators_url":"https://api.github.com/repos/codice/ddf/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/codice/ddf/teams","hooks_url":"https://api.github.com/repos/codice/ddf/hooks","issue_events_url":"https://api.github.com/repos/codice/ddf/issues/events{/number}","events_url":"https://api.github.com/repos/codice/ddf/events","assignees_url":"https://api.github.com/repos/codice/ddf/assignees{/user}","branches_url":"https://api.github.com/repos/codice/ddf/branches{/branch}","tags_url":"https://api.github.com/repos/codice/ddf/tags","blobs_url":"https://api.github.com/repos/codice/ddf/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/codice/ddf/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/codice/ddf/git/refs{/sha}","trees_url":"https://api.github.com/repos/codice/ddf/git/trees{/sha}","statuses_url":"https://api.github.com/repos/codice/ddf/statuses/{sha}","languages_url":"https://api.github.com/repos/codice/ddf/languages","stargazers_url":"https://api.github.com/repos/codice/ddf/stargazers","contributors_url":"https://api.github.com/repos/codice/ddf/contributors","subscribers_url":"https://api.github.com/repos/codice/ddf/subscribers","subscription_url":"https://api.github.com/repos/codice/ddf/subscription","commits_url":"https://api.github.com/repos/codice/ddf/commits{/sha}","git_commits_url":"https://api.github.com/repos/codice/ddf/git/commits{/sha}","comments_url":"https://api.github.com/repos/codice/ddf/comments{/number}","issue_comment_url":"https://api.github.com/repos/codice/ddf/issues/comments{/number}","contents_url":"https://api.github.com/repos/codice/ddf/contents/{+path}","compare_url":"https://api.github.com/repos/codice/ddf/compare/{base}...{head}","merges_url":"https://api.github.com/repos/codice/ddf/merges","archive_url":"https://api.github.com/repos/codice/ddf/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/codice/ddf/downloads","issues_url":"https://api.github.com/repos/codice/ddf/issues{/number}","pulls_url":"https://api.github.com/repos/codice/ddf/pulls{/number}","milestones_url":"https://api.github.com/repos/codice/ddf/milestones{/number}","notifications_url":"https://api.github.com/repos/codice/ddf/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/codice/ddf/labels{/name}","releases_url":"https://api.github.com/repos/codice/ddf/releases{/id}","deployments_url":"https://api.github.com/repos/codice/ddf/deployments","created_at":"2013-12-13T20:38:28Z","updated_at":"2016-09-16T18:40:56Z","pushed_at":"2016-09-30T02:13:39Z","git_url":"git://github.com/codice/ddf.git","ssh_url":"git@github.com:codice/ddf.git","clone_url":"https://github.com/codice/ddf.git","svn_url":"https://github.com/codice/ddf","homepage":"http://ddf.codice.org","size":287351,"stargazers_count":46,"watchers_count":46,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":true,"forks_count":93,"mirror_url":null,"open_issues_count":27,"forks":93,"open_issues":27,"watchers":46,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/codice/ddf/pulls/1292"},"html":{"href":"https://github.com/codice/ddf/pull/1292"},"issue":{"href":"https://api.github.com/repos/codice/ddf/issues/1292"},"comments":{"href":"https://api.github.com/repos/codice/ddf/issues/1292/comments"},"review_comments":{"href":"https://api.github.com/repos/codice/ddf/pulls/1292/comments"},"review_comment":{"href":"https://api.github.com/repos/codice/ddf/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/codice/ddf/pulls/1292/commits"},"statuses":{"href":"https://api.github.com/repos/codice/ddf/statuses/98cdd95ffefdc7e568a961b1e8315093ad941b69"}}}}
{"actor":{"display_login":"lessarderic"}}