Closed thehabes closed 3 years ago
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."}
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;
}
}
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.