Skip to content

Commit 97c2b87

Browse files
authored
Initial check-in CBv2 with Spring 3 (#734)
1 parent 20c81f6 commit 97c2b87

Some content is hidden

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

47 files changed

+2137
-0
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Cloudbank Version 2 Spring Boot 3.1.x
2+
3+
This version of Cloudbank uses Spring Boot version 3.1.x and Spring Cloud 2022.0.4
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!-- Copyright (c) 2023, Oracle and/or its affiliates. -->
3+
<!-- Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/ -->
4+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
6+
<modelVersion>4.0.0</modelVersion>
7+
8+
<parent>
9+
<groupId>com.example</groupId>
10+
<artifactId>sample-spring-apps</artifactId>
11+
<version>0.0.1-SNAPSHOT</version>
12+
</parent>
13+
14+
<artifactId>account</artifactId>
15+
<version>0.0.1-SNAPSHOT</version>
16+
<name>account</name>
17+
<description>Account Application</description>
18+
19+
<properties>
20+
<microprofile-lra-api.version>1.0</microprofile-lra-api.version>
21+
<narayana-lra.version>5.13.1.Final</narayana-lra.version>
22+
<jakarta.enterprise.cdi-api.version>2.0.2</jakarta.enterprise.cdi-api.version>
23+
<oracle-springboot-starter.version>3.1.0</oracle-springboot-starter.version>
24+
<liquibase.version>4.19.0</liquibase.version>
25+
</properties>
26+
27+
<dependencies>
28+
<dependency>
29+
<groupId>org.springframework.boot</groupId>
30+
<artifactId>spring-boot-starter-data-jpa</artifactId>
31+
</dependency>
32+
<dependency>
33+
<groupId>org.springframework.cloud</groupId>
34+
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
35+
<exclusions>
36+
<exclusion>
37+
<groupId>javax.ws.rs</groupId>
38+
<artifactId>jsr311-api</artifactId>
39+
</exclusion>
40+
<exclusion>
41+
<groupId>javax.servlet</groupId>
42+
<artifactId>servlet-api</artifactId>
43+
</exclusion>
44+
</exclusions>
45+
</dependency>
46+
<dependency>
47+
<groupId>org.springframework.boot</groupId>
48+
<artifactId>spring-boot-starter-jersey</artifactId>
49+
</dependency>
50+
<dependency>
51+
<groupId>com.oracle.database.spring</groupId>
52+
<artifactId>oracle-spring-boot-starter-ucp</artifactId>
53+
<version>${oracle-springboot-starter.version}</version>
54+
<type>pom</type>
55+
</dependency>
56+
<dependency>
57+
<groupId>com.oracle.database.spring</groupId>
58+
<artifactId>oracle-spring-boot-starter-wallet</artifactId>
59+
<version>${oracle-springboot-starter.version}</version>
60+
<type>pom</type>
61+
</dependency>
62+
<dependency>
63+
<groupId>org.liquibase</groupId>
64+
<artifactId>liquibase-core</artifactId>
65+
<version>${liquibase.version}</version>
66+
</dependency>
67+
<dependency>
68+
<groupId>org.eclipse.microprofile.lra</groupId>
69+
<artifactId>microprofile-lra-api</artifactId>
70+
<version>${microprofile-lra-api.version}</version>
71+
</dependency>
72+
<dependency>
73+
<groupId>org.jboss.narayana.rts</groupId>
74+
<artifactId>narayana-lra</artifactId>
75+
<version>${narayana-lra.version}</version>
76+
</dependency>
77+
<dependency>
78+
<groupId>jakarta.enterprise</groupId>
79+
<artifactId>jakarta.enterprise.cdi-api</artifactId>
80+
<version>${jakarta.enterprise.cdi-api.version}</version>
81+
</dependency>
82+
</dependencies>
83+
84+
<build>
85+
<plugins>
86+
<plugin>
87+
<groupId>org.springframework.boot</groupId>
88+
<artifactId>spring-boot-maven-plugin</artifactId>
89+
<configuration>
90+
<excludes>
91+
<exclude>
92+
<groupId>org.projectlombok</groupId>
93+
<artifactId>lombok</artifactId>
94+
</exclude>
95+
</excludes>
96+
</configuration>
97+
</plugin>
98+
<plugin>
99+
<groupId>org.liquibase</groupId>
100+
<artifactId>liquibase-maven-plugin</artifactId>
101+
</plugin>
102+
</plugins>
103+
</build>
104+
105+
</project>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright (c) 2023, Oracle and/or its affiliates.
2+
// Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/
3+
4+
package com.example.accounts;
5+
6+
import org.springframework.boot.SpringApplication;
7+
import org.springframework.boot.autoconfigure.SpringBootApplication;
8+
9+
@SpringBootApplication
10+
public class AccountsApplication {
11+
12+
public static void main(String[] args) {
13+
SpringApplication.run(AccountsApplication.class, args);
14+
}
15+
16+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Copyright (c) 2023, Oracle and/or its affiliates.
2+
// Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/
3+
4+
package com.example.accounts;
5+
6+
import java.net.URISyntaxException;
7+
import java.util.logging.Logger;
8+
9+
import org.springframework.beans.factory.annotation.Value;
10+
import org.springframework.context.annotation.Bean;
11+
import org.springframework.context.annotation.Configuration;
12+
13+
import io.narayana.lra.client.NarayanaLRAClient;
14+
15+
@Configuration
16+
public class ApplicationConfig {
17+
private static final Logger log = Logger.getLogger(ApplicationConfig.class.getName());
18+
19+
public ApplicationConfig(@Value("${lra.coordinator.url}") String lraCoordinatorUrl) {
20+
log.info(NarayanaLRAClient.LRA_COORDINATOR_URL_KEY + " = " + lraCoordinatorUrl);
21+
System.getProperties().setProperty(NarayanaLRAClient.LRA_COORDINATOR_URL_KEY, lraCoordinatorUrl);
22+
}
23+
24+
@Bean
25+
public NarayanaLRAClient NarayanaLRAClient() throws URISyntaxException {
26+
return new NarayanaLRAClient();
27+
}
28+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// Copyright (c) 2023, Oracle and/or its affiliates.
2+
// Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/
3+
4+
package com.example.accounts;
5+
6+
import javax.ws.rs.ApplicationPath;
7+
8+
import org.glassfish.hk2.utilities.binding.AbstractBinder;
9+
import org.glassfish.jersey.server.ResourceConfig;
10+
import org.glassfish.jersey.servlet.ServletProperties;
11+
import org.springframework.stereotype.Component;
12+
13+
import com.example.accounts.services.DepositService;
14+
import com.example.accounts.services.WithdrawService;
15+
16+
import io.narayana.lra.client.internal.proxy.nonjaxrs.LRAParticipantRegistry;
17+
18+
@Component
19+
@ApplicationPath("/")
20+
public class JerseyConfig extends ResourceConfig {
21+
22+
public JerseyConfig() {
23+
register(DepositService.class);
24+
register(WithdrawService.class);
25+
register(io.narayana.lra.filter.ServerLRAFilter.class);
26+
register(new AbstractBinder(){
27+
@Override
28+
protected void configure() {
29+
bind(LRAParticipantRegistry.class)
30+
.to(LRAParticipantRegistry.class);
31+
}
32+
});
33+
property(ServletProperties.FILTER_FORWARD_ON_404, true);
34+
}
35+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
// Copyright (c) 2023, Oracle and/or its affiliates.
2+
// Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/
3+
4+
package com.example.accounts.controller;
5+
6+
import org.springframework.web.bind.annotation.GetMapping;
7+
import org.springframework.web.bind.annotation.RequestMapping;
8+
import org.springframework.web.bind.annotation.RestController;
9+
import com.example.accounts.repository.AccountRepository;
10+
import com.example.accounts.repository.JournalRepository;
11+
import java.util.List;
12+
import com.example.accounts.model.Account;
13+
import com.example.accounts.model.Journal;
14+
import org.springframework.web.bind.annotation.PostMapping;
15+
import org.springframework.web.bind.annotation.RequestBody;
16+
import org.springframework.http.HttpStatus;
17+
import org.springframework.http.ResponseEntity;
18+
import org.springframework.web.bind.annotation.PathVariable;
19+
import java.util.ArrayList;
20+
import java.util.Optional;
21+
import org.springframework.web.bind.annotation.DeleteMapping;
22+
23+
@RestController
24+
@RequestMapping("/api/v1")
25+
public class AccountController {
26+
27+
final AccountRepository accountRepository;
28+
final JournalRepository journalRepository;
29+
30+
@GetMapping("/hello")
31+
public String ping() {
32+
return "Hello from Spring Boot";
33+
}
34+
35+
public AccountController(AccountRepository accountRepository, JournalRepository journalRepository) {
36+
this.accountRepository = accountRepository;
37+
this.journalRepository = journalRepository;
38+
}
39+
40+
@GetMapping("/accounts")
41+
public List<Account> getAllAccounts() {
42+
return accountRepository.findAll();
43+
}
44+
45+
@PostMapping("/account")
46+
public ResponseEntity<Account> createAccount(@RequestBody Account account) {
47+
try {
48+
Account _account = accountRepository.saveAndFlush(account);
49+
return new ResponseEntity<>(_account, HttpStatus.CREATED);
50+
} catch (Exception e) {
51+
return new ResponseEntity<>(null, HttpStatus.INTERNAL_SERVER_ERROR);
52+
}
53+
}
54+
55+
@GetMapping("/account/{accountId}")
56+
public ResponseEntity<Account> getAccountById(@PathVariable("accountId") long accountId) {
57+
Optional<Account> accountData = accountRepository.findById(accountId);
58+
try {
59+
return accountData.map(account -> new ResponseEntity<>(account, HttpStatus.OK))
60+
.orElseGet(() -> new ResponseEntity<>(HttpStatus.NOT_FOUND));
61+
} catch (Exception e) {
62+
return new ResponseEntity<>(null, HttpStatus.INTERNAL_SERVER_ERROR);
63+
}
64+
}
65+
66+
@GetMapping("/account/getAccounts/{customerId}")
67+
public ResponseEntity<List<Account>> getAccountsByCustomerId(@PathVariable("customerId") String customerId) {
68+
try {
69+
List<Account> accountData = new ArrayList<Account>();
70+
accountData.addAll(accountRepository.findByAccountCustomerId(customerId));
71+
if (accountData.isEmpty()) {
72+
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
73+
}
74+
return new ResponseEntity<>(accountData, HttpStatus.OK);
75+
} catch (Exception e) {
76+
return new ResponseEntity<>(null, HttpStatus.INTERNAL_SERVER_ERROR);
77+
}
78+
}
79+
80+
@DeleteMapping("/account/{accountId}")
81+
public ResponseEntity<HttpStatus> deleteAccount(@PathVariable("accountId") long accountId) {
82+
try {
83+
accountRepository.deleteById(accountId);
84+
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
85+
} catch (Exception e) {
86+
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
87+
}
88+
}
89+
90+
@GetMapping("/account/{accountId}/transactions")
91+
public ResponseEntity<List<Journal>> getTransactions(@PathVariable("accountId") long accountId) {
92+
try {
93+
List<Journal> transactions = new ArrayList<Journal>();
94+
transactions.addAll(journalRepository.findByAccountId(accountId));
95+
if (transactions.isEmpty()) {
96+
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
97+
}
98+
return new ResponseEntity<>(transactions, HttpStatus.OK);
99+
} catch (Exception e) {
100+
return new ResponseEntity<>(null, HttpStatus.INTERNAL_SERVER_ERROR);
101+
}
102+
}
103+
104+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// Copyright (c) 2023, Oracle and/or its affiliates.
2+
// Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/
3+
4+
package com.example.accounts.model;
5+
6+
import jakarta.persistence.Entity;
7+
import jakarta.persistence.Table;
8+
import lombok.Data;
9+
import lombok.NoArgsConstructor;
10+
import jakarta.persistence.Column;
11+
import jakarta.persistence.GeneratedValue;
12+
import jakarta.persistence.GenerationType;
13+
import jakarta.persistence.Id;
14+
15+
@Data
16+
@NoArgsConstructor
17+
@Entity
18+
@Table(name = "ACCOUNTS")
19+
public class Account {
20+
21+
@Id
22+
@GeneratedValue(strategy = GenerationType.IDENTITY)
23+
@Column(name = "ACCOUNT_ID")
24+
private long accountId;
25+
26+
@Column(name = "ACCOUNT_NAME")
27+
private String accountName;
28+
29+
@Column(name = "ACCOUNT_TYPE")
30+
private String accountType;
31+
32+
@Column(name = "CUSTOMER_ID")
33+
private String accountCustomerId;
34+
35+
@Column(name = "ACCOUNT_OTHER_DETAILS")
36+
private String accountOtherDetails;
37+
38+
@Column(name = "ACCOUNT_BALANCE")
39+
private long accountBalance;
40+
41+
public Account(String accountName, String accountType, String accountOtherDetails, String accountCustomerId) {
42+
this.accountName = accountName;
43+
this.accountType = accountType;
44+
this.accountOtherDetails = accountOtherDetails;
45+
this.accountCustomerId = accountCustomerId;
46+
}
47+
}

0 commit comments

Comments
 (0)