/** * @param orderSetService the orderSetService to set */ public void setOrderSetService(OrderSetService orderSetService) { setService(OrderSetService.class, orderSetService); }
/** * There should only be one ServiceContext per openmrs (java virtual machine). This method * should be used when wanting to fetch the service context Note: The ServiceContext shouldn't * be used independently. All calls should go through the Context * * @return This VM's current ServiceContext. * @see org.openmrs.api.context.Context */ public static ServiceContext getInstance() { if (ServiceContextHolder.instance == null) { ServiceContextHolder.instance = new ServiceContext(); } return ServiceContextHolder.instance; }
ServiceContext.destroyInstance(); Thread.currentThread().setContextClassLoader(OpenmrsClassLoader.getInstance()); ServiceContext.getInstance().startRefreshingContext(); try { ctx.refresh(); ServiceContext.getInstance().doneRefreshingContext();
@Before public void setUp() throws Exception { String xml = (new TestUtil()).loadXmlFromFile(XML_HTML_FORM_ENTRY_REGIMEN_UTIL_TEST_DATASET); // used to avoid lock timeout on GP#order.nextOrderNumberSeed AdministrationService administrationService = mock(AdministrationService.class); when(administrationService.getGlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_STANDARD_DRUG_REGIMENS)) .thenReturn(xml); when(administrationService.getGlobalProperty("")).thenAnswer(new Answer<String>() { @Override public String answer(InvocationOnMock invocationOnMock) throws Throwable { return "" + orderNumberCounter++; } }); ServiceContext.getInstance().setAdministrationService(administrationService); }
/** * @verifies return a localized message if specified */ @Test public void getDisplayString_shouldReturnALocalizedMessageIfSpecified() throws Exception { String UUID = "0cbe2ed3-cd5f-4f46-9459-26127c9265ab"; MessageSourceService messageSourceService = mock(MessageSourceService.class); when(messageSourceService.getMessage("ui.i18n.Location.name." + UUID)).thenReturn("Correct"); ServiceContext.getInstance().setMessageSourceService(messageSourceService); Location location = new Location(); location.setName("Incorrect"); location.setUuid(UUID); MockLocationResource resource = new MockLocationResource(); String display = resource.getDisplayString(location); assertThat(display, is("Correct")); }
/** * Gets the currently defined service context. If one is not defined, one will be created and * then returned. * * @return the current ServiceContext */ static ServiceContext getServiceContext() { if (serviceContext == null) { synchronized (Context.class) { if (serviceContext == null) { log.error("serviceContext is null. Creating new ServiceContext()"); serviceContext = ServiceContext.getInstance(); } } } log.trace("serviceContext: {}", serviceContext); return ServiceContext.getInstance(); }
setService(cls, classInstance); runOpenmrsServiceOnStartup((OpenmrsService) classInstance, classString);
public void revertMocks() { for (Map.Entry<Class<?>, Object> realService : realServices.entrySet()) { Context.getServiceContext().setService(realService.getKey(), realService.getValue()); Context.getServiceContext().setApplicationContext(realApplicationContext); realApplicationContext = null;
/** * Moves advisors and advice added by ServiceContext from the source service to the target one. * * @param source the existing service * @param target the new service */ private void moveAddedAOP(Advised source, Advised target) { Class serviceClass = source.getClass(); Set<Advisor> existingAdvisors = getAddedAdvisors(serviceClass); for (Advisor advisor : existingAdvisors) { target.addAdvisor(advisor); source.removeAdvisor(advisor); } Set<Advice> existingAdvice = getAddedAdvice(serviceClass); for (Advice advice : existingAdvice) { target.addAdvice(advice); source.removeAdvice(advice); } }
/** * @param cls * @param advisor */ public void removeAdvisor(Class cls, Advisor advisor) { Advised advisedService = (Advised) services.get(cls); advisedService.removeAdvisor(advisor); getAddedAdvisors(cls).remove(advisor); }
/** * @param cls * @param advice */ public void removeAdvice(Class cls, Advice advice) { Advised advisedService = (Advised) services.get(cls); advisedService.removeAdvice(advice); getAddedAdvice(cls).remove(advice); }
/** * Adds an AOP advisor around the given Class <code>cls</code> * <p> * Advisors can wrap around a method and effect the method before or after * * @param cls * @param advisor */ public static void addAdvisor(Class cls, Advisor advisor) { getServiceContext().addAdvisor(cls, advisor); }
/** * Adds an AOP advice object around the given Class <code>cls</code> * <p> * Advice comes in the form of before or afterReturning methods * * @param cls * @param advice */ public static void addAdvice(Class cls, Advice advice) { getServiceContext().addAdvice(cls, advice); }
/** * @param cls * @param advisor */ public void addAdvisor(Class cls, Advisor advisor) { Advised advisedService = (Advised) services.get(cls); if (advisedService.indexOf(advisor) < 0) { advisedService.addAdvisor(advisor); } addedAdvisors.computeIfAbsent(cls, k -> new HashSet<>()); getAddedAdvisors(cls).add(advisor); }
/** * @param cls * @param advice */ public void addAdvice(Class cls, Advice advice) { Advised advisedService = (Advised) services.get(cls); if (advisedService.indexOf(advice) < 0) { advisedService.addAdvice(advice); } addedAdvice.computeIfAbsent(cls, k -> new HashSet<>()); getAddedAdvice(cls).add(advice); }
/** * Sets the provider service. * * @param providerService the providerService to set * @since 1.9 **/ public void setProviderService(ProviderService providerService) { setService(ProviderService.class, providerService); }
/** * @param diagnosisService diagnosis related service * * @since 2.2 */ public void setDiagnosisService(DiagnosisService diagnosisService) { setService(DiagnosisService.class, diagnosisService); }
/** * @param cs cohort related service */ public void setCohortService(CohortService cs) { setService(CohortService.class, cs); }
/** * Set the scheduler service. * * @param schedulerService */ public void setSchedulerService(SchedulerService schedulerService) { setService(SchedulerService.class, schedulerService); }
/** * @param formService the formService to set */ public void setFormService(FormService formService) { setService(FormService.class, formService); }