diff --git a/Agetac-client/.classpath b/Agetac-client/.classpath index 8a6e6e7..a1b0ce3 100644 --- a/Agetac-client/.classpath +++ b/Agetac-client/.classpath @@ -4,7 +4,6 @@ - @@ -20,5 +19,9 @@ + + + + diff --git a/Agetac-client/lib/asm-3.3.jar b/Agetac-client/lib/asm-3.3.jar new file mode 100644 index 0000000..d44dfd8 Binary files /dev/null and b/Agetac-client/lib/asm-3.3.jar differ diff --git a/Agetac-client/lib/datanucleus-api-jdo-3.0.5.jar b/Agetac-client/lib/datanucleus-api-jdo-3.0.5.jar new file mode 100644 index 0000000..cc3236f Binary files /dev/null and b/Agetac-client/lib/datanucleus-api-jdo-3.0.5.jar differ diff --git a/Agetac-client/lib/gson-2.1.jar b/Agetac-client/lib/gson-2.1.jar new file mode 100644 index 0000000..b85f091 Binary files /dev/null and b/Agetac-client/lib/gson-2.1.jar differ diff --git a/Agetac-client/lib/jdo-api-3.1-SNAPSHOT-20110926.jar b/Agetac-client/lib/jdo-api-3.1-SNAPSHOT-20110926.jar new file mode 100644 index 0000000..e305d3c Binary files /dev/null and b/Agetac-client/lib/jdo-api-3.1-SNAPSHOT-20110926.jar differ diff --git a/Agetac-client/src/org/agetac/activity/MoyensActivity.java b/Agetac-client/src/org/agetac/activity/MoyensActivity.java index 18c568c..12aeeb7 100644 --- a/Agetac-client/src/org/agetac/activity/MoyensActivity.java +++ b/Agetac-client/src/org/agetac/activity/MoyensActivity.java @@ -158,9 +158,9 @@ public void update() { } public Vehicule genVehicule(CategorieVehicule cat) { - Vehicule veh = new Vehicule(null, null, + Vehicule veh = new Vehicule(null, cat, "Janze", EtatVehicule.ALERTE, - new Groupe("0", null, null), getTime()); + new Groupe(null, null), getTime()); return veh; } diff --git a/Agetac-client/src/org/agetac/activity/SITACActivity.java b/Agetac-client/src/org/agetac/activity/SITACActivity.java index 1892e92..7f6ed40 100644 --- a/Agetac-client/src/org/agetac/activity/SITACActivity.java +++ b/Agetac-client/src/org/agetac/activity/SITACActivity.java @@ -158,7 +158,7 @@ public void onOverlayLongPressed(MotionEvent e, MapView mapView) { Position p = new Position(m.getLongitudeE6(), m.getLatitudeE6()); flag = ActionFlag.ADD; - Vehicule v = new Vehicule(null, p, CategorieVehicule.FPT, "Janze", EtatVehicule.PARTIS, new Groupe("0", new Agent(), new ArrayList()), "4242"); + Vehicule v = new Vehicule(p, CategorieVehicule.FPT, "Janze", EtatVehicule.PARTIS, new Groupe(new Agent(), new ArrayList()), "4242"); touchedEntity = new Entity(v, currentPicto, EntityState.ON_SITAC); //TODO vrai relation picto-Entity observable.setChanged(); @@ -249,7 +249,7 @@ public boolean onUp(MotionEvent end, MapView mapView) { LinePicto lp = new LinePicto(currentPicto.getName(), currentPicto.getBitmap(), currentPicto.getColor(), currentPicto.getState(), currentPicto.getShape(), currentPicto.getGraphicalOverload(), start, stop, mapView.getProjection().metersToEquatorPixels(1.0f)); - Action as = new Action("42", lineMiddlePos, ActionType.FIRE, lineBeginPos, lineEndPos); + Action as = new Action(lineMiddlePos, ActionType.FIRE, lineBeginPos, lineEndPos); touchedEntity = new Entity(as, lp, EntityState.ON_SITAC); //TODO vrai relation picto-Entity flag = ActionFlag.ADD; observable.setChanged(); diff --git a/Agetac-client/src/org/agetac/command/SendMessageCommand.java b/Agetac-client/src/org/agetac/command/SendMessageCommand.java index 11cf726..4fffb4d 100644 --- a/Agetac-client/src/org/agetac/command/SendMessageCommand.java +++ b/Agetac-client/src/org/agetac/command/SendMessageCommand.java @@ -3,20 +3,16 @@ import java.io.IOException; import java.util.Date; -import org.agetac.common.exception.BadResponseException; import org.agetac.common.model.impl.Message; import org.agetac.controller.Controller; import org.agetac.entity.Entity; import org.agetac.memento.IMemento; -import org.json.JSONException; public class SendMessageCommand implements IRecordableCommand { public static final String NAME = "EnvoyerMessage"; private static int idMessage = 0; private static boolean messOk = false; - - private Controller controller; public SendMessageCommand(Controller controller) { @@ -24,90 +20,90 @@ public SendMessageCommand(Controller controller) { } - public static void setMessOk (boolean b){ + public static void setMessOk(boolean b) { messOk = b; } - public static boolean getMessOk () { + public static boolean getMessOk() { return messOk; } - public String getGroupeHoraire(){ + public String getGroupeHoraire() { Date d = new Date(); - String res=""; + String res = ""; int minutes = d.getMinutes(); int heures = d.getHours(); - if(heures < 10 ) {res = "0" + heures;} - else {res = "" + heures;} + if (heures < 10) { + res = "0" + heures; + } else { + res = "" + heures; + } - if (minutes < 10) {res = res +"0" + minutes;} - else { res = res + minutes;} + if (minutes < 10) { + res = res + "0" + minutes; + } else { + res = res + minutes; + } return res; } - - public void sendMessage(String message) throws BadResponseException, IOException, JSONException { + public void sendMessage(String message) throws IOException { // TODO c'pas possible ça ... - // la connexion au serveur est déjà faite dans org.agetac.network.ServerConnection - -// String date = getGroupeHoraire(); -// String id = "" + SendMessageCommand.idMessage; -// Message mess = new Message ( id, message, date); -// System.out.println("Message : "+id + "," + message + "," + date); -// -// String interId = "0"; -// ServerConnection serv = new ServerConnection("148.60.13.116", "8112", "agetacserver"); -// -// -// Representation r = null; -// try { -// r = new JsonRepresentation(mess.toJSON()); -// serv.putResource("intervention/" + interId + "/message", -// mess.getUniqueID(), r); -// messOk = true; -// -// } catch (JSONException e) { -// -// System.out.println("Le message n'a pas pu �tre envoy� sur le serveur"); -// e.printStackTrace(); -// } -// -// -// -// -// Representation rep = serv.getResource("intervention/" + interId + "/message", -// mess.getUniqueID()); -// JsonRepresentation jrepr = new JsonRepresentation(rep); -// -// -// System.out.println(new Message(jrepr.getJsonObject()).getMessage()); + // la connexion au serveur est déjà faite dans + // org.agetac.network.ServerConnection + + // String date = getGroupeHoraire(); + // String id = "" + SendMessageCommand.idMessage; + // Message mess = new Message ( id, message, date); + // System.out.println("Message : "+id + "," + message + "," + date); + // + // String interId = "0"; + // ServerConnection serv = new ServerConnection("148.60.13.116", "8112", + // "agetacserver"); + // + // + // Representation r = null; + // try { + // r = new JsonRepresentation(mess.toJSON()); + // serv.putResource("intervention/" + interId + "/message", + // mess.getUniqueID(), r); + // messOk = true; + // + // } catch (JSONException e) { + // + // System.out.println("Le message n'a pas pu �tre envoy� sur le serveur"); + // e.printStackTrace(); + // } + // + // + // + // + // Representation rep = serv.getResource("intervention/" + interId + + // "/message", + // mess.getUniqueID()); + // JsonRepresentation jrepr = new JsonRepresentation(rep); + // + // + // System.out.println(new Message(jrepr.getJsonObject()).getMessage()); } - public void execute() { try { - try { - sendMessage(controller.getMessage()); - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (JSONException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } catch (BadResponseException e) { + sendMessage(controller.getMessage()); + } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } + idMessage++; } diff --git a/Agetac-client/src/org/agetac/engine/InterventionEngine.java b/Agetac-client/src/org/agetac/engine/InterventionEngine.java index 8d23a47..8ce2411 100644 --- a/Agetac-client/src/org/agetac/engine/InterventionEngine.java +++ b/Agetac-client/src/org/agetac/engine/InterventionEngine.java @@ -20,105 +20,98 @@ import org.agetac.network.ServerConnection; import org.agetac.network.ServerThread; import org.agetac.observer.MyObservable; -import org.json.JSONException; import org.restlet.ext.json.JsonRepresentation; import org.restlet.representation.Representation; +import com.google.gson.Gson; + public class InterventionEngine implements IInterventionEngine { private static final String TAG = "InterventionEngine"; - + private Intervention intervention; private List entities; private MyObservable observable; private InterventionConnection iConn; - + public InterventionEngine(ServerConnection serv) { observable = new MyObservable(); entities = new ArrayList(); - - // TODO need auth ici pour récupérer l'intervention associée au COS connecté + + // TODO need auth ici pour récupérer l'intervention associée au COS + // connecté Representation repr = serv.getResource("intervention", "1"); - + try { JsonRepresentation jsonRepr = new JsonRepresentation(repr); - intervention = new Intervention(jsonRepr.getJsonObject()); + intervention = new Gson().fromJson(jsonRepr.getReader(), + Intervention.class); iConn = new InterventionConnection(intervention.getUniqueID(), serv); - + } catch (IOException e) { android.util.Log.d(TAG, e.getMessage()); - - } catch (JSONException e) { - android.util.Log.d(TAG, e.getMessage()); - - } catch (InvalidJSONException e) { - android.util.Log.d(TAG, e.getMessage()); - + } catch (Exception e) { // XXX hack qui ne marche pas toujours... GREAT - android.util.Log.d(TAG, ""+e.getMessage()); + android.util.Log.d(TAG, "" + e.getMessage()); } } - + @Override public void sendMessage(Message m) { try { iConn.putMessage(m); } catch (BadResponseException e) { android.util.Log.d(TAG, e.getMessage()); - - } catch (JSONException e) { - android.util.Log.d(TAG, e.getMessage()); + } } public void demandeMoyen(DemandeMoyen dm) { -// dm = iConn.putDemandeMoyen(dm); -// ServerThread t = new ServerThread(iConn, dm); -// t.start(); + // dm = iConn.putDemandeMoyen(dm); + // ServerThread t = new ServerThread(iConn, dm); + // t.start(); } - + @Override public void addEntity(IEntity entity) { try { if (entity.getModel() instanceof Vehicule) { Vehicule v = (Vehicule) entity.getModel(); -// entity.setModel(iConn.putVehicule(v)); + // entity.setModel(iConn.putVehicule(v)); iConn.putVehicule(v); entities.add(entity); - + } else if (entity.getModel() instanceof Action) { Action a = (Action) entity.getModel(); -// entity.setModel(iConn.putAction(a)); + // entity.setModel(iConn.putAction(a)); iConn.putAction(a); entities.add(entity); - + } else if (entity.getModel() instanceof Source) { Source s = (Source) entity.getModel(); -// entity.setModel(iConn.putSource(s)); + // entity.setModel(iConn.putSource(s)); iConn.putSource(s); entities.add(entity); - + } else if (entity.getModel() instanceof Cible) { Cible c = (Cible) entity.getModel(); -// entity.setModel(iConn.putCible(c)); + // entity.setModel(iConn.putCible(c)); iConn.putCible(c); entities.add(entity); - + } else if (entity.getModel() instanceof Implique) { Implique i = (Implique) entity.getModel(); -// entity.setModel(iConn.putImplique(i)); + // entity.setModel(iConn.putImplique(i)); iConn.putImplique(i); entities.add(entity); } - + } catch (BadResponseException e) { android.util.Log.d(TAG, e.getMessage()); - - } catch (JSONException e) { - android.util.Log.d(TAG, e.getMessage()); + } catch (Exception e) { - android.util.Log.d(TAG, ""+e.getMessage()); + android.util.Log.d(TAG, "" + e.getMessage()); } notifyObservers(); @@ -131,32 +124,32 @@ public void removeEntity(IEntity entity) { Vehicule v = (Vehicule) entity.getModel(); iConn.deleteVehicule(v); entities.remove(entity); - + } else if (entity.getModel() instanceof Action) { Action a = (Action) entity.getModel(); iConn.deleteAction(a); entities.remove(entity); - + } else if (entity.getModel() instanceof Source) { Source s = (Source) entity.getModel(); iConn.deleteSource(s); entities.remove(entity); - + } else if (entity.getModel() instanceof Cible) { Cible c = (Cible) entity.getModel(); iConn.deleteCible(c); entities.remove(entity); - + } else if (entity.getModel() instanceof Implique) { Implique i = (Implique) entity.getModel(); iConn.deleteImplique(i); entities.remove(entity); } - + } catch (BadResponseException e) { android.util.Log.d(TAG, e.getMessage()); } - + notifyObservers(); } @@ -169,12 +162,12 @@ public void editEntity(IEntity entity) { public List getEntities() { return entities; } - + @Override public Intervention getIntervention() { return intervention; } - + private void notifyObservers() { observable.setChanged(); observable.notifyObservers(intervention);