Fixes issue 12824: api check build 327
authorDavid Alsasua <david.alsasua@openbravo.com>
Fri, 09 Apr 2010 18:50:30 +0200
changeset 6970 5c592e20669a
parent 6969 e809fe06034d
child 6971 6c78ad9d5176
Fixes issue 12824: api check build 327
src-db/database/sourcedata/AD_MESSAGE.xml
src-util/buildvalidation/src/org/openbravo/buildvalidation/Cbpvendoracct.java
src-util/buildvalidation/src/org/openbravo/buildvalidation/Cbpvendoracct_data.xsql
--- a/src-db/database/sourcedata/AD_MESSAGE.xml	Fri Apr 09 16:05:37 2010 +0200
+++ b/src-db/database/sourcedata/AD_MESSAGE.xml	Fri Apr 09 18:50:30 2010 +0200
@@ -8731,7 +8731,7 @@
 <!--800203-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
 <!--800203-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
 <!--800203-->  <VALUE><![CDATA[C_BP_VENDOR_ACCT_ACCTSCHEMA_UN]]></VALUE>
-<!--800203-->  <MSGTEXT><![CDATA[The vendor already has a record with the same accounting schema, with the same organization and with the same status. At least change one of the three]]></MSGTEXT>
+<!--800203-->  <MSGTEXT><![CDATA[The vendor already has a record with the same accounting schema and with the same status. At least change one of them]]></MSGTEXT>
 <!--800203-->  <MSGTYPE><![CDATA[E]]></MSGTYPE>
 <!--800203-->  <AD_MODULE_ID><![CDATA[0]]></AD_MODULE_ID>
 <!--800203--></AD_MESSAGE>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src-util/buildvalidation/src/org/openbravo/buildvalidation/Cbpvendoracct.java	Fri Apr 09 18:50:30 2010 +0200
@@ -0,0 +1,50 @@
+/*
+ *************************************************************************
+ * 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) 2010 Openbravo SLU
+ * All Rights Reserved.
+ * Contributor(s):  ______________________________________.
+ ************************************************************************
+ */
+package org.openbravo.buildvalidation;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.openbravo.database.ConnectionProvider;
+
+/**
+ * This validation is related to this issue: https://issues.openbravo.com/view.php?id=12824 The
+ * unique constraint C_BP_VENDOR_ACCT_ACCTSCHEMA_UN was made more restrictive, and it will fail if
+ * the data is not correct and is not fixed before updating.
+ */
+public class Cbpvendoracct extends BuildValidation {
+
+  @Override
+  public List<String> execute() {
+    ConnectionProvider cp = getConnectionProvider();
+    ArrayList<String> errors = new ArrayList<String>();
+    try {
+      int a = Integer.parseInt(CbpvendoracctData.countNoDistinct(cp));
+      int b = Integer.parseInt(CbpvendoracctData.countDistinct(cp));
+      if (a != b) {
+        errors
+            .add("Due to a database constraint modification, is no longer allowed to have more than one entry in business partner -> vendor -> accounting tab, for the same accounting schema and status. In previous releases, one per organization was allowed, but is not the case now. There exists data in your database that do not fit this new constraint. Please fix it before updating the database.");
+      }
+    } catch (Exception e) {
+      return handleError(e);
+    }
+    return errors;
+  }
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src-util/buildvalidation/src/org/openbravo/buildvalidation/Cbpvendoracct_data.xsql	Fri Apr 09 18:50:30 2010 +0200
@@ -0,0 +1,37 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!--
+ *************************************************************************
+ * 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) 2010 Openbravo SLU
+ * All Rights Reserved.
+ * Contributor(s):  ______________________________________.
+ ************************************************************************
+-->
+
+
+<SqlClass name="CbpvendoracctData" package="org.openbravo.buildvalidation">
+  <SqlMethod name="countNoDistinct" type="preparedStatement" return="string">
+      <SqlMethodComment>This query counts the number of rows in c_bp_vendor_acct</SqlMethodComment>
+      <Sql><![CDATA[
+         SELECT count(*) as count from (select c_acctschema_id, c_bpartner_id, status from c_bp_vendor_acct) a
+          ]]>
+      </Sql>
+  </SqlMethod>
+  <SqlMethod name="countDistinct" type="preparedStatement" return="string">
+      <SqlMethodComment>This query counts the number of unique combinations of (c_acctschema_id, c_bpartner_id, status) tuples in c_bp_vendor_acct</SqlMethodComment>
+      <Sql><![CDATA[
+         SELECT count(*) as count from (select distinct c_acctschema_id, c_bpartner_id, status from c_bp_vendor_acct) a
+          ]]>
+      </Sql>
+  </SqlMethod>
+</SqlClass>