Skip to content

Stucom-Pelai/MP0485_Optional_Java_People

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PEOPLE

This desktop application is an academic example of the use of the Model-View-Controller (MVC) code organization system and uses Java as an object-oriented programming language. The application allows the user to do CRUD operations of the defined entity (Person 🙋) and works with different storage systems, both temporary and persistent.

🛠️How it works

The application code is distributed in the following packages:

📦 Model.Class

🗒️ Person.java

Class that defines the type of object with which the application works. In our case it structures the person 🙋 entity. The key attribute that distinguishes one person from another is their NIF. People with the same NIF cannot exist in the applicationThe three main MVC packages do not exchange basic data but rather exchange objects of this class.

🗒️ PersonException.java

Own exception thrown from the Controller package when an attempt is made to insert or delete a person who has not been previously registered. The management of the exception is also carried out within the Controller package by displaying an alert message to the user. It is not necessary to include it for the code to function, but since it is an academic activity it has been deemed appropriate to include it.

📦 Controller

🗒️ IController.java

Interface that defines the operations that the controller, and therefore the application, can perform regardless of the type of storage selected. These operations are: read one or all people, register a person, update a person, and delete one or all people. The use of an interface isolates the Controller package code from the rest of the application packages, minimizing the impact on future software updates.

🗒️ ControllerImplementation.java

Class that implements the IController.java interface. It is responsible for scheduling and managing the events of the visual part. Thanks to these events, it is able to prepare the necessary structure for data storage, operate with these structures and show the information to the user if necessary. This block also manages exceptions that are mainly related to information access problems.

📦 Model.DataAccessObject

🗒️ IDAO.java

This interface defines the operations that will have to be performed on the data storage system chosen by the user. Depending on the system, the implementation varies. These operations are: read one or all people, register a person, update a person, and delete one or all people.The use of an interface allows different classes to be implemented with the appropriate code for data access according to the selected storage structure with minimal impact on the rest of the blocks. This way, the code is better organized and easier to read.

🗒️ DAOArrayList.java

This class implements the IDAO interface and completes the code blocks of the functions so that they can operate with an ArrayList structure where objects are referenced.

🗒️ DAOFile.java

This class implements the IDAO interface and completes the code of the functions so that they can work with files. Each object is decomposed into basic data and saved in the "dataFile.txt" file and the associated photo, if any, is saved with the name NIF.png in the "Photos" folder. Both the "dataFile.txt" file and the "Photos" folder are located under the "File" folder within the application's working folder.

🗒️ DAOFileSerializable.java

This class implements the IDAO interface and completes the code of the functions so that they can work with files. Each object is saved in the "dataFile.ser" file. The "dataFile.ser" file is located under the "FileSer" folder within the application's working folder.

🗒️ DAOHashMap.java

This class implements the IDAO interface and completes the code blocks of the functions so that they can operate with an HashMap structure where objects are referenced.

🗒️ DAOJPA.java

This class implements the IDAO interface and completes the code blocks of the functions so that they can operate with a database designed for object storage using the Java Persistence API.

🗒️ DAOSQL.java

This class implements the IDAO interface and completes the code blocks of the functions so that they can operate with a relational SQL database using the Java Database Connector (JDBC) API. In this type of storage, objects are broken down into basic elements and stored in tables, except for photos of people, which, if present, are stored in the "Photo" folder under the "SQL_Database" directory in the application's working folder. Only the paths to the images are stored in the database.

📦 View

The files in this package contain the graphical part of the application. They have been created with the Swing API. One of the functions of this block is to validate that the data entered by the user is correct. For example: that the NIF cannot contain letters in the numerical part or "strange" symbols, that the user name cannot contain numbers and that the images are in . png format and cannot exceed a size of 64KB.

🗒️ DataStorageSelection.java

Class that allows the user to select the data storage system that the application will use. You can choose between volatile storage systems that reference "Person" objects such as ArrayList and HashMap and non-volatile ones. Within this last group you can choose between systems that store object information in a fractional way in simple data such as files (File) and relational databases (SQL) or systems that store objects as files combined with serialization (File - Serialization) and object-oriented databases (JPA).

