Skip to content

Commit

Permalink
Merge branch 'main' into gen-sdk-updates
Browse files Browse the repository at this point in the history
  • Loading branch information
jenschude committed Jan 30, 2024
2 parents 542d32a + 3ec9f82 commit 6755f69
Show file tree
Hide file tree
Showing 32 changed files with 2,241 additions and 4 deletions.
1 change: 1 addition & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ a8ec45c8ea4ba559247b654d01b0d35b21a68865
430a1a0a5dd4efe78e21526c37bec9dbce036401



2 changes: 2 additions & 0 deletions .kodiak.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
version = 1
merge.show_missing_automerge_label_message = false
3 changes: 1 addition & 2 deletions Best-practices.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ The ApiRootBuilder can be used to configure it.
ApiRootBuilder.of().withErrorMiddleware();
```

barbara79 marked this conversation as resolved.
If the `defaultClient` builder method is used it will be configured. The builder also ensures that the ErrorMiddleware is always the last middleware in the call stack. The following examples shows custom configuration of the equivalent of the above method:

```java
Expand Down Expand Up @@ -168,7 +167,7 @@ ApiRootBuilder.of().addNotFoundExceptionMiddleware(request -> request.getUri().g

### How to reuse the Client
The client can be created once, it can be used by creating the **ApiRoot** object instance and reusing the object instance throughout the whole application.
barbara79 marked this conversation as resolved.

```java
ProjectApiRoot apiRoot = ApiRootBuilder.of()
.defaultClient(ClientCredentials.of()
Expand Down
3 changes: 3 additions & 0 deletions api-java-mixin.raml
Original file line number Diff line number Diff line change
Expand Up @@ -1602,6 +1602,9 @@ types:
(java-implements):
'ByProjectKeyProductProjectionsGetMixin'
/search:
get:
(java-implements):
'ByProjectKeyProductProjectionsSearchGetMixin'
post:
(java-implements): 'ByProjectKeyProductProjectionsSearchPostMixin'
/product-selections:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@
@Generated(value = "io.vrap.rmf.codegen.rendering.CoreCodeGenerator", comments = "https://github.com/commercetools/rmf-codegen")
public class ByProjectKeyProductProjectionsSearchGet extends
TypeApiMethod<ByProjectKeyProductProjectionsSearchGet, com.commercetools.api.models.product.ProductProjectionPagedSearchResponse>
implements com.commercetools.api.client.SortableTrait<ByProjectKeyProductProjectionsSearchGet>,
implements ByProjectKeyProductProjectionsSearchGetMixin,
com.commercetools.api.client.SortableTrait<ByProjectKeyProductProjectionsSearchGet>,
com.commercetools.api.client.PagingTrait<ByProjectKeyProductProjectionsSearchGet>,
com.commercetools.api.client.ProjectionselectingTrait<ByProjectKeyProductProjectionsSearchGet>,
com.commercetools.api.client.PriceselectingTrait<ByProjectKeyProductProjectionsSearchGet>,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@

package com.commercetools.api.client;

import java.util.function.Function;

import com.commercetools.api.search.products.FacetExpression;
import com.commercetools.api.search.products.FilterExpression;
import com.commercetools.api.search.products.ProductFacetExpressionBuilder;
import com.commercetools.api.search.products.ProductFilterExpressionBuilder;

public interface ByProjectKeyProductProjectionsSearchGetMixin {
public <TValue> ByProjectKeyProductProjectionsSearchGet addFilter(final TValue filter);

public <TValue> ByProjectKeyProductProjectionsSearchGet addFilterFacets(final TValue filterFacets);

public <TValue> ByProjectKeyProductProjectionsSearchGet addFilterQuery(final TValue filterQuery);

public <TValue> ByProjectKeyProductProjectionsSearchGet addFacet(final TValue facet);

default ProductFilterExpressionBuilder filterDsl() {
return new ProductFilterExpressionBuilder();
}

default ProductFacetExpressionBuilder facetDsl() {
return new ProductFacetExpressionBuilder();
}

default ByProjectKeyProductProjectionsSearchGet filter(
Function<ProductFilterExpressionBuilder, FilterExpression> fn) {
return addFilter(fn.apply(filterDsl()).render());
}

default ByProjectKeyProductProjectionsSearchGet filterFacets(
Function<ProductFilterExpressionBuilder, FilterExpression> fn) {
return addFilterFacets(fn.apply(filterDsl()).render());
}

default ByProjectKeyProductProjectionsSearchGet filterQuery(
Function<ProductFilterExpressionBuilder, FilterExpression> fn) {
return addFilterQuery(fn.apply(filterDsl()).render());
}

default ByProjectKeyProductProjectionsSearchGet facet(
Function<ProductFacetExpressionBuilder, FacetExpression<?>> fn) {
return addFacet(fn.apply(facetDsl()).render());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
import java.util.function.Supplier;
import java.util.stream.Collectors;

import com.commercetools.api.search.products.FacetExpression;
import com.commercetools.api.search.products.FilterExpression;
import com.commercetools.api.search.products.ProductFacetExpressionBuilder;
import com.commercetools.api.search.products.ProductFilterExpressionBuilder;

import io.vrap.rmf.base.client.ApiMethod;

public interface ByProjectKeyProductProjectionsSearchPostMixin {
Expand Down Expand Up @@ -1654,4 +1659,32 @@ public default <TValue> ByProjectKeyProductProjectionsSearchPost addText(final S
.map(s -> new ApiMethod.ParamEntry<>(placeholderName, s.toString()))
.collect(Collectors.toList()));
}

default ProductFilterExpressionBuilder filterDsl() {
return new ProductFilterExpressionBuilder();
}

default ProductFacetExpressionBuilder facetDsl() {
return new ProductFacetExpressionBuilder();
}

default ByProjectKeyProductProjectionsSearchPost filter(
Function<ProductFilterExpressionBuilder, FilterExpression> fn) {
return addFilter(fn.apply(filterDsl()).render());
}

default ByProjectKeyProductProjectionsSearchPost filterFacets(
Function<ProductFilterExpressionBuilder, FilterExpression> fn) {
return addFilterFacets(fn.apply(filterDsl()).render());
}

default ByProjectKeyProductProjectionsSearchPost filterQuery(
Function<ProductFilterExpressionBuilder, FilterExpression> fn) {
return addFilterQuery(fn.apply(filterDsl()).render());
}

default ByProjectKeyProductProjectionsSearchPost facet(
Function<ProductFacetExpressionBuilder, FacetExpression<?>> fn) {
return addFacet(fn.apply(facetDsl()).render());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,8 @@ public interface Identifiable<T> {
* @return ID
*/
String getId();

static <T> Identifiable<T> of(final String id) {
return new SimpleIdentifiable<>(id);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@

package com.commercetools.api.models;

public class SimpleIdentifiable<T> implements Identifiable<T> {

private final String id;

public SimpleIdentifiable(String id) {
this.id = id;
}

@Override
public String getId() {
return id;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import org.javamoney.moneta.spi.JDKCurrencyProvider;

final class CurrencyUtils {
public final class CurrencyUtils {
static final JDKCurrencyProvider CURRENCY_PROVIDER = new JDKCurrencyProvider();

public static CurrencyUnit ofCode(final String currencyCode) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@

package com.commercetools.api.search.products;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
import java.util.stream.StreamSupport;

import com.commercetools.api.models.Identifiable;
import com.commercetools.api.models.category.Category;

public class CategoryTermFacetExpression extends TermFacetExpression<String> {

public CategoryTermFacetExpression(PathExpression expression) {
super(expression, TermFormatter::format);
}

public CategoryTermFacetExpression(PathExpression expression, List<FilterExpression> term) {
super(expression, term, TermFormatter::format);
}

public CategoryTermFacetExpression is(String value) {
List<FilterExpression> terms = Optional.ofNullable(terms()).map(term -> {
List<FilterExpression> expressions = new ArrayList<>(terms());
expressions.add(formatter().apply(value));
return expressions;
}).orElse(Collections.singletonList(formatter().apply(value)));
return new CategoryTermFacetExpression(expression(), terms);
}

public CategoryTermFacetExpression is(Identifiable<Category> value) {
return is(value.getId());
}

public CategoryTermFacetExpression subTree(String value) {
List<FilterExpression> terms = Optional.ofNullable(terms()).map(term -> {
List<FilterExpression> expressions = new ArrayList<>(terms());
expressions.add(
ContainerExpression.of().parent(ConstantExpression.of("subTree")).inner(formatter().apply(value)));
return expressions;
})
.orElse(Collections.singletonList(
ContainerExpression.of().parent(ConstantExpression.of("subTree")).inner(formatter().apply(value))));
return new CategoryTermFacetExpression(expression(), terms);
}

public CategoryTermFacetExpression subTree(Identifiable<Category> value) {
return subTree(value.getId());
}

public CategoryTermFacetExpression isIn(Iterable<String> values) {
List<FilterExpression> terms = Optional.ofNullable(terms()).map(term -> {
List<FilterExpression> expressions = new ArrayList<>(terms());
values.forEach(v -> expressions.add(formatter().apply(v)));
return expressions;
}).orElse(StreamSupport.stream(values.spliterator(), false).map(formatter()).collect(Collectors.toList()));

return new CategoryTermFacetExpression(expression(), terms);
}

public CategoryTermFacetExpression containsAny(Iterable<Identifiable<Category>> values) {
return isIn(
StreamSupport.stream(values.spliterator(), false).map(Identifiable::getId).collect(Collectors.toList()));
}

public static CategoryTermFacetExpression of(PathExpression expression) {
return new CategoryTermFacetExpression(expression);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@

package com.commercetools.api.search.products;

import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.StreamSupport;

import com.commercetools.api.models.Identifiable;
import com.commercetools.api.models.category.Category;

public class CategoryTermFilterExpression extends TermFilterExpression<String> {

public CategoryTermFilterExpression(PathExpression expression) {
super(expression, TermFormatter::format);
}

public CategoryTermFilterExpression(PathExpression expression, List<FilterExpression> term) {
super(expression, term, TermFormatter::format);
}

public CategoryTermFilterExpression is(String value) {
List<FilterExpression> terms = Optional.ofNullable(terms()).map(term -> {
List<FilterExpression> expressions = new ArrayList<>(terms());
expressions.add(formatter().apply(value));
return expressions;
}).orElse(Collections.singletonList(formatter().apply(value)));
return new CategoryTermFilterExpression(expression(), terms);
}

public CategoryTermFilterExpression is(Identifiable<Category> value) {
return is(value.getId());
}

public CategoryTermFilterExpression subTree(String value) {
List<FilterExpression> terms = Optional.ofNullable(terms()).map(term -> {
List<FilterExpression> expressions = new ArrayList<>(terms());
expressions.add(
ContainerExpression.of().parent(ConstantExpression.of("subTree")).inner(formatter().apply(value)));
return expressions;
})
.orElse(Collections.singletonList(
ContainerExpression.of().parent(ConstantExpression.of("subTree")).inner(formatter().apply(value))));
return new CategoryTermFilterExpression(expression(), terms);
}

public CategoryTermFilterExpression subTree(Identifiable<Category> value) {
return subTree(value.getId());
}

public CategoryTermFilterExpression isIn(Iterable<String> values) {
List<FilterExpression> terms = Optional.ofNullable(terms()).map(term -> {
List<FilterExpression> expressions = new ArrayList<>(terms());
values.forEach(v -> expressions.add(formatter().apply(v)));
return expressions;
}).orElse(StreamSupport.stream(values.spliterator(), false).map(formatter()).collect(Collectors.toList()));

return new CategoryTermFilterExpression(expression(), terms);
}

public CategoryTermFilterExpression containsAny(Iterable<Identifiable<Category>> values) {
return isIn(
StreamSupport.stream(values.spliterator(), false).map(Identifiable::getId).collect(Collectors.toList()));
}

public static CategoryTermFilterExpression of(PathExpression expression) {
return new CategoryTermFilterExpression(expression);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@

package com.commercetools.api.search.products;

public class ConstantExpression implements FilterExpression {
private final String value;

public ConstantExpression(String value) {
this.value = value;
}

public String value() {
return value;
}

@Override
public String render() {
return value;
}

public static ConstantExpression of(String value) {
return new ConstantExpression(value);
}
}
Loading

0 comments on commit 6755f69

Please sign in to comment.