diff --git a/livingatlas/pipelines/src/main/java/au/org/ala/pipelines/beam/IndexRecordToSolrPipeline.java b/livingatlas/pipelines/src/main/java/au/org/ala/pipelines/beam/IndexRecordToSolrPipeline.java index 8225691b87..ce21419052 100644 --- a/livingatlas/pipelines/src/main/java/au/org/ala/pipelines/beam/IndexRecordToSolrPipeline.java +++ b/livingatlas/pipelines/src/main/java/au/org/ala/pipelines/beam/IndexRecordToSolrPipeline.java @@ -560,15 +560,26 @@ public void processElement(ProcessContext c) { public void processElement(ProcessContext c) { KV> e = c.element(); - - IndexRecord indexRecord = e.getValue().getKey(); - String id = indexRecord.getId(); + String id = e.getKey(); DistributionOutlierRecord outlierRecord = e.getValue().getValue(); - indexRecord.getDoubles().put(DISTANCE_TO_EDL, outlierRecord.getDistanceOutOfEDL()); - - c.output(KV.of(id, indexRecord)); + IndexRecord indexRecord = e.getValue().getKey(); + IndexRecord ouputIR = + IndexRecord.newBuilder() + .setId(indexRecord.getId()) + .setTaxonID(indexRecord.getTaxonID()) + .setLatLng(indexRecord.getLatLng()) + .setMultiValues(indexRecord.getMultiValues()) + .setDates(indexRecord.getDates()) + .setLongs(indexRecord.getLongs()) + .setBooleans(indexRecord.getBooleans()) + .setInts(indexRecord.getInts()) + .build(); + + ouputIR.getDoubles().put(DISTANCE_TO_EDL, outlierRecord.getDistanceOutOfEDL()); + + c.output(KV.of(id, ouputIR)); } }; } diff --git a/livingatlas/pipelines/src/main/java/au/org/ala/pipelines/transforms/DistributionOutlierTransform.java b/livingatlas/pipelines/src/main/java/au/org/ala/pipelines/transforms/DistributionOutlierTransform.java index 44ca5771ef..aa9f0c1e2f 100644 --- a/livingatlas/pipelines/src/main/java/au/org/ala/pipelines/transforms/DistributionOutlierTransform.java +++ b/livingatlas/pipelines/src/main/java/au/org/ala/pipelines/transforms/DistributionOutlierTransform.java @@ -7,6 +7,7 @@ import au.org.ala.pipelines.interpreters.DistributionOutlierInterpreter; import java.util.*; import java.util.stream.StreamSupport; +import lombok.extern.slf4j.Slf4j; import org.apache.beam.sdk.transforms.*; import org.apache.beam.sdk.values.*; import org.gbif.pipelines.core.functions.SerializableConsumer; @@ -14,6 +15,7 @@ import org.gbif.pipelines.io.avro.*; import org.gbif.pipelines.transforms.Transform; +@Slf4j public class DistributionOutlierTransform extends Transform { @@ -71,11 +73,13 @@ public Iterable apply( DistributionServiceImpl distributionService = DistributionServiceImpl.init(spatialUrl); List edl = distributionService.findLayersByLsid(lsid); + boolean hasEDL = edl.size() > 0 ? true : false; + double distanceToEDL = hasEDL ? 0 : -1; // 0 -inside, -1: no EDL // Available EDLD of this species Map points = new HashMap(); while (iter.hasNext()) { IndexRecord record = iter.next(); - DistributionOutlierRecord dr = convertToDistribution(record); + DistributionOutlierRecord dr = convertToDistribution(record, distanceToEDL); outputs.add(dr); Map point = new HashMap(); @@ -84,7 +88,7 @@ public Iterable apply( points.put(dr.getOccurrenceID(), point); } - if (edl.size() > 0) { + if (hasEDL) { Map results = distributionService.outliers(lsid, points); Iterator> iterator = results.entrySet().iterator(); while (iterator.hasNext()) { @@ -96,8 +100,9 @@ public Iterable apply( } } catch (ExpertDistributionException e) { + log.error(e.getMessage()); throw new RuntimeException( - "Expert distribution service returns error: " + e.getMessage()); + "Expert distribution service throws a runtime error, please check logs"); } catch (Exception e) { throw new RuntimeException("Runtime error: " + e.getMessage()); } @@ -119,18 +124,19 @@ public MapElements flatToString() { /** * Only can be used when EDL exists - which means the record can only in/out EDL Force to reset - * distanceOutOfEDL 0 because Spatial EDL service only return distance of outlier records + * distanceOutOfEDL 0: inside edl, -1: no edl * * @param record * @return */ - private DistributionOutlierRecord convertToDistribution(IndexRecord record) { + private DistributionOutlierRecord convertToDistribution( + IndexRecord record, double distanceToEDL) { DistributionOutlierRecord newRecord = DistributionOutlierRecord.newBuilder() .setId(record.getId()) .setOccurrenceID(record.getId()) - .setDistanceOutOfEDL(0.0d) .setSpeciesID(record.getTaxonID()) + .setDistanceOutOfEDL(distanceToEDL) .build(); String latlng = record.getLatLng(); diff --git a/livingatlas/solr/conf/managed-schema b/livingatlas/solr/conf/managed-schema index 3bd75ab14e..3eafaceed1 100644 --- a/livingatlas/solr/conf/managed-schema +++ b/livingatlas/solr/conf/managed-schema @@ -440,6 +440,9 @@ + + +