Skip to content

Commit

Permalink
Upgrade Cloudbank to SB 32 (#800)
Browse files Browse the repository at this point in the history
* springboot 3.2 initial commit

* spingboot 3.2 initial commit

* minimal changes

* minimal changes

* springboot 3.2 initial commit

* spingboot 3.2 initial commit

* minimal changes

* minimal changes
  • Loading branch information
andytael authored Dec 18, 2023
1 parent 56cdbc9 commit 7279cd3
Show file tree
Hide file tree
Showing 89 changed files with 6,039 additions and 0 deletions.
575 changes: 575 additions & 0 deletions cloudbank-v32/README.md

Large diffs are not rendered by default.

329 changes: 329 additions & 0 deletions cloudbank-v32/account/checkstyle/checkstyle.xml

Large diffs are not rendered by default.

13 changes: 13 additions & 0 deletions cloudbank-v32/account/checkstyle/suppressions.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0"?>

<!DOCTYPE suppressions PUBLIC
"-//Puppy Crawl//DTD Suppressions 1.1//EN"
"http://www.puppycrawl.com/dtds/suppressions_1_1.dtd">

<suppressions>
<!-- There's nothing wrong with these - ignore them b/c they generate noise -->
<suppress checks="AbbreviationAsWordInName" files=".*"/>
<suppress checks="MemberNameCheck" files=".*"/>
<suppress checks="VariableDeclarationUsageDistanceCheck" files=".*"/>
<suppress checks="AbbreviationAsWordInNameCheck" files=".*"/>
</suppressions>
3 changes: 3 additions & 0 deletions cloudbank-v32/account/dependency-check/suppressions.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?xml version="1.0" encoding="UTF-8"?>
<suppressions xmlns="https://jeremylong.github.io/DependencyCheck/dependency-suppression.1.3.xsd">
</suppressions>
76 changes: 76 additions & 0 deletions cloudbank-v32/account/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Copyright (c) 2023, Oracle and/or its affiliates. -->
<!-- Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/ -->
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>com.example</groupId>
<artifactId>sample-spring-apps</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>

<artifactId>account</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>account</name>
<description>Account Application</description>

<properties>
<oracle-springboot-starter.version>23.4.0</oracle-springboot-starter.version>
<liquibase.version>4.24.0</liquibase.version>
</properties>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>com.oracle.database.spring</groupId>
<artifactId>oracle-spring-boot-starter-ucp</artifactId>
<version>${oracle-springboot-starter.version}</version>
<type>pom</type>
</dependency>
<dependency>
<groupId>com.oracle.database.spring</groupId>
<artifactId>oracle-spring-boot-starter-wallet</artifactId>
<version>${oracle-springboot-starter.version}</version>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-core</artifactId>
<version>${liquibase.version}</version>
</dependency>
<dependency>
<groupId>com.oracle.microtx.lra</groupId>
<artifactId>microtx-lra-spring-boot-starter</artifactId>
<version>23.4.1</version>
</dependency>
<dependency>
<groupId>jakarta.inject</groupId>
<artifactId>jakarta.inject-api</artifactId>
<version>2.0.1</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.graalvm.buildtools</groupId>
<artifactId>native-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-maven-plugin</artifactId>
<version>${liquibase.version}</version>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright (c) 2023, Oracle and/or its affiliates.
// Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/

package com.example.accounts;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class AccountsApplication {

public static void main(String[] args) {
SpringApplication.run(AccountsApplication.class, args);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
// Copyright (c) 2023, Oracle and/or its affiliates.
// Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/

package com.example.accounts.controller;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

import com.example.accounts.model.Account;
import com.example.accounts.model.Journal;
import com.example.accounts.repository.AccountRepository;
import com.example.accounts.repository.JournalRepository;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/v1")
public class AccountController {

final AccountRepository accountRepository;
final JournalRepository journalRepository;

public AccountController(AccountRepository accountRepository, JournalRepository journalRepository) {
this.accountRepository = accountRepository;
this.journalRepository = journalRepository;
}

/**
* Get all Accounts.
* @return List off accounts
*/
@GetMapping("/accounts")
public List<Account> getAllAccounts() {
return accountRepository.findAll();
}

/**
* Create an account.
* @param account Account object
* @return Http Status Code
*/
@PostMapping("/account")
public ResponseEntity<Account> createAccount(@RequestBody Account account) {
try {
Account newAccount = accountRepository.saveAndFlush(account);
return new ResponseEntity<>(newAccount, HttpStatus.CREATED);
} catch (Exception e) {
return new ResponseEntity<>(null, HttpStatus.INTERNAL_SERVER_ERROR);
}
}

/**
* Find an account by Account Id.
* @param accountId Account Id
* @return An account
*/
@GetMapping("/account/{accountId}")
public ResponseEntity<Account> getAccountById(@PathVariable("accountId") long accountId) {
Optional<Account> accountData = accountRepository.findById(accountId);
try {
return accountData.map(account -> new ResponseEntity<>(account, HttpStatus.OK))
.orElseGet(() -> new ResponseEntity<>(HttpStatus.NOT_FOUND));
} catch (Exception e) {
return new ResponseEntity<>(null, HttpStatus.INTERNAL_SERVER_ERROR);
}
}

/**
* Find an account by customer Id.
* @param customerId Customer Id
* @return A list opf Account(s)
*/
@GetMapping("/account/getAccounts/{customerId}")
public ResponseEntity<List<Account>> getAccountsByCustomerId(@PathVariable("customerId") String customerId) {
try {
List<Account> accountData = new ArrayList<Account>();
accountData.addAll(accountRepository.findByAccountCustomerId(customerId));
if (accountData.isEmpty()) {
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
}
return new ResponseEntity<>(accountData, HttpStatus.OK);
} catch (Exception e) {
return new ResponseEntity<>(null, HttpStatus.INTERNAL_SERVER_ERROR);
}
}

/**
* Delete an Account with specific Id.
* @param accountId Account ID
* @return HTTP Status Code
*/
@DeleteMapping("/account/{accountId}")
public ResponseEntity<HttpStatus> deleteAccount(@PathVariable("accountId") long accountId) {
try {
accountRepository.deleteById(accountId);
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
} catch (Exception e) {
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
}
}

/**
* Get transactions (Journal) for an Account Id.
* @param accountId Account Id
* @return List of Journal object(s)
*/
@GetMapping("/account/{accountId}/transactions")
public ResponseEntity<List<Journal>> getTransactions(@PathVariable("accountId") long accountId) {
try {
List<Journal> transactions = new ArrayList<Journal>();
transactions.addAll(journalRepository.findByAccountId(accountId));
if (transactions.isEmpty()) {
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
}
return new ResponseEntity<>(transactions, HttpStatus.OK);
} catch (Exception e) {
return new ResponseEntity<>(null, HttpStatus.INTERNAL_SERVER_ERROR);
}
}

/**
* Create a Journal entry.
* @param journalEntry Journal object
* @return HTTP Status Code
*/
@PostMapping("/account/journal")
public ResponseEntity<Journal> postSimpleJournalEntry(@RequestBody Journal journalEntry) {
try {
Journal newJournalEntry = journalRepository.saveAndFlush(journalEntry);
return new ResponseEntity<>(newJournalEntry, HttpStatus.CREATED);
} catch (Exception e) {
return new ResponseEntity<>(null, HttpStatus.INTERNAL_SERVER_ERROR);
}
}

/**
* Find Journal entries by Account Id.
* @param accountId Account Id
* @return Journal object(s)
*/
@GetMapping("/account/{accountId}/journal")
public List<Journal> getJournalEntriesForAccount(@PathVariable("accountId") long accountId) {
return journalRepository.findJournalByAccountId(accountId);
}

/**
* Clears the Journal Entry.
* @param journalId Journal Id
* @return HTTP Status Code
*/
@PostMapping("/account/journal/{journalId}/clear")
public ResponseEntity<Journal> clearJournalEntry(@PathVariable long journalId) {
try {
Optional<Journal> data = journalRepository.findById(journalId);
if (data.isPresent()) {
Journal newJournalEntry = data.get();
newJournalEntry.setJournalType("DEPOSIT");
journalRepository.saveAndFlush(newJournalEntry);
return new ResponseEntity<Journal>(newJournalEntry, HttpStatus.OK);
} else {
return new ResponseEntity<Journal>(new Journal(), HttpStatus.ACCEPTED);
}
} catch (Exception e) {
return new ResponseEntity<>(null, HttpStatus.INTERNAL_SERVER_ERROR);
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// Copyright (c) 2023, Oracle and/or its affiliates.
// Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/

package com.example.accounts.model;

import java.util.Date;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.Table;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.Generated;
import org.hibernate.annotations.GenerationTime;

@SuppressWarnings("deprecation") // TODO: Needs to be removed
@Data
@NoArgsConstructor
@Entity
@Table(name = "ACCOUNTS")
public class Account {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "ACCOUNT_ID")
private long accountId;

@Column(name = "ACCOUNT_NAME")
private String accountName;

@Column(name = "ACCOUNT_TYPE")
private String accountType;

@Column(name = "CUSTOMER_ID")
private String accountCustomerId;

@Generated(GenerationTime.INSERT)
@Column(name = "ACCOUNT_OPENED_DATE", updatable = false, insertable = false)
private Date accountOpenedDate;

@Column(name = "ACCOUNT_OTHER_DETAILS")
private String accountOtherDetails;

@Column(name = "ACCOUNT_BALANCE")
private long accountBalance;

/**
* Create Account object.
* @param accountName Account name
* @param accountType Account Type
* @param accountOtherDetails Other details about account
* @param accountCustomerId Account Customer ID
*/
public Account(String accountName, String accountType, String accountOtherDetails, String accountCustomerId) {
this.accountName = accountName;
this.accountType = accountType;
this.accountOtherDetails = accountOtherDetails;
this.accountCustomerId = accountCustomerId;
}
}
Loading

0 comments on commit 7279cd3

Please sign in to comment.