OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 165 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
147 ilm 1
package org.openconcerto.modules.customersupport;
2
 
3
import java.io.IOException;
4
import java.sql.Date;
5
import java.sql.SQLException;
6
import java.util.Arrays;
7
import java.util.Calendar;
8
import java.util.List;
9
import java.util.Set;
10
 
11
import org.openconcerto.erp.config.MainFrame;
12
import org.openconcerto.erp.modules.AbstractModule;
13
import org.openconcerto.erp.modules.ComponentsContext;
14
import org.openconcerto.erp.modules.DBContext;
15
import org.openconcerto.erp.modules.MenuContext;
16
import org.openconcerto.erp.modules.ModuleFactory;
17
import org.openconcerto.sql.Configuration;
18
import org.openconcerto.sql.element.GlobalMapper;
19
import org.openconcerto.sql.element.SQLElement;
20
import org.openconcerto.sql.element.SQLElementDirectory;
21
import org.openconcerto.sql.model.FieldPath;
22
import org.openconcerto.sql.model.SQLRowAccessor;
23
import org.openconcerto.sql.model.SQLRowValues;
24
import org.openconcerto.sql.model.Where;
25
import org.openconcerto.sql.model.graph.Path;
26
import org.openconcerto.sql.utils.SQLCreateTable;
27
import org.openconcerto.sql.view.ListeAddPanel;
28
import org.openconcerto.sql.view.list.BaseSQLTableModelColumn;
29
import org.openconcerto.sql.view.list.IListe;
30
import org.openconcerto.sql.view.list.SQLTableModelSourceOnline;
31
import org.openconcerto.utils.CollectionUtils;
32
 
