diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
new file mode 100644
index 0000000..8f19212
--- /dev/null
+++ b/.github/workflows/build.yml
@@ -0,0 +1,19 @@
+name: Build Artifact
+
+on:
+ pull_request:
+ branches:
+ - '*'
+
+jobs:
+ build:
+ runs-on: ubuntu-20.04
+ steps:
+ - uses: actions/checkout@v2
+ - name: Set up Maven Central Repository
+ uses: actions/setup-java@v2
+ with:
+ java-version: '15'
+ distribution: 'adopt'
+ - name: Build package
+ run: mvn --batch-mode clean package
\ No newline at end of file
diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml
new file mode 100644
index 0000000..14e50ed
--- /dev/null
+++ b/.github/workflows/deploy.yml
@@ -0,0 +1,22 @@
+name: Deploy Artifact
+
+on:
+ push:
+ branches:
+ - 'master'
+ - 'main'
+
+jobs:
+ deploy:
+ runs-on: ubuntu-20.04
+ steps:
+ - name: Checkout Repo
+ uses: actions/checkout@v2
+
+ - name: Deploy package
+ uses: valitydev/action-deploy-jdk-package@v1.0.9
+ with:
+ server-username: ${{ secrets.OSSRH_USERNAME }}
+ server-password: ${{ secrets.OSSRH_TOKEN }}
+ deploy-secret-key: ${{ secrets.OSSRH_GPG_SECRET_KEY }}
+ deploy-secret-key-password: ${{ secrets.OSSRH_GPG_SECRET_KEY_PASSWORD }}
\ No newline at end of file
diff --git a/.gitmodules b/.gitmodules
deleted file mode 100644
index 4a5266f..0000000
--- a/.gitmodules
+++ /dev/null
@@ -1,3 +0,0 @@
-[submodule "build_utils"]
- path = build_utils
- url = git@github.com:rbkmoney/build_utils.git
diff --git a/Jenkinsfile b/Jenkinsfile
deleted file mode 100644
index f20ea03..0000000
--- a/Jenkinsfile
+++ /dev/null
@@ -1,13 +0,0 @@
-#!groovy
-build('magista_dsl', 'docker-host') {
- checkoutRepo()
- loadBuildUtils()
-
- def javaLibPipeline
- runStage('load JavaLib pipeline') {
- javaLibPipeline = load("build_utils/jenkins_lib/pipeJavaLib.groovy")
- }
-
- def buildImageTag = "fcf116dd775cc2e91bffb6a36835754e3f2d5321"
- javaLibPipeline(buildImageTag)
-}
\ No newline at end of file
diff --git a/build_utils b/build_utils
deleted file mode 160000
index e131872..0000000
--- a/build_utils
+++ /dev/null
@@ -1 +0,0 @@
-Subproject commit e1318727d4d0c3e48f5122bf3197158b6695f50e
diff --git a/pom.xml b/pom.xml
index 857955e..6173020 100644
--- a/pom.xml
+++ b/pom.xml
@@ -5,9 +5,9 @@
4.0.0
- com.rbkmoney
- parent
- 1.0.5
+ dev.vality
+ library-parent-pom
+ 1.0.0
magista-dsl
diff --git a/src/main/java/com/rbkmoney/magista/dsl/builder/AbstractQueryBuilder.java b/src/main/java/com/rbkmoney/magista/dsl/builder/AbstractQueryBuilder.java
deleted file mode 100644
index d0e0006..0000000
--- a/src/main/java/com/rbkmoney/magista/dsl/builder/AbstractQueryBuilder.java
+++ /dev/null
@@ -1,89 +0,0 @@
-package com.rbkmoney.magista.dsl.builder;
-
-import com.rbkmoney.magista.dsl.*;
-import com.rbkmoney.magista.dsl.parser.QueryPart;
-
-import java.util.Collections;
-import java.util.List;
-import java.util.function.BiFunction;
-import java.util.function.Function;
-import java.util.stream.Collectors;
-import java.util.stream.Stream;
-
-public abstract class AbstractQueryBuilder implements QueryBuilder {
-
- protected Stream getMatchedPartsStream(Object descriptor, List queryParts) {
- return queryParts.stream().filter(queryPart -> descriptor.equals(queryPart.getDescriptor()));
- }
-
-
- protected CompositeQuery createCompositeQuery(
- Object descriptor,
- QueryParameters derivedParameters,
- List childQueries,
- Function> execFunction,
- BiFunction, QueryResult> parallelExecFunction
- ) {
- return BaseCompositeQuery.newInstance(descriptor, new QueryParameters(Collections.emptyMap(), derivedParameters), childQueries, execFunction, parallelExecFunction);
- }
-
- protected CompositeQuery createCompositeQuery(
- Object descriptor,
- QueryParameters derivedParameters,
- List childQueries
- ) {
- return createCompositeQuery(
- descriptor, derivedParameters, childQueries,
- context -> new BaseQueryResult<>(
- () -> childQueries.stream().map(query -> query.execute(context)),
- () -> childQueries.stream().map(query -> query.execute(context)).collect(Collectors.toList())
- ),
- (context, queryResults) -> new BaseQueryResult<>(
- () -> queryResults.stream(),
- () -> queryResults
- )
-
- );
- }
-
- protected CompositeQuery createCompositeQuery(
- Object descriptor,
- List childQueries,
- Function> execFunction,
- BiFunction, QueryResult> parallelExecFunction
- ) {
- return createCompositeQuery(descriptor, new QueryParameters(Collections.emptyMap(), null), childQueries, execFunction, parallelExecFunction);
- }
-
- protected QueryParameters getParameters(QueryPart queryPart) {
- return queryPart == null ? null : queryPart.getParameters();
- }
-
- protected List buildQueries(Object matchDescriptor, List queryParts, Function queryCreator) {
- List matchedParts = getMatchedPartsStream(matchDescriptor, queryParts).collect(Collectors.toList());
- return matchedParts.stream().map(queryPart -> queryCreator.apply(queryPart)).collect(Collectors.toList());
- }
-
- protected Query buildSingleQuery(Object matchDescriptor, List queryParts, Function queryCreator) {
- List queries = buildQueries(matchDescriptor, queryParts, queryCreator);
- if (queries.size() == 0) {
- throw new QueryBuilderException("No queries found in referred data");
- } else if (queries.size() > 1) {
- throw new QueryBuilderException("Only one query expected");
- } else {
- return queries.get(0);
- }
- }
-
- protected Query buildAndWrapQueries(
- Object matchDescriptor,
- List queryParts,
- Function queryCreator,
- QueryParameters parentParameters,
- Function> execFunction,
- BiFunction, QueryResult> parallelExecFunction
- ) {
- List queries = buildQueries(matchDescriptor, queryParts, queryCreator);
- return createCompositeQuery(queries.get(0).getDescriptor(), parentParameters, queries, execFunction, parallelExecFunction);
- }
-}
diff --git a/src/main/java/com/rbkmoney/magista/dsl/builder/QueryBuilder.java b/src/main/java/com/rbkmoney/magista/dsl/builder/QueryBuilder.java
deleted file mode 100644
index f951de1..0000000
--- a/src/main/java/com/rbkmoney/magista/dsl/builder/QueryBuilder.java
+++ /dev/null
@@ -1,13 +0,0 @@
-package com.rbkmoney.magista.dsl.builder;
-
-import com.rbkmoney.magista.dsl.Query;
-import com.rbkmoney.magista.dsl.parser.QueryPart;
-
-import java.util.List;
-
-public interface QueryBuilder {
-
- Query buildQuery(List queryParts, String continuationToken, QueryPart parentQueryPart, QueryBuilder baseBuilder) throws QueryBuilderException;
-
- boolean apply(List queryParts, QueryPart parent);
-}
diff --git a/src/main/java/com/rbkmoney/magista/dsl/parser/QueryParser.java b/src/main/java/com/rbkmoney/magista/dsl/parser/QueryParser.java
deleted file mode 100644
index 1906cf1..0000000
--- a/src/main/java/com/rbkmoney/magista/dsl/parser/QueryParser.java
+++ /dev/null
@@ -1,9 +0,0 @@
-package com.rbkmoney.magista.dsl.parser;
-
-
-import java.util.List;
-
-public interface QueryParser {
- List parseQuery(Src source, QueryPart parent) throws QueryParserException;
- boolean apply(Src source, QueryPart parent);
-}
diff --git a/src/main/java/com/rbkmoney/magista/dsl/BadTokenException.java b/src/main/java/dev/vality/magista/dsl/BadTokenException.java
similarity index 91%
rename from src/main/java/com/rbkmoney/magista/dsl/BadTokenException.java
rename to src/main/java/dev/vality/magista/dsl/BadTokenException.java
index 6d646f0..3b12973 100644
--- a/src/main/java/com/rbkmoney/magista/dsl/BadTokenException.java
+++ b/src/main/java/dev/vality/magista/dsl/BadTokenException.java
@@ -1,4 +1,4 @@
-package com.rbkmoney.magista.dsl;
+package dev.vality.magista.dsl;
public class BadTokenException extends IllegalArgumentException {
diff --git a/src/main/java/com/rbkmoney/magista/dsl/BaseCompositeQuery.java b/src/main/java/dev/vality/magista/dsl/BaseCompositeQuery.java
similarity index 59%
rename from src/main/java/com/rbkmoney/magista/dsl/BaseCompositeQuery.java
rename to src/main/java/dev/vality/magista/dsl/BaseCompositeQuery.java
index bbfc3a8..9206429 100644
--- a/src/main/java/com/rbkmoney/magista/dsl/BaseCompositeQuery.java
+++ b/src/main/java/dev/vality/magista/dsl/BaseCompositeQuery.java
@@ -1,4 +1,4 @@
-package com.rbkmoney.magista.dsl;
+package dev.vality.magista.dsl;
import java.util.List;
@@ -7,22 +7,13 @@ import java.util.function.Function;
import java.util.stream.Collectors;
public class BaseCompositeQuery extends BaseQuery implements CompositeQuery {
- private List queries;
private final Function> execFunction;
private final BiFunction, QueryResult> parallelExecFunction;
+ private List queries;
- public static BaseCompositeQuery newInstance(Object descriptor, QueryParameters params, List queries, Function> execFunction) {
- return newInstance(descriptor, params, queries, execFunction, null);
- }
-
- public static BaseCompositeQuery newInstance(Object descriptor, QueryParameters params, List queries, Function> execFunction, BiFunction, QueryResult> parallelExecFunction) {
- BaseCompositeQuery compositeQuery = new BaseCompositeQuery<>(descriptor, params, execFunction, parallelExecFunction);
- compositeQuery.setChildQueries(queries);
- return compositeQuery;
- }
-
-
- public BaseCompositeQuery(Object descriptor, QueryParameters params, Function> execFunction, BiFunction, QueryResult> parallelExecFunction) {
+ public BaseCompositeQuery(Object descriptor, QueryParameters params,
+ Function> execFunction,
+ BiFunction, QueryResult> parallelExecFunction) {
super(descriptor, params);
if (execFunction == null) {
throw new NullPointerException("Null exec function is not allowed");
@@ -31,10 +22,32 @@ public class BaseCompositeQuery extends BaseQuery implements Compo
this.parallelExecFunction = parallelExecFunction;
}
+ public static BaseCompositeQuery newInstance(Object descriptor, QueryParameters params,
+ List queries,
+ Function> execFunction) {
+ return newInstance(descriptor, params, queries, execFunction, null);
+ }
+
+ public static BaseCompositeQuery newInstance(Object descriptor, QueryParameters params,
+ List queries,
+ Function> execFunction,
+ BiFunction,
+ QueryResult> parallelExecFunction) {
+ BaseCompositeQuery compositeQuery =
+ new BaseCompositeQuery<>(descriptor, params, execFunction, parallelExecFunction);
+ compositeQuery.setChildQueries(queries);
+ return compositeQuery;
+ }
+
public List getChildQueries() {
return queries;
}
+ protected void setChildQueries(List queries) {
+ this.queries = queries.stream().peek(query -> query.setParentQuery(this)).collect(Collectors.toList());
+ }
+
public boolean isParallel() {
return parallelExecFunction != null;
}
@@ -45,15 +58,12 @@ public class BaseCompositeQuery extends BaseQuery implements Compo
}
@Override
- public QueryResult execute(QueryContext context, List collectedResults) throws QueryExecutionException {
+ public QueryResult execute(QueryContext context, List collectedResults)
+ throws QueryExecutionException {
if (parallelExecFunction != null) {
return parallelExecFunction.apply(context, collectedResults);
} else {
return CompositeQuery.super.execute(context, collectedResults);
}
}
-
- protected void setChildQueries(List queries) {
- this.queries = queries.stream().peek(query -> query.setParentQuery(this)).collect(Collectors.toList());
- }
}
diff --git a/src/main/java/com/rbkmoney/magista/dsl/BaseFunction.java b/src/main/java/dev/vality/magista/dsl/BaseFunction.java
similarity index 91%
rename from src/main/java/com/rbkmoney/magista/dsl/BaseFunction.java
rename to src/main/java/dev/vality/magista/dsl/BaseFunction.java
index 9f8b6d5..b5e653a 100644
--- a/src/main/java/com/rbkmoney/magista/dsl/BaseFunction.java
+++ b/src/main/java/dev/vality/magista/dsl/BaseFunction.java
@@ -1,4 +1,4 @@
-package com.rbkmoney.magista.dsl;
+package dev.vality.magista.dsl;
public abstract class BaseFunction extends BaseQuery implements FunctionQuery {
diff --git a/src/main/java/com/rbkmoney/magista/dsl/BaseQuery.java b/src/main/java/dev/vality/magista/dsl/BaseQuery.java
similarity index 97%
rename from src/main/java/com/rbkmoney/magista/dsl/BaseQuery.java
rename to src/main/java/dev/vality/magista/dsl/BaseQuery.java
index 1f1fdb2..6e421c6 100644
--- a/src/main/java/com/rbkmoney/magista/dsl/BaseQuery.java
+++ b/src/main/java/dev/vality/magista/dsl/BaseQuery.java
@@ -1,4 +1,4 @@
-package com.rbkmoney.magista.dsl;
+package dev.vality.magista.dsl;
public abstract class BaseQuery implements Query {
private final Object descriptor;
diff --git a/src/main/java/com/rbkmoney/magista/dsl/BaseQueryResult.java b/src/main/java/dev/vality/magista/dsl/BaseQueryResult.java
similarity index 94%
rename from src/main/java/com/rbkmoney/magista/dsl/BaseQueryResult.java
rename to src/main/java/dev/vality/magista/dsl/BaseQueryResult.java
index 4e7cb83..1d04b06 100644
--- a/src/main/java/com/rbkmoney/magista/dsl/BaseQueryResult.java
+++ b/src/main/java/dev/vality/magista/dsl/BaseQueryResult.java
@@ -1,4 +1,4 @@
-package com.rbkmoney.magista.dsl;
+package dev.vality.magista.dsl;
import java.util.function.Supplier;
import java.util.stream.Stream;
diff --git a/src/main/java/com/rbkmoney/magista/dsl/BaseQueryValidator.java b/src/main/java/dev/vality/magista/dsl/BaseQueryValidator.java
similarity index 82%
rename from src/main/java/com/rbkmoney/magista/dsl/BaseQueryValidator.java
rename to src/main/java/dev/vality/magista/dsl/BaseQueryValidator.java
index f42c040..268b533 100644
--- a/src/main/java/com/rbkmoney/magista/dsl/BaseQueryValidator.java
+++ b/src/main/java/dev/vality/magista/dsl/BaseQueryValidator.java
@@ -1,4 +1,4 @@
-package com.rbkmoney.magista.dsl;
+package dev.vality.magista.dsl;
import java.time.Instant;
import java.time.temporal.TemporalAccessor;
@@ -21,9 +21,11 @@ public abstract class BaseQueryValidator implements QueryValidator {
}
}
- protected T checkParamsType(QueryParameters parameters, Class extends QueryParameters> expectedType) {
+ protected T checkParamsType(QueryParameters parameters,
+ Class extends QueryParameters> expectedType) {
if (!expectedType.isAssignableFrom(parameters.getClass())) {
- checkParamsResult(true, "Parameters has wrong type:" + parameters.getClass() + ", expected: " + expectedType);
+ checkParamsResult(true,
+ "Parameters has wrong type:" + parameters.getClass() + ", expected: " + expectedType);
}
return (T) parameters;
}
diff --git a/src/main/java/com/rbkmoney/magista/dsl/CompositeQuery.java b/src/main/java/dev/vality/magista/dsl/CompositeQuery.java
similarity index 75%
rename from src/main/java/com/rbkmoney/magista/dsl/CompositeQuery.java
rename to src/main/java/dev/vality/magista/dsl/CompositeQuery.java
index b5af4bb..6e5ba5a 100644
--- a/src/main/java/com/rbkmoney/magista/dsl/CompositeQuery.java
+++ b/src/main/java/dev/vality/magista/dsl/CompositeQuery.java
@@ -1,4 +1,4 @@
-package com.rbkmoney.magista.dsl;
+package dev.vality.magista.dsl;
import java.util.List;
@@ -9,7 +9,8 @@ public interface CompositeQuery extends Query {
return false;
}
- default QueryResult execute(QueryContext context, List collectedResults) throws QueryExecutionException {
+ default QueryResult execute(QueryContext context, List collectedResults)
+ throws QueryExecutionException {
throw new UnsupportedOperationException("Explicit implementation required");
}
diff --git a/src/main/java/com/rbkmoney/magista/dsl/FunctionQuery.java b/src/main/java/dev/vality/magista/dsl/FunctionQuery.java
similarity index 71%
rename from src/main/java/com/rbkmoney/magista/dsl/FunctionQuery.java
rename to src/main/java/dev/vality/magista/dsl/FunctionQuery.java
index fedc616..2e16e03 100644
--- a/src/main/java/com/rbkmoney/magista/dsl/FunctionQuery.java
+++ b/src/main/java/dev/vality/magista/dsl/FunctionQuery.java
@@ -1,4 +1,4 @@
-package com.rbkmoney.magista.dsl;
+package dev.vality.magista.dsl;
public interface FunctionQuery extends Query {
diff --git a/src/main/java/com/rbkmoney/magista/dsl/PagedBaseFunction.java b/src/main/java/dev/vality/magista/dsl/PagedBaseFunction.java
similarity index 76%
rename from src/main/java/com/rbkmoney/magista/dsl/PagedBaseFunction.java
rename to src/main/java/dev/vality/magista/dsl/PagedBaseFunction.java
index 0285fbf..c8f569f 100644
--- a/src/main/java/com/rbkmoney/magista/dsl/PagedBaseFunction.java
+++ b/src/main/java/dev/vality/magista/dsl/PagedBaseFunction.java
@@ -1,15 +1,13 @@
-package com.rbkmoney.magista.dsl;
+package dev.vality.magista.dsl;
import java.util.Map;
import java.util.Optional;
-import static com.rbkmoney.magista.dsl.Parameters.SIZE_PARAMETER;
-
public abstract class PagedBaseFunction extends BaseFunction {
public static final int MAX_SIZE_VALUE = 1000;
- private String continuationToken;
+ private final String continuationToken;
public PagedBaseFunction(Object descriptor, QueryParameters params, String name, String continuationToken) {
super(descriptor, params, name);
@@ -35,8 +33,7 @@ public abstract class PagedBaseFunction extends BaseFunction {
}
public Integer getSize() {
- return Optional.ofNullable(getIntParameter(SIZE_PARAMETER, true))
- .orElse(MAX_SIZE_VALUE);
+ return Optional.ofNullable(getIntParameter(Parameters.SIZE_PARAMETER, true)).orElse(MAX_SIZE_VALUE);
}
}
@@ -46,7 +43,8 @@ public abstract class PagedBaseFunction extends BaseFunction {
public void validateQuery(Query query) throws IllegalArgumentException {
super.validateQuery(query);
if (query instanceof PagedBaseFunction) {
- validateContinuationToken(query.getQueryParameters(), ((PagedBaseFunction) query).getContinuationToken());
+ validateContinuationToken(query.getQueryParameters(),
+ ((PagedBaseFunction) query).getContinuationToken());
}
}
@@ -55,15 +53,12 @@ public abstract class PagedBaseFunction extends BaseFunction {
super.validateParameters(parameters);
PagedBaseParameters pagedBaseParameters = super.checkParamsType(parameters, PagedBaseParameters.class);
checkParamsResult(pagedBaseParameters.getSize() > MAX_SIZE_VALUE,
- String.format(
- "Size must be less or equals to %d but was %d",
- MAX_SIZE_VALUE,
- pagedBaseParameters.getSize()
- )
- );
+ String.format("Size must be less or equals to %d but was %d", MAX_SIZE_VALUE,
+ pagedBaseParameters.getSize()));
}
- private void validateContinuationToken(QueryParameters queryParameters, String continuationToken) throws BadTokenException {
+ private void validateContinuationToken(QueryParameters queryParameters, String continuationToken)
+ throws BadTokenException {
try {
TokenUtil.validateToken(queryParameters, continuationToken);
} catch (IllegalArgumentException ex) {
diff --git a/src/main/java/com/rbkmoney/magista/dsl/Parameters.java b/src/main/java/dev/vality/magista/dsl/Parameters.java
similarity index 80%
rename from src/main/java/com/rbkmoney/magista/dsl/Parameters.java
rename to src/main/java/dev/vality/magista/dsl/Parameters.java
index 5a0b6e7..db2b656 100644
--- a/src/main/java/com/rbkmoney/magista/dsl/Parameters.java
+++ b/src/main/java/dev/vality/magista/dsl/Parameters.java
@@ -1,4 +1,4 @@
-package com.rbkmoney.magista.dsl;
+package dev.vality.magista.dsl;
public class Parameters {
public static final String QUERY_PARAMETER = "query";
diff --git a/src/main/java/com/rbkmoney/magista/dsl/Query.java b/src/main/java/dev/vality/magista/dsl/Query.java
similarity index 88%
rename from src/main/java/com/rbkmoney/magista/dsl/Query.java
rename to src/main/java/dev/vality/magista/dsl/Query.java
index 1b61c09..9773f17 100644
--- a/src/main/java/com/rbkmoney/magista/dsl/Query.java
+++ b/src/main/java/dev/vality/magista/dsl/Query.java
@@ -1,4 +1,4 @@
-package com.rbkmoney.magista.dsl;
+package dev.vality.magista.dsl;
public interface Query {
Object getDescriptor();
diff --git a/src/main/java/com/rbkmoney/magista/dsl/QueryContext.java b/src/main/java/dev/vality/magista/dsl/QueryContext.java
similarity index 50%
rename from src/main/java/com/rbkmoney/magista/dsl/QueryContext.java
rename to src/main/java/dev/vality/magista/dsl/QueryContext.java
index 41818e7..d02fbd9 100644
--- a/src/main/java/com/rbkmoney/magista/dsl/QueryContext.java
+++ b/src/main/java/dev/vality/magista/dsl/QueryContext.java
@@ -1,4 +1,4 @@
-package com.rbkmoney.magista.dsl;
+package dev.vality.magista.dsl;
public interface QueryContext {
}
diff --git a/src/main/java/com/rbkmoney/magista/dsl/QueryContextFactory.java b/src/main/java/dev/vality/magista/dsl/QueryContextFactory.java
similarity index 68%
rename from src/main/java/com/rbkmoney/magista/dsl/QueryContextFactory.java
rename to src/main/java/dev/vality/magista/dsl/QueryContextFactory.java
index 5e355d4..86eb2bb 100644
--- a/src/main/java/com/rbkmoney/magista/dsl/QueryContextFactory.java
+++ b/src/main/java/dev/vality/magista/dsl/QueryContextFactory.java
@@ -1,4 +1,4 @@
-package com.rbkmoney.magista.dsl;
+package dev.vality.magista.dsl;
public interface QueryContextFactory {
QueryContext getContext();
diff --git a/src/main/java/com/rbkmoney/magista/dsl/QueryExecutionException.java b/src/main/java/dev/vality/magista/dsl/QueryExecutionException.java
similarity index 80%
rename from src/main/java/com/rbkmoney/magista/dsl/QueryExecutionException.java
rename to src/main/java/dev/vality/magista/dsl/QueryExecutionException.java
index 5b630e3..344c3c3 100644
--- a/src/main/java/com/rbkmoney/magista/dsl/QueryExecutionException.java
+++ b/src/main/java/dev/vality/magista/dsl/QueryExecutionException.java
@@ -1,4 +1,4 @@
-package com.rbkmoney.magista.dsl;
+package dev.vality.magista.dsl;
public class QueryExecutionException extends QueryProcessingException {
public QueryExecutionException() {
@@ -16,7 +16,8 @@ public class QueryExecutionException extends QueryProcessingException {
super(cause);
}
- public QueryExecutionException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
+ public QueryExecutionException(String message, Throwable cause, boolean enableSuppression,
+ boolean writableStackTrace) {
super(message, cause, enableSuppression, writableStackTrace);
}
}
diff --git a/src/main/java/com/rbkmoney/magista/dsl/QueryParameters.java b/src/main/java/dev/vality/magista/dsl/QueryParameters.java
similarity index 85%
rename from src/main/java/com/rbkmoney/magista/dsl/QueryParameters.java
rename to src/main/java/dev/vality/magista/dsl/QueryParameters.java
index ee48744..8d5e53b 100644
--- a/src/main/java/com/rbkmoney/magista/dsl/QueryParameters.java
+++ b/src/main/java/dev/vality/magista/dsl/QueryParameters.java
@@ -1,4 +1,4 @@
-package com.rbkmoney.magista.dsl;
+package dev.vality.magista.dsl;
import com.rbkmoney.geck.common.util.TypeUtil;
@@ -9,10 +9,6 @@ import java.util.Map;
import java.util.Objects;
public class QueryParameters {
- public interface QueryParametersRef {
- T newInstance(Map parameters, QueryParameters derivedParameters);
- }
-
private final Map parameters;
private final QueryParameters derivedParameters;
@@ -26,7 +22,8 @@ public class QueryParameters {
}
public Object getParameter(String key, boolean deepSearch) {
- return parameters.getOrDefault(key, deepSearch && derivedParameters != null ? derivedParameters.getParameter(key, deepSearch) : null);
+ return parameters.getOrDefault(key,
+ deepSearch && derivedParameters != null ? derivedParameters.getParameter(key, deepSearch) : null);
}
public T removeParameters(QueryParametersRef parametersRef, String... keys) {
@@ -99,11 +96,15 @@ public class QueryParameters {
@Override
public boolean equals(Object o) {
- if (this == o) return true;
- if (o == null || getClass() != o.getClass()) return false;
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
QueryParameters that = (QueryParameters) o;
- return Objects.equals(parameters, that.parameters) &&
- Objects.equals(derivedParameters, that.derivedParameters);
+ return Objects.equals(parameters, that.parameters)
+ && Objects.equals(derivedParameters, that.derivedParameters);
}
@Override
@@ -113,9 +114,11 @@ public class QueryParameters {
@Override
public String toString() {
- return "QueryParameters{" +
- "parameters=" + parameters +
- ", derivedParameters=" + (derivedParameters == null ? "null" : "notnull") +
- '}';
+ return "QueryParameters{" + "parameters=" + parameters + ", derivedParameters=" +
+ (derivedParameters == null ? "null" : "notnull") + '}';
+ }
+
+ public interface QueryParametersRef {
+ T newInstance(Map parameters, QueryParameters derivedParameters);
}
}
diff --git a/src/main/java/com/rbkmoney/magista/dsl/QueryProcessingException.java b/src/main/java/dev/vality/magista/dsl/QueryProcessingException.java
similarity index 80%
rename from src/main/java/com/rbkmoney/magista/dsl/QueryProcessingException.java
rename to src/main/java/dev/vality/magista/dsl/QueryProcessingException.java
index 5cca402..7ee1ee5 100644
--- a/src/main/java/com/rbkmoney/magista/dsl/QueryProcessingException.java
+++ b/src/main/java/dev/vality/magista/dsl/QueryProcessingException.java
@@ -1,4 +1,4 @@
-package com.rbkmoney.magista.dsl;
+package dev.vality.magista.dsl;
public class QueryProcessingException extends RuntimeException {
public QueryProcessingException() {
@@ -16,7 +16,8 @@ public class QueryProcessingException extends RuntimeException {
super(cause);
}
- public QueryProcessingException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
+ public QueryProcessingException(String message, Throwable cause, boolean enableSuppression,
+ boolean writableStackTrace) {
super(message, cause, enableSuppression, writableStackTrace);
}
}
diff --git a/src/main/java/com/rbkmoney/magista/dsl/QueryProcessor.java b/src/main/java/dev/vality/magista/dsl/QueryProcessor.java
similarity index 78%
rename from src/main/java/com/rbkmoney/magista/dsl/QueryProcessor.java
rename to src/main/java/dev/vality/magista/dsl/QueryProcessor.java
index f466807..a422c62 100644
--- a/src/main/java/com/rbkmoney/magista/dsl/QueryProcessor.java
+++ b/src/main/java/dev/vality/magista/dsl/QueryProcessor.java
@@ -1,4 +1,4 @@
-package com.rbkmoney.magista.dsl;
+package dev.vality.magista.dsl;
public interface QueryProcessor {
R processQuery(S source) throws BadTokenException, QueryProcessingException;
diff --git a/src/main/java/com/rbkmoney/magista/dsl/QueryResult.java b/src/main/java/dev/vality/magista/dsl/QueryResult.java
similarity index 80%
rename from src/main/java/com/rbkmoney/magista/dsl/QueryResult.java
rename to src/main/java/dev/vality/magista/dsl/QueryResult.java
index b00cc85..8c24f28 100644
--- a/src/main/java/com/rbkmoney/magista/dsl/QueryResult.java
+++ b/src/main/java/dev/vality/magista/dsl/QueryResult.java
@@ -1,4 +1,4 @@
-package com.rbkmoney.magista.dsl;
+package dev.vality.magista.dsl;
import java.util.stream.Stream;
diff --git a/src/main/java/com/rbkmoney/magista/dsl/QueryValidator.java b/src/main/java/dev/vality/magista/dsl/QueryValidator.java
similarity index 88%
rename from src/main/java/com/rbkmoney/magista/dsl/QueryValidator.java
rename to src/main/java/dev/vality/magista/dsl/QueryValidator.java
index 9497b83..375355f 100644
--- a/src/main/java/com/rbkmoney/magista/dsl/QueryValidator.java
+++ b/src/main/java/dev/vality/magista/dsl/QueryValidator.java
@@ -1,4 +1,4 @@
-package com.rbkmoney.magista.dsl;
+package dev.vality.magista.dsl;
public interface QueryValidator {
void validateParameters(QueryParameters parameters) throws IllegalArgumentException;
diff --git a/src/main/java/com/rbkmoney/magista/dsl/RootQuery.java b/src/main/java/dev/vality/magista/dsl/RootQuery.java
similarity index 67%
rename from src/main/java/com/rbkmoney/magista/dsl/RootQuery.java
rename to src/main/java/dev/vality/magista/dsl/RootQuery.java
index 96da474..65f7d3c 100644
--- a/src/main/java/com/rbkmoney/magista/dsl/RootQuery.java
+++ b/src/main/java/dev/vality/magista/dsl/RootQuery.java
@@ -1,11 +1,11 @@
-package com.rbkmoney.magista.dsl;
+package dev.vality.magista.dsl;
-import com.rbkmoney.magista.dsl.builder.AbstractQueryBuilder;
-import com.rbkmoney.magista.dsl.builder.QueryBuilder;
-import com.rbkmoney.magista.dsl.builder.QueryBuilderException;
-import com.rbkmoney.magista.dsl.parser.AbstractQueryParser;
-import com.rbkmoney.magista.dsl.parser.QueryParserException;
-import com.rbkmoney.magista.dsl.parser.QueryPart;
+import dev.vality.magista.dsl.builder.AbstractQueryBuilder;
+import dev.vality.magista.dsl.builder.QueryBuilder;
+import dev.vality.magista.dsl.builder.QueryBuilderException;
+import dev.vality.magista.dsl.parser.AbstractQueryParser;
+import dev.vality.magista.dsl.parser.QueryParserException;
+import dev.vality.magista.dsl.parser.QueryPart;
import java.util.Collection;
import java.util.List;
@@ -14,8 +14,6 @@ import java.util.Optional;
import java.util.stream.Collectors;
import java.util.stream.Stream;
-import static com.rbkmoney.magista.dsl.Parameters.QUERY_PARAMETER;
-
public class RootQuery extends BaseQuery {
private final Query childQuery;
@@ -39,12 +37,12 @@ public class RootQuery extends BaseQuery {
}
public Map getQuery() {
- Object obj = getParameter(QUERY_PARAMETER, false);
+ Object obj = getParameter(Parameters.QUERY_PARAMETER, false);
return obj instanceof Map ? (Map) obj : null;
}
public QueryParameters getRestParameters() {
- return removeParameters(QueryParameters::new, QUERY_PARAMETER);
+ return removeParameters(QueryParameters::new, Parameters.QUERY_PARAMETER);
}
}
@@ -56,7 +54,7 @@ public class RootQuery extends BaseQuery {
super.validateParameters(parameters);
RootParameters rootParameters = super.checkParamsType(parameters, RootParameters.class);
if (rootParameters.getQuery() == null) {
- checkParamsResult(true, QUERY_PARAMETER, DEFAULT_ERR_MSG_STRING);
+ checkParamsResult(true, Parameters.QUERY_PARAMETER, DEFAULT_ERR_MSG_STRING);
}
}
@@ -65,14 +63,14 @@ public class RootQuery extends BaseQuery {
if (query instanceof RootQuery) {
Query childQuery = ((RootQuery) query).childQuery;
if (childQuery instanceof CompositeQuery) {
- Optional extends Collection> childQueries = Optional.ofNullable(((CompositeQuery) childQuery).getChildQueries());
- checkParamsResult(
- !childQueries.isPresent() || childQueries.get().isEmpty(),
- "Request must contain at least one query"
- );
+ Optional extends Collection> childQueries =
+ Optional.ofNullable(((CompositeQuery) childQuery).getChildQueries());
+ checkParamsResult(!childQueries.isPresent() || childQueries.get().isEmpty(),
+ "Request must contain at least one query");
}
} else if (query instanceof CompositeQuery) {
- checkParamsResult(true, "Request can't hold more than one query, received count: " + ((CompositeQuery) query).getChildQueries().size());
+ checkParamsResult(true, "Request can't hold more than one query, received count: " +
+ ((CompositeQuery) query).getChildQueries().size());
} else {
assert false : "No other types expected here";
}
@@ -80,15 +78,20 @@ public class RootQuery extends BaseQuery {
}
public static class RootParser extends AbstractQueryParser {
- private RootValidator validator = new RootValidator();
+ private final RootValidator validator = new RootValidator();
+
+ public static String getMainDescriptor() {
+ return Parameters.QUERY_PARAMETER;
+ }
@Override
public List parseQuery(Map source, QueryPart parent) throws QueryParserException {
RootParameters parameters = getValidatedParameters(source, parent, RootParameters::new, validator);
return Stream.of(
- new QueryPart(getMainDescriptor(), new QueryParameters(parameters.getQuery(), parameters), parent),
- new QueryPart(QueryPart.DEFAULT_DESCRIPTOR, parameters.getRestParameters(), parent))
+ new QueryPart(getMainDescriptor(),
+ new QueryParameters(parameters.getQuery(), parameters), parent),
+ new QueryPart(QueryPart.DEFAULT_DESCRIPTOR, parameters.getRestParameters(), parent))
.collect(Collectors.toList());
}
@@ -96,24 +99,23 @@ public class RootQuery extends BaseQuery {
public boolean apply(Map source, QueryPart parent) {
return parent == null;
}
-
- public static String getMainDescriptor() {
- return QUERY_PARAMETER;
- }
}
public static class RootBuilder extends AbstractQueryBuilder {
- private RootValidator validator = new RootValidator();
+ private final RootValidator validator = new RootValidator();
@Override
- public Query buildQuery(List queryParts, String continuationToken, QueryPart parentQueryPart, QueryBuilder baseBuilder) throws QueryBuilderException {
- Query resultQuery = buildSingleQuery(RootParser.getMainDescriptor(), queryParts, queryPart -> createQuery(queryPart, continuationToken, baseBuilder));
+ public Query buildQuery(List queryParts, String continuationToken, QueryPart parentQueryPart,
+ QueryBuilder baseBuilder) throws QueryBuilderException {
+ Query resultQuery = buildSingleQuery(RootParser.getMainDescriptor(), queryParts,
+ queryPart -> createQuery(queryPart, continuationToken, baseBuilder));
validator.validateQuery(resultQuery);
return resultQuery;
}
private RootQuery createQuery(QueryPart queryPart, String continuationToken, QueryBuilder baseBuilder) {
- Query childQuery = baseBuilder.buildQuery(queryPart.getChildren(), continuationToken, queryPart, baseBuilder);
+ Query childQuery =
+ baseBuilder.buildQuery(queryPart.getChildren(), continuationToken, queryPart, baseBuilder);
RootQuery rootQuery = new RootQuery(queryPart.getDescriptor(), queryPart.getParameters(), childQuery);
childQuery.setParentQuery(rootQuery);
return rootQuery;
diff --git a/src/main/java/com/rbkmoney/magista/dsl/TokenUtil.java b/src/main/java/dev/vality/magista/dsl/TokenUtil.java
similarity index 95%
rename from src/main/java/com/rbkmoney/magista/dsl/TokenUtil.java
rename to src/main/java/dev/vality/magista/dsl/TokenUtil.java
index 30b417d..d8cff6e 100644
--- a/src/main/java/com/rbkmoney/magista/dsl/TokenUtil.java
+++ b/src/main/java/dev/vality/magista/dsl/TokenUtil.java
@@ -1,4 +1,4 @@
-package com.rbkmoney.magista.dsl;
+package dev.vality.magista.dsl;
import java.util.Optional;
import java.util.UUID;
diff --git a/src/main/java/dev/vality/magista/dsl/builder/AbstractQueryBuilder.java b/src/main/java/dev/vality/magista/dsl/builder/AbstractQueryBuilder.java
new file mode 100644
index 0000000..e690758
--- /dev/null
+++ b/src/main/java/dev/vality/magista/dsl/builder/AbstractQueryBuilder.java
@@ -0,0 +1,82 @@
+package dev.vality.magista.dsl.builder;
+
+import dev.vality.magista.dsl.*;
+import dev.vality.magista.dsl.parser.QueryPart;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.function.BiFunction;
+import java.util.function.Function;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+public abstract class AbstractQueryBuilder implements QueryBuilder {
+
+ protected Stream getMatchedPartsStream(Object descriptor, List queryParts) {
+ return queryParts.stream().filter(queryPart -> descriptor.equals(queryPart.getDescriptor()));
+ }
+
+
+ protected CompositeQuery createCompositeQuery(Object descriptor, QueryParameters derivedParameters,
+ List childQueries,
+ Function> execFunction,
+ BiFunction,
+ QueryResult> parallelExecFunction) {
+ return BaseCompositeQuery.newInstance(descriptor,
+ new QueryParameters(Collections.emptyMap(), derivedParameters), childQueries, execFunction,
+ parallelExecFunction);
+ }
+
+ protected CompositeQuery createCompositeQuery(Object descriptor, QueryParameters derivedParameters,
+ List childQueries) {
+ return createCompositeQuery(descriptor, derivedParameters, childQueries,
+ context -> new BaseQueryResult<>(() -> childQueries.stream().map(query -> query.execute(context)),
+ () -> childQueries.stream().map(query -> query.execute(context)).collect(Collectors.toList())),
+ (context, queryResults) -> new BaseQueryResult<>(() -> queryResults.stream(), () -> queryResults)
+
+ );
+ }
+
+ protected CompositeQuery createCompositeQuery(Object descriptor, List childQueries,
+ Function> execFunction,
+ BiFunction,
+ QueryResult> parallelExecFunction) {
+ return createCompositeQuery(descriptor, new QueryParameters(Collections.emptyMap(), null),
+ childQueries, execFunction, parallelExecFunction);
+ }
+
+ protected QueryParameters getParameters(QueryPart queryPart) {
+ return queryPart == null ? null : queryPart.getParameters();
+ }
+
+ protected List buildQueries(Object matchDescriptor, List queryParts,
+ Function queryCreator) {
+ List matchedParts = getMatchedPartsStream(matchDescriptor, queryParts).collect(Collectors.toList());
+ return matchedParts.stream().map(queryPart -> queryCreator.apply(queryPart)).collect(Collectors.toList());
+ }
+
+ protected Query buildSingleQuery(Object matchDescriptor, List queryParts,
+ Function queryCreator) {
+ List queries = buildQueries(matchDescriptor, queryParts, queryCreator);
+ if (queries.size() == 0) {
+ throw new QueryBuilderException("No queries found in referred data");
+ } else if (queries.size() > 1) {
+ throw new QueryBuilderException("Only one query expected");
+ } else {
+ return queries.get(0);
+ }
+ }
+
+ protected Query buildAndWrapQueries(Object matchDescriptor, List queryParts,
+ Function queryCreator,
+ QueryParameters parentParameters,
+ Function> execFunction,
+ BiFunction,
+ QueryResult> parallelExecFunction) {
+ List queries = buildQueries(matchDescriptor, queryParts, queryCreator);
+ return createCompositeQuery(queries.get(0).getDescriptor(), parentParameters, queries, execFunction,
+ parallelExecFunction);
+ }
+}
diff --git a/src/main/java/com/rbkmoney/magista/dsl/builder/BaseQueryBuilder.java b/src/main/java/dev/vality/magista/dsl/builder/BaseQueryBuilder.java
similarity index 65%
rename from src/main/java/com/rbkmoney/magista/dsl/builder/BaseQueryBuilder.java
rename to src/main/java/dev/vality/magista/dsl/builder/BaseQueryBuilder.java
index 74cc44e..b531163 100644
--- a/src/main/java/com/rbkmoney/magista/dsl/builder/BaseQueryBuilder.java
+++ b/src/main/java/dev/vality/magista/dsl/builder/BaseQueryBuilder.java
@@ -1,8 +1,8 @@
-package com.rbkmoney.magista.dsl.builder;
+package dev.vality.magista.dsl.builder;
-import com.rbkmoney.magista.dsl.BadTokenException;
-import com.rbkmoney.magista.dsl.Query;
-import com.rbkmoney.magista.dsl.parser.QueryPart;
+import dev.vality.magista.dsl.BadTokenException;
+import dev.vality.magista.dsl.Query;
+import dev.vality.magista.dsl.parser.QueryPart;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -22,15 +22,13 @@ public abstract class BaseQueryBuilder implements QueryBuilder {
}
@Override
- public Query buildQuery(List queryParts, String continuationToken, QueryPart parentQueryPart, QueryBuilder baseBuilder) throws QueryBuilderException {
+ public Query buildQuery(List queryParts, String continuationToken, QueryPart parentQueryPart,
+ QueryBuilder baseBuilder) throws QueryBuilderException {
try {
- List queries = queryParts.isEmpty() ? Collections.emptyList() : builders.stream()
- .filter(
- builder -> builder.apply(queryParts, parentQueryPart))
- .map(
- builder -> builder.buildQuery(queryParts, continuationToken, parentQueryPart, baseBuilder == null ? this : baseBuilder)
- )
- .collect(Collectors.toList());
+ List queries = queryParts.isEmpty() ? Collections.emptyList() :
+ builders.stream().filter(builder -> builder.apply(queryParts, parentQueryPart))
+ .map(builder -> builder.buildQuery(queryParts, continuationToken, parentQueryPart,
+ baseBuilder == null ? this : baseBuilder)).collect(Collectors.toList());
if (queries.size() > 1) {
throw new QueryBuilderException("Build result has more than one query");
} else if (queries.size() == 1) {
diff --git a/src/main/java/dev/vality/magista/dsl/builder/QueryBuilder.java b/src/main/java/dev/vality/magista/dsl/builder/QueryBuilder.java
new file mode 100644
index 0000000..0fcacee
--- /dev/null
+++ b/src/main/java/dev/vality/magista/dsl/builder/QueryBuilder.java
@@ -0,0 +1,14 @@
+package dev.vality.magista.dsl.builder;
+
+import dev.vality.magista.dsl.Query;
+import dev.vality.magista.dsl.parser.QueryPart;
+
+import java.util.List;
+
+public interface QueryBuilder {
+
+ Query buildQuery(List queryParts, String continuationToken, QueryPart parentQueryPart,
+ QueryBuilder baseBuilder) throws QueryBuilderException;
+
+ boolean apply(List queryParts, QueryPart parent);
+}
diff --git a/src/main/java/com/rbkmoney/magista/dsl/builder/QueryBuilderException.java b/src/main/java/dev/vality/magista/dsl/builder/QueryBuilderException.java
similarity index 73%
rename from src/main/java/com/rbkmoney/magista/dsl/builder/QueryBuilderException.java
rename to src/main/java/dev/vality/magista/dsl/builder/QueryBuilderException.java
index 1cb921a..6fc3cd0 100644
--- a/src/main/java/com/rbkmoney/magista/dsl/builder/QueryBuilderException.java
+++ b/src/main/java/dev/vality/magista/dsl/builder/QueryBuilderException.java
@@ -1,6 +1,6 @@
-package com.rbkmoney.magista.dsl.builder;
+package dev.vality.magista.dsl.builder;
-import com.rbkmoney.magista.dsl.QueryProcessingException;
+import dev.vality.magista.dsl.QueryProcessingException;
public class QueryBuilderException extends QueryProcessingException {
public QueryBuilderException() {
@@ -18,7 +18,8 @@ public class QueryBuilderException extends QueryProcessingException {
super(cause);
}
- public QueryBuilderException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
+ public QueryBuilderException(String message, Throwable cause, boolean enableSuppression,
+ boolean writableStackTrace) {
super(message, cause, enableSuppression, writableStackTrace);
}
}
diff --git a/src/main/java/com/rbkmoney/magista/dsl/parser/AbstractQueryParser.java b/src/main/java/dev/vality/magista/dsl/parser/AbstractQueryParser.java
similarity index 59%
rename from src/main/java/com/rbkmoney/magista/dsl/parser/AbstractQueryParser.java
rename to src/main/java/dev/vality/magista/dsl/parser/AbstractQueryParser.java
index 70199be..380c75b 100644
--- a/src/main/java/com/rbkmoney/magista/dsl/parser/AbstractQueryParser.java
+++ b/src/main/java/dev/vality/magista/dsl/parser/AbstractQueryParser.java
@@ -1,7 +1,7 @@
-package com.rbkmoney.magista.dsl.parser;
+package dev.vality.magista.dsl.parser;
-import com.rbkmoney.magista.dsl.QueryParameters;
-import com.rbkmoney.magista.dsl.QueryValidator;
+import dev.vality.magista.dsl.QueryParameters;
+import dev.vality.magista.dsl.QueryValidator;
import java.util.Map;
@@ -11,7 +11,10 @@ public abstract class AbstractQueryParser implements QueryParser