Error en Vocabulary en la función synchronize cuando descargo la escena activa

parent 153e6af3
...@@ -172,8 +172,10 @@ public class Vocabulary implements Iterable<Picto> { ...@@ -172,8 +172,10 @@ public class Vocabulary implements Iterable<Picto> {
// and (ii) downloading // and (ii) downloading
if (!upload_pending) { if (!upload_pending) {
final String picto_str = "/pictos"; //final String picto_str = "/pictos";
final String picto_str = "/activeScene";
String operation = PCBcontext.getPcbdb().getCurrentUser().get_restapi_operation_stu() + picto_str; String operation = PCBcontext.getPcbdb().getCurrentUser().get_restapi_operation_stu() + picto_str;
Log.i("TAG_PRUEBAS","Ruta: "+operation);
PCBcontext.getRestapiWrapper().ask(operation, new RestapiWrapper.iRestapiListener() { PCBcontext.getRestapiWrapper().ask(operation, new RestapiWrapper.iRestapiListener() {
@Override @Override
public void preExecute() { public void preExecute() {
...@@ -182,24 +184,32 @@ public class Vocabulary implements Iterable<Picto> { ...@@ -182,24 +184,32 @@ public class Vocabulary implements Iterable<Picto> {
@Override @Override
public void result(JSONArray result) { public void result(JSONArray result) {
}
@Override
public void result(JSONObject result) {
if (result != null) { if (result != null) {
final String jpicto = "picto"; Log.i("TAG_PRUEBAS",result.toString());
/* final String jpicto = "picto";
final String jid = "id"; final String jid = "id";
final String juri = "uri"; final String juri = "uri";
final String jattributes = "attributes"; final String jattributes = "attributes";*/
Picto[] pictos = new Picto[result.length()];
JSONObject picto, attributes; JSONObject picto, attributes;
JSONObject stupicto = null; JSONObject stupicto = null;
try { try {
for (int i = 0; i < result.length(); i++) { JSONArray stu_pictos = result.getJSONArray("pictos"); //Obtengo el JSONArray de los pictos
stupicto = result.getJSONObject(i); Log.i("TAG_PRUEBAS",stu_pictos.toString());
picto = stupicto.getJSONObject(jpicto); Picto[] pictos = new Picto[stu_pictos.length()];
attributes = stupicto.getJSONObject(jattributes);
attributes.put(Picto.JSON_ATTTRS.STUPICTO_ID, stupicto.get(jid)); for (int i = 0; i < stu_pictos.length(); i++) {
pictos[i] = new Picto(picto.getInt(jid), stupicto = stu_pictos.getJSONObject(i);
picto.getString(juri), picto = stupicto.getJSONObject("picto");
attributes = stupicto.getJSONObject("attributes");
attributes.put(Picto.JSON_ATTTRS.STUPICTO_ID, stupicto.getInt("id"));
pictos[i] = new Picto(stupicto.getInt("id"),
picto.getString("uri"),
attributes); attributes);
} }
synchronizeImgs(pictos); synchronizeImgs(pictos);
...@@ -215,12 +225,14 @@ public class Vocabulary implements Iterable<Picto> { ...@@ -215,12 +225,14 @@ public class Vocabulary implements Iterable<Picto> {
Log.e(this.getClass().getName(), " Picto JSON error from server: " + stupicto.toString()); Log.e(this.getClass().getName(), " Picto JSON error from server: " + stupicto.toString());
this.error(new RestapiWrapper.HTTPException("JSON Error:" + e.getMessage(), -1)); this.error(new RestapiWrapper.HTTPException("JSON Error:" + e.getMessage(), -1));
} }
}else{
Log.i("TAG_PRUEBAS","result null");
} }
} }
@Override /*@Override
public void result(JSONObject result) { public void result(JSONObject result) {
} }*/
@Override @Override
public void error(RestapiWrapper.HTTPException e) { public void error(RestapiWrapper.HTTPException e) {
...@@ -245,13 +257,15 @@ public class Vocabulary implements Iterable<Picto> { ...@@ -245,13 +257,15 @@ public class Vocabulary implements Iterable<Picto> {
this.pictos.clear(); this.pictos.clear();
for (Picto updated_picto: updated_collection) { for (Picto updated_picto: updated_collection) {
LinkedList<Picto> pictos_cat; LinkedList<Picto> pictos_cat;
Log.i("TAG_PRUEBAS","ID: "+updated_picto.get_id());
Picto picto = new Picto(updated_picto.get_id(), Picto picto = new Picto(updated_picto.get_id(),
updated_picto.get_url(), updated_picto.get_url(),
updated_picto.get_translation(), updated_picto.get_translation(),
updated_picto.get_json_attrs()); updated_picto.get_json_attrs());
if (pictos.containsKey(picto.get_category())) if (pictos.containsKey(picto.get_category())) {
pictos_cat = pictos.get(picto.get_category()); pictos_cat = pictos.get(picto.get_category());
else { Log.i("TAG_PRUEBAS","Tiene categoria: "+pictos_cat);
}else {
pictos_cat = new LinkedList<>(); pictos_cat = new LinkedList<>();
pictos.put(new Integer(picto.get_category()),pictos_cat); pictos.put(new Integer(picto.get_category()),pictos_cat);
} }
......
...@@ -56,4 +56,4 @@ public class VocabularyIterator implements Iterator<Picto> { ...@@ -56,4 +56,4 @@ public class VocabularyIterator implements Iterator<Picto> {
public void remove() { public void remove() {
} }
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment