aymeric_vandewoorde 5 سال پیش
والد
کامیت
2a868eb097
1فایلهای تغییر یافته به همراه36 افزوده شده و 5 حذف شده
  1. 36 5
      src/rest/RestService.java

+ 36 - 5
src/rest/RestService.java

@@ -1,38 +1,69 @@
 package rest;
 
+import java.text.SimpleDateFormat;
 import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
 import java.util.logging.Logger;
 
-import javax.ws.rs.ApplicationPath;
+import javax.servlet.ServletContext;
 import javax.ws.rs.GET;
 import javax.ws.rs.Path;
 import javax.ws.rs.PathParam;
 import javax.ws.rs.Produces;
+import javax.ws.rs.core.Context;
 
 @Path("/")
 @Produces("text/plain")
 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}")
 	@GET
-	public String validerBadge(@PathParam("id") String id, @PathParam("espace") String espace) {
+	public String validerBadge(@PathParam("id") String id, @PathParam("espace") String espace, @Context ServletContext context) {
 		LOGGER.info("validation du badge " + id + " a l'espace " + espace);
-		return "Success";
+		Map<String,String> mapPassageMicrofolies = (Map<String, String>) context.getAttribute("MapPassageMicrofolies");
+		String stringVerifPassage = sdf.format(new Date())+ " " + espace;
+		String messageRetour=messageBienvenue + espace;
+		if(mapPassageMicrofolies==null) {
+			mapPassageMicrofolies=new HashMap<String,String>();
+			mapPassageMicrofolies.put(id, stringVerifPassage);
+		}
+		else {
+			String listPassage = mapPassageMicrofolies.get(id);
+			if(listPassage==null) {
+				mapPassageMicrofolies.put(id,new Date().toString() + " " + espace);
+			} else {
+				if(!listPassage.contains(stringVerifPassage)){
+					mapPassageMicrofolies.put(id,listPassage);
+				} else {
+					messageRetour=messagePlusieursPassages + espace;
+				}
+			}
+		}	
+		context.setAttribute("MapPassageMicrofolies", mapPassageMicrofolies);
+		return messageRetour;
 	}
 
 	@Path("freq/{espace}/{from}/{to}")
 	@GET
 	public String frequence(@PathParam("espace") String espace, @PathParam("from") Date from, @PathParam("to") Date to) {
 		LOGGER.info("frequence de " + from + " a " + to + " espace " + espace);
-		return "Graphe";
+		return "frequence de " + from + " a " + to + " espace " + espace;
 	}
 
 	@Path("profile/{id}")
 	@GET
 	public String profil(@PathParam("id")String id) {
 		LOGGER.info("profil " +id);
-		return "Profil";
+		return "Profil de " + id;
 	}
+
 }