🗒️ Menu.java

Class that defines the main panel where the buttons with all the options implemented in the application are displayed and that the user can execute. If this panel is closed, the application also closes.

🗒️ DropPhotoListener.java

Class that implements the DropTargetListener interface and allows the user to drag&drop images.

🗒️ Delete.java

Class that allows deleting a person from their NIF.

🗒️ Insert.java

Class that allows a person to be registered, with the NIF and name being mandatory elements.

🗒️ Read.java

Class that allows you to search for a person based on their NIF.

🗒️ ReadAll.java

Class that shows all registered people.

🗒️ Update.java

Class that allows you to update all of a person's data, except their NIF.

📦 Start

🗒️ Start.java

Class that contains the application's "main" method.

🗒️ Routes.java

Instead of using a text file as a configuration to host the location information for files and folders and the connection to remote storage systems, and since this is an academic application, it was decided to use a special class in Java called Enumeration.

📦 OtherFuncitions

🗒️ DataValidation.java

Class that contains a method for validating data entered by the user.

image

The application flow control is detailed below:

1️⃣ The application starts by executing the Start.java file that contains the "main" method. This method generates a ControllerImplementation (CIO) type object that receives a DataStorageSelection (DSSO) type object as an argument. From CIO, the "listener" is programmed, which in this case will manage the event generated from DSS0 when the user has selected which storage system to work with.

image

2️⃣ Once the user has selected the storage system, the CIO prepares, with the help of the Routes.java file, and certifies that the system is available and generates a DAO object to be able to access the methods that allow CRUD operations to be performed. If the system is available, the CIO shows the user the main screen of the application (Menu.java); otherwise, the user is informed and the application is closed. If during the execution of the application the storage system becomes unavailable, the application will also close after informing the user.

image image

The CIO is also responsible for programming a listener for each menu option. These events triggered from the visual side will cause the CIO to open a new screen with a suitable format so that the user can enter the data and carry out the relevant option. Once the user has selected an option from the menu, the CIO opens a new window and programs the "listeners" that allow him to perform the relevant operations against the storage system thanks to the DAO object.

3️⃣ INSERT: in order to register a person, it is mandatory to enter the NIF and the name. If you try to register a person with an existing NIF, the application does not allow it.

image image

4️⃣ READ: to search for a person you need to enter their NIF and the application will display the data they have registered. If there is no person registered with the NIF entered, the user will be informed.

image image

5️⃣ UPDATE: any attribute of a person can be updated except their NIF. To update a person you need to enter their NIF. If there is no person registered with the NIF entered, the user will be informed.

image image

6️⃣ DELETE: to delete a person you need to enter their NIF. If there is no person registered with the NIF entered, the user will be informed.

image image

7️⃣ READ ALL: the program displays a grid with the available data of all registered persons. If there is no registered person, the program informs the user.

image image

8️⃣ DELETE ALL: his option allows you to delete all registered user information. Before executing it, the program asks the user for confirmation.

image

🚀Getting started

1️⃣ Download version 1.1.0 (.zip) of the project and import it with an IDE that allows you to manage projects developed with Maven, such as Netbeans.

2️⃣ Run the application from the IDE, you can use any storage system, but you need to read this about the options with databases, both SQL and JPA, and files:

2️⃣.1️⃣ SQL: I have used locally the MariaDB database integrated into XAMPP with the root user and without a password. You can modify these parameters in the Routes.java file within the Start package.

2️⃣.2️⃣ JPA: I have used locally the ObjectDB database with the root admin and password a admin. You can modify these parameters in the Routes.java file within the Start package.

3️⃣ For the files I have also used local directories, but you can also use network drives. You can modify these parameters in the Routes.java file within the Start package.

4️⃣ If you want an executable .jar file you must create it yourself.

Releases

No releases published

Packages

No packages published

Languages

  • Java 100.0%