{"action":"created","comment":{"url":"https://api.github.com/repos/syndesisio/syndesis-qe/pulls/comments/173105659","pull_request_review_id":102236345,"id":173105659,"diff_hunk":"@@ -0,0 +1,92 @@\n+package io.syndesis.qe.utils;\n+\n+import com.dropbox.core.DbxException;\n+import com.dropbox.core.DbxRequestConfig;\n+import com.dropbox.core.v2.DbxClientV2;\n+import com.dropbox.core.v2.files.FileMetadata;\n+import com.dropbox.core.v2.files.GetMetadataErrorException;\n+import io.syndesis.qe.accounts.Account;\n+import io.syndesis.qe.accounts.AccountsDirectory;\n+import javassist.tools.rmi.ObjectNotFoundException;\n+import lombok.extern.slf4j.Slf4j;\n+import org.springframework.stereotype.Component;\n+\n+import java.io.BufferedWriter;\n+import java.io.File;\n+import java.io.FileInputStream;\n+import java.io.FileWriter;\n+import java.io.IOException;\n+import java.io.InputStream;\n+import java.util.Optional;\n+\n+@Slf4j\n+@Component\n+public class DropBoxUtils {\n+    private final DbxClientV2 client;\n+\n+    public DropBoxUtils() throws ObjectNotFoundException, DbxException {\n+        Optional<Account> optional = AccountsDirectory.getInstance().getAccount(\"QE Dropbox\");\n+\n+        if (optional.isPresent()) {\n+            DbxRequestConfig config = new DbxRequestConfig(optional.get().getProperty(\"clientIdentifier\"));\n+            this.client = new DbxClientV2(config, optional.get().getProperty(\"accessToken\"));\n+        } else {\n+            throw new ObjectNotFoundException(\"DropBox credentials were not found.\");\n+        }\n+        log.info(\"DropBox client created, logged as: \" + client.users().getCurrentAccount());\n+    }\n+\n+    /**\n+     * Check if file with filePath exists - dropbox uses its own file structure\n+     *\n+     * @param filePath example: filePath = /folder/file.name\n+     * @return true if file exists\n+     */\n+    public boolean checkIfFileExists(String filePath) {\n+        boolean found = true;\n+        try {\n+            client.files().getMetadata(filePath);\n+        } catch (GetMetadataErrorException exception) {\n+            if (exception.errorValue.isPath() && exception.errorValue.getPathValue().isNotFound()) {\n+                found = false;\n+            }\n+        } catch (DbxException e) {\n+            e.printStackTrace();\n+            found = false;\n+        }\n+        return found;\n+    }\n+\n+    /**\n+     * Example: deleteFile(\"/someFolder/file.name\")\n+     *\n+     * @param filePath\n+     * @throws DbxException\n+     */\n+    public void deleteFile(String filePath) throws DbxException {\n+        client.files().deleteV2(filePath);\n+    }\n+\n+    /**\n+     * Example: uploadFile(\"/someFolder/file.name\", \"whatever Text You Want Inside\")\n+     *\n+     * @param filePath\n+     * @param text\n+     * @throws IOException\n+     * @throws DbxException\n+     */\n+    public void uploadFile(String filePath, String text) throws IOException, DbxException {\n+        try {","path":"utilities/src/main/java/io/syndesis/qe/utils/DropBoxUtils.java","position":84,"original_position":79,"commit_id":"538eb91d36da7225fd1f290a4a2ac0af32590e87","original_commit_id":"994e020192d59cb0569c665be9c07a8d1094c2cc","user":{"login":"mcada","id":14313995,"avatar_url":"https://avatars1.githubusercontent.com/u/14313995?v=4","gravatar_id":"","url":"https://api.github.com/users/mcada","html_url":"https://github.com/mcada","followers_url":"https://api.github.com/users/mcada/followers","following_url":"https://api.github.com/users/mcada/following{/other_user}","gists_url":"https://api.github.com/users/mcada/gists{/gist_id}","starred_url":"https://api.github.com/users/mcada/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mcada/subscriptions","organizations_url":"https://api.github.com/users/mcada/orgs","repos_url":"https://api.github.com/users/mcada/repos","events_url":"https://api.github.com/users/mcada/events{/privacy}","received_events_url":"https://api.github.com/users/mcada/received_events","type":"User","site_admin":false},"body":"I am stupid, I was trying to autoclose temp file instead of streams and ofc it does not support that structure as there is nothing to close...\r\n\r\nWhat about this:\r\n```\r\n        File temp = File.createTempFile(filePath, \"\");\r\n        try (BufferedWriter bw = new BufferedWriter(new FileWriter(temp))) {\r\n            temp.deleteOnExit();\r\n            bw.write(text);\r\n            bw.flush();\r\n            try (InputStream is = new FileInputStream(temp)) {\r\n                client.files().uploadBuilder(filePath)\r\n                        .uploadAndFinish(is);\r\n\r\n                log.debug(\"Text inside new file: {}\", is.toString());\r\n            }\r\n        } catch (IOException ex) {\r\n            log.error(\"Error with tmp file: \" + ex);\r\n        }\r\n```","created_at":"2018-03-08T09:35:58Z","updated_at":"2018-03-08T09:35:58Z","html_url":"https://github.com/syndesisio/syndesis-qe/pull/343#discussion_r173105659","pull_request_url":"https://api.github.com/repos/syndesisio/syndesis-qe/pulls/343","author_association":"CONTRIBUTOR","_links":{"self":{"href":"https://api.github.com/repos/syndesisio/syndesis-qe/pulls/comments/173105659"},"html":{"href":"https://github.com/syndesisio/syndesis-qe/pull/343#discussion_r173105659"},"pull_request":{"href":"https://api.github.com/repos/syndesisio/syndesis-qe/pulls/343"}},"in_reply_to_id":172890861},"pull_request":{"url":"https://api.github.com/repos/syndesisio/syndesis-qe/pulls/343","id":173490258,"html_url":"https://github.com/syndesisio/syndesis-qe/pull/343","diff_url":"https://github.com/syndesisio/syndesis-qe/pull/343.diff","patch_url":"https://github.com/syndesisio/syndesis-qe/pull/343.patch","issue_url":"https://api.github.com/repos/syndesisio/syndesis-qe/issues/343","number":343,"state":"open","locked":false,"title":"Created test for dropbox connection","user":{"login":"mcada","id":14313995,"avatar_url":"https://avatars1.githubusercontent.com/u/14313995?v=4","gravatar_id":"","url":"https://api.github.com/users/mcada","html_url":"https://github.com/mcada","followers_url":"https://api.github.com/users/mcada/followers","following_url":"https://api.github.com/users/mcada/following{/other_user}","gists_url":"https://api.github.com/users/mcada/gists{/gist_id}","starred_url":"https://api.github.com/users/mcada/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mcada/subscriptions","organizations_url":"https://api.github.com/users/mcada/orgs","repos_url":"https://api.github.com/users/mcada/repos","events_url":"https://api.github.com/users/mcada/events{/privacy}","received_events_url":"https://api.github.com/users/mcada/received_events","type":"User","site_admin":false},"body":"https://github.com/syndesisio/syndesis-qe/issues/311","created_at":"2018-03-07T15:43:27Z","updated_at":"2018-03-08T09:35:58Z","closed_at":null,"merged_at":null,"merge_commit_sha":"c266a3a69e79eecbd201790211d356761648ce72","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/syndesisio/syndesis-qe/pulls/343/commits","review_comments_url":"https://api.github.com/repos/syndesisio/syndesis-qe/pulls/343/comments","review_comment_url":"https://api.github.com/repos/syndesisio/syndesis-qe/pulls/comments{/number}","comments_url":"https://api.github.com/repos/syndesisio/syndesis-qe/issues/343/comments","statuses_url":"https://api.github.com/repos/syndesisio/syndesis-qe/statuses/538eb91d36da7225fd1f290a4a2ac0af32590e87","head":{"label":"mcada:dropboxConnectorTest","ref":"dropboxConnectorTest","sha":"538eb91d36da7225fd1f290a4a2ac0af32590e87","user":{"login":"mcada","id":14313995,"avatar_url":"https://avatars1.githubusercontent.com/u/14313995?v=4","gravatar_id":"","url":"https://api.github.com/users/mcada","html_url":"https://github.com/mcada","followers_url":"https://api.github.com/users/mcada/followers","following_url":"https://api.github.com/users/mcada/following{/other_user}","gists_url":"https://api.github.com/users/mcada/gists{/gist_id}","starred_url":"https://api.github.com/users/mcada/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mcada/subscriptions","organizations_url":"https://api.github.com/users/mcada/orgs","repos_url":"https://api.github.com/users/mcada/repos","events_url":"https://api.github.com/users/mcada/events{/privacy}","received_events_url":"https://api.github.com/users/mcada/received_events","type":"User","site_admin":false},"repo":{"id":108544438,"name":"syndesis-qe","full_name":"mcada/syndesis-qe","owner":{"login":"mcada","id":14313995,"avatar_url":"https://avatars1.githubusercontent.com/u/14313995?v=4","gravatar_id":"","url":"https://api.github.com/users/mcada","html_url":"https://github.com/mcada","followers_url":"https://api.github.com/users/mcada/followers","following_url":"https://api.github.com/users/mcada/following{/other_user}","gists_url":"https://api.github.com/users/mcada/gists{/gist_id}","starred_url":"https://api.github.com/users/mcada/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mcada/subscriptions","organizations_url":"https://api.github.com/users/mcada/orgs","repos_url":"https://api.github.com/users/mcada/repos","events_url":"https://api.github.com/users/mcada/events{/privacy}","received_events_url":"https://api.github.com/users/mcada/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/mcada/syndesis-qe","description":null,"fork":true,"url":"https://api.github.com/repos/mcada/syndesis-qe","forks_url":"https://api.github.com/repos/mcada/syndesis-qe/forks","keys_url":"https://api.github.com/repos/mcada/syndesis-qe/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mcada/syndesis-qe/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mcada/syndesis-qe/teams","hooks_url":"https://api.github.com/repos/mcada/syndesis-qe/hooks","issue_events_url":"https://api.github.com/repos/mcada/syndesis-qe/issues/events{/number}","events_url":"https://api.github.com/repos/mcada/syndesis-qe/events","assignees_url":"https://api.github.com/repos/mcada/syndesis-qe/assignees{/user}","branches_url":"https://api.github.com/repos/mcada/syndesis-qe/branches{/branch}","tags_url":"https://api.github.com/repos/mcada/syndesis-qe/tags","blobs_url":"https://api.github.com/repos/mcada/syndesis-qe/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mcada/syndesis-qe/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mcada/syndesis-qe/git/refs{/sha}","trees_url":"https://api.github.com/repos/mcada/syndesis-qe/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mcada/syndesis-qe/statuses/{sha}","languages_url":"https://api.github.com/repos/mcada/syndesis-qe/languages","stargazers_url":"https://api.github.com/repos/mcada/syndesis-qe/stargazers","contributors_url":"https://api.github.com/repos/mcada/syndesis-qe/contributors","subscribers_url":"https://api.github.com/repos/mcada/syndesis-qe/subscribers","subscription_url":"https://api.github.com/repos/mcada/syndesis-qe/subscription","commits_url":"https://api.github.com/repos/mcada/syndesis-qe/commits{/sha}","git_commits_url":"https://api.github.com/repos/mcada/syndesis-qe/git/commits{/sha}","comments_url":"https://api.github.com/repos/mcada/syndesis-qe/comments{/number}","issue_comment_url":"https://api.github.com/repos/mcada/syndesis-qe/issues/comments{/number}","contents_url":"https://api.github.com/repos/mcada/syndesis-qe/contents/{+path}","compare_url":"https://api.github.com/repos/mcada/syndesis-qe/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mcada/syndesis-qe/merges","archive_url":"https://api.github.com/repos/mcada/syndesis-qe/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mcada/syndesis-qe/downloads","issues_url":"https://api.github.com/repos/mcada/syndesis-qe/issues{/number}","pulls_url":"https://api.github.com/repos/mcada/syndesis-qe/pulls{/number}","milestones_url":"https://api.github.com/repos/mcada/syndesis-qe/milestones{/number}","notifications_url":"https://api.github.com/repos/mcada/syndesis-qe/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mcada/syndesis-qe/labels{/name}","releases_url":"https://api.github.com/repos/mcada/syndesis-qe/releases{/id}","deployments_url":"https://api.github.com/repos/mcada/syndesis-qe/deployments","created_at":"2017-10-27T12:39:18Z","updated_at":"2017-11-16T10:44:34Z","pushed_at":"2018-03-07T17:35:11Z","git_url":"git://github.com/mcada/syndesis-qe.git","ssh_url":"git@github.com:mcada/syndesis-qe.git","clone_url":"https://github.com/mcada/syndesis-qe.git","svn_url":"https://github.com/mcada/syndesis-qe","homepage":null,"size":16808,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":0,"license":{"key":"apache-2.0","name":"Apache License 2.0","spdx_id":"Apache-2.0","url":"https://api.github.com/licenses/apache-2.0"},"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"syndesisio:master","ref":"master","sha":"a388aeed6a2b41cdb5553637282c895cd9118e04","user":{"login":"syndesisio","id":23079786,"avatar_url":"https://avatars3.githubusercontent.com/u/23079786?v=4","gravatar_id":"","url":"https://api.github.com/users/syndesisio","html_url":"https://github.com/syndesisio","followers_url":"https://api.github.com/users/syndesisio/followers","following_url":"https://api.github.com/users/syndesisio/following{/other_user}","gists_url":"https://api.github.com/users/syndesisio/gists{/gist_id}","starred_url":"https://api.github.com/users/syndesisio/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/syndesisio/subscriptions","organizations_url":"https://api.github.com/users/syndesisio/orgs","repos_url":"https://api.github.com/users/syndesisio/repos","events_url":"https://api.github.com/users/syndesisio/events{/privacy}","received_events_url":"https://api.github.com/users/syndesisio/received_events","type":"Organization","site_admin":false},"repo":{"id":92716590,"name":"syndesis-qe","full_name":"syndesisio/syndesis-qe","owner":{"login":"syndesisio","id":23079786,"avatar_url":"https://avatars3.githubusercontent.com/u/23079786?v=4","gravatar_id":"","url":"https://api.github.com/users/syndesisio","html_url":"https://github.com/syndesisio","followers_url":"https://api.github.com/users/syndesisio/followers","following_url":"https://api.github.com/users/syndesisio/following{/other_user}","gists_url":"https://api.github.com/users/syndesisio/gists{/gist_id}","starred_url":"https://api.github.com/users/syndesisio/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/syndesisio/subscriptions","organizations_url":"https://api.github.com/users/syndesisio/orgs","repos_url":"https://api.github.com/users/syndesisio/repos","events_url":"https://api.github.com/users/syndesisio/events{/privacy}","received_events_url":"https://api.github.com/users/syndesisio/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/syndesisio/syndesis-qe","description":null,"fork":false,"url":"https://api.github.com/repos/syndesisio/syndesis-qe","forks_url":"https://api.github.com/repos/syndesisio/syndesis-qe/forks","keys_url":"https://api.github.com/repos/syndesisio/syndesis-qe/keys{/key_id}","collaborators_url":"https://api.github.com/repos/syndesisio/syndesis-qe/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/syndesisio/syndesis-qe/teams","hooks_url":"https://api.github.com/repos/syndesisio/syndesis-qe/hooks","issue_events_url":"https://api.github.com/repos/syndesisio/syndesis-qe/issues/events{/number}","events_url":"https://api.github.com/repos/syndesisio/syndesis-qe/events","assignees_url":"https://api.github.com/repos/syndesisio/syndesis-qe/assignees{/user}","branches_url":"https://api.github.com/repos/syndesisio/syndesis-qe/branches{/branch}","tags_url":"https://api.github.com/repos/syndesisio/syndesis-qe/tags","blobs_url":"https://api.github.com/repos/syndesisio/syndesis-qe/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/syndesisio/syndesis-qe/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/syndesisio/syndesis-qe/git/refs{/sha}","trees_url":"https://api.github.com/repos/syndesisio/syndesis-qe/git/trees{/sha}","statuses_url":"https://api.github.com/repos/syndesisio/syndesis-qe/statuses/{sha}","languages_url":"https://api.github.com/repos/syndesisio/syndesis-qe/languages","stargazers_url":"https://api.github.com/repos/syndesisio/syndesis-qe/stargazers","contributors_url":"https://api.github.com/repos/syndesisio/syndesis-qe/contributors","subscribers_url":"https://api.github.com/repos/syndesisio/syndesis-qe/subscribers","subscription_url":"https://api.github.com/repos/syndesisio/syndesis-qe/subscription","commits_url":"https://api.github.com/repos/syndesisio/syndesis-qe/commits{/sha}","git_commits_url":"https://api.github.com/repos/syndesisio/syndesis-qe/git/commits{/sha}","comments_url":"https://api.github.com/repos/syndesisio/syndesis-qe/comments{/number}","issue_comment_url":"https://api.github.com/repos/syndesisio/syndesis-qe/issues/comments{/number}","contents_url":"https://api.github.com/repos/syndesisio/syndesis-qe/contents/{+path}","compare_url":"https://api.github.com/repos/syndesisio/syndesis-qe/compare/{base}...{head}","merges_url":"https://api.github.com/repos/syndesisio/syndesis-qe/merges","archive_url":"https://api.github.com/repos/syndesisio/syndesis-qe/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/syndesisio/syndesis-qe/downloads","issues_url":"https://api.github.com/repos/syndesisio/syndesis-qe/issues{/number}","pulls_url":"https://api.github.com/repos/syndesisio/syndesis-qe/pulls{/number}","milestones_url":"https://api.github.com/repos/syndesisio/syndesis-qe/milestones{/number}","notifications_url":"https://api.github.com/repos/syndesisio/syndesis-qe/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/syndesisio/syndesis-qe/labels{/name}","releases_url":"https://api.github.com/repos/syndesisio/syndesis-qe/releases{/id}","deployments_url":"https://api.github.com/repos/syndesisio/syndesis-qe/deployments","created_at":"2017-05-29T07:27:50Z","updated_at":"2017-11-15T17:30:48Z","pushed_at":"2018-03-08T09:27:27Z","git_url":"git://github.com/syndesisio/syndesis-qe.git","ssh_url":"git@github.com:syndesisio/syndesis-qe.git","clone_url":"https://github.com/syndesisio/syndesis-qe.git","svn_url":"https://github.com/syndesisio/syndesis-qe","homepage":null,"size":16808,"stargazers_count":2,"watchers_count":2,"language":"Java","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":10,"mirror_url":null,"archived":false,"open_issues_count":17,"license":{"key":"apache-2.0","name":"Apache License 2.0","spdx_id":"Apache-2.0","url":"https://api.github.com/licenses/apache-2.0"},"forks":10,"open_issues":17,"watchers":2,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/syndesisio/syndesis-qe/pulls/343"},"html":{"href":"https://github.com/syndesisio/syndesis-qe/pull/343"},"issue":{"href":"https://api.github.com/repos/syndesisio/syndesis-qe/issues/343"},"comments":{"href":"https://api.github.com/repos/syndesisio/syndesis-qe/issues/343/comments"},"review_comments":{"href":"https://api.github.com/repos/syndesisio/syndesis-qe/pulls/343/comments"},"review_comment":{"href":"https://api.github.com/repos/syndesisio/syndesis-qe/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/syndesisio/syndesis-qe/pulls/343/commits"},"statuses":{"href":"https://api.github.com/repos/syndesisio/syndesis-qe/statuses/538eb91d36da7225fd1f290a4a2ac0af32590e87"}},"author_association":"CONTRIBUTOR"}}
{"actor":{"display_login":"mcada"}}