Skip to content

Commit

Permalink
Merge branch 'release/2.0.0-RC2'
Browse files Browse the repository at this point in the history
  • Loading branch information
vegegoku committed Nov 6, 2024
2 parents 3a998ea + 62a78c7 commit c9019bd
Show file tree
Hide file tree
Showing 23 changed files with 930 additions and 24 deletions.
3 changes: 1 addition & 2 deletions domino-rest-client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>domino-rest</artifactId>
<groupId>org.dominokit</groupId>
<version>2.0.0-RC1</version>
<version>2.0.0-RC2</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down Expand Up @@ -84,7 +84,6 @@
<artifactId>jakarta.ws.rs-api</artifactId>
<version>${jax.rs.version}</version>
</dependency>

<dependency>
<groupId>org.dominokit</groupId>
<artifactId>domino-rest-jaxrs</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
import static java.util.Objects.nonNull;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.dominokit.jackson.JacksonContextProvider;
import org.dominokit.rest.js.DefaultServiceRoot;
import org.dominokit.rest.js.ServerEventFactory;
Expand Down Expand Up @@ -69,6 +71,10 @@ public class DominoRestConfig implements RestConfig {

private static NullQueryParamStrategy nullQueryParamStrategy = NullQueryParamStrategy.EMPTY;

private static final Map<String, String> globalPathParams = new HashMap<>();
private static final Map<String, String> globalHeaderParams = new HashMap<>();
private static final Map<String, List<String>> globalQueryParams = new HashMap<>();

/**
* Gets and initialize the instance with the default configurations
*
Expand Down Expand Up @@ -270,4 +276,78 @@ public UrlTokenRegexMatcher getUrlTokenRegexMatcher() {
return url;
};
}

@Override
public Map<String, String> getGlobalPathParameters() {
return globalPathParams;
}

@Override
public Map<String, String> getGlobalHeaderParameters() {
return globalHeaderParams;
}

@Override
public Map<String, List<String>> getGlobalQueryParameters() {
return globalQueryParams;
}

@Override
public RestConfig setGlobalPathParameter(String name, String value) {
getGlobalPathParameters().put(name, value);
return this;
}

@Override
public RestConfig setGlobalPathParameters(Map<String, String> pathParameters) {
getGlobalPathParameters().putAll(pathParameters);
return this;
}

@Override
public RestConfig setGlobalHeaderParameter(String name, String value) {
getGlobalHeaderParameters().put(name, value);
return this;
}

@Override
public RestConfig setGlobalHeaderParameters(Map<String, String> headerParameters) {
getGlobalHeaderParameters().putAll(headerParameters);
return this;
}

@Override
public RestConfig setGlobalQueryParameter(String name, String value) {
getGlobalQueryParameters().put(name, new ArrayList<>());
addGlobalQueryParameter(name, value);
return this;
}

@Override
public RestConfig addGlobalQueryParameter(String name, String value) {
if (getGlobalQueryParameters().containsKey(name)) {
getGlobalQueryParameters().get(name).add(value);
} else {
setGlobalQueryParameter(name, value);
}
return this;
}

@Override
public RestConfig setGlobalQueryParameters(Map<String, List<String>> parameters) {
parameters
.keySet()
.forEach(
name -> parameters.get(name).forEach(value -> addGlobalQueryParameter(name, value)));
return this;
}

@Override
public RestConfig addGlobalQueryParameters(Map<String, List<String>> parameters) {
parameters.forEach(
(key, values) -> {
values.forEach(value -> addGlobalQueryParameter(key, value));
});
return this;
}
}
2 changes: 1 addition & 1 deletion domino-rest-jaxrs/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.dominokit</groupId>
<artifactId>domino-rest</artifactId>
<version>2.0.0-RC1</version>
<version>2.0.0-RC2</version>
</parent>

<artifactId>domino-rest-jaxrs</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion domino-rest-jvm/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>domino-rest</artifactId>
<groupId>org.dominokit</groupId>
<version>2.0.0-RC1</version>
<version>2.0.0-RC2</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.regex.Matcher;
Expand Down Expand Up @@ -70,6 +72,10 @@ public class DominoRestConfig implements RestConfig {

private static NullQueryParamStrategy nullQueryParamStrategy = NullQueryParamStrategy.EMPTY;

private static final Map<String, String> globalPathParams = new HashMap<>();
private static final Map<String, String> globalHeaderParams = new HashMap<>();
private static final Map<String, List<String>> globalQueryParams = new HashMap<>();

/**
* Gets and initialize the instance with the default configurations
*
Expand Down Expand Up @@ -270,4 +276,78 @@ public UrlTokenRegexMatcher getUrlTokenRegexMatcher() {
return url;
};
}

@Override
public Map<String, String> getGlobalPathParameters() {
return globalPathParams;
}

@Override
public Map<String, String> getGlobalHeaderParameters() {
return globalHeaderParams;
}

@Override
public Map<String, List<String>> getGlobalQueryParameters() {
return globalQueryParams;
}

@Override
public RestConfig setGlobalPathParameter(String name, String value) {
getGlobalPathParameters().put(name, value);
return this;
}

@Override
public RestConfig setGlobalPathParameters(Map<String, String> pathParameters) {
getGlobalPathParameters().putAll(pathParameters);
return this;
}

@Override
public RestConfig setGlobalHeaderParameter(String name, String value) {
getGlobalHeaderParameters().put(name, value);
return this;
}

@Override
public RestConfig setGlobalHeaderParameters(Map<String, String> headerParameters) {
getGlobalHeaderParameters().putAll(headerParameters);
return this;
}

@Override
public RestConfig setGlobalQueryParameter(String name, String value) {
getGlobalQueryParameters().put(name, new ArrayList<>());
addGlobalQueryParameter(name, value);
return this;
}

@Override
public RestConfig addGlobalQueryParameter(String name, String value) {
if (getGlobalQueryParameters().containsKey(name)) {
getGlobalQueryParameters().get(name).add(value);
} else {
setGlobalQueryParameter(name, value);
}
return this;
}

@Override
public RestConfig setGlobalQueryParameters(Map<String, List<String>> parameters) {
parameters
.keySet()
.forEach(
name -> parameters.get(name).forEach(value -> addGlobalQueryParameter(name, value)));
return this;
}

@Override
public RestConfig addGlobalQueryParameters(Map<String, List<String>> parameters) {
parameters.forEach(
(key, values) -> {
values.forEach(value -> addGlobalQueryParameter(key, value));
});
return this;
}
}
2 changes: 1 addition & 1 deletion domino-rest-processor/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<artifactId>domino-rest</artifactId>
<groupId>org.dominokit</groupId>
<version>2.0.0-RC1</version>
<version>2.0.0-RC2</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import org.dominokit.jackson.processor.deserialization.FieldDeserializersChainBuilder;
import org.dominokit.jackson.processor.serialization.FieldSerializerChainBuilder;
import org.dominokit.rest.shared.MultipartForm;
import org.dominokit.rest.shared.Response;
import org.dominokit.rest.shared.request.*;
import org.dominokit.rest.shared.request.service.annotations.*;
import org.dominokit.rest.shared.request.service.annotations.Request;
Expand Down Expand Up @@ -668,6 +669,10 @@ private TypeMirror getMappingType(TypeMirror returnType) {
return elements.getTypeElement(Void.class.getCanonicalName()).asType();
}

if (processorUtil.isAssignableFrom(returnType, jakarta.ws.rs.core.Response.class)) {
return elements.getTypeElement(Response.class.getCanonicalName()).asType();
}

if (Type.isArray(returnType)) {
return returnType;
}
Expand Down Expand Up @@ -959,6 +964,12 @@ private Optional<CodeBlock> getResponseReader(ServiceMethod serviceMethod) {
"setResponseReader(response -> new $T().read(response))",
TypeName.get(readerType)));
return Optional.of(builder.build());
} else if (isGenericResponse(serviceMethod)) {

builder.addStatement(
"setResponseReader(response -> new $T().read(response))",
TypeName.get(GeneralResponseReader.class));
return Optional.of(builder.build());
} else if (producesJson(serviceMethod)) {

TypeMirror responseBeanType = getResponseBeanType(serviceMethod);
Expand Down Expand Up @@ -997,6 +1008,10 @@ private Optional<CodeBlock> getResponseReader(ServiceMethod serviceMethod) {
return Optional.empty();
}

private boolean isGenericResponse(ServiceMethod serviceMethod) {
return processorUtil.isAssignableFrom(getResponseBeanType(serviceMethod), Response.class);
}

private boolean producesJson(ServiceMethod serviceMethod) {
String acceptResponse = getAcceptResponse(serviceMethod);
return acceptResponse.contains(MediaType.APPLICATION_JSON)
Expand Down
8 changes: 2 additions & 6 deletions domino-rest-shared/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>domino-rest</artifactId>
<groupId>org.dominokit</groupId>
<version>2.0.0-RC1</version>
<version>2.0.0-RC2</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down Expand Up @@ -33,6 +33,7 @@
<groupId>org.dominokit</groupId>
<artifactId>domino-rest-jaxrs</artifactId>
<version>${project.version}</version>
<scope>provided</scope>
</dependency>

<dependency>
Expand All @@ -45,11 +46,6 @@
<artifactId>domino-aggregator-shared</artifactId>
<version>${domino.aggregator.version}</version>
</dependency>
<dependency>
<groupId>org.dominokit</groupId>
<artifactId>domino-history-shared</artifactId>
<version>${domino.history.version}</version>
</dependency>
<dependency>
<groupId>javax.annotation</groupId>
<artifactId>javax.annotation-api</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Copyright © 2019 Dominokit
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.dominokit.rest.shared.request;

import org.dominokit.rest.shared.Response;

/** Reads the response body as a {@link String} */
public class GeneralResponseReader implements ResponseReader<Response> {
@Override
public Response read(Response response) {
return response;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import java.util.Date;
import java.util.List;
import java.util.Map;
import org.dominokit.rest.shared.request.service.annotations.DateFormat;

/** The global configurations for domino rest. */
Expand Down Expand Up @@ -176,6 +177,28 @@ default NullQueryParamStrategy getNullQueryParamStrategy() {

UrlTokenRegexMatcher getUrlTokenRegexMatcher();

Map<String, String> getGlobalPathParameters();

Map<String, String> getGlobalHeaderParameters();

Map<String, List<String>> getGlobalQueryParameters();

RestConfig setGlobalPathParameter(String name, String value);

RestConfig setGlobalPathParameters(Map<String, String> pathParameters);

RestConfig setGlobalHeaderParameter(String name, String value);

RestConfig setGlobalHeaderParameters(Map<String, String> headerParameters);

RestConfig setGlobalQueryParameter(String name, String value);

RestConfig addGlobalQueryParameter(String name, String value);

RestConfig setGlobalQueryParameters(Map<String, List<String>> parameters);

RestConfig addGlobalQueryParameters(Map<String, List<String>> parameters);

/** Formatter to format the date parameter based on a patter */
@FunctionalInterface
interface DateParamFormatter {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,10 @@ public void normalizeUrl() {
(isNull(this.serviceRoot) || this.serviceRoot.isEmpty())
? ServiceRootMatcher.matchedServiceRoot(path)
: (this.serviceRoot + path);
UrlFormatter urlFormatter = new UrlFormatter(pathParameters);
Map<String, String> combinedParams = new HashMap<>();
combinedParams.putAll(DominoRestContext.make().getConfig().getGlobalPathParameters());
combinedParams.putAll(pathParameters);
UrlFormatter urlFormatter = new UrlFormatter(combinedParams);
this.setUrl(urlFormatter.formatUrl(root));
}
}
Expand Down
Loading

0 comments on commit c9019bd

Please sign in to comment.