{"action":"created","comment":{"url":"https://api.github.com/repos/codice/ddf/pulls/comments/57965878","id":57965878,"diff_hunk":"@@ -0,0 +1,243 @@\n+/**\n+ * Copyright (c) Codice Foundation\n+ * <p/>\n+ * This is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser\n+ * General Public License as published by the Free Software Foundation, either version 3 of the\n+ * License, or any later version.\n+ * <p/>\n+ * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without\n+ * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n+ * Lesser General Public License for more details. A copy of the GNU Lesser General Public License\n+ * is distributed along with this program and can be found at\n+ * <http://www.gnu.org/licenses/lgpl.html>.\n+ */\n+package ddf.catalog.transformer.input.pptx;\n+\n+import static org.apache.commons.lang3.Validate.notNull;\n+\n+import java.awt.Dimension;\n+import java.awt.Graphics2D;\n+import java.awt.RenderingHints;\n+import java.awt.image.BufferedImage;\n+import java.io.ByteArrayOutputStream;\n+import java.io.IOException;\n+import java.io.InputStream;\n+\n+import javax.validation.constraints.NotNull;\n+\n+import org.apache.commons.io.IOUtils;\n+import org.apache.pdfbox.tools.imageio.ImageIOUtil;\n+import org.apache.poi.sl.usermodel.SlideShow;\n+import org.apache.poi.sl.usermodel.SlideShowFactory;\n+import org.apache.poi.xslf.usermodel.XMLSlideShow;\n+import org.slf4j.Logger;\n+import org.slf4j.LoggerFactory;\n+\n+import com.google.common.io.FileBackedOutputStream;\n+\n+import ddf.catalog.data.Metacard;\n+import ddf.catalog.data.impl.AttributeImpl;\n+import ddf.catalog.transform.CatalogTransformerException;\n+import ddf.catalog.transform.InputTransformer;\n+\n+/**\n+ * This is a decorator class that adds a thumbnail for PPTX files. It relies on\n+ * an injected {@link InputTransformer} to extract the metadata, and then it generates a\n+ * thumbnail image with Apache POI.\n+ */\n+public class PptxInputTransformer implements InputTransformer {\n+\n+    private static final Logger LOGGER = LoggerFactory.getLogger(PptxInputTransformer.class);\n+\n+    private static final int RESOLUTION_DPI = 44;\n+\n+    private static final float IMAGE_QUALITY = 1.0f;\n+\n+    private static final float IMAGE_HEIGHTWIDTH = 128;\n+\n+    private static final String FORMAT_NAME = \"jpg\";\n+\n+    private static final int FILE_BACKED_THRESHOLD = 1000000;\n+\n+    private final InputTransformer inputTransformer;\n+\n+    /**\n+     * The inputTransformer parameter will be used to generate the basic metadata. If the parameter\n+     * is null, then a {@link NullPointerException} will be thrown.\n+     *\n+     * @param inputTransformer must be non-null\n+     * @throws NullPointerException\n+     */\n+    public PptxInputTransformer(@NotNull InputTransformer inputTransformer) {\n+\n+        notNull(inputTransformer, \"The inputTransformer parameter must be non-null\");\n+\n+        this.inputTransformer = inputTransformer;\n+    }\n+\n+    @Override\n+    public Metacard transform(InputStream input) throws IOException, CatalogTransformerException {\n+        return transform(input, null);\n+    }\n+\n+    @Override\n+    public Metacard transform(InputStream input, String id)\n+            throws IOException, CatalogTransformerException {\n+\n+        if (input == null) {\n+            throw new CatalogTransformerException(\"Cannot transform null input.\");\n+        }\n+\n+        return transformLogic(input, id);\n+    }\n+\n+    /**\n+     * This is a three step process. First, create a FileBackedOutputStream because we need to\n+     * consume the stream twice. Once for the injected inputTransformer and once for Apache POI.\n+     * Next, extract the metadata with the injected input transformer. And last, use Apache POI\n+     * to create the thumbnail.\n+     *\n+     * @param input\n+     * @param id\n+     * @return\n+     * @throws IOException\n+     * @throws CatalogTransformerException\n+     */\n+    private Metacard transformLogic(InputStream input, String id)\n+            throws IOException, CatalogTransformerException {\n+\n+        try (FileBackedOutputStream fileBackedOutputStream = new FileBackedOutputStream(\n+                FILE_BACKED_THRESHOLD)) {\n+            try {\n+                int c = IOUtils.copy(input, fileBackedOutputStream);\n+                LOGGER.debug(\"copied {} bytes from input stream to file backed output stream\", c);\n+            } catch (IOException e) {\n+                throw new CatalogTransformerException(\"Could not copy bytes of content message.\",\n+                        e);\n+            }\n+\n+            Metacard metacard = extractInitialMetadata(fileBackedOutputStream.asByteSource()\n+                    .openStream());\n+\n+            extractThumbnail(metacard,\n+                    fileBackedOutputStream.asByteSource()\n+                            .openStream());\n+\n+            return metacard;\n+        }\n+\n+    }\n+\n+    /**\n+     * Extract the initial metadata using the injected input transformer.\n+     *\n+     * @param input\n+     * @return\n+     * @throws IOException\n+     * @throws CatalogTransformerException\n+     */\n+    private Metacard extractInitialMetadata(InputStream input)\n+            throws IOException, CatalogTransformerException {\n+        return inputTransformer.transform(input);\n+    }\n+\n+    /**\n+     * SlideShowFactory.create() handles the old-style (OLE2) PPT file and the newer OOXML PPTX files. But\n+     * the old-style is not well supported (it's not even a part of the normal jars). The only reason I'm","path":"catalog/transformer/catalog-transformer-pptx/src/main/java/ddf/catalog/transformer/input/pptx/PptxInputTransformer.java","position":146,"original_position":146,"commit_id":"7f1beefb3727dc9db76b86df79cecaf160be9575","original_commit_id":"7f1beefb3727dc9db76b86df79cecaf160be9575","user":{"login":"jlcsmith","id":4503545,"avatar_url":"https://avatars.githubusercontent.com/u/4503545?v=3","gravatar_id":"","url":"https://api.github.com/users/jlcsmith","html_url":"https://github.com/jlcsmith","followers_url":"https://api.github.com/users/jlcsmith/followers","following_url":"https://api.github.com/users/jlcsmith/following{/other_user}","gists_url":"https://api.github.com/users/jlcsmith/gists{/gist_id}","starred_url":"https://api.github.com/users/jlcsmith/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jlcsmith/subscriptions","organizations_url":"https://api.github.com/users/jlcsmith/orgs","repos_url":"https://api.github.com/users/jlcsmith/repos","events_url":"https://api.github.com/users/jlcsmith/events{/privacy}","received_events_url":"https://api.github.com/users/jlcsmith/received_events","type":"User","site_admin":false},"body":"I appreciate the details here, but it would be better to avoid personal commentary.  Content is good though.","created_at":"2016-03-30T21:20:24Z","updated_at":"2016-03-30T21:20:24Z","html_url":"https://github.com/codice/ddf/pull/649#discussion_r57965878","pull_request_url":"https://api.github.com/repos/codice/ddf/pulls/649","_links":{"self":{"href":"https://api.github.com/repos/codice/ddf/pulls/comments/57965878"},"html":{"href":"https://github.com/codice/ddf/pull/649#discussion_r57965878"},"pull_request":{"href":"https://api.github.com/repos/codice/ddf/pulls/649"}}},"pull_request":{"url":"https://api.github.com/repos/codice/ddf/pulls/649","id":64079424,"html_url":"https://github.com/codice/ddf/pull/649","diff_url":"https://github.com/codice/ddf/pull/649.diff","patch_url":"https://github.com/codice/ddf/pull/649.patch","issue_url":"https://api.github.com/repos/codice/ddf/issues/649","number":649,"state":"open","locked":false,"title":"DDF-1974 Add PPTX Input Transformer","user":{"login":"glenhein","id":17837152,"avatar_url":"https://avatars.githubusercontent.com/u/17837152?v=3","gravatar_id":"","url":"https://api.github.com/users/glenhein","html_url":"https://github.com/glenhein","followers_url":"https://api.github.com/users/glenhein/followers","following_url":"https://api.github.com/users/glenhein/following{/other_user}","gists_url":"https://api.github.com/users/glenhein/gists{/gist_id}","starred_url":"https://api.github.com/users/glenhein/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/glenhein/subscriptions","organizations_url":"https://api.github.com/users/glenhein/orgs","repos_url":"https://api.github.com/users/glenhein/repos","events_url":"https://api.github.com/users/glenhein/events{/privacy}","received_events_url":"https://api.github.com/users/glenhein/received_events","type":"User","site_admin":false},"body":"#### What does this PR do?\r\nAdd a pptx (powerpoint (ooxml)) input transformer that uses the original tika input transformer for generating the basic metadata and Apache POI for creating the thumbnail.\r\n\r\n#### Who is reviewing it?\r\n@ricklarsen @pklinef @rzwiefel @kcwire @Lambeaux \r\n\r\n#### How should this be tested?\r\nIngest a PPTX file and then search for it. Confirm that the thumbnail represents the first page of the PPTX document. There are several test documents in ddf/catalog/transformer/catalog-transformer-pptx/src/test/resources.\r\n\r\n#### Any background context you want to provide?\r\n#### What are the relevant tickets?\r\n\r\nhttps://codice.atlassian.net/browse/DDF-1974\r\n\r\n#### Screenshots (if appropriate)\r\n#### Checklist:\r\n- [x] Documentation Updated\r\n- [x] Update / Add Unit Tests\r\n- [ ] Update / Add Integration Tests\r\n","created_at":"2016-03-24T18:37:49Z","updated_at":"2016-03-30T21:20:24Z","closed_at":null,"merged_at":null,"merge_commit_sha":"2bf8954bcae5cfb5559b2826bb46823ce14b3ba3","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/codice/ddf/pulls/649/commits","review_comments_url":"https://api.github.com/repos/codice/ddf/pulls/649/comments","review_comment_url":"https://api.github.com/repos/codice/ddf/pulls/comments{/number}","comments_url":"https://api.github.com/repos/codice/ddf/issues/649/comments","statuses_url":"https://api.github.com/repos/codice/ddf/statuses/7f1beefb3727dc9db76b86df79cecaf160be9575","head":{"label":"glenhein:DDF-1974","ref":"DDF-1974","sha":"7f1beefb3727dc9db76b86df79cecaf160be9575","user":{"login":"glenhein","id":17837152,"avatar_url":"https://avatars.githubusercontent.com/u/17837152?v=3","gravatar_id":"","url":"https://api.github.com/users/glenhein","html_url":"https://github.com/glenhein","followers_url":"https://api.github.com/users/glenhein/followers","following_url":"https://api.github.com/users/glenhein/following{/other_user}","gists_url":"https://api.github.com/users/glenhein/gists{/gist_id}","starred_url":"https://api.github.com/users/glenhein/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/glenhein/subscriptions","organizations_url":"https://api.github.com/users/glenhein/orgs","repos_url":"https://api.github.com/users/glenhein/repos","events_url":"https://api.github.com/users/glenhein/events{/privacy}","received_events_url":"https://api.github.com/users/glenhein/received_events","type":"User","site_admin":false},"repo":{"id":54487089,"name":"ddf","full_name":"glenhein/ddf","owner":{"login":"glenhein","id":17837152,"avatar_url":"https://avatars.githubusercontent.com/u/17837152?v=3","gravatar_id":"","url":"https://api.github.com/users/glenhein","html_url":"https://github.com/glenhein","followers_url":"https://api.github.com/users/glenhein/followers","following_url":"https://api.github.com/users/glenhein/following{/other_user}","gists_url":"https://api.github.com/users/glenhein/gists{/gist_id}","starred_url":"https://api.github.com/users/glenhein/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/glenhein/subscriptions","organizations_url":"https://api.github.com/users/glenhein/orgs","repos_url":"https://api.github.com/users/glenhein/repos","events_url":"https://api.github.com/users/glenhein/events{/privacy}","received_events_url":"https://api.github.com/users/glenhein/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/glenhein/ddf","description":"The Distributed Data Framework - Federated Open Geospatial Consortium (OGC) filter powered metadata catalog with SAML Web SSO secured container","fork":true,"url":"https://api.github.com/repos/glenhein/ddf","forks_url":"https://api.github.com/repos/glenhein/ddf/forks","keys_url":"https://api.github.com/repos/glenhein/ddf/keys{/key_id}","collaborators_url":"https://api.github.com/repos/glenhein/ddf/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/glenhein/ddf/teams","hooks_url":"https://api.github.com/repos/glenhein/ddf/hooks","issue_events_url":"https://api.github.com/repos/glenhein/ddf/issues/events{/number}","events_url":"https://api.github.com/repos/glenhein/ddf/events","assignees_url":"https://api.github.com/repos/glenhein/ddf/assignees{/user}","branches_url":"https://api.github.com/repos/glenhein/ddf/branches{/branch}","tags_url":"https://api.github.com/repos/glenhein/ddf/tags","blobs_url":"https://api.github.com/repos/glenhein/ddf/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/glenhein/ddf/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/glenhein/ddf/git/refs{/sha}","trees_url":"https://api.github.com/repos/glenhein/ddf/git/trees{/sha}","statuses_url":"https://api.github.com/repos/glenhein/ddf/statuses/{sha}","languages_url":"https://api.github.com/repos/glenhein/ddf/languages","stargazers_url":"https://api.github.com/repos/glenhein/ddf/stargazers","contributors_url":"https://api.github.com/repos/glenhein/ddf/contributors","subscribers_url":"https://api.github.com/repos/glenhein/ddf/subscribers","subscription_url":"https://api.github.com/repos/glenhein/ddf/subscription","commits_url":"https://api.github.com/repos/glenhein/ddf/commits{/sha}","git_commits_url":"https://api.github.com/repos/glenhein/ddf/git/commits{/sha}","comments_url":"https://api.github.com/repos/glenhein/ddf/comments{/number}","issue_comment_url":"https://api.github.com/repos/glenhein/ddf/issues/comments{/number}","contents_url":"https://api.github.com/repos/glenhein/ddf/contents/{+path}","compare_url":"https://api.github.com/repos/glenhein/ddf/compare/{base}...{head}","merges_url":"https://api.github.com/repos/glenhein/ddf/merges","archive_url":"https://api.github.com/repos/glenhein/ddf/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/glenhein/ddf/downloads","issues_url":"https://api.github.com/repos/glenhein/ddf/issues{/number}","pulls_url":"https://api.github.com/repos/glenhein/ddf/pulls{/number}","milestones_url":"https://api.github.com/repos/glenhein/ddf/milestones{/number}","notifications_url":"https://api.github.com/repos/glenhein/ddf/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/glenhein/ddf/labels{/name}","releases_url":"https://api.github.com/repos/glenhein/ddf/releases{/id}","deployments_url":"https://api.github.com/repos/glenhein/ddf/deployments","created_at":"2016-03-22T15:36:01Z","updated_at":"2016-03-22T15:36:13Z","pushed_at":"2016-03-29T22:13:32Z","git_url":"git://github.com/glenhein/ddf.git","ssh_url":"git@github.com:glenhein/ddf.git","clone_url":"https://github.com/glenhein/ddf.git","svn_url":"https://github.com/glenhein/ddf","homepage":"","size":151043,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"codice:master","ref":"master","sha":"6295f600988f853392477a7fd855935310544c25","user":{"login":"codice","id":2386734,"avatar_url":"https://avatars.githubusercontent.com/u/2386734?v=3","gravatar_id":"","url":"https://api.github.com/users/codice","html_url":"https://github.com/codice","followers_url":"https://api.github.com/users/codice/followers","following_url":"https://api.github.com/users/codice/following{/other_user}","gists_url":"https://api.github.com/users/codice/gists{/gist_id}","starred_url":"https://api.github.com/users/codice/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/codice/subscriptions","organizations_url":"https://api.github.com/users/codice/orgs","repos_url":"https://api.github.com/users/codice/repos","events_url":"https://api.github.com/users/codice/events{/privacy}","received_events_url":"https://api.github.com/users/codice/received_events","type":"Organization","site_admin":false},"repo":{"id":15173563,"name":"ddf","full_name":"codice/ddf","owner":{"login":"codice","id":2386734,"avatar_url":"https://avatars.githubusercontent.com/u/2386734?v=3","gravatar_id":"","url":"https://api.github.com/users/codice","html_url":"https://github.com/codice","followers_url":"https://api.github.com/users/codice/followers","following_url":"https://api.github.com/users/codice/following{/other_user}","gists_url":"https://api.github.com/users/codice/gists{/gist_id}","starred_url":"https://api.github.com/users/codice/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/codice/subscriptions","organizations_url":"https://api.github.com/users/codice/orgs","repos_url":"https://api.github.com/users/codice/repos","events_url":"https://api.github.com/users/codice/events{/privacy}","received_events_url":"https://api.github.com/users/codice/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/codice/ddf","description":"The Distributed Data Framework - Federated Open Geospatial Consortium (OGC) filter powered metadata catalog with SAML Web SSO secured container","fork":false,"url":"https://api.github.com/repos/codice/ddf","forks_url":"https://api.github.com/repos/codice/ddf/forks","keys_url":"https://api.github.com/repos/codice/ddf/keys{/key_id}","collaborators_url":"https://api.github.com/repos/codice/ddf/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/codice/ddf/teams","hooks_url":"https://api.github.com/repos/codice/ddf/hooks","issue_events_url":"https://api.github.com/repos/codice/ddf/issues/events{/number}","events_url":"https://api.github.com/repos/codice/ddf/events","assignees_url":"https://api.github.com/repos/codice/ddf/assignees{/user}","branches_url":"https://api.github.com/repos/codice/ddf/branches{/branch}","tags_url":"https://api.github.com/repos/codice/ddf/tags","blobs_url":"https://api.github.com/repos/codice/ddf/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/codice/ddf/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/codice/ddf/git/refs{/sha}","trees_url":"https://api.github.com/repos/codice/ddf/git/trees{/sha}","statuses_url":"https://api.github.com/repos/codice/ddf/statuses/{sha}","languages_url":"https://api.github.com/repos/codice/ddf/languages","stargazers_url":"https://api.github.com/repos/codice/ddf/stargazers","contributors_url":"https://api.github.com/repos/codice/ddf/contributors","subscribers_url":"https://api.github.com/repos/codice/ddf/subscribers","subscription_url":"https://api.github.com/repos/codice/ddf/subscription","commits_url":"https://api.github.com/repos/codice/ddf/commits{/sha}","git_commits_url":"https://api.github.com/repos/codice/ddf/git/commits{/sha}","comments_url":"https://api.github.com/repos/codice/ddf/comments{/number}","issue_comment_url":"https://api.github.com/repos/codice/ddf/issues/comments{/number}","contents_url":"https://api.github.com/repos/codice/ddf/contents/{+path}","compare_url":"https://api.github.com/repos/codice/ddf/compare/{base}...{head}","merges_url":"https://api.github.com/repos/codice/ddf/merges","archive_url":"https://api.github.com/repos/codice/ddf/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/codice/ddf/downloads","issues_url":"https://api.github.com/repos/codice/ddf/issues{/number}","pulls_url":"https://api.github.com/repos/codice/ddf/pulls{/number}","milestones_url":"https://api.github.com/repos/codice/ddf/milestones{/number}","notifications_url":"https://api.github.com/repos/codice/ddf/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/codice/ddf/labels{/name}","releases_url":"https://api.github.com/repos/codice/ddf/releases{/id}","deployments_url":"https://api.github.com/repos/codice/ddf/deployments","created_at":"2013-12-13T20:38:28Z","updated_at":"2016-03-17T15:01:17Z","pushed_at":"2016-03-30T21:08:32Z","git_url":"git://github.com/codice/ddf.git","ssh_url":"git@github.com:codice/ddf.git","clone_url":"https://github.com/codice/ddf.git","svn_url":"https://github.com/codice/ddf","homepage":"","size":165887,"stargazers_count":35,"watchers_count":35,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":true,"forks_count":74,"mirror_url":null,"open_issues_count":16,"forks":74,"open_issues":16,"watchers":35,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/codice/ddf/pulls/649"},"html":{"href":"https://github.com/codice/ddf/pull/649"},"issue":{"href":"https://api.github.com/repos/codice/ddf/issues/649"},"comments":{"href":"https://api.github.com/repos/codice/ddf/issues/649/comments"},"review_comments":{"href":"https://api.github.com/repos/codice/ddf/pulls/649/comments"},"review_comment":{"href":"https://api.github.com/repos/codice/ddf/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/codice/ddf/pulls/649/commits"},"statuses":{"href":"https://api.github.com/repos/codice/ddf/statuses/7f1beefb3727dc9db76b86df79cecaf160be9575"}}}}