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 @@ -8,7 +8,6 @@
package de.ii.xtraplatform.features.graphql.app;

import de.ii.xtraplatform.crs.domain.BoundingBox;
import de.ii.xtraplatform.crs.domain.CrsTransformer;
import de.ii.xtraplatform.crs.domain.CrsTransformerFactory;
import de.ii.xtraplatform.crs.domain.EpsgCrs;
import de.ii.xtraplatform.crs.domain.OgcCrs;
Expand All @@ -18,20 +17,19 @@
import de.ii.xtraplatform.streams.domain.Reactive;
import de.ii.xtraplatform.streams.domain.Reactive.Stream;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import org.threeten.extra.Interval;

public class AggregateStatsReaderGraphQl implements AggregateStatsReader<FeatureSchema> {

private final FeatureMetadata featureMetadata;
private final Optional<CrsTransformer> crsTransformer;

public AggregateStatsReaderGraphQl(
FeatureMetadata featureMetadata,
CrsTransformerFactory crsTransformerFactory,
EpsgCrs nativeCrs) {
this.featureMetadata = featureMetadata;
this.crsTransformer = crsTransformerFactory.getTransformer(OgcCrs.CRS84, nativeCrs, true);
Objects.requireNonNull(featureMetadata);
Objects.requireNonNull(crsTransformerFactory)
.getTransformer(OgcCrs.CRS84, Objects.requireNonNull(nativeCrs), true);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,6 @@ public Optional<BoundingBox> getSpatialExtent(String typeName) {
.join();
} catch (Throwable e) {
// continue
boolean br = true;
}

return Optional.empty();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import de.ii.xtraplatform.features.graphql.domain.FeatureProviderGraphQlData;
import de.ii.xtraplatform.features.graphql.domain.ImmutableFeatureProviderGraphQlData;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import javax.inject.Inject;
Expand All @@ -41,7 +42,6 @@ public class FeatureProviderGraphQlFactory
private static final Logger LOGGER = LoggerFactory.getLogger(FeatureProviderGraphQlFactory.class);

private final Lazy<Set<SchemaFragmentResolver>> schemaResolvers;
private final ConnectorFactory connectorFactory;

@Inject
public FeatureProviderGraphQlFactory(
Expand All @@ -50,7 +50,7 @@ public FeatureProviderGraphQlFactory(
ProviderGraphQlFactoryAssisted providerGraphQlFactoryAssisted) {
super(providerGraphQlFactoryAssisted);
this.schemaResolvers = schemaResolvers;
this.connectorFactory = connectorFactory;
Objects.requireNonNull(connectorFactory);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.stream.Collectors;
import java.util.stream.Stream;
Expand All @@ -39,7 +40,6 @@ public class FeatureQueryEncoderGraphQl implements FeatureQueryEncoder<String, Q
private final Map<String, FeatureSchema> featureSchemas;
private final Map<String, List<FeatureSchema>> sourceSchemas;
private final GraphQlQueries queryGeneration;
private final EpsgCrs nativeCrs;
private final FilterEncoderGraphQl filterEncoder;

public FeatureQueryEncoderGraphQl(
Expand All @@ -52,8 +52,8 @@ public FeatureQueryEncoderGraphQl(
Cql cql) {
this.featureSchemas = featureSchemas;
this.sourceSchemas = sourceSchemas;
Objects.requireNonNull(connectionInfo);
this.queryGeneration = queryGeneration;
this.nativeCrs = nativeCrs;
this.filterEncoder =
new FilterEncoderGraphQl(nativeCrs, crsTransformerFactory, cql, queryGeneration);
}
Expand Down Expand Up @@ -95,22 +95,16 @@ private String getNestedFields(String sourcePath) {
return sourcePath;
}

String fields = "";

String[] split = sourcePath.split("/");
for (int i = split.length - 1; i >= 0; i--) {
String elem = split[i];
if (!fields.isBlank()) {
elem = elem + " " + fields;
}
if (i > 0) {
fields = "{ " + elem + " }";
} else {
fields = elem;
}
StringBuilder fields = new StringBuilder(split[split.length - 1]);

for (int i = split.length - 2; i >= 0; i--) {
fields.insert(0, " { ");
fields.insert(0, split[i]);
fields.append(" }");
}

return fields;
return fields.toString();
}

public String getFields(FeatureSchema featureSchema, String indentation) {
Expand Down Expand Up @@ -146,7 +140,9 @@ public String encodeFeatureQuery(

String q = String.format(queryTemplate, name + arguments, fields);

LOGGER.debug("GraphQL Request\n{}", q.replaceAll("\\\\n", "\n"));
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("GraphQL Request\n{}", q.replaceAll("\\\\n", "\n"));
}

return q;
}
Expand Down Expand Up @@ -174,7 +170,7 @@ private List<String> getPaging(int limit, int offset) {
.map(
template ->
StringTemplateFilters.applyTemplate(
template, (Map.of("value", String.valueOf(limit)))::get))
template, Map.of("value", String.valueOf(limit))::get))
.ifPresent(arguments::add);

queryGeneration
Expand All @@ -184,7 +180,7 @@ private List<String> getPaging(int limit, int offset) {
.map(
template ->
StringTemplateFilters.applyTemplate(
template, (Map.of("value", String.valueOf(offset)))::get))
template, Map.of("value", String.valueOf(offset))::get))
.ifPresent(arguments::add);

return arguments;
Expand Down Expand Up @@ -212,7 +208,7 @@ private List<String> getFilter(
String argument =
StringTemplateFilters.applyTemplate(
queryGeneration.getCollection().getArguments().getFilter().orElse("{{value}}"),
(Map.of("value", filterString))::get);
Map.of("value", filterString)::get);

return List.of(argument);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,12 @@
import java.util.Objects;
import java.util.Optional;
import java.util.stream.Collectors;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class FeatureTokenDecoderGraphQlJson2
extends FeatureTokenDecoder<
byte[], FeatureSchema, SchemaMapping, ModifiableContext<FeatureSchema, SchemaMapping>>
implements Decoder.Pipeline {

private static final Logger LOGGER =
LoggerFactory.getLogger(FeatureTokenDecoderGraphQlJson2.class);
private static final JsonFactory JSON_FACTORY = new JsonFactory();

private final JsonParser parser;
Expand All @@ -47,23 +43,21 @@ public class FeatureTokenDecoderGraphQlJson2
private final Map<String, SchemaMapping> mappings;
private final String type;
private final String wrapper;
private final Optional<String> nullValue;

private boolean started;
private int depth = -1;
private int featureDepth = 0;
private boolean inFeatures = false;
private boolean inProperties = false;
private boolean isCollection = false;
private boolean inErrors = false;
private int lastNameIsArrayDepth = 0;
private int startArray = 0;
private int endArray = 0;
private final ParsingState state;

private ModifiableContext<FeatureSchema, SchemaMapping> context;
private List<List<String>> arrayPaths;
private DecoderJsonProperties decoderJsonProperties;

private static final class ParsingState {
boolean started;
int featureDepth;
boolean inFeatures;
boolean inProperties;
boolean isCollection;
boolean inErrors;
}

public FeatureTokenDecoderGraphQlJson2(
FeatureSchema featureSchema,
FeatureQuery query,
Expand All @@ -80,6 +74,7 @@ public FeatureTokenDecoderGraphQlJson2(
String type,
String wrapper,
Optional<String> nullValue) {
super();
try {
this.parser = JSON_FACTORY.createNonBlockingByteArrayParser();
} catch (IOException e) {
Expand All @@ -91,7 +86,8 @@ public FeatureTokenDecoderGraphQlJson2(
this.mappings = mappings;
this.type = type;
this.wrapper = wrapper;
this.nullValue = nullValue;
this.state = new ParsingState();
Objects.requireNonNull(nullValue);
}

@Override
Expand All @@ -102,7 +98,7 @@ protected void init() {
.setMappings(mappings)
.setQuery(featureQuery);

this.arrayPaths =
List<List<String>> arrayPaths =
context.mapping().getSchemasByTargetPath().entrySet().stream()
.filter(entry -> entry.getValue().get(0).isArray())
.map(entry -> entry.getKey())
Expand All @@ -128,7 +124,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 @@ -147,6 +143,7 @@ private void feedInput(byte[] data) {
}
}

@SuppressWarnings({"PMD.CognitiveComplexity", "PMD.CyclomaticComplexity"})
public boolean advanceParser() {

boolean feedMeMore = false;
Expand All @@ -165,44 +162,44 @@ public boolean advanceParser() {

case START_OBJECT:
case START_ARRAY:
if (!inProperties) {
if (inFeatures && context.path().size() == featureDepth) {
this.inProperties = true;
if (isCollection) {
if (!state.inProperties) {
if (state.inFeatures && context.path().size() == state.featureDepth) {
state.inProperties = true;
if (state.isCollection) {
startFeature();
}
} else if (!inFeatures && Objects.equals(currentName, wrapper)) {
} else if (!state.inFeatures && Objects.equals(currentName, wrapper)) {
startIfNecessary(nextToken == JsonToken.START_ARRAY);
} else if (!inFeatures && Objects.equals(currentName, "errors")) {
this.inErrors = true;
} else if (!state.inFeatures && Objects.equals(currentName, "errors")) {
state.inErrors = true;
}
break;
}
feedMeMore = decoderJsonProperties.parse(nextToken, currentName, featureDepth);
feedMeMore = decoderJsonProperties.parse(nextToken, currentName, state.featureDepth);
break;
case END_OBJECT:
if (inProperties && context.path().size() == featureDepth) {
this.inProperties = false;
if (state.inProperties && context.path().size() == state.featureDepth) {
state.inProperties = false;
getDownstream().onFeatureEnd(context);
if (!isCollection) {
if (!state.isCollection) {
getDownstream().onEnd(context);
this.inFeatures = false;
state.inFeatures = false;
}
break;
}
feedMeMore = decoderJsonProperties.parse(nextToken, currentName, featureDepth);
feedMeMore = decoderJsonProperties.parse(nextToken, currentName, state.featureDepth);
break;
case END_ARRAY:
if (!inProperties && context.path().size() == featureDepth) {
if (!state.inProperties && context.path().size() == state.featureDepth) {
getDownstream().onEnd(context);
this.inFeatures = false;
state.inFeatures = false;
break;
}
feedMeMore = decoderJsonProperties.parse(nextToken, currentName, featureDepth);
feedMeMore = decoderJsonProperties.parse(nextToken, currentName, state.featureDepth);
break;
default:
if (!inErrors) {
feedMeMore = decoderJsonProperties.parse(nextToken, currentName, featureDepth);
if (!state.inErrors) {
feedMeMore = decoderJsonProperties.parse(nextToken, currentName, state.featureDepth);
break;
}
if (Objects.equals(currentName, "message")) {
Expand Down Expand Up @@ -231,10 +228,10 @@ public ModifiableContext<FeatureSchema, SchemaMapping> context() {
}

private void startIfNecessary(boolean isCollection) {
if (!started) {
this.started = true;
this.inFeatures = true;
this.isCollection = isCollection;
if (!state.started) {
state.started = true;
state.inFeatures = true;
state.isCollection = isCollection;

if (!isCollection) {
context.metadata().isSingleFeature(true);
Expand All @@ -251,7 +248,7 @@ private void startFeature() {
context.setIndexes(List.of());
decoderJsonProperties.reset();
getDownstream().onFeatureStart(context);
this.featureDepth = context.path().size();
this.inProperties = true;
state.featureDepth = context.path().size();
state.inProperties = true;
}
}
Loading
Loading