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 .github/workflows/secrets.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ jobs:
with:
args: -O .rules.toml https://raw.githubusercontent.com/fnxpt/gitleaks-action/rules/.rules.toml
- name: gitleaks-action
uses: zricethezav/gitleaks-action@master
uses: gitleaks/gitleaks-action@v1.6.0
with:
config-path: .rules.toml
3 changes: 3 additions & 0 deletions service-sdk/15.0.0/add-persistence-to-service/README.md
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)
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
target
.idea
*.iml
blackduck-scan-wars/hub-detect.sh
*.springBeans
/flaws.json
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.war`

## Authorization

Requests to this service are authorized with a Backbase Internal JWT, therefore you must access this service via the Backbase Gateway after authenticating with the authentication 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.
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?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>15.0.1</version>
<relativePath />
</parent>

<groupId>com.backbase.example</groupId>
<artifactId>example-persistence-service</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>war</packaging>
<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>1.4.200</version>
<scope>test</scope>
</dependency>
<!-- Required for MySql -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</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>
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);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package com.backbase.example;

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[]
}
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 javax.annotation.Generated;
import javax.validation.constraints.NotNull;
import javax.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;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.backbase.example.domain;

import javax.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;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.backbase.example.mapper;

import com.backbase.example.Message;
import com.backbase.example.domain.Greeting;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;

import java.util.List;

@Mapper
public interface GreetingsMapper {

GreetingsMapper INSTANCE = Mappers.getMapper( GreetingsMapper.class);

Message greetingToMessage(Greeting greeting);
List<Message> greetingsToMessages(List<Greeting> greetings);
Greeting messageToGreeting(Message message);
}
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();
}
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);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.backbase.example.service;

import com.backbase.example.domain.Greeting;
import com.backbase.example.repository.GreetingsRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class GreetingsServiceImpl implements GreetingsService {

@Autowired
private GreetingsRepository greetingsRepository;

@Override
public List<Greeting> getGreetings() {
return greetingsRepository.findAll();
}

@Override
public Greeting getGreetingById(String id) {
return greetingsRepository.findById(id).get();
}

@Override
public void addNewGreeting(Greeting greeting) {
greetingsRepository.save(greeting);
}
}
Loading