Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
qifeng-bai opened this issue Oct 21, 2021 · 10 comments
Assignees
Milestone

Comments

@qifeng-bai
Copy link
Contributor

qifeng-bai commented Oct 21, 2021

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
}

@qifeng-bai qifeng-bai changed the title Biocaches returns 500 error if no occurrences are found Biocaches returns 500 error if query a bbox in the query of searching Acacia in the middle of ocean Oct 21, 2021
@alexhuang091
Copy link
Contributor

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
Copy link
Contributor

@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
Copy link
Contributor

nickdos commented Oct 24, 2021

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

@qifeng-bai
Copy link
Contributor Author

qifeng-bai commented Oct 24, 2021

@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
Copy link
Contributor

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

@qifeng-bai
Copy link
Contributor Author

@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
Copy link
Contributor

alexhuang091 commented Oct 25, 2021

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?

  • just an empty string "" so caller needs to check this special case: String[] parts = str.split('); if (parts.length == 4) {}, if caller not already doing this check, return "" may cause them to crash
  • return 0,0,0,0 which means a box of size 0? - or maybe -180,180,-90,90?

@nickdos
Copy link
Contributor

nickdos commented Oct 25, 2021

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
Copy link
Contributor

Moving to biocache-service

@adam-collins adam-collins transferred this issue from AtlasOfLivingAustralia/biocache-hubs Jan 30, 2024
@adam-collins adam-collins self-assigned this Feb 5, 2024
adam-collins pushed a commit that referenced this issue Feb 5, 2024
@adam-collins adam-collins added this to the 3.5.0 milestone Feb 5, 2024
adam-collins added a commit that referenced this issue Mar 28, 2024
@adam-collins
Copy link
Contributor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants