{"action":"created","comment":{"url":"https://api.github.com/repos/sakaiproject/sakai/pulls/comments/88252149","pull_request_review_id":8829388,"id":88252149,"diff_hunk":"@@ -0,0 +1,132 @@\n+/**********************************************************************************\n+ *\n+ * Copyright (c) 2006 Sakai Foundation\n+ *\n+ * Licensed under the Educational Community 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.osedu.org/licenses/ECL-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.sakaiproject.contentreview.compilatio;\n+\n+import java.io.IOException;\n+import java.util.HashSet;\n+import java.util.Map;\n+import java.util.Set;\n+import java.util.SortedSet;\n+\n+import org.apache.commons.logging.Log;\n+import org.apache.commons.logging.LogFactory;\n+import org.apache.poi.hpsf.SummaryInformation;\n+import org.apache.poi.hwpf.HWPFDocument;\n+import org.apache.poi.poifs.filesystem.POIFSFileSystem;\n+import org.sakaiproject.component.api.ServerConfigurationService;\n+import org.sakaiproject.content.api.ContentResource;\n+import org.sakaiproject.contentreview.service.ContentReviewService;\n+import org.sakaiproject.entity.api.ResourceProperties;\n+import org.sakaiproject.exception.ServerOverloadException;\n+\n+/**\n+ * This class contains the implementation of \n+ * {@link ContentReviewService.isAcceptableContent}. This includes other\n+ * utility logic for checking the length and correctness of Word Documents and\n+ * other things.\n+ * \n+ * @author sgithens\n+ *\n+ */\n+public class CompilatioContentValidator {\n+\tprivate static final Log log = LogFactory.getLog(CompilatioContentValidator.class);\n+\t\n+\tContentReviewService contentReviewService = null;\n+\tpublic void setContentReviewService(ContentReviewService contentReviewService) {\n+\t\tthis.contentReviewService = contentReviewService;\n+\t}\n+\t\n+\tprivate ServerConfigurationService serverConfigurationService; \n+\tpublic void setServerConfigurationService (ServerConfigurationService serverConfigurationService) {\n+\t\tthis.serverConfigurationService = serverConfigurationService;\n+\t}\n+\t\n+\tpublic void init() {}\n+\t\n+\tpublic boolean isAcceptableContent(ContentResource resource) {\n+\t\t//for now we accept all content\n+\t\t// TODO: Check against content types accepted by Compilatio\n+\t\t/*\n+\t\t * Compilatio currently accepts the following file types for submission: MS Word (.doc), WordPerfect (.wpd), PostScript (.eps), Portable Document Format (.pdf), HTML (.htm), Rich Text (.rtf) and Plain Text (.txt)\n+\t\t * text/plain\n+\t\t * text/html\n+\t\t * application/msword\n+\t\t * application/msword\n+\t\t * application/postscript\n+\t\t */\n+\t\tif (resource == null) {\n+\t\t\treturn false;\n+\t\t}\n+\t\tString mime = resource.getContentType();\n+\t\tlog.debug(\"Got a content type of \" + mime);\n+\n+\t\t// TII-157\t--bbailla2\n+\t\tMap<String, SortedSet<String>> acceptableExtensionsToMimeTypes = contentReviewService.getAcceptableExtensionsToMimeTypes();\n+\t\tSet<String> acceptableMimeTypes = new HashSet<String>();\n+\t\tfor (SortedSet<String> mimeTypes : acceptableExtensionsToMimeTypes.values())\n+\t\t{\n+\t\t\tacceptableMimeTypes.addAll(mimeTypes);\n+\t\t}\n+\n+\t\tBoolean fileTypeOk = false;\n+\t\tif (acceptableMimeTypes.contains(mime))\n+\t\t{\n+\t\t\tfileTypeOk =  true;\n+\t\t\tlog.debug(\"FileType matches a known mime\");\n+\t\t}\n+\t\telse\n+\t\t{\n+\t\t\tlog.debug(\"FileType doesn't match a known mime\");\n+\t\t\t//TODO: return false here if we're confident that CRS.getAcceptableExtensionsToMimeTypes() gets us all of TII's acceptable mime types\n+\t\t}\n+\n+\t\t//as mime's can be tricky check the extensions\n+\t\tif (!fileTypeOk) {\n+\t\t\tResourceProperties resourceProperties = resource.getProperties();\n+\t\t\tString fileName = resourceProperties.getProperty(resourceProperties.getNamePropDisplayName());\n+\t\t\tif (fileName.indexOf(\".\")>0) {\n+\n+\t\t\t\tString extension = fileName.substring(fileName.lastIndexOf(\".\"));\n+\t\t\t\tlog.debug(\"file has an extension of \" + extension);\n+\t\t\t\tSet<String> extensions = acceptableExtensionsToMimeTypes.keySet();\n+\t\t\t\tif (extensions.contains(extension))\n+\t\t\t\t{\n+\t\t\t\t\tfileTypeOk = true;\n+\t\t\t\t}\n+\t\t\t\telse\n+\t\t\t\t{\n+\t\t\t\t\t// Neither the mime type nor the file extension are accepted\n+\t\t\t\t\treturn false;\n+\t\t\t\t}\n+\n+\t\t\t} else {\n+\t\t\t\t// No extension is not accepted\n+\t\t\t\t// TODO: Make this configurable\n+\t\t\t\treturn false;\n+\t\t\t}\n+\t\t}\n+\n+        // for files like .png we'd like to get a status code from TII so we can display an error message\n+        // other than \"An unknown error occurred\"\n+\t\tif (!fileTypeOk) {","path":"content-review/impl/compilatio/src/main/java/org/sakaiproject/contentreview/compilatio/CompilatioContentValidator.java","position":126,"original_position":126,"commit_id":"5d583374d0de26dd87bcd318073775d9def2394a","original_commit_id":"5d583374d0de26dd87bcd318073775d9def2394a","user":{"login":"bjones86","id":10403943,"avatar_url":"https://avatars.githubusercontent.com/u/10403943?v=3","gravatar_id":"","url":"https://api.github.com/users/bjones86","html_url":"https://github.com/bjones86","followers_url":"https://api.github.com/users/bjones86/followers","following_url":"https://api.github.com/users/bjones86/following{/other_user}","gists_url":"https://api.github.com/users/bjones86/gists{/gist_id}","starred_url":"https://api.github.com/users/bjones86/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bjones86/subscriptions","organizations_url":"https://api.github.com/users/bjones86/orgs","repos_url":"https://api.github.com/users/bjones86/repos","events_url":"https://api.github.com/users/bjones86/events{/privacy}","received_events_url":"https://api.github.com/users/bjones86/received_events","type":"User","site_admin":false},"body":"This if/else is redundant:\r\n\r\n`return fileTypeOk`","created_at":"2016-11-16T15:00:06Z","updated_at":"2016-11-16T15:00:06Z","html_url":"https://github.com/sakaiproject/sakai/pull/3596#discussion_r88252149","pull_request_url":"https://api.github.com/repos/sakaiproject/sakai/pulls/3596","_links":{"self":{"href":"https://api.github.com/repos/sakaiproject/sakai/pulls/comments/88252149"},"html":{"href":"https://github.com/sakaiproject/sakai/pull/3596#discussion_r88252149"},"pull_request":{"href":"https://api.github.com/repos/sakaiproject/sakai/pulls/3596"}}},"pull_request":{"url":"https://api.github.com/repos/sakaiproject/sakai/pulls/3596","id":93957234,"html_url":"https://github.com/sakaiproject/sakai/pull/3596","diff_url":"https://github.com/sakaiproject/sakai/pull/3596.diff","patch_url":"https://github.com/sakaiproject/sakai/pull/3596.patch","issue_url":"https://api.github.com/repos/sakaiproject/sakai/issues/3596","number":3596,"state":"open","locked":false,"title":"SAK-31949 : Compilatio content-review implementation","user":{"login":"frasese","id":6773967,"avatar_url":"https://avatars.githubusercontent.com/u/6773967?v=3","gravatar_id":"","url":"https://api.github.com/users/frasese","html_url":"https://github.com/frasese","followers_url":"https://api.github.com/users/frasese/followers","following_url":"https://api.github.com/users/frasese/following{/other_user}","gists_url":"https://api.github.com/users/frasese/gists{/gist_id}","starred_url":"https://api.github.com/users/frasese/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/frasese/subscriptions","organizations_url":"https://api.github.com/users/frasese/orgs","repos_url":"https://api.github.com/users/frasese/repos","events_url":"https://api.github.com/users/frasese/events{/privacy}","received_events_url":"https://api.github.com/users/frasese/received_events","type":"User","site_admin":false},"body":"","created_at":"2016-11-16T12:33:00Z","updated_at":"2016-11-16T15:21:36Z","closed_at":null,"merged_at":null,"merge_commit_sha":"2eff58b22250004290ea37343df02bd1af6c313c","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/sakaiproject/sakai/pulls/3596/commits","review_comments_url":"https://api.github.com/repos/sakaiproject/sakai/pulls/3596/comments","review_comment_url":"https://api.github.com/repos/sakaiproject/sakai/pulls/comments{/number}","comments_url":"https://api.github.com/repos/sakaiproject/sakai/issues/3596/comments","statuses_url":"https://api.github.com/repos/sakaiproject/sakai/statuses/5d583374d0de26dd87bcd318073775d9def2394a","head":{"label":"frasese:SAK-31949","ref":"SAK-31949","sha":"5d583374d0de26dd87bcd318073775d9def2394a","user":{"login":"frasese","id":6773967,"avatar_url":"https://avatars.githubusercontent.com/u/6773967?v=3","gravatar_id":"","url":"https://api.github.com/users/frasese","html_url":"https://github.com/frasese","followers_url":"https://api.github.com/users/frasese/followers","following_url":"https://api.github.com/users/frasese/following{/other_user}","gists_url":"https://api.github.com/users/frasese/gists{/gist_id}","starred_url":"https://api.github.com/users/frasese/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/frasese/subscriptions","organizations_url":"https://api.github.com/users/frasese/orgs","repos_url":"https://api.github.com/users/frasese/repos","events_url":"https://api.github.com/users/frasese/events{/privacy}","received_events_url":"https://api.github.com/users/frasese/received_events","type":"User","site_admin":false},"repo":{"id":37525352,"name":"sakai-apereo","full_name":"frasese/sakai-apereo","owner":{"login":"frasese","id":6773967,"avatar_url":"https://avatars.githubusercontent.com/u/6773967?v=3","gravatar_id":"","url":"https://api.github.com/users/frasese","html_url":"https://github.com/frasese","followers_url":"https://api.github.com/users/frasese/followers","following_url":"https://api.github.com/users/frasese/following{/other_user}","gists_url":"https://api.github.com/users/frasese/gists{/gist_id}","starred_url":"https://api.github.com/users/frasese/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/frasese/subscriptions","organizations_url":"https://api.github.com/users/frasese/orgs","repos_url":"https://api.github.com/users/frasese/repos","events_url":"https://api.github.com/users/frasese/events{/privacy}","received_events_url":"https://api.github.com/users/frasese/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/frasese/sakai-apereo","description":"Sakai is a freely available, feature-rich technology solution for learning, teaching, research and collaboration. Sakai is an open source software suite developed by a diverse and global adopter community.","fork":true,"url":"https://api.github.com/repos/frasese/sakai-apereo","forks_url":"https://api.github.com/repos/frasese/sakai-apereo/forks","keys_url":"https://api.github.com/repos/frasese/sakai-apereo/keys{/key_id}","collaborators_url":"https://api.github.com/repos/frasese/sakai-apereo/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/frasese/sakai-apereo/teams","hooks_url":"https://api.github.com/repos/frasese/sakai-apereo/hooks","issue_events_url":"https://api.github.com/repos/frasese/sakai-apereo/issues/events{/number}","events_url":"https://api.github.com/repos/frasese/sakai-apereo/events","assignees_url":"https://api.github.com/repos/frasese/sakai-apereo/assignees{/user}","branches_url":"https://api.github.com/repos/frasese/sakai-apereo/branches{/branch}","tags_url":"https://api.github.com/repos/frasese/sakai-apereo/tags","blobs_url":"https://api.github.com/repos/frasese/sakai-apereo/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/frasese/sakai-apereo/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/frasese/sakai-apereo/git/refs{/sha}","trees_url":"https://api.github.com/repos/frasese/sakai-apereo/git/trees{/sha}","statuses_url":"https://api.github.com/repos/frasese/sakai-apereo/statuses/{sha}","languages_url":"https://api.github.com/repos/frasese/sakai-apereo/languages","stargazers_url":"https://api.github.com/repos/frasese/sakai-apereo/stargazers","contributors_url":"https://api.github.com/repos/frasese/sakai-apereo/contributors","subscribers_url":"https://api.github.com/repos/frasese/sakai-apereo/subscribers","subscription_url":"https://api.github.com/repos/frasese/sakai-apereo/subscription","commits_url":"https://api.github.com/repos/frasese/sakai-apereo/commits{/sha}","git_commits_url":"https://api.github.com/repos/frasese/sakai-apereo/git/commits{/sha}","comments_url":"https://api.github.com/repos/frasese/sakai-apereo/comments{/number}","issue_comment_url":"https://api.github.com/repos/frasese/sakai-apereo/issues/comments{/number}","contents_url":"https://api.github.com/repos/frasese/sakai-apereo/contents/{+path}","compare_url":"https://api.github.com/repos/frasese/sakai-apereo/compare/{base}...{head}","merges_url":"https://api.github.com/repos/frasese/sakai-apereo/merges","archive_url":"https://api.github.com/repos/frasese/sakai-apereo/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/frasese/sakai-apereo/downloads","issues_url":"https://api.github.com/repos/frasese/sakai-apereo/issues{/number}","pulls_url":"https://api.github.com/repos/frasese/sakai-apereo/pulls{/number}","milestones_url":"https://api.github.com/repos/frasese/sakai-apereo/milestones{/number}","notifications_url":"https://api.github.com/repos/frasese/sakai-apereo/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/frasese/sakai-apereo/labels{/name}","releases_url":"https://api.github.com/repos/frasese/sakai-apereo/releases{/id}","deployments_url":"https://api.github.com/repos/frasese/sakai-apereo/deployments","created_at":"2015-06-16T11:11:02Z","updated_at":"2016-11-14T13:42:49Z","pushed_at":"2016-11-16T12:57:31Z","git_url":"git://github.com/frasese/sakai-apereo.git","ssh_url":"git@github.com:frasese/sakai-apereo.git","clone_url":"https://github.com/frasese/sakai-apereo.git","svn_url":"https://github.com/frasese/sakai-apereo","homepage":"https://www.sakaiproject.org","size":316750,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":true,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"sakaiproject:master","ref":"master","sha":"ad9197258ddbb777db9620222fde5e95242ac26b","user":{"login":"sakaiproject","id":314726,"avatar_url":"https://avatars.githubusercontent.com/u/314726?v=3","gravatar_id":"","url":"https://api.github.com/users/sakaiproject","html_url":"https://github.com/sakaiproject","followers_url":"https://api.github.com/users/sakaiproject/followers","following_url":"https://api.github.com/users/sakaiproject/following{/other_user}","gists_url":"https://api.github.com/users/sakaiproject/gists{/gist_id}","starred_url":"https://api.github.com/users/sakaiproject/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sakaiproject/subscriptions","organizations_url":"https://api.github.com/users/sakaiproject/orgs","repos_url":"https://api.github.com/users/sakaiproject/repos","events_url":"https://api.github.com/users/sakaiproject/events{/privacy}","received_events_url":"https://api.github.com/users/sakaiproject/received_events","type":"Organization","site_admin":false},"repo":{"id":28589709,"name":"sakai","full_name":"sakaiproject/sakai","owner":{"login":"sakaiproject","id":314726,"avatar_url":"https://avatars.githubusercontent.com/u/314726?v=3","gravatar_id":"","url":"https://api.github.com/users/sakaiproject","html_url":"https://github.com/sakaiproject","followers_url":"https://api.github.com/users/sakaiproject/followers","following_url":"https://api.github.com/users/sakaiproject/following{/other_user}","gists_url":"https://api.github.com/users/sakaiproject/gists{/gist_id}","starred_url":"https://api.github.com/users/sakaiproject/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sakaiproject/subscriptions","organizations_url":"https://api.github.com/users/sakaiproject/orgs","repos_url":"https://api.github.com/users/sakaiproject/repos","events_url":"https://api.github.com/users/sakaiproject/events{/privacy}","received_events_url":"https://api.github.com/users/sakaiproject/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/sakaiproject/sakai","description":"Sakai is a freely available, feature-rich technology solution for learning, teaching, research and collaboration. Sakai is an open source software suite developed by a diverse and global adopter community.","fork":false,"url":"https://api.github.com/repos/sakaiproject/sakai","forks_url":"https://api.github.com/repos/sakaiproject/sakai/forks","keys_url":"https://api.github.com/repos/sakaiproject/sakai/keys{/key_id}","collaborators_url":"https://api.github.com/repos/sakaiproject/sakai/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/sakaiproject/sakai/teams","hooks_url":"https://api.github.com/repos/sakaiproject/sakai/hooks","issue_events_url":"https://api.github.com/repos/sakaiproject/sakai/issues/events{/number}","events_url":"https://api.github.com/repos/sakaiproject/sakai/events","assignees_url":"https://api.github.com/repos/sakaiproject/sakai/assignees{/user}","branches_url":"https://api.github.com/repos/sakaiproject/sakai/branches{/branch}","tags_url":"https://api.github.com/repos/sakaiproject/sakai/tags","blobs_url":"https://api.github.com/repos/sakaiproject/sakai/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/sakaiproject/sakai/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/sakaiproject/sakai/git/refs{/sha}","trees_url":"https://api.github.com/repos/sakaiproject/sakai/git/trees{/sha}","statuses_url":"https://api.github.com/repos/sakaiproject/sakai/statuses/{sha}","languages_url":"https://api.github.com/repos/sakaiproject/sakai/languages","stargazers_url":"https://api.github.com/repos/sakaiproject/sakai/stargazers","contributors_url":"https://api.github.com/repos/sakaiproject/sakai/contributors","subscribers_url":"https://api.github.com/repos/sakaiproject/sakai/subscribers","subscription_url":"https://api.github.com/repos/sakaiproject/sakai/subscription","commits_url":"https://api.github.com/repos/sakaiproject/sakai/commits{/sha}","git_commits_url":"https://api.github.com/repos/sakaiproject/sakai/git/commits{/sha}","comments_url":"https://api.github.com/repos/sakaiproject/sakai/comments{/number}","issue_comment_url":"https://api.github.com/repos/sakaiproject/sakai/issues/comments{/number}","contents_url":"https://api.github.com/repos/sakaiproject/sakai/contents/{+path}","compare_url":"https://api.github.com/repos/sakaiproject/sakai/compare/{base}...{head}","merges_url":"https://api.github.com/repos/sakaiproject/sakai/merges","archive_url":"https://api.github.com/repos/sakaiproject/sakai/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/sakaiproject/sakai/downloads","issues_url":"https://api.github.com/repos/sakaiproject/sakai/issues{/number}","pulls_url":"https://api.github.com/repos/sakaiproject/sakai/pulls{/number}","milestones_url":"https://api.github.com/repos/sakaiproject/sakai/milestones{/number}","notifications_url":"https://api.github.com/repos/sakaiproject/sakai/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/sakaiproject/sakai/labels{/name}","releases_url":"https://api.github.com/repos/sakaiproject/sakai/releases{/id}","deployments_url":"https://api.github.com/repos/sakaiproject/sakai/deployments","created_at":"2014-12-29T11:14:17Z","updated_at":"2016-11-16T13:57:36Z","pushed_at":"2016-11-16T15:04:02Z","git_url":"git://github.com/sakaiproject/sakai.git","ssh_url":"git@github.com:sakaiproject/sakai.git","clone_url":"https://github.com/sakaiproject/sakai.git","svn_url":"https://github.com/sakaiproject/sakai","homepage":"https://www.sakaiproject.org","size":345824,"stargazers_count":189,"watchers_count":189,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":321,"mirror_url":null,"open_issues_count":83,"forks":321,"open_issues":83,"watchers":189,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/sakaiproject/sakai/pulls/3596"},"html":{"href":"https://github.com/sakaiproject/sakai/pull/3596"},"issue":{"href":"https://api.github.com/repos/sakaiproject/sakai/issues/3596"},"comments":{"href":"https://api.github.com/repos/sakaiproject/sakai/issues/3596/comments"},"review_comments":{"href":"https://api.github.com/repos/sakaiproject/sakai/pulls/3596/comments"},"review_comment":{"href":"https://api.github.com/repos/sakaiproject/sakai/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/sakaiproject/sakai/pulls/3596/commits"},"statuses":{"href":"https://api.github.com/repos/sakaiproject/sakai/statuses/5d583374d0de26dd87bcd318073775d9def2394a"}}}}
{"actor":{"display_login":"bjones86"}}