GitHub PullRequestReviewCommentEvent at 2014-07-30 06:33:35
Repository: zanata-server
Actor: carlosmunoz
Payload: {"action":"created","comment":{"url":"https://api.github.com/repos/zanata/zanata-server/pulls/comments/15568161","id":15568161,"diff_hunk":"@@ -0,0 +1,306 @@\n+package org.zanata.util;\n+\n+import java.beans.PropertyDescriptor;\n+import java.lang.reflect.AccessibleObject;\n+import java.lang.reflect.Field;\n+import java.lang.reflect.InvocationTargetException;\n+import java.lang.reflect.Method;\n+import java.util.List;\n+import java.util.Map;\n+import java.util.Set;\n+\n+import javax.annotation.Nonnull;\n+import javax.persistence.OneToMany;\n+import javax.persistence.OneToOne;\n+\n+import org.apache.commons.beanutils.BeanUtilsBean;\n+import org.apache.commons.beanutils.PropertyUtilsBean;\n+import org.apache.commons.lang.StringUtils;\n+import org.apache.commons.lang.reflect.FieldUtils;\n+import org.hibernate.proxy.HibernateProxyHelper;\n+\n+import com.google.common.base.Preconditions;\n+import com.google.common.collect.ImmutableList;\n+import com.google.common.collect.Lists;\n+import com.google.common.collect.Maps;\n+import com.google.common.collect.Sets;\n+import com.google.common.primitives.Primitives;\n+import lombok.extern.slf4j.Slf4j;\n+\n+/**\n+ * @author Alex Eng <a href=\"mailto:aeng@redhat.com\">aeng@redhat.com</a>\n+ */\n+@Slf4j\n+public class JPACopier {\n+\n+    private static final List<String> MODEL_ENTITY_IGNORE_LIST = ImmutableList\n+            .<String> builder().add(\"id\").add(\"creationDate\")\n+            .add(\"lastChanged\").build();\n+\n+    private static Map<Class, List<String>> CLASS_JPA_COPIER_MAP = Maps\n+            .newConcurrentMap();\n+\n+    /**\n+     * Create a clone of all writable properties from fromBean.\n+     *\n+     * @param fromBean\n+     *            original bean to be copy from. Needs to have no-arguments\n+     *            constructor.\n+     * @param ignoreProperties\n+     *            properties to be ignore when copy\n+     * @throws IllegalAccessException\n+     * @throws InstantiationException\n+     * @throws InvocationTargetException\n+     * @throws NoSuchMethodException\n+     */\n+    public static <T> T copyBean(@Nonnull T fromBean,\n+            String... ignoreProperties)\n+            throws IllegalAccessException, InstantiationException,\n+            InvocationTargetException, NoSuchMethodException {\n+        Preconditions.checkNotNull(fromBean);\n+\n+        // create a copy of the bean entity\n+        Object copy = HibernateProxyHelper.getClassWithoutInitializingProxy(\n+                fromBean).newInstance();\n+        copy = copyBean(fromBean, copy, ignoreProperties);\n+        return (T) copy;\n+    }\n+\n+    /**\n+     * Create a clone of all writable properties from fromBean.\n+     *\n+     * @param fromBean\n+     *            original bean to be copy from\n+     * @param toBean\n+     *            destination bean\n+     * @param ignoreProperties\n+     *            properties to be ignore when copy\n+     * @throws IllegalAccessException\n+     * @throws InstantiationException\n+     * @throws InvocationTargetException\n+     * @throws NoSuchMethodException\n+     */\n+    public static <T> T copyBean(@Nonnull T fromBean,\n+            @Nonnull T toBean, String... ignoreProperties)\n+            throws IllegalAccessException, InstantiationException,\n+            InvocationTargetException, NoSuchMethodException {\n+\n+        Preconditions.checkNotNull(fromBean);\n+        Preconditions.checkNotNull(toBean);\n+\n+        if (isPrimitiveOrString(fromBean)) {\n+            toBean = fromBean;\n+            return toBean;\n+        }\n+\n+        BeanUtilsBean beanUtilsBean = BeanUtilsBean.getInstance();\n+\n+        if (isCollectionType(fromBean.getClass())) {\n+            toBean =\n+                    (T) createNewCollection(fromBean.getClass(), fromBean);\n+            return toBean;\n+        }\n+\n+        List<String> ignoreList = Lists.newArrayList(ignoreProperties);\n+        ignoreList.addAll(MODEL_ENTITY_IGNORE_LIST);\n+\n+        Map<String, Object> propertiesMap =\n+                beanUtilsBean.getPropertyUtils().describe(fromBean);\n+\n+        for (Map.Entry<String, Object> entry : propertiesMap.entrySet()) {\n+            String property = entry.getKey();\n+            Object value = entry.getValue();\n+\n+            if (!isProceedCopy(beanUtilsBean.getPropertyUtils(), toBean,\n+                    property,\n+                    ignoreList)) {\n+                continue;\n+            }\n+\n+            if (value != null && isJPACopyProperty(fromBean, property)) {\n+                value = copyBean(value);\n+            }\n+            copyProperty(beanUtilsBean, toBean, property, value);\n+        }\n+        return toBean;\n+    }\n+\n+    /**\n+     * Check if property is writable and not in ignore list.\n+     *\n+     * @param propertyUtilsBean\n+     * @param toBean\n+     * @param property\n+     * @param ignoreList\n+     */\n+    private static boolean isProceedCopy(PropertyUtilsBean propertyUtilsBean,\n+            Object toBean, String property, List<String> ignoreList) {","path":"zanata-model/src/main/java/org/zanata/util/JPACopier.java","position":137,"original_position":137,"commit_id":"0522a6f7aa4eb1991a7d089d130d3254fd466907","original_commit_id":"0522a6f7aa4eb1991a7d089d130d3254fd466907","user":{"login":"carlosmunoz","id":84676,"avatar_url":"https://avatars.githubusercontent.com/u/84676?v=1","gravatar_id":"325bb3a4f9a4dfac2d415ff43efb1e9b","url":"https://api.github.com/users/carlosmunoz","html_url":"https://github.com/carlosmunoz","followers_url":"https://api.github.com/users/carlosmunoz/followers","following_url":"https://api.github.com/users/carlosmunoz/following{/other_user}","gists_url":"https://api.github.com/users/carlosmunoz/gists{/gist_id}","starred_url":"https://api.github.com/users/carlosmunoz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/carlosmunoz/subscriptions","organizations_url":"https://api.github.com/users/carlosmunoz/orgs","repos_url":"https://api.github.com/users/carlosmunoz/repos","events_url":"https://api.github.com/users/carlosmunoz/events{/privacy}","received_events_url":"https://api.github.com/users/carlosmunoz/received_events","type":"User","site_admin":false},"body":"Can we call this something like `canCopy` or `shouldCopy`?","created_at":"2014-07-30T06:33:35Z","updated_at":"2014-07-30T06:33:35Z","html_url":"https://github.com/zanata/zanata-server/pull/525#discussion_r15568161","pull_request_url":"https://api.github.com/repos/zanata/zanata-server/pulls/525","_links":{"self":{"href":"https://api.github.com/repos/zanata/zanata-server/pulls/comments/15568161"},"html":{"href":"https://github.com/zanata/zanata-server/pull/525#discussion_r15568161"},"pull_request":{"href":"https://api.github.com/repos/zanata/zanata-server/pulls/525"}}},"pull_request":{"url":"https://api.github.com/repos/zanata/zanata-server/pulls/525","id":17980237,"html_url":"https://github.com/zanata/zanata-server/pull/525","diff_url":"https://github.com/zanata/zanata-server/pull/525.diff","patch_url":"https://github.com/zanata/zanata-server/pull/525.patch","issue_url":"https://api.github.com/repos/zanata/zanata-server/issues/525","number":525,"state":"open","title":"fork/copy from previous version with source and translation","user":{"login":"aeng","id":766762,"avatar_url":"https://avatars.githubusercontent.com/u/766762?v=1","gravatar_id":"c7fa4315c62b48925680bed7e9788a47","url":"https://api.github.com/users/aeng","html_url":"https://github.com/aeng","followers_url":"https://api.github.com/users/aeng/followers","following_url":"https://api.github.com/users/aeng/following{/other_user}","gists_url":"https://api.github.com/users/aeng/gists{/gist_id}","starred_url":"https://api.github.com/users/aeng/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aeng/subscriptions","organizations_url":"https://api.github.com/users/aeng/orgs","repos_url":"https://api.github.com/users/aeng/repos","events_url":"https://api.github.com/users/aeng/events{/privacy}","received_events_url":"https://api.github.com/users/aeng/received_events","type":"User","site_admin":false},"body":"http://bugzilla.redhat.com/show_bug.cgi?id=1104015","created_at":"2014-07-04T05:50:09Z","updated_at":"2014-07-30T06:33:36Z","closed_at":null,"merged_at":null,"merge_commit_sha":"bd91010c1ab6b199421289e40a3a384ddf16cb7a","assignee":{"login":"huangp","id":1005842,"avatar_url":"https://avatars.githubusercontent.com/u/1005842?v=1","gravatar_id":"15d66320e6e6466cc25e2db86268f5de","url":"https://api.github.com/users/huangp","html_url":"https://github.com/huangp","followers_url":"https://api.github.com/users/huangp/followers","following_url":"https://api.github.com/users/huangp/following{/other_user}","gists_url":"https://api.github.com/users/huangp/gists{/gist_id}","starred_url":"https://api.github.com/users/huangp/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/huangp/subscriptions","organizations_url":"https://api.github.com/users/huangp/orgs","repos_url":"https://api.github.com/users/huangp/repos","events_url":"https://api.github.com/users/huangp/events{/privacy}","received_events_url":"https://api.github.com/users/huangp/received_events","type":"User","site_admin":false},"milestone":null,"commits_url":"https://api.github.com/repos/zanata/zanata-server/pulls/525/commits","review_comments_url":"https://api.github.com/repos/zanata/zanata-server/pulls/525/comments","review_comment_url":"https://api.github.com/repos/zanata/zanata-server/pulls/comments/{number}","comments_url":"https://api.github.com/repos/zanata/zanata-server/issues/525/comments","statuses_url":"https://api.github.com/repos/zanata/zanata-server/statuses/0522a6f7aa4eb1991a7d089d130d3254fd466907","head":{"label":"zanata:rhbz1104015","ref":"rhbz1104015","sha":"0522a6f7aa4eb1991a7d089d130d3254fd466907","user":{"login":"zanata","id":637455,"avatar_url":"https://avatars.githubusercontent.com/u/637455?v=1","gravatar_id":"0a06368d154f4db91cae77f7aedb4dfa","url":"https://api.github.com/users/zanata","html_url":"https://github.com/zanata","followers_url":"https://api.github.com/users/zanata/followers","following_url":"https://api.github.com/users/zanata/following{/other_user}","gists_url":"https://api.github.com/users/zanata/gists{/gist_id}","starred_url":"https://api.github.com/users/zanata/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zanata/subscriptions","organizations_url":"https://api.github.com/users/zanata/orgs","repos_url":"https://api.github.com/users/zanata/repos","events_url":"https://api.github.com/users/zanata/events{/privacy}","received_events_url":"https://api.github.com/users/zanata/received_events","type":"Organization","site_admin":false},"repo":{"id":1461609,"name":"zanata-server","full_name":"zanata/zanata-server","owner":{"login":"zanata","id":637455,"avatar_url":"https://avatars.githubusercontent.com/u/637455?v=1","gravatar_id":"0a06368d154f4db91cae77f7aedb4dfa","url":"https://api.github.com/users/zanata","html_url":"https://github.com/zanata","followers_url":"https://api.github.com/users/zanata/followers","following_url":"https://api.github.com/users/zanata/following{/other_user}","gists_url":"https://api.github.com/users/zanata/gists{/gist_id}","starred_url":"https://api.github.com/users/zanata/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zanata/subscriptions","organizations_url":"https://api.github.com/users/zanata/orgs","repos_url":"https://api.github.com/users/zanata/repos","events_url":"https://api.github.com/users/zanata/events{/privacy}","received_events_url":"https://api.github.com/users/zanata/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/zanata/zanata-server","description":"Zanata is a web-based system for translators to translate documentation and software online using a web browser.","fork":false,"url":"https://api.github.com/repos/zanata/zanata-server","forks_url":"https://api.github.com/repos/zanata/zanata-server/forks","keys_url":"https://api.github.com/repos/zanata/zanata-server/keys{/key_id}","collaborators_url":"https://api.github.com/repos/zanata/zanata-server/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/zanata/zanata-server/teams","hooks_url":"https://api.github.com/repos/zanata/zanata-server/hooks","issue_events_url":"https://api.github.com/repos/zanata/zanata-server/issues/events{/number}","events_url":"https://api.github.com/repos/zanata/zanata-server/events","assignees_url":"https://api.github.com/repos/zanata/zanata-server/assignees{/user}","branches_url":"https://api.github.com/repos/zanata/zanata-server/branches{/branch}","tags_url":"https://api.github.com/repos/zanata/zanata-server/tags","blobs_url":"https://api.github.com/repos/zanata/zanata-server/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/zanata/zanata-server/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/zanata/zanata-server/git/refs{/sha}","trees_url":"https://api.github.com/repos/zanata/zanata-server/git/trees{/sha}","statuses_url":"https://api.github.com/repos/zanata/zanata-server/statuses/{sha}","languages_url":"https://api.github.com/repos/zanata/zanata-server/languages","stargazers_url":"https://api.github.com/repos/zanata/zanata-server/stargazers","contributors_url":"https://api.github.com/repos/zanata/zanata-server/contributors","subscribers_url":"https://api.github.com/repos/zanata/zanata-server/subscribers","subscription_url":"https://api.github.com/repos/zanata/zanata-server/subscription","commits_url":"https://api.github.com/repos/zanata/zanata-server/commits{/sha}","git_commits_url":"https://api.github.com/repos/zanata/zanata-server/git/commits{/sha}","comments_url":"https://api.github.com/repos/zanata/zanata-server/comments{/number}","issue_comment_url":"https://api.github.com/repos/zanata/zanata-server/issues/comments/{number}","contents_url":"https://api.github.com/repos/zanata/zanata-server/contents/{+path}","compare_url":"https://api.github.com/repos/zanata/zanata-server/compare/{base}...{head}","merges_url":"https://api.github.com/repos/zanata/zanata-server/merges","archive_url":"https://api.github.com/repos/zanata/zanata-server/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/zanata/zanata-server/downloads","issues_url":"https://api.github.com/repos/zanata/zanata-server/issues{/number}","pulls_url":"https://api.github.com/repos/zanata/zanata-server/pulls{/number}","milestones_url":"https://api.github.com/repos/zanata/zanata-server/milestones{/number}","notifications_url":"https://api.github.com/repos/zanata/zanata-server/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/zanata/zanata-server/labels{/name}","releases_url":"https://api.github.com/repos/zanata/zanata-server/releases{/id}","created_at":"2011-03-10T00:24:47Z","updated_at":"2014-07-18T01:59:22Z","pushed_at":"2014-07-30T05:51:42Z","git_url":"git://github.com/zanata/zanata-server.git","ssh_url":"git@github.com:zanata/zanata-server.git","clone_url":"https://github.com/zanata/zanata-server.git","svn_url":"https://github.com/zanata/zanata-server","homepage":"http://zanata.org","size":221013,"stargazers_count":55,"watchers_count":55,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":true,"forks_count":20,"mirror_url":null,"open_issues_count":10,"forks":20,"open_issues":10,"watchers":55,"default_branch":"master"}},"base":{"label":"zanata:integration/master","ref":"integration/master","sha":"87695aa7b0aaa7bd7b66a38d9dec329c6a42e849","user":{"login":"zanata","id":637455,"avatar_url":"https://avatars.githubusercontent.com/u/637455?v=1","gravatar_id":"0a06368d154f4db91cae77f7aedb4dfa","url":"https://api.github.com/users/zanata","html_url":"https://github.com/zanata","followers_url":"https://api.github.com/users/zanata/followers","following_url":"https://api.github.com/users/zanata/following{/other_user}","gists_url":"https://api.github.com/users/zanata/gists{/gist_id}","starred_url":"https://api.github.com/users/zanata/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zanata/subscriptions","organizations_url":"https://api.github.com/users/zanata/orgs","repos_url":"https://api.github.com/users/zanata/repos","events_url":"https://api.github.com/users/zanata/events{/privacy}","received_events_url":"https://api.github.com/users/zanata/received_events","type":"Organization","site_admin":false},"repo":{"id":1461609,"name":"zanata-server","full_name":"zanata/zanata-server","owner":{"login":"zanata","id":637455,"avatar_url":"https://avatars.githubusercontent.com/u/637455?v=1","gravatar_id":"0a06368d154f4db91cae77f7aedb4dfa","url":"https://api.github.com/users/zanata","html_url":"https://github.com/zanata","followers_url":"https://api.github.com/users/zanata/followers","following_url":"https://api.github.com/users/zanata/following{/other_user}","gists_url":"https://api.github.com/users/zanata/gists{/gist_id}","starred_url":"https://api.github.com/users/zanata/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zanata/subscriptions","organizations_url":"https://api.github.com/users/zanata/orgs","repos_url":"https://api.github.com/users/zanata/repos","events_url":"https://api.github.com/users/zanata/events{/privacy}","received_events_url":"https://api.github.com/users/zanata/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/zanata/zanata-server","description":"Zanata is a web-based system for translators to translate documentation and software online using a web browser.","fork":false,"url":"https://api.github.com/repos/zanata/zanata-server","forks_url":"https://api.github.com/repos/zanata/zanata-server/forks","keys_url":"https://api.github.com/repos/zanata/zanata-server/keys{/key_id}","collaborators_url":"https://api.github.com/repos/zanata/zanata-server/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/zanata/zanata-server/teams","hooks_url":"https://api.github.com/repos/zanata/zanata-server/hooks","issue_events_url":"https://api.github.com/repos/zanata/zanata-server/issues/events{/number}","events_url":"https://api.github.com/repos/zanata/zanata-server/events","assignees_url":"https://api.github.com/repos/zanata/zanata-server/assignees{/user}","branches_url":"https://api.github.com/repos/zanata/zanata-server/branches{/branch}","tags_url":"https://api.github.com/repos/zanata/zanata-server/tags","blobs_url":"https://api.github.com/repos/zanata/zanata-server/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/zanata/zanata-server/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/zanata/zanata-server/git/refs{/sha}","trees_url":"https://api.github.com/repos/zanata/zanata-server/git/trees{/sha}","statuses_url":"https://api.github.com/repos/zanata/zanata-server/statuses/{sha}","languages_url":"https://api.github.com/repos/zanata/zanata-server/languages","stargazers_url":"https://api.github.com/repos/zanata/zanata-server/stargazers","contributors_url":"https://api.github.com/repos/zanata/zanata-server/contributors","subscribers_url":"https://api.github.com/repos/zanata/zanata-server/subscribers","subscription_url":"https://api.github.com/repos/zanata/zanata-server/subscription","commits_url":"https://api.github.com/repos/zanata/zanata-server/commits{/sha}","git_commits_url":"https://api.github.com/repos/zanata/zanata-server/git/commits{/sha}","comments_url":"https://api.github.com/repos/zanata/zanata-server/comments{/number}","issue_comment_url":"https://api.github.com/repos/zanata/zanata-server/issues/comments/{number}","contents_url":"https://api.github.com/repos/zanata/zanata-server/contents/{+path}","compare_url":"https://api.github.com/repos/zanata/zanata-server/compare/{base}...{head}","merges_url":"https://api.github.com/repos/zanata/zanata-server/merges","archive_url":"https://api.github.com/repos/zanata/zanata-server/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/zanata/zanata-server/downloads","issues_url":"https://api.github.com/repos/zanata/zanata-server/issues{/number}","pulls_url":"https://api.github.com/repos/zanata/zanata-server/pulls{/number}","milestones_url":"https://api.github.com/repos/zanata/zanata-server/milestones{/number}","notifications_url":"https://api.github.com/repos/zanata/zanata-server/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/zanata/zanata-server/labels{/name}","releases_url":"https://api.github.com/repos/zanata/zanata-server/releases{/id}","created_at":"2011-03-10T00:24:47Z","updated_at":"2014-07-18T01:59:22Z","pushed_at":"2014-07-30T05:51:42Z","git_url":"git://github.com/zanata/zanata-server.git","ssh_url":"git@github.com:zanata/zanata-server.git","clone_url":"https://github.com/zanata/zanata-server.git","svn_url":"https://github.com/zanata/zanata-server","homepage":"http://zanata.org","size":221013,"stargazers_count":55,"watchers_count":55,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":true,"forks_count":20,"mirror_url":null,"open_issues_count":10,"forks":20,"open_issues":10,"watchers":55,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/zanata/zanata-server/pulls/525"},"html":{"href":"https://github.com/zanata/zanata-server/pull/525"},"issue":{"href":"https://api.github.com/repos/zanata/zanata-server/issues/525"},"comments":{"href":"https://api.github.com/repos/zanata/zanata-server/issues/525/comments"},"review_comments":{"href":"https://api.github.com/repos/zanata/zanata-server/pulls/525/comments"},"review_comment":{"href":"https://api.github.com/repos/zanata/zanata-server/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/zanata/zanata-server/pulls/525/commits"},"statuses":{"href":"https://api.github.com/repos/zanata/zanata-server/statuses/0522a6f7aa4eb1991a7d089d130d3254fd466907"}}}}