OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

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

Rev 73 Rev 80
Line 17... Line 17...
17
import org.openconcerto.erp.config.ComptaPropsConfiguration;
17
import org.openconcerto.erp.config.ComptaPropsConfiguration;
18
import org.openconcerto.erp.config.DefaultMenuConfiguration;
18
import org.openconcerto.erp.config.DefaultMenuConfiguration;
19
import org.openconcerto.erp.config.Gestion;
19
import org.openconcerto.erp.config.Gestion;
20
import org.openconcerto.erp.config.Log;
20
import org.openconcerto.erp.config.Log;
21
import org.openconcerto.erp.config.MainFrame;
21
import org.openconcerto.erp.config.MainFrame;
-
 
22
import org.openconcerto.erp.config.MenuManager;
-
 
23
import org.openconcerto.erp.config.MinimalMenuConfiguration;
22
import org.openconcerto.erp.core.common.ui.PanelFrame;
24
import org.openconcerto.erp.core.common.ui.PanelFrame;
23
import org.openconcerto.erp.core.common.ui.StatusPanel;
25
import org.openconcerto.erp.core.common.ui.StatusPanel;
24
import org.openconcerto.erp.core.finance.tax.model.TaxeCache;
26
import org.openconcerto.erp.core.finance.tax.model.TaxeCache;
25
import org.openconcerto.erp.core.humanresources.payroll.element.CaisseCotisationSQLElement;
27
import org.openconcerto.erp.core.humanresources.payroll.element.CaisseCotisationSQLElement;
26
import org.openconcerto.erp.element.objet.ClasseCompte;
28
import org.openconcerto.erp.element.objet.ClasseCompte;
Line 56... Line 58...
56
import org.openconcerto.utils.JImage;
58
import org.openconcerto.utils.JImage;
57
import org.openconcerto.utils.cc.IClosure;
59
import org.openconcerto.utils.cc.IClosure;
58
import org.openconcerto.utils.i18n.TranslationManager;
60
import org.openconcerto.utils.i18n.TranslationManager;
59
 
61
 
60
import java.awt.Color;
62
import java.awt.Color;
61
import java.awt.Dimension;
-
 
62
import java.awt.GridBagConstraints;
63
import java.awt.GridBagConstraints;
63
import java.awt.GridBagLayout;
64
import java.awt.GridBagLayout;
64
import java.awt.Image;
65
import java.awt.Image;
65
import java.awt.Insets;
66
import java.awt.Insets;
66
import java.io.InputStream;
67
import java.io.InputStream;
Line 82... Line 83...
82
import javax.swing.SwingWorker;
83
import javax.swing.SwingWorker;
83
import javax.swing.UIManager;
84
import javax.swing.UIManager;
84
 
85
 
85
public class NouvelleConnexionAction extends CreateFrameAbstractAction {
86
public class NouvelleConnexionAction extends CreateFrameAbstractAction {
86
    private ConnexionPanel connexionPanel;
87
    private ConnexionPanel connexionPanel;
87
    // Module configuration frame used when something goes wrong
-
 
88
    private ModuleFrame fMod;
-
 
89
 
88
 
90
    public NouvelleConnexionAction() {
89
    public NouvelleConnexionAction() {
91
        super();
90
        super();
92
        this.putValue(Action.NAME, "Changer d'utilisateur");
91
        this.putValue(Action.NAME, "Changer d'utilisateur");
93
    }
92
    }
Line 136... Line 135...
136
                        SQLPreferences.startMemCached(comptaPropsConfiguration.getRootSociete());
135
                        SQLPreferences.startMemCached(comptaPropsConfiguration.getRootSociete());
137
                    } catch (Exception e) {
136
                    } catch (Exception e) {
138
                        // don't die now, we might not need them
137
                        // don't die now, we might not need them
139
                        ExceptionHandler.handle("Impossible d'accéder aux préférences", e);
138
                        ExceptionHandler.handle("Impossible d'accéder aux préférences", e);
140
                    }
139
                    }
-
 
140
                    // needed by openEmergencyModuleManager()
-
 
141
                    UserRightsManager.getInstance().addRightForAdmins(new RightTuple(ModuleManager.MODULE_DB_RIGHT, true));
141
                    // finish filling the configuration before going any further, otherwise the
142
                    // finish filling the configuration before going any further, otherwise the
142
                    // SQLElementDirectory is not coherent
143
                    // SQLElementDirectory is not coherent
143
                    try {
-
 
144
                        ModuleManager.getInstance().setup(comptaPropsConfiguration.getRootSociete(), comptaPropsConfiguration);
144
                    ModuleManager.getInstance().setup(comptaPropsConfiguration.getRootSociete(), comptaPropsConfiguration);
-
 
145
                    try {
-
 
146
                        ModuleManager.getInstance().init();
145
                    } catch (Throwable e) {
147
                    } catch (Throwable e) {
146
                        // not OK to continue without required elements
148
                        // not OK to continue without required elements
147
                        openEmergencyModuleManager("Impossible de configurer les modules requis", e);
149
                        openEmergencyModuleManager("Impossible de configurer les modules requis", e);
148
                        return;
150
                        return;
149
                    }
151
                    }
