Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix inconsistent behaviour of feature version filter when using the CLI #188

Merged
merged 1 commit into from
May 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
import org.citydb.registry.ObjectRegistry;
import picocli.CommandLine;

import javax.xml.datatype.DatatypeFactory;
import java.util.ArrayList;
import java.util.List;

Expand Down Expand Up @@ -92,14 +91,14 @@ public QueryConfig toQueryConfig() {
queryConfig.setFeatureTypeFilter(typeNamesOption.toFeatureTypeFilter());
}

if (featureVersionOption != null) {
DatatypeFactory datatypeFactory = ObjectRegistry.getInstance().getDatatypeFactory();
SimpleFeatureVersionFilter versionFilter = featureVersionOption.toFeatureVersionFilter(datatypeFactory);
if (versionFilter != null) {
AbstractPredicate predicate = versionFilter.toPredicate();
if (predicate != null) {
predicates.add(predicate);
}
SimpleFeatureVersionFilter versionFilter = featureVersionOption != null ?
featureVersionOption.toFeatureVersionFilter(ObjectRegistry.getInstance().getDatatypeFactory()) :
FeatureVersionOption.defaultFeatureVersionFilter();

if (versionFilter != null) {
AbstractPredicate predicate = versionFilter.toPredicate();
if (predicate != null) {
predicates.add(predicate);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
import org.citydb.registry.ObjectRegistry;
import picocli.CommandLine;

import javax.xml.datatype.DatatypeFactory;
import java.util.ArrayList;
import java.util.List;

Expand Down Expand Up @@ -104,14 +103,14 @@ public QueryConfig toQueryConfig() {
queryConfig.setFeatureTypeFilter(typeNamesOption.toFeatureTypeFilter());
}

if (featureVersionOption != null) {
DatatypeFactory datatypeFactory = ObjectRegistry.getInstance().getDatatypeFactory();
SimpleFeatureVersionFilter versionFilter = featureVersionOption.toFeatureVersionFilter(datatypeFactory);
if (versionFilter != null) {
AbstractPredicate predicate = versionFilter.toPredicate();
if (predicate != null) {
predicates.add(predicate);
}
SimpleFeatureVersionFilter versionFilter = featureVersionOption != null ?
featureVersionOption.toFeatureVersionFilter(ObjectRegistry.getInstance().getDatatypeFactory()) :
FeatureVersionOption.defaultFeatureVersionFilter();

if (versionFilter != null) {
AbstractPredicate predicate = versionFilter.toPredicate();
if (predicate != null) {
predicates.add(predicate);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public class SimpleFeatureVersionFilter {
private XMLGregorianCalendar endDate;

public SimpleFeatureVersionFilterMode getMode() {
return mode;
return mode != null ? mode : SimpleFeatureVersionFilterMode.LATEST;
}

public void setMode(SimpleFeatureVersionFilterMode mode) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@
import java.time.temporal.ChronoField;

public class FeatureVersionOption implements CliOption {
@CommandLine.Option(names = {"-r", "--feature-version"}, required = true,
description = "Feature version: ${COMPLETION-CANDIDATES}.")
@CommandLine.Option(names = {"-r", "--feature-version"}, required = true, defaultValue = "latest",
description = "Feature version: ${COMPLETION-CANDIDATES} (default: ${DEFAULT-VALUE}).")
private Version version;

@CommandLine.Option(names = {"-R", "--feature-version-timestamp"}, paramLabel = "<timestamp[,timestamp]>",
Expand All @@ -60,6 +60,10 @@ public class FeatureVersionOption implements CliOption {
private OffsetDateTime endDateTime;
private SimpleFeatureVersionFilter featureVersionFilter;

public static SimpleFeatureVersionFilter defaultFeatureVersionFilter() {
return new SimpleFeatureVersionFilter();
}

public SimpleFeatureVersionFilter toFeatureVersionFilter(DatatypeFactory datatypeFactory) {
if (featureVersionFilter != null) {
if (startDateTime != null) {
Expand Down