Skip to content

Commit

Permalink
Add code to get granule acceptor from indexer config, or fallback to …
Browse files Browse the repository at this point in the history
…default
  • Loading branch information
Devon Tucker committed Jun 17, 2016
1 parent 98a869f commit bcc41ba
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 3 deletions.
Expand Up @@ -34,6 +34,7 @@
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Properties;
Expand Down Expand Up @@ -63,13 +64,16 @@
import org.geotools.data.collection.ListFeatureCollection;
import org.geotools.data.shapefile.ShapefileDataStoreFactory;
import org.geotools.data.simple.SimpleFeatureCollection;
import org.geotools.factory.FactoryRegistry;
import org.geotools.factory.Hints;
import org.geotools.factory.Hints.Key;
import org.geotools.feature.collection.AbstractFeatureVisitor;
import org.geotools.feature.simple.SimpleFeatureTypeBuilder;
import org.geotools.gce.imagemosaic.Utils.Prop;
import org.geotools.gce.imagemosaic.acceptors.DefaultGranuleAcceptor;
import org.geotools.gce.imagemosaic.acceptors.GranuleAcceptor;
import org.geotools.gce.imagemosaic.acceptors.GranuleAcceptorFactorySPI;
import org.geotools.gce.imagemosaic.acceptors.GranuleAcceptorFinder;
import org.geotools.gce.imagemosaic.catalog.CatalogConfigurationBean;
import org.geotools.gce.imagemosaic.catalog.GranuleCatalog;
import org.geotools.gce.imagemosaic.catalog.GranuleCatalogFactory;
Expand Down Expand Up @@ -248,8 +252,27 @@ public class ImageMosaicConfigHandler {
* @param indexer the indexer configuration
*/
private List<GranuleAcceptor> initializeGranuleAcceptors(Indexer indexer) {
// TODO update to actually do something useful, just want to get a stub here for now
return Collections.singletonList(new DefaultGranuleAcceptor());
List<GranuleAcceptor> finalGranuleAcceptors = new ArrayList<>();

if (indexer != null) {
String granuleAcceptorsString = IndexerUtils.getParameter(Prop.GRANULE_ACCEPTORS, indexer);
Map<String, GranuleAcceptorFactorySPI> granuleAcceptorsMap =
GranuleAcceptorFinder.getPropertiesCollectorSPI();
if (granuleAcceptors != null && !granuleAcceptors.isEmpty()) {
Arrays.stream(granuleAcceptorsString.split(",")).forEach((factoryImpl) -> {
if (granuleAcceptorsMap.containsKey(factoryImpl)) {
finalGranuleAcceptors.add(granuleAcceptorsMap.get(factoryImpl).create());
}
});
}
}

//if we didn't find any granule acceptors in the index configuration, use the default
if (finalGranuleAcceptors.isEmpty()) {
finalGranuleAcceptors.add(new DefaultGranuleAcceptor());
}

return finalGranuleAcceptors;
}

/**
Expand Down Expand Up @@ -911,7 +934,7 @@ private void loadPropertyCollectors() {
.getPropertiesCollectorSPI();

// parse the string
final List<PropertiesCollector> pcs = new ArrayList<PropertiesCollector>();
final List<PropertiesCollector> pcs = new ArrayList<>();
for (Collector collector : collectorList) {
PropertiesCollectorSPI selectedSPI = null;
final String spiName = collector.getSpi();
Expand Down
Expand Up @@ -270,6 +270,8 @@ public static class Prop {
public final static String CACHING = "Caching";

public static final String WRAP_STORE = "WrapStore";

public static final String GRANULE_ACCEPTORS = "GranuleAcceptors";
}

/**
Expand Down
@@ -0,0 +1,57 @@
/*
* GeoTools - The Open Source Java GIS Toolkit
* http://geotools.org
*
* (C) 2016, Open Source Geospatial Foundation (OSGeo)
*
* This library 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;
* version 2.1 of the License.
*
* This library 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.
*/

package org.geotools.gce.imagemosaic.acceptors;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

import org.geotools.factory.FactoryCreator;
import org.geotools.factory.FactoryRegistry;

/**
* Helper to find GranuleFactorySPI instances
*/
public class GranuleAcceptorFinder {

private static FactoryCreator registry;

public static synchronized Map<String, GranuleAcceptorFactorySPI> getPropertiesCollectorSPI() {
// get all GridFormatFactorySpi implementations
final Iterator<GranuleAcceptorFactorySPI> it = getServiceRegistry().getServiceProviders(GranuleAcceptorFactorySPI.class, true);
Map<String, GranuleAcceptorFactorySPI> acceptorFactorySPIMap = new HashMap<>();
while (it.hasNext()) {
GranuleAcceptorFactorySPI granuleAcceptorFactorySPI = it.next();
acceptorFactorySPIMap.put(granuleAcceptorFactorySPI.getClass().getName(),
granuleAcceptorFactorySPI);
}
return acceptorFactorySPIMap;
}

/**
* Returns the service registry. The registry will be created the first time
* this method is invoked.
*/
private static FactoryRegistry getServiceRegistry() {
if (registry == null) {
registry = new FactoryCreator(Arrays.asList(new Class<?>[] { GranuleAcceptorFactorySPI.class }));
}
return registry;
}
}

0 comments on commit bcc41ba

Please sign in to comment.