Skip to content

Commit a396bae

Browse files
committed
Adds ExampleClientV2 API
1 parent b750729 commit a396bae

File tree

8 files changed

+82
-7
lines changed

8 files changed

+82
-7
lines changed

apis/src/main/java/io/dirigible/samples/api/client/ExampleClient.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package io.dirigible.samples.api.client;
22

3-
import java.time.ZonedDateTime;
3+
import java.util.Date;
4+
5+
import com.google.gson.Gson;
46

57
import io.dirigible.samples.api.domain.Example;
68
import io.dirigible.samples.api.domain.SubExample;
@@ -13,10 +15,11 @@ public class ExampleClient implements ExampleService {
1315
@Override
1416
public ExampleResponse doExample(ExampleRequest request) {
1517
final var exampleResponse = new ExampleResponse();
16-
final var subexample = new SubExample().withDate(ZonedDateTime.now());
18+
final var subexample = new SubExample().withDate(new Date());
1719
final var example = new Example().withId(request.getExampleId()).withName("Example Name");
1820
example.getSubexamples().add(subexample);
1921
exampleResponse.getExamples().add(example);
22+
new Gson().fromJson("", ExampleRequest.class);
2023
return exampleResponse;
2124
}
2225

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package io.dirigible.samples.api.client;
2+
3+
import java.util.Date;
4+
5+
import com.google.gson.Gson;
6+
7+
import io.dirigible.samples.api.domain.Example;
8+
import io.dirigible.samples.api.domain.SubExample;
9+
import io.dirigible.samples.api.domain.input.ExampleRequest;
10+
import io.dirigible.samples.api.domain.output.ExampleResponse;
11+
12+
public class ExampleClientV2 {
13+
14+
public String doExample(String requestAsString) {
15+
final var gson = new Gson();
16+
final var request = gson.fromJson(requestAsString, ExampleRequest.class);
17+
final var exampleResponse = new ExampleResponse();
18+
final var subexample = new SubExample().withDate(new Date());
19+
final var example = new Example().withId(request.getExampleId()).withName("Example Name");
20+
example.getSubexamples().add(subexample);
21+
exampleResponse.getExamples().add(example);
22+
return gson.toJson(exampleResponse);
23+
}
24+
25+
}

apis/src/main/java/io/dirigible/samples/api/domain/SubExample.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
package io.dirigible.samples.api.domain;
22

3-
import java.time.ZonedDateTime;
3+
import java.util.Date;
44

55
public class SubExample {
66

7-
private ZonedDateTime date;
7+
private Date date;
88

9-
public ZonedDateTime getDate() {
9+
public Date getDate() {
1010
return date;
1111
}
1212

13-
public void setDate(ZonedDateTime date) {
13+
public void setDate(Date date) {
1414
this.date = date;
1515
}
1616

17-
public SubExample withDate(ZonedDateTime date) {
17+
public SubExample withDate(Date date) {
1818
setDate(date);
1919
return this;
2020
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { ExampleResponseV2 } from "./ExampleResponseV2";
2+
import { ExampleRequestV2 } from "./ExampleRequestV2";
3+
4+
const ExampleClientV2Class = Java.type("io.dirigible.samples.api.client.ExampleClientV2");
5+
6+
export class ExampleClientV2 {
7+
8+
public doExample(request: ExampleRequestV2): ExampleResponseV2 {
9+
const response = new ExampleClientV2Class().doExample(JSON.stringify(request));
10+
return JSON.parse(response);
11+
}
12+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export interface ExampleRequestV2 {
2+
readonly exampleId: string;
3+
readonly exampleName: string;
4+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
export interface SubExampleV2 {
2+
readonly date: Date;
3+
}
4+
5+
export interface ExampleV2 {
6+
readonly id: string;
7+
readonly name: string;
8+
readonly subexamples: SubExampleV2[];
9+
}
10+
11+
export interface ExampleResponseV2 {
12+
readonly examples: ExampleV2[];
13+
}

demo-application/demo-client-v2.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { response } from "sdk/http";
2+
import { ExampleClientV2 } from "custom-api/ExampleClientV2";
3+
import { ExampleRequestV2 } from "custom-api/ExampleRequestV2";
4+
5+
const exampleRequest: ExampleRequestV2 = {
6+
exampleId: 'example-id-1234',
7+
exampleName: 'Custom Stack Example'
8+
};
9+
10+
const exampleClient = new ExampleClientV2();
11+
const exampleResponse = exampleClient.doExample(exampleRequest);
12+
13+
response.println(JSON.stringify(exampleResponse, null, 2));

pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,11 @@
155155
</exclusions>
156156
</dependency>
157157

158+
<dependency>
159+
<groupId>com.google.code.gson</groupId>
160+
<artifactId>gson</artifactId>
161+
</dependency>
162+
158163
</dependencies>
159164

160165
<dependencyManagement>

0 commit comments

Comments
 (0)