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
- 639 discussions
r3002 - in branches/ng-jtimer/src/main: java/org/chorem/jtimer/storage java/org/chorem/jtimer/utils java/org/chorem/jtimer/web resources webapp/js webapp/partials
by obruce@users.chorem.org 17 Jun '14
by obruce@users.chorem.org 17 Jun '14
17 Jun '14
Author: obruce
Date: 2014-06-17 18:02:11 +0200 (Tue, 17 Jun 2014)
New Revision: 3002
Url: http://forge.chorem.org/projects/jtimer/repository/revisions/3002
Log:
Ajout mustache par projet avec sous tache
Added:
branches/ng-jtimer/src/main/java/org/chorem/jtimer/utils/MustacheHandler.java
Modified:
branches/ng-jtimer/src/main/java/org/chorem/jtimer/storage/Storage.java
branches/ng-jtimer/src/main/java/org/chorem/jtimer/utils/MustacheReport.java
branches/ng-jtimer/src/main/java/org/chorem/jtimer/utils/ReportTask.java
branches/ng-jtimer/src/main/java/org/chorem/jtimer/web/ReportResource.java
branches/ng-jtimer/src/main/resources/ByDay_template.mustache
branches/ng-jtimer/src/main/resources/ByProject.mustache
branches/ng-jtimer/src/main/resources/subtasks.mustache
branches/ng-jtimer/src/main/webapp/js/app.js
branches/ng-jtimer/src/main/webapp/js/controllers.js
branches/ng-jtimer/src/main/webapp/js/service.js
branches/ng-jtimer/src/main/webapp/partials/reportModal.html
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-16 15:37:22 UTC (rev 3001)
+++ branches/ng-jtimer/src/main/java/org/chorem/jtimer/storage/Storage.java 2014-06-17 16:02:11 UTC (rev 3002)
@@ -1,6 +1,5 @@
package org.chorem.jtimer.storage;
-import org.apache.commons.lang3.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.chorem.jtimer.entities.TimerTask;
@@ -510,31 +509,40 @@
}
public List getReportByProject(Long startDate, Long endDate){
- List list = new ArrayList<ReportTask>();
+
+ List list = new ArrayList<ReportTask>();
PreparedStatement statement = null;
+ PreparedStatement statement2 = null;
try{
- statement = connection.prepareStatement("SELECT TA.name AS task, TA.parent AS parent, sum(TI.duration) AS totalduration" +
- " FROM " + TABLE_TASK+" TA," + TABLE_TIME +" TI" +
- " WHERE TA.taskId = TI.taskid" +
- " AND TA.modificationDate >" + startDate +
- " AND TA.modificationDate <" + endDate +
- " GROUP BY TA.taskId");
+ statement = connection.prepareStatement(
+ "SELECT TA.taskId AS taskid, TA.name AS task, TA.parent AS parent, sum(TI.duration) AS totalduration" +
+ " FROM " + TABLE_TASK+" TA," + TABLE_TIME +" TI" +
+ " WHERE TA.taskId = TI.taskid" +
+ " AND TA.modificationDate >" + startDate +
+ " AND TA.modificationDate <" + endDate +
+ " GROUP BY TA.taskId");
ResultSet rs = statement.executeQuery();
while(rs.next()){
- log.info("getReport");
- if(StringUtils.isNotBlank(rs.getString("parent"))){
+ list.add(new ReportTask(rs.getString("task"),rs.getString("taskid"), rs.getString("parent") , rs.getLong("totalduration")));
+ }
- }else{
- list.add(new ReportTask(rs.getString("task"), rs.getLong("totalduration")));
- }
+ // not timed tasks
+ statement2 = connection.prepareStatement("SELECT * FROM " + TABLE_TASK +
+ " WHERE (taskId not in (SELECT taskid FROM " + TABLE_TIME + ")" +
+ " AND parent = '' )"
+ );
+ rs = statement2.executeQuery();
+ while(rs.next()){
+ list.add(new ReportTask(rs.getString("name"), rs.getString("taskId"),rs.getString("parent"), (long) 0));
}
}catch(SQLException ex) {
throw new StorageException("Can't get report", ex);
} finally {
closeStatement(statement);
+ closeStatement(statement2);
}
return list;
Added: branches/ng-jtimer/src/main/java/org/chorem/jtimer/utils/MustacheHandler.java
===================================================================
--- branches/ng-jtimer/src/main/java/org/chorem/jtimer/utils/MustacheHandler.java (rev 0)
+++ branches/ng-jtimer/src/main/java/org/chorem/jtimer/utils/MustacheHandler.java 2014-06-17 16:02:11 UTC (rev 3002)
@@ -0,0 +1,67 @@
+package org.chorem.jtimer.utils;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+
+/**
+ * Created by olivia on 17/06/14.
+ * <p/>
+ * Project name : jtimer
+ * <p/>
+ * Package name : org.chorem.jtimer.utils
+ */
+public class MustacheHandler {
+
+ protected static final Log log = LogFactory.getLog(MustacheReport.class);
+
+ List<ReportTask> tasks;
+
+ List tasks() {
+ //On tri les taches avant de les envoyer au template
+ HashMap<String, ArrayList<ReportTask>> map = new HashMap<String,ArrayList<ReportTask>>();
+
+ Iterator iter = tasks.iterator();
+ while(iter.hasNext()) {
+
+ ReportTask t = (ReportTask)iter.next();
+
+ //un enfant dans map
+ if(map.containsKey(t.getTaskId())){
+ for(ReportTask task :map.get(t.getTaskId()))
+ t.addChild(task);
+ }
+
+ //un enfant
+ if(!t.getParent().equals("")){
+ log.info("enfant");
+ //On ajoute l'enfant à la map
+ ArrayList tmp = new ArrayList();
+
+ if(map.get(t.parent) != null){
+ tmp=map.get(t.parent);
+ }
+ tmp.add(t);
+
+ map.put(t.parent, tmp);
+ iter.remove();
+ }
+ }
+
+ return tasks;
+ }
+
+
+ /**
+ * Constructeur
+ * @param mustacheList la liste des taches
+ */
+ public MustacheHandler(List<ReportTask> mustacheList){
+ this.tasks = mustacheList;
+ }
+
+}
Modified: branches/ng-jtimer/src/main/java/org/chorem/jtimer/utils/MustacheReport.java
===================================================================
--- branches/ng-jtimer/src/main/java/org/chorem/jtimer/utils/MustacheReport.java 2014-06-16 15:37:22 UTC (rev 3001)
+++ branches/ng-jtimer/src/main/java/org/chorem/jtimer/utils/MustacheReport.java 2014-06-17 16:02:11 UTC (rev 3002)
@@ -22,42 +22,41 @@
public class MustacheReport {
protected static final Log log = LogFactory.getLog(MustacheReport.class);
- //Storage
- protected Storage storage;
+
protected Context context;
- //Borne
- protected long start;
- protected long end;
+ protected List mustacheList;
- List tasks() {
- return storage.getReportByProject(start, end);
- }
/**
* Default Constructor
* @param context
*/
- public MustacheReport(Context context, long start, long end){
+ public MustacheReport(Context context){
this.context = context;
- storage = (Storage)context.getAttributes().get(Storage.class.getName());
- this.start = start;
- this.end = end;
}
/**
* Methode qui cree une moustache
* @throws IOException
*/
- public String createMustache() throws IOException {
+ public String createByProjectMustache(String type, long start, long end) throws IOException {
- log.info("create a Mustache"+start + " " +end);
+ log.info("create a Mustache "+start + " " +end);
MustacheFactory mf = new DefaultMustacheFactory();
Mustache mustache = mf.compile("ByProject.mustache");
+ //On recupere les taches
+ Storage storage = (Storage) context.getAttributes().get(Storage.class.getName());
+ mustacheList = storage.getReportByProject(start, end);
+
StringWriter sw = new StringWriter();
- mustache.execute(sw,new MustacheReport(context,start,end)).flush();
+ mustache.execute(sw, new MustacheHandler(mustacheList)).flush();
return sw.toString();
}
+
+ public String createByDayMustache(String type, long startDate, long endDate) {
+ return null;
+ }
}
Modified: branches/ng-jtimer/src/main/java/org/chorem/jtimer/utils/ReportTask.java
===================================================================
--- branches/ng-jtimer/src/main/java/org/chorem/jtimer/utils/ReportTask.java 2014-06-16 15:37:22 UTC (rev 3001)
+++ branches/ng-jtimer/src/main/java/org/chorem/jtimer/utils/ReportTask.java 2014-06-17 16:02:11 UTC (rev 3002)
@@ -13,15 +13,60 @@
public class ReportTask {
/** Le nom de la tache*/
- String name;
+ protected String name;
+ protected String taskId;
+ protected String parent;
+ protected long time;
+ protected List subtasks;
- long time;
- List children;
-
- public ReportTask(String name, long time){
+ /**
+ * Constructeur
+ * @param name le nom
+ * @param taskId l'identifiant
+ * @param parent l'identifiant du parent
+ * @param time le temps
+ */
+ public ReportTask(String name, String taskId, String parent, long time){
+ this.taskId = taskId;
this.name = name;
+ this.parent = parent;
this.time = time;
- children = new ArrayList();
+
+ this.subtasks = new ArrayList();
}
+ /** Ajout */
+ public void addChild(ReportTask t){
+ this.subtasks.add(t);
+ this.time += t.getTime();
+ }
+
+ /**Getter */
+
+ public String getTaskId() {
+ return taskId;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public String getParent() {
+ return parent;
+ }
+
+ public long getTime() {
+ return time;
+ }
+
+ @Override
+ public String toString() {
+ return "ReportTask{" +
+ "name='" + name + '\'' +
+ ", taskId='" + taskId + '\'' +
+ ", parent='" + parent + '\'' +
+ ", time=" + time +
+ ", subtasks=" + subtasks +
+ '}';
+ }
}
Modified: branches/ng-jtimer/src/main/java/org/chorem/jtimer/web/ReportResource.java
===================================================================
--- branches/ng-jtimer/src/main/java/org/chorem/jtimer/web/ReportResource.java 2014-06-16 15:37:22 UTC (rev 3001)
+++ branches/ng-jtimer/src/main/java/org/chorem/jtimer/web/ReportResource.java 2014-06-17 16:02:11 UTC (rev 3002)
@@ -30,8 +30,6 @@
@Get
public Representation getReport() throws IOException {
- log.info("Passage dans get report");
-
String type ="BY_PROJECT";
String res="";
long startDate = (long) 0;
@@ -39,20 +37,31 @@
try {
type = String.valueOf(getQuery().getValues("type"));
+ } catch (Exception e) {
+ log.info("type non present dans l'url" + e);
+ }
+ try {
startDate = Long.valueOf(getQuery().getValues("startDate"));
+ } catch (Exception e) {
+ log.info("type non present dans l'url" + e);
+ }
+ try {
endDate = Long.valueOf(getQuery().getValues("endDate"));
} catch (Exception e) {
- log.error("Parametre non present dans l'url" + e);
+ log.info("type non present dans l'url" + e);
}
- MustacheReport report = new MustacheReport(getContext(), startDate, endDate);
+ MustacheReport report = new MustacheReport(getContext());
- if(type.equals("BY_PROJECT")){
- res = report.createMustache();
- log.info("Ce qui est produit " + res);
- }
+ res = report.createByProjectMustache(type, startDate, endDate);
+ log.info("Ce qui est produit " + res);
- return new StringRepresentation(res, MediaType.APPLICATION_JSON);
+ res = report.createByDayMustache(type, startDate, endDate);
+ log.info("Ce qui est produit " + res);
+
+
+
+ return new StringRepresentation(res, MediaType.TEXT_JAVASCRIPT);
}
}
\ No newline at end of file
Modified: branches/ng-jtimer/src/main/resources/ByDay_template.mustache
===================================================================
--- branches/ng-jtimer/src/main/resources/ByDay_template.mustache 2014-06-16 15:37:22 UTC (rev 3001)
+++ branches/ng-jtimer/src/main/resources/ByDay_template.mustache 2014-06-17 16:02:11 UTC (rev 3002)
@@ -1,8 +1,8 @@
+Rapport
+=======
+
{{#days}}
- Day : {{day}}
- {{#tasks}}
- Name : {{name}} | Time : {{time}}
- {{> subtasks}}
- {{/tasks}}
+ Jour : {{day}}
+ {{>ByProject}}
{{/days}}
Modified: branches/ng-jtimer/src/main/resources/ByProject.mustache
===================================================================
--- branches/ng-jtimer/src/main/resources/ByProject.mustache 2014-06-16 15:37:22 UTC (rev 3001)
+++ branches/ng-jtimer/src/main/resources/ByProject.mustache 2014-06-17 16:02:11 UTC (rev 3002)
@@ -1,7 +1,13 @@
-Report by project :
-===================
+Rapport:
+========
+<hr/>
{{#tasks}}
- -{{name}} temps : {{time}}
- {{>subtasks}}
-{{/tasks}}
\ No newline at end of file
+<b>Projet : {{name}}</b>
+
+{{>subtasks}}
+
+Temps total : {{time}}|time
+
+<hr/>
+{{/tasks}}
Modified: branches/ng-jtimer/src/main/resources/subtasks.mustache
===================================================================
--- branches/ng-jtimer/src/main/resources/subtasks.mustache 2014-06-16 15:37:22 UTC (rev 3001)
+++ branches/ng-jtimer/src/main/resources/subtasks.mustache 2014-06-17 16:02:11 UTC (rev 3002)
@@ -1,4 +1,4 @@
{{#subtasks}}
- -{{name}} temps : {{time}}
- {{> subtasks}}
+ -{{name}} temps : {{time}}|time
+ {{> subtasks}}
{{/subtasks}}
\ No newline at end of file
Modified: branches/ng-jtimer/src/main/webapp/js/app.js
===================================================================
--- branches/ng-jtimer/src/main/webapp/js/app.js 2014-06-16 15:37:22 UTC (rev 3001)
+++ branches/ng-jtimer/src/main/webapp/js/app.js 2014-06-17 16:02:11 UTC (rev 3002)
@@ -306,7 +306,7 @@
/**
* Module de webtimer
**/
-angular.module('webtimer', ['webtimerFilters', 'ngRoute', 'ngAnimate', 'ui.bootstrap','serverAccessService', 'serverTimeService' ])
+angular.module('webtimer', ['webtimerFilters', 'ngRoute', 'ngAnimate', 'ui.bootstrap','serverAccessService', 'serverTimeService','serverReportService' ])
.config(['$routeProvider', function($routeProvider) {
$routeProvider.
when('/tasks', {templateUrl: 'partials/tasks.html', controller: TasksCtrl}).
Modified: branches/ng-jtimer/src/main/webapp/js/controllers.js
===================================================================
--- branches/ng-jtimer/src/main/webapp/js/controllers.js 2014-06-16 15:37:22 UTC (rev 3001)
+++ branches/ng-jtimer/src/main/webapp/js/controllers.js 2014-06-17 16:02:11 UTC (rev 3002)
@@ -964,7 +964,7 @@
};
}
-function ReportModalInstanceCtrl($scope, $modalInstance, times, tasks){
+function ReportModalInstanceCtrl($scope, $modalInstance, times, tasks, serverReportAccess){
$scope.obj={
startDate : new Date(),
@@ -973,8 +973,9 @@
};
$scope.radioModel = '5';
+ $scope.htmlReport="";
- $scope.generateReport= function(){
+ /*$scope.generateReport= function(){
report = [];
angular.forEach(times, function(timeArray,task){
@@ -994,6 +995,14 @@
});
+ }*/
+
+ $scope.generateReport= function(){
+ serverReportAccess.get({}, function(response){
+ console.log(response);
+ $scope.htmlReport = response;
+ }
+ );
}
Modified: branches/ng-jtimer/src/main/webapp/js/service.js
===================================================================
--- branches/ng-jtimer/src/main/webapp/js/service.js 2014-06-16 15:37:22 UTC (rev 3001)
+++ branches/ng-jtimer/src/main/webapp/js/service.js 2014-06-17 16:02:11 UTC (rev 3002)
@@ -31,3 +31,14 @@
);
}
);
+
+angular.module("serverReportService", ["ngResource"])
+.factory("serverReportAccess", function ( $resource) {
+ // Encapsule l'acces au server
+ return $resource("/rest/report",{},
+ {
+ get : {method: 'GET', isArray: false},
+ }
+ );
+ }
+);
\ No newline at end of file
Modified: branches/ng-jtimer/src/main/webapp/partials/reportModal.html
===================================================================
--- branches/ng-jtimer/src/main/webapp/partials/reportModal.html 2014-06-16 15:37:22 UTC (rev 3001)
+++ branches/ng-jtimer/src/main/webapp/partials/reportModal.html 2014-06-17 16:02:11 UTC (rev 3002)
@@ -50,11 +50,12 @@
<div>
<alert type="info" >
- Rapport :<br/>
+ <!--Rapport :<br/>
=========
<div ng-repeat="elem in obj.report">
{{elem.task}} : {{elem.time | time}}
- </div>
+ </div>-->
+ {{htmlReport}}
</alert>
</div>
1
0
r3001 - in branches/ng-jtimer: . src/main/java/org/chorem/jtimer src/main/java/org/chorem/jtimer/storage src/main/java/org/chorem/jtimer/utils src/main/java/org/chorem/jtimer/web src/main/resources src/main/webapp/js src/main/webapp/partials
by obruce@users.chorem.org 16 Jun '14
by obruce@users.chorem.org 16 Jun '14
16 Jun '14
Author: obruce
Date: 2014-06-16 17:37:22 +0200 (Mon, 16 Jun 2014)
New Revision: 3001
Url: http://forge.chorem.org/projects/jtimer/repository/revisions/3001
Log:
Ajout d'un petit peu de moustache (en cours) pour le rapport
Added:
branches/ng-jtimer/src/main/java/org/chorem/jtimer/utils/
branches/ng-jtimer/src/main/java/org/chorem/jtimer/utils/MustacheReport.java
branches/ng-jtimer/src/main/java/org/chorem/jtimer/utils/ReportTask.java
branches/ng-jtimer/src/main/resources/ByDay_template.mustache
branches/ng-jtimer/src/main/resources/ByProject.mustache
branches/ng-jtimer/src/main/resources/subtasks.mustache
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/ReportResource.java
branches/ng-jtimer/src/main/java/org/chorem/jtimer/web/RestApplication.java
branches/ng-jtimer/src/main/resources/jtimer-default.properties
branches/ng-jtimer/src/main/webapp/js/app.js
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-13 15:23:28 UTC (rev 3000)
+++ branches/ng-jtimer/pom.xml 2014-06-16 15:37:22 UTC (rev 3001)
@@ -161,7 +161,12 @@
</build>
<dependencies>
- <dependency>
+ <dependency>
+ <groupId>com.github.spullara.mustache.java</groupId>
+ <artifactId>compiler</artifactId>
+ <version>0.8.15</version>
+ </dependency>
+ <dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
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-13 15:23:28 UTC (rev 3000)
+++ branches/ng-jtimer/src/main/java/org/chorem/jtimer/storage/Storage.java 2014-06-16 15:37:22 UTC (rev 3001)
@@ -1,9 +1,11 @@
package org.chorem.jtimer.storage;
+import org.apache.commons.lang3.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.chorem.jtimer.entities.TimerTask;
import org.chorem.jtimer.entities.TimerTime;
+import org.chorem.jtimer.utils.ReportTask;
import java.sql.Connection;
import java.sql.DriverManager;
@@ -507,12 +509,11 @@
return times;
}
- public String getRepportByProject(Long startDate, Long endDate){
- String res = "Rapport\n ========== \n";
- long tot = (long) 0;
+ public List getReportByProject(Long startDate, Long endDate){
+ List list = new ArrayList<ReportTask>();
PreparedStatement statement = null;
try{
- statement = connection.prepareStatement("SELECT TA.name AS task, sum(TI.duration) AS totalduration" +
+ statement = connection.prepareStatement("SELECT TA.name AS task, TA.parent AS parent, sum(TI.duration) AS totalduration" +
" FROM " + TABLE_TASK+" TA," + TABLE_TIME +" TI" +
" WHERE TA.taskId = TI.taskid" +
" AND TA.modificationDate >" + startDate +
@@ -521,18 +522,22 @@
ResultSet rs = statement.executeQuery();
while(rs.next()){
- res += rs.getString("task") + " : " +rs.getLong("totalduration") + ", \n";
- tot += rs.getLong("totalduration");
+ log.info("getReport");
+ if(StringUtils.isNotBlank(rs.getString("parent"))){
+
+ }else{
+ list.add(new ReportTask(rs.getString("task"), rs.getLong("totalduration")));
+ }
+
}
- res +="Totale : " + tot;
}catch(SQLException ex) {
throw new StorageException("Can't get report", ex);
} finally {
closeStatement(statement);
}
- return res;
+ return list;
}
Added: branches/ng-jtimer/src/main/java/org/chorem/jtimer/utils/MustacheReport.java
===================================================================
--- branches/ng-jtimer/src/main/java/org/chorem/jtimer/utils/MustacheReport.java (rev 0)
+++ branches/ng-jtimer/src/main/java/org/chorem/jtimer/utils/MustacheReport.java 2014-06-16 15:37:22 UTC (rev 3001)
@@ -0,0 +1,63 @@
+package org.chorem.jtimer.utils;
+
+import com.github.mustachejava.DefaultMustacheFactory;
+import com.github.mustachejava.Mustache;
+import com.github.mustachejava.MustacheFactory;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.chorem.jtimer.storage.Storage;
+import org.restlet.Context;
+
+import java.io.IOException;
+import java.io.StringWriter;
+import java.util.List;
+
+/**
+ * Created by olivia on 16/06/14.
+ * <p/>
+ * Project name : jtimer
+ * <p/>
+ * Package name : org.chorem.jtimer.utils
+ */
+public class MustacheReport {
+
+ protected static final Log log = LogFactory.getLog(MustacheReport.class);
+ //Storage
+ protected Storage storage;
+ protected Context context;
+ //Borne
+ protected long start;
+ protected long end;
+
+ List tasks() {
+ return storage.getReportByProject(start, end);
+ }
+
+ /**
+ * Default Constructor
+ * @param context
+ */
+ public MustacheReport(Context context, long start, long end){
+ this.context = context;
+ storage = (Storage)context.getAttributes().get(Storage.class.getName());
+ this.start = start;
+ this.end = end;
+ }
+
+ /**
+ * Methode qui cree une moustache
+ * @throws IOException
+ */
+ public String createMustache() throws IOException {
+
+ log.info("create a Mustache"+start + " " +end);
+ MustacheFactory mf = new DefaultMustacheFactory();
+ Mustache mustache = mf.compile("ByProject.mustache");
+
+ StringWriter sw = new StringWriter();
+ mustache.execute(sw,new MustacheReport(context,start,end)).flush();
+
+ return sw.toString();
+ }
+
+}
Added: branches/ng-jtimer/src/main/java/org/chorem/jtimer/utils/ReportTask.java
===================================================================
--- branches/ng-jtimer/src/main/java/org/chorem/jtimer/utils/ReportTask.java (rev 0)
+++ branches/ng-jtimer/src/main/java/org/chorem/jtimer/utils/ReportTask.java 2014-06-16 15:37:22 UTC (rev 3001)
@@ -0,0 +1,27 @@
+package org.chorem.jtimer.utils;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Created by olivia on 16/06/14.
+ * <p/>
+ * Project name : jtimer
+ * <p/>
+ * Package name : org.chorem.jtimer.utils
+ */
+public class ReportTask {
+
+ /** Le nom de la tache*/
+ String name;
+
+ long time;
+ List children;
+
+ public ReportTask(String name, long time){
+ this.name = name;
+ this.time = time;
+ children = new ArrayList();
+ }
+
+}
Modified: branches/ng-jtimer/src/main/java/org/chorem/jtimer/web/ReportResource.java
===================================================================
--- branches/ng-jtimer/src/main/java/org/chorem/jtimer/web/ReportResource.java 2014-06-13 15:23:28 UTC (rev 3000)
+++ branches/ng-jtimer/src/main/java/org/chorem/jtimer/web/ReportResource.java 2014-06-16 15:37:22 UTC (rev 3001)
@@ -1,8 +1,15 @@
package org.chorem.jtimer.web;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.chorem.jtimer.utils.MustacheReport;
+import org.restlet.data.MediaType;
import org.restlet.representation.Representation;
+import org.restlet.representation.StringRepresentation;
import org.restlet.resource.Get;
+import java.io.IOException;
+
/**
* Created by olivia on 11/06/14.
* <p/>
@@ -12,44 +19,40 @@
*/
public class ReportResource extends AbstractResource {
+ protected static final Log log = LogFactory.getLog(ReportResource.class);
+
/**
* Methode qui retourne la representation du rapport
* Suite a une requete de type GET
*
* @return representation du rapport
*/
- @Get("json")
- public Representation getReport() {
+ @Get
+ public Representation getReport() throws IOException {
- String type ="";
+ log.info("Passage dans get report");
+ String type ="BY_PROJECT";
+ String res="";
+ long startDate = (long) 0;
+ long endDate = Long.MAX_VALUE;
+
try {
type = String.valueOf(getQuery().getValues("type"));
+ startDate = Long.valueOf(getQuery().getValues("startDate"));
+ endDate = Long.valueOf(getQuery().getValues("endDate"));
} catch (Exception e) {
- e.printStackTrace();
+ log.error("Parametre non present dans l'url" + e);
}
- switch (type){
- case "BY_DAY":
- break;
+ MustacheReport report = new MustacheReport(getContext(), startDate, endDate);
- case "BY_WEEK":
- break;
- case "BY_MONTH":
- break;
-
- case "BY_YEAR":
- break;
-
- case "BY_PROJECT":
- break;
-
- default:
- //By project
- break;
+ if(type.equals("BY_PROJECT")){
+ res = report.createMustache();
+ log.info("Ce qui est produit " + res);
}
- return null;
+ return new StringRepresentation(res, MediaType.APPLICATION_JSON);
}
}
\ No newline at end of file
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-13 15:23:28 UTC (rev 3000)
+++ branches/ng-jtimer/src/main/java/org/chorem/jtimer/web/RestApplication.java 2014-06-16 15:37:22 UTC (rev 3001)
@@ -23,10 +23,11 @@
/** Resource qui va pousser les elements vers d'autres serveurs */
protected TiersServerResource tiers = new TiersServerResource();
+
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;
@@ -55,7 +56,7 @@
router.attach("/tasks/task/{taskId}", TaskResource.class);
router.attach("/tasks/time/{taskId}", TimeResource.class);
router.attach("/tasks/time", TimesResource.class);
- router.attach("/tasks/report", ReportResource.class);
+ router.attach("/report", ReportResource.class);
//router.attach("/tiers", TiersServerResource.class);
Added: branches/ng-jtimer/src/main/resources/ByDay_template.mustache
===================================================================
--- branches/ng-jtimer/src/main/resources/ByDay_template.mustache (rev 0)
+++ branches/ng-jtimer/src/main/resources/ByDay_template.mustache 2014-06-16 15:37:22 UTC (rev 3001)
@@ -0,0 +1,8 @@
+{{#days}}
+ Day : {{day}}
+ {{#tasks}}
+ Name : {{name}} | Time : {{time}}
+ {{> subtasks}}
+ {{/tasks}}
+{{/days}}
+
Added: branches/ng-jtimer/src/main/resources/ByProject.mustache
===================================================================
--- branches/ng-jtimer/src/main/resources/ByProject.mustache (rev 0)
+++ branches/ng-jtimer/src/main/resources/ByProject.mustache 2014-06-16 15:37:22 UTC (rev 3001)
@@ -0,0 +1,7 @@
+Report by project :
+===================
+
+{{#tasks}}
+ -{{name}} temps : {{time}}
+ {{>subtasks}}
+{{/tasks}}
\ No newline at end of file
Modified: branches/ng-jtimer/src/main/resources/jtimer-default.properties
===================================================================
--- branches/ng-jtimer/src/main/resources/jtimer-default.properties 2014-06-13 15:23:28 UTC (rev 3000)
+++ branches/ng-jtimer/src/main/resources/jtimer-default.properties 2014-06-16 15:37:22 UTC (rev 3001)
@@ -2,5 +2,5 @@
# jTimer default properties
###
# jTimer storage path
-jtimer.storage.path=/home/olivia/Bureau/jtimer/jtimer/jtimer8081
+jtimer.storage.path=/tmp/jtimer/jtimer8081
Added: branches/ng-jtimer/src/main/resources/subtasks.mustache
===================================================================
--- branches/ng-jtimer/src/main/resources/subtasks.mustache (rev 0)
+++ branches/ng-jtimer/src/main/resources/subtasks.mustache 2014-06-16 15:37:22 UTC (rev 3001)
@@ -0,0 +1,4 @@
+{{#subtasks}}
+ -{{name}} temps : {{time}}
+ {{> subtasks}}
+{{/subtasks}}
\ No newline at end of file
Modified: branches/ng-jtimer/src/main/webapp/js/app.js
===================================================================
--- branches/ng-jtimer/src/main/webapp/js/app.js 2014-06-13 15:23:28 UTC (rev 3000)
+++ branches/ng-jtimer/src/main/webapp/js/app.js 2014-06-16 15:37:22 UTC (rev 3001)
@@ -258,8 +258,8 @@
service.callback.status(true);
};
- ws.onerror = function() {
- console.log('Websocket error');
+ ws.onerror = function(evt) {
+ console.log('Websocket error' + evt);
};
ws.onclose = function() {
Modified: branches/ng-jtimer/src/main/webapp/js/controllers.js
===================================================================
--- branches/ng-jtimer/src/main/webapp/js/controllers.js 2014-06-13 15:23:28 UTC (rev 3000)
+++ branches/ng-jtimer/src/main/webapp/js/controllers.js 2014-06-16 15:37:22 UTC (rev 3001)
@@ -713,6 +713,11 @@
save();
};
+ /** Methode qui va tenter d'envoyer la tâche vers le serveur */
+ $scope.persistToServ = function(task){
+
+ };
+
/**
* Active/desactive le comptage de temps pour une tache
* @param {type} task
@@ -771,12 +776,6 @@
}
});
-
- var testWebsocket = function(){
- jTimerWebsocket.send(JSON.stringify($scope.data.tasks));
- console.log("un message est envoyé websocket")
- };
-
/** Idleness*/
/**
@@ -945,11 +944,7 @@
// connect to webscocket server (go client)
wtWebsocket.connect();
- jTimerWebsocket.connect();
- testWebsocket();
-
-
}
Modified: branches/ng-jtimer/src/main/webapp/partials/tasks.html
===================================================================
--- branches/ng-jtimer/src/main/webapp/partials/tasks.html 2014-06-13 15:23:28 UTC (rev 3000)
+++ branches/ng-jtimer/src/main/webapp/partials/tasks.html 2014-06-16 15:37:22 UTC (rev 3001)
@@ -90,7 +90,9 @@
ng-show="!$node.task.isRoot() ">
<i class="glyphicon glyphicon-pencil" ></i>
</a>
-
+ <a class="btn btn-default btn-xs" ng-click="persistToServ($node.task)">
+ <i class="glyphicon glyphicon-floppy-disk" ></i>
+ </a>
</span>
</div>
1
0
r3000 - in branches/ng-jtimer: . src/main/java/org/chorem/jtimer/storage src/main/java/org/chorem/jtimer/web src/main/java/org/chorem/jtimer/web/websocket src/main/resources src/main/webapp src/main/webapp/css src/main/webapp/js src/main/webapp/partials
by obruce@users.chorem.org 13 Jun '14
by obruce@users.chorem.org 13 Jun '14
13 Jun '14
Author: obruce
Date: 2014-06-13 17:23:28 +0200 (Fri, 13 Jun 2014)
New Revision: 3000
Url: http://forge.chorem.org/projects/jtimer/repository/revisions/3000
Log:
Ajout jettywebsocket avec un simple echo
Added:
branches/ng-jtimer/src/main/java/org/chorem/jtimer/web/websocket/
branches/ng-jtimer/src/main/java/org/chorem/jtimer/web/websocket/WebsocketHandler.java
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/ReportResource.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/java/org/chorem/jtimer/web/TimesResource.java
branches/ng-jtimer/src/main/resources/jtimer-default.properties
branches/ng-jtimer/src/main/webapp/css/app.css
branches/ng-jtimer/src/main/webapp/js/app.js
branches/ng-jtimer/src/main/webapp/js/controllers.js
branches/ng-jtimer/src/main/webapp/partials/reportModal.html
branches/ng-jtimer/src/main/webapp/partials/tasks.html
branches/ng-jtimer/src/main/webapp/webtimer.appcache
Modified: branches/ng-jtimer/pom.xml
===================================================================
--- branches/ng-jtimer/pom.xml 2014-06-11 15:48:49 UTC (rev 2999)
+++ branches/ng-jtimer/pom.xml 2014-06-13 15:23:28 UTC (rev 3000)
@@ -34,7 +34,7 @@
<restletVersion>2.2.1</restletVersion>
<gsonVersion>2.2.4</gsonVersion>
<h2Version>1.4.178</h2Version>
- <jettyVersion>9.1.5.v20140505</jettyVersion>
+ <jettyVersion>9.2.1.v20140609</jettyVersion>
</properties>
<build>
@@ -116,7 +116,7 @@
<version>${jettyVersion}</version>
<configuration>
<httpConnector>
- <port>8080</port>
+ <port>8081</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-11 15:48:49 UTC (rev 2999)
+++ branches/ng-jtimer/src/main/java/org/chorem/jtimer/storage/Storage.java 2014-06-13 15:23:28 UTC (rev 3000)
@@ -253,7 +253,59 @@
return tasks;
}
+ /**
+ * Query that returns not removed tasks
+ * @return tasks arraylist of tasks
+ */
+ public ArrayList<TimerTask> getRemovedTasks(Long date) {
+ ArrayList<TimerTask> tasks = new ArrayList<>();
+ PreparedStatement statement = null;
+ PreparedStatement statement2 = null;
+ try {
+ statement = connection.prepareStatement("SELECT TA.*, sum(TI.duration) AS totalduration FROM " +
+ TABLE_TASK + " TA, " + TABLE_TIME + " TI" +
+ " WHERE TA.taskId = TI.taskid" +
+ " AND TA.removed > 0"+
+ " GROUP BY TA.taskId");
+ ResultSet rs = statement.executeQuery();
+ while (rs.next()) {
+ TimerTask task = new TimerTask();
+ task.setTaskId(rs.getString("taskId"));
+ task.setName(rs.getString("name"));
+ task.setParent(rs.getString("parent"));
+ task.setRemoved(rs.getLong("removed"));
+ task.setTodayTime(0);
+ task.setModificationDate(new java.util.Date(rs.getLong("modificationDate")));
+ task.setTotalTime(rs.getLong("totalduration"));
+ tasks.add(task);
+ }
+ // not timed tasks
+ statement2 = connection.prepareStatement("SELECT * FROM " + TABLE_TASK +
+ " 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.setName(rs.getString("name"));
+ task.setTaskId(rs.getString("taskId"));
+ task.setParent(rs.getString("parent"));
+ task.setModificationDate(new java.util.Date(rs.getLong("modificationDate")));
+ task.setRemoved(rs.getLong("removed"));
+ task.setTodayTime(0);
+ task.setTotalTime(0);
+ tasks.add(task);
+ }
+ } catch (SQLException ex) {
+ throw new StorageException("Can't get task", ex);
+ } finally {
+ closeStatement(statement);
+ closeStatement(statement2);
+ }
+ return tasks;
+ }
+
+
/* Insert, Update, Delete */
public void addTask(TimerTask task) {
Modified: branches/ng-jtimer/src/main/java/org/chorem/jtimer/web/ReportResource.java
===================================================================
--- branches/ng-jtimer/src/main/java/org/chorem/jtimer/web/ReportResource.java 2014-06-11 15:48:49 UTC (rev 2999)
+++ branches/ng-jtimer/src/main/java/org/chorem/jtimer/web/ReportResource.java 2014-06-13 15:23:28 UTC (rev 3000)
@@ -1,5 +1,8 @@
package org.chorem.jtimer.web;
+import org.restlet.representation.Representation;
+import org.restlet.resource.Get;
+
/**
* Created by olivia on 11/06/14.
* <p/>
@@ -7,5 +10,46 @@
* <p/>
* Package name : org.chorem.jtimer.web
*/
-public class ReportResource extends AbstractResource{
-}
+public class ReportResource extends AbstractResource {
+
+ /**
+ * Methode qui retourne la representation du rapport
+ * Suite a une requete de type GET
+ *
+ * @return representation du rapport
+ */
+ @Get("json")
+ public Representation getReport() {
+
+ String type ="";
+
+ try {
+ type = String.valueOf(getQuery().getValues("type"));
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ switch (type){
+ case "BY_DAY":
+ break;
+
+ case "BY_WEEK":
+ break;
+
+ case "BY_MONTH":
+ break;
+
+ case "BY_YEAR":
+ break;
+
+ case "BY_PROJECT":
+ break;
+
+ default:
+ //By project
+ break;
+ }
+
+ return null;
+ }
+}
\ No newline at end of file
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-11 15:48:49 UTC (rev 2999)
+++ branches/ng-jtimer/src/main/java/org/chorem/jtimer/web/RestApplication.java 2014-06-13 15:23:28 UTC (rev 3000)
@@ -26,7 +26,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;
/**Application configuration */
JtimerConfig jtimerConf;
@@ -58,12 +58,14 @@
router.attach("/tasks/report", ReportResource.class);
//router.attach("/tiers", TiersServerResource.class);
+
+
return router;
}
/**
* Initialise le context de l'application REST
- * @param context
+ * @param context le contexte de l'application
*/
protected void initContext(Context context) throws Exception {
@@ -168,7 +170,5 @@
}
}
- };
-
-
+ }
}
\ No newline at end of file
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-11 15:48:49 UTC (rev 2999)
+++ branches/ng-jtimer/src/main/java/org/chorem/jtimer/web/TasksResource.java 2014-06-13 15:23:28 UTC (rev 3000)
@@ -73,7 +73,7 @@
* Methode qui retourne la representation de la liste de toutes les taches
* Suite a une requete de type GET
*
- * @return
+ * @return reprentation des taches
*/
@Get("json")
public Representation getTasks() {
@@ -83,7 +83,9 @@
try {
date = Long.valueOf(getQuery().getValues("date"));
} catch (Exception e) {
- date = (long) 0;
+ if(log.isErrorEnabled()){
+ log.error("enttities.getTasks date revenu null");
+ }
}
ArrayList<TimerTask> timerTasks;
Gson gson = builder.create();
@@ -116,7 +118,7 @@
public void createTask(Representation representation) throws IOException {
Gson gson = builder.create();
- String repr1 = "";
+ String repr1;
dispatch = getDispatch();
@@ -139,7 +141,7 @@
/**
* Recupere la valeur de dispatch dans l'url
* TODO 04/06/14 obruce : remove this method when config will be available
- * @return
+ * @return la valeur du dispatch
*/
private boolean getDispatch() {
boolean res;
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-11 15:48:49 UTC (rev 2999)
+++ branches/ng-jtimer/src/main/java/org/chorem/jtimer/web/TimeResource.java 2014-06-13 15:23:28 UTC (rev 3000)
@@ -143,7 +143,9 @@
if (dispatch) {
String taskId = (String) getRequest().getAttributes().get("taskId");
Pair p = Pair.of(taskId, jsonRepr);
- log.info(" la pair cree" + p.toString()+ p.getKey().toString()+p.getValue().toString());
+
+ //log.info(" la pair cree" + p.toString()+ p.getKey().toString()+p.getValue().toString());
+
todoList.pushCreatedTime(p);
}
}
@@ -164,6 +166,10 @@
String jsonRepr = representation.getText();
TimerTime t = gson.fromJson(jsonRepr, TimerTime.class);
+ if (log.isInfoEnabled()) {
+ log.info("La periode suivante est en maj : " + t.toString());
+ }
+
storage.modifyTime(t);
if (dispatch) {
Modified: branches/ng-jtimer/src/main/java/org/chorem/jtimer/web/TimesResource.java
===================================================================
--- branches/ng-jtimer/src/main/java/org/chorem/jtimer/web/TimesResource.java 2014-06-11 15:48:49 UTC (rev 2999)
+++ branches/ng-jtimer/src/main/java/org/chorem/jtimer/web/TimesResource.java 2014-06-13 15:23:28 UTC (rev 3000)
@@ -86,10 +86,6 @@
String json = gson.toJson(timerTasks);
- if (log.isInfoEnabled()) {
- log.info(json);
- }
-
return new StringRepresentation(json, MediaType.APPLICATION_JSON);
}
Added: branches/ng-jtimer/src/main/java/org/chorem/jtimer/web/websocket/WebsocketHandler.java
===================================================================
--- branches/ng-jtimer/src/main/java/org/chorem/jtimer/web/websocket/WebsocketHandler.java (rev 0)
+++ branches/ng-jtimer/src/main/java/org/chorem/jtimer/web/websocket/WebsocketHandler.java 2014-06-13 15:23:28 UTC (rev 3000)
@@ -0,0 +1,62 @@
+package org.chorem.jtimer.web.websocket;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.eclipse.jetty.websocket.api.Session;
+import org.eclipse.jetty.websocket.api.annotations.OnWebSocketClose;
+import org.eclipse.jetty.websocket.api.annotations.OnWebSocketConnect;
+import org.eclipse.jetty.websocket.api.annotations.OnWebSocketError;
+import org.eclipse.jetty.websocket.api.annotations.OnWebSocketMessage;
+import org.eclipse.jetty.websocket.api.annotations.WebSocket;
+import org.eclipse.jetty.websocket.servlet.WebSocketServlet;
+import org.eclipse.jetty.websocket.servlet.WebSocketServletFactory;
+
+import javax.servlet.annotation.WebServlet;
+import java.io.IOException;
+
+/**
+ * Created by olivia on 12/06/14.
+ * <p/>
+ * Project name : jtimer
+ * <p/>
+ * Package name : org.chorem.jtimer.web.websocket
+ */
+
+@WebSocket
+@WebServlet(name = "MyEcho WebSocket Servlet", urlPatterns = { "/echo" })
+public class WebsocketHandler extends WebSocketServlet {
+
+
+ private static final Log log = LogFactory.getLog(WebsocketHandler.class);
+
+ @OnWebSocketClose
+ public void onClose(int statusCode, String reason) {
+ log.info("Close: statusCode=" + statusCode + ", reason=" + reason);
+ }
+
+ @OnWebSocketError
+ public void onError(Throwable t) throws Throwable {
+ throw t;
+ }
+
+ @OnWebSocketConnect
+ public void onConnect(Session session) {
+ log.info("Connect: " + session.getRemoteAddress().getAddress());
+ try {
+ session.getRemote().sendString("Hello World!");
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+
+ @OnWebSocketMessage
+ public void onMessage(String message) {
+ log.info("Message de l'interface : " + message);
+ }
+
+ @Override
+ public void configure(WebSocketServletFactory factory) {
+ factory.getPolicy().setIdleTimeout(10000);
+ factory.register(WebsocketHandler.class);
+ }
+}
Modified: branches/ng-jtimer/src/main/resources/jtimer-default.properties
===================================================================
--- branches/ng-jtimer/src/main/resources/jtimer-default.properties 2014-06-11 15:48:49 UTC (rev 2999)
+++ branches/ng-jtimer/src/main/resources/jtimer-default.properties 2014-06-13 15:23:28 UTC (rev 3000)
@@ -2,5 +2,5 @@
# jTimer default properties
###
# jTimer storage path
-jtimer.storage.path=/home/olivia/Bureau/jtimer/jtimer/jtimer
+jtimer.storage.path=/home/olivia/Bureau/jtimer/jtimer/jtimer8081
Modified: branches/ng-jtimer/src/main/webapp/css/app.css
===================================================================
--- branches/ng-jtimer/src/main/webapp/css/app.css 2014-06-11 15:48:49 UTC (rev 2999)
+++ branches/ng-jtimer/src/main/webapp/css/app.css 2014-06-13 15:23:28 UTC (rev 3000)
@@ -261,3 +261,11 @@
width : 50%;
margin : auto;
}
+
+.small_input{
+ width : 100px;
+}
+
+.medium_input{
+ width : 200px;
+}
\ No newline at end of file
Modified: branches/ng-jtimer/src/main/webapp/js/app.js
===================================================================
--- branches/ng-jtimer/src/main/webapp/js/app.js 2014-06-11 15:48:49 UTC (rev 2999)
+++ branches/ng-jtimer/src/main/webapp/js/app.js 2014-06-13 15:23:28 UTC (rev 3000)
@@ -242,8 +242,67 @@
return service;
}];
+/**
+ * Pour le websocket
+ */
+var wtJTIMERWebSocketService = [function() {
+ var service = {};
+ service.connect = function() {
+ if(service.ws) { return; }
+ var ws = new WebSocket("ws://localhost:8081/echo");
+
+ ws.onopen = function() {
+ console.log('Websocket open');
+ service.callback.status(true);
+ };
+
+ ws.onerror = function() {
+ console.log('Websocket error');
+ };
+
+ ws.onclose = function() {
+ service.callback.status(false);
+ console.log('Websocket closing');
+ };
+
+ ws.onmessage = function(message) {
+ console.log("Un message reçu venant du websocket :" + message.data)
+ };
+
+ service.ws = ws;
+ };
+
+ service.send = function(message) {
+ waitForConnection(function () {
+ service.ws.send(message);
+ if (typeof callback !== 'undefined') {
+ callback();
+ }
+ }, 1000);
+ };
+
+ service.subscribe = function(callback) {
+ service.callback = callback;
+ };
+
+ waitForConnection = function (callback, interval) {
+ if (service.ws.readyState === 1) {
+ callback();
+ } else {
+ var that = this;
+ setTimeout(function () {
+ that.waitForConnection(callback);
+ }, interval);
+ }
+ };
+
+ return service;
+}];
+
+
+
/**
* Module de webtimer
**/
@@ -295,7 +354,9 @@
.directive('wtTreeRepeat', wtTreeRepeatDirective)
.service('wtWebsocket', wtWebSocketService);
+angular.module('webtimer').factory('jTimerWebsocket', wtJTIMERWebSocketService);
+
/**
* Cette directive permet de confirmer/ infirmer une action.
* Usage: Ajouter attributs: ng-really-message="Êtes vous d'accord?" ng-really-click="takeAction()"
Modified: branches/ng-jtimer/src/main/webapp/js/controllers.js
===================================================================
--- branches/ng-jtimer/src/main/webapp/js/controllers.js 2014-06-11 15:48:49 UTC (rev 2999)
+++ branches/ng-jtimer/src/main/webapp/js/controllers.js 2014-06-13 15:23:28 UTC (rev 3000)
@@ -1,4 +1,4 @@
-function TasksCtrl($scope, $interval, $timeout, $q, serverTaskAccess, serverTimeAccess, $localStorage, $window, $document, $modal, wtWebsocket) {
+function TasksCtrl($scope, $interval, $timeout, $q, serverTaskAccess, serverTimeAccess, $localStorage, $window, $document, $modal, wtWebsocket, jTimerWebsocket) {
// {Boolean} vrai si on est online
$scope.online = $window.navigator.onLine;
@@ -15,7 +15,7 @@
//interval de conec
var interval = 30000; //TODO: obruce 05-05-14 decider d'un intervalle interessant
// periode de delais = 3 periode +1msec
- var delayAccess = 2 * interval +1;
+ var delayAccess = interval + 1;
// {TreeNode} l'arbre regenere automatiquement lorsque les donnees changent
$scope.tree;
@@ -160,7 +160,7 @@
*/
var initTasksFromServ = function(){
- serverTaskAccess.query({}, function (response) {
+ serverTaskAccess.query({date : 0}, function (response) {
angular.forEach(response, function (item) {
@@ -182,10 +182,6 @@
//Un noeud avec un parent est ajoute à l'arbre de son parent
$scope.data.tasks[newTask.taskId] = newTask;
save();
- //Les temps sont recuperes du serveur
- getTimesFromServerWithTask(newTask);
-
- save();
}
save();
}
@@ -197,11 +193,11 @@
$scope.taskAccess = Date.now();
$scope.todo.lastTaskAccess= $scope.taskAccess;
- $scope.timeAccess = Date.now();
- $scope.todo.lastTimeAccess= $scope.timeAccess;
save();
});
+
+ updateTimesFromServer();
};
@@ -211,7 +207,6 @@
*
*/
var updateTasksFromServ = function(){
- console.log("updateTasksFromServ debut");
serverTaskAccess.query({date : ($scope.taskAccess-delayAccess)}, function (response) {
@@ -228,7 +223,9 @@
if(item.removed != 0){
$scope.removeTask(tmp);
}else{
- tmp.task.name = item.name;
+ if(item.name != "New task"){
+ tmp.task.name = item.name;
+ }
}
save();
@@ -267,7 +264,6 @@
save();
}
}
-
});
});
@@ -275,8 +271,6 @@
$scope.taskAccess = Date.now();
$scope.todo.lastTaskAccess= $scope.taskAccess;
save();
-
- console.log("updateTasksFromServ fin");
}
/**
@@ -409,7 +403,7 @@
angular.forEach($scope.todo.stockedNewTasks, function(task){
//On change la date au dernier acces
- task['modificationDate']=$scope.taskAccess;
+ task['modificationDate']= Date.now();
serverTaskAccess.create({dispatch:true}, angular.toJson(task), //TODO obruce 04/06/14 dispatch a enlever
function(){
@@ -423,7 +417,7 @@
//On ajoute au serveur les taches stockees pour l'ajout
angular.forEach($scope.todo.stockedEditedTasks, function(task){
//On change la date au dernier acces
- task["modificationDate"]=$scope.taskAccess;
+ task["modificationDate"]=Date.now();
serverTaskAccess.update({dispatch:true},angular.toJson(task), //TODO
function(){
@@ -439,7 +433,7 @@
angular.forEach($scope.todo.stockedNewTimes, function(times,task){
angular.forEach(times, function(time){
//On change la date au dernier acces
- time["modificationDate"]=$scope.timeAccess;
+ time["modificationDate"]=Date.now();
serverTimeAccess.create({taskId: task,dispatch:true} , angular.toJson(time),
function(){
@@ -456,7 +450,7 @@
angular.forEach($scope.todo.stockedEditedTimes, function(times,task){
angular.forEach(times, function(time){
- time["modificationDate"]=$scope.timeAccess;
+ time["modificationDate"]=Date.now();
serverTimeAccess.update({taskId: task,dispatch:true}, angular.toJson(time),
function(){
@@ -765,6 +759,26 @@
return moment().format("HH:mm DD/MM/YYYY");
};
+ console.log(jTimerWebsocket);
+
+ jTimerWebsocket.subscribe({
+ message: function(data) {
+ //var jsData = JSON.parse(data);
+ console.log("data " +data);
+ },
+ status: function(status) {
+ $scope.webSocketClientOnline = status;
+ }
+ });
+
+
+ var testWebsocket = function(){
+ jTimerWebsocket.send(JSON.stringify($scope.data.tasks));
+ console.log("un message est envoyé websocket")
+ };
+
+ /** Idleness*/
+
/**
* Subscribe to websocket messages queue.
*/
@@ -801,6 +815,7 @@
modalInstance.result.then($scope.restartFromIdleness);
};
+
/**
* Called by modal dialog to resume from idle.
*
@@ -930,7 +945,11 @@
// connect to webscocket server (go client)
wtWebsocket.connect();
+ jTimerWebsocket.connect();
+ testWebsocket();
+
+
}
Modified: branches/ng-jtimer/src/main/webapp/partials/reportModal.html
===================================================================
--- branches/ng-jtimer/src/main/webapp/partials/reportModal.html 2014-06-11 15:48:49 UTC (rev 2999)
+++ branches/ng-jtimer/src/main/webapp/partials/reportModal.html 2014-06-13 15:23:28 UTC (rev 3000)
@@ -1,55 +1,63 @@
-Option du rapport:
+<div>
+ <h2>Option du rapport:</h2>
+</div>
+<hr/>
+
<div>
+ <div>
+ De :
+ <div ng-controller="ReportDatePickerCtrl" class="row">
+ <div class="col-md-6">
+ <p class="input-group medium_input">
+ <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>
- <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" />
+ A :
+ <div class="row" ng-controller="ReportDatePickerCtrl">
+ <div class="col-md-6">
+ <p class="input-group medium_input">
+ <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>
+ </p>
+ </div>
</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>
+
+ <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>
- </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>
+ <p>
+
+ </p>
</div>
- <p>
-
- </p>
+ <div>
- <alert type="info" >
- Rapport :<br/>
- =========
- <div ng-repeat="elem in obj.report">
- {{elem.task}} : {{elem.time | time}}
- </div>
+ <alert type="info" >
+ Rapport :<br/>
+ =========
+ <div ng-repeat="elem in obj.report">
+ {{elem.task}} : {{elem.time | time}}
+ </div>
- </alert>
+ </alert>
+ </div>
</div>
Modified: branches/ng-jtimer/src/main/webapp/partials/tasks.html
===================================================================
--- branches/ng-jtimer/src/main/webapp/partials/tasks.html 2014-06-11 15:48:49 UTC (rev 2999)
+++ branches/ng-jtimer/src/main/webapp/partials/tasks.html 2014-06-13 15:23:28 UTC (rev 3000)
@@ -1,9 +1,9 @@
<div id="header">
<!--Header partie gauche -->
<span class='left form-inline'>
- <input class='search-query form-group form-control input-sm' ng-model="query" placeholder="Search">
+ <input class='search-query form-group form-control input-sm small_input' ng-model="query" placeholder="Search">
<form ng-submit="addTask()">
- <input class='search-query form-group form-group form-control input-sm' ng-model="name" placeholder="New Task">
+ <input class='search-query form-group form-control input-sm small_input' ng-model="name" placeholder="New Task">
</form>
</span>
Modified: branches/ng-jtimer/src/main/webapp/webtimer.appcache
===================================================================
--- branches/ng-jtimer/src/main/webapp/webtimer.appcache 2014-06-11 15:48:49 UTC (rev 2999)
+++ branches/ng-jtimer/src/main/webapp/webtimer.appcache 2014-06-13 15:23:28 UTC (rev 3000)
@@ -7,6 +7,7 @@
partials/contact.html
partials/tasks.html
partials/timeModal.html
+partials/reportModal.html
css/app.css
css/jtimer.css
js/app.js
1
0
r2999 - in branches/ng-jtimer/src/main/java/org/chorem/jtimer: storage web
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 17:48:49 +0200 (Wed, 11 Jun 2014)
New Revision: 2999
Url: http://forge.chorem.org/projects/jtimer/repository/revisions/2999
Log:
Abstract resource pour requete option
Added:
branches/ng-jtimer/src/main/java/org/chorem/jtimer/web/AbstractResource.java
branches/ng-jtimer/src/main/java/org/chorem/jtimer/web/ReportResource.java
Modified:
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/TaskResource.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/java/org/chorem/jtimer/web/TimesResource.java
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-11 14:23:29 UTC (rev 2998)
+++ branches/ng-jtimer/src/main/java/org/chorem/jtimer/storage/Storage.java 2014-06-11 15:48:49 UTC (rev 2999)
@@ -35,7 +35,7 @@
protected static final String TABLE_TIME = "tasktime";
protected static final String TABLE_VERSION = "version";
- protected static String STORAGE_PATH;
+ protected String STORAGE_PATH;
protected Connection connection;
@@ -66,6 +66,7 @@
@Override
protected void finalize() throws Throwable {
connection.close();
+ super.finalize();
}
protected Connection getConnection() throws SQLException {
@@ -320,30 +321,6 @@
}
/**
- * Returns task number with ID
- * @param id identifiant de la tache
- * @return le long representant la tache dans la base
- */
- public long getTaskNumber(String id) {
- PreparedStatement statement = null;
- long result= 0;
- try {
- statement = connection.prepareStatement("SELECT id FROM " +TABLE_TASK +
- " WHERE taskId = '" + id+"'");
-
- ResultSet rs = statement.executeQuery();
- while (rs.next()) {
- result = rs.getLong(1);
- }
- } catch (SQLException ex) {
- throw new StorageException("Read error", ex);
- } finally {
- closeStatement(statement);
- }
- return result;
- }
-
- /**
* Ajoute une periode pour une tache
* @param task la tache qui va recevoir un temps
* @param date la date de creation
@@ -478,7 +455,35 @@
return times;
}
+ public String getRepportByProject(Long startDate, Long endDate){
+ String res = "Rapport\n ========== \n";
+ long tot = (long) 0;
+ PreparedStatement statement = null;
+ try{
+ statement = connection.prepareStatement("SELECT TA.name AS task, sum(TI.duration) AS totalduration" +
+ " FROM " + TABLE_TASK+" TA," + TABLE_TIME +" TI" +
+ " WHERE TA.taskId = TI.taskid" +
+ " AND TA.modificationDate >" + startDate +
+ " AND TA.modificationDate <" + endDate +
+ " GROUP BY TA.taskId");
+ ResultSet rs = statement.executeQuery();
+ while(rs.next()){
+ res += rs.getString("task") + " : " +rs.getLong("totalduration") + ", \n";
+ tot += rs.getLong("totalduration");
+ }
+
+ res +="Totale : " + tot;
+ }catch(SQLException ex) {
+ throw new StorageException("Can't get report", ex);
+ } finally {
+ closeStatement(statement);
+ }
+
+ return res;
+ }
+
+
/** Suppression de tuple **/
/**
Added: branches/ng-jtimer/src/main/java/org/chorem/jtimer/web/AbstractResource.java
===================================================================
--- branches/ng-jtimer/src/main/java/org/chorem/jtimer/web/AbstractResource.java (rev 0)
+++ branches/ng-jtimer/src/main/java/org/chorem/jtimer/web/AbstractResource.java 2014-06-11 15:48:49 UTC (rev 2999)
@@ -0,0 +1,30 @@
+package org.chorem.jtimer.web;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.restlet.resource.Options;
+import org.restlet.resource.ServerResource;
+
+/**
+ * Created by olivia on 11/06/14.
+ * <p/>
+ * Project name : jtimer
+ * <p/>
+ * Package name : org.chorem.jtimer.web
+ */
+public class AbstractResource extends ServerResource {
+
+ private static final Log log = LogFactory.getLog(AbstractResource.class);
+
+ /**
+ * Called when option requests are catched
+ * Needed to avoid cross origin
+ */
+ @Options
+ public void Options() {
+ if (log.isInfoEnabled()) {
+ log.info("org.chorem.jtimer.web.AbstractResource.Options");
+ }
+ }
+
+}
Added: branches/ng-jtimer/src/main/java/org/chorem/jtimer/web/ReportResource.java
===================================================================
--- branches/ng-jtimer/src/main/java/org/chorem/jtimer/web/ReportResource.java (rev 0)
+++ branches/ng-jtimer/src/main/java/org/chorem/jtimer/web/ReportResource.java 2014-06-11 15:48:49 UTC (rev 2999)
@@ -0,0 +1,11 @@
+package org.chorem.jtimer.web;
+
+/**
+ * Created by olivia on 11/06/14.
+ * <p/>
+ * Project name : jtimer
+ * <p/>
+ * Package name : org.chorem.jtimer.web
+ */
+public class ReportResource extends AbstractResource{
+}
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-11 14:23:29 UTC (rev 2998)
+++ branches/ng-jtimer/src/main/java/org/chorem/jtimer/web/RestApplication.java 2014-06-11 15:48:49 UTC (rev 2999)
@@ -55,6 +55,7 @@
router.attach("/tasks/task/{taskId}", TaskResource.class);
router.attach("/tasks/time/{taskId}", TimeResource.class);
router.attach("/tasks/time", TimesResource.class);
+ router.attach("/tasks/report", ReportResource.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-11 14:23:29 UTC (rev 2998)
+++ branches/ng-jtimer/src/main/java/org/chorem/jtimer/web/TaskResource.java 2014-06-11 15:48:49 UTC (rev 2999)
@@ -1,7 +1,6 @@
package org.chorem.jtimer.web;
import com.google.gson.Gson;
-
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.chorem.jtimer.entities.TodoList;
@@ -9,12 +8,14 @@
import org.restlet.data.MediaType;
import org.restlet.representation.Representation;
import org.restlet.representation.StringRepresentation;
-import org.restlet.resource.*;
+import org.restlet.resource.Delete;
+import org.restlet.resource.Get;
+import org.restlet.resource.ResourceException;
import java.util.Date;
-public class TaskResource extends ServerResource {
+public class TaskResource extends AbstractResource {
private static final Log log = LogFactory.getLog(TaskResource.class);
@@ -84,15 +85,4 @@
}
return res;
}
-
-
-
- @Options
- public void taskOptions() {
- if (log.isInfoEnabled()) {
- log.info("org.chorem.jtimer.web.TaskResource.taskOptions");
- }
- }
-
-
}
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-11 14:23:29 UTC (rev 2998)
+++ branches/ng-jtimer/src/main/java/org/chorem/jtimer/web/TasksResource.java 2014-06-11 15:48:49 UTC (rev 2999)
@@ -1,11 +1,14 @@
package org.chorem.jtimer.web;
-import java.io.IOException;
-import java.lang.reflect.Type;
-import java.util.ArrayList;
-import java.util.Date;
-
-
+import com.google.gson.Gson;
+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.lang3.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -16,23 +19,16 @@
import org.restlet.representation.Representation;
import org.restlet.representation.StringRepresentation;
import org.restlet.resource.Get;
-import org.restlet.resource.Options;
import org.restlet.resource.Post;
import org.restlet.resource.Put;
import org.restlet.resource.ResourceException;
-import org.restlet.resource.ServerResource;
-import com.google.gson.Gson;
-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 java.io.IOException;
+import java.lang.reflect.Type;
+import java.util.ArrayList;
+import java.util.Date;
-public class TasksResource extends ServerResource {
+public class TasksResource extends AbstractResource {
private static final Log log = LogFactory.getLog(TasksResource.class);
@@ -189,11 +185,5 @@
}
- @Options
- public void tasksOptions() {
- if (log.isInfoEnabled()) {
- log.info("org.chorem.jtimer.web.TasksResource.tasksOptions");
- }
- }
}
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-11 14:23:29 UTC (rev 2998)
+++ branches/ng-jtimer/src/main/java/org/chorem/jtimer/web/TimeResource.java 2014-06-11 15:48:49 UTC (rev 2999)
@@ -20,18 +20,16 @@
import org.restlet.representation.StringRepresentation;
import org.restlet.resource.Delete;
import org.restlet.resource.Get;
-import org.restlet.resource.Options;
import org.restlet.resource.Post;
import org.restlet.resource.Put;
import org.restlet.resource.ResourceException;
-import org.restlet.resource.ServerResource;
import java.io.IOException;
import java.lang.reflect.Type;
import java.util.Date;
import java.util.List;
-public class TimeResource extends ServerResource {
+public class TimeResource extends AbstractResource {
private static final Log log = LogFactory.getLog(TimeResource.class);
@@ -176,15 +174,8 @@
}
- /**
- * 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
Modified: branches/ng-jtimer/src/main/java/org/chorem/jtimer/web/TimesResource.java
===================================================================
--- branches/ng-jtimer/src/main/java/org/chorem/jtimer/web/TimesResource.java 2014-06-11 14:23:29 UTC (rev 2998)
+++ branches/ng-jtimer/src/main/java/org/chorem/jtimer/web/TimesResource.java 2014-06-11 15:48:49 UTC (rev 2999)
@@ -1,9 +1,16 @@
package org.chorem.jtimer.web;
-import com.google.gson.*;
+import com.google.gson.Gson;
+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.TimerTime;
import org.chorem.jtimer.storage.Storage;
import org.restlet.data.MediaType;
@@ -11,17 +18,15 @@
import org.restlet.representation.StringRepresentation;
import org.restlet.resource.Get;
import org.restlet.resource.ResourceException;
-import org.restlet.resource.ServerResource;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.Date;
-import java.util.HashMap;
/**
* Created by olivia on 21/05/14.
*/
-public class TimesResource extends ServerResource {
+public class TimesResource extends AbstractResource {
private static final Log log = LogFactory.getLog(TaskResource.class);
protected Storage storage;
1
0
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