diff --git a/PositioningServer/.idea/workspace.xml b/PositioningServer/.idea/workspace.xml index cce6fcd..56df425 100644 --- a/PositioningServer/.idea/workspace.xml +++ b/PositioningServer/.idea/workspace.xml @@ -18,117 +18,21 @@ - - + + - - + + - - + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + @@ -192,10 +96,10 @@ - @@ -237,20 +141,6 @@ - + + + + @@ -663,10 +579,9 @@ - + - @@ -680,14 +595,14 @@ - + - + @@ -695,6 +610,7 @@ + @@ -1020,28 +936,7 @@ - - - - - - - - - - - - - - - - - - - - - @@ -1056,16 +951,10 @@ - - - - - - - + - + @@ -1075,55 +964,77 @@ - + + + - + - + + + + + + + + + + + + + + + + + + + - - + + - + - - + + - + - - + + - - - - - - - + + + + + + + + + - + @@ -1133,7 +1044,7 @@ - + @@ -1141,20 +1052,30 @@ - + - - + + - + + + - + - - + + + + + + + + + + diff --git a/PositioningServer/PositioningServer.iml b/PositioningServer/PositioningServer.iml index a35874b..924ebe1 100644 --- a/PositioningServer/PositioningServer.iml +++ b/PositioningServer/PositioningServer.iml @@ -1,6 +1,6 @@ - + diff --git a/PositioningServer/Server_Servlets/Server_Servlets.iml b/PositioningServer/Server_Servlets/Server_Servlets.iml index 9ca1ec2..f599562 100644 --- a/PositioningServer/Server_Servlets/Server_Servlets.iml +++ b/PositioningServer/Server_Servlets/Server_Servlets.iml @@ -1,6 +1,6 @@ - + diff --git a/project/.idea/compiler.xml b/project/.idea/compiler.xml new file mode 100644 index 0000000..70ac13f --- /dev/null +++ b/project/.idea/compiler.xml @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/project/.idea/libraries/Maven__antlr_antlr_2_7_6.xml b/project/.idea/libraries/Maven__antlr_antlr_2_7_6.xml new file mode 100644 index 0000000..c8d18a7 --- /dev/null +++ b/project/.idea/libraries/Maven__antlr_antlr_2_7_6.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/project/.idea/libraries/Maven__commons_collections_commons_collections_3_1.xml b/project/.idea/libraries/Maven__commons_collections_commons_collections_3_1.xml new file mode 100644 index 0000000..01dd005 --- /dev/null +++ b/project/.idea/libraries/Maven__commons_collections_commons_collections_3_1.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/project/.idea/libraries/Maven__dom4j_dom4j_1_6_1.xml b/project/.idea/libraries/Maven__dom4j_dom4j_1_6_1.xml new file mode 100644 index 0000000..14681ee --- /dev/null +++ b/project/.idea/libraries/Maven__dom4j_dom4j_1_6_1.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/project/.idea/libraries/Maven__javassist_javassist_3_9_0_GA.xml b/project/.idea/libraries/Maven__javassist_javassist_3_9_0_GA.xml new file mode 100644 index 0000000..8d8be19 --- /dev/null +++ b/project/.idea/libraries/Maven__javassist_javassist_3_9_0_GA.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/project/.idea/libraries/Maven__javax_javaee_web_api_6_0.xml b/project/.idea/libraries/Maven__javax_javaee_web_api_6_0.xml new file mode 100644 index 0000000..6f532e6 --- /dev/null +++ b/project/.idea/libraries/Maven__javax_javaee_web_api_6_0.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/project/.idea/libraries/Maven__javax_transaction_jta_1_1.xml b/project/.idea/libraries/Maven__javax_transaction_jta_1_1.xml new file mode 100644 index 0000000..3047243 --- /dev/null +++ b/project/.idea/libraries/Maven__javax_transaction_jta_1_1.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/project/.idea/libraries/Maven__log4j_log4j_1_2_14.xml b/project/.idea/libraries/Maven__log4j_log4j_1_2_14.xml new file mode 100644 index 0000000..2825a67 --- /dev/null +++ b/project/.idea/libraries/Maven__log4j_log4j_1_2_14.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/project/.idea/libraries/Maven__org_hibernate_hibernate_annotations_3_5_6_Final.xml b/project/.idea/libraries/Maven__org_hibernate_hibernate_annotations_3_5_6_Final.xml new file mode 100644 index 0000000..d26bdad --- /dev/null +++ b/project/.idea/libraries/Maven__org_hibernate_hibernate_annotations_3_5_6_Final.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/project/.idea/libraries/Maven__org_hibernate_hibernate_commons_annotations_3_2_0_Final.xml b/project/.idea/libraries/Maven__org_hibernate_hibernate_commons_annotations_3_2_0_Final.xml new file mode 100644 index 0000000..dbb890e --- /dev/null +++ b/project/.idea/libraries/Maven__org_hibernate_hibernate_commons_annotations_3_2_0_Final.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/project/.idea/libraries/Maven__org_hibernate_hibernate_core_3_5_6_Final.xml b/project/.idea/libraries/Maven__org_hibernate_hibernate_core_3_5_6_Final.xml new file mode 100644 index 0000000..2083af8 --- /dev/null +++ b/project/.idea/libraries/Maven__org_hibernate_hibernate_core_3_5_6_Final.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/project/.idea/libraries/Maven__org_hibernate_javax_persistence_hibernate_jpa_2_0_api_1_0_0_Final.xml b/project/.idea/libraries/Maven__org_hibernate_javax_persistence_hibernate_jpa_2_0_api_1_0_0_Final.xml new file mode 100644 index 0000000..6b42b8a --- /dev/null +++ b/project/.idea/libraries/Maven__org_hibernate_javax_persistence_hibernate_jpa_2_0_api_1_0_0_Final.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/project/.idea/libraries/Maven__org_postgresql_postgresql_9_4_1212.xml b/project/.idea/libraries/Maven__org_postgresql_postgresql_9_4_1212.xml new file mode 100644 index 0000000..ad56bbd --- /dev/null +++ b/project/.idea/libraries/Maven__org_postgresql_postgresql_9_4_1212.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/project/.idea/libraries/Maven__org_slf4j_slf4j_api_1_5_8.xml b/project/.idea/libraries/Maven__org_slf4j_slf4j_api_1_5_8.xml new file mode 100644 index 0000000..0ea470a --- /dev/null +++ b/project/.idea/libraries/Maven__org_slf4j_slf4j_api_1_5_8.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/project/.idea/libraries/Maven__org_slf4j_slf4j_log4j12_1_5_8.xml b/project/.idea/libraries/Maven__org_slf4j_slf4j_log4j12_1_5_8.xml new file mode 100644 index 0000000..f4725a3 --- /dev/null +++ b/project/.idea/libraries/Maven__org_slf4j_slf4j_log4j12_1_5_8.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/project/.idea/libraries/Maven__xml_apis_xml_apis_1_0_b2.xml b/project/.idea/libraries/Maven__xml_apis_xml_apis_1_0_b2.xml new file mode 100644 index 0000000..c36e717 --- /dev/null +++ b/project/.idea/libraries/Maven__xml_apis_xml_apis_1_0_b2.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/project/.idea/misc.xml b/project/.idea/misc.xml new file mode 100644 index 0000000..e8942bd --- /dev/null +++ b/project/.idea/misc.xml @@ -0,0 +1,13 @@ + + + + + + + + + \ No newline at end of file diff --git a/project/.idea/modules.xml b/project/.idea/modules.xml new file mode 100644 index 0000000..30a22c7 --- /dev/null +++ b/project/.idea/modules.xml @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/project/.idea/workspace.xml b/project/.idea/workspace.xml new file mode 100644 index 0000000..7d16e52 --- /dev/null +++ b/project/.idea/workspace.xml @@ -0,0 +1,882 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1495960020203 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/project/pom.xml b/project/pom.xml new file mode 100644 index 0000000..0929d1e --- /dev/null +++ b/project/pom.xml @@ -0,0 +1,66 @@ + + + 4.0.0 + + com.utbm.lo53 + project + pom + 1.0-SNAPSHOT + + server_core + server_servlet + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + 1.8 + 1.8 + + + + + + + + org.postgresql + postgresql + 9.4.1212 + + + + + org.hibernate + hibernate-core + 3.5.6-Final + + + + + org.hibernate + hibernate-annotations + 3.5.6-Final + + + + + org.slf4j + slf4j-log4j12 + 1.5.8 + runtime + + + + javassist + javassist + 3.9.0.GA + runtime + + + + \ No newline at end of file diff --git a/project/project.iml b/project/project.iml new file mode 100644 index 0000000..924ebe1 --- /dev/null +++ b/project/project.iml @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/project/server_core/pom.xml b/project/server_core/pom.xml new file mode 100644 index 0000000..8599beb --- /dev/null +++ b/project/server_core/pom.xml @@ -0,0 +1,16 @@ + + + + project + com.utbm.lo53 + 1.0-SNAPSHOT + + jar + 4.0.0 + + server_core + + + \ No newline at end of file diff --git a/project/server_core/server_core.iml b/project/server_core/server_core.iml new file mode 100644 index 0000000..924ebe1 --- /dev/null +++ b/project/server_core/server_core.iml @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/project/server_core/src/main/java/dao/DebianDao.java b/project/server_core/src/main/java/dao/DebianDao.java new file mode 100644 index 0000000..079842f --- /dev/null +++ b/project/server_core/src/main/java/dao/DebianDao.java @@ -0,0 +1,9 @@ +package com.utbm.lo53.dao; + +/** + * Created by Guillaume on 09/05/2017. + */ +public class DebianDao { + + public String getMacAddr(String ipAddr){return null;} +} diff --git a/project/server_core/src/main/java/dao/HibernateDao.java b/project/server_core/src/main/java/dao/HibernateDao.java new file mode 100644 index 0000000..a4913d1 --- /dev/null +++ b/project/server_core/src/main/java/dao/HibernateDao.java @@ -0,0 +1,175 @@ +package dao; + +import repository.*; +import utils.HibernateUtil; +import org.hibernate.HibernateException; +import org.hibernate.Query; +import org.hibernate.Session; + +import java.util.ArrayList; +import java.util.List; + +/** + * Created by Guillaume on 09/05/2017. + */ +public class HibernateDao { + + public HibernateDao () { + } + + private TransactionCallBack execTransactionProcess(ITransactionProcess itp) { + Session session = HibernateUtil.getSessionFactory().openSession(); + TransactionCallBack reply = new TransactionCallBack(); + try { + session.beginTransaction(); + reply = itp.exec(session); + session.getTransaction().commit(); + reply.setStatus(true); + return reply; + } catch (HibernateException he) { + he.printStackTrace(); + if (session.getTransaction() != null) { + try { + session.getTransaction().rollback(); + } catch (HibernateException he2) { + he2.printStackTrace(); + } + } + } finally { + if (session != null) { + try { + session.close(); + } catch (HibernateException ex) { + ex.printStackTrace(); + } + } + } + return reply; + } + private List internal_getData(Class clazz){ + TransactionCallBack callBack = execTransactionProcess((session)->{ + TransactionCallBack reply = new TransactionCallBack(); + Query query = session.createQuery("from "+clazz.getSimpleName()); + List results = query.list(); + for(Object result : results){ + if(clazz.isInstance(result)) + reply.getResults().add(result); + } + return reply; + }); + return callBack.getResults(); + } + private boolean internal_saveData(Object... objs){ + TransactionCallBack callBack = execTransactionProcess((session)->{ + TransactionCallBack reply = new TransactionCallBack(); + for(Object obj : objs){ + session.persist(obj); + } + return reply; + }); + + return callBack!=null && callBack.isStatus(); + } + + public boolean saveTempRssi(TempRssi... trs){ + return internal_saveData(trs); + } + public List getTempRssi(String macAddr){ + if(macAddr == null) + return new ArrayList<>(); + + TransactionCallBack callBack = execTransactionProcess((session)->{ + TransactionCallBack reply = new TransactionCallBack(); + Query query = session.createQuery("from TempRssi tr where tr.client_mac_addr = :mac_addr"); + query.setParameter("mac_addr", macAddr); + List results = query.list(); + for(Object result : results){ + if(result instanceof TempRssi) + reply.getResults().add(result); + } + return reply; + }); + return callBack.getResults(); + } + + public boolean saveRssiRecord(RssiRecord... rssis){ + return internal_saveData(rssis); + } + public List getRssiRecord(){ + return internal_getData(RssiRecord.class); + } + public List getRssiRecord(Integer locationID){ + if(locationID == null) + return getRssiRecord(); + + TransactionCallBack callBack = execTransactionProcess((session)->{ + TransactionCallBack reply = new TransactionCallBack(); + Query query = session.createQuery("from RssiRecord rr where rr.id = :id"); + query.setParameter("id", locationID); + List results = query.list(); + for(Object result : results){ + if(result instanceof RssiRecord) + reply.getResults().add(result); + } + return reply; + }); + return callBack.getResults(); + } + + public List getLocations(){ + return internal_getData(Location.class); + } + + public boolean saveAccessPoint (final AccessPoint... aps) { + return internal_saveData(aps); + } + public List getAccessPoint () { + return internal_getData(AccessPoint.class); + } + + public boolean saveMap(final Mape mape){return internal_saveData(mape);} + public Mape getMap(int mapId){ + TransactionCallBack callBack = execTransactionProcess((session)->{ + TransactionCallBack reply = new TransactionCallBack(); + Query query = session.createQuery("from Mape m where m.id = :id"); + query.setParameter("id", mapId); + List results = query.list(); + for(Object result : results){ + if(result instanceof RssiRecord) + reply.getResults().add(result); + } + return reply; + }); + return (callBack.getResults().isEmpty()?null:(Mape)callBack.getResults().get(0)); + } + + private interface ITransactionProcess{ + public TransactionCallBack exec(Session tr); + } + + private class TransactionCallBack{ + private boolean status; + private List results; + + public TransactionCallBack () { + status = false; + results = new ArrayList(); + } + + public boolean isStatus () { + return status; + } + + public void setStatus (final boolean status) { + this.status = status; + } + + public List getResults () { + return results; + } + + public void setResults (final List results) { + this.results = results; + } + } +} diff --git a/project/server_core/src/main/java/repository/AccessPoint.java b/project/server_core/src/main/java/repository/AccessPoint.java new file mode 100644 index 0000000..e7cdf76 --- /dev/null +++ b/project/server_core/src/main/java/repository/AccessPoint.java @@ -0,0 +1,35 @@ +package repository; + +import java.io.Serializable; +import javax.persistence.*; + +/** + * Created by Guillaume on 09/05/2017. + */ +@Entity +@Table(name ="ACCESS_POINT") +public class AccessPoint implements Serializable{ + @Id @GeneratedValue + private Integer id; + + private String mac_addr; + + public AccessPoint () { + } + + public AccessPoint(Integer id, String mac_addr){ + this.mac_addr = mac_addr; + } + + public Integer getId(){return id;} + + public void setId(Integer id){this.id = id;} + + public String getMac_addr () { + return mac_addr; + } + + public void setMac_addr (final String mac_addr) { + this.mac_addr = mac_addr; + } +} diff --git a/project/server_core/src/main/java/repository/Location.java b/project/server_core/src/main/java/repository/Location.java new file mode 100644 index 0000000..5e03d99 --- /dev/null +++ b/project/server_core/src/main/java/repository/Location.java @@ -0,0 +1,50 @@ +package repository; + +import javax.persistence.*; +import java.io.Serializable; + +/** + * Created by Guillaume on 09/05/2017. + */ +@Entity +@Table(name = "LOCATION") +public class Location implements Serializable { + @Id @GeneratedValue + private Integer id; + private Double x, y; + + @OneToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "id", nullable = false) + private Mape mape; + + public Location () { + } + + public Integer getId(){return id;} + + public void setId(Integer id){this.id = id;} + + public Double getX () { + return x; + } + + public void setX (final Double x) { + this.x = x; + } + + public Double getY () { + return y; + } + + public void setY (final Double y) { + this.y = y; + } + + public Mape getMape () { + return mape; + } + + public void setMape (final Mape mape) { + this.mape = mape; + } +} diff --git a/project/server_core/src/main/java/repository/Mape.java b/project/server_core/src/main/java/repository/Mape.java new file mode 100644 index 0000000..1f22912 --- /dev/null +++ b/project/server_core/src/main/java/repository/Mape.java @@ -0,0 +1,77 @@ +package repository; + +import javax.persistence.*; +import java.io.Serializable; + +/** + * Created by Guillaume on 09/05/2017. + */ +@Entity +@Table(name = "MAPE") +public class Mape implements Serializable{ + @Id @GeneratedValue + private Integer id; + private Integer px_width, px_height; + private Byte[] content; + private String desc; + private Double m_width, m_height; + + public Mape () { + } + + public Integer getId () { + return id; + } + + public void setId (final Integer id) { + this.id = id; + } + + public Integer getPx_width () { + return px_width; + } + + public void setPx_width (final Integer px_width) { + this.px_width = px_width; + } + + public Integer getPx_height () { + return px_height; + } + + public void setPx_height (final Integer px_height) { + this.px_height = px_height; + } + + public Byte[] getContent () { + return content; + } + + public void setContent (final Byte[] content) { + this.content = content; + } + + public String getDesc () { + return desc; + } + + public void setDesc (final String desc) { + this.desc = desc; + } + + public Double getM_width () { + return m_width; + } + + public void setM_width (final Double m_width) { + this.m_width = m_width; + } + + public Double getM_height () { + return m_height; + } + + public void setM_height (final Double m_height) { + this.m_height = m_height; + } +} diff --git a/project/server_core/src/main/java/repository/RssiRecord.java b/project/server_core/src/main/java/repository/RssiRecord.java new file mode 100644 index 0000000..3840329 --- /dev/null +++ b/project/server_core/src/main/java/repository/RssiRecord.java @@ -0,0 +1,69 @@ +package repository; + +import javax.persistence.*; +import java.io.Serializable; + +/** + * Created by Guillaume on 09/05/2017. + */ +@Entity +@Table (name = "RSSI_RECORD") +public class RssiRecord implements Serializable { + @Id @GeneratedValue + private Integer id; + + + @OneToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "id", nullable = false) + private Location loc; + + @OneToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "id", nullable = false) + private AccessPoint ap; + + private Double avg; + private Double stdDev; + + public RssiRecord () { + } + + public RssiRecord(Location loc, AccessPoint ap, Double avg, Double stdDev){ + id = null; + this.loc = loc; + this.ap = ap; + this.avg = avg; + this.stdDev = stdDev; + } + + public Location getLoc () { + return loc; + } + + public void setLoc (final Location loc) { + this.loc = loc; + } + + public AccessPoint getAp () { + return ap; + } + + public void setAp (final AccessPoint ap) { + this.ap = ap; + } + + public Double getAvg () { + return avg; + } + + public void setAvg (final Double avg) { + this.avg = avg; + } + + public Double getStdDev () { + return stdDev; + } + + public void setStdDev (final Double stdDev) { + this.stdDev = stdDev; + } +} diff --git a/project/server_core/src/main/java/repository/TempRssi.java b/project/server_core/src/main/java/repository/TempRssi.java new file mode 100644 index 0000000..5dc60d0 --- /dev/null +++ b/project/server_core/src/main/java/repository/TempRssi.java @@ -0,0 +1,54 @@ +package repository; + +import javax.persistence.*; + +/** + * Created by Guillaume on 09/05/2017. + */ +@Entity +@Table (name = "TEMP_RSSI") +public class TempRssi { + @Id @GeneratedValue + private Integer id; + + @OneToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "id", nullable = false) + private AccessPoint ap; + + private String client_mac_addr; + private Double avg, stdDev; + + public TempRssi () {} + + public AccessPoint getAp () { + return ap; + } + + public void setAp (final AccessPoint ap) { + this.ap = ap; + } + + public String getClient_mac_addr () { + return client_mac_addr; + } + + public void setClient_mac_addr (final String client_mac_addr) { + this.client_mac_addr = client_mac_addr; + } + + public Double getAvg () { + return avg; + } + + public void setAvg (final Double avg) { + this.avg = avg; + } + + public Double getStdDev () { + return stdDev; + } + + public void setStdDev (final Double stdDev) { + this.stdDev = stdDev; + } +} diff --git a/project/server_core/src/main/java/service/CalibrationService.java b/project/server_core/src/main/java/service/CalibrationService.java new file mode 100644 index 0000000..748385d --- /dev/null +++ b/project/server_core/src/main/java/service/CalibrationService.java @@ -0,0 +1,26 @@ +package service; + +import dao.HibernateDao; +import repository.AccessPoint; +import repository.RssiRecord; + +import java.util.List; + +/** + * Created by Guillaume on 09/05/2017. + */ +public class CalibrationService { + + private HibernateDao dao; + + public CalibrationService(){this.dao = new HibernateDao();} + public CalibrationService(HibernateDao dao){this.dao = dao;} + + public boolean registerCalibrationData(RssiRecord... records){ + return dao.saveRssiRecord(records); + } + public boolean registerAp(AccessPoint ap){ + return dao.saveAccessPoint(ap); + } + public List getAllAccessPoints(){return dao.getAccessPoint();} +} diff --git a/project/server_core/src/main/java/service/ConnectionService.java b/project/server_core/src/main/java/service/ConnectionService.java new file mode 100644 index 0000000..11a1c93 --- /dev/null +++ b/project/server_core/src/main/java/service/ConnectionService.java @@ -0,0 +1,12 @@ +package service; + +/** + * Created by Guillaume on 09/05/2017. + */ +public class ConnectionService { + + + public void queryApData(boolean tryAgainMessage){} + public void acknoledge(){} + public void sendPosition(){} +} diff --git a/project/server_core/src/main/java/service/PositioningService.java b/project/server_core/src/main/java/service/PositioningService.java new file mode 100644 index 0000000..6d8de3d --- /dev/null +++ b/project/server_core/src/main/java/service/PositioningService.java @@ -0,0 +1,95 @@ +package service; + +import dao.HibernateDao; +import repository.Location; +import repository.RssiRecord; +import repository.TempRssi; + +import java.util.ArrayList; +import java.util.List; + +/** + * Created by Guillaume on 09/05/2017. + */ +public class PositioningService { + + private static final double DEFAULT_POSITIONING_PRECISION = 7.5; + + private HibernateDao dao; + + public PositioningService () { + this.dao = new HibernateDao(); + } + public PositioningService (HibernateDao dao) { + this.dao = dao; + } + + public Location getLocation (String clientMacAddr) { + Location bestLoc = null; + double bestLocProbability = -1; + for(Location loc : dao.getLocations()) { + //Liste des RSSISample pour une position donnée, chaque RSSISample étant + //assossié à un AccessPoint + List rssis = dao.getRssiRecord(loc.getId()); + + //Liste des RSSISample associé à un ap, mesuré pour un client + List clientRssi = dao.getTempRssi(clientMacAddr); + + double currentLocProbability = probability(clientRssi, rssis, DEFAULT_POSITIONING_PRECISION); + if(bestLocProbability == -1 || currentLocProbability > bestLocProbability){ + bestLoc = loc; + bestLocProbability = currentLocProbability; + } + } + return bestLoc; + } + + private double probability(List temps, List rssis, double precision){ + try { + double probability = 1; + for (TempRssi temp : temps) { + RssiRecord rssi = find(temp.getAp().getMac_addr(), rssis); + probability*=gauss_probability(temp.getAvg(), temp.getStdDev(), rssi.getAvg(), rssi.getStdDev(), precision); + } + return probability; + }catch(IllegalArgumentException e){ + e.printStackTrace(); + return -1; + } + } + private double gauss_probability(double avg1, double std1, double avg2, double std2, double precision){ + final double + valDebut = Math.min(avg1-3*std1, avg2-3*std2), + valFin = Math.max(avg1+3*std1, avg2+3*std2); + double + rectDebut = valDebut, + rectFin = valDebut+precision, + probabilite = 0; + + do{ + probabilite+=Math.min( gauss(avg1, std1, (rectDebut+rectFin)/2), gauss(avg2, std2, (rectDebut+rectFin)/2)); + rectDebut = rectFin; + rectFin+=precision; + }while(rectFin rrs){ + final List results = new ArrayList<>(); + rrs.stream().filter(rr->rr.getAp().getMac_addr().equals(macAddr)).forEach(rr->results.add(rr)); + + switch(results.size()){ + case 0: + throw new IllegalArgumentException("No matching RssiRecord for mac address <"+macAddr+">"); + case 1: + return results.get(0); + default : + throw new IllegalArgumentException("Several("+results.size()+") matching RssiRecord for mac address <"+macAddr+">"); + } + } + + +} diff --git a/project/server_core/src/main/java/utils/HibernateUtil.java b/project/server_core/src/main/java/utils/HibernateUtil.java new file mode 100644 index 0000000..9a1968c --- /dev/null +++ b/project/server_core/src/main/java/utils/HibernateUtil.java @@ -0,0 +1,21 @@ +package utils; + +import org.hibernate.SessionFactory; +import org.hibernate.cfg.AnnotationConfiguration; + +public class HibernateUtil { + + private static final SessionFactory sessionFactory = buildSessionFactory(); + private static SessionFactory buildSessionFactory() { + try { + // Create the SessionFactory from hibernate.cfg.xml + return new AnnotationConfiguration().configure().buildSessionFactory(); + } catch (Exception ex) { + System.err.println("Initial SessionFactory creation failed." + ex); + throw new ExceptionInInitializerError(ex); + } + } + public static SessionFactory getSessionFactory() { + return sessionFactory; + } +} \ No newline at end of file diff --git a/project/server_servlet/pom.xml b/project/server_servlet/pom.xml new file mode 100644 index 0000000..ebc4d7b --- /dev/null +++ b/project/server_servlet/pom.xml @@ -0,0 +1,24 @@ + + + + project + com.utbm.lo53 + 1.0-SNAPSHOT + + war + 4.0.0 + + server_servlet + + + + javax + javaee-web-api + 6.0 + provided + + + + \ No newline at end of file diff --git a/project/server_servlet/server_servlet.iml b/project/server_servlet/server_servlet.iml new file mode 100644 index 0000000..c339303 --- /dev/null +++ b/project/server_servlet/server_servlet.iml @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/project/server_servlet/src/main/java/CalibrationServlet.java b/project/server_servlet/src/main/java/CalibrationServlet.java new file mode 100644 index 0000000..e38bf1d --- /dev/null +++ b/project/server_servlet/src/main/java/CalibrationServlet.java @@ -0,0 +1,28 @@ +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; + +/** + * Created by Guillaume on 15/05/2017. + */ +public class CalibrationServlet extends HttpServlet{ + @Override + public void service (final HttpServletRequest servletRequest, final HttpServletResponse servletResponse) + throws ServletException, IOException { + //TODO + } + + @Override + public void doGet(final HttpServletRequest servletRequest, final HttpServletResponse servletResponse) + throws ServletException, IOException { + service(servletRequest, servletResponse); + } + + @Override + public void doPost(final HttpServletRequest servletRequest, final HttpServletResponse servletResponse) + throws ServletException, IOException { + service(servletRequest, servletResponse); + } +} diff --git a/project/server_servlet/src/main/java/PositioningServlet.java b/project/server_servlet/src/main/java/PositioningServlet.java new file mode 100644 index 0000000..8a7d027 --- /dev/null +++ b/project/server_servlet/src/main/java/PositioningServlet.java @@ -0,0 +1,29 @@ + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; + +/** + * Created by Guillaume on 15/05/2017. + */ +public class PositioningServlet extends HttpServlet{ + @Override + public void service (final HttpServletRequest servletRequest, final HttpServletResponse servletResponse) + throws ServletException, IOException { + //TODO + } + + @Override + public void doGet(final HttpServletRequest servletRequest, final HttpServletResponse servletResponse) + throws ServletException, IOException { + service(servletRequest, servletResponse); + } + + @Override + public void doPost(final HttpServletRequest servletRequest, final HttpServletResponse servletResponse) + throws ServletException, IOException { + service(servletRequest, servletResponse); + } +} -- libgit2 0.21.4