use of org.eol.globi.domain.TaxonImage in project eol-globi-data by jhpoelen.
the class TaxonUtilTest method toTaxonImageNonEOL.
@Test
public void toTaxonImageNonEOL() {
TaxonImage image = new TaxonImage();
Taxon taxon = new TaxonImpl("Donald duckus", "ZZZ:123");
taxon.setCommonNames("bla @en | boo @de");
taxon.setPath("one | two | three");
Map<String, String> taxonMap = new TreeMap<String, String>(TaxonUtil.taxonToMap(taxon));
taxonMap.put(PropertyAndValueDictionary.THUMBNAIL_URL, "http://foo/bar/thumb");
taxonMap.put(PropertyAndValueDictionary.EXTERNAL_URL, "http://foo/bar");
TaxonImage enrichedImage = TaxonUtil.enrichTaxonImageWithTaxon(taxonMap, image);
assertThat(enrichedImage.getCommonName(), is("bla"));
assertThat(enrichedImage.getTaxonPath(), is("one | two | three"));
assertThat(enrichedImage.getInfoURL(), is("http://foo/bar"));
assertThat(enrichedImage.getThumbnailURL(), is("http://foo/bar/thumb"));
assertThat(enrichedImage.getPageId(), is(nullValue()));
assertThat(enrichedImage.getImageURL(), is(nullValue()));
}
use of org.eol.globi.domain.TaxonImage in project eol-globi-data by jhpoelen.
the class EOLTaxonImageService method lookupImage.
private TaxonImage lookupImage(String externalId) throws PropertyEnricherException {
TaxonImage image;
Map<String, String> enrich = new EOLService().enrich(TaxonUtil.taxonToMap(new TaxonImpl(null, externalId)));
Taxon taxon = TaxonUtil.mapToTaxon(enrich);
image = taxonToTaxonImage(taxon);
return image;
}
use of org.eol.globi.domain.TaxonImage in project eol-globi-data by jhpoelen.
the class ImageLinker method link.
@Override
public void link() {
ExecutionEngine engine = new ExecutionEngine(graphDb);
ExecutionResult executionResult = engine.execute("START taxon = node:taxons('*:*')\n" + "WHERE not(has(taxon.thumbnailUrl)) AND has(taxon.externalId) AND taxon.externalId <> 'no:match'\n" + "RETURN id(taxon) as `id`, taxon.externalId as `externalId`");
for (Map<String, Object> externalIdMap : executionResult) {
final String externalId = (String) externalIdMap.get("externalId");
final Long nodeId = (Long) externalIdMap.get("id");
TaxonImage taxonImage = null;
try {
taxonImage = new EOLTaxonImageService().lookupImageForExternalId(externalId);
} catch (IOException e) {
LOG.warn("failed to lookup externalId [" + externalId + "]", e);
}
if (taxonImage == null) {
if (out != null) {
out.println(StringUtils.join(Arrays.asList("EOL:12345", "", "", ""), "\t"));
}
} else {
final String infoURL = taxonImage.getInfoURL() == null ? "" : taxonImage.getInfoURL();
final String thumbnailURL = taxonImage.getThumbnailURL() == null ? "" : taxonImage.getThumbnailURL();
final String imageURL = taxonImage.getImageURL() == null ? "" : taxonImage.getImageURL();
ExecutionResult execute = engine.execute("START taxon = node({nodeId})\n" + "SET taxon.externalUrl={infoUrl}, taxon.imageUrl={imageUrl}, taxon.thumbnailUrl={thumbnailUrl}\n" + "RETURN taxon.externalId, taxon.externalUrl, taxon.thumbnailUrl, taxon.imageUrl", new HashMap<String, Object>() {
{
put("nodeId", nodeId);
put("infoUrl", infoURL);
put("imageUrl", imageURL);
put("thumbnailUrl", thumbnailURL);
}
});
if (out != null) {
for (Map<String, Object> stringObjectMap : execute) {
out.println(StringUtils.join(CSVTSVUtil.escapeValues(stringObjectMap.values()), "\t"));
}
}
if (execute != null && execute.iterator() != null) {
execute.iterator().close();
}
}
}
}
use of org.eol.globi.domain.TaxonImage in project eol-globi-data by jhpoelen.
the class EOLTaxonImageService method taxonToTaxonImage.
private static TaxonImage taxonToTaxonImage(Taxon taxon) {
TaxonImage image = new TaxonImage();
if (StringUtils.isNotBlank(taxon.getCommonNames())) {
String[] names = StringUtils.split(taxon.getCommonNames(), CharsetConstant.SEPARATOR_CHAR);
for (String name : names) {
String[] nameParts = StringUtils.split(name, CharsetConstant.LANG_SEPARATOR_CHAR);
if (nameParts.length > 1) {
String vernacularName = StringUtils.trim(nameParts[0]);
String language = StringUtils.trim(nameParts[1]);
if ("en".equals(language)) {
String commonName = vernacularName.replaceAll("\\(.*\\)", "");
String capitalize = WordUtils.capitalize(commonName);
image.setCommonName(capitalize.replaceAll("\\sAnd\\s", " and "));
break;
}
}
}
}
image.setThumbnailURL(taxon.getThumbnailUrl());
image.setImageURL(taxon.getThumbnailUrl());
image.setInfoURL(taxon.getExternalUrl());
image.setScientificName(taxon.getName());
image.setTaxonPath(taxon.getPath());
if (StringUtils.startsWith(taxon.getExternalId(), TaxonomyProvider.ID_PREFIX_EOL)) {
image.setPageId(StringUtils.replace(taxon.getExternalId(), TaxonomyProvider.ID_PREFIX_EOL, ""));
}
return image;
}
use of org.eol.globi.domain.TaxonImage in project eol-globi-data by jhpoelen.
the class ImageService method findTaxonImagesForTaxonWithName.
@RequestMapping(value = "/imagesForName/{scientificName}", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
@ResponseBody
public TaxonImage findTaxonImagesForTaxonWithName(@PathVariable("scientificName") String scientificName) throws IOException {
TaxonImage taxonImage = new TaxonImage();
if (TaxonUtil.isEmptyValue(scientificName)) {
taxonImage.setScientificName(scientificName);
} else {
Map<String, String> taxonWithImage = taxonSearch.findTaxonWithImage(scientificName);
if (taxonWithImage == null || taxonWithImage.isEmpty()) {
Map<String, String> taxon = taxonSearch.findTaxon(scientificName, null);
if (taxon != null) {
if (taxon.containsKey(PropertyAndValueDictionary.EXTERNAL_ID)) {
taxonImage = imageSearch.lookupImageForExternalId(taxon.get(PropertyAndValueDictionary.EXTERNAL_ID));
if (taxonImage == null) {
taxonImage = new TaxonImage();
}
TaxonUtil.enrichTaxonImageWithTaxon(taxon, taxonImage);
}
}
} else {
taxonImage = TaxonUtil.enrichTaxonImageWithTaxon(taxonWithImage, new TaxonImage());
}
}
if (taxonImage == null) {
throw new ResourceNotFoundException("no image for [" + scientificName + "]");
}
return taxonImage;
}
Aggregations