OpenConcerto

Dépôt officiel du code source de l'ERP OpenConcerto
sonarqube

svn://code.openconcerto.org/openconcerto

Rev

Rev 149 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 149 Rev 174
Line 161... Line 161...
161
     * Parse all receipts logged in this. This also validates that data recorded in this log matches
161
     * Parse all receipts logged in this. This also validates that data recorded in this log matches
162
     * the parsed receipts' files.
162
     * the parsed receipts' files.
163
     * 
163
     * 
164
     * @return the list of current receipts in this.
164
     * @return the list of current receipts in this.
165
     * @throws ParseException if an entry couldn't be parsed.
165
     * @throws ParseException if an entry couldn't be parsed.
-
 
166
     * @throws IOException if the receipts couldn't be parsed.
166
     */
167
     */
167
    public final List<Ticket> parseReceipts() throws ParseException {
168
    public final List<Ticket> parseReceipts() throws ParseException, IOException {
168
        final List<Ticket> receipts = new ArrayList<>();
169
        final List<Ticket> receipts = new ArrayList<>();
169
        final Path toUse = this.getLogFile().getParent();
170
        final Path toUse = this.getLogFile().getParent();
170
        final List<ReceiptEntry> receiptEvents = this.getReceiptEvents();
171
        final List<ReceiptEntry> receiptEvents = this.getReceiptEvents();
171
        String lastHash = this.getFirstRegisterEvent().getLastReceiptHash();
172
        String lastHash = this.getFirstRegisterEvent().getLastReceiptHash();
172
        int index = 1;
173
        int index = 1;
173
        for (final ReceiptEntry receiptEntry : receiptEvents) {
174
        for (final ReceiptEntry receiptEntry : receiptEvents) {
174
            final Path receiptFile = toUse.resolve(receiptEntry.getCode().getFileName());
175
            final Path receiptFile = toUse.resolve(receiptEntry.getCode().getFileName());
-
 
176
            final Ticket receipt;
-
 
177
            try {
175
            final Ticket receipt = Ticket.parseFile(receiptFile.toFile(), HashMode.equalTo(receiptEntry.getFileHash()));
178
                receipt = Ticket.parseFile(receiptFile.toFile(), HashMode.equalTo(receiptEntry.getFileHash()));
-
 
179
            } catch (Exception e) {
-
 
180
                throw new IOException("Couldn't parse file of " + receiptEntry + " : " + receiptFile, e);
-
 
181
            }
-
 
182
            assert receipt != null;
176
            if (!receipt.getCode().equals(receiptEntry.getCodeString()))
183
            if (!receipt.getCode().equals(receiptEntry.getCodeString()))
177
                throw new IllegalStateException("Code mismatch");
184
                throw new IllegalStateException("Code mismatch");
178
            if (!CompareUtils.equals(lastHash, receipt.getPreviousHash()))
185
            if (!CompareUtils.equals(lastHash, receipt.getPreviousHash()))
179
                throw new IllegalStateException("Previous hash mismatch for " + receiptEntry.getCodeString());
186
                throw new IllegalStateException("Previous hash mismatch for " + receiptEntry.getCodeString());
180
            lastHash = receiptEntry.getFileHash();
187
            lastHash = receiptEntry.getFileHash();