Commit 021592d3 authored by Matija Obreza's avatar Matija Obreza
Browse files

Updates for taxonomy-tools compatibility

parent 8fd2c025
......@@ -28,11 +28,11 @@ import org.genesys.geotools.service.CountryOfOriginService;
import org.genesys.geotools.service.LandOrSeaService;
import org.genesys.geotools.service.impl.CountryOfOriginServiceImpl;
import org.genesys.geotools.service.impl.LandOrSeaServiceImpl;
import org.genesys.taxonomy.checker.CachingInMemoryTaxonomyDatabase;
import org.genesys.taxonomy.checker.InMemoryTaxonomyDatabase;
import org.genesys.taxonomy.checker.TaxonomyChecker;
import org.genesys.taxonomy.checker.TaxonomyException;
import org.genesys.taxonomy.checker.web.service.ProcessService;
import org.genesys.taxonomy.checker.web.service.impl.CachingInMemoryTaxonomyDatabase;
import org.genesys.taxonomy.checker.web.service.impl.CountryProcessServiceImpl;
import org.genesys.taxonomy.checker.web.service.impl.LandOrSeaProcessServiceImpl;
import org.genesys.taxonomy.checker.web.service.impl.ProcessServiceImpl;
......
/*
* Copyright 2017 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.genesys.taxonomy.checker.web.service.impl;
import java.util.List;
import java.util.concurrent.ExecutionException;
import org.genesys.taxonomy.checker.InMemoryTaxonomyDatabase;
import org.genesys.taxonomy.gringlobal.model.SpeciesRow;
import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
/**
* Guava cache supported in-memory taxonomy database.
*/
public class CachingInMemoryTaxonomyDatabase extends InMemoryTaxonomyDatabase {
// private final static Logger LOG =
// LoggerFactory.getLogger(CachingInMemoryTaxonomyDatabase.class);
/** The cache genus species. */
private final Cache<String, List<SpeciesRow>> cacheGenusSpecies = CacheBuilder.newBuilder().maximumSize(100).build();
/** The cache genus suggestions. */
private final Cache<String, List<String>> cacheGenusSuggestions = CacheBuilder.newBuilder().maximumSize(100).build();
/** The cache species suggestions. */
private final Cache<String, List<String>> cacheSpeciesSuggestions = CacheBuilder.newBuilder().maximumSize(100).build();
/**
* Gets the all genus species.
*
* @param genus the genus
* @return the all genus species
*/
/*
* (non-Javadoc)
* @see
* org.genesys.taxonomy.checker.InMemoryTaxonomyDatabase#getAllGenusSpecies(java
* .lang.String)
*/
@Override
protected List<SpeciesRow> getAllGenusSpecies(final String genus) {
try {
return cacheGenusSpecies.get(genus, () -> CachingInMemoryTaxonomyDatabase.super.getAllGenusSpecies(genus));
} catch (final ExecutionException e) {
throw new RuntimeException(e);
}
}
/**
* Find similar genus.
*
* @param genus the genus
* @param maxSize the max size
* @return the list
*/
/*
* (non-Javadoc)
* @see
* org.genesys.taxonomy.checker.InMemoryTaxonomyDatabase#findSimilarGenus(java.
* lang.String, int)
*/
@Override
public List<String> findSimilarGenus(final String genus, final int maxSize) {
try {
return cacheGenusSuggestions.get(genus + "-" + maxSize, () -> CachingInMemoryTaxonomyDatabase.super.findSimilarGenus(genus, maxSize));
} catch (final ExecutionException e) {
throw new RuntimeException(e);
}
}
/**
* Find similar species.
*
* @param genus the genus
* @param species the species
* @param maxSize the max size
* @return the list
*/
/*
* (non-Javadoc)
* @see
* org.genesys.taxonomy.checker.InMemoryTaxonomyDatabase#findSimilarSpecies(java
* .lang.String, java.lang.String, int)
*/
@Override
public List<String> findSimilarSpecies(final String genus, final String species, final int maxSize) {
try {
return cacheSpeciesSuggestions.get(genus + "-" + species + "-" + maxSize, () -> CachingInMemoryTaxonomyDatabase.super.findSimilarSpecies(genus, species, maxSize));
} catch (final ExecutionException e) {
throw new RuntimeException(e);
}
}
}
......@@ -40,6 +40,7 @@ import org.genesys.taxonomy.checker.web.service.ProcessService;
import org.genesys.taxonomy.checker.web.util.ApplicationUtils;
import org.genesys.taxonomy.gringlobal.component.CabReader;
import org.genesys.taxonomy.gringlobal.model.GenusRow;
import org.genesys.taxonomy.gringlobal.model.IGrinSpecies;
import org.genesys.taxonomy.gringlobal.model.SpeciesRow;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -326,14 +327,14 @@ public class TaxonomyProcessServiceImpl implements ProcessService {
}
if (outputHeaders.indexOf(ApplicationUtils.HEADER_GRINTAX_SPECIESID) >= 0) {
final List<SpeciesRow> speciesRows = taxonomyDatabase.findSpeciesRow(genus, species, StringUtils.defaultIfBlank(subtaxa, null));
final List<IGrinSpecies> speciesRows = taxonomyDatabase.findSpeciesRow(genus, species, StringUtils.defaultIfBlank(subtaxa, null));
if (speciesRows.size() == 1) {
final SpeciesRow speciesRow = speciesRows.get(0);
final IGrinSpecies speciesRow = speciesRows.get(0);
outputLine[outputHeaders.indexOf(ApplicationUtils.HEADER_GRINTAX_SPECIESID)] = speciesRow.getSpeciesId().toString();
outputLine[outputHeaders.indexOf(ApplicationUtils.HEADER_GRINTAX_SPECIESCURRENT)] = Boolean.toString(speciesRow.isCurrent());
if (!speciesRow.isCurrent() && toCurrentTaxa) {
LOG.debug("{} is not current", speciesRow);
final SpeciesRow currentSpecies = taxonomyDatabase.getSpeciesRow(speciesRow.getCurrentTaxonomySpeciesId());
final IGrinSpecies currentSpecies = taxonomyDatabase.getSpeciesRow(speciesRow.getCurrentTaxonomySpeciesId());
final String currentGenus = taxonomyDatabase.getGenus(currentSpecies.getGenusId());
// LOG.warn("Result: {}", Arrays.toString(outputLine));
updateOutputColumn(outputLine, outputHeaders.indexOf(ApplicationUtils.HEADER_GENUS_CHECK), currentGenus, genus, ApplicationUtils.CURRENT_SUFFIX);
......
Supports Markdown
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