Skip to content

Commit

Permalink
[GEOS-7544] Use File for Importer (not Resource)
Browse files Browse the repository at this point in the history
  • Loading branch information
tbarsballe authored and jodygarnett committed May 21, 2016
1 parent 8e85f6a commit ce3624f
Show file tree
Hide file tree
Showing 34 changed files with 325 additions and 416 deletions.
@@ -1,4 +1,4 @@
/* (c) 2014 Open Source Geospatial Foundation - all rights reserved
/* (c) 2014 - 2016 Open Source Geospatial Foundation - all rights reserved
* (c) 2001 - 2013 OpenPlans
* This code is licensed under the GPL 2.0 license, available at the root
* application directory.
Expand All @@ -21,7 +21,6 @@
import org.geoserver.importer.ImportStore;
import org.geoserver.importer.ImportTask;
import org.geoserver.importer.Importer;
import org.geoserver.platform.resource.Resource;

import com.sleepycat.bind.EntryBinding;
import com.sleepycat.bind.serial.ClassCatalog;
Expand Down Expand Up @@ -114,9 +113,10 @@ public void init() {
envCfg.setTransactional(true);
envCfg.setConfigParam("je.log.fileMax", String.valueOf(100 * 1024 * 1024));

Resource dbRoot = importer.getImportRoot().get("bdb");
File dbRoot = new File(importer.getImportRoot(), "bdb");
dbRoot.mkdir();

Environment env = new Environment(dbRoot.dir(), envCfg);
Environment env = new Environment(dbRoot, envCfg);

DatabaseConfig dbConfig = new DatabaseConfig();
dbConfig.setAllowCreate(true);
Expand Down
Expand Up @@ -23,8 +23,6 @@
import org.geoserver.importer.ImporterTestSupport;
import org.geoserver.importer.RemoteData;
import org.geoserver.importer.bdb.BDBImportStore.BindingType;
import org.geoserver.platform.resource.Files;
import org.geoserver.platform.resource.Resource;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
Expand All @@ -46,7 +44,7 @@ public static Collection<Object[]> data() {
}

BDBImportStore store;
Resource dbRoot;
File dbRoot;

private BindingType bindingType;

Expand All @@ -59,7 +57,7 @@ public void setupStoreField() throws Exception {
store = new BDBImportStore(importer);
store.setBinding(bindingType);
store.init();
dbRoot = importer.getImportRoot().get("bdb");
dbRoot = new File(importer.getImportRoot(), "bdb");
}

// in order to test this, run once, then change the serialVersionUID of ImportContext2
Expand All @@ -68,8 +66,10 @@ public void testSerialVersionUIDChange() throws Exception {
Importer imp = new Importer(null) {

@Override
public Resource getImportRoot() {
return Files.asResource(new File("target"));
public File getImportRoot() {
File root = new File("target");
root.mkdirs();
return root;
}

};
Expand Down Expand Up @@ -227,7 +227,7 @@ public boolean isFound() {
public void destroyStore() throws Exception {
store.destroy();
// clean up the databse
dbRoot.delete();
FileUtils.deleteDirectory(dbRoot);

}
}
Expand Up @@ -5,11 +5,11 @@
*/
package org.geoserver.importer;

import org.geoserver.platform.resource.Resource;
import java.io.File;