-
 
152
                    MenuManager.setInstance((Gestion.isMinimalMode() ? new MinimalMenuConfiguration() : new DefaultMenuConfiguration()).createMenuAndActions());
-
 
153
 
-
 
154
                    User user = UserManager.getInstance().getCurrentUser();
-
 
155
                    // Si l'utilisateur n'est pas superUser ou si il n'a pas de droit d'accéder
-
 
156
                    // à toutes les société
-
 
157
                    final int userId = user.getId();
-
 
158
                    if (!user.getRights().isSuperUser() && !user.getRights().haveRight("ACCES_ALL_SOCIETE")) {
-
 
159
                        final boolean emptyMeansAllow;
-
 
160
                        {
-
 
161
                            emptyMeansAllow = true;
-
 
162
                        }
-
 
163
 
-
 
164
                        final SQLTable tableAcces = comptaPropsConfiguration.getRoot().findTable("ACCES_SOCIETE");
-
 
165
                        SQLSelect sel = new SQLSelect();
-
 
166
                        sel.addSelectStar(tableAcces);
-
 
167
                        sel.setWhere(new Where(tableAcces.getField("ID_USER_COMMON"), "=", userId));
-
 
168
                        if (!emptyMeansAllow) {
-
 
169
                            sel.andWhere(new Where(tableAcces.getField("ID_SOCIETE_COMMON"), "=", selectedSociete));
-
 
170
                        }
-
 
171
 
-
 
172
                        final List<SQLRow> accessRows = SQLRowListRSH.execute(sel);
-
 
173
                        final boolean accessGranted;
-
 
174
                        if (!emptyMeansAllow) {
-
 
175
                            accessGranted = accessRows.size() > 0;
-
 
176
                        } else {
-
 
177
                            if (accessRows.size() == 0) {
-
 
178
                                accessGranted = true;
-
 
179
                            } else {
-
 
180
                                boolean tmp = false;
-
 
181
                                for (final SQLRow r : accessRows) {
-
 
182
                                    if (r.getInt("ID_SOCIETE_COMMON") == selectedSociete) {
-
 
183
                                        tmp = true;
-
 
184
                                        break;
-
 
185
                                    }
-
 
186
                                }
-
 
187
                                accessGranted = tmp;
-
 
188
                            }
-
 
189
                        }
150
 
190
 
-
 
191
                        if (!accessGranted) {
-
 
192
                            JOptionPane.showMessageDialog(null, "Vous n'avez pas les droits suffisants, pour accéder à cette société!");
-
 
193
                            return;
-
 
194
                        }
-
 
195
                    }
151
 
196
 
152
                    SwingUtilities.invokeLater(new Runnable() {
197
                    SwingUtilities.invokeLater(new Runnable() {
153
                        @Override
198
                        @Override
154
                        public void run() {
199
                        public void run() {
155
                            // even for quick login, check the license before displaying the main
200
                            // even for quick login, check the license before displaying the main
Line 159... Line 204...
159
                            final MainFrame f = new MainFrame();
204
                            final MainFrame f = new MainFrame();
160
                            String version = comptaPropsConfiguration.getVersion();
205
                            String version = comptaPropsConfiguration.getVersion();
161
                            final String socTitle = comptaPropsConfiguration.getRowSociete() == null ? "" : ", [Société " + comptaPropsConfiguration.getRowSociete().getString("NOM") + "]";
206
                            final String socTitle = comptaPropsConfiguration.getRowSociete() == null ? "" : ", [Société " + comptaPropsConfiguration.getRowSociete().getString("NOM") + "]";
162
                            f.setTitle(comptaPropsConfiguration.getAppName() + " " + version + socTitle);
207
                            f.setTitle(comptaPropsConfiguration.getAppName() + " " + version + socTitle);
163
                            f.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
208
                            f.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
164
                            // Init menus
-
 
165
                            // DefaultMenuConfiguration mConfiguration = new
-
 
166
                            // DefaultMenuConfiguration();
-
 
167
                            // mConfiguration.createMenuAndActions();
-
 
168
 
-
 
169
                        }
209
                        }
170
                    });
210
                    });
