Skip to content

Commit

Permalink
[GEOS-8522][GEOS-8501][GEOS-8500] Fix Page results and index result t…
Browse files Browse the repository at this point in the history
…ype support
  • Loading branch information
Nuno Oliveira committed Jan 11, 2018
1 parent 22df2ba commit bca5f89
Show file tree
Hide file tree
Showing 55 changed files with 12,396 additions and 187 deletions.
4 changes: 2 additions & 2 deletions data/citensg-1.0/nsg-profile/configuration.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
resultSets.db.password=sa
resultSets.timeToLive=600
resultSets.db.user=sa
resultSets.db.database=/home/aaime/devel/git-gs/data/citensg-1.0/nsg-profile/db/resultSets
resultSets.db.database=${GEOSERVER_DATA_DIR}/nsg-profile/db/resultSets
resultSets.db.dbtype=h2
resultSets.storage.path=/home/aaime/devel/git-gs/data/citensg-1.0/nsg-profile/resultSets
resultSets.storage.path=${GEOSERVER_DATA_DIR}/nsg-profile/resultSets
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/* (c) 2017 Open Source Geospatial Foundation - all rights reserved
* This code is licensed under the GPL 2.0 license, available at the root
* application directory.
*/
package org.geoserver.nsg;

import org.geoserver.platform.ExtensionFilter;
import org.geoserver.wfs.xml.v2_0.WfsXmlReader;

