- Improve performance of "ValidatorController.getRuleSet()" endpoint.

- Improve exception-handling.
- Replace deprecated method-calls.
- Code polishing.
This commit is contained in:
Lampros Smyrnaios 2023-01-31 16:57:37 +02:00
parent a239164f97
commit 8bf0f76ad6
6 changed files with 21 additions and 27 deletions

View File

@ -95,7 +95,6 @@ public class MonitorServiceImpl implements MonitorService {
|| (job.getValidationType().equals("U") && job.getContentJobStatus().equals("none") && job.getUsageJobStatus().equals("finished") && job.getUsageJobScore() <= 50)) { || (job.getValidationType().equals("U") && job.getContentJobStatus().equals("none") && job.getUsageJobStatus().equals("finished") && job.getUsageJobScore() <= 50)) {
job.setValidationStatus("failed"); job.setValidationStatus("failed");
} }
} }
} }
@ -140,7 +139,6 @@ public class MonitorServiceImpl implements MonitorService {
///////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////
return retJobs; return retJobs;
} }
private int getJobsTotalNumberOfUser(String user, String jobType, String validationStatus) throws ValidatorServiceException { private int getJobsTotalNumberOfUser(String user, String jobType, String validationStatus) throws ValidatorServiceException {
@ -166,13 +164,12 @@ public class MonitorServiceImpl implements MonitorService {
} }
@Override @Override
public StoredJob getJobSummary(String jobId, public StoredJob getJobSummary(String jobId, String groupBy) {
String groupBy) throws JSONException {
logger.debug("Getting job summary with id : " + jobId); logger.debug("Getting job summary with id : " + jobId);
StoredJob job = null; StoredJob job = null;
try { try {
job = getValidationService().getStoredJob(Integer.parseInt(jobId), groupBy); job = getValidationService().getStoredJob(Integer.parseInt(jobId), groupBy);
} catch (ValidatorServiceException e) { } catch (Exception e) {
logger.error(e.getMessage(), e); logger.error(e.getMessage(), e);
} }
///////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////
@ -189,4 +186,5 @@ public class MonitorServiceImpl implements MonitorService {
///////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////
return job; return job;
} }
} }

View File

@ -226,12 +226,12 @@ public class PiWikServiceImpl implements PiWikService {
@Override @Override
public Integer getTotal() { public Integer getTotal() {
return new JdbcTemplate(dataSource).queryForObject(GET_PIWIK_SITES_TOTAL, new Object[]{}, Integer.class); return new JdbcTemplate(dataSource).queryForObject(GET_PIWIK_SITES_TOTAL, Integer.class, new Object[]{});
} }
@Override @Override
public Integer getValidated(boolean validated) { public Integer getValidated(boolean validated) {
String finalizedQuery = GET_PIWIK_SITES_TOTAL + " where validated = ?"; String finalizedQuery = GET_PIWIK_SITES_TOTAL + " where validated = ?";
return new JdbcTemplate(dataSource).queryForObject(finalizedQuery, new Object[]{validated}, Integer.class); return new JdbcTemplate(dataSource).queryForObject(finalizedQuery, Integer.class, validated);
} }
} }

View File