33
public final class Module extends AbstractModule {
34
 
35
    public static final String TABLE_CUSTOMER_SUPPORT_TICKET = "CUSTOMER_SUPPORT_TICKET";
36
    public static final String TABLE_CUSTOMER_SUPPORT_TICKET_HISTORY = "CUSTOMER_SUPPORT_TICKET_HISTORY";
37
 
38
    public Module(ModuleFactory f) throws IOException {
39
        super(f);
40
    }
41
 
42
    @Override
153 ilm 43
    protected void install(DBContext ctxt) throws SQLException, IOException {
147 ilm 44
        super.install(ctxt);
45
        // TODO use version to upgrade
46
        if (ctxt.getRoot().getTable(TABLE_CUSTOMER_SUPPORT_TICKET) == null) {
47
            final SQLCreateTable createTable = ctxt.getCreateTable(TABLE_CUSTOMER_SUPPORT_TICKET);
48
 
49
            createTable.addIntegerColumn("NUMBER", 0);
50
            createTable.addVarCharColumn("LABEL", 256);
51
            //
52
            createTable.addForeignColumn("CLIENT");
53
            createTable.addForeignColumn("ID_USER_COMMON", ctxt.getRoot().findTable("USER_COMMON"));
54
            //
55
            createTable.addVarCharColumn("INFOS", 4096);
56
            //
57
            createTable.addVarCharColumn("RATING", 200);
58
            createTable.addVarCharColumn("TYPE", 128);
59
            createTable.addVarCharColumn("STATUS", 128);
60
            createTable.addDateAndTimeColumn("REMIND_DATE");
61
            createTable.addDateAndTimeColumn("DATE");
62
            createTable.addBooleanColumn("CLOSED_AND_ARCHIVED", Boolean.FALSE, false);
63
 
64
            // Suivi
65
            final SQLCreateTable createHistory = ctxt.getCreateTable(TABLE_CUSTOMER_SUPPORT_TICKET_HISTORY);
66
            createHistory.addDateAndTimeColumn("DATE");
67
            createHistory.addForeignColumn(createTable);
68
            createHistory.addVarCharColumn("INFORMATION", 10240);
69
            createHistory.addIntegerColumn("ATTACHMENTS", 0);
70
            createHistory.addForeignColumn("ID_USER_COMMON", ctxt.getRoot().findTable("USER_COMMON"));
71
 
72
            // STATUT
73
            // NOUVEAU, OUVERT, FERME, REJETE, EN COURS
74
            try {
75
                List<String> status = Arrays.asList("En cours", "Fermé", "Nouveau", "Ouvert", "Rejeté");
76
                for (String s : status) {
77
 
78
                    SQLRowValues rowVals = new SQLRowValues(ctxt.getRoot().getTable("COMPLETION"));
79
                    rowVals.put("CHAMP", TABLE_CUSTOMER_SUPPORT_TICKET + ".STATUS");
80
                    rowVals.put("LABEL", s);
81
                    rowVals.insert(true, false);
82
                }
83
 
84
                List<String> prio = Arrays.asList("Basse", "Normale", "Haute");
85
                for (String p : prio) {
86
 
87
                    SQLRowValues rowVals = new SQLRowValues(ctxt.getRoot().getTable("COMPLETION"));
88
                    rowVals.put("CHAMP", TABLE_CUSTOMER_SUPPORT_TICKET + ".RATING");
89
                    rowVals.put("LABEL", p);
90
                    rowVals.insert(true, false);
91
                }
92
 
93
            } catch (SQLException e) {
94
                throw new IllegalStateException("erreur lors de l'ajout des status", e);
95
            }
96
        }
97
    }
98
 
99
    @Override
100
    protected void setupElements(final SQLElementDirectory dir) {
101
        super.setupElements(dir);
102
        final CustomerSupportTicketSQLElement element = new CustomerSupportTicketSQLElement(this);
103
        GlobalMapper.getInstance().map(element.getCode() + ".default", new CustomerSupportTicketGroup());
104
        dir.addSQLElement(element);
105
        dir.addSQLElement(new CustomerTicketHistorySQLElement(this));
106
    }
107
 
108
    @Override
109
    protected void setupComponents(ComponentsContext ctxt) {
110
        // nothing
111
    }
112
 
113
    @Override
114
    protected void setupMenu(final MenuContext ctxt) {
115
        ctxt.addMenuItem(new CustomerSupportTicketListAction(), MainFrame.LIST_MENU);
116
        ctxt.addMenuItem(new CustomerSupportTicketHistoryListAction(), MainFrame.LIST_MENU);
117
    }
118
 
119
    @Override
120
    protected void start() {
121
 
122
        final SQLElement elt = Configuration.getInstance().getDirectory().getElement(Module.TABLE_CUSTOMER_SUPPORT_TICKET);
123
        // Filter
124
        final SQLTableModelSourceOnline source = elt.getTableSource(true);
125
        source.getColumns().remove(source.getColumn(elt.getTable().getField("CLOSED_AND_ARCHIVED")));
126
        Where wAttente = new Where(elt.getTable().getField("CLOSED_AND_ARCHIVED"), "=", Boolean.FALSE);
127
        source.getReq().setWhere(wAttente);
128
 
129
        // Filter
130
        BaseSQLTableModelColumn dateRemind = new BaseSQLTableModelColumn("Date de rappel", Date.class) {
131
 
132
            @Override
133
            protected Object show_(SQLRowAccessor r) {
134
 
135
                Calendar c = r.getDate("REMIND_DATE");
136
                if (c == null) {
137
                    return null;
138
                } else {
139
                    return new Date(c.getTime().getTime());
140
                }
141
 
142
            }
143
 
144
            @Override
145
            public Set<FieldPath> getPaths() {
146
                Path p = new Path(elt.getTable());
147
                return CollectionUtils.createSet(new FieldPath(p, "REMIND_DATE"));
148
            }
149
        };
150
 
151
        dateRemind.setRenderer(new RemindDateRenderer());
152
        source.getColumns().add(dateRemind);
153
 
154
        final ListeAddPanel pane = new ListeAddPanel(elt, new IListe(source), "Open");
155
        pane.getListe().setOpaque(false);
156
        pane.setOpaque(false);
157
        MainFrame.getInstance().getTabbedPane().addTab("Ticket support ouvert", pane);
158
 
159
    }
160
 
161
    @Override
162
    protected void stop() {
163
        // nothing to stop
164
    }
165
 
166
}