Commit f11aded1 authored by Matija Obreza's avatar Matija Obreza

Resolved most important warnings from FindBugs and PMD

parent 73d705e3
......@@ -40,7 +40,7 @@ cleanup.remove_unused_private_fields=true
cleanup.remove_unused_private_members=false
cleanup.remove_unused_private_methods=true
cleanup.remove_unused_private_types=true
cleanup.sort_members=true
cleanup.sort_members=false
cleanup.sort_members_all=false
cleanup.use_blocks=true
cleanup.use_blocks_only_for_return_and_throw=false
......
......@@ -59,6 +59,7 @@ public class DavrosCountrySource {
response = httpclient.execute(httpget);
} catch (final ClientProtocolException e) {
LOG.error(e.getMessage(), e);
throw new IOException("Could not execute HTTP request: " + e.getMessage(), e);
}
LOG.debug(response.getStatusLine());
......
......@@ -63,6 +63,7 @@ public class GeoNamesCountrySource {
response = httpclient.execute(httpget);
} catch (final ClientProtocolException e) {
LOG.error(e.getMessage(), e);
throw new IOException("Could not execute HTTP request: " + e.getMessage(), e);
}
LOG.debug(response.getStatusLine());
......
......@@ -56,7 +56,7 @@ public class AsAdminAspect {
// check whether it's not SYS_ADMIN already
// FIXME check if prevAuth has ADMIN role
if (prevAuth == null || prevAuth.getName() != SYS_ADMIN.getName()) {
if (prevAuth == null || !prevAuth.getName().equals(SYS_ADMIN.getName())) {
LOG.warn("Granting ADMIN privileges");
swapped = true;
......
/**
* Copyright 2014 Global Crop Diversity Trust
*
* Licensed 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
*
* http://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.
**/
package org.genesys2.server.factory;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Service;
@Service
public class ObjectFactory implements ApplicationContextAware {
private static ApplicationContext applicationContext;
@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
ObjectFactory.applicationContext = applicationContext;
}
public static <T> T getBean(Class<T> beanClass) {
return applicationContext.getBean(beanClass);
}
public static Object getBean(String beanName) {
return applicationContext.getBean(beanName);
}
}
......@@ -62,33 +62,35 @@ public class GenesysLowlevelRepositoryImpl implements GenesysLowlevelRepository
@Transactional(readOnly = false)
public void updateFaoInstituteRefs() {
LOG.info("Updating institute references");
int count = jdbcTemplate.update("UPDATE `accession` A inner join `faoinstitute` FI on FI.code=A.instCode set A.instituteId=FI.id;");
int count = this.jdbcTemplate.update("UPDATE `accession` A inner join `faoinstitute` FI on FI.code=A.instCode set A.instituteId=FI.id;");
LOG.info("Institute references updated: " + count);
LOG.info("Updating institute accession count");
count = jdbcTemplate
count = this.jdbcTemplate
.update("UPDATE faoinstitute FI inner join (select instituteId, count(*) X from accession group by instituteId) A on A.instituteId=FI.id set FI.accessionCount=A.X;");
LOG.info("Institute accession counts updated: " + count);
}
// @Override
// @Transactional(readOnly = false, propagation = Propagation.SUPPORTS)
// public void updateInstituteAccessionCount(long instituteId) {
// LOG.debug("Updating institute accession count for instituteId=" + instituteId);
// // int count = jdbcTemplate
// // .update("UPDATE faoinstitute FI inner join (select instituteId, count(*) X from accession where instituteId= ? group by instituteId) A on A.instituteId=FI.id set FI.accessionCount=A.X where FI.id = ?;",
// // instituteId, instituteId);
// jdbcTemplate.update("UPDATE faoinstitute SET accessionCount = (select count(*) from accession where instituteId=?) where id = ?;",
// instituteId, instituteId);
// LOG.info("Institute accession count updated for " + instituteId);
// }
// @Override
// @Transactional(readOnly = false, propagation = Propagation.SUPPORTS)
// public void updateInstituteAccessionCount(long instituteId) {
// LOG.debug("Updating institute accession count for instituteId=" +
// instituteId);
// // int count = jdbcTemplate
// //
// .update("UPDATE faoinstitute FI inner join (select instituteId, count(*) X from accession where instituteId= ? group by instituteId) A on A.instituteId=FI.id set FI.accessionCount=A.X where FI.id = ?;",
// // instituteId, instituteId);
// jdbcTemplate.update("UPDATE faoinstitute SET accessionCount = (select count(*) from accession where instituteId=?) where id = ?;",
// instituteId, instituteId);
// LOG.info("Institute accession count updated for " + instituteId);
// }
@Override
@PreAuthorize("hasRole('ADMINISTRATOR')")
@Transactional(readOnly = false)
public void updateCountryRefs() {
LOG.info("Updating country references");
final int count = jdbcTemplate
final int count = this.jdbcTemplate
.update("UPDATE `accession` A inner join `country` C on C.code3=A.orgCty set A.orgCtyId=C.id WHERE A.orgCty IS NOT NULL;");
LOG.info("Country references updated: " + count);
}
......@@ -98,16 +100,16 @@ public class GenesysLowlevelRepositoryImpl implements GenesysLowlevelRepository
@Transactional(readOnly = false)
public void updateFaoInstituteCountries() {
LOG.info("Updating country references");
final int count = jdbcTemplate.update("UPDATE `faoinstitute` I inner join `country` C on C.code3=left(I.code, 3) set I.countryId=C.id;");
final int count = this.jdbcTemplate.update("UPDATE `faoinstitute` I inner join `country` C on C.code3=left(I.code, 3) set I.countryId=C.id;");
LOG.info("Country references updated: " + count);
}
@Override
public void ensureMethodTable(Method method) {
public void ensureMethodTable(final Method method) {
LOG.info("Ensuring method table for " + method);
try {
LOG.info("Checking for table with name " + method.getId().toString());
final DatabaseMetaData databaseMetadata = jdbcTemplate.getDataSource().getConnection().getMetaData();
final DatabaseMetaData databaseMetadata = this.jdbcTemplate.getDataSource().getConnection().getMetaData();
final ResultSet matchingTables = databaseMetadata.getTables(null, null, method.getId().toString(), new String[] { "TABLE" });
if (matchingTables.next()) {
......@@ -128,7 +130,7 @@ public class GenesysLowlevelRepositoryImpl implements GenesysLowlevelRepository
.append("` (`id` BIGINT NOT NULL AUTO_INCREMENT, `accessionId` BIGINT NOT NULL, `metadataId` BIGINT NOT NULL, ");
// Value column
createTableSql.append("`").append(method.getFieldName()).append("` ");
createTableSql.append('`').append(method.getFieldName()).append("` ");
createTableSql.append(getValueColumnDDL(method));
createTableSql.append(" NOT NULL");
......@@ -148,7 +150,7 @@ public class GenesysLowlevelRepositoryImpl implements GenesysLowlevelRepository
createTableSql.append(") ENGINE=InnoDB DEFAULT CHARSET=utf8;");
LOG.warn("Creating method table: " + createTableSql.toString());
jdbcTemplate.execute(createTableSql.toString());
this.jdbcTemplate.execute(createTableSql.toString());
}
LOG.info("Done");
} catch (final SQLException e) {
......@@ -156,7 +158,7 @@ public class GenesysLowlevelRepositoryImpl implements GenesysLowlevelRepository
}
}
private String getValueColumnDDL(Method method) {
private String getValueColumnDDL(final Method method) {
if (method.getFieldType() == 0) {
return "VARCHAR(" + method.getFieldSize() + ")";
} else if (method.getFieldType() == 1) {
......@@ -170,10 +172,10 @@ public class GenesysLowlevelRepositoryImpl implements GenesysLowlevelRepository
@Override
@Transactional(readOnly = false)
public void refreshMetadataMethods() {
jdbcTemplate.update("delete from metadatamethod");
jdbcTemplate.update("delete from accessiontrait");
this.jdbcTemplate.update("delete from metadatamethod");
this.jdbcTemplate.update("delete from accessiontrait");
final List<Long> methodIds = jdbcTemplate.queryForList("select id from method", Long.class);
final List<Long> methodIds = this.jdbcTemplate.queryForList("select id from method", Long.class);
for (final long methodId : methodIds) {
LOG.info("Updating metadatamethod for methodId=" + methodId);
......@@ -189,7 +191,7 @@ public class GenesysLowlevelRepositoryImpl implements GenesysLowlevelRepository
// Insert reference to metadatamethod
try {
final int inserted = jdbcTemplate.update("insert into metadatamethod (metadataId, methodId) (select distinct metadataId, " + methodId
final int inserted = this.jdbcTemplate.update("insert into metadatamethod (metadataId, methodId) (select distinct metadataId, " + methodId
+ " from `" + methodId + "`)");
if (inserted == 0) {
LOG.warn("Method " + methodId + " has no entries?");
......@@ -201,7 +203,7 @@ public class GenesysLowlevelRepositoryImpl implements GenesysLowlevelRepository
}
try {
final int inserted2 = jdbcTemplate
final int inserted2 = this.jdbcTemplate
.update("insert into accessiontrait (metadataId , accessionId, methodId) (select distinct metadataId, accessionId, " + methodId
+ " from `" + methodId + "`)");
if (inserted2 == 0) {
......@@ -216,32 +218,32 @@ public class GenesysLowlevelRepositoryImpl implements GenesysLowlevelRepository
}
@Override
public int countAccessions(ObjectNode filter) {
public int countAccessions(final ObjectNode filter) {
final DirectMysqlQuery directQuery = new DirectMysqlQuery("accession", "a");
directQuery.jsonFilter(filter, new MethodResolver() {
@Override
public Method getMethod(long methodId) {
return methodRepository.findOne(methodId);
public Method getMethod(final long methodId) {
return GenesysLowlevelRepositoryImpl.this.methodRepository.findOne(methodId);
}
});
return jdbcTemplate.queryForObject(directQuery.getCountQuery("a.id"), directQuery.getParameters(), Integer.class);
return this.jdbcTemplate.queryForObject(directQuery.getCountQuery("a.id"), directQuery.getParameters(), Integer.class);
}
@Override
public void listAccessions(final ObjectNode filter, RowCallbackHandler rowCallbackHandler) {
public void listAccessions(final ObjectNode filter, final RowCallbackHandler rowCallbackHandler) {
final DirectMysqlQuery directQuery = new DirectMysqlQuery("accession", "a");
directQuery.outerJoin("taxonomy2", "t", "t.id=a.taxonomyId2");
directQuery.jsonFilter(filter, new MethodResolver() {
@Override
public Method getMethod(long methodId) {
return methodRepository.findOne(methodId);
public Method getMethod(final long methodId) {
return GenesysLowlevelRepositoryImpl.this.methodRepository.findOne(methodId);
}
});
jdbcTemplate.query(new PreparedStatementCreator() {
this.jdbcTemplate.query(new PreparedStatementCreator() {
@Override
public PreparedStatement createPreparedStatement(Connection con) throws SQLException {
public PreparedStatement createPreparedStatement(final Connection con) throws SQLException {
final PreparedStatement stmt = con.prepareStatement(directQuery
.getQuery("a.id, a.uuid, a.instCode, a.acceNumb, t.genus, t.species, t.taxonName, a.orgCty, a.acqSrc, a.acqDate, a.mlsStat, a.available, a.storage, a.sampStat, a.duplSite, a.createdBy, a.createdDate, a.lastModifiedBy, a.lastModifiedDate"));
......@@ -256,19 +258,19 @@ public class GenesysLowlevelRepositoryImpl implements GenesysLowlevelRepository
}
@Override
public void listAccessionsGeo(final ObjectNode filter, RowCallbackHandler rowCallbackHandler) {
public void listAccessionsGeo(final ObjectNode filter, final RowCallbackHandler rowCallbackHandler) {
final DirectMysqlQuery directQuery = new DirectMysqlQuery("accessiongeo", "geo");
directQuery.innerJoin("accession", "a", "a.id=geo.accessionId");
directQuery.jsonFilter(filter, new MethodResolver() {
@Override
public Method getMethod(long methodId) {
return methodRepository.findOne(methodId);
public Method getMethod(final long methodId) {
return GenesysLowlevelRepositoryImpl.this.methodRepository.findOne(methodId);
}
});
jdbcTemplate.query(new PreparedStatementCreator() {
this.jdbcTemplate.query(new PreparedStatementCreator() {
@Override
public PreparedStatement createPreparedStatement(Connection con) throws SQLException {
public PreparedStatement createPreparedStatement(final Connection con) throws SQLException {
final PreparedStatement stmt = con.prepareStatement(directQuery
.getQuery("a.id, geo.latitude, geo.longitude, geo.elevation, geo.datum, geo.uncertainty, geo.method, geo.version"));
......@@ -283,20 +285,20 @@ public class GenesysLowlevelRepositoryImpl implements GenesysLowlevelRepository
}
@Override
public void listAccessionsAlias(final ObjectNode filter, RowCallbackHandler rowCallbackHandler) {
public void listAccessionsAlias(final ObjectNode filter, final RowCallbackHandler rowCallbackHandler) {
// from n inner join accession a on a.id=n.accessionId
final DirectMysqlQuery directQuery = new DirectMysqlQuery("accessionalias", "n");
directQuery.innerJoin("accession", "a", "a.id=n.accessionId");
directQuery.jsonFilter(filter, new MethodResolver() {
@Override
public Method getMethod(long methodId) {
return methodRepository.findOne(methodId);
public Method getMethod(final long methodId) {
return GenesysLowlevelRepositoryImpl.this.methodRepository.findOne(methodId);
}
});
jdbcTemplate.query(new PreparedStatementCreator() {
this.jdbcTemplate.query(new PreparedStatementCreator() {
@Override
public PreparedStatement createPreparedStatement(Connection con) throws SQLException {
public PreparedStatement createPreparedStatement(final Connection con) throws SQLException {
final PreparedStatement stmt = con.prepareStatement(directQuery.getQuery("a.id, n.instCode, n.name, n.aliasType, n.lang, n.version"));
final ArgumentPreparedStatementSetter apss = new ArgumentPreparedStatementSetter(directQuery.getParameters());
......@@ -310,11 +312,10 @@ public class GenesysLowlevelRepositoryImpl implements GenesysLowlevelRepository
}
@Override
public void listAccessionsAlias(RowCallbackHandler rowCallbackHandler) {
jdbcTemplate.query(new PreparedStatementCreator() {
public void listAccessionsAlias(final RowCallbackHandler rowCallbackHandler) {
this.jdbcTemplate.query(new PreparedStatementCreator() {
@Override
public PreparedStatement createPreparedStatement(Connection con) throws SQLException {
System.err.println("NEW listAccessionAlias PSTMT");
public PreparedStatement createPreparedStatement(final Connection con) throws SQLException {
final PreparedStatement stmt = con
.prepareStatement("select n.accessionId, n.instCode, n.name, n.aliasType, n.lang, n.version, n.id from accessionalias n order by n.accessionId");
// Set mysql JConnector to stream results
......@@ -325,21 +326,21 @@ public class GenesysLowlevelRepositoryImpl implements GenesysLowlevelRepository
}
@Override
public void listAccessionsColl(final ObjectNode filter, RowCallbackHandler rowCallbackHandler) {
public void listAccessionsColl(final ObjectNode filter, final RowCallbackHandler rowCallbackHandler) {
// from accessioncollect coll inner join accession a on
// a.id=coll.accessionId
final DirectMysqlQuery directQuery = new DirectMysqlQuery("accessioncollect", "coll");
directQuery.innerJoin("accession", "a", "a.id=coll.accessionId");
directQuery.jsonFilter(filter, new MethodResolver() {
@Override
public Method getMethod(long methodId) {
return methodRepository.findOne(methodId);
public Method getMethod(final long methodId) {
return GenesysLowlevelRepositoryImpl.this.methodRepository.findOne(methodId);
}
});
jdbcTemplate.query(new PreparedStatementCreator() {
this.jdbcTemplate.query(new PreparedStatementCreator() {
@Override
public PreparedStatement createPreparedStatement(Connection con) throws SQLException {
public PreparedStatement createPreparedStatement(final Connection con) throws SQLException {
final PreparedStatement stmt = con.prepareStatement(directQuery
.getQuery("a.id, coll.collMissId, coll.collNumb, coll.collDate, coll.collSrc, coll.collSite, coll.collCode, coll.collName, coll.collInstAddress, coll.version"));
......@@ -354,10 +355,10 @@ public class GenesysLowlevelRepositoryImpl implements GenesysLowlevelRepository
}
@Override
public void listMetadataAccessions(final long id, RowCallbackHandler rowCallbackHandler) {
jdbcTemplate.query(new PreparedStatementCreator() {
public void listMetadataAccessions(final long id, final RowCallbackHandler rowCallbackHandler) {
this.jdbcTemplate.query(new PreparedStatementCreator() {
@Override
public PreparedStatement createPreparedStatement(Connection con) throws SQLException {
public PreparedStatement createPreparedStatement(final Connection con) throws SQLException {
final PreparedStatement stmt = con
.prepareStatement("select distinct a.id, a.instCode, a.acceNumb, a.genus from accessiontrait at inner join accession a on a.id=at.accessionId where at.metadataId = ?");
stmt.setLong(1, id);
......@@ -369,10 +370,10 @@ public class GenesysLowlevelRepositoryImpl implements GenesysLowlevelRepository
}
@Override
public void listAccessionsAccenames(RowCallbackHandler rowCallbackHandler) {
jdbcTemplate.query(new PreparedStatementCreator() {
public void listAccessionsAccenames(final RowCallbackHandler rowCallbackHandler) {
this.jdbcTemplate.query(new PreparedStatementCreator() {
@Override
public PreparedStatement createPreparedStatement(Connection con) throws SQLException {
public PreparedStatement createPreparedStatement(final Connection con) throws SQLException {
final PreparedStatement stmt = con.prepareStatement("select accessionId, names, otherIds from accessionname");
// Set mysql JConnector to stream results
stmt.setFetchSize(Integer.MIN_VALUE);
......
......@@ -387,6 +387,7 @@ public class GeoServiceImpl implements GeoService {
public ITPGRFAStatus updateITPGRFA(Country country, String contractingParty, String membership, String membershipBy, String nameOfNFP) {
if (country == null) {
LOG.warn("Country is null, not updating ITPGRFA");
return null;
}
ITPGRFAStatus itpgrfaStatus = itpgrfaRepository.findByCountry(country);
......
......@@ -131,7 +131,7 @@ public class OAuth2JPATokenStoreImpl implements JPATokenStoreCleanup, JPATokenSt
};
private ObjectMapper mapper = new ObjectMapper();
/**
* Cleanup executed every 10 minutes
*/
......@@ -404,6 +404,11 @@ public class OAuth2JPATokenStoreImpl implements JPATokenStoreCleanup, JPATokenSt
@Override
public void storeAccessToken(OAuth2AccessToken token, OAuth2Authentication authentication) {
if (authentication == null) {
LOG.warn("Authentication object is null, ignoring storeAccessToken request.");
return;
}
LOG.info("Storing new access token " + token.getValue());
if (authentication != null) {
LOG.debug("Access token authentication " + authentication.getClass() + " auth=" + authentication);
......@@ -458,6 +463,11 @@ public class OAuth2JPATokenStoreImpl implements JPATokenStoreCleanup, JPATokenSt
@Override
public void storeRefreshToken(OAuth2RefreshToken refreshToken, OAuth2Authentication authentication) {
if (authentication == null) {
LOG.warn("Authentication object is null, ignoring storeRefreshToken request.");
return;
}
LOG.info("Storing new refresh token " + refreshToken.getValue());
if (authentication != null) {
LOG.debug("Refresh token authentication " + authentication.getClass() + " auth=" + authentication);
......
......@@ -439,7 +439,7 @@ public class UserServiceImpl implements UserService {
final Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
if (principal instanceof AuthUserDetails) {
if (((AuthUserDetails) principal).getUser().getId() != user.getId()) {
if (! ((AuthUserDetails) principal).getUser().getId().equals(user.getId())) {
LOG.warn("Not adding role, user != principal");
return;
}
......
......@@ -17,7 +17,6 @@
package org.genesys2.server.service.worker;
import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
......@@ -66,9 +65,7 @@ import com.fasterxml.jackson.databind.node.ObjectNode;
@Component
public class CountryAlternateNamesUpdater implements CountryNamesUpdater {
public static String ALTERNATE_NAMES_URL = "http://download.geonames.org/export/dump/alternateNames.zip";
private static String ALTERNATE_NAMES_FILE = "/Users/mobreza/Downloads/alternateNames/alternateNames.txt";
public static final String ALTERNATE_NAMES_URL = "http://download.geonames.org/export/dump/alternateNames.zip";
public static final Log LOG = LogFactory.getLog(CountryAlternateNamesUpdater.class);
......@@ -85,7 +82,7 @@ public class CountryAlternateNamesUpdater implements CountryNamesUpdater {
/**
* Update local FaoInstitute with data from WIEWS database
*
*
* @throws IOException
*/
@Override
......@@ -112,6 +109,8 @@ public class CountryAlternateNamesUpdater implements CountryNamesUpdater {
ZipEntry zipEntry = null;
do {
zipEntry = instream.getNextEntry();
if (zipEntry == null)
break;
LOG.debug("Got entry: " + zipEntry.getName());
if (zipEntry.getName().equals("alternateNames.txt")) {
LOG.info("Found alternateNames.zip");
......@@ -126,8 +125,6 @@ public class CountryAlternateNamesUpdater implements CountryNamesUpdater {
return;
}
}
} catch (final IllegalStateException e) {
alternateNamesStream = new FileInputStream(ALTERNATE_NAMES_FILE);
} catch (final ClientProtocolException e) {
LOG.error(e.getMessage(), e);
throw new IOException(e);
......
/**
* Copyright 2014 Global Crop Diversity Trust
*
* Licensed 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
*
* http://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.
**/
package org.genesys2.server.service.worker;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
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;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.http.Header;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.genesys2.server.model.genesys.Accession;
import org.genesys2.server.model.impl.FaoInstitute;
import org.genesys2.server.service.GenesysService;
import org.genesys2.server.service.GeoService;
import org.genesys2.server.service.InstituteService;
import org.genesys2.server.service.TaxonomyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.task.TaskExecutor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Component;
import au.com.bytecode.opencsv.CSVReader;
@Component
public class SGSVInsertMissing {
private static final String SGSV_DOWNLOAD_URL = "http://www.nordgen.org/sgsv/download.php?file=/scope/sgsv/files/sgsv_templates.tab";
public static final Log LOG = LogFactory.getLog(SGSVInsertMissing.class);
private static final int BATCH_SIZE = 50;
@Autowired
private GeoService geoService;
@Autowired
private TaskExecutor taskExecutor;
private static final String[] institutes = { "AUS039", "BDI003", "BDI004", "BDI005", "BRA001", "BRA008", "CAN004", "CHL002", "CIV039", "CRI001", "ECU076",
"GBR072", "GEO028", "GRC035", "IDN179", "ISR003", "ITA411", "KEN015", "KEN023", "KEN045", "KEN053", "KEN055", "KOR043", "MLI002", "MLI003",
"MLI219", "MMR003", "MNG030", "NGA010", "PAK001", "PER002", "PHL129", "PRK013", "SDN034", "THA214", "TJK027", "TWN006", "UGA031", "UKR001",
"UZB006", "ZMB030" };
@Value("${download.files.dir}")
String filesPath;
@Autowired
private GenesysService genesysService;
@Autowired
private InstituteService instituteService;
@Autowired
private TaxonomyService taxonomyService;
private final Map<String, FaoInstitute> faoInstituteCache = new HashMap<String, FaoInstitute>();
@PreAuthorize("hasRole('ADMINISTRATOR')")
public void importMissingSGSV() {
LOG.warn("Importing SGSV data from " + SGSV_DOWNLOAD_URL);
final HttpClient httpclient = new DefaultHttpClient();
final HttpGet httpget = new HttpGet(SGSV_DOWNLOAD_URL);
HttpResponse response = null;
try {
response = httpclient.execute(httpget);
} catch (final ClientProtocolException e) {
LOG.error(e.getMessage(), e);
} catch (final IOException e) {
LOG.error(e.getMessage(), e);
}
LOG.debug(response.getStatusLine());
// Get hold of the response entity
final HttpEntity entity = response.getEntity();
for (final Header header : response.getAllHeaders()) {
LOG.debug(header);