[isidorus-cvs] r896 - branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/isidorus
lgiessmann at common-lisp.net
lgiessmann at common-lisp.net
Wed Sep 14 09:25:05 UTC 2011
Author: lgiessmann
Date: Wed Sep 14 02:25:05 2011
New Revision: 896
Log:
gdl-frontend: Widgets: changed the update mechanism when committing http://textgrid.org/serviceregistry/model/types/Hash-Object instances => instead of deleting the entire old topic, only the old occurrence is deleted
Modified:
branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/isidorus/CommitCallback.java
Modified: branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/isidorus/CommitCallback.java
==============================================================================
--- branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/isidorus/CommitCallback.java Wed Sep 14 00:29:19 2011 (r895)
+++ branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/isidorus/CommitCallback.java Wed Sep 14 02:25:05 2011 (r896)
@@ -5,6 +5,8 @@
import us.isidor.gdl.anaToMia.Widgets.base.TmHelper;
import us.isidor.gdl.anaToMia.Widgets.base.Utils;
import us.isidor.gdl.anaToMia.Widgets.environment.Pair;
+import us.isidor.gdl.anaToMia.Widgets.environment.TopicIdentifierTypes;
+
import com.google.gwt.core.client.JsArray;
import com.google.gwt.http.client.Request;
import com.google.gwt.http.client.RequestBuilder;
@@ -14,7 +16,9 @@
import com.google.gwt.http.client.URL;
import com.google.gwt.json.client.JSONArray;
import com.google.gwt.json.client.JSONObject;
+import com.google.gwt.json.client.JSONParser;
import com.google.gwt.json.client.JSONString;
+import com.google.gwt.json.client.JSONValue;
import com.google.gwt.user.client.Window;
import us.isidor.gdl.anaToMia.TopicMaps.TmEngineModel.ExporterException;
import us.isidor.gdl.anaToMia.TopicMaps.TmEngineModel.TmEngine;
@@ -33,6 +37,7 @@
public final String DELETE_REUQEST_URL = IsidorusConstants.DELETE_REQUEST_URL;
public final String COMMIT_REQUEST_URL = IsidorusConstants.COMMIT_REQUEST_URL;
public final String GET_REQUEST_URL = IsidorusConstants.GET_FRAGMENT_REQUEST_URL;
+ public final String HASH_VALUE_OCCURRENCE_TYPE = "http://textgrid.org/serviceregistry/model/value";
@Override
@@ -234,24 +239,24 @@
if (200 == response.getStatusCode()) {
if(edited){
String[] topPsi = Utils.splitUriByLastFragment(psi);
- String[] tmPsi = Utils.splitUriByLastFragment(IsidorusConstants.TOPIC_MAP_IDENTIFIER);
+ String[] hashValuePsi = Utils.splitUriByLastFragment(CommitCallback.this.HASH_VALUE_OCCURRENCE_TYPE);
JSONObject delObj = new JSONObject();
- delObj.put("type", new JSONString("Topic"));
- JSONObject prefs = new JSONObject();
- prefs.put("pref_1", new JSONString(topPsi[0]));
- prefs.put("pref_2", new JSONString(tmPsi[0]));
- JSONObject delTop = new JSONObject();
- delTop.put("prefixes", prefs);
- delTop.put("version", new JSONString("1.1"));
- delTop.put("item_type", new JSONString("topic"));
- JSONArray jPsis = new JSONArray();
- jPsis.set(0, new JSONString("[pref_1:" + topPsi[1] + "]"));
- delTop.put("subject_identifiers", jPsis);
+ delObj.put("type", new JSONString("Occurrence"));
+ JSONObject delOcc = new JSONObject();
+ delObj.put("delete", delOcc);
+ delOcc.put("version", new JSONString("1.1"));
+ delOcc.put("item_type", new JSONString("occurrence"));
+ JSONObject prefixes = new JSONObject();
+ prefixes.put("pref_1", new JSONString(topPsi[0]));
+ prefixes.put("pref_2", new JSONString(hashValuePsi[0]));
+ delOcc.put("prefixes", prefixes);
JSONArray jParents = new JSONArray();
- jParents.set(0, new JSONString("ii:[pref_2:" + tmPsi[1] + "]"));
- delTop.put("parent", jParents);
- delObj.put("delete", delTop);
+ jParents.set(0, new JSONString("si:[pref_1:" + topPsi[1] + "]"));
+ delOcc.put("parent", jParents);
+
+ delOcc.put("value", this.getOldHashValue(response.getText(), this.psi));
+ delOcc.put("type", new JSONString("si:[pref_2:" + hashValuePsi[1] + "]"));
Window.alert(">>\n" + delObj.toString());
@@ -284,6 +289,122 @@
// TODO: reset page
}
}
+
+
+ private JSONString getOldHashValue(String jtmFragment, String topicPsiToBeUpdated){
+ JSONString result = new JSONString("");
+ if(jtmFragment == null || topicPsiToBeUpdated == null) return result;
+
+ JSONValue receivedFragment = JSONParser.parseStrict(jtmFragment);
+ JSONObject fragment = receivedFragment.isObject();
+ if(fragment == null) return result;
+
+ JSONValue topsVal = fragment.get("topics");
+ if(topsVal == null) return result;
+ JSONArray topics = topsVal.isArray();
+ if(topics == null) return result;
+
+ JSONValue prefVal = fragment.get("prefixes");
+ JSONObject prefixes = null;
+ if(prefVal != null) prefixes = prefVal.isObject();
+
+ for(int topicIdx = 0; topicIdx != topics.size(); ++topicIdx){
+ JSONValue hashTopicVal = topics.get(topicIdx);
+ if(hashTopicVal == null) continue;
+
+ JSONObject hashTopic = hashTopicVal.isObject();
+ if(hashTopic == null) continue;
+
+ JSONValue psisVal = topics.get(topicIdx);
+ if(psisVal == null) continue;
+
+ JSONArray psis = psisVal.isArray();
+ if(psis == null) continue;
+ for(int psiIdx = 0; psiIdx != psis.size(); ++psiIdx){
+ JSONValue psiVal = psis.get(psiIdx);
+ if(psiVal == null) continue;
+
+ JSONString psi = psiVal.isString();
+ if(psi != null && this.computeUri(psi.stringValue(), prefixes).equals(psi)){
+ JSONObject occ = this.gethashValueOccurrence(hashTopic, prefixes);
+ if(occ == null) continue;
+
+ JSONValue occVal = occ.get("value");
+ if(occVal == null) continue;
+
+ JSONString occValue = occVal.isString();
+ if(occValue != null) return occValue;
+ }
+ }
+ }
+
+
+ return result;
+ }
+
+
+ private JSONObject gethashValueOccurrence(JSONObject hashTopic, JSONObject prefixes){
+ if(hashTopic == null) return null;
+
+ JSONValue occsVal = hashTopic.get("occurrences");
+ if(occsVal == null) return null;
+ JSONArray occurrences = occsVal.isArray();
+ if(occurrences == null) return null;
+ for(int occIdx = 0; occIdx != occurrences.size(); ++occIdx){
+ JSONValue occVal = occurrences.get(occIdx);
+ if(occVal == null) continue;
+ JSONObject occurrence = occVal.isObject();
+ if(occurrence == null) continue;
+ JSONValue typeVal = occurrence.get("type");
+ if(typeVal == null) continue;
+ JSONString typeReference = typeVal.isString();
+ if(typeReference == null) continue;
+
+ Pair<String, TopicIdentifierTypes> typeRef = this.computeReferenceUri(typeReference, prefixes);
+ if(typeRef != null && typeRef.getSecond().equals(TopicIdentifierTypes.SubjectIdentifier) && typeRef.getFirst().equals(CommitCallback.this.HASH_VALUE_OCCURRENCE_TYPE)) return occurrence;
+ }
+
+ return null;
+ }
+
+
+ private Pair<String, TopicIdentifierTypes> computeReferenceUri(JSONString curieReference, JSONObject prefixes){
+ if(curieReference == null) return null;
+
+ String curieString = curieReference.stringValue();
+ if(curieString == null) return null;
+
+ if(curieString.startsWith("ii:")){
+ return new Pair<String, TopicIdentifierTypes>(this.computeUri(curieString.substring(3), prefixes), TopicIdentifierTypes.ItemIdentifier);
+ } else if(curieString.startsWith("si:")){
+ return new Pair<String, TopicIdentifierTypes>(this.computeUri(curieString.substring(3), prefixes), TopicIdentifierTypes.SubjectIdentifier);
+ } else if(curieString.startsWith("sl:")){
+ return new Pair<String, TopicIdentifierTypes>(this.computeUri(curieString.substring(3), prefixes), TopicIdentifierTypes.SubjectLocator);
+ } else {
+ return null;
+ }
+ }
+
+
+ private String computeUri(String curie, JSONObject prefixes){
+ if(curie == null) return "";
+
+ if(curie.charAt(0) == '[' && curie.charAt(curie.length() - 1) == ']'){
+ if(prefixes == null) return "";
+ String rawString = curie.substring(1, curie.length() - 1);
+ String[] parts = rawString.split(":");
+ if(parts.length != 2) return "";
+
+ JSONValue prefVal = prefixes.get(parts[0]);
+ if(prefVal == null) return "";
+ JSONString prefString = prefVal.isString();
+ if(prefString == null) return "";
+
+ return prefString + parts[1];
+ } else {
+ return curie;
+ }
+ }
@Override
@@ -294,6 +415,8 @@
}
+
+
private class HashObjectDeleteRequest implements RequestCallback{
private String objectToBeDeleted = null;
private String objectToBeSend = null;
More information about the Isidorus-cvs
mailing list