AtlasOfLivingAustralia / biocache-service

Occurrence & mapping webservices
https://biocache-ws.ala.org.au/ws/
Other
9 stars 26 forks source link

Biocaches returns 500 error if query a bbox in the query of searching Acacia in the middle of ocean #876

Open qifeng-bai opened 3 years ago

qifeng-bai commented 3 years ago

For example:
Suppose return a bbox when I search Acacia in the middle of ocean

https://biocache.ala.org.au/ws/webportal/bbox?q=qid:1634854192098&type=application/json

{ message: "null", errorType: "Server error", statusCode: 500 }

alexhuang091 commented 3 years ago
public double[] getBBox(SpatialSearchRequestParams requestParams) throws Exception {
        SolrQuery query = initSolrQuery(requestParams, false, null);
        query.setRows(0);
        query.setFacet(false);

        query.add("json.facet", "{x2:\"max(decimalLongitude)\",x1:\"min(decimalLongitude)\",y2:\"max(decimalLatitude)\",y1:\"min(decimalLatitude)\"}");
        QueryResponse qr = indexDao.query(query);

        SimpleOrderedMap facets = SearchUtils.getMap(qr.getResponse(), "facets");

        return new double[]{toDouble(facets.get("x1")), toDouble(facets.get("y1")), toDouble(facets.get("x2")), toDouble(facets.get("y2"))};
    }

it fails in last line facets.get("x1") because facets is an empty map

the actual query being sent to solr is q=taxonConceptID:"https://id.biodiversity.org.au/taxon/apni/51311124"&fq=spatiallyValid:true&fq=-occurrenceStatus:ABSENT&fq=geohash:"Intersects(POLYGON((94.130859375+-33.6089008561002,102.3046875+-33.6089008561002,102.3046875+-28.25963451165,94.130859375+-28.25963451165,94.130859375+-33.6089008561002)))"&qt=standard&rows=0&start=0&sort=score+asc&fl=country,raw_countryCode,references,scientificName,year,point-0.01,lat_long,decimalLatitude,catalogNumber,basisOfRecord,raw_scientificName,raw_vernacularName,taxonConceptID,point-0.1,id,assertions,spatiallyValid,order,taxonRankID,dataResourceName,recordNumber,raw_basisOfRecord,stateProvince,decimalLongitude,collectionCode,speciesID,occurrenceID,point-1,sensitive,point-0.0001,license,month,dataResourceUid,genus,dataHubUid,lft,subspecies,imageIDs,eventDate,imageID,raw_typeStatus,coordinateUncertaintyInMeters,taxonRank,genusID,identificationVerificationStatus,collectionName,vernacularName,locationRemarks,institutionCode,rights,class,collectionUid,rgt,countryConservation,names_and_lsid,point-0.001,typeStatus,kingdom,dataProviderUid,recordedBy,multimedia,phylum,institutionUid,species,dataProviderName,institutionName,dataHubName,subspeciesID,eventDateEnd,occurrenceRemarks,speciesGroup,stateConservation,family,userAssertions&json.facet={x2:"max(decimalLongitude)",x1:"min(decimalLongitude)",y2:"max(decimalLatitude)",y1:"min(decimalLatitude)"}

but the thing is the query itself returns 0 record

which causes (facets.get("x1")) fail seems

alexhuang091 commented 3 years ago

@nickdos SP expects a string

var bb = response.data.split(",");
return [[bb[1], bb[0]], [bb[3], bb[2]]];

biocache-service:

    @RequestMapping(value = {"/webportal/bbox", "/mapping/bbox"}, method = RequestMethod.GET)
    public void boundingBox(
            SpatialSearchRequestParams requestParams,
            HttpServletResponse response)
            throws Exception {

        double[] bbox = null;

        if (bbox == null) {
            bbox = searchDAO.getBBox(requestParams);
        }

        writeBytes(response, (bbox[0] + "," + bbox[1] + "," + bbox[2] + "," + bbox[3]).getBytes(StandardCharsets.UTF_8));
    }

but searchDAO.getBBox doesn't find anything so return new double[]{toDouble(facets.get("x1")), toDouble(facets.get("y1")), toDouble(facets.get("x2")), toDouble(facets.get("y2"))}; throws an exception

Is every call to /webportal/bbox supposed to return a valid value? what to do if like in this case solr search returns nothing?

nickdos commented 3 years ago

@adam-collins - see comment above, can you answer that?

qifeng-bai commented 3 years ago

@nickdos @adam-collins At this moment, SP cannot handle an empty "BBox", but I think anyway Biocache should return a meaningful info back. SP will update code after

At this moment, SP created two promises : /bbox and /occurrences. If there is no occurrences, SP can display "no occurrences" warning.

adam-collins commented 3 years ago

SP should report no occurrences. Not concerned about the 500 when there is no data for /bbox.

qifeng-bai commented 3 years ago

@adam-collins SP can report no occurrences, after SP is able to catch the 500 error returned from /bbox query. I have fixed it up

alexhuang091 commented 3 years ago

Hi @nickdos , the API is supposed to return a , separated string in normal case, what do you recommend to return in case of no record found?

nickdos commented 3 years ago

Other geospatial libraries must have to deal with this... Maybe look into what Geotools does? @adam-collins Any ideas on best string representation?

My guess is 0,0,0,0 is easiest to read, as being an empty envelope...

adam-collins commented 9 months ago

Moving to biocache-service

adam-collins commented 6 months ago

Prod url that fails https://biocache.ala.org.au/ws/mapping/bbox?q=-: Test url that works https://biocache-ws-test.ala.org.au/ws/mapping/bbox?q=-:

kylie-m commented 3 months ago

Test is working for me - pass