OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

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

Rev 81 Rev 83
Line 50... Line 50...
50
import org.openconcerto.sql.utils.ChangeTable.ForeignColSpec;
50
import org.openconcerto.sql.utils.ChangeTable.ForeignColSpec;
51
import org.openconcerto.sql.utils.DropTable;
51
import org.openconcerto.sql.utils.DropTable;
52
import org.openconcerto.sql.utils.SQLCreateTable;
52
import org.openconcerto.sql.utils.SQLCreateTable;
53
import org.openconcerto.sql.utils.SQLUtils;
53
import org.openconcerto.sql.utils.SQLUtils;
54
import org.openconcerto.sql.utils.SQLUtils.SQLFactory;
54
import org.openconcerto.sql.utils.SQLUtils.SQLFactory;
55
import org.openconcerto.sql.view.list.RowAction;
55
import org.openconcerto.sql.view.list.IListeAction;
56
import org.openconcerto.ui.SwingThreadUtils;
56
import org.openconcerto.ui.SwingThreadUtils;
57
import org.openconcerto.utils.CollectionMap2.Mode;
57
import org.openconcerto.utils.CollectionMap2.Mode;
58
import org.openconcerto.utils.CollectionUtils;
58
import org.openconcerto.utils.CollectionUtils;
59
import org.openconcerto.utils.ExceptionHandler;
59
import org.openconcerto.utils.ExceptionHandler;
60
import org.openconcerto.utils.FileUtils;
60
import org.openconcerto.utils.FileUtils;
Line 887... Line 887...
887
            vals.put(MODULE_VERSION_COLNAME, factory.getVersion().getMerged());
887
            vals.put(MODULE_VERSION_COLNAME, factory.getVersion().getMerged());
888
            vals.put(MODULE_COLNAME, factory.getID());
888
            vals.put(MODULE_COLNAME, factory.getID());
889
            for (final String added : ctxt.getAddedTables()) {
889
            for (final String added : ctxt.getAddedTables()) {
890
                vals.put(TABLE_COLNAME, added).put(FIELD_COLNAME, null).insert();
890
                vals.put(TABLE_COLNAME, added).put(FIELD_COLNAME, null).insert();
891
                final SQLTable t = ctxt.getRoot().findTable(added);
891
                final SQLTable t = ctxt.getRoot().findTable(added);
-
 
892
                if (t == null) {
-
 
893
                    throw new IllegalStateException("Unable to find added table " + added + " in root " + ctxt.getRoot().getName());
-
 
894
                }
892
                for (final SQLField field : t.getFields()) {
895
                for (final SQLField field : t.getFields()) {
893
                    vals.put(TABLE_COLNAME, added).put(FIELD_COLNAME, field.getName()).put(ISKEY_COLNAME, field.isKey()).insert();
896
                    vals.put(TABLE_COLNAME, added).put(FIELD_COLNAME, field.getName()).put(ISKEY_COLNAME, field.isKey()).insert();
894
                }
897
                }
895
                vals.remove(ISKEY_COLNAME);
898
                vals.remove(ISKEY_COLNAME);
896
            }
899
            }
Line 1064... Line 1067...
1064
                final Map<SQLTable, SQLElement> beforeElements = new HashMap<SQLTable, SQLElement>(dir.getElementsMap());
1067
                final Map<SQLTable, SQLElement> beforeElements = new HashMap<SQLTable, SQLElement>(dir.getElementsMap());
1065
                module.setupElements(dir);
1068
                module.setupElements(dir);
1066
                final IdentityHashMap<SQLElement, SQLElement> elements = new IdentityHashMap<SQLElement, SQLElement>();
1069
                final IdentityHashMap<SQLElement, SQLElement> elements = new IdentityHashMap<SQLElement, SQLElement>();
1067
                // use IdentitySet so as not to call equals() since it triggers initFF()
1070
                // use IdentitySet so as not to call equals() since it triggers initFF()
1068
                final IdentitySet<SQLElement> beforeElementsSet = new IdentityHashSet<SQLElement>(beforeElements.values());
1071
                final IdentitySet<SQLElement> beforeElementsSet = new IdentityHashSet<SQLElement>(beforeElements.values());
-
 
1072
                // copy to be able to restore elements while iterating
-
 
1073
                final IdentitySet<SQLElement> afterElementsSet = new IdentityHashSet<SQLElement>(dir.getElements());
