Commit 4e4ce720 authored by Matija Obreza's avatar Matija Obreza

Removed workarounds for ITPGRFA country status import

parent 8f2f02bc
......@@ -41,7 +41,22 @@ public interface GeoService {
*/
void updateCountryData() throws IOException;
Country getCountry(String iso3);
/**
* Get country by ISO CODE (either 2 or 3)
*
* @param isoCode
* @return
*/
Country getCountry(String isoCode);
/**
* Tries to find country by ISO CODE2, ISO CODE3, Country name and
* translations
*
* @param findCountry
* @return
*/
Country findCountry(String countryString);
List<Country> listAll();
......@@ -92,7 +107,7 @@ public interface GeoService {
* @param membership
* @param membershipBy
* @param nameOfNFP
* @return
* @return
*/
ITPGRFAStatus updateITPGRFA(Country country, String contractingParty, String membership, String membershipBy, String nameOfNFP);
......
......@@ -95,14 +95,21 @@ public class GeoServiceImpl implements GeoService {
}
@Override
public Country getCountry(String countryString) {
public Country getCountry(String isoCode) {
Country country = null;
if (countryString.length() == 3) {
country = countryRepository.findByCode3(countryString);
} else if (countryString.length() == 2) {
country = countryRepository.findByCode2(countryString);
if (isoCode.length() == 3) {
country = countryRepository.findByCode3(isoCode);
} else if (isoCode.length() == 2) {
country = countryRepository.findByCode2(isoCode);
}
return country;
}
@Override
public Country findCountry(String countryString) {
Country country = getCountry(countryString);
// Let's try the name
if (country == null) {
country = countryRepository.findByName(countryString);
......@@ -383,7 +390,7 @@ public class GeoServiceImpl implements GeoService {
LOG.info("Updating ITPGRFA entry for " + country.getName());
}
itpgrfaStatus.setContractingParty(contractingParty);
itpgrfaStatus.setMembership(membershipBy);
itpgrfaStatus.setMembership(membership);
itpgrfaStatus.setMembershipBy(membershipBy);
itpgrfaStatus.setNameOfNFP(nameOfNFP);
......
......@@ -22,9 +22,7 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.ArrayUtils;
......@@ -68,28 +66,14 @@ public class ITPGRFAStatusUpdater {
private static final int BATCH_SIZE = 20;
// FIXME Need ISO CODE3 in ITPGRFA CSV file!!
private static final Map<String, String> workarounds = new HashMap<String, String>();
private static final String[] CSV_HEADERS = { "Country", "FAO Region 1", "FAO Region 2", "CP", "Name of NFP", "Membership", "by", "Income", "Development" };
static {
workarounds.put("Democratic People's Republic of Korea", "PRK");
workarounds.put("Iran (Islamic Republic of)", "IRN");
workarounds.put("Cote d'Ivoire", "CIV");
workarounds.put("Micronesia (Federated States of)", "FSM");
workarounds.put("Republic of Moldova", "MDA");
workarounds.put("Lao People's Democratic Republic", "LAO");
workarounds.put("Republic of Korea", "KOR");
workarounds.put("Syrian Arab Republic", "SYR");
workarounds.put("The former Yugoslav Republic of Macedonia", "MKD");
workarounds.put("Russian Federation", "RUS");
workarounds.put("United Republic of Tanzania", "TZA");
workarounds.put("United States of America", "USA");
workarounds.put("Venezuela (Bolivarian Republic of)", "VEN");
workarounds.put("Viet Nam", "VNM");
LOG.warn("There are still " + workarounds.size() + " hardcoded workarounds for country names in ITPGRFA CSV file!");
}
private static final String[] CSV_HEADERS = { "Country ISO CODE", "Country", "FAO Region 1", "FAO Region 2", "CP", "Name of NFP", "Membership", "by",
"Income", "Development" };
protected static final int COLUMN_ISOCODE3 = 0;
protected static final int COLUMN_CONTRACTING_PARTY = 4;
protected static final int COLUMN_NAME_OF_NFP = 5;
protected static final int COLUMN_MEMBERSHIP = 6;
protected static final int COLUMN_MEMBERSHIP_BY = 7;
/**
* Update local {@link ITPGRFAStatus} entries with data from CSV
......@@ -163,16 +147,11 @@ public class ITPGRFAStatusUpdater {
}
}
if (line[0] == null) {
LOG.warn("Country name is null, skipping line" + ArrayUtils.toString(line, "NULL"));
if (line[COLUMN_ISOCODE3] == null) {
LOG.warn("Country ISO CODE 3 is null, skipping line" + ArrayUtils.toString(line, "NULL"));
continue;
}
if (workarounds.containsKey(line[0])) {
LOG.warn("Replacing " + line[0] + " with " + workarounds.get(line[0]));
line[0] = workarounds.get(line[0]);
}
LOG.warn(">>> " + ArrayUtils.toString(line, "NULL"));
batch.add(line);
......@@ -210,17 +189,18 @@ public class ITPGRFAStatusUpdater {
if (LOG.isDebugEnabled()) {
LOG.debug("Working on " + ArrayUtils.toString(line, "NULL"));
}
updateCountry(line[0], line[3], line[4], line[5], line[6]);
updateCountry(line[COLUMN_ISOCODE3], line[COLUMN_CONTRACTING_PARTY], line[COLUMN_NAME_OF_NFP], line[COLUMN_MEMBERSHIP],
line[COLUMN_MEMBERSHIP_BY]);
}
}
});
}
protected void updateCountry(String countryName, String contractingParty, String nameOfNFP, String membership, String membershipBy) {
Country country = geoService.getCountry(countryName);
protected void updateCountry(String countryIso3, String contractingParty, String nameOfNFP, String membership, String membershipBy) {
Country country = geoService.getCountry(countryIso3);
if (country == null) {
LOG.error("No country with name=" + countryName);
LOG.error("No country with name=" + countryIso3);
return;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment