Skip to content
Merged
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
2 changes: 1 addition & 1 deletion exercises/version-workflow/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ String versionKey = "MovedThankYouAfterLoop";
int version = Workflow.getVersion(versionKey, Workflow.DEFAULT_VERSION, 1);

if (version != Workflow.DEFAULT_VERSION) {
Workflow.upsertTypedSearchAttributes(TEMPORAL_CHANGE_VERSION
Workflow.upsertTypedSearchAttributes(TEMPORAL_CHANGE_VERSION
.valueSet(Arrays.asList((versionKey + "-" + version))));
}
```
Expand Down
6 changes: 3 additions & 3 deletions exercises/version-workflow/practice/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<dependency>
<groupId>io.temporal</groupId>
<artifactId>temporal-sdk</artifactId>
<version>1.31.0</version>
<version>1.32.1</version>
</dependency>

<dependency>
Expand All @@ -40,14 +40,14 @@
<dependency>
<groupId>io.temporal</groupId>
<artifactId>temporal-testing</artifactId>
<version>1.31.0</version>
<version>1.32.1</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.14.1</version>
<version>5.11.4</version>
<scope>test</scope>
</dependency>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

public class Constants {

public static final String taskQueueName = "loan-processing-workflow-taskqueue";
public static final String TASK_QUEUE_NAME = "loan-processing-workflow-taskqueue";

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
@ActivityInterface
public interface LoanProcessingActivities {

public String chargeCustomer(ChargeInput input);
String chargeCustomer(ChargeInput input);

public String sendThankYouToCustomer(CustomerInfo input);
String sendThankYouToCustomer(CustomerInfo input);

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public static void main(String[] args) {
WorkflowClient client = WorkflowClient.newInstance(service);
WorkerFactory factory = WorkerFactory.newInstance(client);

Worker worker = factory.newWorker(Constants.taskQueueName);
Worker worker = factory.newWorker(Constants.TASK_QUEUE_NAME);

worker.registerWorkflowImplementationTypes(LoanProcessingWorkflowImpl.class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
public interface LoanProcessingWorkflow {

@WorkflowMethod
public String loanProcessingWorkflow(CustomerInfo info);
String loanProcessingWorkflow(CustomerInfo info);

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.slf4j.Logger;

import java.time.Duration;
import java.util.Arrays;
import java.util.List;

public class LoanProcessingWorkflowImpl implements LoanProcessingWorkflow {
Expand All @@ -26,7 +27,6 @@ public String loanProcessingWorkflow(CustomerInfo info) {

String customerId = info.getCustomerID();
int amount = info.getAmount();
String email = info.getEmailAddress();
int numberOfPeriods = info.getNumberOfPeriods();

int totalPaid = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ public static void main(String[] args) {

WorkflowOptions options = WorkflowOptions.newBuilder()
.setWorkflowId("loan-processing-workflow-customer-" + info.getCustomerID())
.setTaskQueue(Constants.taskQueueName).build();
.setTaskQueue(Constants.TASK_QUEUE_NAME)
.build();

LoanProcessingWorkflow workflow = client.newWorkflowStub(LoanProcessingWorkflow.class, options);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
package getversion.model;

public class ChargeInput {
private String customerID;
private String customerId;
private int amount;
private int periodNumber;
private int numberOfPeriods;

public ChargeInput() {}

public ChargeInput(String customerID, int amount, int periodNumber, int numberOfPeriods) {
this.customerID = customerID;
public ChargeInput(String customerId, int amount, int periodNumber, int numberOfPeriods) {
this.customerId = customerId;
this.amount = amount;
this.periodNumber = periodNumber;
this.numberOfPeriods = numberOfPeriods;
}

public String getCustomerID() {
return customerID;
return customerId;
}

public void setCustomerID(String customerID) {
this.customerID = customerID;
public void setCustomerID(String customerId) {
this.customerId = customerId;
}

public int getAmount() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,29 +1,28 @@
package getversion.model;

public class CustomerInfo {
private String customerID;
private String customerId;
private String name;
private String emailAddress;
private int amount;
private int numberOfPeriods;

public CustomerInfo() {}

public CustomerInfo(String customerID, String name, String emailAddress, int amount,
int numberOfPeriods) {
this.customerID = customerID;
public CustomerInfo(String customerId, String name, String emailAddress, int amount, int numberOfPeriods) {
this.customerId = customerId;
this.name = name;
this.emailAddress = emailAddress;
this.amount = amount;
this.numberOfPeriods = numberOfPeriods;
}

public String getCustomerID() {
return customerID;
return customerId;
}

public void setCustomerID(String customerID) {
this.customerID = customerID;
public void setCustomerID(String customerId) {
this.customerId = customerId;
}

public String getName() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,16 @@ private void populate() {

CustomerInfo customer01 = new CustomerInfo("a100", "Ana Garcia", "ana@example.com", 500, 10);
CustomerInfo customer02 = new CustomerInfo("a101", "Amit Singh", "asingh@example.com", 250, 15);
CustomerInfo customer03 =
new CustomerInfo("a102", "Mary O'Connor", "marymo@example.com", 425, 12);
CustomerInfo customer03 = new CustomerInfo("a102", "Mary O'Connor", "marymo@example.com", 425, 12);

customers.put(customer01.getCustomerID(), customer01);
customers.put(customer02.getCustomerID(), customer02);
customers.put(customer03.getCustomerID(), customer03);
}

@Override
public CustomerInfo get(String customerID) {
CustomerInfo info = customers.get(customerID);
public CustomerInfo get(String customerId) {
CustomerInfo info = customers.get(customerId);
if (info == null) {
throw new RuntimeException("Customer ID does not exist in the database");
}
Expand Down
6 changes: 3 additions & 3 deletions exercises/version-workflow/solution/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<dependency>
<groupId>io.temporal</groupId>
<artifactId>temporal-sdk</artifactId>
<version>1.31.0</version>
<version>1.32.1</version>
</dependency>

<dependency>
Expand All @@ -40,14 +40,14 @@
<dependency>
<groupId>io.temporal</groupId>
<artifactId>temporal-testing</artifactId>
<version>1.31.0</version>
<version>1.32.1</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.14.1</version>
<version>5.11.4</version>
<scope>test</scope>
</dependency>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

public class Constants {

public static final String taskQueueName = "loan-processing-workflow-taskqueue";
public static final String TASK_QUEUE_NAME = "loan-processing-workflow-taskqueue";

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
@ActivityInterface
public interface LoanProcessingActivities {

public String chargeCustomer(ChargeInput input);
String chargeCustomer(ChargeInput input);

public String sendThankYouToCustomer(CustomerInfo input);
String sendThankYouToCustomer(CustomerInfo input);

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@ public class LoanProcessingActivitiesImpl implements LoanProcessingActivities {

@Override
public String chargeCustomer(ChargeInput input) {
String customerID = input.getCustomerID();
String customerId = input.getCustomerID();
int amount = input.getAmount();
int numberOfPeriods = input.getNumberOfPeriods();

logger.info("*** Charging customer***: CustomerID: {}, Amount {}, Number of Periods: {}",
customerID, amount, numberOfPeriods);
customerId, amount, numberOfPeriods);

// pretend we charge them

String confirmation = String.format("Charged %d to customer '%s'", amount, customerID);
String confirmation = String.format("Charged %d to customer '%s'", amount, customerId);

return confirmation;

Expand All @@ -29,14 +29,14 @@ public String chargeCustomer(ChargeInput input) {
@Override
public String sendThankYouToCustomer(CustomerInfo input) {

String customerID = input.getCustomerID();
String customerId = input.getCustomerID();
String email = input.getEmailAddress();


logger.info("*** Sending thank you message to Customer ***: CustomerID: {}, Email {}",
customerID, email);
customerId, email);

String confirmation = String.format("Sent thank you message to customer '%s'", customerID);
String confirmation = String.format("Sent thank you message to customer '%s'", customerId);

return confirmation;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public static void main(String[] args) {
WorkflowClient client = WorkflowClient.newInstance(service);
WorkerFactory factory = WorkerFactory.newInstance(client);

Worker worker = factory.newWorker(Constants.taskQueueName);
Worker worker = factory.newWorker(Constants.TASK_QUEUE_NAME);

worker.registerWorkflowImplementationTypes(LoanProcessingWorkflowImpl.class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
public interface LoanProcessingWorkflow {

@WorkflowMethod
public String loanProcessingWorkflow(CustomerInfo info);
String loanProcessingWorkflow(CustomerInfo info);

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ public class LoanProcessingWorkflowImpl implements LoanProcessingWorkflow {

public static final SearchAttributeKey<List<String>> TEMPORAL_CHANGE_VERSION = SearchAttributeKey.forKeywordList("TemporalChangeVersion");

ActivityOptions options =
ActivityOptions.newBuilder().setStartToCloseTimeout(Duration.ofSeconds(5)).build();
ActivityOptions options = ActivityOptions.newBuilder()
.setStartToCloseTimeout(Duration.ofSeconds(5))
.build();

private final LoanProcessingActivities activities =
Workflow.newActivityStub(LoanProcessingActivities.class, options);
Expand Down Expand Up @@ -59,8 +60,7 @@ public String loanProcessingWorkflow(CustomerInfo info) {
}

if (version == 1) {
// for workflow executions started before the change, send thank you before the
// loop
// for workflow executions started before the change, send thank you before the loop
String confirmation = activities.sendThankYouToCustomer(info);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public static void main(String[] args) {

WorkflowOptions options = WorkflowOptions.newBuilder()
.setWorkflowId("loan-processing-workflow-customer-" + info.getCustomerID())
.setTaskQueue(Constants.taskQueueName)
.setTaskQueue(Constants.TASK_QUEUE_NAME)
.build();

LoanProcessingWorkflow workflow = client.newWorkflowStub(LoanProcessingWorkflow.class, options);
Expand Down
Loading