diff --git a/src-db/database/model/tables/OBPOS_ERRORS.xml b/src-db/database/model/tables/OBPOS_ERRORS.xml
--- a/src-db/database/model/tables/OBPOS_ERRORS.xml
+++ b/src-db/database/model/tables/OBPOS_ERRORS.xml
@@ -61,6 +61,10 @@
+
+
+
+
diff --git a/src-db/database/sourcedata/AD_COLUMN.xml b/src-db/database/sourcedata/AD_COLUMN.xml
--- a/src-db/database/sourcedata/AD_COLUMN.xml
+++ b/src-db/database/sourcedata/AD_COLUMN.xml
@@ -2615,6 +2615,40 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src-db/database/sourcedata/AD_ELEMENT.xml b/src-db/database/sourcedata/AD_ELEMENT.xml
--- a/src-db/database/sourcedata/AD_ELEMENT.xml
+++ b/src-db/database/sourcedata/AD_ELEMENT.xml
@@ -14,6 +14,19 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src-db/database/sourcedata/AD_FIELD.xml b/src-db/database/sourcedata/AD_FIELD.xml
--- a/src-db/database/sourcedata/AD_FIELD.xml
+++ b/src-db/database/sourcedata/AD_FIELD.xml
@@ -2565,6 +2565,32 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src-db/database/sourcedata/AD_PROCESS.xml b/src-db/database/sourcedata/AD_PROCESS.xml
--- a/src-db/database/sourcedata/AD_PROCESS.xml
+++ b/src-db/database/sourcedata/AD_PROCESS.xml
@@ -46,4 +46,26 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/org/openbravo/retail/posterminal/ErrorComparator.java b/src/org/openbravo/retail/posterminal/ErrorComparator.java
new file mode 100644
--- /dev/null
+++ b/src/org/openbravo/retail/posterminal/ErrorComparator.java
@@ -0,0 +1,46 @@
+package org.openbravo.retail.posterminal;
+
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.openbravo.dal.core.OBContext;
+import org.openbravo.dal.service.OBDal;
+import org.openbravo.model.ad.domain.Reference;
+
+public class ErrorComparator implements Comparator {
+ private static String TYPES_REFERENCE = "20A228A295C844C68B4451622057A893";
+ private Map sequenceNumbers = new HashMap();
+
+ public ErrorComparator() {
+ super();
+ OBContext.setAdminMode(false);
+ try {
+ Reference ref = OBDal.getInstance().get(Reference.class, TYPES_REFERENCE);
+ for (org.openbravo.model.ad.domain.List listRef : ref.getADListList()) {
+ if (listRef.getSequenceNumber() != null) {
+ sequenceNumbers.put(listRef.getSearchKey(), listRef.getSequenceNumber());
+ }
+ }
+ } finally {
+ OBContext.restorePreviousMode();
+ }
+
+ }
+
+ @Override
+ public int compare(OBPOSErrors error1, OBPOSErrors error2) {
+ Long l1 = sequenceNumbers.get(error1.getTypeofdata());
+ Long l2 = sequenceNumbers.get(error2.getTypeofdata());
+ if (l1 == null && l2 == null) {
+ return 0;
+ } else if (l1 == null && l2 != null) {
+ return -1;
+ } else if (l1 != null && l2 == null) {
+ return 1;
+ } else {
+ return l1.compareTo(l2);
+ }
+ }
+
+}
diff --git a/src/org/openbravo/retail/posterminal/SaveDataActionHandler.java b/src/org/openbravo/retail/posterminal/SaveDataActionHandler.java
--- a/src/org/openbravo/retail/posterminal/SaveDataActionHandler.java
+++ b/src/org/openbravo/retail/posterminal/SaveDataActionHandler.java
@@ -10,8 +10,6 @@
import java.util.ArrayList;
import java.util.Collections;
-import java.util.Comparator;
-import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -30,7 +28,6 @@
import org.openbravo.dal.service.OBDal;
import org.openbravo.erpCommon.utility.Utility;
import org.openbravo.mobile.core.process.DataSynchronizationProcess;
-import org.openbravo.model.ad.domain.Reference;
import org.openbravo.service.db.DalConnectionProvider;
import org.openbravo.service.json.JsonConstants;
@@ -116,40 +113,3 @@
return null;
}
}
-
-class ErrorComparator implements Comparator {
- private static String TYPES_REFERENCE = "20A228A295C844C68B4451622057A893";
- private Map sequenceNumbers = new HashMap();
-
- public ErrorComparator() {
- super();
- OBContext.setAdminMode(false);
- try {
- Reference ref = OBDal.getInstance().get(Reference.class, TYPES_REFERENCE);
- for (org.openbravo.model.ad.domain.List listRef : ref.getADListList()) {
- if (listRef.getSequenceNumber() != null) {
- sequenceNumbers.put(listRef.getSearchKey(), listRef.getSequenceNumber());
- }
- }
- } finally {
- OBContext.restorePreviousMode();
- }
-
- }
-
- @Override
- public int compare(OBPOSErrors error1, OBPOSErrors error2) {
- Long l1 = sequenceNumbers.get(error1.getTypeofdata());
- Long l2 = sequenceNumbers.get(error2.getTypeofdata());
- if (l1 == null && l2 == null) {
- return 0;
- } else if (l1 == null && l2 != null) {
- return -1;
- } else if (l1 != null && l2 == null) {
- return 1;
- } else {
- return l1.compareTo(l2);
- }
- }
-
-}
diff --git a/src/org/openbravo/retail/posterminal/SyncAllErrorsWhileImporting.java b/src/org/openbravo/retail/posterminal/SyncAllErrorsWhileImporting.java
new file mode 100644
--- /dev/null
+++ b/src/org/openbravo/retail/posterminal/SyncAllErrorsWhileImporting.java
@@ -0,0 +1,112 @@
+/*
+ *************************************************************************
+ * The contents of this file are subject to the Openbravo Public License
+ * Version 1.0 (the "License"), being the Mozilla Public License
+ * Version 1.1 with a permitted attribution clause; you may not use this
+ * file except in compliance with the License. You may obtain a copy of
+ * the License at http://www.openbravo.com/legal/license.html
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ * The Original Code is Openbravo ERP.
+ * The Initial Developer of the Original Code is Openbravo SLU
+ * All portions are Copyright (C) 2015 Openbravo SLU
+ * All Rights Reserved.
+ * Contributor(s): ______________________________________.
+ *************************************************************************
+ */
+package org.openbravo.retail.posterminal;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.Set;
+
+import javax.enterprise.inject.Any;
+import javax.enterprise.inject.Instance;
+import javax.enterprise.inject.spi.Bean;
+import javax.enterprise.inject.spi.BeanManager;
+import javax.inject.Inject;
+
+import org.apache.log4j.Logger;
+import org.codehaus.jettison.json.JSONObject;
+import org.hibernate.criterion.Restrictions;
+import org.openbravo.base.weld.WeldUtils;
+import org.openbravo.dal.core.OBContext;
+import org.openbravo.dal.service.OBCriteria;
+import org.openbravo.dal.service.OBDal;
+import org.openbravo.erpCommon.utility.OBMessageUtils;
+import org.openbravo.mobile.core.process.DataSynchronizationProcess;
+import org.openbravo.scheduling.ProcessBundle;
+import org.openbravo.scheduling.ProcessLogger;
+import org.openbravo.service.db.DalBaseProcess;
+import org.openbravo.service.json.JsonConstants;
+
+/**
+ * @author malsasua
+ *
+ */
+public class SyncAllErrorsWhileImporting extends DalBaseProcess {
+ private static final Logger log4j = Logger.getLogger(SyncAllErrorsWhileImporting.class);
+ private ProcessLogger logger;
+
+ @Inject
+ @Any
+ private Instance syncProcesses;
+
+ @Override
+ protected void doExecute(ProcessBundle bundle) throws Exception {
+ logger = bundle.getLogger();
+ try {
+ OBCriteria queryListErrors = OBDal.getInstance().createCriteria(
+ OBPOSErrors.class);
+ queryListErrors.add(Restrictions.eq(OBPOSErrors.PROPERTY_ORDERSTATUS, "N"));
+ queryListErrors.add(Restrictions.le(OBPOSErrors.PROPERTY_ATTEMPTS, new Long("3")));
+ queryListErrors.addOrderBy(OBPOSErrors.PROPERTY_CREATIONDATE, true);
+
+ List listErrors = queryListErrors.list();
+ Collections.sort(listErrors, new ErrorComparator());
+
+ for (OBPOSErrors error : listErrors) {
+ String errorId = error.getId();
+ String type = error.getTypeofdata();
+
+ // RequestContext.get().setSessionAttribute("#AD_ORG_ID", "1000000");
+ POSDataSynchronizationProcess syncProcess = null;
+ BeanManager beanManager = WeldUtils.getStaticInstanceBeanManager();
+ Set> beans = beanManager.getBeans(POSDataSynchronizationProcess.class,
+ new DataSynchronizationProcess.Selector(type));
+
+ for (Bean> bean : beans) {
+ syncProcess = (POSDataSynchronizationProcess) beanManager.getReference(bean,
+ POSDataSynchronizationProcess.class, beanManager.createCreationalContext(bean));
+ }
+ JSONObject record = new JSONObject(error.getJsoninfo());
+ record.put("posErrorId", errorId);
+ JSONObject data = new JSONObject();
+ data.put("data", record);
+ JSONObject result = syncProcess.exec(data, true);
+ try {
+ OBContext.setAdminMode(true);
+ error = OBDal.getInstance().get(OBPOSErrors.class, errorId);
+ if (result.get(JsonConstants.RESPONSE_STATUS).equals(
+ JsonConstants.RPCREQUEST_STATUS_FAILURE)) {
+ logger.logln("Record has not been synced: " + error.getIdentifier());
+ } else {
+ error.setOrderstatus("Y");
+ logger.logln("Record has been synced successfully: " + error.getIdentifier());
+ }
+ error.setAttempts(error.getAttempts() + 1);
+ OBDal.getInstance().save(error);
+ OBDal.getInstance().flush();
+ OBDal.getInstance().commitAndClose();
+ } finally {
+ OBContext.restorePreviousMode();
+ }
+ }
+ logger.logln(OBMessageUtils.messageBD("Success"));
+ } catch (Exception e) {// won't' happen
+ logger.logln(OBMessageUtils.messageBD("Error"));
+ }
+ }
+}