{"action":"created","comment":{"url":"https://api.github.com/repos/openMF/mifosx/pulls/comments/27342622","id":27342622,"diff_hunk":"@@ -0,0 +1,121 @@\n+/**\n+ * This Source Code Form is subject to the terms of the Mozilla Public\n+ * License, v. 2.0. If a copy of the MPL was not distributed with this file,\n+ * You can obtain one at http://mozilla.org/MPL/2.0/.\n+ */\n+package org.mifosplatform.portfolio.paymenttype.data;\n+\n+import java.lang.reflect.Type;\n+import java.util.ArrayList;\n+import java.util.List;\n+import java.util.Map;\n+\n+import org.apache.commons.lang.StringUtils;\n+import org.mifosplatform.infrastructure.core.data.ApiParameterError;\n+import org.mifosplatform.infrastructure.core.data.DataValidatorBuilder;\n+import org.mifosplatform.infrastructure.core.exception.InvalidJsonException;\n+import org.mifosplatform.infrastructure.core.exception.PlatformApiDataValidationException;\n+import org.mifosplatform.infrastructure.core.serialization.FromJsonHelper;\n+import org.mifosplatform.portfolio.paymenttype.api.PaymentTypeApiResourceConstants;\n+import org.springframework.beans.factory.annotation.Autowired;\n+import org.springframework.stereotype.Component;\n+\n+import com.google.gson.JsonElement;\n+import com.google.gson.reflect.TypeToken;\n+\n+@Component\n+public class PaymentTypeDataValidator {\n+\n+    private final FromJsonHelper fromApiJsonHelper;\n+\n+    @Autowired\n+    public PaymentTypeDataValidator(final FromJsonHelper fromApiJsonHelper) {\n+        this.fromApiJsonHelper = fromApiJsonHelper;\n+    }\n+\n+    public void validateForCreate(final String json) {\n+\n+        if (StringUtils.isBlank(json)) { throw new InvalidJsonException(); }\n+\n+        final Type typeOfMap = new TypeToken<Map<String, Object>>() {}.getType();\n+        this.fromApiJsonHelper.checkForUnsupportedParameters(typeOfMap, json,\n+                PaymentTypeApiResourceConstants.CREATE_PAYMENT_TYPE_REQUEST_DATA_PARAMETERS);\n+        final JsonElement element = this.fromApiJsonHelper.parse(json);\n+\n+        final List<ApiParameterError> dataValidationErrors = new ArrayList<>();\n+\n+        final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors)\n+                .resource(PaymentTypeApiResourceConstants.resourceNameForPermissions);\n+\n+        if (this.fromApiJsonHelper.parameterExists(PaymentTypeApiResourceConstants.NAME, element)) {\n+            final String name = this.fromApiJsonHelper.extractStringNamed(PaymentTypeApiResourceConstants.NAME, element);\n+            baseDataValidator.reset().parameter(PaymentTypeApiResourceConstants.NAME).value(name).notBlank();\n+        }\n+\n+        if (this.fromApiJsonHelper.parameterExists(PaymentTypeApiResourceConstants.DESCRIPTION, element)) {\n+            final String description = this.fromApiJsonHelper.extractStringNamed(PaymentTypeApiResourceConstants.DESCRIPTION, element);\n+            baseDataValidator.reset().parameter(PaymentTypeApiResourceConstants.DESCRIPTION).value(description).notExceedingLengthOf(500);\n+        }\n+\n+        if (this.fromApiJsonHelper.parameterExists(PaymentTypeApiResourceConstants.ISCASHPAYMENT, element)) {\n+            final Boolean isCashPayment = this.fromApiJsonHelper\n+                    .extractBooleanNamed(PaymentTypeApiResourceConstants.ISCASHPAYMENT, element);\n+            baseDataValidator.reset().parameter(PaymentTypeApiResourceConstants.ISCASHPAYMENT).value(isCashPayment);","path":"mifosng-provider/src/main/java/org/mifosplatform/portfolio/paymenttype/data/PaymentTypeDataValidator.java","position":63,"original_position":63,"commit_id":"c73e38fc8c030ea35574c96891b0535c9dbbc509","original_commit_id":"c73e38fc8c030ea35574c96891b0535c9dbbc509","user":{"login":"vishwasbabu","id":542697,"avatar_url":"https://avatars.githubusercontent.com/u/542697?v=3","gravatar_id":"","url":"https://api.github.com/users/vishwasbabu","html_url":"https://github.com/vishwasbabu","followers_url":"https://api.github.com/users/vishwasbabu/followers","following_url":"https://api.github.com/users/vishwasbabu/following{/other_user}","gists_url":"https://api.github.com/users/vishwasbabu/gists{/gist_id}","starred_url":"https://api.github.com/users/vishwasbabu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vishwasbabu/subscriptions","organizations_url":"https://api.github.com/users/vishwasbabu/orgs","repos_url":"https://api.github.com/users/vishwasbabu/repos","events_url":"https://api.github.com/users/vishwasbabu/events{/privacy}","received_events_url":"https://api.github.com/users/vishwasbabu/received_events","type":"User","site_admin":false},"body":"you should do a boolean check here?","created_at":"2015-03-28T05:45:08Z","updated_at":"2015-03-28T05:45:08Z","html_url":"https://github.com/openMF/mifosx/pull/1320#discussion_r27342622","pull_request_url":"https://api.github.com/repos/openMF/mifosx/pulls/1320","_links":{"self":{"href":"https://api.github.com/repos/openMF/mifosx/pulls/comments/27342622"},"html":{"href":"https://github.com/openMF/mifosx/pull/1320#discussion_r27342622"},"pull_request":{"href":"https://api.github.com/repos/openMF/mifosx/pulls/1320"}}},"pull_request":{"url":"https://api.github.com/repos/openMF/mifosx/pulls/1320","id":31938591,"html_url":"https://github.com/openMF/mifosx/pull/1320","diff_url":"https://github.com/openMF/mifosx/pull/1320.diff","patch_url":"https://github.com/openMF/mifosx/pull/1320.patch","issue_url":"https://api.github.com/repos/openMF/mifosx/issues/1320","number":1320,"state":"open","locked":false,"title":"MIFOSX-1904 : Moving payment type to their own table","user":{"login":"MithunKashyap","id":9151325,"avatar_url":"https://avatars.githubusercontent.com/u/9151325?v=3","gravatar_id":"","url":"https://api.github.com/users/MithunKashyap","html_url":"https://github.com/MithunKashyap","followers_url":"https://api.github.com/users/MithunKashyap/followers","following_url":"https://api.github.com/users/MithunKashyap/following{/other_user}","gists_url":"https://api.github.com/users/MithunKashyap/gists{/gist_id}","starred_url":"https://api.github.com/users/MithunKashyap/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/MithunKashyap/subscriptions","organizations_url":"https://api.github.com/users/MithunKashyap/orgs","repos_url":"https://api.github.com/users/MithunKashyap/repos","events_url":"https://api.github.com/users/MithunKashyap/events{/privacy}","received_events_url":"https://api.github.com/users/MithunKashyap/received_events","type":"User","site_admin":false},"body":"","created_at":"2015-03-25T16:18:03Z","updated_at":"2015-03-28T05:45:08Z","closed_at":null,"merged_at":null,"merge_commit_sha":"cf3355d5013130d1a926a464e2c93722706bf887","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/openMF/mifosx/pulls/1320/commits","review_comments_url":"https://api.github.com/repos/openMF/mifosx/pulls/1320/comments","review_comment_url":"https://api.github.com/repos/openMF/mifosx/pulls/comments{/number}","comments_url":"https://api.github.com/repos/openMF/mifosx/issues/1320/comments","statuses_url":"https://api.github.com/repos/openMF/mifosx/statuses/c73e38fc8c030ea35574c96891b0535c9dbbc509","head":{"label":"MithunKashyap:MIFOSX-1904","ref":"MIFOSX-1904","sha":"c73e38fc8c030ea35574c96891b0535c9dbbc509","user":{"login":"MithunKashyap","id":9151325,"avatar_url":"https://avatars.githubusercontent.com/u/9151325?v=3","gravatar_id":"","url":"https://api.github.com/users/MithunKashyap","html_url":"https://github.com/MithunKashyap","followers_url":"https://api.github.com/users/MithunKashyap/followers","following_url":"https://api.github.com/users/MithunKashyap/following{/other_user}","gists_url":"https://api.github.com/users/MithunKashyap/gists{/gist_id}","starred_url":"https://api.github.com/users/MithunKashyap/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/MithunKashyap/subscriptions","organizations_url":"https://api.github.com/users/MithunKashyap/orgs","repos_url":"https://api.github.com/users/MithunKashyap/repos","events_url":"https://api.github.com/users/MithunKashyap/events{/privacy}","received_events_url":"https://api.github.com/users/MithunKashyap/received_events","type":"User","site_admin":false},"repo":{"id":25167275,"name":"mifosx","full_name":"MithunKashyap/mifosx","owner":{"login":"MithunKashyap","id":9151325,"avatar_url":"https://avatars.githubusercontent.com/u/9151325?v=3","gravatar_id":"","url":"https://api.github.com/users/MithunKashyap","html_url":"https://github.com/MithunKashyap","followers_url":"https://api.github.com/users/MithunKashyap/followers","following_url":"https://api.github.com/users/MithunKashyap/following{/other_user}","gists_url":"https://api.github.com/users/MithunKashyap/gists{/gist_id}","starred_url":"https://api.github.com/users/MithunKashyap/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/MithunKashyap/subscriptions","organizations_url":"https://api.github.com/users/MithunKashyap/orgs","repos_url":"https://api.github.com/users/MithunKashyap/repos","events_url":"https://api.github.com/users/MithunKashyap/events{/privacy}","received_events_url":"https://api.github.com/users/MithunKashyap/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/MithunKashyap/mifosx","description":"The next evolution of mifos focusing on being faster, lighter and cheaper to change (than existing mifos) so that it is more responsive to the needs of MFIs and Integrators","fork":true,"url":"https://api.github.com/repos/MithunKashyap/mifosx","forks_url":"https://api.github.com/repos/MithunKashyap/mifosx/forks","keys_url":"https://api.github.com/repos/MithunKashyap/mifosx/keys{/key_id}","collaborators_url":"https://api.github.com/repos/MithunKashyap/mifosx/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/MithunKashyap/mifosx/teams","hooks_url":"https://api.github.com/repos/MithunKashyap/mifosx/hooks","issue_events_url":"https://api.github.com/repos/MithunKashyap/mifosx/issues/events{/number}","events_url":"https://api.github.com/repos/MithunKashyap/mifosx/events","assignees_url":"https://api.github.com/repos/MithunKashyap/mifosx/assignees{/user}","branches_url":"https://api.github.com/repos/MithunKashyap/mifosx/branches{/branch}","tags_url":"https://api.github.com/repos/MithunKashyap/mifosx/tags","blobs_url":"https://api.github.com/repos/MithunKashyap/mifosx/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/MithunKashyap/mifosx/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/MithunKashyap/mifosx/git/refs{/sha}","trees_url":"https://api.github.com/repos/MithunKashyap/mifosx/git/trees{/sha}","statuses_url":"https://api.github.com/repos/MithunKashyap/mifosx/statuses/{sha}","languages_url":"https://api.github.com/repos/MithunKashyap/mifosx/languages","stargazers_url":"https://api.github.com/repos/MithunKashyap/mifosx/stargazers","contributors_url":"https://api.github.com/repos/MithunKashyap/mifosx/contributors","subscribers_url":"https://api.github.com/repos/MithunKashyap/mifosx/subscribers","subscription_url":"https://api.github.com/repos/MithunKashyap/mifosx/subscription","commits_url":"https://api.github.com/repos/MithunKashyap/mifosx/commits{/sha}","git_commits_url":"https://api.github.com/repos/MithunKashyap/mifosx/git/commits{/sha}","comments_url":"https://api.github.com/repos/MithunKashyap/mifosx/comments{/number}","issue_comment_url":"https://api.github.com/repos/MithunKashyap/mifosx/issues/comments{/number}","contents_url":"https://api.github.com/repos/MithunKashyap/mifosx/contents/{+path}","compare_url":"https://api.github.com/repos/MithunKashyap/mifosx/compare/{base}...{head}","merges_url":"https://api.github.com/repos/MithunKashyap/mifosx/merges","archive_url":"https://api.github.com/repos/MithunKashyap/mifosx/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/MithunKashyap/mifosx/downloads","issues_url":"https://api.github.com/repos/MithunKashyap/mifosx/issues{/number}","pulls_url":"https://api.github.com/repos/MithunKashyap/mifosx/pulls{/number}","milestones_url":"https://api.github.com/repos/MithunKashyap/mifosx/milestones{/number}","notifications_url":"https://api.github.com/repos/MithunKashyap/mifosx/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/MithunKashyap/mifosx/labels{/name}","releases_url":"https://api.github.com/repos/MithunKashyap/mifosx/releases{/id}","created_at":"2014-10-13T16:35:14Z","updated_at":"2014-12-23T08:19:31Z","pushed_at":"2015-03-25T16:41:11Z","git_url":"git://github.com/MithunKashyap/mifosx.git","ssh_url":"git@github.com:MithunKashyap/mifosx.git","clone_url":"https://github.com/MithunKashyap/mifosx.git","svn_url":"https://github.com/MithunKashyap/mifosx","homepage":"http://mifos.org/product/mifos-x","size":28578,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"develop"}},"base":{"label":"openMF:develop","ref":"develop","sha":"5624da89ea93bb7b5e139414d08c489584fa5ba0","user":{"login":"openMF","id":3473607,"avatar_url":"https://avatars.githubusercontent.com/u/3473607?v=3","gravatar_id":"","url":"https://api.github.com/users/openMF","html_url":"https://github.com/openMF","followers_url":"https://api.github.com/users/openMF/followers","following_url":"https://api.github.com/users/openMF/following{/other_user}","gists_url":"https://api.github.com/users/openMF/gists{/gist_id}","starred_url":"https://api.github.com/users/openMF/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/openMF/subscriptions","organizations_url":"https://api.github.com/users/openMF/orgs","repos_url":"https://api.github.com/users/openMF/repos","events_url":"https://api.github.com/users/openMF/events{/privacy}","received_events_url":"https://api.github.com/users/openMF/received_events","type":"Organization","site_admin":false},"repo":{"id":4084995,"name":"mifosx","full_name":"openMF/mifosx","owner":{"login":"openMF","id":3473607,"avatar_url":"https://avatars.githubusercontent.com/u/3473607?v=3","gravatar_id":"","url":"https://api.github.com/users/openMF","html_url":"https://github.com/openMF","followers_url":"https://api.github.com/users/openMF/followers","following_url":"https://api.github.com/users/openMF/following{/other_user}","gists_url":"https://api.github.com/users/openMF/gists{/gist_id}","starred_url":"https://api.github.com/users/openMF/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/openMF/subscriptions","organizations_url":"https://api.github.com/users/openMF/orgs","repos_url":"https://api.github.com/users/openMF/repos","events_url":"https://api.github.com/users/openMF/events{/privacy}","received_events_url":"https://api.github.com/users/openMF/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/openMF/mifosx","description":"The next evolution of mifos focusing on being faster, lighter and cheaper to change (than existing mifos) so that it is more responsive to the needs of MFIs and Integrators","fork":false,"url":"https://api.github.com/repos/openMF/mifosx","forks_url":"https://api.github.com/repos/openMF/mifosx/forks","keys_url":"https://api.github.com/repos/openMF/mifosx/keys{/key_id}","collaborators_url":"https://api.github.com/repos/openMF/mifosx/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/openMF/mifosx/teams","hooks_url":"https://api.github.com/repos/openMF/mifosx/hooks","issue_events_url":"https://api.github.com/repos/openMF/mifosx/issues/events{/number}","events_url":"https://api.github.com/repos/openMF/mifosx/events","assignees_url":"https://api.github.com/repos/openMF/mifosx/assignees{/user}","branches_url":"https://api.github.com/repos/openMF/mifosx/branches{/branch}","tags_url":"https://api.github.com/repos/openMF/mifosx/tags","blobs_url":"https://api.github.com/repos/openMF/mifosx/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/openMF/mifosx/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/openMF/mifosx/git/refs{/sha}","trees_url":"https://api.github.com/repos/openMF/mifosx/git/trees{/sha}","statuses_url":"https://api.github.com/repos/openMF/mifosx/statuses/{sha}","languages_url":"https://api.github.com/repos/openMF/mifosx/languages","stargazers_url":"https://api.github.com/repos/openMF/mifosx/stargazers","contributors_url":"https://api.github.com/repos/openMF/mifosx/contributors","subscribers_url":"https://api.github.com/repos/openMF/mifosx/subscribers","subscription_url":"https://api.github.com/repos/openMF/mifosx/subscription","commits_url":"https://api.github.com/repos/openMF/mifosx/commits{/sha}","git_commits_url":"https://api.github.com/repos/openMF/mifosx/git/commits{/sha}","comments_url":"https://api.github.com/repos/openMF/mifosx/comments{/number}","issue_comment_url":"https://api.github.com/repos/openMF/mifosx/issues/comments{/number}","contents_url":"https://api.github.com/repos/openMF/mifosx/contents/{+path}","compare_url":"https://api.github.com/repos/openMF/mifosx/compare/{base}...{head}","merges_url":"https://api.github.com/repos/openMF/mifosx/merges","archive_url":"https://api.github.com/repos/openMF/mifosx/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/openMF/mifosx/downloads","issues_url":"https://api.github.com/repos/openMF/mifosx/issues{/number}","pulls_url":"https://api.github.com/repos/openMF/mifosx/pulls{/number}","milestones_url":"https://api.github.com/repos/openMF/mifosx/milestones{/number}","notifications_url":"https://api.github.com/repos/openMF/mifosx/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/openMF/mifosx/labels{/name}","releases_url":"https://api.github.com/repos/openMF/mifosx/releases{/id}","created_at":"2012-04-20T09:31:01Z","updated_at":"2015-03-28T05:14:50Z","pushed_at":"2015-03-28T05:14:50Z","git_url":"git://github.com/openMF/mifosx.git","ssh_url":"git@github.com:openMF/mifosx.git","clone_url":"https://github.com/openMF/mifosx.git","svn_url":"https://github.com/openMF/mifosx","homepage":"http://mifos.org/product/mifos-x","size":60689,"stargazers_count":86,"watchers_count":86,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":385,"mirror_url":null,"open_issues_count":18,"forks":385,"open_issues":18,"watchers":86,"default_branch":"develop"}},"_links":{"self":{"href":"https://api.github.com/repos/openMF/mifosx/pulls/1320"},"html":{"href":"https://github.com/openMF/mifosx/pull/1320"},"issue":{"href":"https://api.github.com/repos/openMF/mifosx/issues/1320"},"comments":{"href":"https://api.github.com/repos/openMF/mifosx/issues/1320/comments"},"review_comments":{"href":"https://api.github.com/repos/openMF/mifosx/pulls/1320/comments"},"review_comment":{"href":"https://api.github.com/repos/openMF/mifosx/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/openMF/mifosx/pulls/1320/commits"},"statuses":{"href":"https://api.github.com/repos/openMF/mifosx/statuses/c73e38fc8c030ea35574c96891b0535c9dbbc509"}}}}