details: https://code.openbravo.com/erp/devel/pi/rev/b12d3da979df changeset: 32533:b12d3da979df user: Asier Lostalé <asier.lostale <at> openbravo.com> date: Tue Aug 01 13:42:56 2017 +0200 summary: fixed 36559: platform callouts should be refactored to implement SimpleCallout
diffstat: modules/org.openbravo.userinterface.selector/src/org/openbravo/userinterface/selector/SelectorFieldPropertyCallout.java | 85 +--- src/org/openbravo/erpCommon/ad_callouts/Activation_Message.java | 76 +-- src/org/openbravo/erpCommon/ad_callouts/SL_AlertRule_SQL.java | 199 ++++----- src/org/openbravo/erpCommon/ad_callouts/SL_Column.java | 76 +--- src/org/openbravo/erpCommon/ad_callouts/SL_IsDefault.java | 99 +--- src/org/openbravo/erpCommon/ad_callouts/SL_ModuleCallout.java | 125 +---- src/org/openbravo/erpCommon/ad_callouts/SL_Module_Minor_Version.java | 80 +--- src/org/openbravo/erpCommon/ad_callouts/SL_TableAudit.java | 88 +--- 8 files changed, 239 insertions(+), 589 deletions(-) diffs (truncated from 1145 to 300 lines): diff -r 9732bf05ed79 -r b12d3da979df modules/org.openbravo.userinterface.selector/src/org/openbravo/userinterface/selector/SelectorFieldPropertyCallout.java --- a/modules/org.openbravo.userinterface.selector/src/org/openbravo/userinterface/selector/SelectorFieldPropertyCallout.java Wed Aug 02 19:28:53 2017 -0400 +++ b/modules/org.openbravo.userinterface.selector/src/org/openbravo/userinterface/selector/SelectorFieldPropertyCallout.java Tue Aug 01 13:42:56 2017 +0200 @@ -11,60 +11,43 @@ * under the License. * The Original Code is Openbravo ERP. * The Initial Developer of the Original Code is Openbravo SLU - * All portions are Copyright (C) 2009-2011 Openbravo SLU + * All portions are Copyright (C) 2009-2017 Openbravo SLU * All Rights Reserved. * Contributor(s): ______________________________________. ************************************************************************ */ package org.openbravo.userinterface.selector; -import java.io.IOException; -import java.io.PrintWriter; import java.util.List; import javax.servlet.ServletException; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; +import org.apache.commons.lang.StringUtils; import org.hibernate.criterion.Restrictions; import org.openbravo.base.filter.IsIDFilter; import org.openbravo.base.model.Entity; import org.openbravo.base.model.ModelProvider; import org.openbravo.base.model.Property; -import org.openbravo.base.secureApp.HttpSecureAppServlet; -import org.openbravo.base.secureApp.VariablesSecureApp; import org.openbravo.dal.core.OBContext; import org.openbravo.dal.service.OBCriteria; import org.openbravo.dal.service.OBDal; +import org.openbravo.erpCommon.ad_callouts.SimpleCallout; import org.openbravo.model.ad.datamodel.Column; import org.openbravo.model.ad.datamodel.Table; import org.openbravo.service.json.JsonConstants; -import org.openbravo.xmlEngine.XmlDocument; /** * This call out computes the columnid of a Selector Field. * * @author mtaal */ -public class SelectorFieldPropertyCallout extends HttpSecureAppServlet { - - private static final long serialVersionUID = 1L; +public class SelectorFieldPropertyCallout extends SimpleCallout { @Override - public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, - ServletException { - VariablesSecureApp vars = new VariablesSecureApp(request); - - // printRequest(request); - - printPage(response, vars); - } - - private void printPage(HttpServletResponse response, VariablesSecureApp vars) throws IOException, - ServletException { - final String selectorID = vars.getStringParameter("inpobuiselSelectorId", IsIDFilter.instance) + protected void execute(CalloutInfo info) throws ServletException { + final String selectorID = info.getStringParameter("inpobuiselSelectorId", IsIDFilter.instance) .trim(); - final String property = vars.getStringParameter("inpproperty").trim(); + final String property = info.getStringParameter("inpproperty").trim(); final Selector selector = OBDal.getInstance().get(Selector.class, selectorID); final Table table; if (selector.getTable() != null) { @@ -74,7 +57,6 @@ table = selector.getObserdsDatasource().getTable(); } else { // no table don't do anything - writeEmptyResult(response); return; } // some cases: @@ -83,9 +65,9 @@ final Entity entity = ModelProvider.getInstance().getEntity(table.getName()); Property foundProperty = null; - if (property.equals(JsonConstants.IDENTIFIER)) { + if (StringUtils.equals(property, JsonConstants.IDENTIFIER)) { if (entity.getIdentifierProperties().isEmpty()) { - writeEmptyResult(response); + // no properties don't do anything return; } foundProperty = entity.getIdentifierProperties().get(0); @@ -94,13 +76,12 @@ Entity currentEntity = entity; Property currentProperty = null; for (String part : parts) { - if (part.length() == 0) { - writeEmptyResult(response); + if (StringUtils.isEmpty(part)) { return; } - if (part.equals(JsonConstants.IDENTIFIER) || part.equals(JsonConstants.ID)) { + if (StringUtils.equals(part, JsonConstants.IDENTIFIER) + || StringUtils.equals(part, JsonConstants.ID)) { if (foundProperty == null) { - writeEmptyResult(response); return; } break; @@ -111,7 +92,7 @@ break; } - if (Entity.COMPUTED_COLUMNS_PROXY_PROPERTY.equals(currentProperty.getName())) { + if (StringUtils.equals(currentProperty.getName(), Entity.COMPUTED_COLUMNS_PROXY_PROPERTY)) { currentEntity = ModelProvider.getInstance().getEntity( currentEntity.getName() + Entity.COMPUTED_COLUMNS_CLASS_APPENDIX); } else { @@ -143,49 +124,15 @@ Restrictions.eq(Column.PROPERTY_DBCOLUMNNAME, foundProperty.getColumnName()))); final List<Column> columnList = columnCriteria.list(); if (columnList.isEmpty()) { - writeEmptyResult(response); + // No columns, don't do anything return; } - final XmlDocument xmlDocument = xmlEngine.readXmlTemplate( - "org/openbravo/erpCommon/ad_callouts/CallOut").createXmlDocument(); - - final StringBuilder sb = new StringBuilder(); - sb.append("var calloutName='Selector_Field_Property_Callout';\n"); - final StringBuilder array = new StringBuilder(); - array.append("var respuesta = new Array("); - array.append("new Array('inpadColumnId', \"" + columnList.get(0).getId() + "\")"); - // construct the array, where the first dimension contains the name - // of the field to be changed and the second one our newly generated - // value - array.append(");"); - xmlDocument.setParameter("array", sb.toString() + array.toString()); - xmlDocument.setParameter("frameName", "appFrame"); - response.setContentType("text/html; charset=UTF-8"); - PrintWriter out = response.getWriter(); - out.println(xmlDocument.print()); - out.close(); + // Update the column ID + info.addResult("inpadColumnId", columnList.get(0).getId()); } finally { OBContext.restorePreviousMode(); } } - - private void writeEmptyResult(HttpServletResponse response) throws IOException { - - final XmlDocument xmlDocument = xmlEngine.readXmlTemplate( - "org/openbravo/erpCommon/ad_callouts/CallOut").createXmlDocument(); - - final StringBuilder sb = new StringBuilder(); - sb.append("var calloutName='Selector_Field_Property_Callout';\n"); - final StringBuilder array = new StringBuilder(); - array.append("var respuesta = new Array("); - array.append(");"); - xmlDocument.setParameter("array", sb.toString() + array.toString()); - xmlDocument.setParameter("frameName", "appFrame"); - response.setContentType("text/html; charset=UTF-8"); - PrintWriter out = response.getWriter(); - out.println(xmlDocument.print()); - out.close(); - } } diff -r 9732bf05ed79 -r b12d3da979df src/org/openbravo/erpCommon/ad_callouts/Activation_Message.java --- a/src/org/openbravo/erpCommon/ad_callouts/Activation_Message.java Wed Aug 02 19:28:53 2017 -0400 +++ b/src/org/openbravo/erpCommon/ad_callouts/Activation_Message.java Tue Aug 01 13:42:56 2017 +0200 @@ -11,70 +11,34 @@ * under the License. * The Original Code is Openbravo ERP. * The Initial Developer of the Original Code is Openbravo SLU - * All portions are Copyright (C) 2008-2010 Openbravo SLU + * All portions are Copyright (C) 2008-2017 Openbravo SLU * All Rights Reserved. * Contributor(s): ______________________________________. ************************************************************************ */ package org.openbravo.erpCommon.ad_callouts; -import java.io.IOException; -import java.io.PrintWriter; +import javax.servlet.ServletException; -import javax.servlet.ServletConfig; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; +import org.apache.commons.lang.StringUtils; +import org.openbravo.base.filter.ValueListFilter; +import org.openbravo.erpCommon.utility.Utility; -import org.openbravo.base.secureApp.HttpSecureAppServlet; -import org.openbravo.base.secureApp.VariablesSecureApp; -import org.openbravo.erpCommon.utility.Utility; -import org.openbravo.xmlEngine.XmlDocument; +public class Activation_Message extends SimpleCallout { + @Override + protected void execute(CalloutInfo info) throws ServletException { + // Parameters + String strHBActive = info.getStringParameter("inpisheartbeatactive", new ValueListFilter("Y", + "N")); + String strRegActive = info.getStringParameter("inpisregistrationactive", new ValueListFilter( + "Y", "N")); -public class Activation_Message extends HttpSecureAppServlet { - private static final long serialVersionUID = 1L; - - public void init(ServletConfig config) { - super.init(config); - boolHist = false; - } - - public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, - ServletException { - VariablesSecureApp vars = new VariablesSecureApp(request); - if (vars.commandIn("DEFAULT")) { - String strHBActive = vars.getStringParameter("inpisheartbeatactive"); - String strRegActive = vars.getStringParameter("inpisregistrationactive"); - try { - printPage(response, vars, strHBActive, strRegActive); - } catch (ServletException ex) { - pageErrorCallOut(response); - } - } else - pageError(response); - } - - private void printPage(HttpServletResponse response, VariablesSecureApp vars, String strHBActive, - String strRegActive) throws IOException, ServletException { - if (log4j.isDebugEnabled()) - log4j.debug("Output: dataSheet"); - XmlDocument xmlDocument = xmlEngine.readXmlTemplate( - "org/openbravo/erpCommon/ad_callouts/CallOut").createXmlDocument(); - - String msg = (strHBActive.equalsIgnoreCase("Y") || strRegActive.equalsIgnoreCase("Y") ? Utility - .messageBD(this, "REG_INFO_MESSAGE", vars.getLanguage()) : ""); - - StringBuffer resultado = new StringBuffer(); - resultado.append("var calloutName='Activation_Message';\n\n"); - resultado.append("var respuesta = new Array("); - if (!msg.equals("")) - resultado.append("new Array(\"MESSAGE\", \"" + msg + "\")"); - resultado.append(");"); - xmlDocument.setParameter("array", resultado.toString()); - xmlDocument.setParameter("frameName", "appFrame"); - response.setContentType("text/html; charset=UTF-8"); - PrintWriter out = response.getWriter(); - out.println(xmlDocument.print()); - out.close(); + // Message + String msg = StringUtils.equalsIgnoreCase(strHBActive, "Y") + || StringUtils.equalsIgnoreCase(strRegActive, "Y") ? Utility.messageBD(this, + "REG_INFO_MESSAGE", info.vars.getLanguage()) : ""; + if (StringUtils.isNotEmpty(msg)) { + info.showMessage(msg); + } } } diff -r 9732bf05ed79 -r b12d3da979df src/org/openbravo/erpCommon/ad_callouts/SL_AlertRule_SQL.java --- a/src/org/openbravo/erpCommon/ad_callouts/SL_AlertRule_SQL.java Wed Aug 02 19:28:53 2017 -0400 +++ b/src/org/openbravo/erpCommon/ad_callouts/SL_AlertRule_SQL.java Tue Aug 01 13:42:56 2017 +0200 @@ -18,134 +18,125 @@ */ package org.openbravo.erpCommon.ad_callouts; -import java.io.IOException; -import java.io.PrintWriter; +import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSetMetaData; import java.sql.SQLException; -import javax.servlet.ServletConfig; import javax.servlet.ServletException; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import org.openbravo.base.secureApp.HttpSecureAppServlet; -import org.openbravo.base.secureApp.VariablesSecureApp; +import org.apache.commons.lang.StringUtils; +import org.openbravo.database.ConnectionProvider; import org.openbravo.erpCommon.utility.Utility; -import org.openbravo.exception.NoConnectionAvailableException; +import org.openbravo.service.db.DalConnectionProvider; import org.openbravo.utils.FormatUtilities; -import org.openbravo.xmlEngine.XmlDocument; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; /** * Checks the SQL in Alert Rule to ensure all required columns are included. */ -public class SL_AlertRule_SQL extends HttpSecureAppServlet { - private static final long serialVersionUID = 1L; ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot _______________________________________________ Openbravo-commits mailing list Openbravo-commits@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/openbravo-commits