Skip to content
Snippets Groups Projects
Commit 5d99e387 authored by BEAUVAIS ANTOINE's avatar BEAUVAIS ANTOINE
Browse files

Merge branch 'develop' into 'master'

Merge new API transaction handling into 'master'.

See merge request !2
parents 1bc5555f 10fc4cb8
Branches
1 merge request!2Merge new API transaction handling into 'master'.
Showing
with 586 additions and 36 deletions
......@@ -10,18 +10,37 @@ package fr.unistra.sil.erp.back;
*/
public class Config {
/**
* API version.
*/
public static final String API_VERSION = "v1";
/**
* Prefix for API calls.
*/
public static final String URL_PREFIX = "/api/" + API_VERSION;
/**
* API Mapping for retrieving all items.
*/
public static final String MAPPING_RETRIEVEALL = URL_PREFIX +
"/retrieveAll";
/**
* API Mapping for retrieving all categories.
*/
public static final String MAPPING_GETCATEGORIES = URL_PREFIX +
"/retrieveCategories";
/**
* API Mapping for submitting transactions.
*/
public static final String MAPPING_SUBTRANSAC = URL_PREFIX +
"/submitTransaction";
/**
* API Mapping for retrieving stocks.
*/
public static final String MAPPING_GETSTOCKS = URL_PREFIX +
"/retrieveStocks";
}
......@@ -10,7 +10,7 @@ import fr.unistra.sil.erp.back.db.DatabaseSQLiteImpl;
/**
* Manages the database implementation to use.
* @author BEAUVAIS ANTOINE <antoine.beauvais@etu.unistra.fr>
* @author BEAUVAIS ANTOINE
*/
public class DatabaseSystem {
......@@ -33,7 +33,7 @@ public class DatabaseSystem {
DatabaseSystem.instance = new DatabaseSQLiteImpl();
if(DatabaseSystem.instance == null)
throw new DatabaseConnectionException();
throw new DatabaseConnectionException("Failed to create DB.");
return DatabaseSystem.instance;
}
......
......@@ -14,6 +14,13 @@ import org.springframework.http.ResponseEntity;
*/
public interface IRetrieveStocks {
/**
* Returns the list of stocks to the user.
* @param request the HTTP Servlet request, provided by Spring.
* @param response the HTTP Servlet response, provided by Spring.
* @return the response to the user.
* @throws Exception if the query fails.
*/
public ResponseEntity<Object> retrieveStocks(HttpServletRequest request,
HttpServletResponse response) throws Exception;
......
......@@ -5,11 +5,26 @@
package fr.unistra.sil.erp.back.controller.api;
/**
* HTTP error 400 Bad Request for the API.
* HTTP error 400 Bad Request JSON content.
*
* If the user sends invalid or incomplete data, the query will typically
* fail and this Exception will be thrown.
*
* This Exception allows the application to tell the user what went
* wrong with his query.
*
* Bad Request errors should only be sent if the error is caused by the user's
* input. If the error happens because of a server problem,
* the ApiServerErrorException should be used instead.
*
* @author BEAUVAIS ANTOINE
*/
public class ApiBadRequestException extends Exception {
/**
* Class constructor.
* @param errMsg the error message.
*/
public ApiBadRequestException(String errMsg)
{
super(errMsg);
......
......@@ -14,11 +14,22 @@ import org.springframework.web.bind.annotation.RestControllerAdvice;
/**
* Handles API exceptions.
*
* When an Exception is thrown while processing a request, the behavior
* to adopt for each Exception is defined here.
*
* @author BEAUVAIS ANTOINE
*/
@RestControllerAdvice
public class ApiErrorHandler {
/**
* Handler for HTTP 500 Internal Server Error.
* @param ex the thrown Exception.
* @param request the HTTP Servlet request, provided by Spring.
* @param response the HTTP Servlet response, provided by Spring.
* @return the response to the client.
*/
@ExceptionHandler(ApiServerErrorException.class)
public ResponseEntity<Object> handleServerError(Exception ex,
HttpServletRequest request, HttpServletResponse response)
......@@ -27,6 +38,13 @@ public class ApiErrorHandler {
HttpStatus.INTERNAL_SERVER_ERROR);
}
/**
* Handler for HTTP 400 Bad Request.
* @param ex the thrown Exception.
* @param request the HTTP Servlet request.
* @param response the HTTP Servlet response.
* @return the response to the client.
*/
@ExceptionHandler(ApiBadRequestException.class)
public ResponseEntity<Object> handleBadRequest(Exception ex,
HttpServletRequest request, HttpServletResponse response)
......@@ -35,4 +53,19 @@ public class ApiErrorHandler {
HttpStatus.BAD_REQUEST);
}
/**
* Handler for HTTP 404 Not Found.
* @param ex the thrown Exception.
* @param request the HTTP Servlet request.
* @param response the HTTP Servlet response.
* @return the response to the client.
*/
@ExceptionHandler(ApiResourceNotFoundException.class)
public ResponseEntity<Object> handleResourceNotFound(Exception ex,
HttpServletRequest request, HttpServletResponse response)
{
return new ResponseEntity<>(new ErrorMessage(ex.getMessage()),
HttpStatus.NOT_FOUND);
}
}
/*
* CONTRAT DE LICENCE DE LOGICIEL LIBRE CeCILL-B
* https://cecill.info/licences/Licence_CeCILL-B_V1-fr.html
*/
package fr.unistra.sil.erp.back.controller.api;
/**
* API Exception for HTTP 404 Not Found.
*
* If a resource requested by the user does not exist, this exception
* is thrown and handled through ApiErrorHandler.class.
*
* @see ApiErrorHandler
*
* @author BEAUVAIS ANTOINE
*/
public class ApiResourceNotFoundException extends Exception {
/**
* Class constructor.
* @param errMsg the error message.
*/
public ApiResourceNotFoundException(String errMsg)
{
super(errMsg);
}
}
......@@ -5,7 +5,6 @@
package fr.unistra.sil.erp.back.controller.api;
import static fr.unistra.sil.erp.back.Config.MAPPING_GETCATEGORIES;
import static fr.unistra.sil.erp.back.Config.MAPPING_GETSTOCKS;
import fr.unistra.sil.erp.back.DatabaseSystem;
import fr.unistra.sil.erp.back.controller.IRetrieveCategoriesController;
import fr.unistra.sil.erp.back.model.Category;
......
......@@ -13,7 +13,6 @@ import fr.unistra.sil.erp.back.db.DatabaseInterface;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
......
......@@ -5,11 +5,21 @@
package fr.unistra.sil.erp.back.controller.api;
/**
* Returns HTTP 500 error page.
* @author BEAUVAIS ANTOINE <antoine.beauvais@etu.unistra.fr>
* Returns HTTP 500 JSON error.
*
* This exception allows the application to handle internal
* server errors by replying proper JSON content to the caller.
*
* The message will be given to the user.
*
* @author BEAUVAIS ANTOINE
*/
public class ApiServerErrorException extends Exception {
/**
* Class constructor.
* @param errMsg the error message to display to the end-user.
*/
public ApiServerErrorException(String errMsg)
{
super(errMsg);
......
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
* CONTRAT DE LICENCE DE LOGICIEL LIBRE CeCILL-B
* https://cecill.info/licences/Licence_CeCILL-B_V1-fr.html
*/
package fr.unistra.sil.erp.back.controller.api;
import com.google.gson.Gson;
import com.google.gson.JsonParseException;
import static fr.unistra.sil.erp.back.Config.MAPPING_SUBTRANSAC;
import fr.unistra.sil.erp.back.DatabaseSystem;
import fr.unistra.sil.erp.back.controller.ISubmitTransactionController;
import fr.unistra.sil.erp.back.db.DatabaseConnectionException;
import fr.unistra.sil.erp.back.db.DatabaseInterface;
import fr.unistra.sil.erp.back.db.DatabaseResourceNotFoundException;
import fr.unistra.sil.erp.back.db.DatabaseUpdateException;
import fr.unistra.sil.erp.back.model.Stock;
import fr.unistra.sil.erp.back.model.Transaction;
import java.io.IOException;
import java.util.logging.Level;
......@@ -29,10 +35,21 @@ import org.springframework.web.bind.annotation.RestController;
public class ApiSubmitTransactionController
implements ISubmitTransactionController {
/**
* Handler for transaction submissions.
* @param request the HTTP Servlet Request provided by Spring.
* @param response the HTTP Servlet Response provided by Spring.
* @return the response for the user.
* @throws ApiBadRequestException if the query failed.
* @throws ApiServerErrorException Server error.
* @throws ApiResourceNotFoundException Stock not found.
*/
@RequestMapping(value=MAPPING_SUBTRANSAC, method = RequestMethod.POST)
@Override
public ResponseEntity<Object> submitTransaction(HttpServletRequest request,
HttpServletResponse response) throws ApiBadRequestException
HttpServletResponse response)
throws ApiBadRequestException, ApiServerErrorException,
ApiResourceNotFoundException
{
Gson gson = new Gson();
String body;
......@@ -63,9 +80,34 @@ public class ApiSubmitTransactionController
if(!t.checkIfValid())
throw new ApiBadRequestException("Invalid JSON schema.");
System.out.println("Transaction : " + t.getItem() +
t.getType() + " " + t.getAmount());
DatabaseInterface db;
Stock s;
try {
db = DatabaseSystem.getInstance();
s = db.getStockForItem(t.getItem());
if(s == null)
throw new ApiServerErrorException("Database failure.");
int newQuantity = s.getQuantity() + t.getQuantity();
if(newQuantity < 0)
newQuantity = 0;
db.updateStock(s.getId(), newQuantity);
} catch (DatabaseConnectionException ex) {
Logger.getLogger(ApiSubmitTransactionController.class.getName())
.log(Level.SEVERE, ex.getMessage(), ex);
throw new ApiServerErrorException("Database failure.");
} catch (DatabaseResourceNotFoundException ex) {
//Logger.getLogger(ApiSubmitTransactionController.class.getName())
// .log(Level.SEVERE, null, ex);
throw new ApiResourceNotFoundException("No stock found for item " +
t.getItem());
} catch (DatabaseUpdateException ex) {
Logger.getLogger(ApiSubmitTransactionController.class.getName())
.log(Level.SEVERE, ex.getMessage(), ex);
throw new ApiServerErrorException("Database update failure.");
}
return new ResponseEntity<>(t, HttpStatus.CREATED);
}
......
......@@ -5,9 +5,24 @@
package fr.unistra.sil.erp.back.db;
/**
*
* @author BEAUVAIS ANTOINE <antoine.beauvais@etu.unistra.fr>
* General database error.
*
* This is a custom Exception thrown when the database could not
* be used by the application, for whatever reason.
*
* This allows the program to handle error cases.
*
* @author BEAUVAIS ANTOINE
*/
public class DatabaseConnectionException extends Exception {
/**
* Class constructor.
* @param errMsg the error message.
*/
public DatabaseConnectionException(String errMsg)
{
super(errMsg);
}
}
......@@ -15,7 +15,7 @@ import java.util.List;
* This interface allows the application to be able to use different
* database systems (CSV, SQLite, MySQL...) by simply switching
* implementations.
* @author BEAUVAIS ANTOINE <antoine.beauvais@etu.unistra.fr>
* @author BEAUVAIS ANTOINE
*/
public interface DatabaseInterface {
......@@ -46,4 +46,22 @@ public interface DatabaseInterface {
*/
public List<Stock> getStocks();
/**
* Returns the stock entry of an item.
* @param id the item's ID.
* @return the stock line.
* @throws DatabaseResourceNotFoundException when the query fails.
*/
public Stock getStockForItem(int itemId)
throws DatabaseResourceNotFoundException;
/**
* Updates the specified stock's quantity.
* @param id the stock entry's ID.
* @param quantity the new quantity.
* @throws DatabaseUpdateException when the query fails.
*/
public void updateStock(int id, int quantity)
throws DatabaseConnectionException, DatabaseUpdateException;
}
/*
* CONTRAT DE LICENCE DE LOGICIEL LIBRE CeCILL-B
* https://cecill.info/licences/Licence_CeCILL-B_V1-fr.html
*/
package fr.unistra.sil.erp.back.db;
/**
* Exception for non-existent database resources.
*
* If the information requested in a database doesn't exist, this Exception
* is thrown.
*
* @author BEAUVAIS ANTOINE
*/
public class DatabaseResourceNotFoundException extends Exception {
/**
* Class constructor.
* @param errMsg the error message.
*/
public DatabaseResourceNotFoundException(String errMsg)
{
super(errMsg);
}
}
......@@ -20,27 +20,60 @@ import java.util.logging.Logger;
/**
* SQLite implementation of the Database interface.
* @author BEAUVAIS ANTOINE <antoine.beauvais@etu.unistra.fr>
*
* This allows the software to store and process information through
* a SQLite database file.
*
* @author BEAUVAIS ANTOINE
*/
public class DatabaseSQLiteImpl implements DatabaseInterface {
/**
* SQLite's connection string for the JDBC driver.
*/
private static final String CONNECTION_URL = "jdbc:sqlite:dev.db";
/**
* Query used to select all items stored in the database.
*/
private static final String SQL_GETALLITEMS =
"SELECT ref, name, price, subscriberPrice, category FROM items";
/**
* Query used to get all items stored in the database from a specific
* category.
*/
private static final String SQL_GETITEMSFROMCATEGORY = SQL_GETALLITEMS +
" WHERE category = ?";
/**
* Query used to retrieve all categories stored in the database.
*/
private static final String SQL_GETCATEGORIES =
"SELECT id, name FROM categories";
/**
* Query used to fetch all stocks stored in the database.
*/
private static final String SQL_GETSTOCKS =
"SELECT s.id AS id, s.item AS item, " +
"i.name AS name, s.quantity AS quantity FROM stocks s " +
"INNER JOIN items i ON s.item = i.ref";
private static final String SQL_GETSTOCKFORITEM = SQL_GETSTOCKS +
" WHERE item = ?";
private static final String SQL_UPDATESTOCK =
"UPDATE stocks SET quantity = ? WHERE item = ?";
/**
* SQL Connection object.
*/
private Connection conn;
/**
* Class constructor.
*/
public DatabaseSQLiteImpl()
{
try {
......@@ -51,6 +84,11 @@ public class DatabaseSQLiteImpl implements DatabaseInterface {
}
}
/**
* Executes a standard query, without parameters.
* @param query the string's query.
* @return the result set for this query.
*/
private ResultSet query(String query)
{
Statement stmt;
......@@ -67,6 +105,10 @@ public class DatabaseSQLiteImpl implements DatabaseInterface {
return rs;
}
/**
* Retrieves all items from inside the database.
* @return the list of items.
*/
@Override
public List<Item> getAllItems() {
ResultSet rs = query(SQL_GETALLITEMS);
......@@ -92,6 +134,11 @@ public class DatabaseSQLiteImpl implements DatabaseInterface {
return res;
}
/**
* Returns all items from the specified category.
* @param category the category to filter the results with.
* @return the list of items.
*/
@Override
public List<Item> getItemsFromCategory(int category) {
......@@ -136,11 +183,16 @@ public class DatabaseSQLiteImpl implements DatabaseInterface {
} catch (SQLException ex) {
Logger.getLogger(DatabaseSQLiteImpl.class.getName()).log(
Level.SEVERE, "Failed to parse results.", ex);
return null;
}
return res;
}
/**
* Retrieves all categories from the database.
* @return the list of categories.
*/
@Override
public List<Category> getCategories() {
ResultSet rs = this.query(SQL_GETCATEGORIES);
......@@ -163,6 +215,10 @@ public class DatabaseSQLiteImpl implements DatabaseInterface {
return res;
}
/**
* Retrieves all stock entries from the database.
* @return the list of stock entries.
*/
@Override
public List<Stock> getStocks() {
ResultSet rs = this.query(SQL_GETSTOCKS);
......@@ -186,5 +242,96 @@ public class DatabaseSQLiteImpl implements DatabaseInterface {
return res;
}
/**
* Returns the stock entry for the specified item.
* @param itemId the item's ID.
* @return the Stock entry.
* @throws DatabaseResourceNotFoundException if the stock doesn't exist.
*/
@Override
public Stock getStockForItem(int itemId)
throws DatabaseResourceNotFoundException {
PreparedStatement ps;
try {
ps = this.conn.prepareStatement(SQL_GETSTOCKFORITEM);
} catch (SQLException ex) {
Logger.getLogger(DatabaseSQLiteImpl.class.getName()).log(
Level.SEVERE, "Failed to connect to database.", ex);
return null;
}
try {
ps.setInt(1, itemId);
} catch (SQLException ex) {
Logger.getLogger(DatabaseSQLiteImpl.class.getName()).log(
Level.SEVERE, "Failed to set query parameter.", ex);
return null;
}
ResultSet rs;
try {
rs = ps.executeQuery();
} catch (SQLException ex) {
Logger.getLogger(DatabaseSQLiteImpl.class.getName()).log(
Level.SEVERE, "Failed to fetch stock for item " +
itemId, ex);
return null;
}
Stock s;
try {
if(rs.next())
s = new Stock(rs.getInt("id"), rs.getInt("item"),
rs.getString("name"),
rs.getInt("quantity"));
else
throw new DatabaseResourceNotFoundException("Stock not found.");
} catch (SQLException ex) {
Logger.getLogger(DatabaseSQLiteImpl.class.getName()).log(
Level.SEVERE, "Failed to parse results.", ex);
return null;
}
return s;
}
/**
* Updates the specified stock entry with the new quantity.
* @param id the stock's ID.
* @param quantity the associated quantity.
* @throws DatabaseConnectionException when the connection to the DB fails.
* @throws DatabaseUpdateException when the update fails.
*/
@Override
public void updateStock(int id, int quantity)
throws DatabaseConnectionException, DatabaseUpdateException {
PreparedStatement ps;
try {
ps = this.conn.prepareStatement(SQL_UPDATESTOCK);
} catch (SQLException ex) {
Logger.getLogger(DatabaseSQLiteImpl.class.getName()).log(
Level.SEVERE, "Failed to connect to database.", ex);
throw new DatabaseConnectionException("Failed to connect to DB.");
}
try {
ps.setInt(1, quantity);
ps.setInt(2, id);
} catch (SQLException ex) {
Logger.getLogger(DatabaseSQLiteImpl.class.getName()).log(
Level.SEVERE, "Failed to set query parameter.", ex);
throw new DatabaseUpdateException("Failed to set query params.");
}
try {
ps.execute();
} catch (SQLException ex) {
Logger.getLogger(DatabaseSQLiteImpl.class.getName())
.log(Level.SEVERE, "Failed to execute query.", ex);
throw new DatabaseUpdateException("Failed to execute query.");
}
}
}
/*
* CONTRAT DE LICENCE DE LOGICIEL LIBRE CeCILL-B
* https://cecill.info/licences/Licence_CeCILL-B_V1-fr.html
*/
package fr.unistra.sil.erp.back.db;
/**
* Exception for database update failures.
*
* When a database system fails to update specific rows
* from the database, then it throws this Exception so
* the application can handle it.
*
* @author BEAUVAIS ANTOINE
*/
public class DatabaseUpdateException extends Exception {
/**
* Class constructor.
* @param errMsg the error message.
*/
public DatabaseUpdateException(String errMsg)
{
super(errMsg);
}
}
......@@ -6,17 +6,35 @@ package fr.unistra.sil.erp.back.model;
/**
* JSON error message.
*
* When an error occurs, the application will send this type of message
* to the user.
*
* This object only provides a simple message to briefly inform the user
* of what went wrong with the query.
*
* @author BEAUVAIS ANTOINE
*/
public class ErrorMessage {
/**
* The error message.
*/
private final String message;
/**
* Class constructor.
* @param message the error message to display.
*/
public ErrorMessage(String message)
{
this.message = message;
}
/**
* Returns the error message.
* @return the message.
*/
public String getMessage()
{
return this.message;
......
......@@ -7,8 +7,16 @@ package fr.unistra.sil.erp.back.model;
import java.math.BigDecimal;
/**
* Item description.
* @author BEAUVAIS ANTOINE <antoine.beauvais@etu.unistra.fr>
* Item object.
*
* Items are products that can be bought and sold.
*
* Any transaction must be linked to an item.
*
* Items have specific quantities stored as "stocks" and cannot be sold
* if the quantity is depleted.
*
* @author BEAUVAIS ANTOINE
*/
public class Item {
......
......@@ -8,25 +8,66 @@ import java.math.BigDecimal;
import java.time.LocalDateTime;
/**
* Transaction object.
* Entry in the Registry.
*
* The registry contains all credit and debit operations relative to
* the operating organization.
*
* @author BEAUVAIS ANTOINE
*/
public class RegistryEntry {
/**
* The entry's ID.
*/
private final int id;
private final int transactionId;
/**
* The transaction's type.
*/
private final int transactionType;
/**
* The date and time for this transaction.
*/
private final LocalDateTime dt;
/**
* The ID of the associated account.
*/
private final int accountId;
/**
* The amount of money, if it's a debit.
*/
private final BigDecimal debit;
/**
* The amount of money, if it's a credit.
*/
private final BigDecimal credit;
/**
* Arbitrary remarks. Optional.
*/
private final String remarks;
public RegistryEntry(int id, int transactionId, LocalDateTime dt,
/**
* Class constructor.
* @param id the entry's ID.
* @param transactionType the transaction type.
* @param dt the date and time.
* @param accountId the associated account's ID.
* @param debit money for the debit.
* @param credit money for the credit.
* @param remarks arbitrary remarks.
*/
public RegistryEntry(int id, int transactionType, LocalDateTime dt,
int accountId, BigDecimal debit, BigDecimal credit,
String remarks)
{
this.id = id;
this.transactionId = transactionId;
this.transactionType = transactionType;
this.dt = dt;
this.accountId = accountId;
this.debit = debit;
......@@ -34,36 +75,64 @@ public class RegistryEntry {
this.remarks = remarks;
}
/**
* Returns the entry's ID.
* @return the entry's ID.
*/
public int getId()
{
return this.id;
}
public int getTransactionId()
/**
* Returns the transaction's type.
* @return the transaction's type.
*/
public int getTransactionType()
{
return this.transactionId;
return this.transactionType;
}
/**
* Returns the transaction's date and time.
* @return the date and time.
*/
public LocalDateTime getDatetime()
{
return this.dt;
}
/**
* Returns the associated account's ID.
* @return the associated account's ID.
*/
public int getAccountId()
{
return this.accountId;
}
/**
* Returns the debit amount.
* @return the amount.
*/
public BigDecimal getDebit()
{
return this.debit;
}
/**
* Returns the credit amount.
* @return the amount.
*/
public BigDecimal getCredit()
{
return this.credit;
}
/**
* Returns the arbitrary remarks.
* @return the remarks.
*/
public String getRemarks()
{
return this.remarks;
......
......@@ -6,18 +6,42 @@ package fr.unistra.sil.erp.back.model;
/**
* Representation of a stock entry.
*
* Stocks simply provide the available quantity for each item.
*
* If an item's quantity is depleted, it cannot be sold.
*
* @author BEAUVAIS ANTOINE
*/
public class Stock {
/**
* The stock entry's ID.
*/
private final int id;
/**
* The stock's item ID.
*/
private final int itemId;
/**
* The stock's item name.
*/
private final String itemName;
/**
* The quantity for the item.
*/
private final int quantity;
/**
* Class constructor.
* @param id the Stock's ID.
* @param itemId the item's ID.
* @param itemName the item's name.
* @param quantity the quantity.
*/
public Stock(int id, int itemId, String itemName, int quantity)
{
this.id = id;
......@@ -26,21 +50,37 @@ public class Stock {
this.quantity = quantity;
}
/**
* Returns the stock ID.
* @return the stock's ID.
*/
public int getId()
{
return this.id;
}
/**
* Returns the item's ID.
* @return the item's ID.
*/
public int getItemId()
{
return this.itemId;
}
/**
* Returns the item's name.
* @return the item's name.
*/
public String getItemName()
{
return this.itemName;
}
/**
* Returns the quantity for the item.
* @return the quantity.
*/
public int getQuantity()
{
return this.quantity;
......
......@@ -8,51 +8,81 @@ import java.math.BigDecimal;
/**
* Representation of a transaction.
*
* A Transaction is a query from the MONEY component that represents
* the information used for a proper transaction.
*
* Transactions automatically update stocks as well as the Registry
* when applicable.
*
* @author BEAUVAIS ANTOINE
*/
public class Transaction {
/**
* Item ID.
*/
private final Integer item;
/**
* Transaction type.
*/
private final Integer type;
private final BigDecimal amount;
/**
* Number of items.
*/
private final Integer quantity;
public Transaction(Integer item, Integer type, BigDecimal amount,
Integer quantity)
/**
* Class constructor.
* @param item Item's identifier.
* @param type Transaction type.
* @param amount Transaction's amount.
* @param quantity Quantity of items involved.
*/
public Transaction(Integer item, Integer type, Integer quantity)
{
this.item = item;
this.type = type;
this.amount = amount;
this.quantity = quantity;
}
/**
* Returns the Transaction's item ID.
* @return the item ID.
*/
public Integer getItem()
{
return this.item;
}
/**
* Returns the Transaction's type.
* @return the transaction's type.
*/
public Integer getType()
{
return this.type;
}
public BigDecimal getAmount()
{
return this.amount;
}
/**
* Returns the number of items in the Transaction.
* @return the number of items.
*/
public Integer getQuantity()
{
return this.quantity;
}
/**
* Checks that the Transaction is valid.
* @return whether the Transaction is valid.
*/
public boolean checkIfValid()
{
return (this.item != null && this.type != null
&& this.amount != null && this.quantity != null);
&& this.quantity != null);
}
}
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment