OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 156 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 156 Rev 174
Line 39... Line 39...
39
import java.io.ObjectOutput;
39
import java.io.ObjectOutput;
40
import java.math.BigDecimal;
40
import java.math.BigDecimal;
41
import java.sql.SQLException;
41
import java.sql.SQLException;
42
import java.sql.Timestamp;
42
import java.sql.Timestamp;
43
import java.util.Date;
43
import java.util.Date;
-
 
44
import java.util.HashMap;
-
 
45
import java.util.List;
44
import java.util.Map;
46
import java.util.Map;
45
import java.util.concurrent.Future;
47
import java.util.concurrent.Future;
46
 
48
 
47
import net.minidev.json.JSONObject;
49
import net.minidev.json.JSONObject;
48
 
50
 
Line 143... Line 145...
143
            throw new IllegalStateException("null field mapper");
145
            throw new IllegalStateException("null field mapper");
144
        }
146
        }
145
 
147
 
146
        final SQLElement sqlElement = configuration.getDirectory().getElement(this.sqlRow.getTable());
148
        final SQLElement sqlElement = configuration.getDirectory().getElement(this.sqlRow.getTable());
147
 
149
 
148
        final Map<String, CustomEditorProvider> customEditors;
-
 
149
        if (this.editMode.equals(EditMode.CREATION)) {
-
 
150
            customEditors = sqlElement.getCustomEditorProviderForCreation(configuration, sessionSecurityToken);
150
        final List<CustomRowEditor> customRowEditors = sqlElement.getCustomRowEditors(configuration, sessionSecurityToken);
151
        } else {
-
 
152
            customEditors = sqlElement.getCustomEditorProviderForModification(configuration, this.sqlRow, sessionSecurityToken);
-
 
153
        }
-
 
154
 
151
 
-
 
152
        final Map<String, CustomRowEditor> customEditors = new HashMap<>(customRowEditors.size());
-
 
153
        for (CustomRowEditor e : customRowEditors) {
-
 
154
            customEditors.put(e.getItemId(), e);
-
 
155
        }
155
        this.createRowValues(configuration, sqlElement, fieldMapper, this.group, customEditors);
156
        this.createRowValues(configuration, sqlElement, fieldMapper, this.group, customEditors);
156
        this.setMetaData(userId);
157
        this.setMetaData(userId);
157
    }
158
    }
158
 
159
 
159
    final protected void createRowValues(final Configuration configuration, final SQLElement sqlElement, final FieldMapper fieldMapper, final Group group,
160
    protected final void createRowValues(final Configuration configuration, final SQLElement sqlElement, final FieldMapper fieldMapper, final Group group,
160
            final Map<String, CustomEditorProvider> customEditors) {
161
            final Map<String, CustomRowEditor> customEditors) {
161
        final int itemCount = group.getSize();
162
        final int itemCount = group.getSize();
162
        for (int i = 0; i < itemCount; i++) {
163
        for (int i = 0; i < itemCount; i++) {
163
            final Item item = group.getItem(i);
164
            final Item item = group.getItem(i);
164
            if (item instanceof Group) {
165
            if (item instanceof Group) {
165
                this.createRowValues(configuration, sqlElement, fieldMapper, (Group) item, customEditors);
166
                this.createRowValues(configuration, sqlElement, fieldMapper, (Group) item, customEditors);
Line 174... Line 175...
174
 
175
 
175
                    if (!uiElement.isNotSaved()) {
176
                    if (!uiElement.isNotSaved()) {
176
                        this.putValueFromUserControl(configuration, sqlElement, field, uiElement, customEditors);
177
                        this.putValueFromUserControl(configuration, sqlElement, field, uiElement, customEditors);
177
                    }
178
                    }
178
                } else {
179
                } else {
-
 
180
                    final LightUIElement uiElement = this.findChildByID(item.getId(), LightUIElement.class);
-
 
181
                    if (uiElement == null) {
-
 
182
                        throw new IllegalArgumentException("Impossible to find UI Element with id: " + item.getId());
-
 
183
                    }
-
 
184
                    if (customEditors.containsKey(uiElement.getId())) {
-
 
185
                        final CustomRowEditor customEditor = customEditors.get(uiElement.getId());
-
 
186
                        customEditor.store(uiElement, this.sqlRow);
-
 
187
                    } else {
179
                    Log.get().warning("No field attached to " + item.getId());
188
                        Log.get().warning("No field attached to " + item.getId());
180
                }
189
                    }
181
            }
190
                }
182
        }
191
            }
183
    }
192
        }
-
 
193
    }
184
 
194
 
185
    protected final void putValueFromUserControl(final Configuration configuration, final SQLElement sqlElement, final SQLField sqlField, final LightUIElement uiElement,
195
    protected final void putValueFromUserControl(final Configuration configuration, final SQLElement sqlElement, final SQLField sqlField, final LightUIElement uiElement,
186
            final Map<String, CustomEditorProvider> customEditors) {
196
            final Map<String, CustomRowEditor> customEditors) {
187
        if (!uiElement.isNotSaved()) {
197
        if (!uiElement.isNotSaved()) {
188
            boolean useElementValue = true;
-
 
189
            final Class<?> fieldType = sqlField.getType().getJavaType();
198
            final Class<?> fieldType = sqlField.getType().getJavaType();
190
            if (customEditors.containsKey(uiElement.getId())) {
199
            if (customEditors.containsKey(uiElement.getId())) {
191
                final CustomEditorProvider customEditor = customEditors.get(uiElement.getId());
200
                final CustomRowEditor customEditor = customEditors.get(uiElement.getId());
192
                if (customEditor instanceof SavableCustomEditorProvider) {
201
                customEditor.store(uiElement, this.sqlRow);
193
                    ((SavableCustomEditorProvider) customEditor).save(this.sqlRow, sqlField, uiElement);
-
 
194
                    useElementValue = false;
-
 
195
                }
202
            } else {
196
            }
-
 
197
 
-
 
198
            if (useElementValue) {
-
 
199
                final String fieldName = sqlField.getFieldName();
203
                final String fieldName = sqlField.getFieldName();
200
                if (sqlField.isKey()) {
204
                if (sqlField.isKey()) {
201
                    if (!(uiElement instanceof LightUIComboBox)) {
205
                    if (!(uiElement instanceof LightUIComboBox)) {
202
                        throw new IllegalArgumentException("Invalid UI Element for field: " + fieldName + ". When field is foreign key, UI Element must be a LightUIDate");
206
                        throw new IllegalArgumentException("Invalid UI Element for field: " + fieldName + ". When field is foreign key, UI Element must be a LightUIDate");
203
                    }
207
                    }
Line 266... Line 270...
266
     * @param group Element edit group
270
     * @param group Element edit group
267
     * @param frame Element edit frame
271
     * @param frame Element edit frame
268
     * @param row Element saved row
272
     * @param row Element saved row
269
     * @param customEditors List of custom editors used in element edit frame
273
     * @param customEditors List of custom editors used in element edit frame
270
     */
274
     */
-
 
275
    @Deprecated
271
    final public void saveReferentRows(final Configuration configuration, final SQLRow parentSqlRow, final Map<String, CustomEditorProvider> customEditors, final String sessionSecurityToken) {
276
    public final void saveReferentRows(final Configuration configuration, final SQLRow parentSqlRow, final Map<String, CustomEditorProvider> customEditors, final String sessionSecurityToken) {
272
        this.saveReferentRows(configuration, this.group, parentSqlRow, customEditors, sessionSecurityToken);
277
        this.saveReferentRows(configuration, this.group, parentSqlRow, customEditors, sessionSecurityToken);
273
    }
278
    }
274
 
279
 
-
 
280
    @Deprecated
275
    final private void saveReferentRows(final Configuration configuration, final Group group, final SQLRow parentSqlRow, final Map<String, CustomEditorProvider> customEditors,
281
    private final void saveReferentRows(final Configuration configuration, final Group group, final SQLRow parentSqlRow, final Map<String, CustomEditorProvider> customEditors,
276
            final String sessionSecurityToken) {
282
            final String sessionSecurityToken) {
277
        for (int i = 0; i < group.getSize(); i++) {
283
        for (int i = 0; i < group.getSize(); i++) {
278
            final Item item = group.getItem(i);
284
            final Item item = group.getItem(i);
279
            if (item instanceof Group) {
285
            if (item instanceof Group) {
280
                this.saveReferentRows(configuration, (Group) item, parentSqlRow, customEditors, sessionSecurityToken);
286
                this.saveReferentRows(configuration, (Group) item, parentSqlRow, customEditors, sessionSecurityToken);