{"action":"created","comment":{"url":"https://api.github.com/repos/codice/ddf/pulls/comments/76270697","id":76270697,"diff_hunk":"@@ -0,0 +1,126 @@\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.spatial.geocoding.plugin;\n+\n+import java.io.Serializable;\n+import java.util.Map;\n+import java.util.Optional;\n+\n+import org.codice.ddf.spatial.geocoder.GeoCoder;\n+import org.slf4j.Logger;\n+import org.slf4j.LoggerFactory;\n+\n+import ddf.catalog.data.Metacard;\n+import ddf.catalog.data.impl.AttributeImpl;\n+import ddf.catalog.data.types.Location;\n+import ddf.catalog.operation.CreateRequest;\n+import ddf.catalog.operation.DeleteRequest;\n+import ddf.catalog.operation.UpdateRequest;\n+import ddf.catalog.plugin.PluginExecutionException;\n+import ddf.catalog.plugin.PreIngestPlugin;\n+import ddf.catalog.plugin.StopProcessingException;\n+import ddf.catalog.util.impl.ServiceSelector;\n+\n+/**\n+ * The {@code GeoCoderPlugin} is responsible for adding a {@link Location#COUNTRY_CODE} in ISO 3166-1 format\n+ * to {@code Metacard}s that have the {@link Metacard#GEOGRAPHY} attribute.\n+ */\n+public class GeoCoderPlugin implements PreIngestPlugin {\n+\n+    private static final Logger LOGGER = LoggerFactory.getLogger(GeoCoderPlugin.class);\n+\n+    private static ServiceSelector<GeoCoder> geoCoderFactory;\n+\n+    private int radiusInKm = 10;\n+\n+    public GeoCoderPlugin(ServiceSelector<GeoCoder> geoCoderFactory) {\n+        if (geoCoderFactory == null) {\n+            throw new IllegalArgumentException(\n+                    \"GeoCoderPlugin(): constructor argument 'geoCoderFactory' may not be null.\");\n+        }\n+\n+        this.geoCoderFactory = geoCoderFactory;\n+    }\n+\n+    @Override\n+    public CreateRequest process(CreateRequest input)\n+            throws PluginExecutionException, StopProcessingException {\n+        if (input.getMetacards() == null) {\n+            return input;\n+        }\n+\n+        for (Metacard metacard : input.getMetacards()) {\n+            Optional<String> wktLocation = Optional.ofNullable(metacard.getLocation());\n+\n+            if (wktLocation.isPresent()) {\n+                if (countryCodeNeeded(metacard)) {\n+                    GeoCoder geocoder = geoCoderFactory.getService();\n+\n+                    if (geocoder != null) {\n+                        Optional<String> alpha3CountryCode =\n+                                geocoder.getCountryCode(wktLocation.get(), radiusInKm);\n+\n+                        if (alpha3CountryCode.isPresent()) {\n+                            setCountryCodeAttribute(metacard, alpha3CountryCode.get());\n+                            LOGGER.trace(\n+                                    \"Setting metacard country code to {} for metacard with id {}\",\n+                                    alpha3CountryCode.get(),\n+                                    metacard.getId());\n+                        }\n+                    }\n+                }\n+            }\n+        }\n+        return input;\n+    }\n+\n+    @Override\n+    public UpdateRequest process(UpdateRequest input)\n+            throws PluginExecutionException, StopProcessingException {\n+        // TODO: Implement when AdaptedMetacard updated to use taxonomy\n+        return input;\n+    }\n+\n+    @Override\n+    public DeleteRequest process(DeleteRequest input)\n+            throws PluginExecutionException, StopProcessingException {\n+        return input;\n+    }\n+\n+    public void updateConfiguration(Map<String, Object> properties) {\n+        LOGGER.trace(\"Updating GeoCoderPlugin search radius\");\n+\n+        if (properties != null) {\n+            if (properties.get(\"radiusInKm\") instanceof Integer) {","path":"catalog/spatial/geocoding/spatial-geocoding-plugin/src/main/java/org/codice/ddf/spatial/geocoding/plugin/GeoCoderPlugin.java","position":105,"original_position":105,"commit_id":"ed70d3fb8a8160f22e4171d82d2a75be21e29d05","original_commit_id":"ed70d3fb8a8160f22e4171d82d2a75be21e29d05","user":{"login":"peterhuffer","id":17572782,"avatar_url":"https://avatars.githubusercontent.com/u/17572782?v=3","gravatar_id":"","url":"https://api.github.com/users/peterhuffer","html_url":"https://github.com/peterhuffer","followers_url":"https://api.github.com/users/peterhuffer/followers","following_url":"https://api.github.com/users/peterhuffer/following{/other_user}","gists_url":"https://api.github.com/users/peterhuffer/gists{/gist_id}","starred_url":"https://api.github.com/users/peterhuffer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/peterhuffer/subscriptions","organizations_url":"https://api.github.com/users/peterhuffer/orgs","repos_url":"https://api.github.com/users/peterhuffer/repos","events_url":"https://api.github.com/users/peterhuffer/events{/privacy}","received_events_url":"https://api.github.com/users/peterhuffer/received_events","type":"User","site_admin":false},"body":"Changed.","created_at":"2016-08-25T15:52:07Z","updated_at":"2016-08-25T15:52:07Z","html_url":"https://github.com/codice/ddf/pull/1171#discussion_r76270697","pull_request_url":"https://api.github.com/repos/codice/ddf/pulls/1171","_links":{"self":{"href":"https://api.github.com/repos/codice/ddf/pulls/comments/76270697"},"html":{"href":"https://github.com/codice/ddf/pull/1171#discussion_r76270697"},"pull_request":{"href":"https://api.github.com/repos/codice/ddf/pulls/1171"}}},"pull_request":{"url":"https://api.github.com/repos/codice/ddf/pulls/1171","id":82270847,"html_url":"https://github.com/codice/ddf/pull/1171","diff_url":"https://github.com/codice/ddf/pull/1171.diff","patch_url":"https://github.com/codice/ddf/pull/1171.patch","issue_url":"https://api.github.com/repos/codice/ddf/issues/1171","number":1171,"state":"open","locked":false,"title":"DDF-2325: Populates Location.COUNTRY_CODE field for geolocated metacards","user":{"login":"peterhuffer","id":17572782,"avatar_url":"https://avatars.githubusercontent.com/u/17572782?v=3","gravatar_id":"","url":"https://api.github.com/users/peterhuffer","html_url":"https://github.com/peterhuffer","followers_url":"https://api.github.com/users/peterhuffer/followers","following_url":"https://api.github.com/users/peterhuffer/following{/other_user}","gists_url":"https://api.github.com/users/peterhuffer/gists{/gist_id}","starred_url":"https://api.github.com/users/peterhuffer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/peterhuffer/subscriptions","organizations_url":"https://api.github.com/users/peterhuffer/orgs","repos_url":"https://api.github.com/users/peterhuffer/repos","events_url":"https://api.github.com/users/peterhuffer/events{/privacy}","received_events_url":"https://api.github.com/users/peterhuffer/received_events","type":"User","site_admin":false},"body":"#### What does this PR do?\r\n- Adds ability for local and websearch gazetteers to get country code for a wktLocation\r\n- Adds a PreIngestPlugin for populate Location.COUNTRY_CODE field for metacard if Metacard.GEOGRAPHY is present\r\n\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@glenhein @emmberk @jrnorth @ricklarsen \r\n#### Choose 2 committers to review/merge the PR (please choose ONLY two committers from below, delete the rest).\r\n@kcwire\r\n@shaundmorris\r\n#### How should this be tested?\r\nUnit tests. There is no visible affect from this addition due to many components not supporting the taxonomy yet.\r\n#### Any background context you want to provide?\r\n#### What are the relevant tickets?\r\nhttps://codice.atlassian.net/browse/DDF-2325\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\r\n","created_at":"2016-08-22T21:58:35Z","updated_at":"2016-08-25T15:52:07Z","closed_at":null,"merged_at":null,"merge_commit_sha":"cf61e5d65c15347f12fb65bba94cf2cbd7c37fb1","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/codice/ddf/pulls/1171/commits","review_comments_url":"https://api.github.com/repos/codice/ddf/pulls/1171/comments","review_comment_url":"https://api.github.com/repos/codice/ddf/pulls/comments{/number}","comments_url":"https://api.github.com/repos/codice/ddf/issues/1171/comments","statuses_url":"https://api.github.com/repos/codice/ddf/statuses/ed70d3fb8a8160f22e4171d82d2a75be21e29d05","head":{"label":"peterhuffer:DDF-2325","ref":"DDF-2325","sha":"ed70d3fb8a8160f22e4171d82d2a75be21e29d05","user":{"login":"peterhuffer","id":17572782,"avatar_url":"https://avatars.githubusercontent.com/u/17572782?v=3","gravatar_id":"","url":"https://api.github.com/users/peterhuffer","html_url":"https://github.com/peterhuffer","followers_url":"https://api.github.com/users/peterhuffer/followers","following_url":"https://api.github.com/users/peterhuffer/following{/other_user}","gists_url":"https://api.github.com/users/peterhuffer/gists{/gist_id}","starred_url":"https://api.github.com/users/peterhuffer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/peterhuffer/subscriptions","organizations_url":"https://api.github.com/users/peterhuffer/orgs","repos_url":"https://api.github.com/users/peterhuffer/repos","events_url":"https://api.github.com/users/peterhuffer/events{/privacy}","received_events_url":"https://api.github.com/users/peterhuffer/received_events","type":"User","site_admin":false},"repo":{"id":53069510,"name":"ddf","full_name":"peterhuffer/ddf","owner":{"login":"peterhuffer","id":17572782,"avatar_url":"https://avatars.githubusercontent.com/u/17572782?v=3","gravatar_id":"","url":"https://api.github.com/users/peterhuffer","html_url":"https://github.com/peterhuffer","followers_url":"https://api.github.com/users/peterhuffer/followers","following_url":"https://api.github.com/users/peterhuffer/following{/other_user}","gists_url":"https://api.github.com/users/peterhuffer/gists{/gist_id}","starred_url":"https://api.github.com/users/peterhuffer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/peterhuffer/subscriptions","organizations_url":"https://api.github.com/users/peterhuffer/orgs","repos_url":"https://api.github.com/users/peterhuffer/repos","events_url":"https://api.github.com/users/peterhuffer/events{/privacy}","received_events_url":"https://api.github.com/users/peterhuffer/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/peterhuffer/ddf","description":"The Distributed Data Framework - Federated Open Geospatial Consortium (OGC) filter powered metadata catalog with SAML Web SSO secured container","fork":true,"url":"https://api.github.com/repos/peterhuffer/ddf","forks_url":"https://api.github.com/repos/peterhuffer/ddf/forks","keys_url":"https://api.github.com/repos/peterhuffer/ddf/keys{/key_id}","collaborators_url":"https://api.github.com/repos/peterhuffer/ddf/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/peterhuffer/ddf/teams","hooks_url":"https://api.github.com/repos/peterhuffer/ddf/hooks","issue_events_url":"https://api.github.com/repos/peterhuffer/ddf/issues/events{/number}","events_url":"https://api.github.com/repos/peterhuffer/ddf/events","assignees_url":"https://api.github.com/repos/peterhuffer/ddf/assignees{/user}","branches_url":"https://api.github.com/repos/peterhuffer/ddf/branches{/branch}","tags_url":"https://api.github.com/repos/peterhuffer/ddf/tags","blobs_url":"https://api.github.com/repos/peterhuffer/ddf/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/peterhuffer/ddf/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/peterhuffer/ddf/git/refs{/sha}","trees_url":"https://api.github.com/repos/peterhuffer/ddf/git/trees{/sha}","statuses_url":"https://api.github.com/repos/peterhuffer/ddf/statuses/{sha}","languages_url":"https://api.github.com/repos/peterhuffer/ddf/languages","stargazers_url":"https://api.github.com/repos/peterhuffer/ddf/stargazers","contributors_url":"https://api.github.com/repos/peterhuffer/ddf/contributors","subscribers_url":"https://api.github.com/repos/peterhuffer/ddf/subscribers","subscription_url":"https://api.github.com/repos/peterhuffer/ddf/subscription","commits_url":"https://api.github.com/repos/peterhuffer/ddf/commits{/sha}","git_commits_url":"https://api.github.com/repos/peterhuffer/ddf/git/commits{/sha}","comments_url":"https://api.github.com/repos/peterhuffer/ddf/comments{/number}","issue_comment_url":"https://api.github.com/repos/peterhuffer/ddf/issues/comments{/number}","contents_url":"https://api.github.com/repos/peterhuffer/ddf/contents/{+path}","compare_url":"https://api.github.com/repos/peterhuffer/ddf/compare/{base}...{head}","merges_url":"https://api.github.com/repos/peterhuffer/ddf/merges","archive_url":"https://api.github.com/repos/peterhuffer/ddf/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/peterhuffer/ddf/downloads","issues_url":"https://api.github.com/repos/peterhuffer/ddf/issues{/number}","pulls_url":"https://api.github.com/repos/peterhuffer/ddf/pulls{/number}","milestones_url":"https://api.github.com/repos/peterhuffer/ddf/milestones{/number}","notifications_url":"https://api.github.com/repos/peterhuffer/ddf/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/peterhuffer/ddf/labels{/name}","releases_url":"https://api.github.com/repos/peterhuffer/ddf/releases{/id}","deployments_url":"https://api.github.com/repos/peterhuffer/ddf/deployments","created_at":"2016-03-03T17:28:01Z","updated_at":"2016-03-03T17:28:14Z","pushed_at":"2016-08-24T16:19:33Z","git_url":"git://github.com/peterhuffer/ddf.git","ssh_url":"git@github.com:peterhuffer/ddf.git","clone_url":"https://github.com/peterhuffer/ddf.git","svn_url":"https://github.com/peterhuffer/ddf","homepage":"","size":149258,"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":"8e0f49a578cb54eaa50082815996c4477af1a5b7","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-08-20T06:33:26Z","pushed_at":"2016-08-25T15:32:51Z","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":283017,"stargazers_count":43,"watchers_count":43,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":true,"forks_count":86,"mirror_url":null,"open_issues_count":24,"forks":86,"open_issues":24,"watchers":43,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/codice/ddf/pulls/1171"},"html":{"href":"https://github.com/codice/ddf/pull/1171"},"issue":{"href":"https://api.github.com/repos/codice/ddf/issues/1171"},"comments":{"href":"https://api.github.com/repos/codice/ddf/issues/1171/comments"},"review_comments":{"href":"https://api.github.com/repos/codice/ddf/pulls/1171/comments"},"review_comment":{"href":"https://api.github.com/repos/codice/ddf/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/codice/ddf/pulls/1171/commits"},"statuses":{"href":"https://api.github.com/repos/codice/ddf/statuses/ed70d3fb8a8160f22e4171d82d2a75be21e29d05"}}}}
{"actor":{"display_login":"peterhuffer"}}