r2993 - in branches/ng-jtimer: . src/main/java/org/chorem/jtimer/entities src/main/java/org/chorem/jtimer/storage src/main/java/org/chorem/jtimer/web src/main/webapp/js
Author: obruce Date: 2014-06-03 18:27:59 +0200 (Tue, 03 Jun 2014) New Revision: 2993 Url: http://forge.chorem.org/projects/jtimer/repository/revisions/2993 Log: Ajout d'une todolist pour le serveur, test pour taper sur un autre server Added: branches/ng-jtimer/src/main/java/org/chorem/jtimer/entities/TodoList.java branches/ng-jtimer/src/main/java/org/chorem/jtimer/web/TiersServerResource.java Modified: branches/ng-jtimer/pom.xml branches/ng-jtimer/src/main/java/org/chorem/jtimer/entities/TimerTask.java branches/ng-jtimer/src/main/java/org/chorem/jtimer/storage/Storage.java branches/ng-jtimer/src/main/java/org/chorem/jtimer/web/RestApplication.java branches/ng-jtimer/src/main/java/org/chorem/jtimer/web/TasksResource.java branches/ng-jtimer/src/main/java/org/chorem/jtimer/web/TimeResource.java branches/ng-jtimer/src/main/webapp/js/controllers.js Modified: branches/ng-jtimer/pom.xml =================================================================== --- branches/ng-jtimer/pom.xml 2014-05-28 09:38:19 UTC (rev 2992) +++ branches/ng-jtimer/pom.xml 2014-06-03 16:27:59 UTC (rev 2993) @@ -113,6 +113,12 @@ <groupId>org.eclipse.jetty</groupId> <artifactId>jetty-maven-plugin</artifactId> <version>${jettyVersion}</version> + <configuration> + <httpConnector> + <port>8081</port> + </httpConnector> + </configuration> + </plugin> <plugin> <artifactId>maven-war-plugin</artifactId> Modified: branches/ng-jtimer/src/main/java/org/chorem/jtimer/entities/TimerTask.java =================================================================== --- branches/ng-jtimer/src/main/java/org/chorem/jtimer/entities/TimerTask.java 2014-05-28 09:38:19 UTC (rev 2992) +++ branches/ng-jtimer/src/main/java/org/chorem/jtimer/entities/TimerTask.java 2014-06-03 16:27:59 UTC (rev 2993) @@ -43,9 +43,6 @@ /** serialVersionUID */ private static final long serialVersionUID = -7590755569706702695L; - /** Task number. */ - protected long number; - /** Task uuid */ protected String taskId; @@ -75,8 +72,7 @@ */ public TimerTask() { // wrong value to detect bug - number = -1; - this.isremoved = false; + this.isremoved = true; } /** @@ -84,9 +80,8 @@ * * @param name task name */ - public TimerTask(long number, String name) { + public TimerTask( String name) { this(); - this.number = number; this.name = name; this.taskId = UUID.randomUUID().toString(); this.parent = ""; @@ -99,9 +94,8 @@ * * @param name task name */ - public TimerTask(long number, String name, long datetime) { + public TimerTask( String name, long datetime) { this(); - this.number = number; this.name = name; this.taskId = UUID.randomUUID().toString(); this.parent = ""; @@ -110,26 +104,7 @@ } - /** - * Get task number. - * - * @return the number - */ - public long getNumber() { - return number; - } - - /** - * Set task number. - * - * @param number the number to set - */ - public void setNumber(long number) { - this.number = number; - } - - /** * Set task uuid * * @param taskuuid task uuid Added: branches/ng-jtimer/src/main/java/org/chorem/jtimer/entities/TodoList.java =================================================================== --- branches/ng-jtimer/src/main/java/org/chorem/jtimer/entities/TodoList.java (rev 0) +++ branches/ng-jtimer/src/main/java/org/chorem/jtimer/entities/TodoList.java 2014-06-03 16:27:59 UTC (rev 2993) @@ -0,0 +1,159 @@ +package org.chorem.jtimer.entities; + +import java.util.LinkedList; +import java.util.Queue; + +/** + * Created by olivia on 03/06/14. + * + * Classe qui represente la liste des choses à faire par le serveur + * + */ +public class TodoList { + + /** {Arraylist of tasks} stockage des taches crees avant synchro */ + protected Queue<String> createdTasks; + + /** {Arraylist of tasks} stockage des taches mise à jour avant synchro */ + protected Queue<String> updatedTasks; + + /** {Arraylist of long} stockage des identifiants taches supprimées avant synchro */ + protected Queue<String> deletedTasks; + + /** {Arraylist of times} stockage des temps crees avant synchro */ + protected Queue<String> createdTimes; + + /** {Arraylist of times} stockage des temps mis à jour avant synchro */ + protected Queue<String> updatedTimes; + + /** {Arraylist of long} stockage des identifiants temps supprimees avant synchro */ + protected Queue<String> deletedTimes; + + /** + * Default Constructor + */ + private TodoList(){ + + createdTasks = new LinkedList<>(); + updatedTasks = new LinkedList<>(); + deletedTasks = new LinkedList<>(); + createdTimes = new LinkedList<>(); + updatedTimes = new LinkedList<>(); + deletedTimes = new LinkedList<>(); + + } + + /** Holder */ + private static class SingletonHolder + { + /** Instance unique non préinitialisée */ + private final static TodoList instance = new TodoList(); + } + + /** Point d'accès pour l'instance unique du singleton */ + public static TodoList getInstance() + { + return SingletonHolder.instance; + } + + + /** Methode ajout/suppression fifo **/ + + public void pushCreatedTask(String task) { + createdTasks.add(task); + } + + public void pushUpdatedTask(String task) { + updatedTasks.add(task); + } + + public void pushDeletedTask(String taskId) { + deletedTasks.add(taskId); + } + + public void pushCreatedTime(String time) { + createdTimes.add(time); + } + + public void pushUpdatedTime(String time) { + updatedTimes.add(time); + } + + public void pushDeletedTime(String timeId) { + deletedTimes.add(timeId); + } + + public void removeCreatedTask() { + createdTasks.poll(); + } + + public void removeUpdatedTask() { + updatedTasks.poll(); + } + + public void removeDeletedTask() { + deletedTasks.poll(); + } + + public void removeCreatedTime() { + createdTimes.poll(); + } + + public void removeUpdatedTime() { + updatedTimes.poll(); + } + + public void removeDeletedTime() { + deletedTimes.poll(); + } + + /** Getter Setter **/ + + public Queue<String> getCreatedTasks() { + return createdTasks; + } + + public void setCreatedTasks(Queue<String> createdTasks) { + this.createdTasks = createdTasks; + } + + public Queue<String> getUpdatedTasks() { + return updatedTasks; + } + + public void setUpdatedTasks(Queue<String> updatedTasks) { + this.updatedTasks = updatedTasks; + } + + public Queue<String> getDeletedTasks() { + return deletedTasks; + } + + public void setDeletedTasks(Queue<String> deletedTasks) { + this.deletedTasks = deletedTasks; + } + + public Queue<String> getCreatedTimes() { + return createdTimes; + } + + public void setCreatedTimes(Queue<String> createdTimes) { + this.createdTimes = createdTimes; + } + + public Queue<String> getUpdatedTimes() { + return updatedTimes; + } + + public void setUpdatedTimes(Queue<String> updatedTimes) { + this.updatedTimes = updatedTimes; + } + + public Queue<String> getDeletedTimes() { + return deletedTimes; + } + + public void setDeletedTimes(Queue<String> deletedTimes) { + this.deletedTimes = deletedTimes; + } +} Modified: branches/ng-jtimer/src/main/java/org/chorem/jtimer/storage/Storage.java =================================================================== --- branches/ng-jtimer/src/main/java/org/chorem/jtimer/storage/Storage.java 2014-05-28 09:38:19 UTC (rev 2992) +++ branches/ng-jtimer/src/main/java/org/chorem/jtimer/storage/Storage.java 2014-06-03 16:27:59 UTC (rev 2993) @@ -66,7 +66,7 @@ protected Connection getConnection() throws SQLException { //TODO obruce 15-05-14 path a definir - String url = "/tmp/jtimer/jtimer"; + String url = "/tmp/jtimer/jtimer8081"; //String url = "/home/olivia/Bureau/jtimer/jtimer"; if (log.isInfoEnabled()) { @@ -146,25 +146,24 @@ statement.executeUpdate("CREATE TABLE " + TABLE_VERSION + "(version VARCHAR(10))"); statement.executeUpdate("CREATE TABLE " + TABLE_TASK + - "(id LONG NOT NULL AUTO_INCREMENT," + - " taskId VARCHAR(255) NOT NULL UNIQUE," + + "(taskId VARCHAR(255) NOT NULL," + " name VARCHAR(255) NOT NULL," + " parent VARCHAR(255)," + " modificationDate LONG, " + " hidden BOOLEAN," + " note TEXT," + "removed BOOLEAN," + - " PRIMARY KEY (id, taskId))"); + " PRIMARY KEY (taskId))"); statement.executeUpdate("CREATE TABLE " + TABLE_TIME + - "(taskid LONG NOT NULL," + + "(taskid VARCHAR(255) NOT NULL," + " date LONG," + " uuid varchar(255) unique," + " duration LONG," + " modificationDate LONG," + - "removed BOOLEAN," + + " removed BOOLEAN," + " PRIMARY KEY (taskid, date, uuid)," + " FOREIGN KEY (taskid)" + - " REFERENCES " + TABLE_TASK +"(id)" + + " REFERENCES " + TABLE_TASK +"(taskId)" + " ON DELETE CASCADE" + ")"); } catch (SQLException ex) { @@ -211,13 +210,12 @@ try { statement = connection.prepareStatement("SELECT TA.*, sum(TI.duration) AS totalduration FROM " + TABLE_TASK + " TA, " + TABLE_TIME + " TI" + - " WHERE TA.id = TI.taskid" + + " WHERE TA.taskId = TI.taskid" + " AND TA.modificationDate >" +date + - " GROUP BY TA.id"); + " GROUP BY TA.taskId"); ResultSet rs = statement.executeQuery(); while (rs.next()) { TimerTask task = new TimerTask(); - task.setNumber(rs.getInt("id")); task.setTaskId(rs.getString("taskId")); task.setName(rs.getString("name")); task.setParent(rs.getString("parent")); @@ -230,12 +228,11 @@ // not timed tasks statement2 = connection.prepareStatement("SELECT * FROM " + TABLE_TASK + - " WHERE (id not in (SELECT taskid FROM " + TABLE_TIME + "))" + + " WHERE (taskId not in (SELECT taskid FROM " + TABLE_TIME + "))" + " AND "+ TABLE_TASK +".modificationDate >" +date); rs = statement2.executeQuery(); while (rs.next()) { TimerTask task = new TimerTask(); - task.setNumber(rs.getInt("id")); task.setName(rs.getString("name")); task.setTaskId(rs.getString("taskId")); task.setParent(rs.getString("parent")); @@ -262,7 +259,7 @@ try { statement = connection.prepareStatement("INSERT INTO " + TABLE_TASK + "(name, parent, taskId, hidden, note, modificationDate, removed)" + - " VALUES (?, ?, ?, ?, ?, ?, ?)", Statement.RETURN_GENERATED_KEYS); + " VALUES (?, ?, ?, ?, ?, ?, ?)"); statement.setString(1, task.getName()); statement.setString(2, task.getParent()); statement.setString(3, task.getTaskId()); @@ -272,11 +269,6 @@ statement.setBoolean(7,task.getRemoved()); statement.executeUpdate(); - // get generated id - ResultSet rs = statement.getGeneratedKeys(); - if (rs.next()) { - task.setNumber(rs.getInt(1)); - } } catch (SQLException ex) { throw new StorageException("Can't add project", ex); } finally { @@ -364,7 +356,7 @@ "(taskid, date, uuid, duration, modificationDate, removed)" + " VALUES(?, ?, ?, ?, ?, ?)"); - statement.setLong(1, task.getNumber()); + statement.setString(1, task.getTaskId()); statement.setLong(2, date.getTime()); statement.setString(3, uuid); statement.setLong(4, duration); @@ -381,16 +373,15 @@ /** * Ajoute une periode pour une tache * @param time le timertime a ajouter - * @param number le numero identidfiant la tache dans la base */ - public void addTaskTime(TimerTime time, long number) { + public void addTaskTime(TimerTime time) { PreparedStatement statement = null; try { statement = connection.prepareStatement("INSERT INTO " + TABLE_TIME + "(taskid, date, uuid, duration, modificationDate, removed)" + " VALUES(?, ?, ?, ?, ?, ?)"); - statement.setLong(1, number); + statement.setString(1, time.getTaskId()); statement.setLong(2, time.getCreationDate().getTime()); statement.setString(3, time.getTimeId()); statement.setLong(4, time.getTime()); @@ -424,7 +415,7 @@ try { statement = connection.prepareStatement("SELECT TA.taskId AS mytask, TI.* FROM " + TABLE_TASK + " TA, "+ TABLE_TIME + " TI" + - " WHERE TA.id = TI.taskid" + + " WHERE TA.taskId = TI.taskid" + " AND TI.modificationDate >" +date); ResultSet rs = statement.executeQuery(); @@ -461,9 +452,9 @@ List<TimerTime> times = new ArrayList<>(); PreparedStatement statement = null; try { - statement = connection.prepareStatement("SELECT TI.* FROM " + - TABLE_TASK + " TA, "+ TABLE_TIME + " TI" + - " WHERE TA.id = TI.taskid AND TA.taskId = '" +taskid +"' " + + statement = connection.prepareStatement("SELECT TI.*" + + " FROM " + TABLE_TASK + " TA, "+ TABLE_TIME + " TI" + + " WHERE TA.taskId = TI.taskid AND TA.taskId = '" +taskid +"' " + " AND TA.removed = 0" + " AND TI.modificationDate >" +date); ResultSet rs = statement.executeQuery(); Modified: branches/ng-jtimer/src/main/java/org/chorem/jtimer/web/RestApplication.java =================================================================== --- branches/ng-jtimer/src/main/java/org/chorem/jtimer/web/RestApplication.java 2014-05-28 09:38:19 UTC (rev 2992) +++ branches/ng-jtimer/src/main/java/org/chorem/jtimer/web/RestApplication.java 2014-06-03 16:27:59 UTC (rev 2993) @@ -1,18 +1,53 @@ package org.chorem.jtimer.web; import java.util.Date; +import java.util.Timer; import java.util.UUID; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.chorem.jtimer.entities.TimerTask; +import org.chorem.jtimer.entities.TodoList; import org.chorem.jtimer.storage.Storage; import org.restlet.Application; import org.restlet.Context; import org.restlet.Restlet; import org.restlet.routing.Router; + public class RestApplication extends Application { + protected Timer timer = new Timer(); + protected TiersServerResource tiers = new TiersServerResource(); + protected static final Log log = LogFactory.getLog(RestApplication.class); + protected boolean connected = true; + protected TodoList todoList; + + + + protected class TodoTask extends java.util.TimerTask{ + @Override + public void run() { + log.info("/home/olivia/Workspace/CL/ng-jtimer/src/main/java/org/chorem/jtimer/web/RestApplication.java : passage dans le run"); + + if(connected){ + + if(todoList.getCreatedTasks() != null){ + //Les taches crees + for (String task : todoList.getCreatedTasks()){ + + if(tiers.postTask(task)){ + todoList.removeCreatedTask(); + } + + } + } + + } + } + }; + /** * Creates a root Restlet that will receive all incoming calls. */ @@ -27,21 +62,22 @@ // Defines only one route router.attach("/tasks/task", TasksResource.class); router.attach("/tasks/task/{taskId}", TaskResource.class); - //router.attach("/tasks/{taskId}/time", TimeResource.class); router.attach("/tasks/time/{taskId}", TimeResource.class); router.attach("/tasks/time", TimesResource.class); + router.attach("/tiers", TiersServerResource.class); return router; } protected void initContext(Context context) { + //Initialisation du storage Storage storage = new Storage(); if (storage.getTasksCount() == 0) { - TimerTask jTimerProject = new TimerTask(1, "jTimer"); - TimerTask jTimerTask1 = new TimerTask(2, "WebService"); - TimerTask jTimerTask2 = new TimerTask(8, "WebService2"); + TimerTask jTimerProject = new TimerTask( "jTimer"); + TimerTask jTimerTask1 = new TimerTask( "WebService"); + TimerTask jTimerTask2 = new TimerTask( "WebService2"); jTimerTask1.setParent(jTimerProject.getTaskId()); jTimerTask2.setParent(jTimerProject.getTaskId()); storage.addTask(jTimerProject); @@ -52,14 +88,20 @@ storage.addTaskTime(jTimerTask1, new Date(), UUID.randomUUID().toString(), 1000000); storage.addTaskTime(jTimerTask2, new Date(), UUID.randomUUID().toString(), 45); - storage.addTask(new TimerTask(3, "Chorem")); - storage.addTask(new TimerTask(4, "Wikitty")); - storage.addTask(new TimerTask(5, "Nuiton-js")); - storage.addTask(new TimerTask(6, "Angular")); - storage.addTask(new TimerTask(7, "Isis-Fish")); + storage.addTask(new TimerTask( "Chorem")); + storage.addTask(new TimerTask( "Wikitty")); + storage.addTask(new TimerTask( "Nuiton-js")); + storage.addTask(new TimerTask( "Angular")); + storage.addTask(new TimerTask( "Isis-Fish")); } context.getAttributes().put(Storage.class.getName(), storage); + + + //Initialisation du timer + timer.schedule(new TodoTask(), new Date(), (long) 30000); + + todoList = TodoList.getInstance(); } Modified: branches/ng-jtimer/src/main/java/org/chorem/jtimer/web/TasksResource.java =================================================================== --- branches/ng-jtimer/src/main/java/org/chorem/jtimer/web/TasksResource.java 2014-05-28 09:38:19 UTC (rev 2992) +++ branches/ng-jtimer/src/main/java/org/chorem/jtimer/web/TasksResource.java 2014-06-03 16:27:59 UTC (rev 2993) @@ -10,10 +10,16 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.chorem.jtimer.entities.TimerTask; +import org.chorem.jtimer.entities.TodoList; import org.chorem.jtimer.storage.Storage; +import org.restlet.Client; +import org.restlet.Context; import org.restlet.data.MediaType; +import org.restlet.data.Protocol; import org.restlet.representation.Representation; import org.restlet.representation.StringRepresentation; +import org.restlet.representation.Variant; +import org.restlet.resource.ClientResource; import org.restlet.resource.Get; import org.restlet.resource.Options; import org.restlet.resource.Post; @@ -36,7 +42,8 @@ private static final Log log = LogFactory.getLog(TasksResource.class); protected Storage storage; - private GsonBuilder builder; + protected GsonBuilder builder; + protected TodoList todoList; /** * Methode qui initialis la resource @@ -47,10 +54,7 @@ protected void doInit() throws ResourceException { storage = (Storage) getContext().getAttributes().get(Storage.class.getName()); - builder = new GsonBuilder(); // Register an adapter to manage the date types as long values - //GSON builder to format dates - builder = new GsonBuilder(); builder.registerTypeAdapter(Date.class, new JsonDeserializer<Date>() { @@ -66,6 +70,10 @@ return new JsonPrimitive(date.getTime()); } }); + + //On recupere la todoList courante + todoList = TodoList.getInstance(); + } /** @@ -76,6 +84,7 @@ */ @Get("json") public Representation getTasks() { + Long date = (long) 0; try { @@ -114,16 +123,19 @@ public void createTask(Representation representation) throws IOException { Gson gson = builder.create(); - String repr1 = representation.getText(); - if (log.isInfoEnabled()) { - log.info("La task suivante est cree : " + repr1); + String repr1 =""; + + if(representation.isAvailable()) { + + repr1 = representation.getText(); + TimerTask t = gson.fromJson(repr1, TimerTask.class); + + t.setRemoved(false); + + storage.addTask(t); + + todoList.pushCreatedTask(repr1); } - TimerTask t = gson.fromJson(repr1, TimerTask.class); - if (log.isInfoEnabled()) { - log.info("La task suivante est cree : " + t.toString()); - } - t.setRemoved(false); - storage.addTask(t); } /** @@ -133,15 +145,21 @@ @Put("json") public void updateTask(Representation representation) throws IOException { - Gson gson = builder.create(); - String repr1 = representation.getText(); - TimerTask t = gson.fromJson(repr1, TimerTask.class); + if(representation.isAvailable()) { - if (log.isInfoEnabled()) { - log.info("La task suivante est en cours de maj : " + t.toString()); + Gson gson = builder.create(); + String repr1 = representation.getText(); + TimerTask t = gson.fromJson(repr1, TimerTask.class); + + if (log.isInfoEnabled()) { + log.info("La task suivante est en cours de maj : " + t.toString()); + } + + storage.modifyTask(t); + } + toRepresentation("{}", new Variant(MediaType.APPLICATION_JSON)); - storage.modifyTask(t); } Added: branches/ng-jtimer/src/main/java/org/chorem/jtimer/web/TiersServerResource.java =================================================================== --- branches/ng-jtimer/src/main/java/org/chorem/jtimer/web/TiersServerResource.java (rev 0) +++ branches/ng-jtimer/src/main/java/org/chorem/jtimer/web/TiersServerResource.java 2014-06-03 16:27:59 UTC (rev 2993) @@ -0,0 +1,108 @@ +package org.chorem.jtimer.web; + +import com.google.gson.GsonBuilder; +import com.google.gson.JsonDeserializationContext; +import com.google.gson.JsonDeserializer; +import com.google.gson.JsonElement; +import com.google.gson.JsonParseException; +import com.google.gson.JsonPrimitive; +import com.google.gson.JsonSerializationContext; +import com.google.gson.JsonSerializer; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.chorem.jtimer.entities.TimerTask; +import org.chorem.jtimer.entities.TodoList; +import org.chorem.jtimer.storage.Storage; +import org.restlet.Client; +import org.restlet.Context; +import org.restlet.data.MediaType; +import org.restlet.data.Protocol; +import org.restlet.representation.Representation; +import org.restlet.representation.Variant; +import org.restlet.resource.ClientResource; +import org.restlet.resource.Post; +import org.restlet.resource.ResourceException; +import org.restlet.resource.ServerResource; + +import java.lang.reflect.Type; +import java.util.Date; + +/** + * Created by olivia on 03/06/14. + */ +public class TiersServerResource extends ServerResource { + + protected static final Log log = LogFactory.getLog(RestApplication.class); + + protected Storage storage; + protected GsonBuilder builder; + protected TodoList todoList; + + @Override + protected void doInit() throws ResourceException { + storage = (Storage) getContext().getAttributes().get(Storage.class.getName()); + + // Register an adapter to manage the date types as long values + builder = new GsonBuilder(); + builder.registerTypeAdapter(Date.class, new JsonDeserializer<Date>() { + + public Date deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { + return new Date(json.getAsJsonPrimitive().getAsLong()); + } + + }); + + builder.registerTypeAdapter(Date.class, new JsonSerializer<Date>() { + @Override + public JsonElement serialize(Date date, Type type, JsonSerializationContext jsonSerializationContext) { + return new JsonPrimitive(date.getTime()); + } + }); + + //On recupere la todoList courante + todoList = TodoList.getInstance(); + + } + + + /** + * Methode qui va pousser vers le serveur distant une tache + * @param t + */ + @Post("json") + public boolean postTask(String t){ + //Determine si la requete a ete un succes + boolean success = false; + + + Client client = new Client(new Context(), Protocol.HTTP); + //Le client a qui l'on s'adresse + ClientResource clientTaskResource = new ClientResource("http://localhost:8080/rest/tasks/task"); + clientTaskResource.setNext(client); + + try{ + log.info("La representation " + t); + Representation representation = toRepresentation(t, new Variant(MediaType.APPLICATION_JSON)); + log.info(representation.getText()); + + clientTaskResource.post(representation); + success = true; + }catch(Exception e){ + e.printStackTrace(); + success = false; + } + + return success; + } + + + public void putTask(){ + + + } + + public void deleteTask(){ + + + } +} Modified: branches/ng-jtimer/src/main/java/org/chorem/jtimer/web/TimeResource.java =================================================================== --- branches/ng-jtimer/src/main/java/org/chorem/jtimer/web/TimeResource.java 2014-05-28 09:38:19 UTC (rev 2992) +++ branches/ng-jtimer/src/main/java/org/chorem/jtimer/web/TimeResource.java 2014-06-03 16:27:59 UTC (rev 2993) @@ -111,19 +111,38 @@ @Post("json") public void createTime(Representation representation) throws IOException { - String timeId = (String)getRequest().getAttributes().get("taskId"); - long number = storage.getTaskNumber(timeId); + String taskId = (String)getRequest().getAttributes().get("taskId"); Gson gson = builder.create(); String repr1 = representation.getText(); - TimerTime t = gson.fromJson(repr1, TimerTime.class); + TimerTime newTime = gson.fromJson(repr1, TimerTime.class); + List<TimerTime> list = storage.getTimes(taskId, newTime.getCreationDate().getTime()); + + for(TimerTime oldTime : list){ + long oldStart= oldTime.getCreationDate().getTime(); + long oldEnd = oldStart + oldTime.getTime(); + long newStart =newTime.getCreationDate().getTime(); + long newEnd = newStart + newTime.getTime(); + + + if(oldEnd > newStart || newEnd > oldStart){ + //Les temps ne se chevauchent pas + + }else{ + //un temps chevauchent un autre + + } + + } + if (log.isInfoEnabled()) { - log.info("La periode suivante est cree : " + t.toString()); + log.info("La periode suivante est cree : " + newTime.toString()); } - storage.addTaskTime(t, number); + storage.addTaskTime(newTime); + } /** Modified: branches/ng-jtimer/src/main/webapp/js/controllers.js =================================================================== --- branches/ng-jtimer/src/main/webapp/js/controllers.js 2014-05-28 09:38:19 UTC (rev 2992) +++ branches/ng-jtimer/src/main/webapp/js/controllers.js 2014-06-03 16:27:59 UTC (rev 2993) @@ -289,10 +289,11 @@ if(!item.isremoved){ console.log("Temps existe donc remplacé"); //Le temps existe - var editedTime = getObjectInArrayWithId($scope.data.times[item.taskId],item.timeId); editedTime.time = item.time; editedTime.creationDate = item.creationDate; + //TODO obruce 2/6/14 verfication chevauchement temps + save(); } @@ -304,6 +305,8 @@ taskTime = new TaskTime($scope.data.tasks[item.taskId], item.timeId, item.creationDate, item.time); $scope.data.times[item.taskId].push(taskTime); + //TODO obruce 2/6/14 verfication chevauchement temps + save(); } @@ -316,17 +319,6 @@ } - //Recuperer un element dans un array avec son id - var getObjectInArrayWithId= function(array, id){ - var res; - angular.forEach(array, function(time){ - if(time.timeId == id){ - res = time; - } - }); - return res; - } - /** * Methode qui recupere les temps pour une tache */ @@ -336,13 +328,14 @@ angular.forEach(response, function (item) { - if(!$scope.data.times[task.taskId]){$scope.data.times[task.taskId] = []} + if(!$scope.data.times[task.taskId]){$scope.data.times[task.taskId] = []} if(!(existInObject($scope.data.times,item.timeId,task.taskId)) && !(existInObject($scope.todo.stockedDeletedTimes, item.timeId, task.taskId)) && !item.isremoved){ //On cree le tasktime taskTime = new TaskTime(task, item.timeId, item.creationDate, item.time); $scope.data.times[task.taskId].push(taskTime); save(); + //TODO obruce 2/6/14 verfication chevauchement temps } }); //On change la date de dernier acces @@ -352,6 +345,18 @@ }); } + + //Recuperer un element dans un array avec son id + var getObjectInArrayWithId= function(array, id){ + var res; + angular.forEach(array, function(time){ + if(time.timeId == id){ + res = time; + } + }); + return res; + } + /** * Methode qui retourne l'existence d'un element dans un array */
participants (1)
-
obruce@users.chorem.org