details: https://code.openbravo.com/erp/devel/pi/rev/d54c0d9a007f changeset: 31495:d54c0d9a007f user: Carlos Aristu <carlos.aristu <at> openbravo.com> date: Fri Feb 03 13:03:52 2017 +0100 summary: fixes issue 35149: use ResponseActionsBuilder API
diffstat: modules/org.openbravo.client.application/src/org/openbravo/client/application/report/BaseReportActionHandler.java | 28 +---- src/org/openbravo/common/actionhandler/KillProcess.java | 39 +++----- src/org/openbravo/portal/GrantPortalAccessProcess.java | 43 +++------ 3 files changed, 40 insertions(+), 70 deletions(-) diffs (226 lines): diff -r bea15095b80f -r d54c0d9a007f modules/org.openbravo.client.application/src/org/openbravo/client/application/report/BaseReportActionHandler.java --- a/modules/org.openbravo.client.application/src/org/openbravo/client/application/report/BaseReportActionHandler.java Fri Feb 03 12:48:19 2017 +0100 +++ b/modules/org.openbravo.client.application/src/org/openbravo/client/application/report/BaseReportActionHandler.java Fri Feb 03 13:03:52 2017 +0100 @@ -56,6 +56,7 @@ import org.openbravo.client.application.Parameter; import org.openbravo.client.application.ReportDefinition; import org.openbravo.client.application.process.BaseProcessActionHandler; +import org.openbravo.client.application.process.ResponseActionsBuilder.MessageType; import org.openbravo.client.application.report.ReportingUtils.ExportType; import org.openbravo.client.kernel.KernelConstants; import org.openbravo.client.kernel.RequestContext; @@ -117,36 +118,21 @@ @Override protected JSONObject doExecute(Map<String, Object> parameters, String content) { - JSONObject result = new JSONObject(); try { - result.put("retryExecution", true); - result.put("showResultsInProcessView", true); + JSONObject result = getResponseBuilder().retryExecution().showResultsInProcessView().build(); final JSONObject jsonContent = new JSONObject(content); final String action = jsonContent.getString(ApplicationConstants.BUTTON_VALUE); doGenerateReport(result, parameters, jsonContent, action); return result; - } catch (OBException e) { - log.error("Error generating report id: {}", parameters.get("reportId"), e); - JSONObject msg = new JSONObject(); - try { - msg.put("severity", "error"); - msg.put("text", OBMessageUtils.translateError(e.getMessage()).getMessage()); - result.put("message", msg); - } catch (JSONException ignore) { - } - return result; } catch (Exception e) { log.error("Error generating report id: {}", parameters.get("reportId"), e); - JSONObject msg = new JSONObject(); - try { - msg.put("severity", "error"); - msg.put("text", OBMessageUtils.translateError(e.getMessage()).getMessage()); - result.put("message", msg); - } catch (JSONException ignore) { - } - return result; + return getResponseBuilder() + .retryExecution() + .showResultsInProcessView() + .showMsgInProcessView(MessageType.ERROR, + OBMessageUtils.translateError(e.getMessage()).getMessage()).build(); } } diff -r bea15095b80f -r d54c0d9a007f src/org/openbravo/common/actionhandler/KillProcess.java --- a/src/org/openbravo/common/actionhandler/KillProcess.java Fri Feb 03 12:48:19 2017 +0100 +++ b/src/org/openbravo/common/actionhandler/KillProcess.java Fri Feb 03 13:03:52 2017 +0100 @@ -11,7 +11,7 @@ * under the License. * The Original Code is Openbravo ERP. * The Initial Developer of the Original Code is Openbravo SLU - * All portions are Copyright (C) 2014-2016 Openbravo SLU + * All portions are Copyright (C) 2014-2017 Openbravo SLU * All Rights Reserved. * Contributor(s): ______________________________________. ************************************************************************ @@ -21,9 +21,9 @@ import java.util.List; import java.util.Map; -import org.codehaus.jettison.json.JSONArray; import org.codehaus.jettison.json.JSONObject; import org.openbravo.client.application.process.BaseProcessActionHandler; +import org.openbravo.client.application.process.ResponseActionsBuilder.MessageType; import org.openbravo.erpCommon.utility.OBMessageUtils; import org.openbravo.scheduling.DefaultJob; import org.openbravo.scheduling.KillableProcess; @@ -49,7 +49,8 @@ JSONObject result = new JSONObject(); try { if (OBScheduler.isNoExecuteBackgroundPolicy()) { - return buildResult("error", "Error", "BackgroundPolicyNoExecuteMsg"); + return getResponseBuilder().showMsgInProcessView(MessageType.ERROR, + OBMessageUtils.getI18NMessage("BackgroundPolicyNoExecuteMsg", null)).build(); } JSONObject request = new JSONObject(content); @@ -74,10 +75,12 @@ // Kill Process ((KillableProcess) process).kill(jobInstance.getBundle()); jobInstance.setKilled(true); - return buildResult("info", "Info", "ProcessKilled"); + return getResponseBuilder().showMsgInProcessView(MessageType.INFO, + OBMessageUtils.getI18NMessage("ProcessKilled", null)).build(); } else { // KillableProcess not implemented - return buildResult("warning", "Info", "KillableProcessNotImplemented"); + return getResponseBuilder().showMsgInProcessView(MessageType.WARNING, + OBMessageUtils.getI18NMessage("KillableProcessNotImplemented", null)).build(); } } @@ -89,7 +92,8 @@ Throwable e = DbUtility.getUnderlyingSQLException(ex); log.error("Error in Kill Process", e); try { - result = buildResult("error", "Error", e.getMessage()); + return getResponseBuilder().showMsgInProcessView(MessageType.ERROR, + getTranslatedExceptionMessage(e)).build(); } catch (Exception ignoreException) { // do nothing } @@ -99,21 +103,12 @@ } - private JSONObject buildResult(String type, String title, String messagetext) throws Exception { - JSONObject result = new JSONObject(); - JSONObject message = new JSONObject(); - JSONObject msgTotalAction = new JSONObject(); - JSONArray actions = new JSONArray(); - - message.put("msgType", type); - message.put("msgTitle", OBMessageUtils.getI18NMessage(title, null)); - String msgText = OBMessageUtils.getI18NMessage(messagetext, null); - message.put("msgText", msgText == null ? messagetext : msgText); - - msgTotalAction.put("showMsgInProcessView", message); - actions.put(msgTotalAction); - result.put("responseActions", actions); - - return result; + private String getTranslatedExceptionMessage(Throwable throwable) { + String message = throwable.getMessage(); + String translatedMessage = OBMessageUtils.getI18NMessage(message, null); + if (translatedMessage != null) { + return translatedMessage; + } + return message; } } diff -r bea15095b80f -r d54c0d9a007f src/org/openbravo/portal/GrantPortalAccessProcess.java --- a/src/org/openbravo/portal/GrantPortalAccessProcess.java Fri Feb 03 12:48:19 2017 +0100 +++ b/src/org/openbravo/portal/GrantPortalAccessProcess.java Fri Feb 03 13:03:52 2017 +0100 @@ -11,7 +11,7 @@ * under the License. * The Original Code is Openbravo ERP. * The Initial Developer of the Original Code is Openbravo SLU - * All portions are Copyright (C) 2013 Openbravo SLU + * All portions are Copyright (C) 2013-2017 Openbravo SLU * All Rights Reserved. * Contributor(s): ______________________________________. ************************************************************************ @@ -26,11 +26,11 @@ import org.apache.commons.lang.RandomStringUtils; import org.apache.commons.lang.StringUtils; import org.apache.log4j.Logger; -import org.codehaus.jettison.json.JSONException; import org.codehaus.jettison.json.JSONObject; import org.hibernate.criterion.Restrictions; import org.openbravo.base.provider.OBProvider; import org.openbravo.client.application.process.BaseProcessActionHandler; +import org.openbravo.client.application.process.ResponseActionsBuilder.MessageType; import org.openbravo.dal.core.OBContext; import org.openbravo.dal.service.OBCriteria; import org.openbravo.dal.service.OBDal; @@ -109,45 +109,34 @@ Map<String, Object> emailData = new HashMap<String, Object>(); emailData.put("user", user); emailData.put("password", newPassword); - JSONObject msg = new JSONObject(); + MessageType messageType; + String messageText; try { boolean emailSent = emailManager.sendEmail(EVT_NEW_USER, user.getEmail(), emailData); if (emailSent) { - msg.put("severity", "success"); - msg.put("text", OBMessageUtils.getI18NMessage("Portal_UserGranted", null)); + messageType = MessageType.SUCCESS; + messageText = OBMessageUtils.getI18NMessage("Portal_UserGranted", null); user.setGrantPortalAccess(true); } else { - msg.put("severity", "warning"); - msg.put("text", OBMessageUtils.getI18NMessage("Portal_UserGrantedNoEmail", null)); + messageType = MessageType.WARNING; + messageText = OBMessageUtils.getI18NMessage("Portal_UserGrantedNoEmail", null); } } catch (Exception e) { log.error("Error sending email", e); - msg.put("severity", "warning"); - msg.put("text", - OBMessageUtils.getI18NMessage("ErrorInEmail", new String[] { e.getMessage() })); + return getResponseBuilder().showMsgInProcessView(MessageType.WARNING, + OBMessageUtils.getI18NMessage("ErrorInEmail", new String[] { e.getMessage() })).build(); } - JSONObject result = new JSONObject(); - result.put("message", msg); - return result; + return getResponseBuilder().showMsgInProcessView(messageType, messageText).build(); } catch (Exception e) { log.error("Error granting access to portal", e); - JSONObject result = new JSONObject(); - JSONObject msg = new JSONObject(); - try { - OBDal.getInstance().rollbackAndClose(); - msg.put("severity", "error"); - msg.put( - "text", - OBMessageUtils.getI18NMessage("Portal_ErrorGrantingPortalAccess", - new String[] { e.getMessage() })); - result.put("message", msg); - } catch (JSONException e1) { - log.error("Couldn't genereate error msg", e1); - } - return result; + OBDal.getInstance().rollbackAndClose(); + return getResponseBuilder().showMsgInProcessView( + MessageType.ERROR, + OBMessageUtils.getI18NMessage("Portal_ErrorGrantingPortalAccess", + new String[] { e.getMessage() })).build(); } } } ------------------------------------------------------------------------------ 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