
package galileo.fs;

import java.io.File;
import java.io.IOException;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import galileo.dataset.Block;
import galileo.dataset.Metadata;
import galileo.graph.FeaturePath;
import galileo.graph.MetadataGraph;
import galileo.query.Query;
import galileo.serialization.SerializationException;
import galileo.serialization.Serializer;
import galileo.util.StackTraceToString;

public class GeospatialFileSystem extends FileSystem {

    private static final String metadataStore = "metadata.graph";

    private static final Log logger =
        LogFactory.getLog(GeospatialFileSystem.class);


    public MetadataGraph metadataGraph;

    private GeospatialPhysicalGraph physicalGraph;

    public GeospatialFileSystem(String storageDirectory)
    throws FileSystemException, IOException, SerializationException {
        initialize(storageDirectory);

        File metaFile = new File(storageDirectory + "/" + metadataStore);
        if (metaFile.exists()) {
            metadataGraph = Serializer.restore(MetadataGraph.class, metaFile);
        } else {
            metadataGraph = new MetadataGraph();
        }
        physicalGraph = new GeospatialPhysicalGraph(storageDirectory);
    }

    public void storeBlock(Block block)
    throws FileSystemException, IOException {
        String physicalPath = physicalGraph.storeBlock(block);

        Metadata meta = block.getMetadata();
        FeaturePath<String> path = createPath(physicalPath, meta);

        try {
            metadataGraph.addPath(path);
        } catch (Exception e) {
            throw new FileSystemException("Error storing block: "
                    + e.getClass().getCanonicalName() + ":"
                    + System.lineSeparator() +
                    StackTraceToString.convert(e));
        }
    }

    protected FeaturePath<String> createPath(
            String physicalPath, Metadata meta) {

        FeaturePath<String> path = new FeaturePath<String>(
                physicalPath, meta.getAttributes().toArray());

        return path;
    }

    public MetadataGraph query(Query query) {
        return metadataGraph.evaluateQuery(query);
    }

    public void shutdown() {
        try {
            Serializer.persist(metadataGraph,
                    storageDirectory + "/" + metadataStore);
        } catch (IOException e) {
            logger.error("Error writing persistent index file", e);
        }
    }
}

@@ -72,34 +72,25 @@
 %0Aimport 
-org.apache.commons
+java.util
 .logging
@@ -91,18 +91,20 @@
 ogging.L
-og
+evel
 ;%0Aimport
@@ -108,26 +108,17 @@
 ort 
-org.apache.commons
+java.util
 .log
@@ -125,23 +125,19 @@
 ging.Log
-Factory
+ger
 ;%0A%0Aimpor
@@ -512,143 +512,119 @@
 nal 
-String metadataStore = %22metadata.graph%22;%0A%0A    private static final Log logger =%0A        LogFactory.getLog(GeospatialFileSystem.class);%0A
+Logger logger = Logger.getLogger(%22galileo%22);%0A%0A    private static final String metadataStore = %22metadata.graph%22;
 %0A%0A  
@@ -2372,14 +2372,26 @@
 ger.
-error(
+log(Level.SEVERE, 
 %22Err

Remove auto-imported commons logging framework