java.lang.Object
com.prog3.ipt.Model.FacadeClasses.FacadeSingleton
Thread-safe Singleton class. The instance is lazily initialized and thus needs synchronization mechanism.
-
Field Summary
Modifier and TypeFieldDescriptionprivate static final String
private static Connection
private static DatabaseConnectionSingleton
private static FacadeSingleton
private static final int
private static final int
private static javafx.collections.ObservableList<RideLineFX>
private static javafx.collections.ObservableList<Notice>
private static PreparedStatement
private static ResultSet
private static int
private static final Random
private static String
private static Statement
private static javafx.collections.ObservableList<TravelDocumentFX>
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic boolean
checkTicketIssueDateValidity
(String ticketLineID, LocalDate ticketIssueDate) Validates an issue date for a SingleTicket object.static void
Close a connection previously openedprivate static void
connect()
Set up a connection to IPT MySQL Database using a DatabaseConnectionSingleton object.private static boolean
deleteMembershipStatement
(String queryTemplate) Allows to make a DML operation to the Membership table in IPT database, SQL DELETE in this case, and get the result of the given SQL DELETE operation The returning integer value is put in a static int object, such as queryOutputDML variable.static boolean
deleteMyMembership
(TravelDocumentFX localMembership) Deletes a membership bought by the logged citizen from the Ticket table of IPT databasestatic boolean
deleteMySingleTicket
(TravelDocumentFX localSingleTicket) Deletes a ticket bought by the logged citizen from the Ticket table of IPT databaseprivate static boolean
deleteSingleTicketStatement
(String queryTemplate) Allows to make a DML operation to the Ticket table in IPT database, SQL DELETE in this case, and get the result of the given SQL DELETE operation The returning integer value is put in a static int object, such as queryOutputDML variable.private static boolean
executeQuery
(String queryString) Wrapper method that allow to connect to IPT database, initialize a Statement object and get the result set as output of the Statement object.private static String
generateSecurePassword
(String password) Generates a secure password stored in the password field in the Citizen table of IPT databasestatic javafx.collections.ObservableList<RideLineFX>
Returns information about the IPT lines and rides that are displayed in Info viewstatic FacadeSingleton
Recovers the salt key from the Salt table of IPT database and returns the FacadeSingleton instance.static javafx.collections.ObservableList<TravelDocumentFX>
Returns the memberships bought by the logged citizen that are displayed in the MyMemberships viewstatic javafx.collections.ObservableList<TravelDocumentFX>
Returns the tickets bought by the logged citizen that are displayed in the MyTickets viewstatic javafx.collections.ObservableList<Notice>
Returns the notices issued by IPT that are displayed in the Notices viewprivate static String
getSalt
(int length) Builds the salt key as stringprivate static boolean
Return the salt key stored into the salt field in the Salt table of IPT database.private static byte[]
hash
(char[] password, byte[] salt) Hash function to generete a secret keystatic boolean
insertCitizen
(Citizen localCitizen) Inserts a Citizen record in the Citizen table of IPT databaseprivate static boolean
insertCitizenQuerySender
(String queryTemplate, Citizen newCitizen) Returns the result of an SQL INSERT operation in the Citizen table of IPT databasestatic boolean
Inserts an order made by the logged citizen as a transaction record to the Transaction table of IPT database.static Citizen
retrieveCitizen
(String citizenUsername, String citizenPassword) Retrieves data about citizen signed in with a given username and a given passwordstatic boolean
updateCitizenData
(Citizen localCitizen) Updates logged citizen's data in the Citizen table of IPT databaseprivate static boolean
updateCitizenQuerySender
(String queryTemplate, Citizen newCitizen) Updates logged citizen's data in the Citizen table of IPT databaseprivate static boolean
updateMembershipStatement
(String queryTemplate, Membership membership) Allows to make a DML operation to the Membership table in IPT database, SQL INSERT in this case, and get the result of the given SQL INSERT operationprivate static boolean
updatePreparedStatement
(String queryTemplate) Wrapper method that allow to connect to IPT database, initialize and set a PreparedStatement objectprivate static boolean
updateTicketStatement
(String queryTemplate, SingleTicket singleTicket) Allows to make a DML operation to the Ticket table in IPT database, SQL INSERT in this case, and get the result of the given SQL INSERT operationprivate static boolean
updateTransactionStatement
(String queryTemplate, Order localOrder) Allows to make a DML operation to the Transaction table in IPT database, SQL INSERT in this case, and get the result of the given SQL INSERT operation The returning integer value is put in a static int object, such as queryOutputDML variable.static boolean
validateGeneratedCitizenID
(Citizen localCitizen) Validates a 5-chars citizen unique identifier generated using randomUUID method and converted to a String object.static boolean
validateGeneratedMembershipID
(String membershipID) Validates a 5-chars membership unique identifier generated using randomUUID method and converted to a String object.static boolean
validateGeneratedSingleTicketID
(String singleTicketID) Validates a 5-chars ticket unique identifier generated using randomUUID method and converted to a String object.private static boolean
validateGeneratedTransactionID
(String transactionCode) Validates a 5-chars transaction code generated using randomUUID method and converted to a String object.static boolean
validateRide
(String ticketLineID, String ticketRideID) Checks if the ticket that a citizen is going to buy is a ticket for a valid line and ride.private static boolean
verifyUserPassword
(String providedPassword, String securedPassword) Verifies the given user password is valid
-
Field Details
-
instance
-
databaseConnection
-
connection
-
statement
-
preparedStatement
-
queryOutput
-
queryOutputDML
private static int queryOutputDML -
noticeObservableList
-
lineRideObservableList
-
travelDocumentObservableList
-
RANDOM
-
ALPHABET
- See Also:
-
ITERATIONS
private static final int ITERATIONS- See Also:
-
KEY_LENGTH
private static final int KEY_LENGTH- See Also:
-
salt
-
-
Constructor Details
-
FacadeSingleton
private FacadeSingleton()FacadeSingleton constructor
-
-
Method Details
-
getInstance
Recovers the salt key from the Salt table of IPT database and returns the FacadeSingleton instance. The instance doesn't get created until the method is called for the first time.- Returns:
- A reference to a FacadeSingleton object.
- See Also:
-
connect
private static void connect()Set up a connection to IPT MySQL Database using a DatabaseConnectionSingleton object. -
closeConnection
public static void closeConnection()Close a connection previously opened- See Also:
-
executeQuery
Wrapper method that allow to connect to IPT database, initialize a Statement object and get the result set as output of the Statement object. The returning ResultSet object is put in a static ResultSet object, such as queryOutput variable.- Parameters:
queryString
- an SQL statement to be sent to the database, typically a static SQL SELECT statement- Returns:
- True if the given query is syntactically correct, otherwise false.
- See Also:
-
updatePreparedStatement
Wrapper method that allow to connect to IPT database, initialize and set a PreparedStatement object- Parameters:
queryTemplate
- an SQL statement to be sent to the database, typically a static SQL INSERT statement- Returns:
- True if the given query is syntactically correct, otherwise false
- See Also:
-
updateTicketStatement
Allows to make a DML operation to the Ticket table in IPT database, SQL INSERT in this case, and get the result of the given SQL INSERT operation- Parameters:
queryTemplate
- an SQL statement to be sent to the database, typically a static SQL INSERT statementsingleTicket
- A reference to a SingleTicket object that provides its fields as parameters to a PreparedStatement object- Returns:
- True if the result of given query is syntactically correct and is not zero, otherwise false
- See Also:
-
updateMembershipStatement
Allows to make a DML operation to the Membership table in IPT database, SQL INSERT in this case, and get the result of the given SQL INSERT operation- Parameters:
queryTemplate
- an SQL statement to be sent to the database, typically a static SQL INSERT statementmembership
- A reference to a Membership object that provides its fields as parameters to a PreparedStatement object- Returns:
- True if the result of given query is syntactically correct and is not zero, otherwise false
- See Also:
-
deleteSingleTicketStatement
Allows to make a DML operation to the Ticket table in IPT database, SQL DELETE in this case, and get the result of the given SQL DELETE operation The returning integer value is put in a static int object, such as queryOutputDML variable.- Parameters:
queryTemplate
- An SQL statement to be sent to the database, typically a static SQL DELETE statement- Returns:
- True if the result of given query is syntactically correct and is not zero, otherwise false
- See Also:
-
deleteMembershipStatement
Allows to make a DML operation to the Membership table in IPT database, SQL DELETE in this case, and get the result of the given SQL DELETE operation The returning integer value is put in a static int object, such as queryOutputDML variable.- Parameters:
queryTemplate
- An SQL statement to be sent to the database, typically a static SQL DELETE statement- Returns:
- True if the result of given query is syntactically correct and is not zero, otherwise false
- See Also:
-
updateTransactionStatement
Allows to make a DML operation to the Transaction table in IPT database, SQL INSERT in this case, and get the result of the given SQL INSERT operation The returning integer value is put in a static int object, such as queryOutputDML variable.- Parameters:
queryTemplate
- An SQL statement to be sent to the database, typically a static SQL INSERT statementlocalOrder
- A reference to a Order object that provides its fields as parameters to a PreparedStatement object- Returns:
- True if the result of given query is syntactically correct and is not zero, otherwise false
- See Also:
-
validateGeneratedTransactionID
Validates a 5-chars transaction code generated using randomUUID method and converted to a String object. Checks if the transaction code string is not already used by a record in the Transaction table of IPT database- Parameters:
transactionCode
- A 5-chars transaction code generated using randomUUID method and converted to a String object.- Returns:
- True if the transaction code is not already used, so it is a valid transaction code, otherwise false
- See Also:
-
insertTransaction
public static boolean insertTransaction()Inserts an order made by the logged citizen as a transaction record to the Transaction table of IPT database. This operation obviously involves the insertion of the travel documents, bought by the logged citizen, in the Ticket and Membership tables of IPT database.- Returns:
- True on success, otherwise false
- See Also:
-
UUID.randomUUID()
ObservableSingleton.updateOrderWithOrderID(String, LocalDate, double, String, PaymentMethodStrategy, ArrayList, ObservableList)
updateTransactionStatement(String, Order)
TravelDocument.updateTravelDocument(double, LocalDate, LocalDate, String, String, String, LocalDate, LocalDate)
updateTicketStatement(String, SingleTicket)
updateMembershipStatement(String, Membership)
-
checkTicketIssueDateValidity
Validates an issue date for a SingleTicket object. Tickets cannot be bought for an inactive line.- Parameters:
ticketLineID
- A string that represents a unique identifier of a lineticketIssueDate
- An issue date for the ticket- Returns:
- True if the issue date of the ticket is valid, otherwise false
- See Also:
-
validateRide
Checks if the ticket that a citizen is going to buy is a ticket for a valid line and ride.- Parameters:
ticketLineID
- A unique identifier of the line to validateticketRideID
- A unique identifier of the ride to validate- Returns:
- True if the line and the ride are valid, otherwise false
- See Also:
-
getMyTicketsViewContent
Returns the tickets bought by the logged citizen that are displayed in the MyTickets view- Returns:
- An ObservableList
used for displaying items in a TableView JavaFX object - See Also:
-
FXCollections.observableArrayList()
executeQuery(String)
List.add(Object)
-
deleteMySingleTicket
Deletes a ticket bought by the logged citizen from the Ticket table of IPT database- Parameters:
localSingleTicket
- A reference to a TravelDocumentFX object, representing a ticket- Returns:
- True on success, otherwise false
- See Also:
-
getMyMembershipsViewContent
Returns the memberships bought by the logged citizen that are displayed in the MyMemberships view- Returns:
- An ObservableList
used for displaying items in a TableView JavaFX object - See Also:
-
deleteMyMembership
Deletes a membership bought by the logged citizen from the Ticket table of IPT database- Parameters:
localMembership
- A reference to a TravelDocumentFX object, representing a membership- Returns:
- True on success, otherwise false
- See Also:
-
getNoticesViewContent
Returns the notices issued by IPT that are displayed in the Notices view- Returns:
- An ObservableList
used for displaying items in a TableView JavaFX object - See Also:
-
getCorsaLineaViewContent
Returns information about the IPT lines and rides that are displayed in Info view- Returns:
- An ObservableList
used for displaying items in a TableView JavaFX object - See Also:
-
insertCitizenQuerySender
Returns the result of an SQL INSERT operation in the Citizen table of IPT database- Parameters:
queryTemplate
- An SQL statement to be sent to the database, typically a static SQL INSERT statementnewCitizen
- A reference to a Citizen object that provides its fields to a PreparedStatement object- Returns:
- True if the given query is syntactically correct and the result is not zero, otherwise false
- See Also:
-
updateCitizenQuerySender
Updates logged citizen's data in the Citizen table of IPT database- Parameters:
queryTemplate
- An SQL statement to be sent to the database, typically a static SQL UPDATE statementnewCitizen
- A reference to a Citizen object, typically an IPT user- Returns:
- See Also:
-
retrieveCitizen
Retrieves data about citizen signed in with a given username and a given password- Parameters:
citizenUsername
- A string that represents the username of a CitizencitizenPassword
- A string that represents the password of a Citizen- Returns:
- A reference to a Citizen object if the given username and the given password are valid, otherwise null
- See Also:
-
insertCitizen
Inserts a Citizen record in the Citizen table of IPT database- Parameters:
localCitizen
- A reference to a Citizen object, typically a new user- Returns:
- True on success, otherwise false
- See Also:
-
validateGeneratedCitizenID
Validates a 5-chars citizen unique identifier generated using randomUUID method and converted to a String object. Checks if the citizen unique identifier string is not already used by a record in the Citizen table of IPT database- Parameters:
localCitizen
- A 5-chars citizen unique identifier generated using randomUUID method and converted to a String object.- Returns:
- True if the citizen unique identifier is not already used, so it is a valid citizen unique identifier, otherwise false
- See Also:
-
updateCitizenData
Updates logged citizen's data in the Citizen table of IPT database- Returns:
- True on success, otherwise false
- See Also:
-
validateGeneratedSingleTicketID
Validates a 5-chars ticket unique identifier generated using randomUUID method and converted to a String object. Checks if the ticket unique identifier string is not already used by a record in the Ticket table of IPT database- Parameters:
singleTicketID
- A 5-chars ticket unique identifier generated using randomUUID method and converted to a String object.- Returns:
- True if the ticket unique identifier is not already used, so it is a valid ticket unique identifier, otherwise false
- See Also:
-
validateGeneratedMembershipID
Validates a 5-chars membership unique identifier generated using randomUUID method and converted to a String object. Checks if the membership unique identifier string is not already used by a record in the Ticket table of IPT database- Parameters:
membershipID
- A 5-chars membership unique identifier generated using randomUUID method and converted to a String object.- Returns:
- True if the membership unique identifier is not already used, so it is a valid membership unique identifier, otherwise false
- See Also:
-
getSaltFromDB
private static boolean getSaltFromDB()Return the salt key stored into the salt field in the Salt table of IPT database.- Returns:
- True on success, otherwise false
- See Also:
-
getSalt
Builds the salt key as string- Parameters:
length
- The length of the salt key as integer value- Returns:
- A string that represents a new salt key string
-
hash
private static byte[] hash(char[] password, byte[] salt) Hash function to generete a secret key- Parameters:
password
- An array of characters representing a password stringsalt
- An array of bytes representing the salt key- Returns:
- A secret key as an array of bytes
- See Also:
-
generateSecurePassword
Generates a secure password stored in the password field in the Citizen table of IPT database- Parameters:
password
- A string that represents a user password- Returns:
- A coded string for the given password
- See Also:
-
verifyUserPassword
Verifies the given user password is valid- Parameters:
providedPassword
- A string that represents a user passwordsecuredPassword
- A string that represents a secured password stored in the password filed of a Citizen record in the Citizen table of IPT database- Returns:
- True if the given user password is valid, otherwise false
- See Also:
-