OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

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

Rev 141 Rev 150
Line 7... Line 7...
7
import java.util.Collections;
7
import java.util.Collections;
8
import java.util.Date;
8
import java.util.Date;
9
import java.util.HashMap;
9
import java.util.HashMap;
10
import java.util.List;
10
import java.util.List;
11
import java.util.Map;
11
import java.util.Map;
-
 
12
import java.util.Objects;
12
 
13
 
13
import javax.swing.SwingUtilities;
14
import javax.swing.SwingUtilities;
14
 
15
 
15
import org.jopencalendar.model.Flag;
16
import org.jopencalendar.model.Flag;
16
import org.jopencalendar.model.JCalendarItem;
17
import org.jopencalendar.model.JCalendarItem;
17
import org.jopencalendar.model.JCalendarItemGroup;
18
import org.jopencalendar.model.JCalendarItemGroup;
18
import org.jopencalendar.ui.JCalendarItemProvider;
19
import org.jopencalendar.ui.JCalendarItemProvider;
19
import org.openconcerto.erp.config.ComptaPropsConfiguration;
20
import org.openconcerto.erp.config.ComptaPropsConfiguration;
-
 
21
import org.openconcerto.erp.core.project.element.CalendarItemGroupSQLElement;
-
 
22
import org.openconcerto.erp.core.project.element.CalendarItemSQLElement;
-
 
23
import org.openconcerto.sql.element.SQLElementDirectory;
20
import org.openconcerto.sql.model.DBRoot;
24
import org.openconcerto.sql.model.DBRoot;
21
import org.openconcerto.sql.model.SQLRow;
25
import org.openconcerto.sql.model.SQLRow;
22
import org.openconcerto.sql.model.SQLRowMode;
26
import org.openconcerto.sql.model.SQLRowMode;
23
import org.openconcerto.sql.model.SQLRowValues;
27
import org.openconcerto.sql.model.SQLRowValues;
24
import org.openconcerto.sql.model.SQLRowValuesListFetcher;
28
import org.openconcerto.sql.model.SQLRowValuesListFetcher;
Line 33... Line 37...
33
import org.openconcerto.utils.CollectionUtils;
37
import org.openconcerto.utils.CollectionUtils;
34
import org.openconcerto.utils.StringUtils;
38
import org.openconcerto.utils.StringUtils;
35
import org.openconcerto.utils.cc.ITransformer;
39
import org.openconcerto.utils.cc.ITransformer;
36
 
40
 
