PageRenderTime 102ms CodeModel.GetById 60ms app.highlight 7ms RepoModel.GetById 33ms app.codeStats 0ms

/src/mpv5/webshopinterface/wsdjobs/addContactJob.java

http://mp-rechnungs-und-kundenverwaltung.googlecode.com/
Java | 99 lines | 52 code | 21 blank | 26 comment | 2 complexity | f0de13b35f6c08b52f3284664abc6693 MD5 | raw file
 1
 2/*
 3*  This file is part of YaBS.
 4*
 5*      YaBS is free software: you can redistribute it and/or modify
 6*      it under the terms of the GNU General Public License as published by
 7*      the Free Software Foundation, either version 3 of the License, or
 8*      (at your option) any later version.
 9*
10*      YaBS is distributed in the hope that it will be useful,
11*      but WITHOUT ANY WARRANTY; without even the implied warranty of
12*      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13*      GNU General Public License for more details.
14*
15*      You should have received a copy of the GNU General Public License
16*      along with YaBS.  If not, see <http://www.gnu.org/licenses/>.
17 */
18package mpv5.webshopinterface.wsdjobs;
19
20//~--- non-JDK imports --------------------------------------------------------
21
22import mpv5.db.common.DatabaseObject;
23import mpv5.db.objects.Contact;
24import mpv5.db.objects.WSContactsMapping;
25import mpv5.db.objects.WebShop;
26
27import mpv5.globals.Messages;
28
29import mpv5.logging.Log;
30
31import mpv5.ui.frames.MPView;
32
33import mpv5.utils.arrays.ArrayUtilities;
34
35import mpv5.webshopinterface.WSConnectionClient;
36import mpv5.webshopinterface.WSDaemon;
37import mpv5.webshopinterface.WSDaemonJob;
38import mpv5.webshopinterface.WSIManager;
39
40import org.apache.xmlrpc.XmlRpcException;
41
42//~--- JDK imports ------------------------------------------------------------
43
44import java.util.List;
45import java.util.logging.Level;
46import java.util.logging.Logger;
47
48/**
49 * Pushes contacts to a webshop
50 */
51public class addContactJob implements WSDaemonJob {
52    private final WSDaemon daemon;
53    private boolean        done;
54
55    /**
56     *  Create a new job
57     * @param ddaemon
58     */
59    public addContactJob(WSDaemon ddaemon) {
60        this.daemon = ddaemon;
61    }
62
63    public boolean isOneTimeJob() {
64        return true;
65    }
66
67    public boolean isDone() {
68        return done;
69    }
70
71    public void work(WSConnectionClient client) {
72        List<Contact> data = WSContactsMapping.getUnmappedContacts(daemon.getWebShop());
73
74        try {
75            for (Contact c : data) {
76                Object id = client.getClient().invokeSetCommand(WSConnectionClient.COMMANDS.ADD_NEW_CONTACT.toString(),
77                                ArrayUtilities.inserValue(c.getValues2().toArray(new Object[0][]), c.__getIDS(), -1));
78                WSContactsMapping ws = new WSContactsMapping();
79
80                ws.setContactsids(c.__getIDS());
81                ws.setCname(String.valueOf(id) + "@" + daemon.getWebShopID());
82                ws.setWebshopsids(daemon.getWebShopID());
83                ws.setWscontact(String.valueOf(id));
84                ws.setGroupsids(mpv5.db.objects.User.getCurrentUser().__getGroupsids());
85                ws.save();
86            }
87
88            if (!data.isEmpty()) {
89                mpv5.YabsViewProxy.instance().addMessage(data.size() + " " + Messages.CONTACTS_TRANSMITTED.toString() + " "
90                                  + daemon.getWebShop());
91            }
92        } catch (XmlRpcException ex) {
93            Log.Debug(this, ex.getMessage());
94        }
95    }
96}
97
98
99//~ Formatted by Jindent --- http://www.jindent.com