Skip to content

Commit

Permalink
- Remove ResourceStore interface from a number of classes that were just
Browse files Browse the repository at this point in the history
  delegating to actual implementations
- Changed the spring config for the resource store to support a factory
  approach that checks for a "resourceStoreImpl" bean before
  falling back to the DataDirectory based resource store.
- Remove now unneeded ResourceStore methods from classes that had that
  interface removed
- Update the copyright on resource loader
- Update resourcestorefactory to refer to bean by name rather than class
  • Loading branch information
Devon Tucker authored and jodygarnett committed Feb 24, 2016
1 parent e4b7cad commit 8039744
Show file tree
Hide file tree
Showing 9 changed files with 133 additions and 258 deletions.
@@ -1,14 +1,9 @@
/* (c) 2016 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.jdbcconfig.internal; package org.geoserver.jdbcconfig.internal;


import static org.junit.Assert.*;
import static org.geoserver.jdbcconfig.JDBCConfigTestSupport.*;
import static org.hamcrest.CoreMatchers.*;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Properties;

import org.apache.commons.io.FileUtils; import org.apache.commons.io.FileUtils;
import org.geoserver.jdbcloader.JDBCLoaderPropertiesFactoryBean; import org.geoserver.jdbcloader.JDBCLoaderPropertiesFactoryBean;
import org.geoserver.platform.GeoServerResourceLoader; import org.geoserver.platform.GeoServerResourceLoader;
Expand All @@ -17,6 +12,15 @@
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;


import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Properties;

import static org.geoserver.jdbcconfig.JDBCConfigTestSupport.createTempDir;
import static org.hamcrest.CoreMatchers.containsString;
import static org.junit.Assert.*;

public class JDBCConfigPropertiesTest { public class JDBCConfigPropertiesTest {


protected static final String CONFIG_FILE = "jdbcconfig.properties"; protected static final String CONFIG_FILE = "jdbcconfig.properties";
Expand Down
18 changes: 4 additions & 14 deletions src/community/jdbcstore/src/main/resources/applicationContext.xml
@@ -1,13 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" <beans xmlns="http://www.springframework.org/schema/beans"
xmlns:jdbc="http://www.springframework.org/schema/jdbc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:tx = "http://www.springframework.org/schema/tx" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
">


<!-- main configuration, loaded via factory bean --> <!-- main configuration, loaded via factory bean -->
<bean id="jdbcStoreProperties" <bean id="jdbcStoreProperties"
Expand All @@ -25,7 +19,7 @@
</bean> </bean>


<!-- resource store --> <!-- resource store -->
<bean id="jdbcResourceStore" class="org.geoserver.jdbcstore.JDBCResourceStoreFactoryBean"> <bean id="resourceStoreImpl" class="org.geoserver.jdbcstore.JDBCResourceStoreFactoryBean">
<constructor-arg ref="dataDirectoryResourceStore" /> <constructor-arg ref="dataDirectoryResourceStore" />
<constructor-arg ref="jdbcStoreDataSource" /> <constructor-arg ref="jdbcStoreDataSource" />
<constructor-arg ref="jdbcStoreProperties" /> <constructor-arg ref="jdbcStoreProperties" />
Expand All @@ -34,8 +28,4 @@
<property name="resourceNotificationDispatcher" ref="resourceNotificationDispatcher"/> <property name="resourceNotificationDispatcher" ref="resourceNotificationDispatcher"/>
</bean> </bean>


<bean id="resourceStore" class="org.geoserver.platform.resource.ResourceStoreProxy">
<property name="delegate" ref="jdbcResourceStore"/>
</bean>

</beans> </beans>
7 changes: 4 additions & 3 deletions src/main/src/main/java/applicationContext.xml
Expand Up @@ -22,10 +22,11 @@
<!-- resources --> <!-- resources -->
<bean id="dataDirectoryResourceStore" class="org.geoserver.platform.resource.DataDirectoryResourceStore"> <bean id="dataDirectoryResourceStore" class="org.geoserver.platform.resource.DataDirectoryResourceStore">
<property name="lockProvider" ref="lockProvider"/> <property name="lockProvider" ref="lockProvider"/>
</bean>
<bean id="resourceStore" class="org.geoserver.platform.resource.ResourceStoreProxy">
<property name="delegate" ref="dataDirectoryResourceStore"/>
</bean> </bean>

<bean id="resourceStore" class="org.geoserver.platform.resource.ResourceStoreFactory"
depends-on="dataDirectoryResourceStore"/>

<bean id="resourceLoader" class="org.geoserver.platform.GeoServerResourceLoader"> <bean id="resourceLoader" class="org.geoserver.platform.GeoServerResourceLoader">
<constructor-arg ref="resourceStore"/> <constructor-arg ref="resourceStore"/>
</bean> </bean>
Expand Down
@@ -1,59 +1,32 @@
/* (c) 2014 - 2015 Open Source Geospatial Foundation - all rights reserved /* (c) 2014 - 2016 Open Source Geospatial Foundation - all rights reserved
* (c) 2001 - 2013 OpenPlans * (c) 2001 - 2013 OpenPlans
* This code is licensed under the GPL 2.0 license, available at the root * This code is licensed under the GPL 2.0 license, available at the root
* application directory. * application directory.
*/ */
package org.geoserver.config; package org.geoserver.config;


import org.apache.commons.io.FileUtils;
import org.geoserver.catalog.*;
import org.geoserver.platform.GeoServerResourceLoader;
import org.geoserver.platform.resource.Paths;
import org.geoserver.platform.resource.Resource;
import org.geoserver.platform.resource.Resource.Type;
import org.geoserver.platform.resource.ResourceStore;
import org.geoserver.platform.resource.Resources;
import org.geotools.data.DataUtilities;
import org.geotools.styling.*;

import javax.annotation.Nonnull;
import java.io.File; import java.io.File;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.OutputStream;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.net.URI;
import java.net.URL; import java.net.URL;
import java.net.URLConnection;
import java.net.URLStreamHandler;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.logging.Level; import java.util.logging.Level;


import javax.annotation.Nonnull;
import javax.annotation.Nullable;

import org.apache.commons.io.FileUtils;
import org.geoserver.catalog.CoverageInfo;
import org.geoserver.catalog.CoverageStoreInfo;
import org.geoserver.catalog.DataStoreInfo;
import org.geoserver.catalog.FeatureTypeInfo;
import org.geoserver.catalog.LayerGroupInfo;
import org.geoserver.catalog.LayerInfo;
import org.geoserver.catalog.NamespaceInfo;
import org.geoserver.catalog.ResourceInfo;
import org.geoserver.catalog.StoreInfo;
import org.geoserver.catalog.StyleInfo;
import org.geoserver.catalog.Styles;
import org.geoserver.catalog.WMSLayerInfo;
import org.geoserver.catalog.WMSStoreInfo;
import org.geoserver.catalog.WorkspaceInfo;
import org.geoserver.platform.GeoServerResourceLoader;
import org.geoserver.platform.resource.Files;
import org.geoserver.platform.resource.Paths;
import org.geoserver.platform.resource.Resource;
import org.geoserver.platform.resource.Resource.Type;
import org.geoserver.platform.resource.ResourceNotificationDispatcher;
import org.geoserver.platform.resource.ResourceStore;
import org.geoserver.platform.resource.Resources;
import org.geotools.data.DataUtilities;
import org.geotools.styling.AbstractStyleVisitor;
import org.geotools.styling.ChannelSelection;
import org.geotools.styling.DefaultResourceLocator;
import org.geotools.styling.ExternalGraphic;
import org.geotools.styling.SelectedChannelType;
import org.geotools.styling.Style;
import org.geotools.styling.StyledLayerDescriptor;

/** /**
* File or Resource access to GeoServer data directory. In addition to paths Catalog obhjects such as workspace or FeatureTypeInfo can be used to * File or Resource access to GeoServer data directory. In addition to paths Catalog obhjects such as workspace or FeatureTypeInfo can be used to
* locate resources. * locate resources.
Expand Down Expand Up @@ -81,7 +54,7 @@
* @author Justin Deoliveira, OpenGeo * @author Justin Deoliveira, OpenGeo
*/ */
@SuppressWarnings("unused") @SuppressWarnings("unused")
public class GeoServerDataDirectory implements ResourceStore { public class GeoServerDataDirectory {


/** /**
* resource loader * resource loader
Expand Down Expand Up @@ -109,21 +82,10 @@ public GeoServerResourceLoader getResourceLoader() {
return resourceLoader; return resourceLoader;
} }


@Override
public Resource get(String path) { public Resource get(String path) {
return resourceLoader.get(path); return resourceLoader.get(path);
} }


@Override
public boolean move(String path, String target) {
return resourceLoader.move(path, target);
}

@Override
public boolean remove(String path) {
return resourceLoader.remove(path);
}

/** /**
* The root of the data directory. * The root of the data directory.
*/ */
Expand Down Expand Up @@ -1394,9 +1356,7 @@ public static URL fileToUrlPreservingCqlTemplates(File file) {
} }
} }