public class ASpatialFile extends FileData {

public ASpatialFile(Resource file) {
public ASpatialFile(File file) {
super(file);
}

Expand Down
Expand Up @@ -8,35 +8,18 @@
import java.io.File;
import java.io.IOException;

import org.geoserver.platform.resource.Files;
import org.geoserver.platform.resource.Resource;

public class Archive extends Directory {

private static final long serialVersionUID = -6007727652626093242L;

/**
*
* Create archive from a resource.
*
* @param resource the resource
* @throws IOException
*/
public Archive(Resource resource) throws IOException {
super(Directory.createFromArchive(resource).getFile());
}

/**
*
* Create archive from a file.
*
* @param file the file
* @throws IOException
* @deprecated Use Resource instead of File
*/
@Deprecated
public Archive(File file) throws IOException {
this(Files.asResource(file));
super(Directory.createFromArchive(file).getFile());
}

}
Expand Up @@ -22,7 +22,6 @@
import org.geoserver.platform.GeoServerExtensions;
import org.geoserver.platform.resource.Files;
import org.geoserver.platform.resource.Paths;
import org.geoserver.platform.resource.Resource;
import org.geotools.coverage.grid.io.AbstractGridFormat;
import org.geotools.coverage.grid.io.GridFormatFinder;
import org.geotools.coverage.grid.io.UnknownFormat;
Expand All @@ -48,18 +47,8 @@ public abstract class DataFormat implements Serializable {

/**
* looks up a format based on file extension.
*
* @deprecated Use {@link #lookup(Resource)}
*/
@Deprecated
public static DataFormat lookup(File file) {
return lookup(Files.asResource(file));
}

/**
* looks up a format based on file extension.
*/
public static DataFormat lookup(Resource file) {
FileData fileData = new FileData(file);
for (DataFormat df : GeoServerExtensions.extensions(DataFormat.class)) {
try {
Expand All @@ -68,19 +57,19 @@ public static DataFormat lookup(Resource file) {
}
} catch (IOException e) {
LOG.log(Level.FINER, String.format("Error checking if format %s can read file %s, " +
df.getName(), file.path()), e);
df.getName(), file.getPath()), e);
}
}

//look for a datastore that can handle the file
String ext = FilenameUtils.getExtension(file.name());
String ext = FilenameUtils.getExtension(file.getName());
FileDataStoreFactorySpi factory = FileDataStoreFinder.getDataStoreFactory(ext);
if (factory != null) {
return new DataStoreFormat(factory);
}

//look for a gridformat that can handle the file
Set<AbstractGridFormat> formats = GridFormatFinder.findFormats(file.file());
Set<AbstractGridFormat> formats = GridFormatFinder.findFormats(file);
AbstractGridFormat format = null;
// in the case of 2 formats, let's ensure any ambiguity that cannot
// be resolved is an error to prevent spurious bugs related to
Expand Down Expand Up @@ -149,10 +138,10 @@ public abstract List<ImportTask> list(ImportData data, Catalog catalog, Progress
* @param data
*
*/
protected Resource getFileFromData(ImportData data) {
protected File getFileFromData(ImportData data) {
assert data instanceof FileData;
FileData fileData = (FileData) data;
Resource file = fileData.getFile();
File file = fileData.getFile();
return file;
}

Expand Down
Expand Up @@ -5,6 +5,7 @@
*/
package org.geoserver.importer;

import java.io.File;
import java.io.IOException;
import java.io.Serializable;
import java.util.ArrayList;
Expand All @@ -25,6 +26,7 @@
import org.geoserver.catalog.WorkspaceInfo;
import org.geotools.data.DataStore;
import org.geotools.data.DataStoreFactorySpi;
import org.geotools.data.DataUtilities;
import org.geotools.data.FeatureReader;
import org.geotools.data.FileDataStoreFactorySpi;
import org.geotools.data.Query;
Expand All @@ -33,8 +35,6 @@
import org.geotools.jdbc.JDBCDataStoreFactory;
import org.geotools.util.logging.Logging;
import org.geoserver.importer.job.ProgressMonitor;
import org.geoserver.platform.resource.Resource;
import org.geoserver.platform.resource.Resources;
import org.opengis.feature.simple.SimpleFeatureType;
import org.opengis.feature.type.AttributeDescriptor;
import org.opengis.feature.type.FeatureType;
Expand Down Expand Up @@ -214,7 +214,7 @@ public DataStore createDataStore(ImportData data) throws IOException {
public Map<String,Serializable> createConnectionParameters(ImportData data, Catalog catalog) throws IOException {
//try file based
if (dataStoreFactory instanceof FileDataStoreFactorySpi) {
Resource f = null;
File f = null;
if (data instanceof SpatialFile) {
f = ((SpatialFile) data).getFile();
}
Expand All @@ -224,7 +224,7 @@ public Map<String,Serializable> createConnectionParameters(ImportData data, Cata

if (f != null) {
Map<String,Serializable> map = new HashMap<String, Serializable>();
map.put("url", relativeDataFileURL(Resources.find(f).toURI().toURL().toString(), catalog));
map.put("url", relativeDataFileURL(DataUtilities.fileToURL(f).toString(), catalog));
if (data.getCharsetEncoding() != null) {
// @todo this map only work for shapefile
map.put("charset",data.getCharsetEncoding());
Expand Down

0 comments on commit ce3624f

Please sign in to comment.