Commit 13300e01b46c7822d94915ffaeac706db106829f

Authored by Notmoo-PC\Notmoo
1 parent 1e8c5c71

Clear code + ajout commentaire

src/main/java/core/ServerApp.java deleted
1 -import core.dao.HibernateDao;  
2 -import core.repository.AccessPoint;  
3 -import core.repository.Map;  
4 -  
5 -/**  
6 - * Created by Guillaume on 09/05/2017.  
7 - */  
8 -public class ServerApp {  
9 - public static void main(String args[]){  
10 - HibernateDao dao = new HibernateDao();  
11 - AccessPoint ap = new AccessPoint();  
12 - ap.setMac_addr("aa:aa:aa:aa:aa:aa:aa:aa");  
13 - dao.saveAccessPoint(ap);  
14 -  
15 - Map map = new Map();  
16 - dao.saveMap(map);/**/  
17 - }  
18 -}  
src/main/java/core/dao/DebianDao.java deleted
1 -package core.dao;  
2 -  
3 -/**  
4 - * Created by Guillaume on 09/05/2017.  
5 - */  
6 -public class DebianDao {  
7 -  
8 - public String getMacAddr(String ipAddr){  
9 - //TODO  
10 - return null;  
11 - }  
12 -}  
src/main/java/core/dao/HibernateDao.java
@@ -12,13 +12,24 @@ import java.util.List; @@ -12,13 +12,24 @@ import java.util.List;
12 12
13 13
14 /** 14 /**
  15 + * Dao class handling access to database's data using Hibernate
  16 + *
15 * Created by Guillaume on 09/05/2017. 17 * Created by Guillaume on 09/05/2017.
16 */ 18 */
17 public class HibernateDao { 19 public class HibernateDao {
18 20
19 public HibernateDao () { 21 public HibernateDao () {
20 } 22 }
21 - 23 +
  24 + /**
  25 + * Execute a ITransactionProcess containing an Hibernate transaction,
  26 + * and return a callback object containing a list of results filled by
  27 + * the transactioin process and a boolean status.
  28 + *
  29 + * Handle properly Hibernate session's opening and closing, and handle exceptions that can occur.
  30 + * @param itp transaction process to run
  31 + * @return {@link TransactionCallBack}
  32 + */
22 private TransactionCallBack execTransactionProcess(ITransactionProcess itp) { 33 private TransactionCallBack execTransactionProcess(ITransactionProcess itp) {
23 Session session = HibernateUtil.getSessionFactory().openSession(); 34 Session session = HibernateUtil.getSessionFactory().openSession();
24 TransactionCallBack reply = new TransactionCallBack(); 35 TransactionCallBack reply = new TransactionCallBack();
@@ -48,9 +59,18 @@ public class HibernateDao { @@ -48,9 +59,18 @@ public class HibernateDao {
48 } 59 }
49 return reply; 60 return reply;
50 } 61 }
51 - private <T> List<T> internal_getData(Class<T> clazz){ 62 +
  63 + /**
  64 + * Generic method that return a list of objects that
  65 + * are contained in the database handled by Hibernate.
  66 + *
  67 + * @param clazz class of elements requests
  68 + *
  69 + * @return a list of objects of class {@code clazz}
  70 + */
  71 + private <T extends IJavaBean> List<T> internal_getData(Class<T> clazz){
52 TransactionCallBack callBack = execTransactionProcess((session)->{ 72 TransactionCallBack callBack = execTransactionProcess((session)->{
53 - TransactionCallBack reply = new TransactionCallBack<T>(); 73 + TransactionCallBack reply = new TransactionCallBack<IJavaBean>();
54 Query query = session.createQuery("from "+clazz.getSimpleName()); 74 Query query = session.createQuery("from "+clazz.getSimpleName());
55 List<Object> results = query.list(); 75 List<Object> results = query.list();
56 for(Object result : results){ 76 for(Object result : results){
@@ -61,6 +81,12 @@ public class HibernateDao { @@ -61,6 +81,12 @@ public class HibernateDao {
61 }); 81 });
62 return callBack.getResults(); 82 return callBack.getResults();
63 } 83 }
  84 +
  85 + /**
  86 + * Generic method that push javabeans to the database using Hibernate.
  87 + * @param objs
  88 + * @return status, true if the transaction is successful, false otherwise
  89 + */
64 private boolean internal_saveData(Object... objs){ 90 private boolean internal_saveData(Object... objs){
65 TransactionCallBack callBack = execTransactionProcess((session)->{ 91 TransactionCallBack callBack = execTransactionProcess((session)->{
66 TransactionCallBack reply = new TransactionCallBack(); 92 TransactionCallBack reply = new TransactionCallBack();
@@ -72,10 +98,21 @@ public class HibernateDao { @@ -72,10 +98,21 @@ public class HibernateDao {
72 98
73 return callBack!=null && callBack.isStatus(); 99 return callBack!=null && callBack.isStatus();
74 } 100 }
75 - 101 +
  102 + /**
  103 + *
  104 + * @param trs
  105 + * @return
  106 + */
76 public boolean saveTempRssi(TempRssi... trs){ 107 public boolean saveTempRssi(TempRssi... trs){
77 return internal_saveData(trs); 108 return internal_saveData(trs);
78 } 109 }
  110 +
  111 + /**
  112 + *
  113 + * @param macAddr
  114 + * @return
  115 + */
79 public List<TempRssi> getTempRssi(String macAddr){ 116 public List<TempRssi> getTempRssi(String macAddr){
80 if(macAddr == null) 117 if(macAddr == null)
81 return new ArrayList<>(); 118 return new ArrayList<>();
@@ -93,13 +130,28 @@ public class HibernateDao { @@ -93,13 +130,28 @@ public class HibernateDao {
93 }); 130 });
94 return callBack.getResults(); 131 return callBack.getResults();
95 } 132 }
96 - 133 +
  134 + /**
  135 + *
  136 + * @param rssis
  137 + * @return
  138 + */
97 public boolean saveRssiRecord(RssiRecord... rssis){ 139 public boolean saveRssiRecord(RssiRecord... rssis){
98 return internal_saveData(rssis); 140 return internal_saveData(rssis);
99 } 141 }
  142 + /**
  143 + *
  144 + * @return
  145 + */
100 public List<RssiRecord> getRssiRecord(){ 146 public List<RssiRecord> getRssiRecord(){
101 return internal_getData(RssiRecord.class); 147 return internal_getData(RssiRecord.class);
102 } 148 }
  149 +
  150 + /**
  151 + *
  152 + * @param locationID
  153 + * @return
  154 + */
103 public List<RssiRecord> getRssiRecord(Integer locationID){ 155 public List<RssiRecord> getRssiRecord(Integer locationID){
104 if(locationID == null) 156 if(locationID == null)
105 return getRssiRecord(); 157 return getRssiRecord();
@@ -117,19 +169,44 @@ public class HibernateDao { @@ -117,19 +169,44 @@ public class HibernateDao {
117 }); 169 });
118 return callBack.getResults(); 170 return callBack.getResults();
119 } 171 }
120 - 172 +
  173 + /**
  174 + *
  175 + * @return
  176 + */
121 public List<Location> getLocations(){ 177 public List<Location> getLocations(){
122 return internal_getData(Location.class); 178 return internal_getData(Location.class);
123 } 179 }
124 - 180 +
  181 + /**
  182 + *
  183 + * @param aps
  184 + * @return
  185 + */
125 public boolean saveAccessPoint (final AccessPoint... aps) { 186 public boolean saveAccessPoint (final AccessPoint... aps) {
126 return internal_saveData(aps); 187 return internal_saveData(aps);
127 } 188 }
  189 +
  190 + /**
  191 + *
  192 + * @return
  193 + */
128 public List<AccessPoint> getAccessPoint () { 194 public List<AccessPoint> getAccessPoint () {
129 return internal_getData(AccessPoint.class); 195 return internal_getData(AccessPoint.class);
130 } 196 }
131 - 197 +
  198 + /**
  199 + *
  200 + * @param map
  201 + * @return
  202 + */
132 public boolean saveMap(final Map map){return internal_saveData(map);} 203 public boolean saveMap(final Map map){return internal_saveData(map);}
  204 +
  205 + /**
  206 + *
  207 + * @param mapId
  208 + * @return
  209 + */
133 public Map getMap(int mapId){ 210 public Map getMap(int mapId){
134 TransactionCallBack callBack = execTransactionProcess((session)->{ 211 TransactionCallBack callBack = execTransactionProcess((session)->{
135 TransactionCallBack reply = new TransactionCallBack<Map>(); 212 TransactionCallBack reply = new TransactionCallBack<Map>();
@@ -145,6 +222,11 @@ public class HibernateDao { @@ -145,6 +222,11 @@ public class HibernateDao {
145 return (callBack.getResults().isEmpty()?null:(Map)callBack.getResults().get(0)); 222 return (callBack.getResults().isEmpty()?null:(Map)callBack.getResults().get(0));
146 } 223 }
147 224
  225 + /**
  226 + *
  227 + * @param apMacAddress
  228 + * @return
  229 + */
148 public List<AccessPoint> getAccessPoints(String apMacAddress) { 230 public List<AccessPoint> getAccessPoints(String apMacAddress) {
149 TransactionCallBack callBack = execTransactionProcess((session)->{ 231 TransactionCallBack callBack = execTransactionProcess((session)->{
150 TransactionCallBack reply = new TransactionCallBack<AccessPoint>(); 232 TransactionCallBack reply = new TransactionCallBack<AccessPoint>();
@@ -163,7 +245,11 @@ public class HibernateDao { @@ -163,7 +245,11 @@ public class HibernateDao {
163 return reply; 245 return reply;
164 } 246 }
165 247
166 - 248 + /**
  249 + *
  250 + * @param location
  251 + * @return
  252 + */
167 public int saveLocation(Location location) { 253 public int saveLocation(Location location) {
168 TransactionCallBack callBack = execTransactionProcess((session)->{ 254 TransactionCallBack callBack = execTransactionProcess((session)->{
169 TransactionCallBack<Integer> reply = new TransactionCallBack<Integer>(); 255 TransactionCallBack<Integer> reply = new TransactionCallBack<Integer>();
@@ -177,6 +263,12 @@ public class HibernateDao { @@ -177,6 +263,12 @@ public class HibernateDao {
177 return (Integer)callBack.results.get(0); 263 return (Integer)callBack.results.get(0);
178 return -1; 264 return -1;
179 } 265 }
  266 +
  267 + /**
  268 + *
  269 + * @param Location
  270 + * @return
  271 + */
180 public Location getLocation(int Location) { 272 public Location getLocation(int Location) {
181 TransactionCallBack callBack = execTransactionProcess((session)->{ 273 TransactionCallBack callBack = execTransactionProcess((session)->{
182 TransactionCallBack reply = new TransactionCallBack<Location>(); 274 TransactionCallBack reply = new TransactionCallBack<Location>();
@@ -192,11 +284,19 @@ public class HibernateDao { @@ -192,11 +284,19 @@ public class HibernateDao {
192 return (callBack.getResults().isEmpty()?null:(Location)callBack.getResults().get(0)); 284 return (callBack.getResults().isEmpty()?null:(Location)callBack.getResults().get(0));
193 } 285 }
194 286
195 - 287 + /**
  288 + * This functional interface's purpose is to define a common
  289 + * type to give process to internal methods.
  290 + */
196 private interface ITransactionProcess{ 291 private interface ITransactionProcess{
197 TransactionCallBack exec(Session tr); 292 TransactionCallBack exec(Session tr);
198 } 293 }
199 - 294 +
  295 + /**
  296 + * Class designed to contains results from transaction process.
  297 + *
  298 + * @param <T>
  299 + */
200 private class TransactionCallBack<T>{ 300 private class TransactionCallBack<T>{
201 private boolean status; 301 private boolean status;
202 private List<T> results; 302 private List<T> results;
src/main/java/core/repository/AccessPoint.java
@@ -8,7 +8,7 @@ import javax.persistence.*; @@ -8,7 +8,7 @@ import javax.persistence.*;
8 */ 8 */
9 @Entity 9 @Entity
10 @Table(name ="ACCESS_POINT") 10 @Table(name ="ACCESS_POINT")
11 -public class AccessPoint implements Serializable{ 11 +public class AccessPoint implements IJavaBean{
12 @Id @GeneratedValue 12 @Id @GeneratedValue
13 private int id; 13 private int id;
14 14
src/main/java/core/repository/IJavaBean.java 0 โ†’ 100644
  1 +package core.repository;
  2 +
  3 +import java.io.Serializable;
  4 +
  5 +/**
  6 + * Common type shared by all javabeans created for this positioning server
  7 + *
  8 + * Created by Notmoo on 17/06/2017.
  9 + */
  10 +public interface IJavaBean extends Serializable{
  11 +}
src/main/java/core/repository/Location.java
@@ -8,7 +8,7 @@ import java.io.Serializable; @@ -8,7 +8,7 @@ import java.io.Serializable;
8 */ 8 */
9 @Entity 9 @Entity
10 @Table(name = "LOCATION") 10 @Table(name = "LOCATION")
11 -public class Location implements Serializable { 11 +public class Location implements IJavaBean {
12 @Id @GeneratedValue 12 @Id @GeneratedValue
13 private int id; 13 private int id;
14 private Double x, y; 14 private Double x, y;
src/main/java/core/repository/Map.java
@@ -8,7 +8,7 @@ import java.io.Serializable; @@ -8,7 +8,7 @@ import java.io.Serializable;
8 */ 8 */
9 @Entity 9 @Entity
10 @Table(name = "MAP") 10 @Table(name = "MAP")
11 -public class Map implements Serializable{ 11 +public class Map implements IJavaBean{
12 @Id @GeneratedValue 12 @Id @GeneratedValue
13 private int id; 13 private int id;
14 private Double x_topLeft, y_topLeft; 14 private Double x_topLeft, y_topLeft;
src/main/java/core/repository/RssiRecord.java
@@ -8,7 +8,7 @@ import java.io.Serializable; @@ -8,7 +8,7 @@ import java.io.Serializable;
8 */ 8 */
9 @Entity 9 @Entity
10 @Table (name = "RSSI_RECORD") 10 @Table (name = "RSSI_RECORD")
11 -public class RssiRecord implements Serializable { 11 +public class RssiRecord implements IJavaBean {
12 @Id @GeneratedValue 12 @Id @GeneratedValue
13 private int id; 13 private int id;
14 14
src/main/java/core/repository/TempRssi.java
@@ -7,7 +7,7 @@ import javax.persistence.*; @@ -7,7 +7,7 @@ import javax.persistence.*;
7 */ 7 */
8 @Entity 8 @Entity
9 @Table (name = "TEMP_RSSI") 9 @Table (name = "TEMP_RSSI")
10 -public class TempRssi { 10 +public class TempRssi implements IJavaBean{
11 @Id @GeneratedValue 11 @Id @GeneratedValue
12 private int id; 12 private int id;
13 13
src/main/java/core/service/CalibrationService.java
@@ -8,6 +8,9 @@ import core.repository.RssiRecord; @@ -8,6 +8,9 @@ import core.repository.RssiRecord;
8 import java.util.List; 8 import java.util.List;
9 9
10 /** 10 /**
  11 + * CalibrationService is a service class providing a way to register new calibration datas and new locations,
  12 + * that can be used afterwards to compute locations.
  13 + *
11 * Created by Guillaume on 09/05/2017. 14 * Created by Guillaume on 09/05/2017.
12 */ 15 */
13 public class CalibrationService { 16 public class CalibrationService {
src/main/java/core/service/MapService.java
@@ -4,6 +4,9 @@ import core.dao.HibernateDao; @@ -4,6 +4,9 @@ import core.dao.HibernateDao;
4 import core.repository.Map; 4 import core.repository.Map;
5 5
6 /** 6 /**
  7 + * MapService is a service class providing methods to access map data
  8 + * stored in the database according to a map id.
  9 + *
7 * Created by Guillaume on 29/05/2017. 10 * Created by Guillaume on 29/05/2017.
8 */ 11 */
9 public class MapService { 12 public class MapService {
src/main/java/core/service/MeasurementService.java
@@ -7,6 +7,10 @@ import core.repository.TempRssi; @@ -7,6 +7,10 @@ import core.repository.TempRssi;
7 import java.util.List; 7 import java.util.List;
8 8
9 /** 9 /**
  10 + * MesaurementService is a service class providing methods to register positioning data.
  11 + * One shouldn't use this service to registrer calibration data, as a dedicated service class
  12 + * has been made to handle this kind of registrations.
  13 + *
10 * Created by Guillaume on 29/05/2017. 14 * Created by Guillaume on 29/05/2017.
11 */ 15 */
12 public class MeasurementService { 16 public class MeasurementService {
@@ -16,7 +20,13 @@ public class MeasurementService { @@ -16,7 +20,13 @@ public class MeasurementService {
16 public MeasurementService(){ 20 public MeasurementService(){
17 dao = new HibernateDao(); 21 dao = new HibernateDao();
18 } 22 }
19 - 23 +
  24 + /**
  25 + * Register into the database a measured positioning data.
  26 + * @param apMacAddr mac address of access point that measured the data
  27 + * @param clientMacAddr mac address of client that has been use as base for measurement
  28 + * @param val value measured
  29 + */
20 public void registerMeasurement(String apMacAddr, String clientMacAddr, double val){ 30 public void registerMeasurement(String apMacAddr, String clientMacAddr, double val){
21 List<AccessPoint> aps = dao.getAccessPoints(apMacAddr); 31 List<AccessPoint> aps = dao.getAccessPoints(apMacAddr);
22 32
src/main/java/core/service/PositioningService.java
1 package core.service; 1 package core.service;
2 2
3 -import core.dao.DebianDao;  
4 import core.dao.HibernateDao; 3 import core.dao.HibernateDao;
5 import core.repository.Location; 4 import core.repository.Location;
6 import core.repository.RssiRecord; 5 import core.repository.RssiRecord;
@@ -10,24 +9,23 @@ import java.util.ArrayList; @@ -10,24 +9,23 @@ import java.util.ArrayList;
10 import java.util.List; 9 import java.util.List;
11 10
12 /** 11 /**
  12 + * PositioningService is a service class designed to provide methods to compute one's location using measured data.
  13 + *
  14 + * To register measured data, please use {@link MeasurementService}. To register calibration data, please use {@link CalibrationService}
13 * Created by Guillaume on 09/05/2017. 15 * Created by Guillaume on 09/05/2017.
14 */ 16 */
15 public class PositioningService { 17 public class PositioningService {
16 18
17 - private static final double DEFAULT_POSITIONING_PRECISION = 7.5;  
18 -  
19 private HibernateDao hibDao; 19 private HibernateDao hibDao;
20 - private DebianDao debDao;  
21 20
22 public PositioningService () { 21 public PositioningService () {
23 - this.debDao = new DebianDao();  
24 this.hibDao = new HibernateDao(); 22 this.hibDao = new HibernateDao();
25 } 23 }
26 24
27 - public Location getLocation (String ipAddr) { 25 + public Location getLocation (String macAddr) {
28 26
29 //Liste des RSSISample associรฉ ร  un ap, mesurรฉ pour un client 27 //Liste des RSSISample associรฉ ร  un ap, mesurรฉ pour un client
30 - List<TempRssi> clientRssi = hibDao.getTempRssi(debDao.getMacAddr(ipAddr)); 28 + List<TempRssi> clientRssi = hibDao.getTempRssi(macAddr);
31 29
32 if(clientRssi.size()>=3) { 30 if(clientRssi.size()>=3) {
33 31
src/main/java/core/utils/HibernateUtil.java
@@ -3,6 +3,9 @@ package core.utils; @@ -3,6 +3,9 @@ package core.utils;
3 import org.hibernate.SessionFactory; 3 import org.hibernate.SessionFactory;
4 import org.hibernate.cfg.AnnotationConfiguration; 4 import org.hibernate.cfg.AnnotationConfiguration;
5 5
  6 +/**
  7 + * Singleton class granting access to Hibernate's session, built from annotations and hibernate config file
  8 + */
6 public class HibernateUtil { 9 public class HibernateUtil {
7 10
8 private static final SessionFactory sessionFactory = buildSessionFactory(); 11 private static final SessionFactory sessionFactory = buildSessionFactory();
src/main/java/servlet/APCalibrationServlet.java
@@ -10,6 +10,8 @@ import javax.servlet.http.HttpServletResponse; @@ -10,6 +10,8 @@ import javax.servlet.http.HttpServletResponse;
10 import java.io.IOException; 10 import java.io.IOException;
11 11
12 /** 12 /**
  13 + * Servlet designed to receive registration requests about calibration data.
  14 + *
13 * Created by Guillaume on 07/06/2017. 15 * Created by Guillaume on 07/06/2017.
14 */ 16 */
15 public class APCalibrationServlet extends HttpServlet { 17 public class APCalibrationServlet extends HttpServlet {
src/main/java/servlet/APMeasurementServlet.java
@@ -9,6 +9,8 @@ import javax.servlet.http.HttpServletResponse; @@ -9,6 +9,8 @@ import javax.servlet.http.HttpServletResponse;
9 import java.io.IOException; 9 import java.io.IOException;
10 10
11 /** 11 /**
  12 + * Servlet designed to receive registration requests about positioning data.
  13 + *
12 * Created by Guillaume on 29/05/2017. 14 * Created by Guillaume on 29/05/2017.
13 */ 15 */
14 public class APMeasurementServlet extends HttpServlet { 16 public class APMeasurementServlet extends HttpServlet {
src/main/java/servlet/CalibrationServlet.java
@@ -14,6 +14,8 @@ import java.net.InetAddress; @@ -14,6 +14,8 @@ import java.net.InetAddress;
14 import java.util.Random; 14 import java.util.Random;
15 15
16 /** 16 /**
  17 + * Servlet handling calibration request coming from clients.
  18 + *
17 * Created by Guillaume on 15/05/2017. 19 * Created by Guillaume on 15/05/2017.
18 */ 20 */
19 public class CalibrationServlet extends HttpServlet{ 21 public class CalibrationServlet extends HttpServlet{
@@ -60,10 +62,15 @@ public class CalibrationServlet extends HttpServlet{ @@ -60,10 +62,15 @@ public class CalibrationServlet extends HttpServlet{
60 execute(servletRequest, servletResponse); 62 execute(servletRequest, servletResponse);
61 } 63 }
62 64
  65 + /**
  66 + * Method broadcasting UPD request to AP, request asking fo calibration data.
  67 + * @param clientMacAddress mac address of client on which ap's measurement will be based
  68 + * @param locationId id of corresponding location in database
  69 + */
63 private void multicastCalibrationRequest(String clientMacAddress, int locationId){ 70 private void multicastCalibrationRequest(String clientMacAddress, int locationId){
64 try (DatagramSocket socket = new DatagramSocket(4445)){ 71 try (DatagramSocket socket = new DatagramSocket(4445)){
65 72
66 - byte[] buf = new byte[256]; 73 + byte[] buf;
67 74
68 String dString = "{\"CALIB\": \"" + clientMacAddress + "\", \"SERV\": \"" + Inet4Address.getLocalHost().getHostAddress()+"\", \"LOC_ID\": \""+locationId+"\"}"; 75 String dString = "{\"CALIB\": \"" + clientMacAddress + "\", \"SERV\": \"" + Inet4Address.getLocalHost().getHostAddress()+"\", \"LOC_ID\": \""+locationId+"\"}";
69 buf = dString.getBytes(); 76 buf = dString.getBytes();
src/main/java/servlet/MapByteServlet.java
@@ -10,6 +10,8 @@ import javax.servlet.http.HttpServletResponse; @@ -10,6 +10,8 @@ import javax.servlet.http.HttpServletResponse;
10 import java.io.IOException; 10 import java.io.IOException;
11 11
12 /** 12 /**
  13 + * Servlet designed to access to map image bytes. This kind of request is usually sent by clients.
  14 + *
13 * Created by Guillaume on 29/05/2017. 15 * Created by Guillaume on 29/05/2017.
14 */ 16 */
15 public class MapByteServlet extends HttpServlet { 17 public class MapByteServlet extends HttpServlet {
src/main/java/servlet/MapScaleServlet.java
@@ -10,6 +10,8 @@ import javax.servlet.http.HttpServletResponse; @@ -10,6 +10,8 @@ import javax.servlet.http.HttpServletResponse;
10 import java.io.IOException; 10 import java.io.IOException;
11 11
12 /** 12 /**
  13 + * Servlet designed to access to map scale, which can be use to convert real-life coordinates to on-screen coordinates. This kind of request is usually sent by clients.
  14 + *
13 * Created by Guillaume on 29/05/2017. 15 * Created by Guillaume on 29/05/2017.
14 */ 16 */
15 public class MapScaleServlet extends HttpServlet { 17 public class MapScaleServlet extends HttpServlet {
src/main/java/servlet/PositioningServlet.java
@@ -16,6 +16,8 @@ import java.net.InetAddress; @@ -16,6 +16,8 @@ import java.net.InetAddress;
16 import static java.lang.Thread.sleep; 16 import static java.lang.Thread.sleep;
17 17
18 /** 18 /**
  19 + * Servlet handling positioning request coming from clients.
  20 + *
19 * Created by Guillaume on 15/05/2017. 21 * Created by Guillaume on 15/05/2017.
20 */ 22 */
21 public class PositioningServlet extends HttpServlet{ 23 public class PositioningServlet extends HttpServlet{
@@ -30,10 +32,10 @@ public class PositioningServlet extends HttpServlet{ @@ -30,10 +32,10 @@ public class PositioningServlet extends HttpServlet{
30 multicastPositioningRequest(clientMacAddr); 32 multicastPositioningRequest(clientMacAddr);
31 33
32 34
33 - Location loc = null; 35 + Location loc;
34 do{ 36 do{
35 try{ 37 try{
36 - sleep(500l); 38 + sleep(500L);
37 } catch (InterruptedException e) { 39 } catch (InterruptedException e) {
38 e.printStackTrace(); 40 e.printStackTrace();
39 } 41 }
@@ -56,11 +58,16 @@ public class PositioningServlet extends HttpServlet{ @@ -56,11 +58,16 @@ public class PositioningServlet extends HttpServlet{
56 throws ServletException, IOException { 58 throws ServletException, IOException {
57 service(servletRequest, servletResponse); 59 service(servletRequest, servletResponse);
58 } 60 }
59 - 61 +
  62 + /**
  63 + * Method broadcasting UPD request to AP, request asking for positioning data.
  64 + *
  65 + * @param clientMacAddress mac address of client on which ap's measurement will be based
  66 + */
60 private void multicastPositioningRequest(String clientMacAddress){ 67 private void multicastPositioningRequest(String clientMacAddress){
61 try (DatagramSocket socket = new DatagramSocket(4445)){ 68 try (DatagramSocket socket = new DatagramSocket(4445)){
62 69
63 - byte[] buf = new byte[256]; 70 + byte[] buf;
64 71
65 String dString = "{\"LOCATE\": \"" + clientMacAddress + "\", \"SERV\": \"" + Inet4Address.getLocalHost().getHostAddress()+"\"}"; 72 String dString = "{\"LOCATE\": \"" + clientMacAddress + "\", \"SERV\": \"" + Inet4Address.getLocalHost().getHostAddress()+"\"}";
66 buf = dString.getBytes(); 73 buf = dString.getBytes();
src/main/resources/hibernate.cfg.xml
@@ -10,7 +10,7 @@ @@ -10,7 +10,7 @@
10 <property name="connection.username">lo53_user</property> 10 <property name="connection.username">lo53_user</property>
11 <property name="connection.password">lo53</property> 11 <property name="connection.password">lo53</property>
12 <property name="connection.pool_size">1</property> 12 <property name="connection.pool_size">1</property>
13 - <property name="hibernate.hbm2ddl.auto">create</property> 13 + <property name="hibernate.hbm2ddl.auto">update</property>
14 14
15 <mapping class="core.repository.AccessPoint"/> 15 <mapping class="core.repository.AccessPoint"/>
16 <mapping class="core.repository.Location"/> 16 <mapping class="core.repository.Location"/>