Adding sovereign state and new flag

* Adding sovereign state, the sovereign state that governs the territory
* flag is now the object containing the png, svg, alt and **emoji**
This commit is contained in:
Alejandro Matos
2026-02-25 22:26:34 -05:00
parent c5f8c84307
commit 43f399832c
12 changed files with 3660 additions and 3353 deletions
+1
View File
@@ -13,3 +13,4 @@ out/
.settings .settings
.classpath .classpath
.factorypath .factorypath
src/main/resources/infoboxes/
+15
View File
@@ -18,6 +18,7 @@ Complete reference for all fields returned by the v4 API (`/v4`). The v4 API res
| `independent` | Boolean | ISO 3166-1 sovereignty status | | `independent` | Boolean | ISO 3166-1 sovereignty status |
| `status` | String | ISO 3166-1 assignment status | | `status` | String | ISO 3166-1 assignment status |
| `unMember` | Boolean | UN member state | | `unMember` | Boolean | UN member state |
| `sovereignState` | String | ★ cca3 of the governing sovereign state, or `""` |
| `currencies` | List\<Object\> | Official currencies | | `currencies` | List\<Object\> | Official currencies |
| `idd` | Object | International direct dialling info | | `idd` | Object | International direct dialling info |
| `callingCodes` | List\<String\> | ★ Full international calling codes | | `callingCodes` | List\<String\> | ★ Full international calling codes |
@@ -194,6 +195,19 @@ Complete reference for all fields returned by the v4 API (`/v4`). The v4 API res
--- ---
#### `sovereignState` ★ New in v4
**Type:** String
**Description:** The `cca3` code of the sovereign state that governs this territory. Empty string (`""`) for independent countries. Populated only for non-independent territories (where `independent` is `false`).
```json
"sovereignState": "NLD"
```
> **Examples:** Aruba → `"NLD"`, Gibraltar → `"GBR"`, Puerto Rico → `"USA"`, Hong Kong → `"CHN"`, Greenland → `"DNK"`.
---
### Geography ### Geography
--- ---
@@ -857,6 +871,7 @@ The following fields are **not present in v3.1** and were introduced in v4:
| `hdi` | Human Development Index score | | `hdi` | Human Development Index score |
| `nationalHoliday` | National/independence day date | | `nationalHoliday` | National/independence day date |
| `anthem` | Name of the national anthem | | `anthem` | Name of the national anthem |
| `sovereignState` | cca3 of the governing sovereign state (`""` for independent) |
### Shape changes from v3.1 ### Shape changes from v3.1
@@ -98,10 +98,9 @@ public class ControllerV4Helper {
"landlocked", "landlocked",
"borders", "borders",
"area", "area",
"flags", "flag",
"demonyms", "demonyms",
"population", "population",
"flag",
"maps", "maps",
"gini", "gini",
"fifa", "fifa",
@@ -123,6 +122,8 @@ public class ControllerV4Helper {
"nationalHoliday", "nationalHoliday",
"anthem", "anthem",
"regionalBlocs", "regionalBlocs",
"callingCodes" "callingCodes",
"hdi",
"sovereignState"
}; };
} }
@@ -187,6 +187,24 @@ public class CountryControllerV4 extends ControllerV4Helper {
} }
} }
@Get("sovereignstate/{cca3}")
@Schema(name = "RestCountries")
public Object getBySovereignState(@PathVariable("cca3") String cca3,
@QueryParam("fields") Optional<String> fields) {
if (isEmpty(cca3) || cca3.length() != 3) {
return ControllerHelper.badRequest();
}
try {
var countries = CountryServiceV4.getInstance().getBySovereignState(cca3);
if (!countries.isEmpty()) {
return ControllerHelper.ok(checkFieldsAndParseCountries(fields, countries));
}
return ControllerHelper.notFound();
} catch (Exception e) {
return HttpResponse.serverError(Response.Status.INTERNAL_SERVER_ERROR);
}
}
@Get("independent") @Get("independent")
@Schema(name = "RestCountries") @Schema(name = "RestCountries")
public Object getIndependentCountries(@QueryParam("status") Optional<Boolean> status, public Object getIndependentCountries(@QueryParam("status") Optional<Boolean> status,
@@ -8,6 +8,7 @@ import java.util.Map;
@Serdeable.Serializable @Serdeable.Serializable
public class BaseCountry extends BaseCountryCore { public class BaseCountry extends BaseCountryCore {
private String flag;
private Name name; private Name name;
private Map<String, Currency> currencies; private Map<String, Currency> currencies;
private Map<String, String> languages; private Map<String, String> languages;
@@ -16,6 +17,14 @@ public class BaseCountry extends BaseCountryCore {
private Map<String, Map<String, String>> demonyms; private Map<String, Map<String, String>> demonyms;
private Map<String, Double> gini; private Map<String, Double> gini;
public String getFlag() {
return flag;
}
public void setFlag(String flag) {
this.flag = flag;
}
public Name getName() { public Name getName() {
return name; return name;
} }
@@ -25,7 +25,6 @@ public abstract class BaseCountryCore {
private List<String> borders; private List<String> borders;
private Double area; private Double area;
private List<String> callingCodes; private List<String> callingCodes;
private String flag;
private Map<String, String> maps; private Map<String, String> maps;
private Integer population; private Integer population;
private String fifa; private String fifa;
@@ -169,14 +168,6 @@ public abstract class BaseCountryCore {
this.callingCodes = callingCodes; this.callingCodes = callingCodes;
} }
public String getFlag() {
return flag;
}
public void setFlag(String flag) {
this.flag = flag;
}
public Map<String, String> getMaps() { public Map<String, String> getMaps() {
return maps; return maps;
} }
@@ -7,6 +7,7 @@ public class Flag {
private String png; private String png;
private String svg; private String svg;
private String alt; private String alt;
private String emoji;
public String getPng() { public String getPng() {
return png; return png;
@@ -31,4 +32,12 @@ public class Flag {
public void setAlt(String alt) { public void setAlt(String alt) {
this.alt = alt; this.alt = alt;
} }
public String getEmoji() {
return emoji;
}
public void setEmoji(String emoji) {
this.emoji = emoji;
}
} }
@@ -17,7 +17,7 @@ public class Country extends BaseCountryCore {
private List<Translation> translations; private List<Translation> translations;
private List<Demonym> demonyms; private List<Demonym> demonyms;
private List<Gini> gini; private List<Gini> gini;
private Flag flags; private Flag flag;
private Flag coatOfArms; private Flag coatOfArms;
private String startOfWeek; private String startOfWeek;
private CapitalInformation capitalInfo; private CapitalInformation capitalInfo;
@@ -32,6 +32,7 @@ public class Country extends BaseCountryCore {
private String anthem; private String anthem;
private List<RegionalBloc> regionalBlocs; private List<RegionalBloc> regionalBlocs;
private Double hdi; private Double hdi;
private String sovereignState;
public Name getName() { public Name getName() {
return name; return name;
@@ -81,12 +82,12 @@ public class Country extends BaseCountryCore {
this.gini = gini; this.gini = gini;
} }
public Flag getFlags() { public Flag getFlag() {
return flags; return flag;
} }
public void setFlags(Flag flags) { public void setFlag(Flag flag) {
this.flags = flags; this.flag = flag;
} }
public Flag getCoatOfArms() { public Flag getCoatOfArms() {
@@ -200,4 +201,12 @@ public class Country extends BaseCountryCore {
public void setHdi(Double hdi) { public void setHdi(Double hdi) {
this.hdi = hdi; this.hdi = hdi;
} }
public String getSovereignState() {
return sovereignState;
}
public void setSovereignState(String sovereignState) {
this.sovereignState = sovereignState;
}
} }
@@ -174,6 +174,16 @@ public class CountryServiceBaseV4 {
return result; return result;
} }
protected Set<Country> getBySovereignState(String cca3, Set<Country> countries) {
Set<Country> result = new HashSet<>();
for (var country : countries) {
if (cca3.equalsIgnoreCase(country.getSovereignState())) {
result.add(country);
}
}
return result;
}
protected String normalize(String string) { protected String normalize(String string) {
return Normalizer.normalize(string, Normalizer.Form.NFD) return Normalizer.normalize(string, Normalizer.Form.NFD)
.replaceAll("\\p{InCombiningDiacriticalMarks}+", ""); .replaceAll("\\p{InCombiningDiacriticalMarks}+", "");
@@ -5,7 +5,6 @@ import com.restcountries.domain.v4.Country;
import java.text.Normalizer; import java.text.Normalizer;
import java.util.HashSet; import java.util.HashSet;
import java.util.Set; import java.util.Set;
import java.util.stream.Collectors;
public class CountryServiceV4 extends CountryServiceBaseV4 { public class CountryServiceV4 extends CountryServiceBaseV4 {
@@ -67,11 +66,18 @@ public class CountryServiceV4 extends CountryServiceBaseV4 {
return super.getByTranslation(translation, countries); return super.getByTranslation(translation, countries);
} }
public Set<Country> getBySovereignState(String cca3) {
return super.getBySovereignState(cca3, countries);
}
public Set<Country> getIndependent(boolean status) { public Set<Country> getIndependent(boolean status) {
return countries.stream().filter(country -> { Set<Country> result = new HashSet<>();
var independent = Boolean.TRUE.equals(country.getIndependent()); for (var country : countries) {
return independent == status; if (Boolean.TRUE.equals(country.getIndependent()) == status) {
}).collect(Collectors.toSet()); result.add(country);
}
}
return result;
} }
@Override @Override
File diff suppressed because it is too large Load Diff
+1 -1
View File
@@ -547,7 +547,7 @@
</p> </p>
<div class="info-box"> <div class="info-box">
Requests are growing fast &mdash; about 4 million hits <strong>each day</strong> and 120 GB of bandwidth Requests are growing fast &mdash; morethan 6 million hits <strong>each day</strong> and 120 GB of bandwidth
<strong>per day</strong>. Please consider making a <strong>per day</strong>. Please consider making a
<a href="https://www.patreon.com/amatos">donation</a> to help cover server costs. <a href="https://www.patreon.com/amatos">donation</a> to help cover server costs.
</div> </div>