171
                    final FutureTask<?> showMainFrame = new FutureTask<Object>(new Runnable() {
211
                    final FutureTask<?> showMainFrame = new FutureTask<Object>(new Runnable() {
172
                        @Override
212
                        @Override
173
                        public void run() {
213
                        public void run() {
-
 
214
                            // make sure the application is started with all required and mandatory
-
 
215
                            // modules
174
                            if (ModuleManager.getInstance().isSetup()) {
216
                            if (ModuleManager.getInstance().isInited()) {
175
                                final MainFrame mainFrame = MainFrame.getInstance();
217
                                final MainFrame mainFrame = MainFrame.getInstance();
176
                                mainFrame.initMenuBar();
218
                                mainFrame.initMenuBar();
177
                                FrameUtil.show(mainFrame);
219
                                FrameUtil.show(mainFrame);
178
                            }
220
                            }
179
                        }
221
                        }
Line 183... Line 225...
183
                        public void executeChecked(ModuleManager input) {
225
                        public void executeChecked(ModuleManager input) {
184
                            // start modules before displaying the frame (e.g. avoid modifying a
226
                            // start modules before displaying the frame (e.g. avoid modifying a
185
                            // visible menu bar)
227
                            // visible menu bar)
186
                            try {
228
                            try {
187
                                input.startRequiredModules();
229
                                input.startRequiredModules();
-
 
230
                                try {
188
                                input.startPreviouslyRunningModules();
231
                                    input.startPreviouslyRunningModules();
-
 
232
                                } catch (Exception exn) {
-
 
233
                                    // OK to start the application without all modules started
-
 
234
                                    // but don't continue right away otherwise connexion panel will
-
 
235
                                    // be closed and the popup with it
-
 
236
                                    try {
-
 
237
                                        ExceptionHandler.handle(NouvelleConnexionAction.this.connexionPanel, "Impossible de démarrer les modules", exn).getDialogFuture().get();
-
 
238
                                    } catch (Exception e) {
-
 
239
                                        e.printStackTrace();
-
 
240
                                    }
-
 
241
                                }
189
                                SwingUtilities.invokeLater(showMainFrame);
242
                                SwingUtilities.invokeLater(showMainFrame);
190
                            } catch (Exception exn) {
243
                            } catch (Exception exn) {
191
                                openEmergencyModuleManager("Impossible de démarrer les modules requis", exn);
244
                                openEmergencyModuleManager("Impossible de démarrer les modules requis", exn);
192
                            }
245
                            }
193
 
-
 
194
                        }
246
                        }
195
                    });
247
                    });
196
                    initCache();
248
                    initCache(comptaPropsConfiguration);
197
                    // don't close ConnexionPanel until the main frame is shown
249
                    // don't close ConnexionPanel until the main frame is shown
198
                    showMainFrame.get();
250
                    showMainFrame.get();
199
                } catch (Throwable e) {
251
                } catch (Throwable e) {
200
                    ExceptionHandler.handle("Erreur de connexion", e);
252
                    ExceptionHandler.handle("Erreur de connexion", e);
201
                }
253
                }
Line 260... Line 312...
260
        panelFrame.pack();
312
        panelFrame.pack();
261
        panelFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
313
        panelFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
262
        return panelFrame;
314
        return panelFrame;
263
    }
315
    }
264
 
316
 
265
    private void initCache() {
317
    private void initCache(final ComptaPropsConfiguration comptaConf) {
266
        final SQLBase baseSociete = ((ComptaPropsConfiguration) Configuration.getInstance()).getSQLBaseSociete();
318
        final SQLBase baseSociete = comptaConf.getSQLBaseSociete();
267
        // ensure consistent state before cache loading
-
 
268
        baseSociete.getGraph();
-
 
269
        Thread t = new Thread() {
319
        Thread t = new Thread() {
270
            @Override
320
            @Override
271
            public void run() {
321
            public void run() {
272
                // laisse le temps au logiciel de demarrer
322
                // laisse le temps au logiciel de demarrer
273
                try {
323
                try {
Line 327... Line 377...
327
        Log.get().log(Level.SEVERE, "Normal startup impossible, opening the module manager in order to resolve the issue.", e);
377
        Log.get().log(Level.SEVERE, "Normal startup impossible, opening the module manager in order to resolve the issue.", e);
328
        SwingUtilities.invokeLater(new Runnable() {
378
        SwingUtilities.invokeLater(new Runnable() {
329
            @Override
379
            @Override
330
            public void run() {
380
            public void run() {
331
                ExceptionHandler.handle(str, e);
381
                ExceptionHandler.handle(str, e);
332
                final ModuleFrame fMod = new ModuleFrame();
382
                // can't start since there's no main frame (and obviously no modules can be stopped
333
                fMod.pack();
383
                // since none are running)
334
                fMod.setMinimumSize(new Dimension(480, 640));
384
                final ModuleFrame fMod = ModuleFrame.createInstallOnlyInstance();
335
                fMod.setLocationRelativeTo(null);
-
 
336
                fMod.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
385
                fMod.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
337
                fMod.setTitle(str);
386
                fMod.setTitle(str);
338
                fMod.setVisible(true);
387
                FrameUtil.show(fMod);
339
                fMod.toFront();
-
 
340
            }
388
            }
341
        });
389
        });
342
    }
390
    }
343
}
391
}