Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

updated to sdk version 17.5 #34

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 6 additions & 9 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ plugins {

id 'idea'

id 'maven'
id 'maven-publish'

id 'java'
Expand All @@ -20,16 +19,15 @@ 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",
]
}

allprojects {
apply plugin: 'java'
sourceCompatibility = 1.8
targetCompatibility = 1.8
java {
sourceCompatibility = JavaVersion.VERSION_1_8
sourceCompatibility = JavaVersion.VERSION_1_8
}


Expand All @@ -46,7 +44,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
92 changes: 61 additions & 31 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 @@ -24,43 +26,71 @@ public static void main(String[] args) throws IOException, ExecutionException, I

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

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

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(
"mhOrderPacked1",
StateTypeEnum.ORDER_STATE,
true,
"MH Order Packed1"
)
.toCompletableFuture().get()
);

logger.info("State info {}",
stateMachineService.setStateTransitions(
orderShippedState,
new ArrayList<>()
)
.toCompletableFuture().get()
);
.exceptionally( throwable -> {
logger.error("Exception: " + throwable.getMessage());
try {
return stateMachineService.getStateByKey("mhOrderPacked1").get();
}
catch (Exception e){client.close();logger.error(e.getMessage());return null;}
})
.thenCombineAsync(
stateMachineService.createState(
"mhOrderShipped1",
StateTypeEnum.ORDER_STATE,
false,
"MH Order Shipped1"
)
.exceptionally( throwable -> {
logger.error("Exception: " + throwable.getMessage());
try {
return stateMachineService.getStateByKey("mhOrderShipped1").get();
}
catch (Exception e){client.close();logger.error(e.getMessage());return null;}
}),
(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<>()
)
)
)
.get()
.thenApply(ApiHttpResponse::getBody)
.handle((state, exception) -> {
if (exception == null) {
logger.info("Initial state key {}", state.getKey());
return state;
};
logger.error("Exception: " + 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
Loading
Loading