r2999 - in branches/ng-jtimer/src/main/java/org/chorem/jtimer: storage web
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;
participants (1)
-
obruceļ¼ users.chorem.org