From 9c701b4c2c526cd34812f92fd90c562b97717f3a Mon Sep 17 00:00:00 2001 From: BEAUVAIS ANTOINE <antoine.beauvais@etu.unistra.fr> Date: Thu, 23 Sep 2021 21:07:16 +0200 Subject: [PATCH] Updated Javadoc. --- .../java/fr/unistra/sil/erp/back/Config.java | 19 +++++ .../unistra/sil/erp/back/DatabaseSystem.java | 2 +- .../erp/back/controller/IRetrieveStocks.java | 7 ++ .../api/ApiBadRequestException.java | 17 +++- .../back/controller/api/ApiErrorHandler.java | 18 +++++ .../api/ApiRetrieveCategoriesController.java | 1 - .../api/ApiRetrieveInfoController.java | 1 - .../api/ApiServerErrorException.java | 14 +++- .../api/ApiSubmitTransactionController.java | 7 ++ .../back/db/DatabaseConnectionException.java | 10 ++- .../sil/erp/back/db/DatabaseInterface.java | 2 +- .../sil/erp/back/db/DatabaseSQLiteImpl.java | 51 +++++++++++- .../sil/erp/back/model/ErrorMessage.java | 18 +++++ .../fr/unistra/sil/erp/back/model/Item.java | 12 ++- .../sil/erp/back/model/RegistryEntry.java | 81 +++++++++++++++++-- .../fr/unistra/sil/erp/back/model/Stock.java | 40 +++++++++ .../sil/erp/back/model/Transaction.java | 46 +++++++++++ 17 files changed, 328 insertions(+), 18 deletions(-) diff --git a/src/main/java/fr/unistra/sil/erp/back/Config.java b/src/main/java/fr/unistra/sil/erp/back/Config.java index dd7c053..ed8cc4d 100644 --- a/src/main/java/fr/unistra/sil/erp/back/Config.java +++ b/src/main/java/fr/unistra/sil/erp/back/Config.java @@ -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"; } diff --git a/src/main/java/fr/unistra/sil/erp/back/DatabaseSystem.java b/src/main/java/fr/unistra/sil/erp/back/DatabaseSystem.java index 321f119..4cdb1f3 100644 --- a/src/main/java/fr/unistra/sil/erp/back/DatabaseSystem.java +++ b/src/main/java/fr/unistra/sil/erp/back/DatabaseSystem.java @@ -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 { diff --git a/src/main/java/fr/unistra/sil/erp/back/controller/IRetrieveStocks.java b/src/main/java/fr/unistra/sil/erp/back/controller/IRetrieveStocks.java index 883ba1d..dd9d14b 100644 --- a/src/main/java/fr/unistra/sil/erp/back/controller/IRetrieveStocks.java +++ b/src/main/java/fr/unistra/sil/erp/back/controller/IRetrieveStocks.java @@ -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; diff --git a/src/main/java/fr/unistra/sil/erp/back/controller/api/ApiBadRequestException.java b/src/main/java/fr/unistra/sil/erp/back/controller/api/ApiBadRequestException.java index 7443d03..07cf910 100644 --- a/src/main/java/fr/unistra/sil/erp/back/controller/api/ApiBadRequestException.java +++ b/src/main/java/fr/unistra/sil/erp/back/controller/api/ApiBadRequestException.java @@ -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); diff --git a/src/main/java/fr/unistra/sil/erp/back/controller/api/ApiErrorHandler.java b/src/main/java/fr/unistra/sil/erp/back/controller/api/ApiErrorHandler.java index 2e85fb6..fbd17bf 100644 --- a/src/main/java/fr/unistra/sil/erp/back/controller/api/ApiErrorHandler.java +++ b/src/main/java/fr/unistra/sil/erp/back/controller/api/ApiErrorHandler.java @@ -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) diff --git a/src/main/java/fr/unistra/sil/erp/back/controller/api/ApiRetrieveCategoriesController.java b/src/main/java/fr/unistra/sil/erp/back/controller/api/ApiRetrieveCategoriesController.java index 977b42a..fa4a767 100644 --- a/src/main/java/fr/unistra/sil/erp/back/controller/api/ApiRetrieveCategoriesController.java +++ b/src/main/java/fr/unistra/sil/erp/back/controller/api/ApiRetrieveCategoriesController.java @@ -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; diff --git a/src/main/java/fr/unistra/sil/erp/back/controller/api/ApiRetrieveInfoController.java b/src/main/java/fr/unistra/sil/erp/back/controller/api/ApiRetrieveInfoController.java index 0b9e426..ba8c6af 100644 --- a/src/main/java/fr/unistra/sil/erp/back/controller/api/ApiRetrieveInfoController.java +++ b/src/main/java/fr/unistra/sil/erp/back/controller/api/ApiRetrieveInfoController.java @@ -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; diff --git a/src/main/java/fr/unistra/sil/erp/back/controller/api/ApiServerErrorException.java b/src/main/java/fr/unistra/sil/erp/back/controller/api/ApiServerErrorException.java index 7cfe6a0..2ba9a23 100644 --- a/src/main/java/fr/unistra/sil/erp/back/controller/api/ApiServerErrorException.java +++ b/src/main/java/fr/unistra/sil/erp/back/controller/api/ApiServerErrorException.java @@ -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); diff --git a/src/main/java/fr/unistra/sil/erp/back/controller/api/ApiSubmitTransactionController.java b/src/main/java/fr/unistra/sil/erp/back/controller/api/ApiSubmitTransactionController.java index 37189f0..33f6b5c 100644 --- a/src/main/java/fr/unistra/sil/erp/back/controller/api/ApiSubmitTransactionController.java +++ b/src/main/java/fr/unistra/sil/erp/back/controller/api/ApiSubmitTransactionController.java @@ -29,6 +29,13 @@ 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. + */ @RequestMapping(value=MAPPING_SUBTRANSAC, method = RequestMethod.POST) @Override public ResponseEntity<Object> submitTransaction(HttpServletRequest request, diff --git a/src/main/java/fr/unistra/sil/erp/back/db/DatabaseConnectionException.java b/src/main/java/fr/unistra/sil/erp/back/db/DatabaseConnectionException.java index 1b1598f..fcff9c1 100644 --- a/src/main/java/fr/unistra/sil/erp/back/db/DatabaseConnectionException.java +++ b/src/main/java/fr/unistra/sil/erp/back/db/DatabaseConnectionException.java @@ -5,8 +5,14 @@ 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 { diff --git a/src/main/java/fr/unistra/sil/erp/back/db/DatabaseInterface.java b/src/main/java/fr/unistra/sil/erp/back/db/DatabaseInterface.java index 19f0dfa..988daf0 100644 --- a/src/main/java/fr/unistra/sil/erp/back/db/DatabaseInterface.java +++ b/src/main/java/fr/unistra/sil/erp/back/db/DatabaseInterface.java @@ -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 { diff --git a/src/main/java/fr/unistra/sil/erp/back/db/DatabaseSQLiteImpl.java b/src/main/java/fr/unistra/sil/erp/back/db/DatabaseSQLiteImpl.java index 6ba2ee9..dd162f3 100644 --- a/src/main/java/fr/unistra/sil/erp/back/db/DatabaseSQLiteImpl.java +++ b/src/main/java/fr/unistra/sil/erp/back/db/DatabaseSQLiteImpl.java @@ -20,27 +20,54 @@ 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"; + /** + * SQL Connection object. + */ private Connection conn; + /** + * Class constructor. + */ public DatabaseSQLiteImpl() { try { @@ -51,6 +78,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 +99,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 +128,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) { @@ -141,6 +182,10 @@ public class DatabaseSQLiteImpl implements DatabaseInterface { 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 +208,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); diff --git a/src/main/java/fr/unistra/sil/erp/back/model/ErrorMessage.java b/src/main/java/fr/unistra/sil/erp/back/model/ErrorMessage.java index c7fac54..a5d4ba8 100644 --- a/src/main/java/fr/unistra/sil/erp/back/model/ErrorMessage.java +++ b/src/main/java/fr/unistra/sil/erp/back/model/ErrorMessage.java @@ -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; diff --git a/src/main/java/fr/unistra/sil/erp/back/model/Item.java b/src/main/java/fr/unistra/sil/erp/back/model/Item.java index b37069d..a7586d8 100644 --- a/src/main/java/fr/unistra/sil/erp/back/model/Item.java +++ b/src/main/java/fr/unistra/sil/erp/back/model/Item.java @@ -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 { diff --git a/src/main/java/fr/unistra/sil/erp/back/model/RegistryEntry.java b/src/main/java/fr/unistra/sil/erp/back/model/RegistryEntry.java index 8cb06fa..d3c10b2 100644 --- a/src/main/java/fr/unistra/sil/erp/back/model/RegistryEntry.java +++ b/src/main/java/fr/unistra/sil/erp/back/model/RegistryEntry.java @@ -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; diff --git a/src/main/java/fr/unistra/sil/erp/back/model/Stock.java b/src/main/java/fr/unistra/sil/erp/back/model/Stock.java index 05c9504..b2c8dd2 100644 --- a/src/main/java/fr/unistra/sil/erp/back/model/Stock.java +++ b/src/main/java/fr/unistra/sil/erp/back/model/Stock.java @@ -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; diff --git a/src/main/java/fr/unistra/sil/erp/back/model/Transaction.java b/src/main/java/fr/unistra/sil/erp/back/model/Transaction.java index b4eadec..205760b 100644 --- a/src/main/java/fr/unistra/sil/erp/back/model/Transaction.java +++ b/src/main/java/fr/unistra/sil/erp/back/model/Transaction.java @@ -8,18 +8,44 @@ 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; + /** + * Transaction's amount. + */ private final BigDecimal amount; + /** + * Number of items. + */ private final 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, BigDecimal amount, Integer quantity) { @@ -29,26 +55,46 @@ public class Transaction { 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; } + /** + * Returns the Transaction's amount of money. + * @return the amount. + */ 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 -- GitLab