{"action":"created","comment":{"url":"https://api.github.com/repos/wso2/product-pc/pulls/comments/79302852","id":79302852,"diff_hunk":"@@ -0,0 +1,554 @@\n+/*\n+ * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.\n+ *\n+ * Licensed under the Apache License, Version 2.0 (the \"License\");\n+ * you may not use this file except in compliance with the License.\n+ * You may obtain a copy of the License at\n+ *\n+ * http://www.apache.org/licenses/LICENSE-2.0\n+ *\n+ * Unless required by applicable law or agreed to in writing, software\n+ * distributed under the License is distributed on an \"AS IS\" BASIS,\n+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n+ * See the License for the specific language governing permissions and\n+ * limitations under the License.\n+ */\n+\n+package org.wso2.carbon.pc.core.transfer;\n+\n+import org.apache.commons.io.Charsets;\n+import org.apache.commons.io.FileUtils;\n+import org.apache.commons.io.FilenameUtils;\n+import org.apache.commons.logging.Log;\n+import org.apache.commons.logging.LogFactory;\n+import org.json.JSONArray;\n+import org.json.JSONException;\n+import org.json.JSONObject;\n+import org.w3c.dom.Document;\n+import org.wso2.carbon.governance.api.util.GovernanceUtils;\n+import org.wso2.carbon.pc.core.ProcessCenterConstants;\n+import org.wso2.carbon.pc.core.ProcessCenterException;\n+import org.wso2.carbon.pc.core.audit.util.RegPermissionUtil;\n+import org.wso2.carbon.pc.core.internal.ProcessCenterServerHolder;\n+import org.wso2.carbon.registry.core.Resource;\n+import org.wso2.carbon.registry.core.exceptions.RegistryException;\n+import org.wso2.carbon.registry.core.service.RegistryService;\n+import org.wso2.carbon.registry.core.session.UserRegistry;\n+import org.wso2.carbon.user.api.UserStoreException;\n+import org.xml.sax.SAXException;\n+\n+import javax.ws.rs.core.MediaType;\n+import javax.xml.parsers.DocumentBuilder;\n+import javax.xml.parsers.DocumentBuilderFactory;\n+import javax.xml.parsers.ParserConfigurationException;\n+import javax.xml.transform.TransformerException;\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.zip.ZipEntry;\n+import java.util.zip.ZipInputStream;\n+\n+import org.wso2.carbon.pc.core.ProcessStore;\n+\n+public class ProcessImport {\n+    private static final Log log = LogFactory.getLog(ProcessImport.class);\n+    File[] listOfProcessDirs;\n+    RegistryService registryService = ProcessCenterServerHolder.getInstance().getRegistryService();\n+    UserRegistry reg;\n+    String user;\n+\n+    /**\n+     * @param processZipInputStream\n+     * @param user\n+     * @throws IOException\n+     * @throws RegistryException\n+     * @throws ProcessCenterException\n+     * @throws UserStoreException\n+     */\n+    public void importProcesses(InputStream processZipInputStream, String user)\n+            throws IOException, RegistryException, ProcessCenterException, UserStoreException, JSONException,\n+            TransformerException, SAXException, ParserConfigurationException {\n+\n+        if (registryService != null) {\n+            reg = registryService.getGovernanceUserRegistry(user);\n+            this.user = user;\n+            //extract zip file stream to the system disk\n+            byte[] buffer = new byte[2048];\n+            ZipInputStream zipInputStream = new ZipInputStream(processZipInputStream);\n+            File importsDir = new File(ProcessCenterConstants.IMPORTS_DIR);\n+            if (importsDir != null) {\n+                importsDir.mkdirs();\n+\n+                try {\n+                    ZipEntry entry;\n+                    while ((entry = zipInputStream.getNextEntry()) != null) {\n+                        //counter++;\n+                        String outpath = ProcessCenterConstants.IMPORTS_DIR + \"/\" + entry.getName();\n+                        String dirPath = outpath.substring(0, outpath.lastIndexOf(\"/\"));\n+                        new File(dirPath).mkdirs();\n+                        FileOutputStream fileOutputStream = null;\n+                        try {\n+                            fileOutputStream = new FileOutputStream(outpath);\n+                            int len = 0;\n+                            while ((len = zipInputStream.read(buffer)) > 0) {\n+                                fileOutputStream.write(buffer, 0, len);\n+                            }\n+                        } finally {\n+                            if (fileOutputStream != null) {\n+                                fileOutputStream.close();\n+                            }\n+                        }\n+                    }\n+                } finally {\n+                    zipInputStream.close();\n+                }\n+\n+                //check if the importing processes are already available\n+                boolean isProcessesAvailableAlready = isProcessesAlreadyAvailble();\n+                if (isProcessesAvailableAlready) {\n+                    log.error(","path":"modules/components/core/org.wso2.carbon.pc.core/src/main/java/org/wso2/carbon/pc/core/transfer/ProcessImport.java","position":111,"original_position":111,"commit_id":"58122da92c5b9ad9f6cf2f4e0266136fa7919e29","original_commit_id":"58122da92c5b9ad9f6cf2f4e0266136fa7919e29","user":{"login":"rmsamitha","id":2484781,"avatar_url":"https://avatars.githubusercontent.com/u/2484781?v=3","gravatar_id":"","url":"https://api.github.com/users/rmsamitha","html_url":"https://github.com/rmsamitha","followers_url":"https://api.github.com/users/rmsamitha/followers","following_url":"https://api.github.com/users/rmsamitha/following{/other_user}","gists_url":"https://api.github.com/users/rmsamitha/gists{/gist_id}","starred_url":"https://api.github.com/users/rmsamitha/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rmsamitha/subscriptions","organizations_url":"https://api.github.com/users/rmsamitha/orgs","repos_url":"https://api.github.com/users/rmsamitha/repos","events_url":"https://api.github.com/users/rmsamitha/events{/privacy}","received_events_url":"https://api.github.com/users/rmsamitha/received_events","type":"User","site_admin":false},"body":"Already fixed (this block is removed already)","created_at":"2016-09-18T10:32:33Z","updated_at":"2016-09-18T10:32:33Z","html_url":"https://github.com/wso2/product-pc/pull/139#discussion_r79302852","pull_request_url":"https://api.github.com/repos/wso2/product-pc/pulls/139","_links":{"self":{"href":"https://api.github.com/repos/wso2/product-pc/pulls/comments/79302852"},"html":{"href":"https://github.com/wso2/product-pc/pull/139#discussion_r79302852"},"pull_request":{"href":"https://api.github.com/repos/wso2/product-pc/pulls/139"}}},"pull_request":{"url":"https://api.github.com/repos/wso2/product-pc/pulls/139","id":80494884,"html_url":"https://github.com/wso2/product-pc/pull/139","diff_url":"https://github.com/wso2/product-pc/pull/139.diff","patch_url":"https://github.com/wso2/product-pc/pull/139.patch","issue_url":"https://api.github.com/repos/wso2/product-pc/issues/139","number":139,"state":"closed","locked":false,"title":"Process Import & Export","user":{"login":"rmsamitha","id":2484781,"avatar_url":"https://avatars.githubusercontent.com/u/2484781?v=3","gravatar_id":"","url":"https://api.github.com/users/rmsamitha","html_url":"https://github.com/rmsamitha","followers_url":"https://api.github.com/users/rmsamitha/followers","following_url":"https://api.github.com/users/rmsamitha/following{/other_user}","gists_url":"https://api.github.com/users/rmsamitha/gists{/gist_id}","starred_url":"https://api.github.com/users/rmsamitha/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rmsamitha/subscriptions","organizations_url":"https://api.github.com/users/rmsamitha/orgs","repos_url":"https://api.github.com/users/rmsamitha/repos","events_url":"https://api.github.com/users/rmsamitha/events{/privacy}","received_events_url":"https://api.github.com/users/rmsamitha/received_events","type":"User","site_admin":false},"body":"","created_at":"2016-08-08T18:04:35Z","updated_at":"2016-09-18T10:32:33Z","closed_at":"2016-08-08T18:39:14Z","merged_at":"2016-08-08T18:39:14Z","merge_commit_sha":"7fb070d9acb95c95a308166bc05480ddc88a0252","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/wso2/product-pc/pulls/139/commits","review_comments_url":"https://api.github.com/repos/wso2/product-pc/pulls/139/comments","review_comment_url":"https://api.github.com/repos/wso2/product-pc/pulls/comments{/number}","comments_url":"https://api.github.com/repos/wso2/product-pc/issues/139/comments","statuses_url":"https://api.github.com/repos/wso2/product-pc/statuses/58122da92c5b9ad9f6cf2f4e0266136fa7919e29","head":{"label":"rmsamitha:master","ref":"master","sha":"58122da92c5b9ad9f6cf2f4e0266136fa7919e29","user":{"login":"rmsamitha","id":2484781,"avatar_url":"https://avatars.githubusercontent.com/u/2484781?v=3","gravatar_id":"","url":"https://api.github.com/users/rmsamitha","html_url":"https://github.com/rmsamitha","followers_url":"https://api.github.com/users/rmsamitha/followers","following_url":"https://api.github.com/users/rmsamitha/following{/other_user}","gists_url":"https://api.github.com/users/rmsamitha/gists{/gist_id}","starred_url":"https://api.github.com/users/rmsamitha/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rmsamitha/subscriptions","organizations_url":"https://api.github.com/users/rmsamitha/orgs","repos_url":"https://api.github.com/users/rmsamitha/repos","events_url":"https://api.github.com/users/rmsamitha/events{/privacy}","received_events_url":"https://api.github.com/users/rmsamitha/received_events","type":"User","site_admin":false},"repo":{"id":52355346,"name":"product-pc","full_name":"rmsamitha/product-pc","owner":{"login":"rmsamitha","id":2484781,"avatar_url":"https://avatars.githubusercontent.com/u/2484781?v=3","gravatar_id":"","url":"https://api.github.com/users/rmsamitha","html_url":"https://github.com/rmsamitha","followers_url":"https://api.github.com/users/rmsamitha/followers","following_url":"https://api.github.com/users/rmsamitha/following{/other_user}","gists_url":"https://api.github.com/users/rmsamitha/gists{/gist_id}","starred_url":"https://api.github.com/users/rmsamitha/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rmsamitha/subscriptions","organizations_url":"https://api.github.com/users/rmsamitha/orgs","repos_url":"https://api.github.com/users/rmsamitha/repos","events_url":"https://api.github.com/users/rmsamitha/events{/privacy}","received_events_url":"https://api.github.com/users/rmsamitha/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/rmsamitha/product-pc","description":"","fork":true,"url":"https://api.github.com/repos/rmsamitha/product-pc","forks_url":"https://api.github.com/repos/rmsamitha/product-pc/forks","keys_url":"https://api.github.com/repos/rmsamitha/product-pc/keys{/key_id}","collaborators_url":"https://api.github.com/repos/rmsamitha/product-pc/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/rmsamitha/product-pc/teams","hooks_url":"https://api.github.com/repos/rmsamitha/product-pc/hooks","issue_events_url":"https://api.github.com/repos/rmsamitha/product-pc/issues/events{/number}","events_url":"https://api.github.com/repos/rmsamitha/product-pc/events","assignees_url":"https://api.github.com/repos/rmsamitha/product-pc/assignees{/user}","branches_url":"https://api.github.com/repos/rmsamitha/product-pc/branches{/branch}","tags_url":"https://api.github.com/repos/rmsamitha/product-pc/tags","blobs_url":"https://api.github.com/repos/rmsamitha/product-pc/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/rmsamitha/product-pc/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/rmsamitha/product-pc/git/refs{/sha}","trees_url":"https://api.github.com/repos/rmsamitha/product-pc/git/trees{/sha}","statuses_url":"https://api.github.com/repos/rmsamitha/product-pc/statuses/{sha}","languages_url":"https://api.github.com/repos/rmsamitha/product-pc/languages","stargazers_url":"https://api.github.com/repos/rmsamitha/product-pc/stargazers","contributors_url":"https://api.github.com/repos/rmsamitha/product-pc/contributors","subscribers_url":"https://api.github.com/repos/rmsamitha/product-pc/subscribers","subscription_url":"https://api.github.com/repos/rmsamitha/product-pc/subscription","commits_url":"https://api.github.com/repos/rmsamitha/product-pc/commits{/sha}","git_commits_url":"https://api.github.com/repos/rmsamitha/product-pc/git/commits{/sha}","comments_url":"https://api.github.com/repos/rmsamitha/product-pc/comments{/number}","issue_comment_url":"https://api.github.com/repos/rmsamitha/product-pc/issues/comments{/number}","contents_url":"https://api.github.com/repos/rmsamitha/product-pc/contents/{+path}","compare_url":"https://api.github.com/repos/rmsamitha/product-pc/compare/{base}...{head}","merges_url":"https://api.github.com/repos/rmsamitha/product-pc/merges","archive_url":"https://api.github.com/repos/rmsamitha/product-pc/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/rmsamitha/product-pc/downloads","issues_url":"https://api.github.com/repos/rmsamitha/product-pc/issues{/number}","pulls_url":"https://api.github.com/repos/rmsamitha/product-pc/pulls{/number}","milestones_url":"https://api.github.com/repos/rmsamitha/product-pc/milestones{/number}","notifications_url":"https://api.github.com/repos/rmsamitha/product-pc/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/rmsamitha/product-pc/labels{/name}","releases_url":"https://api.github.com/repos/rmsamitha/product-pc/releases{/id}","deployments_url":"https://api.github.com/repos/rmsamitha/product-pc/deployments","created_at":"2016-02-23T11:54:05Z","updated_at":"2016-02-23T11:54:08Z","pushed_at":"2016-08-11T07:53:56Z","git_url":"git://github.com/rmsamitha/product-pc.git","ssh_url":"git@github.com:rmsamitha/product-pc.git","clone_url":"https://github.com/rmsamitha/product-pc.git","svn_url":"https://github.com/rmsamitha/product-pc","homepage":null,"size":20225,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":false,"has_downloads":true,"has_wiki":true,"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":"wso2:master","ref":"master","sha":"bd44ff038fddb50251c1679e6c1e9ddc60b86aae","user":{"login":"wso2","id":533043,"avatar_url":"https://avatars.githubusercontent.com/u/533043?v=3","gravatar_id":"","url":"https://api.github.com/users/wso2","html_url":"https://github.com/wso2","followers_url":"https://api.github.com/users/wso2/followers","following_url":"https://api.github.com/users/wso2/following{/other_user}","gists_url":"https://api.github.com/users/wso2/gists{/gist_id}","starred_url":"https://api.github.com/users/wso2/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wso2/subscriptions","organizations_url":"https://api.github.com/users/wso2/orgs","repos_url":"https://api.github.com/users/wso2/repos","events_url":"https://api.github.com/users/wso2/events{/privacy}","received_events_url":"https://api.github.com/users/wso2/received_events","type":"Organization","site_admin":false},"repo":{"id":25909621,"name":"product-pc","full_name":"wso2/product-pc","owner":{"login":"wso2","id":533043,"avatar_url":"https://avatars.githubusercontent.com/u/533043?v=3","gravatar_id":"","url":"https://api.github.com/users/wso2","html_url":"https://github.com/wso2","followers_url":"https://api.github.com/users/wso2/followers","following_url":"https://api.github.com/users/wso2/following{/other_user}","gists_url":"https://api.github.com/users/wso2/gists{/gist_id}","starred_url":"https://api.github.com/users/wso2/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wso2/subscriptions","organizations_url":"https://api.github.com/users/wso2/orgs","repos_url":"https://api.github.com/users/wso2/repos","events_url":"https://api.github.com/users/wso2/events{/privacy}","received_events_url":"https://api.github.com/users/wso2/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/wso2/product-pc","description":"Welcome to the WSO2 Process Center source code! For info on working with the WSO2 Process Center repository and contributing code, click the link below.","fork":false,"url":"https://api.github.com/repos/wso2/product-pc","forks_url":"https://api.github.com/repos/wso2/product-pc/forks","keys_url":"https://api.github.com/repos/wso2/product-pc/keys{/key_id}","collaborators_url":"https://api.github.com/repos/wso2/product-pc/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/wso2/product-pc/teams","hooks_url":"https://api.github.com/repos/wso2/product-pc/hooks","issue_events_url":"https://api.github.com/repos/wso2/product-pc/issues/events{/number}","events_url":"https://api.github.com/repos/wso2/product-pc/events","assignees_url":"https://api.github.com/repos/wso2/product-pc/assignees{/user}","branches_url":"https://api.github.com/repos/wso2/product-pc/branches{/branch}","tags_url":"https://api.github.com/repos/wso2/product-pc/tags","blobs_url":"https://api.github.com/repos/wso2/product-pc/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/wso2/product-pc/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/wso2/product-pc/git/refs{/sha}","trees_url":"https://api.github.com/repos/wso2/product-pc/git/trees{/sha}","statuses_url":"https://api.github.com/repos/wso2/product-pc/statuses/{sha}","languages_url":"https://api.github.com/repos/wso2/product-pc/languages","stargazers_url":"https://api.github.com/repos/wso2/product-pc/stargazers","contributors_url":"https://api.github.com/repos/wso2/product-pc/contributors","subscribers_url":"https://api.github.com/repos/wso2/product-pc/subscribers","subscription_url":"https://api.github.com/repos/wso2/product-pc/subscription","commits_url":"https://api.github.com/repos/wso2/product-pc/commits{/sha}","git_commits_url":"https://api.github.com/repos/wso2/product-pc/git/commits{/sha}","comments_url":"https://api.github.com/repos/wso2/product-pc/comments{/number}","issue_comment_url":"https://api.github.com/repos/wso2/product-pc/issues/comments{/number}","contents_url":"https://api.github.com/repos/wso2/product-pc/contents/{+path}","compare_url":"https://api.github.com/repos/wso2/product-pc/compare/{base}...{head}","merges_url":"https://api.github.com/repos/wso2/product-pc/merges","archive_url":"https://api.github.com/repos/wso2/product-pc/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/wso2/product-pc/downloads","issues_url":"https://api.github.com/repos/wso2/product-pc/issues{/number}","pulls_url":"https://api.github.com/repos/wso2/product-pc/pulls{/number}","milestones_url":"https://api.github.com/repos/wso2/product-pc/milestones{/number}","notifications_url":"https://api.github.com/repos/wso2/product-pc/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/wso2/product-pc/labels{/name}","releases_url":"https://api.github.com/repos/wso2/product-pc/releases{/id}","deployments_url":"https://api.github.com/repos/wso2/product-pc/deployments","created_at":"2014-10-29T07:33:38Z","updated_at":"2016-08-02T08:28:42Z","pushed_at":"2016-09-07T08:30:14Z","git_url":"git://github.com/wso2/product-pc.git","ssh_url":"git@github.com:wso2/product-pc.git","clone_url":"https://github.com/wso2/product-pc.git","svn_url":"https://github.com/wso2/product-pc","homepage":"http://wso2.github.io/","size":21674,"stargazers_count":4,"watchers_count":4,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":19,"mirror_url":null,"open_issues_count":1,"forks":19,"open_issues":1,"watchers":4,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/wso2/product-pc/pulls/139"},"html":{"href":"https://github.com/wso2/product-pc/pull/139"},"issue":{"href":"https://api.github.com/repos/wso2/product-pc/issues/139"},"comments":{"href":"https://api.github.com/repos/wso2/product-pc/issues/139/comments"},"review_comments":{"href":"https://api.github.com/repos/wso2/product-pc/pulls/139/comments"},"review_comment":{"href":"https://api.github.com/repos/wso2/product-pc/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/wso2/product-pc/pulls/139/commits"},"statuses":{"href":"https://api.github.com/repos/wso2/product-pc/statuses/58122da92c5b9ad9f6cf2f4e0266136fa7919e29"}}}}
{"actor":{"display_login":"rmsamitha"}}