Skip to content

Commit

Permalink
Sonar fixes (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
Hilbrand authored May 3, 2022
1 parent f4a6e0d commit 6c336d3
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
* Crown copyright
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see http://www.gnu.org/licenses/.
*/
package nl.aerius.search.tasks;

import org.geotools.geometry.jts.JTS;
Expand Down Expand Up @@ -40,11 +56,7 @@ public String toBNGWKT(final String wkt) {
final String unionWkt = writer.write(result);
LOG.info("Input: {} Output: {}", wkt, unionWkt);
return unionWkt;
} catch (final MismatchedDimensionException e) {
throw new InterpretationRuntimeException(e);
} catch (final TransformException e) {
throw new InterpretationRuntimeException(e);
} catch (final ParseException e) {
} catch (final MismatchedDimensionException | ParseException | TransformException e) {
throw new InterpretationRuntimeException(e);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import nl.aerius.search.domain.SearchTaskResult;

@SpringBootTest
class PdokSearchServiceTest {
class BingSearchServiceTest {
@Autowired BingSearchService delegator;

@Value("${nl.aerius.bing.apiKey:#{null}}") private String apiKey;
Expand All @@ -44,6 +44,6 @@ void testWorksAtAll() {

final SearchTaskResult suggestions = result.blockingGet();

assertEquals(suggestions.getSuggestions().size(), 10, "Expected 10 results for 'utrecht'");
assertEquals(10, suggestions.getSuggestions().size(), "Expected 10 results for 'utrecht'");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,6 @@ void testWorksAtAll() {

final SearchTaskResult suggestions = result.blockingGet();

assertEquals(suggestions.getSuggestions().size(), 10, "Expected 10 results for 'utrecht'");
assertEquals(10, suggestions.getSuggestions().size(), "Expected 10 results for 'utrecht'");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import java.util.List;
import java.util.Optional;
import java.util.regex.Pattern;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
Expand All @@ -38,6 +39,7 @@
public class SearchRestService {
private static final String DEFAULT_CAPABILITIES = "MOCK_0,MOCK_01,MOCK_05,RECEPTOR";
private static final String DEFAULT_REGION = "NL";
private static final Pattern SCRUB_PATTERN = Pattern.compile("[\n\r\t]");

@Autowired SearchTaskDelegator taskDelegator;

Expand Down Expand Up @@ -72,7 +74,7 @@ public SearchResult retrieveSearchResultsAsync(final String query,
* Remove newlines, carriage returns, and tabs
*/
private static String scrub(final String query) {
return query.replaceAll("[\n\r\t]", "");
return SCRUB_PATTERN.matcher(query).replaceAll("");
}

@GetMapping(value = "/api/results/{uuid}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import nl.aerius.search.domain.SearchCapability;
import nl.aerius.search.domain.SearchRegion;

public class CapabilityKey {
public final class CapabilityKey {
private SearchCapability capability;
private SearchRegion region;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.util.Comparator;
import java.util.Map;
import java.util.Set;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

import org.slf4j.Logger;
Expand All @@ -36,14 +37,13 @@
*/
public final class TaskUtils {
private static final Logger LOG = LoggerFactory.getLogger(TaskUtils.class);
private static final Pattern REGION_WARN_PATTERN = Pattern.compile("[\n\r\t]");

private static final Comparator<SearchSuggestion> COMPARATOR = Comparator
.<SearchSuggestion>comparingDouble(SearchSuggestion::getScore)
.reversed()
.thenComparing(SearchSuggestion::getDescription);

// (o1, o2) -> Double.compare(o1.getScore(), o2.getScore());

private TaskUtils() {}

/**
Expand All @@ -56,7 +56,7 @@ public static Map<CapabilityKey, SearchTaskService> findTaskServices(final TaskF
if (taskFactory.hasCapability(v)) {
return true;
} else {
log.error("No task for known capability: " + v);
log.error("No task for known capability: {}", v);
return false;
}
})
Expand All @@ -74,8 +74,8 @@ public static Comparator<SearchSuggestion> getResultComparator() {

public static Set<CapabilityKey> parseCapabilities(final Collection<String> capabilities, final String region) {
final SearchRegion reg = SearchRegion.safeValueOf(region);
if (reg == null) {
LOG.warn("Requested region that does not exist: {}", region.replaceAll("[\n\r\t]", "_"));
if (reg == null && LOG.isWarnEnabled()) {
LOG.warn("Requested region that does not exist: {}", REGION_WARN_PATTERN.matcher(region).replaceAll("_"));
return Set.of();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,7 @@ public SearchResult retrieveSearchResultsAsync(final String query, final Set<Cap
.parallel()
.runOn(Schedulers.io())
.map(v -> v.retrieveSearchResults(query))
.doOnError(e -> {
LOG.error("Error while executing search task:", e);
})
.doOnError(e -> LOG.error("Error while executing search task:", e))
.flatMap(Single::toFlowable)
.doAfterNext(r -> task.complete(r))
.sequential()
Expand Down
5 changes: 5 additions & 0 deletions search-sonar-report/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@
<artifactId>search-service</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>nl.aerius</groupId>
<artifactId>search-service-bing-geocoder</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>nl.aerius</groupId>
<artifactId>search-service-extension</artifactId>
Expand Down

0 comments on commit 6c336d3

Please sign in to comment.