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

healHistoryTree & External Objects #214

Merged
merged 12 commits into from
Aug 12, 2021
35 changes: 19 additions & 16 deletions src/java/edu/slu/action/ObjectAction.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
Expand All @@ -15,7 +15,6 @@
* to request that the origin server accept the entity enclosed in the request
* as a new subordinate of the resource identified by the Request-URI
* in the Request-Line.

* PUT
* HTTP.PUT can be used when the client is sending data to the the server and
* the client is determining the URI for the newly created resource. The PUT method
Expand All @@ -28,7 +27,6 @@
* It is most-often utilized for update capabilities, PUT-ing to a known resource
* URI with the request body containing the newly-updated representation of the
* original resource.

* PATCH
* HTTP.PATCH can be used when the client is sending one or more changes to be
* applied by the the server. The PATCH method requests that a set of changes described
Expand Down Expand Up @@ -110,7 +108,6 @@
* @author hanyan && bhaberbe
All the actions hit as an API like ex. /saveNewObject.action
This implementation follows RESTFUL standards. If you make changes, please adhere to this standard.

*/
public class ObjectAction extends ActionSupport implements ServletRequestAware, ServletResponseAware{
private String content;
Expand Down Expand Up @@ -2268,13 +2265,12 @@ private boolean healHistoryTree(JSONObject obj){
}
catch(Exception e){
//@cubap @theHabes #44. What if obj does not have __rerum or __rerum.history
previous_id = ""; //This ensures detectedPrevious is false
previous_id = ""; //This ensures history.previous will not be processed.
prime_id = ""; //This ensures isRoot is false
next_ids = new JSONArray(); //This ensures the loop below does not run.
success = false; //This will bubble out to deleteObj() and have the side effect that this object is not deleted. @see treeHealed
}
boolean isRoot = prime_id.equals("root");
boolean detectedPrevious = !previous_id.equals("");
//Update the history.previous of all the next ids in the array of the deleted object
for(int n=0; n<next_ids.size(); n++){
BasicDBObject query = new BasicDBObject();
Expand All @@ -2289,7 +2285,7 @@ private boolean healHistoryTree(JSONObject obj){
fixHistory.getJSONObject("__rerum").getJSONObject("history").element("prime", "root");
newTreePrime(fixHistory);
}
else if(detectedPrevious){ //The object being deleted had a previous. That is now absorbed by this next object to mend the gap.
else if(!previous_id.equals("")){ //The object being deleted had a previous. That is now absorbed by this next object to mend the gap.
fixHistory.getJSONObject("__rerum").getJSONObject("history").element("previous", previous_id);
}
else{
Expand All @@ -2304,13 +2300,16 @@ else if(detectedPrevious){ //The object being deleted had a previous. That is n
mongoDBService.update(Constant.COLLECTION_ANNOTATION, objToUpdate, objWithUpdate);
}
else{
System.out.println("could not find an object assosiated with id found in history tree");
success = false;
//Yikes this is an error, could not find an object assosiated with id found in history tree.
System.out.println("Cannot find object associated with the history.next[i] URI. It is not in the RERUM database. URI:"+nextID);
previous_id = ""; //A hack to make sure we do not process the history.previous b/c there was an error.
success = false;
//Yikes this is an error, could not find an object assosiated with id found in history tree.
break;
}
}
if(detectedPrevious){
//The object being deleted had a previous. That previous object next[] must be updated with the deleted object's next[].
if(previous_id.contains(Constant.RERUM_PREFIX)){
//The object being deleted had a previous that is internal to RERUM. That previous object next[] must be updated with the deleted object's next[].
//For external objects, do nothing is the right thing to do here.
BasicDBObject query2 = new BasicDBObject();
BasicDBObject objToUpdate2;
BasicDBObject objWithUpdate2;
Expand All @@ -2334,11 +2333,16 @@ else if(detectedPrevious){ //The object being deleted had a previous. That is n
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;
//The history.previous object could not be found in this RERUM Database.
//It has this APIs id pattern, that means we expected to find it. This is an error.
System.out.println("Cannot find object associated with the history.previous URI. It is not in the RERUM database. URI:"+previous_id);
success = false;
}
}
else{
//The history.previous is an external object. It does not have history, the buck stops here and that's OK.
System.out.println("The value of history.previous was an external URI. Nothing to heal. URI:"+previous_id);
}
return success;
}

Expand Down Expand Up @@ -2833,4 +2837,3 @@ private BasicDBObject expandPrivateRerumProperty(BasicDBObject thisObject) {
}

}

4 changes: 2 additions & 2 deletions src/java/edu/slu/common/Constant.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class Constant {

//Mongo Connection String
public static final String DATABASE_CONNECTION = "mongodb://rerum-dev:69Trombones@f-vl-cdh-img-01:27017/annotationStoreDev?w=majority&authMechanism=SCRAM-SHA-256";
//"mongodb://rerum:Singul4rity@f-vl-cdh-img-01:27017/annotationStore?w=majority&authMechanism=SCRAM-SHA-256";
//public static final String DATABASE_CONNECTION = "mongodb://rerum:Singul4rity@f-vl-cdh-img-01:27017/annotationStore?w=majority&authMechanism=SCRAM-SHA-256";

//Mongo Database Name
public static final String DATABASE_NAME = "annotationStoreDev"; // NOTE this changes between dev and prod. Check the connection string.
Expand All @@ -33,7 +33,7 @@ public class Constant {
public static final String RERUM_AGENT_ClAIM="http://devstore.rerum.io/v1/agent";

//RERUM API Linked Data context
public static final String RERUM_CONTEXT="http://devstore.rerum.io/v1/context.json";
public static final String RERUM_CONTEXT="http://store.rerum.io/v1/context.json";

//The location of the public API documents. This is necessary for JSON-LD context purposes.
public static final String RERUM_API_DOC="https://github.com/CenterForDigitalHumanities/rerum_server/blob/master/API.md#__rerum";
Expand Down