Skip to content

Commit 4deafc0

Browse files
authored
adding 'ui' to springboot samples (temporalio#476)
* adding 'ui' to springboot samples Signed-off-by: Tihomir Surdilovic <tihomir@temporal.io> * fix text Signed-off-by: Tihomir Surdilovic <tihomir@temporal.io> --------- Signed-off-by: Tihomir Surdilovic <tihomir@temporal.io>
1 parent 5ae487f commit 4deafc0

File tree

13 files changed

+190
-18
lines changed

13 files changed

+190
-18
lines changed

README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,15 @@ See the README.md file in each main sample directory for cut/paste Gradle comman
129129
<!-- @@@SNIPEND -->
130130

131131
### Running SpringBoot Samples
132-
See the README.md file in each main sample directory for cut/paste Gradle command to run specific example.
133132

133+
1. Start SpringBoot from main repo dir:
134+
135+
./gradlew bootRun
136+
137+
2. Navigate to [localhost:3030](http://localhost:3030)
138+
139+
3. Select which sample you want to run
140+
141+
More info on each sample:
134142
- [**Hello**](/springboot/src/main/java/io/temporal/samples/springboot/hello): Invoke simple "Hello" workflow from a GET endpoint
135143

build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ subprojects {
3838
exclude '**/*.json'
3939
exclude '**/*.yaml'
4040
exclude '**/*.yml'
41+
exclude '**/*.html'
4142
}
4243

4344
if (JavaVersion.current().isJava11Compatible()) {

springboot/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ apply plugin: 'org.springframework.boot'
22

33
dependencies {
44
implementation "org.springframework.boot:spring-boot-starter-web"
5+
implementation "org.springframework.boot:spring-boot-starter-thymeleaf"
56
implementation "org.springframework.boot:spring-boot-starter-actuator"
67
implementation "io.temporal:temporal-spring-boot-starter-alpha:$javaSDKVersion"
78
testImplementation "org.springframework.boot:spring-boot-starter-test"

springboot/src/main/java/io/temporal/samples/springboot/SamplesController.java

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,31 @@
2222
import io.temporal.client.WorkflowClient;
2323
import io.temporal.client.WorkflowOptions;
2424
import io.temporal.samples.springboot.hello.HelloWorkflow;
25+
import io.temporal.samples.springboot.hello.model.Person;
2526
import org.springframework.beans.factory.annotation.Autowired;
26-
import org.springframework.web.bind.annotation.GetMapping;
27-
import org.springframework.web.bind.annotation.PathVariable;
28-
import org.springframework.web.bind.annotation.RestController;
27+
import org.springframework.http.HttpStatus;
28+
import org.springframework.http.MediaType;
29+
import org.springframework.http.ResponseEntity;
30+
import org.springframework.stereotype.Controller;
31+
import org.springframework.ui.Model;
32+
import org.springframework.web.bind.annotation.*;
2933

30-
@RestController
34+
@Controller
3135
public class SamplesController {
3236

3337
@Autowired WorkflowClient client;
3438

35-
@GetMapping("/hello/{name}")
36-
String helloSample(@PathVariable String name) {
39+
@GetMapping("/hello")
40+
public String hello(Model model) {
41+
model.addAttribute("sample", "Say Hello");
42+
return "hello";
43+
}
44+
45+
@PostMapping(
46+
value = "/hello",
47+
consumes = {MediaType.APPLICATION_JSON_VALUE},
48+
produces = {MediaType.TEXT_HTML_VALUE})
49+
ResponseEntity helloSample(@RequestBody Person person) {
3750
HelloWorkflow workflow =
3851
client.newWorkflowStub(
3952
HelloWorkflow.class,
@@ -42,6 +55,7 @@ String helloSample(@PathVariable String name) {
4255
.setWorkflowId("HelloSample")
4356
.build());
4457

45-
return workflow.sayHello(name);
58+
// bypass thymeleaf, don't return template name just result
59+
return new ResponseEntity("\"" + workflow.sayHello(person) + "\"", HttpStatus.OK);
4660
}
4761
}

springboot/src/main/java/io/temporal/samples/springboot/hello/HelloActivity.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@
2020
package io.temporal.samples.springboot.hello;
2121

2222
import io.temporal.activity.ActivityInterface;
23+
import io.temporal.samples.springboot.hello.model.Person;
2324

2425
@ActivityInterface
2526
public interface HelloActivity {
26-
String hello(String name);
27+
String hello(Person person);
2728
}

springboot/src/main/java/io/temporal/samples/springboot/hello/HelloActivityImpl.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
package io.temporal.samples.springboot.hello;
2121

22+
import io.temporal.samples.springboot.hello.model.Person;
2223
import io.temporal.spring.boot.ActivityImpl;
2324
import org.springframework.beans.factory.annotation.Value;
2425
import org.springframework.stereotype.Component;
@@ -30,8 +31,8 @@ public class HelloActivityImpl implements HelloActivity {
3031
private String language;
3132

3233
@Override
33-
public String hello(String name) {
34+
public String hello(Person person) {
3435
String greeting = language.equals("spanish") ? "Hola " : "Hello ";
35-
return greeting + name + "!";
36+
return greeting + person.getFirstName() + " " + person.getLastName() + "!";
3637
}
3738
}

springboot/src/main/java/io/temporal/samples/springboot/hello/HelloWorkflow.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,12 @@
1919

2020
package io.temporal.samples.springboot.hello;
2121

22+
import io.temporal.samples.springboot.hello.model.Person;
2223
import io.temporal.workflow.WorkflowInterface;
2324
import io.temporal.workflow.WorkflowMethod;
2425

2526
@WorkflowInterface
2627
public interface HelloWorkflow {
2728
@WorkflowMethod
28-
String sayHello(String message);
29+
String sayHello(Person person);
2930
}

springboot/src/main/java/io/temporal/samples/springboot/hello/HelloWorkflowImpl.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
package io.temporal.samples.springboot.hello;
2121

2222
import io.temporal.activity.ActivityOptions;
23+
import io.temporal.samples.springboot.hello.model.Person;
2324
import io.temporal.spring.boot.WorkflowImpl;
2425
import io.temporal.workflow.Workflow;
2526
import java.time.Duration;
@@ -33,7 +34,7 @@ public class HelloWorkflowImpl implements HelloWorkflow {
3334
ActivityOptions.newBuilder().setStartToCloseTimeout(Duration.ofSeconds(2)).build());
3435

3536
@Override
36-
public String sayHello(String name) {
37-
return activity.hello(name);
37+
public String sayHello(Person person) {
38+
return activity.hello(person);
3839
}
3940
}

springboot/src/main/java/io/temporal/samples/springboot/hello/README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@
66

77
2. In your browser navigate to:
88

9-
http://localhost:3030/hello/Temporal%20User
9+
http://localhost:3030/hello
1010

11-
You should see "Hello Temporal User!" show on the page which is the result of our
12-
Hello workflow execution.
11+
Enter in first and last name in the form then click on Run Workflow
12+
to start workflow execution. Page will be updated to show the workflow
13+
execution results (the greeting).
1314

1415
You can try changing the language setting in [application.yaml](../../../../../../resources/application.yaml) file
1516
from "english" to "spanish" to get the greeting result in Spanish.
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* Copyright (c) 2020 Temporal Technologies, Inc. All Rights Reserved
3+
*
4+
* Copyright 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
5+
*
6+
* Modifications copyright (C) 2017 Uber Technologies, Inc.
7+
*
8+
* Licensed under the Apache License, Version 2.0 (the "License"). You may not
9+
* use this file except in compliance with the License. A copy of the License is
10+
* located at
11+
*
12+
* http://aws.amazon.com/apache2.0
13+
*
14+
* or in the "license" file accompanying this file. This file is distributed on
15+
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
16+
* express or implied. See the License for the specific language governing
17+
* permissions and limitations under the License.
18+
*/
19+
20+
package io.temporal.samples.springboot.hello.model;
21+
22+
public class Person {
23+
private String firstName;
24+
private String lastName;
25+
26+
public Person() {}
27+
;
28+
29+
public Person(String firstName, String lastName) {
30+
this.firstName = firstName;
31+
this.lastName = lastName;
32+
}
33+
34+
public String getFirstName() {
35+
return firstName;
36+
}
37+
38+
public void setFirstName(String firstName) {
39+
this.firstName = firstName;
40+
}
41+
42+
public String getLastName() {
43+
return lastName;
44+
}
45+
46+
public void setLastName(String lastName) {
47+
this.lastName = lastName;
48+
}
49+
}

0 commit comments

Comments
 (0)