details: https://code.openbravo.com/erp/devel/pi/rev/f8de3bcd78f3 changeset: 28273:f8de3bcd78f3 user: Asier Lostalé <asier.lostale <at> openbravo.com> date: Thu Jan 21 12:44:16 2016 +0100 summary: fixed issue 31973: detect situation created by issue 31959
Added module script that creates alert when in this situation diffstat: src-util/modulescript/build/classes/org/openbravo/modulescript/PgJdbcDatesIssue.class | 0 src-util/modulescript/build/classes/org/openbravo/modulescript/PgJdbcDatesIssueData.class | 0 src-util/modulescript/src/org/openbravo/modulescript/PgJdbcDatesIssue.java | 100 ++++++++++ src-util/modulescript/src/org/openbravo/modulescript/PgJdbcDatesIssue_data.xsql | 98 +++++++++ 4 files changed, 198 insertions(+), 0 deletions(-) diffs (211 lines): diff -r c6ee63dab444 -r f8de3bcd78f3 src-util/modulescript/build/classes/org/openbravo/modulescript/PgJdbcDatesIssue.class Binary file src-util/modulescript/build/classes/org/openbravo/modulescript/PgJdbcDatesIssue.class has changed diff -r c6ee63dab444 -r f8de3bcd78f3 src-util/modulescript/build/classes/org/openbravo/modulescript/PgJdbcDatesIssueData.class Binary file src-util/modulescript/build/classes/org/openbravo/modulescript/PgJdbcDatesIssueData.class has changed diff -r c6ee63dab444 -r f8de3bcd78f3 src-util/modulescript/src/org/openbravo/modulescript/PgJdbcDatesIssue.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src-util/modulescript/src/org/openbravo/modulescript/PgJdbcDatesIssue.java Thu Jan 21 12:44:16 2016 +0100 @@ -0,0 +1,100 @@ +/* + ************************************************************************* + * The contents of this file are subject to the Openbravo Public License + * Version 1.1 (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) 2016 Openbravo SLU + * All Rights Reserved. + * Contributor(s): ______________________________________. + ************************************************************************ + */ + +package org.openbravo.modulescript; + +import java.io.FileInputStream; +import java.util.Properties; + +import org.apache.commons.lang.StringUtils; +import org.apache.log4j.Logger; +import org.openbravo.database.ConnectionProvider; + +/** + * Creates an alert for instances that might be affected by issue 31959 + * + * @author alostale + * + */ +public class PgJdbcDatesIssue extends ModuleScript { + + private static final Logger log = Logger.getLogger(PgJdbcDatesIssue.class); + private static final String CORE = "0"; + private static final OpenbravoVersion PR15Q4 = new OpenbravoVersion("3.0.27657"); + private static final OpenbravoVersion FIXED_VERSION = new OpenbravoVersion("3.0.28174"); + private static final String ALERT_NAME = "Updating from 15PRQ4 potential problems with dates"; + private static final String ALERT_TXT = "Some dates can be corrupted. Check http://wiki.openbravo.com/wiki/Release_Notes/Issue31959"; + + @Override + public void execute() { + if (!shouldExecute()) { + return; + } + + try { + createAlert(); + } catch (Exception e) { + log.error("Error processing alert", e); + } + } + + private boolean shouldExecute() { + ConnectionProvider cp = getConnectionProvider(); + if (!"POSTGRE".equals(cp.getRDBMS())) { + return false; + } + + Properties properties = new Properties(); + try { + properties.load(new FileInputStream(getPropertiesFile())); + } catch (Exception e) { + log.error("Could not load Openbravo.properties"); + return false; + } + + boolean usingCommonsDBCPPool = StringUtils.isBlank(properties + .getProperty("db.externalPoolClassName")); + + if (!usingCommonsDBCPPool) { + return false; + } + + try { + boolean alertAlreadyCraeted = PgJdbcDatesIssueData.existsAlert(cp, ALERT_NAME); + return !alertAlreadyCraeted; + } catch (Exception e) { + log.error("Error processing alert", e); + return false; + } + } + + private void createAlert() throws Exception { + log.warn(ALERT_NAME + " - " + ALERT_TXT); + ConnectionProvider cp = getConnectionProvider(); + PgJdbcDatesIssueData.insertAlertRule(cp, ALERT_NAME); + String ruleId = PgJdbcDatesIssueData.getAlertRuleId(cp, ALERT_NAME); + PgJdbcDatesIssueData.insertAlertRecipient(cp, ruleId); + PgJdbcDatesIssueData.insertAlert(cp, ALERT_TXT, ruleId); + } + + @Override + protected ModuleScriptExecutionLimits getModuleScriptExecutionLimits() { + return new ModuleScriptExecutionLimits(CORE, PR15Q4, FIXED_VERSION); + } +} diff -r c6ee63dab444 -r f8de3bcd78f3 src-util/modulescript/src/org/openbravo/modulescript/PgJdbcDatesIssue_data.xsql --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src-util/modulescript/src/org/openbravo/modulescript/PgJdbcDatesIssue_data.xsql Thu Jan 21 12:44:16 2016 +0100 @@ -0,0 +1,98 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<!-- + ************************************************************************* + * The contents of this file are subject to the Openbravo Public License + * Version 1.1 (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) 2016 Openbravo SLU + * All Rights Reserved. + * Contributor(s): ______________________________________. + ************************************************************************ +--> +<SqlClass name="PgJdbcDatesIssueData" package="org.openbravo.modulescript"> + <SqlMethod name="existsAlertRule" type="preparedStatement" return="boolean"> + <Sql><![CDATA[ + SELECT COUNT(*) AS EXISTING + FROM AD_ALERTRULE + WHERE NAME = ? + ]]> + </Sql> + <Parameter name="alertRule"/> + </SqlMethod> + + <SqlMethod name="existsAlert" type="preparedStatement" return="boolean"> + <Sql><![CDATA[ + SELECT COUNT(*) AS EXISTING + FROM AD_ALERTRULE + WHERE NAME = ? + ]]> + </Sql> + <Parameter name="name"/> + </SqlMethod> + + <SqlMethod name="getAlertRuleId" type="preparedStatement" return="string"> + <SqlMethodComment></SqlMethodComment> + <Sql><![CDATA[ + SELECT MAX(ad_alertrule_id) AS id + FROM AD_ALERTRULE + WHERE NAME = ? + ]]></Sql> + <Parameter name="name"/> + </SqlMethod> + + <SqlMethod name="insertAlertRule" type="preparedStatement" return="rowcount"> + <SqlMethodComment></SqlMethodComment> + <Sql><![CDATA[ + INSERT INTO AD_ALERTRULE ( + AD_ALERTRULE_ID, AD_CLIENT_ID, AD_ORG_ID, ISACTIVE, + CREATED, CREATEDBY, UPDATED, UPDATEDBY, + NAME, TYPE + ) VALUES ( + get_uuid(), '0', '0', 'Y', + now(), '0', now(), '0', + ?, 'E' + ) + ]]></Sql> + <Parameter name="name"/> + </SqlMethod> + + <SqlMethod name="insertAlert" type="preparedStatement" return="rowcount"> + <Sql><![CDATA[ + INSERT INTO AD_Alert ( + AD_Alert_ID, AD_Client_ID, AD_Org_ID, IsActive, + Created, CreatedBy, Updated, UpdatedBy, + Description, AD_AlertRule_ID, Referencekey_ID + ) VALUES ( + get_uuid(), '0', '0', 'Y', + NOW(), '0', NOW(), '0', + ?, ?, '0') + ]]> + </Sql> + <Parameter name="description" /> + <Parameter name="adAlertRuleId" /> + </SqlMethod> + + <SqlMethod name="insertAlertRecipient" type="preparedStatement" return="rowcount"> + <Sql><![CDATA[ + INSERT INTO ad_alertrecipient( + ad_client_id, ad_org_id, isactive, created, createdby, + updated, updatedby, ad_alertrecipient_id, ad_alertrule_id, ad_role_id, + sendemail) + select ad_client_id, ad_org_id, 'Y', now(), '0', + now(), '0', get_uuid(), ?, ad_role_id, 'N' + from ad_role + where isactive = 'Y' + ]]> + </Sql> + <Parameter name="adAlertRuleId" /> + </SqlMethod> + +</SqlClass> \ No newline at end of file ------------------------------------------------------------------------------ Site24x7 APM Insight: Get Deep Visibility into Application Performance APM + Mobile APM + RUM: Monitor 3 App instances at just $35/Month Monitor end-to-end web transactions and take corrective actions now Troubleshoot faster and improve end-user experience. Signup Now! http://pubads.g.doubleclick.net/gampad/clk?id=267308311&iu=/4140 _______________________________________________ Openbravo-commits mailing list Openbravo-commits@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/openbravo-commits