Skip to content

Commit

Permalink
Merge pull request #188 from 3dcitydb/hotfix-feature-version-filter-cli
Browse files Browse the repository at this point in the history
Fix inconsistent behaviour of feature version filter when using the CLI
  • Loading branch information
Zhihang Yao authored May 12, 2021
2 parents 2a3335f + 7f72fb9 commit 81b97ab
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 21 deletions.
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

0 comments on commit 81b97ab

Please sign in to comment.