Skip to content

Commit

Permalink
Merge pull request #185 from daveneiman/tika_bug
Browse files Browse the repository at this point in the history
Fixes in Tika and JHOVE
  • Loading branch information
daveneiman authored Nov 6, 2018
2 parents b1bda17 + 6de7de4 commit 97da781
Show file tree
Hide file tree
Showing 15 changed files with 1,999 additions and 18 deletions.
12 changes: 12 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,18 @@
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcore</artifactId>
<version>4.4.9</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpmime</artifactId>
<version>4.5.5</version>
<scope>test</scope>
</dependency>
</dependencies>

<repositories>
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/edu/harvard/hul/ois/fits/FitsOutput.java
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,9 @@ else if (t.getRunStatus() == RunStatus.SHOULDRUN){
else if (t.getRunStatus() == RunStatus.SHOULDNOTRUN){
tool.setAttribute("status","did not run");
}
else if (t.getRunStatus() == RunStatus.FAILED){
tool.setAttribute("status","failed");
}

statistics.addContent(tool);

Expand Down
132 changes: 128 additions & 4 deletions src/main/java/edu/harvard/hul/ois/fits/tools/ToolBelt.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
import org.apache.log4j.Logger;

import edu.harvard.hul.ois.fits.Fits;
import edu.harvard.hul.ois.fits.exceptions.FitsToolException;
import edu.harvard.hul.ois.fits.identity.ToolIdentity;
import edu.harvard.hul.ois.fits.tools.utils.ParentLastClassLoader;

public class ToolBelt {
Expand Down Expand Up @@ -131,15 +133,21 @@ private void init(XMLConfiguration config, Fits fits) {
t.applyToolsUsed (toolsUsedList);
tools.add(t);
}
} catch(ReflectiveOperationException |
MalformedURLException ex) {
} catch(Exception ex) {
// Catch and report any exception during tool instantiation, otherwise
// exception might be lost on thread creation.
// Can't use this tool, but continue anyway.
//throw new FitsConfigurationException("Error initializing "+tClass,e);
logger.error ("Thread "+Thread.currentThread().getId() +
" error initializing " + tClass +
": " + ex.getClass().getName() +
" Message: " + ex.getMessage(), ex);
continue;

// Capture tool error so failure can be reported for tool, then move on to next tool
ToolInfo info = new ToolInfo(bareClassName(tClass), "[unknown]", null);
Tool tool = getFailedTool(info);
tools.add(tool);
continue;

} finally {
// ***** IMPORTANT: set back original ClassLoader if changed *****
if (Thread.currentThread().getContextClassLoader() != savedClassLoader) {
Expand Down Expand Up @@ -294,4 +302,120 @@ private File getFileFromName(String dirName) throws MalformedURLException {
File dirFile = new File(fullPathPrefix + dirName);
return dirFile;
}

/*
* Creates a skeletal instance of Tool that indicates a 'failed' state that is not enabled to run.
*
* @param toolInfo Contains tool name and version (which is unknown in this situation).
*
* @return Tool which indicates a failed state and not enabled.
*/
private Tool getFailedTool(final ToolInfo toolInfo) {

Tool failedTool = new Tool() {

@Override
public void run() {}

@Override
public ToolOutput extractInfo(File file) throws FitsToolException {
return null;
}

@Override
public boolean isIdentityKnown(ToolIdentity identity) {
return false;
}

@Override
public ToolInfo getToolInfo() {
return toolInfo;
}

@Override
public Boolean canIdentify() {
return false;
}

@Override
public String getName() {
return toolInfo.getName();
}

@Override
public void setName(String name) {}

@Override
public void addExcludedExtension(String ext) {}

@Override
public void addIncludedExtension(String ext) {}

@Override
public boolean hasExcludedExtension(String ext) {
return true;
}

@Override
public boolean hasIncludedExtension(String ext) {
return false;
}

@Override
public boolean hasIncludedExtensions() {
return false;
}

@Override
public boolean hasExcludedExtensions() {
return false;
}

@Override
public void applyToolsUsed(List<ToolsUsedItem> toolsUsedItems) {}

@Override
public void resetOutput() {}

/**
* Indicates that the tool is not enabled so should be no attempt to run tool.
*/
@Override
public boolean isEnabled() {
return false;
}

@Override
public void setEnabled(boolean value) {}

@Override
public void setInputFile(File file) {}

@Override
public ToolOutput getOutput() {
return null;
}

@Override
public long getDuration() {
return 0;
}

/**
* Return status that shows the tool failed.
*/
@Override
public RunStatus getRunStatus() {
return RunStatus.FAILED;
}

@Override
public void setRunStatus(RunStatus runStatus) {}

@Override
public void addExceptions(List<Throwable> exceptions) {}
};

return failedTool;
}
}
24 changes: 12 additions & 12 deletions src/main/java/edu/harvard/hul/ois/fits/tools/ToolInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,10 @@
*/
public class ToolInfo {

public String name;
public String version;
public String date;
public String note;

public String getNote() {
return note;
}

public void setNote(String note) {
this.note = note;
}
private String name;
private String version;
private String date;
private String note;

public ToolInfo() {

Expand Down Expand Up @@ -74,6 +66,14 @@ public String print() {
return value;
}

public String getNote() {
return note;
}

public void setNote(String note) {
this.note = note;
}

@Override
public String toString() {
StringBuilder sb = new StringBuilder("ToolInfo: [");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ private enum TikaProperty {
public TikaTool(Fits fits) throws FitsToolException {
super();
try {
TikaConfig config = new TikaConfig("xml/tika/tika-config.xml");
TikaConfig config = new TikaConfig(Fits.FITS_XML_DIR + "tika" + File.separator + "tika-config.xml");
tika = new Tika (config);
} catch (Exception e) {
throw new FitsToolException("Problem loading tika-config.xml", e);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*
* Copyright 2016 Harvard University Library
*
* This file is part of FITS (File Information Tool Set).
*
* FITS is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* FITS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with FITS. If not, see <http://www.gnu.org/licenses/>.
*/
package edu.harvard.hul.ois.fits.junit.service;

import java.io.File;
import java.util.Scanner;

import org.jdom.output.Format;
import org.jdom.output.XMLOutputter;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;

import edu.harvard.hul.ois.fits.FitsOutput;
import edu.harvard.hul.ois.fits.tests.AbstractXmlUnitTest;

/**
* These tests compare actual FITS output with expected output on Adobe Illustrator files.
* NOTE: This is an integration test that requires a running web application with the
* FITS Service running.
*
* @author dan179
*/
@Ignore
public class AdobeIllustratorXmlUnitServiceTest extends AbstractXmlUnitTest {

@BeforeClass
public static void initializeHttpClient() throws Exception {
AbstractXmlUnitTest.beforeServiceTest();
}

@AfterClass
public static void afterClass() throws Exception {
AbstractXmlUnitTest.afterServiceTest();
}

@Test
public void testAdobeIllustratorFile() throws Exception {

String inputFilename = "MMS-82A.08.12.02.ai";
File input = new File("testfiles/" + inputFilename);

FitsOutput fitsOut = super.examine(input);

fitsOut.saveToDisk("test-generated-output/" + inputFilename + ACTUAL_OUTPUT_FILE_SUFFIX);

XMLOutputter serializer = new XMLOutputter(Format.getPrettyFormat());
String actualXmlStr = serializer.outputString(fitsOut.getFitsXml());

// Read in the expected XML file
Scanner scan = new Scanner(new File(
"testfiles/output/" + inputFilename + EXPECTED_OUTPUT_FILE_SUFFIX));
String expectedXmlStr = scan.
useDelimiter("\\Z").next();
scan.close();

testActualAgainstExpected(actualXmlStr, expectedXmlStr, inputFilename);
}

}
Loading

0 comments on commit 97da781

Please sign in to comment.