{"action":"created","comment":{"url":"https://api.github.com/repos/KualiCo/kc/pulls/comments/24467414","id":24467414,"diff_hunk":"@@ -0,0 +1,195 @@\n+package org.kuali.coeus.sys.impl.workflow;\n+\n+import java.io.BufferedInputStream;\n+import java.io.ByteArrayInputStream;\n+import java.io.File;\n+import java.io.IOException;\n+import java.sql.Connection;\n+import java.sql.PreparedStatement;\n+import java.sql.ResultSet;\n+import java.sql.SQLException;\n+import java.sql.Statement;\n+import java.util.ArrayList;\n+import java.util.Collection;\n+import java.util.Collections;\n+import java.util.HashMap;\n+import java.util.List;\n+import java.util.Map;\n+import java.util.Set;\n+import java.util.TreeSet;\n+import java.util.regex.Pattern;\n+import java.util.zip.CRC32;\n+\n+import javax.sql.DataSource;\n+\n+import org.apache.log4j.Logger;\n+import org.bouncycastle.util.io.Streams;\n+import org.kuali.rice.core.api.impex.xml.StreamXmlDoc;\n+import org.kuali.rice.core.api.impex.xml.XmlDoc;\n+import org.kuali.rice.core.api.impex.xml.XmlDocCollection;\n+import org.kuali.rice.core.api.impex.xml.XmlIngesterService;\n+import org.reflections.Reflections;\n+import org.reflections.scanners.ResourcesScanner;\n+import org.reflections.util.ClasspathHelper;\n+import org.reflections.util.FilterBuilder;\n+import org.springframework.beans.factory.annotation.Autowired;\n+import org.springframework.beans.factory.annotation.Qualifier;\n+\n+\n+public class KcKewAutoIngestorService {\n+\t\n+\tprivate static final Logger LOG = Logger.getLogger(KcKewAutoIngestorService.class);\n+\n+\t@Autowired\n+\t@Qualifier(\"riceDataSource\")\n+\tprivate DataSource riceDataSource;\n+\t\n+\tprivate List<String> pathsToScan = new ArrayList<>();\n+\tprivate String principalIdToIngestAs;\n+\t\n+\t@Autowired\n+\t@Qualifier(\"xmlIngesterService\")\n+\tprivate XmlIngesterService xmlIngesterService;\n+\n+\tpublic void ingest() throws Exception {\n+\t\tMap<String, Integer> newChecksums = new HashMap<>();\n+\t\ttry (Connection conn = riceDataSource.getConnection()) {\n+\t\t\tconn.setAutoCommit(false);\n+\t\t\tMap<String, Integer> previousChecksums = readChecksums(conn);\n+\t\t\tfor (String path : pathsToScan) {\n+\t\t\t\tReflections reflections = new Reflections(ClasspathHelper.forPackage(path),\n+\t\t\t\t\t\tnew ResourcesScanner(), new FilterBuilder().includePackage(path));\n+\t\t\t\tSet <String> kewFiles = new TreeSet<>(reflections.getResources(Pattern.compile(\".*\\\\.xml\")));\n+\t\t\t\tAutoXmlDocCollection docCollection = new AutoXmlDocCollection(new File(path));\n+\t\t\t\tfor (String file : kewFiles) {\n+\t\t\t\t\tBufferedInputStream is = new BufferedInputStream(KcKewAutoIngestorService.class.getClassLoader().getResourceAsStream(file));\n+\t\t\t\t\tbyte[] encoded = Streams.readAll(is);\n+\t\t\t\t\tint checkSum = calculateChecksum(encoded);\n+\t\t\t\t\tString baseName = new File(file).getName();\n+\t\t\t\t\tif (previousChecksums.containsKey(baseName) && previousChecksums.get(baseName) == checkSum) {","path":"coeus-impl/src/main/java/org/kuali/coeus/sys/impl/workflow/KcKewAutoIngestorService.java","position":69,"original_position":69,"commit_id":"d18e1840a677d520344bd0dcf6d0ea824c3328a6","original_commit_id":"d18e1840a677d520344bd0dcf6d0ea824c3328a6","user":{"login":"blackcathacker","id":3145921,"avatar_url":"https://avatars.githubusercontent.com/u/3145921?v=3","gravatar_id":"","url":"https://api.github.com/users/blackcathacker","html_url":"https://github.com/blackcathacker","followers_url":"https://api.github.com/users/blackcathacker/followers","following_url":"https://api.github.com/users/blackcathacker/following{/other_user}","gists_url":"https://api.github.com/users/blackcathacker/gists{/gist_id}","starred_url":"https://api.github.com/users/blackcathacker/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/blackcathacker/subscriptions","organizations_url":"https://api.github.com/users/blackcathacker/orgs","repos_url":"https://api.github.com/users/blackcathacker/repos","events_url":"https://api.github.com/users/blackcathacker/events{/privacy}","received_events_url":"https://api.github.com/users/blackcathacker/received_events","type":"User","site_admin":false},"body":"Yeah. You can just throw the new files in there and it should ingest them. And if we make changes it should reingest the file because the checksum will change.","created_at":"2015-02-11T01:07:10Z","updated_at":"2015-02-11T01:07:10Z","html_url":"https://github.com/KualiCo/kc/pull/21#discussion_r24467414","pull_request_url":"https://api.github.com/repos/KualiCo/kc/pulls/21","_links":{"self":{"href":"https://api.github.com/repos/KualiCo/kc/pulls/comments/24467414"},"html":{"href":"https://github.com/KualiCo/kc/pull/21#discussion_r24467414"},"pull_request":{"href":"https://api.github.com/repos/KualiCo/kc/pulls/21"}}},"pull_request":{"url":"https://api.github.com/repos/KualiCo/kc/pulls/21","id":28969251,"html_url":"https://github.com/KualiCo/kc/pull/21","diff_url":"https://github.com/KualiCo/kc/pull/21.diff","patch_url":"https://github.com/KualiCo/kc/pull/21.patch","issue_url":"https://api.github.com/repos/KualiCo/kc/issues/21","number":21,"state":"open","locked":false,"title":"KRACOEUS-8824 : Auto Ingester","user":{"login":"blackcathacker","id":3145921,"avatar_url":"https://avatars.githubusercontent.com/u/3145921?v=3","gravatar_id":"","url":"https://api.github.com/users/blackcathacker","html_url":"https://github.com/blackcathacker","followers_url":"https://api.github.com/users/blackcathacker/followers","following_url":"https://api.github.com/users/blackcathacker/following{/other_user}","gists_url":"https://api.github.com/users/blackcathacker/gists{/gist_id}","starred_url":"https://api.github.com/users/blackcathacker/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/blackcathacker/subscriptions","organizations_url":"https://api.github.com/users/blackcathacker/orgs","repos_url":"https://api.github.com/users/blackcathacker/repos","events_url":"https://api.github.com/users/blackcathacker/events{/privacy}","received_events_url":"https://api.github.com/users/blackcathacker/received_events","type":"User","site_admin":false},"body":"Auto ingesting of coeus-db-xml. Runs within the process using Rice services as the KEW file and the numerous associated tables and XML formats makes writing this ourselves de-coupled from Rice pretty ugly. Sadly this also means it doesn't run with or associated too Flyway though. Does a checksum of each KEW file before merging it using the XmlIngesterService. And keeps track of that in the associated table seen in the referenced PR to kc-sql.","created_at":"2015-02-10T00:05:27Z","updated_at":"2015-02-11T01:07:10Z","closed_at":null,"merged_at":null,"merge_commit_sha":"83f2d26fa2fe84de7b1d6dcead15770866965390","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/KualiCo/kc/pulls/21/commits","review_comments_url":"https://api.github.com/repos/KualiCo/kc/pulls/21/comments","review_comment_url":"https://api.github.com/repos/KualiCo/kc/pulls/comments/{number}","comments_url":"https://api.github.com/repos/KualiCo/kc/issues/21/comments","statuses_url":"https://api.github.com/repos/KualiCo/kc/statuses/d18e1840a677d520344bd0dcf6d0ea824c3328a6","head":{"label":"blackcathacker:auto_ingestion","ref":"auto_ingestion","sha":"d18e1840a677d520344bd0dcf6d0ea824c3328a6","user":{"login":"blackcathacker","id":3145921,"avatar_url":"https://avatars.githubusercontent.com/u/3145921?v=3","gravatar_id":"","url":"https://api.github.com/users/blackcathacker","html_url":"https://github.com/blackcathacker","followers_url":"https://api.github.com/users/blackcathacker/followers","following_url":"https://api.github.com/users/blackcathacker/following{/other_user}","gists_url":"https://api.github.com/users/blackcathacker/gists{/gist_id}","starred_url":"https://api.github.com/users/blackcathacker/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/blackcathacker/subscriptions","organizations_url":"https://api.github.com/users/blackcathacker/orgs","repos_url":"https://api.github.com/users/blackcathacker/repos","events_url":"https://api.github.com/users/blackcathacker/events{/privacy}","received_events_url":"https://api.github.com/users/blackcathacker/received_events","type":"User","site_admin":false},"repo":{"id":16320118,"name":"kc","full_name":"blackcathacker/kc","owner":{"login":"blackcathacker","id":3145921,"avatar_url":"https://avatars.githubusercontent.com/u/3145921?v=3","gravatar_id":"","url":"https://api.github.com/users/blackcathacker","html_url":"https://github.com/blackcathacker","followers_url":"https://api.github.com/users/blackcathacker/followers","following_url":"https://api.github.com/users/blackcathacker/following{/other_user}","gists_url":"https://api.github.com/users/blackcathacker/gists{/gist_id}","starred_url":"https://api.github.com/users/blackcathacker/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/blackcathacker/subscriptions","organizations_url":"https://api.github.com/users/blackcathacker/orgs","repos_url":"https://api.github.com/users/blackcathacker/repos","events_url":"https://api.github.com/users/blackcathacker/events{/privacy}","received_events_url":"https://api.github.com/users/blackcathacker/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/blackcathacker/kc","description":"Kuali Coeus","fork":true,"url":"https://api.github.com/repos/blackcathacker/kc","forks_url":"https://api.github.com/repos/blackcathacker/kc/forks","keys_url":"https://api.github.com/repos/blackcathacker/kc/keys{/key_id}","collaborators_url":"https://api.github.com/repos/blackcathacker/kc/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/blackcathacker/kc/teams","hooks_url":"https://api.github.com/repos/blackcathacker/kc/hooks","issue_events_url":"https://api.github.com/repos/blackcathacker/kc/issues/events{/number}","events_url":"https://api.github.com/repos/blackcathacker/kc/events","assignees_url":"https://api.github.com/repos/blackcathacker/kc/assignees{/user}","branches_url":"https://api.github.com/repos/blackcathacker/kc/branches{/branch}","tags_url":"https://api.github.com/repos/blackcathacker/kc/tags","blobs_url":"https://api.github.com/repos/blackcathacker/kc/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/blackcathacker/kc/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/blackcathacker/kc/git/refs{/sha}","trees_url":"https://api.github.com/repos/blackcathacker/kc/git/trees{/sha}","statuses_url":"https://api.github.com/repos/blackcathacker/kc/statuses/{sha}","languages_url":"https://api.github.com/repos/blackcathacker/kc/languages","stargazers_url":"https://api.github.com/repos/blackcathacker/kc/stargazers","contributors_url":"https://api.github.com/repos/blackcathacker/kc/contributors","subscribers_url":"https://api.github.com/repos/blackcathacker/kc/subscribers","subscription_url":"https://api.github.com/repos/blackcathacker/kc/subscription","commits_url":"https://api.github.com/repos/blackcathacker/kc/commits{/sha}","git_commits_url":"https://api.github.com/repos/blackcathacker/kc/git/commits{/sha}","comments_url":"https://api.github.com/repos/blackcathacker/kc/comments{/number}","issue_comment_url":"https://api.github.com/repos/blackcathacker/kc/issues/comments/{number}","contents_url":"https://api.github.com/repos/blackcathacker/kc/contents/{+path}","compare_url":"https://api.github.com/repos/blackcathacker/kc/compare/{base}...{head}","merges_url":"https://api.github.com/repos/blackcathacker/kc/merges","archive_url":"https://api.github.com/repos/blackcathacker/kc/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/blackcathacker/kc/downloads","issues_url":"https://api.github.com/repos/blackcathacker/kc/issues{/number}","pulls_url":"https://api.github.com/repos/blackcathacker/kc/pulls{/number}","milestones_url":"https://api.github.com/repos/blackcathacker/kc/milestones{/number}","notifications_url":"https://api.github.com/repos/blackcathacker/kc/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/blackcathacker/kc/labels{/name}","releases_url":"https://api.github.com/repos/blackcathacker/kc/releases{/id}","created_at":"2014-01-28T17:50:39Z","updated_at":"2015-02-09T02:48:12Z","pushed_at":"2015-02-10T05:18:42Z","git_url":"git://github.com/blackcathacker/kc.git","ssh_url":"git@github.com:blackcathacker/kc.git","clone_url":"https://github.com/blackcathacker/kc.git","svn_url":"https://github.com/blackcathacker/kc","homepage":"http://www.kuali.org/kc","size":648983,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"base":{"label":"KualiCo:master","ref":"master","sha":"b166897795fb5d1a517f001a503c09f9600499f3","user":{"login":"KualiCo","id":8756237,"avatar_url":"https://avatars.githubusercontent.com/u/8756237?v=3","gravatar_id":"","url":"https://api.github.com/users/KualiCo","html_url":"https://github.com/KualiCo","followers_url":"https://api.github.com/users/KualiCo/followers","following_url":"https://api.github.com/users/KualiCo/following{/other_user}","gists_url":"https://api.github.com/users/KualiCo/gists{/gist_id}","starred_url":"https://api.github.com/users/KualiCo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/KualiCo/subscriptions","organizations_url":"https://api.github.com/users/KualiCo/orgs","repos_url":"https://api.github.com/users/KualiCo/repos","events_url":"https://api.github.com/users/KualiCo/events{/privacy}","received_events_url":"https://api.github.com/users/KualiCo/received_events","type":"Organization","site_admin":false},"repo":{"id":30315971,"name":"kc","full_name":"KualiCo/kc","owner":{"login":"KualiCo","id":8756237,"avatar_url":"https://avatars.githubusercontent.com/u/8756237?v=3","gravatar_id":"","url":"https://api.github.com/users/KualiCo","html_url":"https://github.com/KualiCo","followers_url":"https://api.github.com/users/KualiCo/followers","following_url":"https://api.github.com/users/KualiCo/following{/other_user}","gists_url":"https://api.github.com/users/KualiCo/gists{/gist_id}","starred_url":"https://api.github.com/users/KualiCo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/KualiCo/subscriptions","organizations_url":"https://api.github.com/users/KualiCo/orgs","repos_url":"https://api.github.com/users/KualiCo/repos","events_url":"https://api.github.com/users/KualiCo/events{/privacy}","received_events_url":"https://api.github.com/users/KualiCo/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/KualiCo/kc","description":"Kuali Coeus","fork":true,"url":"https://api.github.com/repos/KualiCo/kc","forks_url":"https://api.github.com/repos/KualiCo/kc/forks","keys_url":"https://api.github.com/repos/KualiCo/kc/keys{/key_id}","collaborators_url":"https://api.github.com/repos/KualiCo/kc/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/KualiCo/kc/teams","hooks_url":"https://api.github.com/repos/KualiCo/kc/hooks","issue_events_url":"https://api.github.com/repos/KualiCo/kc/issues/events{/number}","events_url":"https://api.github.com/repos/KualiCo/kc/events","assignees_url":"https://api.github.com/repos/KualiCo/kc/assignees{/user}","branches_url":"https://api.github.com/repos/KualiCo/kc/branches{/branch}","tags_url":"https://api.github.com/repos/KualiCo/kc/tags","blobs_url":"https://api.github.com/repos/KualiCo/kc/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/KualiCo/kc/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/KualiCo/kc/git/refs{/sha}","trees_url":"https://api.github.com/repos/KualiCo/kc/git/trees{/sha}","statuses_url":"https://api.github.com/repos/KualiCo/kc/statuses/{sha}","languages_url":"https://api.github.com/repos/KualiCo/kc/languages","stargazers_url":"https://api.github.com/repos/KualiCo/kc/stargazers","contributors_url":"https://api.github.com/repos/KualiCo/kc/contributors","subscribers_url":"https://api.github.com/repos/KualiCo/kc/subscribers","subscription_url":"https://api.github.com/repos/KualiCo/kc/subscription","commits_url":"https://api.github.com/repos/KualiCo/kc/commits{/sha}","git_commits_url":"https://api.github.com/repos/KualiCo/kc/git/commits{/sha}","comments_url":"https://api.github.com/repos/KualiCo/kc/comments{/number}","issue_comment_url":"https://api.github.com/repos/KualiCo/kc/issues/comments/{number}","contents_url":"https://api.github.com/repos/KualiCo/kc/contents/{+path}","compare_url":"https://api.github.com/repos/KualiCo/kc/compare/{base}...{head}","merges_url":"https://api.github.com/repos/KualiCo/kc/merges","archive_url":"https://api.github.com/repos/KualiCo/kc/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/KualiCo/kc/downloads","issues_url":"https://api.github.com/repos/KualiCo/kc/issues{/number}","pulls_url":"https://api.github.com/repos/KualiCo/kc/pulls{/number}","milestones_url":"https://api.github.com/repos/KualiCo/kc/milestones{/number}","notifications_url":"https://api.github.com/repos/KualiCo/kc/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/KualiCo/kc/labels{/name}","releases_url":"https://api.github.com/repos/KualiCo/kc/releases{/id}","created_at":"2015-02-04T19:11:49Z","updated_at":"2015-02-10T19:02:55Z","pushed_at":"2015-02-10T19:02:55Z","git_url":"git://github.com/KualiCo/kc.git","ssh_url":"git@github.com:KualiCo/kc.git","clone_url":"https://github.com/KualiCo/kc.git","svn_url":"https://github.com/KualiCo/kc","homepage":"http://www.kuali.org/kc","size":387319,"stargazers_count":2,"watchers_count":2,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":2,"mirror_url":null,"open_issues_count":6,"forks":2,"open_issues":6,"watchers":2,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/KualiCo/kc/pulls/21"},"html":{"href":"https://github.com/KualiCo/kc/pull/21"},"issue":{"href":"https://api.github.com/repos/KualiCo/kc/issues/21"},"comments":{"href":"https://api.github.com/repos/KualiCo/kc/issues/21/comments"},"review_comments":{"href":"https://api.github.com/repos/KualiCo/kc/pulls/21/comments"},"review_comment":{"href":"https://api.github.com/repos/KualiCo/kc/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/KualiCo/kc/pulls/21/commits"},"statuses":{"href":"https://api.github.com/repos/KualiCo/kc/statuses/d18e1840a677d520344bd0dcf6d0ea824c3328a6"}}}}