@ -95,22 +95,20 @@ public class SushiliteServiceImpl implements SushiliteService {
Customer customer = reportResponseWrapper.getReportResponse().getReportWrapper().getReport().getCustomer(); Customer customer = reportResponseWrapper.getReportResponse().getReportWrapper().getReport().getCustomer();
List<ReportItem> allReportItems = customer.getReportItems(); List<ReportItem> allReportItems = customer.getReportItems();
if ( allReportItems != null) { if ( allReportItems != null ) {
try { try {
int totalItems = allReportItems.size(); int totalItems = allReportItems.size();
int size = Integer.parseInt(pageSize); int size = Integer.parseInt(pageSize);
int offset = (Integer.parseInt(page) * size); int offset = (Integer.parseInt(page) * size);
if ( offset < totalItems ) {
if (offset < totalItems ) {
int upperIndex = (offset + size); int upperIndex = (offset + size);
if (upperIndex > totalItems) { if ( upperIndex > totalItems ) {
upperIndex = totalItems; upperIndex = totalItems;
} }
requestedItemList = allReportItems.subList(offset, upperIndex); requestedItemList = allReportItems.subList(offset, upperIndex);
} }
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
logger.debug("Exception on getReportResults - trying to cast strings to integers", e); logger.error("Exception on getReportResults - trying to cast strings to integers", e);
//emailUtils.reportException(e);
throw e; throw e;
} }
} }

View File

@ -185,7 +185,7 @@ public class ValidatorServiceImpl implements ValidatorService {
} }
} }
} }
if (ruleSet != null){ if (ruleSet != null) {
for (int ruleId : job.getRules()) { for (int ruleId : job.getRules()) {
if (ruleSet.getContentRulesIds().contains(ruleId)) if (ruleSet.getContentRulesIds().contains(ruleId))
contentRules.add(ruleId); contentRules.add(ruleId);
@ -210,16 +210,13 @@ public class ValidatorServiceImpl implements ValidatorService {
@Override @Override
public List<String> getSetsOfRepository(String url) { public List<String> getSetsOfRepository(String url) {
logger.debug("Getting sets of repository with url : {}", url); logger.debug("Getting sets of repository with url : {}", url);
List<String> sets = null; List<String> sets = null;
try { try {
sets = OaiTools.getSetsOfRepo(url); sets = OaiTools.getSetsOfRepo(url);
} catch (Exception e) { } catch (Exception e) {
logger.error("Exception on getSetsOfRepository", e); logger.error("Exception on getSetsOfRepository", e);
} }
return sets; // It may be null.
return sets;
} }
@Override @Override
@ -239,13 +236,16 @@ public class ValidatorServiceImpl implements ValidatorService {
RuleSet ruleSet = null; RuleSet ruleSet = null;
try { try {
for (List<RuleSet> ruleSets : this.rulesetMap.values()) { for (List<RuleSet> ruleSets : this.rulesetMap.values()) {
for (RuleSet rSet : ruleSets) for ( RuleSet rSet : ruleSets ) {
if (rSet.getGuidelinesAcronym().equals(acronym)) { if ( rSet.getGuidelinesAcronym().equals(acronym) ) {
ruleSet = rSet; ruleSet = rSet;
break; break;
} }
} }
return ruleSet; if ( ruleSet != null )
break;
}
return ruleSet; // It may be null.
} catch (Exception e) { } catch (Exception e) {
logger.error("Error getting ruleset", e); logger.error("Error getting ruleset", e);
return null; return null;

View File

@ -49,16 +49,14 @@ public class HttpUtils {
public JsonElement get(String path, Map<String, String> params) { public JsonElement get(String path, Map<String, String> params) {
RestTemplate restTemplate = new RestTemplate(); RestTemplate restTemplate = new RestTemplate();
String url = registryUrl + path + ((params != null) ? createParams(params) : null); String url = registryUrl + path + ((params != null) ? createParams(params) : null);
ResponseEntity<String> responseEntity = restTemplate.exchange ResponseEntity<String> responseEntity = restTemplate.exchange(url, HttpMethod.GET, new HttpEntity<>(createHeaders(user, password)), String.class);
(url, HttpMethod.GET, new HttpEntity<>(createHeaders(user, password)), String.class);
return getResponseEntityAsJsonElement(responseEntity); return getResponseEntityAsJsonElement(responseEntity);
} }
public JsonElement delete(String path) { public JsonElement delete(String path) {
RestTemplate restTemplate = new RestTemplate(); RestTemplate restTemplate = new RestTemplate();
String url = registryUrl + path; String url = registryUrl + path;
ResponseEntity<String> responseEntity = restTemplate.exchange ResponseEntity<String> responseEntity = restTemplate.exchange(url, HttpMethod.DELETE, new HttpEntity<>(createHeaders(user, password)), String.class);
(url, HttpMethod.DELETE, new HttpEntity<>(createHeaders(user, password)), String.class);
return getResponseEntityAsJsonElement(responseEntity); return getResponseEntityAsJsonElement(responseEntity);
} }

View File

@ -25,7 +25,7 @@ public class OaiTools {
disableSslVerification(); disableSslVerification();
} }
private static Logger logger = LoggerFactory.getLogger(OaiTools.class); private static final Logger logger = LoggerFactory.getLogger(OaiTools.class);
public static List<String> getSetsOfRepo(String baseUrl) throws Exception { public static List<String> getSetsOfRepo(String baseUrl) throws Exception {
try { try {
@ -36,8 +36,8 @@ public class OaiTools {
List<Set> sets = new ArrayList<>(setList.asList()); List<Set> sets = new ArrayList<>(setList.asList());
while (token != null) { while (token != null) {
setList = harvester.listSets(token); setList = harvester.listSets(token);
token = setList.getResumptionToken();
sets.addAll(setList.asList()); sets.addAll(setList.asList());
token = setList.getResumptionToken();
} }
List<String> ret = new ArrayList<String>(); List<String> ret = new ArrayList<String>();