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);
}
}
......@@ -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);
......
......@@ -31,7 +31,6 @@ 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;
......@@ -88,10 +87,9 @@ public class SGSVUpdate {
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);
return;
}
LOG.debug(response.getStatusLine());
......@@ -121,10 +119,9 @@ public class SGSVUpdate {
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);
throw new IOException("Could not execute HTTP request: " + e.getMessage(), e);
}
LOG.debug(response.getStatusLine());
......
......@@ -65,7 +65,10 @@ public class KPIServiceTest {
log.info("Test 1");
Object res = null;
res = kpiService.getSingleResult("select count(distinct _base) from Accession _base inner join _base.institute _ped1 where (10 member of _base.stoRage) and ( _ped1.code = ?1 )", "HUN003");
res = kpiService
.getSingleResult(
"select count(distinct _base) from Accession _base inner join _base.institute _ped1 where (10 member of _base.stoRage) and ( _ped1.code = ?1 )",
"HUN003");
printRes(res);
}
......@@ -221,8 +224,10 @@ public class KPIServiceTest {
KPIParameter kPIParameter = paramExec.getParameter();
if (res != null)
log.info(kPIParameter.getName() + "=" + res + " " + res.getClass());
else
log.info(kPIParameter.getName() + " is null");
else {
log.warn(kPIParameter.getName() + " has no result (null)");
return;
}
Observation observation = new Observation();
observation.setExecution(paramExec);
......
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