OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

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