The AccountsResource class
This document will cover the class AccountsResource
- What
is and what it is used for.HBankDataAccess
- What
is and what it is used for.AccountsResource
- Variables and functions defined in
.AccountsResource
What is HBankDataAccess
HBankDataAccess
HBankDataAccess
Db2
What is AccountsResource
AccountsResource
AccountsResource
HBankDataAccess
Variables and functions
The constructor AccountsResource
public AccountsResource()
{
/**
* Constructor
*/
sortOutLogging();
}
The function createAccountExternal
createAccountInternal
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response createAccountExternal(AccountJSON account)
{
/**
* This method is called from OUTSIDE Liberty. We need to know in order
* to keep track of DB2 connections
*/
logger.entering(this.getClass().getName(),
CREATE_ACCOUNT_EXTERNAL + " for account " + account.toString());
Response myResponse = createAccountInternal(account);
HBankDataAccess myHBankDataAccess = new HBankDataAccess();
myHBankDataAccess.terminate();
logger.exiting(this.getClass().getName(), CREATE_ACCOUNT_EXTERNAL,
myResponse);
return myResponse;
The function createAccountInternal
public Response createAccountInternal(
/**
* Internal methods can be called by either the external methods, or
* another part of Liberty
*/
AccountJSON account)
{
logger.entering(this.getClass().getName(),
CREATE_ACCOUNT_INTERNAL + " for account " + account.toString());
Response myResponse = null;
JSONObject error = validateNewAccount(account);
if (error != null)
{
myResponse = Response.status(400).entity(error.toString()).build();
logger.exiting(this.getClass().getName(), CREATE_ACCOUNT_INTERNAL,
myResponse);
return myResponse;
}
The function getAccountExternal
getAccountInternal
@GET
@Path("/{accountNumber}")
@Produces("application/json")
public Response getAccountExternal(
@PathParam("accountNumber") Long accountNumber)
{
/** This will list one single account of the specified number. */
logger.entering(this.getClass().getName(),
"getAccountExternal(Long accountNumber)");
Response myResponse = getAccountInternal(accountNumber);
HBankDataAccess myHBankDataAccess = new HBankDataAccess();
myHBankDataAccess.terminate();
logger.exiting(this.getClass().getName(),
"getAccountExternal(Long accountNumber)", myResponse);
return myResponse;
}
The function getAccountInternal
public Response getAccountInternal(Long accountNumber)
{
/** This will list one single account of the specified number. */
logger.entering(this.getClass().getName(), GET_ACCOUNT_INTERNAL);
Response myResponse = null;
JSONObject response = new JSONObject();
Integer sortCode = this.getSortCode();
Long idSafe = accountNumber;
com.ibm.cics.cip.bankliberty.web.db2.Account db2Account = new Account();
db2Account = db2Account.getAccount(accountNumber.intValue(), sortCode);
if (db2Account != null)
{
response.put(JSON_SORT_CODE, db2Account.getSortcode().trim());
response.put("id", db2Account.getAccountNumber());
response.put(JSON_CUSTOMER_NUMBER, db2Account.getCustomerNumber());
response.put(JSON_ACCOUNT_TYPE, db2Account.getType().trim());
response.put(JSON_AVAILABLE_BALANCE,
The function getAccountsByCustomerExternal
getAccountsByCustomerInternal
@GET
@Path("/retrieveByCustomerNumber/{customerNumber}")
@Produces("application/json")
public Response getAccountsByCustomerExternal(
@PathParam(JSON_CUSTOMER_NUMBER) Long customerNumber,
@QueryParam("countOnly") Boolean countOnly)
{
/** This will list accounts owned by a specified customer */
logger.entering(this.getClass().getName(),
"getAccountsByCustomerExternal(Long customerNumber, Boolean countOnly)");
Response myResponse = getAccountsByCustomerInternal(customerNumber);
HBankDataAccess myHBankDataAccess = new HBankDataAccess();
myHBankDataAccess.terminate();
logger.exiting(this.getClass().getName(),
"getAccountsByCustomerExternal(Long customerNumber, Boolean countOnly)",
myResponse);
return myResponse;
}
The function getAccountsByCustomerInternal
public Response getAccountsByCustomerInternal(
@PathParam(JSON_CUSTOMER_NUMBER) Long customerNumber)
{
logger.entering(this.getClass().getName(),
GET_ACCOUNTS_BY_CUSTOMER_INTERNAL);
JSONArray accounts = null;
Response myResponse = null;
JSONObject response = new JSONObject();
Integer sortCode = this.getSortCode();
int numberOfAccounts = 0;
CustomerResource myCustomer = new CustomerResource();
Response customerResponse = myCustomer
.getCustomerInternal(customerNumber);
if (customerResponse.getStatus() != 200)
{
if (customerResponse.getStatus() == 404)
{
The function getSortCode
SortCode
private Integer getSortCode()
{
/** This will get the Sort Code from the SortCode Resource */
SortCodeResource mySortCodeResource = new SortCodeResource();
Response mySortCodeJSON = mySortCodeResource.getSortCode();
String mySortCode = ((String) mySortCodeJSON.getEntity()).substring(13,
19);
return Integer.parseInt(mySortCode);
}
The function updateAccountExternal
updateAccountInternal
@PUT
@Path("/{id}")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response updateAccountExternal(@PathParam("id") Long id,
AccountJSON account)
{
/**
* Update the account specified by "id" with the JSON in AccountJSON.
* This is for interest rates, types and overdraft limits, not balances
*/
logger.entering(this.getClass().getName(),
"updateAccountExternal(Long id, AccountJSON account)");
Response myResponse = updateAccountInternal(id, account);
HBankDataAccess myHBankDataAccess = new HBankDataAccess();
myHBankDataAccess.terminate();
logger.exiting(this.getClass().getName(),
"updateAccountExternal(Long id, AccountJSON account)",
myResponse);
return myResponse;
}
The function updateAccountInternal
public Response updateAccountInternal(Long id, AccountJSON account)
{
/**
* Update the account specified by "id" with the JSON in AccountJSON.
* This is for interest rates, types and overdraft limits, not balances
*/
logger.entering(this.getClass().getName(), UPDATE_ACCOUNT_INTERNAL);
JSONObject response = new JSONObject();
Response myResponse = null;
if (!(account.validateType(account.getAccountType().trim())))
// If account type invalid
{
JSONObject error = new JSONObject();
error.put(JSON_ERROR_MSG,
ACC_TYPE_STRING + account.getAccountType() + NOT_SUPPORTED);
logger.log(Level.WARNING, () -> (ACC_TYPE_STRING
+ account.getAccountType() + NOT_SUPPORTED));
myResponse = Response.status(400).entity(error.toString()).build();
logger.exiting(this.getClass().getName(), UPDATE_ACCOUNT_INTERNAL,
myResponse);
The function debitAccountExternal
debitAccountInternal
@PUT
@Path("/debit/{id}")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response debitAccountExternal(@PathParam("id") String accountNumber,
DebitCreditAccountJSON dbcr)
{
// we use this to subtract money from an account
logger.entering(this.getClass().getName(),
"debitAccountExternal(String accountNumber, DebitCreditAccountJSON dbcr)");
Response myResponse = debitAccountInternal(accountNumber, dbcr);
HBankDataAccess myHBankDataAccess = new HBankDataAccess();
myHBankDataAccess.terminate();
logger.exiting(this.getClass().getName(),
"debitAccountExternal(String accountNumber, DebitCreditAccountJSON dbcr)",
myResponse);
return myResponse;
}
The function debitAccountInternal
public Response debitAccountInternal(String accountNumber,
DebitCreditAccountJSON dbcr)
{
// we use this to subtract money from an account
logger.entering(this.getClass().getName(), DEBIT_ACCOUNT_INTERNAL);
Response myResponse = null;
AccountsResource checkAccount = new AccountsResource();
Response checkAccountResponse = checkAccount
.getAccountInternal(Long.parseLong(accountNumber));
if (checkAccountResponse.getStatus() != 200)
{
if (checkAccountResponse.getStatus() == 404)
{
JSONObject error = new JSONObject();
error.put(JSON_ERROR_MSG, FAILED_TO_READ + accountNumber
+ IN_DEBIT_ACCOUNT + this.getClass().toString());
logger.log(Level.WARNING, () -> (FAILED_TO_READ + accountNumber
+ IN_DEBIT_ACCOUNT + this.getClass().toString()));
myResponse = Response.status(404).entity(error.toString())
The function creditAccountExternal
creditAccountInternal
@PUT
@Path("/credit/{id}")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response creditAccountExternal(@PathParam("id") String accountNumber,
DebitCreditAccountJSON dbcr)
{
// we use this to add money to an account
logger.entering(this.getClass().getName(),
"creditAccountExternal(String accountNumber, DebitCreditAccountJSON dbcr)");
Response myResponse = creditAccountInternal(accountNumber, dbcr);
HBankDataAccess myHBankDataAccess = new HBankDataAccess();
myHBankDataAccess.terminate();
logger.exiting(this.getClass().getName(),
"creditAccountExternal(String accountNumber, DebitCreditAccountJSON dbcr)",
myResponse);
return myResponse;
}
The function creditAccountInternal
public Response creditAccountInternal(@PathParam("id") String accountNumber,
DebitCreditAccountJSON dbcr)
{
// we use this to add money to an account
logger.entering(this.getClass().getName(), CREDIT_ACCOUNT_INTERNAL);
Response myResponse = null;
AccountsResource checkAccount = new AccountsResource();
Response checkAccountResponse = checkAccount
.getAccountInternal(Long.parseLong(accountNumber));
if (checkAccountResponse.getStatus() != 200)
{
if (checkAccountResponse.getStatus() == 404)
{
JSONObject error = new JSONObject();
error.put(JSON_ERROR_MSG, FAILED_TO_READ + accountNumber
+ IN_CREDIT_ACCOUNT + this.getClass().toString());
logger.log(Level.WARNING, () -> (FAILED_TO_READ + accountNumber
+ IN_CREDIT_ACCOUNT + this.getClass().toString()));
myResponse = Response.status(404).entity(error.toString())
The function transferLocalExternal
transferLocalInternal
@PUT
@Path("/transfer/{id}")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response transferLocalExternal(@PathParam("id") String accountNumber,
TransferLocalJSON transferLocal)
{
// we use this to move money between two accounts at the same bank
logger.entering(this.getClass().getName(),
"transferLocalExternal(String accountNumber, TransferLocalJSON transferLocal)");
Integer accountNumberInteger;
try
{
accountNumberInteger = Integer.parseInt(accountNumber);
if (accountNumberInteger.intValue() < 1
|| accountNumberInteger.intValue() == 99999999)
{
return null;
}
}
catch (NumberFormatException e)
The function transferLocalInternal
public Response transferLocalInternal(@PathParam("id") String accountNumber,
TransferLocalJSON transferLocal)
{
// we use this to move money between two accounts at the same bank
logger.entering(this.getClass().getName(), TRANSFER_LOCAL_INTERNAL);
Response myResponse = null;
// * We are transferring money from account "id" at this bank, to
// another account at this bank
// * The amount MUST be positive
JSONObject response = new JSONObject();
if (Integer.parseInt(accountNumber) == transferLocal.getTargetAccount())
{
JSONObject error = new JSONObject();
error.put(JSON_ERROR_MSG, NEED_DIFFERENT_ACCOUNTS);
logger.log(Level.WARNING, () -> (NEED_DIFFERENT_ACCOUNTS));
myResponse = Response.status(400).entity(error.toString()).build();
logger.exiting(this.getClass().getName(), TRANSFER_LOCAL_INTERNAL,
myResponse);
return myResponse;
The function debitCreditAccount
debitAccount
private Response debitCreditAccount(Long sortCode, String accountNumber,
BigDecimal apiAmount, boolean debitAccount)
{
// This method does both debit AND credit, controlled by the boolean
logger.entering(this.getClass().getName(), DEBIT_CREDIT_ACCOUNT);
Response myResponse = null;
JSONObject response = new JSONObject();
if (debitAccount)
apiAmount = apiAmount.multiply(BigDecimal.valueOf(-1));
com.ibm.cics.cip.bankliberty.web.db2.Account db2Account = new com.ibm.cics.cip.bankliberty.web.db2.Account();
db2Account.setAccountNumber(accountNumber);
db2Account.setSortcode(sortCode.toString());
if (!db2Account.debitCredit(apiAmount))
{
JSONObject error = new JSONObject();
if (apiAmount.doubleValue() < 0)
{
error.put(JSON_ERROR_MSG, "Failed to debit account "
+ accountNumber + CLASS_NAME_MSG);
The function deleteAccountExternal
deleteAccountInternal
@DELETE
@Path("/{accountNumber}")
@Produces("application/json")
public Response deleteAccountExternal(
@PathParam("accountNumber") Long accountNumber)
{
logger.entering(this.getClass().getName(),
"deleteAccountExternal(Long accountNumber)");
Response myResponse = deleteAccountInternal(accountNumber);
HBankDataAccess myHBankDataAccess = new HBankDataAccess();
myHBankDataAccess.terminate();
logger.exiting(this.getClass().getName(),
"deleteAccountExternal(Long accountNumber)", myResponse);
return myResponse;
}
The function deleteAccountInternal
public Response deleteAccountInternal(Long accountNumber)
{
logger.entering(this.getClass().getName(), DELETE_ACCOUNT);
Response myResponse = null;
JSONObject response = new JSONObject();
Integer sortCode = this.getSortCode();
com.ibm.cics.cip.bankliberty.web.db2.Account db2Account = new Account();
db2Account = db2Account.deleteAccount(accountNumber.intValue(),
sortCode.intValue());
if (db2Account != null)
{
response.put(JSON_SORT_CODE, db2Account.getSortcode().trim());
response.put("id", db2Account.getAccountNumber());
response.put(JSON_CUSTOMER_NUMBER, db2Account.getCustomerNumber());
response.put(JSON_ACCOUNT_TYPE, db2Account.getType().trim());
response.put(JSON_AVAILABLE_BALANCE,
BigDecimal.valueOf(db2Account.getAvailableBalance()));
The function getAccountsExternal
getAccountsInternal
@GET
@Produces("application/json")
public Response getAccountsExternal(@QueryParam("limit") Integer limit,
@QueryParam("offset") Integer offset,
@QueryParam("countOnly") Boolean countOnly)
{
// This method returns a fixed number of accounts, up to limit "limit",
// starting at offset "offset"
logger.entering(this.getClass().getName(),
"getAccountsExternal(Integer limit, Integer offset,Boolean countOnly)");
boolean countOnlyReal = false;
if (countOnly != null)
{
countOnlyReal = countOnly.booleanValue();
}
Response myResponse = getAccountsInternal(limit, offset, countOnlyReal);
HBankDataAccess myHBankDataAccess = new HBankDataAccess();
myHBankDataAccess.terminate();
logger.exiting(this.getClass().getName(),
"getAccountsExternal(Integer limit, Integer offset,Boolean countOnly)",
myResponse);
This is an auto-generated document by Swimm 🌊 and has not yet been verified by a human