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

/delete throws a 500 #211

Closed
thehabes opened this issue Aug 2, 2021 · 2 comments · Fixed by #214
Closed

/delete throws a 500 #211

thehabes opened this issue Aug 2, 2021 · 2 comments · Fixed by #214
Assignees
Labels

Comments

@thehabes
Copy link
Member

thehabes commented Aug 2, 2021

We noticed this in the Glossing Matthew project. To reproduce, go to http://glossing.rerum.io/ms.html#http://devstore.rerum.io/v1/id/61040f4d0634984db99592fa and attempt to Drop from Collection for this entry. There is an error in RERUM's updateHistoryTree() function. We believe this has something to do with the "update that is a fork", where a prime may in fact have a previous.

@thehabes thehabes added the bug label Aug 2, 2021
@thehabes thehabes self-assigned this Aug 3, 2021
@thehabes
Copy link
Member Author

thehabes commented Aug 10, 2021

Obj to delete: http://store.rerum.io/v1/id/6104404cffce846a83e700f0
delete approved? true
We had a previous id in the object but could not find it in the store
Here is the error response json object to return with status 500
{"code":500,"message":"We could not update the history tree correctly.  The delete failed."}

@thehabes
Copy link
Member Author

Fails to delete b/c We had a previous id in the history object but could not find it in the store. The previous for that object is http://devstore.rerum.io/v1/id/61040f500634984db99592fe, which is not in the annotationStore db on img-01. It is in annotationStoreDev. So this logic is a bit wonky for "imported" objects. Here is the code that needs patched:

if(detectedPrevious){ 
    //The object being deleted had a previous.  That previous object next[] must be updated with the deleted object's next[].
    System.out.println("The object being deleted had a previous.  That previous object next[] must be updated with the deleted object's next[]");
    BasicDBObject query2 = new BasicDBObject();
    BasicDBObject objToUpdate2;
    BasicDBObject objWithUpdate2;
    query2.append("@id", previous_id);
    objToUpdate2 = (BasicDBObject) mongoDBService.findOneByExample(Constant.COLLECTION_ANNOTATION, query2); 
    if(null != objToUpdate2){
       JSONObject fixHistory2 = JSONObject.fromObject(objToUpdate2); 
       JSONArray origNextArray = fixHistory2.getJSONObject("__rerum").getJSONObject("history").getJSONArray("next");
       JSONArray newNextArray = new JSONArray();  
       //JSONArray does not have splice, but we can code our own.  This will splice out obj["@id"].
       for (int i=0; i<origNextArray.size(); i++){ 
           if (!origNextArray.getString(i).equals(obj.getString("@id"))){
               //So long as the value is not the deleted id, add it to the newNextArray (this is the splice).  
               newNextArray.add(origNextArray.get(i));
           }
       } 
       newNextArray.addAll(next_ids); //Adds next array of deleted object to the end of this array in order.
       fixHistory2.getJSONObject("__rerum").getJSONObject("history").element("next", newNextArray); //Rewrite the next[] array to fix the history
       Object forMongo2 = JSON.parse(fixHistory2.toString()); //JSONObject cannot be converted to BasicDBObject
       objWithUpdate2 = (BasicDBObject)forMongo2;
       mongoDBService.update(Constant.COLLECTION_ANNOTATION, objToUpdate2, objWithUpdate2);
    }
    else{
        //Yikes this is an error.  We had a previous id in the object but could not find it in the store.
        System.out.println("We had a previous id in the object but could not find it in the store");
        success = false;
    }
}

@thehabes thehabes linked a pull request Aug 10, 2021 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant