Skip to content

Commit

Permalink
Prevent unavailable backend options from being selected for GeoGig re…
Browse files Browse the repository at this point in the history
…positories

Signed-off-by: Erik Merkle <emerkle@boundlessgeo.com>
  • Loading branch information
Erik Merkle committed Jun 16, 2017
1 parent 8d09c28 commit 46029eb
Show file tree
Hide file tree
Showing 14 changed files with 492 additions and 68 deletions.
79 changes: 58 additions & 21 deletions src/community/geogig/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@
<mockito.version>1.8.5</mockito.version>
<logback.version>1.1.2</logback.version>
<cucumber-java.version>1.2.4</cucumber-java.version>
<!--
The PostgreSQL version should match the version as depended upon transitively by
gt-jdbc-postgis. It is set here because it is not a managed dependency in the POM
hierarchy and we need it to compile and run tests. It is marked as "provided" in
the dependency seciton below.
-->
<postgresql.version>9.4.1211</postgresql.version>
<hikaricp.version>2.4.2</hikaricp.version>
</properties>

<repositories>
Expand Down Expand Up @@ -49,11 +57,6 @@
<artifactId>logback-classic</artifactId>
<version>${logback.version}</version>
</dependency>
<dependency>
<groupId>org.locationtech.geogig</groupId>
<artifactId>geogig-cli</artifactId>
<version>${geogig.version}</version>
</dependency>
<dependency>
<groupId>org.locationtech.geogig</groupId>
<artifactId>geogig-geotools</artifactId>
Expand All @@ -70,9 +73,9 @@
<version>${geogig.version}</version>
</dependency>
<dependency>
<groupId>org.locationtech.geogig</groupId>
<artifactId>geogig-postgres</artifactId>
<version>${geogig.version}</version>
<groupId>com.zaxxer</groupId>
<artifactId>HikariCP</artifactId>
<version>${hikaricp.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
Expand All @@ -93,43 +96,46 @@
<dependency>
<groupId>org.geotools.jdbc</groupId>
<artifactId>gt-jdbc-postgis</artifactId>
<version>${gt.version}</version>
<scope>provided</scope>
</dependency>
<!--
This is an explicit "provided" dependency as the PostgreSQL library is a transitive dependency provided by
the GeoTools version of gt-jdbc-postgis above.
-->
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>${postgresql.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.geotools.jdbc</groupId>
<artifactId>gt-jdbc-sqlserver</artifactId>
<version>${gt.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.geotools.jdbc</groupId>
<artifactId>gt-jdbc-oracle</artifactId>
<version>${gt.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.geotools</groupId>
<artifactId>gt-referencing</artifactId>
<version>${gt.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.geotools</groupId>
<artifactId>gt-main</artifactId>
<version>${gt.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.geotools</groupId>
<artifactId>gt-cql</artifactId>
<version>${gt.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.geotools</groupId>
<artifactId>gt-epsg-hsql</artifactId>
<version>${gt.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
Expand All @@ -148,13 +154,11 @@
<dependency>
<groupId>org.geoserver</groupId>
<artifactId>gs-main</artifactId>
<version>${gs.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.geoserver.web</groupId>
<artifactId>gs-web-core</artifactId>
<version>${gs.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
Expand All @@ -165,25 +169,21 @@
<dependency>
<groupId>org.geoserver</groupId>
<artifactId>gs-ows</artifactId>
<version>${gs.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.geoserver</groupId>
<artifactId>gs-rest</artifactId>
<version>${gs.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.geoserver</groupId>
<artifactId>gs-wfs</artifactId>
<version>${gs.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.geoserver</groupId>
<artifactId>gs-gwc</artifactId>
<version>${gs.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
Expand Down Expand Up @@ -254,6 +254,13 @@
<classifier>tests</classifier>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.locationtech.geogig</groupId>
<artifactId>geogig-api</artifactId>
<version>${geogig.version}</version>
<classifier>tests</classifier>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.geoserver.web</groupId>
<artifactId>gs-web-core</artifactId>
Expand Down Expand Up @@ -367,5 +374,35 @@
</plugins>
</build>
</profile>
<profile>
<!-- Profile to build in RocksDB backend module. This profile is active by default. -->
<id>geogig-rocksdb</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<dependencies>
<dependency>
<groupId>org.locationtech.geogig</groupId>
<artifactId>geogig-rocksdb</artifactId>
<version>${geogig.version}</version>
<scope>runtime</scope>
</dependency>
</dependencies>
</profile>
<profile>
<!-- Profile to build in PostgreSQL backend module. This profile is active by default. -->
<id>geogig-postgresql</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<dependencies>
<dependency>
<groupId>org.locationtech.geogig</groupId>
<artifactId>geogig-postgres</artifactId>
<version>${geogig.version}</version>
<scope>runtime</scope>
</dependency>
</dependencies>
</profile>
</profiles>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@
import org.geoserver.platform.resource.ResourceListener;
import org.geoserver.platform.resource.ResourceNotification;
import org.geoserver.platform.resource.ResourceNotification.Event;
import org.geoserver.platform.resource.ResourceNotification.Kind;
import org.geoserver.platform.resource.ResourceNotificationDispatcher;
import org.geoserver.platform.resource.ResourceStore;
import org.geotools.util.logging.Logging;
import org.locationtech.geogig.repository.RepositoryResolver;

import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Charsets;
Expand Down Expand Up @@ -228,7 +228,9 @@ void populateCache() {
private void loadResource(Resource resource) {
try {
RepositoryInfo info = load(resource);
cache.put(info.getId(), info);
if (info != null) {
cache.put(info.getId(), info);
}
} catch (IOException e) {
// log the bad info
LOGGER.log(Level.WARNING, "Error loading RepositoryInfo", e);
Expand Down Expand Up @@ -318,7 +320,8 @@ public RepositoryInfo get(final String id) throws IOException {

public RepositoryInfo getByName(final String name) {
for (RepositoryInfo cached : cache.values()) {
if (cached.getRepoName().equals(name)) {
final String cachedRepoName = cached.getRepoName();
if (cachedRepoName != null && cachedRepoName.equals(name)) {
return cached;
}
}
Expand Down Expand Up @@ -351,6 +354,12 @@ private static RepositoryInfo load(Resource input) throws IOException {
if (info.getLocation() == null) {
throw new IOException("Repository info has incomplete information: " + info);
}
// we have a location, make sure we have a resolver for the scheme
if (!RepositoryResolver.resolverAvailableForURIScheme(info.getLocation().getScheme())) {
LOGGER.log(Level.WARNING, "No RepositoryResolver available for URI: {0}",
info.getLocation().toString());
return null;
}
return info;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,10 @@ public String getRepoName() {
if (this.location != null) {
if (this.repoName == null) {
// lookup the resolver
RepositoryResolver resolver = RepositoryResolver.lookup(this.location);
this.repoName = resolver.getName(this.location);
if (RepositoryResolver.resolverAvailableForURIScheme(this.location.getScheme())) {
RepositoryResolver resolver = RepositoryResolver.lookup(this.location);
this.repoName = resolver.getName(this.location);
}
}
}
return this.repoName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,6 @@ public Repository createRepo(final Hints hints) {
hints.set(Hints.REPOSITORY_URL, repoURI);
}

String scheme = repoURI.getScheme();
Preconditions.checkArgument(RepositoryResolver.resolverAvailableForURIScheme(scheme),
"Unsupported repository URI scheme: " + scheme);
Context context = GlobalContextBuilder.builder().build(hints);
RepositoryResolver repositoryResolver = RepositoryResolver.lookup(repoURI);
final boolean exists = repositoryResolver.repoExists(repoURI);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@

import java.io.Serializable;
import java.net.URI;
import java.util.Arrays;
import java.util.ArrayList;
import java.util.List;

import org.apache.wicket.model.IModel;
import org.geogig.geoserver.config.RepositoryInfo;
import org.locationtech.geogig.repository.RepositoryResolver;

import com.google.common.annotations.VisibleForTesting;

/**
* Data model for the drop-down choice for GeoGig repository configuration. Currently, either a
Expand All @@ -19,12 +22,25 @@
public class DropDownModel implements IModel<Serializable> {

private static final long serialVersionUID = 1L;
static final String NO_DEFAULT_AVAILABLE = "No available repository types";

public static final String PG_CONFIG = "PostgreSQL";
public static final String DIRECTORY_CONFIG = "Directory";
public static final String DEFAULT_CONFIG = DIRECTORY_CONFIG;
public static final List<String> CONFIG_LIST = Arrays.asList(DropDownModel.DIRECTORY_CONFIG,
DropDownModel.PG_CONFIG);
static String DEFAULT_CONFIG;
public static final List<String> CONFIG_LIST = new ArrayList<>(2);
static {
if (RepositoryResolver.resolverAvailableForURIScheme("file")) {
CONFIG_LIST.add(DIRECTORY_CONFIG);
}
if (RepositoryResolver.resolverAvailableForURIScheme("postgresql")) {
CONFIG_LIST.add(PG_CONFIG);
}
if (!CONFIG_LIST.isEmpty()) {
DEFAULT_CONFIG = CONFIG_LIST.get(0);
} else {
DEFAULT_CONFIG = NO_DEFAULT_AVAILABLE;
}
}

private final IModel<RepositoryInfo> repoModel;
private String type;
Expand Down Expand Up @@ -74,4 +90,18 @@ public static String getType(URI location) {
}
return DEFAULT_CONFIG;
}

@VisibleForTesting
static void setConfigList(List<String> configs, String defaultConfig) {
// clear the existing list
CONFIG_LIST.clear();
// re-populate with provided configs
CONFIG_LIST.addAll(configs);
// set the default
if (null != defaultConfig) {
DEFAULT_CONFIG = defaultConfig;
} else {
DEFAULT_CONFIG = NO_DEFAULT_AVAILABLE;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -92,16 +92,17 @@ public void updateChoices(boolean reportError, Form<?> form) {
RepositoryResolver resolver = RepositoryResolver.lookup(repoURI);
String repoName = resolver.getName(repoURI);
RepositoryInfo repoInfo = manager.getByRepoName(repoName);
String repoId = repoInfo.getId();
List<Ref> branchRefs = manager.listBranches(repoId);
for (Ref branch : branchRefs) {
branchNames.add(branch.localName());
if (repoInfo != null) {
String repoId = repoInfo.getId();
List<Ref> branchRefs = manager.listBranches(repoId);
for (Ref branch : branchRefs) {
branchNames.add(branch.localName());
}
}
} catch (IOException | URISyntaxException e) {
if (reportError) {
form.error("Could not list branches: " + e.getMessage());
}
branchNames = new ArrayList<String>();
}
String current = (String) choice.getModelObject();
if (current != null && !branchNames.contains(current)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,9 @@ public void testCreateRepoUnsupportedURIScheme() {
fail();
} catch (IllegalArgumentException e) {
//expected
assertEquals("Unsupported repository URI scheme: unknown", e.getMessage());
assertEquals(
"No repository initializer found capable of handling this kind of URI: unknown://repo1",
e.getMessage());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.locationtech.geogig.repository.Repository;

import com.google.inject.Inject;
import cucumber.api.java.After;
import cucumber.api.java.en.Given;
import cucumber.runtime.java.StepDefAnnotation;
import cucumber.runtime.java.guice.ScenarioScoped;
Expand Down Expand Up @@ -45,7 +46,7 @@ String systemTempPath() throws IOException {
return context.getTempFolder().getCanonicalPath().replace("\\", "/");
}

@Given("I have \"([^\"]*)\" that is not managed by GeoServer$")
@Given("^I have \"([^\"]*)\" that is not managed by GeoServer$")
public void setupExtraUnMangedRepo(String repoName) throws Exception {
context.createUnManagedRepoWithAltRoot(repoName)
.init("geogigUser", "repo1_Owner@geogig.org")
Expand All @@ -54,7 +55,7 @@ public void setupExtraUnMangedRepo(String repoName) throws Exception {
this.repoName = repoName;
}

@cucumber.api.java.After
@After
public void after() {
if (repoName != null) {
try {
Expand Down

0 comments on commit 46029eb

Please sign in to comment.