/**
* Filter GeoServer extensions that are override by NSG extensions.
*/
public class NsgExtensionsFilter implements ExtensionFilter {

@Override
public boolean exclude(String beanId, Object bean) {
return bean instanceof WfsXmlReader && ((WfsXmlReader) bean).getElement().getLocalPart().equalsIgnoreCase("GetFeature");
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@
* @author sandr
*/

public final class IndexInitializer implements GeoServerInitializer {
public final class IndexConfigurationManager implements GeoServerInitializer {

static Logger LOGGER = Logging.getLogger(IndexInitializer.class);
static Logger LOGGER = Logging.getLogger(IndexConfigurationManager.class);

static final String PROPERTY_DB_PREFIX = "resultSets.db.";

Expand All @@ -89,10 +89,9 @@ public final class IndexInitializer implements GeoServerInitializer {
static final String STORE_SCHEMA = "ID:java.lang.String,created:java.lang.Long,updated:java.lang.Long";
private final GeoServerDataDirectory dd;

private IndexConfiguration indexConfiguration;
private final IndexConfiguration indexConfiguration = new IndexConfiguration();

public IndexInitializer(IndexConfiguration indexConfiguration, GeoServerDataDirectory dd) {
this.indexConfiguration = indexConfiguration;
public IndexConfigurationManager(GeoServerDataDirectory dd) {
this.dd = dd;
}

Expand All @@ -107,7 +106,7 @@ public void initialize(GeoServer geoServer) throws Exception {
Resource resource = dd.get(MODULE_DIR + "/" + PROPERTY_FILENAME);
if (resource.getType() == Resource.Type.UNDEFINED) {
Properties properties = new Properties();
try (InputStream stream = IndexInitializer.class
try (InputStream stream = IndexConfigurationManager.class
.getResourceAsStream("/" + PROPERTY_FILENAME)) {
properties.load(stream);
// Replace GEOSERVER_DATA_DIR placeholder
Expand Down Expand Up @@ -143,10 +142,13 @@ public void initialize(GeoServer geoServer) throws Exception {
*/
private void loadConfigurations(Resource resource) throws Exception {
try {
IndexInitializer.READ_WRITE_LOCK.writeLock().lock();
IndexConfigurationManager.READ_WRITE_LOCK.writeLock().lock();
Properties properties = new Properties();
InputStream is = resource.in();
properties.load(is);
// Replace GEOSERVER_DATA_DIR placeholder
properties.replaceAll((k, v) -> ((String) v).replace("${GEOSERVER_DATA_DIR}",
dd.root().getPath()));
is.close();
// Reload database
Map<String, Object> params = new HashMap<>();
Expand Down Expand Up @@ -182,7 +184,7 @@ private void loadConfigurations(Resource resource) throws Exception {
} catch (Exception exception) {
throw new RuntimeException("Error reload configurations.", exception);
} finally {
IndexInitializer.READ_WRITE_LOCK.writeLock().unlock();
IndexConfigurationManager.READ_WRITE_LOCK.writeLock().unlock();
}
}

Expand Down Expand Up @@ -340,7 +342,7 @@ private void moveData(DataStore exDataStore, DataStore newDataStore) throws Exce
public void clean() throws Exception {
Transaction session = new DefaultTransaction("RemoveOld");
try {
IndexInitializer.READ_WRITE_LOCK.writeLock().lock();
IndexConfigurationManager.READ_WRITE_LOCK.writeLock().lock();
// Remove record
Long timeToLive = indexConfiguration.getTimeToLiveInSec();
DataStore currentDataStore = indexConfiguration.getCurrentDataStore();
Expand Down Expand Up @@ -376,7 +378,107 @@ public void clean() throws Exception {
LOGGER.log(Level.WARNING, "Error on clean data", t);
} finally {
session.close();
IndexInitializer.READ_WRITE_LOCK.writeLock().unlock();
IndexConfigurationManager.READ_WRITE_LOCK.writeLock().unlock();
}
}

public DataStore getCurrentDataStore() {
IndexConfigurationManager.READ_WRITE_LOCK.readLock().lock();
try {
return indexConfiguration.getCurrentDataStore();
} finally {
IndexConfigurationManager.READ_WRITE_LOCK.readLock().unlock();
}
}

public Map<String, Object> getCurrentDataStoreParams() {
IndexConfigurationManager.READ_WRITE_LOCK.readLock().lock();
try {
return indexConfiguration.getCurrentDataStoreParams();
} finally {
IndexConfigurationManager.READ_WRITE_LOCK.readLock().unlock();
}
}

public Resource getStorageResource() {
IndexConfigurationManager.READ_WRITE_LOCK.readLock().lock();
try {
return indexConfiguration.getStorageResource();
} finally {
IndexConfigurationManager.READ_WRITE_LOCK.readLock().unlock();
}
}

public Long getTimeToLiveInSec() {
IndexConfigurationManager.READ_WRITE_LOCK.readLock().lock();
try {
return indexConfiguration.getTimeToLiveInSec();
} finally {
IndexConfigurationManager.READ_WRITE_LOCK.readLock().unlock();
}
}

/**
* Class used to store the index result type configuration managed by {@link IndexConfigurationManager}
*
* @author sandr
*/
public class IndexConfiguration {

private DataStore currentDataStore;

private Resource storageResource;

private Long timeToLiveInSec = 600L;

private Map<String, Object> currentDataStoreParams;

/**
* Store the DB parameters and the relative {@link DataStore}
*
* @param currentDataStoreParams
* @param currentDataStore
*/
public void setCurrentDataStore(Map<String, Object> currentDataStoreParams,
DataStore currentDataStore) {
this.currentDataStoreParams = currentDataStoreParams;
this.currentDataStore = currentDataStore;
}

/**
* Store the reference to resource used to archive the serialized GetFeatureRequest
*
* @param storageResource
*/
public void setStorageResource(Resource storageResource) {
this.storageResource = storageResource;
}

/**
* Store the value of time to live of stored GetFeatureRequest
*
* @param timeToLive
* @param timeUnit
*/
public void setTimeToLive(Long timeToLive, TimeUnit timeUnit) {
this.timeToLiveInSec = timeUnit.toSeconds(timeToLive);
}

public DataStore getCurrentDataStore() {
return currentDataStore;
}

public Map<String, Object> getCurrentDataStoreParams() {
return currentDataStoreParams;
}

public Resource getStorageResource() {
return storageResource;
}

public Long getTimeToLiveInSec() {
return timeToLiveInSec;
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
import java.util.logging.Logger;

/**
* This output format handles requests if the original requested result type was "index" </br>
* This output format handles requests if the original requested result type was "index"
* See {@link IndexResultTypeDispatcherCallback}
*
* @author sandr
Expand All @@ -59,9 +59,9 @@ public class IndexOutputFormat extends HitsOutputFormat {

private Request request;

private IndexConfiguration indexConfiguration;
private IndexConfigurationManager indexConfiguration;

public IndexOutputFormat(GeoServer gs, IndexConfiguration indexConfiguration) {
public IndexOutputFormat(GeoServer gs, IndexConfigurationManager indexConfiguration) {
super(gs);
this.indexConfiguration = indexConfiguration;
}
Expand Down Expand Up @@ -114,11 +114,11 @@ protected void encode(FeatureCollectionResponse hits, OutputStream output, WFSIn
*/
private void storeGetFeature(String resultSetId, Request request) throws RuntimeException {
try {
IndexInitializer.READ_WRITE_LOCK.writeLock().lock();
IndexConfigurationManager.READ_WRITE_LOCK.writeLock().lock();
DataStore dataStore = this.indexConfiguration.getCurrentDataStore();
// Create and store new feature
SimpleFeatureStore featureStore = (SimpleFeatureStore) dataStore
.getFeatureSource(IndexInitializer.STORE_SCHEMA_NAME);
.getFeatureSource(IndexConfigurationManager.STORE_SCHEMA_NAME);
SimpleFeatureBuilder builder = new SimpleFeatureBuilder(featureStore.getSchema());
Long now = System.currentTimeMillis();
// Add ID field value (see IndexInitializer.STORE_SCHEMA)
Expand All @@ -140,6 +140,9 @@ private void storeGetFeature(String resultSetId, Request request) throws Runtime
RequestData data = new RequestData();
data.setKvp(kvp);
data.setRawKvp(rawKvp);
if (kvp.containsKey("POST_REQUEST")) {
data.setPostRequest((String) kvp.get("POST_REQUEST"));
}

try (ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(
new File(storageResource.dir(), resultSetId + ".feature")))) {
Expand All @@ -148,7 +151,7 @@ private void storeGetFeature(String resultSetId, Request request) throws Runtime
} catch (Exception exception) {
throw new RuntimeException("Error storing feature.", exception);
} finally {
IndexInitializer.READ_WRITE_LOCK.writeLock().unlock();
IndexConfigurationManager.READ_WRITE_LOCK.writeLock().unlock();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@ public class IndexResultTypeDispatcherCallback extends AbstractDispatcherCallbac

private GeoServer gs;

private IndexConfiguration indexConfiguration;
private IndexConfigurationManager indexConfiguration;

private static final String RESULT_TYPE_PARAMETER = "resultType";

private static final String RESULT_TYPE_INDEX = "index";

static final String RESULT_TYPE_INDEX_PARAMETER = "RESULT_TYPE_INDEX";

public IndexResultTypeDispatcherCallback(GeoServer gs, IndexConfiguration indexConfiguration) {
public IndexResultTypeDispatcherCallback(GeoServer gs, IndexConfigurationManager indexConfiguration) {
this.gs = gs;
this.indexConfiguration = indexConfiguration;
}
Expand Down

0 comments on commit bca5f89

Please sign in to comment.