{"action":"created","comment":{"url":"https://api.github.com/repos/mulesoft/mule/pulls/comments/62212943","id":62212943,"diff_hunk":"@@ -0,0 +1,102 @@\n+/*\n+ * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com\n+ * The software in this package is published under the terms of the CPAL v1.0\n+ * license, a copy of which has been included with this distribution in the\n+ * LICENSE.txt file.\n+ */\n+package org.mule.runtime.module.extension.internal.metadata;\n+\n+import static java.lang.String.format;\n+import static java.util.stream.Collectors.toMap;\n+import static org.mule.runtime.module.extension.internal.util.IntrospectionUtils.checkInstantiable;\n+import static org.mule.runtime.module.extension.internal.util.IntrospectionUtils.getAnnotatedFields;\n+import org.mule.runtime.api.metadata.MetadataKey;\n+import org.mule.runtime.api.metadata.MetadataResolvingException;\n+import org.mule.runtime.api.metadata.resolving.FailureCode;\n+import org.mule.runtime.extension.api.annotation.metadata.MetadataKeyId;\n+import org.mule.runtime.extension.api.annotation.metadata.MetadataKeyPart;\n+import org.mule.runtime.extension.api.introspection.ComponentModel;\n+import org.mule.runtime.extension.api.introspection.property.MetadataKeyIdModelProperty;\n+\n+import java.lang.reflect.Field;\n+import java.util.HashMap;\n+import java.util.Map;\n+import java.util.function.Function;\n+\n+/**\n+ * Provides an instance of the annotated {@link MetadataKeyId} parameter's complex type.\n+ * The instance will be populated with all the corresponding values of the passed {@link MetadataKey}.\n+ *\n+ * @since 4.0\n+ */\n+final class MetadataKeyIdObjectResolver\n+{\n+\n+    private final Class type;\n+    private final Map<Field, String> fieldValueMap = new HashMap<>();\n+\n+    /**\n+     * Creates a new instance.\n+     *\n+     * @param component the component model that contains the parameter annotated with {@link MetadataKeyId}.\n+     * @param key            the {@link MetadataKey} associated to the POJO that its going to be instantiated.\n+     */\n+    MetadataKeyIdObjectResolver(ComponentModel component, MetadataKey key) throws MetadataResolvingException\n+    {\n+\n+        type = component.getModelProperty(MetadataKeyIdModelProperty.class)\n+                .orElseThrow(() -> buildException(format(\"Component '%s' doesn't have a MetadataKeyId parameter assosiated\", component.getName())))\n+                .getType();\n+        checkInstantiable(type);\n+        fillFieldValueMap(key);\n+    }\n+\n+    private void fillFieldValueMap(MetadataKey key) throws MetadataResolvingException\n+    {\n+        Map<Integer, Field> metadataKeyPartMap = getAnnotatedFields(type, MetadataKeyPart.class)\n+                                                                .stream().collect(toMap(f -> f.getAnnotation(MetadataKeyPart.class).order(), Function.identity()));\n+        int order = 1;\n+        while (!key.getChilds().isEmpty())\n+        {\n+            fieldValueMap.put(metadataKeyPartMap.get(order), key.getId());\n+            key = key.getChilds().iterator().next();\n+            order++;\n+        }\n+        fieldValueMap.put(metadataKeyPartMap.get(order), key.getId());\n+    }\n+\n+    /**\n+     * @return a new instance of the {@link MetadataKeyId} parameter {@code type} with the values of the\n+     * passed {@link MetadataKey}.\n+     * @throws MetadataResolvingException if the instantiation fails.\n+     */\n+    public Object resolve() throws MetadataResolvingException\n+    {\n+        try\n+        {\n+            Object metadataKeyId = type.newInstance();\n+            for (Field field : fieldValueMap.keySet())","path":"modules/extensions-support/src/main/java/org/mule/runtime/module/extension/internal/metadata/MetadataKeyIdObjectResolver.java","position":78,"original_position":78,"commit_id":"03651753aef0b27d15764a28f1391be4ad1f15cb","original_commit_id":"03651753aef0b27d15764a28f1391be4ad1f15cb","user":{"login":"marianogonzalez","id":1272771,"avatar_url":"https://avatars.githubusercontent.com/u/1272771?v=3","gravatar_id":"","url":"https://api.github.com/users/marianogonzalez","html_url":"https://github.com/marianogonzalez","followers_url":"https://api.github.com/users/marianogonzalez/followers","following_url":"https://api.github.com/users/marianogonzalez/following{/other_user}","gists_url":"https://api.github.com/users/marianogonzalez/gists{/gist_id}","starred_url":"https://api.github.com/users/marianogonzalez/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/marianogonzalez/subscriptions","organizations_url":"https://api.github.com/users/marianogonzalez/orgs","repos_url":"https://api.github.com/users/marianogonzalez/repos","events_url":"https://api.github.com/users/marianogonzalez/events{/privacy}","received_events_url":"https://api.github.com/users/marianogonzalez/received_events","type":"User","site_admin":false},"body":"Use FieldSetter instead","created_at":"2016-05-05T16:27:47Z","updated_at":"2016-05-05T16:27:47Z","html_url":"https://github.com/mulesoft/mule/pull/2625#discussion_r62212943","pull_request_url":"https://api.github.com/repos/mulesoft/mule/pulls/2625","_links":{"self":{"href":"https://api.github.com/repos/mulesoft/mule/pulls/comments/62212943"},"html":{"href":"https://github.com/mulesoft/mule/pull/2625#discussion_r62212943"},"pull_request":{"href":"https://api.github.com/repos/mulesoft/mule/pulls/2625"}}},"pull_request":{"url":"https://api.github.com/repos/mulesoft/mule/pulls/2625","id":68743718,"html_url":"https://github.com/mulesoft/mule/pull/2625","diff_url":"https://github.com/mulesoft/mule/pull/2625.diff","patch_url":"https://github.com/mulesoft/mule/pull/2625.patch","issue_url":"https://api.github.com/repos/mulesoft/mule/issues/2625","number":2625,"state":"open","locked":false,"title":"MULE-9473: Add multi-level key support for Datasense","user":{"login":"juandesi","id":3811690,"avatar_url":"https://avatars.githubusercontent.com/u/3811690?v=3","gravatar_id":"","url":"https://api.github.com/users/juandesi","html_url":"https://github.com/juandesi","followers_url":"https://api.github.com/users/juandesi/followers","following_url":"https://api.github.com/users/juandesi/following{/other_user}","gists_url":"https://api.github.com/users/juandesi/gists{/gist_id}","starred_url":"https://api.github.com/users/juandesi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/juandesi/subscriptions","organizations_url":"https://api.github.com/users/juandesi/orgs","repos_url":"https://api.github.com/users/juandesi/repos","events_url":"https://api.github.com/users/juandesi/events{/privacy}","received_events_url":"https://api.github.com/users/juandesi/received_events","type":"User","site_admin":false},"body":"","created_at":"2016-05-03T17:30:57Z","updated_at":"2016-05-05T16:27:47Z","closed_at":null,"merged_at":null,"merge_commit_sha":"b1ed95a25a193a7e41e218624c854df8cd15c51d","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/mulesoft/mule/pulls/2625/commits","review_comments_url":"https://api.github.com/repos/mulesoft/mule/pulls/2625/comments","review_comment_url":"https://api.github.com/repos/mulesoft/mule/pulls/comments{/number}","comments_url":"https://api.github.com/repos/mulesoft/mule/issues/2625/comments","statuses_url":"https://api.github.com/repos/mulesoft/mule/statuses/03651753aef0b27d15764a28f1391be4ad1f15cb","head":{"label":"mulesoft:multilevel-datasense","ref":"multilevel-datasense","sha":"03651753aef0b27d15764a28f1391be4ad1f15cb","user":{"login":"mulesoft","id":185740,"avatar_url":"https://avatars.githubusercontent.com/u/185740?v=3","gravatar_id":"","url":"https://api.github.com/users/mulesoft","html_url":"https://github.com/mulesoft","followers_url":"https://api.github.com/users/mulesoft/followers","following_url":"https://api.github.com/users/mulesoft/following{/other_user}","gists_url":"https://api.github.com/users/mulesoft/gists{/gist_id}","starred_url":"https://api.github.com/users/mulesoft/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mulesoft/subscriptions","organizations_url":"https://api.github.com/users/mulesoft/orgs","repos_url":"https://api.github.com/users/mulesoft/repos","events_url":"https://api.github.com/users/mulesoft/events{/privacy}","received_events_url":"https://api.github.com/users/mulesoft/received_events","type":"Organization","site_admin":false},"repo":{"id":7058562,"name":"mule","full_name":"mulesoft/mule","owner":{"login":"mulesoft","id":185740,"avatar_url":"https://avatars.githubusercontent.com/u/185740?v=3","gravatar_id":"","url":"https://api.github.com/users/mulesoft","html_url":"https://github.com/mulesoft","followers_url":"https://api.github.com/users/mulesoft/followers","following_url":"https://api.github.com/users/mulesoft/following{/other_user}","gists_url":"https://api.github.com/users/mulesoft/gists{/gist_id}","starred_url":"https://api.github.com/users/mulesoft/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mulesoft/subscriptions","organizations_url":"https://api.github.com/users/mulesoft/orgs","repos_url":"https://api.github.com/users/mulesoft/repos","events_url":"https://api.github.com/users/mulesoft/events{/privacy}","received_events_url":"https://api.github.com/users/mulesoft/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/mulesoft/mule","description":"Mule Community Edition","fork":false,"url":"https://api.github.com/repos/mulesoft/mule","forks_url":"https://api.github.com/repos/mulesoft/mule/forks","keys_url":"https://api.github.com/repos/mulesoft/mule/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mulesoft/mule/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mulesoft/mule/teams","hooks_url":"https://api.github.com/repos/mulesoft/mule/hooks","issue_events_url":"https://api.github.com/repos/mulesoft/mule/issues/events{/number}","events_url":"https://api.github.com/repos/mulesoft/mule/events","assignees_url":"https://api.github.com/repos/mulesoft/mule/assignees{/user}","branches_url":"https://api.github.com/repos/mulesoft/mule/branches{/branch}","tags_url":"https://api.github.com/repos/mulesoft/mule/tags","blobs_url":"https://api.github.com/repos/mulesoft/mule/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mulesoft/mule/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mulesoft/mule/git/refs{/sha}","trees_url":"https://api.github.com/repos/mulesoft/mule/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mulesoft/mule/statuses/{sha}","languages_url":"https://api.github.com/repos/mulesoft/mule/languages","stargazers_url":"https://api.github.com/repos/mulesoft/mule/stargazers","contributors_url":"https://api.github.com/repos/mulesoft/mule/contributors","subscribers_url":"https://api.github.com/repos/mulesoft/mule/subscribers","subscription_url":"https://api.github.com/repos/mulesoft/mule/subscription","commits_url":"https://api.github.com/repos/mulesoft/mule/commits{/sha}","git_commits_url":"https://api.github.com/repos/mulesoft/mule/git/commits{/sha}","comments_url":"https://api.github.com/repos/mulesoft/mule/comments{/number}","issue_comment_url":"https://api.github.com/repos/mulesoft/mule/issues/comments{/number}","contents_url":"https://api.github.com/repos/mulesoft/mule/contents/{+path}","compare_url":"https://api.github.com/repos/mulesoft/mule/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mulesoft/mule/merges","archive_url":"https://api.github.com/repos/mulesoft/mule/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mulesoft/mule/downloads","issues_url":"https://api.github.com/repos/mulesoft/mule/issues{/number}","pulls_url":"https://api.github.com/repos/mulesoft/mule/pulls{/number}","milestones_url":"https://api.github.com/repos/mulesoft/mule/milestones{/number}","notifications_url":"https://api.github.com/repos/mulesoft/mule/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mulesoft/mule/labels{/name}","releases_url":"https://api.github.com/repos/mulesoft/mule/releases{/id}","deployments_url":"https://api.github.com/repos/mulesoft/mule/deployments","created_at":"2012-12-07T19:23:06Z","updated_at":"2016-05-05T14:36:13Z","pushed_at":"2016-05-05T16:26:57Z","git_url":"git://github.com/mulesoft/mule.git","ssh_url":"git@github.com:mulesoft/mule.git","clone_url":"https://github.com/mulesoft/mule.git","svn_url":"https://github.com/mulesoft/mule","homepage":null,"size":230874,"stargazers_count":315,"watchers_count":315,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":338,"mirror_url":null,"open_issues_count":18,"forks":338,"open_issues":18,"watchers":315,"default_branch":"mule-3.x"}},"base":{"label":"mulesoft:mule-4.x","ref":"mule-4.x","sha":"2b39ae72339481a7d3b3fc78d248e35983202c6e","user":{"login":"mulesoft","id":185740,"avatar_url":"https://avatars.githubusercontent.com/u/185740?v=3","gravatar_id":"","url":"https://api.github.com/users/mulesoft","html_url":"https://github.com/mulesoft","followers_url":"https://api.github.com/users/mulesoft/followers","following_url":"https://api.github.com/users/mulesoft/following{/other_user}","gists_url":"https://api.github.com/users/mulesoft/gists{/gist_id}","starred_url":"https://api.github.com/users/mulesoft/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mulesoft/subscriptions","organizations_url":"https://api.github.com/users/mulesoft/orgs","repos_url":"https://api.github.com/users/mulesoft/repos","events_url":"https://api.github.com/users/mulesoft/events{/privacy}","received_events_url":"https://api.github.com/users/mulesoft/received_events","type":"Organization","site_admin":false},"repo":{"id":7058562,"name":"mule","full_name":"mulesoft/mule","owner":{"login":"mulesoft","id":185740,"avatar_url":"https://avatars.githubusercontent.com/u/185740?v=3","gravatar_id":"","url":"https://api.github.com/users/mulesoft","html_url":"https://github.com/mulesoft","followers_url":"https://api.github.com/users/mulesoft/followers","following_url":"https://api.github.com/users/mulesoft/following{/other_user}","gists_url":"https://api.github.com/users/mulesoft/gists{/gist_id}","starred_url":"https://api.github.com/users/mulesoft/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mulesoft/subscriptions","organizations_url":"https://api.github.com/users/mulesoft/orgs","repos_url":"https://api.github.com/users/mulesoft/repos","events_url":"https://api.github.com/users/mulesoft/events{/privacy}","received_events_url":"https://api.github.com/users/mulesoft/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/mulesoft/mule","description":"Mule Community Edition","fork":false,"url":"https://api.github.com/repos/mulesoft/mule","forks_url":"https://api.github.com/repos/mulesoft/mule/forks","keys_url":"https://api.github.com/repos/mulesoft/mule/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mulesoft/mule/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mulesoft/mule/teams","hooks_url":"https://api.github.com/repos/mulesoft/mule/hooks","issue_events_url":"https://api.github.com/repos/mulesoft/mule/issues/events{/number}","events_url":"https://api.github.com/repos/mulesoft/mule/events","assignees_url":"https://api.github.com/repos/mulesoft/mule/assignees{/user}","branches_url":"https://api.github.com/repos/mulesoft/mule/branches{/branch}","tags_url":"https://api.github.com/repos/mulesoft/mule/tags","blobs_url":"https://api.github.com/repos/mulesoft/mule/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mulesoft/mule/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mulesoft/mule/git/refs{/sha}","trees_url":"https://api.github.com/repos/mulesoft/mule/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mulesoft/mule/statuses/{sha}","languages_url":"https://api.github.com/repos/mulesoft/mule/languages","stargazers_url":"https://api.github.com/repos/mulesoft/mule/stargazers","contributors_url":"https://api.github.com/repos/mulesoft/mule/contributors","subscribers_url":"https://api.github.com/repos/mulesoft/mule/subscribers","subscription_url":"https://api.github.com/repos/mulesoft/mule/subscription","commits_url":"https://api.github.com/repos/mulesoft/mule/commits{/sha}","git_commits_url":"https://api.github.com/repos/mulesoft/mule/git/commits{/sha}","comments_url":"https://api.github.com/repos/mulesoft/mule/comments{/number}","issue_comment_url":"https://api.github.com/repos/mulesoft/mule/issues/comments{/number}","contents_url":"https://api.github.com/repos/mulesoft/mule/contents/{+path}","compare_url":"https://api.github.com/repos/mulesoft/mule/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mulesoft/mule/merges","archive_url":"https://api.github.com/repos/mulesoft/mule/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mulesoft/mule/downloads","issues_url":"https://api.github.com/repos/mulesoft/mule/issues{/number}","pulls_url":"https://api.github.com/repos/mulesoft/mule/pulls{/number}","milestones_url":"https://api.github.com/repos/mulesoft/mule/milestones{/number}","notifications_url":"https://api.github.com/repos/mulesoft/mule/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mulesoft/mule/labels{/name}","releases_url":"https://api.github.com/repos/mulesoft/mule/releases{/id}","deployments_url":"https://api.github.com/repos/mulesoft/mule/deployments","created_at":"2012-12-07T19:23:06Z","updated_at":"2016-05-05T14:36:13Z","pushed_at":"2016-05-05T16:26:57Z","git_url":"git://github.com/mulesoft/mule.git","ssh_url":"git@github.com:mulesoft/mule.git","clone_url":"https://github.com/mulesoft/mule.git","svn_url":"https://github.com/mulesoft/mule","homepage":null,"size":230874,"stargazers_count":315,"watchers_count":315,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":338,"mirror_url":null,"open_issues_count":18,"forks":338,"open_issues":18,"watchers":315,"default_branch":"mule-3.x"}},"_links":{"self":{"href":"https://api.github.com/repos/mulesoft/mule/pulls/2625"},"html":{"href":"https://github.com/mulesoft/mule/pull/2625"},"issue":{"href":"https://api.github.com/repos/mulesoft/mule/issues/2625"},"comments":{"href":"https://api.github.com/repos/mulesoft/mule/issues/2625/comments"},"review_comments":{"href":"https://api.github.com/repos/mulesoft/mule/pulls/2625/comments"},"review_comment":{"href":"https://api.github.com/repos/mulesoft/mule/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/mulesoft/mule/pulls/2625/commits"},"statuses":{"href":"https://api.github.com/repos/mulesoft/mule/statuses/03651753aef0b27d15764a28f1391be4ad1f15cb"}}}}