Skip to content
Open
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 @@ -37,12 +37,10 @@
import de.ii.xtraplatform.features.domain.FeatureProviderConnector;
import de.ii.xtraplatform.features.domain.FeatureProviderConnector.QueryOptions;
import de.ii.xtraplatform.features.domain.FeatureProviderDataV2;
import de.ii.xtraplatform.features.domain.FeatureQueries;
import de.ii.xtraplatform.features.domain.FeatureQueriesPassThrough;
import de.ii.xtraplatform.features.domain.FeatureQuery;
import de.ii.xtraplatform.features.domain.FeatureQueryEncoder;
import de.ii.xtraplatform.features.domain.FeatureSchema;
import de.ii.xtraplatform.features.domain.FeatureStorePathParser;
import de.ii.xtraplatform.features.domain.FeatureStream;
import de.ii.xtraplatform.features.domain.FeatureStreamImpl;
import de.ii.xtraplatform.features.domain.FeatureTokenDecoder;
Expand All @@ -53,7 +51,6 @@
import de.ii.xtraplatform.features.domain.SchemaMapping;
import de.ii.xtraplatform.features.domain.transform.OnlyQueryables;
import de.ii.xtraplatform.features.domain.transform.OnlySortables;
import de.ii.xtraplatform.features.gml.domain.ConnectionInfoWfsHttp;
import de.ii.xtraplatform.features.gml.domain.FeatureProviderWfsData;
import de.ii.xtraplatform.features.gml.domain.WfsConnector;
import de.ii.xtraplatform.features.gml.domain.XMLNamespaceNormalizer;
Expand Down Expand Up @@ -112,15 +109,11 @@
value = FeatureProviderWfs.PROVIDER_SUB_TYPE)
},
data = FeatureProviderWfsData.class)
@SuppressWarnings("PMD.CouplingBetweenObjects")
public class FeatureProviderWfs
extends AbstractFeatureProvider<
byte[], String, FeatureProviderConnector.QueryOptions, FeatureSchema>
implements FeatureProvider,
FeatureQueries,
FeatureCrs,
FeatureExtents,
FeatureMetadata,
FeatureQueriesPassThrough {
implements FeatureCrs, FeatureExtents, FeatureMetadata, FeatureQueriesPassThrough {

private static final Logger LOGGER = LoggerFactory.getLogger(FeatureProviderWfs.class);

Expand All @@ -132,7 +125,6 @@ public class FeatureProviderWfs

private FeatureQueryEncoderWfs queryTransformer;
private AggregateStatsReader<FeatureSchema> aggregateStatsReader;
private FeatureStorePathParser pathParser;

@AssistedInject
public FeatureProviderWfs(
Expand Down Expand Up @@ -162,8 +154,6 @@ public FeatureProviderWfs(

@Override
protected boolean onStartup() throws InterruptedException {
this.pathParser = createPathParser(getData().getConnectionInfo());

boolean success = super.onStartup();

if (!success) {
Expand All @@ -186,16 +176,9 @@ protected boolean onStartup() throws InterruptedException {

@Override
protected Map<String, List<FeatureSchema>> getSourceSchemas() {
Map<String, List<FeatureSchema>> types =
getData().getTypes().entrySet().stream()
.map(entry -> new SimpleImmutableEntry<>(entry.getKey(), List.of(entry.getValue())))
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
return types;
}

private static FeatureStorePathParser createPathParser(
ConnectionInfoWfsHttp connectionInfoWfsHttp) {
return new FeatureStorePathParserWfs(connectionInfoWfsHttp.getNamespaces());
return getData().getTypes().entrySet().stream()
.map(entry -> new SimpleImmutableEntry<>(entry.getKey(), List.of(entry.getValue())))
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
}

@Override
Expand Down Expand Up @@ -282,7 +265,7 @@ public long getFeatureCount(String typeName) {
.exceptionally(throwable -> -1L)
.toCompletableFuture()
.join();
} catch (Throwable e) {
} catch (Throwable e) { // NOPMD AvoidCatchingThrowable
// continue
}

Expand Down Expand Up @@ -328,9 +311,8 @@ public Optional<BoundingBox> getSpatialExtent(String typeName) {
.exceptionally(throwable -> Optional.empty())
.toCompletableFuture()
.join();
} catch (Throwable e) {
} catch (Throwable e) { // NOPMD AvoidCatchingThrowable
// continue
boolean br = true;
}

return Optional.empty();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public FeatureProviderWfsAuto(WfsClientBasicFactory clientFactory) {

@Override
public <T extends AutoEntity> Map<String, String> check(T entityData) {
return null;
return Map.of();
}

@Override
Expand Down Expand Up @@ -105,7 +105,7 @@ public <T extends AutoEntity> T generate(

private FeatureProviderWfsData completeConnectionInfoIfNecessary(
WfsClientBasic wfsClient, FeatureProviderWfsData data) {
ConnectionInfoWfsHttp connectionInfo = (ConnectionInfoWfsHttp) data.getConnectionInfo();
ConnectionInfoWfsHttp connectionInfo = data.getConnectionInfo();

if (connectionInfo.getNamespaces().isEmpty()) {

Expand All @@ -128,13 +128,13 @@ private FeatureProviderWfsData generateTypesIfNecessary(
Map<String, List<String>> includeTypes,
Consumer<Map<String, List<String>>> tracker) {
if (data.getTypes().isEmpty()) {
ConnectionInfoWfsHttp connectionInfo = (ConnectionInfoWfsHttp) data.getConnectionInfo();
ConnectionInfoWfsHttp connectionInfo = data.getConnectionInfo();

WfsSchemaCrawler schemaCrawler = new WfsSchemaCrawler(wfsClient, connectionInfo);

List<FeatureSchema> types = schemaCrawler.parseSchema(includeTypes, tracker);

ImmutableMap<String, FeatureSchema> typeMap =
Map<String, FeatureSchema> typeMap =
types.stream()
.map(type -> new AbstractMap.SimpleImmutableEntry<>(type.getName(), type))
.collect(ImmutableMap.toImmutableMap(Map.Entry::getKey, Map.Entry::getValue));
Expand All @@ -148,7 +148,7 @@ private FeatureProviderWfsData generateTypesIfNecessary(
private FeatureProviderWfsData generateNativeCrsIfNecessary(
WfsClientBasic wfsClient, FeatureProviderWfsData data) {
if (!data.getNativeCrs().isPresent()) {
ConnectionInfoWfsHttp connectionInfo = (ConnectionInfoWfsHttp) data.getConnectionInfo();
ConnectionInfoWfsHttp connectionInfo = data.getConnectionInfo();

WfsSchemaCrawler schemaCrawler = new WfsSchemaCrawler(wfsClient, connectionInfo);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import de.ii.xtraplatform.entities.domain.AutoEntityFactory;
import de.ii.xtraplatform.entities.domain.EntityData;
import de.ii.xtraplatform.entities.domain.EntityDataBuilder;
import de.ii.xtraplatform.entities.domain.EntityFactory;
import de.ii.xtraplatform.entities.domain.PersistentEntity;
import de.ii.xtraplatform.features.domain.ConnectorFactory;
import de.ii.xtraplatform.features.domain.FeatureProviderDataV2;
Expand All @@ -36,8 +35,7 @@
@Singleton
@AutoBind
public class FeatureProviderWfsFactory
extends AbstractEntityFactory<FeatureProviderDataV2, FeatureProviderWfs>
implements EntityFactory {
extends AbstractEntityFactory<FeatureProviderDataV2, FeatureProviderWfs> {

private static final Logger LOGGER = LoggerFactory.getLogger(FeatureProviderWfsFactory.class);

Expand Down Expand Up @@ -114,9 +112,11 @@ public EntityData hydrateData(EntityData entityData) {

try {
if (data.isAuto()) {
LOGGER.info(
"Feature provider with id '{}' is in auto mode, generating configuration ...",
data.getId());
if (LOGGER.isInfoEnabled()) {
LOGGER.info(
"Feature provider with id '{}' is in auto mode, generating configuration ...",
data.getId());
}

Map<String, List<String>> types = featureProviderWfsAuto.analyze(data);

Expand All @@ -125,7 +125,7 @@ public EntityData hydrateData(EntityData entityData) {

return data;

} catch (Throwable e) {
} catch (Throwable e) { // NOPMD AvoidCatchingThrowable
LogContext.error(
LOGGER, e, "Feature provider with id '{}' could not be started", data.getId());
}
Expand All @@ -134,6 +134,7 @@ public EntityData hydrateData(EntityData entityData) {
}

@AssistedFactory
@FunctionalInterface
public interface ProviderWfsFactoryAssisted
extends FactoryAssisted<FeatureProviderDataV2, FeatureProviderWfs> {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,10 @@
import java.net.URI;
import java.util.Map;
import javax.xml.namespace.QName;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@SuppressWarnings("PMD.CouplingBetweenObjects")
public class FeatureQueryEncoderWfs implements FeatureQueryEncoder<String, QueryOptions> {

private static final Logger LOGGER = LoggerFactory.getLogger(FeatureQueryEncoderWfs.class);

private final Map<String, FeatureSchema> featureSchemas;
private final XMLNamespaceNormalizer namespaceNormalizer;
private final WfsRequestEncoder wfsRequestEncoder;
Expand Down Expand Up @@ -71,8 +68,7 @@ public FeatureQueryEncoderWfs(
connectionInfo.getNamespaces(),
urls);
this.nativeCrs = nativeCrs;
this.filterEncoder =
new FilterEncoderWfs(nativeCrs, crsTransformerFactory, cql, namespaceNormalizer);
this.filterEncoder = new FilterEncoderWfs(nativeCrs, crsTransformerFactory, cql);
}

// TODO: add cql2 classes
Expand Down Expand Up @@ -127,7 +123,7 @@ GetFeature encodeGetFeature(
return encodeGetFeature(
query, featureTypeName, featureSchemas.get(query.getType()), additionalQueryParameters);
} catch (CqlParseException e) {
throw new IllegalArgumentException("Filter is invalid", e.getCause());
throw new IllegalArgumentException("Filter is invalid", e);
}
}

Expand All @@ -139,8 +135,7 @@ private GetFeature encodeGetFeature(
FeatureQuery query,
QName featureTypeName,
FeatureSchema featureSchema,
Map<String, String> additionalQueryParameters)
throws CqlParseException {
Map<String, String> additionalQueryParameters) {
final String featureTypeNameFull =
namespaceNormalizer.getQualifiedName(
featureTypeName.getNamespaceURI(), featureTypeName.getLocalPart());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,20 @@
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;

public class FeatureStorePathParserWfs implements FeatureStorePathParser {

public FeatureStorePathParserWfs(Map<String, String> namespaces) {}
public FeatureStorePathParserWfs(Map<String, String> namespaces) {
Objects.requireNonNull(namespaces);
}

@Override
public List<FeatureStoreInstanceContainer> parse(FeatureSchema schema) {

LinkedHashMap<String, ImmutableFeatureStoreInstanceContainer.Builder>
instanceContainerBuilders = new LinkedHashMap<>();
Map<String, ImmutableFeatureStoreInstanceContainer.Builder> instanceContainerBuilders =
new LinkedHashMap<>();

String instanceContainerName = schema.getName();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
*
* @author zahnen
*/
@SuppressWarnings("PMD.GodClass")
public class FeatureTokenDecoderGmlFromWfs
extends FeatureTokenDecoder<
byte[], FeatureSchema, SchemaMapping, ModifiableContext<FeatureSchema, SchemaMapping>> {
Expand All @@ -51,16 +52,19 @@ public class FeatureTokenDecoderGmlFromWfs
private final FeatureQuery featureQuery;
private final Map<String, SchemaMapping> mappings;
private final List<QName> featureTypes;

@SuppressWarnings("PMD.AvoidStringBufferField")
private final StringBuilder buffer;

private final GmlMultiplicityTracker multiplicityTracker;
private final boolean passThrough;
private final GeometryDecoderGml geometryDecoder;

private boolean isBuffering;
private int depth = 0;
private int featureDepth = 0;
private boolean inFeature = false;
private boolean inGeometry = false;
private int depth;
private int featureDepth;
private boolean inFeature;
private boolean inGeometry;
private Optional<EpsgCrs> crs = Optional.empty();
private OptionalInt srsDimension = OptionalInt.empty();
private ModifiableContext<FeatureSchema, SchemaMapping> context;
Expand All @@ -72,6 +76,7 @@ public FeatureTokenDecoderGmlFromWfs(
FeatureQuery query,
Map<String, SchemaMapping> mappings,
boolean passThrough) {
super();
this.namespaceNormalizer = new XMLNamespaceNormalizer(namespaces);
this.featureSchema = featureSchema;
this.featureQuery = query;
Expand All @@ -85,7 +90,7 @@ public FeatureTokenDecoderGmlFromWfs(
try {
this.parser = new InputFactoryImpl().createAsyncFor(new byte[0]);
} catch (XMLStreamException e) {
throw new IllegalStateException("Could not create GML decoder: " + e.getMessage());
throw new IllegalStateException("Could not create GML decoder: " + e.getMessage(), e);
}
}

Expand All @@ -109,7 +114,7 @@ public void onPush(byte[] bytes) {
}

// for unit tests
void parse(String data) throws Exception {
void parse(String data) {
byte[] dataBytes = data.getBytes(StandardCharsets.UTF_8);
feedInput(dataBytes);
cleanup();
Expand All @@ -128,6 +133,14 @@ private void feedInput(byte[] data) {
}
}

@SuppressWarnings({
"PMD.NcssCount",
"PMD.CognitiveComplexity",
"PMD.CyclomaticComplexity",
"PMD.NPathComplexity",
"PMD.SwitchDensity",
"PMD.AvoidDeeplyNestedIfStmts"
})
protected boolean advanceParser() {

boolean feedMeMore = false;
Expand Down Expand Up @@ -199,21 +212,23 @@ protected boolean advanceParser() {
getDownstream().onStart(context);
} else if ("Envelope".equals(parser.getLocalName()) && depth == 2) {
String srsName = parser.getAttributeValue(null, "srsName");
Optional<EpsgCrs> parsedCrs = Optional.empty();
if (srsName != null && !srsName.isEmpty()) {
try {
crs = Optional.of(EpsgCrs.fromString(srsName));
parsedCrs = Optional.of(EpsgCrs.fromString(srsName));
} catch (IllegalArgumentException e) {
crs = Optional.empty();
parsedCrs = Optional.empty();
}
} else {
crs = Optional.empty();
}
crs = parsedCrs;
OptionalInt parsedSrsDimension;
try {
srsDimension =
parsedSrsDimension =
OptionalInt.of(Integer.parseInt(parser.getAttributeValue(null, "srsDimension")));
} catch (NumberFormatException e) {
srsDimension = OptionalInt.empty();
parsedSrsDimension = OptionalInt.empty();
}
srsDimension = parsedSrsDimension;
} else if (matchesFeatureType(parser.getNamespaceURI(), parser.getLocalName())
|| matchesFeatureType(parser.getLocalName())) {
inFeature = true;
Expand Down Expand Up @@ -357,11 +372,9 @@ protected boolean advanceParser() {
break;

case XMLStreamConstants.CHARACTERS:
if (inFeature) {
if (!parser.isWhiteSpace()) {
this.isBuffering = true;
buffer.append(parser.getText());
}
if (inFeature && !parser.isWhiteSpace()) {
this.isBuffering = true;
buffer.append(parser.getText());
}
break;

Expand All @@ -372,7 +385,7 @@ protected boolean advanceParser() {
default:
// advanceParser(in);
}
} catch (Exception e) {
} catch (Exception e) { // NOPMD AvoidCatchingGenericException
throw new IllegalArgumentException("Could not parse GML: " + e.getMessage(), e);
}
return feedMeMore;
Expand Down
Loading
Loading