Access a car's revision dates and plate stored in a MySQL database. Data is available in XML format.
The API offers various calls, however keep in mind that the program is still under heavy development; further informations can be found below in the document.
To use both Java and MySQL, JDBC drivers have been used.
To manage each revision, a Database has been created; below the the creation of said Database with relative Table:
CREATE DATABASE CentroRevisioni;
USE CentroRevisioni;
CREATE TABLE revisioni(
targa VARCHAR(16) NOT NULL,
anno_immatricolazione INTEGER NOT NULL,
data_revisione DATE NOT NULL,
mese_scadenza INTEGER NOT NULL,
anno_scadenza INTEGER,
esito CHAR(1) NOT NULL,
PRIMARY KEY(targa, data_revisione)
);
Because the Database contains a Date value, and because it made the code easier to read, a converter class has been created.
This class converts a String (either taken from the URL or Parsed from an XML file) and converts it to a sql.Date value in order to work with the Database.
Source coude is viewable down below, or in its repository folder.
public class Converter {
public Converter(){}
public java.sql.Date stringToDate(String date){
java.sql.Date sqlDate = null;
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
try{
java.util.Date uDate = format.parse(date);
sqlDate = new java.sql.Date(uDate.getTime());
}catch(ParseException exception){}
return sqlDate;
}
}
The API call (executed in GET) returns an XML file which stores every car with an expiring revision.
Every date between a certain span time will be included in the XML file.
http://localhost:8080/CarManager/Servlet/Expiring?start={month/year}&end={month/year}
Format of both parameters is (month/year) e.g. 05/2022.
start- The initial value of the intended range of dates.
end- The end value of the intended range of dates.
Example of API repsonse in case of success:
<revisions>
<car>
<plate>X5D3SL</plate>
</car>
<car>
<plate>XV452BP</plate>
</car>
</revisions>
Example of API response in case of failure:
400 - BAD REQUEST if either the initial or final span is missing; wheter the parameter is malformed or completely missing, a 400 code will be returned.
500 - INTERNAL SERVER ERROR if the connection to the database fails for whichever reason.
The API call (executed in GET) returns an XML file which stores the given car's revision dates.
plate- The plate of the given car.
Example of API response in case of success:
<revision>
<revisionDate>2032-08-10</revisionDate>
<expireMonth>5</expireMonth>
<expireYear>2034</expireYear>
<esit>N</esit>
</revision>
Example of API response in case of failure:
400 - BAD REQUEST if the plate is missing; wheter malformed or completely missing, a 400 code will be returned.
500 - INTERNAL SERVER ERROR if the connection to the database fails for whichever reason.
The API call (executed in GET) returns an XML file which stores every available data of a given car.
http://localhost:8080/CarManager/Servlet/revisions?plate={plate}
plate- The plate of the given car.
Example of API response in case of success:
<revision>
<car>
<plate>X5D3SL</plate>
<matricolation>2022</matricolation>
<revDate>2032-08-10</revDate>
<expireMonth>5</expireMonth>
<expireYear>2034</expireYear>
<esit>N</esit>
</car>
</revision>
Example of API response in case of failure:
400 - BAD REQUEST if the plate is missing; wheter malformed or completely missing, a 400 code will be returned.
500 - INTERNAL SERVER ERROR if the connection to the database fails for whichever reason.
The API call (executed in POST) registers a new car in the "CentroRevisioni" database. Specifically inside the only available table: "revisioni".
The request has no visible parameters, however, an XML file containing every data should be sent. Inside the table, the following data is stored:
targaof type VARCHAR(16)- The plate of the given car.
anno_immatricolazioneof type INTEGER- The year of matricolation of the car.
data_revisioneof type DATE- The year of the first revision performed on the car.
mese_scadenzaof type INTEGER- The expiring month of the current revision.
anno_scadenzaof type INTEGER- The expiring year of the current revision.
esitoof type CHAR(1)- The final esit of the revision: can be either 'S' for "success" or 'N' for failure.
For context, the table's primary key is the (targa, data_revisione) pair.
It is possible to perform CRUD operations on the database, however those are still under development.
The API call (executed in POST) inserts a new revision inside the database.
No visible parameter is needed, however a user should send an XML body containing right and coherent data.
Response in case of success provides no XML body, it does provide a:
200 status code however.
Respose in case of failure:
400 - BAD REQUEST if the one or more parameter(s) are still missing after parsing the XML body sent.
500 - INTERNAL SERVER ERROR if the connection to the database fails for whichever reason.
Not available yet.
Not available yet.
Not available yet.
Further methods, operations and bug-fixes will be included over time.