Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BEFOUND-1247 - Error object to have key field #93

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
3 changes: 3 additions & 0 deletions service-sdk/18.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,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.
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>
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,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;
}

}
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[]
}
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;
}
}
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);
}
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,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);
}
}
Loading
Loading