diff --git a/commons/src/main/java/org/restheart/exchange/MongoRequest.java b/commons/src/main/java/org/restheart/exchange/MongoRequest.java index d3194a67c..1ca70abdc 100644 --- a/commons/src/main/java/org/restheart/exchange/MongoRequest.java +++ b/commons/src/main/java/org/restheart/exchange/MongoRequest.java @@ -19,11 +19,6 @@ */ package org.restheart.exchange; -import io.undertow.server.HttpServerExchange; -import io.undertow.util.AttachmentKey; -import io.undertow.util.Headers; -import io.undertow.util.PathTemplateMatch; - import java.io.InputStream; import java.net.URI; import java.net.URISyntaxException; @@ -32,6 +27,7 @@ import java.util.Map; import java.util.Optional; import java.util.stream.Collectors; + import org.bson.BsonArray; import org.bson.BsonDocument; import org.bson.BsonInt32; @@ -40,19 +36,54 @@ import org.bson.BsonValue; import org.bson.json.JsonMode; import org.bson.json.JsonParseException; -import static org.restheart.exchange.ExchangeKeys.*; -import static org.restheart.utils.BsonUtils.document; +import static org.restheart.exchange.ExchangeKeys.ADMIN; +import static org.restheart.exchange.ExchangeKeys.BINARY_CONTENT; +import static org.restheart.exchange.ExchangeKeys.CACHE_QPARAM_KEY; +import static org.restheart.exchange.ExchangeKeys.COLL_META_DOCID_PREFIX; +import static org.restheart.exchange.ExchangeKeys.CONFIG; +import static org.restheart.exchange.ExchangeKeys.DB_META_DOCID; import org.restheart.exchange.ExchangeKeys.DOC_ID_TYPE; +import static org.restheart.exchange.ExchangeKeys.ETAG_CHECK_QPARAM_KEY; +import static org.restheart.exchange.ExchangeKeys.FS_CHUNKS_SUFFIX; +import static org.restheart.exchange.ExchangeKeys.FS_FILES_SUFFIX; import org.restheart.exchange.ExchangeKeys.HAL_MODE; +import static org.restheart.exchange.ExchangeKeys.JSON_MODE_QPARAM_KEY; +import static org.restheart.exchange.ExchangeKeys.LOCAL; +import static org.restheart.exchange.ExchangeKeys.META_COLLNAME; +import static org.restheart.exchange.ExchangeKeys.NO_CACHE_QPARAM_KEY; +import static org.restheart.exchange.ExchangeKeys.NO_PROPS_KEY; +import static org.restheart.exchange.ExchangeKeys.NUL; +import static org.restheart.exchange.ExchangeKeys.READ_CONCERN_QPARAM_KEY; +import static org.restheart.exchange.ExchangeKeys.READ_PREFERENCE_QPARAM_KEY; import org.restheart.exchange.ExchangeKeys.REPRESENTATION_FORMAT; +import static org.restheart.exchange.ExchangeKeys.RESOURCES_WILDCARD_KEY; +import static org.restheart.exchange.ExchangeKeys.SYSTEM; import org.restheart.exchange.ExchangeKeys.TYPE; +import static org.restheart.exchange.ExchangeKeys.WRITE_CONCERN_QPARAM_KEY; import org.restheart.exchange.ExchangeKeys.WRITE_MODE; +import static org.restheart.exchange.ExchangeKeys.WRITE_MODE_QPARAM_KEY; +import static org.restheart.exchange.ExchangeKeys.WRITE_MODE_SHORT_QPARAM_KEY; +import static org.restheart.exchange.ExchangeKeys._AGGREGATIONS; +import static org.restheart.exchange.ExchangeKeys._INDEXES; +import static org.restheart.exchange.ExchangeKeys._META; +import static org.restheart.exchange.ExchangeKeys._METRICS; +import static org.restheart.exchange.ExchangeKeys._SCHEMAS; +import static org.restheart.exchange.ExchangeKeys._SESSIONS; +import static org.restheart.exchange.ExchangeKeys._SIZE; +import static org.restheart.exchange.ExchangeKeys._STREAMS; +import static org.restheart.exchange.ExchangeKeys._TRANSACTIONS; import org.restheart.mongodb.RSOps; import org.restheart.mongodb.db.sessions.ClientSessionImpl; +import static org.restheart.utils.BsonUtils.document; import org.restheart.utils.MongoServiceAttachments; import org.restheart.utils.URLUtils; -import org.slf4j.LoggerFactory; import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import io.undertow.server.HttpServerExchange; +import io.undertow.util.AttachmentKey; +import io.undertow.util.Headers; +import io.undertow.util.PathTemplateMatch; /** * @@ -208,12 +239,12 @@ protected MongoRequest(HttpServerExchange exchange, String requestUri, String re this.writeMode = mode; var anyRsSet = false; - var rsOps = new RSOps(); + var _rsOps = new RSOps(); // readConcern if (exchange.getQueryParameters().containsKey(READ_CONCERN_QPARAM_KEY)) { try { - rsOps = rsOps.withReadConcern(exchange.getQueryParameters().get(READ_CONCERN_QPARAM_KEY).getFirst()); + _rsOps = _rsOps.withReadConcern(exchange.getQueryParameters().get(READ_CONCERN_QPARAM_KEY).getFirst()); anyRsSet = true; } catch (IllegalArgumentException iae) { // nothing to do @@ -223,7 +254,7 @@ protected MongoRequest(HttpServerExchange exchange, String requestUri, String re // readPreference if (exchange.getQueryParameters().containsKey(READ_PREFERENCE_QPARAM_KEY)) { try { - rsOps = rsOps.withReadPreference(exchange.getQueryParameters().get(READ_PREFERENCE_QPARAM_KEY).getFirst()); + _rsOps = _rsOps.withReadPreference(exchange.getQueryParameters().get(READ_PREFERENCE_QPARAM_KEY).getFirst()); anyRsSet = true; } catch (IllegalArgumentException iae) { // nothing to do @@ -232,12 +263,12 @@ protected MongoRequest(HttpServerExchange exchange, String requestUri, String re // writeConcern if (exchange.getQueryParameters().containsKey(WRITE_CONCERN_QPARAM_KEY)) { - rsOps = rsOps.withWriteConcern(exchange.getQueryParameters().get(WRITE_CONCERN_QPARAM_KEY).getFirst()); + _rsOps = _rsOps.withWriteConcern(exchange.getQueryParameters().get(WRITE_CONCERN_QPARAM_KEY).getFirst()); anyRsSet = true; } - this.rsOps = anyRsSet ? Optional.of(rsOps) : Optional.empty(); - LOGGER.debug("ReplicaSet connection options: {}", rsOps); + this.rsOps = anyRsSet ? Optional.of(_rsOps) : Optional.empty(); + LOGGER.debug("ReplicaSet connection options: {}", _rsOps); } private String defaultWriteMode() { @@ -655,7 +686,7 @@ public String getSid() { * @return the txn id or null if request type is not TRANSACTION */ public Long getTxnId() { - return isTxn() ? Long.parseLong(getPathTokenAt(4)) : null; + return isTxn() ? Long.valueOf(getPathTokenAt(4)) : null; } /** @@ -1093,7 +1124,7 @@ public boolean isContentInjected() { return this.wrapped.getAttachment(CONTENT_INJECTED); } - public void setContentInjected(boolean value) { + public final void setContentInjected(boolean value) { this.wrapped.putAttachment(CONTENT_INJECTED, value); } @@ -1599,7 +1630,7 @@ public boolean isNoCache() { /** * ReplicaSet connection otpions * - * @return the rsOps + * @return the _rsOps */ public Optional rsOps() { return rsOps; diff --git a/graphql/src/main/java/org/restheart/graphql/datafetchers/GQLAggregationDataFetcher.java b/graphql/src/main/java/org/restheart/graphql/datafetchers/GQLAggregationDataFetcher.java index 81051c385..b0235a886 100644 --- a/graphql/src/main/java/org/restheart/graphql/datafetchers/GQLAggregationDataFetcher.java +++ b/graphql/src/main/java/org/restheart/graphql/datafetchers/GQLAggregationDataFetcher.java @@ -38,6 +38,7 @@ import com.mongodb.client.AggregateIterable; import graphql.schema.DataFetchingEnvironment; +import graphql.schema.GraphQLList; public class GQLAggregationDataFetcher extends GraphQLDataFetcher { @@ -99,12 +100,14 @@ public Object get(DataFetchingEnvironment env) throws Exception { .allowDiskUse(aggregation.getAllowDiskUse().getValue()) .maxTime(this.aggregationTimeLimit, TimeUnit.MILLISECONDS); - var stageOutput = new ArrayList(); + boolean isMultiple = env.getFieldDefinition().getType() instanceof GraphQLList; - if (res != null) { - res.into(stageOutput); + if (isMultiple) { + var aggregationResult = new BsonArray(); + res.into(aggregationResult.asArray()); + return aggregationResult; + } else { + return res.first(); } - - return stageOutput; } } diff --git a/metrics/src/main/java/org/restheart/metrics/JvmMetricsCollector.java b/metrics/src/main/java/org/restheart/metrics/JvmMetricsCollector.java index 7794f4eaa..19464301a 100644 --- a/metrics/src/main/java/org/restheart/metrics/JvmMetricsCollector.java +++ b/metrics/src/main/java/org/restheart/metrics/JvmMetricsCollector.java @@ -21,19 +21,21 @@ package org.restheart.metrics; +import static org.restheart.metrics.MetricsService.METRICS_REGISTRIES_PREFIX; import org.restheart.plugins.Initializer; import org.restheart.plugins.RegisterPlugin; -import static org.restheart.metrics.MetricsService.METRICS_REGISTRIES_PREFIX; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import com.codahale.metrics.SharedMetricRegistries; import com.codahale.metrics.jvm.GarbageCollectorMetricSet; import com.codahale.metrics.jvm.MemoryUsageGaugeSet; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; @RegisterPlugin(name="jvmMetricsCollector", description = "registers the JVM metrics", enabledByDefault = false) public class JvmMetricsCollector implements Initializer { private static final Logger LOGGER = LoggerFactory.getLogger(JvmMetricsCollector.class); + @Override public void init() { var registry = SharedMetricRegistries.getOrCreate(METRICS_REGISTRIES_PREFIX + "/jvm"); registry.registerAll("jvm mem", new MemoryUsageGaugeSet());