OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

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

Rev 151 Rev 156
Line 41... Line 41...
41
 
41
 
42
import org.jdom2.JDOMException;
42
import org.jdom2.JDOMException;
43
 
43
 
44
public class CheckIntegrity {
44
public class CheckIntegrity {
45
 
45
 
46
    public static void main(String[] args) {
46
    public static void main(String[] args) throws JDOMException, IOException {
47
        final POSConfiguration posConf = POSConfiguration.getInstance();
47
        final POSConfiguration posConf = POSConfiguration.setInstance();
48
        final ComptaPropsConfiguration conf = posConf.createConnexion();
48
        final ComptaPropsConfiguration conf = posConf.createConnexion();
49
        try {
49
        try {
50
            for (final RegisterFiles files : RegisterFiles.scan(posConf.getRootDir())) {
50
            for (final RegisterFiles files : RegisterFiles.scan(posConf.getRootDir())) {
51
                final RegisterDB registerDB = new RegisterDB(conf.getDirectory(), conf.getProductInfo(), files.getPosID());
51
                final RegisterDB registerDB = new RegisterDB(conf.getDirectory(), conf.getProductInfo(), files.getPosID());
52
                checkRegisterFiles(registerDB, files);
52
                checkRegisterFiles(registerDB, files);
Line 229... Line 229...
229
                        throw new IllegalStateException("Date in the DB doesn't match log");
229
                        throw new IllegalStateException("Date in the DB doesn't match log");
230
                    if (!row.getString("FILE_HASH").equals(receiptEvent.getFileHash()))
230
                    if (!row.getString("FILE_HASH").equals(receiptEvent.getFileHash()))
231
                        throw new IllegalStateException("File hash in the DB doesn't match log : " + row.getString("FILE_HASH") + " != " + receiptEvent.getFileHash());
231
                        throw new IllegalStateException("File hash in the DB doesn't match log : " + row.getString("FILE_HASH") + " != " + receiptEvent.getFileHash());
232
                    if (!Objects.equals(row.getString("FILE_HASH_PREVIOUS"), receipt.getPreviousHash()))
232
                    if (!Objects.equals(row.getString("FILE_HASH_PREVIOUS"), receipt.getPreviousHash()))
233
                        throw new IllegalStateException("Previous file hash in the DB doesn't match log");
233
                        throw new IllegalStateException("Previous file hash in the DB doesn't match log");
234
                    if (row.getLong("TOTAL_TTC") != receipt.getPaidTotal())
234
                    if (row.getLong("TOTAL_TTC") != receipt.getTotalInCents())
235
                        throw new IllegalStateException("TTC in the DB " + row.getLong("TOTAL_TTC") + " doesn't match log " + receipt.getPaidTotal());
235
                        throw new IllegalStateException("TTC in the DB " + row.getLong("TOTAL_TTC") + " doesn't match log " + receipt.getTotalInCents());
-
 
236
                    // ATTN the paid amount isn't stored in the DB by
-
 
237
                    // POSConfiguration.importReceipts() so we can't check it exactly
-
 
238
                    if (row.getLong("TOTAL_TTC") > receipt.getPaidTotal())
-
 
239
                        throw new IllegalStateException("Paid amount in the log (" + receipt.getPaidTotal() + ") is less than total in the DB " + row.getLong("TOTAL_TTC"));
236
                } catch (Exception exn) {
240
                } catch (Exception exn) {
237
                    throw new IllegalStateException("Error while checking " + row + " against " + receipt + " in " + log, exn);
241
                    throw new IllegalStateException("Error while checking " + row + " against " + receipt + " in " + log, exn);
238
                }
242
                }
239
            }
243
            }
240
            assert !iter.hasNext() && !receiptEventsIter.hasNext();
244
            assert !iter.hasNext() && !receiptEventsIter.hasNext();