Jtimer-commits
Threads by month
- ----- 2026 -----
- June
- May
- April
- March
- February
- January
- ----- 2025 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
- November
- October
- September
- August
June 2014
- 1 participants
- 16 discussions
r2998 - in branches/ng-jtimer: . src/main/java/org/chorem/jtimer src/main/java/org/chorem/jtimer/config src/main/java/org/chorem/jtimer/storage src/main/java/org/chorem/jtimer/web src/main/resources
by obruce@users.chorem.org 11 Jun '14
by obruce@users.chorem.org 11 Jun '14
11 Jun '14
Author: obruce
Date: 2014-06-11 16:23:29 +0200 (Wed, 11 Jun 2014)
New Revision: 2998
Url: http://forge.chorem.org/projects/jtimer/repository/revisions/2998
Log:
Ajout de nuiton config
Added:
branches/ng-jtimer/src/main/java/org/chorem/jtimer/config/
branches/ng-jtimer/src/main/java/org/chorem/jtimer/config/JtimerConfig.java
branches/ng-jtimer/src/main/java/org/chorem/jtimer/config/JtimerConfigOption.java
branches/ng-jtimer/src/main/resources/jtimer-default.properties
Modified:
branches/ng-jtimer/pom.xml
branches/ng-jtimer/src/main/java/org/chorem/jtimer/storage/Storage.java
branches/ng-jtimer/src/main/java/org/chorem/jtimer/web/RestApplication.java
Modified: branches/ng-jtimer/pom.xml
===================================================================
--- branches/ng-jtimer/pom.xml 2014-06-06 16:12:32 UTC (rev 2997)
+++ branches/ng-jtimer/pom.xml 2014-06-11 14:23:29 UTC (rev 2998)
@@ -59,6 +59,7 @@
<artifactId>nuiton-js-angular-ui-bootstrap</artifactId>
<version>0.11.0-2</version>
</dependency>
+
<dependency>
<groupId>org.nuiton.js</groupId>
<artifactId>nuiton-js-jquery</artifactId>
@@ -198,6 +199,11 @@
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.nuiton</groupId>
+ <artifactId>nuiton-config</artifactId>
+ <version>3.0-alpha-2</version>
+ </dependency>
</dependencies>
<repositories>
Added: branches/ng-jtimer/src/main/java/org/chorem/jtimer/config/JtimerConfig.java
===================================================================
--- branches/ng-jtimer/src/main/java/org/chorem/jtimer/config/JtimerConfig.java (rev 0)
+++ branches/ng-jtimer/src/main/java/org/chorem/jtimer/config/JtimerConfig.java 2014-06-11 14:23:29 UTC (rev 2998)
@@ -0,0 +1,77 @@
+package org.chorem.jtimer.config;
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.nuiton.config.ApplicationConfig;
+
+import java.util.Properties;
+
+/**
+ * Created by olivia on 11/06/14.
+ * <p/>
+ * Project name : jtimer
+ * <p/>
+ * Package name : org.chorem.jtimer.config
+ */
+public class JtimerConfig{
+
+ static private Log log = LogFactory.getLog(JtimerConfig.class);
+
+ /** Fichier de configuration par defaut */
+ protected static final String JTIMER_DEFAULT_CONF_FILENAME = "jtimer-default.properties";
+
+ /** Application configuration */
+ protected ApplicationConfig appConfig;
+
+ /**
+ * Constructeur par defaut
+ */
+ public JtimerConfig() throws Exception {
+
+ try{
+ //On essaye de retrouver le fichier de conf par defaut et de le parser
+ appConfig = new ApplicationConfig(JTIMER_DEFAULT_CONF_FILENAME);
+ appConfig.loadDefaultOptions(JtimerConfigOption.values());
+ appConfig.parse();
+
+ }catch(Exception e){
+ throw new Exception("Can't read property file");
+ }
+
+ }
+
+
+
+ public JtimerConfig(String configFileName) throws Exception {
+
+ try {
+ //On essaye de retrouver le fichier de conf par defaut et de le parser
+ ApplicationConfig defaultConfig = new ApplicationConfig(JTIMER_DEFAULT_CONF_FILENAME);
+ defaultConfig.loadDefaultOptions(JtimerConfigOption.values());
+ defaultConfig.parse();
+
+ if (StringUtils.isNotBlank(configFileName)) {
+ Properties flatOptions = defaultConfig.getFlatOptions(false);
+ appConfig = new ApplicationConfig(flatOptions, configFileName);
+ appConfig.parse();
+ } else {
+ if (log.isWarnEnabled()) {
+ log.warn("No specific configuration provided, using the default one");
+ }
+ appConfig = defaultConfig;
+ }
+ } catch (Exception e) {
+ throw new Exception("Can't read property file");
+ }
+ }
+
+
+ /**
+ * Methode qui retourne le path ou implanter le storage
+ * @return le path du storage
+ */
+ public String getStoragePath(){
+ return appConfig.getOption(JtimerConfigOption.JTIMER_STORAGE_PATH.getKey());
+ }
+}
Added: branches/ng-jtimer/src/main/java/org/chorem/jtimer/config/JtimerConfigOption.java
===================================================================
--- branches/ng-jtimer/src/main/java/org/chorem/jtimer/config/JtimerConfigOption.java (rev 0)
+++ branches/ng-jtimer/src/main/java/org/chorem/jtimer/config/JtimerConfigOption.java 2014-06-11 14:23:29 UTC (rev 2998)
@@ -0,0 +1,83 @@
+package org.chorem.jtimer.config;
+
+import org.nuiton.config.ConfigOptionDef;
+
+/**
+ * Created by olivia on 11/06/14.
+ * <p/>
+ * Project name : jtimer
+ * <p/>
+ * Package name : org.chorem.jtimer.config
+ */
+public enum JtimerConfigOption implements ConfigOptionDef {
+ JTIMER_STORAGE_PATH(
+ "jtimer.storage.path",
+ "chemin qui indique où se trouve le stockage",
+ "/tmp/jtimer8080",
+ String.class),
+ JTIMER_STORAGE_CREDENTIALS(
+ "jtimer.storage.credentials",
+ "indique les éléments dont on a besoin pour s'authentifier à la base",
+ "",
+ String.class);
+
+ public final String key;
+ public final String description;
+ public String defaultValue;
+ public final Class<?> type;
+
+
+ JtimerConfigOption(String key, String description, String defaultValue,
+ Class<?> type) {
+ this.key = key;
+ this.description = description;
+ this.defaultValue = defaultValue;
+ this.type = type;
+
+ }
+
+ @Override
+ public String getKey() {
+ return key;
+ }
+
+ @Override
+ public Class<?> getType() {
+ return type;
+ }
+
+ @Override
+ public String getDescription() {
+ return description;
+ }
+
+ @Override
+ public String getDefaultValue() {
+ return defaultValue;
+ }
+
+ @Override
+ public boolean isTransient() {
+ return false;
+ }
+
+ @Override
+ public boolean isFinal() {
+ return false;
+ }
+
+ @Override
+ public void setDefaultValue(String defaultValue) {
+ this.defaultValue = defaultValue;
+ }
+
+ @Override
+ public void setTransient(boolean isTransient) {
+
+ }
+
+ @Override
+ public void setFinal(boolean isFinal) {
+
+ }
+}
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-06-06 16:12:32 UTC (rev 2997)
+++ branches/ng-jtimer/src/main/java/org/chorem/jtimer/storage/Storage.java 2014-06-11 14:23:29 UTC (rev 2998)
@@ -35,10 +35,14 @@
protected static final String TABLE_TIME = "tasktime";
protected static final String TABLE_VERSION = "version";
+ protected static String STORAGE_PATH;
+
protected Connection connection;
- public Storage() {
+ public Storage(String path) {
+ this.STORAGE_PATH = path;
+
try {
if (log.isDebugEnabled()) {
log.debug("Registering jdbc driver");
@@ -65,14 +69,11 @@
}
protected Connection getConnection() throws SQLException {
- //TODO obruce 15-05-14 path a definir
- String url = "/tmp/jtimer/jtimer8080";
- //String url = "/home/olivia/Bureau/jtimer/jtimer";
if (log.isInfoEnabled()) {
- log.info("Opening connection to database : " + url);
+ log.info("Opening connection to database : " + STORAGE_PATH);
}
- Connection conn = DriverManager.getConnection("jdbc:h2:" + url, "sa",
+ Connection conn = DriverManager.getConnection("jdbc:h2:" + STORAGE_PATH, "sa",
"");
conn.setAutoCommit(true);
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-06-06 16:12:32 UTC (rev 2997)
+++ branches/ng-jtimer/src/main/java/org/chorem/jtimer/web/RestApplication.java 2014-06-11 14:23:29 UTC (rev 2998)
@@ -3,6 +3,7 @@
import org.apache.commons.lang3.tuple.Pair;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.chorem.jtimer.config.JtimerConfig;
import org.chorem.jtimer.entities.TodoList;
import org.chorem.jtimer.storage.Storage;
import org.restlet.Application;
@@ -25,8 +26,11 @@
protected static final Log log = LogFactory.getLog(RestApplication.class);
/** Determine si la connexion est établie */ //TODO obruce 05/06/2014 to change when configuration available
- protected boolean connected = true;
+ protected boolean connected = false;
+ /**Application configuration */
+ JtimerConfig jtimerConf;
+
/** Todolist instance */
protected TodoList todoList;
@@ -39,7 +43,11 @@
// Create a router Restlet that routes each call to a
// new instance of ProjectsResource.
Context context = getContext();
- initContext(context);
+ try {
+ initContext(context);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
Router router = new Router(context);
// Defines only one route
@@ -56,13 +64,13 @@
* Initialise le context de l'application REST
* @param context
*/
- protected void initContext(Context context) {
- //Initialisation du storage
- Storage storage = new Storage();
+ protected void initContext(Context context) throws Exception {
- if (storage.getTasksCount() == 0) {
+ // Application Configuration
+ jtimerConf = new JtimerConfig();
- }
+ //Initialisation du storage
+ Storage storage = new Storage(jtimerConf.getStoragePath());
context.getAttributes().put(Storage.class.getName(), storage);
Added: branches/ng-jtimer/src/main/resources/jtimer-default.properties
===================================================================
--- branches/ng-jtimer/src/main/resources/jtimer-default.properties (rev 0)
+++ branches/ng-jtimer/src/main/resources/jtimer-default.properties 2014-06-11 14:23:29 UTC (rev 2998)
@@ -0,0 +1,6 @@
+###
+# jTimer default properties
+###
+# jTimer storage path
+jtimer.storage.path=/home/olivia/Bureau/jtimer/jtimer/jtimer
+
1
0
r2997 - in branches/ng-jtimer: . src/main/java/org/chorem/jtimer/storage src/main/webapp/js src/main/webapp/partials
by obruce@users.chorem.org 06 Jun '14
by obruce@users.chorem.org 06 Jun '14
06 Jun '14
Author: obruce
Date: 2014-06-06 18:12:32 +0200 (Fri, 06 Jun 2014)
New Revision: 2997
Url: http://forge.chorem.org/projects/jtimer/repository/revisions/2997
Log:
Ajout popup pour les rapports
Added:
branches/ng-jtimer/src/main/webapp/partials/reportModal.html
Modified:
branches/ng-jtimer/pom.xml
branches/ng-jtimer/src/main/java/org/chorem/jtimer/storage/Storage.java
branches/ng-jtimer/src/main/webapp/js/controllers.js
branches/ng-jtimer/src/main/webapp/partials/tasks.html
Modified: branches/ng-jtimer/pom.xml
===================================================================
--- branches/ng-jtimer/pom.xml 2014-06-06 09:15:16 UTC (rev 2996)
+++ branches/ng-jtimer/pom.xml 2014-06-06 16:12:32 UTC (rev 2997)
@@ -115,7 +115,7 @@
<version>${jettyVersion}</version>
<configuration>
<httpConnector>
- <port>8081</port>
+ <port>8080</port>
</httpConnector>
</configuration>
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-06-06 09:15:16 UTC (rev 2996)
+++ branches/ng-jtimer/src/main/java/org/chorem/jtimer/storage/Storage.java 2014-06-06 16:12:32 UTC (rev 2997)
@@ -66,7 +66,7 @@
protected Connection getConnection() throws SQLException {
//TODO obruce 15-05-14 path a definir
- String url = "/tmp/jtimer/jtimer8081";
+ String url = "/tmp/jtimer/jtimer8080";
//String url = "/home/olivia/Bureau/jtimer/jtimer";
if (log.isInfoEnabled()) {
Modified: branches/ng-jtimer/src/main/webapp/js/controllers.js
===================================================================
--- branches/ng-jtimer/src/main/webapp/js/controllers.js 2014-06-06 09:15:16 UTC (rev 2996)
+++ branches/ng-jtimer/src/main/webapp/js/controllers.js 2014-06-06 16:12:32 UTC (rev 2997)
@@ -890,6 +890,26 @@
}
+ $scope.reportPopup = function (){
+
+ var modalInstance = $modal.open({
+ templateUrl: 'partials/reportModal.html',
+ controller: ReportModalInstanceCtrl,
+ resolve: {
+ times : function () {
+ return angular.copy($scope.data.times);
+ },
+ tasks : function () {
+ return angular.copy($scope.data.tasks);
+ }
+ }
+
+ });
+
+ modalInstance.result.then(function (item) {
+ });
+ }
+
/**
*Méthode qui lance les actions à faires sur le serveur
*/
@@ -930,7 +950,60 @@
};
}
+function ReportModalInstanceCtrl($scope, $modalInstance, times, tasks){
+ $scope.obj={
+ startDate : new Date(),
+ endDate : new Date(),
+ report:[]
+ };
+
+ $scope.radioModel = '5';
+
+ $scope.generateReport= function(){
+ report = [];
+
+ angular.forEach(times, function(timeArray,task){
+
+ var res={};
+ res.time = -1;
+ angular.forEach(timeArray, function(time){
+
+ if(time.creationDate >= $scope.obj.startDate.getTime() && time.creationDate <= $scope.obj.endDate.getTime()){
+ res.time = res.time + time.time;
+ res.task = tasks[task].name;
+ }
+ });
+ if(res.time != -1 ){
+ $scope.obj.report.push(res);
+ }
+ });
+
+
+ }
+
+
+ $scope.changeFonc= function(){
+ }
+
+ $scope.close = function() {
+ $modalInstance.close();
+ };
+
+}
+
+function ReportDatePickerCtrl($scope){
+
+ $scope.format ='dd/MM/yyyy';
+
+ $scope.open = function($event) {
+ $event.preventDefault();
+ $event.stopPropagation();
+
+ $scope.opened = true;
+ };
+}
+
function ModalInstanceCtrl($scope, $modalInstance, taskTimes,indent) {
// Les temps de la tache
Added: branches/ng-jtimer/src/main/webapp/partials/reportModal.html
===================================================================
--- branches/ng-jtimer/src/main/webapp/partials/reportModal.html (rev 0)
+++ branches/ng-jtimer/src/main/webapp/partials/reportModal.html 2014-06-06 16:12:32 UTC (rev 2997)
@@ -0,0 +1,61 @@
+Option du rapport:
+
+<div>
+
+ <br/>
+ De :
+ <div ng-controller="ReportDatePickerCtrl" class="row">
+ <div class="col-md-6">
+ <p class="input-group">
+ <input type="text" class="form-control" datepicker-popup="{{format}}" ng-model="obj.startDate" is-open="opened" min-date="minDate" max-date="obj.endDate" ng-required="true" close-text="Close" />
+ <span class="input-group-btn">
+ <button type="button" class="btn btn-default" ng-click="open($event)"><i class="glyphicon glyphicon-calendar"></i></button>
+ </span>
+ </p>
+ </div>
+ </div>
+ A :
+ <div class="row" ng-controller="ReportDatePickerCtrl">
+ <div class="col-md-6">
+ <p class="input-group">
+ <input type="text" class="form-control" datepicker-popup="{{format}}" ng-model="obj.endDate" is-open="opened" min-date="obj.startDate" max-date="maxDate" ng-required="true" close-text="Close" />
+ <span class="input-group-btn">
+ <button type="button" class="btn btn-default" ng-click="open($event)"><i class="glyphicon glyphicon-calendar"></i></button>
+ </span>
+ </p>
+ </div>
+ </div>
+
+ <p>
+
+ </p>
+
+ <div class="btn-group" ng-show="false">
+ <label class="btn btn-primary" ng-change="changeFonc()" ng-model="radioModel" btn-radio="'1'">Jour</label>
+ <label class="btn btn-primary" ng-change="changeFonc()" ng-model="radioModel" btn-radio="'2'">Semaine</label>
+ <label class="btn btn-primary" ng-change="changeFonc()" ng-model="radioModel" btn-radio="'3'">Mois</label>
+ <label class="btn btn-primary" ng-change="changeFonc()" ng-model="radioModel" btn-radio="'4'">Année</label>
+ <label class="btn btn-primary" ng-change="changeFonc()" ng-model="radioModel" btn-radio="'5'">Projet</label>
+ </div>
+
+ <p>
+
+ </p>
+
+ <alert type="info" >
+ Rapport :<br/>
+ =========
+ <div ng-repeat="elem in obj.report">
+ {{elem.task}} : {{elem.time | time}}
+ </div>
+
+ </alert>
+
+
+</div>
+
+
+<div class="modal-footer">
+ <button class="btn btn-primary" ng-click="generateReport()">Generer</button>
+ <button class="btn btn-primary" ng-click="close()">Fermer</button>
+</div>
\ No newline at end of file
Modified: branches/ng-jtimer/src/main/webapp/partials/tasks.html
===================================================================
--- branches/ng-jtimer/src/main/webapp/partials/tasks.html 2014-06-06 09:15:16 UTC (rev 2996)
+++ branches/ng-jtimer/src/main/webapp/partials/tasks.html 2014-06-06 16:12:32 UTC (rev 2997)
@@ -10,9 +10,9 @@
<!--Header partie droite -->
<span class="right">
- <a class="glyphicon glyphicon-plus-sign" ng-click="showMenu = !showMenu">
-
- </a>
+ <a class="glyphicon glyphicon-cog" ng-click="reportPopup()">Rapport </a>
+
+ <a class="glyphicon glyphicon-plus-sign" ng-click="showMenu = !showMenu"></a>
<ul class="dropdown-menu" ng-class="{'menu-show': showMenu}">
<li>Keep Tree opened <input type='checkbox' ng-model="forceExpanded"></li>
<li>Name <input type='checkbox' ng-model='showName'/></li>
1
0
r2996 - in branches/ng-jtimer/src/main: java/org/chorem/jtimer/entities java/org/chorem/jtimer/web webapp/js
by obruce@users.chorem.org 06 Jun '14
by obruce@users.chorem.org 06 Jun '14
06 Jun '14
Author: obruce
Date: 2014-06-06 11:15:16 +0200 (Fri, 06 Jun 2014)
New Revision: 2996
Url: http://forge.chorem.org/projects/jtimer/repository/revisions/2996
Log:
Changement Pair, correction controller upTask
Removed:
branches/ng-jtimer/src/main/java/org/chorem/jtimer/entities/Pair.java
Modified:
branches/ng-jtimer/src/main/java/org/chorem/jtimer/entities/TodoList.java
branches/ng-jtimer/src/main/java/org/chorem/jtimer/web/RestApplication.java
branches/ng-jtimer/src/main/java/org/chorem/jtimer/web/TiersServerResource.java
branches/ng-jtimer/src/main/java/org/chorem/jtimer/web/TimeResource.java
branches/ng-jtimer/src/main/webapp/js/controllers.js
Deleted: branches/ng-jtimer/src/main/java/org/chorem/jtimer/entities/Pair.java
===================================================================
--- branches/ng-jtimer/src/main/java/org/chorem/jtimer/entities/Pair.java 2014-06-05 16:19:13 UTC (rev 2995)
+++ branches/ng-jtimer/src/main/java/org/chorem/jtimer/entities/Pair.java 2014-06-06 09:15:16 UTC (rev 2996)
@@ -1,46 +0,0 @@
-package org.chorem.jtimer.entities;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-/**
- * Created by olivia on 05/06/14.
- * <p/>
- * Project name : jtimer
- * <p/>
- * Package name : org.chorem.jtimer.entities
- *
- * Cette classe represente un duo d'element type cle/valeur
- * @param <K> la cle
- * @param <V> la valeur
- */
-public class Pair<K,V>{
-
- protected static final Log log = LogFactory.getLog(Pair.class);
-
- private K key; //la clef de la pair
- private V value; //la valeur de la pair
-
- public Pair(K key, V value){
- this.key = key;
- this.value = value;
-
- log.info(this.key.toString() + this.value.toString());
- }
-
- public V getValue() {
- return value;
- }
-
- public void setValue(V value) {
- this.value = value;
- }
-
- public K getKey() {
- return key;
- }
-
- public void setKey(K key) {
- this.key = key;
- }
-}
Modified: branches/ng-jtimer/src/main/java/org/chorem/jtimer/entities/TodoList.java
===================================================================
--- branches/ng-jtimer/src/main/java/org/chorem/jtimer/entities/TodoList.java 2014-06-05 16:19:13 UTC (rev 2995)
+++ branches/ng-jtimer/src/main/java/org/chorem/jtimer/entities/TodoList.java 2014-06-06 09:15:16 UTC (rev 2996)
@@ -1,7 +1,9 @@
package org.chorem.jtimer.entities;
-import java.util.LinkedList;
+import org.apache.commons.lang3.tuple.Pair;
+
import java.util.Queue;
+import java.util.concurrent.LinkedTransferQueue;
/**
* Created by olivia on 03/06/14.
@@ -34,12 +36,12 @@
*/
private TodoList(){
- createdTasks = new LinkedList<>();
- updatedTasks = new LinkedList<>();
- deletedTasks = new LinkedList<>();
- createdTimes = new LinkedList<>();
- updatedTimes = new LinkedList<>();
- deletedTimes = new LinkedList<>();
+ createdTasks = new LinkedTransferQueue<>();
+ updatedTasks = new LinkedTransferQueue<>();
+ deletedTasks = new LinkedTransferQueue<>();
+ createdTimes = new LinkedTransferQueue<>();
+ updatedTimes = new LinkedTransferQueue<>();
+ deletedTimes = new LinkedTransferQueue<>();
}
@@ -71,7 +73,7 @@
deletedTasks.add(taskId);
}
- public void pushCreatedTime(Pair<String,String> time) {
+ public void pushCreatedTime(Pair time) {
createdTimes.add(time);
}
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-06-05 16:19:13 UTC (rev 2995)
+++ branches/ng-jtimer/src/main/java/org/chorem/jtimer/web/RestApplication.java 2014-06-06 09:15:16 UTC (rev 2996)
@@ -1,8 +1,8 @@
package org.chorem.jtimer.web;
+import org.apache.commons.lang3.tuple.Pair;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.chorem.jtimer.entities.Pair;
import org.chorem.jtimer.entities.TodoList;
import org.chorem.jtimer.storage.Storage;
import org.restlet.Application;
@@ -25,7 +25,7 @@
protected static final Log log = LogFactory.getLog(RestApplication.class);
/** Determine si la connexion est établie */ //TODO obruce 05/06/2014 to change when configuration available
- protected boolean connected = false;
+ protected boolean connected = true;
/** Todolist instance */
protected TodoList todoList;
@@ -66,11 +66,12 @@
context.getAttributes().put(Storage.class.getName(), storage);
+ //initialisation de la todoList
+ todoList = TodoList.getInstance();
//Initialisation du timer
timer.schedule(new TodoTask(), new Date(), (long) 10000); //TODO obruce change timer time
- todoList = TodoList.getInstance();
}
/**
Modified: branches/ng-jtimer/src/main/java/org/chorem/jtimer/web/TiersServerResource.java
===================================================================
--- branches/ng-jtimer/src/main/java/org/chorem/jtimer/web/TiersServerResource.java 2014-06-05 16:19:13 UTC (rev 2995)
+++ branches/ng-jtimer/src/main/java/org/chorem/jtimer/web/TiersServerResource.java 2014-06-06 09:15:16 UTC (rev 2996)
@@ -1,5 +1,6 @@
package org.chorem.jtimer.web;
+import org.apache.commons.lang3.tuple.Pair;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.http.client.methods.CloseableHttpResponse;
@@ -10,7 +11,6 @@
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
-import org.chorem.jtimer.entities.Pair;
/**
* Created by olivia on 03/06/14.
@@ -134,14 +134,14 @@
}
- public boolean postTime(Pair<String, String> time) {
+ public boolean postTime(Pair time) {
boolean success = false;
CloseableHttpClient httpclient = HttpClients.createDefault();
HttpPost httpPost = new HttpPost(path+ "time/"+ time.getKey()+dispatch);
- StringEntity myEntity = new StringEntity(time.getValue(),ContentType.create("application/json", "UTF-8"));
+ StringEntity myEntity = new StringEntity((String) time.getValue(),ContentType.create("application/json", "UTF-8"));
//On ajoute l'entite
httpPost.setEntity(myEntity);
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-06-05 16:19:13 UTC (rev 2995)
+++ branches/ng-jtimer/src/main/java/org/chorem/jtimer/web/TimeResource.java 2014-06-06 09:15:16 UTC (rev 2996)
@@ -9,9 +9,9 @@
import com.google.gson.JsonPrimitive;
import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer;
+import org.apache.commons.lang3.tuple.Pair;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.chorem.jtimer.entities.Pair;
import org.chorem.jtimer.entities.TimerTime;
import org.chorem.jtimer.entities.TodoList;
import org.chorem.jtimer.storage.Storage;
@@ -144,7 +144,7 @@
if (dispatch) {
String taskId = (String) getRequest().getAttributes().get("taskId");
- Pair p = new Pair<String, String>(taskId, jsonRepr);
+ Pair p = Pair.of(taskId, jsonRepr);
log.info(" la pair cree" + p.toString()+ p.getKey().toString()+p.getValue().toString());
todoList.pushCreatedTime(p);
}
@@ -170,7 +170,7 @@
if (dispatch) {
String taskId = (String) getRequest().getAttributes().get("taskId");
- todoList.pushUpdatedTime(new Pair<String, String>(taskId, jsonRepr));
+ todoList.pushUpdatedTime(Pair.of(taskId, jsonRepr));
}
}
Modified: branches/ng-jtimer/src/main/webapp/js/controllers.js
===================================================================
--- branches/ng-jtimer/src/main/webapp/js/controllers.js 2014-06-05 16:19:13 UTC (rev 2995)
+++ branches/ng-jtimer/src/main/webapp/js/controllers.js 2014-06-06 09:15:16 UTC (rev 2996)
@@ -212,6 +212,7 @@
*/
var updateTasksFromServ = function(){
console.log("updateTasksFromServ debut");
+
serverTaskAccess.query({date : ($scope.taskAccess-delayAccess)}, function (response) {
angular.forEach(response, function (item) {
@@ -234,7 +235,7 @@
}else if(item.removed == 0){
- console.log("Nouvelle tache" +item);
+ console.log("Nouvelle tache" +item.name);
var newTask = new Task( item.name, item.taskId, item.parent);
@@ -249,12 +250,15 @@
}else{
//Un noeud avec un parent est ajoute à l'arbre de son parent
- $scope.data.tasks[newTask.taskId] = newTask;
- save();
//On ajoute le node à l'arbre
- if ($scope.tree) {
- $scope.tree.getNode(item.parent).addChild($scope.createTreeNode(newTask));
+ if ($scope.tree.getNode(item.parent)) {
+ $scope.data.tasks[newTask.taskId] = newTask;
+ save();
+ $scope.tree.getNode(item.parent).addChild($scope.createTreeNode(newTask));
+ }else{
+ $scope.data.tasks[newTask.taskId] = newTask;
+ save();
}
//Les temps sont recuperes du serveur
1
0
r2995 - in branches/ng-jtimer/src/main: java/org/chorem/jtimer/entities java/org/chorem/jtimer/storage java/org/chorem/jtimer/web webapp/js
by obruce@users.chorem.org 05 Jun '14
by obruce@users.chorem.org 05 Jun '14
05 Jun '14
Author: obruce
Date: 2014-06-05 18:19:13 +0200 (Thu, 05 Jun 2014)
New Revision: 2995
Url: http://forge.chorem.org/projects/jtimer/repository/revisions/2995
Log:
Ajout synchro serveur-serveur
Changement removed de timertime
Synchro a verifier
Added:
branches/ng-jtimer/src/main/java/org/chorem/jtimer/entities/Pair.java
Modified:
branches/ng-jtimer/src/main/java/org/chorem/jtimer/entities/TimerTime.java
branches/ng-jtimer/src/main/java/org/chorem/jtimer/entities/TodoList.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/TiersServerResource.java
branches/ng-jtimer/src/main/java/org/chorem/jtimer/web/TimeResource.java
branches/ng-jtimer/src/main/webapp/js/controllers.js
Added: branches/ng-jtimer/src/main/java/org/chorem/jtimer/entities/Pair.java
===================================================================
--- branches/ng-jtimer/src/main/java/org/chorem/jtimer/entities/Pair.java (rev 0)
+++ branches/ng-jtimer/src/main/java/org/chorem/jtimer/entities/Pair.java 2014-06-05 16:19:13 UTC (rev 2995)
@@ -0,0 +1,46 @@
+package org.chorem.jtimer.entities;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * Created by olivia on 05/06/14.
+ * <p/>
+ * Project name : jtimer
+ * <p/>
+ * Package name : org.chorem.jtimer.entities
+ *
+ * Cette classe represente un duo d'element type cle/valeur
+ * @param <K> la cle
+ * @param <V> la valeur
+ */
+public class Pair<K,V>{
+
+ protected static final Log log = LogFactory.getLog(Pair.class);
+
+ private K key; //la clef de la pair
+ private V value; //la valeur de la pair
+
+ public Pair(K key, V value){
+ this.key = key;
+ this.value = value;
+
+ log.info(this.key.toString() + this.value.toString());
+ }
+
+ public V getValue() {
+ return value;
+ }
+
+ public void setValue(V value) {
+ this.value = value;
+ }
+
+ public K getKey() {
+ return key;
+ }
+
+ public void setKey(K key) {
+ this.key = key;
+ }
+}
Modified: branches/ng-jtimer/src/main/java/org/chorem/jtimer/entities/TimerTime.java
===================================================================
--- branches/ng-jtimer/src/main/java/org/chorem/jtimer/entities/TimerTime.java 2014-06-04 14:21:46 UTC (rev 2994)
+++ branches/ng-jtimer/src/main/java/org/chorem/jtimer/entities/TimerTime.java 2014-06-05 16:19:13 UTC (rev 2995)
@@ -29,12 +29,12 @@
/** Time Elapsed in the period */
protected long time;
- /** */
- protected boolean isremoved;
+ /** Specifies if the time has been removed */
+ protected long removed;
public TimerTime() {
- isremoved = false;
+ removed = 0;
}
/**
@@ -49,7 +49,7 @@
this.time = time;
this.creationDate = creationDate;
this.modificationDate = creationDate;
- this.isremoved=false;
+ this.removed=0;
}
@@ -104,11 +104,11 @@
'}';
}
- public void setRemoved(boolean removed) {
- this.isremoved = removed;
+ public void setRemoved(long removed) {
+ this.removed = removed;
}
- public boolean getRemoved() {
- return isremoved;
+ public long getRemoved() {
+ return removed;
}
}
Modified: branches/ng-jtimer/src/main/java/org/chorem/jtimer/entities/TodoList.java
===================================================================
--- branches/ng-jtimer/src/main/java/org/chorem/jtimer/entities/TodoList.java 2014-06-04 14:21:46 UTC (rev 2994)
+++ branches/ng-jtimer/src/main/java/org/chorem/jtimer/entities/TodoList.java 2014-06-05 16:19:13 UTC (rev 2995)
@@ -21,10 +21,10 @@
protected Queue<String> deletedTasks;
/** {Arraylist of times} stockage des temps crees avant synchro */
- protected Queue<String> createdTimes;
+ protected Queue<Pair<String,String>> createdTimes;
/** {Arraylist of times} stockage des temps mis à jour avant synchro */
- protected Queue<String> updatedTimes;
+ protected Queue<Pair<String,String>> updatedTimes;
/** {Arraylist of long} stockage des identifiants temps supprimees avant synchro */
protected Queue<String> deletedTimes;
@@ -71,11 +71,11 @@
deletedTasks.add(taskId);
}
- public void pushCreatedTime(String time) {
+ public void pushCreatedTime(Pair<String,String> time) {
createdTimes.add(time);
}
- public void pushUpdatedTime(String time) {
+ public void pushUpdatedTime(Pair<String,String> time) {
updatedTimes.add(time);
}
@@ -113,47 +113,24 @@
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() {
+ public Queue<Pair<String, String>> getCreatedTimes() {
return createdTimes;
}
- public void setCreatedTimes(Queue<String> createdTimes) {
- this.createdTimes = createdTimes;
- }
-
- public Queue<String> getUpdatedTimes() {
+ public Queue<Pair<String, 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-06-04 14:21:46 UTC (rev 2994)
+++ branches/ng-jtimer/src/main/java/org/chorem/jtimer/storage/Storage.java 2014-06-05 16:19:13 UTC (rev 2995)
@@ -152,7 +152,7 @@
" modificationDate LONG, " +
" hidden BOOLEAN," +
" note TEXT," +
- "removed LONG," +
+ " removed LONG," +
" PRIMARY KEY (taskId))");
statement.executeUpdate("CREATE TABLE " + TABLE_TIME +
"(taskid VARCHAR(255) NOT NULL," +
@@ -160,7 +160,7 @@
" uuid varchar(255) unique," +
" duration LONG," +
" modificationDate LONG," +
- " removed BOOLEAN," +
+ " removed LONG," +
" PRIMARY KEY (taskid, date, uuid)," +
" FOREIGN KEY (taskid)" +
" REFERENCES " + TABLE_TASK +"(taskId)" +
@@ -308,7 +308,7 @@
statement.setLong(1, t.getCreationDate().getTime());
statement.setLong(2, t.getTime());
statement.setLong(3, t.getModificationDate().getTime()); //modificationDate
- statement.setBoolean(4, t.getRemoved());
+ statement.setLong(4, t.getRemoved());
statement.setString(5, t.getTimeId() );
statement.executeUpdate();
} catch (SQLException ex) {
@@ -386,7 +386,7 @@
statement.setString(3, time.getTimeId());
statement.setLong(4, time.getTime());
statement.setLong(5, time.getModificationDate().getTime());
- statement.setBoolean(6, time.getRemoved());
+ statement.setLong(6, time.getRemoved());
statement.executeUpdate();
} catch (SQLException ex) {
throw new StorageException("Can't add task time", ex);
@@ -428,7 +428,7 @@
time.setTime(rs.getLong("duration"));
time.setCreationDate(new java.util.Date(rs.getLong("date")));
time.setModificationDate(new java.util.Date(rs.getLong("modificationDate")));
- time.setRemoved(rs.getBoolean("removed"));
+ time.setRemoved(rs.getLong("removed"));
times.add(time);
@@ -465,7 +465,7 @@
time.setTime(rs.getLong("duration"));
time.setCreationDate(new java.util.Date(rs.getLong("date")));
time.setModificationDate(new java.util.Date(rs.getLong("modificationDate")));
- time.setRemoved(rs.getBoolean("removed"));
+ time.setRemoved(rs.getLong("removed"));
times.add(time);
}
@@ -530,7 +530,7 @@
PreparedStatement statement = null;
try {
statement = connection.prepareStatement("UPDATE " +
- TABLE_TIME + " SET removed = 1, modificationDate =" +time +
+ TABLE_TIME + " SET removed = "+time+", modificationDate =" +time +
" WHERE uuid = ?");
statement.setString(1, timeId);
@@ -552,7 +552,7 @@
PreparedStatement statement = null;
try {
statement = connection.prepareStatement("UPDATE " +
- TABLE_TASK + " SET removed = 1, modificationDate =" +time +
+ TABLE_TASK + " SET removed = "+time+", modificationDate =" +time +
" WHERE taskId = '"+taskId +"'");
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-06-04 14:21:46 UTC (rev 2994)
+++ branches/ng-jtimer/src/main/java/org/chorem/jtimer/web/RestApplication.java 2014-06-05 16:19:13 UTC (rev 2995)
@@ -1,12 +1,8 @@
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.Pair;
import org.chorem.jtimer.entities.TodoList;
import org.chorem.jtimer.storage.Storage;
import org.restlet.Application;
@@ -14,59 +10,27 @@
import org.restlet.Restlet;
import org.restlet.routing.Router;
+import java.util.Date;
+import java.util.Iterator;
+import java.util.Timer;
+
public class RestApplication extends Application {
+ /** Timer qui va se lancer toutes les x minutes */
protected Timer timer = new Timer();
+
+ /** Resource qui va pousser les elements vers d'autres serveurs */
protected TiersServerResource tiers = new TiersServerResource();
protected static final Log log = LogFactory.getLog(RestApplication.class);
- protected boolean connected = true;
+ /** Determine si la connexion est établie */ //TODO obruce 05/06/2014 to change when configuration available
+ protected boolean connected = false;
+
+ /** Todolist instance */
protected TodoList todoList;
-
- protected class TodoTask extends java.util.TimerTask{
- @Override
- public void run() {
- log.info("Passage dans le run");
-
- if(connected){
-
- if(!todoList.getCreatedTasks().isEmpty()) {
- //Les taches crees
- log.info("Des taches creer à envoyer");
- for (String task : todoList.getCreatedTasks()) {
- if (tiers.postTask(task)) {
- todoList.removeCreatedTask();
- }
- }
- }
-
- if(!todoList.getUpdatedTasks().isEmpty() ){
- log.info("Des taches avec update à envoyer");
- for (String task : todoList.getUpdatedTasks()){
- if(tiers.updateTask(task)){
- log.info("update fait");
- todoList.removeUpdatedTask();
- }
- }
- }
-
- if(!todoList.getDeletedTasks().isEmpty()){
- log.info("Des taches avec update à envoyer");
- for (String task : todoList.getDeletedTasks()){
- if(tiers.deleteTask(task)){
- log.info("update fait");
- todoList.removeUpdatedTask();
- }
- }
- }
-
- }
- }
- };
-
/**
* Creates a root Restlet that will receive all incoming calls.
*/
@@ -88,42 +52,113 @@
return router;
}
+ /**
+ * Initialise le context de l'application REST
+ * @param context
+ */
protected void initContext(Context context) {
//Initialisation du storage
Storage storage = new Storage();
if (storage.getTasksCount() == 0) {
- 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);
- storage.addTask(jTimerTask1);
- storage.addTask(jTimerTask2);
-
- storage.addTaskTime(jTimerTask1, new Date(), UUID.randomUUID().toString(), 4567);
- storage.addTaskTime(jTimerTask1, new Date(), UUID.randomUUID().toString(), 1000000);
- storage.addTaskTime(jTimerTask2, new Date(), UUID.randomUUID().toString(), 45);
-
- 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);
+ timer.schedule(new TodoTask(), new Date(), (long) 10000); //TODO obruce change timer time
todoList = TodoList.getInstance();
}
+ /**
+ * Classe representant la tache a effectuer pendant le timer
+ *
+ * Methode run: qui se lance toutes les x minutes
+ */
+ protected class TodoTask extends java.util.TimerTask{
+ @Override
+ public void run() {
+ log.info("Passage dans le run");
+ if(connected){
+ if(!todoList.getCreatedTasks().isEmpty()) {
+ //Les taches crees
+ log.info("Des taches creer à envoyer");
+ Iterator iter = todoList.getCreatedTasks().iterator();
+ while(iter.hasNext()) {
+ if (tiers.postTask((String) iter.next())) {
+ iter.remove();
+ }
+ }
+
+ }
+
+ if(!todoList.getUpdatedTasks().isEmpty() ){
+ log.info("Des taches avec update à envoyer");
+
+ Iterator iter = todoList.getUpdatedTasks().iterator();
+ while(iter.hasNext()) {
+ if (tiers.updateTask((String) iter.next())) {
+ iter.remove();
+ }
+ }
+ }
+
+ if(!todoList.getDeletedTasks().isEmpty()){
+ log.info("Des taches supprimée à envoyer");
+
+ Iterator iter = todoList.getDeletedTasks().iterator();
+ while(iter.hasNext()) {
+ if (tiers.deleteTask((String) iter.next())) {
+ iter.remove();
+ }
+ }
+ }
+
+ if(!todoList.getCreatedTimes().isEmpty()) {
+
+ log.info("Des temps creer à envoyer");
+
+ Iterator iter = todoList.getCreatedTimes().iterator();
+ while(iter.hasNext()) {
+ if (tiers.postTime((Pair) iter.next())) {
+ iter.remove();
+ }
+ }
+
+ }
+
+ if(!todoList.getUpdatedTimes().isEmpty() ){
+ log.info("Des temps avec update à envoyer");
+
+ Iterator iter = todoList.getUpdatedTimes().iterator();
+ while(iter.hasNext()) {
+ if (tiers.updateTime((Pair) iter.next())) {
+ iter.remove();
+ }
+ }
+
+ }
+
+ if(!todoList.getDeletedTimes().isEmpty()){
+ log.info("Des temps supprimé à envoyer");
+
+ Iterator iter = todoList.getDeletedTimes().iterator();
+ while(iter.hasNext()) {
+ if (tiers.deleteTime((String) iter.next())) {
+ iter.remove();
+ }
+ }
+ }
+
+ }
+ }
+ };
+
+
}
\ No newline at end of file
Modified: branches/ng-jtimer/src/main/java/org/chorem/jtimer/web/TiersServerResource.java
===================================================================
--- branches/ng-jtimer/src/main/java/org/chorem/jtimer/web/TiersServerResource.java 2014-06-04 14:21:46 UTC (rev 2994)
+++ branches/ng-jtimer/src/main/java/org/chorem/jtimer/web/TiersServerResource.java 2014-06-05 16:19:13 UTC (rev 2995)
@@ -10,7 +10,7 @@
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
-import org.restlet.resource.ServerResource;
+import org.chorem.jtimer.entities.Pair;
/**
* Created by olivia on 03/06/14.
@@ -21,11 +21,13 @@
*
*
*/
-public class TiersServerResource extends ServerResource {
+public class TiersServerResource{
protected static final Log log = LogFactory.getLog(TiersServerResource.class);
protected static final String dispatch = "?dispatch=false"; //TODO 04/06/14 obruce : remove this parameter when config will be available
+ protected static final String path = "http://localhost:8080/rest/tasks/"; //TODO 04/06/14 obruce : remove this parameter when config will be available
+
/**
* Ctr
*/
@@ -43,7 +45,7 @@
boolean success = false;
CloseableHttpClient httpclient = HttpClients.createDefault();
- HttpPost httpPost = new HttpPost("http://localhost:8080/rest/tasks/task"+dispatch);
+ HttpPost httpPost = new HttpPost(path+ "task"+dispatch);
StringEntity myEntity = new StringEntity(t,ContentType.create("application/json", "UTF-8"));
@@ -77,7 +79,7 @@
boolean success = false;
CloseableHttpClient httpclient = HttpClients.createDefault();
- HttpPut httpPut = new HttpPut("http://localhost:8080/rest/tasks/task"+dispatch);
+ HttpPut httpPut = new HttpPut(path+"task"+dispatch);
StringEntity myEntity = new StringEntity(task,ContentType.create("application/json", "UTF-8"));
@@ -111,7 +113,7 @@
boolean success = false;
CloseableHttpClient httpclient = HttpClients.createDefault();
- HttpDelete httpDelete = new HttpDelete("http://localhost:8080/rest/tasks/task/"+taskId +dispatch);
+ HttpDelete httpDelete = new HttpDelete(path+"task/"+taskId +dispatch);
try{
CloseableHttpResponse response2 = httpclient.execute(httpDelete);
@@ -132,4 +134,95 @@
}
+ public boolean postTime(Pair<String, String> time) {
+
+ boolean success = false;
+
+ CloseableHttpClient httpclient = HttpClients.createDefault();
+ HttpPost httpPost = new HttpPost(path+ "time/"+ time.getKey()+dispatch);
+
+ StringEntity myEntity = new StringEntity(time.getValue(),ContentType.create("application/json", "UTF-8"));
+
+ //On ajoute l'entite
+ httpPost.setEntity(myEntity);
+
+ try{
+ CloseableHttpResponse response2 = httpclient.execute(httpPost);
+ log.info(" Reponse du server 2 : " +response2.getStatusLine());
+
+ //On ferme la reponse
+ response2.close();
+
+ //Mission accompli
+ success = true;
+
+ }catch(Exception e){
+ e.printStackTrace();
+ }
+
+ return success;
+ }
+
+ /**
+ * Methode qui envoie les mise a jour des temps vers le serveur
+ * @param time l'objet temps avec la task et la representation du temŝ
+ * @return boolean of Http success
+ */
+ public boolean updateTime(Pair<String, String> time) {
+
+ boolean success = false;
+
+ CloseableHttpClient httpclient = HttpClients.createDefault();
+ HttpPut httpPut = new HttpPut(path+ "time/"+ time.getKey()+dispatch);
+
+ StringEntity myEntity = new StringEntity(time.getValue(),ContentType.create("application/json", "UTF-8"));
+
+ //On ajoute l'entite
+ httpPut.setEntity(myEntity);
+
+ try{
+ CloseableHttpResponse response2 = httpclient.execute(httpPut);
+ log.info(" Reponse du server 2 : " +response2.getStatusLine());
+
+ //On ferme la reponse
+ response2.close();
+
+ //Mission accompli
+ success = true;
+
+ }catch(Exception e){
+ e.printStackTrace();
+ }
+
+ return success;
+ }
+
+ /**
+ * Methode qui envoie les temps taggee comme supprimer
+ * @param time l'objet temps avec la task et la representation du temŝ
+ * @return boolean of Http success
+ */
+ public boolean deleteTime(String time) {
+ boolean success = false;
+
+ CloseableHttpClient httpclient = HttpClients.createDefault();
+ HttpDelete httpDelete = new HttpDelete(path+ "time/"+ time+dispatch);
+
+ try{
+ CloseableHttpResponse response2 = httpclient.execute(httpDelete);
+ log.info(" Reponse du server 2 : " +response2.getStatusLine());
+
+ //On ferme la reponse
+ response2.close();
+
+ //Mission accompli
+ success = true;
+
+ }catch(Exception e){
+ e.printStackTrace();
+ }
+
+ return success;
+
+ }
}
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-06-04 14:21:46 UTC (rev 2994)
+++ branches/ng-jtimer/src/main/java/org/chorem/jtimer/web/TimeResource.java 2014-06-05 16:19:13 UTC (rev 2995)
@@ -11,7 +11,9 @@
import com.google.gson.JsonSerializer;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.chorem.jtimer.entities.Pair;
import org.chorem.jtimer.entities.TimerTime;
+import org.chorem.jtimer.entities.TodoList;
import org.chorem.jtimer.storage.Storage;
import org.restlet.data.MediaType;
import org.restlet.representation.Representation;
@@ -33,9 +35,16 @@
private static final Log log = LogFactory.getLog(TimeResource.class);
+ /** Builder for serialisation deserialisation */
private GsonBuilder builder;
+ /** H2 storage instance */
protected Storage storage;
+ /** Todolist instance */
+ protected TodoList todoList;
+ /** Specifies if the post should be dispatched */
+ protected boolean dispatch; //TODO 04/06/14 obruce : remove this parameter when config will be available
+
/**
* Methode qui initialis la resource
* @throws ResourceException
@@ -65,6 +74,7 @@
storage = (Storage)getContext().getAttributes().get(Storage.class.getName());
+ todoList = TodoList.getInstance();
}
/**
@@ -100,8 +110,14 @@
*/
@Delete
public void deleteTime() {
+
+ dispatch = getDispatch();
String timeId = (String)getRequest().getAttributes().get("taskId");
storage.removeTimeWithId(timeId, new Date().getTime());
+
+ if (dispatch) {
+ todoList.pushDeletedTime(timeId);
+ }
}
/**
@@ -111,38 +127,28 @@
@Post("json")
public void createTime(Representation representation) throws IOException {
- String taskId = (String)getRequest().getAttributes().get("taskId");
+ if(representation.isAvailable()) {
- Gson gson = builder.create();
- String repr1 = representation.getText();
+ dispatch = getDispatch();
+ Gson gson = builder.create();
- TimerTime newTime = gson.fromJson(repr1, TimerTime.class);
+ //On reconstruit l'element avec la representation
+ String jsonRepr = representation.getText();
+ TimerTime newTime = gson.fromJson(jsonRepr, TimerTime.class);
- List<TimerTime> list = storage.getTimes(taskId, newTime.getCreationDate().getTime());
+ if (log.isInfoEnabled()) {
+ log.info("La periode suivante est cree : " + newTime.toString());
+ }
- for(TimerTime oldTime : list){
- long oldStart= oldTime.getCreationDate().getTime();
- long oldEnd = oldStart + oldTime.getTime();
- long newStart =newTime.getCreationDate().getTime();
- long newEnd = newStart + newTime.getTime();
+ storage.addTaskTime(newTime);
-
- if(oldEnd > newStart || newEnd > oldStart){
- //Les temps ne se chevauchent pas
-
- }else{
- //un temps chevauchent un autre
-
+ if (dispatch) {
+ String taskId = (String) getRequest().getAttributes().get("taskId");
+ Pair p = new Pair<String, String>(taskId, jsonRepr);
+ log.info(" la pair cree" + p.toString()+ p.getKey().toString()+p.getValue().toString());
+ todoList.pushCreatedTime(p);
}
-
}
-
- if (log.isInfoEnabled()) {
- log.info("La periode suivante est cree : " + newTime.toString());
- }
-
- storage.addTaskTime(newTime);
-
}
/**
@@ -152,16 +158,47 @@
@Put("json")
public void updateTime(Representation representation) throws IOException{
- Gson gson = builder.create();
- String repr1 = representation.getText();
- TimerTime t = gson.fromJson(repr1, TimerTime.class);
+ if(representation.isAvailable()) {
- storage.modifyTime(t);
+ dispatch = getDispatch();
+
+ Gson gson = builder.create();
+ String jsonRepr = representation.getText();
+ TimerTime t = gson.fromJson(jsonRepr, TimerTime.class);
+
+ storage.modifyTime(t);
+
+ if (dispatch) {
+ String taskId = (String) getRequest().getAttributes().get("taskId");
+ todoList.pushUpdatedTime(new Pair<String, String>(taskId, jsonRepr));
+ }
+ }
+
}
+ /**
+ * Called when option requests are catched
+ * Needed to avoid cross origin
+ */
@Options
public void timeOptions() {
+ //do nothing
+ }
+ /**
+ * Recupere la valeur de dispatch dans l'url
+ * TODO 04/06/14 obruce : remove this method when config will be available
+ * @return
+ */
+ private boolean getDispatch() {
+ boolean res;
+ try {
+ res = Boolean.valueOf(getQuery().getValues("dispatch"));
+ } catch (Exception e) {
+ e.printStackTrace();
+ res = true;
+ }
+ return res;
}
}
Modified: branches/ng-jtimer/src/main/webapp/js/controllers.js
===================================================================
--- branches/ng-jtimer/src/main/webapp/js/controllers.js 2014-06-04 14:21:46 UTC (rev 2994)
+++ branches/ng-jtimer/src/main/webapp/js/controllers.js 2014-06-05 16:19:13 UTC (rev 2995)
@@ -288,7 +288,7 @@
var editedTime = getObjectInArrayWithId($scope.data.times[item.taskId],item.timeId);
if(editedTime){
- if(!item.isremoved){
+ if(item.removed == 0){
console.log("Temps existe donc remplacé");
//Le temps existe
editedTime.time = item.time;
@@ -297,9 +297,12 @@
//TODO obruce 2/6/14 verfication chevauchement temps
save();
+ }else{
+ //TODO supprimer si existant mais removed
+ suppressObjectInArrayWithId($scope.data.times[item.taskId],item.timeId);
}
- }else if(!item.isremoved){
+ }else if(item.removed == 0){
console.log("le temps n'existe pas");
//init de l'array des temps de la tache
if(!$scope.data.times[item.taskId]){$scope.data.times[item.taskId] = []}
@@ -359,6 +362,21 @@
return res;
}
+
+ //Recuperer un element dans un array avec son id
+ var suppressObjectInArrayWithId= function(array, timeid,taskid){
+ var res=0;
+ angular.forEach(array, function(time){
+ if(time.timeId == timeid){
+ array.splice(res,1);
+
+ }
+ res++;
+ });
+ return res;
+ }
+
+
/**
* Methode qui retourne l'existence d'un element dans un array
*/
@@ -419,7 +437,7 @@
//On change la date au dernier acces
time["modificationDate"]=$scope.timeAccess;
- serverTimeAccess.create({taskId: task} , angular.toJson(time),
+ serverTimeAccess.create({taskId: task,dispatch:true} , angular.toJson(time),
function(){
console.log("persist time success" + task);
$scope.todo.stockedNewTimes[task].shift();
@@ -436,7 +454,7 @@
time["modificationDate"]=$scope.timeAccess;
- serverTimeAccess.update({taskId: task}, angular.toJson(time),
+ serverTimeAccess.update({taskId: task,dispatch:true}, angular.toJson(time),
function(){
console.log("update time success" + task);
$scope.todo.stockedEditedTimes[task].shift();
@@ -450,7 +468,7 @@
//On supprime de la base les taches sotckees pour suppression
angular.forEach($scope.todo.stockedDeletedTimes, function(times,task){
angular.forEach(times, function(time){
- serverTimeAccess.deleteTime({taskId: time},
+ serverTimeAccess.deleteTime({taskId: time,dispatch:true},
function(){
console.log("delete time success" + task);
$scope.todo.stockedDeletedTimes[task].shift();
@@ -866,10 +884,6 @@
}
});
- modalInstance.result.finally(function() {
- console.log("finally");
- });
-
}
/**
@@ -968,9 +982,6 @@
$modalInstance.dismiss('cancel');
};
- $scope.$on('$destroy', function() {
- console.log('Modal scope should be destroyed.');
- });
};
function DatePickerCtrl($scope){
1
0
r2994 - 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
by obruce@users.chorem.org 04 Jun '14
by obruce@users.chorem.org 04 Jun '14
04 Jun '14
Author: obruce
Date: 2014-06-04 16:21:46 +0200 (Wed, 04 Jun 2014)
New Revision: 2994
Url: http://forge.chorem.org/projects/jtimer/repository/revisions/2994
Log:
Ajout communication des tasks entre serveur
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/ApplicationServletFilter.java
branches/ng-jtimer/src/main/java/org/chorem/jtimer/web/RestApplication.java
branches/ng-jtimer/src/main/java/org/chorem/jtimer/web/TaskResource.java
branches/ng-jtimer/src/main/java/org/chorem/jtimer/web/TasksResource.java
branches/ng-jtimer/src/main/java/org/chorem/jtimer/web/TiersServerResource.java
branches/ng-jtimer/src/main/webapp/js/controllers.js
Modified: branches/ng-jtimer/pom.xml
===================================================================
--- branches/ng-jtimer/pom.xml 2014-06-03 16:27:59 UTC (rev 2993)
+++ branches/ng-jtimer/pom.xml 2014-06-04 14:21:46 UTC (rev 2994)
@@ -194,6 +194,10 @@
<version>${jettyVersion}</version>
<scope>provided</scope>
</dependency>
+ <dependency>
+ <groupId>org.apache.httpcomponents</groupId>
+ <artifactId>httpclient</artifactId>
+ </dependency>
</dependencies>
<repositories>
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-06-03 16:27:59 UTC (rev 2993)
+++ branches/ng-jtimer/src/main/java/org/chorem/jtimer/entities/TimerTask.java 2014-06-04 14:21:46 UTC (rev 2994)
@@ -64,15 +64,15 @@
/** Total time. */
protected long totalTime;
- /** if task is removed */
- protected boolean isremoved;
+ /** date if task is removed */
+ protected long removed;
/**
* Constructor.
*/
public TimerTask() {
// wrong value to detect bug
- this.isremoved = true;
+ this.removed = 0;
}
/**
@@ -86,7 +86,7 @@
this.taskId = UUID.randomUUID().toString();
this.parent = "";
this.modificationDate = new Date();
- this.isremoved = false;
+ this.removed = 0;
}
/**
@@ -100,7 +100,7 @@
this.taskId = UUID.randomUUID().toString();
this.parent = "";
this.modificationDate = new Date(datetime);
- this.isremoved = false;
+ this.removed = 0;
}
@@ -207,7 +207,21 @@
this.totalTime = totalTime;
}
- public boolean getRemoved() {return isremoved;}
+ public long getRemoved() {return removed;}
- public void setRemoved(boolean removed) {this.isremoved = removed;}
+ public void setRemoved(long removed) {this.removed = removed;}
+
+ @Override
+ public String toString() {
+ return "TimerTask {" +
+ "taskId='" + taskId + '\'' +
+ ", parent='" + parent + '\'' +
+ ", name='" + name + '\'' +
+ ", modificationDate=" + modificationDate +
+ ", closed=" + closed +
+ ", todayTime=" + todayTime +
+ ", totalTime=" + totalTime +
+ ", removed=" + removed +
+ '}';
+ }
}
\ No newline at end of file
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-06-03 16:27:59 UTC (rev 2993)
+++ branches/ng-jtimer/src/main/java/org/chorem/jtimer/storage/Storage.java 2014-06-04 14:21:46 UTC (rev 2994)
@@ -152,7 +152,7 @@
" modificationDate LONG, " +
" hidden BOOLEAN," +
" note TEXT," +
- "removed BOOLEAN," +
+ "removed LONG," +
" PRIMARY KEY (taskId))");
statement.executeUpdate("CREATE TABLE " + TABLE_TIME +
"(taskid VARCHAR(255) NOT NULL," +
@@ -219,7 +219,7 @@
task.setTaskId(rs.getString("taskId"));
task.setName(rs.getString("name"));
task.setParent(rs.getString("parent"));
- task.setRemoved(rs.getBoolean("removed"));
+ task.setRemoved(rs.getLong("removed"));
task.setTodayTime(0);
task.setModificationDate(new java.util.Date(rs.getLong("modificationDate")));
task.setTotalTime(rs.getLong("totalduration"));
@@ -237,7 +237,7 @@
task.setTaskId(rs.getString("taskId"));
task.setParent(rs.getString("parent"));
task.setModificationDate(new java.util.Date(rs.getLong("modificationDate")));
- task.setRemoved(rs.getBoolean("removed"));
+ task.setRemoved(rs.getLong("removed"));
task.setTodayTime(0);
task.setTotalTime(0);
tasks.add(task);
@@ -266,7 +266,7 @@
statement.setBoolean(4, task.isClosed());
statement.setString(5, null /*project.getNote()*/);
statement.setLong(6, task.getModificationDate().getTime());
- statement.setBoolean(7,task.getRemoved());
+ statement.setLong(7,task.getRemoved());
statement.executeUpdate();
} catch (SQLException ex) {
@@ -288,7 +288,7 @@
statement.setString(4, null /*project.getNote()*/);//note
statement.setLong(5, task.getModificationDate().getTime()); //modificationDate
- statement.setBoolean(6,task.getRemoved());
+ statement.setLong(6,task.getRemoved());
statement.setString(7, task.getTaskId()); //taskId
statement.executeUpdate();
Modified: branches/ng-jtimer/src/main/java/org/chorem/jtimer/web/ApplicationServletFilter.java
===================================================================
--- branches/ng-jtimer/src/main/java/org/chorem/jtimer/web/ApplicationServletFilter.java 2014-06-03 16:27:59 UTC (rev 2993)
+++ branches/ng-jtimer/src/main/java/org/chorem/jtimer/web/ApplicationServletFilter.java 2014-06-04 14:21:46 UTC (rev 2994)
@@ -22,8 +22,7 @@
*/
public class ApplicationServletFilter implements Filter {
- // private final static Logger LOGGER = Logger.getLogger(TasksResource.class.getName());
- private static final Log log = LogFactory.getLog(TasksResource.class);
+ private static final Log log = LogFactory.getLog(ApplicationServletFilter.class);
private static final String HEADER_ACCESS_CONTROL_ALLOW_ORIGIN = "Access-Control-Allow-Origin";
private static final String HEADER_ACCESS_CONTROL_ALLOW_CREDENTIALS = "Access-Control-Allow-Credentials";
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-06-03 16:27:59 UTC (rev 2993)
+++ branches/ng-jtimer/src/main/java/org/chorem/jtimer/web/RestApplication.java 2014-06-04 14:21:46 UTC (rev 2994)
@@ -29,21 +29,40 @@
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");
+ log.info("Passage dans le run");
if(connected){
- if(todoList.getCreatedTasks() != null){
+ if(!todoList.getCreatedTasks().isEmpty()) {
//Les taches crees
- for (String task : todoList.getCreatedTasks()){
-
- if(tiers.postTask(task)){
+ log.info("Des taches creer à envoyer");
+ for (String task : todoList.getCreatedTasks()) {
+ if (tiers.postTask(task)) {
todoList.removeCreatedTask();
}
+ }
+ }
+ if(!todoList.getUpdatedTasks().isEmpty() ){
+ log.info("Des taches avec update à envoyer");
+ for (String task : todoList.getUpdatedTasks()){
+ if(tiers.updateTask(task)){
+ log.info("update fait");
+ todoList.removeUpdatedTask();
+ }
}
}
+ if(!todoList.getDeletedTasks().isEmpty()){
+ log.info("Des taches avec update à envoyer");
+ for (String task : todoList.getDeletedTasks()){
+ if(tiers.deleteTask(task)){
+ log.info("update fait");
+ todoList.removeUpdatedTask();
+ }
+ }
+ }
+
}
}
};
@@ -64,7 +83,7 @@
router.attach("/tasks/task/{taskId}", TaskResource.class);
router.attach("/tasks/time/{taskId}", TimeResource.class);
router.attach("/tasks/time", TimesResource.class);
- router.attach("/tiers", TiersServerResource.class);
+ //router.attach("/tiers", TiersServerResource.class);
return router;
}
Modified: branches/ng-jtimer/src/main/java/org/chorem/jtimer/web/TaskResource.java
===================================================================
--- branches/ng-jtimer/src/main/java/org/chorem/jtimer/web/TaskResource.java 2014-06-03 16:27:59 UTC (rev 2993)
+++ branches/ng-jtimer/src/main/java/org/chorem/jtimer/web/TaskResource.java 2014-06-04 14:21:46 UTC (rev 2994)
@@ -4,6 +4,7 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.chorem.jtimer.entities.TodoList;
import org.chorem.jtimer.storage.Storage;
import org.restlet.data.MediaType;
import org.restlet.representation.Representation;
@@ -18,6 +19,7 @@
private static final Log log = LogFactory.getLog(TaskResource.class);
protected Storage storage;
+ protected TodoList todoList;
/**
* Methode qui initialis la resource
@@ -25,7 +27,12 @@
*/
@Override
protected void doInit() throws ResourceException {
+
storage = (Storage)getContext().getAttributes().get(Storage.class.getName());
+
+ //On recupere la todoList courante
+ todoList = TodoList.getInstance();
+
}
/**
@@ -50,11 +57,36 @@
*/
@Delete
public void deleteTask() {
+
+ boolean dispatch = getDispatch();
+
String taskId = (String)getRequest().getAttributes().get("taskId");
storage.removeTaskWithId(taskId, new Date().getTime());
+
+
+
+ if(dispatch)
+ todoList.pushDeletedTask(taskId);
}
+ /**
+ * Recupere la valeur de dispatch dans l'url
+ * TODO 04/06/14 obruce : remove this method when config will be available
+ * @return
+ */
+ private boolean getDispatch() {
+ boolean res;
+ try {
+ res = Boolean.valueOf(getQuery().getValues("dispatch"));
+ } catch (Exception e) {
+ e.printStackTrace();
+ res = true;
+ }
+ return res;
+ }
+
+
@Options
public void taskOptions() {
if (log.isInfoEnabled()) {
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-06-03 16:27:59 UTC (rev 2993)
+++ branches/ng-jtimer/src/main/java/org/chorem/jtimer/web/TasksResource.java 2014-06-04 14:21:46 UTC (rev 2994)
@@ -12,14 +12,9 @@
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;
@@ -45,6 +40,8 @@
protected GsonBuilder builder;
protected TodoList todoList;
+ protected boolean dispatch; //TODO 04/06/14 obruce : remove this parameter when config will be available
+
/**
* Methode qui initialis la resource
*
@@ -123,28 +120,51 @@
public void createTask(Representation representation) throws IOException {
Gson gson = builder.create();
- String repr1 ="";
+ String repr1 = "";
- if(representation.isAvailable()) {
+ dispatch = getDispatch();
+ if (representation.isAvailable()) {
+
repr1 = representation.getText();
TimerTask t = gson.fromJson(repr1, TimerTask.class);
- t.setRemoved(false);
+ t.setRemoved(0);
storage.addTask(t);
- todoList.pushCreatedTask(repr1);
+ if (dispatch) {
+ todoList.pushCreatedTask(repr1);
+ log.info("on dispatch");
+ }
}
}
/**
+ * Recupere la valeur de dispatch dans l'url
+ * TODO 04/06/14 obruce : remove this method when config will be available
+ * @return
+ */
+ private boolean getDispatch() {
+ boolean res;
+ try {
+ res = Boolean.valueOf(getQuery().getValues("dispatch"));
+ } catch (Exception e) {
+ e.printStackTrace();
+ res = true;
+ }
+ return res;
+ }
+
+ /**
* Methode qui met à jour une tache
* suite d'une requête de type PUT
*/
@Put("json")
public void updateTask(Representation representation) throws IOException {
+ dispatch = getDispatch();
+
if(representation.isAvailable()) {
Gson gson = builder.create();
@@ -157,9 +177,15 @@
storage.modifyTask(t);
+ if (dispatch) {
+ todoList.pushUpdatedTask(repr1);
+ log.info("on dispatch update");
+ }
+
}
- toRepresentation("{}", new Variant(MediaType.APPLICATION_JSON));
+
+
}
Modified: branches/ng-jtimer/src/main/java/org/chorem/jtimer/web/TiersServerResource.java
===================================================================
--- branches/ng-jtimer/src/main/java/org/chorem/jtimer/web/TiersServerResource.java 2014-06-03 16:27:59 UTC (rev 2993)
+++ branches/ng-jtimer/src/main/java/org/chorem/jtimer/web/TiersServerResource.java 2014-06-04 14:21:46 UTC (rev 2994)
@@ -1,108 +1,135 @@
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.apache.http.client.methods.CloseableHttpResponse;
+import org.apache.http.client.methods.HttpDelete;
+import org.apache.http.client.methods.HttpPost;
+import org.apache.http.client.methods.HttpPut;
+import org.apache.http.entity.ContentType;
+import org.apache.http.entity.StringEntity;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.impl.client.HttpClients;
import org.restlet.resource.ServerResource;
-import java.lang.reflect.Type;
-import java.util.Date;
-
/**
* Created by olivia on 03/06/14.
+ *
+ * Project name : ${PROJECT_NAME}
+ *
+ * Package name : ${PACKAGE_NAME}
+ *
+ *
*/
public class TiersServerResource extends ServerResource {
- protected static final Log log = LogFactory.getLog(RestApplication.class);
+ protected static final Log log = LogFactory.getLog(TiersServerResource.class);
+ protected static final String dispatch = "?dispatch=false"; //TODO 04/06/14 obruce : remove this parameter when config will be available
- protected Storage storage;
- protected GsonBuilder builder;
- protected TodoList todoList;
+ /**
+ * Ctr
+ */
+ public TiersServerResource(){
- @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>() {
+ /**
+ * Methode qui va pousser vers le serveur distant une tache qui vient d'etre creee
+ * @param t la representation dune tache
+ * @return booleen de succes
+ */
+ public boolean postTask(String t){
+ //Determine si la requete a ete un succes
+ boolean success = false;
- public Date deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
- return new Date(json.getAsJsonPrimitive().getAsLong());
- }
+ CloseableHttpClient httpclient = HttpClients.createDefault();
+ HttpPost httpPost = new HttpPost("http://localhost:8080/rest/tasks/task"+dispatch);
- });
+ StringEntity myEntity = new StringEntity(t,ContentType.create("application/json", "UTF-8"));
- builder.registerTypeAdapter(Date.class, new JsonSerializer<Date>() {
- @Override
- public JsonElement serialize(Date date, Type type, JsonSerializationContext jsonSerializationContext) {
- return new JsonPrimitive(date.getTime());
- }
- });
+ //On ajoute l'entite
+ httpPost.setEntity(myEntity);
- //On recupere la todoList courante
- todoList = TodoList.getInstance();
+ try{
+ CloseableHttpResponse response2 = httpclient.execute(httpPost);
+ log.info(" Reponse du server 2 : " +response2.getStatusLine());
+ //On ferme la reponse
+ response2.close();
+
+ //Mission accompli
+ success = true;
+
+ }catch(Exception e){
+ e.printStackTrace();
+ }
+
+ return success;
}
-
/**
- * Methode qui va pousser vers le serveur distant une tache
- * @param t
+ * Methode qui va pousser vers le serveur distant une tache qui vient d'etre mise a jour
+ * @param task la tache a mettre a jour
+ * @return booleen de succes
*/
- @Post("json")
- public boolean postTask(String t){
- //Determine si la requete a ete un succes
+ public boolean updateTask(String task) {
+
boolean success = false;
+ CloseableHttpClient httpclient = HttpClients.createDefault();
+ HttpPut httpPut = new HttpPut("http://localhost:8080/rest/tasks/task"+dispatch);
- 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);
+ StringEntity myEntity = new StringEntity(task,ContentType.create("application/json", "UTF-8"));
+ //On ajoute l'entite
+ httpPut.setEntity(myEntity);
+
try{
- log.info("La representation " + t);
- Representation representation = toRepresentation(t, new Variant(MediaType.APPLICATION_JSON));
- log.info(representation.getText());
+ CloseableHttpResponse response2 = httpclient.execute(httpPut);
+ log.info(" Reponse du server 2 : " +response2.getStatusLine());
- clientTaskResource.post(representation);
+ //On ferme la reponse
+ response2.close();
+
+ //Mission accompli
success = true;
+
}catch(Exception e){
e.printStackTrace();
- success = false;
}
return success;
}
+ /**
+ * Methode qui va pousser vers le serveur distant une tache qui vient d'etre mise a jour
+ * @param taskId l'identifiant de la tache a mettre a jour
+ * @return booleen de succes
+ */
+ public boolean deleteTask(String taskId){
- public void putTask(){
+ boolean success = false;
+ CloseableHttpClient httpclient = HttpClients.createDefault();
+ HttpDelete httpDelete = new HttpDelete("http://localhost:8080/rest/tasks/task/"+taskId +dispatch);
- }
+ try{
+ CloseableHttpResponse response2 = httpclient.execute(httpDelete);
+ log.info(" Reponse du server 2 : " +response2.getStatusLine());
- public void deleteTask(){
+ //On ferme la reponse
+ response2.close();
+ //Mission accompli
+ success = true;
+ }catch(Exception e){
+ e.printStackTrace();
+ }
+
+ return success;
+
}
+
+
}
Modified: branches/ng-jtimer/src/main/webapp/js/controllers.js
===================================================================
--- branches/ng-jtimer/src/main/webapp/js/controllers.js 2014-06-03 16:27:59 UTC (rev 2993)
+++ branches/ng-jtimer/src/main/webapp/js/controllers.js 2014-06-04 14:21:46 UTC (rev 2994)
@@ -164,7 +164,7 @@
angular.forEach(response, function (item) {
- if((!(item.taskId in $scope.data.tasks)) && item.isremoved == false){
+ if((!(item.taskId in $scope.data.tasks)) && item.removed == 0){
console.log( "Un element non present " + item.name + item.modificationDate);
var newTask = new Task( item.name, item.taskId, item.parent);
@@ -211,7 +211,7 @@
*
*/
var updateTasksFromServ = function(){
-
+ console.log("updateTasksFromServ debut");
serverTaskAccess.query({date : ($scope.taskAccess-delayAccess)}, function (response) {
angular.forEach(response, function (item) {
@@ -224,7 +224,7 @@
//On cherche le node et on le met à jour
var tmp = $scope.tree.getNode(item.taskId);
- if(item.isremoved){
+ if(item.removed != 0){
$scope.removeTask(tmp);
}else{
tmp.task.name = item.name;
@@ -232,7 +232,7 @@
save();
- }else if(!item.isremoved){
+ }else if(item.removed == 0){
console.log("Nouvelle tache" +item);
@@ -271,6 +271,8 @@
$scope.taskAccess = Date.now();
$scope.todo.lastTaskAccess= $scope.taskAccess;
save();
+
+ console.log("updateTasksFromServ fin");
}
/**
@@ -372,7 +374,7 @@
//On supprime de la base les taches sotckees pour suppression
angular.forEach($scope.todo.stockedDeletedTasks, function(task){
- serverTaskAccess.deleteTask({taskId: task},
+ serverTaskAccess.deleteTask({taskId: task,dispatch:true},
function(){
console.log("delete success" + task);
$scope.todo.stockedDeletedTasks.shift();
@@ -387,7 +389,7 @@
//On change la date au dernier acces
task['modificationDate']=$scope.taskAccess;
- serverTaskAccess.create(angular.toJson(task),
+ serverTaskAccess.create({dispatch:true}, angular.toJson(task), //TODO obruce 04/06/14 dispatch a enlever
function(){
console.log("persist task success" + task);
$scope.todo.stockedNewTasks.shift();
@@ -401,7 +403,7 @@
//On change la date au dernier acces
task["modificationDate"]=$scope.taskAccess;
- serverTaskAccess.update(angular.toJson(task),
+ serverTaskAccess.update({dispatch:true},angular.toJson(task), //TODO
function(){
console.log("update task success" + task);
$scope.todo.stockedEditedTasks.shift();
@@ -472,7 +474,7 @@
$scope.data.tasks[newTask.taskId] = newTask;
//On synchronise la tache creer
- serverTaskAccess.create(angular.toJson(newTask),
+ serverTaskAccess.create({dispatch:true}, angular.toJson(newTask), //TODO obruce 04/06/14 dispatch a enlever
function(){
console.log("persist task success" + newTask);
$scope.todo.stockedNewTasks.shift();
@@ -501,7 +503,7 @@
$scope.data.tasks[newTask.taskId] = newTask;
//On synchronise la tache creer
- serverTaskAccess.create(angular.toJson(newTask),
+ serverTaskAccess.create({dispatch:true}, angular.toJson(newTask), //TODO obruce 04/06/14 dispatch a enlever
function(){
console.log("persist task success" + newTask);
$scope.todo.stockedNewTasks.shift();
@@ -533,7 +535,7 @@
delete $scope.todo.stockedNewTimes[task.taskId];
- serverTaskAccess.deleteTask({taskId: task.taskId}, function(){
+ serverTaskAccess.deleteTask({taskId: task.taskId, dispatch:true}, function(){
console.log("delete success" + task.taskId);
},
function(){
1
0
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
by obruce@users.chorem.org 03 Jun '14
by obruce@users.chorem.org 03 Jun '14
03 Jun '14
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
*/
1
0