@Override public ResourceStore getResourceStore() {
public ResourceNotificationDispatcher getResourceNotificationDispatcher() { return resourceLoader.getResourceStore();
return resourceLoader.getResourceNotificationDispatcher();
} }

} }
@@ -1,21 +1,21 @@
/* (c) 2014 Open Source Geospatial Foundation - all rights reserved /* (c) 2014 - 2016 Open Source Geospatial Foundation - all rights reserved
* (c) 2001 - 2013 OpenPlans * (c) 2001 - 2013 OpenPlans
* This code is licensed under the GPL 2.0 license, available at the root * This code is licensed under the GPL 2.0 license, available at the root
* application directory. * application directory.
*/ */
package org.geoserver.config; package org.geoserver.config;


import org.geotools.util.logging.Logging;
import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;
import org.springframework.core.io.Resource;

import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.IOException; import java.io.IOException;
import java.io.OutputStream; import java.io.OutputStream;
import java.util.Properties; import java.util.Properties;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;


import org.geotools.util.logging.Logging;
import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;
import org.springframework.core.io.Resource;

/** /**
* A spring placeholder configurer that loads properties from the data directory. * A spring placeholder configurer that loads properties from the data directory.
* <p> * <p>
Expand Down Expand Up @@ -82,7 +82,7 @@ public org.geoserver.platform.resource.Resource getConfigFile() {
@Override @Override
public void setLocation(Resource location) { public void setLocation(Resource location) {
try { try {
location = SpringResourceAdaptor.relative(location, data); location = SpringResourceAdaptor.relative(location, data.getResourceStore());
if (location instanceof SpringResourceAdaptor) { if (location instanceof SpringResourceAdaptor) {
configFile = ((SpringResourceAdaptor) location).getResource(); configFile = ((SpringResourceAdaptor) location).getResource();
} }
Expand Down
@@ -1,19 +1,18 @@
/* (c) 2015 Open Source Geospatial Foundation - all rights reserved /* (c) 2015 - 2016 Open Source Geospatial Foundation - all rights reserved
* This code is licensed under the GPL 2.0 license, available at the root * This code is licensed under the GPL 2.0 license, available at the root
* application directory. * application directory.
*/ */
package org.geoserver.config; package org.geoserver.config;


import org.geotools.util.logging.Logging;
import org.springframework.beans.factory.config.PropertyOverrideConfigurer;
import org.springframework.core.io.Resource;

import java.io.IOException; import java.io.IOException;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import java.util.regex.Pattern; import java.util.regex.Pattern;


import org.geoserver.config.GeoServerDataDirectory;
import org.geotools.util.logging.Logging;
import org.springframework.beans.factory.config.PropertyOverrideConfigurer;
import org.springframework.core.io.Resource;

/** /**
* *
* Allows the use of ${GEOSERVER_DATA_DIR} inside properties to refer to the data directory, * Allows the use of ${GEOSERVER_DATA_DIR} inside properties to refer to the data directory,
Expand All @@ -37,7 +36,7 @@ public GeoServerPropertyOverrideConfigurer(GeoServerDataDirectory data) {
@Override @Override
public void setLocation(Resource location) { public void setLocation(Resource location) {
try { try {
location = SpringResourceAdaptor.relative(location, data); location = SpringResourceAdaptor.relative(location, data.getResourceStore());
} catch(IOException e) { } catch(IOException e) {
LOGGER.log(Level.WARNING, "Error reading resource " + location, e); LOGGER.log(Level.WARNING, "Error reading resource " + location, e);
} }
Expand All @@ -50,7 +49,8 @@ public void setLocations(Resource[] locations) {
Resource[] newLocations = new Resource[locations.length]; Resource[] newLocations = new Resource[locations.length];
for (int i = 0; i < locations.length; i++) { for (int i = 0; i < locations.length; i++) {
try { try {
newLocations[i] = SpringResourceAdaptor.relative(locations[i], data); newLocations[i] = SpringResourceAdaptor.relative(
locations[i], data.getResourceStore());
} catch (IOException e) { } catch (IOException e) {
LOGGER.log(Level.WARNING, "Error reading resource " + locations[i], e); LOGGER.log(Level.WARNING, "Error reading resource " + locations[i], e);
newLocations[i] = locations[i]; newLocations[i] = locations[i];
Expand Down

0 comments on commit 8039744

Please sign in to comment.