From 47e413f05f71591d2d2a4ca8ea9746fde82aa7e0 Mon Sep 17 00:00:00 2001 From: Norbert Pomaroli Date: Fri, 1 Mar 2024 14:17:31 +0100 Subject: [PATCH 1/2] Add option to not reset database between test cases --- LTS-CHANGELOG.adoc | 5 +++++ .../gentics/mesh/test/MeshTestSetting.java | 10 ++++++++++ .../mesh/search/AbstractMultiESTest.java | 5 +++++ .../mesh/test/context/MeshTestContext.java | 19 +++++++++++++++++++ 4 files changed, 39 insertions(+) diff --git a/LTS-CHANGELOG.adoc b/LTS-CHANGELOG.adoc index 4c04a0ec1d..41a0cb8ad1 100644 --- a/LTS-CHANGELOG.adoc +++ b/LTS-CHANGELOG.adoc @@ -17,6 +17,11 @@ include::content/docs/variables.adoc-include[] The LTS changelog lists releases which are only accessible via a commercial subscription. All fixes and changes in LTS releases will be released the next minor release. Changes from LTS 1.4.x will be included in release 1.5.0. +[[v1.10.29]] +== 1.10.29 (TBD) + +icon:check[] Tests: The tests API has been extended to allow tests which do not reset the database between test cases. + [[v1.10.28]] == 1.10.28 (27.02.2024) diff --git a/tests/context-api/src/main/java/com/gentics/mesh/test/MeshTestSetting.java b/tests/context-api/src/main/java/com/gentics/mesh/test/MeshTestSetting.java index 3eee183b1b..0e791f884e 100644 --- a/tests/context-api/src/main/java/com/gentics/mesh/test/MeshTestSetting.java +++ b/tests/context-api/src/main/java/com/gentics/mesh/test/MeshTestSetting.java @@ -94,5 +94,15 @@ */ MeshCoreOptionChanger optionChanger() default MeshCoreOptionChanger.NO_CHANGE; + /** + * Class of the option changer to user + * @return + */ Class customOptionChanger() default NoOptionChanger.class; + + /** + * Flag which indicates whether the database shall be reset between test runs (default is true) + * @return + */ + boolean resetBetweenTests() default true; } diff --git a/tests/tests-core/src/main/java/com/gentics/mesh/search/AbstractMultiESTest.java b/tests/tests-core/src/main/java/com/gentics/mesh/search/AbstractMultiESTest.java index 9464cfcacc..13a33d00d7 100644 --- a/tests/tests-core/src/main/java/com/gentics/mesh/search/AbstractMultiESTest.java +++ b/tests/tests-core/src/main/java/com/gentics/mesh/search/AbstractMultiESTest.java @@ -178,6 +178,11 @@ public MeshCoreOptionChanger optionChanger() { public Class customOptionChanger() { return delegate.customOptionChanger(); } + + @Override + public boolean resetBetweenTests() { + return delegate.resetBetweenTests(); + } } @Override diff --git a/tests/tests-core/src/main/java/com/gentics/mesh/test/context/MeshTestContext.java b/tests/tests-core/src/main/java/com/gentics/mesh/test/context/MeshTestContext.java index f8c2fc9863..f9c3b99e05 100644 --- a/tests/tests-core/src/main/java/com/gentics/mesh/test/context/MeshTestContext.java +++ b/tests/tests-core/src/main/java/com/gentics/mesh/test/context/MeshTestContext.java @@ -132,6 +132,8 @@ public class MeshTestContext implements TestRule { private MeshTestContextProvider meshTestContextProvider; + private boolean needsSetup = true; + public Statement apply(final Statement base, final Description description) { return new Statement() { @Override @@ -161,6 +163,10 @@ protected void starting(Description description) throws Throwable { } public void setup(MeshTestSetting settings) throws Exception { + if (!needsSetup) { + // database has already been setup, so omit this step + return; + } meshTestContextProvider.getInstanceProvider().initMeshData(settings, meshDagger); initFolders(mesh.getOptions()); listenToSearchIdleEvent(); @@ -266,6 +272,11 @@ protected void finished(Description description) { } public void tearDown(MeshTestSetting settings) throws Exception { + if (!settings.resetBetweenTests()) { + // the test does not require the database to be reset between test runs + needsSetup = false; + return; + } cleanupFolders(); if (settings.startServer()) { undeployAndReset(); @@ -888,4 +899,12 @@ public MeshOptions getOptions() { public MeshTestActions actions() { return getInstanceProvider().actions(); } + + /** + * Does the test need setup? This will be true whenever the database has been setup from scratch + * @return true if the test needs to be setup + */ + public boolean needsSetup() { + return needsSetup; + } } From 6ea1da42194ac3bfe15dbd6c7eba7e9c924e59f5 Mon Sep 17 00:00:00 2001 From: Norbert Pomaroli Date: Mon, 4 Mar 2024 16:40:59 +0100 Subject: [PATCH 2/2] Add default parameters to mesh rest client config --- LTS-CHANGELOG.adoc | 2 + .../context/impl/LocalActionContextImpl.java | 2 +- .../client/AbstractMeshRestHttpClient.java | 38 ++-- .../rest/client/MeshRestClientConfig.java | 20 ++ .../client/impl/MeshRestHttpClientImpl.java | 184 +++++++++--------- .../com/gentics/mesh/rest/RestClientTest.java | 36 +++- 6 files changed, 175 insertions(+), 107 deletions(-) diff --git a/LTS-CHANGELOG.adoc b/LTS-CHANGELOG.adoc index 41a0cb8ad1..4cf10c0e2e 100644 --- a/LTS-CHANGELOG.adoc +++ b/LTS-CHANGELOG.adoc @@ -20,6 +20,8 @@ All fixes and changes in LTS releases will be released the next minor release. C [[v1.10.29]] == 1.10.29 (TBD) +icon:check[] REST client: The configuration now allows adding default parameter provider for query parameters, that should be added to every request (unless overwritten). + icon:check[] Tests: The tests API has been extended to allow tests which do not reset the database between test cases. [[v1.10.28]] diff --git a/mdm/common/src/main/java/com/gentics/mesh/context/impl/LocalActionContextImpl.java b/mdm/common/src/main/java/com/gentics/mesh/context/impl/LocalActionContextImpl.java index 0129977d98..4ae1b7bf61 100644 --- a/mdm/common/src/main/java/com/gentics/mesh/context/impl/LocalActionContextImpl.java +++ b/mdm/common/src/main/java/com/gentics/mesh/context/impl/LocalActionContextImpl.java @@ -63,7 +63,7 @@ public class LocalActionContextImpl extends AbstractInternalActionContext imp public LocalActionContextImpl(BootstrapInitializer boot, MeshAuthUser user, Class classOfResponse, ParameterProvider... requestParameters) { this.boot = boot; - this.query = getQuery(requestParameters); + this.query = getQuery(null, requestParameters); this.user = user; this.classOfResponse = classOfResponse; data.put(SecurityLoggingHandler.SECURITY_LOGGER_CONTEXT_KEY, securityLogger); diff --git a/rest-client/src/main/java/com/gentics/mesh/rest/client/AbstractMeshRestHttpClient.java b/rest-client/src/main/java/com/gentics/mesh/rest/client/AbstractMeshRestHttpClient.java index 99ed43b654..e464760f02 100644 --- a/rest-client/src/main/java/com/gentics/mesh/rest/client/AbstractMeshRestHttpClient.java +++ b/rest-client/src/main/java/com/gentics/mesh/rest/client/AbstractMeshRestHttpClient.java @@ -1,6 +1,12 @@ package com.gentics.mesh.rest.client; import java.io.InputStream; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +import org.apache.commons.lang.StringUtils; import com.gentics.mesh.core.rest.common.GenericMessageResponse; import com.gentics.mesh.core.rest.common.RestModel; @@ -143,21 +149,31 @@ abstract public MeshRequest prepareRequest(HttpMethod method, String path /** * Return the query aggregated parameter string for the given providers. - * + * @param config configuration object (may be null) * @param parameters + * * @return */ - public static String getQuery(ParameterProvider... parameters) { - StringBuilder builder = new StringBuilder(); - for (int i = 0; i < parameters.length; i++) { - ParameterProvider provider = parameters[i]; - builder.append(provider.getQueryParameters()); - if (i != parameters.length - 1) { - builder.append("&"); - } + public static String getQuery(MeshRestClientConfig config, ParameterProvider... parameters) { + Map params = new LinkedHashMap<>(); + if (config != null) { + // get the default parameters from the configuration (if any) + ParameterProvider[] defaultParameters = config.getDefaultParameters(); + // put all non-blank parameters to the map + Stream.of(defaultParameters).flatMap(provider -> provider.getParameters().entrySet().stream()) + .filter(entry -> StringUtils.isNotBlank(entry.getKey()) && StringUtils.isNotBlank(entry.getValue())) + .forEach(entry -> params.put(entry.getKey(), entry.getValue())); } - if (builder.length() > 0) { - return "?" + builder.toString(); + + // put all non-blank parameters from the given providers to the map + Stream.of(parameters).flatMap(provider -> provider.getParameters().entrySet().stream()) + .filter(entry -> StringUtils.isNotBlank(entry.getKey()) && StringUtils.isNotBlank(entry.getValue())) + .forEach(entry -> params.put(entry.getKey(), entry.getValue())); + + // combine all parameters to a query string + String query = params.entrySet().stream().map(entry -> String.format("%s=%s", entry.getKey(), entry.getValue())).collect(Collectors.joining("&")); + if (query.length() > 0) { + return "?" + query; } else { return ""; } diff --git a/rest-client/src/main/java/com/gentics/mesh/rest/client/MeshRestClientConfig.java b/rest-client/src/main/java/com/gentics/mesh/rest/client/MeshRestClientConfig.java index b1d3e5d655..ce4a2259b7 100644 --- a/rest-client/src/main/java/com/gentics/mesh/rest/client/MeshRestClientConfig.java +++ b/rest-client/src/main/java/com/gentics/mesh/rest/client/MeshRestClientConfig.java @@ -10,6 +10,8 @@ import org.apache.commons.io.IOUtils; +import com.gentics.mesh.parameter.ParameterProvider; + /** * Gentics Mesh REST client configuration. */ @@ -27,6 +29,7 @@ public class MeshRestClientConfig { private final boolean hostnameVerification; private final int maxRetries; private final int retryDelayMs; + private final ParameterProvider[] defaultParameters; public MeshRestClientConfig(Builder builder) { this.host = Objects.requireNonNull(builder.host); @@ -41,6 +44,7 @@ public MeshRestClientConfig(Builder builder) { this.clientKey = builder.clientKey; this.maxRetries = builder.maxRetries; this.retryDelayMs = builder.retryDelayMs; + this.defaultParameters = builder.defaultParameters; } /** @@ -106,6 +110,10 @@ public int getRetryDelayMs() { return retryDelayMs; } + public ParameterProvider[] getDefaultParameters() { + return defaultParameters; + } + /** * Create a fresh config builder. * @@ -135,6 +143,8 @@ public static class Builder { // max call timeout. private int retryDelayMs = -1; + private ParameterProvider[] defaultParameters = new ParameterProvider[0]; + public Builder() { trustedCAs = new HashSet<>(); } @@ -401,6 +411,16 @@ public Builder setRetryDelayMs(int retryDelayMs) { return this; } + /** + * Set default parameters, which should be added to every request (unless overwritten) + * @param defaultParameters default parameters + * @return fluent API + */ + public Builder setDefaultParameters(ParameterProvider... defaultParameters) { + this.defaultParameters = defaultParameters; + return this; + } + private static byte[] readFile(String path) { Objects.requireNonNull(path); File keyFile = new File(path); diff --git a/rest-client/src/main/java/com/gentics/mesh/rest/client/impl/MeshRestHttpClientImpl.java b/rest-client/src/main/java/com/gentics/mesh/rest/client/impl/MeshRestHttpClientImpl.java index f855d5394d..3892dc3332 100644 --- a/rest-client/src/main/java/com/gentics/mesh/rest/client/impl/MeshRestHttpClientImpl.java +++ b/rest-client/src/main/java/com/gentics/mesh/rest/client/impl/MeshRestHttpClientImpl.java @@ -138,7 +138,7 @@ public MeshRestClient disableAnonymousAccess() { @Override public MeshRequest findNodeByUuid(String projectName, String uuid, ParameterProvider... parameters) { Objects.requireNonNull(projectName, "projectName must not be null"); - return prepareRequest(GET, "/" + encodeSegment(projectName) + "/nodes/" + uuid + getQuery(parameters), NodeResponse.class); + return prepareRequest(GET, "/" + encodeSegment(projectName) + "/nodes/" + uuid + getQuery(getConfig(), parameters), NodeResponse.class); } @Override @@ -146,7 +146,7 @@ public MeshRequest upsertNode(String projectName, String uuid, Nod ParameterProvider... parameters) { Objects.requireNonNull(projectName, "projectName must not be null"); Objects.requireNonNull(nodeUpsertRequest, "nodeUpsertRequest must not be null"); - return prepareRequest(POST, "/" + encodeSegment(projectName) + "/nodes/" + uuid + getQuery(parameters), NodeResponse.class, + return prepareRequest(POST, "/" + encodeSegment(projectName) + "/nodes/" + uuid + getQuery(getConfig(), parameters), NodeResponse.class, nodeUpsertRequest); } @@ -154,7 +154,7 @@ public MeshRequest upsertNode(String projectName, String uuid, Nod public MeshRequest createNode(String projectName, NodeCreateRequest nodeCreateRequest, ParameterProvider... parameters) { Objects.requireNonNull(projectName, "projectName must not be null"); Objects.requireNonNull(nodeCreateRequest, "nodeCreateRequest must not be null"); - return prepareRequest(POST, "/" + encodeSegment(projectName) + "/nodes" + getQuery(parameters), NodeResponse.class, nodeCreateRequest); + return prepareRequest(POST, "/" + encodeSegment(projectName) + "/nodes" + getQuery(getConfig(), parameters), NodeResponse.class, nodeCreateRequest); } @Override @@ -163,7 +163,7 @@ public MeshRequest createNode(String uuid, String projectName, Nod Objects.requireNonNull(uuid, "uuid must not be null"); Objects.requireNonNull(projectName, "projectName must not be null"); Objects.requireNonNull(nodeCreateRequest, "nodeCreateRequest must not be null"); - return prepareRequest(POST, "/" + encodeSegment(projectName) + "/nodes/" + uuid + getQuery(parameters), NodeResponse.class, + return prepareRequest(POST, "/" + encodeSegment(projectName) + "/nodes/" + uuid + getQuery(getConfig(), parameters), NodeResponse.class, nodeCreateRequest); } @@ -172,7 +172,7 @@ public MeshRequest updateNode(String projectName, String uuid, Nod ParameterProvider... parameters) { Objects.requireNonNull(projectName, "projectName must not be null"); Objects.requireNonNull(nodeUpdateRequest, "nodeUpdateRequest must not be null"); - return prepareRequest(POST, "/" + encodeSegment(projectName) + "/nodes/" + uuid + getQuery(parameters), NodeResponse.class, + return prepareRequest(POST, "/" + encodeSegment(projectName) + "/nodes/" + uuid + getQuery(getConfig(), parameters), NodeResponse.class, nodeUpdateRequest); } @@ -180,7 +180,7 @@ public MeshRequest updateNode(String projectName, String uuid, Nod public MeshRequest deleteNode(String projectName, String uuid, ParameterProvider... parameters) { Objects.requireNonNull(projectName, "projectName must not be null"); Objects.requireNonNull(uuid, "uuid must not be null"); - return prepareRequest(DELETE, "/" + encodeSegment(projectName) + "/nodes/" + uuid + getQuery(parameters), EmptyResponse.class); + return prepareRequest(DELETE, "/" + encodeSegment(projectName) + "/nodes/" + uuid + getQuery(getConfig(), parameters), EmptyResponse.class); } @Override @@ -188,7 +188,7 @@ public MeshRequest deleteNode(String projectName, String uuid, St Objects.requireNonNull(projectName, "projectName must not be null"); Objects.requireNonNull(uuid, "uuid must not be null"); Objects.requireNonNull(languageTag, "languageTag must not be null"); - return prepareRequest(DELETE, "/" + encodeSegment(projectName) + "/nodes/" + uuid + "/languages/" + languageTag + getQuery(parameters), + return prepareRequest(DELETE, "/" + encodeSegment(projectName) + "/nodes/" + uuid + "/languages/" + languageTag + getQuery(getConfig(), parameters), EmptyResponse.class); } @@ -197,21 +197,21 @@ public MeshRequest moveNode(String projectName, String nodeUuid, Objects.requireNonNull(projectName, "projectName must not be null"); Objects.requireNonNull(nodeUuid, "nodeUuid must not be null"); Objects.requireNonNull(targetFolderUuid, "targetFolderUuid must not be null"); - return prepareRequest(POST, "/" + encodeSegment(projectName) + "/nodes/" + nodeUuid + "/moveTo/" + targetFolderUuid + getQuery(parameters), + return prepareRequest(POST, "/" + encodeSegment(projectName) + "/nodes/" + nodeUuid + "/moveTo/" + targetFolderUuid + getQuery(getConfig(), parameters), EmptyResponse.class); } @Override public MeshRequest findNodes(String projectName, ParameterProvider... parameters) { Objects.requireNonNull(projectName, "projectName must not be null"); - return prepareRequest(GET, "/" + encodeSegment(projectName) + "/nodes" + getQuery(parameters), NodeListResponse.class); + return prepareRequest(GET, "/" + encodeSegment(projectName) + "/nodes" + getQuery(getConfig(), parameters), NodeListResponse.class); } @Override public MeshRequest listNodeVersions(String projectName, String nodeUuid, ParameterProvider... parameters) { Objects.requireNonNull(projectName, "projectName must not be null"); Objects.requireNonNull(nodeUuid, "nodeUuid must not be null"); - return prepareRequest(GET, "/" + encodeSegment(projectName) + "/nodes/" + nodeUuid + "/versions" + getQuery(parameters), + return prepareRequest(GET, "/" + encodeSegment(projectName) + "/nodes/" + nodeUuid + "/versions" + getQuery(getConfig(), parameters), NodeVersionsResponse.class); } @@ -219,7 +219,7 @@ public MeshRequest listNodeVersions(String projectName, St public MeshRequest findTags(String projectName, String tagFamilyUuid, ParameterProvider... parameters) { Objects.requireNonNull(projectName, "projectName must not be null"); Objects.requireNonNull(tagFamilyUuid, "tagFamilyUuid must not be null"); - return prepareRequest(GET, "/" + encodeSegment(projectName) + "/tagFamilies/" + tagFamilyUuid + "/tags" + getQuery(parameters), + return prepareRequest(GET, "/" + encodeSegment(projectName) + "/tagFamilies/" + tagFamilyUuid + "/tags" + getQuery(getConfig(), parameters), TagListResponse.class); } @@ -227,7 +227,7 @@ public MeshRequest findTags(String projectName, String tagFamil public MeshRequest findTagsForNode(String projectName, String nodeUuid, ParameterProvider... parameters) { Objects.requireNonNull(projectName, "projectName must not be null"); Objects.requireNonNull(nodeUuid, "nodeUuid must not be null"); - return prepareRequest(GET, "/" + encodeSegment(projectName) + "/nodes/" + nodeUuid + "/tags" + getQuery(parameters), TagListResponse.class); + return prepareRequest(GET, "/" + encodeSegment(projectName) + "/nodes/" + nodeUuid + "/tags" + getQuery(getConfig(), parameters), TagListResponse.class); } @Override @@ -235,7 +235,7 @@ public MeshRequest updateTagsForNode(String projectName, String ParameterProvider... parameters) { Objects.requireNonNull(projectName, "projectName must not be null"); Objects.requireNonNull(nodeUuid, "nodeUuid must not be null"); - return prepareRequest(POST, "/" + encodeSegment(projectName) + "/nodes/" + nodeUuid + "/tags" + getQuery(parameters), TagListResponse.class, + return prepareRequest(POST, "/" + encodeSegment(projectName) + "/nodes/" + nodeUuid + "/tags" + getQuery(getConfig(), parameters), TagListResponse.class, request); } @@ -243,7 +243,7 @@ public MeshRequest updateTagsForNode(String projectName, String public MeshRequest findNodeChildren(String projectName, String parentNodeUuid, ParameterProvider... parameters) { Objects.requireNonNull(projectName, "projectName must not be null"); Objects.requireNonNull(parentNodeUuid, "parentNodeUuid must not be null"); - return prepareRequest(GET, "/" + encodeSegment(projectName) + "/nodes/" + parentNodeUuid + "/children" + getQuery(parameters), + return prepareRequest(GET, "/" + encodeSegment(projectName) + "/nodes/" + parentNodeUuid + "/children" + getQuery(getConfig(), parameters), NodeListResponse.class); } @@ -251,7 +251,7 @@ public MeshRequest findNodeChildren(String projectName, String public MeshRequest loadNavigation(String projectName, String uuid, ParameterProvider... parameters) { Objects.requireNonNull(projectName, "projectName must not be null"); Objects.requireNonNull(uuid, "uuid must not be null"); - return prepareRequest(GET, "/" + encodeSegment(projectName) + "/nodes/" + uuid + "/navigation" + getQuery(parameters), + return prepareRequest(GET, "/" + encodeSegment(projectName) + "/nodes/" + uuid + "/navigation" + getQuery(getConfig(), parameters), NavigationResponse.class); } @@ -268,7 +268,7 @@ public MeshRequest createTag(String projectName, String tagFamilyUu public MeshRequest findTagByUuid(String projectName, String tagFamilyUuid, String uuid, ParameterProvider... parameters) { Objects.requireNonNull(projectName, "projectName must not be null"); Objects.requireNonNull(uuid, "uuid must not be null"); - return prepareRequest(GET, "/" + encodeSegment(projectName) + "/tagFamilies/" + tagFamilyUuid + "/tags/" + uuid + getQuery(parameters), + return prepareRequest(GET, "/" + encodeSegment(projectName) + "/tagFamilies/" + tagFamilyUuid + "/tags/" + uuid + getQuery(getConfig(), parameters), TagResponse.class); } @@ -298,7 +298,7 @@ public MeshRequest deleteTag(String projectName, String tagFamily @Override public MeshRequest findTagFamilies(String projectName, ParameterProvider... parameters) { Objects.requireNonNull(projectName, "projectName must not be null"); - return prepareRequest(GET, "/" + encodeSegment(projectName) + "/tagFamilies" + getQuery(parameters), TagFamilyListResponse.class); + return prepareRequest(GET, "/" + encodeSegment(projectName) + "/tagFamilies" + getQuery(getConfig(), parameters), TagFamilyListResponse.class); } // // TODO can we actually do this? @@ -315,24 +315,24 @@ public MeshRequest findNodesForTag(String projectName, String Objects.requireNonNull(tagFamilyUuid, "tagFamilyUuid must not be null"); Objects.requireNonNull(tagUuid, "tagUuid must not be null"); return prepareRequest(GET, "/" + encodeSegment(projectName) + "/tagFamilies/" + tagFamilyUuid + "/tags/" + tagUuid + "/nodes" + getQuery( - parameters), NodeListResponse.class); + getConfig(), parameters), NodeListResponse.class); } @Override public MeshRequest findProjectByUuid(String uuid, ParameterProvider... parameters) { Objects.requireNonNull(uuid, "uuid must not be null"); - return prepareRequest(GET, "/projects/" + uuid + getQuery(parameters), ProjectResponse.class); + return prepareRequest(GET, "/projects/" + uuid + getQuery(getConfig(), parameters), ProjectResponse.class); } @Override public MeshRequest findProjectByName(String name, ParameterProvider... parameters) { Objects.requireNonNull(name, "name must not be null"); - return prepareRequest(GET, "/" + encodeSegment(name) + getQuery(parameters), ProjectResponse.class); + return prepareRequest(GET, "/" + encodeSegment(name) + getQuery(getConfig(), parameters), ProjectResponse.class); } @Override public MeshRequest findProjects(ParameterProvider... parameters) { - return prepareRequest(GET, "/projects" + getQuery(parameters), ProjectListResponse.class); + return prepareRequest(GET, "/projects" + getQuery(getConfig(), parameters), ProjectListResponse.class); } @Override @@ -378,7 +378,7 @@ public MeshRequest deleteProject(String uuid) { @Override public MeshRequest purgeProject(String uuid, ParameterProvider... parameters) { Objects.requireNonNull(uuid, "uuid must not be null"); - return prepareRequest(POST, "/projects/" + uuid + "/maintenance/purge" + getQuery(parameters), GenericMessageResponse.class); + return prepareRequest(POST, "/projects/" + uuid + "/maintenance/purge" + getQuery(getConfig(), parameters), GenericMessageResponse.class); } @Override @@ -398,7 +398,7 @@ public MeshRequest unassignSchemaFromProject(String projectName, @Override public MeshRequest findSchemas(String projectName, ParameterProvider... parameters) { Objects.requireNonNull(projectName, "projectName must not be null"); - return prepareRequest(GET, "/" + encodeSegment(projectName) + "/schemas" + getQuery(parameters), SchemaListResponse.class); + return prepareRequest(GET, "/" + encodeSegment(projectName) + "/schemas" + getQuery(getConfig(), parameters), SchemaListResponse.class); } @Override @@ -418,18 +418,18 @@ public MeshRequest unassignMicroschemaFromProject(String projectN @Override public MeshRequest findMicroschemas(String projectName, ParameterProvider... parameters) { Objects.requireNonNull(projectName, "projectName must not be null"); - return prepareRequest(GET, "/" + encodeSegment(projectName) + "/microschemas" + getQuery(parameters), MicroschemaListResponse.class); + return prepareRequest(GET, "/" + encodeSegment(projectName) + "/microschemas" + getQuery(getConfig(), parameters), MicroschemaListResponse.class); } @Override public MeshRequest findTagFamilyByUuid(String projectName, String uuid, ParameterProvider... parameters) { - return prepareRequest(GET, "/" + encodeSegment(projectName) + "/tagFamilies/" + uuid + getQuery(parameters), TagFamilyResponse.class); + return prepareRequest(GET, "/" + encodeSegment(projectName) + "/tagFamilies/" + uuid + getQuery(getConfig(), parameters), TagFamilyResponse.class); } @Override public MeshRequest findTagFamilies(String projectName, PagingParameters pagingInfo) { Objects.requireNonNull(projectName, "projectName must not be null"); - return prepareRequest(GET, "/" + encodeSegment(projectName) + "/tagFamilies" + getQuery(pagingInfo), TagFamilyListResponse.class); + return prepareRequest(GET, "/" + encodeSegment(projectName) + "/tagFamilies" + getQuery(getConfig(), pagingInfo), TagFamilyListResponse.class); } @Override @@ -467,12 +467,12 @@ public MeshRequest createTagFamily(String projectName, String @Override public MeshRequest findGroupByUuid(String uuid, ParameterProvider... parameters) { Objects.requireNonNull(uuid, "uuid must not be null"); - return prepareRequest(GET, "/groups/" + uuid + getQuery(parameters), GroupResponse.class); + return prepareRequest(GET, "/groups/" + uuid + getQuery(getConfig(), parameters), GroupResponse.class); } @Override public MeshRequest findGroups(ParameterProvider... parameters) { - return prepareRequest(GET, "/groups" + getQuery(parameters), GroupListResponse.class); + return prepareRequest(GET, "/groups" + getQuery(getConfig(), parameters), GroupListResponse.class); } @Override @@ -504,32 +504,32 @@ public MeshRequest deleteGroup(String uuid) { @Override public MeshRequest findUserByUuid(String uuid, ParameterProvider... parameters) { Objects.requireNonNull(uuid, "uuid must not be null"); - return prepareRequest(GET, "/users/" + uuid + getQuery(parameters), UserResponse.class); + return prepareRequest(GET, "/users/" + uuid + getQuery(getConfig(), parameters), UserResponse.class); } @Override public MeshRequest findUsers(ParameterProvider... parameters) { - return prepareRequest(GET, "/users" + getQuery(parameters), UserListResponse.class); + return prepareRequest(GET, "/users" + getQuery(getConfig(), parameters), UserListResponse.class); } @Override public MeshRequest createUser(UserCreateRequest userCreateRequest, ParameterProvider... parameters) { Objects.requireNonNull(userCreateRequest, "userCreateRequest must not be null"); - return prepareRequest(POST, "/users" + getQuery(parameters), UserResponse.class, userCreateRequest); + return prepareRequest(POST, "/users" + getQuery(getConfig(), parameters), UserResponse.class, userCreateRequest); } @Override public MeshRequest createUser(String uuid, UserCreateRequest userCreateRequest, ParameterProvider... parameters) { Objects.requireNonNull(uuid, "uuid must not be null"); Objects.requireNonNull(userCreateRequest, "userCreateRequest must not be null"); - return prepareRequest(POST, "/users/" + uuid + getQuery(parameters), UserResponse.class, userCreateRequest); + return prepareRequest(POST, "/users/" + uuid + getQuery(getConfig(), parameters), UserResponse.class, userCreateRequest); } @Override public MeshRequest updateUser(String uuid, UserUpdateRequest userUpdateRequest, ParameterProvider... parameters) { Objects.requireNonNull(uuid, "uuid must not be null"); Objects.requireNonNull(userUpdateRequest, "userUpdateRequest must not be null"); - return prepareRequest(POST, "/users/" + uuid + getQuery(parameters), UserResponse.class, userUpdateRequest); + return prepareRequest(POST, "/users/" + uuid + getQuery(getConfig(), parameters), UserResponse.class, userUpdateRequest); } @Override @@ -565,12 +565,12 @@ public MeshRequest readUserPermissions(String uuid, Stri @Override public MeshRequest findRoleByUuid(String uuid, ParameterProvider... parameters) { - return prepareRequest(GET, "/roles/" + uuid + getQuery(parameters), RoleResponse.class); + return prepareRequest(GET, "/roles/" + uuid + getQuery(getConfig(), parameters), RoleResponse.class); } @Override public MeshRequest findRoles(ParameterProvider... parameters) { - return prepareRequest(GET, "/roles" + getQuery(parameters), RoleListResponse.class); + return prepareRequest(GET, "/roles" + getQuery(getConfig(), parameters), RoleListResponse.class); } @Override @@ -590,7 +590,7 @@ public MeshRequest deleteRole(String uuid) { @Override public MeshRequest me(ParameterProvider... parameters) { - return prepareRequest(GET, "/auth/me" + getQuery(parameters), UserResponse.class); + return prepareRequest(GET, "/auth/me" + getQuery(getConfig(), parameters), UserResponse.class); } @Override @@ -598,7 +598,7 @@ public MeshRequest addTagToNode(String projectName, String nodeUui Objects.requireNonNull(projectName, "projectName must not be null"); Objects.requireNonNull(nodeUuid, "nodeUuid must not be null"); Objects.requireNonNull(tagUuid, "tagUuid must not be null"); - return prepareRequest(POST, "/" + encodeSegment(projectName) + "/nodes/" + nodeUuid + "/tags/" + tagUuid + getQuery(parameters), + return prepareRequest(POST, "/" + encodeSegment(projectName) + "/nodes/" + nodeUuid + "/tags/" + tagUuid + getQuery(getConfig(), parameters), NodeResponse.class); } @@ -607,7 +607,7 @@ public MeshRequest removeTagFromNode(String projectName, String n Objects.requireNonNull(projectName, "projectName must not be null"); Objects.requireNonNull(nodeUuid, "nodeUuid must not be null"); Objects.requireNonNull(tagUuid, "tagUuid must not be null"); - return prepareRequest(DELETE, "/" + encodeSegment(projectName) + "/nodes/" + nodeUuid + "/tags/" + tagUuid + getQuery(parameters), + return prepareRequest(DELETE, "/" + encodeSegment(projectName) + "/nodes/" + nodeUuid + "/tags/" + tagUuid + getQuery(getConfig(), parameters), EmptyResponse.class); } @@ -615,7 +615,7 @@ public MeshRequest removeTagFromNode(String projectName, String n public MeshRequest getNodePublishStatus(String projectName, String nodeUuid, ParameterProvider... parameters) { Objects.requireNonNull(projectName, "projectName must not be null"); Objects.requireNonNull(nodeUuid, "nodeUuid must not be null"); - return prepareRequest(GET, "/" + encodeSegment(projectName) + "/nodes/" + nodeUuid + "/published" + getQuery(parameters), + return prepareRequest(GET, "/" + encodeSegment(projectName) + "/nodes/" + nodeUuid + "/published" + getQuery(getConfig(), parameters), PublishStatusResponse.class); } @@ -623,7 +623,7 @@ public MeshRequest getNodePublishStatus(String projectNam public MeshRequest publishNode(String projectName, String nodeUuid, ParameterProvider... parameters) { Objects.requireNonNull(projectName, "projectName must not be null"); Objects.requireNonNull(nodeUuid, "nodeUuid must not be null"); - return prepareRequest(POST, "/" + encodeSegment(projectName) + "/nodes/" + nodeUuid + "/published" + getQuery(parameters), + return prepareRequest(POST, "/" + encodeSegment(projectName) + "/nodes/" + nodeUuid + "/published" + getQuery(getConfig(), parameters), PublishStatusResponse.class); } @@ -631,7 +631,7 @@ public MeshRequest publishNode(String projectName, String public MeshRequest takeNodeOffline(String projectName, String nodeUuid, ParameterProvider... parameters) { Objects.requireNonNull(projectName, "projectName must not be null"); Objects.requireNonNull(nodeUuid, "nodeUuid must not be null"); - return prepareRequest(DELETE, "/" + encodeSegment(projectName) + "/nodes/" + nodeUuid + "/published" + getQuery(parameters), + return prepareRequest(DELETE, "/" + encodeSegment(projectName) + "/nodes/" + nodeUuid + "/published" + getQuery(getConfig(), parameters), EmptyResponse.class); } @@ -642,7 +642,7 @@ public MeshRequest getNodeLanguagePublishStatus(String proje Objects.requireNonNull(nodeUuid, "nodeUuid must not be null"); Objects.requireNonNull(languageTag, "languageTag must not be null"); return prepareRequest(GET, "/" + encodeSegment(projectName) + "/nodes/" + nodeUuid + "/languages/" + languageTag + "/published" + getQuery( - parameters), PublishStatusModel.class); + getConfig(), parameters), PublishStatusModel.class); } @Override @@ -652,7 +652,7 @@ public MeshRequest publishNodeLanguage(String projectName, S Objects.requireNonNull(nodeUuid, "nodeUuid must not be null"); Objects.requireNonNull(languageTag, "languageTag must not be null"); return prepareRequest(POST, "/" + encodeSegment(projectName) + "/nodes/" + nodeUuid + "/languages/" + languageTag + "/published" + getQuery( - parameters), PublishStatusModel.class); + getConfig(), parameters), PublishStatusModel.class); } @Override @@ -662,13 +662,13 @@ public MeshRequest takeNodeLanguageOffline(String projectName, St Objects.requireNonNull(nodeUuid, "nodeUuid must not be null"); Objects.requireNonNull(languageTag, "languageTag must not be null"); return prepareRequest(DELETE, "/" + encodeSegment(projectName) + "/nodes/" + nodeUuid + "/languages/" + languageTag + "/published" - + getQuery(parameters), EmptyResponse.class); + + getQuery(getConfig(), parameters), EmptyResponse.class); } @Override public MeshRequest findUsersOfGroup(String groupUuid, ParameterProvider... parameters) { Objects.requireNonNull(groupUuid, "groupUuid must not be null"); - return prepareRequest(GET, "/groups/" + groupUuid + "/users" + getQuery(parameters), UserListResponse.class); + return prepareRequest(GET, "/groups/" + groupUuid + "/users" + getQuery(getConfig(), parameters), UserListResponse.class); } @Override @@ -686,7 +686,7 @@ public MeshRequest removeUserFromGroup(String groupUuid, String u @Override public MeshRequest findRolesForGroup(String groupUuid, ParameterProvider... parameters) { Objects.requireNonNull(groupUuid, "groupUuid must not be null"); - return prepareRequest(GET, "/groups/" + groupUuid + "/roles" + getQuery(parameters), RoleListResponse.class); + return prepareRequest(GET, "/groups/" + groupUuid + "/roles" + getQuery(getConfig(), parameters), RoleListResponse.class); } @Override @@ -703,12 +703,12 @@ public MeshRequest removeRoleFromGroup(String groupUuid, String r @Override public MeshRequest createSchema(SchemaCreateRequest request, ParameterProvider... parameters) { - return prepareRequest(POST, "/schemas" + getQuery(parameters), SchemaResponse.class, request); + return prepareRequest(POST, "/schemas" + getQuery(getConfig(), parameters), SchemaResponse.class, request); } @Override public MeshRequest createSchema(String uuid, SchemaCreateRequest request, ParameterProvider... parameters) { - return prepareRequest(POST, "/schemas/" + uuid + getQuery(parameters), SchemaResponse.class, request); + return prepareRequest(POST, "/schemas/" + uuid + getQuery(getConfig(), parameters), SchemaResponse.class, request); } @Override @@ -719,13 +719,13 @@ public MeshRequest updateRole(String uuid, RoleUpdateRequest restR @Override public MeshRequest findSchemaByUuid(String uuid, ParameterProvider... parameters) { Objects.requireNonNull(uuid, "uuid must not be null"); - return prepareRequest(GET, "/schemas/" + uuid + getQuery(parameters), SchemaResponse.class); + return prepareRequest(GET, "/schemas/" + uuid + getQuery(getConfig(), parameters), SchemaResponse.class); } @Override public MeshRequest updateSchema(String uuid, SchemaUpdateRequest request, ParameterProvider... parameters) { Objects.requireNonNull(uuid, "uuid must not be null"); - return prepareRequest(POST, "/schemas/" + uuid + getQuery(parameters), GenericMessageResponse.class, request); + return prepareRequest(POST, "/schemas/" + uuid + getQuery(getConfig(), parameters), GenericMessageResponse.class, request); } @Override @@ -772,7 +772,7 @@ public MeshRequest webroot(String projectName, String[] pat .map(URIUtils::encodeSegment) .collect(Collectors.joining("/", "/", "")); - return prepareRequest(GET, "/" + encodeSegment(projectName) + "/webroot" + path + getQuery(parameters), MeshWebrootResponse.class); + return prepareRequest(GET, "/" + encodeSegment(projectName) + "/webroot" + path + getQuery(getConfig(), parameters), MeshWebrootResponse.class); } @Override @@ -798,7 +798,7 @@ public MeshRequest webrootUpdate(String projectName, String[] path .map(URIUtils::encodeSegment) .collect(Collectors.joining("/", "/", "")); - String requestUri = "/" + encodeSegment(projectName) + "/webroot" + path + getQuery(parameters); + String requestUri = "/" + encodeSegment(projectName) + "/webroot" + path + getQuery(getConfig(), parameters); return prepareRequest(POST, requestUri, NodeResponse.class, nodeUpdateRequest); } @@ -825,7 +825,7 @@ public MeshRequest webrootCreate(String projectName, String[] path .map(URIUtils::encodeSegment) .collect(Collectors.joining("/", "/", "")); - String requestUri = "/" + encodeSegment(projectName) + "/webroot" + path + getQuery(parameters); + String requestUri = "/" + encodeSegment(projectName) + "/webroot" + path + getQuery(getConfig(), parameters); return prepareRequest(POST, requestUri, NodeResponse.class, nodeCreateRequest); } @@ -836,7 +836,7 @@ public MeshRequest navroot(String projectName, String path, if (!path.startsWith("/")) { throw new RuntimeException("The path {" + path + "} must start with a slash"); } - String requestUri = "/" + encodeSegment(projectName) + "/navroot" + path + getQuery(parameters); + String requestUri = "/" + encodeSegment(projectName) + "/navroot" + path + getQuery(getConfig(), parameters); return prepareRequest(GET, requestUri, NavigationResponse.class); } @@ -848,39 +848,39 @@ public MeshRequest deleteSchema(String uuid) { @Override public MeshRequest findSchemas(ParameterProvider... parameters) { - return prepareRequest(GET, "/schemas" + getQuery(parameters), SchemaListResponse.class); + return prepareRequest(GET, "/schemas" + getQuery(getConfig(), parameters), SchemaListResponse.class); } @Override public MeshRequest searchNodes(String json, ParameterProvider... parameters) { Objects.requireNonNull(json, "json must not be null"); - return handleRequest(POST, "/search/nodes" + getQuery(parameters), NodeListResponse.class, json); + return handleRequest(POST, "/search/nodes" + getQuery(getConfig(), parameters), NodeListResponse.class, json); } @Override public MeshRequest searchNodesRaw(String json, ParameterProvider... parameters) { Objects.requireNonNull(json, "json must not be null"); - return handleRequest(POST, "/rawSearch/nodes" + getQuery(parameters), ObjectNode.class, json); + return handleRequest(POST, "/rawSearch/nodes" + getQuery(getConfig(), parameters), ObjectNode.class, json); } @Override public MeshRequest searchNodes(String projectName, String json, ParameterProvider... parameters) { Objects.requireNonNull(projectName, "projectName must not be null"); Objects.requireNonNull(json, "json must not be null"); - return handleRequest(POST, "/" + encodeSegment(projectName) + "/search/nodes" + getQuery(parameters), NodeListResponse.class, json); + return handleRequest(POST, "/" + encodeSegment(projectName) + "/search/nodes" + getQuery(getConfig(), parameters), NodeListResponse.class, json); } @Override public MeshRequest searchNodesRaw(String projectName, String json, ParameterProvider... parameters) { Objects.requireNonNull(projectName, "projectName must not be null"); Objects.requireNonNull(json, "json must not be null"); - return handleRequest(POST, "/" + encodeSegment(projectName) + "/rawSearch/nodes" + getQuery(parameters), ObjectNode.class, json); + return handleRequest(POST, "/" + encodeSegment(projectName) + "/rawSearch/nodes" + getQuery(getConfig(), parameters), ObjectNode.class, json); } @Override public MeshRequest searchUsers(String json, ParameterProvider... parameters) { Objects.requireNonNull(json, "json must not be null"); - return handleRequest(POST, "/search/users" + getQuery(parameters), UserListResponse.class, json); + return handleRequest(POST, "/search/users" + getQuery(getConfig(), parameters), UserListResponse.class, json); } @Override @@ -892,7 +892,7 @@ public MeshRequest searchUsersRaw(String json) { @Override public MeshRequest searchGroups(String json, ParameterProvider... parameters) { Objects.requireNonNull(json, "json must not be null"); - return handleRequest(POST, "/search/groups" + getQuery(parameters), GroupListResponse.class, json); + return handleRequest(POST, "/search/groups" + getQuery(getConfig(), parameters), GroupListResponse.class, json); } @Override @@ -904,7 +904,7 @@ public MeshRequest searchGroupsRaw(String json) { @Override public MeshRequest searchRoles(String json, ParameterProvider... parameters) { Objects.requireNonNull(json, "json must not be null"); - return handleRequest(POST, "/search/roles" + getQuery(parameters), RoleListResponse.class, json); + return handleRequest(POST, "/search/roles" + getQuery(getConfig(), parameters), RoleListResponse.class, json); } @Override @@ -916,7 +916,7 @@ public MeshRequest searchRolesRaw(String json) { @Override public MeshRequest searchMicroschemas(String json, ParameterProvider... parameters) { Objects.requireNonNull(json, "json must not be null"); - return handleRequest(POST, "/search/microschemas" + getQuery(parameters), MicroschemaListResponse.class, json); + return handleRequest(POST, "/search/microschemas" + getQuery(getConfig(), parameters), MicroschemaListResponse.class, json); } @Override @@ -928,7 +928,7 @@ public MeshRequest searchMicroschemasRaw(String json) { @Override public MeshRequest searchProjects(String json, ParameterProvider... parameters) { Objects.requireNonNull(json, "json must not be null"); - return handleRequest(POST, "/search/projects" + getQuery(parameters), ProjectListResponse.class, json); + return handleRequest(POST, "/search/projects" + getQuery(getConfig(), parameters), ProjectListResponse.class, json); } @Override @@ -940,7 +940,7 @@ public MeshRequest searchProjectsRaw(String json) { @Override public MeshRequest searchTags(String json, ParameterProvider... parameters) { Objects.requireNonNull(json, "json must not be null"); - return handleRequest(POST, "/search/tags" + getQuery(parameters), TagListResponse.class, json); + return handleRequest(POST, "/search/tags" + getQuery(getConfig(), parameters), TagListResponse.class, json); } @Override @@ -953,7 +953,7 @@ public MeshRequest searchTagsRaw(String json) { public MeshRequest searchTags(String projectName, String json, ParameterProvider... parameters) { Objects.requireNonNull(projectName, "projectName must not be null"); Objects.requireNonNull(json, "json must not be null"); - return handleRequest(POST, "/" + encodeSegment(projectName) + "/search/tags" + getQuery(parameters), TagListResponse.class, json); + return handleRequest(POST, "/" + encodeSegment(projectName) + "/search/tags" + getQuery(getConfig(), parameters), TagListResponse.class, json); } @Override @@ -966,7 +966,7 @@ public MeshRequest searchTagsRaw(String projectName, String json) { @Override public MeshRequest searchSchemas(String json, ParameterProvider... parameters) { Objects.requireNonNull(json, "json must not be null"); - return handleRequest(POST, "/search/schemas" + getQuery(parameters), SchemaListResponse.class, json); + return handleRequest(POST, "/search/schemas" + getQuery(getConfig(), parameters), SchemaListResponse.class, json); } @Override @@ -978,7 +978,7 @@ public MeshRequest searchSchemasRaw(String json) { @Override public MeshRequest searchTagFamilies(String json, ParameterProvider... parameters) { Objects.requireNonNull(json, "json must not be null"); - return handleRequest(POST, "/search/tagFamilies" + getQuery(parameters), TagFamilyListResponse.class, json); + return handleRequest(POST, "/search/tagFamilies" + getQuery(getConfig(), parameters), TagFamilyListResponse.class, json); } @Override @@ -991,7 +991,7 @@ public MeshRequest searchTagFamiliesRaw(String json) { public MeshRequest searchTagFamilies(String projectName, String json, ParameterProvider... parameters) { Objects.requireNonNull(projectName, "projectName must not be null"); Objects.requireNonNull(json, "json must not be null"); - return handleRequest(POST, "/" + encodeSegment(projectName) + "/search/tagFamilies" + getQuery(parameters), TagFamilyListResponse.class, + return handleRequest(POST, "/" + encodeSegment(projectName) + "/search/tagFamilies" + getQuery(getConfig(), parameters), TagFamilyListResponse.class, json); } @@ -1004,12 +1004,12 @@ public MeshRequest searchTagFamiliesRaw(String projectName, String j @Override public MeshRequest invokeIndexClear(ParameterProvider... parameters) { - return prepareRequest(POST, "/search/clear" + getQuery(parameters), GenericMessageResponse.class); + return prepareRequest(POST, "/search/clear" + getQuery(getConfig(), parameters), GenericMessageResponse.class); } @Override public MeshRequest invokeIndexSync(ParameterProvider... parameters) { - return prepareRequest(POST, "/search/sync" + getQuery(parameters), GenericMessageResponse.class); + return prepareRequest(POST, "/search/sync" + getQuery(getConfig(), parameters), GenericMessageResponse.class); } @Override @@ -1024,7 +1024,7 @@ public MeshRequest invokeBackup() { @Override public MeshRequest invokeBackup(BackupParameters parameters) { - return prepareRequest(POST, "/admin/graphdb/backup" + getQuery(parameters), GenericMessageResponse.class); + return prepareRequest(POST, "/admin/graphdb/backup" + getQuery(getConfig(), parameters), GenericMessageResponse.class); } @Override @@ -1044,12 +1044,12 @@ public MeshRequest invokeRestore() { @Override public MeshRequest checkConsistency(ParameterProvider... parameters) { - return prepareRequest(GET, "/admin/consistency/check" + getQuery(parameters), ConsistencyCheckResponse.class); + return prepareRequest(GET, "/admin/consistency/check" + getQuery(getConfig(), parameters), ConsistencyCheckResponse.class); } @Override public MeshRequest repairConsistency(ParameterProvider... parameters) { - return prepareRequest(POST, "/admin/consistency/repair" + getQuery(parameters), ConsistencyCheckResponse.class); + return prepareRequest(POST, "/admin/consistency/repair" + getQuery(getConfig(), parameters), ConsistencyCheckResponse.class); } @Override @@ -1128,7 +1128,7 @@ public MeshRequest updateNodeBinaryField(String projectName, Strin suffix)); SequenceInputStream completeStream = new SequenceInputStream(streams.elements()); - return prepareRequest(POST, "/" + encodeSegment(projectName) + "/nodes/" + nodeUuid + "/binary/" + fieldKey + getQuery(parameters), + return prepareRequest(POST, "/" + encodeSegment(projectName) + "/nodes/" + nodeUuid + "/binary/" + fieldKey + getQuery(getConfig(), parameters), NodeResponse.class, completeStream, fileSize, bodyContentType); } @@ -1137,7 +1137,7 @@ public MeshRequest updateNodeS3BinaryField(String projectName, S Objects.requireNonNull(projectName, "projectName must not be null"); Objects.requireNonNull(nodeUuid, "nodeUuid must not be null"); - return prepareRequest(POST, "/" + encodeSegment(projectName) + "/nodes/" + nodeUuid + "/s3binary/" + fieldKey + getQuery(parameters), + return prepareRequest(POST, "/" + encodeSegment(projectName) + "/nodes/" + nodeUuid + "/s3binary/" + fieldKey + getQuery(getConfig(), parameters), S3RestResponse.class, request); } @@ -1146,7 +1146,7 @@ public MeshRequest extractMetadataNodeS3BinaryField(String project Objects.requireNonNull(projectName, "projectName must not be null"); Objects.requireNonNull(nodeUuid, "nodeUuid must not be null"); - return prepareRequest(POST, "/" + encodeSegment(projectName) + "/nodes/" + nodeUuid + "/s3binary/" + fieldKey + "/parseMetadata" + getQuery(parameters), + return prepareRequest(POST, "/" + encodeSegment(projectName) + "/nodes/" + nodeUuid + "/s3binary/" + fieldKey + "/parseMetadata" + getQuery(getConfig(), parameters), NodeResponse.class, request); } @@ -1156,7 +1156,7 @@ public MeshRequest downloadBinaryField(String projectName, S Objects.requireNonNull(projectName, "projectName must not be null"); Objects.requireNonNull(nodeUuid, "nodeUuid must not be null"); - String path = "/" + encodeSegment(projectName) + "/nodes/" + nodeUuid + "/binary/" + fieldKey + getQuery(parameters); + String path = "/" + encodeSegment(projectName) + "/nodes/" + nodeUuid + "/binary/" + fieldKey + getQuery(getConfig(), parameters); return prepareRequest(GET, path, MeshBinaryResponse.class); } @@ -1172,7 +1172,7 @@ public MeshRequest downloadBinaryField(String projectName, S throw new InvalidParameterException(String.format("Parameter to must be equal or greater then from. Given values: %d-%d", from, to)); } - String path = "/" + encodeSegment(projectName) + "/nodes/" + nodeUuid + "/binary/" + fieldKey + getQuery(parameters); + String path = "/" + encodeSegment(projectName) + "/nodes/" + nodeUuid + "/binary/" + fieldKey + getQuery(getConfig(), parameters); MeshRequest request = prepareRequest(GET, path, MeshBinaryResponse.class); request.setHeader("Range", String.format("bytes=%d-%d", from, to)); @@ -1231,18 +1231,18 @@ public MeshRequest createMicroschema(String uuid, Microsche @Override public MeshRequest findMicroschemaByUuid(String uuid, ParameterProvider... parameters) { Objects.requireNonNull(uuid, "uuid must not be null"); - return prepareRequest(GET, "/microschemas/" + uuid + getQuery(parameters), MicroschemaResponse.class); + return prepareRequest(GET, "/microschemas/" + uuid + getQuery(getConfig(), parameters), MicroschemaResponse.class); } @Override public MeshRequest findMicroschemas(ParameterProvider... parameters) { - return prepareRequest(GET, "/microschemas" + getQuery(parameters), MicroschemaListResponse.class); + return prepareRequest(GET, "/microschemas" + getQuery(getConfig(), parameters), MicroschemaListResponse.class); } @Override public MeshRequest updateMicroschema(String uuid, MicroschemaUpdateRequest request, ParameterProvider... parameters) { Objects.requireNonNull(uuid, "uuid must not be null"); - return prepareRequest(POST, "/microschemas/" + uuid + getQuery(parameters), GenericMessageResponse.class, request); + return prepareRequest(POST, "/microschemas/" + uuid + getQuery(getConfig(), parameters), GenericMessageResponse.class, request); } @Override @@ -1266,7 +1266,7 @@ public MeshRequest applyChangesToMicroschema(String uuid @Override public MeshRequest resolveLinks(String body, ParameterProvider... parameters) { Objects.requireNonNull(body, "body must not be null"); - return handleTextRequest(POST, "/utilities/linkResolver" + getQuery(parameters), String.class, body); + return handleTextRequest(POST, "/utilities/linkResolver" + getQuery(getConfig(), parameters), String.class, body); } @Override @@ -1275,7 +1275,7 @@ public MeshRequest createBranch(String projectName, BranchCreate Objects.requireNonNull(projectName, "projectName must not be null"); Objects.requireNonNull(branchCreateRequest, "branchCreateRequest must not be null"); - return prepareRequest(POST, "/" + encodeSegment(projectName) + "/branches" + getQuery(parameters), BranchResponse.class, + return prepareRequest(POST, "/" + encodeSegment(projectName) + "/branches" + getQuery(getConfig(), parameters), BranchResponse.class, branchCreateRequest); } @@ -1286,7 +1286,7 @@ public MeshRequest createBranch(String projectName, String uuid, Objects.requireNonNull(uuid, "uuid must not be null"); Objects.requireNonNull(branchCreateRequest, "branchesCreateRequest must not be null"); - return prepareRequest(POST, "/" + encodeSegment(projectName) + "/branches/" + uuid + getQuery(parameters), BranchResponse.class, + return prepareRequest(POST, "/" + encodeSegment(projectName) + "/branches/" + uuid + getQuery(getConfig(), parameters), BranchResponse.class, branchCreateRequest); } @@ -1295,14 +1295,14 @@ public MeshRequest findBranchByUuid(String projectName, String b Objects.requireNonNull(projectName, "projectName must not be null"); Objects.requireNonNull(branchUuid, "branchUuid must not be null"); - return prepareRequest(GET, "/" + encodeSegment(projectName) + "/branches/" + branchUuid + getQuery(parameters), BranchResponse.class); + return prepareRequest(GET, "/" + encodeSegment(projectName) + "/branches/" + branchUuid + getQuery(getConfig(), parameters), BranchResponse.class); } @Override public MeshRequest findBranches(String projectName, ParameterProvider... parameters) { Objects.requireNonNull(projectName, "projectName must not be null"); - return prepareRequest(GET, "/" + encodeSegment(projectName) + "/branches" + getQuery(parameters), BranchListResponse.class); + return prepareRequest(GET, "/" + encodeSegment(projectName) + "/branches" + getQuery(getConfig(), parameters), BranchListResponse.class); } @Override @@ -1429,7 +1429,7 @@ public MeshRequest removeTagFromBranch(String projectName, String public MeshRequest findTagsForBranch(String projectName, String branchUuid, ParameterProvider... parameters) { Objects.requireNonNull(projectName, "projectName must not be null"); Objects.requireNonNull(branchUuid, "branchUuid must not be null"); - return prepareRequest(GET, "/" + encodeSegment(projectName) + "/branches/" + branchUuid + "/tags" + getQuery(parameters), + return prepareRequest(GET, "/" + encodeSegment(projectName) + "/branches/" + branchUuid + "/tags" + getQuery(getConfig(), parameters), TagListResponse.class); } @@ -1447,13 +1447,13 @@ public MeshRequest graphql(String projectName, GraphQLRequest r Objects.requireNonNull(request, "request must not be null"); Objects.requireNonNull(request.getQuery(), "query within the request must not be null"); - String path = "/" + encodeSegment(projectName) + "/graphql" + getQuery(parameters); + String path = "/" + encodeSegment(projectName) + "/graphql" + getQuery(getConfig(), parameters); return prepareRequest(POST, path, GraphQLResponse.class, request); } @Override public MeshRequest findJobs(ParameterProvider... parameters) { - return prepareRequest(GET, "/admin/jobs" + getQuery(parameters), JobListResponse.class); + return prepareRequest(GET, "/admin/jobs" + getQuery(getConfig(), parameters), JobListResponse.class); } @Override @@ -1499,7 +1499,7 @@ public MeshRequest undeployPlugin(String id) { @Override public MeshRequest findPlugins(ParameterProvider... parameters) { - return prepareRequest(GET, "/admin/plugins" + getQuery(parameters), PluginListResponse.class); + return prepareRequest(GET, "/admin/plugins" + getQuery(getConfig(), parameters), PluginListResponse.class); } @Override @@ -1670,7 +1670,7 @@ public MeshRequest webrootField(String projectName, St .map(URIUtils::encodeSegment) .collect(Collectors.joining("/", "/", "")); - return prepareRequest(GET, "/" + encodeSegment(projectName) + "/webrootfield/" + fieldName + path + getQuery(parameters), MeshWebrootFieldResponse.class); + return prepareRequest(GET, "/" + encodeSegment(projectName) + "/webrootfield/" + fieldName + path + getQuery(getConfig(), parameters), MeshWebrootFieldResponse.class); } @Override diff --git a/tests/tests-rest-client/src/main/java/com/gentics/mesh/rest/RestClientTest.java b/tests/tests-rest-client/src/main/java/com/gentics/mesh/rest/RestClientTest.java index 37ee33d7f8..741e181a2e 100644 --- a/tests/tests-rest-client/src/main/java/com/gentics/mesh/rest/RestClientTest.java +++ b/tests/tests-rest-client/src/main/java/com/gentics/mesh/rest/RestClientTest.java @@ -5,6 +5,7 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; +import java.util.Map; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; @@ -13,8 +14,10 @@ import org.junit.Test; import com.gentics.mesh.parameter.NodeParameters; +import com.gentics.mesh.parameter.client.GenericParametersImpl; import com.gentics.mesh.rest.client.AbstractMeshRestHttpClient; import com.gentics.mesh.rest.client.MeshRestClient; +import com.gentics.mesh.rest.client.MeshRestClientConfig; public class RestClientTest { @@ -30,7 +33,8 @@ public void testParameterHandling() { when(parameters1.getLanguages()).thenReturn(new String[] { "en" }); assertThat(parameters1.getLanguages()).contains("en"); when(parameters1.getQueryParameters()).thenReturn("lang=en"); - assertEquals("?lang=en", AbstractMeshRestHttpClient.getQuery(parameters1)); + when(parameters1.getParameters()).thenReturn(Map.of("lang", "en")); + assertEquals("?lang=en", AbstractMeshRestHttpClient.getQuery(null, parameters1)); NodeParameters parameters2 = mock(NodeParameters.class); @@ -38,9 +42,10 @@ public void testParameterHandling() { assertThat(parameters2.getExpandedFieldNames()).contains("test"); when(parameters2.getQueryParameters()).thenReturn("expand=test"); - assertEquals("?lang=en&expand=test", AbstractMeshRestHttpClient.getQuery(parameters1, parameters2)); + when(parameters2.getParameters()).thenReturn(Map.of("expand", "test")); + assertEquals("?lang=en&expand=test", AbstractMeshRestHttpClient.getQuery(null, parameters1, parameters2)); - assertEquals("", AbstractMeshRestHttpClient.getQuery()); + assertEquals("", AbstractMeshRestHttpClient.getQuery(null)); } /** @@ -90,4 +95,29 @@ public void testHandlingConnectError() throws InterruptedException { assertThat(caught.get()).as("Caught exception").isNotNull().hasMessageStartingWith( "I/O Error in GET http://localhost:4711/api/v1/ : ConnectException"); } + + /** + * Test that default parameters in the config are handled correctly + */ + @Test + public void testDefaultParameter() { + // generate a minimal config with setting etag=false per default + MeshRestClientConfig config = MeshRestClientConfig + .newConfig() + .setHost("localhost") + .setDefaultParameters(new GenericParametersImpl().setETag(false)) + .build(); + + // get query without additional parameters + assertThat(AbstractMeshRestHttpClient.getQuery(config)).as("Query").isEqualTo("?etag=false"); + + // get query with additional other parameter + assertThat(AbstractMeshRestHttpClient.getQuery(config, new GenericParametersImpl().setFields("uuid"))).as("Query").isEqualTo("?etag=false&fields=uuid"); + + // get query with overridden default parameter + assertThat(AbstractMeshRestHttpClient.getQuery(config, new GenericParametersImpl().setETag(true))).as("Query").isEqualTo("?etag=true"); + + // get query with overridden default parameter + assertThat(AbstractMeshRestHttpClient.getQuery(config, new GenericParametersImpl().setETag(true).setFields("fields,perms"))).as("Query").isEqualTo("?etag=true&fields=fields,perms"); + } }