Skip to content

Commit

Permalink
added CountryMessageConverter
Browse files Browse the repository at this point in the history
(cherry picked from commit cdce1bb)
  • Loading branch information
marcos-lg committed Oct 29, 2024
1 parent a48ebee commit ed456a8
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.gbif.checklistbank.ws.client.NubResourceClient;
import org.gbif.registry.domain.ws.*;
import org.gbif.registry.security.precheck.AuthPreCheckInterceptor;
import org.gbif.registry.ws.converter.CountryMessageConverter;
import org.gbif.registry.ws.converter.UuidTextMessageConverter;
import org.gbif.registry.ws.provider.CollectionDescriptorsSearchRequestHandlerMethodArgumentResolver;
import org.gbif.registry.ws.provider.CollectionSearchRequestHandlerMethodArgumentResolver;
Expand Down Expand Up @@ -192,4 +193,9 @@ public NubResourceClient nubResourceClient(@Value("${api.root.url}") String apiR
.withUrl(apiRootUrl)
.build(NubResourceClient.class);
}

@Bean
public CountryMessageConverter countryMessageConverter() {
return new CountryMessageConverter();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package org.gbif.registry.ws.converter;

import org.gbif.api.util.VocabularyUtils;
import org.gbif.api.vocabulary.Country;
import org.springframework.core.convert.converter.Converter;

public class CountryMessageConverter implements Converter<String, Country> {

@Override
public Country convert(String source) {
return parseCountry(source);
}

private Country parseCountry(String param) {
Country country = Country.fromIsoCode(param);
if (country == null) {
// if nothing found also try by enum name
country = VocabularyUtils.lookupEnum(param, Country.class);
}
return country;
}
}

0 comments on commit ed456a8

Please sign in to comment.