|
@@ -28,11 +28,11 @@ import classes.Frequentation;
|
|
|
public class RestService {
|
|
|
|
|
|
private static Logger LOGGER = Logger.getLogger("jai.jaxrs");
|
|
|
-
|
|
|
+
|
|
|
private static SimpleDateFormat sdf= new SimpleDateFormat("MMddyyyy");
|
|
|
-
|
|
|
+
|
|
|
private static String messageBienvenue="Bienvenue à l'espace ";
|
|
|
-
|
|
|
+
|
|
|
private static String messagePlusieursPassages="De nouveau bienvenue à l'espace ";
|
|
|
|
|
|
@Path("/badge/{id}/{espace}")
|
|
@@ -65,28 +65,36 @@ public class RestService {
|
|
|
@Path("freq/{espace}/{from}/{to}")
|
|
|
@GET
|
|
|
public String frequence(@PathParam("espace") String espace, @PathParam("from") String from, @PathParam("to") String to, @Context ServletContext context) {
|
|
|
- Pattern pattern = Pattern.compile(",");
|
|
|
- try (BufferedReader in = new BufferedReader(new FileReader(context.getRealPath("data/frequentation.csv")));) {
|
|
|
- List<Frequentation> frequentations = in .lines() .skip(1) .map(line -> {
|
|
|
- String[] x = pattern.split(line);
|
|
|
- try {
|
|
|
- return new Frequentation(x[0], x[1], x[2]);
|
|
|
- } catch (ParseException e) {
|
|
|
- e.printStackTrace();
|
|
|
+ try {
|
|
|
+ Date begin = sdf.parse(from);
|
|
|
+ Date end = sdf.parse(to);
|
|
|
+ Pattern pattern = Pattern.compile(",");
|
|
|
+ try (BufferedReader in = new BufferedReader(new FileReader(context.getRealPath("data/frequentation.csv")));) {
|
|
|
+ List<Frequentation> frequentations = in .lines() .skip(1) .map(line -> {
|
|
|
+ String[] x = pattern.split(line);
|
|
|
+ try {
|
|
|
+ return new Frequentation(x[0], x[1], x[2]);
|
|
|
+ } catch (ParseException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ return null; }) .collect(Collectors.toList());
|
|
|
+ String toReturn = "{\"data\":[";
|
|
|
+ for (Frequentation f : frequentations) {
|
|
|
+ if(f.getDate().after(begin) && f.getDate().before(end))
|
|
|
+ toReturn+=f.toString()+",";
|
|
|
}
|
|
|
- return null; }) .collect(Collectors.toList());
|
|
|
- String toReturn = "{\"data\":[";
|
|
|
- for (Frequentation f : frequentations) {
|
|
|
- toReturn+=f.toString()+",";
|
|
|
+ toReturn=toReturn.substring(0,toReturn.length()-1) + "]}";
|
|
|
+ return toReturn;
|
|
|
+ } catch (FileNotFoundException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ return "File not valid";
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ return "File not valid";
|
|
|
}
|
|
|
- toReturn=toReturn.substring(0,toReturn.length()-1) + "]}";
|
|
|
- return toReturn;
|
|
|
- } catch (FileNotFoundException e) {
|
|
|
- e.printStackTrace();
|
|
|
- return "File not valid";
|
|
|
- } catch (IOException e) {
|
|
|
- e.printStackTrace();
|
|
|
- return "File not valid";
|
|
|
+ } catch (ParseException e1) {
|
|
|
+ e1.printStackTrace();
|
|
|
+ return "Date not valid, format : MMddyyyy";
|
|
|
}
|
|
|
}
|
|
|
|