Author: rwesten
Date: Fri Oct 14 13:38:26 2011
New Revision: 1183356
URL: http://svn.apache.org/viewvc?rev=1183356&view=rev
Log:
fixes STANBOL-328: ResourceLoader has now an option to fail on the first Error.
The RDFIndexingSource activates this feature when loading RDF files
Modified:
incubator/stanbol/trunk/entityhub/indexing/core/src/main/java/org/apache/stanbol/entityhub/indexing/core/source/ResourceLoader.java
incubator/stanbol/trunk/entityhub/indexing/core/src/test/java/org/apache/stanbol/entityhub/indexing/core/ResourceLoaderTest.java
incubator/stanbol/trunk/entityhub/indexing/source/jenatdb/src/main/java/org/apache/stanbol/entityhub/indexing/source/jenatdb/RdfIndexingSource.java
Modified:
incubator/stanbol/trunk/entityhub/indexing/core/src/main/java/org/apache/stanbol/entityhub/indexing/core/source/ResourceLoader.java
URL:
http://svn.apache.org/viewvc/incubator/stanbol/trunk/entityhub/indexing/core/src/main/java/org/apache/stanbol/entityhub/indexing/core/source/ResourceLoader.java?rev=1183356&r1=1183355&r2=1183356&view=diff
==============================================================================
---
incubator/stanbol/trunk/entityhub/indexing/core/src/main/java/org/apache/stanbol/entityhub/indexing/core/source/ResourceLoader.java
(original)
+++
incubator/stanbol/trunk/entityhub/indexing/core/src/main/java/org/apache/stanbol/entityhub/indexing/core/source/ResourceLoader.java
Fri Oct 14 13:38:26 2011
@@ -39,6 +39,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class ResourceLoader {
+ private final boolean failOnError;
private static final Logger log =
LoggerFactory.getLogger(ResourceLoader.class);
private final ResourceImporter resourceImporter;
@@ -50,10 +51,10 @@ public class ResourceLoader {
* parsed to the resource handler.
*/
private boolean loadEntriesWithinZipArchives = true;
- public ResourceLoader(ResourceImporter resourceImporter) {
- this(resourceImporter,true);
+ public ResourceLoader(ResourceImporter resourceImporter,boolean
failOnError) {
+ this(resourceImporter,true,failOnError);
}
- public ResourceLoader(ResourceImporter resourceImporter, boolean
processEntriesWithinArchives) {
+ public ResourceLoader(ResourceImporter resourceImporter, boolean
processEntriesWithinArchives,boolean failOnError) {
if(resourceImporter == null){
throw new IllegalStateException("The parsed ResourceProcessor
instance MUST NOT be NULL!");
}
@@ -61,6 +62,7 @@ public class ResourceLoader {
this.loadEntriesWithinZipArchives = processEntriesWithinArchives;
//use a tree map to have the files sorted
this.files = new TreeMap<String,ResourceState>();
+ this.failOnError = failOnError;
}
/**
@@ -263,6 +265,16 @@ public class ResourceLoader {
if(files.containsKey(file)){
log.debug("File {} now in state {}",file,state);
files.put(file, state);
+ //if failOnError is activated we stop the loading on the first
+ //error!
+ if(failOnError && ResourceState.ERROR == state){
+ String msg = "Error while loading Resource "+file;
+ if(e != null){
+ throw new IllegalStateException(msg,e);
+ } else {
+ throw new IllegalStateException(msg);
+ }
+ }
} else {
log.info("Ignore Error for File {} because it is no longer
registered with this RdfLoader",
file);
Modified:
incubator/stanbol/trunk/entityhub/indexing/core/src/test/java/org/apache/stanbol/entityhub/indexing/core/ResourceLoaderTest.java
URL:
http://svn.apache.org/viewvc/incubator/stanbol/trunk/entityhub/indexing/core/src/test/java/org/apache/stanbol/entityhub/indexing/core/ResourceLoaderTest.java?rev=1183356&r1=1183355&r2=1183356&view=diff
==============================================================================
---
incubator/stanbol/trunk/entityhub/indexing/core/src/test/java/org/apache/stanbol/entityhub/indexing/core/ResourceLoaderTest.java
(original)
+++
incubator/stanbol/trunk/entityhub/indexing/core/src/test/java/org/apache/stanbol/entityhub/indexing/core/ResourceLoaderTest.java
Fri Oct 14 13:38:26 2011
@@ -95,7 +95,7 @@ public class ResourceLoaderTest {
public void testSingleFile(){
DummyResourceImporter importer = new DummyResourceImporter(
Arrays.asList(rootDir+"singleFileTest.txt"));
- ResourceLoader loader = new ResourceLoader(importer, false);
+ ResourceLoader loader = new ResourceLoader(importer, false, false);
loader.addResource(new File(rootDir,"singleFileTest.txt"));
assertEquals(new
HashSet<String>(Arrays.asList(rootDir+"singleFileTest.txt")),
loader.getResources(ResourceState.REGISTERED));
@@ -124,7 +124,7 @@ public class ResourceLoaderTest {
folder+"otherFileInFolder.txt"));
DummyResourceImporter importer = new DummyResourceImporter(
expectedFolderResources);
- ResourceLoader loader = new ResourceLoader(importer, false);
+ ResourceLoader loader = new ResourceLoader(importer, false, false);
loader.addResource(new File(rootDir,"testFolder"));
assertEquals(expectedFolderResources,
loader.getResources(ResourceState.REGISTERED));
assertTrue(loader.getResources(ResourceState.ERROR).isEmpty());
@@ -168,7 +168,7 @@ public class ResourceLoaderTest {
"otherFileInFolder.txt");
DummyResourceImporter importer = new DummyResourceImporter(
expectedResourceNames);
- ResourceLoader loader = new ResourceLoader(importer, true);
+ ResourceLoader loader = new ResourceLoader(importer, true, false);
loader.addResource(new File(rootDir,TEST_FOLDER_NAME));
assertEquals(expectedResources,
loader.getResources(ResourceState.REGISTERED));
Modified:
incubator/stanbol/trunk/entityhub/indexing/source/jenatdb/src/main/java/org/apache/stanbol/entityhub/indexing/source/jenatdb/RdfIndexingSource.java
URL:
http://svn.apache.org/viewvc/incubator/stanbol/trunk/entityhub/indexing/source/jenatdb/src/main/java/org/apache/stanbol/entityhub/indexing/source/jenatdb/RdfIndexingSource.java?rev=1183356&r1=1183355&r2=1183356&view=diff
==============================================================================
---
incubator/stanbol/trunk/entityhub/indexing/source/jenatdb/src/main/java/org/apache/stanbol/entityhub/indexing/source/jenatdb/RdfIndexingSource.java
(original)
+++
incubator/stanbol/trunk/entityhub/indexing/source/jenatdb/src/main/java/org/apache/stanbol/entityhub/indexing/source/jenatdb/RdfIndexingSource.java
Fri Oct 14 13:38:26 2011
@@ -152,7 +152,8 @@ public class RdfIndexingSource implement
}
//init the store
this.indexingDataset = createRdfModel(modelLocation);
- this.loader = new ResourceLoader(new
RdfResourceImporter(indexingDataset), true);
+ //use a ResourceLoader that fails on the first invalid RDF file
(STANBOL-328)
+ this.loader = new ResourceLoader(new
RdfResourceImporter(indexingDataset), true,true);
loader.addResource(sourceFileOrDirectory);
}
@Override