Compare commits
291 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| a3d76db7d7 | |||
| 1993aa6a65 | |||
| d139284376 | |||
| 5841613ae0 | |||
| 8b2111c8e1 | |||
| 49bf6e26b5 | |||
| cee84c84e5 | |||
| 4d0c0f6d5f | |||
| 883940e36b | |||
| c2c74db463 | |||
| 423251208c | |||
| 32b937341b | |||
| ecd9e6c588 | |||
| 59c9383978 | |||
| 90a8fff6f5 | |||
| db5a085a93 | |||
| 97d02fde04 | |||
| 3ebefc002e | |||
| e51c115631 | |||
| 5277a57f47 | |||
| 1fda9163d5 | |||
| 47e5447de9 | |||
| d815c26ab2 | |||
| 261e7e3a0b | |||
| c5a2e71b66 | |||
| 8f04e59ae1 | |||
| 9b8d08c120 | |||
| c1bf20eff1 | |||
| 227da47d2a | |||
| 46e82a9334 | |||
| fe6275fd91 | |||
| ce78e0e33c | |||
| 3ef0d593f5 | |||
| 793f7c477a | |||
| a1e5339c01 | |||
| e2716064ea | |||
| 65e996dece | |||
| 7dfe4ed534 | |||
| fd6c6834dd | |||
| 3e9f6d6bd6 | |||
| 6ca8666a2d | |||
| 7378efe122 | |||
| 8c264c0a6c | |||
| 5e1ac7624e | |||
| 952b37e00e | |||
| 09f18cb17c | |||
| 47ad02fa78 | |||
| 389e992459 | |||
| a28550fa02 | |||
| 40e21ae949 | |||
| d36e2a8605 | |||
| e94bf89ba3 | |||
| 72b77288cf | |||
| a646d4d5b0 | |||
| 0d86f1ce03 | |||
| 10a3263673 | |||
| 5435650866 | |||
| 8524f480f2 | |||
| 77cb7de959 | |||
| 70224421d0 | |||
| b3ff22a100 | |||
| 767a2be9bd | |||
| 5b2b9f72ac | |||
| 23dbc90165 | |||
| 035f132ade | |||
| 67bf122161 | |||
| 18f2883968 | |||
| 087c783463 | |||
| ccdfe20876 | |||
| 55177a1a13 | |||
| 83a3c1a7d6 | |||
| 817d0018e5 | |||
| 366381015b | |||
| 688a6e9fe5 | |||
| b9170a3ced | |||
| c341b1e5ff | |||
| 1f969a97b1 | |||
| f9dd67cbf6 | |||
| 306352c2c9 | |||
| de69f8b9cc | |||
| 0b1c25de8e | |||
| 1784e5cbf1 | |||
| 71bd3cc230 | |||
| f2e3e31e80 | |||
| 6acdb0aa92 | |||
| e67beb4421 | |||
| 21ddaeff41 | |||
| aac0ff5f91 | |||
| 65b879eeff | |||
| d65710c3f7 | |||
| 6a9678f8be | |||
| 9d3916cb49 | |||
| dbb7caac78 | |||
| 377a98cd49 | |||
| d1154f3a1c | |||
| be04c41c88 | |||
| 9ad00c75e9 | |||
| 8ed5625d94 | |||
| ee498c74ad | |||
| bc15c46c2f | |||
| 38e97f44c1 | |||
| faaed1b971 | |||
| 8ac63ce707 | |||
| da9c798b7f | |||
| 5265ba86c6 | |||
| 8026f6d736 | |||
| ada356dc8c | |||
| 1a0c03c4e3 | |||
| 8464f315ec | |||
| eb6424a0db | |||
| 8342be9bdf | |||
| 6c8773d398 | |||
| 45f99e36f3 | |||
| b51e696283 | |||
| ce0d43a982 | |||
| 1123a6dea8 | |||
| 3afb1f7dcb | |||
| 3deb53df5f | |||
| aab349e06a | |||
| 5de2255fff | |||
| 22341d6efb | |||
| e167961a22 | |||
| c707b2d885 | |||
| eb76b72e52 | |||
| 7b0a4f2a21 | |||
| 74ad597513 | |||
| 59ea26d423 | |||
| e202435cc3 | |||
| 341f0fdb69 | |||
| 5c19f17c13 | |||
| c42fe46ea2 | |||
| 64d7de12e1 | |||
| 78c44ffc60 | |||
| 6071113b4a | |||
| 857efa988d | |||
| ac870ef548 | |||
| 01aed3f4c7 | |||
| adc935a761 | |||
| 2b4dac3e97 | |||
| 1f6b12de22 | |||
| 0ae03045eb | |||
| 4a609d373f | |||
| 718248f4ad | |||
| 4647daf01c | |||
| acaf61f74a | |||
| 043b9ab87d | |||
| 2c30416c8f | |||
| 9cec59e652 | |||
| bc65bb03dc | |||
| d488a8ad64 | |||
| ce9b97bae5 | |||
| ccc5a2ce02 | |||
| 0bf7e53dc2 | |||
| 5dba603e50 | |||
| 7138b2af97 | |||
| c502592192 | |||
| 9cf493cf62 | |||
| 4703f5c8dc | |||
| 3868264a7f | |||
| 4a5da1f40e | |||
| 07af6e3908 | |||
| b5834e3673 | |||
| c47296df7e | |||
| 666492a60f | |||
| a61c7bced2 | |||
| 7a111655df | |||
| 62c2d79b13 | |||
| 68372cb453 | |||
| d9a4b2d88b | |||
| 8a1d3da6e8 | |||
| c6c83086c8 | |||
| 27ff9a21d4 | |||
| 6cf8153de7 | |||
| 5681387d9c | |||
| 1ec9a0c785 | |||
| 26610868b1 | |||
| 2c85d34658 | |||
| 1e2946f126 | |||
| fc50401adc | |||
| a86a7adf8e | |||
| 89e1c43f5c | |||
| 85d658a6ce | |||
| 6fe422e776 | |||
| eaa157834b | |||
| 6e7f6a4355 | |||
| d348f184da | |||
| fc0876c493 | |||
| 591996e4bc | |||
| 6da77ad073 | |||
| 04af529616 | |||
| 44adb68c5b | |||
| a81aa3a8a4 | |||
| cb6e18520b | |||
| 3fd920648b | |||
| 2613a67d2f | |||
| c8efcca409 | |||
| db0e1f0309 | |||
| a4fceb6230 | |||
| 8a02cf44b7 | |||
| 46ed2970fd | |||
| 4d1e8e4200 | |||
| 487aecf949 | |||
| 5bd4378e9e | |||
| 003b3ba66f | |||
| 03e50c52c3 | |||
| 1080ab9849 | |||
| e2c3cb5693 | |||
| 252157a62d | |||
| 2be6e44c03 | |||
| f2a826545a | |||
| 4f3b1cf4e3 | |||
| 1e086a78d3 | |||
| 09c5671cf8 | |||
| 1ad12ae34d | |||
| baf690da1e | |||
| e744431b09 | |||
| 562d402969 | |||
| e985735b2f | |||
| 461db4fa8d | |||
| 762b134ad7 | |||
| ce72e0d301 | |||
| e68900022c | |||
| 037bdf1289 | |||
| a2a6ca4db4 | |||
| b29dc0da47 | |||
| 4fbf6d0293 | |||
| 513ea55f2f | |||
| fa833674bf | |||
| 3c7f7dcb19 | |||
| 34189e20ea | |||
| bbe18589ad | |||
| 40325eff46 | |||
| 5d3bec2afd | |||
| 5642be6868 | |||
| 01785c6e99 | |||
| c4d2fafc58 | |||
| 7da6c6152f | |||
| dc07c2f20e | |||
| be129ab93c | |||
| 1ce6d03d0c | |||
| b23014b4b8 | |||
| 0f40f524d7 | |||
| 4a9ef14cdb | |||
| 04a0db56bc | |||
| c60c5cc753 | |||
| 87e877bb31 | |||
| 1cd8e4b0ca | |||
| eec59a4e46 | |||
| d535ee73d4 | |||
| 4a8e5f1919 | |||
| cbfccb4d6f | |||
| e20ce02a2e | |||
| ed7ed6f7cb | |||
| c651f4e0e0 | |||
| bcebd6ea51 | |||
| ca2398187d | |||
| 0c5d718f20 | |||
| 538572bd45 | |||
| d6a2055d37 | |||
| 4f56e96ccf | |||
| cd933d9f8a | |||
| ca0c518bb7 | |||
| d74f056083 | |||
| 030f3abef2 | |||
| 9edd144399 | |||
| 3f1b14c5a3 | |||
| ee33852eb8 | |||
| ba4b931292 | |||
| db57a83f79 | |||
| b9d1d02332 | |||
| 976d2b2064 | |||
| d5ffe9a8fc | |||
| 2245dc629b | |||
| c73cab182f | |||
| dda9a05942 | |||
| 580dc39e8c | |||
| cb48f225aa | |||
| c91772cc86 | |||
| f5fef436d3 | |||
| cfa1ebb94f | |||
| 19f8c78f19 | |||
| 4592f9eb87 | |||
| 5a5627ee7b | |||
| 5f74df330c | |||
| 0e0a7f9fc3 | |||
| 3395d8ceb8 | |||
| e24fbf2eb4 | |||
| ca36890e8a | |||
| 8f1f5f6e75 | |||
| 64dbf1890c | |||
| 7d3d517faf |
@@ -4,6 +4,7 @@ Thumbs.db
|
||||
build/
|
||||
target/
|
||||
out/
|
||||
.micronaut/
|
||||
.idea
|
||||
*.iml
|
||||
*.ipr
|
||||
@@ -11,3 +12,4 @@ out/
|
||||
.project
|
||||
.settings
|
||||
.classpath
|
||||
.factorypath
|
||||
|
||||
@@ -2,7 +2,7 @@ variables:
|
||||
MAVEN_OPTS: "-Dhttps.protocols=TLSv1.2 -Dmaven.repo.local=$CI_PROJECT_DIR/.m2/repository -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=WARN -Dorg.slf4j.simpleLogger.showDateTime=true -Djava.awt.headless=true"
|
||||
MAVEN_CLI_OPTS: "--batch-mode --errors --fail-at-end --show-version -DinstallAtEnd=true -DdeployAtEnd=true"
|
||||
|
||||
image: adoptopenjdk/openjdk14:alpine-slim
|
||||
image: eclipse-temurin:17.0.10_7-jdk-alpine
|
||||
|
||||
stages:
|
||||
- package
|
||||
@@ -36,7 +36,7 @@ docker-push:
|
||||
- docker info
|
||||
- cp target/*.jar .
|
||||
script:
|
||||
- docker login -u "gitlab-ci-token" -p "$CI_BUILD_TOKEN" $REGISTRY_URL
|
||||
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
|
||||
- docker build -t $IMAGE_TAG .
|
||||
- docker push $IMAGE_TAG
|
||||
|
||||
@@ -48,9 +48,11 @@ docker-run:
|
||||
- apk add openssh-client
|
||||
- mkdir -p ~/.ssh
|
||||
- echo "$PRIVATE_VEY" | tr -d '\r' > ~/.ssh/id_rsa
|
||||
- chmod 700 ~/.ssh/id_rsa
|
||||
- chmod 600 ~/.ssh/id_rsa
|
||||
- eval "$(ssh-agent -s)"
|
||||
- ssh-add ~/.ssh/id_rsa
|
||||
- touch ~/.ssh/known_hosts
|
||||
- ssh-keygen -R $DEPLOYMENT_SERVER_IP || true
|
||||
- ssh-keyscan -H $DEPLOYMENT_SERVER_IP >> ~/.ssh/known_hosts
|
||||
dependencies:
|
||||
- docker-push
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
Please detail the following information when submitting an issue:
|
||||
|
||||
* API version:
|
||||
* Evidence that the data is incorrect:
|
||||
|
||||
Please consider donating
|
||||
* [Paypal](https://www.paypal.me/amatosg/15)
|
||||
* [Patreon](https://www.patreon.com/amatos)
|
||||
@@ -1 +1,18 @@
|
||||
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.5.3/apache-maven-3.5.3-bin.zip
|
||||
# Licensed to the Apache Software Foundation (ASF) under one
|
||||
# or more contributor license agreements. See the NOTICE file
|
||||
# distributed with this work for additional information
|
||||
# regarding copyright ownership. The ASF licenses this file
|
||||
# to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance
|
||||
# with the License. You may obtain a copy of the License at
|
||||
#
|
||||
# https://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing,
|
||||
# software distributed under the License is distributed on an
|
||||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
# KIND, either express or implied. See the License for the
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.9/apache-maven-3.9.9-bin.zip
|
||||
wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.1/maven-wrapper-3.1.1.jar
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
|
||||
# Contributor Covenant Code of Conduct
|
||||
|
||||
## Our Pledge
|
||||
|
||||
In the interest of fostering an open and welcoming environment, we as
|
||||
contributors and maintainers pledge to make participation in our project and
|
||||
our community a harassment-free experience for everyone, regardless of age, body
|
||||
size, disability, ethnicity, sex characteristics, gender identity and expression,
|
||||
level of experience, education, socio-economic status, nationality, personal
|
||||
appearance, race, religion, or sexual identity and orientation.
|
||||
|
||||
## Our Standards
|
||||
|
||||
Examples of behavior that contributes to creating a positive environment
|
||||
include:
|
||||
|
||||
* Using welcoming and inclusive language
|
||||
* Being respectful of differing viewpoints and experiences
|
||||
* Gracefully accepting constructive criticism
|
||||
* Focusing on what is best for the community
|
||||
* Showing empathy towards other community members
|
||||
|
||||
Examples of unacceptable behavior by participants include:
|
||||
|
||||
* The use of sexualized language or imagery and unwelcome sexual attention or
|
||||
advances
|
||||
* Trolling, insulting/derogatory comments, and personal or political attacks
|
||||
* Public or private harassment
|
||||
* Publishing others' private information, such as a physical or electronic
|
||||
address, without explicit permission
|
||||
* Other conduct which could reasonably be considered inappropriate in a
|
||||
professional setting
|
||||
|
||||
## Our Responsibilities
|
||||
|
||||
Project maintainers are responsible for clarifying the standards of acceptable
|
||||
behavior and are expected to take appropriate and fair corrective action in
|
||||
response to any instances of unacceptable behavior.
|
||||
|
||||
Project maintainers have the right and responsibility to remove, edit, or
|
||||
reject comments, commits, code, wiki edits, issues, and other contributions
|
||||
that are not aligned to this Code of Conduct, or to ban temporarily or
|
||||
permanently any contributor for other behaviors that they deem inappropriate,
|
||||
threatening, offensive, or harmful.
|
||||
|
||||
## Scope
|
||||
|
||||
This Code of Conduct applies within all project spaces, and it also applies when
|
||||
an individual is representing the project or its community in public spaces.
|
||||
Examples of representing a project or community include using an official
|
||||
project e-mail address, posting via an official social media account, or acting
|
||||
as an appointed representative at an online or offline event. Representation of
|
||||
a project may be further defined and clarified by project maintainers.
|
||||
|
||||
## Enforcement
|
||||
|
||||
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
||||
reported by contacting the project team at amatos@gmail.com. All
|
||||
complaints will be reviewed and investigated and will result in a response that
|
||||
is deemed necessary and appropriate to the circumstances. The project team is
|
||||
obligated to maintain confidentiality with regard to the reporter of an incident.
|
||||
Further details of specific enforcement policies may be posted separately.
|
||||
|
||||
Project maintainers who do not follow or enforce the Code of Conduct in good
|
||||
faith may face temporary or permanent repercussions as determined by other
|
||||
members of the project's leadership.
|
||||
|
||||
## Attribution
|
||||
|
||||
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
||||
available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html
|
||||
|
||||
[homepage]: https://www.contributor-covenant.org
|
||||
|
||||
For answers to common questions about this code of conduct, see
|
||||
https://www.contributor-covenant.org/faq
|
||||
@@ -1,4 +1,9 @@
|
||||
FROM openjdk:14-alpine
|
||||
COPY target/dev.amatos.restcountries-*.jar dev.amatos.restcountries.jar
|
||||
FROM maven:3-openjdk-17-slim as build
|
||||
WORKDIR /
|
||||
COPY . .
|
||||
RUN mvn --batch-mode package
|
||||
|
||||
FROM openjdk:17-ea-slim
|
||||
COPY --from=build target/restcountries-*.jar restcountries.jar
|
||||
EXPOSE 8080
|
||||
CMD ["java", "-Dcom.sun.management.jmxremote", "-Xmx128m", "-jar", "dev.amatos.restcountries.jar"]
|
||||
CMD ["java", "-Dcom.sun.management.jmxremote", "-Xmx128m", "-jar", "restcountries.jar"]
|
||||
@@ -0,0 +1,47 @@
|
||||
# API data fields
|
||||
|
||||
In this table you can find the fields of the different API versions, extra information and sources.
|
||||
|
||||
| field | v2 | v3 | v3.1 | Info |
|
||||
|------------------------|----|----|------|-------------------------------------------------------------------------------------------------|
|
||||
| alpha2Code / cca2 | v | v | v | ISO 3166-1 alpha-2 two-letter country codes |
|
||||
| alpha3Code / cca3 | v | v | v | ISO 3166-1 alpha-3 three-letter country codes |
|
||||
| altSpellings | v | v | v | Alternate spellings of the country name |
|
||||
| area | v | v | v | Geographical size |
|
||||
| borders | v | v | v | Border countries |
|
||||
| callingCodes / idd | v | v | v | International dialing codes |
|
||||
| capital | v | v | v | Capital cities |
|
||||
| capitalInfo > latlng | | | | Capital latitude and longitude |
|
||||
| car > signs | | | v | Car distinguised (oval) signs |
|
||||
| car > side | | | v | Car driving side |
|
||||
| cioc | v | v | v | Code of the International Olympic Committee |
|
||||
| coatOfArms | | | v | [MainFacts.com](https://mainfacts.com/coat-of-arms-countries-world) links to svg and png images |
|
||||
| continents | | | v | List of continents the country is on |
|
||||
| currencies | v | v | v | List of all currencies |
|
||||
| demonym | v | | | Inhabitants of the country |
|
||||
| demonyms (m/f) | | v | v | Genderized inhabitants of the country |
|
||||
| independent | v | v | v | ISO 3166-1 independence status (the country is considered a sovereign state) |
|
||||
| fifa | | | v | FIFA code |
|
||||
| flag | v | v | v | v2: Link to the svg flag on [Flagpedia](https://flagpedia.net/), v3: flag emoji |
|
||||
| flags | v | v | v | [Flagpedia](https://flagpedia.net/) links to svg and png flags |
|
||||
| gini | v | v | v | Worldbank [Gini](https://data.worldbank.org/indicator/SI.POV.GINI) index |
|
||||
| landlocked | | v | v | Landlocked country |
|
||||
| languages | v | v | v | List of official languages |
|
||||
| latlng | v | v | v | Latitude and longitude |
|
||||
| maps | v | v | v | Link to Google maps and Open Street maps |
|
||||
| name | v | v | v | Country name |
|
||||
| name > official/common | | v | v | Official and common country name |
|
||||
| nativeName | v | v | | Native country name |
|
||||
| nativeName > official/common | | v | v | Official and common native country name |
|
||||
| numericCode / ccn3 | v | | | ISO 3166-1 numeric code (UN M49) |
|
||||
| population | v | v | v | Country population |
|
||||
| postalCodes > format/regex | | | | Country postal codes |
|
||||
| region | v | v | v | UN [demographic regions](https://unstats.un.org/unsd/methodology/m49/) |
|
||||
| regionalBlocs | v | | | |
|
||||
| startOfWeek | | | | Day of the start of week (Sunday/Monday/Saturday) |
|
||||
| status | | v | v | ISO 3166-1 assignment status |
|
||||
| subregion | v | v | v | UN [demographic subregions](https://unstats.un.org/unsd/methodology/m49/) |
|
||||
| timezones | v | | | Timezones |
|
||||
| topLevelDomain / tld | v | v | v | Internet top level domains |
|
||||
| translations | v | v | v | List of country name translations |
|
||||
| unMember | | v | v | UN Member status |
|
||||
@@ -1,398 +1,213 @@
|
||||
# About this Project
|
||||
This project is inspired on restcountries.eu by Fayder Florez. As it hasn't had any activity in at least 14 months, I decided to take action :)
|
||||
This project is inspired on restcountries.eu by Fayder Florez. Although the original project has now moved to
|
||||
a subscription base API, this project is still Open Source and Free to use.
|
||||
|
||||
## Important Information About Version 2
|
||||
The structure has been reverted to its original form from the [Original Project] to maintain compatibility.
|
||||
## Important Information
|
||||
* The structure of V2 has been reverted to its original form from the [Original Project] to maintain compatibility.
|
||||
* ***Only the latest version will receive updates and improvements.***
|
||||
|
||||
# REST Countries
|
||||
You can access API through https://restcountries.com/v3/all
|
||||
You can access API through https://restcountries.com/v3.1/all
|
||||
|
||||
# TODO:
|
||||
Please reffer to the [issue website](https://gitlab.com/amatos/rest-countries/-/issues)
|
||||
|
||||
# Contributing
|
||||
Any help is welcome! Just edit the file relevant file and create a new Merge Request or you can also
|
||||
[donate](https://www.paypal.me/amatosg/15).
|
||||
Any help is always welcome! Just edit the relevant file and create a new Merge Request or you can also
|
||||
donate using [Patreon](https://www.patreon.com/amatos) or [PayPal](https://www.paypal.me/amatosg/15).
|
||||
|
||||
# Donations
|
||||
Donation will help me paying the server's bills and any upgrade the server might need due to usage so if
|
||||
you feel like helping me, you're welcome to [donate](https://www.paypal.me/amatosg/15) or you can also
|
||||
[buy me a coffee](https://www.buymeacoffee.com/amatos).
|
||||
This are getting out of control. As I stated [here](https://gitlab.com/restcountries/restcountries/-/issues/187), the server is not going to hold much longer. I'm getting about 4 million hits **each day** and that means CPU ussage (99%) and also bandwidth consumption (120 GB **per day!**) so costs have obviously increased. **Please**, consider making a donation on [Patreon](https://www.patreon.com/amatos) or [PayPal](https://www.paypal.me/amatosg/15). This will help me pay the server's bills
|
||||
|
||||
|
||||
# Changelog
|
||||
### V3
|
||||
- Added population
|
||||
### V3.1
|
||||
- Added population
|
||||
- Added named object for `flags`
|
||||
# Fields
|
||||
You can check the [FIELDS.md](FIELDS.md) file to get a description for each field (thanks to @ePascalC!).
|
||||
|
||||
# API Endpoints
|
||||
|
||||
Currently there are 3 versions:
|
||||
- Version 2 is the original version from restcountries.eu by Fayder Florez
|
||||
- Version 3 is the implementation from [this project](https://github.com/mledoze/countries)
|
||||
- Version 3.1 adds named values to the `flags` object like this:
|
||||
## Using this Project
|
||||
|
||||
```json
|
||||
"flags": {
|
||||
"svg": "https://restcountries.com/data/per.svg",
|
||||
"png": "https://restcountries.com/data/png/per.png"
|
||||
}
|
||||
```
|
||||
- [Famosos](https://famosos.com)
|
||||
- [Cultural Care](https://www.culturalcare.world/)
|
||||
- [Covidata](https://worldcovidata.com/)
|
||||
- [Asendia](https://tracking.asendia.com)
|
||||
- [Picker](https://mwb.pickerexpress.com/#/login)
|
||||
|
||||
# Endpoints
|
||||
Below are described the REST endpoints available that you can use to search for countries
|
||||
|
||||
## All
|
||||
## Latest added Endpoint
|
||||
|
||||
### V2
|
||||
### Independent
|
||||
Now you can get all independent (or not independent) countries by calling this endpoint:
|
||||
``` html
|
||||
https://restcountries.com/v2/all
|
||||
https://restcountries.com/v3.1/independent?status=true
|
||||
```
|
||||
If you don't specify the status, true will be taken as default. You can mix it with the `fields` filter like this:
|
||||
|
||||
``` html
|
||||
https://restcountries.com/v3.1/independent?status=true&fields=languages,capital
|
||||
```
|
||||
|
||||
### V3
|
||||
## All
|
||||
You **must** specify the fields you need (up to 10 fields) when calling the `all` endpoints,
|
||||
otherwise you'll get a `bad request` response. Please see [this issue](https://gitlab.com/restcountries/restcountries/-/issues/265)
|
||||
for more information. This applies to all versions.
|
||||
``` html
|
||||
https://restcountries.com/v3/all
|
||||
https://restcountries.com/v3.1/all
|
||||
```
|
||||
|
||||
|
||||
## Name
|
||||
|
||||
### V2
|
||||
Search by country name. It can be the native name or partial name
|
||||
|
||||
``` javascript
|
||||
https://restcountries.com/v2/name/{name}
|
||||
**Search** by country name. If you want to get an exact match, use the next endpoint. It can be the common or official value
|
||||
``` html
|
||||
https://restcountries.com/v3.1/name/{name}
|
||||
```
|
||||
|
||||
``` html
|
||||
https://restcountries.com/v2/name/eesti
|
||||
https://restcountries.com/v3.1/name/eesti
|
||||
```
|
||||
|
||||
``` html
|
||||
https://restcountries.com/v2/name/united
|
||||
```
|
||||
|
||||
### V3
|
||||
Search by country name. It can be the common or official value
|
||||
``` html
|
||||
https://restcountries.com/v3/name/{name}
|
||||
```
|
||||
|
||||
``` html
|
||||
https://restcountries.com/v3/name/eesti
|
||||
```
|
||||
|
||||
``` html
|
||||
https://restcountries.com/v3/name/deutschland
|
||||
https://restcountries.com/v3.1/name/deutschland
|
||||
```
|
||||
|
||||
## Full Name
|
||||
### V2
|
||||
Search by country's full name
|
||||
|
||||
``` html
|
||||
https://restcountries.com/v2/name/{name}?fullText=true
|
||||
```
|
||||
|
||||
``` html
|
||||
https://restcountries.com/v2/name/aruba?fullText=true
|
||||
```
|
||||
|
||||
### V3
|
||||
Search by country's full name. It can be the common or official value
|
||||
``` html
|
||||
https://restcountries.com/v3/name/{name}?fullText=true
|
||||
https://restcountries.com/v3.1/name/{name}?fullText=true
|
||||
```
|
||||
|
||||
``` html
|
||||
https://restcountries.com/v3/name/aruba?fullText=true
|
||||
https://restcountries.com/v3.1/name/aruba?fullText=true
|
||||
```
|
||||
## Code
|
||||
### V2
|
||||
Search by ISO 3166-1 2-letter or 3-letter country code
|
||||
|
||||
``` html
|
||||
https://restcountries.com/v2/alpha/{code}
|
||||
```
|
||||
|
||||
``` html
|
||||
https://restcountries.com/v2/alpha/co
|
||||
```
|
||||
|
||||
``` html
|
||||
https://restcountries.com/v2/alpha/col
|
||||
```
|
||||
### V3
|
||||
Search by cca2, ccn3, cca3 or cioc country code (yes, any!)
|
||||
|
||||
``` html
|
||||
https://restcountries.com/v3/alpha/{code}
|
||||
https://restcountries.com/v3.1/alpha/{code}
|
||||
```
|
||||
|
||||
``` html
|
||||
https://restcountries.com/v3/alpha/co
|
||||
https://restcountries.com/v3.1/alpha/co
|
||||
```
|
||||
|
||||
``` html
|
||||
https://restcountries.com/v3/alpha/col
|
||||
https://restcountries.com/v3.1/alpha/col
|
||||
```
|
||||
|
||||
``` html
|
||||
https://restcountries.com/v3/alpha/170
|
||||
https://restcountries.com/v3.1/alpha/170
|
||||
```
|
||||
## List of codes
|
||||
### V2
|
||||
Search by list of ISO 3166-1 2-letter or 3-letter country codes
|
||||
|
||||
``` html
|
||||
https://restcountries.com/v2/alpha?codes={code},{code},{code}
|
||||
```
|
||||
|
||||
``` html
|
||||
https://restcountries.com/v2/alpha?codes=col,no,ee,pe
|
||||
```
|
||||
### V3
|
||||
Search by cca2, ccn3, cca3 or cioc country code (yes, any!)
|
||||
``` html
|
||||
https://restcountries.com/v3/alpha?codes={code},{code},{code}
|
||||
https://restcountries.com/v3.1/alpha?codes={code},{code},{code}
|
||||
```
|
||||
|
||||
``` html
|
||||
https://restcountries.com/v3/alpha?codes=170,no,est,pe
|
||||
https://restcountries.com/v3.1/alpha?codes=170,no,est,pe
|
||||
```
|
||||
## Currency
|
||||
### V2
|
||||
Search by ISO 4217 currency code
|
||||
|
||||
``` html
|
||||
https://restcountries.com/v2/currency/{currency}
|
||||
```
|
||||
``` html
|
||||
https://restcountries.com/v2/currency/cop
|
||||
```
|
||||
### V3
|
||||
Search by currency code or name
|
||||
``` html
|
||||
https://restcountries.com/v3/currency/{currency}
|
||||
https://restcountries.com/v3.1/currency/{currency}
|
||||
```
|
||||
``` html
|
||||
https://restcountries.com/v3/currency/cop
|
||||
https://restcountries.com/v3.1/currency/cop
|
||||
```
|
||||
|
||||
### Demonym
|
||||
### V3
|
||||
## Demonym
|
||||
Now you can search by how a citizen is called.
|
||||
``` html
|
||||
https://restcountries.com/v3/demonym/{demonym}
|
||||
https://restcountries.com/v3.1/demonym/{demonym}
|
||||
```
|
||||
``` html
|
||||
https://restcountries.com/v3/demonym/peruvian
|
||||
https://restcountries.com/v3.1/demonym/peruvian
|
||||
```
|
||||
|
||||
## Language
|
||||
### V2
|
||||
Search by ISO 639-1 language code
|
||||
|
||||
``` javascript
|
||||
https://restcountries.com/v2/lang/{et}
|
||||
```
|
||||
``` html
|
||||
https://restcountries.com/v2/lang/es
|
||||
```
|
||||
|
||||
### V3
|
||||
Search by language code or name
|
||||
``` html
|
||||
https://restcountries.com/v3/lang/{currency}
|
||||
https://restcountries.com/v3.1/lang/{currency}
|
||||
```
|
||||
``` html
|
||||
https://restcountries.com/v3/lang/cop
|
||||
https://restcountries.com/v3.1/lang/cop
|
||||
```
|
||||
``` html
|
||||
https://restcountries.com/v3/lang/spanish
|
||||
https://restcountries.com/v3.1/lang/spanish
|
||||
```
|
||||
|
||||
## Capital city
|
||||
|
||||
_This is the same in both versions_
|
||||
|
||||
Search by capital city
|
||||
|
||||
``` javascript
|
||||
https://restcountries.com/v2/capital/{capital}
|
||||
``` html
|
||||
https://restcountries.com/v3.1/capital/{capital}
|
||||
```
|
||||
``` html
|
||||
https://restcountries.com/v2/capital/tallinn
|
||||
```
|
||||
|
||||
``` javascript
|
||||
https://restcountries.com/v3/capital/{capital}
|
||||
```
|
||||
``` html
|
||||
https://restcountries.com/v3/capital/tallinn
|
||||
https://restcountries.com/v3.1/capital/tallinn
|
||||
```
|
||||
|
||||
## Calling code
|
||||
### V2
|
||||
Search by calling code
|
||||
|
||||
``` html
|
||||
https://restcountries.com/v2/callingcode/{callingcode}
|
||||
```
|
||||
``` html
|
||||
https://restcountries.com/v2/callingcode/372
|
||||
```
|
||||
### V3
|
||||
In version 3, calling codes are in the _idd_ object. There is no implementation
|
||||
to search by calling codes in V3.
|
||||
|
||||
## Region
|
||||
### V2
|
||||
In version 2 regions are _continent_ and subregions are _region_
|
||||
Search by continent: Africa, Americas, Asia, Europe, Oceania
|
||||
Search by region (replace X with the version you want to use)
|
||||
|
||||
``` html
|
||||
https://restcountries.com/v2/continent/{continent}
|
||||
https://restcountries.com/v3.1/region/{region}
|
||||
```
|
||||
``` html
|
||||
https://restcountries.com/v2/continent/europe
|
||||
```
|
||||
### V3
|
||||
In version 3, continents are _Regions_ and regions are _Subregions_
|
||||
|
||||
``` html
|
||||
https://restcountries.com/v2/region/{region}
|
||||
```
|
||||
``` html
|
||||
https://restcountries.com/v2/region/europe
|
||||
https://restcountries.com/v3.1/region/europe
|
||||
```
|
||||
## Subregions
|
||||
###V3
|
||||
You can search by subregions
|
||||
You can search by subregions (replace X with the version you want to use)
|
||||
``` html
|
||||
https://restcountries.com/v2/subregion/{subregion}
|
||||
https://restcountries.com/v3.1/subregion/{subregion}
|
||||
```
|
||||
``` html
|
||||
https://restcountries.com/v2/subregion/Northern Europe
|
||||
```
|
||||
|
||||
## Regional Bloc (*Version 2 only*)
|
||||
|
||||
|
||||
|
||||
Search by regional bloc:
|
||||
|
||||
- EU (European Union)
|
||||
- EFTA (European Free Trade Association)
|
||||
- CARICOM (Caribbean Community)
|
||||
- PA (Pacific Alliance)
|
||||
- AU (African Union)
|
||||
- USAN (Union of South American Nations)
|
||||
- EEU (Eurasian Economic Union)
|
||||
- AL (Arab League)
|
||||
- ASEAN (Association of Southeast Asian Nations)
|
||||
- CAIS (Central American Integration System)
|
||||
- CEFTA (Central European Free Trade Agreement)
|
||||
- NAFTA (North American Free Trade Agreement)
|
||||
- SAARC (South Asian Association for Regional Cooperation)
|
||||
|
||||
``` html
|
||||
https://restcountries.com/v2/regionalbloc/{regionalbloc}
|
||||
```
|
||||
``` html
|
||||
https://restcountries.com/v2/regionalbloc/eu
|
||||
https://restcountries.com/v3.1/subregion/Northern Europe
|
||||
```
|
||||
|
||||
## Translation
|
||||
You can search by any translation name
|
||||
``` html
|
||||
https://restcountries.com/v3/translation/{translation}
|
||||
https://restcountries.com/v3.1/translation/{translation}
|
||||
```
|
||||
``` html
|
||||
https://restcountries.com/v3/translation/germany
|
||||
https://restcountries.com/v3.1/translation/germany
|
||||
```
|
||||
``` html
|
||||
https://restcountries.com/v3/translation/alemania
|
||||
https://restcountries.com/v3.1/translation/alemania
|
||||
```
|
||||
``` html
|
||||
https://restcountries.com/v3/translation/Saksamaa
|
||||
```
|
||||
|
||||
## Response Example
|
||||
|
||||
``` html
|
||||
https://restcountries.com/v2/alpha/col
|
||||
```
|
||||
|
||||
``` json
|
||||
[[{
|
||||
"name": "Colombia",
|
||||
"topLevelDomain": [".co"],
|
||||
"alpha2Code": "CO",
|
||||
"alpha3Code": "COL",
|
||||
"callingCodes": ["57"],
|
||||
"capital": "Bogotá",
|
||||
"altSpellings": ["CO", "Republic of Colombia", "República de Colombia"],
|
||||
"region": "Americas",
|
||||
"subregion": "South America",
|
||||
"population": 48759958,
|
||||
"latlng": [4.0, -72.0],
|
||||
"demonym": "Colombian",
|
||||
"area": 1141748.0,
|
||||
"gini": 55.9,
|
||||
"timezones": ["UTC-05:00"],
|
||||
"borders": ["BRA", "ECU", "PAN", "PER", "VEN"],
|
||||
"nativeName": "Colombia",
|
||||
"numericCode": "170",
|
||||
"currencies": [{
|
||||
"code": "COP",
|
||||
"name": "Colombian peso",
|
||||
"symbol": "$"
|
||||
}],
|
||||
"languages": [{
|
||||
"iso639_1": "es",
|
||||
"iso639_2": "spa",
|
||||
"name": "Spanish",
|
||||
"nativeName": "Español"
|
||||
}],
|
||||
"translations": {
|
||||
"de": "Kolumbien",
|
||||
"es": "Colombia",
|
||||
"fr": "Colombie",
|
||||
"ja": "コロンビア",
|
||||
"it": "Colombia",
|
||||
"br": "Colômbia",
|
||||
"pt": "Colômbia"
|
||||
},
|
||||
"flag": "https://restcountries.com/data/col.svg",
|
||||
"regionalBlocs": [{
|
||||
"acronym": "PA",
|
||||
"name": "Pacific Alliance",
|
||||
"otherAcronyms": [],
|
||||
"otherNames": ["Alianza del Pacífico"]
|
||||
}, {
|
||||
"acronym": "USAN",
|
||||
"name": "Union of South American Nations",
|
||||
"otherAcronyms": ["UNASUR", "UNASUL", "UZAN"],
|
||||
"otherNames": ["Unión de Naciones Suramericanas", "União de Nações Sul-Americanas", "Unie van Zuid-Amerikaanse Naties", "South American Union"]
|
||||
}]
|
||||
}]
|
||||
https://restcountries.com/v3.1/translation/Saksamaa
|
||||
```
|
||||
|
||||
## Filter Response
|
||||
|
||||
You can filter the output of your request to include only the specified fields.
|
||||
|
||||
``` javascript
|
||||
https://restcountries.com/v2/{service}?fields={field},{field},{field}
|
||||
``` html
|
||||
https://restcountries.com/v3.1/{service}?fields={field},{field},{field}
|
||||
```
|
||||
``` html
|
||||
https://restcountries.com/v2/all?fields=name,capital,currencies
|
||||
https://restcountries.com/v3.1/all?fields=name,capital,currencies
|
||||
```
|
||||
## Using this Project
|
||||
## REST Countries Typed API Package
|
||||
Yusif Aliyev from Azerbaijan created [an npm package](https://www.npmjs.com/package/@yusifaliyevpro/countries)
|
||||
which provides TypeScript support for the REST Countries API. Everyone can use
|
||||
the package for their own purpose.
|
||||
This package offers full type and autocomplete support for anyone using
|
||||
JavaScript or TypeScript. Users no longer need to spend time reading
|
||||
documentation or manually writing API URLs and types. You can easily use
|
||||
all the package's functionalities by calling its functions.
|
||||
He is also open to contributing further improvements.
|
||||
|
||||
- [Nations24](https://nations24.com)
|
||||
You can find the code [here](https://github.com/yusifaliyevpro/countries)
|
||||
|
||||
## Similar projects
|
||||
* [REST Countries] (original project)
|
||||
@@ -401,6 +216,7 @@ https://restcountries.com/v2/all?fields=name,capital,currencies
|
||||
* [REST Countries Ruby]
|
||||
* [REST Countries Go]
|
||||
* [REST Countries Python]
|
||||
* [REST Countries Java]
|
||||
* [world-currencies]
|
||||
|
||||
[world-currencies]: https://github.com/wiredmax/world-currencies
|
||||
@@ -408,6 +224,10 @@ https://restcountries.com/v2/all?fields=name,capital,currencies
|
||||
[REST Countries Ruby]: https://github.com/davidesantangelo/restcountry
|
||||
[REST Countries Go]: https://github.com/alediaferia/gocountries
|
||||
[REST Countries Python]: https://github.com/SteinRobert/python-restcountries
|
||||
[REST Countries PHP]: https://github.com/hamedhaghi/countries-client
|
||||
[Countries of the world]: http://countries.petethompson.net
|
||||
[REST Countries]: https://github.com/apilayer/restcountries
|
||||
[Original Project]: https://github.com/apilayer/restcountries/
|
||||
[donation]: https://www.paypal.me/amatosg/15
|
||||
[donate]: https://www.paypal.me/amatosg/15
|
||||
[REST Countries Java]: https://github.com/awais2075/restcountries
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
# AOT configuration properties for jar packaging
|
||||
# Please review carefully the optimizations enabled below
|
||||
# Check https://micronaut-projects.github.io/micronaut-aot/latest/guide/ for more details
|
||||
|
||||
# Caches environment property values: environment properties will be deemed immutable after application startup.
|
||||
cached.environment.enabled=true
|
||||
|
||||
# Precomputes Micronaut configuration property keys from the current environment variables
|
||||
precompute.environment.properties.enabled=true
|
||||
|
||||
# Replaces logback.xml with a pure Java configuration
|
||||
logback.xml.to.java.enabled=true
|
||||
|
||||
# Converts YAML configuration files to Java configuration
|
||||
yaml.to.java.config.enabled=true
|
||||
|
||||
# Scans for service types ahead-of-time, avoiding classpath scanning at startup
|
||||
serviceloading.jit.enabled=true
|
||||
|
||||
# Scans reactive types at build time instead of runtime
|
||||
scan.reactive.types.enabled=true
|
||||
|
||||
# Deduces the environment at build time instead of runtime
|
||||
deduce.environment.enabled=true
|
||||
|
||||
# Checks for the existence of some types at build time instead of runtime
|
||||
known.missing.types.enabled=true
|
||||
|
||||
# Precomputes property sources at build time
|
||||
sealed.property.source.enabled=true
|
||||
|
||||
# The list of service types to be scanned (comma separated)
|
||||
service.types=io.micronaut.context.env.PropertySourceLoader,io.micronaut.inject.BeanConfiguration,io.micronaut.inject.BeanDefinitionReference,io.micronaut.http.HttpRequestFactory,io.micronaut.http.HttpResponseFactory,io.micronaut.core.beans.BeanIntrospectionReference,io.micronaut.core.convert.TypeConverterRegistrar,io.micronaut.context.env.PropertyExpressionResolver
|
||||
|
||||
# A list of types that the AOT analyzer needs to check for existence (comma separated)
|
||||
known.missing.types.list=io.reactivex.Observable,reactor.core.publisher.Flux,kotlinx.coroutines.flow.Flow,io.reactivex.rxjava3.core.Flowable,io.reactivex.rxjava3.core.Observable,io.reactivex.Single,reactor.core.publisher.Mono,io.reactivex.Maybe,io.reactivex.rxjava3.core.Single,io.reactivex.rxjava3.core.Maybe,io.reactivex.Completable,io.reactivex.rxjava3.core.Completable,io.methvin.watchservice.MacOSXListeningWatchService,io.micronaut.core.async.publisher.CompletableFuturePublisher,io.micronaut.core.async.publisher.Publishers.JustPublisher,io.micronaut.core.async.subscriber.Completable
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
applicationType: default
|
||||
defaultPackage: dev.amatos.restcountries
|
||||
defaultPackage: com.restcountries
|
||||
testFramework: junit
|
||||
sourceLanguage: java
|
||||
buildTool: maven
|
||||
features: [app-name, docker, file-watch, http-client, java, java-application, junit, logback, maven, netty-server, readme, shade, yaml]
|
||||
features: [app-name, http-client, java, java-application, junit, logback, maven, maven-enforcer-plugin, micronaut-aot, micronaut-http-validation, netty-server, properties, readme, serialization-jackson, shade, static-resources, validation]
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
# "License"); you may not use this file except in compliance
|
||||
# with the License. You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
# https://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing,
|
||||
# software distributed under the License is distributed on an
|
||||
@@ -19,7 +19,7 @@
|
||||
# ----------------------------------------------------------------------------
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# Maven2 Start Up Batch script
|
||||
# Apache Maven Wrapper startup batch script, version 3.1.1
|
||||
#
|
||||
# Required ENV vars:
|
||||
# ------------------
|
||||
@@ -27,7 +27,6 @@
|
||||
#
|
||||
# Optional ENV vars
|
||||
# -----------------
|
||||
# M2_HOME - location of maven2's installed home dir
|
||||
# MAVEN_OPTS - parameters passed to the Java VM when running Maven
|
||||
# e.g. to debug Maven itself, use
|
||||
# set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
|
||||
@@ -36,6 +35,10 @@
|
||||
|
||||
if [ -z "$MAVEN_SKIP_RC" ] ; then
|
||||
|
||||
if [ -f /usr/local/etc/mavenrc ] ; then
|
||||
. /usr/local/etc/mavenrc
|
||||
fi
|
||||
|
||||
if [ -f /etc/mavenrc ] ; then
|
||||
. /etc/mavenrc
|
||||
fi
|
||||
@@ -58,9 +61,9 @@ case "`uname`" in
|
||||
# See https://developer.apple.com/library/mac/qa/qa1170/_index.html
|
||||
if [ -z "$JAVA_HOME" ]; then
|
||||
if [ -x "/usr/libexec/java_home" ]; then
|
||||
export JAVA_HOME="`/usr/libexec/java_home`"
|
||||
JAVA_HOME="`/usr/libexec/java_home`"; export JAVA_HOME
|
||||
else
|
||||
export JAVA_HOME="/Library/Java/Home"
|
||||
JAVA_HOME="/Library/Java/Home"; export JAVA_HOME
|
||||
fi
|
||||
fi
|
||||
;;
|
||||
@@ -72,36 +75,8 @@ if [ -z "$JAVA_HOME" ] ; then
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ -z "$M2_HOME" ] ; then
|
||||
## resolve links - $0 may be a link to maven's home
|
||||
PRG="$0"
|
||||
|
||||
# need this for relative symlinks
|
||||
while [ -h "$PRG" ] ; do
|
||||
ls=`ls -ld "$PRG"`
|
||||
link=`expr "$ls" : '.*-> \(.*\)$'`
|
||||
if expr "$link" : '/.*' > /dev/null; then
|
||||
PRG="$link"
|
||||
else
|
||||
PRG="`dirname "$PRG"`/$link"
|
||||
fi
|
||||
done
|
||||
|
||||
saveddir=`pwd`
|
||||
|
||||
M2_HOME=`dirname "$PRG"`/..
|
||||
|
||||
# make it fully qualified
|
||||
M2_HOME=`cd "$M2_HOME" && pwd`
|
||||
|
||||
cd "$saveddir"
|
||||
# echo Using m2 at $M2_HOME
|
||||
fi
|
||||
|
||||
# For Cygwin, ensure paths are in UNIX format before anything is touched
|
||||
if $cygwin ; then
|
||||
[ -n "$M2_HOME" ] &&
|
||||
M2_HOME=`cygpath --unix "$M2_HOME"`
|
||||
[ -n "$JAVA_HOME" ] &&
|
||||
JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
|
||||
[ -n "$CLASSPATH" ] &&
|
||||
@@ -110,11 +85,8 @@ fi
|
||||
|
||||
# For Mingw, ensure paths are in UNIX format before anything is touched
|
||||
if $mingw ; then
|
||||
[ -n "$M2_HOME" ] &&
|
||||
M2_HOME="`(cd "$M2_HOME"; pwd)`"
|
||||
[ -n "$JAVA_HOME" ] &&
|
||||
JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`"
|
||||
# TODO classpath?
|
||||
fi
|
||||
|
||||
if [ -z "$JAVA_HOME" ]; then
|
||||
@@ -146,7 +118,7 @@ if [ -z "$JAVACMD" ] ; then
|
||||
JAVACMD="$JAVA_HOME/bin/java"
|
||||
fi
|
||||
else
|
||||
JAVACMD="`which java`"
|
||||
JAVACMD="`\\unset -f command; \\command -v java`"
|
||||
fi
|
||||
fi
|
||||
|
||||
@@ -160,12 +132,9 @@ if [ -z "$JAVA_HOME" ] ; then
|
||||
echo "Warning: JAVA_HOME environment variable is not set."
|
||||
fi
|
||||
|
||||
CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher
|
||||
|
||||
# traverses directory structure from process work directory to filesystem root
|
||||
# first directory with .mvn subdirectory is considered project base directory
|
||||
find_maven_basedir() {
|
||||
|
||||
if [ -z "$1" ]
|
||||
then
|
||||
echo "Path not specified to find_maven_basedir"
|
||||
@@ -185,7 +154,7 @@ find_maven_basedir() {
|
||||
fi
|
||||
# end of workaround
|
||||
done
|
||||
echo "${basedir}"
|
||||
printf '%s' "$(cd "$basedir"; pwd)"
|
||||
}
|
||||
|
||||
# concatenates all lines of a file
|
||||
@@ -195,11 +164,16 @@ concat_lines() {
|
||||
fi
|
||||
}
|
||||
|
||||
BASE_DIR=`find_maven_basedir "$(pwd)"`
|
||||
BASE_DIR=$(find_maven_basedir "$(dirname $0)")
|
||||
if [ -z "$BASE_DIR" ]; then
|
||||
exit 1;
|
||||
fi
|
||||
|
||||
MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"}; export MAVEN_PROJECTBASEDIR
|
||||
if [ "$MVNW_VERBOSE" = true ]; then
|
||||
echo $MAVEN_PROJECTBASEDIR
|
||||
fi
|
||||
|
||||
##########################################################################################
|
||||
# Extension to allow automatically downloading the maven-wrapper.jar from Maven-central
|
||||
# This allows using the maven wrapper in projects that prohibit checking in binary data.
|
||||
@@ -212,40 +186,67 @@ else
|
||||
if [ "$MVNW_VERBOSE" = true ]; then
|
||||
echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..."
|
||||
fi
|
||||
jarUrl="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.0/maven-wrapper-0.4.0.jar"
|
||||
if [ -n "$MVNW_REPOURL" ]; then
|
||||
wrapperUrl="$MVNW_REPOURL/org/apache/maven/wrapper/maven-wrapper/3.1.1/maven-wrapper-3.1.1.jar"
|
||||
else
|
||||
wrapperUrl="https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.1/maven-wrapper-3.1.1.jar"
|
||||
fi
|
||||
while IFS="=" read key value; do
|
||||
case "$key" in (wrapperUrl) jarUrl="$value"; break ;;
|
||||
case "$key" in (wrapperUrl) wrapperUrl="$value"; break ;;
|
||||
esac
|
||||
done < "$BASE_DIR/.mvn/wrapper/maven-wrapper.properties"
|
||||
if [ "$MVNW_VERBOSE" = true ]; then
|
||||
echo "Downloading from: $jarUrl"
|
||||
echo "Downloading from: $wrapperUrl"
|
||||
fi
|
||||
wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar"
|
||||
if $cygwin; then
|
||||
wrapperJarPath=`cygpath --path --windows "$wrapperJarPath"`
|
||||
fi
|
||||
|
||||
if command -v wget > /dev/null; then
|
||||
QUIET="--quiet"
|
||||
if [ "$MVNW_VERBOSE" = true ]; then
|
||||
echo "Found wget ... using wget"
|
||||
QUIET=""
|
||||
fi
|
||||
wget "$jarUrl" -O "$wrapperJarPath"
|
||||
if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then
|
||||
wget $QUIET "$wrapperUrl" -O "$wrapperJarPath"
|
||||
else
|
||||
wget $QUIET --http-user="$MVNW_USERNAME" --http-password="$MVNW_PASSWORD" "$wrapperUrl" -O "$wrapperJarPath"
|
||||
fi
|
||||
[ $? -eq 0 ] || rm -f "$wrapperJarPath"
|
||||
elif command -v curl > /dev/null; then
|
||||
QUIET="--silent"
|
||||
if [ "$MVNW_VERBOSE" = true ]; then
|
||||
echo "Found curl ... using curl"
|
||||
QUIET=""
|
||||
fi
|
||||
curl -o "$wrapperJarPath" "$jarUrl"
|
||||
if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then
|
||||
curl $QUIET -o "$wrapperJarPath" "$wrapperUrl" -f -L
|
||||
else
|
||||
curl $QUIET --user "$MVNW_USERNAME:$MVNW_PASSWORD" -o "$wrapperJarPath" "$wrapperUrl" -f -L
|
||||
fi
|
||||
[ $? -eq 0 ] || rm -f "$wrapperJarPath"
|
||||
else
|
||||
if [ "$MVNW_VERBOSE" = true ]; then
|
||||
echo "Falling back to using Java to download"
|
||||
fi
|
||||
javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java"
|
||||
if [ -e "$javaClass" ]; then
|
||||
if [ ! -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then
|
||||
javaSource="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java"
|
||||
javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class"
|
||||
# For Cygwin, switch paths to Windows format before running javac
|
||||
if $cygwin; then
|
||||
javaSource=`cygpath --path --windows "$javaSource"`
|
||||
javaClass=`cygpath --path --windows "$javaClass"`
|
||||
fi
|
||||
if [ -e "$javaSource" ]; then
|
||||
if [ ! -e "$javaClass" ]; then
|
||||
if [ "$MVNW_VERBOSE" = true ]; then
|
||||
echo " - Compiling MavenWrapperDownloader.java ..."
|
||||
fi
|
||||
# Compiling the Java class
|
||||
("$JAVA_HOME/bin/javac" "$javaClass")
|
||||
("$JAVA_HOME/bin/javac" "$javaSource")
|
||||
fi
|
||||
if [ -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then
|
||||
if [ -e "$javaClass" ]; then
|
||||
# Running the downloader
|
||||
if [ "$MVNW_VERBOSE" = true ]; then
|
||||
echo " - Running MavenWrapperDownloader.java ..."
|
||||
@@ -259,16 +260,10 @@ fi
|
||||
# End of extension
|
||||
##########################################################################################
|
||||
|
||||
export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"}
|
||||
if [ "$MVNW_VERBOSE" = true ]; then
|
||||
echo $MAVEN_PROJECTBASEDIR
|
||||
fi
|
||||
MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS"
|
||||
|
||||
# For Cygwin, switch paths to Windows format before running java
|
||||
if $cygwin; then
|
||||
[ -n "$M2_HOME" ] &&
|
||||
M2_HOME=`cygpath --path --windows "$M2_HOME"`
|
||||
[ -n "$JAVA_HOME" ] &&
|
||||
JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"`
|
||||
[ -n "$CLASSPATH" ] &&
|
||||
@@ -277,10 +272,16 @@ if $cygwin; then
|
||||
MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"`
|
||||
fi
|
||||
|
||||
# Provide a "standardized" way to retrieve the CLI args that will
|
||||
# work with both Windows and non-Windows executions.
|
||||
MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $@"
|
||||
export MAVEN_CMD_LINE_ARGS
|
||||
|
||||
WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
|
||||
|
||||
exec "$JAVACMD" \
|
||||
$MAVEN_OPTS \
|
||||
$MAVEN_DEBUG_OPTS \
|
||||
-classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \
|
||||
"-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \
|
||||
"-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \
|
||||
${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@"
|
||||
|
||||
@@ -1,161 +1,187 @@
|
||||
@REM ----------------------------------------------------------------------------
|
||||
@REM Licensed to the Apache Software Foundation (ASF) under one
|
||||
@REM or more contributor license agreements. See the NOTICE file
|
||||
@REM distributed with this work for additional information
|
||||
@REM regarding copyright ownership. The ASF licenses this file
|
||||
@REM to you under the Apache License, Version 2.0 (the
|
||||
@REM "License"); you may not use this file except in compliance
|
||||
@REM with the License. You may obtain a copy of the License at
|
||||
@REM
|
||||
@REM http://www.apache.org/licenses/LICENSE-2.0
|
||||
@REM
|
||||
@REM Unless required by applicable law or agreed to in writing,
|
||||
@REM software distributed under the License is distributed on an
|
||||
@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
@REM KIND, either express or implied. See the License for the
|
||||
@REM specific language governing permissions and limitations
|
||||
@REM under the License.
|
||||
@REM ----------------------------------------------------------------------------
|
||||
|
||||
@REM ----------------------------------------------------------------------------
|
||||
@REM Maven2 Start Up Batch script
|
||||
@REM
|
||||
@REM Required ENV vars:
|
||||
@REM JAVA_HOME - location of a JDK home dir
|
||||
@REM
|
||||
@REM Optional ENV vars
|
||||
@REM M2_HOME - location of maven2's installed home dir
|
||||
@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands
|
||||
@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending
|
||||
@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven
|
||||
@REM e.g. to debug Maven itself, use
|
||||
@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
|
||||
@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files
|
||||
@REM ----------------------------------------------------------------------------
|
||||
|
||||
@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on'
|
||||
@echo off
|
||||
@REM set title of command window
|
||||
title %0
|
||||
@REM enable echoing my setting MAVEN_BATCH_ECHO to 'on'
|
||||
@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO%
|
||||
|
||||
@REM set %HOME% to equivalent of $HOME
|
||||
if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%")
|
||||
|
||||
@REM Execute a user defined script before this one
|
||||
if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre
|
||||
@REM check for pre script, once with legacy .bat ending and once with .cmd ending
|
||||
if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat"
|
||||
if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd"
|
||||
:skipRcPre
|
||||
|
||||
@setlocal
|
||||
|
||||
set ERROR_CODE=0
|
||||
|
||||
@REM To isolate internal variables from possible post scripts, we use another setlocal
|
||||
@setlocal
|
||||
|
||||
@REM ==== START VALIDATION ====
|
||||
if not "%JAVA_HOME%" == "" goto OkJHome
|
||||
|
||||
echo.
|
||||
echo Error: JAVA_HOME not found in your environment. >&2
|
||||
echo Please set the JAVA_HOME variable in your environment to match the >&2
|
||||
echo location of your Java installation. >&2
|
||||
echo.
|
||||
goto error
|
||||
|
||||
:OkJHome
|
||||
if exist "%JAVA_HOME%\bin\java.exe" goto init
|
||||
|
||||
echo.
|
||||
echo Error: JAVA_HOME is set to an invalid directory. >&2
|
||||
echo JAVA_HOME = "%JAVA_HOME%" >&2
|
||||
echo Please set the JAVA_HOME variable in your environment to match the >&2
|
||||
echo location of your Java installation. >&2
|
||||
echo.
|
||||
goto error
|
||||
|
||||
@REM ==== END VALIDATION ====
|
||||
|
||||
:init
|
||||
|
||||
@REM Find the project base dir, i.e. the directory that contains the folder ".mvn".
|
||||
@REM Fallback to current working directory if not found.
|
||||
|
||||
set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR%
|
||||
IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir
|
||||
|
||||
set EXEC_DIR=%CD%
|
||||
set WDIR=%EXEC_DIR%
|
||||
:findBaseDir
|
||||
IF EXIST "%WDIR%"\.mvn goto baseDirFound
|
||||
cd ..
|
||||
IF "%WDIR%"=="%CD%" goto baseDirNotFound
|
||||
set WDIR=%CD%
|
||||
goto findBaseDir
|
||||
|
||||
:baseDirFound
|
||||
set MAVEN_PROJECTBASEDIR=%WDIR%
|
||||
cd "%EXEC_DIR%"
|
||||
goto endDetectBaseDir
|
||||
|
||||
:baseDirNotFound
|
||||
set MAVEN_PROJECTBASEDIR=%EXEC_DIR%
|
||||
cd "%EXEC_DIR%"
|
||||
|
||||
:endDetectBaseDir
|
||||
|
||||
IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig
|
||||
|
||||
@setlocal EnableExtensions EnableDelayedExpansion
|
||||
for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a
|
||||
@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS%
|
||||
|
||||
:endReadAdditionalConfig
|
||||
|
||||
SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe"
|
||||
set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar"
|
||||
set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
|
||||
|
||||
set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.0/maven-wrapper-0.4.0.jar"
|
||||
FOR /F "tokens=1,2 delims==" %%A IN (%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties) DO (
|
||||
IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B
|
||||
)
|
||||
|
||||
@REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central
|
||||
@REM This allows using the maven wrapper in projects that prohibit checking in binary data.
|
||||
if exist %WRAPPER_JAR% (
|
||||
echo Found %WRAPPER_JAR%
|
||||
) else (
|
||||
echo Couldn't find %WRAPPER_JAR%, downloading it ...
|
||||
echo Downloading from: %DOWNLOAD_URL%
|
||||
powershell -Command "(New-Object Net.WebClient).DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')"
|
||||
echo Finished downloading %WRAPPER_JAR%
|
||||
)
|
||||
@REM End of extension
|
||||
|
||||
%MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %*
|
||||
if ERRORLEVEL 1 goto error
|
||||
goto end
|
||||
|
||||
:error
|
||||
set ERROR_CODE=1
|
||||
|
||||
:end
|
||||
@endlocal & set ERROR_CODE=%ERROR_CODE%
|
||||
|
||||
if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost
|
||||
@REM check for post script, once with legacy .bat ending and once with .cmd ending
|
||||
if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat"
|
||||
if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd"
|
||||
:skipRcPost
|
||||
|
||||
@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on'
|
||||
if "%MAVEN_BATCH_PAUSE%" == "on" pause
|
||||
|
||||
if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE%
|
||||
|
||||
exit /B %ERROR_CODE%
|
||||
@REM ----------------------------------------------------------------------------
|
||||
@REM Licensed to the Apache Software Foundation (ASF) under one
|
||||
@REM or more contributor license agreements. See the NOTICE file
|
||||
@REM distributed with this work for additional information
|
||||
@REM regarding copyright ownership. The ASF licenses this file
|
||||
@REM to you under the Apache License, Version 2.0 (the
|
||||
@REM "License"); you may not use this file except in compliance
|
||||
@REM with the License. You may obtain a copy of the License at
|
||||
@REM
|
||||
@REM https://www.apache.org/licenses/LICENSE-2.0
|
||||
@REM
|
||||
@REM Unless required by applicable law or agreed to in writing,
|
||||
@REM software distributed under the License is distributed on an
|
||||
@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
@REM KIND, either express or implied. See the License for the
|
||||
@REM specific language governing permissions and limitations
|
||||
@REM under the License.
|
||||
@REM ----------------------------------------------------------------------------
|
||||
|
||||
@REM ----------------------------------------------------------------------------
|
||||
@REM Apache Maven Wrapper startup batch script, version 3.1.1
|
||||
@REM
|
||||
@REM Required ENV vars:
|
||||
@REM JAVA_HOME - location of a JDK home dir
|
||||
@REM
|
||||
@REM Optional ENV vars
|
||||
@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands
|
||||
@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a keystroke before ending
|
||||
@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven
|
||||
@REM e.g. to debug Maven itself, use
|
||||
@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
|
||||
@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files
|
||||
@REM ----------------------------------------------------------------------------
|
||||
|
||||
@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on'
|
||||
@echo off
|
||||
@REM set title of command window
|
||||
title %0
|
||||
@REM enable echoing by setting MAVEN_BATCH_ECHO to 'on'
|
||||
@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO%
|
||||
|
||||
@REM set %HOME% to equivalent of $HOME
|
||||
if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%")
|
||||
|
||||
@REM Execute a user defined script before this one
|
||||
if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre
|
||||
@REM check for pre script, once with legacy .bat ending and once with .cmd ending
|
||||
if exist "%USERPROFILE%\mavenrc_pre.bat" call "%USERPROFILE%\mavenrc_pre.bat" %*
|
||||
if exist "%USERPROFILE%\mavenrc_pre.cmd" call "%USERPROFILE%\mavenrc_pre.cmd" %*
|
||||
:skipRcPre
|
||||
|
||||
@setlocal
|
||||
|
||||
set ERROR_CODE=0
|
||||
|
||||
@REM To isolate internal variables from possible post scripts, we use another setlocal
|
||||
@setlocal
|
||||
|
||||
@REM ==== START VALIDATION ====
|
||||
if not "%JAVA_HOME%" == "" goto OkJHome
|
||||
|
||||
echo.
|
||||
echo Error: JAVA_HOME not found in your environment. >&2
|
||||
echo Please set the JAVA_HOME variable in your environment to match the >&2
|
||||
echo location of your Java installation. >&2
|
||||
echo.
|
||||
goto error
|
||||
|
||||
:OkJHome
|
||||
if exist "%JAVA_HOME%\bin\java.exe" goto init
|
||||
|
||||
echo.
|
||||
echo Error: JAVA_HOME is set to an invalid directory. >&2
|
||||
echo JAVA_HOME = "%JAVA_HOME%" >&2
|
||||
echo Please set the JAVA_HOME variable in your environment to match the >&2
|
||||
echo location of your Java installation. >&2
|
||||
echo.
|
||||
goto error
|
||||
|
||||
@REM ==== END VALIDATION ====
|
||||
|
||||
:init
|
||||
|
||||
@REM Find the project base dir, i.e. the directory that contains the folder ".mvn".
|
||||
@REM Fallback to current working directory if not found.
|
||||
|
||||
set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR%
|
||||
IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir
|
||||
|
||||
set EXEC_DIR=%CD%
|
||||
set WDIR=%EXEC_DIR%
|
||||
:findBaseDir
|
||||
IF EXIST "%WDIR%"\.mvn goto baseDirFound
|
||||
cd ..
|
||||
IF "%WDIR%"=="%CD%" goto baseDirNotFound
|
||||
set WDIR=%CD%
|
||||
goto findBaseDir
|
||||
|
||||
:baseDirFound
|
||||
set MAVEN_PROJECTBASEDIR=%WDIR%
|
||||
cd "%EXEC_DIR%"
|
||||
goto endDetectBaseDir
|
||||
|
||||
:baseDirNotFound
|
||||
set MAVEN_PROJECTBASEDIR=%EXEC_DIR%
|
||||
cd "%EXEC_DIR%"
|
||||
|
||||
:endDetectBaseDir
|
||||
|
||||
IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig
|
||||
|
||||
@setlocal EnableExtensions EnableDelayedExpansion
|
||||
for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a
|
||||
@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS%
|
||||
|
||||
:endReadAdditionalConfig
|
||||
|
||||
SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe"
|
||||
set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar"
|
||||
set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
|
||||
|
||||
set WRAPPER_URL="https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.1/maven-wrapper-3.1.1.jar"
|
||||
|
||||
FOR /F "usebackq tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO (
|
||||
IF "%%A"=="wrapperUrl" SET WRAPPER_URL=%%B
|
||||
)
|
||||
|
||||
@REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central
|
||||
@REM This allows using the maven wrapper in projects that prohibit checking in binary data.
|
||||
if exist %WRAPPER_JAR% (
|
||||
if "%MVNW_VERBOSE%" == "true" (
|
||||
echo Found %WRAPPER_JAR%
|
||||
)
|
||||
) else (
|
||||
if not "%MVNW_REPOURL%" == "" (
|
||||
SET WRAPPER_URL="%MVNW_REPOURL%/org/apache/maven/wrapper/maven-wrapper/3.1.1/maven-wrapper-3.1.1.jar"
|
||||
)
|
||||
if "%MVNW_VERBOSE%" == "true" (
|
||||
echo Couldn't find %WRAPPER_JAR%, downloading it ...
|
||||
echo Downloading from: %WRAPPER_URL%
|
||||
)
|
||||
|
||||
powershell -Command "&{"^
|
||||
"$webclient = new-object System.Net.WebClient;"^
|
||||
"if (-not ([string]::IsNullOrEmpty('%MVNW_USERNAME%') -and [string]::IsNullOrEmpty('%MVNW_PASSWORD%'))) {"^
|
||||
"$webclient.Credentials = new-object System.Net.NetworkCredential('%MVNW_USERNAME%', '%MVNW_PASSWORD%');"^
|
||||
"}"^
|
||||
"[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $webclient.DownloadFile('%WRAPPER_URL%', '%WRAPPER_JAR%')"^
|
||||
"}"
|
||||
if "%MVNW_VERBOSE%" == "true" (
|
||||
echo Finished downloading %WRAPPER_JAR%
|
||||
)
|
||||
)
|
||||
@REM End of extension
|
||||
|
||||
@REM Provide a "standardized" way to retrieve the CLI args that will
|
||||
@REM work with both Windows and non-Windows executions.
|
||||
set MAVEN_CMD_LINE_ARGS=%*
|
||||
|
||||
%MAVEN_JAVA_EXE% ^
|
||||
%JVM_CONFIG_MAVEN_PROPS% ^
|
||||
%MAVEN_OPTS% ^
|
||||
%MAVEN_DEBUG_OPTS% ^
|
||||
-classpath %WRAPPER_JAR% ^
|
||||
"-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" ^
|
||||
%WRAPPER_LAUNCHER% %MAVEN_CONFIG% %*
|
||||
if ERRORLEVEL 1 goto error
|
||||
goto end
|
||||
|
||||
:error
|
||||
set ERROR_CODE=1
|
||||
|
||||
:end
|
||||
@endlocal & set ERROR_CODE=%ERROR_CODE%
|
||||
|
||||
if not "%MAVEN_SKIP_RC%"=="" goto skipRcPost
|
||||
@REM check for post script, once with legacy .bat ending and once with .cmd ending
|
||||
if exist "%USERPROFILE%\mavenrc_post.bat" call "%USERPROFILE%\mavenrc_post.bat"
|
||||
if exist "%USERPROFILE%\mavenrc_post.cmd" call "%USERPROFILE%\mavenrc_post.cmd"
|
||||
:skipRcPost
|
||||
|
||||
@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on'
|
||||
if "%MAVEN_BATCH_PAUSE%"=="on" pause
|
||||
|
||||
if "%MAVEN_TERMINATE_CMD%"=="on" exit %ERROR_CODE%
|
||||
|
||||
cmd /C exit /B %ERROR_CODE%
|
||||
|
||||
@@ -1,44 +1,39 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>dev.amatos.restcountries</groupId>
|
||||
<artifactId>dev.amatos.restcountries</artifactId>
|
||||
<version>1</version>
|
||||
<groupId>com.restcountries</groupId>
|
||||
<artifactId>restcountries</artifactId>
|
||||
<version>2025.04.20</version>
|
||||
<packaging>${packaging}</packaging>
|
||||
|
||||
<parent>
|
||||
<groupId>io.micronaut</groupId>
|
||||
<groupId>io.micronaut.platform</groupId>
|
||||
<artifactId>micronaut-parent</artifactId>
|
||||
<version>2.0.1</version>
|
||||
<version>4.7.6</version>
|
||||
</parent>
|
||||
|
||||
<properties>
|
||||
<jdk.version>14</jdk.version>
|
||||
<!-- If you are building with JDK 9 or higher, you can uncomment the lines below to set the release version -->
|
||||
<release.version>14</release.version>
|
||||
<micronaut.version>2.0.1</micronaut.version>
|
||||
<exec.mainClass>dev.amatos.restcountries.Application</exec.mainClass>
|
||||
<java.version>14</java.version>
|
||||
<packaging>jar</packaging>
|
||||
<jdk.version>17</jdk.version>
|
||||
<release.version>17</release.version>
|
||||
<micronaut.version>4.7.6</micronaut.version>
|
||||
<micronaut.runtime>netty</micronaut.runtime>
|
||||
<micronaut.aot.enabled>false</micronaut.aot.enabled>
|
||||
<micronaut.aot.packageName>com.restcountries.aot.generated</micronaut.aot.packageName>
|
||||
<exec.mainClass>com.restcountries.Application</exec.mainClass>
|
||||
</properties>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>jcenter.bintray.com</id>
|
||||
<url>https://jcenter.bintray.com</url>
|
||||
<id>central</id>
|
||||
<url>https://repo.maven.apache.org/maven2</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>io.micronaut</groupId>
|
||||
<artifactId>micronaut-inject</artifactId>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.micronaut</groupId>
|
||||
<artifactId>micronaut-validation</artifactId>
|
||||
<artifactId>micronaut-http-client</artifactId>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
@@ -47,13 +42,18 @@
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.micronaut</groupId>
|
||||
<artifactId>micronaut-http-client</artifactId>
|
||||
<groupId>io.micronaut.serde</groupId>
|
||||
<artifactId>micronaut-serde-jackson</artifactId>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.micronaut</groupId>
|
||||
<artifactId>micronaut-runtime</artifactId>
|
||||
<groupId>io.micronaut.validation</groupId>
|
||||
<artifactId>micronaut-validation</artifactId>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>jakarta.validation</groupId>
|
||||
<artifactId>jakarta.validation-api</artifactId>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
@@ -61,6 +61,11 @@
|
||||
<artifactId>logback-classic</artifactId>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.micronaut.test</groupId>
|
||||
<artifactId>micronaut-test-junit5</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
<artifactId>junit-jupiter-api</artifactId>
|
||||
@@ -71,105 +76,92 @@
|
||||
<artifactId>junit-jupiter-engine</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.micronaut.test</groupId>
|
||||
<artifactId>micronaut-test-junit5</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.micronaut</groupId>
|
||||
<artifactId>micronaut-management</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.code.gson</groupId>
|
||||
<artifactId>gson</artifactId>
|
||||
<version>2.8.2</version>
|
||||
<version>2.10.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>log4j</groupId>
|
||||
<artifactId>log4j</artifactId>
|
||||
<version>1.2.16</version>
|
||||
<groupId>io.swagger.core.v3</groupId>
|
||||
<artifactId>swagger-annotations</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jboss.spec.javax.ws.rs</groupId>
|
||||
<artifactId>jboss-jaxrs-api_2.0_spec</artifactId>
|
||||
<version>1.0.1.Beta1</version>
|
||||
<version>1.0.1.Final</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.glassfish.jersey.core</groupId>
|
||||
<artifactId>jersey-common</artifactId>
|
||||
<version>2.22.2</version>
|
||||
<groupId>jakarta.ws.rs</groupId>
|
||||
<artifactId>jakarta.ws.rs-api</artifactId>
|
||||
<version>4.0.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jboss.resteasy</groupId>
|
||||
<artifactId>resteasy-client</artifactId>
|
||||
<version>3.6.0.Final</version>
|
||||
<groupId>org.apache.logging.log4j</groupId>
|
||||
<artifactId>log4j-core</artifactId>
|
||||
<version>2.17.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.yaml</groupId>
|
||||
<artifactId>snakeyaml</artifactId>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>io.micronaut.build</groupId>
|
||||
<groupId>io.micronaut.maven</groupId>
|
||||
<artifactId>micronaut-maven-plugin</artifactId>
|
||||
<configuration>
|
||||
<configFile>aot-${packaging}.properties</configFile>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-failsafe-plugin</artifactId>
|
||||
<artifactId>maven-enforcer-plugin</artifactId>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.8.1</version>
|
||||
<configuration>
|
||||
<!-- Uncomment to enable incremental compilation -->
|
||||
<!-- <useIncrementalCompilation>false</useIncrementalCompilation> -->
|
||||
<annotationProcessorPaths>
|
||||
|
||||
<annotationProcessorPaths combine.children="append">
|
||||
<path>
|
||||
<groupId>io.micronaut</groupId>
|
||||
<artifactId>micronaut-inject-java</artifactId>
|
||||
<version>${micronaut.version}</version>
|
||||
<artifactId>micronaut-http-validation</artifactId>
|
||||
<version>${micronaut.core.version}</version>
|
||||
</path>
|
||||
<path>
|
||||
<groupId>io.micronaut</groupId>
|
||||
<artifactId>micronaut-validation</artifactId>
|
||||
<version>${micronaut.version}</version>
|
||||
<groupId>io.micronaut.serde</groupId>
|
||||
<artifactId>micronaut-serde-processor</artifactId>
|
||||
<version>${micronaut.serialization.version}</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>io.micronaut</groupId>
|
||||
<artifactId>micronaut-inject</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</path>
|
||||
<path>
|
||||
<groupId>io.micronaut.validation</groupId>
|
||||
<artifactId>micronaut-validation-processor</artifactId>
|
||||
<version>${micronaut.validation.version}</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>io.micronaut</groupId>
|
||||
<artifactId>micronaut-inject</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</path>
|
||||
</annotationProcessorPaths>
|
||||
<compilerArgs>
|
||||
<arg>-Amicronaut.processing.group=dev.amatos.restcountries</arg>
|
||||
<arg>-Amicronaut.processing.module=dev.amatos.restcountries</arg>
|
||||
<arg>-Amicronaut.processing.group=com.restcountries</arg>
|
||||
<arg>-Amicronaut.processing.module=restcountries</arg>
|
||||
</compilerArgs>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>test-compile</id>
|
||||
<goals>
|
||||
<goal>testCompile</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<annotationProcessorPaths>
|
||||
<path>
|
||||
<groupId>io.micronaut</groupId>
|
||||
<artifactId>micronaut-inject-java</artifactId>
|
||||
<version>${micronaut.version}</version>
|
||||
</path>
|
||||
<path>
|
||||
<groupId>io.micronaut</groupId>
|
||||
<artifactId>micronaut-validation</artifactId>
|
||||
<version>${micronaut.version}</version>
|
||||
</path>
|
||||
</annotationProcessorPaths>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
|
||||
</project>
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
package dev.amatos.restcountries;
|
||||
package com.restcountries;
|
||||
|
||||
import io.micronaut.runtime.Micronaut;
|
||||
|
||||
public class Application {
|
||||
|
||||
public static void main(String[] args) {
|
||||
Micronaut.run(Application.class, args);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,105 @@
|
||||
package com.restcountries.controller;
|
||||
|
||||
import com.restcountries.domain.ResponseEntity;
|
||||
import io.micronaut.http.HttpResponse;
|
||||
import jakarta.ws.rs.core.Response;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static com.restcountries.utils.Constants.CACHE_CONTROL_VALUE;
|
||||
import static io.micronaut.http.HttpHeaders.CACHE_CONTROL;
|
||||
|
||||
public class ControllerHelper {
|
||||
|
||||
protected static final String[] COUNTRY_FIELDS_V2 = new String[]{
|
||||
"name",
|
||||
"topLevelDomain",
|
||||
"alpha2Code",
|
||||
"alpha3Code",
|
||||
"callingCodes",
|
||||
"capital",
|
||||
"altSpellings",
|
||||
"region",
|
||||
"subregion",
|
||||
"translations",
|
||||
"population",
|
||||
"latlng",
|
||||
"demonym",
|
||||
"area",
|
||||
"gini",
|
||||
"timezones",
|
||||
"borders",
|
||||
"nativeName",
|
||||
"numericCode",
|
||||
"currencies",
|
||||
"languages",
|
||||
"flags",
|
||||
"regionalBlocs",
|
||||
"cioc",
|
||||
"independent",
|
||||
"continent",
|
||||
"borders",
|
||||
"flag",
|
||||
"flags"
|
||||
};
|
||||
|
||||
protected static HttpResponse<Object> ok(Object object) {
|
||||
return HttpResponse.ok(object).header(CACHE_CONTROL, CACHE_CONTROL_VALUE);
|
||||
}
|
||||
|
||||
protected static HttpResponse<Object> notFound() {
|
||||
return HttpResponse.notFound().body(
|
||||
new ResponseEntity(
|
||||
Response.Status.NOT_FOUND.getStatusCode(),
|
||||
Response.Status.NOT_FOUND.getReasonPhrase()
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
protected static HttpResponse<Object> internalError() {
|
||||
return HttpResponse.serverError().body(
|
||||
new ResponseEntity(
|
||||
Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(),
|
||||
Response.Status.INTERNAL_SERVER_ERROR.getReasonPhrase()
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
protected static HttpResponse<Object> badRequest() {
|
||||
return HttpResponse.badRequest().body(
|
||||
new ResponseEntity(
|
||||
Response.Status.BAD_REQUEST.getStatusCode(),
|
||||
Response.Status.BAD_REQUEST.getReasonPhrase()
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
protected static HttpResponse<Object> badAllRequest() {
|
||||
return HttpResponse.badRequest().body(
|
||||
new ResponseEntity(
|
||||
Response.Status.BAD_REQUEST.getStatusCode(),
|
||||
"'fields' query not specified or you're requesting more than 10 fields"
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
protected static boolean hasInvalidFields(Optional<String> fields) {
|
||||
if (fields.isEmpty()) {
|
||||
return true;
|
||||
}
|
||||
var totalFields = Arrays
|
||||
.stream(fields.get().split(","))
|
||||
.toList()
|
||||
.stream()
|
||||
.map(String::trim)
|
||||
.collect(Collectors.toCollection(ArrayList::new));
|
||||
boolean isEmptyOrHasBlank = totalFields.isEmpty() || totalFields.stream().anyMatch(String::isEmpty);
|
||||
if (isEmptyOrHasBlank || totalFields.size() > 10) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,122 @@
|
||||
package com.restcountries.controller;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
import com.restcountries.domain.ICountryRestSymbols;
|
||||
import com.restcountries.domain.base.BaseCountry;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class ControllerV3Helper {
|
||||
|
||||
protected Object checkFieldsAndParseCountries(Optional<String> fields,
|
||||
Set<? extends com.restcountries.domain.base.BaseCountry> countries) {
|
||||
if (fields.isPresent()) {
|
||||
return parsedCountries(countries, fields.get());
|
||||
} else {
|
||||
return parsedCountries(countries, null);
|
||||
}
|
||||
}
|
||||
|
||||
protected Object checkFieldsAndParseCountry(Set<? extends com.restcountries.domain.base.BaseCountry> countries, Optional<String> fields) {
|
||||
if (fields.isPresent()) {
|
||||
return parsedCountry(countries, fields.get());
|
||||
} else {
|
||||
return parsedCountry(countries, null);
|
||||
}
|
||||
}
|
||||
|
||||
protected Object parsedCountries(Set<? extends com.restcountries.domain.base.BaseCountry> countries, String excludedFields) {
|
||||
if (excludedFields == null || excludedFields.isEmpty()) {
|
||||
return countries;
|
||||
} else {
|
||||
return getCountriesJson(countries,
|
||||
Arrays.asList(excludedFields.split(ICountryRestSymbols.COLON)));
|
||||
}
|
||||
}
|
||||
|
||||
protected static Object parsedCountry(Set<? extends BaseCountry> countries, String fields) {
|
||||
if (fields == null || fields.isEmpty()) {
|
||||
return countries;
|
||||
} else {
|
||||
StringBuilder result = new StringBuilder();
|
||||
countries.forEach(country -> result.append(
|
||||
getCountryJson(country, Arrays.asList(fields.split(ICountryRestSymbols.COLON)))));
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
private static String getCountryJson(BaseCountry country, List<String> fields) {
|
||||
var gson = new Gson();
|
||||
var jsonObject = JsonParser.parseString(gson.toJson(country)).getAsJsonObject();
|
||||
List<String> excludedFields = new ArrayList<>(Arrays.asList(V3_COUNTRY_FIELDS));
|
||||
excludedFields.removeAll(fields);
|
||||
excludedFields.forEach(jsonObject::remove);
|
||||
return jsonObject.toString();
|
||||
}
|
||||
|
||||
private String getCountriesJson(Set<? extends com.restcountries.domain.base.BaseCountry> countries, List<String> fields) {
|
||||
var gson = new Gson();
|
||||
var jsonArray = JsonParser.parseString(gson.toJson(countries)).getAsJsonArray();
|
||||
var resultArray = new JsonArray();
|
||||
jsonArray.forEach(element -> {
|
||||
var jsonObject = (JsonObject) element;
|
||||
var excludedFields = getExcludedFields(fields);
|
||||
excludedFields.forEach(jsonObject::remove);
|
||||
resultArray.add(jsonObject);
|
||||
});
|
||||
return resultArray.toString();
|
||||
}
|
||||
|
||||
private List<String> getExcludedFields(List<String> fields) {
|
||||
List<String> excludedFields = new ArrayList<>(Arrays.asList(V3_COUNTRY_FIELDS));
|
||||
excludedFields.removeAll(fields);
|
||||
return excludedFields;
|
||||
}
|
||||
|
||||
boolean isEmpty(String value) {
|
||||
return value == null || value.isEmpty();
|
||||
}
|
||||
|
||||
protected static final String[] V3_COUNTRY_FIELDS = new String[]{
|
||||
"name",
|
||||
"tld",
|
||||
"cca2",
|
||||
"ccn3",
|
||||
"cca3",
|
||||
"cioc",
|
||||
"independent",
|
||||
"status",
|
||||
"unMember",
|
||||
"currencies",
|
||||
"idd",
|
||||
"region",
|
||||
"subregion",
|
||||
"languages",
|
||||
"translations",
|
||||
"latlng",
|
||||
"landlocked",
|
||||
"borders",
|
||||
"area",
|
||||
"flags",
|
||||
"demonyms",
|
||||
"population",
|
||||
"flags",
|
||||
"flag",
|
||||
"maps",
|
||||
"population",
|
||||
"gini",
|
||||
"fifa",
|
||||
"car",
|
||||
"timezones",
|
||||
"continents",
|
||||
"coatOfArms",
|
||||
"startOfWeek",
|
||||
"capitalInfo",
|
||||
"postalCode",
|
||||
"capital",
|
||||
"altSpellings"
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,128 @@
|
||||
package com.restcountries.controller;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
import com.restcountries.domain.ICountryRestSymbols;
|
||||
import com.restcountries.domain.v4.Country;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class ControllerV4Helper {
|
||||
|
||||
protected Object checkFieldsAndParseCountries(Optional<String> fields, Set<Country> countries) {
|
||||
if (fields.isPresent()) {
|
||||
return parsedCountries(countries, fields.get());
|
||||
} else {
|
||||
return parsedCountries(countries, null);
|
||||
}
|
||||
}
|
||||
|
||||
protected Object checkFieldsAndParseCountry(Set<Country> countries, Optional<String> fields) {
|
||||
if (fields.isPresent()) {
|
||||
return parsedCountry(countries, fields.get());
|
||||
} else {
|
||||
return parsedCountry(countries, null);
|
||||
}
|
||||
}
|
||||
|
||||
protected Object parsedCountries(Set<Country> countries, String excludedFields) {
|
||||
if (excludedFields == null || excludedFields.isEmpty()) {
|
||||
return countries;
|
||||
} else {
|
||||
return getCountriesJson(countries,
|
||||
Arrays.asList(excludedFields.split(ICountryRestSymbols.COLON)));
|
||||
}
|
||||
}
|
||||
|
||||
protected static Object parsedCountry(Set<Country> countries, String fields) {
|
||||
if (fields == null || fields.isEmpty()) {
|
||||
return countries;
|
||||
} else {
|
||||
StringBuilder result = new StringBuilder();
|
||||
countries.forEach(country -> result.append(
|
||||
getCountryJson(country, Arrays.asList(fields.split(ICountryRestSymbols.COLON)))));
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
private static String getCountryJson(Country country, List<String> fields) {
|
||||
var gson = new Gson();
|
||||
var jsonObject = JsonParser.parseString(gson.toJson(country)).getAsJsonObject();
|
||||
List<String> excludedFields = new ArrayList<>(Arrays.asList(V4_COUNTRY_FIELDS));
|
||||
excludedFields.removeAll(fields);
|
||||
excludedFields.forEach(jsonObject::remove);
|
||||
return jsonObject.toString();
|
||||
}
|
||||
|
||||
private String getCountriesJson(Set<Country> countries, List<String> fields) {
|
||||
var gson = new Gson();
|
||||
var jsonArray = JsonParser.parseString(gson.toJson(countries)).getAsJsonArray();
|
||||
var resultArray = new JsonArray();
|
||||
jsonArray.forEach(element -> {
|
||||
var jsonObject = (JsonObject) element;
|
||||
var excludedFields = getExcludedFields(fields);
|
||||
excludedFields.forEach(jsonObject::remove);
|
||||
resultArray.add(jsonObject);
|
||||
});
|
||||
return resultArray.toString();
|
||||
}
|
||||
|
||||
private List<String> getExcludedFields(List<String> fields) {
|
||||
List<String> excludedFields = new ArrayList<>(Arrays.asList(V4_COUNTRY_FIELDS));
|
||||
excludedFields.removeAll(fields);
|
||||
return excludedFields;
|
||||
}
|
||||
|
||||
boolean isEmpty(String value) {
|
||||
return value == null || value.isEmpty();
|
||||
}
|
||||
|
||||
protected static final String[] V4_COUNTRY_FIELDS = new String[]{
|
||||
"name",
|
||||
"tld",
|
||||
"cca2",
|
||||
"ccn3",
|
||||
"cca3",
|
||||
"cioc",
|
||||
"independent",
|
||||
"status",
|
||||
"unMember",
|
||||
"currencies",
|
||||
"idd",
|
||||
"region",
|
||||
"subregion",
|
||||
"languages",
|
||||
"translations",
|
||||
"landlocked",
|
||||
"borders",
|
||||
"area",
|
||||
"flags",
|
||||
"demonyms",
|
||||
"population",
|
||||
"flag",
|
||||
"maps",
|
||||
"gini",
|
||||
"fifa",
|
||||
"car",
|
||||
"timezones",
|
||||
"continents",
|
||||
"coatOfArms",
|
||||
"startOfWeek",
|
||||
"capitalInfo",
|
||||
"postalCode",
|
||||
"capital",
|
||||
"altSpellings",
|
||||
"geolocation",
|
||||
"religion",
|
||||
"ethnicity",
|
||||
"government",
|
||||
"density",
|
||||
"gdp",
|
||||
"nationalHoliday",
|
||||
"anthem",
|
||||
"regionalBlocs",
|
||||
"callingCodes"
|
||||
};
|
||||
}
|
||||
@@ -1,56 +1,215 @@
|
||||
package dev.amatos.restcountries.controller;
|
||||
package com.restcountries.controller;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
import dev.amatos.restcountries.domain.ICountryRestSymbols;
|
||||
import dev.amatos.restcountries.domain.ResponseEntity;
|
||||
import dev.amatos.restcountries.service.v2.CountryServiceV2;
|
||||
import dev.amatos.restcountries.domain.v2.Country;
|
||||
import com.restcountries.domain.ICountryRestSymbols;
|
||||
import com.restcountries.domain.v2.Country;
|
||||
import com.restcountries.service.v2.CountryServiceV2;
|
||||
import io.micronaut.http.HttpResponse;
|
||||
import io.micronaut.http.MediaType;
|
||||
import io.micronaut.http.annotation.Controller;
|
||||
import io.micronaut.http.annotation.Get;
|
||||
import io.micronaut.http.annotation.PathVariable;
|
||||
import io.micronaut.http.annotation.QueryValue;
|
||||
import io.swagger.v3.oas.annotations.Hidden;
|
||||
|
||||
import javax.ws.rs.QueryParam;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import javax.ws.rs.QueryParam;
|
||||
import javax.ws.rs.core.Response;
|
||||
|
||||
@Controller("v2/")
|
||||
public class CountryController {
|
||||
import static com.restcountries.controller.ControllerHelper.hasInvalidFields;
|
||||
|
||||
@Hidden
|
||||
@Controller("/v2/")
|
||||
public class CountryControllerV2 {
|
||||
|
||||
@Get(uri = "all", produces = MediaType.APPLICATION_JSON)
|
||||
public Object getAllCountries(@QueryValue("fields") Optional<String> fields) {
|
||||
if (hasInvalidFields(fields)) {
|
||||
return ControllerHelper.badAllRequest();
|
||||
}
|
||||
List<Country> countries = CountryServiceV2.getInstance().getAll();
|
||||
return checkFieldsAndParseCountries(fields, countries);
|
||||
}
|
||||
|
||||
private Object checkFieldsAndParseCountries(Optional<String> fields, List<Country> countries) {
|
||||
if (fields.isPresent()) {
|
||||
return parsedCountries(countries, fields.get());
|
||||
} else {
|
||||
return parsedCountries(countries, null);
|
||||
}
|
||||
}
|
||||
|
||||
@Get("alpha/{alphacode}")
|
||||
public Object getByAlpha(@PathVariable("alphacode") String alpha,
|
||||
public HttpResponse<Object> getByAlpha(@PathVariable("alphacode") String alpha,
|
||||
@QueryValue("fields") Optional<String> fields) {
|
||||
if (alpha.contains("codes")) {
|
||||
alpha = alpha.replace("codes=", "");
|
||||
}
|
||||
if (isEmpty(alpha) || alpha.length() < 2 || alpha.length() > 3) {
|
||||
return getResponse(Response.Status.BAD_REQUEST);
|
||||
return ControllerHelper.badRequest();
|
||||
}
|
||||
Country country = CountryServiceV2.getInstance().getByAlpha(alpha);
|
||||
if (country != null) {
|
||||
return checkFieldsAndParseCountry(country, fields);
|
||||
return ControllerHelper.ok(checkFieldsAndParseCountry(country, fields));
|
||||
}
|
||||
return ControllerHelper.notFound();
|
||||
}
|
||||
|
||||
@Get("alpha/")
|
||||
public HttpResponse<Object> getByAlphaList(@QueryParam("codes") String codes,
|
||||
@QueryParam("fields") Optional<String> fields) {
|
||||
if (isEmpty(codes) || codes.length() < 2 || (codes.length() > 3 && !codes.contains(","))) {
|
||||
return ControllerHelper.badRequest();
|
||||
}
|
||||
try {
|
||||
List<Country> countries = CountryServiceV2.getInstance().getByCodeList(codes);
|
||||
if (null != countries && !countries.isEmpty()) {
|
||||
return ControllerHelper.ok(checkFieldsAndParseCountries(fields, countries));
|
||||
}
|
||||
return ControllerHelper.notFound();
|
||||
} catch (Exception e) {
|
||||
return ControllerHelper.internalError();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Get("currency/{currency}")
|
||||
public HttpResponse<Object> getByCurrency(@PathVariable("currency") String currency,
|
||||
@QueryParam("fields") Optional<String> fields) {
|
||||
if (isEmpty(currency) || currency.length() != 3) {
|
||||
return ControllerHelper.badRequest();
|
||||
}
|
||||
try {
|
||||
List<Country> countries = CountryServiceV2.getInstance().getByCurrency(currency);
|
||||
if (!countries.isEmpty()) {
|
||||
return ControllerHelper.ok(checkFieldsAndParseCountries(fields, countries));
|
||||
}
|
||||
return ControllerHelper.notFound();
|
||||
} catch (Exception e) {
|
||||
return ControllerHelper.internalError();
|
||||
}
|
||||
}
|
||||
|
||||
@Get("name/{name}")
|
||||
public HttpResponse<Object> getByName(@PathVariable("name") String name,
|
||||
@QueryParam("fullText") Optional<Boolean> fullText,
|
||||
@QueryParam("fields") Optional<String> fields) {
|
||||
try {
|
||||
List<Country> countries = CountryServiceV2.getInstance()
|
||||
.getByName(name, fullText.orElse(false));
|
||||
if (!countries.isEmpty()) {
|
||||
return ControllerHelper.ok(checkFieldsAndParseCountries(fields, countries));
|
||||
}
|
||||
return ControllerHelper.notFound();
|
||||
} catch (Exception e) {
|
||||
return ControllerHelper.internalError();
|
||||
}
|
||||
}
|
||||
|
||||
@Get("callingcode/{callingCode}")
|
||||
public HttpResponse<Object> getByCallingCode(@PathVariable("callingCode") String callingCode,
|
||||
@QueryParam("fields") Optional<String> fields) {
|
||||
|
||||
try {
|
||||
List<Country> countries = CountryServiceV2.getInstance().getByCallingCode(callingCode);
|
||||
if (!countries.isEmpty()) {
|
||||
return ControllerHelper.ok(checkFieldsAndParseCountries(fields, countries));
|
||||
}
|
||||
return ControllerHelper.notFound();
|
||||
} catch (Exception e) {
|
||||
return ControllerHelper.internalError();
|
||||
}
|
||||
}
|
||||
|
||||
@Get("capital/{capital}")
|
||||
public HttpResponse<Object> getByCapital(@PathVariable("capital") String capital,
|
||||
@QueryParam("fields") Optional<String> fields) {
|
||||
try {
|
||||
List<Country> countries = CountryServiceV2.getInstance().getByCapital(capital);
|
||||
if (!countries.isEmpty()) {
|
||||
return ControllerHelper.ok(checkFieldsAndParseCountries(fields, countries));
|
||||
}
|
||||
return ControllerHelper.notFound();
|
||||
} catch (Exception e) {
|
||||
return ControllerHelper.internalError();
|
||||
}
|
||||
}
|
||||
|
||||
@Get("region/{region}")
|
||||
public HttpResponse<Object> getByContinent(@PathVariable("region") String region,
|
||||
@QueryParam("fields") Optional<String> fields) {
|
||||
try {
|
||||
List<Country> countries = CountryServiceV2.getInstance().getByRegion(region);
|
||||
if (!countries.isEmpty()) {
|
||||
return ControllerHelper.ok(checkFieldsAndParseCountries(fields, countries));
|
||||
}
|
||||
return ControllerHelper.notFound();
|
||||
} catch (Exception e) {
|
||||
return ControllerHelper.internalError();
|
||||
}
|
||||
}
|
||||
|
||||
@Get("subregion/{subregion}")
|
||||
public HttpResponse<Object> getBySubRegion(@PathVariable("subregion") String subregion,
|
||||
@QueryParam("fields") Optional<String> fields) {
|
||||
try {
|
||||
List<Country> countries = CountryServiceV2.getInstance().getBySubregion(subregion);
|
||||
if (!countries.isEmpty()) {
|
||||
return ControllerHelper.ok(checkFieldsAndParseCountries(fields, countries));
|
||||
}
|
||||
return ControllerHelper.notFound();
|
||||
} catch (Exception e) {
|
||||
return ControllerHelper.internalError();
|
||||
}
|
||||
}
|
||||
|
||||
@Get("lang/{lang}")
|
||||
public HttpResponse<Object> getByLanguage(@PathVariable("lang") String language,
|
||||
@QueryParam("fields") Optional<String> fields) {
|
||||
try {
|
||||
List<Country> countries = CountryServiceV2.getInstance().getByLanguage(language);
|
||||
if (!countries.isEmpty()) {
|
||||
return ControllerHelper.ok(checkFieldsAndParseCountries(fields, countries));
|
||||
}
|
||||
return ControllerHelper.notFound();
|
||||
} catch (Exception e) {
|
||||
return ControllerHelper.internalError();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Get("demonym/{demonym}")
|
||||
public HttpResponse<Object> getByDemonym(@PathVariable("demonym") String demonym,
|
||||
@QueryParam("fields") Optional<String> fields) {
|
||||
try {
|
||||
List<Country> countries = CountryServiceV2.getInstance().getByDemonym(demonym);
|
||||
if (!countries.isEmpty()) {
|
||||
return ControllerHelper.ok(checkFieldsAndParseCountries(fields, countries));
|
||||
}
|
||||
return ControllerHelper.notFound();
|
||||
} catch (Exception e) {
|
||||
return ControllerHelper.internalError();
|
||||
}
|
||||
}
|
||||
|
||||
@Get("regionalbloc/{regionalBlock}")
|
||||
public HttpResponse<Object> getByRegionalBloc(@PathVariable("regionalBlock") String regionalBlock,
|
||||
@QueryParam("fields") Optional<String> fields) {
|
||||
try {
|
||||
List<Country> countries = CountryServiceV2.getInstance().getByRegionalBloc(regionalBlock);
|
||||
if (!countries.isEmpty()) {
|
||||
return ControllerHelper.ok(checkFieldsAndParseCountries(fields, countries));
|
||||
}
|
||||
return ControllerHelper.notFound();
|
||||
} catch (Exception e) {
|
||||
return ControllerHelper.internalError();
|
||||
}
|
||||
}
|
||||
|
||||
private List<Country> checkFieldsAndParseCountries(Optional<String> fields,
|
||||
List<Country> countries) {
|
||||
if (fields.isPresent()) {
|
||||
return parsedCountries(countries, fields.get());
|
||||
} else {
|
||||
return parsedCountries(countries, null);
|
||||
}
|
||||
return getResponse(Response.Status.NOT_FOUND);
|
||||
}
|
||||
|
||||
private Object checkFieldsAndParseCountry(Country country, Optional<String> fields) {
|
||||
@@ -61,158 +220,7 @@ public class CountryController {
|
||||
}
|
||||
}
|
||||
|
||||
@Get("alpha/")
|
||||
public Object getByAlphaList(@QueryParam("codes") String codes,
|
||||
@QueryParam("fields") Optional<String> fields) {
|
||||
if (isEmpty(codes) || codes.length() < 2 || (codes.length() > 3 && !codes.contains(","))) {
|
||||
return getResponse(Response.Status.BAD_REQUEST);
|
||||
}
|
||||
try {
|
||||
List<Country> countries = CountryServiceV2.getInstance().getByCodeList(codes);
|
||||
if (!countries.isEmpty()) {
|
||||
return checkFieldsAndParseCountries(fields, countries);
|
||||
}
|
||||
return getResponse(Response.Status.NOT_FOUND);
|
||||
} catch (Exception e) {
|
||||
return getResponse(Response.Status.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Get("currency/{currency}")
|
||||
public Object getByCurrency(@PathVariable("currency") String currency,
|
||||
@QueryParam("fields") Optional<String> fields) {
|
||||
if (isEmpty(currency) || currency.length() != 3) {
|
||||
return getResponse(Response.Status.BAD_REQUEST);
|
||||
}
|
||||
try {
|
||||
List<Country> countries = CountryServiceV2.getInstance().getByCurrency(currency);
|
||||
if (!countries.isEmpty()) {
|
||||
return checkFieldsAndParseCountries(fields, countries);
|
||||
}
|
||||
return getResponse(Response.Status.NOT_FOUND);
|
||||
} catch (Exception e) {
|
||||
return getResponse(Response.Status.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
@Get("name/{name}")
|
||||
public Object getByName(@PathVariable("name") String name,
|
||||
@QueryParam("fullText") Optional<Boolean> fullText,
|
||||
@QueryParam("fields") Optional<String> fields) {
|
||||
try {
|
||||
List<Country> countries = CountryServiceV2.getInstance()
|
||||
.getByName(name, fullText.orElse(false));
|
||||
if (!countries.isEmpty()) {
|
||||
return checkFieldsAndParseCountries(fields, countries);
|
||||
}
|
||||
return getResponse(Response.Status.NOT_FOUND);
|
||||
} catch (Exception e) {
|
||||
return getResponse(Response.Status.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
@Get("callingcode/{callingCode}")
|
||||
public Object getByCallingCode(@PathVariable("callingCode") String callingCode,
|
||||
@QueryParam("fields") Optional<String> fields) {
|
||||
|
||||
try {
|
||||
List<Country> countries = CountryServiceV2.getInstance().getByCallingCode(callingCode);
|
||||
if (!countries.isEmpty()) {
|
||||
return checkFieldsAndParseCountries(fields, countries);
|
||||
}
|
||||
return getResponse(Response.Status.NOT_FOUND);
|
||||
} catch (Exception e) {
|
||||
return getResponse(Response.Status.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
@Get("capital/{capital}")
|
||||
public Object getByCapital(@PathVariable("capital") String capital,
|
||||
@QueryParam("fields") Optional<String> fields) {
|
||||
try {
|
||||
List<Country> countries = CountryServiceV2.getInstance().getByCapital(capital);
|
||||
if (!countries.isEmpty()) {
|
||||
return checkFieldsAndParseCountries(fields, countries);
|
||||
}
|
||||
return getResponse(Response.Status.NOT_FOUND);
|
||||
} catch (Exception e) {
|
||||
return getResponse(Response.Status.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
@Get("continent/{continent}")
|
||||
public Object getByContinent(@PathVariable("continent") String region,
|
||||
@QueryParam("fields") Optional<String> fields) {
|
||||
try {
|
||||
List<Country> countries = CountryServiceV2.getInstance().getByContinent(region);
|
||||
if (!countries.isEmpty()) {
|
||||
return checkFieldsAndParseCountries(fields, countries);
|
||||
}
|
||||
return getResponse(Response.Status.NOT_FOUND);
|
||||
} catch (Exception e) {
|
||||
return getResponse(Response.Status.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
@Get("region/{region}")
|
||||
public Object getBySubRegion(@PathVariable("region") String region,
|
||||
@QueryParam("fields") Optional<String> fields) {
|
||||
try {
|
||||
List<Country> countries = CountryServiceV2.getInstance().getByRegion(region);
|
||||
if (!countries.isEmpty()) {
|
||||
return checkFieldsAndParseCountries(fields, countries);
|
||||
}
|
||||
return getResponse(Response.Status.NOT_FOUND);
|
||||
} catch (Exception e) {
|
||||
return getResponse(Response.Status.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
@Get("lang/{lang}")
|
||||
public Object getByLanguage(@PathVariable("lang") String language,
|
||||
@QueryParam("fields") Optional<String> fields) {
|
||||
try {
|
||||
List<Country> countries = CountryServiceV2.getInstance().getByLanguage(language);
|
||||
if (!countries.isEmpty()) {
|
||||
return checkFieldsAndParseCountries(fields, countries);
|
||||
}
|
||||
return getResponse(Response.Status.NOT_FOUND);
|
||||
} catch (Exception e) {
|
||||
return getResponse(Response.Status.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Get("demonym/{demonym}")
|
||||
public Object getByDemonym(@PathVariable("demonym") String demonym,
|
||||
@QueryParam("fields") Optional<String> fields) {
|
||||
try {
|
||||
List<Country> countries = CountryServiceV2.getInstance().getByDemonym(demonym);
|
||||
if (!countries.isEmpty()) {
|
||||
return checkFieldsAndParseCountries(fields, countries);
|
||||
}
|
||||
return getResponse(Response.Status.NOT_FOUND);
|
||||
} catch (Exception e) {
|
||||
return getResponse(Response.Status.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
@Get("regionalbloc/{regionalBlock}")
|
||||
public Object getByRegionalBloc(@PathVariable("regionalBlock") String regionalBlock,
|
||||
@QueryParam("fields") Optional<String> fields) {
|
||||
try {
|
||||
List<Country> countries = CountryServiceV2.getInstance().getByRegionalBloc(regionalBlock);
|
||||
if (!countries.isEmpty()) {
|
||||
return checkFieldsAndParseCountries(fields, countries);
|
||||
}
|
||||
return getResponse(Response.Status.NOT_FOUND);
|
||||
} catch (Exception e) {
|
||||
return getResponse(Response.Status.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
private Object parsedCountries(List<Country> countries, String excludedFields) {
|
||||
private List<Country> parsedCountries(List<Country> countries, String excludedFields) {
|
||||
if (excludedFields == null || excludedFields.isEmpty()) {
|
||||
return countries;
|
||||
} else {
|
||||
@@ -221,37 +229,28 @@ public class CountryController {
|
||||
}
|
||||
}
|
||||
|
||||
private String getCountriesJson(List<Country> countries, List<String> fields) {
|
||||
private List<Country> getCountriesJson(List<Country> countries, List<String> fields) {
|
||||
List<Country> result = new ArrayList<>();
|
||||
var gson = new Gson();
|
||||
var parser = new JsonParser();
|
||||
JsonArray jsonArray = parser.parse(gson.toJson(countries)).getAsJsonArray();
|
||||
var resultArray = new JsonArray();
|
||||
for (var i = 0; i < jsonArray.size(); i++) {
|
||||
var jsonObject = (JsonObject) jsonArray.get(i);
|
||||
|
||||
List<String> excludedFields = getExcludedFields(fields);
|
||||
for (String excludedField : excludedFields) {
|
||||
jsonObject.remove(excludedField);
|
||||
}
|
||||
resultArray.add(jsonObject);
|
||||
result.add(gson.fromJson(jsonObject, Country.class));
|
||||
}
|
||||
return resultArray.toString();
|
||||
return result;
|
||||
}
|
||||
|
||||
private List<String> getExcludedFields(List<String> fields) {
|
||||
List<String> excludedFields = new ArrayList<>(Arrays.asList(COUNTRY_FIELDS));
|
||||
List<String> excludedFields = new ArrayList<>(Arrays.asList(ControllerHelper.COUNTRY_FIELDS_V2));
|
||||
excludedFields.removeAll(fields);
|
||||
return excludedFields;
|
||||
}
|
||||
|
||||
private Object getResponse(Response.Status status) {
|
||||
var gson = new Gson();
|
||||
return Response
|
||||
.status(status)
|
||||
.entity(gson.toJson(new ResponseEntity(status.getStatusCode(),
|
||||
status.getReasonPhrase()))).build().getEntity();
|
||||
}
|
||||
|
||||
private Object parsedCountry(Country country, String fields) {
|
||||
if (fields == null || fields.isEmpty()) {
|
||||
return country;
|
||||
@@ -272,38 +271,6 @@ public class CountryController {
|
||||
return jsonObject.toString();
|
||||
}
|
||||
|
||||
private static final String[] COUNTRY_FIELDS = new String[]{
|
||||
"name",
|
||||
"topLevelDomain",
|
||||
"alpha2Code",
|
||||
"alpha3Code",
|
||||
"callingCodes",
|
||||
"capital",
|
||||
"altSpellings",
|
||||
"region",
|
||||
"subregion",
|
||||
"translations",
|
||||
"population",
|
||||
"latlng",
|
||||
"demonym",
|
||||
"area",
|
||||
"gini",
|
||||
"timezones",
|
||||
"borders",
|
||||
"nativeName",
|
||||
"numericCode",
|
||||
"currencies",
|
||||
"languages",
|
||||
"flags",
|
||||
"regionalBlocs",
|
||||
"cioc",
|
||||
"independent",
|
||||
"continent",
|
||||
"borders",
|
||||
"flag",
|
||||
"flags"
|
||||
};
|
||||
|
||||
private boolean isEmpty(String value) {
|
||||
return value == null || value.isEmpty();
|
||||
}
|
||||
@@ -0,0 +1,182 @@
|
||||
package com.restcountries.controller;
|
||||
|
||||
import com.restcountries.service.v3.CountryServiceV3;
|
||||
import io.micronaut.http.HttpResponse;
|
||||
import io.micronaut.http.MediaType;
|
||||
import io.micronaut.http.annotation.Controller;
|
||||
import io.micronaut.http.annotation.Get;
|
||||
import io.micronaut.http.annotation.PathVariable;
|
||||
import io.micronaut.http.annotation.QueryValue;
|
||||
import io.swagger.v3.oas.annotations.Hidden;
|
||||
|
||||
import javax.ws.rs.QueryParam;
|
||||
import java.util.Optional;
|
||||
|
||||
import static com.restcountries.controller.ControllerHelper.hasInvalidFields;
|
||||
|
||||
@Hidden
|
||||
@Controller("/v3/")
|
||||
public class CountryControllerV3 extends ControllerV3Helper {
|
||||
|
||||
@Get(uri = "all", produces = MediaType.APPLICATION_JSON)
|
||||
public HttpResponse<Object> getAllCountries(@QueryValue("fields") Optional<String> fields) {
|
||||
if (hasInvalidFields(fields)) {
|
||||
return ControllerHelper.badAllRequest();
|
||||
}
|
||||
var countries = CountryServiceV3.getInstance().getAll();
|
||||
return ControllerHelper.ok(checkFieldsAndParseCountries(fields, countries));
|
||||
}
|
||||
|
||||
@Get("alpha/{alphacode}")
|
||||
public HttpResponse<Object> getByAlpha(@PathVariable("alphacode") String alpha,
|
||||
@QueryValue("fields") Optional<String> fields) {
|
||||
if (alpha.contains("codes")) {
|
||||
alpha = alpha.replace("codes=", "");
|
||||
}
|
||||
if (isEmpty(alpha) || alpha.length() < 2 || alpha.length() > 3) {
|
||||
return ControllerHelper.badRequest();
|
||||
}
|
||||
var country = CountryServiceV3.getInstance().getByAlpha(alpha);
|
||||
if (country != null && !country.isEmpty()) {
|
||||
return HttpResponse.ok(checkFieldsAndParseCountry(country, fields));
|
||||
}
|
||||
return ControllerHelper.notFound();
|
||||
}
|
||||
|
||||
@Get("alpha/")
|
||||
public HttpResponse<Object> getByAlphaList(@QueryParam("codes") String codes,
|
||||
@QueryParam("fields") Optional<String> fields) {
|
||||
if (isEmpty(codes) || codes.length() < 2 || (codes.length() > 3 && !codes.contains(","))) {
|
||||
return ControllerHelper.badRequest();
|
||||
}
|
||||
try {
|
||||
var countries = CountryServiceV3.getInstance().getByCodeList(codes);
|
||||
if (!countries.isEmpty()) {
|
||||
return ControllerHelper.ok(checkFieldsAndParseCountries(fields, countries));
|
||||
}
|
||||
return ControllerHelper.notFound();
|
||||
} catch (Exception e) {
|
||||
return ControllerHelper.internalError();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Get("currency/{currency}")
|
||||
public HttpResponse<Object> getByCurrency(@PathVariable("currency") String currency,
|
||||
@QueryParam("fields") Optional<String> fields) {
|
||||
if (isEmpty(currency)) {
|
||||
return ControllerHelper.notFound();
|
||||
}
|
||||
try {
|
||||
var countries = CountryServiceV3.getInstance().getByCurrency(currency);
|
||||
if (!countries.isEmpty()) {
|
||||
return ControllerHelper.ok(checkFieldsAndParseCountries(fields, countries));
|
||||
}
|
||||
return ControllerHelper.notFound();
|
||||
} catch (Exception e) {
|
||||
return ControllerHelper.internalError();
|
||||
}
|
||||
}
|
||||
|
||||
@Get("name/{name}")
|
||||
public HttpResponse<Object> getByName(@PathVariable("name") String name,
|
||||
@QueryParam("fullText") Optional<Boolean> fullText,
|
||||
@QueryParam("fields") Optional<String> fields) {
|
||||
try {
|
||||
var countries = CountryServiceV3.getInstance()
|
||||
.getByName(name, fullText.orElse(false));
|
||||
if (!countries.isEmpty()) {
|
||||
return ControllerHelper.ok(checkFieldsAndParseCountries(fields, countries));
|
||||
}
|
||||
return ControllerHelper.notFound();
|
||||
} catch (Exception e) {
|
||||
return ControllerHelper.internalError();
|
||||
}
|
||||
}
|
||||
|
||||
@Get("capital/{capital}")
|
||||
public HttpResponse<Object> getByCapital(@PathVariable("capital") String capital,
|
||||
@QueryParam("fields") Optional<String> fields) {
|
||||
try {
|
||||
var countries = CountryServiceV3.getInstance().getByCapital(capital);
|
||||
if (!countries.isEmpty()) {
|
||||
return ControllerHelper.ok(checkFieldsAndParseCountries(fields, countries));
|
||||
}
|
||||
return ControllerHelper.notFound();
|
||||
} catch (Exception e) {
|
||||
return ControllerHelper.internalError();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Get("region/{region}")
|
||||
public HttpResponse<Object> getByContinent(@PathVariable("region") String region,
|
||||
@QueryParam("fields") Optional<String> fields) {
|
||||
try {
|
||||
var countries = CountryServiceV3.getInstance().getByRegion(region);
|
||||
if (!countries.isEmpty()) {
|
||||
return ControllerHelper.ok(checkFieldsAndParseCountries(fields, countries));
|
||||
}
|
||||
return ControllerHelper.notFound();
|
||||
} catch (Exception e) {
|
||||
return ControllerHelper.internalError();
|
||||
}
|
||||
}
|
||||
|
||||
@Get("subregion/{subregion}")
|
||||
public HttpResponse<Object> getBySubRegion(@PathVariable("subregion") String subregion,
|
||||
@QueryParam("fields") Optional<String> fields) {
|
||||
try {
|
||||
var countries = CountryServiceV3.getInstance().getBySubregion(subregion);
|
||||
if (!countries.isEmpty()) {
|
||||
return ControllerHelper.ok(checkFieldsAndParseCountries(fields, countries));
|
||||
}
|
||||
return ControllerHelper.notFound();
|
||||
} catch (Exception e) {
|
||||
return ControllerHelper.internalError();
|
||||
}
|
||||
}
|
||||
|
||||
@Get("lang/{lang}")
|
||||
public HttpResponse<Object> getByLanguage(@PathVariable("lang") String language,
|
||||
@QueryParam("fields") Optional<String> fields) {
|
||||
try {
|
||||
var countries = CountryServiceV3.getInstance().getByLanguage(language);
|
||||
if (!countries.isEmpty()) {
|
||||
return ControllerHelper.ok(checkFieldsAndParseCountries(fields, countries));
|
||||
}
|
||||
return ControllerHelper.notFound();
|
||||
} catch (Exception e) {
|
||||
return ControllerHelper.internalError();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Get("demonym/{demonym}")
|
||||
public HttpResponse<Object> getByDemonym(@PathVariable("demonym") String demonym,
|
||||
@QueryParam("fields") Optional<String> fields) {
|
||||
try {
|
||||
var countries = CountryServiceV3.getInstance().getByDemonym(demonym);
|
||||
if (!countries.isEmpty()) {
|
||||
return ControllerHelper.ok(checkFieldsAndParseCountries(fields, countries));
|
||||
}
|
||||
return ControllerHelper.notFound();
|
||||
} catch (Exception e) {
|
||||
return ControllerHelper.internalError();
|
||||
}
|
||||
}
|
||||
|
||||
@Get("translation/{translation}")
|
||||
public HttpResponse<Object> getByTranslation(@PathVariable("translation") String translation,
|
||||
@QueryParam("fields") Optional<String> fields) {
|
||||
try {
|
||||
var countries = CountryServiceV3.getInstance().getByTranslation(translation);
|
||||
if (!countries.isEmpty()) {
|
||||
return ControllerHelper.ok(checkFieldsAndParseCountries(fields, countries));
|
||||
}
|
||||
return ControllerHelper.notFound();
|
||||
} catch (Exception e) {
|
||||
return ControllerHelper.internalError();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,210 @@
|
||||
package com.restcountries.controller;
|
||||
|
||||
import com.restcountries.service.v3.v31.CountryServiceV31;
|
||||
import io.micronaut.http.HttpResponse;
|
||||
import io.micronaut.http.MediaType;
|
||||
import io.micronaut.http.annotation.Controller;
|
||||
import io.micronaut.http.annotation.Get;
|
||||
import io.micronaut.http.annotation.PathVariable;
|
||||
import io.micronaut.http.annotation.QueryValue;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
|
||||
import javax.ws.rs.QueryParam;
|
||||
import javax.ws.rs.core.Response;
|
||||
import java.util.Optional;
|
||||
|
||||
import static com.restcountries.controller.ControllerHelper.hasInvalidFields;
|
||||
|
||||
@Controller("/v3.1/")
|
||||
public class CountryControllerV31 extends ControllerV3Helper {
|
||||
|
||||
@Get(uri = "all", produces = MediaType.APPLICATION_JSON)
|
||||
@Schema(name = "RestCountries")
|
||||
public Object getAllCountries(@QueryValue("fields") Optional<String> fields) {
|
||||
if (hasInvalidFields(fields)) {
|
||||
return ControllerHelper.badAllRequest();
|
||||
}
|
||||
var countries = CountryServiceV31.getInstance().getAll();
|
||||
return ControllerHelper.ok(checkFieldsAndParseCountries(fields, countries));
|
||||
}
|
||||
|
||||
@Get("alpha/{alphacode}")
|
||||
@Schema(name = "RestCountries")
|
||||
public Object getByAlpha(@PathVariable("alphacode") String alpha,
|
||||
@QueryValue("fields") Optional<String> fields) {
|
||||
if (alpha.contains("codes")) {
|
||||
alpha = alpha.replace("codes=", "");
|
||||
}
|
||||
if (isEmpty(alpha) || alpha.length() < 2 || alpha.length() > 3) {
|
||||
return ControllerHelper.badRequest();
|
||||
}
|
||||
var country = CountryServiceV31.getInstance().getByAlpha(alpha);
|
||||
if (country != null && !country.isEmpty()) {
|
||||
return ControllerHelper.ok(checkFieldsAndParseCountry(country, fields));
|
||||
}
|
||||
return ControllerHelper.notFound();
|
||||
}
|
||||
|
||||
@Get("alpha/")
|
||||
@Schema(name = "RestCountries")
|
||||
public Object getByAlphaList(@QueryParam("codes") String codes,
|
||||
@QueryParam("fields") Optional<String> fields) {
|
||||
if (isEmpty(codes) || codes.length() < 2 || (codes.length() > 3 && !codes.contains(","))) {
|
||||
return ControllerHelper.badRequest();
|
||||
}
|
||||
try {
|
||||
var countries = CountryServiceV31.getInstance().getByCodeList(codes);
|
||||
if (!countries.isEmpty()) {
|
||||
return ControllerHelper.ok(checkFieldsAndParseCountries(fields, countries));
|
||||
}
|
||||
return ControllerHelper.notFound();
|
||||
} catch (Exception e) {
|
||||
return ControllerHelper.internalError();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Get("currency/{currency}")
|
||||
@Schema(name = "RestCountries")
|
||||
public Object getByCurrency(@PathVariable("currency") String currency,
|
||||
@QueryParam("fields") Optional<String> fields) {
|
||||
if (isEmpty(currency)) {
|
||||
return ControllerHelper.badRequest();
|
||||
}
|
||||
try {
|
||||
var countries = CountryServiceV31.getInstance().getByCurrency(currency);
|
||||
if (!countries.isEmpty()) {
|
||||
return ControllerHelper.ok(checkFieldsAndParseCountries(fields, countries));
|
||||
}
|
||||
return ControllerHelper.notFound();
|
||||
} catch (Exception e) {
|
||||
return ControllerHelper.internalError();
|
||||
}
|
||||
}
|
||||
|
||||
@Get("name/{name}")
|
||||
@Schema(name = "RestCountries")
|
||||
public Object getByName(@PathVariable("name") String name,
|
||||
@QueryParam("fullText") Optional<Boolean> fullText,
|
||||
@QueryParam("fields") Optional<String> fields) {
|
||||
try {
|
||||
var countries = CountryServiceV31.getInstance().getByName(name, fullText.orElse(false));
|
||||
if (!countries.isEmpty()) {
|
||||
return ControllerHelper.ok(checkFieldsAndParseCountries(fields, countries));
|
||||
}
|
||||
return ControllerHelper.notFound();
|
||||
} catch (Exception e) {
|
||||
return HttpResponse.serverError(Response.Status.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
@Get("capital/{capital}")
|
||||
@Schema(name = "RestCountries")
|
||||
public Object getByCapital(@PathVariable("capital") String capital,
|
||||
@QueryParam("fields") Optional<String> fields) {
|
||||
try {
|
||||
var countries = CountryServiceV31.getInstance().getByCapital(capital);
|
||||
if (!countries.isEmpty()) {
|
||||
return ControllerHelper.ok(checkFieldsAndParseCountries(fields, countries));
|
||||
}
|
||||
return ControllerHelper.notFound();
|
||||
} catch (Exception e) {
|
||||
return HttpResponse.serverError(Response.Status.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Get("region/{region}")
|
||||
@Schema(name = "RestCountries")
|
||||
public Object getByContinent(@PathVariable("region") String region,
|
||||
@QueryParam("fields") Optional<String> fields) {
|
||||
try {
|
||||
var countries = CountryServiceV31.getInstance().getByRegion(region);
|
||||
if (!countries.isEmpty()) {
|
||||
return ControllerHelper.ok(checkFieldsAndParseCountries(fields, countries));
|
||||
}
|
||||
return ControllerHelper.notFound();
|
||||
} catch (Exception e) {
|
||||
return HttpResponse.serverError(Response.Status.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
@Get("subregion/{subregion}")
|
||||
@Schema(name = "RestCountries")
|
||||
public Object getBySubRegion(@PathVariable("subregion") String subregion,
|
||||
@QueryParam("fields") Optional<String> fields) {
|
||||
try {
|
||||
var countries = CountryServiceV31.getInstance().getBySubregion(subregion);
|
||||
if (!countries.isEmpty()) {
|
||||
return ControllerHelper.ok(checkFieldsAndParseCountries(fields, countries));
|
||||
}
|
||||
return ControllerHelper.notFound();
|
||||
} catch (Exception e) {
|
||||
return HttpResponse.serverError(Response.Status.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
@Get("lang/{lang}")
|
||||
@Schema(name = "RestCountries")
|
||||
public Object getByLanguage(@PathVariable("lang") String language,
|
||||
@QueryParam("fields") Optional<String> fields) {
|
||||
try {
|
||||
var countries = CountryServiceV31.getInstance().getByLanguage(language);
|
||||
if (!countries.isEmpty()) {
|
||||
return ControllerHelper.ok(checkFieldsAndParseCountries(fields, countries));
|
||||
}
|
||||
return ControllerHelper.notFound();
|
||||
} catch (Exception e) {
|
||||
return HttpResponse.serverError(Response.Status.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Get("demonym/{demonym}")
|
||||
@Schema(name = "RestCountries")
|
||||
public Object getByDemonym(@PathVariable("demonym") String demonym,
|
||||
@QueryParam("fields") Optional<String> fields) {
|
||||
try {
|
||||
var countries = CountryServiceV31.getInstance().getByDemonym(demonym);
|
||||
if (!countries.isEmpty()) {
|
||||
return ControllerHelper.ok(checkFieldsAndParseCountries(fields, countries));
|
||||
}
|
||||
return ControllerHelper.notFound();
|
||||
} catch (Exception e) {
|
||||
return HttpResponse.serverError(Response.Status.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
@Get("translation/{translation}")
|
||||
@Schema(name = "RestCountries")
|
||||
public Object getByTranslation(@PathVariable("translation") String translation,
|
||||
@QueryParam("fields") Optional<String> fields) {
|
||||
try {
|
||||
var countries = CountryServiceV31.getInstance().getByTranslation(translation);
|
||||
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")
|
||||
@Schema(name = "RestCountries")
|
||||
public Object getIndependentCountries(@QueryParam("status") Optional<Boolean> status, @QueryParam("fields") Optional<String> fields) {
|
||||
try {
|
||||
var result = true;
|
||||
if (status.isPresent()) {
|
||||
result = Boolean.TRUE.equals(status.get());
|
||||
}
|
||||
var countries = CountryServiceV31.getInstance().getIndependent(result);
|
||||
if (!countries.isEmpty()) {
|
||||
return ControllerHelper.ok(checkFieldsAndParseCountries(fields, countries));
|
||||
}
|
||||
return ControllerHelper.notFound();
|
||||
} catch (Exception e) {
|
||||
return HttpResponse.serverError(Response.Status.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,208 @@
|
||||
package com.restcountries.controller;
|
||||
|
||||
import com.restcountries.service.v4.CountryServiceV4;
|
||||
import io.micronaut.http.HttpResponse;
|
||||
import io.micronaut.http.MediaType;
|
||||
import io.micronaut.http.annotation.Controller;
|
||||
import io.micronaut.http.annotation.Get;
|
||||
import io.micronaut.http.annotation.PathVariable;
|
||||
import io.micronaut.http.annotation.QueryValue;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
|
||||
import javax.ws.rs.QueryParam;
|
||||
import javax.ws.rs.core.Response;
|
||||
import java.util.Optional;
|
||||
|
||||
import static com.restcountries.controller.ControllerHelper.hasInvalidFields;
|
||||
|
||||
@Controller("/v4/")
|
||||
public class CountryControllerV4 extends ControllerV4Helper {
|
||||
|
||||
@Get(uri = "all", produces = MediaType.APPLICATION_JSON)
|
||||
@Schema(name = "RestCountries")
|
||||
public Object getAllCountries(@QueryValue("fields") Optional<String> fields) {
|
||||
if (hasInvalidFields(fields)) {
|
||||
return ControllerHelper.badAllRequest();
|
||||
}
|
||||
var countries = CountryServiceV4.getInstance().getAll();
|
||||
return ControllerHelper.ok(checkFieldsAndParseCountries(fields, countries));
|
||||
}
|
||||
|
||||
@Get("alpha/{alphacode}")
|
||||
@Schema(name = "RestCountries")
|
||||
public Object getByAlpha(@PathVariable("alphacode") String alpha,
|
||||
@QueryValue("fields") Optional<String> fields) {
|
||||
if (alpha.contains("codes")) {
|
||||
alpha = alpha.replace("codes=", "");
|
||||
}
|
||||
if (isEmpty(alpha) || alpha.length() < 2 || alpha.length() > 3) {
|
||||
return ControllerHelper.badRequest();
|
||||
}
|
||||
var country = CountryServiceV4.getInstance().getByAlpha(alpha);
|
||||
if (country != null && !country.isEmpty()) {
|
||||
return ControllerHelper.ok(checkFieldsAndParseCountry(country, fields));
|
||||
}
|
||||
return ControllerHelper.notFound();
|
||||
}
|
||||
|
||||
@Get("alpha/")
|
||||
@Schema(name = "RestCountries")
|
||||
public Object getByAlphaList(@QueryParam("codes") String codes,
|
||||
@QueryParam("fields") Optional<String> fields) {
|
||||
if (isEmpty(codes) || codes.length() < 2 || (codes.length() > 3 && !codes.contains(","))) {
|
||||
return ControllerHelper.badRequest();
|
||||
}
|
||||
try {
|
||||
var countries = CountryServiceV4.getInstance().getByCodeList(codes);
|
||||
if (!countries.isEmpty()) {
|
||||
return ControllerHelper.ok(checkFieldsAndParseCountries(fields, countries));
|
||||
}
|
||||
return ControllerHelper.notFound();
|
||||
} catch (Exception e) {
|
||||
return ControllerHelper.internalError();
|
||||
}
|
||||
}
|
||||
|
||||
@Get("currency/{currency}")
|
||||
@Schema(name = "RestCountries")
|
||||
public Object getByCurrency(@PathVariable("currency") String currency,
|
||||
@QueryParam("fields") Optional<String> fields) {
|
||||
if (isEmpty(currency)) {
|
||||
return ControllerHelper.badRequest();
|
||||
}
|
||||
try {
|
||||
var countries = CountryServiceV4.getInstance().getByCurrency(currency);
|
||||
if (!countries.isEmpty()) {
|
||||
return ControllerHelper.ok(checkFieldsAndParseCountries(fields, countries));
|
||||
}
|
||||
return ControllerHelper.notFound();
|
||||
} catch (Exception e) {
|
||||
return ControllerHelper.internalError();
|
||||
}
|
||||
}
|
||||
|
||||
@Get("name/{name}")
|
||||
@Schema(name = "RestCountries")
|
||||
public Object getByName(@PathVariable("name") String name,
|
||||
@QueryParam("fullText") Optional<Boolean> fullText,
|
||||
@QueryParam("fields") Optional<String> fields) {
|
||||
try {
|
||||
var countries = CountryServiceV4.getInstance().getByName(name, fullText.orElse(false));
|
||||
if (!countries.isEmpty()) {
|
||||
return ControllerHelper.ok(checkFieldsAndParseCountries(fields, countries));
|
||||
}
|
||||
return ControllerHelper.notFound();
|
||||
} catch (Exception e) {
|
||||
return HttpResponse.serverError(Response.Status.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
@Get("capital/{capital}")
|
||||
@Schema(name = "RestCountries")
|
||||
public Object getByCapital(@PathVariable("capital") String capital,
|
||||
@QueryParam("fields") Optional<String> fields) {
|
||||
try {
|
||||
var countries = CountryServiceV4.getInstance().getByCapital(capital);
|
||||
if (!countries.isEmpty()) {
|
||||
return ControllerHelper.ok(checkFieldsAndParseCountries(fields, countries));
|
||||
}
|
||||
return ControllerHelper.notFound();
|
||||
} catch (Exception e) {
|
||||
return HttpResponse.serverError(Response.Status.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
@Get("region/{region}")
|
||||
@Schema(name = "RestCountries")
|
||||
public Object getByContinent(@PathVariable("region") String region,
|
||||
@QueryParam("fields") Optional<String> fields) {
|
||||
try {
|
||||
var countries = CountryServiceV4.getInstance().getByRegion(region);
|
||||
if (!countries.isEmpty()) {
|
||||
return ControllerHelper.ok(checkFieldsAndParseCountries(fields, countries));
|
||||
}
|
||||
return ControllerHelper.notFound();
|
||||
} catch (Exception e) {
|
||||
return HttpResponse.serverError(Response.Status.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
@Get("subregion/{subregion}")
|
||||
@Schema(name = "RestCountries")
|
||||
public Object getBySubRegion(@PathVariable("subregion") String subregion,
|
||||
@QueryParam("fields") Optional<String> fields) {
|
||||
try {
|
||||
var countries = CountryServiceV4.getInstance().getBySubregion(subregion);
|
||||
if (!countries.isEmpty()) {
|
||||
return ControllerHelper.ok(checkFieldsAndParseCountries(fields, countries));
|
||||
}
|
||||
return ControllerHelper.notFound();
|
||||
} catch (Exception e) {
|
||||
return HttpResponse.serverError(Response.Status.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
@Get("lang/{lang}")
|
||||
@Schema(name = "RestCountries")
|
||||
public Object getByLanguage(@PathVariable("lang") String language,
|
||||
@QueryParam("fields") Optional<String> fields) {
|
||||
try {
|
||||
var countries = CountryServiceV4.getInstance().getByLanguage(language);
|
||||
if (!countries.isEmpty()) {
|
||||
return ControllerHelper.ok(checkFieldsAndParseCountries(fields, countries));
|
||||
}
|
||||
return ControllerHelper.notFound();
|
||||
} catch (Exception e) {
|
||||
return HttpResponse.serverError(Response.Status.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
@Get("demonym/{demonym}")
|
||||
@Schema(name = "RestCountries")
|
||||
public Object getByDemonym(@PathVariable("demonym") String demonym,
|
||||
@QueryParam("fields") Optional<String> fields) {
|
||||
try {
|
||||
var countries = CountryServiceV4.getInstance().getByDemonym(demonym);
|
||||
if (!countries.isEmpty()) {
|
||||
return ControllerHelper.ok(checkFieldsAndParseCountries(fields, countries));
|
||||
}
|
||||
return ControllerHelper.notFound();
|
||||
} catch (Exception e) {
|
||||
return HttpResponse.serverError(Response.Status.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
@Get("translation/{translation}")
|
||||
@Schema(name = "RestCountries")
|
||||
public Object getByTranslation(@PathVariable("translation") String translation,
|
||||
@QueryParam("fields") Optional<String> fields) {
|
||||
try {
|
||||
var countries = CountryServiceV4.getInstance().getByTranslation(translation);
|
||||
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")
|
||||
@Schema(name = "RestCountries")
|
||||
public Object getIndependentCountries(@QueryParam("status") Optional<Boolean> status,
|
||||
@QueryParam("fields") Optional<String> fields) {
|
||||
try {
|
||||
var result = true;
|
||||
if (status.isPresent()) {
|
||||
result = Boolean.TRUE.equals(status.get());
|
||||
}
|
||||
var countries = CountryServiceV4.getInstance().getIndependent(result);
|
||||
if (!countries.isEmpty()) {
|
||||
return ControllerHelper.ok(checkFieldsAndParseCountries(fields, countries));
|
||||
}
|
||||
return ControllerHelper.notFound();
|
||||
} catch (Exception e) {
|
||||
return HttpResponse.serverError(Response.Status.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,11 @@
|
||||
package dev.amatos.restcountries.domain;
|
||||
package com.restcountries.domain;
|
||||
|
||||
import io.micronaut.serde.annotation.Serdeable;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Serdeable.Serializable
|
||||
public class BaseCountry {
|
||||
|
||||
protected String name;
|
||||
@@ -2,7 +2,7 @@
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
package dev.amatos.restcountries.domain;
|
||||
package com.restcountries.domain;
|
||||
|
||||
public interface ICountryRestSymbols {
|
||||
String COLON = ",";
|
||||
@@ -1,8 +1,11 @@
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
package dev.amatos.restcountries.domain;
|
||||
package com.restcountries.domain;
|
||||
|
||||
import io.micronaut.serde.annotation.Serdeable;
|
||||
|
||||
@Serdeable.Serializable
|
||||
public class ResponseEntity {
|
||||
|
||||
private final int status;
|
||||
@@ -0,0 +1,104 @@
|
||||
package com.restcountries.domain.base;
|
||||
|
||||
import io.micronaut.serde.annotation.Serdeable;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Serdeable.Serializable
|
||||
public class BaseCountry extends BaseCountryCore {
|
||||
|
||||
private Name name;
|
||||
private Map<String, Currency> currencies;
|
||||
private Map<String, String> languages;
|
||||
private Map<String, Map<String, String>> translations;
|
||||
private List<Double> latlng;
|
||||
private Map<String, Map<String, String>> demonyms;
|
||||
private Map<String, Double> gini;
|
||||
|
||||
public Name getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(Name name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public Map<String, Currency> getCurrencies() {
|
||||
return currencies;
|
||||
}
|
||||
|
||||
public void setCurrencies(
|
||||
Map<String, Currency> currencies) {
|
||||
this.currencies = currencies;
|
||||
}
|
||||
|
||||
public Map<String, String> getLanguages() {
|
||||
return languages;
|
||||
}
|
||||
|
||||
public void setLanguages(Map<String, String> languages) {
|
||||
this.languages = languages;
|
||||
}
|
||||
|
||||
public List<Double> getLatlng() {
|
||||
return latlng;
|
||||
}
|
||||
|
||||
public void setLatlng(List<Double> latlng) {
|
||||
this.latlng = latlng;
|
||||
}
|
||||
|
||||
public Map<String, Map<String, String>> getDemonyms() {
|
||||
return demonyms;
|
||||
}
|
||||
|
||||
public void setDemonyms(
|
||||
Map<String, Map<String, String>> demonyms) {
|
||||
this.demonyms = demonyms;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Country{" + "\n" +
|
||||
"NativeName=" + name.getNativeName() + "\n" +
|
||||
"Common=" + name.getCommon() + "\n" +
|
||||
"Official=" + name.getOfficial() + "\n" +
|
||||
", tld=" + getTld() + "\n" +
|
||||
", cca2='" + getCca2() + '\'' + "\n" +
|
||||
", ccn3='" + getCcn3() + '\'' + "\n" +
|
||||
", cioc='" + getCioc() + '\'' + "\n" +
|
||||
", independent=" + getIndependent() + "\n" +
|
||||
", status='" + getStatus() + '\'' + "\n" +
|
||||
", unMember=" + getUnMember() + "\n" +
|
||||
", currencies=" + currencies + "\n" +
|
||||
", idd=" + getIdd() + "\n" +
|
||||
", capital=" + getCapital() + "\n" +
|
||||
", altSpelling=" + getAltSpellings() + "\n" +
|
||||
", region='" + getRegion() + '\'' + "\n" +
|
||||
", subregion='" + getSubregion() + '\'' + "\n" +
|
||||
", language=" + languages + "\n" +
|
||||
", latlng=" + latlng + "\n" +
|
||||
", landlocked=" + getLandlocked() + "\n" +
|
||||
", borders=" + getBorders() + "\n" +
|
||||
", area=" + getArea() + "\n" +
|
||||
", demonyms=" + demonyms + "\n" +
|
||||
'}';
|
||||
}
|
||||
|
||||
public Map<String, Map<String, String>> getTranslations() {
|
||||
return translations;
|
||||
}
|
||||
|
||||
public void setTranslations(Map<String, Map<String, String>> translations) {
|
||||
this.translations = translations;
|
||||
}
|
||||
|
||||
public Map<String, Double> getGini() {
|
||||
return gini;
|
||||
}
|
||||
|
||||
public void setGini(Map<String, Double> gini) {
|
||||
this.gini = gini;
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,13 @@
|
||||
package dev.amatos.restcountries.domain.base;
|
||||
package com.restcountries.domain.base;
|
||||
|
||||
import io.micronaut.serde.annotation.Serdeable;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class BaseCountry {
|
||||
private Name name;
|
||||
@Serdeable.Serializable
|
||||
public abstract class BaseCountryCore {
|
||||
|
||||
private List<String> tld;
|
||||
private String cca2;
|
||||
private String ccn3;
|
||||
@@ -13,30 +16,22 @@ public class BaseCountry {
|
||||
private Boolean independent;
|
||||
private String status;
|
||||
private Boolean unMember;
|
||||
private Map<String, Currency> currencies;
|
||||
private Idd idd;
|
||||
private List<String> capital;
|
||||
private List<String> altSpellings;
|
||||
private String region;
|
||||
private String subregion;
|
||||
private Map<String, String> languages;
|
||||
private Map<String, Map<String, String>> translations;
|
||||
private List<Double> latlng;
|
||||
private Boolean landlocked;
|
||||
private List<String> borders;
|
||||
private Double area;
|
||||
private Map<String, Map<String, String>> demonyms;
|
||||
private List<String> callingCodes;
|
||||
private String flag;
|
||||
private Map<String, String> maps;
|
||||
|
||||
public Name getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(Name name) {
|
||||
this.name = name;
|
||||
}
|
||||
private Integer population;
|
||||
private String fifa;
|
||||
private Car car;
|
||||
private List<String> timezones;
|
||||
private List<String> continents;
|
||||
|
||||
public List<String> getTld() {
|
||||
return tld;
|
||||
@@ -62,6 +57,14 @@ public class BaseCountry {
|
||||
this.ccn3 = ccn3;
|
||||
}
|
||||
|
||||
public String getCca3() {
|
||||
return cca3;
|
||||
}
|
||||
|
||||
public void setCca3(String cca3) {
|
||||
this.cca3 = cca3;
|
||||
}
|
||||
|
||||
public String getCioc() {
|
||||
return cioc;
|
||||
}
|
||||
@@ -94,15 +97,6 @@ public class BaseCountry {
|
||||
this.unMember = unMember;
|
||||
}
|
||||
|
||||
public Map<String, Currency> getCurrencies() {
|
||||
return currencies;
|
||||
}
|
||||
|
||||
public void setCurrencies(
|
||||
Map<String, Currency> currencies) {
|
||||
this.currencies = currencies;
|
||||
}
|
||||
|
||||
public Idd getIdd() {
|
||||
return idd;
|
||||
}
|
||||
@@ -143,22 +137,6 @@ public class BaseCountry {
|
||||
this.subregion = subregion;
|
||||
}
|
||||
|
||||
public Map<String, String> getLanguages() {
|
||||
return languages;
|
||||
}
|
||||
|
||||
public void setLanguages(Map<String, String> languages) {
|
||||
this.languages = languages;
|
||||
}
|
||||
|
||||
public List<Double> getLatlng() {
|
||||
return latlng;
|
||||
}
|
||||
|
||||
public void setLatlng(List<Double> latlng) {
|
||||
this.latlng = latlng;
|
||||
}
|
||||
|
||||
public Boolean getLandlocked() {
|
||||
return landlocked;
|
||||
}
|
||||
@@ -183,59 +161,6 @@ public class BaseCountry {
|
||||
this.area = area;
|
||||
}
|
||||
|
||||
public Map<String, Map<String, String>> getDemonyms() {
|
||||
return demonyms;
|
||||
}
|
||||
|
||||
public void setDemonyms(
|
||||
Map<String, Map<String, String>> demonyms) {
|
||||
this.demonyms = demonyms;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Country{" + "\n" +
|
||||
"NativeName=" + name.getNativeName() + "\n" +
|
||||
"Common=" + name.getCommon() + "\n" +
|
||||
"Official=" + name.getOfficial() + "\n" +
|
||||
", tld=" + tld + "\n" +
|
||||
", cca2='" + cca2 + '\'' + "\n" +
|
||||
", ccn3='" + ccn3 + '\'' + "\n" +
|
||||
", cioc='" + cioc + '\'' + "\n" +
|
||||
", independent=" + independent + "\n" +
|
||||
", status='" + status + '\'' + "\n" +
|
||||
", unMember=" + unMember + "\n" +
|
||||
", currencies=" + currencies + "\n" +
|
||||
", idd=" + idd + "\n" +
|
||||
", capital=" + capital + "\n" +
|
||||
", altSpelling=" + altSpellings + "\n" +
|
||||
", region='" + region + '\'' + "\n" +
|
||||
", subregion='" + subregion + '\'' + "\n" +
|
||||
", language=" + languages + "\n" +
|
||||
", latlng=" + latlng + "\n" +
|
||||
", landlocked=" + landlocked + "\n" +
|
||||
", borders=" + borders + "\n" +
|
||||
", area=" + area + "\n" +
|
||||
", demonyms=" + demonyms + "\n" +
|
||||
'}';
|
||||
}
|
||||
|
||||
public String getCca3() {
|
||||
return cca3;
|
||||
}
|
||||
|
||||
public void setCca3(String cca3) {
|
||||
this.cca3 = cca3;
|
||||
}
|
||||
|
||||
public Map<String, Map<String, String>> getTranslations() {
|
||||
return translations;
|
||||
}
|
||||
|
||||
public void setTranslations(Map<String, Map<String, String>> translations) {
|
||||
this.translations = translations;
|
||||
}
|
||||
|
||||
public List<String> getCallingCodes() {
|
||||
return callingCodes;
|
||||
}
|
||||
@@ -259,4 +184,44 @@ public class BaseCountry {
|
||||
public void setMaps(Map<String, String> maps) {
|
||||
this.maps = maps;
|
||||
}
|
||||
|
||||
public Integer getPopulation() {
|
||||
return population;
|
||||
}
|
||||
|
||||
public void setPopulation(Integer population) {
|
||||
this.population = population;
|
||||
}
|
||||
|
||||
public String getFifa() {
|
||||
return fifa;
|
||||
}
|
||||
|
||||
public void setFifa(String fifa) {
|
||||
this.fifa = fifa;
|
||||
}
|
||||
|
||||
public Car getCar() {
|
||||
return car;
|
||||
}
|
||||
|
||||
public void setCar(Car car) {
|
||||
this.car = car;
|
||||
}
|
||||
|
||||
public List<String> getTimezones() {
|
||||
return timezones;
|
||||
}
|
||||
|
||||
public void setTimezones(List<String> timezones) {
|
||||
this.timezones = timezones;
|
||||
}
|
||||
|
||||
public List<String> getContinents() {
|
||||
return continents;
|
||||
}
|
||||
|
||||
public void setContinents(List<String> continents) {
|
||||
this.continents = continents;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package com.restcountries.domain.base;
|
||||
|
||||
import io.micronaut.serde.annotation.Serdeable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Serdeable.Serializable
|
||||
public class Car {
|
||||
private List<String> signs;
|
||||
private String side;
|
||||
|
||||
public List<String> getSigns() {
|
||||
return signs;
|
||||
}
|
||||
|
||||
public void setSigns(List<String> signs) {
|
||||
this.signs = signs;
|
||||
}
|
||||
|
||||
public String getSide() {
|
||||
return side;
|
||||
}
|
||||
|
||||
public void setSide(String side) {
|
||||
this.side = side;
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,8 @@
|
||||
package dev.amatos.restcountries.domain.base;
|
||||
package com.restcountries.domain.base;
|
||||
|
||||
import io.micronaut.serde.annotation.Serdeable;
|
||||
|
||||
@Serdeable.Serializable
|
||||
public class Currency {
|
||||
private String name;
|
||||
private String symbol;
|
||||
@@ -1,7 +1,10 @@
|
||||
package dev.amatos.restcountries.domain.base;
|
||||
package com.restcountries.domain.base;
|
||||
|
||||
import io.micronaut.serde.annotation.Serdeable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Serdeable.Serializable
|
||||
public class Idd {
|
||||
private String root;
|
||||
private List<String> suffixes;
|
||||
@@ -1,12 +1,18 @@
|
||||
package dev.amatos.restcountries.domain.base;
|
||||
package com.restcountries.domain.base;
|
||||
|
||||
import io.micronaut.serde.annotation.Serdeable;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Serdeable.Serializable
|
||||
public class Name {
|
||||
private String common;
|
||||
private String official;
|
||||
private Map<String, NativeName> nativeName;
|
||||
|
||||
private List<String> altSpellings;
|
||||
|
||||
public String getCommon() {
|
||||
return common;
|
||||
}
|
||||
@@ -31,4 +37,12 @@ public class Name {
|
||||
Map<String, NativeName> nativeName) {
|
||||
this.nativeName = nativeName;
|
||||
}
|
||||
|
||||
public List<String> getAltSpellings() {
|
||||
return altSpellings;
|
||||
}
|
||||
|
||||
public void setAltSpellings(List<String> altSpellings) {
|
||||
this.altSpellings = altSpellings;
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,8 @@
|
||||
package dev.amatos.restcountries.domain.base;
|
||||
package com.restcountries.domain.base;
|
||||
|
||||
import io.micronaut.serde.annotation.Serdeable;
|
||||
|
||||
@Serdeable.Serializable
|
||||
public class NativeName {
|
||||
private String official;
|
||||
private String common;
|
||||
@@ -1,4 +1,4 @@
|
||||
package dev.amatos.restcountries.domain.v2;
|
||||
package com.restcountries.domain.v2;
|
||||
|
||||
/**
|
||||
* Created by fayder on 24/02/2017.
|
||||
@@ -1,13 +1,14 @@
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
package dev.amatos.restcountries.domain.v2;
|
||||
package com.restcountries.domain.v2;
|
||||
|
||||
import com.restcountries.domain.BaseCountry;
|
||||
import io.micronaut.serde.annotation.Serdeable;
|
||||
|
||||
import dev.amatos.restcountries.domain.BaseCountry;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Serdeable.Serializable
|
||||
public class Country extends BaseCountry {
|
||||
|
||||
private List<Currency> currencies;
|
||||
@@ -1,8 +1,11 @@
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
package dev.amatos.restcountries.domain.v2;
|
||||
package com.restcountries.domain.v2;
|
||||
|
||||
import io.micronaut.serde.annotation.Serdeable;
|
||||
|
||||
@Serdeable.Serializable
|
||||
public class Currency {
|
||||
|
||||
private String code;
|
||||
@@ -1,5 +1,8 @@
|
||||
package dev.amatos.restcountries.domain.v2;
|
||||
package com.restcountries.domain.v2;
|
||||
|
||||
import io.micronaut.serde.annotation.Serdeable;
|
||||
|
||||
@Serdeable.Serializable
|
||||
public class Flag {
|
||||
private String svg;
|
||||
private String png;
|
||||
@@ -1,8 +1,11 @@
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
package dev.amatos.restcountries.domain.v2;
|
||||
package com.restcountries.domain.v2;
|
||||
|
||||
import io.micronaut.serde.annotation.Serdeable;
|
||||
|
||||
@Serdeable.Serializable
|
||||
public class Language {
|
||||
|
||||
private String iso639_1;
|
||||
@@ -1,5 +1,8 @@
|
||||
package dev.amatos.restcountries.domain.v2;
|
||||
package com.restcountries.domain.v2;
|
||||
|
||||
import io.micronaut.serde.annotation.Serdeable;
|
||||
|
||||
@Serdeable.Serializable
|
||||
public class Maps {
|
||||
private String gmaps;
|
||||
private String openstreetmap;
|
||||
@@ -1,4 +1,6 @@
|
||||
package dev.amatos.restcountries.domain.v2;
|
||||
package com.restcountries.domain.v2;
|
||||
|
||||
import io.micronaut.serde.annotation.Serdeable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -6,6 +8,7 @@ import java.util.List;
|
||||
/**
|
||||
* Created by fayder on 30/04/2017.
|
||||
*/
|
||||
@Serdeable.Serializable
|
||||
public class RegionalBloc {
|
||||
|
||||
private String acronym;
|
||||
@@ -1,9 +1,12 @@
|
||||
package dev.amatos.restcountries.domain.v2;
|
||||
package com.restcountries.domain.v2;
|
||||
|
||||
|
||||
import io.micronaut.serde.annotation.Serdeable;
|
||||
|
||||
/**
|
||||
* Created by fayder on 05/03/2017.
|
||||
*/
|
||||
@Serdeable.Serializable
|
||||
public class Translations {
|
||||
|
||||
private String br;
|
||||
@@ -1,8 +1,11 @@
|
||||
package dev.amatos.restcountries.domain.v3;
|
||||
package com.restcountries.domain.v3;
|
||||
|
||||
import com.restcountries.domain.base.BaseCountry;
|
||||
import io.micronaut.serde.annotation.Serdeable;
|
||||
|
||||
import dev.amatos.restcountries.domain.base.BaseCountry;
|
||||
import java.util.List;
|
||||
|
||||
@Serdeable.Serializable
|
||||
public class Country extends BaseCountry {
|
||||
private List<String> flags;
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.restcountries.domain.v3.v31;
|
||||
|
||||
import io.micronaut.serde.annotation.Serdeable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Serdeable.Serializable
|
||||
public class CapitalInformation {
|
||||
|
||||
private List<Double> latlng;
|
||||
|
||||
public List<Double> getLatlng() {
|
||||
return latlng;
|
||||
}
|
||||
|
||||
public void setLatlng(List<Double> latlng) {
|
||||
this.latlng = latlng;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
package com.restcountries.domain.v3.v31;
|
||||
|
||||
import com.restcountries.domain.base.BaseCountry;
|
||||
import io.micronaut.serde.annotation.Serdeable;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@Serdeable.Serializable
|
||||
public class Country extends BaseCountry {
|
||||
private Flag flags;
|
||||
private Flag coatOfArms;
|
||||
private String startOfWeek;
|
||||
private CapitalInformation capitalInfo;
|
||||
private Map<String, String> postalCode;
|
||||
|
||||
public Flag getFlags() {
|
||||
return flags;
|
||||
}
|
||||
|
||||
public void setFlags(Flag flags) {
|
||||
this.flags = flags;
|
||||
}
|
||||
|
||||
public Flag getCoatOfArms() {
|
||||
return coatOfArms;
|
||||
}
|
||||
|
||||
public void setCoatOfArms(Flag coatOfArms) {
|
||||
this.coatOfArms = coatOfArms;
|
||||
}
|
||||
|
||||
public String getStartOfWeek() {
|
||||
return startOfWeek;
|
||||
}
|
||||
|
||||
public void setStartOfWeek(String startOfWeek) {
|
||||
this.startOfWeek = startOfWeek;
|
||||
}
|
||||
|
||||
public CapitalInformation getCapitalInfo() {
|
||||
return capitalInfo;
|
||||
}
|
||||
|
||||
public void setCapitalInfo(CapitalInformation capitalInfo) {
|
||||
this.capitalInfo = capitalInfo;
|
||||
}
|
||||
|
||||
public Map<String, String> getPostalCode() {
|
||||
return postalCode;
|
||||
}
|
||||
|
||||
public void setPostalCode(Map<String, String> postalCode) {
|
||||
this.postalCode = postalCode;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package com.restcountries.domain.v3.v31;
|
||||
|
||||
import io.micronaut.serde.annotation.Serdeable;
|
||||
|
||||
@Serdeable.Serializable
|
||||
public class Flag {
|
||||
private String png;
|
||||
private String svg;
|
||||
private String alt;
|
||||
|
||||
public String getPng() {
|
||||
return png;
|
||||
}
|
||||
|
||||
public void setPng(String png) {
|
||||
this.png = png;
|
||||
}
|
||||
|
||||
public String getSvg() {
|
||||
return svg;
|
||||
}
|
||||
|
||||
public void setSvg(String svg) {
|
||||
this.svg = svg;
|
||||
}
|
||||
|
||||
public String getAlt() {
|
||||
return alt;
|
||||
}
|
||||
|
||||
public void setAlt(String alt) {
|
||||
this.alt = alt;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,203 @@
|
||||
package com.restcountries.domain.v4;
|
||||
|
||||
import com.restcountries.domain.base.BaseCountryCore;
|
||||
import com.restcountries.domain.v3.v31.CapitalInformation;
|
||||
import com.restcountries.domain.v3.v31.Flag;
|
||||
import io.micronaut.serde.annotation.Serdeable;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Serdeable.Serializable
|
||||
public class Country extends BaseCountryCore {
|
||||
|
||||
private Name name;
|
||||
private List<Currency> currencies;
|
||||
private List<Language> languages;
|
||||
private List<Translation> translations;
|
||||
private List<Demonym> demonyms;
|
||||
private List<Gini> gini;
|
||||
private Flag flags;
|
||||
private Flag coatOfArms;
|
||||
private String startOfWeek;
|
||||
private CapitalInformation capitalInfo;
|
||||
private Map<String, String> postalCode;
|
||||
private Geolocation geolocation;
|
||||
private List<Religion> religion;
|
||||
private List<Ethnicity> ethnicity;
|
||||
private Government government;
|
||||
private Double density;
|
||||
private GDP gdp;
|
||||
private String nationalHoliday;
|
||||
private String anthem;
|
||||
private List<RegionalBloc> regionalBlocs;
|
||||
private Double hdi;
|
||||
|
||||
public Name getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(Name name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public List<Currency> getCurrencies() {
|
||||
return currencies;
|
||||
}
|
||||
|
||||
public void setCurrencies(List<Currency> currencies) {
|
||||
this.currencies = currencies;
|
||||
}
|
||||
|
||||
public List<Language> getLanguages() {
|
||||
return languages;
|
||||
}
|
||||
|
||||
public void setLanguages(List<Language> languages) {
|
||||
this.languages = languages;
|
||||
}
|
||||
|
||||
public List<Translation> getTranslations() {
|
||||
return translations;
|
||||
}
|
||||
|
||||
public void setTranslations(List<Translation> translations) {
|
||||
this.translations = translations;
|
||||
}
|
||||
|
||||
public List<Demonym> getDemonyms() {
|
||||
return demonyms;
|
||||
}
|
||||
|
||||
public void setDemonyms(List<Demonym> demonyms) {
|
||||
this.demonyms = demonyms;
|
||||
}
|
||||
|
||||
public List<Gini> getGini() {
|
||||
return gini;
|
||||
}
|
||||
|
||||
public void setGini(List<Gini> gini) {
|
||||
this.gini = gini;
|
||||
}
|
||||
|
||||
public Flag getFlags() {
|
||||
return flags;
|
||||
}
|
||||
|
||||
public void setFlags(Flag flags) {
|
||||
this.flags = flags;
|
||||
}
|
||||
|
||||
public Flag getCoatOfArms() {
|
||||
return coatOfArms;
|
||||
}
|
||||
|
||||
public void setCoatOfArms(Flag coatOfArms) {
|
||||
this.coatOfArms = coatOfArms;
|
||||
}
|
||||
|
||||
public String getStartOfWeek() {
|
||||
return startOfWeek;
|
||||
}
|
||||
|
||||
public void setStartOfWeek(String startOfWeek) {
|
||||
this.startOfWeek = startOfWeek;
|
||||
}
|
||||
|
||||
public CapitalInformation getCapitalInfo() {
|
||||
return capitalInfo;
|
||||
}
|
||||
|
||||
public void setCapitalInfo(CapitalInformation capitalInfo) {
|
||||
this.capitalInfo = capitalInfo;
|
||||
}
|
||||
|
||||
public Map<String, String> getPostalCode() {
|
||||
return postalCode;
|
||||
}
|
||||
|
||||
public void setPostalCode(Map<String, String> postalCode) {
|
||||
this.postalCode = postalCode;
|
||||
}
|
||||
|
||||
public Geolocation getGeolocation() {
|
||||
return geolocation;
|
||||
}
|
||||
|
||||
public void setGeolocation(Geolocation geolocation) {
|
||||
this.geolocation = geolocation;
|
||||
}
|
||||
|
||||
public List<Religion> getReligion() {
|
||||
return religion;
|
||||
}
|
||||
|
||||
public void setReligion(List<Religion> religion) {
|
||||
this.religion = religion;
|
||||
}
|
||||
|
||||
public List<Ethnicity> getEthnicity() {
|
||||
return ethnicity;
|
||||
}
|
||||
|
||||
public void setEthnicity(List<Ethnicity> ethnicity) {
|
||||
this.ethnicity = ethnicity;
|
||||
}
|
||||
|
||||
public Government getGovernment() {
|
||||
return government;
|
||||
}
|
||||
|
||||
public void setGovernment(Government government) {
|
||||
this.government = government;
|
||||
}
|
||||
|
||||
public Double getDensity() {
|
||||
return density;
|
||||
}
|
||||
|
||||
public void setDensity(Double density) {
|
||||
this.density = density;
|
||||
}
|
||||
|
||||
public GDP getGdp() {
|
||||
return gdp;
|
||||
}
|
||||
|
||||
public void setGdp(GDP gdp) {
|
||||
this.gdp = gdp;
|
||||
}
|
||||
|
||||
public String getNationalHoliday() {
|
||||
return nationalHoliday;
|
||||
}
|
||||
|
||||
public void setNationalHoliday(String nationalHoliday) {
|
||||
this.nationalHoliday = nationalHoliday;
|
||||
}
|
||||
|
||||
public String getAnthem() {
|
||||
return anthem;
|
||||
}
|
||||
|
||||
public void setAnthem(String anthem) {
|
||||
this.anthem = anthem;
|
||||
}
|
||||
|
||||
public List<RegionalBloc> getRegionalBlocs() {
|
||||
return regionalBlocs;
|
||||
}
|
||||
|
||||
public void setRegionalBlocs(List<RegionalBloc> regionalBlocs) {
|
||||
this.regionalBlocs = regionalBlocs;
|
||||
}
|
||||
|
||||
public Double getHdi() {
|
||||
return hdi;
|
||||
}
|
||||
|
||||
public void setHdi(Double hdi) {
|
||||
this.hdi = hdi;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package com.restcountries.domain.v4;
|
||||
|
||||
import io.micronaut.serde.annotation.Serdeable;
|
||||
|
||||
@Serdeable.Serializable
|
||||
public class Currency {
|
||||
private String code;
|
||||
private String name;
|
||||
private String symbol;
|
||||
|
||||
public String getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public void setCode(String code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getSymbol() {
|
||||
return symbol;
|
||||
}
|
||||
|
||||
public void setSymbol(String symbol) {
|
||||
this.symbol = symbol;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package com.restcountries.domain.v4;
|
||||
|
||||
import io.micronaut.serde.annotation.Serdeable;
|
||||
|
||||
@Serdeable.Serializable
|
||||
public class Demonym {
|
||||
private String lang;
|
||||
private String male;
|
||||
private String female;
|
||||
|
||||
public String getLang() {
|
||||
return lang;
|
||||
}
|
||||
|
||||
public void setLang(String lang) {
|
||||
this.lang = lang;
|
||||
}
|
||||
|
||||
public String getMale() {
|
||||
return male;
|
||||
}
|
||||
|
||||
public void setMale(String male) {
|
||||
this.male = male;
|
||||
}
|
||||
|
||||
public String getFemale() {
|
||||
return female;
|
||||
}
|
||||
|
||||
public void setFemale(String female) {
|
||||
this.female = female;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.restcountries.domain.v4;
|
||||
|
||||
import io.micronaut.serde.annotation.Serdeable;
|
||||
|
||||
@Serdeable.Serializable
|
||||
public class Ethnicity {
|
||||
private String name;
|
||||
private Double percentage;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public Double getPercentage() {
|
||||
return percentage;
|
||||
}
|
||||
|
||||
public void setPercentage(Double percentage) {
|
||||
this.percentage = percentage;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.restcountries.domain.v4;
|
||||
|
||||
import io.micronaut.serde.annotation.Serdeable;
|
||||
|
||||
@Serdeable.Serializable
|
||||
public class GDP {
|
||||
private Long total;
|
||||
private Long perCapita;
|
||||
|
||||
public Long getTotal() {
|
||||
return total;
|
||||
}
|
||||
|
||||
public void setTotal(Long total) {
|
||||
this.total = total;
|
||||
}
|
||||
|
||||
public Long getPerCapita() {
|
||||
return perCapita;
|
||||
}
|
||||
|
||||
public void setPerCapita(Long perCapita) {
|
||||
this.perCapita = perCapita;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.restcountries.domain.v4;
|
||||
|
||||
import io.micronaut.serde.annotation.Serdeable;
|
||||
|
||||
@Serdeable.Serializable
|
||||
public class Geolocation {
|
||||
private Double latitude;
|
||||
private Double longitude;
|
||||
|
||||
public Double getLatitude() {
|
||||
return latitude;
|
||||
}
|
||||
|
||||
public void setLatitude(Double latitude) {
|
||||
this.latitude = latitude;
|
||||
}
|
||||
|
||||
public Double getLongitude() {
|
||||
return longitude;
|
||||
}
|
||||
|
||||
public void setLongitude(Double longitude) {
|
||||
this.longitude = longitude;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.restcountries.domain.v4;
|
||||
|
||||
import io.micronaut.serde.annotation.Serdeable;
|
||||
|
||||
@Serdeable.Serializable
|
||||
public class Gini {
|
||||
private String year;
|
||||
private Double value;
|
||||
|
||||
public String getYear() {
|
||||
return year;
|
||||
}
|
||||
|
||||
public void setYear(String year) {
|
||||
this.year = year;
|
||||
}
|
||||
|
||||
public Double getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public void setValue(Double value) {
|
||||
this.value = value;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package com.restcountries.domain.v4;
|
||||
|
||||
import io.micronaut.serde.annotation.Serdeable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Serdeable.Serializable
|
||||
public class Government {
|
||||
private String type;
|
||||
private List<Leader> leaders;
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public List<Leader> getLeaders() {
|
||||
return leaders;
|
||||
}
|
||||
|
||||
public void setLeaders(List<Leader> leaders) {
|
||||
this.leaders = leaders;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package com.restcountries.domain.v4;
|
||||
|
||||
import io.micronaut.serde.annotation.Serdeable;
|
||||
|
||||
@Serdeable.Serializable
|
||||
public class Language {
|
||||
private String iso639_1;
|
||||
private String iso639_2;
|
||||
private String name;
|
||||
private String nativeName;
|
||||
|
||||
public String getIso639_1() {
|
||||
return iso639_1;
|
||||
}
|
||||
|
||||
public void setIso639_1(String iso639_1) {
|
||||
this.iso639_1 = iso639_1;
|
||||
}
|
||||
|
||||
public String getIso639_2() {
|
||||
return iso639_2;
|
||||
}
|
||||
|
||||
public void setIso639_2(String iso639_2) {
|
||||
this.iso639_2 = iso639_2;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getNativeName() {
|
||||
return nativeName;
|
||||
}
|
||||
|
||||
public void setNativeName(String nativeName) {
|
||||
this.nativeName = nativeName;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.restcountries.domain.v4;
|
||||
|
||||
import io.micronaut.serde.annotation.Serdeable;
|
||||
|
||||
@Serdeable.Serializable
|
||||
public class Leader {
|
||||
private String title;
|
||||
private String name;
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
public void setTitle(String title) {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package com.restcountries.domain.v4;
|
||||
|
||||
import io.micronaut.serde.annotation.Serdeable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Serdeable.Serializable
|
||||
public class Name {
|
||||
private String common;
|
||||
private String official;
|
||||
private List<NativeName> nativeName;
|
||||
|
||||
public String getCommon() {
|
||||
return common;
|
||||
}
|
||||
|
||||
public void setCommon(String common) {
|
||||
this.common = common;
|
||||
}
|
||||
|
||||
public String getOfficial() {
|
||||
return official;
|
||||
}
|
||||
|
||||
public void setOfficial(String official) {
|
||||
this.official = official;
|
||||
}
|
||||
|
||||
public List<NativeName> getNativeName() {
|
||||
return nativeName;
|
||||
}
|
||||
|
||||
public void setNativeName(List<NativeName> nativeName) {
|
||||
this.nativeName = nativeName;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package com.restcountries.domain.v4;
|
||||
|
||||
import io.micronaut.serde.annotation.Serdeable;
|
||||
|
||||
@Serdeable.Serializable
|
||||
public class NativeName {
|
||||
private String lang;
|
||||
private String official;
|
||||
private String common;
|
||||
|
||||
public String getLang() {
|
||||
return lang;
|
||||
}
|
||||
|
||||
public void setLang(String lang) {
|
||||
this.lang = lang;
|
||||
}
|
||||
|
||||
public String getOfficial() {
|
||||
return official;
|
||||
}
|
||||
|
||||
public void setOfficial(String official) {
|
||||
this.official = official;
|
||||
}
|
||||
|
||||
public String getCommon() {
|
||||
return common;
|
||||
}
|
||||
|
||||
public void setCommon(String common) {
|
||||
this.common = common;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package com.restcountries.domain.v4;
|
||||
|
||||
import io.micronaut.serde.annotation.Serdeable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Serdeable.Serializable
|
||||
public class RegionalBloc {
|
||||
private String acronym;
|
||||
private String name;
|
||||
private List<String> otherNames;
|
||||
|
||||
public String getAcronym() {
|
||||
return acronym;
|
||||
}
|
||||
|
||||
public void setAcronym(String acronym) {
|
||||
this.acronym = acronym;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public List<String> getOtherNames() {
|
||||
if (otherNames == null) {
|
||||
otherNames = new ArrayList<>();
|
||||
}
|
||||
return otherNames;
|
||||
}
|
||||
|
||||
public void setOtherNames(List<String> otherNames) {
|
||||
this.otherNames = otherNames;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package com.restcountries.domain.v4;
|
||||
|
||||
import io.micronaut.serde.annotation.Serdeable;
|
||||
|
||||
@Serdeable.Serializable
|
||||
public class Religion {
|
||||
private String name;
|
||||
private Long population;
|
||||
private Double percentage;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public Long getPopulation() {
|
||||
return population;
|
||||
}
|
||||
|
||||
public void setPopulation(Long population) {
|
||||
this.population = population;
|
||||
}
|
||||
|
||||
public Double getPercentage() {
|
||||
return percentage;
|
||||
}
|
||||
|
||||
public void setPercentage(Double percentage) {
|
||||
this.percentage = percentage;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package com.restcountries.domain.v4;
|
||||
|
||||
import io.micronaut.serde.annotation.Serdeable;
|
||||
|
||||
@Serdeable.Serializable
|
||||
public class Translation {
|
||||
private String lang;
|
||||
private String official;
|
||||
private String common;
|
||||
|
||||
public String getLang() {
|
||||
return lang;
|
||||
}
|
||||
|
||||
public void setLang(String lang) {
|
||||
this.lang = lang;
|
||||
}
|
||||
|
||||
public String getOfficial() {
|
||||
return official;
|
||||
}
|
||||
|
||||
public void setOfficial(String official) {
|
||||
this.official = official;
|
||||
}
|
||||
|
||||
public String getCommon() {
|
||||
return common;
|
||||
}
|
||||
|
||||
public void setCommon(String common) {
|
||||
this.common = common;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,174 @@
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
package com.restcountries.service.v2;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.stream.JsonReader;
|
||||
import com.restcountries.domain.BaseCountry;
|
||||
import com.restcountries.domain.ICountryRestSymbols;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.text.Normalizer;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class CountryServiceBaseV2 {
|
||||
|
||||
|
||||
protected <T extends BaseCountry> T getByAlpha(String alpha, List<T> countries) {
|
||||
int alphaLength = alpha.length();
|
||||
for (T country : countries) {
|
||||
if (alphaLength == 2) {
|
||||
if (country.getAlpha2Code().equalsIgnoreCase(alpha)) {
|
||||
return country;
|
||||
}
|
||||
} else if (alphaLength == 3 && country.getAlpha3Code().equalsIgnoreCase(alpha)) {
|
||||
return country;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
protected List<? extends BaseCountry> getByCodeList(String codeList,
|
||||
List<? extends BaseCountry> countries) {
|
||||
List<BaseCountry> result = new ArrayList<>();
|
||||
if (codeList == null) {
|
||||
return result;
|
||||
}
|
||||
|
||||
String[] codes = codeList.split(ICountryRestSymbols.COLON);
|
||||
for (String code : codes) {
|
||||
BaseCountry country = getByAlpha(code, countries);
|
||||
if (null != country && !result.contains(country)) {
|
||||
result.add(country);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
protected List<? extends BaseCountry> getByName(String name, boolean fullText,
|
||||
List<? extends BaseCountry> countries) {
|
||||
if (fullText) {
|
||||
return fulltextSearch(name, countries);
|
||||
} else {
|
||||
return substringSearch(name, countries);
|
||||
}
|
||||
}
|
||||
|
||||
protected List<? extends BaseCountry> getByCallingCode(String callingCode,
|
||||
List<? extends BaseCountry> countries) {
|
||||
List<BaseCountry> result = new ArrayList<>();
|
||||
for (BaseCountry country : countries) {
|
||||
for (String c : country.getCallingCodes()) {
|
||||
if (c.equals(callingCode)) {
|
||||
result.add(country);
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
protected List<? extends BaseCountry> getByCapital(String capital,
|
||||
List<? extends BaseCountry> countries) {
|
||||
List<BaseCountry> result = new ArrayList<>();
|
||||
for (BaseCountry country : countries) {
|
||||
if (normalize(country.getCapital().toLowerCase()).contains(
|
||||
normalize(capital.toLowerCase()))) {
|
||||
result.add(country);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
protected List<? extends BaseCountry> getByRegion(String region,
|
||||
List<? extends BaseCountry> countries) {
|
||||
List<BaseCountry> result = new ArrayList<>();
|
||||
for (BaseCountry country : countries) {
|
||||
if (country.getRegion().equalsIgnoreCase(region)) {
|
||||
result.add(country);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
protected List<? extends BaseCountry> getBySubregion(String subregion,
|
||||
List<? extends BaseCountry> countries) {
|
||||
List<BaseCountry> result = new ArrayList<>();
|
||||
for (BaseCountry country : countries) {
|
||||
if (country.getSubregion().equalsIgnoreCase(subregion)) {
|
||||
result.add(country);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private List<? extends BaseCountry> fulltextSearch(String name,
|
||||
List<? extends BaseCountry> countries) {
|
||||
// Using 2 different 'for' loops to give priority to 'name' matches over alternative spellings
|
||||
List<BaseCountry> result = new ArrayList<>();
|
||||
for (BaseCountry country : countries) {
|
||||
if (normalize(country.getName().toLowerCase()).equals(normalize(name.toLowerCase()))) {
|
||||
result.add(country);
|
||||
}
|
||||
}
|
||||
for (BaseCountry country : countries) {
|
||||
for (String alternative : country.getAltSpellings()) {
|
||||
if (normalize(alternative.toLowerCase()).equals(normalize(name.toLowerCase()))
|
||||
&& !result.contains(country)) {
|
||||
result.add(country);
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private List<? extends BaseCountry> substringSearch(String name,
|
||||
List<? extends BaseCountry> countries) {
|
||||
// Using 2 different 'for' loops to give priority to 'name' matches over alternative spellings
|
||||
List<BaseCountry> result = new ArrayList<>();
|
||||
for (BaseCountry country : countries) {
|
||||
if (normalize(country.getName().toLowerCase()).contains(normalize(name.toLowerCase()))) {
|
||||
result.add(country);
|
||||
}
|
||||
}
|
||||
for (BaseCountry country : countries) {
|
||||
for (String alternative : country.getAltSpellings()) {
|
||||
if (normalize(alternative.toLowerCase()).contains(normalize(name.toLowerCase()))
|
||||
&& !result.contains(country)) {
|
||||
result.add(country);
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
protected String normalize(String string) {
|
||||
return Normalizer.normalize(string, Normalizer.Form.NFD)
|
||||
.replaceAll("\\p{InCombiningDiacriticalMarks}+", "");
|
||||
}
|
||||
|
||||
protected List<? extends BaseCountry> loadJson(String filename,
|
||||
Class<? extends BaseCountry> clazz) {
|
||||
List<BaseCountry> countries = new ArrayList<>();
|
||||
InputStream is = CountryServiceBaseV2.class.getClassLoader().getResourceAsStream(filename);
|
||||
var gson = new Gson();
|
||||
JsonReader reader;
|
||||
try {
|
||||
assert is != null;
|
||||
reader = new JsonReader(new InputStreamReader(is, StandardCharsets.UTF_8));
|
||||
reader.beginArray();
|
||||
while (reader.hasNext()) {
|
||||
BaseCountry country = gson.fromJson(reader, clazz);
|
||||
countries.add(country);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return countries;
|
||||
}
|
||||
}
|
||||
@@ -1,19 +1,17 @@
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
package dev.amatos.restcountries.service.v2;
|
||||
package com.restcountries.service.v2;
|
||||
|
||||
import com.restcountries.domain.v2.Country;
|
||||
import com.restcountries.domain.v2.Currency;
|
||||
import com.restcountries.domain.v2.RegionalBloc;
|
||||
|
||||
import dev.amatos.restcountries.domain.v2.Country;
|
||||
import dev.amatos.restcountries.domain.v2.Currency;
|
||||
import dev.amatos.restcountries.domain.v2.Language;
|
||||
import dev.amatos.restcountries.domain.v2.RegionalBloc;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
public class CountryServiceV2 extends CountryServiceBaseV2 {
|
||||
|
||||
private static final Logger LOG = Logger.getLogger(CountryServiceV2.class);
|
||||
|
||||
private static List<Country> countries;
|
||||
|
||||
@@ -58,20 +56,20 @@ public class CountryServiceV2 extends CountryServiceBaseV2 {
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public List<Country> getByContinent(String region) {
|
||||
return (List<Country>) super.getByContinent(region, countries);
|
||||
public List<Country> getByRegion(String region) {
|
||||
return (List<Country>) super.getByRegion(region, countries);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public List<Country> getByRegion(String subregion) {
|
||||
return (List<Country>) super.getByRegion(subregion, countries);
|
||||
public List<Country> getBySubregion(String subregion) {
|
||||
return (List<Country>) super.getBySubregion(subregion, countries);
|
||||
}
|
||||
|
||||
public List<Country> getByCurrency(String currency) {
|
||||
List<Country> result = new ArrayList<>();
|
||||
for (Country country : countries) {
|
||||
for (Currency curr : country.getCurrencies()) {
|
||||
if (curr.getCode() != null && currency.toLowerCase().equals(curr.getCode().toLowerCase())) {
|
||||
if (curr.getCode() != null && currency.equalsIgnoreCase(curr.getCode())) {
|
||||
result.add(country);
|
||||
}
|
||||
}
|
||||
@@ -82,25 +80,29 @@ public class CountryServiceV2 extends CountryServiceBaseV2 {
|
||||
public List<Country> getByLanguage(String language) {
|
||||
List<Country> result = new ArrayList<>();
|
||||
if (language.length() == 2) {
|
||||
for (Country country : countries) {
|
||||
for (Language lang : country.getLanguages()) {
|
||||
if (language.toLowerCase().equals(lang.getIso639_1())) {
|
||||
result.add(country);
|
||||
}
|
||||
}
|
||||
}
|
||||
checkLanguageAndAddIfIso1Matches(language, result);
|
||||
} else if (language.length() == 3) {
|
||||
for (Country country : countries) {
|
||||
for (Language lang : country.getLanguages()) {
|
||||
if (language.toLowerCase().equals(lang.getIso639_2())) {
|
||||
result.add(country);
|
||||
}
|
||||
}
|
||||
}
|
||||
checkLanguageAndAddIfIso2Matches(language, result);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private void checkLanguageAndAddIfIso2Matches(String language, List<Country> result) {
|
||||
countries.forEach(country -> country.getLanguages().forEach(lang -> {
|
||||
if (language.toLowerCase().equals(lang.getIso639_2())) {
|
||||
result.add(country);
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
private void checkLanguageAndAddIfIso1Matches(String language, List<Country> result) {
|
||||
countries.forEach(country -> country.getLanguages().forEach(lang -> {
|
||||
if (language.toLowerCase().equals(lang.getIso639_1())) {
|
||||
result.add(country);
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
public List<Country> getByDemonym(String demonym) {
|
||||
List<Country> result = new ArrayList<>();
|
||||
for (Country country : countries) {
|
||||
@@ -128,8 +130,8 @@ public class CountryServiceV2 extends CountryServiceBaseV2 {
|
||||
|
||||
private boolean getRegionalBlockMatch(String acronym, List<String> otherAcronym,
|
||||
String regionalBlock) {
|
||||
return acronym != null && otherAcronym != null && ((acronym.equalsIgnoreCase(regionalBlock)
|
||||
|| otherAcronym.contains(regionalBlock)));
|
||||
return acronym != null && otherAcronym != null && (acronym.equalsIgnoreCase(regionalBlock)
|
||||
|| otherAcronym.contains(regionalBlock));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@@ -1,12 +1,13 @@
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
package dev.amatos.restcountries.service.v3;
|
||||
package com.restcountries.service.v3;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.stream.JsonReader;
|
||||
import dev.amatos.restcountries.domain.ICountryRestSymbols;
|
||||
import dev.amatos.restcountries.domain.base.BaseCountry;
|
||||
import com.restcountries.domain.ICountryRestSymbols;
|
||||
import com.restcountries.domain.base.BaseCountry;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
@@ -68,12 +69,11 @@ public class CountryServiceBaseV3 {
|
||||
// Using 2 different 'for' loops to give priority to 'name' matches over alternative spellings
|
||||
Set<BaseCountry> result = new HashSet<>();
|
||||
for (var country : countries) {
|
||||
if (name.toLowerCase().contains(country.getName().getCommon().toLowerCase()) ||
|
||||
name.toLowerCase().contains(country.getName().getOfficial().toLowerCase())) {
|
||||
if(country.getName().getCommon().toLowerCase().contains(name.toLowerCase()) ||
|
||||
country.getName().getOfficial().toLowerCase().contains(name.toLowerCase())
|
||||
) {
|
||||
result.add(country);
|
||||
}
|
||||
}
|
||||
for (var country : countries) {
|
||||
for (String alternative : country.getAltSpellings()) {
|
||||
if (alternative.toLowerCase().contains(name.toLowerCase())) {
|
||||
result.add(country);
|
||||
@@ -1,9 +1,10 @@
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
package dev.amatos.restcountries.service.v3;
|
||||
package com.restcountries.service.v3;
|
||||
|
||||
import com.restcountries.domain.v3.Country;
|
||||
|
||||
import dev.amatos.restcountries.domain.v3.Country;
|
||||
import java.text.Normalizer;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
@@ -22,7 +23,7 @@ public class CountryServiceV3 extends CountryServiceBaseV3 {
|
||||
}
|
||||
|
||||
public static CountryServiceV3 getInstance() {
|
||||
return CountryServiceV3.InstanceHolder.INSTANCE;
|
||||
return InstanceHolder.INSTANCE;
|
||||
}
|
||||
|
||||
public Set<Country> getAll() {
|
||||
@@ -77,12 +78,14 @@ public class CountryServiceV3 extends CountryServiceBaseV3 {
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String normalize(String string) {
|
||||
return Normalizer.normalize(string, Normalizer.Form.NFD)
|
||||
.replaceAll("\\p{InCombiningDiacriticalMarks}+", "");
|
||||
}
|
||||
|
||||
private void initialize() {
|
||||
countries = (Set<Country>) super.loadJson("countriesV3.json", Country.class);
|
||||
var c = (Set<Country>) super.loadJson("countriesV3.json", Country.class);
|
||||
countries = c;
|
||||
}
|
||||
}
|
||||
@@ -1,13 +1,15 @@
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
package dev.amatos.restcountries.service.v3.v31;
|
||||
package com.restcountries.service.v3.v31;
|
||||
|
||||
import com.restcountries.domain.v3.v31.Country;
|
||||
import com.restcountries.service.v3.CountryServiceBaseV3;
|
||||
|
||||
import dev.amatos.restcountries.domain.v3.v31.Country;
|
||||
import dev.amatos.restcountries.service.v3.CountryServiceBaseV3;
|
||||
import java.text.Normalizer;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class CountryServiceV31 extends CountryServiceBaseV3 {
|
||||
|
||||
@@ -23,7 +25,7 @@ public class CountryServiceV31 extends CountryServiceBaseV3 {
|
||||
}
|
||||
|
||||
public static CountryServiceV31 getInstance() {
|
||||
return CountryServiceV31.InstanceHolder.INSTANCE;
|
||||
return InstanceHolder.INSTANCE;
|
||||
}
|
||||
|
||||
public Set<Country> getAll() {
|
||||
@@ -78,6 +80,14 @@ public class CountryServiceV31 extends CountryServiceBaseV3 {
|
||||
return result;
|
||||
}
|
||||
|
||||
public Set<Country> getIndependent(boolean status) {
|
||||
return countries.stream().filter(country -> {
|
||||
var independent = Boolean.TRUE.equals(country.getIndependent());
|
||||
return independent == status;
|
||||
}).collect(Collectors.toSet());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String normalize(String string) {
|
||||
return Normalizer.normalize(string, Normalizer.Form.NFD)
|
||||
.replaceAll("\\p{InCombiningDiacriticalMarks}+", "");
|
||||
@@ -0,0 +1,198 @@
|
||||
package com.restcountries.service.v4;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.stream.JsonReader;
|
||||
import com.restcountries.domain.ICountryRestSymbols;
|
||||
import com.restcountries.domain.v4.Country;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.text.Normalizer;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
public class CountryServiceBaseV4 {
|
||||
|
||||
protected Set<Country> getByAlpha(String alpha, Set<Country> countries) {
|
||||
var result = new HashSet<Country>();
|
||||
for (var country : countries) {
|
||||
if ((country.getCca2() != null && country.getCca2().equalsIgnoreCase(alpha)) ||
|
||||
(country.getCcn3() != null && country.getCcn3().equalsIgnoreCase(alpha)) ||
|
||||
(country.getCca3() != null && country.getCca3().equalsIgnoreCase(alpha)) ||
|
||||
(country.getCioc() != null && country.getCioc().equalsIgnoreCase(alpha))
|
||||
) {
|
||||
result.add(country);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
protected Set<Country> getByCodeList(String codeList, Set<Country> countries) {
|
||||
Set<Country> result = new HashSet<>();
|
||||
if (codeList == null) {
|
||||
return result;
|
||||
}
|
||||
String[] codes = codeList.split(ICountryRestSymbols.COLON);
|
||||
for (String code : codes) {
|
||||
result.addAll(getByAlpha(code, countries));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
protected Set<Country> getByName(String name, boolean fullText, Set<Country> countries) {
|
||||
if (fullText) {
|
||||
return fulltextSearch(name, countries);
|
||||
} else {
|
||||
return substringSearch(name, countries);
|
||||
}
|
||||
}
|
||||
|
||||
private Set<Country> fulltextSearch(String name, Set<Country> countries) {
|
||||
Set<Country> result = new HashSet<>();
|
||||
for (var country : countries) {
|
||||
if (name.equalsIgnoreCase(country.getName().getCommon()) ||
|
||||
name.equalsIgnoreCase(country.getName().getOfficial())) {
|
||||
result.add(country);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private Set<Country> substringSearch(String name, Set<Country> countries) {
|
||||
Set<Country> result = new HashSet<>();
|
||||
for (var country : countries) {
|
||||
if (country.getName().getCommon().toLowerCase().contains(name.toLowerCase()) ||
|
||||
country.getName().getOfficial().toLowerCase().contains(name.toLowerCase())) {
|
||||
result.add(country);
|
||||
}
|
||||
for (String alternative : country.getAltSpellings()) {
|
||||
if (alternative.toLowerCase().contains(name.toLowerCase())) {
|
||||
result.add(country);
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
protected Set<Country> getByCurrency(String currency, Set<Country> countries) {
|
||||
Set<Country> result = new HashSet<>();
|
||||
for (var country : countries) {
|
||||
if (country.getCurrencies() != null) {
|
||||
for (var c : country.getCurrencies()) {
|
||||
if ((c.getCode() != null && c.getCode().equalsIgnoreCase(currency)) ||
|
||||
(c.getName() != null && c.getName().toLowerCase().contains(currency.toLowerCase()))) {
|
||||
result.add(country);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
protected Set<Country> getByCapital(String capital, Set<Country> countries) {
|
||||
Set<Country> result = new HashSet<>();
|
||||
for (var country : countries) {
|
||||
if (country.getCapital() != null) {
|
||||
for (String countryCapital : country.getCapital()) {
|
||||
if (normalize(countryCapital.toLowerCase()).contains(normalize(capital.toLowerCase()))) {
|
||||
result.add(country);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
protected Set<Country> getByRegion(String region, Set<Country> countries) {
|
||||
Set<Country> result = new HashSet<>();
|
||||
for (var country : countries) {
|
||||
if ((country.getRegion() != null && country.getRegion().toLowerCase().contains(region.toLowerCase())) ||
|
||||
(country.getSubregion() != null && country.getSubregion().equalsIgnoreCase(region))) {
|
||||
result.add(country);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
protected Set<Country> getBySubregion(String subregion, Set<Country> countries) {
|
||||
Set<Country> result = new HashSet<>();
|
||||
for (var country : countries) {
|
||||
if (country.getSubregion() != null &&
|
||||
(country.getSubregion().toLowerCase().contains(subregion.toLowerCase()) ||
|
||||
country.getSubregion().equalsIgnoreCase(subregion))) {
|
||||
result.add(country);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
protected Set<Country> getByLanguage(String language, Set<Country> countries) {
|
||||
Set<Country> result = new HashSet<>();
|
||||
for (var country : countries) {
|
||||
if (country.getLanguages() != null) {
|
||||
for (var lang : country.getLanguages()) {
|
||||
if ((lang.getName() != null && lang.getName().equalsIgnoreCase(language)) ||
|
||||
(lang.getIso639_1() != null && lang.getIso639_1().equalsIgnoreCase(language)) ||
|
||||
(lang.getIso639_2() != null && lang.getIso639_2().equalsIgnoreCase(language))) {
|
||||
result.add(country);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
protected Set<Country> getByDemonym(String demonym, Set<Country> countries) {
|
||||
Set<Country> result = new HashSet<>();
|
||||
for (var country : countries) {
|
||||
if (country.getDemonyms() != null) {
|
||||
for (var d : country.getDemonyms()) {
|
||||
if ((d.getMale() != null && d.getMale().toLowerCase().contains(demonym.toLowerCase())) ||
|
||||
(d.getFemale() != null && d.getFemale().toLowerCase().contains(demonym.toLowerCase()))) {
|
||||
result.add(country);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
protected Set<Country> getByTranslation(String translation, Set<Country> countries) {
|
||||
Set<Country> result = new HashSet<>();
|
||||
for (var country : countries) {
|
||||
if (country.getTranslations() != null) {
|
||||
for (var t : country.getTranslations()) {
|
||||
if ((t.getOfficial() != null && t.getOfficial().toLowerCase().contains(translation.toLowerCase())) ||
|
||||
(t.getCommon() != null && t.getCommon().toLowerCase().contains(translation.toLowerCase()))) {
|
||||
result.add(country);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
protected String normalize(String string) {
|
||||
return Normalizer.normalize(string, Normalizer.Form.NFD)
|
||||
.replaceAll("\\p{InCombiningDiacriticalMarks}+", "");
|
||||
}
|
||||
|
||||
protected Set<Country> loadJson(String filename) {
|
||||
Set<Country> countries = new HashSet<>();
|
||||
InputStream is = CountryServiceBaseV4.class.getClassLoader().getResourceAsStream(filename);
|
||||
Gson gson = new Gson();
|
||||
try {
|
||||
JsonReader reader = new JsonReader(new InputStreamReader(is, StandardCharsets.UTF_8));
|
||||
reader.beginArray();
|
||||
while (reader.hasNext()) {
|
||||
Country country = gson.fromJson(reader, Country.class);
|
||||
countries.add(country);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return countries;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
package com.restcountries.service.v4;
|
||||
|
||||
import com.restcountries.domain.v4.Country;
|
||||
|
||||
import java.text.Normalizer;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class CountryServiceV4 extends CountryServiceBaseV4 {
|
||||
|
||||
private static Set<Country> countries;
|
||||
|
||||
private CountryServiceV4() {
|
||||
initialize();
|
||||
}
|
||||
|
||||
private static class InstanceHolder {
|
||||
private static final CountryServiceV4 INSTANCE = new CountryServiceV4();
|
||||
}
|
||||
|
||||
public static CountryServiceV4 getInstance() {
|
||||
return InstanceHolder.INSTANCE;
|
||||
}
|
||||
|
||||
public Set<Country> getAll() {
|
||||
return countries;
|
||||
}
|
||||
|
||||
public Set<Country> getByAlpha(String alpha) {
|
||||
return super.getByAlpha(alpha, countries);
|
||||
}
|
||||
|
||||
public Set<Country> getByName(String name, boolean isFullText) {
|
||||
return super.getByName(name, isFullText, countries);
|
||||
}
|
||||
|
||||
public Set<Country> getByCurrency(String currency) {
|
||||
return super.getByCurrency(currency, countries);
|
||||
}
|
||||
|
||||
public Set<Country> getByCodeList(String codeList) {
|
||||
return super.getByCodeList(codeList, countries);
|
||||
}
|
||||
|
||||
public Set<Country> getByCapital(String capital) {
|
||||
return super.getByCapital(capital, countries);
|
||||
}
|
||||
|
||||
public Set<Country> getByRegion(String region) {
|
||||
return super.getByRegion(region, countries);
|
||||
}
|
||||
|
||||
public Set<Country> getBySubregion(String subregion) {
|
||||
return super.getBySubregion(subregion, countries);
|
||||
}
|
||||
|
||||
public Set<Country> getByLanguage(String language) {
|
||||
return super.getByLanguage(language, countries);
|
||||
}
|
||||
|
||||
public Set<Country> getByDemonym(String demonym) {
|
||||
return super.getByDemonym(demonym, countries);
|
||||
}
|
||||
|
||||
public Set<Country> getByTranslation(String translation) {
|
||||
return super.getByTranslation(translation, countries);
|
||||
}
|
||||
|
||||
public Set<Country> getIndependent(boolean status) {
|
||||
return countries.stream().filter(country -> {
|
||||
var independent = Boolean.TRUE.equals(country.getIndependent());
|
||||
return independent == status;
|
||||
}).collect(Collectors.toSet());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String normalize(String string) {
|
||||
return Normalizer.normalize(string, Normalizer.Form.NFD)
|
||||
.replaceAll("\\p{InCombiningDiacriticalMarks}+", "");
|
||||
}
|
||||
|
||||
private void initialize() {
|
||||
countries = super.loadJson("countriesV4.json");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
package com.restcountries.utils;
|
||||
|
||||
public class Constants {
|
||||
public static final String CACHE_CONTROL_VALUE="public, immutable, max-age=31556926";
|
||||
|
||||
}
|
||||
@@ -1,297 +0,0 @@
|
||||
package dev.amatos.restcountries.controller;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
import dev.amatos.restcountries.domain.ICountryRestSymbols;
|
||||
import dev.amatos.restcountries.domain.ResponseEntity;
|
||||
import dev.amatos.restcountries.domain.v3.Country;
|
||||
import dev.amatos.restcountries.service.v3.CountryServiceV3;
|
||||
import io.micronaut.http.HttpResponse;
|
||||
import io.micronaut.http.MediaType;
|
||||
import io.micronaut.http.annotation.Controller;
|
||||
import io.micronaut.http.annotation.Get;
|
||||
import io.micronaut.http.annotation.PathVariable;
|
||||
import io.micronaut.http.annotation.QueryValue;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import javax.ws.rs.QueryParam;
|
||||
import javax.ws.rs.core.Response;
|
||||
|
||||
@Controller("v3/")
|
||||
public class CountryControllerV3 {
|
||||
|
||||
@Get(uri = "all", produces = MediaType.APPLICATION_JSON)
|
||||
public Object getAllCountries(@QueryValue("fields") Optional<String> fields) {
|
||||
var countries = CountryServiceV3.getInstance().getAll();
|
||||
return checkFieldsAndParseCountries(fields, countries);
|
||||
}
|
||||
|
||||
private Object checkFieldsAndParseCountries(Optional<String> fields,
|
||||
Set<Country> countries) {
|
||||
if (fields.isPresent()) {
|
||||
return parsedCountries(countries, fields.get());
|
||||
} else {
|
||||
return parsedCountries(countries, null);
|
||||
}
|
||||
}
|
||||
|
||||
@Get("alpha/{alphacode}")
|
||||
public Object getByAlpha(@PathVariable("alphacode") String alpha,
|
||||
@QueryValue("fields") Optional<String> fields) {
|
||||
if (alpha.contains("codes")) {
|
||||
alpha = alpha.replace("codes=", "");
|
||||
}
|
||||
if (isEmpty(alpha) || alpha.length() < 2 || alpha.length() > 3) {
|
||||
return HttpResponse.badRequest(getResponse(Response.Status.BAD_REQUEST));
|
||||
}
|
||||
var country = CountryServiceV3.getInstance().getByAlpha(alpha);
|
||||
if (country != null) {
|
||||
return checkFieldsAndParseCountry(country, fields);
|
||||
}
|
||||
return HttpResponse.notFound(getResponse(Response.Status.NOT_FOUND));
|
||||
}
|
||||
|
||||
private Object checkFieldsAndParseCountry(Set<Country> countries, Optional<String> fields) {
|
||||
if (fields.isPresent()) {
|
||||
return parsedCountry(countries, fields.get());
|
||||
} else {
|
||||
return parsedCountry(countries, null);
|
||||
}
|
||||
}
|
||||
|
||||
@Get("alpha/")
|
||||
public Object getByAlphaList(@QueryParam("codes") String codes,
|
||||
@QueryParam("fields") Optional<String> fields) {
|
||||
if (isEmpty(codes) || codes.length() < 2 || (codes.length() > 3 && !codes.contains(","))) {
|
||||
return HttpResponse.badRequest(getResponse(Response.Status.BAD_REQUEST));
|
||||
}
|
||||
try {
|
||||
var countries = CountryServiceV3.getInstance().getByCodeList(codes);
|
||||
if (!countries.isEmpty()) {
|
||||
return checkFieldsAndParseCountries(fields, countries);
|
||||
}
|
||||
return HttpResponse.notFound(getResponse(Response.Status.NOT_FOUND));
|
||||
} catch (Exception e) {
|
||||
return HttpResponse.serverError(getResponse(Response.Status.INTERNAL_SERVER_ERROR));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Get("currency/{currency}")
|
||||
public Object getByCurrency(@PathVariable("currency") String currency,
|
||||
@QueryParam("fields") Optional<String> fields) {
|
||||
if (isEmpty(currency)) {
|
||||
return getResponse(Response.Status.BAD_REQUEST);
|
||||
}
|
||||
try {
|
||||
var countries = CountryServiceV3.getInstance().getByCurrency(currency);
|
||||
if (!countries.isEmpty()) {
|
||||
return checkFieldsAndParseCountries(fields, countries);
|
||||
}
|
||||
return HttpResponse.notFound(getResponse(Response.Status.NOT_FOUND));
|
||||
} catch (Exception e) {
|
||||
return HttpResponse.serverError(getResponse(Response.Status.INTERNAL_SERVER_ERROR));
|
||||
}
|
||||
}
|
||||
|
||||
@Get("name/{name}")
|
||||
public Object getByName(@PathVariable("name") String name,
|
||||
@QueryParam("fullText") Optional<Boolean> fullText,
|
||||
@QueryParam("fields") Optional<String> fields) {
|
||||
try {
|
||||
var countries = CountryServiceV3.getInstance()
|
||||
.getByName(name, fullText.orElse(false));
|
||||
if (!countries.isEmpty()) {
|
||||
return checkFieldsAndParseCountries(fields, countries);
|
||||
}
|
||||
return HttpResponse.notFound(getResponse(Response.Status.NOT_FOUND));
|
||||
} catch (Exception e) {
|
||||
return HttpResponse.serverError(Response.Status.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
@Get("capital/{capital}")
|
||||
public Object getByCapital(@PathVariable("capital") String capital,
|
||||
@QueryParam("fields") Optional<String> fields) {
|
||||
try {
|
||||
var countries = CountryServiceV3.getInstance().getByCapital(capital);
|
||||
if (!countries.isEmpty()) {
|
||||
return checkFieldsAndParseCountries(fields, countries);
|
||||
}
|
||||
return HttpResponse.notFound(getResponse(Response.Status.NOT_FOUND));
|
||||
} catch (Exception e) {
|
||||
return HttpResponse.serverError(Response.Status.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Get("region/{region}")
|
||||
public Object getByContinent(@PathVariable("region") String region,
|
||||
@QueryParam("fields") Optional<String> fields) {
|
||||
try {
|
||||
var countries = CountryServiceV3.getInstance().getByRegion(region);
|
||||
if (!countries.isEmpty()) {
|
||||
return checkFieldsAndParseCountries(fields, countries);
|
||||
}
|
||||
return HttpResponse.notFound(getResponse(Response.Status.NOT_FOUND));
|
||||
} catch (Exception e) {
|
||||
return HttpResponse.serverError(Response.Status.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
@Get("subregion/{subregion}")
|
||||
public Object getBySubRegion(@PathVariable("subregion") String subregion,
|
||||
@QueryParam("fields") Optional<String> fields) {
|
||||
try {
|
||||
var countries = CountryServiceV3.getInstance().getBySubregion(subregion);
|
||||
if (!countries.isEmpty()) {
|
||||
return checkFieldsAndParseCountries(fields, countries);
|
||||
}
|
||||
return HttpResponse.notFound(getResponse(Response.Status.NOT_FOUND));
|
||||
} catch (Exception e) {
|
||||
return HttpResponse.serverError(Response.Status.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
@Get("lang/{lang}")
|
||||
public Object getByLanguage(@PathVariable("lang") String language,
|
||||
@QueryParam("fields") Optional<String> fields) {
|
||||
try {
|
||||
var countries = CountryServiceV3.getInstance().getByLanguage(language);
|
||||
if (!countries.isEmpty()) {
|
||||
return checkFieldsAndParseCountries(fields, countries);
|
||||
}
|
||||
return HttpResponse.notFound(getResponse(Response.Status.NOT_FOUND));
|
||||
} catch (Exception e) {
|
||||
return HttpResponse.serverError(Response.Status.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Get("demonym/{demonym}")
|
||||
public Object getByDemonym(@PathVariable("demonym") String demonym,
|
||||
@QueryParam("fields") Optional<String> fields) {
|
||||
try {
|
||||
var countries = CountryServiceV3.getInstance().getByDemonym(demonym);
|
||||
if (!countries.isEmpty()) {
|
||||
return checkFieldsAndParseCountries(fields, countries);
|
||||
}
|
||||
return HttpResponse.notFound(getResponse(Response.Status.NOT_FOUND));
|
||||
} catch (Exception e) {
|
||||
return HttpResponse.serverError(Response.Status.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
@Get("translation/{translation}")
|
||||
public Object getByTranslation(@PathVariable("translation") String translation,
|
||||
@QueryParam("fields") Optional<String> fields) {
|
||||
try {
|
||||
var countries = CountryServiceV3.getInstance().getByTranslation(translation);
|
||||
if (!countries.isEmpty()) {
|
||||
return checkFieldsAndParseCountries(fields, countries);
|
||||
}
|
||||
return HttpResponse.notFound(getResponse(Response.Status.NOT_FOUND));
|
||||
} catch (Exception e) {
|
||||
return HttpResponse.serverError(Response.Status.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
private Object parsedCountries(Set<Country> countries, String excludedFields) {
|
||||
if (excludedFields == null || excludedFields.isEmpty()) {
|
||||
return countries;
|
||||
} else {
|
||||
return getCountriesJson(countries,
|
||||
Arrays.asList(excludedFields.split(ICountryRestSymbols.COLON)));
|
||||
}
|
||||
}
|
||||
|
||||
private String getCountriesJson(Set<Country> countries, List<String> fields) {
|
||||
var gson = new Gson();
|
||||
var parser = new JsonParser();
|
||||
var jsonArray = parser.parse(gson.toJson(countries)).getAsJsonArray();
|
||||
var resultArray = new JsonArray();
|
||||
jsonArray.forEach(element -> {
|
||||
var jsonObject = (JsonObject) element;
|
||||
var excludedFields = getExcludedFields(fields);
|
||||
excludedFields.forEach(jsonObject::remove);
|
||||
resultArray.add(jsonObject);
|
||||
});
|
||||
return resultArray.toString();
|
||||
}
|
||||
|
||||
private List<String> getExcludedFields(List<String> fields) {
|
||||
List<String> excludedFields = new ArrayList<>(Arrays.asList(COUNTRY_FIELDS));
|
||||
excludedFields.removeAll(fields);
|
||||
return excludedFields;
|
||||
}
|
||||
|
||||
private Object getResponse(Response.Status status) {
|
||||
var gson = new Gson();
|
||||
return Response
|
||||
.status(status)
|
||||
.entity(gson.toJson(new ResponseEntity(status.getStatusCode(),
|
||||
status.getReasonPhrase())))
|
||||
.build()
|
||||
.getEntity();
|
||||
}
|
||||
|
||||
private Object parsedCountry(Set<Country> countries, String fields) {
|
||||
if (fields == null || fields.isEmpty()) {
|
||||
return countries;
|
||||
} else {
|
||||
StringBuilder result = new StringBuilder();
|
||||
countries.forEach(country -> result.append(
|
||||
getCountryJson(country, Arrays.asList(fields.split(ICountryRestSymbols.COLON)))));
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
private String getCountryJson(Country country, List<String> fields) {
|
||||
var gson = new Gson();
|
||||
var parser = new JsonParser();
|
||||
var jsonObject = parser.parse(gson.toJson(country)).getAsJsonObject();
|
||||
|
||||
List<String> excludedFields = getExcludedFields(fields);
|
||||
excludedFields.forEach(jsonObject::remove);
|
||||
return jsonObject.toString();
|
||||
}
|
||||
|
||||
private static final String[] COUNTRY_FIELDS = new String[]{
|
||||
"name",
|
||||
"tld",
|
||||
"cca2",
|
||||
"ccn3",
|
||||
"cca3",
|
||||
"cioc",
|
||||
"independent",
|
||||
"status",
|
||||
"unMember",
|
||||
"currencies",
|
||||
"idd",
|
||||
"capital",
|
||||
"altSpellings",
|
||||
"region",
|
||||
"subregion",
|
||||
"languages",
|
||||
"translations",
|
||||
"latlng",
|
||||
"landlocked",
|
||||
"borders",
|
||||
"area",
|
||||
"flags",
|
||||
"demonyms",
|
||||
"population",
|
||||
"flags",
|
||||
"flag",
|
||||
"maps"
|
||||
};
|
||||
|
||||
private boolean isEmpty(String value) {
|
||||
return value == null || value.isEmpty();
|
||||
}
|
||||
}
|
||||
@@ -1,296 +0,0 @@
|
||||
package dev.amatos.restcountries.controller;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
import dev.amatos.restcountries.domain.ICountryRestSymbols;
|
||||
import dev.amatos.restcountries.domain.ResponseEntity;
|
||||
import dev.amatos.restcountries.domain.v3.v31.Country;
|
||||
import dev.amatos.restcountries.service.v3.v31.CountryServiceV31;
|
||||
import io.micronaut.http.HttpResponse;
|
||||
import io.micronaut.http.MediaType;
|
||||
import io.micronaut.http.annotation.Controller;
|
||||
import io.micronaut.http.annotation.Get;
|
||||
import io.micronaut.http.annotation.PathVariable;
|
||||
import io.micronaut.http.annotation.QueryValue;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import javax.ws.rs.QueryParam;
|
||||
import javax.ws.rs.core.Response;
|
||||
|
||||
@Controller("v3.1/")
|
||||
public class CountryControllerV31 {
|
||||
|
||||
@Get(uri = "all", produces = MediaType.APPLICATION_JSON)
|
||||
public Object getAllCountries(@QueryValue("fields") Optional<String> fields) {
|
||||
var countries = CountryServiceV31.getInstance().getAll();
|
||||
return checkFieldsAndParseCountries(fields, countries);
|
||||
}
|
||||
|
||||
private Object checkFieldsAndParseCountries(Optional<String> fields,
|
||||
Set<Country> countries) {
|
||||
if (fields.isPresent()) {
|
||||
return parsedCountries(countries, fields.get());
|
||||
} else {
|
||||
return parsedCountries(countries, null);
|
||||
}
|
||||
}
|
||||
|
||||
@Get("alpha/{alphacode}")
|
||||
public Object getByAlpha(@PathVariable("alphacode") String alpha,
|
||||
@QueryValue("fields") Optional<String> fields) {
|
||||
if (alpha.contains("codes")) {
|
||||
alpha = alpha.replace("codes=", "");
|
||||
}
|
||||
if (isEmpty(alpha) || alpha.length() < 2 || alpha.length() > 3) {
|
||||
return HttpResponse.badRequest(getResponse(Response.Status.BAD_REQUEST));
|
||||
}
|
||||
var country = CountryServiceV31.getInstance().getByAlpha(alpha);
|
||||
if (country != null) {
|
||||
return checkFieldsAndParseCountry(country, fields);
|
||||
}
|
||||
return HttpResponse.notFound(getResponse(Response.Status.NOT_FOUND));
|
||||
}
|
||||
|
||||
private Object checkFieldsAndParseCountry(Set<Country> countries, Optional<String> fields) {
|
||||
if (fields.isPresent()) {
|
||||
return parsedCountry(countries, fields.get());
|
||||
} else {
|
||||
return parsedCountry(countries, null);
|
||||
}
|
||||
}
|
||||
|
||||
@Get("alpha/")
|
||||
public Object getByAlphaList(@QueryParam("codes") String codes,
|
||||
@QueryParam("fields") Optional<String> fields) {
|
||||
if (isEmpty(codes) || codes.length() < 2 || (codes.length() > 3 && !codes.contains(","))) {
|
||||
return HttpResponse.badRequest(getResponse(Response.Status.BAD_REQUEST));
|
||||
}
|
||||
try {
|
||||
var countries = CountryServiceV31.getInstance().getByCodeList(codes);
|
||||
if (!countries.isEmpty()) {
|
||||
return checkFieldsAndParseCountries(fields, countries);
|
||||
}
|
||||
return HttpResponse.notFound(getResponse(Response.Status.NOT_FOUND));
|
||||
} catch (Exception e) {
|
||||
return HttpResponse.serverError(getResponse(Response.Status.INTERNAL_SERVER_ERROR));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Get("currency/{currency}")
|
||||
public Object getByCurrency(@PathVariable("currency") String currency,
|
||||
@QueryParam("fields") Optional<String> fields) {
|
||||
if (isEmpty(currency)) {
|
||||
return getResponse(Response.Status.BAD_REQUEST);
|
||||
}
|
||||
try {
|
||||
var countries = CountryServiceV31.getInstance().getByCurrency(currency);
|
||||
if (!countries.isEmpty()) {
|
||||
return checkFieldsAndParseCountries(fields, countries);
|
||||
}
|
||||
return HttpResponse.notFound(getResponse(Response.Status.NOT_FOUND));
|
||||
} catch (Exception e) {
|
||||
return HttpResponse.serverError(getResponse(Response.Status.INTERNAL_SERVER_ERROR));
|
||||
}
|
||||
}
|
||||
|
||||
@Get("name/{name}")
|
||||
public Object getByName(@PathVariable("name") String name,
|
||||
@QueryParam("fullText") Optional<Boolean> fullText,
|
||||
@QueryParam("fields") Optional<String> fields) {
|
||||
try {
|
||||
var countries = CountryServiceV31.getInstance()
|
||||
.getByName(name, fullText.orElse(false));
|
||||
if (!countries.isEmpty()) {
|
||||
return checkFieldsAndParseCountries(fields, countries);
|
||||
}
|
||||
return HttpResponse.notFound(getResponse(Response.Status.NOT_FOUND));
|
||||
} catch (Exception e) {
|
||||
return HttpResponse.serverError(Response.Status.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
@Get("capital/{capital}")
|
||||
public Object getByCapital(@PathVariable("capital") String capital,
|
||||
@QueryParam("fields") Optional<String> fields) {
|
||||
try {
|
||||
var countries = CountryServiceV31.getInstance().getByCapital(capital);
|
||||
if (!countries.isEmpty()) {
|
||||
return checkFieldsAndParseCountries(fields, countries);
|
||||
}
|
||||
return HttpResponse.notFound(getResponse(Response.Status.NOT_FOUND));
|
||||
} catch (Exception e) {
|
||||
return HttpResponse.serverError(Response.Status.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Get("region/{region}")
|
||||
public Object getByContinent(@PathVariable("region") String region,
|
||||
@QueryParam("fields") Optional<String> fields) {
|
||||
try {
|
||||
var countries = CountryServiceV31.getInstance().getByRegion(region);
|
||||
if (!countries.isEmpty()) {
|
||||
return checkFieldsAndParseCountries(fields, countries);
|
||||
}
|
||||
return HttpResponse.notFound(getResponse(Response.Status.NOT_FOUND));
|
||||
} catch (Exception e) {
|
||||
return HttpResponse.serverError(Response.Status.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
@Get("subregion/{subregion}")
|
||||
public Object getBySubRegion(@PathVariable("subregion") String subregion,
|
||||
@QueryParam("fields") Optional<String> fields) {
|
||||
try {
|
||||
var countries = CountryServiceV31.getInstance().getBySubregion(subregion);
|
||||
if (!countries.isEmpty()) {
|
||||
return checkFieldsAndParseCountries(fields, countries);
|
||||
}
|
||||
return HttpResponse.notFound(getResponse(Response.Status.NOT_FOUND));
|
||||
} catch (Exception e) {
|
||||
return HttpResponse.serverError(Response.Status.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
@Get("lang/{lang}")
|
||||
public Object getByLanguage(@PathVariable("lang") String language,
|
||||
@QueryParam("fields") Optional<String> fields) {
|
||||
try {
|
||||
var countries = CountryServiceV31.getInstance().getByLanguage(language);
|
||||
if (!countries.isEmpty()) {
|
||||
return checkFieldsAndParseCountries(fields, countries);
|
||||
}
|
||||
return HttpResponse.notFound(getResponse(Response.Status.NOT_FOUND));
|
||||
} catch (Exception e) {
|
||||
return HttpResponse.serverError(Response.Status.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Get("demonym/{demonym}")
|
||||
public Object getByDemonym(@PathVariable("demonym") String demonym,
|
||||
@QueryParam("fields") Optional<String> fields) {
|
||||
try {
|
||||
var countries = CountryServiceV31.getInstance().getByDemonym(demonym);
|
||||
if (!countries.isEmpty()) {
|
||||
return checkFieldsAndParseCountries(fields, countries);
|
||||
}
|
||||
return HttpResponse.notFound(getResponse(Response.Status.NOT_FOUND));
|
||||
} catch (Exception e) {
|
||||
return HttpResponse.serverError(Response.Status.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
@Get("translation/{translation}")
|
||||
public Object getByTranslation(@PathVariable("translation") String translation,
|
||||
@QueryParam("fields") Optional<String> fields) {
|
||||
try {
|
||||
var countries = CountryServiceV31.getInstance().getByTranslation(translation);
|
||||
if (!countries.isEmpty()) {
|
||||
return checkFieldsAndParseCountries(fields, countries);
|
||||
}
|
||||
return HttpResponse.notFound(getResponse(Response.Status.NOT_FOUND));
|
||||
} catch (Exception e) {
|
||||
return HttpResponse.serverError(Response.Status.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
private Object parsedCountries(Set<Country> countries, String excludedFields) {
|
||||
if (excludedFields == null || excludedFields.isEmpty()) {
|
||||
return countries;
|
||||
} else {
|
||||
return getCountriesJson(countries,
|
||||
Arrays.asList(excludedFields.split(ICountryRestSymbols.COLON)));
|
||||
}
|
||||
}
|
||||
|
||||
private String getCountriesJson(Set<Country> countries, List<String> fields) {
|
||||
var gson = new Gson();
|
||||
var parser = new JsonParser();
|
||||
var jsonArray = parser.parse(gson.toJson(countries)).getAsJsonArray();
|
||||
var resultArray = new JsonArray();
|
||||
jsonArray.forEach(element -> {
|
||||
var jsonObject = (JsonObject) element;
|
||||
var excludedFields = getExcludedFields(fields);
|
||||
excludedFields.forEach(jsonObject::remove);
|
||||
resultArray.add(jsonObject);
|
||||
});
|
||||
return resultArray.toString();
|
||||
}
|
||||
|
||||
private List<String> getExcludedFields(List<String> fields) {
|
||||
List<String> excludedFields = new ArrayList<>(Arrays.asList(COUNTRY_FIELDS));
|
||||
excludedFields.removeAll(fields);
|
||||
return excludedFields;
|
||||
}
|
||||
|
||||
private Object getResponse(Response.Status status) {
|
||||
var gson = new Gson();
|
||||
return Response
|
||||
.status(status)
|
||||
.entity(gson.toJson(new ResponseEntity(status.getStatusCode(),
|
||||
status.getReasonPhrase())))
|
||||
.build()
|
||||
.getEntity();
|
||||
}
|
||||
|
||||
private Object parsedCountry(Set<Country> countries, String fields) {
|
||||
if (fields == null || fields.isEmpty()) {
|
||||
return countries;
|
||||
} else {
|
||||
StringBuilder result = new StringBuilder();
|
||||
countries.forEach(country -> result.append(
|
||||
getCountryJson(country, Arrays.asList(fields.split(ICountryRestSymbols.COLON)))));
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
private String getCountryJson(Country country, List<String> fields) {
|
||||
var gson = new Gson();
|
||||
var parser = new JsonParser();
|
||||
var jsonObject = parser.parse(gson.toJson(country)).getAsJsonObject();
|
||||
|
||||
List<String> excludedFields = getExcludedFields(fields);
|
||||
excludedFields.forEach(jsonObject::remove);
|
||||
return jsonObject.toString();
|
||||
}
|
||||
|
||||
private static final String[] COUNTRY_FIELDS = new String[]{
|
||||
"name",
|
||||
"tld",
|
||||
"cca2",
|
||||
"ccn3",
|
||||
"cca3",
|
||||
"cioc",
|
||||
"independent",
|
||||
"status",
|
||||
"unMember",
|
||||
"currencies",
|
||||
"idd",
|
||||
"capital",
|
||||
"altSpellings",
|
||||
"region",
|
||||
"subregion",
|
||||
"languages",
|
||||
"translations",
|
||||
"latlng",
|
||||
"landlocked",
|
||||
"borders",
|
||||
"area",
|
||||
"flags",
|
||||
"demonyms",
|
||||
"flag",
|
||||
"population",
|
||||
"maps"
|
||||
};
|
||||
|
||||
private boolean isEmpty(String value) {
|
||||
return value == null || value.isEmpty();
|
||||
}
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
package dev.amatos.restcountries.domain.v3.v31;
|
||||
|
||||
import dev.amatos.restcountries.domain.base.BaseCountry;
|
||||
import java.util.Map;
|
||||
|
||||
public class Country extends BaseCountry {
|
||||
private Map<String, String> flags;
|
||||
|
||||
|
||||
public Map<String, String> getFlags() {
|
||||
return flags;
|
||||
}
|
||||
|
||||
public void setFlags(Map<String, String> flags) {
|
||||
this.flags = flags;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,162 +0,0 @@
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
package dev.amatos.restcountries.service.v2;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.stream.JsonReader;
|
||||
import dev.amatos.restcountries.domain.BaseCountry;
|
||||
import dev.amatos.restcountries.domain.ICountryRestSymbols;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.text.Normalizer;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class CountryServiceBaseV2 {
|
||||
|
||||
private static final Logger LOG = Logger.getLogger(CountryServiceBaseV2.class);
|
||||
|
||||
protected <T extends BaseCountry> T getByAlpha(String alpha, List<T> countries) {
|
||||
int alphaLength = alpha.length();
|
||||
for (T country : countries) {
|
||||
if (alphaLength == 2) {
|
||||
if (country.getAlpha2Code().equalsIgnoreCase(alpha)) {
|
||||
return country;
|
||||
}
|
||||
} else if (alphaLength == 3 && country.getAlpha3Code().equalsIgnoreCase(alpha)) {
|
||||
return country;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
protected List<? extends BaseCountry> getByCodeList(String codeList, List<? extends BaseCountry> countries) {
|
||||
List<BaseCountry> result = new ArrayList<>();
|
||||
if (codeList == null) return result;
|
||||
|
||||
String[] codes = codeList.split(ICountryRestSymbols.COLON);
|
||||
for (String code : codes) {
|
||||
BaseCountry country = getByAlpha(code, countries);
|
||||
if (!result.contains(country))
|
||||
result.add(country);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
protected List<? extends BaseCountry> getByName(String name, boolean fullText, List<? extends BaseCountry> countries) {
|
||||
if (fullText) {
|
||||
return fulltextSearch(name, countries);
|
||||
} else {
|
||||
return substringSearch(name, countries);
|
||||
}
|
||||
}
|
||||
|
||||
protected List<? extends BaseCountry> getByCallingCode(String callingCode, List<? extends BaseCountry> countries) {
|
||||
List<BaseCountry> result = new ArrayList<>();
|
||||
for (BaseCountry country : countries) {
|
||||
for (String c : country.getCallingCodes()) {
|
||||
if (c.equals(callingCode))
|
||||
result.add(country);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
protected List<? extends BaseCountry> getByCapital(String capital, List<? extends BaseCountry> countries) {
|
||||
List<BaseCountry> result = new ArrayList<>();
|
||||
for (BaseCountry country : countries) {
|
||||
if (normalize(country.getCapital().toLowerCase()).contains(normalize(capital.toLowerCase()))) {
|
||||
result.add(country);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
protected List<? extends BaseCountry> getByContinent(String region, List<? extends BaseCountry> countries) {
|
||||
List<BaseCountry> result = new ArrayList<>();
|
||||
for (BaseCountry country : countries) {
|
||||
if (country.getRegion().equalsIgnoreCase(region)) {
|
||||
result.add(country);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
protected List<? extends BaseCountry> getByRegion(String subregion, List<? extends BaseCountry> countries) {
|
||||
List<BaseCountry> result = new ArrayList<>();
|
||||
for (BaseCountry country : countries) {
|
||||
if (country.getSubregion().equalsIgnoreCase(subregion)) {
|
||||
result.add(country);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private List<? extends BaseCountry> fulltextSearch(String name, List<? extends BaseCountry> countries) {
|
||||
// Using 2 different 'for' loops to give priority to 'name' matches over alternative spellings
|
||||
List<BaseCountry> result = new ArrayList<>();
|
||||
for (BaseCountry country : countries) {
|
||||
if (normalize(country.getName().toLowerCase()).equals(normalize(name.toLowerCase()))) {
|
||||
result.add(country);
|
||||
}
|
||||
}
|
||||
for (BaseCountry country : countries) {
|
||||
for (String alternative : country.getAltSpellings()) {
|
||||
if (normalize(alternative.toLowerCase()).equals(normalize(name.toLowerCase()))
|
||||
&& !result.contains(country)) {
|
||||
result.add(country);
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private List<? extends BaseCountry> substringSearch(String name, List<? extends BaseCountry> countries) {
|
||||
// Using 2 different 'for' loops to give priority to 'name' matches over alternative spellings
|
||||
List<BaseCountry> result = new ArrayList<>();
|
||||
for (BaseCountry country : countries) {
|
||||
if (normalize(country.getName().toLowerCase()).contains(normalize(name.toLowerCase()))) {
|
||||
result.add(country);
|
||||
}
|
||||
}
|
||||
for (BaseCountry country : countries) {
|
||||
for (String alternative : country.getAltSpellings()) {
|
||||
if (normalize(alternative.toLowerCase()).contains(normalize(name.toLowerCase()))
|
||||
&& !result.contains(country)) {
|
||||
result.add(country);
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
protected String normalize(String string) {
|
||||
return Normalizer.normalize(string, Normalizer.Form.NFD)
|
||||
.replaceAll("\\p{InCombiningDiacriticalMarks}+", "");
|
||||
}
|
||||
|
||||
protected List<? extends BaseCountry> loadJson(String filename, Class<? extends BaseCountry> clazz) {
|
||||
LOG.debug("Loading JSON " + filename);
|
||||
List<BaseCountry> countries = new ArrayList<>();
|
||||
InputStream is = CountryServiceBaseV2.class.getClassLoader().getResourceAsStream(filename);
|
||||
var gson = new Gson();
|
||||
JsonReader reader;
|
||||
try {
|
||||
assert is != null;
|
||||
reader = new JsonReader(new InputStreamReader(is, StandardCharsets.UTF_8));
|
||||
reader.beginArray();
|
||||
while (reader.hasNext()) {
|
||||
BaseCountry country = gson.fromJson(reader, clazz);
|
||||
countries.add(country);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
LOG.error("Could not load JSON " + filename);
|
||||
}
|
||||
return countries;
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
#Wed Mar 12 15:11:47 UTC 2025
|
||||
micronaut:
|
||||
application:
|
||||
name: dev.amatos.restcountries
|
||||
name=restcountries
|
||||
router.static-resources.default:
|
||||
enabled: true
|
||||
paths: classpath:static
|
||||
@@ -11,4 +12,7 @@ micronaut:
|
||||
configurations:
|
||||
web:
|
||||
allowedMethods:
|
||||
- GET
|
||||
- GET
|
||||
caches:
|
||||
rate-limiter:
|
||||
expire-after-access: 10m
|
||||
@@ -1,7 +1,6 @@
|
||||
<configuration>
|
||||
|
||||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<withJansi>false</withJansi>
|
||||
<!-- encoders are assigned the type
|
||||
ch.qos.logback.classic.encoder.PatternLayoutEncoder by default -->
|
||||
<encoder>
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="900" height="600" viewBox="0 0 27 18">
|
||||
<path d="M0,0H27V18H0z" fill="#4189dd"/>
|
||||
<path d="M0,12H27v1H0v1H27v1H0z" fill="#f9d616"/>
|
||||
<g fill="#fff" transform="translate(4,4)">
|
||||
<path id="s" d="M0,-3 0.707107,-0.707107 3,0 0.707107,0.707107 0,3 -0.707107,0.707107 -3,0 -0.707107,-0.707107z"/>
|
||||
<use xlink:href="#s" transform="scale(0.770376)" fill="#d21034"/>
|
||||
</g>
|
||||
</svg>
|
||||
|
Before Width: | Height: | Size: 502 B |
|
Before Width: | Height: | Size: 46 KiB |
@@ -1,23 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="450" height="300">
|
||||
<rect width="450" height="300" fill="#000"/>
|
||||
<rect width="450" height="150" fill="#ce1126"/>
|
||||
<g fill="#f9d616">
|
||||
<path d="M231.115,91.82A58.5,58.5 0 1,1 187.916,195.244L179.358,205.685A72,72 0 1,0 232.526,78.394z"/>
|
||||
<g id="s3">
|
||||
<path id="s" d="M302.62435,142.35494C303.12516,147.43953 303.12516,152.56101 302.62435,157.6456L287.69659,156.17534C288.10106,152.06855 288.10106,147.93196 287.69659,143.82518z"/>
|
||||
<use xlink:href="#s" transform="rotate(22.5,225,150)"/>
|
||||
<use xlink:href="#s" transform="rotate(45,225,150)"/>
|
||||
</g>
|
||||
<use xlink:href="#s3" transform="rotate(-67.5,225,150)"/>
|
||||
<use xlink:href="#s3" transform="rotate(67.5,225,150)"/>
|
||||
<path d="M199.32444,114.65618H250.67551L209.1325,144.84033 224.99998,96.000328 240.86746,144.84033z"/>
|
||||
<path d="M287.87869,216.3146C291.71694,220.02891 296.88529,223.69038 300.6338,227.01716C304.38231,230.34392 307.25434,233.10958 309.57908,236.88884C312.98624,242.42773 309.16023,248.7008 303.85486,245.01872C300.98581,243.02751 299.18307,237.65214 294.78788,233.20395C291.53252,230.43267 288.96764,227.52745 280.78551,226.1257C280.39268,226.05841 280.27777,225.22842 280.58665,224.86618z"/>
|
||||
<path fill="#000" d="M231.36058,197.84505 251.60791,209.8174 256.00949,226.89558 279.24991,225.13494 289.46162,213.16262 251.60791,186.9291 231.36058,197.84505z"/>
|
||||
<path d="M279.66324,223.6894C253.62799,206.37539 237.07238,197.02622 212.12131,182.83938C202.31974,177.26634 187.0985,163.25747 199.1052,139.81914C199.86106,155.20638 260.67394,197.4423 286.3703,215.80679z"/>
|
||||
<path fill="none" stroke="#000" stroke-width="1.5" stroke-linecap="round" d="M216.08561,167.51949C236.13137,186.41034 261.37565,201.82127 283.89761,218.85496"/>
|
||||
<circle id="c" cx="290.4" cy="222.297" r="1.008" fill="#000"/>
|
||||
<use xlink:href="#c" x="7.41957" y="6.4655991"/>
|
||||
<use xlink:href="#c" x="13.93812" y="13.090317"/>
|
||||
</g>
|
||||
</svg>
|
||||
|
Before Width: | Height: | Size: 2.0 KiB |
@@ -1,23 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="1200" height="600">
|
||||
<clipPath id="c">
|
||||
<path d="M0,0V150H700V300H600zM600,0H300V350H0V300z"/>
|
||||
</clipPath>
|
||||
<rect width="1200" height="600" fill="#00247d"/>
|
||||
<path d="M0,0 600,300M600,0 0,300" stroke="#fff" stroke-width="60"/>
|
||||
<path d="M0,0 600,300M600,0 0,300" stroke="#cf142b" stroke-width="40" clip-path="url(#c)"/>
|
||||
<path d="M300,0V350M0,150H700" stroke="#fff" stroke-width="100"/>
|
||||
<path d="M300,0V350M0,150H700" stroke="#cf142b" stroke-width="60"/>
|
||||
<path d="M0,300H600V0H800V400H0z" fill="#00247d"/>
|
||||
<g>
|
||||
<path fill="#cc3" d="m780.583,154.039c0,148.827,11.8732,201.675,52.6064,242.479,40.7332,40.8042,56.1659,47.2313,67.5231,53.4827,13.1015-7.21148,28.1971-15.1341,65.1152-52.0521,36.513-36.515,54.173-89.15,54.173-246.452-26.559,11.3712-39.7859,15.1175-63.0119,15.0513-17.202,1.68548-43.7399-9.33789-59.6086-16.5484-10.371,6.60246-25.4152,14.4763-52.4514,15.3604-31.2252,1.30952-41.1191-3.73522-64.3451-11.3217z"/>
|
||||
|
||||
<path fill="#fff" d="m787.775,163.438c0,46.0434-2.72184,108.794,7.00639,145.1,9.77001,36.4622,12.0129,41.8034,19.3596,54.5282l171.206-1.27105c10.576-18.3181,11.1098-29.6647,18.9526-58.9348,7.8148-29.1649,9.7886-94.177,10.0167-142.6-17.216,8.72445-39.7613,14.9075-61.6436,12.1948-17.5423-1.2754-33.7513-5.09258-52.6268-15.2637-16.374,9.35261-22.0822,13.6217-49.1184,14.7138-21.0507,0.98975-38.1018,2.61503-63.1522-8.46789z"/>
|
||||
|
||||
<path fill="#9cf" d="m814.51,362.056c12.1849,24.4477,69.6325,71.3032,86.433,81.0029,19.168-11.0667,69.8476-57.368,83.9727-81.0029h-170.406z"/>
|
||||
|
||||
<path fill="#f90" d="m904.221,231.606c5.41355,12.1396,22.7699,25.5448,27.5414,32.1145-6.07314,6.56934-7.28706,5.85387-6.49064,18.0587,10.5604-10.534,10.7499-11.6322,17.5423-10.0346,14.8794,14.1555,2.66292,44.5571-9.63422,51.1666-12.2936,7.05101-10.0622-0.24417-28.4886,8.59299,8.44836,6.88711,18.237-1.01015,26.2362,1.10047,4.34697,4.91697-2.06648,13.8779,1.31216,22.317,7.06953-0.6489,6.22049-14.2559,7.86595-19.1896,5.16445-18.0757,36.2143-30.6826,37.7931-47.2631,6.54677-2.93012,13.09-0.9165,21.0507,3.34487-3.96455-15.5336-17.0792-15.3664-20.5946-20.2178-8.36767-12.1907-15.7845-26.0981-33.6566-29.7059-13.5672-2.73878-12.5532,0.82385-21.2472-4.83-5.41355-4.01853-21.8612-11.6181-19.2298-5.45416z"/>
|
||||
|
||||
<path fill="#f90" d="m860.839,283.106c8.72935-10.2344,13.0534-31.1272,16.9171-38.2184,8.92956,2.05041,8.83312,3.40792,19.7799-2.96497-14.7027-3.98084-15.8096-3.62755-17.5012-10.0994,6.17695-19.1553,40.0786-23.0599,51.953-15.7817,12.2822,7.06894,4.4742,8.596,21.2779,20.0001,2.44044-10.3389-9.45634-14.9009-11.2359-22.6298,2.52932-5.96126,13.8358-4.74122,20.084-11.5316-3.90439-5.6561-16.127,1.41619-21.4712,2.33396-19.1762,4.09085-45.373-16.1931-61.4875-9.77821-5.77578-4.14976-6.96507-10.606-6.73193-19.3072-12.5539,10.5985-6.27225,21.5753-9.12921,26.805-7.39678,12.7485-16.8297,25.4974-11.8265,42.248,3.79803,12.7158,6.62838,10.1968,5.44639,20.1666-1.19785,6.44061-0.56211,23.8553,3.92513,18.7577z"/>
|
||||
|
||||
<path fill="#f90" d="m931.763,290.302c-13.7027-1.82835-34.6943,5.45107-43.0585,5.96673-2.77851-8.34642-1.51002-8.96995-12.8934-14.605,4.03197,14.0554,4.9217,14.7758-0.0129,19.5038-20.3904,4.86884-41.4321-20.7724-41.0411-34.2257-0.008-13.6779,5.40195-8.09713,6.94685-27.7067-10.5433,3.35691-8.48447,15.4235-14.502,20.8735-6.65962,1.01994-11.4131-8.83635-20.7407-10.4218-3.05765,6.11145,9.61345,12.4257,13.2018,16.3114,13.5917,13.53,8.93457,45.397,23.0288,55.2268-0.7374,6.85915-5.91783,11.1692-13.8492,15.48,16.0079,4.76053,22.612-6.04289,28.7845-6.41709,15.2702-0.5594,31.594,0.5423,44.0424-12.2046,9.45-9.67656,5.72467-10.6828,15.2857-14.8756,6.40117-2.35427,21.7049-11.8813,14.8078-12.9056z"/>
|
||||
|
Before Width: | Height: | Size: 4.0 KiB |
@@ -1,13 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
|
||||
<svg height="850" width="1300" version="1.1" xmlns="http://www.w3.org/2000/svg" id="Flag of Ã…land">
|
||||
<rect fill="#0053a5" height="850" width="1300" />
|
||||
<g fill="#ffce00">
|
||||
<rect height="850" width="250" x="400" />
|
||||
<rect height="250" width="1300" y="300" />
|
||||
</g>
|
||||
<g fill="#d21034">
|
||||
<rect height="850" width="100" x="475" />
|
||||
<rect height="100" width="1300" y="375" />
|
||||
</g>
|
||||
</svg>
|
||||
|
Before Width: | Height: | Size: 550 B |
|
Before Width: | Height: | Size: 6.3 KiB |
|
Before Width: | Height: | Size: 76 KiB |
@@ -1,5 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?><svg xmlns="http://www.w3.org/2000/svg" width="1200" height="600" viewBox="0 0 12 6">
|
||||
<rect width="12" height="2" fill="#00732f" id="green"/>
|
||||
<rect width="12" height="2" y="2" fill="#fff"/>
|
||||
<rect width="12" height="2" y="4"/>
|
||||
<rect width="3" height="6" fill="#f00" id="red"/></svg>
|
||||
|
Before Width: | Height: | Size: 326 B |
@@ -1,34 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<svg width="800" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.0" height="500">
|
||||
<rect width="800" fill="#74acdf" height="500"/>
|
||||
<rect y="166.67" width="800" fill="#fff" height="166.67"/>
|
||||
<g id="rays">
|
||||
<path id="ray1" stroke-width="1.1116" stroke="#85340a" fill="#f6b40e" d="m396.84 251.31l28.454 61.992s0.4896 1.185 1.28 0.8586c0.7902-0.3267 0.2988-1.5116 0.2988-1.5116l-23.715-63.956m-0.68 24.12c-0.3465 9.4278 5.4526 14.613 4.6943 23.032-0.7569 8.42 3.8673 13.18 4.9396 16.454 1.0733 3.2744-1.16 5.2323-0.198 5.6982 0.96336 0.4662 3.07-2.1207 2.3833-6.7756-0.68675-4.6549-4.2204-6.0368-3.3898-16.32 0.83-10.283-4.206-12.678-2.98-22.058"/>
|
||||
<use xlink:href="#ray1" transform="rotate(22.5 400,250)"/>
|
||||
<use xlink:href="#ray1" transform="rotate(45 400,250)"/>
|
||||
<use xlink:href="#ray1" transform="rotate(67.5 400,250)"/>
|
||||
<path id="ray2" fill="#85340a" d="m404.31 274.41c0.45334 9.0538 5.5867 13.063 4.5787 21.314 2.2133-6.5249-3.1233-11.583-2.82-21.22m-7.6487-23.757l19.487 42.577-16.329-43.887"/>
|
||||
<use xlink:href="#ray2" transform="rotate(22.5 400,250)"/>
|
||||
<use xlink:href="#ray2" transform="rotate(45 400,250)"/>
|
||||
<use xlink:href="#ray2" transform="rotate(67.5 400,250)"/>
|
||||
</g>
|
||||
<use xlink:href="#rays" transform="rotate(90 400,250)"/>
|
||||
<use xlink:href="#rays" transform="rotate(180 400,250)"/>
|
||||
<use xlink:href="#rays" transform="rotate(270 400,250)"/>
|
||||
<circle r="27.778" stroke="#85340a" cy="250" cx="400" stroke-width="1.5" fill="#f6b40e"/>
|
||||
<path id="loweyecontour" fill="#843511" d="m409.47 244.06c-1.8967 0.00003-3.7131 0.82183-4.7812 2.5312 2.1367 1.9227 6.8565 2.1318 10.062-0.21875-1.3883-1.4954-3.3845-2.3125-5.2812-2.3125zm-0.0312 0.4375c1.8462-0.0335 3.5717 0.81446 3.8125 1.6562-2.1367 2.3504-5.5508 2.1463-7.6875 0.4375 0.9348-1.4957 2.4391-2.0677 3.875-2.0938z"/>
|
||||
<use xlink:href="#uppalpebra" transform="matrix(-1 0 0 1 800.25 0)"/>
|
||||
<use xlink:href="#eyebrow_nose" transform="matrix(-1 0 0 1 800.25 0)"/>
|
||||
<use xlink:href="#pupil" transform="translate(18.862)"/>
|
||||
<use xlink:href="#lowpalpebra" transform="matrix(-1 0 0 1 800.25 0)"/>
|
||||
<path d="m395.75 253.84c-0.91341 0.16668-1.5625 0.97727-1.5625 1.9062 0 1.0614 0.87748 1.9062 1.9375 1.9062 0.62667 0 1.2025-0.2968 1.5625-0.8125 0.73952 0.55614 1.7646 0.61511 2.3125 0.625 0.0843 0.002 0.19312 0 0.25 0 0.54791-0.01 1.573-0.0689 2.3125-0.625 0.36 0.5157 0.93583 0.8125 1.5625 0.8125 1.06 0 1.9375-0.84488 1.9375-1.9062 0-0.92898-0.64918-1.7396-1.5625-1.9062 0.513 0.1809 0.84375 0.6765 0.84375 1.2188 0 0.7074-0.57124 1.2812-1.2812 1.2812-0.6804 0-1.2413-0.54015-1.2812-1.2188-0.20862 0.41637-1.0341 1.6551-2.6562 1.7188-1.6222-0.0636-2.4476-1.3024-2.6562-1.7188-0.04 0.6786-0.60085 1.2188-1.2812 1.2188-0.71001 0-1.2812-0.57385-1.2812-1.2812 0-0.54225 0.33075-1.0378 0.84375-1.2188z" fill="#85340a"/>
|
||||
<path d="m397.84 259.53c-2.138 0-2.9829 1.9368-4.9062 3.2188 1.0687-0.42633 1.9096-1.2693 3.4062-2.125 1.496-0.85442 2.7717 0.1875 3.625 0.1875h0.0312c0.8532 0 2.129-1.0416 3.625-0.1875 1.4967 0.8559 2.3688 1.6987 3.4375 2.125-1.9233-1.282-2.7996-3.2188-4.9375-3.2188-0.4266 0-1.2716 0.23055-2.125 0.65625h-0.0312c-0.85334-0.42642-1.6983-0.65625-2.125-0.65625z" fill="#85340a"/>
|
||||
<path d="m397.12 262.06c-0.8439 0.0374-1.9596 0.20675-3.5625 0.6875 3.8473-0.85434 4.6962 0.4375 6.4062 0.4375h0.0312c1.71 0 2.5588-1.292 6.4062-0.4375-4.2744-1.282-5.1242-0.4375-6.4062-0.4375h-0.0312c-0.80125 0-1.4372-0.3124-2.8438-0.25z" fill="#85340a"/>
|
||||
<path d="m393.75 262.72c-0.24819 0.003-0.51871 0.005-0.8125 0.0312 4.488 0.42766 2.3306 3 7.0312 3h0.0312c4.7007 0 2.5745-2.5724 7.0625-3-4.7007-0.4266-3.2146 2.3438-7.0625 2.3438h-0.0312c-3.6075 0-2.4959-2.4215-6.2188-2.375z" fill="#85340a"/>
|
||||
<path d="m403.85 269.66c0-2.1234-1.7233-3.8465-3.8463-3.8465-2.1233 0-3.8463 1.723-3.8463 3.8465 0.423-1.781 2.0166-3.0393 3.8463-3.0393 1.8333 0 3.424 1.2586 3.8463 3.0393v0 0z" fill="#85340a"/>
|
||||
<path id="eyebrow_nose" fill="#85340a" d="m382.73 244.02c4.9146-4.2729 11.11-4.9147 14.53-1.7086 0.837 1.1207 1.3733 2.319 1.5934 3.5696 0.4302 2.433-0.3303 5.0617-2.2367 7.7559 0.2151-0.001 0.6435 0.2124 0.8568 0.4266 1.6967-3.244 2.2967-6.5761 1.74-9.7454-0.1458-0.828-0.3735-1.643-0.6696-2.4357-4.7007-3.8452-11.11-4.2729-15.811 2.1377z"/>
|
||||
<path id="uppalpebra" fill="#85340a" d="m390.42 242.74c2.7767 0 3.4186 0.6417 4.7007 1.71 1.2833 1.0683 1.9233 0.8541 2.1367 1.0683 0.2124 0.2142 0 0.8541-0.4266 0.6399s-1.2833-0.6399-2.5633-1.7086c-1.2833-1.0696-2.5633-1.0683-3.8463-1.0683-3.8463 0-5.983 3.2046-6.4094 2.9907-0.4266-0.2142 2.1367-3.6325 6.4094-3.6325z"/>
|
||||
<use xlink:href="#loweyecontour" transform="translate(-19.181)"/>
|
||||
<circle id="pupil" cy="246.15" cx="390.54" r="1.923" fill="#85340a"/>
|
||||
<path id="lowpalpebra" fill="#85340a" d="m385.29 247.44c3.6327 2.7783 7.265 2.5644 9.4017 1.282 2.1367-1.282 2.1367-1.7086 1.71-1.7086-0.4266 0-0.8532 0.4266-2.5633 1.281-1.71 0.8559-4.273 0.8559-8.546-0.8541z"/>
|
||||
</svg>
|
||||
|
Before Width: | Height: | Size: 4.9 KiB |
@@ -1,6 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="1200" height="600">
|
||||
<rect fill="#F2A800" width="1200" height="600"/>
|
||||
<rect fill="#0033A0" width="1200" height="400"/>
|
||||
<rect fill="#D90012" width="1200" height="200"/>
|
||||
</svg>
|
||||
|
Before Width: | Height: | Size: 259 B |
@@ -1,110 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="1000" height="500">
|
||||
|
||||
<rect height="500" width="1000" fill="#006"/>
|
||||
|
||||
<path d="M0,250 1000,0V500z" fill="#bd1021"/>
|
||||
|
||||
<path d="M107.14,250 1000,26.79V473.21" fill="#fff"/>
|
||||
<g stroke="#000" stroke-width="1.72">
|
||||
|
||||
<path d="m832.04,306.06s-6.2429-5.108,1.135-13.337c-3.973-3.4049-0.2834-9.9312-0.2834-9.9312s-6.8111-2.5547,0.2834-13.054c-5.108-3.4049-2.8381-11.068-2.8381-11.068s-16.742-6.2429-0.85018-12.201c-13.054,5.6748-25.257-7.6626-25.257-7.6626l-19.012,0.56816c-3.2161-15.797-28.283-2.0814-9.6482-47.39-4.8242-0.85142-10.216-2.27-15.607,1.7027-5.3916,3.9728-20.715,12.486-29.796,3.9728-9.0806-8.5131,5.9593-20.715,6.2431-20.999,0.28367-0.2838,20.148-10.5,22.986-17.31-0.28381-5.108-6.5269-9.0806-0.85142-20.148,6.5267-10.5,46.538-20.432,64.701-23.837,8.7962-3.9728,12.769-11.635,12.769-11.635l1.9865,7.378s40.296-11.918,42.282-17.594c1.9865-5.6755,0.85156,5.1078,0.85156,5.1078,15.891-1.4189,36.038-15.04,38.876-8.7969,13.337-2.5539,38.877-13.905,38.877-13.905s8.7962-0.28364,2.5533,9.3646c3.973,6.2429-1.135,11.635-1.4184,11.635-0.28477,0,1.7017,6.2429-3.4062,9.6482,1.7045,5.3916-3.1215,9.6482-3.1215,9.6482s2.2713,6.5267-6.8097,9.932c0.85157,5.6755-5.108,6.8106-5.108,6.8106s0.85156,5.9593-3.1215,8.5131c0,4.5404-4.5398,6.8106-4.5398,6.8106s2.8367,1.7026-1.1363,4.5404c-3.9716,2.8377-45.119,28.093-45.119,27.81,0-0.28366,30.08,5.3917,32.066,6.5268,1.9865,1.1351,24.688,16.175,24.688,16.175l-22.987,28.377s-25.539-2.8367-26.673-1.4184c-1.135,1.4184,5.3914,1.9865,6.8097,4.2564,1.4197,2.2699,3.6896,7.6627,8.2294,7.0945,4.5412-0.56816-8.5129,8.2295-17.026,9.081,0,3.1215,10.783,3.4049,13.621,0.85155,2.8381-2.5547-6.8111,7.3779-7.9461,8.7962s12.771-1.9865,12.771-1.9865-2.2713,9.3644-14.472,12.202c4.8232,7.946,2.8367,13.054,2.5533,13.054-0.28339,0-7.946-7.946-15.324-6.5277,1.9865,7.6627,7.9461,14.756,9.6492,15.892,1.7017,1.135-13.337,0.85018-15.324-3.4062-1.9865-4.2564-3.6896,10.216,1.7018,14.757-6.2416,0.2834-11.634-3.4062-11.634-3.4062s-3.6882,8.5128-1.135,12.771c2.5547,4.2564-8.7962-8.5142-8.7962-8.5142l-21.567,9.081-4.8246-8.2294z" fill="#9c3900" stroke-linejoin="round"/>
|
||||
|
||||
<g fill="#ffc221">
|
||||
<path d="m665.36,289.17c0.50543,0,31.331-0.50627,45.48-8.5913,7.0747,11.117,16.676,18.697,16.676,18.697l4.5481-16.17s11.117,0.50489,12.128,3.032c-1.516,3.0307-2.0213,7.0739-2.0213,7.0739s7.58,0.50627,8.0853,1.516c0.5053,1.0111-2.0213,9.601-2.0213,9.601l32.342,7.5801s2.5266-12.633,5.0532-11.117c2.5268,1.516,13.644,17.181,29.31,18.192,15.665,1.0111,16.676-13.139,16.676-13.139l3.5369,2.0223s6.569-14.149,7.5801-14.149,2.5272,2.0209,11.117,2.0209c2.5272,3.032,3.5383,10.106,3.5383,10.106s-9.6024,9.6024-6.5704,17.183c3.032,7.5801,3.5383,5.5578,3.5383,5.5578l69.736,16.676s3.5383,5.5592-2.5258,8.5913c0,0.50489-70.242-16.171-70.242-16.171s-6.5704,7.5801-11.623,6.0641c-5.053-1.516-1.516,3.032-1.516,3.032l75.8,6.0641s5.5592,7.0752,1.516,9.0962c-5.053,0.50488-81.864-5.053-81.864-5.053s-4.5481,9.601-9.601,1.516c-3.5369,5.5578-7.5801-1.516-7.5801-1.516s-6.569,5.053-7.5801-0.50626c-5.5592,4.0432-9.0961-2.5258-9.0961-2.5258l-32.341-2.0223-2.0213,3.032s5.5587,1.516-3.032,5.0543c-8.5907,3.5369,51.544,2.0209,53.06,2.5258,1.516,0.50625-4.0418,5.0543-4.0418,5.0543s30.825,2.0209,36.383-4.5481c5.5592-6.5703-2.0209,8.5899-2.0209,8.5899s24.256-1.0098,24.256-2.0209-0.50626,7.5801-17.181,6.569c10.106,6.5704,22.739,10.612,22.739,10.612s-12.633,3.032-27.287-0.50488c2.5258,6.569,13.644,12.633,13.644,12.633s-8.0864,7.0752-26.279-10.107c5.0543,9.0962,1.0111,12.634,0.50625,11.623-0.50625-1.0111-9.0961-13.644-29.309-18.192,12.633,8.085,7.0739,11.623,7.0739,11.623s-6.569-11.623-17.181,0c-4.0432-10.612-19.708-16.676-38.911-17.687-6.064-7.0739-9.6014-5.0529-23.751-9.0961-8.0853-9.0948-19.708-19.202-19.708-19.202s0.5053-13.644,14.149-12.128c1.516,4.5481,1.516,3.032,1.516,3.032s15.16-5.5592,19.708,2.0209c6.5692-11.623,15.665-1.7375,17.181,2.3043,4.3537,0.63832,26.278,1.2326,26.278,1.2326s-2.5272-4.5481-1.0112-4.0418c1.516,0.50488,13.644-4.5481,13.139-6.0641-0.50625-1.516-1.0111-6.569,1.0098-6.0641,2.0223,0.50489-17.181-2.5272-27.793,5.5592-3.5373-3.5383-1.0106-13.139-1.0106-13.139l-31.331-6.569-1.516,8.085s-9.096,1.516-8.5907-0.50487c0.50529-2.0223-2.0213,7.0739-2.0213,7.0739s-12.128-3.0321-12.128-3.5369c0-0.50489,3.5374-18.192,3.5374-17.687,0,0.50626-10.107,1.0112-24.256,11.623-4.0426-12.633-35.879-29.309-35.879-29.814z"/>
|
||||
|
||||
<path d="m704.78,247.73s-21.224,18.191,0,28.803c1.0106-7.0752,2.5268-8.085,2.5268-8.085s17.687,6.569,28.299-9.0961c-4.5481-6.569-12.633-4.0418-12.633-4.0418s-16.676-0.001-18.192-7.5801z"/>
|
||||
</g>
|
||||
<path d="m722.47,255.82-14.655,12.633" fill="none"/>
|
||||
|
||||
<g fill="#fff">
|
||||
<path d="m705.48,247.88,0,0s2.8377-2.8381,3.6891-6.2429c0.85129-3.4049-1.1351-7.0945,2.2702-10.216,3.4051-3.1215,48.241-22.134,51.93-25.823,3.6891-3.6888,10.499-11.634,11.351-13.337,0.85129-1.7027,3.4053,8.5131-4.2566,13.054,8.2293-2.2707,13.621-4.8243,17.026-3.6892-3.4058,4.8242-12.486,12.77-16.743,12.77,9.932-3.6896,19.012-6.8111,21.567-4.8246,2.5533,1.9865-12.202,11.919-18.162,12.486,9.932-2.5533,23.27-6.5263,24.971-2.2699-5.3914,1.7031-3.6896,3.1201-14.756,9.3644-1.4188,1.1363-8.5131,1.4184-8.5131,1.4184,8.5131-0.85156,20.147-4.2564,21.282,1.9865-6.8097,2.5533-9.3639,5.9595-15.039,7.3779-5.6755,1.4197-18.729,3.973-26.675,7.0945-7.9455,3.1215-19.58,12.202-19.58,12.202s-25.256,0.85155-25.256,0.56678c0-0.28339-4.824-11.634-5.1078-11.918z" stroke-linejoin="round"/>
|
||||
|
||||
<path d="m921.99,230.57,49.092,9.3644s5.3928-6.2429,2.5547-9.6478c7.3779-1.7017,5.3914-11.351,5.3914-11.351s8.5128-3.6883,1.4183-12.202c4.826-4.8239-1.135-8.5128-1.135-8.5128s1.9865-8.5131-4.2564-9.3644c1.7031-6.8104-10.783-9.0807-10.783-9.0807s-25.823,7.0944-43.985,7.6618c5.9595,5.9593-2.2699,9.6482-2.2699,9.6482s4.8246,3.4053,3.4049,6.2429c-1.4183,2.8382,0.85157,5.9597-5.3914,7.9462,8.2294,3.6896-0.85156,9.9312-0.85156,9.9312s9.081,6.2429,6.8111,9.3644z"/>
|
||||
|
||||
</g>
|
||||
<g fill="none">
|
||||
|
||||
<path d="m742.17,293.72-6.5694,29.309"/>
|
||||
|
||||
<path d="m748.24,304.83-2.0213,9.601"/>
|
||||
|
||||
<path d="m780.58,312.41-3.032,9.0962"/>
|
||||
|
||||
<path d="m836.67,374.06c-0.50489,0-16.17,2.0209-18.192,1.516-2.0209-0.50489,24.761,8.085,24.761,11.622"/>
|
||||
|
||||
<path d="m808.37,377.6s-15.666-10.106-18.192-9.0961c-2.5269,1.0111,15.665-0.50489,17.181-2.0209"/>
|
||||
|
||||
<path d="m776.03,365.98s-16.171,0.50488-17.687-1.0111,15.665,11.117,18.697,10.107"/>
|
||||
|
||||
<path d="m744.7,358.9c-0.5053,0-11.117-4.0418-15.665-5.0543,4.0426,4.0432,7.0747,9.6024,17.181,11.623"/>
|
||||
|
||||
<path d="m748.74,352.34c-0.50529-1.0111-20.213-7.0752-20.213-10.107,4.5481,1.516,11.117,3.5369,17.181,2.0209"/>
|
||||
|
||||
<path d="m853.35,329.09-2.0209,9.0948"/>
|
||||
|
||||
<path d="m767.6,343.56s3.3779,3.724,0.34585,8.2721"/>
|
||||
|
||||
<path d="m838.69,347.28-5.5578,0.50625"/>
|
||||
|
||||
<path d="m793.21,344.25,10.106,1.516"/>
|
||||
|
||||
<path d="m820.4,318.26s0.2834,10.216-8.2294,9.9326c-8.5128-0.28477-5.6762,0.2834-5.6762,0.2834"/>
|
||||
|
||||
<path d="m826.93,316.55s3.4049,1.135,2.5547,3.6896c-0.85155,2.5533,0.85018,9.9312-9.081,17.026-10.501,2.2699-9.3644-8.7962-9.3644-8.7962"/>
|
||||
|
||||
<path d="m830.62,319.68s6.2429-3.6883,7.0945,2.2713c0.85018,5.9582-5.108,17.026-9.3644,18.729-4.2578,1.7018-9.081-0.28476-8.5142-3.1215"/>
|
||||
|
||||
<path d="m838.28,322.23s5.6762-4.5412,7.3779,1.4184c1.7031,5.9596-4.5398,19.297-7.0945,19.58"/>
|
||||
|
||||
<path d="m846.23,323.65s2.8381-1.4184,4.8232,0.28339"/>
|
||||
|
||||
<path d="m837.15,344.08c-1.135,0.28339-5.9595,0.56678-7.6613-3.1215"/>
|
||||
|
||||
<path d="m811.61,334.15c-0.28339,0-5.9582,0.28476-5.9582,0.28476"/>
|
||||
|
||||
<path d="m833.46,356.57-0.56679-9.3644-2.2699-3.1215-3.973,3.973s-0.56816,9.3644-2.2699,10.216"/>
|
||||
|
||||
<path d="m826.65,347.77c-0.28339-0.56678-3.1215-5.9582-3.1215-5.9582l-4.8246,5.9582s-0.5668,8.5142-2.2699,9.3658"/>
|
||||
|
||||
<path d="m818.7,347.49c0-0.28339-1.9865-5.6748-1.9865-5.6748s-5.6748,3.1215-6.2429,5.3914c-0.56679,2.2699-0.85156,8.5128-2.2699,9.081"/>
|
||||
|
||||
<path d="m810.47,346.07s0.56816-5.108-1.135-5.108c-1.7018,0-9.3644,7.0945-9.6478,13.337"/>
|
||||
|
||||
<path d="m717.39,245.9s0.28382-5.6748,2.8377-7.6613c2.554-1.9865,15.324-6.8111,18.161-11.068,2.8377-4.2564-4.2566,7.3779-3.1215,10.499"/>
|
||||
|
||||
<path d="m722.5,237.38s6.2431,2.2713,4.8242,7.0945"/>
|
||||
|
||||
<path d="m57.344,126.01a3.9192,3.9192,0,1,1,-7.8384,0,3.9192,3.9192,0,1,1,7.8384,0z" transform="matrix(1.1946929,0,0,1.1946929,661.37184,90.106184)" stroke-width="1pt"/>
|
||||
|
||||
<path d="m917.17,220.07,0,0s43.417,5.108,45.404,5.108c1.9865,0,9.6478,2.5547,11.068,5.108"/>
|
||||
|
||||
<path d="m919.44,217.52,60.443,1.4184"/>
|
||||
|
||||
<path d="m919.72,216.1s57.321-3.4049,61.294-9.3644"/>
|
||||
|
||||
<path d="m921.43,203.61s57.606-6.2429,58.174-5.3916"/>
|
||||
|
||||
<path d="m919.44,196.52s55.903-8.7969,56.47-7.378"/>
|
||||
|
||||
<path d="m759.96,160.48s17.594,19.296,15.891,32.35"/>
|
||||
|
||||
<path d="m774.72,182.61s5.6753,8.2293,7.9455,9.0806c2.2702,0.85128,22.134,1.9864,23.269,10.5,1.135,5.3916-4.2564,3.6885-3.4049,7.6616,1.4184,5.108,14.756,11.634,29.228,3.973"/>
|
||||
|
||||
<path d="m818.42,217.8s11.918,17.594,29.512-1.4183"/>
|
||||
|
||||
<path d="m838.85,224.05s14.472,7.6613,26.39-12.202"/>
|
||||
|
||||
<path d="m849.92,225.75s7.0945,5.9596,21.852-1.9851"/>
|
||||
|
||||
<path d="m892.2,215.82s21.85,4.5398,23.27,5.9596"/>
|
||||
|
||||
<path d="m900.43,210.99c0.28339,0,15.324,0.56817,15.324,0.56817"/>
|
||||
|
||||
<path d="m891.06,202.48s26.107-1.7026,29.513,3.6895"/>
|
||||
|
||||
<path d="m879.71,194.25s36.607,1.4188,38.309,3.4053"/>
|
||||
|
||||
<path d="m887.94,231.71s6.2429-1.7017,7.0945-0.85019"/>
|
||||
|
||||
|
Before Width: | Height: | Size: 13 KiB |
|
Before Width: | Height: | Size: 6.7 KiB |
@@ -1,18 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" width="600" height="400">
|
||||
<defs>
|
||||
<path id="s" transform="scale(21)" fill="#fff" d="M0,-1 L0.58779,0.80902 L-0.95106,-0.30902 L0.95106,-0.30902 L-0.58779,0.80902z"/>
|
||||
</defs>
|
||||
<rect fill="#002395" height="400" width="600" />
|
||||
<rect fill="#fff" height="164" width="244" />
|
||||
<rect fill="#002395" height="160" width="80" />
|
||||
<rect fill="#ED2939" height="160" width="80" x="160"/>
|
||||
<path fill="#fff" d="M355,183 l12.875,20.5 h36.625 v71.5 l-27.5,-43 -37,59 h18 l19,-34 39,70 39,-70 19,34 h18 l-37,-59 -27.5,43 v-39.5 h16.5 l12.25,-19.5 h-28.75 v-12.5 h36.625 l12.875,-20.5 h-122z
|
||||
M398,270.5h-40v14h40z
|
||||
M474,270.5h-40v14h40z"/>
|
||||
<use xlink:href="#s" x="416" y="362"/>
|
||||
<use xlink:href="#s" x="371" y="328"/>
|
||||
<use xlink:href="#s" x="461" y="328"/>
|
||||
<use xlink:href="#s" x="333" y="227"/>
|
||||
<use xlink:href="#s" x="499" y="227"/>
|
||||
</svg>
|
||||
|
Before Width: | Height: | Size: 986 B |
@@ -1,17 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="690" height="460" viewBox="0 0 138 92">
|
||||
<rect width="138" height="92" fill="#fff"/>
|
||||
<rect width="138" height="36" fill="#000"/>
|
||||
<g transform="translate(69,36)">
|
||||
<g id="c3">
|
||||
<!-- y3 = -y2 = 30*sin(11.25deg)/sqrt(5-4*cos(11.25deg)-sin^2(11.25deg)) -->
|
||||
<path id="c" d="M-30,0 0,-5.7423716V5.7423716z" fill="#fcd116"/>
|
||||
<use xlink:href="#c" transform="rotate(22.5)"/>
|
||||
<use xlink:href="#c" transform="rotate(45)"/>
|
||||
</g>
|
||||
<use xlink:href="#c3" transform="rotate(67.5)"/>
|
||||
<use xlink:href="#c3" transform="rotate(135)"/>
|
||||
</g>
|
||||
<rect y="36" width="138" height="20" fill="#0072c6"/>
|
||||
<path d="M0,0V92H138V0L69,92z" fill="#ce1126"/>
|
||||
</svg>
|
||||
|
Before Width: | Height: | Size: 769 B |
@@ -1 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="1280" height="640" viewBox="0 0 30240 15120"><defs id="defs6"><polygon points="0,-9 1.735535,-3.6038755 7.0364833,-5.6114082 3.8997116,-0.89008374 8.7743512,2.0026884 3.1273259,2.4939592 3.9049537,8.1087198 0,4 -3.9049537,8.1087198 -3.1273259,2.4939592 -8.7743512,2.0026884 -3.8997116,-0.89008374 -7.0364833,-5.6114082 -1.735535,-3.6038755 0,-9 " id="Star7"/><polygon points="0,-9 2.351141,-3.236068 8.5595086,-2.7811529 3.8042261,1.236068 5.2900673,7.2811529 0,4 -5.2900673,7.2811529 -3.8042261,1.236068 -8.5595086,-2.7811529 -2.351141,-3.236068 0,-9 " id="Star5"/></defs><path d="M 0,0 L 30240,0 L 30240,15120 L 0,15120 L 0,0 z" style="fill:#00008b"/><use transform="matrix(252,0,0,252,7560,11340)" id="Commonwealth_Star" style="fill:#fff" xlink:href="#Star7"/><use transform="matrix(120,0,0,120,22680,12600)" id="Star_Alpha_Crucis" style="fill:#fff" xlink:href="#Star7"/><use transform="matrix(120,0,0,120,18900,6615)" id="Star_Beta_Crucis" style="fill:#fff" xlink:href="#Star7"/><use transform="matrix(120,0,0,120,22680,2520)" id="Star_Gamma_Crucis" style="fill:#fff" xlink:href="#Star7"/><use transform="matrix(120,0,0,120,26040,5607)" id="Star_Delta_Crucis" style="fill:#fff" xlink:href="#Star7"/><use transform="matrix(70,0,0,70,24192,8190)" id="Star_Epsilon_Crucis" style="fill:#fff" xlink:href="#Star5"/><path d="M 6300,0 L 8820,0 L 8820,2520 L 15120,2520 L 15120,5040 L 8820,5040 L 8820,7560 L 6300,7560 L 6300,5040 L 0,5040 L 0,2520 L 6300,2520 L 6300,0 z" id="White_Cross" style="fill:#fff"/><path d="M 0,0 L 1690.4674,0 L 15120,6714.7663 L 15120,7560 L 13429.533,7560 L 0,845.2337 L 0,0 z" id="White_Diagonal" style="fill:#fff"/><use transform="matrix(-1,0,0,1,15120,0)" id="White_Diagonal_Flipped" style="fill:#fff" xlink:href="#White_Diagonal"/><path d="M 6804,0 L 8316,0 L 8316,3024 L 15120,3024 L 15120,4536 L 8316,4536 L 8316,7560 L 6804,7560 L 6804,4536 L 0,4536 L 0,3024 L 6804,3024 L 6804,0 z" id="Red_Cross" style="fill:red"/><path d="M 0,0 L 5040,2520 L 3913.0217,2520 L 0,563.48913 L 0,0 z M 15120,0 L 13993.022,0 L 8953.0217,2520 L 10080,2520 L 15120,0 z" id="Red_Diagonals" style="fill:red"/><use transform="matrix(-1,0,0,-1,15120,7560)" id="Red_Diagonals_Rotated" style="fill:red" xlink:href="#Red_Diagonals"/></svg>
|
||||
|
Before Width: | Height: | Size: 2.3 KiB |
@@ -1,5 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="900" height="600">
|
||||
<rect fill="#ed2939" width="900" height="600"/>
|
||||
<rect fill="#fff" y="200" width="900" height="200"/>
|
||||
</svg>
|
||||
|
Before Width: | Height: | Size: 216 B |
@@ -1,12 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="520" height="340" viewBox="0 0 260 170">
|
||||
<rect fill="#0064AE" width="260" height="170"/>
|
||||
<g fill="#FFD300">
|
||||
<rect x="80" width="50" height="170"/>
|
||||
<rect y="60" width="260" height="50"/>
|
||||
</g>
|
||||
<g fill="#DB0F16">
|
||||
<rect x="95" width="20" height="170"/>
|
||||
<rect y="75" width="260" height="20"/>
|
||||
</g>
|
||||
</svg>
|
||||
|
Before Width: | Height: | Size: 386 B |
@@ -1,8 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?><svg xmlns="http://www.w3.org/2000/svg" width="1200" height="600">
|
||||
<rect width="1200" height="600" style="fill:#0098c3"/>
|
||||
<rect width="1200" height="200" y="200" style="fill:#e00034"/>
|
||||
<rect width="1200" height="200" y="400" style="fill:#00ae65"/>
|
||||
<circle fill="#fff" cx="581" cy="300" r="90"/>
|
||||
<circle fill="#e00034" cx="600" cy="300" r="75"/>
|
||||
<path d="M 716.38014,335.33055 690.58329,323.09028 681.03508,350 671.44912,323.1037 645.66947,335.38014 657.90973,309.58329 631,300.03508 l 26.89631,-9.58596 -12.27645,-25.77965 25.79686,12.24026 9.54821,-26.90973 9.58596,26.8963 25.77965,-12.27644 -12.24026,25.79686 26.90973,9.5482 -26.8963,9.58596 z" style="fill:#fff"/>
|
||||
</svg>
|
||||
|
Before Width: | Height: | Size: 722 B |
@@ -1,27 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="500" height="300">
|
||||
<defs>
|
||||
<g id="b" fill="#1eb53a">
|
||||
<g id="s">
|
||||
<g id="t">
|
||||
<g id="c">
|
||||
<path id="h" d="M0,-20V0H20" transform="rotate(30,0,-20)"/>
|
||||
<use xlink:href="#h" transform="scale(-1,1)"/>
|
||||
</g>
|
||||
<use xlink:href="#c" transform="rotate(120)"/>
|
||||
<use xlink:href="#c" transform="rotate(240)"/>
|
||||
</g>
|
||||
<use xlink:href="#t" transform="rotate(180)"/>
|
||||
</g>
|
||||
<use xlink:href="#s" fill="#ce1126" transform="scale(0.82)"/>
|
||||
</g>
|
||||
<use id="star" xlink:href="#b" x="250" y="106"/>
|
||||
</defs>
|
||||
<path d="M0,0H500L0,300H500z" fill="#ce1126"/>
|
||||
<path d="M0,0V300L500,0V300z" fill="#1eb53a"/>
|
||||
<path d="M0,0 500,300M500,0 0,300" stroke="#fff" stroke-width="40"/>
|
||||
<circle cx="250" cy="150" r="85" fill="#fff"/>
|
||||
<use xlink:href="#star"/>
|
||||
<use xlink:href="#star" transform="rotate(120,250,150)"/>
|
||||
<use xlink:href="#star" transform="rotate(240,250,150)"/>
|
||||
</svg>
|
||||
|
Before Width: | Height: | Size: 985 B |
@@ -1,6 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="450" height="390">
|
||||
<rect width="450" height="390" fill="#ED2939"/>
|
||||
<rect width="300" height="390" fill="#FAE042"/>
|
||||
<rect width="150" height="390"/>
|
||||
</svg>
|
||||
|
Before Width: | Height: | Size: 241 B |
@@ -1,6 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="1500" height="1000" viewBox="0 0 15 10">
|
||||
<rect width="15" height="10" fill="#fcd116" id="Yellow"/>
|
||||
<rect width="15" height="5" y="5" fill="#e8112d" id="Red"/>
|
||||
<rect width="6" height="10" fill="#008751" id="Green"/>
|
||||
</svg>
|
||||
|
Before Width: | Height: | Size: 328 B |
@@ -1,14 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="600" height="400">
|
||||
<rect width="600" height="400" fill="#fff" />
|
||||
<path d="M 600,400 0,400 600,0 z" fill="#012a87" />
|
||||
<path d="M 0,0 0,166.666667 250,0 z" fill="#f9d90f" />
|
||||
<circle cx="165" cy="173" r="80" fill="none" stroke="#000" stroke-width="11" />
|
||||
<g id="g">
|
||||
<path d="m 165,69.834474 15,25.98076211 -30,0 z" fill="#000" id="a"/>
|
||||
<use xlink:href="#a" transform="rotate(180,165,173)" />
|
||||
</g>
|
||||
<use xlink:href="#g" transform="rotate(90,165,173)" />
|
||||
<path d="M 165,122 209.16729559,198.5 120.83270441,198.5 z" fill="#dc171d" id="b" />
|
||||
<use xlink:href="#b" transform="rotate(60,165,173)" />
|
||||
</svg>
|
||||
|
Before Width: | Height: | Size: 737 B |