{"action":"created","comment":{"url":"https://api.github.com/repos/wso2/carbon-apimgt/pulls/comments/41254030","id":41254030,"diff_hunk":"@@ -0,0 +1,275 @@\n+/*\n+ * Copyright (c) 2014, 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.apimgt.impl.workflow;\n+\n+import org.apache.axiom.om.util.AXIOMUtil;\n+import org.apache.axis2.AxisFault;\n+import org.apache.axis2.Constants;\n+import org.apache.axis2.addressing.EndpointReference;\n+import org.apache.axis2.client.Options;\n+import org.apache.axis2.client.ServiceClient;\n+import org.apache.axis2.transport.http.HTTPConstants;\n+import org.apache.axis2.transport.http.HttpTransportProperties;\n+import org.apache.commons.logging.Log;\n+import org.apache.commons.logging.LogFactory;\n+import org.wso2.carbon.apimgt.api.APIManagementException;\n+import org.wso2.carbon.apimgt.api.model.Application;\n+import org.wso2.carbon.apimgt.impl.dao.ApiMgtDAO;\n+import org.wso2.carbon.apimgt.impl.dto.ApplicationWorkflowDTO;\n+import org.wso2.carbon.apimgt.impl.dto.WorkflowDTO;\n+import org.wso2.carbon.apimgt.impl.internal.ServiceReferenceHolder;\n+\n+import javax.xml.stream.XMLStreamException;\n+import java.util.ArrayList;\n+import java.util.HashMap;\n+import java.util.List;\n+import java.util.Map;\n+import java.util.Set;\n+\n+/**\n+ * Simple workflow executor for application delete action\n+ */\n+public class CancelPendingApplicationApprovalWorkflowExecutor extends ApplicationDeletionSimpleWorkflowExecutor {\n+\n+    private String serviceEndpoint;\n+\n+    private String username;\n+\n+    private String password;\n+\n+    private String contentType;\n+\n+    private static final Log log = LogFactory.getLog(ApplicationCreationWSWorkflowExecutor.class);\n+\n+    @Override\n+    public void execute(WorkflowDTO workflowDTO) throws WorkflowException {\n+        ApplicationWorkflowDTO applicationWorkflowDTO = (ApplicationWorkflowDTO) workflowDTO;\n+        removeSubscriptionProcessesByApplication(applicationWorkflowDTO.getApplication());\n+        removeRegistrationProcessByApplicationId(applicationWorkflowDTO.getApplication().getId());\n+        try {\n+            Map<String, String> args = new HashMap<String, String>();\n+            args.put(\"action\", \"http://workflow.application.apimgt.carbon.wso2.org/cancel\");\n+            args.put(\"username\", username);\n+            args.put(\"password\", password);\n+            args.put(\"serviceEndpoint\", serviceEndpoint);\n+            args.put(\"contentType\", contentType);\n+            ServiceClient client = getClient(args);\n+\n+            String payload = \"<p:CancelApplicationApprovalWorkflowProcessRequest \" +\n+                    \"        xmlns:p=\\\"http://workflow.application.apimgt.carbon.wso2.org\\\">\\n\" +\n+                    \"           <p:workflowRef>\" + applicationWorkflowDTO.getExternalWorkflowReference() +\n+                    \"</p:workflowRef>\\n\" +\n+                    \"        </p:CancelApplicationApprovalWorkflowProcessRequest>\";\n+\n+            client.fireAndForget(AXIOMUtil.stringToOM(payload));\n+            // call complete method here since there are no callbacks to fire complete method\n+            complete(workflowDTO);\n+        } catch (AxisFault axisFault) {\n+            log.error(\"Error sending out message\", axisFault);\n+            throw new WorkflowException(\"Error sending out message\", axisFault);\n+        } catch (XMLStreamException e) {\n+            log.error(\"Error converting String to OMElement\", e);\n+            throw new WorkflowException(\"Error converting String to OMElement\", e);\n+        }\n+    }\n+\n+    @Override\n+    public void complete(WorkflowDTO workflowDTO) throws WorkflowException {\n+        ApiMgtDAO apiMgtDAO = new ApiMgtDAO();\n+\n+        workflowDTO.setUpdatedTime(System.currentTimeMillis());\n+        super.complete(workflowDTO);\n+        try {\n+            workflowDTO.setStatus(WorkflowStatus.APPROVED);\n+            apiMgtDAO.updateWorkflowStatus(workflowDTO);\n+            publishEvents(workflowDTO);\n+        } catch (APIManagementException e) {\n+            throw new WorkflowException(\"Error while updating workflow\", e);\n+        }\n+    }\n+\n+    /**\n+     * Removes and application's registration processes created at the BPS\n+     *\n+     * @param applicationId of the application\n+     */\n+    private void removeRegistrationProcessByApplicationId(int applicationId) throws WorkflowException {\n+        ApiMgtDAO apiMgtDAO = new ApiMgtDAO();\n+        ApplicationRegistrationWSWorkflowExecutor applicationRegistrationWFExecutor =\n+                (ApplicationRegistrationWSWorkflowExecutor) WorkflowExecutorFactory.getInstance().\n+                        getWorkflowExecutor(WorkflowConstants.WF_TYPE_AM_APPLICATION_REGISTRATION_PRODUCTION);\n+        String subContentType = applicationRegistrationWFExecutor.getContentType();\n+        String subUsername = applicationRegistrationWFExecutor.getUsername();\n+        String subPassword = applicationRegistrationWFExecutor.getPassword();\n+        String subServiceEndPoint = applicationRegistrationWFExecutor.getServiceEndpoint();\n+\n+        try {\n+            Set<String> registrationIDs = apiMgtDAO.getRegistrationWFReferencesByApplicationId(applicationId);\n+\n+            Map<String, String> args = new HashMap<String, String>();\n+            args.put(\"action\", \"http://workflow.application.apimgt.carbon.wso2.org/cancel\");","path":"components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/workflow/CancelPendingApplicationApprovalWorkflowExecutor.java","position":124,"original_position":124,"commit_id":"c6fb762936e4331d09049e17a53a48dd9fe81f92","original_commit_id":"c6fb762936e4331d09049e17a53a48dd9fe81f92","user":{"login":"harsha89","id":1561366,"avatar_url":"https://avatars.githubusercontent.com/u/1561366?v=3","gravatar_id":"","url":"https://api.github.com/users/harsha89","html_url":"https://github.com/harsha89","followers_url":"https://api.github.com/users/harsha89/followers","following_url":"https://api.github.com/users/harsha89/following{/other_user}","gists_url":"https://api.github.com/users/harsha89/gists{/gist_id}","starred_url":"https://api.github.com/users/harsha89/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/harsha89/subscriptions","organizations_url":"https://api.github.com/users/harsha89/orgs","repos_url":"https://api.github.com/users/harsha89/repos","events_url":"https://api.github.com/users/harsha89/events{/privacy}","received_events_url":"https://api.github.com/users/harsha89/received_events","type":"User","site_admin":false},"body":"Moved to constants","created_at":"2015-10-06T11:49:58Z","updated_at":"2015-10-06T11:49:58Z","html_url":"https://github.com/wso2/carbon-apimgt/pull/1094#discussion_r41254030","pull_request_url":"https://api.github.com/repos/wso2/carbon-apimgt/pulls/1094","_links":{"self":{"href":"https://api.github.com/repos/wso2/carbon-apimgt/pulls/comments/41254030"},"html":{"href":"https://github.com/wso2/carbon-apimgt/pull/1094#discussion_r41254030"},"pull_request":{"href":"https://api.github.com/repos/wso2/carbon-apimgt/pulls/1094"}}},"pull_request":{"url":"https://api.github.com/repos/wso2/carbon-apimgt/pulls/1094","id":46890827,"html_url":"https://github.com/wso2/carbon-apimgt/pull/1094","diff_url":"https://github.com/wso2/carbon-apimgt/pull/1094.diff","patch_url":"https://github.com/wso2/carbon-apimgt/pull/1094.patch","issue_url":"https://api.github.com/repos/wso2/carbon-apimgt/issues/1094","number":1094,"state":"open","locked":false,"title":"Deletion workflow support implementation","user":{"login":"praminda","id":2655553,"avatar_url":"https://avatars.githubusercontent.com/u/2655553?v=3","gravatar_id":"","url":"https://api.github.com/users/praminda","html_url":"https://github.com/praminda","followers_url":"https://api.github.com/users/praminda/followers","following_url":"https://api.github.com/users/praminda/following{/other_user}","gists_url":"https://api.github.com/users/praminda/gists{/gist_id}","starred_url":"https://api.github.com/users/praminda/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/praminda/subscriptions","organizations_url":"https://api.github.com/users/praminda/orgs","repos_url":"https://api.github.com/users/praminda/repos","events_url":"https://api.github.com/users/praminda/events{/privacy}","received_events_url":"https://api.github.com/users/praminda/received_events","type":"User","site_admin":false},"body":"New workflow extensions for,\r\n* Application deletion\r\n* Subscription deletion","created_at":"2015-10-06T11:28:08Z","updated_at":"2015-10-06T11:49:58Z","closed_at":null,"merged_at":null,"merge_commit_sha":"58bc3b07f30cc9348055d1f91835ce25ebc66ddb","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/wso2/carbon-apimgt/pulls/1094/commits","review_comments_url":"https://api.github.com/repos/wso2/carbon-apimgt/pulls/1094/comments","review_comment_url":"https://api.github.com/repos/wso2/carbon-apimgt/pulls/comments{/number}","comments_url":"https://api.github.com/repos/wso2/carbon-apimgt/issues/1094/comments","statuses_url":"https://api.github.com/repos/wso2/carbon-apimgt/statuses/c6fb762936e4331d09049e17a53a48dd9fe81f92","head":{"label":"praminda:release-1.10.x","ref":"release-1.10.x","sha":"c6fb762936e4331d09049e17a53a48dd9fe81f92","user":{"login":"praminda","id":2655553,"avatar_url":"https://avatars.githubusercontent.com/u/2655553?v=3","gravatar_id":"","url":"https://api.github.com/users/praminda","html_url":"https://github.com/praminda","followers_url":"https://api.github.com/users/praminda/followers","following_url":"https://api.github.com/users/praminda/following{/other_user}","gists_url":"https://api.github.com/users/praminda/gists{/gist_id}","starred_url":"https://api.github.com/users/praminda/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/praminda/subscriptions","organizations_url":"https://api.github.com/users/praminda/orgs","repos_url":"https://api.github.com/users/praminda/repos","events_url":"https://api.github.com/users/praminda/events{/privacy}","received_events_url":"https://api.github.com/users/praminda/received_events","type":"User","site_admin":false},"repo":{"id":41840734,"name":"carbon-apimgt","full_name":"praminda/carbon-apimgt","owner":{"login":"praminda","id":2655553,"avatar_url":"https://avatars.githubusercontent.com/u/2655553?v=3","gravatar_id":"","url":"https://api.github.com/users/praminda","html_url":"https://github.com/praminda","followers_url":"https://api.github.com/users/praminda/followers","following_url":"https://api.github.com/users/praminda/following{/other_user}","gists_url":"https://api.github.com/users/praminda/gists{/gist_id}","starred_url":"https://api.github.com/users/praminda/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/praminda/subscriptions","organizations_url":"https://api.github.com/users/praminda/orgs","repos_url":"https://api.github.com/users/praminda/repos","events_url":"https://api.github.com/users/praminda/events{/privacy}","received_events_url":"https://api.github.com/users/praminda/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/praminda/carbon-apimgt","description":"","fork":true,"url":"https://api.github.com/repos/praminda/carbon-apimgt","forks_url":"https://api.github.com/repos/praminda/carbon-apimgt/forks","keys_url":"https://api.github.com/repos/praminda/carbon-apimgt/keys{/key_id}","collaborators_url":"https://api.github.com/repos/praminda/carbon-apimgt/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/praminda/carbon-apimgt/teams","hooks_url":"https://api.github.com/repos/praminda/carbon-apimgt/hooks","issue_events_url":"https://api.github.com/repos/praminda/carbon-apimgt/issues/events{/number}","events_url":"https://api.github.com/repos/praminda/carbon-apimgt/events","assignees_url":"https://api.github.com/repos/praminda/carbon-apimgt/assignees{/user}","branches_url":"https://api.github.com/repos/praminda/carbon-apimgt/branches{/branch}","tags_url":"https://api.github.com/repos/praminda/carbon-apimgt/tags","blobs_url":"https://api.github.com/repos/praminda/carbon-apimgt/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/praminda/carbon-apimgt/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/praminda/carbon-apimgt/git/refs{/sha}","trees_url":"https://api.github.com/repos/praminda/carbon-apimgt/git/trees{/sha}","statuses_url":"https://api.github.com/repos/praminda/carbon-apimgt/statuses/{sha}","languages_url":"https://api.github.com/repos/praminda/carbon-apimgt/languages","stargazers_url":"https://api.github.com/repos/praminda/carbon-apimgt/stargazers","contributors_url":"https://api.github.com/repos/praminda/carbon-apimgt/contributors","subscribers_url":"https://api.github.com/repos/praminda/carbon-apimgt/subscribers","subscription_url":"https://api.github.com/repos/praminda/carbon-apimgt/subscription","commits_url":"https://api.github.com/repos/praminda/carbon-apimgt/commits{/sha}","git_commits_url":"https://api.github.com/repos/praminda/carbon-apimgt/git/commits{/sha}","comments_url":"https://api.github.com/repos/praminda/carbon-apimgt/comments{/number}","issue_comment_url":"https://api.github.com/repos/praminda/carbon-apimgt/issues/comments{/number}","contents_url":"https://api.github.com/repos/praminda/carbon-apimgt/contents/{+path}","compare_url":"https://api.github.com/repos/praminda/carbon-apimgt/compare/{base}...{head}","merges_url":"https://api.github.com/repos/praminda/carbon-apimgt/merges","archive_url":"https://api.github.com/repos/praminda/carbon-apimgt/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/praminda/carbon-apimgt/downloads","issues_url":"https://api.github.com/repos/praminda/carbon-apimgt/issues{/number}","pulls_url":"https://api.github.com/repos/praminda/carbon-apimgt/pulls{/number}","milestones_url":"https://api.github.com/repos/praminda/carbon-apimgt/milestones{/number}","notifications_url":"https://api.github.com/repos/praminda/carbon-apimgt/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/praminda/carbon-apimgt/labels{/name}","releases_url":"https://api.github.com/repos/praminda/carbon-apimgt/releases{/id}","created_at":"2015-09-03T03:44:32Z","updated_at":"2015-09-03T03:44:43Z","pushed_at":"2015-10-06T10:40:23Z","git_url":"git://github.com/praminda/carbon-apimgt.git","ssh_url":"git@github.com:praminda/carbon-apimgt.git","clone_url":"https://github.com/praminda/carbon-apimgt.git","svn_url":"https://github.com/praminda/carbon-apimgt","homepage":null,"size":38951,"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:release-1.10.x","ref":"release-1.10.x","sha":"6c158ff45c086d0b9b1ba0361afe5c2621f1f3a6","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":17201744,"name":"carbon-apimgt","full_name":"wso2/carbon-apimgt","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/carbon-apimgt","description":"","fork":false,"url":"https://api.github.com/repos/wso2/carbon-apimgt","forks_url":"https://api.github.com/repos/wso2/carbon-apimgt/forks","keys_url":"https://api.github.com/repos/wso2/carbon-apimgt/keys{/key_id}","collaborators_url":"https://api.github.com/repos/wso2/carbon-apimgt/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/wso2/carbon-apimgt/teams","hooks_url":"https://api.github.com/repos/wso2/carbon-apimgt/hooks","issue_events_url":"https://api.github.com/repos/wso2/carbon-apimgt/issues/events{/number}","events_url":"https://api.github.com/repos/wso2/carbon-apimgt/events","assignees_url":"https://api.github.com/repos/wso2/carbon-apimgt/assignees{/user}","branches_url":"https://api.github.com/repos/wso2/carbon-apimgt/branches{/branch}","tags_url":"https://api.github.com/repos/wso2/carbon-apimgt/tags","blobs_url":"https://api.github.com/repos/wso2/carbon-apimgt/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/wso2/carbon-apimgt/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/wso2/carbon-apimgt/git/refs{/sha}","trees_url":"https://api.github.com/repos/wso2/carbon-apimgt/git/trees{/sha}","statuses_url":"https://api.github.com/repos/wso2/carbon-apimgt/statuses/{sha}","languages_url":"https://api.github.com/repos/wso2/carbon-apimgt/languages","stargazers_url":"https://api.github.com/repos/wso2/carbon-apimgt/stargazers","contributors_url":"https://api.github.com/repos/wso2/carbon-apimgt/contributors","subscribers_url":"https://api.github.com/repos/wso2/carbon-apimgt/subscribers","subscription_url":"https://api.github.com/repos/wso2/carbon-apimgt/subscription","commits_url":"https://api.github.com/repos/wso2/carbon-apimgt/commits{/sha}","git_commits_url":"https://api.github.com/repos/wso2/carbon-apimgt/git/commits{/sha}","comments_url":"https://api.github.com/repos/wso2/carbon-apimgt/comments{/number}","issue_comment_url":"https://api.github.com/repos/wso2/carbon-apimgt/issues/comments{/number}","contents_url":"https://api.github.com/repos/wso2/carbon-apimgt/contents/{+path}","compare_url":"https://api.github.com/repos/wso2/carbon-apimgt/compare/{base}...{head}","merges_url":"https://api.github.com/repos/wso2/carbon-apimgt/merges","archive_url":"https://api.github.com/repos/wso2/carbon-apimgt/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/wso2/carbon-apimgt/downloads","issues_url":"https://api.github.com/repos/wso2/carbon-apimgt/issues{/number}","pulls_url":"https://api.github.com/repos/wso2/carbon-apimgt/pulls{/number}","milestones_url":"https://api.github.com/repos/wso2/carbon-apimgt/milestones{/number}","notifications_url":"https://api.github.com/repos/wso2/carbon-apimgt/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/wso2/carbon-apimgt/labels{/name}","releases_url":"https://api.github.com/repos/wso2/carbon-apimgt/releases{/id}","created_at":"2014-02-26T06:46:48Z","updated_at":"2015-08-12T12:26:50Z","pushed_at":"2015-10-06T11:28:09Z","git_url":"git://github.com/wso2/carbon-apimgt.git","ssh_url":"git@github.com:wso2/carbon-apimgt.git","clone_url":"https://github.com/wso2/carbon-apimgt.git","svn_url":"https://github.com/wso2/carbon-apimgt","homepage":null,"size":100701,"stargazers_count":13,"watchers_count":13,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":92,"mirror_url":null,"open_issues_count":10,"forks":92,"open_issues":10,"watchers":13,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/wso2/carbon-apimgt/pulls/1094"},"html":{"href":"https://github.com/wso2/carbon-apimgt/pull/1094"},"issue":{"href":"https://api.github.com/repos/wso2/carbon-apimgt/issues/1094"},"comments":{"href":"https://api.github.com/repos/wso2/carbon-apimgt/issues/1094/comments"},"review_comments":{"href":"https://api.github.com/repos/wso2/carbon-apimgt/pulls/1094/comments"},"review_comment":{"href":"https://api.github.com/repos/wso2/carbon-apimgt/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/wso2/carbon-apimgt/pulls/1094/commits"},"statuses":{"href":"https://api.github.com/repos/wso2/carbon-apimgt/statuses/c6fb762936e4331d09049e17a53a48dd9fe81f92"}}}}