congrats Icon
New! Tabnine Pro 14-day free trial
Start a free trial
Tabnine Logo
AdministrationService.getAllowedLocales
Code IndexAdd Tabnine to your IDE (free)

How to use
getAllowedLocales
method
in
org.openmrs.api.AdministrationService

Best Java code snippets using org.openmrs.api.AdministrationService.getAllowedLocales (Showing top 8 results out of 315)

origin: openmrs/openmrs-core

@Override
@Cacheable(value = "userSearchLocales")
public List<Locale> getSearchLocales(Locale currentLocale, User user) throws APIException {
  Set<Locale> locales = new LinkedHashSet<>();
  locales.add(currentLocale); //the currently used full locale
  locales.add(new Locale(currentLocale.getLanguage()));
  if (user != null) {
    List<Locale> proficientLocales = user.getProficientLocales();
    if (proficientLocales != null) {
      locales.addAll(proficientLocales);
    }
  }
  
  //limit locales to only allowed locales
  List<Locale> allowedLocales = Context.getAdministrationService().getAllowedLocales();
  if (allowedLocales != null) {
    Set<Locale> retainLocales = new HashSet<>();
    
    for (Locale allowedLocale : allowedLocales) {
      retainLocales.add(allowedLocale);
      retainLocales.add(new Locale(allowedLocale.getLanguage()));
    }
    
    locales.retainAll(retainLocales);
  }
  
  return new ArrayList<>(locales);
}
origin: openmrs/openmrs-core

locales.add(getDefaultLocale());
if (localesAllowedListCache == null) {
  localesAllowedListCache = Context.getAdministrationService().getAllowedLocales();
origin: openmrs/openmrs-core

@Test
public void getAllowedLocales_shouldReturnAtLeastOneLocaleIfNoLocalesDefinedInDatabaseYet() {
  assertTrue(adminService.getAllowedLocales().size() > 0);
}

origin: openmrs/openmrs-core

@Test
public void getAllowedLocales_shouldNotFailIfNotGlobalPropertyForLocalesAllowedDefinedYet() {
  adminService.purgeGlobalProperty(
    new GlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_LOCALE_ALLOWED_LIST));
  adminService.getAllowedLocales();
}

origin: openmrs/openmrs-core

@Test
public void getAllowedLocales_shouldNotReturnDuplicatesEvenIfTheGlobalPropertyHasThem() {
  adminService.saveGlobalProperty(
    new GlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_LOCALE_ALLOWED_LIST, "en_GB,fr,es,en_GB"));
  assertEquals(3, adminService.getAllowedLocales().size());
}

origin: openmrs/openmrs-module-webservices.rest

@RequestMapping(method = RequestMethod.POST)
@ResponseBody
@ResponseStatus(value = HttpStatus.OK)
public void post(@RequestBody Map<String, String> body) {
  String localeStr = body.get("locale");
  Locale locale = null;
  try {
    locale = LocaleUtils.toLocale(localeStr);
  }
  catch (IllegalArgumentException e) {
    throw new APIException(" '" + localeStr + "' does not represent a valid locale.");
  }
  Set<Locale> allowedLocales = new HashSet<Locale>(Context.getAdministrationService().getAllowedLocales());
  if (allowedLocales.contains(locale)) {
    Context.setLocale(locale);
  } else {
    throw new APIException(" '" + localeStr + "' is not in the list of allowed locales.");
  }
}

origin: openmrs/openmrs-module-webservices.rest

@Test
public void get_shouldReturnLocaleInfoIfTheUserIsAuthenticated() throws Exception {
  Assert.assertTrue(Context.isAuthenticated());
  Object ret = controller.get(request);
  Assert.assertEquals(Context.getLocale(), PropertyUtils.getProperty(ret, "locale"));
  Assert.assertArrayEquals(Context.getAdministrationService().getAllowedLocales().toArray(),
    ((List<Locale>) PropertyUtils.getProperty(ret, "allowedLocales")).toArray());
}

origin: openmrs/openmrs-module-webservices.rest

/**
 * Tells the user their sessionId, and whether or not they are authenticated.
 * 
 * @param request
 * @return
 * @should return the session id if the user is authenticated
 * @should return the session id if the user is not authenticated
 */
@RequestMapping(method = RequestMethod.GET)
@ResponseBody
public Object get(WebRequest request) {
  boolean authenticated = Context.isAuthenticated();
  SimpleObject session = new SimpleObject();
  session.add("sessionId", request.getSessionId()).add("authenticated", authenticated);
  if (authenticated) {
    String repParam = request.getParameter(RestConstants.REQUEST_PROPERTY_FOR_REPRESENTATION);
    Representation rep = (repParam != null) ? restService.getRepresentation(repParam) : Representation.DEFAULT;
    session.add("user", ConversionUtil.convertToRepresentation(Context.getAuthenticatedUser(), rep));
    session.add("locale", Context.getLocale());
    session.add("allowedLocales", Context.getAdministrationService().getAllowedLocales());
  }
  return session;
}

org.openmrs.apiAdministrationServicegetAllowedLocales

Javadoc

Gets the list of locales which the administrator has allowed for use on the system. This is specified with a global property named OpenmrsConstants#GLOBAL_PROPERTY_LOCALE_ALLOWED_LIST.

Popular methods of AdministrationService

  • saveGlobalProperty
    Save the given global property to the database
  • getGlobalProperty
    Gets the global property that has the given propertyName If propertyName is not found in the list of
  • getGlobalPropertyObject
    Gets the global property that has the given propertyName
  • getAllGlobalProperties
    Get a list of all global properties in the system
  • executeSQL
    Runs the sql on the database. If selectOnly is flagged then any non-select sql statements will be re
  • getGlobalPropertiesByPrefix
    Gets all global properties that begin with prefix.
  • getGlobalPropertyByUuid
    Get a global property by its uuid. There should be only one of these in the database (well, in the w
  • getGlobalPropertyValue
    Returns a global property according to the type specified
  • purgeGlobalProperty
    Completely remove the given global property from the database
  • addGlobalPropertyListener
    Allows code to be notified when a global property is created/edited/deleted.
  • getSearchLocales
    Returns a list of locales used by the user when searching.
  • getSystemVariables
    Get a listing or important variables used in openmrs
  • getSearchLocales,
  • getSystemVariables,
  • setGlobalProperty,
  • setImplementationId,
  • validate,
  • getGlobalPropertiesBySuffix,
  • getImplementationId,
  • getMaximumPropertyLength,
  • getPresentationLocales

Popular in Java

  • Creating JSON documents from java classes using gson
  • getResourceAsStream (ClassLoader)
  • compareTo (BigDecimal)
  • getSharedPreferences (Context)
  • BufferedImage (java.awt.image)
    The BufferedImage subclass describes an java.awt.Image with an accessible buffer of image data. All
  • FileNotFoundException (java.io)
    Thrown when a file specified by a program cannot be found.
  • Stack (java.util)
    Stack is a Last-In/First-Out(LIFO) data structure which represents a stack of objects. It enables u
  • TimeUnit (java.util.concurrent)
    A TimeUnit represents time durations at a given unit of granularity and provides utility methods to
  • HttpServletRequest (javax.servlet.http)
    Extends the javax.servlet.ServletRequest interface to provide request information for HTTP servlets.
  • StringUtils (org.apache.commons.lang)
    Operations on java.lang.String that arenull safe. * IsEmpty/IsBlank - checks if a String contains
  • Top 17 PhpStorm Plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyStudentsTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now