Implementando subida de archivos pcb->server

parent 9cf71f79
...@@ -132,7 +132,6 @@ public class RestapiWrapper { ...@@ -132,7 +132,6 @@ public class RestapiWrapper {
// convert inputstream to string // convert inputstream to string
if (inputStream!=null) result = convertInputStreamToString(inputStream); if (inputStream!=null) result = convertInputStreamToString(inputStream);
} catch (IOException e) { } catch (IOException e) {
Log.e(RestapiWrapper.class.getName(), e.getLocalizedMessage());
if (listener!=null) listener.error(e); if (listener!=null) listener.error(e);
result=e.getMessage(); result=e.getMessage();
} }
...@@ -233,13 +232,15 @@ public class RestapiWrapper { ...@@ -233,13 +232,15 @@ public class RestapiWrapper {
} else if (jsonResult instanceof JSONArray) { } else if (jsonResult instanceof JSONArray) {
// The result is an array // The result is an array
params.listener.result((JSONArray) jsonResult); params.listener.result((JSONArray) jsonResult);
} else params.listener.result((JSONObject) null); } else
params.listener.result((JSONObject) null);
}else{ }else{
params.listener.result((JSONObject) null); params.listener.result((JSONObject) null);
} }
} catch (JSONException e) { } catch (JSONException e) {
params.listener.error(e); params.listener.error(e);
} }
params.url_params.clear();
} }
} }
} }
\ No newline at end of file
...@@ -117,7 +117,6 @@ public class SailsSocketsIO { ...@@ -117,7 +117,6 @@ public class SailsSocketsIO {
Log.d(this.getClass().getName(), "Emitted messsage:" + obj); Log.d(this.getClass().getName(), "Emitted messsage:" + obj);
socket.emit(this.EMIT_METHOD, obj, ack); socket.emit(this.EMIT_METHOD, obj, ack);
} }
public void destroy() { public void destroy() {
this.socket.disconnect(); this.socket.disconnect();
this.socket.off(); this.socket.off();
......
...@@ -24,7 +24,6 @@ public class ActionLog implements iRestapiListener { ...@@ -24,7 +24,6 @@ public class ActionLog implements iRestapiListener {
public ActionLog() { public ActionLog() {
actions_buffer=PCBcontext.getPcbdb().loadActions(); actions_buffer=PCBcontext.getPcbdb().loadActions();
actions_buffer=new Vector<>();//TODO BORRAR
if (PCBcontext.getNetService().online()) batch(); if (PCBcontext.getNetService().online()) batch();
} }
// String constant for logs // String constant for logs
...@@ -49,7 +48,7 @@ public class ActionLog implements iRestapiListener { ...@@ -49,7 +48,7 @@ public class ActionLog implements iRestapiListener {
public void batch() { public void batch() {
if (!actions_buffer.isEmpty()) { if (!actions_buffer.isEmpty()) {
Hashtable<String, String> params= new Hashtable<>(1); Hashtable<String, String> params=new Hashtable<>(1);
String url="stu/actions_batch"; String url="stu/actions_batch";
String actions=""; String actions="";
for (JSONObject action: actions_buffer) for (JSONObject action: actions_buffer)
...@@ -58,7 +57,6 @@ public class ActionLog implements iRestapiListener { ...@@ -58,7 +57,6 @@ public class ActionLog implements iRestapiListener {
params.put("actions",actions); params.put("actions",actions);
Log.i(this.getClass().getCanonicalName()," Sending batch actions: "+url+": "+actions); Log.i(this.getClass().getCanonicalName()," Sending batch actions: "+url+": "+actions);
PCBcontext.getRestapiWrapper().ask(url, params, "post", this); PCBcontext.getRestapiWrapper().ask(url, params, "post", this);
params.clear();
} }
} }
......
...@@ -61,6 +61,9 @@ public class PictoAction extends Action { ...@@ -61,6 +61,9 @@ public class PictoAction extends Action {
public JSONObject get_json_picto() throws JSONException { public JSONObject get_json_picto() throws JSONException {
final String param_id_json="id"; final String param_id_json="id";
final String param_picto="picto"; final String param_picto="picto";
final String param_expression="expression";
final String param_expr_lang="lang";
final String param_expr_text="text";
final String param_attrs="attributes"; final String param_attrs="attributes";
final String param_picto_id="id"; final String param_picto_id="id";
final String param_picto_uri="uri"; final String param_picto_uri="uri";
...@@ -69,8 +72,11 @@ public class PictoAction extends Action { ...@@ -69,8 +72,11 @@ public class PictoAction extends Action {
.put(param_picto_uri, picto.get_url()) .put(param_picto_uri, picto.get_url())
.put(param_picto_cat, picto.get_category()); .put(param_picto_cat, picto.get_category());
JSONObject attributes = new JSONObject(picto.get_json_attrs()); JSONObject attributes = new JSONObject(picto.get_json_attrs());
JSONObject expression = new JSONObject().put(param_expr_lang,PCBcontext.getPcbdb().getCurrentUser().get_lang_stu())
.put(param_expr_text,picto.get_translation());
JSONObject subPicto = new JSONObject().put(param_id_json, 1470) JSONObject subPicto = new JSONObject().put(param_id_json, 1470)
.put(param_picto, subsubPicto) .put(param_picto, subsubPicto)
.put(param_expression,expression)
.put(param_attrs, attributes); .put(param_attrs, attributes);
return subPicto; return subPicto;
} }
......
...@@ -34,9 +34,10 @@ import java.util.LinkedList; ...@@ -34,9 +34,10 @@ import java.util.LinkedList;
*/ */
public class Room { public class Room {
protected SailsSocketsIO socket=null; protected SailsSocketsIO socket=null;
protected boolean inRoom=false; protected boolean inRoom=false;
public Room( ) {
public Room( ) {
reconnect(); reconnect();
} }
...@@ -52,7 +53,8 @@ public class Room { ...@@ -52,7 +53,8 @@ public class Room {
this.socket.emit(url, this.common_data(action.get_type(), action.get_json()), new Ack() { this.socket.emit(url, this.common_data(action.get_type(), action.get_json()), new Ack() {
@Override @Override
public void call(Object... args) { public void call(Object... args) {
Log.d(this.getClass().getCanonicalName(),"Action ack received"); for (Object arg : args)
Log.d(this.getClass().getName(), "Ack messsage:" + arg);
} }
}); });
} catch (JSONException e) { } catch (JSONException e) {
...@@ -66,7 +68,8 @@ public class Room { ...@@ -66,7 +68,8 @@ public class Room {
this.socket.emit(url, this.common_data(action.get_type(), action.get_json()).put(token_param, token), new Ack() { this.socket.emit(url, this.common_data(action.get_type(), action.get_json()).put(token_param, token), new Ack() {
@Override @Override
public void call(Object... args) { public void call(Object... args) {
Log.d(this.getClass().getCanonicalName(), "Action ack received"); for (Object arg : args)
Log.d(this.getClass().getName(), "Ack messsage:" + arg);
} }
}); });
} catch (JSONException e) { } catch (JSONException e) {
...@@ -82,13 +85,14 @@ public class Room { ...@@ -82,13 +85,14 @@ public class Room {
this.socket=new SailsSocketsIO(PCBcontext.getRestapiWrapper().getServer(), transport, new Emitter.Listener() { this.socket=new SailsSocketsIO(PCBcontext.getRestapiWrapper().getServer(), transport, new Emitter.Listener() {
@Override @Override
public void call(Object... args) { public void call(Object... args) {
Log.i(this.getClass().getName(), "Reconnect successful");
subscribe(); subscribe();
inRoom=true; inRoom=true;
} }
}, new Emitter.Listener() { }, new Emitter.Listener() {
@Override @Override
public void call(Object... args) { public void call(Object... args) {
Log.i(this.getClass().getName(), "Error sending Action: "+args[0]); Log.i(this.getClass().getName(), "Room exit: "+args[0]);
if (args.length>0 && args[0].toString().equals("transport error") ) { if (args.length>0 && args[0].toString().equals("transport error") ) {
inRoom=false; inRoom=false;
} }
...@@ -99,9 +103,6 @@ public class Room { ...@@ -99,9 +103,6 @@ public class Room {
public void listen(String msg, Emitter.Listener listener) { public void listen(String msg, Emitter.Listener listener) {
this.socket.registerMessage(msg, listener); this.socket.registerMessage(msg, listener);
} }
void subscribe() { void subscribe() {
final String url="/stu/subscribe"; final String url="/stu/subscribe";
final String action="subscribe"; final String action="subscribe";
......
package com.yottacode.pictogram.grammar; package com.yottacode.pictogram.grammar;
import android.os.Environment;
import android.util.Log; import android.util.Log;
import com.yottacode.pictogram.dao.Picto; import com.yottacode.pictogram.dao.Picto;
...@@ -14,6 +15,10 @@ import org.json.JSONArray; ...@@ -14,6 +15,10 @@ import org.json.JSONArray;
import org.json.JSONException; import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Hashtable; import java.util.Hashtable;
import java.util.Iterator; import java.util.Iterator;
import java.util.LinkedList; import java.util.LinkedList;
...@@ -119,6 +124,43 @@ public class Vocabulary implements Iterable<Picto>, iRestapiListener, iVocabular ...@@ -119,6 +124,43 @@ public class Vocabulary implements Iterable<Picto>, iRestapiListener, iVocabular
PCBcontext.getPcbdb().addPicto(pic); PCBcontext.getPcbdb().addPicto(pic);
} }
/**
*TODO: to be finished and tried
*/
public void uploadPicto(String path, String name, String exp, int cat, int coord_x, int coord_y) throws IOException {
File file = new File(path);
FileInputStream imageInFile = new FileInputStream(file);
byte imageData[] = new byte[(int)file.length()];
imageInFile.read(imageData);
Hashtable<String,String> params=new Hashtable<>(3);
params.put("filename", name);
params.put("folder","custompictos");
params.put("id",String.valueOf(PCBcontext.getPcbdb().getCurrentUser().get_id_stu()));
params.put("file", String.valueOf(imageData));
PCBcontext.getRestapiWrapper().ask("upload", params, "post", new iRestapiListener() {
@Override
public void result(JSONArray result) {
}
@Override
public void result(JSONObject result) {
}
@Override
public void error(Exception e) {
}
});
}
/**
*
* @param pic_cat
* @return
*/
private boolean empty_category(int pic_cat) {return this.pictos.get(pic_cat)==null;} private boolean empty_category(int pic_cat) {return this.pictos.get(pic_cat)==null;}
private int find_picto_index(int pic_cat, int pic_id) { private int find_picto_index(int pic_cat, int pic_id) {
......
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