/src/mpv5/webshopinterface/wsdjobs/updatedOrdersJob.java
Java | 126 lines | 76 code | 24 blank | 26 comment | 7 complexity | 9012c3ff36d15fe033a014f80c7a2467 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 -------------------------------------------------------- 21import mpv5.db.common.Context; 22import mpv5.db.common.DatabaseObject; 23import mpv5.db.common.NodataFoundException; 24import mpv5.db.common.QueryCriteria; 25import mpv5.db.objects.Item; 26import mpv5.db.objects.SubItem; 27import mpv5.db.objects.WSItemsMapping; 28 29import mpv5.logging.Log; 30 31import mpv5.webshopinterface.WSConnectionClient; 32import mpv5.webshopinterface.WSDaemon; 33import mpv5.webshopinterface.WSDaemonJob; 34import mpv5.webshopinterface.WSIManager; 35 36import org.apache.xmlrpc.XmlRpcException; 37 38//~--- JDK imports ------------------------------------------------------------ 39 40import java.util.Date; 41import java.util.List; 42import mpv5.ui.dialogs.Popup; 43 44/** 45 * This job tries to fetch updated contacts + adresses of them 46 */ 47public class updatedOrdersJob implements WSDaemonJob { 48 49 private final WSDaemon daemon; 50 51 /** 52 * Create a new job 53 * @param ddaemon 54 */ 55 public updatedOrdersJob(WSDaemon ddaemon) { 56 this.daemon = ddaemon; 57 } 58 59 @Override 60 public boolean isOneTimeJob() { 61 return false; 62 } 63 64 @Override 65 public boolean isDone() { 66 return false; 67 } 68 69 @Override 70 public void work(WSConnectionClient client) { 71 try { 72 Object d = client.getClient().invokeGetCommand(WSConnectionClient.COMMANDS.GET_CHANGED_ORDERS.toString(), 73 new Object[]{}, new Object()); 74 List<Item> obs = WSIManager.createObjects(d, new Item()); 75 76 for (int i = 0; i < obs.size(); i++) { 77 Item contact = obs.get(i); 78 int id = contact.__getIDS(); 79 WSItemsMapping m = null; 80 81 try { 82 m = WSItemsMapping.getMapping(daemon.getWebShopID(), id); 83 contact.setIDS(m.__getItemsids()); 84 contact.save(); 85 } catch (NodataFoundException ex) { 86 throw new UnsupportedOperationException("Invalid contact mapping found: " + id); 87 } 88 89 Object da = 90 client.getClient().invokeGetCommand(WSConnectionClient.COMMANDS.GET_CHANGED_ORDER_ROWS.toString(), 91 new Object[]{m.__getWsitem()}, new Object()); 92 List<SubItem> aobs = WSIManager.createObjects(da, new SubItem()); 93 94 for (SubItem orderRow : aobs) { 95 try { 96 QueryCriteria qs = new QueryCriteria("itemsids", orderRow.__getItemsids()); 97 98 List<DatabaseObject> old = DatabaseObject.getObjects(Context.getAddress(), qs); 99 100 for (int ix = 0; ix < old.size(); ix++) { 101 old.get(ix).delete(); 102 } 103 104 orderRow.setItemsids(m.__getItemsids()); 105 orderRow.saveImport(); 106 } catch (NodataFoundException ex) { 107 Log.Debug(this, ex.getMessage()); 108 } 109 } 110 } 111 112 if (Log.getLoglevel() == Log.LOGLEVEL_DEBUG) { 113 Popup.notice(obs, "Updated orders"); 114 } 115 } catch (XmlRpcException ex) { 116 Log.Debug(this, ex.getMessage()); 117 if (Log.getLoglevel() == Log.LOGLEVEL_DEBUG) { 118 Popup.error(ex); 119 } 120 } 121 } 122} 123 124 125//~ Formatted by Jindent --- http://www.jindent.com 126