OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 156 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
144 ilm 1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved.
5
 *
6
 * The contents of this file are subject to the terms of the GNU General Public License Version 3
7
 * only ("GPL"). You may not use this file except in compliance with the License. You can obtain a
8
 * copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific
9
 * language governing permissions and limitations under the License.
10
 *
11
 * When distributing the software, include this License Header Notice in each file.
12
 */
13
 
14
 package org.openconcerto.erp.utils;
15
 
16
import org.openconcerto.erp.config.ComptaPropsConfiguration;
17
import org.openconcerto.erp.config.MainFrame;
18
import org.openconcerto.sql.Configuration;
19
import org.openconcerto.sql.model.DBRoot;
20
import org.openconcerto.utils.i18n.TranslationManager;
21
 
22
public class HeadlessGestion {
23
    private final ComptaPropsConfiguration comptaPropsConfiguration;
24
 
25
    public HeadlessGestion() {
26
        this.comptaPropsConfiguration = ComptaPropsConfiguration.create();
27
    }
28
 
151 ilm 29
    public HeadlessGestion setup(int userId, int companyId) {
30
        try {
31
            this.comptaPropsConfiguration.getUserManager().setCurrentUserID(userId);
32
            this.comptaPropsConfiguration.setUpSocieteDataBaseConnexion(companyId);
156 ilm 33
            // finish filling the configuration before going any further, otherwise the
34
            // SQLElementDirectory is not coherent
35
            this.comptaPropsConfiguration.getModuleManager().init();
151 ilm 36
        } catch (Exception e) {
156 ilm 37
            throw new IllegalStateException("Unable to configure connection for userId: " + userId + " companyId: " + companyId, e);
151 ilm 38
        }
39
        return this;
40
    }
41
 
144 ilm 42
    public HeadlessGestion setupGlobalState(int userId, int companyId) {
156 ilm 43
        // setUpSocieteDataBaseConnexion() called by setup() needs the directory and elements need
44
        // Configuration.getInstance()
151 ilm 45
        setGlobalState();
156 ilm 46
        setup(userId, companyId);
151 ilm 47
        return this;
48
    }
49
 
50
    public HeadlessGestion setGlobalState() {
144 ilm 51
        System.setProperty("java.awt.headless", "true");
177 ilm 52
        TranslationManager.addTranslationStreamFromClass(MainFrame.class);
53
        TranslationManager.createDefaultInstance();
156 ilm 54
        // TODO remove
144 ilm 55
        Configuration.setInstance(this.comptaPropsConfiguration);
56
        return this;
57
    }
58
 
59
    public ComptaPropsConfiguration getComptaPropsConfiguration() {
60
        return this.comptaPropsConfiguration;
61
    }
62
 
63
    public DBRoot getCompanyRoot() {
64
        return this.comptaPropsConfiguration.getRootSociete();
65
    }
66
 
67
    public DBRoot getCommonRoot() {
68
        return this.comptaPropsConfiguration.getRoot();
69
    }
70
}