-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #30 from 3dcitydb/feature-limit-and-sorting
Add limit option and sorting to Query API
- Loading branch information
Showing
30 changed files
with
874 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
citydb-cli/src/main/java/org/citydb/cli/common/CountLimitOptions.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
* citydb-tool - Command-line tool for the 3D City Database | ||
* https://www.3dcitydb.org/ | ||
* | ||
* Copyright 2022-2024 | ||
* virtualcitysystems GmbH, Germany | ||
* https://vc.systems/ | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.citydb.cli.common; | ||
|
||
import org.citydb.query.limit.CountLimit; | ||
import picocli.CommandLine; | ||
|
||
public class CountLimitOptions implements Option { | ||
@CommandLine.Option(names = "--limit", paramLabel = "<count>", | ||
description = "Maximum number of features to process.") | ||
private Long limit; | ||
|
||
@CommandLine.Option(names = "--start-index", paramLabel = "<index>", | ||
description = "Index within the result set from which features are processed.") | ||
private Long startIndex; | ||
|
||
public CountLimit getCountLimit() { | ||
return limit != null || startIndex != null ? | ||
new CountLimit() | ||
.setLimit(limit) | ||
.setStartIndex(startIndex) : | ||
null; | ||
} | ||
|
||
@Override | ||
public void preprocess(CommandLine commandLine) throws Exception { | ||
if (limit != null && limit < 0) { | ||
throw new CommandLine.ParameterException(commandLine, | ||
"Error: Count limit must be a non-negative integer but was '" + limit + "'"); | ||
} else if (startIndex != null && startIndex < 0) { | ||
throw new CommandLine.ParameterException(commandLine, | ||
"Error: Start index must be a non-negative integer but was '" + startIndex + "'"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
citydb-cli/src/main/java/org/citydb/cli/exporter/options/SortingOption.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
* citydb-tool - Command-line tool for the 3D City Database | ||
* https://www.3dcitydb.org/ | ||
* | ||
* Copyright 2022-2024 | ||
* virtualcitysystems GmbH, Germany | ||
* https://vc.systems/ | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.citydb.cli.exporter.options; | ||
|
||
import org.citydb.cli.common.Option; | ||
import org.citydb.query.filter.encoding.FilterParseException; | ||
import org.citydb.query.sorting.SortOrder; | ||
import org.citydb.query.sorting.Sorting; | ||
import picocli.CommandLine; | ||
|
||
public class SortingOption implements Option { | ||
@CommandLine.Option(names = {"-s", "--sort-by"}, split = ",", paramLabel = "<property[+|-]>", required = true, | ||
description = "Properties and sort orders for sorting features.") | ||
private String[] sortBy; | ||
|
||
public Sorting getSorting() throws FilterParseException { | ||
if (sortBy != null) { | ||
Sorting sorting = new Sorting(); | ||
for (String sortToken : sortBy) { | ||
if (sortToken.endsWith("+")) { | ||
sorting.addSortBy(sortToken.substring(0, sortToken.length() - 1), SortOrder.ASC); | ||
} else if (sortToken.endsWith("-")) { | ||
sorting.addSortBy(sortToken.substring(0, sortToken.length() - 1), SortOrder.DESC); | ||
} else { | ||
sorting.addSortBy(sortToken, SortOrder.ASC); | ||
} | ||
} | ||
|
||
return sorting; | ||
} else { | ||
return null; | ||
} | ||
} | ||
} |
Oops, something went wrong.