From 3c7f001e5baf51ba6cdead77a37e7886ac337772 Mon Sep 17 00:00:00 2001 From: fayder Date: Fri, 1 Nov 2013 16:37:33 +0200 Subject: [PATCH] dev merge --- .../vaeke/restcountries/rest/CountryRest.java | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/main/java/vaeke/restcountries/rest/CountryRest.java b/src/main/java/vaeke/restcountries/rest/CountryRest.java index 69545ab4..07be58c6 100644 --- a/src/main/java/vaeke/restcountries/rest/CountryRest.java +++ b/src/main/java/vaeke/restcountries/rest/CountryRest.java @@ -46,6 +46,31 @@ public Object getCountries() { } } + @GET + @Path("alpha/{alphacode}") + public Object getByAlpha(@PathParam("alphacode") String alpha) { + LOG.info("Getting by alpha " + alpha); + try { + List countries = getAll(); + int alphaLength = alpha.length(); + for(Country country : countries) { + if (alphaLength == 2) { + if (country.getCca2().toLowerCase().equals(alpha.toLowerCase())) { + return country; + } + } else if (alphaLength == 3) { + if (country.getCca3().toLowerCase().equals(alpha.toLowerCase())) { + return country; + } + } + } + return Response.status(Status.NOT_FOUND).entity("404: Not Found").build(); + } catch (IOException e) { + LOG.error(e.getMessage(), e); + return Response.status(Status.INTERNAL_SERVER_ERROR).entity("500: Internal Server Error").build(); + } + } + @GET @Path("alpha2/{alpha2code}") @Deprecated