This is an automated email from the ASF dual-hosted git repository.
desruisseaux pushed a commit to branch geoapi-4.0
in repository https://gitbox.apache.org/repos/asf/sis.git
The following commit(s) were added to refs/heads/geoapi-4.0 by this push:
new cf0f31d12a When a `FeatureQuery` contains a projection (in SQL sense),
and if some properties in the projection are links, recreate the result types
of the links if they changed.
cf0f31d12a is described below
commit cf0f31d12a3eca35099c25c51be45168b8230326
Author: Martin Desruisseaux <[email protected]>
AuthorDate: Fri May 23 06:22:37 2025 +0200
When a `FeatureQuery` contains a projection (in SQL sense), and if some
properties
in the projection are links, recreate the result types of the links if they
changed.
---
.../sis/feature/builder/FeatureTypeBuilder.java | 6 ++--
.../sis/feature/builder/OperationWrapper.java | 36 ++++++++++++++++++++++
.../sis/feature/builder/PropertyTypeBuilder.java | 13 ++++++++
.../feature/privy/FeatureProjectionBuilder.java | 2 +-
4 files changed, 53 insertions(+), 4 deletions(-)
diff --git
a/endorsed/src/org.apache.sis.feature/main/org/apache/sis/feature/builder/FeatureTypeBuilder.java
b/endorsed/src/org.apache.sis.feature/main/org/apache/sis/feature/builder/FeatureTypeBuilder.java
index a11ddf1654..8a22418d3f 100644
---
a/endorsed/src/org.apache.sis.feature/main/org/apache/sis/feature/builder/FeatureTypeBuilder.java
+++
b/endorsed/src/org.apache.sis.feature/main/org/apache/sis/feature/builder/FeatureTypeBuilder.java
@@ -101,7 +101,7 @@ import org.opengis.feature.Operation;
* @author Johann Sorel (Geomatys)
* @author Martin Desruisseaux (Geomatys)
* @author Alexis Manin (Geomatys)
- * @version 1.4
+ * @version 1.5
*
* @see org.apache.sis.parameter.ParameterBuilder
*
@@ -644,7 +644,7 @@ public class FeatureTypeBuilder extends TypeBuilder {
/**
* Returns the builder for the property of the given name. The given name
does not need to contains all elements
- * of a {@link org.opengis.util.ScopedName}; it is okay to specify only
the tip (for example {@code "myName"}
+ * of a {@link org.opengis.util.ScopedName}. It is okay to specify only
the tip (for example {@code "myName"}
* instead of {@code "myScope:myName"}) provided that ignoring the name
head does not create ambiguity.
*
* @param name name of the property to search.
@@ -923,7 +923,7 @@ public class FeatureTypeBuilder extends TypeBuilder {
int identifierCursor = 0;
for (int i=0; i<numSpecified; i++) {
final PropertyTypeBuilder builder = properties.get(i);
- final PropertyType instance = builder.build();
+ final PropertyType instance = builder.buildForFeature();
propertyTypes[propertyCursor] = instance;
/*
* Collect the attributes to use as identifier components
while we loop over all properties.
diff --git
a/endorsed/src/org.apache.sis.feature/main/org/apache/sis/feature/builder/OperationWrapper.java
b/endorsed/src/org.apache.sis.feature/main/org/apache/sis/feature/builder/OperationWrapper.java
index c8ebf432b2..88a470d172 100644
---
a/endorsed/src/org.apache.sis.feature/main/org/apache/sis/feature/builder/OperationWrapper.java
+++
b/endorsed/src/org.apache.sis.feature/main/org/apache/sis/feature/builder/OperationWrapper.java
@@ -18,10 +18,13 @@ package org.apache.sis.feature.builder;
import java.util.Objects;
import org.opengis.util.GenericName;
+import org.apache.sis.feature.Features;
+import org.apache.sis.feature.FeatureOperations;
import org.apache.sis.util.resources.Errors;
// Specific to the geoapi-3.1 and geoapi-4.0 branches:
import org.opengis.feature.PropertyType;
+import org.opengis.feature.Operation;
/**
@@ -56,6 +59,39 @@ final class OperationWrapper extends PropertyTypeBuilder {
return operation;
}
+ /**
+ * Returns the operation or an updated version of the operation.
+ * Updated versions are created only for some kinds of operation,
described below.
+ * Otherwise, this method returns the same value as {@link #build()}.
+ *
+ * <h4>Links</h4>
+ * If the operation is a link to another property of the feature to build,
the result type
+ * of the original operation is replaced by the target of the link in the
feature to build.
+ * Even if the attribute name is the same, sometime the value class or
some characteristics
+ * are different.
+ *
+ * @throws IllegalStateException if the builder contains inconsistent
information.
+ */
+ @Override
+ final PropertyType buildForFeature() {
+ final FeatureTypeBuilder owner = owner();
+ try {
+ return Features.getLinkTarget(operation).<PropertyType>map((name)
-> {
+ final PropertyTypeBuilder target = owner.getProperty(name);
+ if (target != null) {
+ final PropertyType result = target.build();
+ if (!result.equals(((Operation) operation).getResult())) {
+ initialize(operation);
+ return FeatureOperations.link(identification(),
result);
+ }
+ }
+ return null;
+ }).orElse(operation);
+ } catch (IllegalArgumentException e) {
+ throw new IllegalStateException(e.getMessage(), e);
+ }
+ }
+
/**
* Do not allow a change of multiplicity.
*/
diff --git
a/endorsed/src/org.apache.sis.feature/main/org/apache/sis/feature/builder/PropertyTypeBuilder.java
b/endorsed/src/org.apache.sis.feature/main/org/apache/sis/feature/builder/PropertyTypeBuilder.java
index 2c9405313e..214fd41d2a 100644
---
a/endorsed/src/org.apache.sis.feature/main/org/apache/sis/feature/builder/PropertyTypeBuilder.java
+++
b/endorsed/src/org.apache.sis.feature/main/org/apache/sis/feature/builder/PropertyTypeBuilder.java
@@ -296,6 +296,19 @@ public abstract class PropertyTypeBuilder extends
TypeBuilder {
@Override
public abstract PropertyType build() throws IllegalStateException;
+ /**
+ * Builds the final property type to use in {@code FeatureType}.
+ * This method is invoked by {@link FeatureTypeBuilder#build()}.
+ * Subclasses can assume that the {@linkplain
FeatureTypeBuilder#properties property} list is complete
+ * and use that information for refreshing some information such as the
targets of the links.
+ *
+ * @return the property type.
+ * @throws IllegalStateException if the builder contains inconsistent
information.
+ */
+ PropertyType buildForFeature() throws IllegalStateException {
+ return build();
+ }
+
/**
* Flags this builder as a disposed one. The builder should not be used
anymore after this method call.
*/
diff --git
a/endorsed/src/org.apache.sis.feature/main/org/apache/sis/feature/privy/FeatureProjectionBuilder.java
b/endorsed/src/org.apache.sis.feature/main/org/apache/sis/feature/privy/FeatureProjectionBuilder.java
index 2f9c7bd6df..c2dcf01e13 100644
---
a/endorsed/src/org.apache.sis.feature/main/org/apache/sis/feature/privy/FeatureProjectionBuilder.java
+++
b/endorsed/src/org.apache.sis.feature/main/org/apache/sis/feature/privy/FeatureProjectionBuilder.java
@@ -299,7 +299,7 @@ public final class FeatureProjectionBuilder extends
FeatureTypeBuilder {
return null;
}
assert properties().contains(builder) : builder;
- assert requested.stream().noneMatch((item) ->item.builder() ==
builder) : builder;
+ assert requested.stream().noneMatch((item) -> item.builder == builder)
: builder;
final var item = new Item(named ? builder.getName() : null, builder);
requested.add(item);
return item;