Skip to content

Commit

Permalink
updated to sdk version 17.5
Browse files Browse the repository at this point in the history
  • Loading branch information
nagesh-dixit committed Jan 29, 2024
1 parent b84ee86 commit 2f05389
Show file tree
Hide file tree
Showing 29 changed files with 405 additions and 411 deletions.
7 changes: 3 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ plugins {

ext {
versions = [
commercetools: "14.5.0",
slf4j: "1.7.36",
logback: "1.2.10",
commercetools: "17.5.0",
slf4j: "2.0.11",
logback: "1.4.14",
]
}

Expand All @@ -46,7 +46,6 @@ dependencies {
implementation "com.commercetools.sdk:commercetools-sdk-java-api:${versions.commercetools}"
implementation "com.commercetools.sdk:commercetools-graphql-api:${versions.commercetools}"
implementation "com.commercetools.sdk:commercetools-sdk-java-importapi:${versions.commercetools}"
implementation "com.commercetools.sdk:commercetools-sdk-java-ml:${versions.commercetools}"
implementation "org.slf4j:slf4j-api:${versions.slf4j}"
implementation "ch.qos.logback:logback-classic:${versions.logback}"

Expand Down
3 changes: 2 additions & 1 deletion src/main/java/handson/Task02a_CREATE.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ public static void main(String[] args) throws IOException, ExecutionException, I
*/
final String apiClientPrefix = ApiPrefixHelper.API_DEV_CLIENT_PREFIX.getPrefix();

Logger logger = LoggerFactory.getLogger(Task02a_CREATE.class.getName());
Logger logger = LoggerFactory.getLogger("commercetools");

final ProjectApiRoot client = createApiClient(apiClientPrefix);
CustomerService customerService = new CustomerService(client);

Expand Down
3 changes: 2 additions & 1 deletion src/main/java/handson/Task02b_UPDATE_Group.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ public static void main(String[] args) throws IOException, ExecutionException, I

final String apiClientPrefix = ApiPrefixHelper.API_DEV_CLIENT_PREFIX.getPrefix();

Logger logger = LoggerFactory.getLogger(Task02b_UPDATE_Group.class.getName());
Logger logger = LoggerFactory.getLogger("commercetools");

final ProjectApiRoot client = createApiClient(apiClientPrefix);
CustomerService customerService = new CustomerService(client);

Expand Down
5 changes: 3 additions & 2 deletions src/main/java/handson/Task03b_IMPORT_API.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@ public static void main(String[] args) throws IOException, ExecutionException, I
// Provide a container key
//
final String apiImportClientPrefix = ApiPrefixHelper.API_DEV_IMPORT_PREFIX.getPrefix();
final String containerKey = "mh-berlin-store-prices";

Logger logger = LoggerFactory.getLogger(Task02b_UPDATE_Group.class.getName());
Logger logger = LoggerFactory.getLogger("commercetools");
final ProjectApiRoot client = createImportApiClient(apiImportClientPrefix);

final String containerKey = "mh-berlin-store-prices";
final ImportService importService = new ImportService(client);


Expand Down
2 changes: 1 addition & 1 deletion src/main/java/handson/Task03c_SYNC_PROJECTS.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class Task03c_SYNC_PROJECTS {

public static void main(String[] args) throws IOException, InterruptedException {

Logger logger = LoggerFactory.getLogger(Task02b_UPDATE_Group.class.getName());
Logger logger = LoggerFactory.getLogger("commercetools");

// TODO
// Have docker installed
Expand Down
61 changes: 31 additions & 30 deletions src/main/java/handson/Task04a_STATEMACHINE.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@
import com.commercetools.api.models.state.StateTypeEnum;
import handson.impl.ApiPrefixHelper;
import handson.impl.StateMachineService;
import io.vrap.rmf.base.client.ApiHttpResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.util.ArrayList;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.stream.Collectors;
import java.util.stream.Stream;
Expand All @@ -28,39 +30,38 @@ public static void main(String[] args) throws IOException, ExecutionException, I
final ProjectApiRoot client = createApiClient(apiClientPrefix);
final StateMachineService stateMachineService = new StateMachineService(client);

// TODO
// Use StateMachineService.java to create your designed order state machine
// TODO Use StateMachineService.java to create your designed order state machine
//
State orderPackedState =
stateMachineService.createState("mhOrderPacked", StateTypeEnum.ORDER_STATE, true, "MH Order Packed")
.toCompletableFuture().get()
.getBody();
State orderShippedState =
stateMachineService.createState("mhOrderShipped", StateTypeEnum.ORDER_STATE, false, "MH Order Shipped")
.toCompletableFuture().get()
.getBody();

logger.info("State info {}",
stateMachineService.setStateTransitions(
orderPackedState,
Stream.of(
StateResourceIdentifierBuilder.of().
id(orderShippedState.getId())
.build()
)
.collect(Collectors.toList())
stateMachineService.createState("mh1OrderPacked", StateTypeEnum.ORDER_STATE, true, "MH1 Order Packed")
.thenCombineAsync(stateMachineService.createState("mh1OrderShipped", StateTypeEnum.ORDER_STATE, false, "MH1 Order Shipped"),
(orderPackedStateApiResponse, orderShippedStateApiResponse)->
stateMachineService.setStateTransitions(
orderPackedStateApiResponse.getBody(),
Stream.of(
StateResourceIdentifierBuilder.of().
id(orderShippedStateApiResponse.getBody().getId())
.build()
)
.collect(Collectors.toList())
)
.thenComposeAsync(apiHttpResponse ->
stateMachineService.setStateTransitions(
orderShippedStateApiResponse.getBody(),
new ArrayList<>()
)
)
)
.toCompletableFuture().get()
);

logger.info("State info {}",
stateMachineService.setStateTransitions(
orderShippedState,
new ArrayList<>()
)
.toCompletableFuture().get()
);
.get()
.thenApply(ApiHttpResponse::getBody)
.thenAccept(resource -> logger.info("State info {}",resource.getId()))
.exceptionally(exception -> {
logger.info("An error occured " + exception.getMessage());
return null;}
)
.thenRun(() -> client.close());

client.close();
// TODO Create an order in the Merchant Center and verify that custom workflow states are available
//
}
}
7 changes: 4 additions & 3 deletions src/main/java/handson/Task04b_CHECKOUT.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,20 @@ public static void main(String[] args) throws IOException, ExecutionException, I
final String apiClientPrefix = ApiPrefixHelper.API_DEV_CLIENT_PREFIX.getPrefix();

final ProjectApiRoot client = createApiClient(apiClientPrefix);
Logger logger = LoggerFactory.getLogger("commercetools");

CustomerService customerService = new CustomerService(client);
CartService cartService = new CartService(client);
OrderService orderService = new OrderService(client);
PaymentService paymentService = new PaymentService(client);
Logger logger = LoggerFactory.getLogger(Task04b_CHECKOUT.class.getName());



// TODO: Fetch a channel if your inventory mode will not be NONE
//
Channel channel = null;
final String channelKey = "";

final State state = null;
final String initialStateKey = "";


// TODO: Perform cart operations:
Expand Down
34 changes: 24 additions & 10 deletions src/main/java/handson/Task04c_CART_MERGING.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import java.io.IOException;
import java.util.concurrent.ExecutionException;
import java.util.stream.Collectors;

import static com.commercetools.api.models.customer.AnonymousCartSignInMode.MERGE_WITH_EXISTING_CUSTOMER_CART;
import static handson.impl.ClientService.createApiClient;
Expand All @@ -25,31 +26,44 @@ public static void main(String[] args) throws IOException, ExecutionException, I

CustomerService customerService = new CustomerService(client);
CartService cartService = new CartService(client);
Logger logger = LoggerFactory.getLogger(Task04c_CART_MERGING.class.getName());
Logger logger = LoggerFactory.getLogger("commercetools");

final String customerKey = "customer-michael15";
final String channelKey = "berlin-store-channel";

// TODO: Inspect cart merging
// Complete the checkout by adding products, payment, ... test

// Get a customer and create a cart for this customer
//
final Cart cart = customerService.getCustomerByKey("customer-michael15")
final Cart customerCart = customerService.getCustomerByKey(customerKey)
.thenComposeAsync(cartService::createCart)
.toCompletableFuture().get()
.thenComposeAsync(cartApiHttpResponse -> cartService.addProductToCartBySkusAndChannel(
cartApiHttpResponse,
channelKey,
"TULIPSEED01", "TULIPSEED01", "TULIPSEED02"
))
.get()
.getBody();
logger.info("cart-id: " + cart.getId());
logger.info("cart-id: " + customerCart.getId());


// Create an anonymous cart
//
Cart anonymousCart = cartService.createAnonymousCart()
.toCompletableFuture().get()
.thenComposeAsync(cartApiHttpResponse -> cartService.addProductToCartBySkusAndChannel(
cartApiHttpResponse,
channelKey,
"TULIPSEED01"
))
.get()
.getBody();
logger.info("cart-id-anonymous: " + anonymousCart.getId());


// TODO: Decide on a merging strategy
//
String cartString = client
final Cart cart = client
.login()
.post(
CustomerSigninBuilder.of()
Expand All @@ -62,11 +76,11 @@ public static void main(String[] args) throws IOException, ExecutionException, I
.build()
)
.execute()
.toCompletableFuture().get().getBody().getCart().getId();
logger.info("cart-id-after_merge: " + cartString);
.get().getBody().getCart();

// TODO: Inspect the customers carts here or via impex
//
logger.info("cart ID in use after merge: " + cart.getId());

cart.getLineItems().forEach(lineItem -> logger.info(lineItem.getVariant().getSku()));

client.close();
}
Expand Down
129 changes: 0 additions & 129 deletions src/main/java/handson/Task05a_INSTORE_ME.java

This file was deleted.

Loading

0 comments on commit 2f05389

Please sign in to comment.