URL decode account key to prepare for account keys with spaces

Also extend DEBUG logging in controllers
This commit is contained in:
2019-05-11 23:44:48 +02:00
parent 4d192e30fa
commit 4e29ecff6a
3 changed files with 51 additions and 13 deletions

View File

@@ -10,6 +10,9 @@ import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import java.net.URLDecoder;
import java.nio.charset.StandardCharsets;
@RestController @RestController
@RequestMapping("accounts") @RequestMapping("accounts")
public class AccountController { public class AccountController {
@@ -21,7 +24,13 @@ public class AccountController {
@RequestMapping("getByKey") @RequestMapping("getByKey")
public Account getAccountByKey(String key) { public Account getAccountByKey(String key) {
return this.accountService.getAccountByKey(key); final String decoded = URLDecoder.decode(key, StandardCharsets.UTF_8);
if (LOGGER.isDebugEnabled()) {
LOGGER.debug(String.format("/accounts/getAccountByKey got parameter: %s", decoded));
}
return this.accountService.getAccountByKey(decoded);
} }
@RequestMapping("getAll") @RequestMapping("getAll")
@@ -31,11 +40,13 @@ public class AccountController {
@RequestMapping("createAccount") @RequestMapping("createAccount")
public ResponseEntity createAccount(String key, String type) { public ResponseEntity createAccount(String key, String type) {
final String decoded = URLDecoder.decode(key, StandardCharsets.UTF_8);
if (LOGGER.isDebugEnabled()) { if (LOGGER.isDebugEnabled()) {
LOGGER.debug(String.format("/accounts/createAccount got parameters: %s, %s", key, type)); LOGGER.debug(String.format("/accounts/createAccount got parameters: %s, %s", decoded, type));
} }
final ResponseReason responseReason = this.accountService.createAccount(key, type); final ResponseReason responseReason = this.accountService.createAccount(decoded, type);
if (LOGGER.isDebugEnabled()) { if (LOGGER.isDebugEnabled()) {
LOGGER.debug(String.format("/accounts/createAccount returns with %s", responseReason.name())); LOGGER.debug(String.format("/accounts/createAccount returns with %s", responseReason.name()));
@@ -46,11 +57,13 @@ public class AccountController {
@RequestMapping("closeAccount") @RequestMapping("closeAccount")
public ResponseEntity closeAccount(String key) { public ResponseEntity closeAccount(String key) {
final String decoded = URLDecoder.decode(key, StandardCharsets.UTF_8);
if (LOGGER.isDebugEnabled()) { if (LOGGER.isDebugEnabled()) {
LOGGER.debug(String.format("/accounts/closeAccount got parameters: %s", key)); LOGGER.debug(String.format("/accounts/closeAccount got parameters: %s", decoded));
} }
final ResponseReason responseReason = this.accountService.closeAccount(key); final ResponseReason responseReason = this.accountService.closeAccount(decoded);
if (LOGGER.isDebugEnabled()) { if (LOGGER.isDebugEnabled()) {
LOGGER.debug(String.format("/accounts/closeAccount returns with %s", responseReason.name())); LOGGER.debug(String.format("/accounts/closeAccount returns with %s", responseReason.name()));
@@ -61,11 +74,13 @@ public class AccountController {
@RequestMapping("openAccount") @RequestMapping("openAccount")
public ResponseEntity openAccount(String key) { public ResponseEntity openAccount(String key) {
final String decoded = URLDecoder.decode(key, StandardCharsets.UTF_8);
if (LOGGER.isDebugEnabled()) { if (LOGGER.isDebugEnabled()) {
LOGGER.debug(String.format("/accounts/openAccount got parameters: %s", key)); LOGGER.debug(String.format("/accounts/openAccount got parameters: %s", decoded));
} }
final ResponseReason responseReason = this.accountService.openAccount(key); final ResponseReason responseReason = this.accountService.openAccount(decoded);
if (LOGGER.isDebugEnabled()) { if (LOGGER.isDebugEnabled()) {
LOGGER.debug(String.format("/accounts/openAccount returns with %s", responseReason.name())); LOGGER.debug(String.format("/accounts/openAccount returns with %s", responseReason.name()));

View File

@@ -10,6 +10,8 @@ import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import java.net.URLDecoder;
import java.nio.charset.StandardCharsets;
import java.util.Optional; import java.util.Optional;
@RestController @RestController
@@ -33,7 +35,13 @@ public class RecurringTransactionController {
@RequestMapping("getAllForAccount") @RequestMapping("getAllForAccount")
public Iterable<RecurringTransaction> getAllForAccount(String accountKey) { public Iterable<RecurringTransaction> getAllForAccount(String accountKey) {
return this.recurringTransactionService.getAllForAccount(accountKey); final String decoded = URLDecoder.decode(accountKey, StandardCharsets.UTF_8);
if (LOGGER.isDebugEnabled()) {
LOGGER.debug(String.format("/recurringTransactions/getAllForAccount got parameter: %s", decoded));
}
return this.recurringTransactionService.getAllForAccount(decoded);
} }
@RequestMapping("getAllDueToday") @RequestMapping("getAllDueToday")
@@ -47,15 +55,18 @@ public class RecurringTransactionController {
String intervalType, String firstOccurrence, String intervalType, String firstOccurrence,
String lastOccurrence String lastOccurrence
) { ) {
final String decodedFrom = URLDecoder.decode(fromAccountKey, StandardCharsets.UTF_8);
final String decodedTo = URLDecoder.decode(toAccountKey, StandardCharsets.UTF_8);
if (LOGGER.isDebugEnabled()) { if (LOGGER.isDebugEnabled()) {
LOGGER.debug(String LOGGER.debug(String
.format("/recurringTransactions/createRecurringTransaction got parameters: %s, %s, %s, %s, %s, " + .format("/recurringTransactions/createRecurringTransaction got parameters: %s, %s, %s, %s, %s, " +
"%s, %s, %s", fromAccountKey, toAccountKey, amount, description, holidayWeekendType, "%s, %s, %s", decodedFrom, decodedTo, amount, description, holidayWeekendType,
intervalType, firstOccurrence, lastOccurrence)); intervalType, firstOccurrence, lastOccurrence));
} }
final ResponseReason responseReason = this.recurringTransactionService final ResponseReason responseReason = this.recurringTransactionService
.createRecurringTransaction(fromAccountKey, toAccountKey, amount, description, holidayWeekendType, .createRecurringTransaction(decodedFrom, decodedTo, amount, description, holidayWeekendType,
intervalType, firstOccurrence, lastOccurrence); intervalType, firstOccurrence, lastOccurrence);
if (LOGGER.isDebugEnabled()) { if (LOGGER.isDebugEnabled()) {

View File

@@ -10,6 +10,9 @@ import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import java.net.URLDecoder;
import java.nio.charset.StandardCharsets;
@RestController @RestController
@RequestMapping("transactions") @RequestMapping("transactions")
public class TransactionController { public class TransactionController {
@@ -25,21 +28,30 @@ public class TransactionController {
@RequestMapping("getAllForAccount") @RequestMapping("getAllForAccount")
public Iterable<Transaction> getAllForAccount(String accountKey) { public Iterable<Transaction> getAllForAccount(String accountKey) {
return this.transactionService.getAllForAccount(accountKey); final String decoded = URLDecoder.decode(accountKey, StandardCharsets.UTF_8);
if (LOGGER.isDebugEnabled()) {
LOGGER.debug(String.format("/transactions/getAllForAccount got parameter: %s", decoded));
}
return this.transactionService.getAllForAccount(decoded);
} }
@RequestMapping(value = "createTransaction") @RequestMapping(value = "createTransaction")
public ResponseEntity createTransaction(String fromAccountKey, String toAccountKey, Long amount, String date, public ResponseEntity createTransaction(String fromAccountKey, String toAccountKey, Long amount, String date,
String description String description
) { ) {
final String decodedFrom = URLDecoder.decode(fromAccountKey, StandardCharsets.UTF_8);
final String decodedTo = URLDecoder.decode(toAccountKey, StandardCharsets.UTF_8);
if (LOGGER.isDebugEnabled()) { if (LOGGER.isDebugEnabled()) {
LOGGER.debug(String LOGGER.debug(String
.format("/transactions/createTransaction got parameters: %s, %s, %s, %s, %s", .format("/transactions/createTransaction got parameters: %s, %s, %s, %s, %s",
fromAccountKey, toAccountKey, amount, date, description)); decodedFrom, decodedTo, amount, date, description));
} }
final ResponseReason responseReason = this.transactionService final ResponseReason responseReason = this.transactionService
.createTransaction(fromAccountKey, toAccountKey, amount, date, description); .createTransaction(decodedFrom, decodedTo, amount, date, description);
if (LOGGER.isDebugEnabled()) { if (LOGGER.isDebugEnabled()) {
LOGGER.debug(String.format("/transactions/createTransaction returns with %s", responseReason.name())); LOGGER.debug(String.format("/transactions/createTransaction returns with %s", responseReason.name()));