OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

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

Rev 174 Rev 177
Line 46... Line 46...
46
import java.util.Calendar;
46
import java.util.Calendar;
47
import java.util.Collections;
47
import java.util.Collections;
48
import java.util.Comparator;
48
import java.util.Comparator;
49
import java.util.Date;
49
import java.util.Date;
50
import java.util.List;
50
import java.util.List;
-
 
51
import java.util.Objects;
51
import java.util.SortedSet;
52
import java.util.SortedSet;
52
import java.util.TreeSet;
53
import java.util.TreeSet;
53
import java.util.logging.Level;
54
import java.util.logging.Level;
54
import java.util.regex.Pattern;
55
import java.util.regex.Pattern;
55
 
56
 
Line 362... Line 363...
362
    }
363
    }
363
 
364
 
364
    public final RegisterLog open(final int userID, final DBState dbState) throws IOException {
365
    public final RegisterLog open(final int userID, final DBState dbState) throws IOException {
365
        if (!this.hasLock.get())
366
        if (!this.hasLock.get())
366
            throw new IllegalStateException("Not locked");
367
            throw new IllegalStateException("Not locked");
-
 
368
        Objects.requireNonNull(dbState, "Missing DBState");
-
 
369
        // pass null RegisterDB since the DB is already open
367
        return createOpen(userID, null, dbState).transformChecked(this);
370
        return createOpen(userID, null, dbState).transformChecked(this);
368
    }
371
    }
369
 
372
 
370
    public final RegisterLog open(final int userID, final RegisterDB registerDB) throws IOException {
373
    public final RegisterLog open(final int userID, final RegisterDB registerDB) throws IOException {
-
 
374
        Objects.requireNonNull(registerDB, "Missing RegisterDB");
-
 
375
        // pass null DBState to ask for the opening
371
        return this.doWithLock(createOpen(userID, registerDB, null));
376
        return this.doWithLock(createOpen(userID, registerDB, null));
372
    }
377
    }
373
 
378
 
374
    static private final ExnTransformer<RegisterFiles, RegisterLog, IOException> createOpen(final int userID, final RegisterDB registerDB, final DBState passedDBState) throws IOException {
379
    static private final ExnTransformer<RegisterFiles, RegisterLog, IOException> createOpen(final int userID, final RegisterDB registerDB, final DBState passedDBState) throws IOException {
375
        // TODO use UpdateDir like save() and close()
380
        // TODO use UpdateDir like save() and close()
376
        return new ExnTransformer<RegisterFiles, RegisterLog, IOException>() {
381
        return new ExnTransformer<RegisterFiles, RegisterLog, IOException>() {
377
            @Override
382
            @Override
378
            public RegisterLog transformChecked(RegisterFiles input) throws IOException {
383
            public RegisterLog transformChecked(RegisterFiles input) throws IOException {
379
                POSConfiguration.getLogger().log(Level.FINE, "Begin opening of FS state for register {0}", input.getPosID());
384
                POSConfiguration.getLogger().log(Level.FINE, "Begin opening of FS state for register {0}", input.getPosID());
380
                POSConfiguration.checkRegisterID(input.getPosID(), registerDB.getPosID());
-
 
381
                final RegisterLog lastLog = input.checkStatus(true);
385
                final RegisterLog lastLog = input.checkStatus(true);
382
                final String lastLocalHash;
386
                final String lastLocalHash;
383
                final Date prevDate;
387
                final Date prevDate;
384
                if (lastLog == null) {
388
                if (lastLog == null) {
385
                    lastLocalHash = null;
389
                    lastLocalHash = null;
Line 396... Line 400...
396
                }
400
                }
397
 
401
 
398
                final DBState dbState;
402
                final DBState dbState;
399
                if (passedDBState == null) {
403
                if (passedDBState == null) {
400
                    try {
404
                    try {
-
 
405
                        POSConfiguration.checkRegisterID(input.getPosID(), registerDB.getPosID());
401
                        dbState = registerDB.open(lastLocalHash, userID);
406
                        dbState = registerDB.open(lastLocalHash, userID);
402
                    } catch (SQLException e) {
407
                    } catch (SQLException e) {
403
                        throw new IOException("Couldn't open the register in the DB", e);
408
                        throw new IOException("Couldn't open the register in the DB", e);
404
                    }
409
                    }
405
                } else {
410
                } else {
Line 442... Line 447...
442
                            e1.printStackTrace();
447
                            e1.printStackTrace();
443
                        }
448
                        }
444
                    }
449
                    }
445
                }
450
                }
446
 
451
 
447
                POSConfiguration.getLogger().log(Level.INFO, "Finished opening of FS state for register {0}", registerDB);
452
                POSConfiguration.getLogger().log(Level.INFO, "Finished opening of FS state for register {0}", input.getPosID());
448
 
453
 
449
                // TODO parse and validate before moving into place
454
                // TODO parse and validate before moving into place
450
                try {
455
                try {
451
                    return new RegisterLog(currentDir.resolve(LOG_FILENAME)).parse();
456
                    return new RegisterLog(currentDir.resolve(LOG_FILENAME)).parse();
452
                } catch (JDOMException e) {
457
                } catch (JDOMException e) {