37
public class OperationCalendarManager extends JCalendarItemProvider {
41
public class OperationCalendarManager extends JCalendarItemProvider {
38
    private DBRoot root;
42
    private final DBRoot root;
-
 
43
    private final SQLElementDirectory dir;
-
 
44
    private final UserManager userMngr;
-
 
45
    private List<User> users;
-
 
46
    private List<String> states;
-
 
47
    private boolean hideLocked = false;
-
 
48
    private boolean hideUnlocked = false;
39
 
49
 
40
    public OperationCalendarManager(String name) {
50
    public OperationCalendarManager(String name) {
41
        super(name);
-
 
42
        this.root = ComptaPropsConfiguration.getInstanceCompta().getRootSociete();
51
        this(name, ComptaPropsConfiguration.getInstanceCompta());
43
    }
52
    }
44
 
53
 
45
    public OperationCalendarManager(String name, DBRoot root) {
54
    public OperationCalendarManager(final String name, final ComptaPropsConfiguration comptaConf) {
-
 
55
        this(name, comptaConf.getRootSociete(), comptaConf.getDirectory(), comptaConf.getUserManager());
-
 
56
    }
-
 
57
 
-
 
58
    public OperationCalendarManager(final String name, final DBRoot root, final SQLElementDirectory dir, final UserManager userMngr) {
46
        super(name);
59
        super(name);
47
        this.root = root;
60
        this.root = root;
-
 
61
        this.dir = dir;
-
 
62
        this.userMngr = userMngr;
48
    }
63
    }
49
 
64
 
50
    private List<User> users;
65
    public final SQLElementDirectory getDirectory() {
51
    private List<String> states;
66
        return this.dir;
-
 
67
    }
-
 
68
 
52
    private boolean hideLocked = false;
69
    private final SQLTable getCalendarItemTable() {
-
 
70
        return this.dir.getElement(CalendarItemSQLElement.class).getTable();
-
 
71
    }
-
 
72
 
53
    private boolean hideUnlocked = false;
73
    private final SQLTable getCalendarItemGroupTable() {
-
 
74
        return this.dir.getElement(CalendarItemGroupSQLElement.class).getTable();
-
 
75
    }
54
 
76
 
55
    /**
77
    /*
56
     * Set the filter to retrieve items
78
     * Set the filter to retrieve items
57
     * 
79
     * 
58
     * @param users if null don't limit to specific users
80
     * @param users if null don't limit to specific users
-
 
81
     * 
59
     * @param states if null don't limite to specific states
82
     * @param states if null don't limit to specific states
60
     */
83
     */
61
    synchronized public void setFilter(List<User> users, List<String> states, boolean hideLocked, boolean hideUnlocked) {
84
    synchronized public boolean setFilter(List<User> users, List<String> states, boolean hideLocked, boolean hideUnlocked) {
-
 
85
        boolean res = false;
-
 
86
        if (!Objects.equals(this.users, users)) {
62
        this.users = users;
87
            this.users = users;
-
 
88
            res = true;
-
 
89
        }
-
 
90
        if (!Objects.equals(this.states, states)) {
63
        this.states = states;
91
            this.states = states;
-
 
92
            res = true;
-
 
93
        }
-
 
94
        if (this.hideLocked != hideLocked) {
64
        this.hideLocked = hideLocked;
95
            this.hideLocked = hideLocked;
-
 
96
            res = true;
-
 
97
        }
-
 
98
        if (this.hideUnlocked != hideUnlocked) {
65
        this.hideUnlocked = hideUnlocked;
99
            this.hideUnlocked = hideUnlocked;
-
 
100
            res = true;
-
 
101
        }
-
 
102
        return res;
66
    }
103
    }
67
 
104
 
68
    @Override
105
    @Override
69
    synchronized public List<JCalendarItem> getItemInWeek(int week, int year) {
106
    synchronized public List<JCalendarItem> getItemInWeek(int week, int year) {
70
        assert !SwingUtilities.isEventDispatchThread();
107
        assert !SwingUtilities.isEventDispatchThread();
Line 101... Line 138...
101
    }
138
    }
102
 
139
 
103
    public List<JCalendarItem> getItemIn(final Date date1, final Date date2, List<User> selectedUsers, final List<String> selectedStates, final String uid) {
140
    public List<JCalendarItem> getItemIn(final Date date1, final Date date2, List<User> selectedUsers, final List<String> selectedStates, final String uid) {
104
        final List<User> users = new ArrayList<User>();
141
        final List<User> users = new ArrayList<User>();
105
        if (selectedUsers == null) {
142
        if (selectedUsers == null) {
106
            users.addAll(UserManager.getInstance().getAllActiveUsers());
143
            users.addAll(this.userMngr.getAllActiveUsers());
107
        } else {
144
        } else {
108
            users.addAll(selectedUsers);
145
            users.addAll(selectedUsers);
109
        }
146
        }
110
        if (users.isEmpty()) {
147
        if (users.isEmpty()) {
111
            return Collections.emptyList();
148
            return Collections.emptyList();
112
        }
149
        }
113
        if (selectedStates != null && selectedStates.isEmpty()) {
150
        if (selectedStates != null && selectedStates.isEmpty()) {
114
            return Collections.emptyList();
151
            return Collections.emptyList();
115
        }
152
        }
116
        final SQLRowValues valCalendarItems = new SQLRowValues(root.getTable("CALENDAR_ITEM"));
153
        final SQLRowValues valCalendarItems = new SQLRowValues(getCalendarItemTable());
117
        valCalendarItems.putNulls("START", "END", "DURATION_S", "SUMMARY", "DESCRIPTION", "FLAGS", "STATUS", "SOURCE_ID", "SOURCE_TABLE", "UID", "LOCATION");
154
        valCalendarItems.putNulls("START", "END", "DURATION_S", "SUMMARY", "DESCRIPTION", "FLAGS", "STATUS", "SOURCE_ID", "SOURCE_TABLE", "UID", "LOCATION");
118
        final SQLRowValues valsCalendarItemsGroup = valCalendarItems.putRowValues("ID_CALENDAR_ITEM_GROUP");
155
        final SQLRowValues valsCalendarItemsGroup = valCalendarItems.putRowValues("ID_CALENDAR_ITEM_GROUP");
119
        valsCalendarItemsGroup.put("NAME", null);
156
        valsCalendarItemsGroup.put("NAME", null);
120
 
157
 
121
        final SQLRowValues valSite = new SQLRowValues(root.getTable(ModuleOperation.TABLE_SITE));
158
        final SQLRowValues valSite = new SQLRowValues(root.getTable(ModuleOperation.TABLE_SITE));
122
        valSite.putNulls("NAME", "COMMENT");
159
        valSite.putNulls("NAME", "COMMENT");
123
 
160
 
124
        final SQLRowValues valOperation = new SQLRowValues(root.getTable(ModuleOperation.TABLE_OPERATION));
161
        final SQLRowValues valOperation = new SQLRowValues(root.getTable(ModuleOperation.TABLE_OPERATION));
125
        final SQLRowValues userVals = valOperation.putRowValues("ID_USER_COMMON").putNulls("NOM");
162
        final SQLRowValues userVals = valOperation.putRowValues("ID_USER_COMMON").putNulls("NOM", "PRENOM");
126
        valOperation.put("ID_CALENDAR_ITEM_GROUP", valsCalendarItemsGroup);
163
        valOperation.put("ID_CALENDAR_ITEM_GROUP", valsCalendarItemsGroup);
127
        valOperation.put("ID_SITE", valSite);
164
        valOperation.put("ID_SITE", valSite);
128
        valOperation.putNulls("STATUS", "TYPE", "PLANNER_XML", "PLANNER_UID");
165
        valOperation.putNulls("STATUS", "TYPE", "PLANNER_XML", "PLANNER_UID");
129
 
166
 
130
        final SQLRowValuesListFetcher fetcher = SQLRowValuesListFetcher.create(valCalendarItems);
167
        final SQLRowValuesListFetcher fetcher = SQLRowValuesListFetcher.create(valCalendarItems);
-
 
168
        fetcher.setReturnedRowsUnmodifiable(true);
131
        fetcher.setFullOnly(true);
169
        fetcher.setFullOnly(true);
132
        fetcher.setSelTransf(new ITransformer<SQLSelect, SQLSelect>() {
170
        fetcher.setSelTransf(new ITransformer<SQLSelect, SQLSelect>() {
133
 
171
 
134
            @Override
172
            @Override
135
            public SQLSelect transformChecked(SQLSelect input) {
173
            public SQLSelect transformChecked(SQLSelect input) {
Line 194... Line 232...
194
        for (SQLRowValues r : rows) {
232
        for (SQLRowValues r : rows) {
195
            final SQLRowValues user = r.followPath(p);
233
            final SQLRowValues user = r.followPath(p);
196
 
234
 
197
            if (user != null) {
235
            if (user != null) {
198
                final SQLRowValues operation = r.followPath(pItemToOperation);
236
                final SQLRowValues operation = r.followPath(pItemToOperation);
199
                final JCalendarItemDB item = new JCalendarItemDB(r.getID(), r.getString("SOURCE_TABLE"), r.getInt("SOURCE_ID"), r.getForeign("ID_CALENDAR_ITEM_GROUP").getID());
237
                final JCalendarItemDB item = new JCalendarItemDB(this.dir, r);
200
 
238
 
201
                item.setDayOnly(false);
239
                item.setDayOnly(false);
202
                item.setDtStart(r.getDate("START"));
240
                item.setDtStart(r.getDate("START"));
203
                item.setDtEnd(r.getDate("END"));
241
                item.setDtEnd(r.getDate("END"));
204
                item.setSummary(r.getString("SUMMARY"));
242
                item.setSummary(r.getString("SUMMARY"));
Line 280... Line 318...
280
            vOperation.put("DESCRIPTION", description);
318
            vOperation.put("DESCRIPTION", description);
281
 
319
 
282
            final SQLRow operationRow = vOperation.commit();
320
            final SQLRow operationRow = vOperation.commit();
283
            SQLRow calendarGroupRow = operationRow.getForeignRow("ID_CALENDAR_ITEM_GROUP", SQLRowMode.DEFINED);
321
            SQLRow calendarGroupRow = operationRow.getForeignRow("ID_CALENDAR_ITEM_GROUP", SQLRowMode.DEFINED);
284
 
322
 
285
            final SQLRowValues rowItemGroup = new SQLRowValues(root.getTable("CALENDAR_ITEM_GROUP"));
323
            final SQLRowValues rowItemGroup = new SQLRowValues(getCalendarItemGroupTable());
286
            rowItemGroup.put("NAME", summary);
324
            rowItemGroup.put("NAME", summary);
287
            rowItemGroup.put("DESCRIPTION", description);
325
            rowItemGroup.put("DESCRIPTION", description);
288
 
326
 
289
            calendarGroupRow = rowItemGroup.commit();
327
            calendarGroupRow = rowItemGroup.commit();
290
            // Update Operation
328
            // Update Operation
Line 293... Line 331...
293
            operationSQLRowValues.commit();
331
            operationSQLRowValues.commit();
294
            // Insert Calendar Items
332
            // Insert Calendar Items
295
            DateRange dateRange = new DateRange();
333
            DateRange dateRange = new DateRange();
296
            dateRange.setStart(start.getTime());
334
            dateRange.setStart(start.getTime());
297
            dateRange.setStop(end.getTime());
335
            dateRange.setStop(end.getTime());
298
            final SQLRowValues rowItem = new SQLRowValues(root.getTable("CALENDAR_ITEM"));
336
            final SQLRowValues rowItem = new SQLRowValues(getCalendarItemTable());
299
            rowItem.put("START", new Date(dateRange.getStart()));
337
            rowItem.put("START", new Date(dateRange.getStart()));
300
            rowItem.put("END", new Date(dateRange.getStop()));
338
            rowItem.put("END", new Date(dateRange.getStop()));
301
            rowItem.put("DURATION_S", (dateRange.getStop() - dateRange.getStart()) / 1000);
339
            rowItem.put("DURATION_S", (dateRange.getStop() - dateRange.getStart()) / 1000);
302
            rowItem.put("SUMMARY", summary);
340
            rowItem.put("SUMMARY", summary);
303
            rowItem.put("DESCRIPTION", description);
341
            rowItem.put("DESCRIPTION", description);
Line 311... Line 349...
311
            rowItem.commit();
349
            rowItem.commit();
312
        } else {
350
        } else {
313
            if (i instanceof JCalendarItemDB) {
351
            if (i instanceof JCalendarItemDB) {
314
                JCalendarItemDB item = (JCalendarItemDB) i;
352
                JCalendarItemDB item = (JCalendarItemDB) i;
315
                //
353
                //
316
                final SQLRowValues vOperation = tOperation.getRow((int) item.getSourceId()).createEmptyUpdateRow();
354
                final SQLRowValues vOperation = item.getSource().createEmptyUpdateRow();
317
                vOperation.put("DESCRIPTION", description);
355
                vOperation.put("DESCRIPTION", description);
318
                vOperation.commit();
356
                vOperation.commit();
319
                // group
357
                // group
320
                final SQLTable tGroup = root.getTable("CALENDAR_ITEM_GROUP");
-
 
321
                final SQLRowValues rowItemGroup = tGroup.getRow(item.getIdCalendarGroup()).createEmptyUpdateRow();
358
                final SQLRowValues rowItemGroup = item.getCalendarGroup().createEmptyUpdateRow();
322
                rowItemGroup.put("NAME", summary);
359
                rowItemGroup.put("NAME", summary);
323
                rowItemGroup.put("DESCRIPTION", description);
360
                rowItemGroup.put("DESCRIPTION", description);
324
                rowItemGroup.commit();
361
                rowItemGroup.commit();
325
                // item
362
                // item
326
                final SQLTable tItem = root.getTable("CALENDAR_ITEM");
-
 
327
                DateRange dateRange = new DateRange();
363
                DateRange dateRange = new DateRange();
328
                dateRange.setStart(start.getTime());
364
                dateRange.setStart(start.getTime());
329
                dateRange.setStop(end.getTime());
365
                dateRange.setStop(end.getTime());
330
                final SQLRowValues rowItem = tItem.getRow(item.getId()).createEmptyUpdateRow();
366
                final SQLRowValues rowItem = item.getRow().createEmptyUpdateRow();
331
                rowItem.put("START", new Date(dateRange.getStart()));
367
                rowItem.put("START", new Date(dateRange.getStart()));
332
                rowItem.put("END", new Date(dateRange.getStop()));
368
                rowItem.put("END", new Date(dateRange.getStop()));
333
                rowItem.put("DURATION_S", (dateRange.getStop() - dateRange.getStart()) / 1000);
369
                rowItem.put("DURATION_S", (dateRange.getStop() - dateRange.getStart()) / 1000);
334
                rowItem.put("SUMMARY", summary);
370
                rowItem.put("SUMMARY", summary);
335
                rowItem.put("DESCRIPTION", description);
371
                rowItem.put("DESCRIPTION", description);