public class ArticleImporterFromFile
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
private ArticleImportationObserver |
observer
The observer is informed when a new article is imported
|
Constructor and Description |
---|
ArticleImporterFromFile(ArticleImportationObserver observer) |
Modifier and Type | Method and Description |
---|---|
private static java.util.List<Article> |
checkContentConsistency(java.util.List<org.apache.commons.csv.CSVRecord> records)
Checks if all the records, except headers, of the CSV file are consistent.
|
private static java.util.List<Article> |
checkFileConsistency(java.util.List<org.apache.commons.csv.CSVRecord> records)
Checks if the CSV file is consistent (headers + records).
|
private static void |
checkFileHeadersConsistency(org.apache.commons.csv.CSVRecord headerRecords)
Checks if the headers are equal to Headers Enum(Name, Unit, Price)
|
private void |
importData(java.io.File file,
Shop targetShop)
Checks the consistency of a CSV file and import all the records if it is consistent.
|
void |
importFrom(Shop targetShop)
Displays a file chooser to select a CSV file to import and process the importation.
|
private void |
insertToDatabase(java.util.List<Article> articlesToImport,
Shop shop)
Inserts all the articles into the shop, by adding the products and articles in the database
|
private ArticleImportationObserver observer
public ArticleImporterFromFile(ArticleImportationObserver observer)
public void importFrom(Shop targetShop) throws DatabaseConnectionException, CSVNotConsistentException, NoFileSelectedException
targetShop
- Shop in which the articles are imported.DatabaseConnectionException
CSVNotConsistentException
NoFileSelectedException
private void importData(java.io.File file, Shop targetShop) throws CSVNotConsistentException, DatabaseConnectionException
file
- File to importtargetShop
- Shop in which the articles are imported.CSVNotConsistentException
DatabaseConnectionException
private static java.util.List<Article> checkFileConsistency(java.util.List<org.apache.commons.csv.CSVRecord> records) throws HeadersNotConsistentException, RecordNotConsistentException
records
- Records of the imported CSV fileHeadersNotConsistentException
RecordNotConsistentException
private void insertToDatabase(java.util.List<Article> articlesToImport, Shop shop) throws DatabaseConnectionException
articlesToImport
- all the articles to importshop
- Shop in which the articles are imported.DatabaseConnectionException
private static void checkFileHeadersConsistency(org.apache.commons.csv.CSVRecord headerRecords) throws HeadersNotConsistentException
headerRecords
- Header of the imported CSV fileHeadersNotConsistentException
private static java.util.List<Article> checkContentConsistency(java.util.List<org.apache.commons.csv.CSVRecord> records) throws RecordNotConsistentException
records
- Records of the imported CSV fileRecordNotConsistentException