-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
121 changed files
with
4,105 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
This project contains code samples documented in the following section in [Backbase Community](https://community.backbase.com/documentation/ServiceSDK/latest/index): | ||
|
||
* [Add persistence to your capability](https://community.backbase.com/documentation/ServiceSDK/latest/add_persistence_to_core_service) |
25 changes: 25 additions & 0 deletions
25
...ice-sdk/18.0.0/add-persistence-to-service/example-persistence-service/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# example-service | ||
|
||
_Fill out this file with some information about your Service._ | ||
|
||
## Dependencies | ||
|
||
Requires a running Eureka registry, by default on port 8080. | ||
|
||
## Configuration | ||
|
||
Service configuration is under `src/main/resources/application.yaml`. | ||
|
||
## Running | ||
|
||
To run the service in development mode, use: | ||
- `mvn spring-boot:run` | ||
|
||
To run the service from the built binaries, use: | ||
- `java -jar target/example-persistence-service-1.0.0-SNAPSHOT.jar` | ||
|
||
## Authorization | ||
|
||
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. | ||
|
||
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. |
76 changes: 76 additions & 0 deletions
76
service-sdk/18.0.0/add-persistence-to-service/example-persistence-service/pom.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<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"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<!-- The simplest way to build a service with service-sdk-starter-core | ||
is to use it as a parent in your project’s POM file, and alternative If you | ||
don’t want to use service-sdk-starter-core as your project’s parent, you | ||
can declare it as a dependency instead, see pom-as-dependency.xml --> | ||
<parent> | ||
<artifactId>service-sdk-starter-core</artifactId> | ||
<groupId>com.backbase.buildingblocks</groupId> | ||
<version>16.0.0</version> | ||
<relativePath /> | ||
</parent> | ||
|
||
<groupId>com.backbase.example</groupId> | ||
<artifactId>example-persistence-service</artifactId> | ||
<version>1.0.0-SNAPSHOT</version> | ||
<name>Backbase :: Digital Banking Services :: example-persistence-service</name> | ||
|
||
<properties> | ||
<java.version>17</java.version> | ||
</properties> | ||
|
||
<dependencies> | ||
<!-- tag::persistence-dependencies[] --> | ||
<!--Added for persistence --> | ||
<dependency> | ||
<groupId>com.backbase.buildingblocks</groupId> | ||
<artifactId>persistence</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.backbase.buildingblocks</groupId> | ||
<artifactId>service-sdk-starter-mapping</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-cache</artifactId> | ||
</dependency> | ||
<!-- Required for Local testing --> | ||
<dependency> | ||
<groupId>com.h2database</groupId> | ||
<artifactId>h2</artifactId> | ||
<version>2.1.214</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<!-- Required for MySql --> | ||
<dependency> | ||
<groupId>com.mysql</groupId> | ||
<artifactId>mysql-connector-j</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<!-- end::persistence-dependencies[] --> | ||
|
||
<dependency> | ||
<groupId>com.backbase.buildingblocks</groupId> | ||
<artifactId>service-sdk-starter-test</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<!-- Add dependencies for your services, e.g. BB specifications, integration clients --> | ||
|
||
<!-- Uncomment the following dependencies if DBS inter-service communication is needed --> | ||
<!-- | ||
<dependency> | ||
<groupId>com.backbase.buildingblocks</groupId> | ||
<artifactId>communication</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.backbase.buildingblocks</groupId> | ||
<artifactId>auth-security</artifactId> | ||
</dependency> | ||
--> | ||
</dependencies> | ||
|
||
</project> |
21 changes: 21 additions & 0 deletions
21
...o-service/example-persistence-service/src/main/java/com/backbase/example/Application.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.backbase.example; | ||
|
||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.domain.EntityScan; | ||
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; | ||
import org.springframework.cloud.client.discovery.EnableDiscoveryClient; | ||
import org.springframework.data.jpa.repository.config.EnableJpaRepositories; | ||
|
||
// tag::application-annotations[] | ||
@SpringBootApplication | ||
@EnableDiscoveryClient | ||
@EnableJpaRepositories | ||
@EntityScan | ||
public class Application extends SpringBootServletInitializer { | ||
// end::application-annotations[] | ||
public static void main(final String[] args) { | ||
SpringApplication.run(Application.class, args); | ||
} | ||
|
||
} |
61 changes: 61 additions & 0 deletions
61
...ce-to-service/example-persistence-service/src/main/java/com/backbase/example/Message.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package com.backbase.example; | ||
|
||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; | ||
import com.fasterxml.jackson.annotation.JsonInclude; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import com.fasterxml.jackson.annotation.JsonPropertyOrder; | ||
|
||
import jakarta.annotation.Generated; | ||
import jakarta.validation.constraints.NotNull; | ||
import jakarta.validation.constraints.Size; | ||
|
||
@JsonInclude(JsonInclude.Include.NON_NULL) | ||
@Generated("org.jsonschema2pojo") | ||
@JsonPropertyOrder({ | ||
"message" | ||
}) | ||
@JsonIgnoreProperties(ignoreUnknown = true) | ||
public class Message { | ||
|
||
/** | ||
* | ||
* (Required) | ||
* | ||
*/ | ||
@JsonProperty("id") | ||
@NotNull | ||
private String id; | ||
|
||
/** | ||
* Greetings message | ||
*/ | ||
@JsonProperty("message") | ||
@Size(max = 255) | ||
@NotNull | ||
private String message; | ||
|
||
public Message() { | ||
} | ||
|
||
public Message(String id, String message) { | ||
this.id = id; | ||
this.message = message; | ||
} | ||
|
||
public String getId() { | ||
return id; | ||
} | ||
|
||
public void setId(String id) { | ||
this.id = id; | ||
} | ||
|
||
public String getMessage() { | ||
return message; | ||
} | ||
|
||
public void setMessage(String message) { | ||
this.message = message; | ||
} | ||
|
||
} |
48 changes: 48 additions & 0 deletions
48
...example-persistence-service/src/main/java/com/backbase/example/api/ExampleController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package com.backbase.example.api; | ||
|
||
import com.backbase.example.Message; | ||
import com.backbase.example.domain.Greeting; | ||
import com.backbase.example.mapper.GreetingsMapper; | ||
import com.backbase.example.service.GreetingsService; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
import java.util.List; | ||
import java.util.UUID; | ||
|
||
@RestController | ||
public class ExampleController { | ||
|
||
@Autowired | ||
private GreetingsService greetingsService; | ||
|
||
@RequestMapping(method = RequestMethod.GET, value = "/message/{id}", produces = { | ||
"application/json" | ||
}) | ||
@ResponseStatus(HttpStatus.OK) | ||
public Message getMessage(@PathVariable(name = "id") String id) { | ||
Greeting greeting = greetingsService.getGreetingById(id); | ||
return GreetingsMapper.INSTANCE.greetingToMessage(greeting); | ||
} | ||
|
||
@RequestMapping(method = RequestMethod.GET, value = "/messages", produces = { | ||
"application/json" | ||
}) | ||
@ResponseStatus(HttpStatus.OK) | ||
public List<Message> getMessages() { | ||
List<Greeting> greetings = greetingsService.getGreetings(); | ||
return GreetingsMapper.INSTANCE.greetingsToMessages(greetings); | ||
} | ||
// tag::addMessage[] | ||
@RequestMapping(method = RequestMethod.POST, value = "/message") | ||
@ResponseStatus(HttpStatus.CREATED) | ||
public String addMessage(@RequestBody Message message) { | ||
Greeting greeting = GreetingsMapper.INSTANCE.messageToGreeting(message); | ||
String id = UUID.randomUUID().toString(); | ||
greeting.setId(id); | ||
greetingsService.addNewGreeting(greeting); | ||
return id; | ||
} | ||
// end::addMessage[] | ||
} |
31 changes: 31 additions & 0 deletions
31
...rvice/example-persistence-service/src/main/java/com/backbase/example/domain/Greeting.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package com.backbase.example.domain; | ||
|
||
import jakarta.persistence.*; | ||
|
||
@Entity | ||
@Table(name = "greetings") | ||
public class Greeting { | ||
|
||
@Id | ||
@Column(name = "id") | ||
private String id; | ||
|
||
@Column(name = "message") | ||
private String message; | ||
|
||
public String getId() { | ||
return id; | ||
} | ||
|
||
public void setId(String id) { | ||
this.id = id; | ||
} | ||
|
||
public String getMessage() { | ||
return message; | ||
} | ||
|
||
public void setMessage(String message) { | ||
this.message = message; | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
...xample-persistence-service/src/main/java/com/backbase/example/mapper/GreetingsMapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.backbase.example.mapper; | ||
|
||
import com.backbase.example.Message; | ||
import com.backbase.example.domain.Greeting; | ||
import org.mapstruct.Mapper; | ||
import org.mapstruct.ReportingPolicy; | ||
import org.mapstruct.factory.Mappers; | ||
|
||
import java.util.List; | ||
|
||
@Mapper(unmappedTargetPolicy= ReportingPolicy.ERROR) | ||
public interface GreetingsMapper { | ||
|
||
GreetingsMapper INSTANCE = Mappers.getMapper( GreetingsMapper.class); | ||
|
||
Message greetingToMessage(Greeting greeting); | ||
List<Message> greetingsToMessages(List<Greeting> greetings); | ||
Greeting messageToGreeting(Message message); | ||
} |
14 changes: 14 additions & 0 deletions
14
...ersistence-service/src/main/java/com/backbase/example/repository/GreetingsRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.backbase.example.repository; | ||
|
||
import com.backbase.example.domain.Greeting; | ||
import org.springframework.data.repository.CrudRepository; | ||
import org.springframework.stereotype.Repository; | ||
|
||
import java.util.List; | ||
|
||
@Repository | ||
public interface GreetingsRepository extends CrudRepository<Greeting, String> { | ||
|
||
@Override | ||
List<Greeting> findAll(); | ||
} |
14 changes: 14 additions & 0 deletions
14
...mple-persistence-service/src/main/java/com/backbase/example/service/GreetingsService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.backbase.example.service; | ||
|
||
import com.backbase.example.domain.Greeting; | ||
|
||
import java.util.List; | ||
|
||
public interface GreetingsService { | ||
|
||
List<Greeting> getGreetings(); | ||
|
||
Greeting getGreetingById(String id); | ||
|
||
void addNewGreeting(Greeting greeting); | ||
} |
44 changes: 44 additions & 0 deletions
44
...-persistence-service/src/main/java/com/backbase/example/service/GreetingsServiceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package com.backbase.example.service; | ||
|
||
import com.backbase.example.domain.Greeting; | ||
import com.backbase.example.repository.GreetingsRepository; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.security.access.prepost.PreAuthorize; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.util.List; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Service | ||
@Transactional(readOnly=true) | ||
public class GreetingsServiceImpl implements GreetingsService { | ||
|
||
private static final Logger log = LoggerFactory.getLogger(GreetingsServiceImpl.class); | ||
|
||
@Autowired | ||
private GreetingsRepository greetingsRepository; | ||
|
||
@Override | ||
@PreAuthorize("permitAll()") | ||
public List<Greeting> getGreetings() { | ||
log.debug("Service getGreetings is called {}", 1); | ||
return greetingsRepository.findAll(); | ||
} | ||
|
||
@Override | ||
@PreAuthorize("permitAll()") | ||
public Greeting getGreetingById(String id) { | ||
log.debug("Service getGreetingById is called {}", id); | ||
return greetingsRepository.findById(id).get(); | ||
} | ||
|
||
@Override | ||
@PreAuthorize("permitAll()") | ||
@Transactional | ||
public void addNewGreeting(Greeting greeting) { | ||
log.debug("Service addNewGreeting is called {}", 1); | ||
greetingsRepository.save(greeting); | ||
} | ||
} |
Oops, something went wrong.