OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 156 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

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