OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 80 | Rev 93 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 80 Rev 83
Line 35... Line 35...
35
import org.openconcerto.sql.element.SQLElement;
35
import org.openconcerto.sql.element.SQLElement;
36
import org.openconcerto.sql.model.SQLBackgroundTableCache;
36
import org.openconcerto.sql.model.SQLBackgroundTableCache;
37
import org.openconcerto.sql.model.SQLBase;
37
import org.openconcerto.sql.model.SQLBase;
38
import org.openconcerto.sql.model.SQLRow;
38
import org.openconcerto.sql.model.SQLRow;
39
import org.openconcerto.sql.model.SQLRowListRSH;
39
import org.openconcerto.sql.model.SQLRowListRSH;
40
import org.openconcerto.sql.model.SQLRowValues;
-
 
41
import org.openconcerto.sql.model.SQLSelect;
40
import org.openconcerto.sql.model.SQLSelect;
42
import org.openconcerto.sql.model.SQLTable;
41
import org.openconcerto.sql.model.SQLTable;
43
import org.openconcerto.sql.model.UndefinedRowValuesCache;
42
import org.openconcerto.sql.model.UndefinedRowValuesCache;
44
import org.openconcerto.sql.model.Where;
43
import org.openconcerto.sql.model.Where;
45
import org.openconcerto.sql.preferences.SQLPreferences;
44
import org.openconcerto.sql.preferences.SQLPreferences;
Line 49... Line 48...
49
import org.openconcerto.sql.users.User;
48
import org.openconcerto.sql.users.User;
50
import org.openconcerto.sql.users.UserManager;
49
import org.openconcerto.sql.users.UserManager;
51
import org.openconcerto.sql.users.rights.TableAllRights;
50
import org.openconcerto.sql.users.rights.TableAllRights;
52
import org.openconcerto.sql.users.rights.UserRightsManager;
51
import org.openconcerto.sql.users.rights.UserRightsManager;
53
import org.openconcerto.sql.users.rights.UserRightsManager.RightTuple;
52
import org.openconcerto.sql.users.rights.UserRightsManager.RightTuple;
-
 
53
import org.openconcerto.sql.utils.BackupPanel;
54
import org.openconcerto.task.config.ComptaBasePropsConfiguration;
54
import org.openconcerto.task.config.ComptaBasePropsConfiguration;
55
import org.openconcerto.ui.DefaultGridBagConstraints;
55
import org.openconcerto.ui.DefaultGridBagConstraints;
56
import org.openconcerto.ui.FrameUtil;
56
import org.openconcerto.ui.FrameUtil;
-
 
57
import org.openconcerto.ui.component.MutableListComboPopupListener;
57
import org.openconcerto.utils.ExceptionHandler;
58
import org.openconcerto.utils.ExceptionHandler;
58
import org.openconcerto.utils.JImage;
59
import org.openconcerto.utils.JImage;
59
import org.openconcerto.utils.cc.IClosure;
60
import org.openconcerto.utils.cc.IClosure;
60
import org.openconcerto.utils.i18n.TranslationManager;
61
import org.openconcerto.utils.i18n.TranslationManager;
61
 
62
 
Line 63... Line 64...
63
import java.awt.GridBagConstraints;
64
import java.awt.GridBagConstraints;
64
import java.awt.GridBagLayout;
65
import java.awt.GridBagLayout;
65
import java.awt.Image;
66
import java.awt.Image;
66
import java.awt.Insets;
67
import java.awt.Insets;
67
import java.io.InputStream;
68
import java.io.InputStream;
68
import java.sql.SQLException;
-
 
