PageRenderTime 22ms CodeModel.GetById 14ms RepoModel.GetById 1ms app.codeStats 0ms

/src/mpv5/webshopinterface/wsdjobs/updatedOrdersJob.java

http://mp-rechnungs-und-kundenverwaltung.googlecode.com/
Java | 126 lines | 76 code | 24 blank | 26 comment | 7 complexity | 9012c3ff36d15fe033a014f80c7a2467 MD5 | raw file
Possible License(s): LGPL-3.0, Apache-2.0, GPL-3.0, GPL-2.0, AGPL-3.0, JSON, BSD-3-Clause
  1. /*
  2. * This file is part of YaBS.
  3. *
  4. * YaBS is free software: you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation, either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * YaBS is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with YaBS. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. package mpv5.webshopinterface.wsdjobs;
  18. //~--- non-JDK imports --------------------------------------------------------
  19. import mpv5.db.common.Context;
  20. import mpv5.db.common.DatabaseObject;
  21. import mpv5.db.common.NodataFoundException;
  22. import mpv5.db.common.QueryCriteria;
  23. import mpv5.db.objects.Item;
  24. import mpv5.db.objects.SubItem;
  25. import mpv5.db.objects.WSItemsMapping;
  26. import mpv5.logging.Log;
  27. import mpv5.webshopinterface.WSConnectionClient;
  28. import mpv5.webshopinterface.WSDaemon;
  29. import mpv5.webshopinterface.WSDaemonJob;
  30. import mpv5.webshopinterface.WSIManager;
  31. import org.apache.xmlrpc.XmlRpcException;
  32. //~--- JDK imports ------------------------------------------------------------
  33. import java.util.Date;
  34. import java.util.List;
  35. import mpv5.ui.dialogs.Popup;
  36. /**
  37. * This job tries to fetch updated contacts + adresses of them
  38. */
  39. public class updatedOrdersJob implements WSDaemonJob {
  40. private final WSDaemon daemon;
  41. /**
  42. * Create a new job
  43. * @param ddaemon
  44. */
  45. public updatedOrdersJob(WSDaemon ddaemon) {
  46. this.daemon = ddaemon;
  47. }
  48. @Override
  49. public boolean isOneTimeJob() {
  50. return false;
  51. }
  52. @Override
  53. public boolean isDone() {
  54. return false;
  55. }
  56. @Override
  57. public void work(WSConnectionClient client) {
  58. try {
  59. Object d = client.getClient().invokeGetCommand(WSConnectionClient.COMMANDS.GET_CHANGED_ORDERS.toString(),
  60. new Object[]{}, new Object());
  61. List<Item> obs = WSIManager.createObjects(d, new Item());
  62. for (int i = 0; i < obs.size(); i++) {
  63. Item contact = obs.get(i);
  64. int id = contact.__getIDS();
  65. WSItemsMapping m = null;
  66. try {
  67. m = WSItemsMapping.getMapping(daemon.getWebShopID(), id);
  68. contact.setIDS(m.__getItemsids());
  69. contact.save();
  70. } catch (NodataFoundException ex) {
  71. throw new UnsupportedOperationException("Invalid contact mapping found: " + id);
  72. }
  73. Object da =
  74. client.getClient().invokeGetCommand(WSConnectionClient.COMMANDS.GET_CHANGED_ORDER_ROWS.toString(),
  75. new Object[]{m.__getWsitem()}, new Object());
  76. List<SubItem> aobs = WSIManager.createObjects(da, new SubItem());
  77. for (SubItem orderRow : aobs) {
  78. try {
  79. QueryCriteria qs = new QueryCriteria("itemsids", orderRow.__getItemsids());
  80. List<DatabaseObject> old = DatabaseObject.getObjects(Context.getAddress(), qs);
  81. for (int ix = 0; ix < old.size(); ix++) {
  82. old.get(ix).delete();
  83. }
  84. orderRow.setItemsids(m.__getItemsids());
  85. orderRow.saveImport();
  86. } catch (NodataFoundException ex) {
  87. Log.Debug(this, ex.getMessage());
  88. }
  89. }
  90. }
  91. if (Log.getLoglevel() == Log.LOGLEVEL_DEBUG) {
  92. Popup.notice(obs, "Updated orders");
  93. }
  94. } catch (XmlRpcException ex) {
  95. Log.Debug(this, ex.getMessage());
  96. if (Log.getLoglevel() == Log.LOGLEVEL_DEBUG) {
  97. Popup.error(ex);
  98. }
  99. }
  100. }
  101. }
  102. //~ Formatted by Jindent --- http://www.jindent.com