{"action":"created","comment":{"url":"https://api.github.com/repos/aodn/geoserver-build/pulls/comments/55316822","id":55316822,"diff_hunk":"@@ -0,0 +1,252 @@\n+package au.org.emii.gogoduck.worker;\n+\n+import org.apache.commons.io.FilenameUtils;\n+\n+import java.io.*;\n+import java.nio.file.Files;\n+import java.nio.file.Path;\n+import java.nio.file.Paths;\n+import java.util.ArrayList;\n+import java.util.HashMap;\n+import java.util.List;\n+import java.util.Map;\n+import java.util.regex.Matcher;\n+import java.util.regex.Pattern;\n+\n+import org.apache.commons.io.FileUtils;\n+import org.geotools.data.Base64;\n+import org.slf4j.Logger;\n+import org.slf4j.LoggerFactory;\n+\n+import static org.apache.commons.io.FileUtils.readFileToString;\n+\n+public class CSVConverter extends Converter {\n+\n+    private String ncksPath = null;\n+    private String ncpdqPath = null;\n+    private final String mimeType = \"text/csv\";\n+    private final String extension = \"csv\";\n+    private Integer lineNumber = 0;\n+    private Integer attributesEnd = 0;\n+    private List<String> lines = new ArrayList<String>();\n+    private List<String> metadata = new ArrayList<String>();\n+    private List<String> attributeMetadata = new ArrayList<String>();\n+    private List<Map> attributes = new ArrayList<Map>();\n+    private StringBuilder csvString = new StringBuilder();\n+\n+    private final String NEW_LINE = System.getProperty(\"line.separator\");\n+    private final String COMMENT = \"# \";\n+    private static final Logger logger = LoggerFactory.getLogger(GoGoDuck.class);\n+\n+    public CSVConverter() {}\n+\n+    @Override\n+    public void init() {\n+        this.ncksPath = GoGoDuckConfig.ncksPath;\n+        this.ncpdqPath = GoGoDuckConfig.ncpdqPath;\n+    }\n+\n+    @Override\n+    public String getMimeType() { return mimeType; }\n+\n+    @Override\n+    public String getExtension() { return extension; }\n+\n+    @Override\n+    public Path convert(Path outputFile) throws GoGoDuckException {\n+        List<String> ncpdqCommand = new ArrayList<>();\n+        List<String> ncksCommand = new ArrayList<>();\n+        String baseFilename = FilenameUtils.getBaseName(String.valueOf(outputFile));\n+        try {\n+            File tmpNcdf = File.createTempFile(\"tmp\", \".nc\");\n+            // Unpack packed CSV values and store in temp csv\n+            ncpdqCommand.add(ncpdqPath);\n+            ncpdqCommand.add(\"-U\");\n+            ncpdqCommand.add(\"-O\");\n+            ncpdqCommand.add(outputFile.toString());\n+            ncpdqCommand.add(tmpNcdf.getPath());\n+            GoGoDuck.execute(ncpdqCommand);\n+\n+            // Output temp csv and store values\n+            ncksCommand.add(ncksPath);\n+            ncksCommand.add(\"--no_nm_prn\");\n+            ncksCommand.add(\"-a\");\n+            ncksCommand.add(tmpNcdf.getPath());\n+\n+            return executeNcks(ncksCommand, baseFilename, tmpNcdf.toPath());\n+        } catch (Exception e) {\n+            throw new GoGoDuckException(String.format(\"Could not convert output to csv: '%s'\", e.getMessage()));\n+        }\n+    }\n+\n+    private Path executeNcks(List<String> commandList, String baseFilename, Path tempFile) throws IOException, InterruptedException {\n+        logger.info(commandList.toString());\n+\n+        File errorTmpFile = File.createTempFile(\"error\", \".txt\");\n+        ProcessBuilder processor = new ProcessBuilder(commandList);\n+        processor.redirectError(errorTmpFile);","path":"src/extension/wps/src/main/java/au/org/emii/gogoduck/worker/CSVConverter.java","position":87,"original_position":87,"commit_id":"741c0bf85e5792b843ab9bd21e70830789d90057","original_commit_id":"741c0bf85e5792b843ab9bd21e70830789d90057","user":{"login":"danfruehauf","id":830676,"avatar_url":"https://avatars.githubusercontent.com/u/830676?v=3","gravatar_id":"","url":"https://api.github.com/users/danfruehauf","html_url":"https://github.com/danfruehauf","followers_url":"https://api.github.com/users/danfruehauf/followers","following_url":"https://api.github.com/users/danfruehauf/following{/other_user}","gists_url":"https://api.github.com/users/danfruehauf/gists{/gist_id}","starred_url":"https://api.github.com/users/danfruehauf/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/danfruehauf/subscriptions","organizations_url":"https://api.github.com/users/danfruehauf/orgs","repos_url":"https://api.github.com/users/danfruehauf/repos","events_url":"https://api.github.com/users/danfruehauf/events{/privacy}","received_events_url":"https://api.github.com/users/danfruehauf/received_events","type":"User","site_admin":false},"body":"You might have to use a different method, but it is probably possible to consume stderr without redirecting to a file.","created_at":"2016-03-08T05:05:07Z","updated_at":"2016-03-08T05:05:07Z","html_url":"https://github.com/aodn/geoserver-build/pull/123#discussion_r55316822","pull_request_url":"https://api.github.com/repos/aodn/geoserver-build/pulls/123","_links":{"self":{"href":"https://api.github.com/repos/aodn/geoserver-build/pulls/comments/55316822"},"html":{"href":"https://github.com/aodn/geoserver-build/pull/123#discussion_r55316822"},"pull_request":{"href":"https://api.github.com/repos/aodn/geoserver-build/pulls/123"}}},"pull_request":{"url":"https://api.github.com/repos/aodn/geoserver-build/pulls/123","id":61645548,"html_url":"https://github.com/aodn/geoserver-build/pull/123","diff_url":"https://github.com/aodn/geoserver-build/pull/123.diff","patch_url":"https://github.com/aodn/geoserver-build/pull/123.patch","issue_url":"https://api.github.com/repos/aodn/geoserver-build/issues/123","number":123,"state":"open","locked":false,"title":"Add csv point download option to gogoduck","user":{"login":"anguss00","id":5964166,"avatar_url":"https://avatars.githubusercontent.com/u/5964166?v=3","gravatar_id":"","url":"https://api.github.com/users/anguss00","html_url":"https://github.com/anguss00","followers_url":"https://api.github.com/users/anguss00/followers","following_url":"https://api.github.com/users/anguss00/following{/other_user}","gists_url":"https://api.github.com/users/anguss00/gists{/gist_id}","starred_url":"https://api.github.com/users/anguss00/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/anguss00/subscriptions","organizations_url":"https://api.github.com/users/anguss00/orgs","repos_url":"https://api.github.com/users/anguss00/repos","events_url":"https://api.github.com/users/anguss00/events{/privacy}","received_events_url":"https://api.github.com/users/anguss00/received_events","type":"User","site_admin":false},"body":"Initial PR: executes on the command line.\r\nTODO: testing as WPS module.\r\nFor review.","created_at":"2016-03-03T23:46:57Z","updated_at":"2016-03-08T05:05:07Z","closed_at":null,"merged_at":null,"merge_commit_sha":"aebc571991d996346e065dead9d2f3701fe125fc","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/aodn/geoserver-build/pulls/123/commits","review_comments_url":"https://api.github.com/repos/aodn/geoserver-build/pulls/123/comments","review_comment_url":"https://api.github.com/repos/aodn/geoserver-build/pulls/comments{/number}","comments_url":"https://api.github.com/repos/aodn/geoserver-build/issues/123/comments","statuses_url":"https://api.github.com/repos/aodn/geoserver-build/statuses/741c0bf85e5792b843ab9bd21e70830789d90057","head":{"label":"aodn:csv_output_ggd","ref":"csv_output_ggd","sha":"741c0bf85e5792b843ab9bd21e70830789d90057","user":{"login":"aodn","id":2802166,"avatar_url":"https://avatars.githubusercontent.com/u/2802166?v=3","gravatar_id":"","url":"https://api.github.com/users/aodn","html_url":"https://github.com/aodn","followers_url":"https://api.github.com/users/aodn/followers","following_url":"https://api.github.com/users/aodn/following{/other_user}","gists_url":"https://api.github.com/users/aodn/gists{/gist_id}","starred_url":"https://api.github.com/users/aodn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aodn/subscriptions","organizations_url":"https://api.github.com/users/aodn/orgs","repos_url":"https://api.github.com/users/aodn/repos","events_url":"https://api.github.com/users/aodn/events{/privacy}","received_events_url":"https://api.github.com/users/aodn/received_events","type":"Organization","site_admin":false},"repo":{"id":17969422,"name":"geoserver-build","full_name":"aodn/geoserver-build","owner":{"login":"aodn","id":2802166,"avatar_url":"https://avatars.githubusercontent.com/u/2802166?v=3","gravatar_id":"","url":"https://api.github.com/users/aodn","html_url":"https://github.com/aodn","followers_url":"https://api.github.com/users/aodn/followers","following_url":"https://api.github.com/users/aodn/following{/other_user}","gists_url":"https://api.github.com/users/aodn/gists{/gist_id}","starred_url":"https://api.github.com/users/aodn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aodn/subscriptions","organizations_url":"https://api.github.com/users/aodn/orgs","repos_url":"https://api.github.com/users/aodn/repos","events_url":"https://api.github.com/users/aodn/events{/privacy}","received_events_url":"https://api.github.com/users/aodn/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/aodn/geoserver-build","description":"Configures a GeoServer war containing extensions and configuration required by AODN instances","fork":false,"url":"https://api.github.com/repos/aodn/geoserver-build","forks_url":"https://api.github.com/repos/aodn/geoserver-build/forks","keys_url":"https://api.github.com/repos/aodn/geoserver-build/keys{/key_id}","collaborators_url":"https://api.github.com/repos/aodn/geoserver-build/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/aodn/geoserver-build/teams","hooks_url":"https://api.github.com/repos/aodn/geoserver-build/hooks","issue_events_url":"https://api.github.com/repos/aodn/geoserver-build/issues/events{/number}","events_url":"https://api.github.com/repos/aodn/geoserver-build/events","assignees_url":"https://api.github.com/repos/aodn/geoserver-build/assignees{/user}","branches_url":"https://api.github.com/repos/aodn/geoserver-build/branches{/branch}","tags_url":"https://api.github.com/repos/aodn/geoserver-build/tags","blobs_url":"https://api.github.com/repos/aodn/geoserver-build/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/aodn/geoserver-build/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/aodn/geoserver-build/git/refs{/sha}","trees_url":"https://api.github.com/repos/aodn/geoserver-build/git/trees{/sha}","statuses_url":"https://api.github.com/repos/aodn/geoserver-build/statuses/{sha}","languages_url":"https://api.github.com/repos/aodn/geoserver-build/languages","stargazers_url":"https://api.github.com/repos/aodn/geoserver-build/stargazers","contributors_url":"https://api.github.com/repos/aodn/geoserver-build/contributors","subscribers_url":"https://api.github.com/repos/aodn/geoserver-build/subscribers","subscription_url":"https://api.github.com/repos/aodn/geoserver-build/subscription","commits_url":"https://api.github.com/repos/aodn/geoserver-build/commits{/sha}","git_commits_url":"https://api.github.com/repos/aodn/geoserver-build/git/commits{/sha}","comments_url":"https://api.github.com/repos/aodn/geoserver-build/comments{/number}","issue_comment_url":"https://api.github.com/repos/aodn/geoserver-build/issues/comments{/number}","contents_url":"https://api.github.com/repos/aodn/geoserver-build/contents/{+path}","compare_url":"https://api.github.com/repos/aodn/geoserver-build/compare/{base}...{head}","merges_url":"https://api.github.com/repos/aodn/geoserver-build/merges","archive_url":"https://api.github.com/repos/aodn/geoserver-build/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/aodn/geoserver-build/downloads","issues_url":"https://api.github.com/repos/aodn/geoserver-build/issues{/number}","pulls_url":"https://api.github.com/repos/aodn/geoserver-build/pulls{/number}","milestones_url":"https://api.github.com/repos/aodn/geoserver-build/milestones{/number}","notifications_url":"https://api.github.com/repos/aodn/geoserver-build/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/aodn/geoserver-build/labels{/name}","releases_url":"https://api.github.com/repos/aodn/geoserver-build/releases{/id}","deployments_url":"https://api.github.com/repos/aodn/geoserver-build/deployments","created_at":"2014-03-21T05:33:53Z","updated_at":"2016-01-28T05:47:42Z","pushed_at":"2016-03-08T04:36:51Z","git_url":"git://github.com/aodn/geoserver-build.git","ssh_url":"git@github.com:aodn/geoserver-build.git","clone_url":"https://github.com/aodn/geoserver-build.git","svn_url":"https://github.com/aodn/geoserver-build","homepage":null,"size":5249,"stargazers_count":1,"watchers_count":1,"language":"SQLPL","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":13,"forks":1,"open_issues":13,"watchers":1,"default_branch":"master"}},"base":{"label":"aodn:master","ref":"master","sha":"267dbb0a0078bf6becf5c5fbb6e1c9b0d4d291d3","user":{"login":"aodn","id":2802166,"avatar_url":"https://avatars.githubusercontent.com/u/2802166?v=3","gravatar_id":"","url":"https://api.github.com/users/aodn","html_url":"https://github.com/aodn","followers_url":"https://api.github.com/users/aodn/followers","following_url":"https://api.github.com/users/aodn/following{/other_user}","gists_url":"https://api.github.com/users/aodn/gists{/gist_id}","starred_url":"https://api.github.com/users/aodn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aodn/subscriptions","organizations_url":"https://api.github.com/users/aodn/orgs","repos_url":"https://api.github.com/users/aodn/repos","events_url":"https://api.github.com/users/aodn/events{/privacy}","received_events_url":"https://api.github.com/users/aodn/received_events","type":"Organization","site_admin":false},"repo":{"id":17969422,"name":"geoserver-build","full_name":"aodn/geoserver-build","owner":{"login":"aodn","id":2802166,"avatar_url":"https://avatars.githubusercontent.com/u/2802166?v=3","gravatar_id":"","url":"https://api.github.com/users/aodn","html_url":"https://github.com/aodn","followers_url":"https://api.github.com/users/aodn/followers","following_url":"https://api.github.com/users/aodn/following{/other_user}","gists_url":"https://api.github.com/users/aodn/gists{/gist_id}","starred_url":"https://api.github.com/users/aodn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aodn/subscriptions","organizations_url":"https://api.github.com/users/aodn/orgs","repos_url":"https://api.github.com/users/aodn/repos","events_url":"https://api.github.com/users/aodn/events{/privacy}","received_events_url":"https://api.github.com/users/aodn/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/aodn/geoserver-build","description":"Configures a GeoServer war containing extensions and configuration required by AODN instances","fork":false,"url":"https://api.github.com/repos/aodn/geoserver-build","forks_url":"https://api.github.com/repos/aodn/geoserver-build/forks","keys_url":"https://api.github.com/repos/aodn/geoserver-build/keys{/key_id}","collaborators_url":"https://api.github.com/repos/aodn/geoserver-build/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/aodn/geoserver-build/teams","hooks_url":"https://api.github.com/repos/aodn/geoserver-build/hooks","issue_events_url":"https://api.github.com/repos/aodn/geoserver-build/issues/events{/number}","events_url":"https://api.github.com/repos/aodn/geoserver-build/events","assignees_url":"https://api.github.com/repos/aodn/geoserver-build/assignees{/user}","branches_url":"https://api.github.com/repos/aodn/geoserver-build/branches{/branch}","tags_url":"https://api.github.com/repos/aodn/geoserver-build/tags","blobs_url":"https://api.github.com/repos/aodn/geoserver-build/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/aodn/geoserver-build/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/aodn/geoserver-build/git/refs{/sha}","trees_url":"https://api.github.com/repos/aodn/geoserver-build/git/trees{/sha}","statuses_url":"https://api.github.com/repos/aodn/geoserver-build/statuses/{sha}","languages_url":"https://api.github.com/repos/aodn/geoserver-build/languages","stargazers_url":"https://api.github.com/repos/aodn/geoserver-build/stargazers","contributors_url":"https://api.github.com/repos/aodn/geoserver-build/contributors","subscribers_url":"https://api.github.com/repos/aodn/geoserver-build/subscribers","subscription_url":"https://api.github.com/repos/aodn/geoserver-build/subscription","commits_url":"https://api.github.com/repos/aodn/geoserver-build/commits{/sha}","git_commits_url":"https://api.github.com/repos/aodn/geoserver-build/git/commits{/sha}","comments_url":"https://api.github.com/repos/aodn/geoserver-build/comments{/number}","issue_comment_url":"https://api.github.com/repos/aodn/geoserver-build/issues/comments{/number}","contents_url":"https://api.github.com/repos/aodn/geoserver-build/contents/{+path}","compare_url":"https://api.github.com/repos/aodn/geoserver-build/compare/{base}...{head}","merges_url":"https://api.github.com/repos/aodn/geoserver-build/merges","archive_url":"https://api.github.com/repos/aodn/geoserver-build/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/aodn/geoserver-build/downloads","issues_url":"https://api.github.com/repos/aodn/geoserver-build/issues{/number}","pulls_url":"https://api.github.com/repos/aodn/geoserver-build/pulls{/number}","milestones_url":"https://api.github.com/repos/aodn/geoserver-build/milestones{/number}","notifications_url":"https://api.github.com/repos/aodn/geoserver-build/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/aodn/geoserver-build/labels{/name}","releases_url":"https://api.github.com/repos/aodn/geoserver-build/releases{/id}","deployments_url":"https://api.github.com/repos/aodn/geoserver-build/deployments","created_at":"2014-03-21T05:33:53Z","updated_at":"2016-01-28T05:47:42Z","pushed_at":"2016-03-08T04:36:51Z","git_url":"git://github.com/aodn/geoserver-build.git","ssh_url":"git@github.com:aodn/geoserver-build.git","clone_url":"https://github.com/aodn/geoserver-build.git","svn_url":"https://github.com/aodn/geoserver-build","homepage":null,"size":5249,"stargazers_count":1,"watchers_count":1,"language":"SQLPL","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":13,"forks":1,"open_issues":13,"watchers":1,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/aodn/geoserver-build/pulls/123"},"html":{"href":"https://github.com/aodn/geoserver-build/pull/123"},"issue":{"href":"https://api.github.com/repos/aodn/geoserver-build/issues/123"},"comments":{"href":"https://api.github.com/repos/aodn/geoserver-build/issues/123/comments"},"review_comments":{"href":"https://api.github.com/repos/aodn/geoserver-build/pulls/123/comments"},"review_comment":{"href":"https://api.github.com/repos/aodn/geoserver-build/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/aodn/geoserver-build/pulls/123/commits"},"statuses":{"href":"https://api.github.com/repos/aodn/geoserver-build/statuses/741c0bf85e5792b843ab9bd21e70830789d90057"}}}}