From 37aa36a9c94462499ca1f0ac8057afe21174aa8b Mon Sep 17 00:00:00 2001 From: sherrif10 Date: Wed, 10 Feb 2021 19:18:59 +0300 Subject: [PATCH 1/5] RA-1889:Return Relativively Formatted Error Message --- ...ewEncounterWithHtmlFormPageController.java | 29 ++++++++++++++++++- .../pages/htmlform/NullPointerException.gsp | 0 2 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 omod/src/main/webapp/pages/htmlform/NullPointerException.gsp diff --git a/omod/src/main/java/org/openmrs/module/htmlformentryui/page/controller/htmlform/ViewEncounterWithHtmlFormPageController.java b/omod/src/main/java/org/openmrs/module/htmlformentryui/page/controller/htmlform/ViewEncounterWithHtmlFormPageController.java index 085ba4e..b24a530 100644 --- a/omod/src/main/java/org/openmrs/module/htmlformentryui/page/controller/htmlform/ViewEncounterWithHtmlFormPageController.java +++ b/omod/src/main/java/org/openmrs/module/htmlformentryui/page/controller/htmlform/ViewEncounterWithHtmlFormPageController.java @@ -1,8 +1,12 @@ package org.openmrs.module.htmlformentryui.page.controller.htmlform; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + import org.apache.commons.lang.StringUtils; import org.openmrs.Encounter; import org.openmrs.api.AdministrationService; +import org.openmrs.messagesource.MessageSourceService; import org.openmrs.module.emrapi.patient.PatientDomainWrapper; import org.openmrs.module.htmlformentry.HtmlForm; import org.openmrs.module.htmlformentry.HtmlFormEntryService; @@ -11,9 +15,18 @@ import org.openmrs.ui.framework.annotation.InjectBeans; import org.openmrs.ui.framework.annotation.SpringBean; import org.openmrs.ui.framework.page.PageModel; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.RequestParam; public class ViewEncounterWithHtmlFormPageController { + + private static final Log log = LogFactory.getLog(ViewEncounterWithHtmlFormPageController.class); + + @Autowired + private MessageSourceService messageSourceService; + + private String message; public void get(@RequestParam("encounter") Encounter encounter, @RequestParam(value = "showPatientHeader", defaultValue = "true") boolean showPatientHeader, @@ -52,8 +65,16 @@ public void get(@RequestParam("encounter") Encounter encounter, model.addAttribute("showPatientHeader", showPatientHeader); HtmlForm htmlForm = htmlFormEntryService.getHtmlFormByForm(encounter.getForm()); +// HttpSession session = request.getSession(); if (htmlForm == null) { - throw new IllegalArgumentException("encounter.form is not an HTML Form: " + encounter.getForm()); +// HttpSession session = request.getSession(); + message = messageSourceService.getMessage("encounter.form is not an HTML Form" +encounter.getForm()); + log.warn("Active drugs are not supported yet"); +// session.setAttribute(WebConstants.OPENMRS_ERROR_ATTR, message); +// throw new IllegalArgumentException("encounter.form is not an HTML Form: " + encounter.getForm()); + model.addAttribute("htmlForm", htmlForm); + + } model.addAttribute("htmlForm", htmlForm); } @@ -65,5 +86,11 @@ public void get(@RequestParam("encounter") Encounter encounter, private String fixCase(String word) { return Character.toUpperCase(word.charAt(0)) + word.substring(1).toLowerCase(); } + + @ExceptionHandler(value= NullPointerException.class) + public String HandleNullPointerException(Exception e) { + log.warn(message); + return "NullPointerException"; + } } diff --git a/omod/src/main/webapp/pages/htmlform/NullPointerException.gsp b/omod/src/main/webapp/pages/htmlform/NullPointerException.gsp new file mode 100644 index 0000000..e69de29 From 6c7e64a703c4bd93dedbde7efe379f8e6f6e39aa Mon Sep 17 00:00:00 2001 From: sherrif10 Date: Wed, 10 Feb 2021 22:59:58 +0300 Subject: [PATCH 2/5] Collecting the exception handler --- ...ewEncounterWithHtmlFormPageController.java | 20 ++++++++++--------- .../pages/htmlform/NullPointerException.gsp | 5 +++++ 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/omod/src/main/java/org/openmrs/module/htmlformentryui/page/controller/htmlform/ViewEncounterWithHtmlFormPageController.java b/omod/src/main/java/org/openmrs/module/htmlformentryui/page/controller/htmlform/ViewEncounterWithHtmlFormPageController.java index b24a530..f7f6e88 100644 --- a/omod/src/main/java/org/openmrs/module/htmlformentryui/page/controller/htmlform/ViewEncounterWithHtmlFormPageController.java +++ b/omod/src/main/java/org/openmrs/module/htmlformentryui/page/controller/htmlform/ViewEncounterWithHtmlFormPageController.java @@ -16,8 +16,12 @@ import org.openmrs.ui.framework.annotation.SpringBean; import org.openmrs.ui.framework.page.PageModel; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.context.request.WebRequest; public class ViewEncounterWithHtmlFormPageController { @@ -65,13 +69,10 @@ public void get(@RequestParam("encounter") Encounter encounter, model.addAttribute("showPatientHeader", showPatientHeader); HtmlForm htmlForm = htmlFormEntryService.getHtmlFormByForm(encounter.getForm()); -// HttpSession session = request.getSession(); + if (htmlForm == null) { -// HttpSession session = request.getSession(); message = messageSourceService.getMessage("encounter.form is not an HTML Form" +encounter.getForm()); - log.warn("Active drugs are not supported yet"); -// session.setAttribute(WebConstants.OPENMRS_ERROR_ATTR, message); -// throw new IllegalArgumentException("encounter.form is not an HTML Form: " + encounter.getForm()); + log.warn("Active drugs are cannot be editted"); model.addAttribute("htmlForm", htmlForm); @@ -87,10 +88,11 @@ private String fixCase(String word) { return Character.toUpperCase(word.charAt(0)) + word.substring(1).toLowerCase(); } - @ExceptionHandler(value= NullPointerException.class) - public String HandleNullPointerException(Exception e) { - log.warn(message); + @ExceptionHandler(value= NullPointerException.class) + public String HandleNullPointerException(Exception e) { + log.warn("encounter.form is not an HTML Form"); return "NullPointerException"; - } + } + } diff --git a/omod/src/main/webapp/pages/htmlform/NullPointerException.gsp b/omod/src/main/webapp/pages/htmlform/NullPointerException.gsp index e69de29..647be80 100644 --- a/omod/src/main/webapp/pages/htmlform/NullPointerException.gsp +++ b/omod/src/main/webapp/pages/htmlform/NullPointerException.gsp @@ -0,0 +1,5 @@ + + + <% out << " ooppsss!!!! Active drugs cannot be edittted!" %> + + \ No newline at end of file From 64ffe4462738ac61eb804b9f15e32ff9213ada2a Mon Sep 17 00:00:00 2001 From: sherrif10 Date: Wed, 10 Feb 2021 23:30:47 +0300 Subject: [PATCH 3/5] adding error view page --- .../ViewEncounterWithHtmlFormPageController.java | 16 +++++----------- .../pages/htmlform/NullPointerException.gsp | 7 +++++++ 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/omod/src/main/java/org/openmrs/module/htmlformentryui/page/controller/htmlform/ViewEncounterWithHtmlFormPageController.java b/omod/src/main/java/org/openmrs/module/htmlformentryui/page/controller/htmlform/ViewEncounterWithHtmlFormPageController.java index f7f6e88..1d2ab08 100644 --- a/omod/src/main/java/org/openmrs/module/htmlformentryui/page/controller/htmlform/ViewEncounterWithHtmlFormPageController.java +++ b/omod/src/main/java/org/openmrs/module/htmlformentryui/page/controller/htmlform/ViewEncounterWithHtmlFormPageController.java @@ -16,12 +16,8 @@ import org.openmrs.ui.framework.annotation.SpringBean; import org.openmrs.ui.framework.page.PageModel; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.HttpHeaders; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.context.request.WebRequest; public class ViewEncounterWithHtmlFormPageController { @@ -72,10 +68,8 @@ public void get(@RequestParam("encounter") Encounter encounter, if (htmlForm == null) { message = messageSourceService.getMessage("encounter.form is not an HTML Form" +encounter.getForm()); - log.warn("Active drugs are cannot be editted"); - model.addAttribute("htmlForm", htmlForm); - - + log.warn("Active drugs are cannot be editted"); + } model.addAttribute("htmlForm", htmlForm); } @@ -90,9 +84,9 @@ private String fixCase(String word) { @ExceptionHandler(value= NullPointerException.class) public String HandleNullPointerException(Exception e) { - log.warn("encounter.form is not an HTML Form"); - return "NullPointerException"; - } + log.warn("encounter.form is not an HTML Form"); + return "NullPointerException"; + } } diff --git a/omod/src/main/webapp/pages/htmlform/NullPointerException.gsp b/omod/src/main/webapp/pages/htmlform/NullPointerException.gsp index 647be80..5249b30 100644 --- a/omod/src/main/webapp/pages/htmlform/NullPointerException.gsp +++ b/omod/src/main/webapp/pages/htmlform/NullPointerException.gsp @@ -1,5 +1,12 @@ +

Application has encountered an error. Please contact support on ...

<% out << " ooppsss!!!! Active drugs cannot be edittted!" %> + \ No newline at end of file From 3302488b2ab161e847ae2fcce4283a71c82324f4 Mon Sep 17 00:00:00 2001 From: sherrif10 Date: Thu, 11 Feb 2021 01:00:00 +0300 Subject: [PATCH 4/5] Using ArrayList --- .../htmlform/ViewEncounterWithHtmlFormPageController.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/omod/src/main/java/org/openmrs/module/htmlformentryui/page/controller/htmlform/ViewEncounterWithHtmlFormPageController.java b/omod/src/main/java/org/openmrs/module/htmlformentryui/page/controller/htmlform/ViewEncounterWithHtmlFormPageController.java index 1d2ab08..6f0197f 100644 --- a/omod/src/main/java/org/openmrs/module/htmlformentryui/page/controller/htmlform/ViewEncounterWithHtmlFormPageController.java +++ b/omod/src/main/java/org/openmrs/module/htmlformentryui/page/controller/htmlform/ViewEncounterWithHtmlFormPageController.java @@ -3,6 +3,8 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import java.util.List; + import org.apache.commons.lang.StringUtils; import org.openmrs.Encounter; import org.openmrs.api.AdministrationService; @@ -37,6 +39,7 @@ public void get(@RequestParam("encounter") Encounter encounter, @SpringBean("htmlFormEntryService") HtmlFormEntryService htmlFormEntryService, @SpringBean("adminService") AdministrationService administrationService, UiUtils ui, + List errors, PageModel model) { patient.setPatient(encounter.getPatient()); @@ -67,9 +70,8 @@ public void get(@RequestParam("encounter") Encounter encounter, HtmlForm htmlForm = htmlFormEntryService.getHtmlFormByForm(encounter.getForm()); if (htmlForm == null) { - message = messageSourceService.getMessage("encounter.form is not an HTML Form" +encounter.getForm()); - log.warn("Active drugs are cannot be editted"); - + log.warn("Active drugs are cannot be editted"); + errors.add("encounter.form is not an HTML Form:"+encounter.getForm()); } model.addAttribute("htmlForm", htmlForm); } From 85a1720e00ae2b0dd13c530219e9f4d08ddd474c Mon Sep 17 00:00:00 2001 From: sherrif10 Date: Fri, 12 Feb 2021 01:14:03 +0300 Subject: [PATCH 5/5] Collecting the error message --- .../ViewEncounterWithHtmlFormPageController.java | 10 +++++----- ...interException.gsp => IllegalArgumentException.gsp} | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) rename omod/src/main/webapp/pages/htmlform/{NullPointerException.gsp => IllegalArgumentException.gsp} (80%) diff --git a/omod/src/main/java/org/openmrs/module/htmlformentryui/page/controller/htmlform/ViewEncounterWithHtmlFormPageController.java b/omod/src/main/java/org/openmrs/module/htmlformentryui/page/controller/htmlform/ViewEncounterWithHtmlFormPageController.java index 6f0197f..8d9edda 100644 --- a/omod/src/main/java/org/openmrs/module/htmlformentryui/page/controller/htmlform/ViewEncounterWithHtmlFormPageController.java +++ b/omod/src/main/java/org/openmrs/module/htmlformentryui/page/controller/htmlform/ViewEncounterWithHtmlFormPageController.java @@ -70,8 +70,8 @@ public void get(@RequestParam("encounter") Encounter encounter, HtmlForm htmlForm = htmlFormEntryService.getHtmlFormByForm(encounter.getForm()); if (htmlForm == null) { - log.warn("Active drugs are cannot be editted"); - errors.add("encounter.form is not an HTML Form:"+encounter.getForm()); + log.warn("encounter.form is not an HTML Form"); + errors.add("encounter.form is not an HTML Form:"+encounter.getForm()); } model.addAttribute("htmlForm", htmlForm); } @@ -84,10 +84,10 @@ private String fixCase(String word) { return Character.toUpperCase(word.charAt(0)) + word.substring(1).toLowerCase(); } - @ExceptionHandler(value= NullPointerException.class) - public String HandleNullPointerException(Exception e) { + @ExceptionHandler(value= IllegalArgumentException.class) + public String HandleIllegalArgumentException(Exception e) { log.warn("encounter.form is not an HTML Form"); - return "NullPointerException"; + return "IllegalArgumentException"; } diff --git a/omod/src/main/webapp/pages/htmlform/NullPointerException.gsp b/omod/src/main/webapp/pages/htmlform/IllegalArgumentException.gsp similarity index 80% rename from omod/src/main/webapp/pages/htmlform/NullPointerException.gsp rename to omod/src/main/webapp/pages/htmlform/IllegalArgumentException.gsp index 5249b30..b72438b 100644 --- a/omod/src/main/webapp/pages/htmlform/NullPointerException.gsp +++ b/omod/src/main/webapp/pages/htmlform/IllegalArgumentException.gsp @@ -1,7 +1,7 @@

Application has encountered an error. Please contact support on ...

- <% out << " ooppsss!!!! Active drugs cannot be edittted!" %> + <% out << "encounter.form is not an HTML Form" %>