Search in sources :

Example 1 with EOLTaxonImageService

use of org.eol.globi.service.EOLTaxonImageService 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();
            }
        }
    }
}
Also used : ExecutionEngine(org.neo4j.cypher.javacompat.ExecutionEngine) TaxonImage(org.eol.globi.domain.TaxonImage) ExecutionResult(org.neo4j.cypher.javacompat.ExecutionResult) IOException(java.io.IOException) EOLTaxonImageService(org.eol.globi.service.EOLTaxonImageService)

Aggregations

IOException (java.io.IOException)1 TaxonImage (org.eol.globi.domain.TaxonImage)1 EOLTaxonImageService (org.eol.globi.service.EOLTaxonImageService)1 ExecutionEngine (org.neo4j.cypher.javacompat.ExecutionEngine)1 ExecutionResult (org.neo4j.cypher.javacompat.ExecutionResult)1