alphagov/trade-tariff-backend — pull request #94 by sauliusg (2013-08-02 11:50:51+00:00)
Title: Taric importer refactoring and validation fix

There are two main changes here:

* Taric Importer refactoring. It used to rely on hashes and proc's and they are hard to test and override if needed. Now it relies on class naming convention and duck typing instead. This makes specs easier to write (and read) and code to understand. Added some additional integration specs with Measure creation to ensure that we are really working.
* Fixes an false positive conformance error we witnessed in Taric update for 31st of July (`2013-07-31_TGB13144.xml`) which said:

````
FO4
At least one description record is mandatory.
The start date of the first description period must be equal to the start date of the footnote. No two associated description periods may have the same start date.
The start date must be less than or equal to the end date of the footnote.
````

Why is this happening? Take a look at related long-ish Taric update excerpt which creates footnote, its description period and description:

````xml

13924647
200
00
3
3

TM
835
2013-08-01

13924647
200
05
4
3

96485
TM
835
2013-08-01

13924647
200
10
5
3

96485
EN
TM
835
The frequency of physical checks carried out by the Member States shall be significantly reduced provided that the consignments are accompanied by the following documents:(a) the results of sampling and analysis performed by a USDA approved laboratory carried out in accordance with or equivalent to the provisions of Commission Regulation (EC) No 401/2006 of 23 February 2006 laying down the methods of sampling and analysis for the official control of mycotoxins in foodstuffs (TARIC certificate code C692); (b) a certificate in accordance with the model set out in the Annex of Decision 47/2008, completed, signed and verified by an authorised representative of the USDA for foodstuffs from the United States of America (TARIC certificate code C691).

````

Since we process these records one by one we created and validated footnote first and found no associated description period. This change fixes that by enhancing `TaricImporter::Transaction` which now keeps records inside FIFO structure (Stack) and validates them in reverse order.