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 sdk version to 17.4 #33

Open
wants to merge 25 commits into
base: solutions
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
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
23 changes: 6 additions & 17 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,19 +19,17 @@ plugins {

ext {
versions = [
commercetools: "14.5.0",
slf4j: "1.7.36",
logback: "1.2.10",
commercetools: "17.10.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
}


repositories {
mavenCentral()
maven {
Expand All @@ -46,17 +43,9 @@ 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}"

// implementation group: 'org.slf4j', name: 'slf4j-log4j12', version: '2.0.0-alpha0'

// Sync Library + old jvm sdk v1
// implementation 'com.commercetools:commercetools-sync-java:1.9.1'
// implementation 'com.commercetools.sdk.jvm.core:commercetools-models:1.53.0'
// implementation 'com.commercetools.sdk.jvm.core:commercetools-java-client:1.53.0'

implementation group: 'org.json', name: 'json', version: '20200518'
implementation 'javax.json:javax.json-api:1.1.4'
implementation 'org.glassfish:javax.json:1.1.4'
Expand Down
59 changes: 34 additions & 25 deletions src/main/java/handson/Task02a_CREATE.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@
import handson.impl.ApiPrefixHelper;
import handson.impl.ClientService;
import handson.impl.CustomerService;
import io.vrap.rmf.base.client.ApiHttpResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

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

import static handson.impl.ClientService.createApiClient;
import static handson.impl.ClientService.getStoreKey;


/**
Expand All @@ -26,38 +28,45 @@ 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);
final String storeKey = getStoreKey(apiClientPrefix);
CustomerService customerService = new CustomerService(client, storeKey);

logger.info("Customer fetch: " +
customerService
.getCustomerByKey("customer-alex-242281870")
.toCompletableFuture().get()
.getBody().getEmail()
);
customerService
.getCustomerByKey("customer-michael")
.thenApply(ApiHttpResponse::getBody)
.handle((customer, exception) -> {
if (exception == null) {
logger.info("Customer already exists: " + customer.getEmail()); return customer;
};
logger.error("Exception: " + exception.getMessage());
return null;
});

// TODO:
// CREATE a customer
// CREATE a email verification token
// Verify customer
//
logger.info("Customer created: " +
customerService.createCustomer(
"[email protected]",
"password",
"customer-michael15",
"michael",
"hartwig",
"DE"
)
.thenComposeAsync(signInResult -> customerService.createEmailVerificationToken(signInResult, 5))
.thenComposeAsync(customerService::verifyEmail)
.toCompletableFuture().get()
.getBody()
);


client.close();

customerService.createCustomer(
"[email protected]",
"password",
"customer-michael",
"michael",
"tester",
"DE"
)
.thenComposeAsync(signInResult -> customerService.createEmailVerificationToken(signInResult, 5))
.thenComposeAsync(customerService::verifyEmail)
.thenApply(ApiHttpResponse::getBody)
.handle((customer, exception) -> {
if (exception == null) {
logger.info("Customer ID: " + customer.getId()); return customer;
};
logger.error("Exception: " + exception.getMessage());
return null;
}).thenRun(() -> client.close());
}
}
45 changes: 20 additions & 25 deletions src/main/java/handson/Task02b_UPDATE_Group.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import handson.impl.ApiPrefixHelper;
import handson.impl.ClientService;
import handson.impl.CustomerService;
import io.vrap.rmf.base.client.ApiHttpResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -12,43 +13,37 @@
import java.util.concurrent.ExecutionException;

import static handson.impl.ClientService.createApiClient;
import static handson.impl.ClientService.getStoreKey;

/**
* Configure sphere client and get project information.
*
* See:
* TODO dev.properties
* TODO {@link ClientService#createApiClient(String prefix)}
*/
public class Task02b_UPDATE_Group {

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

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);
final String storeKey = getStoreKey(apiClientPrefix);
CustomerService customerService = new CustomerService(client, storeKey);

// TODO:
// GET a customer
// GET a customer group
// ASSIGN the customer to the customer group
//
logger.info("Customer assigned to group: " +
customerService
.getCustomerByKey("customer-michael15")
.thenCombineAsync(
customerService.getCustomerGroupByKey("outdoor-customer-group"),
customerService::assignCustomerToCustomerGroup
)
.thenComposeAsync(CompletableFuture::toCompletableFuture)
.exceptionally(throwable -> { logger.info(throwable.getLocalizedMessage()); return null; })
.toCompletableFuture().get()
.getBody().getEmail()
);

client.close();

customerService.assignCustomerToCustomerGroup(
"customer-michael",
"vip-customers"
)
.thenApply(ApiHttpResponse::getBody)
.handle((customer, exception) -> {
if (exception == null) {
logger.info("Resource ID: " + customer.getId());
return customer;
};
logger.error("Exception: " + exception.getMessage());
return null;
}).thenRun(() -> client.close());
}

}
Expand Down
142 changes: 0 additions & 142 deletions src/main/java/handson/Task03a_SYNC.txt

This file was deleted.

Loading