Skip to content

Commit 5923c94

Browse files
committed
Error object to have key field
1 parent 3450612 commit 5923c94

File tree

121 files changed

+4105
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

121 files changed

+4105
-0
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
This project contains code samples documented in the following section in [Backbase Community](https://community.backbase.com/documentation/ServiceSDK/latest/index):
2+
3+
* [Add persistence to your capability](https://community.backbase.com/documentation/ServiceSDK/latest/add_persistence_to_core_service)
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# example-service
2+
3+
_Fill out this file with some information about your Service._
4+
5+
## Dependencies
6+
7+
Requires a running Eureka registry, by default on port 8080.
8+
9+
## Configuration
10+
11+
Service configuration is under `src/main/resources/application.yaml`.
12+
13+
## Running
14+
15+
To run the service in development mode, use:
16+
- `mvn spring-boot:run`
17+
18+
To run the service from the built binaries, use:
19+
- `java -jar target/example-persistence-service-1.0.0-SNAPSHOT.jar`
20+
21+
## Authorization
22+
23+
Requests to this service are authorized with a Backbase Internal JWT, therefore you must access this service via the Backbase Edge after authenticating with identity service.
24+
25+
For local development, an internal JWT can be created from http://jwt.io, entering ```JWTSecretKeyDontUseInProduction!``` as the secret in the signature to generate a valid signed JWT.
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
5+
<!-- The simplest way to build a service with service-sdk-starter-core
6+
is to use it as a parent in your project’s POM file, and alternative If you
7+
don’t want to use service-sdk-starter-core as your project’s parent, you
8+
can declare it as a dependency instead, see pom-as-dependency.xml -->
9+
<parent>
10+
<artifactId>service-sdk-starter-core</artifactId>
11+
<groupId>com.backbase.buildingblocks</groupId>
12+
<version>16.0.0</version>
13+
<relativePath />
14+
</parent>
15+
16+
<groupId>com.backbase.example</groupId>
17+
<artifactId>example-persistence-service</artifactId>
18+
<version>1.0.0-SNAPSHOT</version>
19+
<name>Backbase :: Digital Banking Services :: example-persistence-service</name>
20+
21+
<properties>
22+
<java.version>17</java.version>
23+
</properties>
24+
25+
<dependencies>
26+
<!-- tag::persistence-dependencies[] -->
27+
<!--Added for persistence -->
28+
<dependency>
29+
<groupId>com.backbase.buildingblocks</groupId>
30+
<artifactId>persistence</artifactId>
31+
</dependency>
32+
<dependency>
33+
<groupId>com.backbase.buildingblocks</groupId>
34+
<artifactId>service-sdk-starter-mapping</artifactId>
35+
</dependency>
36+
<dependency>
37+
<groupId>org.springframework.boot</groupId>
38+
<artifactId>spring-boot-starter-cache</artifactId>
39+
</dependency>
40+
<!-- Required for Local testing -->
41+
<dependency>
42+
<groupId>com.h2database</groupId>
43+
<artifactId>h2</artifactId>
44+
<version>2.1.214</version>
45+
<scope>test</scope>
46+
</dependency>
47+
<!-- Required for MySql -->
48+
<dependency>
49+
<groupId>com.mysql</groupId>
50+
<artifactId>mysql-connector-j</artifactId>
51+
<scope>test</scope>
52+
</dependency>
53+
<!-- end::persistence-dependencies[] -->
54+
55+
<dependency>
56+
<groupId>com.backbase.buildingblocks</groupId>
57+
<artifactId>service-sdk-starter-test</artifactId>
58+
<scope>test</scope>
59+
</dependency>
60+
61+
<!-- Add dependencies for your services, e.g. BB specifications, integration clients -->
62+
63+
<!-- Uncomment the following dependencies if DBS inter-service communication is needed -->
64+
<!--
65+
<dependency>
66+
<groupId>com.backbase.buildingblocks</groupId>
67+
<artifactId>communication</artifactId>
68+
</dependency>
69+
<dependency>
70+
<groupId>com.backbase.buildingblocks</groupId>
71+
<artifactId>auth-security</artifactId>
72+
</dependency>
73+
-->
74+
</dependencies>
75+
76+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.backbase.example;
2+
3+
import org.springframework.boot.autoconfigure.SpringBootApplication;
4+
import org.springframework.boot.SpringApplication;
5+
import org.springframework.boot.autoconfigure.domain.EntityScan;
6+
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
7+
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
8+
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
9+
10+
// tag::application-annotations[]
11+
@SpringBootApplication
12+
@EnableDiscoveryClient
13+
@EnableJpaRepositories
14+
@EntityScan
15+
public class Application extends SpringBootServletInitializer {
16+
// end::application-annotations[]
17+
public static void main(final String[] args) {
18+
SpringApplication.run(Application.class, args);
19+
}
20+
21+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
package com.backbase.example;
2+
3+
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
4+
import com.fasterxml.jackson.annotation.JsonInclude;
5+
import com.fasterxml.jackson.annotation.JsonProperty;
6+
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
7+
8+
import jakarta.annotation.Generated;
9+
import jakarta.validation.constraints.NotNull;
10+
import jakarta.validation.constraints.Size;
11+
12+
@JsonInclude(JsonInclude.Include.NON_NULL)
13+
@Generated("org.jsonschema2pojo")
14+
@JsonPropertyOrder({
15+
"message"
16+
})
17+
@JsonIgnoreProperties(ignoreUnknown = true)
18+
public class Message {
19+
20+
/**
21+
*
22+
* (Required)
23+
*
24+
*/
25+
@JsonProperty("id")
26+
@NotNull
27+
private String id;
28+
29+
/**
30+
* Greetings message
31+
*/
32+
@JsonProperty("message")
33+
@Size(max = 255)
34+
@NotNull
35+
private String message;
36+
37+
public Message() {
38+
}
39+
40+
public Message(String id, String message) {
41+
this.id = id;
42+
this.message = message;
43+
}
44+
45+
public String getId() {
46+
return id;
47+
}
48+
49+
public void setId(String id) {
50+
this.id = id;
51+
}
52+
53+
public String getMessage() {
54+
return message;
55+
}
56+
57+
public void setMessage(String message) {
58+
this.message = message;
59+
}
60+
61+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package com.backbase.example.api;
2+
3+
import com.backbase.example.Message;
4+
import com.backbase.example.domain.Greeting;
5+
import com.backbase.example.mapper.GreetingsMapper;
6+
import com.backbase.example.service.GreetingsService;
7+
import org.springframework.beans.factory.annotation.Autowired;
8+
import org.springframework.http.HttpStatus;
9+
import org.springframework.web.bind.annotation.*;
10+
11+
import java.util.List;
12+
import java.util.UUID;
13+
14+
@RestController
15+
public class ExampleController {
16+
17+
@Autowired
18+
private GreetingsService greetingsService;
19+
20+
@RequestMapping(method = RequestMethod.GET, value = "/message/{id}", produces = {
21+
"application/json"
22+
})
23+
@ResponseStatus(HttpStatus.OK)
24+
public Message getMessage(@PathVariable(name = "id") String id) {
25+
Greeting greeting = greetingsService.getGreetingById(id);
26+
return GreetingsMapper.INSTANCE.greetingToMessage(greeting);
27+
}
28+
29+
@RequestMapping(method = RequestMethod.GET, value = "/messages", produces = {
30+
"application/json"
31+
})
32+
@ResponseStatus(HttpStatus.OK)
33+
public List<Message> getMessages() {
34+
List<Greeting> greetings = greetingsService.getGreetings();
35+
return GreetingsMapper.INSTANCE.greetingsToMessages(greetings);
36+
}
37+
// tag::addMessage[]
38+
@RequestMapping(method = RequestMethod.POST, value = "/message")
39+
@ResponseStatus(HttpStatus.CREATED)
40+
public String addMessage(@RequestBody Message message) {
41+
Greeting greeting = GreetingsMapper.INSTANCE.messageToGreeting(message);
42+
String id = UUID.randomUUID().toString();
43+
greeting.setId(id);
44+
greetingsService.addNewGreeting(greeting);
45+
return id;
46+
}
47+
// end::addMessage[]
48+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package com.backbase.example.domain;
2+
3+
import jakarta.persistence.*;
4+
5+
@Entity
6+
@Table(name = "greetings")
7+
public class Greeting {
8+
9+
@Id
10+
@Column(name = "id")
11+
private String id;
12+
13+
@Column(name = "message")
14+
private String message;
15+
16+
public String getId() {
17+
return id;
18+
}
19+
20+
public void setId(String id) {
21+
this.id = id;
22+
}
23+
24+
public String getMessage() {
25+
return message;
26+
}
27+
28+
public void setMessage(String message) {
29+
this.message = message;
30+
}
31+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.backbase.example.mapper;
2+
3+
import com.backbase.example.Message;
4+
import com.backbase.example.domain.Greeting;
5+
import org.mapstruct.Mapper;
6+
import org.mapstruct.ReportingPolicy;
7+
import org.mapstruct.factory.Mappers;
8+
9+
import java.util.List;
10+
11+
@Mapper(unmappedTargetPolicy= ReportingPolicy.ERROR)
12+
public interface GreetingsMapper {
13+
14+
GreetingsMapper INSTANCE = Mappers.getMapper( GreetingsMapper.class);
15+
16+
Message greetingToMessage(Greeting greeting);
17+
List<Message> greetingsToMessages(List<Greeting> greetings);
18+
Greeting messageToGreeting(Message message);
19+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.backbase.example.repository;
2+
3+
import com.backbase.example.domain.Greeting;
4+
import org.springframework.data.repository.CrudRepository;
5+
import org.springframework.stereotype.Repository;
6+
7+
import java.util.List;
8+
9+
@Repository
10+
public interface GreetingsRepository extends CrudRepository<Greeting, String> {
11+
12+
@Override
13+
List<Greeting> findAll();
14+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.backbase.example.service;
2+
3+
import com.backbase.example.domain.Greeting;
4+
5+
import java.util.List;
6+
7+
public interface GreetingsService {
8+
9+
List<Greeting> getGreetings();
10+
11+
Greeting getGreetingById(String id);
12+
13+
void addNewGreeting(Greeting greeting);
14+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package com.backbase.example.service;
2+
3+
import com.backbase.example.domain.Greeting;
4+
import com.backbase.example.repository.GreetingsRepository;
5+
import org.slf4j.Logger;
6+
import org.slf4j.LoggerFactory;
7+
import org.springframework.beans.factory.annotation.Autowired;
8+
import org.springframework.security.access.prepost.PreAuthorize;
9+
import org.springframework.stereotype.Service;
10+
11+
import java.util.List;
12+
import org.springframework.transaction.annotation.Transactional;
13+
14+
@Service
15+
@Transactional(readOnly=true)
16+
public class GreetingsServiceImpl implements GreetingsService {
17+
18+
private static final Logger log = LoggerFactory.getLogger(GreetingsServiceImpl.class);
19+
20+
@Autowired
21+
private GreetingsRepository greetingsRepository;
22+
23+
@Override
24+
@PreAuthorize("permitAll()")
25+
public List<Greeting> getGreetings() {
26+
log.debug("Service getGreetings is called {}", 1);
27+
return greetingsRepository.findAll();
28+
}
29+
30+
@Override
31+
@PreAuthorize("permitAll()")
32+
public Greeting getGreetingById(String id) {
33+
log.debug("Service getGreetingById is called {}", id);
34+
return greetingsRepository.findById(id).get();
35+
}
36+
37+
@Override
38+
@PreAuthorize("permitAll()")
39+
@Transactional
40+
public void addNewGreeting(Greeting greeting) {
41+
log.debug("Service addNewGreeting is called {}", 1);
42+
greetingsRepository.save(greeting);
43+
}
44+
}

0 commit comments

Comments
 (0)