1069
                for (final SQLElement elem : dir.getElements()) {
1074
                for (final SQLElement elem : afterElementsSet) {
1070
                    if (!beforeElementsSet.contains(elem)) {
1075
                    if (!beforeElementsSet.contains(elem)) {
1071
                        if (!(elem instanceof ModuleElement))
1076
                        if (!(elem instanceof ModuleElement))
1072
                            L.warning("Module added an element that isn't a ModuleElement : " + elem);
1077
                            L.warning("Module added an element that isn't a ModuleElement : " + elem);
1073
                        if (beforeElements.containsKey(elem.getTable())) {
1078
                        if (beforeElements.containsKey(elem.getTable())) {
1074
                            final SQLElement replacedElem = beforeElements.get(elem.getTable());
1079
                            final SQLElement replacedElem = beforeElements.get(elem.getTable());
Line 1076... Line 1081...
1076
                            // replaced. We thus require that elem is a subclass of replacedElem,
1081
                            // replaced. We thus require that elem is a subclass of replacedElem,
1077
                            // i.e. a module can use standard java access rules (e.g. package
1082
                            // i.e. a module can use standard java access rules (e.g. package
1078
                            // private constructor, final method).
1083
                            // private constructor, final method).
1079
                            final boolean codeSafe = replacedElem.getClass().isInstance(elem);
1084
                            final boolean codeSafe = replacedElem.getClass().isInstance(elem);
1080
 
1085
 
1081
                            if (codeSafe && isMngrSafe(module, replacedElem)) {
1086
                            final boolean mngrSafe = isMngrSafe(module, replacedElem);
-
 
1087
                            if (codeSafe && mngrSafe) {
1082
                                // store replacedElem so that it can be restored in unregister()
1088
                                // store replacedElem so that it can be restored in unregister()
1083
                                elements.put(elem, replacedElem);
1089
                                elements.put(elem, replacedElem);
1084
                            } else {
1090
                            } else {
-
 
1091
                                final List<String> pbs = new ArrayList<String>(2);
-
 
1092
                                if (!codeSafe)
-
 
1093
                                    pbs.add(elem + " isn't a subclass of " + replacedElem);
-
 
1094
                                if (!mngrSafe)
-
 
1095
                                    pbs.add(module + " doesn't depend on " + replacedElem);
1085
                                L.warning("Trying to replace element for " + elem.getTable() + " with " + elem);
1096
                                L.warning("Trying to replace element for " + elem.getTable() + " with " + elem + " but\n" + CollectionUtils.join(pbs, "\n"));
1086
                                dir.addSQLElement(replacedElem);
1097
                                dir.addSQLElement(replacedElem);
1087
                            }
1098
                            }
1088
                        } else {
1099
                        } else {
1089
                            elements.put(elem, null);
1100
                            elements.put(elem, null);
1090
                        }
1101
                        }
Line 1704... Line 1715...
1704
                final Locale lang = listIterator.next();
1715
                final Locale lang = listIterator.next();
1705
                final String resourceName = cntrl.toResourceName(cntrl.toBundleName(baseName, lang), "xml");
1716
                final String resourceName = cntrl.toResourceName(cntrl.toBundleName(baseName, lang), "xml");
1706
                final InputStream ins = module.getClass().getResourceAsStream(resourceName);
1717
                final InputStream ins = module.getClass().getResourceAsStream(resourceName);
1707
                // do not force to have one mapping for each locale
1718
                // do not force to have one mapping for each locale
1708
                if (ins != null) {
1719
                if (ins != null) {
1709
                    Log.get().info("module " + module.getName() + " loading translation from " + resourceName);
1720
                    L.config("module " + module.getName() + " loading translation from " + resourceName);
1710
                    final Set<SQLTable> loadedTables;
1721
                    final Set<SQLTable> loadedTables;
1711
                    try {
1722
                    try {
1712
                        loadedTables = trns.load(getRoot(), mdVariant, ins).get0();
1723
                        loadedTables = trns.load(getRoot(), mdVariant, ins).get0();
1713
                    } finally {
1724
                    } finally {
1714
                        ins.close();
1725
                        ins.close();
Line 1897... Line 1908...
1897
    private void tearDownComponents(final AbstractModule module) {
1908
    private void tearDownComponents(final AbstractModule module) {
1898
        assert SwingUtilities.isEventDispatchThread();
1909
        assert SwingUtilities.isEventDispatchThread();
1899
        final String id = module.getFactory().getID();
1910
        final String id = module.getFactory().getID();
1900
        if (this.modulesComponents.containsKey(id)) {
1911
        if (this.modulesComponents.containsKey(id)) {
1901
            final ComponentsContext ctxt = this.modulesComponents.remove(id);
1912
            final ComponentsContext ctxt = this.modulesComponents.remove(id);
1902
            for (final Entry<SQLElement, Collection<String>> e : ctxt.getFields().entrySet())
1913
            for (final Entry<SQLElement, ? extends Collection<String>> e : ctxt.getFields().entrySet())
1903
                for (final String fieldName : e.getValue())
1914
                for (final String fieldName : e.getValue())
1904
                    e.getKey().removeAdditionalField(fieldName);
1915
                    e.getKey().removeAdditionalField(fieldName);
1905
            for (final Entry<SQLElement, Collection<RowAction>> e : ctxt.getRowActions().entrySet())
1916
            for (final Entry<SQLElement, ? extends Collection<IListeAction>> e : ctxt.getRowActions().entrySet())
1906
                e.getKey().getRowActions().removeAll(e.getValue());
1917
                e.getKey().getRowActions().removeAll(e.getValue());
1907
            TranslationManager.getInstance().removeTranslationStreamFromClass(module.getClass());
1918
            TranslationManager.getInstance().removeTranslationStreamFromClass(module.getClass());
1908
            // can't undo so menu is reset in stopModule()
1919
            // can't undo so menu is reset in stopModule()
1909
        }
1920
        }
1910
    }
1921
    }