69
import java.util.ArrayList;
69
import java.util.ArrayList;
70
import java.util.Arrays;
70
import java.util.Arrays;
71
import java.util.List;
71
import java.util.List;
72
import java.util.Locale;
72
import java.util.Locale;
73
import java.util.concurrent.CountDownLatch;
73
import java.util.concurrent.CountDownLatch;
Line 94... Line 94...
94
    public JFrame createFrame() {
94
    public JFrame createFrame() {
95
        // needed as done() must come after us
95
        // needed as done() must come after us
96
        assert SwingUtilities.isEventDispatchThread();
96
        assert SwingUtilities.isEventDispatchThread();
97
        final ComptaPropsConfiguration comptaPropsConfiguration = ((ComptaPropsConfiguration) Configuration.getInstance());
97
        final ComptaPropsConfiguration comptaPropsConfiguration = ((ComptaPropsConfiguration) Configuration.getInstance());
98
 
98
 
99
        // Vérification de la licence
-
 
100
 
-
 
101
        Runnable r = new Runnable() {
99
        Runnable r = new Runnable() {
102
 
100
 
103
            public void run() {
101
            public void run() {
104
                try {
102
                try {
105
                    TranslationManager.getInstance().addTranslationStreamFromClass(MainFrame.class);
103
                    TranslationManager.getInstance().addTranslationStreamFromClass(MainFrame.class);
Line 137... Line 135...
137
                        // don't die now, we might not need them
135
                        // don't die now, we might not need them
138
                        ExceptionHandler.handle("Impossible d'accéder aux préférences", e);
136
                        ExceptionHandler.handle("Impossible d'accéder aux préférences", e);
139
                    }
137
                    }
140
                    // needed by openEmergencyModuleManager()
138
                    // needed by openEmergencyModuleManager()
141
                    UserRightsManager.getInstance().addRightForAdmins(new RightTuple(ModuleManager.MODULE_DB_RIGHT, true));
139
                    UserRightsManager.getInstance().addRightForAdmins(new RightTuple(ModuleManager.MODULE_DB_RIGHT, true));
-
 
140
                    UserRightsManager.getInstance().addRightForAdmins(new RightTuple(BackupPanel.RIGHT_CODE, true));
142
                    // finish filling the configuration before going any further, otherwise the
141
                    // finish filling the configuration before going any further, otherwise the
143
                    // SQLElementDirectory is not coherent
142
                    // SQLElementDirectory is not coherent
144
                    ModuleManager.getInstance().setup(comptaPropsConfiguration.getRootSociete(), comptaPropsConfiguration);
143
                    ModuleManager.getInstance().setup(comptaPropsConfiguration.getRootSociete(), comptaPropsConfiguration);
145
                    try {
144
                    try {
146
                        ModuleManager.getInstance().init();
145
                        ModuleManager.getInstance().init();
Line 149... Line 148...
149
                        openEmergencyModuleManager("Impossible de configurer les modules requis", e);
148
                        openEmergencyModuleManager("Impossible de configurer les modules requis", e);
150
                        return;
149
                        return;
151
                    }
150
                    }
152
                    MenuManager.setInstance((Gestion.isMinimalMode() ? new MinimalMenuConfiguration() : new DefaultMenuConfiguration()).createMenuAndActions());
151
                    MenuManager.setInstance((Gestion.isMinimalMode() ? new MinimalMenuConfiguration() : new DefaultMenuConfiguration()).createMenuAndActions());
153
 
152
 
154
                    User user = UserManager.getInstance().getCurrentUser();
153
                    final User user = UserManager.getInstance().getCurrentUser();
155
                    // Si l'utilisateur n'est pas superUser ou si il n'a pas de droit d'accéder
154
                    // Si l'utilisateur n'est pas superUser ou si il n'a pas de droit d'accéder
156
                    // à toutes les société
155
                    // à toutes les société
157
                    final int userId = user.getId();
156
                    final int userId = user.getId();
158
                    if (!user.getRights().isSuperUser() && !user.getRights().haveRight("ACCES_ALL_SOCIETE")) {
157
                    if (!user.getRights().isSuperUser() && !user.getRights().haveRight("ACCES_ALL_SOCIETE")) {
159
                        final boolean emptyMeansAllow;
158
                        final boolean emptyMeansAllow;
Line 198... Line 197...
198
                        @Override
197
                        @Override
199
                        public void run() {
198
                        public void run() {
200
                            // even for quick login, check the license before displaying the main
199
                            // even for quick login, check the license before displaying the main
201
                            // frame
200
                            // frame
202
 
201
 
-
 
202
                            MutableListComboPopupListener.setLockOverridable(user.getRights().isSuperUser());
-
 
203
 
203
                            StatusPanel.getInstance().fireStatusChanged();
204
                            StatusPanel.getInstance().fireStatusChanged();
204
                            final MainFrame f = new MainFrame();
205
                            final MainFrame f = new MainFrame();
205
                            String version = comptaPropsConfiguration.getVersion();
206
                            String version = comptaPropsConfiguration.getVersion();
206
                            final String socTitle = comptaPropsConfiguration.getRowSociete() == null ? "" : ", [Société " + comptaPropsConfiguration.getRowSociete().getString("NOM") + "]";
207
                            final String socTitle = comptaPropsConfiguration.getRowSociete() == null ? "" : ", [Société " + comptaPropsConfiguration.getRowSociete().getString("NOM") + "]";
207
                            f.setTitle(comptaPropsConfiguration.getAppName() + " " + version + socTitle);
208
                            f.setTitle(comptaPropsConfiguration.getAppName() + " " + version + socTitle);
Line 247... Line 248...
247
                    });
248
                    });
248
                    initCache(comptaPropsConfiguration);
249
                    initCache(comptaPropsConfiguration);
249
                    // don't close ConnexionPanel until the main frame is shown
250
                    // don't close ConnexionPanel until the main frame is shown
250
                    showMainFrame.get();
251
                    showMainFrame.get();
251
                } catch (Throwable e) {
252
                } catch (Throwable e) {
252
                    ExceptionHandler.handle("Erreur de connexion", e);
253
                    if (e.getMessage() != null && e.getMessage().contains("TR_BON_DE_LIVRAISON not found")) {
-
 
254
                        JOptionPane.showMessageDialog(new JFrame(), "Votre base de données n'est pas à jour.\nUtilisez l'outil de configuration et pensez à l'achat du manuel!!!");
253
                }
255
                        return;
254
            }
256
                    }
255
 
-
 
256
            private void fixEcriture() {
-
 
257
                // FIXME Bug archive ecriture (ecriture non archivé ayant un id_mouvement=1)
-
 
258
                SQLElement elt = Configuration.getInstance().getDirectory().getElement("ECRITURE");
-
 
259
                SQLSelect sel = new SQLSelect();
-
 
260
                sel.addSelect(elt.getTable().getKey());
-
 
261
 
-
 
262
                Where w = new Where(elt.getTable().getField("ID_MOUVEMENT"), "=", 1);
-
 
263
                sel.setWhere(w);
-
 
264
                System.err.println(sel.asString());
-
 
265
                List<SQLRow> lerrors = (List<SQLRow>) Configuration.getInstance().getBase().getDataSource().execute(sel.asString(), new SQLRowListRSH(elt.getTable()));
-
 
266
                for (SQLRow row : lerrors) {
-
 
267
                    System.err.println("FIX ERROR ID_MOUVEMENT ON ECRITURE ROW " + row.getID());
-
 
268
                    SQLRowValues rowVals = row.createEmptyUpdateRow();
257
                    ExceptionHandler.handle("Erreur de connexion", e);
269
                    rowVals.put("ARCHIVE", 1);
-
 
270
                    try {
-
 
271
                        rowVals.update();
-
 
272
                    } catch (SQLException e) {
-
 
273
                        // TODO Auto-generated catch block
-
 
274
                        e.printStackTrace();
-
 
275
                    }
258
                }
276
 
-
 
277
                }
259
            }
278
 
260
 
279
                if (lerrors.size() > 0) {
-
 
280
                    System.err.println(lerrors.size() + " erreurs");
-
 
281
                    Thread.dumpStack();
-
 
282
                    // JOptionPane.showMessageDialog(null, lerrors.size() +
-
 
283
                    // " erreurs ont été trouvé et corrigé dans la base.");
-
 
284
                }
-
 
285
            }
-
 
286
        };
261
        };
287
 
262
 
288
        final JImage image = new JImage(ComptaBasePropsConfiguration.class.getResource("logo.png"));
263
        final JImage image = new JImage(ComptaBasePropsConfiguration.class.getResource("logo.png"));
289
        Image customImage = ComptaPropsConfiguration.getInstanceCompta().getCustomLogo();
264
        Image customImage = ComptaPropsConfiguration.getInstanceCompta().getCustomLogo();
290
        if (customImage != null) {
265
        if (customImage != null) {