{"action":"created","comment":{"url":"https://api.github.com/repos/dimagi/commcare-odk/pulls/comments/59381773","id":59381773,"diff_hunk":"@@ -595,21 +599,51 @@ public void prepareFileTransfer() {\n             myStatusText.setText(localize(\"wifi.direct.no.group\"));\r\n             return;\r\n         }\r\n+        moveFormRecordsToFiles();\r\n+    }\r\n \r\n-        zipFiles();\r\n+    private void moveReceivedFiles() {\r\n+        File receiveFolder = new File(toBeSubmittedDirectory);\r\n+        if (!receiveFolder.isDirectory() || !receiveFolder.exists()) {\r\n+            // we haven't received any transfers, just return.\r\n+            return;\r\n+        }\r\n+        // We've received transferred forms. Move them into the to be zipped directory.\r\n+        File[] files = receiveFolder.listFiles();\r\n+        try {\r\n+            Log.d(TAG, \"We have \" + files.length + \" toBeSubmitted files to transfer\");\r\n+            for (File instanceDirectory : files) {\r\n+                FileUtil.copyFileDeep(instanceDirectory,\r\n+                        new File(toBeTransferredDirectory, instanceDirectory.getName()));\r\n+                Log.d(TAG, \"Transferred \" + instanceDirectory + \" to \" + toBeTransferredDirectory\r\n+                        + \"/\" + instanceDirectory.getName());\r\n+            }\r\n+        } catch(IOException e){\r\n+            // if we catch an error, delete all the new files we've copied over\r\n+            for (File instanceDirectory : files) {\r\n+                File newDestination = new File(toBeTransferredDirectory, instanceDirectory.getName());\r\n+                if(newDestination.exists()){\r\n+                    FileUtil.deleteFileOrDir(newDestination);\r\n+                }\r\n+            }\r\n+        }\r\n+        // Delete all the to be submitted files, we have them copied for transfer.\r\n+        for (File instanceDirectory : files) {\r\n+            if(instanceDirectory.exists()){\r\n+                FileUtil.deleteFileOrDir(instanceDirectory);\r\n+            }\r\n+        }\r","path":"app/src/org/commcare/activities/CommCareWiFiDirectActivity.java","position":140,"original_position":140,"commit_id":"b0b1128579ac9976219948a73f6695a63c842eb6","original_commit_id":"b0b1128579ac9976219948a73f6695a63c842eb6","user":{"login":"phillipm","id":94817,"avatar_url":"https://avatars.githubusercontent.com/u/94817?v=3","gravatar_id":"","url":"https://api.github.com/users/phillipm","html_url":"https://github.com/phillipm","followers_url":"https://api.github.com/users/phillipm/followers","following_url":"https://api.github.com/users/phillipm/following{/other_user}","gists_url":"https://api.github.com/users/phillipm/gists{/gist_id}","starred_url":"https://api.github.com/users/phillipm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/phillipm/subscriptions","organizations_url":"https://api.github.com/users/phillipm/orgs","repos_url":"https://api.github.com/users/phillipm/repos","events_url":"https://api.github.com/users/phillipm/events{/privacy}","received_events_url":"https://api.github.com/users/phillipm/received_events","type":"User","site_admin":false},"body":"If you follow the advice above, then you can lift the 3 `for` loops in this method into a helper method that essentially looks like this loop, just taking in a `File[] files` param","created_at":"2016-04-12T14:07:12Z","updated_at":"2016-04-12T14:07:12Z","html_url":"https://github.com/dimagi/commcare-odk/pull/1114#discussion_r59381773","pull_request_url":"https://api.github.com/repos/dimagi/commcare-odk/pulls/1114","_links":{"self":{"href":"https://api.github.com/repos/dimagi/commcare-odk/pulls/comments/59381773"},"html":{"href":"https://github.com/dimagi/commcare-odk/pull/1114#discussion_r59381773"},"pull_request":{"href":"https://api.github.com/repos/dimagi/commcare-odk/pulls/1114"}}},"pull_request":{"url":"https://api.github.com/repos/dimagi/commcare-odk/pulls/1114","id":61836281,"html_url":"https://github.com/dimagi/commcare-odk/pull/1114","diff_url":"https://github.com/dimagi/commcare-odk/pull/1114.diff","patch_url":"https://github.com/dimagi/commcare-odk/pull/1114.patch","issue_url":"https://api.github.com/repos/dimagi/commcare-odk/issues/1114","number":1114,"state":"open","locked":false,"title":"Wifi direct","user":{"login":"wpride","id":2293064,"avatar_url":"https://avatars.githubusercontent.com/u/2293064?v=3","gravatar_id":"","url":"https://api.github.com/users/wpride","html_url":"https://github.com/wpride","followers_url":"https://api.github.com/users/wpride/followers","following_url":"https://api.github.com/users/wpride/following{/other_user}","gists_url":"https://api.github.com/users/wpride/gists{/gist_id}","starred_url":"https://api.github.com/users/wpride/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wpride/subscriptions","organizations_url":"https://api.github.com/users/wpride/orgs","repos_url":"https://api.github.com/users/wpride/repos","events_url":"https://api.github.com/users/wpride/events{/privacy}","received_events_url":"https://api.github.com/users/wpride/received_events","type":"User","site_admin":false},"body":"One major functionality change and a lot of refactor to make this functionality cleaner.\r\n\r\nADRA needs the ability to send forms via Wi-Fi Direct multiple times - IE the tablet collecting the forms via WiFiDirect from the front line workers itself will not ever get connectivity and thus needs to transfer these forms to yet another tablet that will be returned to the home office and sync with the server. This change supports this workflow. Essentially, after pulling any extant FormRecords from the database into the file system, this activity will now check the \"to be submitted\" folder for any forms it previously received via wifi direct. If these are found, we move these into the same folder as the form records we just pulled. Once there, forms from the two sources are functionally equivalent and we can proceed from there. This is accomplished here: https://github.com/dimagi/commcare-odk/compare/wifi-direct?expand=1#diff-1ec3d20f602697a29ebc1680b992c3a3R627\r\n\r\nThe biggest functional refactor is separating the process of moving files from the database to storage and zipping these files into separate tasks so that we can do the step above in between. there's some other cleanup besides. ","created_at":"2016-03-06T07:30:06Z","updated_at":"2016-04-12T14:07:12Z","closed_at":null,"merged_at":null,"merge_commit_sha":"0b4077c1ec01c44ff5af31093b2cf31e9e84c1c2","assignee":null,"milestone":{"url":"https://api.github.com/repos/dimagi/commcare-odk/milestones/8","html_url":"https://github.com/dimagi/commcare-odk/milestones/commcare_2.28","labels_url":"https://api.github.com/repos/dimagi/commcare-odk/milestones/8/labels","id":1652574,"number":8,"title":"commcare_2.28","description":null,"creator":{"login":"phillipm","id":94817,"avatar_url":"https://avatars.githubusercontent.com/u/94817?v=3","gravatar_id":"","url":"https://api.github.com/users/phillipm","html_url":"https://github.com/phillipm","followers_url":"https://api.github.com/users/phillipm/followers","following_url":"https://api.github.com/users/phillipm/following{/other_user}","gists_url":"https://api.github.com/users/phillipm/gists{/gist_id}","starred_url":"https://api.github.com/users/phillipm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/phillipm/subscriptions","organizations_url":"https://api.github.com/users/phillipm/orgs","repos_url":"https://api.github.com/users/phillipm/repos","events_url":"https://api.github.com/users/phillipm/events{/privacy}","received_events_url":"https://api.github.com/users/phillipm/received_events","type":"User","site_admin":false},"open_issues":8,"closed_issues":20,"state":"open","created_at":"2016-03-18T01:54:03Z","updated_at":"2016-04-11T18:47:18Z","due_on":null,"closed_at":null},"commits_url":"https://api.github.com/repos/dimagi/commcare-odk/pulls/1114/commits","review_comments_url":"https://api.github.com/repos/dimagi/commcare-odk/pulls/1114/comments","review_comment_url":"https://api.github.com/repos/dimagi/commcare-odk/pulls/comments{/number}","comments_url":"https://api.github.com/repos/dimagi/commcare-odk/issues/1114/comments","statuses_url":"https://api.github.com/repos/dimagi/commcare-odk/statuses/b0b1128579ac9976219948a73f6695a63c842eb6","head":{"label":"dimagi:wifi-direct","ref":"wifi-direct","sha":"b0b1128579ac9976219948a73f6695a63c842eb6","user":{"login":"dimagi","id":94514,"avatar_url":"https://avatars.githubusercontent.com/u/94514?v=3","gravatar_id":"","url":"https://api.github.com/users/dimagi","html_url":"https://github.com/dimagi","followers_url":"https://api.github.com/users/dimagi/followers","following_url":"https://api.github.com/users/dimagi/following{/other_user}","gists_url":"https://api.github.com/users/dimagi/gists{/gist_id}","starred_url":"https://api.github.com/users/dimagi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dimagi/subscriptions","organizations_url":"https://api.github.com/users/dimagi/orgs","repos_url":"https://api.github.com/users/dimagi/repos","events_url":"https://api.github.com/users/dimagi/events{/privacy}","received_events_url":"https://api.github.com/users/dimagi/received_events","type":"Organization","site_admin":false},"repo":{"id":20939877,"name":"commcare-odk","full_name":"dimagi/commcare-odk","owner":{"login":"dimagi","id":94514,"avatar_url":"https://avatars.githubusercontent.com/u/94514?v=3","gravatar_id":"","url":"https://api.github.com/users/dimagi","html_url":"https://github.com/dimagi","followers_url":"https://api.github.com/users/dimagi/followers","following_url":"https://api.github.com/users/dimagi/following{/other_user}","gists_url":"https://api.github.com/users/dimagi/gists{/gist_id}","starred_url":"https://api.github.com/users/dimagi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dimagi/subscriptions","organizations_url":"https://api.github.com/users/dimagi/orgs","repos_url":"https://api.github.com/users/dimagi/repos","events_url":"https://api.github.com/users/dimagi/events{/privacy}","received_events_url":"https://api.github.com/users/dimagi/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/dimagi/commcare-odk","description":"The best open source form management tool in town","fork":false,"url":"https://api.github.com/repos/dimagi/commcare-odk","forks_url":"https://api.github.com/repos/dimagi/commcare-odk/forks","keys_url":"https://api.github.com/repos/dimagi/commcare-odk/keys{/key_id}","collaborators_url":"https://api.github.com/repos/dimagi/commcare-odk/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/dimagi/commcare-odk/teams","hooks_url":"https://api.github.com/repos/dimagi/commcare-odk/hooks","issue_events_url":"https://api.github.com/repos/dimagi/commcare-odk/issues/events{/number}","events_url":"https://api.github.com/repos/dimagi/commcare-odk/events","assignees_url":"https://api.github.com/repos/dimagi/commcare-odk/assignees{/user}","branches_url":"https://api.github.com/repos/dimagi/commcare-odk/branches{/branch}","tags_url":"https://api.github.com/repos/dimagi/commcare-odk/tags","blobs_url":"https://api.github.com/repos/dimagi/commcare-odk/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/dimagi/commcare-odk/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/dimagi/commcare-odk/git/refs{/sha}","trees_url":"https://api.github.com/repos/dimagi/commcare-odk/git/trees{/sha}","statuses_url":"https://api.github.com/repos/dimagi/commcare-odk/statuses/{sha}","languages_url":"https://api.github.com/repos/dimagi/commcare-odk/languages","stargazers_url":"https://api.github.com/repos/dimagi/commcare-odk/stargazers","contributors_url":"https://api.github.com/repos/dimagi/commcare-odk/contributors","subscribers_url":"https://api.github.com/repos/dimagi/commcare-odk/subscribers","subscription_url":"https://api.github.com/repos/dimagi/commcare-odk/subscription","commits_url":"https://api.github.com/repos/dimagi/commcare-odk/commits{/sha}","git_commits_url":"https://api.github.com/repos/dimagi/commcare-odk/git/commits{/sha}","comments_url":"https://api.github.com/repos/dimagi/commcare-odk/comments{/number}","issue_comment_url":"https://api.github.com/repos/dimagi/commcare-odk/issues/comments{/number}","contents_url":"https://api.github.com/repos/dimagi/commcare-odk/contents/{+path}","compare_url":"https://api.github.com/repos/dimagi/commcare-odk/compare/{base}...{head}","merges_url":"https://api.github.com/repos/dimagi/commcare-odk/merges","archive_url":"https://api.github.com/repos/dimagi/commcare-odk/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/dimagi/commcare-odk/downloads","issues_url":"https://api.github.com/repos/dimagi/commcare-odk/issues{/number}","pulls_url":"https://api.github.com/repos/dimagi/commcare-odk/pulls{/number}","milestones_url":"https://api.github.com/repos/dimagi/commcare-odk/milestones{/number}","notifications_url":"https://api.github.com/repos/dimagi/commcare-odk/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/dimagi/commcare-odk/labels{/name}","releases_url":"https://api.github.com/repos/dimagi/commcare-odk/releases{/id}","deployments_url":"https://api.github.com/repos/dimagi/commcare-odk/deployments","created_at":"2014-06-17T21:17:26Z","updated_at":"2016-01-25T13:36:24Z","pushed_at":"2016-04-11T18:53:57Z","git_url":"git://github.com/dimagi/commcare-odk.git","ssh_url":"git@github.com:dimagi/commcare-odk.git","clone_url":"https://github.com/dimagi/commcare-odk.git","svn_url":"https://github.com/dimagi/commcare-odk","homepage":"https://play.google.com/store/apps/details?id=org.commcare.dalvik&hl=en","size":67368,"stargazers_count":6,"watchers_count":6,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":9,"mirror_url":null,"open_issues_count":11,"forks":9,"open_issues":11,"watchers":6,"default_branch":"master"}},"base":{"label":"dimagi:master","ref":"master","sha":"43b1ed2252dc262819e7374292ef2dc6f3ab80fb","user":{"login":"dimagi","id":94514,"avatar_url":"https://avatars.githubusercontent.com/u/94514?v=3","gravatar_id":"","url":"https://api.github.com/users/dimagi","html_url":"https://github.com/dimagi","followers_url":"https://api.github.com/users/dimagi/followers","following_url":"https://api.github.com/users/dimagi/following{/other_user}","gists_url":"https://api.github.com/users/dimagi/gists{/gist_id}","starred_url":"https://api.github.com/users/dimagi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dimagi/subscriptions","organizations_url":"https://api.github.com/users/dimagi/orgs","repos_url":"https://api.github.com/users/dimagi/repos","events_url":"https://api.github.com/users/dimagi/events{/privacy}","received_events_url":"https://api.github.com/users/dimagi/received_events","type":"Organization","site_admin":false},"repo":{"id":20939877,"name":"commcare-odk","full_name":"dimagi/commcare-odk","owner":{"login":"dimagi","id":94514,"avatar_url":"https://avatars.githubusercontent.com/u/94514?v=3","gravatar_id":"","url":"https://api.github.com/users/dimagi","html_url":"https://github.com/dimagi","followers_url":"https://api.github.com/users/dimagi/followers","following_url":"https://api.github.com/users/dimagi/following{/other_user}","gists_url":"https://api.github.com/users/dimagi/gists{/gist_id}","starred_url":"https://api.github.com/users/dimagi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dimagi/subscriptions","organizations_url":"https://api.github.com/users/dimagi/orgs","repos_url":"https://api.github.com/users/dimagi/repos","events_url":"https://api.github.com/users/dimagi/events{/privacy}","received_events_url":"https://api.github.com/users/dimagi/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/dimagi/commcare-odk","description":"The best open source form management tool in town","fork":false,"url":"https://api.github.com/repos/dimagi/commcare-odk","forks_url":"https://api.github.com/repos/dimagi/commcare-odk/forks","keys_url":"https://api.github.com/repos/dimagi/commcare-odk/keys{/key_id}","collaborators_url":"https://api.github.com/repos/dimagi/commcare-odk/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/dimagi/commcare-odk/teams","hooks_url":"https://api.github.com/repos/dimagi/commcare-odk/hooks","issue_events_url":"https://api.github.com/repos/dimagi/commcare-odk/issues/events{/number}","events_url":"https://api.github.com/repos/dimagi/commcare-odk/events","assignees_url":"https://api.github.com/repos/dimagi/commcare-odk/assignees{/user}","branches_url":"https://api.github.com/repos/dimagi/commcare-odk/branches{/branch}","tags_url":"https://api.github.com/repos/dimagi/commcare-odk/tags","blobs_url":"https://api.github.com/repos/dimagi/commcare-odk/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/dimagi/commcare-odk/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/dimagi/commcare-odk/git/refs{/sha}","trees_url":"https://api.github.com/repos/dimagi/commcare-odk/git/trees{/sha}","statuses_url":"https://api.github.com/repos/dimagi/commcare-odk/statuses/{sha}","languages_url":"https://api.github.com/repos/dimagi/commcare-odk/languages","stargazers_url":"https://api.github.com/repos/dimagi/commcare-odk/stargazers","contributors_url":"https://api.github.com/repos/dimagi/commcare-odk/contributors","subscribers_url":"https://api.github.com/repos/dimagi/commcare-odk/subscribers","subscription_url":"https://api.github.com/repos/dimagi/commcare-odk/subscription","commits_url":"https://api.github.com/repos/dimagi/commcare-odk/commits{/sha}","git_commits_url":"https://api.github.com/repos/dimagi/commcare-odk/git/commits{/sha}","comments_url":"https://api.github.com/repos/dimagi/commcare-odk/comments{/number}","issue_comment_url":"https://api.github.com/repos/dimagi/commcare-odk/issues/comments{/number}","contents_url":"https://api.github.com/repos/dimagi/commcare-odk/contents/{+path}","compare_url":"https://api.github.com/repos/dimagi/commcare-odk/compare/{base}...{head}","merges_url":"https://api.github.com/repos/dimagi/commcare-odk/merges","archive_url":"https://api.github.com/repos/dimagi/commcare-odk/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/dimagi/commcare-odk/downloads","issues_url":"https://api.github.com/repos/dimagi/commcare-odk/issues{/number}","pulls_url":"https://api.github.com/repos/dimagi/commcare-odk/pulls{/number}","milestones_url":"https://api.github.com/repos/dimagi/commcare-odk/milestones{/number}","notifications_url":"https://api.github.com/repos/dimagi/commcare-odk/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/dimagi/commcare-odk/labels{/name}","releases_url":"https://api.github.com/repos/dimagi/commcare-odk/releases{/id}","deployments_url":"https://api.github.com/repos/dimagi/commcare-odk/deployments","created_at":"2014-06-17T21:17:26Z","updated_at":"2016-01-25T13:36:24Z","pushed_at":"2016-04-11T18:53:57Z","git_url":"git://github.com/dimagi/commcare-odk.git","ssh_url":"git@github.com:dimagi/commcare-odk.git","clone_url":"https://github.com/dimagi/commcare-odk.git","svn_url":"https://github.com/dimagi/commcare-odk","homepage":"https://play.google.com/store/apps/details?id=org.commcare.dalvik&hl=en","size":67368,"stargazers_count":6,"watchers_count":6,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":9,"mirror_url":null,"open_issues_count":11,"forks":9,"open_issues":11,"watchers":6,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/dimagi/commcare-odk/pulls/1114"},"html":{"href":"https://github.com/dimagi/commcare-odk/pull/1114"},"issue":{"href":"https://api.github.com/repos/dimagi/commcare-odk/issues/1114"},"comments":{"href":"https://api.github.com/repos/dimagi/commcare-odk/issues/1114/comments"},"review_comments":{"href":"https://api.github.com/repos/dimagi/commcare-odk/pulls/1114/comments"},"review_comment":{"href":"https://api.github.com/repos/dimagi/commcare-odk/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/dimagi/commcare-odk/pulls/1114/commits"},"statuses":{"href":"https://api.github.com/repos/dimagi/commcare-odk/statuses/b0b1128579ac9976219948a73f6695a63c842eb6"}}}}