[Minor] Sorting of supported languages
This commit is contained in:
parent
5526f20220
commit
f02b541848
|
@ -13,8 +13,10 @@ import li.strolch.runtime.configuration.SupportedLanguage;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import java.util.Comparator;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
import static java.util.Comparator.*;
|
||||||
import static li.strolch.utils.helper.ExceptionHelper.getRootCauseMessage;
|
import static li.strolch.utils.helper.ExceptionHelper.getRootCauseMessage;
|
||||||
|
|
||||||
@Path("strolch/languages")
|
@Path("strolch/languages")
|
||||||
|
@ -27,14 +29,20 @@ public class LanguagesResource {
|
||||||
@Produces(MediaType.APPLICATION_JSON)
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
public Response getSupportedLanguages() {
|
public Response getSupportedLanguages() {
|
||||||
try {
|
try {
|
||||||
Set<SupportedLanguage> supportedLanguages = RestfulStrolchComponent.getInstance().getAgent()
|
JsonArray result = RestfulStrolchComponent
|
||||||
.getStrolchConfiguration().getRuntimeConfiguration().getSupportedLanguages();
|
.getInstance()
|
||||||
JsonArray result = supportedLanguages.stream().map(language -> {
|
.getAgent()
|
||||||
JsonObject jsonObject = new JsonObject();
|
.getRuntimeConfiguration()
|
||||||
jsonObject.addProperty(Tags.Json.LOCALE, language.locale());
|
.getSupportedLanguages()
|
||||||
jsonObject.addProperty(Tags.Json.NAME, language.name());
|
.stream()
|
||||||
return jsonObject;
|
.sorted(comparing(SupportedLanguage::name))
|
||||||
}).collect(JsonArray::new, JsonArray::add, JsonArray::addAll);
|
.map(language -> {
|
||||||
|
JsonObject jsonObject = new JsonObject();
|
||||||
|
jsonObject.addProperty(Tags.Json.LOCALE, language.locale());
|
||||||
|
jsonObject.addProperty(Tags.Json.NAME, language.name());
|
||||||
|
return jsonObject;
|
||||||
|
})
|
||||||
|
.collect(JsonArray::new, JsonArray::add, JsonArray::addAll);
|
||||||
|
|
||||||
return Response.ok().entity(result.toString()).build();
|
return Response.ok().entity(result.toString()).build();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|
Loading…
Reference in New Issue