Advertisement
ssmusoke

AijarActivator.java

Dec 23rd, 2015
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.63 KB | None | 0 0
  1. /**
  2. * The contents of this file are subject to the OpenMRS Public License
  3. * Version 1.0 (the "License"); you may not use this file except in
  4. * compliance with the License. You may obtain a copy of the License at
  5. * http://license.openmrs.org
  6. * <p/>
  7. * Software distributed under the License is distributed on an "AS IS"
  8. * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
  9. * License for the specific language governing rights and limitations
  10. * under the License.
  11. * <p/>
  12. * Copyright (C) OpenMRS, LLC. All Rights Reserved.
  13. */
  14. package org.openmrs.module.aijar;
  15.  
  16.  
  17. import org.apache.commons.logging.Log;
  18. import org.apache.commons.logging.LogFactory;
  19. import org.openmrs.api.FormService;
  20. import org.openmrs.api.context.Context;
  21. import org.openmrs.module.Module;
  22. import org.openmrs.module.ModuleActivator;
  23. import org.openmrs.module.ModuleFactory;
  24. import org.openmrs.module.htmlformentry.HtmlFormEntryService;
  25. import org.openmrs.module.htmlformentryui.HtmlFormUtil;
  26. import org.openmrs.ui.framework.resource.ResourceFactory;
  27.  
  28. import java.util.Arrays;
  29. import java.util.List;
  30.  
  31. /**
  32. * This class contains the logic that is run every time this module is either started or stopped.
  33. */
  34. public class AijarActivator extends org.openmrs.module.BaseModuleActivator {
  35.  
  36. protected Log log = LogFactory.getLog(getClass());
  37.  
  38. /**
  39. * @see ModuleActivator#willRefreshContext()
  40. */
  41. public void willRefreshContext() {
  42. log.info("Refreshing aijar Module");
  43. }
  44.  
  45. /**
  46. * @see ModuleActivator#contextRefreshed()
  47. */
  48. public void contextRefreshed() {
  49. log.info("aijar Module refreshed");
  50. }
  51.  
  52. /**
  53. * @see ModuleActivator#willStart()
  54. */
  55. public void willStart() {
  56. log.info("Starting aijar Module");
  57. }
  58.  
  59. /**
  60. * @see ModuleActivator#started()
  61. */
  62. public void started() {
  63. try {
  64.  
  65. setupHtmlForms();
  66.  
  67. } catch (Exception e) {
  68. Module mod = ModuleFactory.getModuleById("aijar");
  69. ModuleFactory.stopModule(mod);
  70. throw new RuntimeException("failed to setup the required modules", e);
  71. }
  72.  
  73. log.info("aijar Module started");
  74. }
  75.  
  76. private void setupHtmlForms() throws Exception {
  77. try {
  78. ResourceFactory resourceFactory = ResourceFactory.getInstance();
  79. FormService formService = Context.getFormService();
  80. HtmlFormEntryService htmlFormEntryService = Context.getService(HtmlFormEntryService.class);
  81.  
  82. List<String> htmlforms = Arrays.asList("aijar:htmlforms/122a-HIVCare_ARTCard-SummaryPage.xml");
  83.  
  84. if (htmlforms != null) {
  85. for (String htmlform : htmlforms) {
  86. HtmlFormUtil.getHtmlFormFromUiResource(resourceFactory, formService, htmlFormEntryService, htmlform);
  87. }
  88. }
  89.  
  90.  
  91. } catch (Exception e) {
  92. log.error("Error loading the HTML forms " + e.toString());
  93. // this is a hack to get component test to pass until we find the proper way to mock this
  94. if (ResourceFactory.getInstance().getResourceProviders() == null) {
  95. log.error("Unable to load HTML forms--this error is expected when running component tests");
  96. } else {
  97. throw e;
  98. }
  99. }
  100.  
  101. }
  102.  
  103. /**
  104. * @see ModuleActivator#willStop()
  105. */
  106. public void willStop() {
  107. log.info("Stopping aijar Module");
  108. }
  109.  
  110. /**
  111. * @see ModuleActivator#stopped()
  112. */
  113. public void stopped() {
  114.  
  115. log.info("aijar Module stopped");
  116. }
  117. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement