Skip to content

Commit

Permalink
upgraded to 14.5 and GraphQL exercise
Browse files Browse the repository at this point in the history
  • Loading branch information
nagesh-dixit committed Jul 14, 2023
1 parent 3162d46 commit b84ee86
Show file tree
Hide file tree
Showing 13 changed files with 90 additions and 235 deletions.
10 changes: 4 additions & 6 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ plugins {

ext {
versions = [
commercetools: "14.0.0",
slf4j: "1.7.32",
logback: "1.2.5",
commercetools: "14.5.0",
slf4j: "1.7.36",
logback: "1.2.10",
]
}

Expand All @@ -44,9 +44,9 @@ repositories {
dependencies {
implementation "com.commercetools.sdk:commercetools-http-client:${versions.commercetools}"
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 'com.fasterxml.jackson.core:jackson-databind:2.12.4'
implementation "org.slf4j:slf4j-api:${versions.slf4j}"
implementation "ch.qos.logback:logback-classic:${versions.logback}"

Expand All @@ -60,6 +60,4 @@ dependencies {
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'

implementation 'io.aexp.nodes.graphql:nodes:0.4.0-atlassian-hosted'
}
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 @@ -45,7 +45,7 @@ public static void main(String[] args) throws IOException, InterruptedException
// Modify as wished
// RUN the project sync
//
dockerRun.append(" commercetools/commercetools-project-sync:5.0.0 -s all");
dockerRun.append(" commercetools/commercetools-project-sync:5.3.1 -s all");
logger.info(dockerRun.toString());

Process process = Runtime.getRuntime().exec(dockerRun.toString());
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/handson/Task05a_INSTORE_ME.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public static void main(String[] args) throws IOException, ExecutionException, I
logger.info("Created in-store cart with a global api client: " +
" "
);

client.close();

// TODO: Create in-store Cart with in-store API client
// Update the ApiPrefixHelper with the prefix for Store API Client
Expand All @@ -51,6 +51,7 @@ public static void main(String[] args) throws IOException, ExecutionException, I
logger.info("Created in-store cart with a store api client: "+
" "
);
// storeClient.close();

// TODO
// Verify on impex that the carts are holding the same information
Expand Down Expand Up @@ -122,7 +123,7 @@ public static void main(String[] args) throws IOException, ExecutionException, I
// );
// storeClient.close();

client.close();


}
}
60 changes: 60 additions & 0 deletions src/main/java/handson/Task06c_GRAPHQL.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package handson;

import com.commercetools.api.client.ProjectApiRoot;
import com.commercetools.api.models.graph_ql.GraphQLRequest;
import com.commercetools.graphql.api.GraphQL;
import com.commercetools.graphql.api.GraphQLResponse;
import com.commercetools.graphql.api.types.ProductQueryResult;
import handson.impl.ApiPrefixHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

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

import static handson.impl.ClientService.*;


public class Task06c_GRAPHQL {

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

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

final ProjectApiRoot client = createApiClient(apiClientPrefix);
Logger logger = LoggerFactory.getLogger(Task04b_CHECKOUT.class.getName());


// TODO:
// Use the GraphQL playground to create a graphql query
//

logger.info("GraphQl : " +
client
.graphql()
.post(
GraphQLRequest.builder()
.query("{ products { total }}")
.build()
)
.execute()
.toCompletableFuture().get()
.getBody()
.getData()
);

GraphQLResponse<ProductQueryResult> responseEntity =
client
.graphql()
.query(GraphQL.products(q -> q.limit(3).sort(Collections.singletonList("masterData.current.name.en desc")))
.projection(p -> p.total().results().id().masterData().current().name("en", null)))
.executeBlocking()
.getBody();
logger.info("Total products: " + responseEntity.getData().getTotal());
responseEntity.getData().getResults().forEach(result ->
logger.info("Id: " + result.getId() + "Name: " + result.getMasterData().getCurrent().getName()));

client.close();
}
}
82 changes: 0 additions & 82 deletions src/main/java/handson/Task06c_GRAPHQL_Nodes.java

This file was deleted.

12 changes: 8 additions & 4 deletions src/main/java/handson/Task08a_SUBSCRIPTION.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@


import com.commercetools.api.client.ProjectApiRoot;
import com.commercetools.api.models.subscription.*;
import com.commercetools.api.models.subscription.GoogleCloudPubSubDestinationBuilder;
import com.commercetools.api.models.subscription.MessageSubscription;
import com.commercetools.api.models.subscription.MessageSubscriptionBuilder;
import com.commercetools.api.models.subscription.MessageSubscriptionResourceTypeId;
import com.commercetools.api.models.subscription.SubscriptionDraftBuilder;
import handson.impl.ApiPrefixHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -47,14 +51,14 @@ public static void main(String[] args) throws IOException, ExecutionException, I
)
.messages(
MessageSubscriptionBuilder.of()
.resourceTypeId(MessageSubscriptionResourceTypeId.ORDER)
.types("OrderCreated")
.resourceTypeId(MessageSubscriptionResourceTypeId.ORDER) // https://docs.commercetools.com/api/types#referencetype
.types("OrderCreated") // https://docs.commercetools.com/api/message-types
.build()
)
.build()
)
.execute()
.get()
.toCompletableFuture().get()
.getBody()
);

Expand Down
18 changes: 0 additions & 18 deletions src/main/java/handson/graphql/Current.java

This file was deleted.

18 changes: 0 additions & 18 deletions src/main/java/handson/graphql/Customers.java

This file was deleted.

13 changes: 0 additions & 13 deletions src/main/java/handson/graphql/MasterData.java

This file was deleted.

28 changes: 0 additions & 28 deletions src/main/java/handson/graphql/ProductCustomerQuery.java

This file was deleted.

25 changes: 0 additions & 25 deletions src/main/java/handson/graphql/Products.java

This file was deleted.

24 changes: 0 additions & 24 deletions src/main/java/handson/graphql/Result.java

This file was deleted.

Loading

0 comments on commit b84ee86

Please sign in to comment.