Commit 05fe05604dabec18427ced96052dc006420c0d55

Authored by thomas godart
1 parent da345024

Web interface

AccessPointListener beginning
First servlets management
.gitignore 0 → 100644
  1 +# Created by .ignore support plugin (hsz.mobi)
... ...
.idea/artifacts/LO53_mobile_localization_war_exploded.xml
... ... @@ -33,6 +33,7 @@
33 33 <element id="library" level="project" name="Maven: commons-beanutils:commons-beanutils:1.9.3" />
34 34 <element id="library" level="project" name="Maven: commons-logging:commons-logging:1.2" />
35 35 <element id="library" level="project" name="Maven: commons-collections:commons-collections:3.2.2" />
  36 + <element id="library" level="project" name="Maven: taglibs:standard:1.1.2" />
36 37 </element>
37 38 </element>
38 39 <element id="directory" name="META-INF">
... ...
.idea/dataSources/767b098c-c5bc-42ee-b3bc-d02e521ecc23.xml
... ... @@ -9,8 +9,8 @@
9 9 </database>
10 10 <schema id="3" parent="2" name="public">
11 11 <ObjectId>2200</ObjectId>
12   - <IntrospectionTimestamp>2017-05-31.07:36:16.132</IntrospectionTimestamp>
13   - <IntrospectionStateNumber>11286</IntrospectionStateNumber>
  12 + <IntrospectionTimestamp>2017-06-07.19:30:21.978</IntrospectionTimestamp>
  13 + <IntrospectionStateNumber>17257</IntrospectionStateNumber>
14 14 <Current>1</Current>
15 15 <Visible>1</Visible>
16 16 </schema>
... ... @@ -30,65 +30,65 @@
30 30 <ObjectId>12113</ObjectId>
31 31 </schema>
32 32 <sequence id="9" parent="3" name="hibernate_sequence">
33   - <ObjectId>35521</ObjectId>
34   - <StateNumber>11277</StateNumber>
  33 + <ObjectId>47042</ObjectId>
  34 + <StateNumber>17248</StateNumber>
35 35 <SequenceIdentity>1</SequenceIdentity>
36 36 </sequence>
37 37 <table id="10" parent="3" name="accesspoint">
38   - <ObjectId>35523</ObjectId>
39   - <StateNumber>11285</StateNumber>
  38 + <ObjectId>47044</ObjectId>
  39 + <StateNumber>17256</StateNumber>
40 40 </table>
41 41 <table id="11" parent="3" name="location">
42   - <ObjectId>35528</ObjectId>
43   - <StateNumber>11286</StateNumber>
  42 + <ObjectId>47049</ObjectId>
  43 + <StateNumber>17257</StateNumber>
44 44 </table>
45 45 <table id="12" parent="3" name="map">
46   - <ObjectId>35533</ObjectId>
47   - <StateNumber>11284</StateNumber>
  46 + <ObjectId>47054</ObjectId>
  47 + <StateNumber>17255</StateNumber>
48 48 </table>
49 49 <table id="13" parent="3" name="rssi">
50   - <ObjectId>35541</ObjectId>
51   - <StateNumber>11286</StateNumber>
  50 + <ObjectId>47062</ObjectId>
  51 + <StateNumber>17257</StateNumber>
52 52 </table>
53 53 <column id="14" parent="10" name="id">
54 54 <Position>1</Position>
55 55 <DataType>integer|0</DataType>
56 56 <NotNull>1</NotNull>
57   - <StateNumber>11278</StateNumber>
  57 + <StateNumber>17249</StateNumber>
58 58 </column>
59 59 <column id="15" parent="10" name="mac_address">
60 60 <Position>2</Position>
61 61 <DataType>varchar(18)|0</DataType>
62   - <StateNumber>11278</StateNumber>
  62 + <StateNumber>17249</StateNumber>
63 63 </column>
64 64 <column id="16" parent="10" name="location_id_id">
65 65 <Position>3</Position>
66 66 <DataType>integer|0</DataType>
67   - <StateNumber>11278</StateNumber>
  67 + <StateNumber>17249</StateNumber>
68 68 </column>
69 69 <index id="17" parent="10" name="accesspoint_pkey">
70   - <ObjectId>35526</ObjectId>
  70 + <ObjectId>47047</ObjectId>
71 71 <ColNames>id</ColNames>
72 72 <Unique>1</Unique>
73 73 </index>
74 74 <index id="18" parent="10" name="uk_58em6b5lhouv812y1d05nwv9w">
75   - <ObjectId>35546</ObjectId>
  75 + <ObjectId>47067</ObjectId>
76 76 <ColNames>mac_address</ColNames>
77 77 <Unique>1</Unique>
78 78 </index>
79 79 <key id="19" parent="10" name="accesspoint_pkey">
80   - <ObjectId>35527</ObjectId>
  80 + <ObjectId>47048</ObjectId>
81 81 <ColNames>id</ColNames>
82 82 <UnderlyingIndexName>accesspoint_pkey</UnderlyingIndexName>
83 83 <Primary>1</Primary>
84 84 </key>
85 85 <key id="20" parent="10" name="uk_58em6b5lhouv812y1d05nwv9w">
86   - <ObjectId>35547</ObjectId>
  86 + <ObjectId>47068</ObjectId>
87 87 <ColNames>mac_address</ColNames>
88 88 <UnderlyingIndexName>uk_58em6b5lhouv812y1d05nwv9w</UnderlyingIndexName>
89 89 </key>
90 90 <foreign-key id="21" parent="10" name="fk6hlfk3hfjm2b4i72q2ihikhhf">
91   - <ObjectId>35548</ObjectId>
  91 + <ObjectId>47069</ObjectId>
92 92 <ColNames>location_id_id</ColNames>
93 93 <RefTableName>location</RefTableName>
94 94 <RefKeyName>location_pkey</RefKeyName>
... ... @@ -98,38 +98,38 @@
98 98 <Position>1</Position>
99 99 <DataType>integer|0</DataType>
100 100 <NotNull>1</NotNull>
101   - <StateNumber>11279</StateNumber>
  101 + <StateNumber>17250</StateNumber>
102 102 </column>
103 103 <column id="23" parent="11" name="x">
104 104 <Position>2</Position>
105 105 <DataType>double precision|0</DataType>
106 106 <NotNull>1</NotNull>
107   - <StateNumber>11279</StateNumber>
  107 + <StateNumber>17250</StateNumber>
108 108 </column>
109 109 <column id="24" parent="11" name="y">
110 110 <Position>3</Position>
111 111 <DataType>double precision|0</DataType>
112 112 <NotNull>1</NotNull>
113   - <StateNumber>11279</StateNumber>
  113 + <StateNumber>17250</StateNumber>
114 114 </column>
115 115 <column id="25" parent="11" name="map_id">
116 116 <Position>4</Position>
117 117 <DataType>integer|0</DataType>
118   - <StateNumber>11279</StateNumber>
  118 + <StateNumber>17250</StateNumber>
119 119 </column>
120 120 <index id="26" parent="11" name="location_pkey">
121   - <ObjectId>35531</ObjectId>
  121 + <ObjectId>47052</ObjectId>
122 122 <ColNames>id</ColNames>
123 123 <Unique>1</Unique>
124 124 </index>
125 125 <key id="27" parent="11" name="location_pkey">
126   - <ObjectId>35532</ObjectId>
  126 + <ObjectId>47053</ObjectId>
127 127 <ColNames>id</ColNames>
128 128 <UnderlyingIndexName>location_pkey</UnderlyingIndexName>
129 129 <Primary>1</Primary>
130 130 </key>
131 131 <foreign-key id="28" parent="11" name="fk5t1p6agc1qiyteqvt1tbkml2e">
132   - <ObjectId>35553</ObjectId>
  132 + <ObjectId>47074</ObjectId>
133 133 <ColNames>map_id</ColNames>
134 134 <RefTableName>map</RefTableName>
135 135 <RefKeyName>map_pkey</RefKeyName>
... ... @@ -139,109 +139,101 @@
139 139 <Position>1</Position>
140 140 <DataType>integer|0</DataType>
141 141 <NotNull>1</NotNull>
142   - <StateNumber>11280</StateNumber>
  142 + <StateNumber>17251</StateNumber>
143 143 </column>
144 144 <column id="30" parent="12" name="content">
145 145 <Position>2</Position>
146 146 <DataType>bytea|0</DataType>
147   - <StateNumber>11280</StateNumber>
  147 + <StateNumber>17251</StateNumber>
148 148 </column>
149 149 <column id="31" parent="12" name="description">
150 150 <Position>3</Position>
151 151 <DataType>varchar(100)|0</DataType>
152   - <StateNumber>11280</StateNumber>
  152 + <StateNumber>17251</StateNumber>
153 153 </column>
154 154 <column id="32" parent="12" name="m_height">
155 155 <Position>4</Position>
156 156 <DataType>double precision|0</DataType>
157 157 <NotNull>1</NotNull>
158   - <StateNumber>11280</StateNumber>
  158 + <StateNumber>17251</StateNumber>
159 159 </column>
160 160 <column id="33" parent="12" name="m_width">
161 161 <Position>5</Position>
162 162 <DataType>double precision|0</DataType>
163 163 <NotNull>1</NotNull>
164   - <StateNumber>11280</StateNumber>
  164 + <StateNumber>17251</StateNumber>
165 165 </column>
166 166 <column id="34" parent="12" name="px_height">
167 167 <Position>6</Position>
168 168 <DataType>integer|0</DataType>
169 169 <NotNull>1</NotNull>
170   - <StateNumber>11280</StateNumber>
  170 + <StateNumber>17251</StateNumber>
171 171 </column>
172 172 <column id="35" parent="12" name="px_width">
173 173 <Position>7</Position>
174 174 <DataType>integer|0</DataType>
175 175 <NotNull>1</NotNull>
176   - <StateNumber>11280</StateNumber>
  176 + <StateNumber>17251</StateNumber>
177 177 </column>
178 178 <index id="36" parent="12" name="map_pkey">
179   - <ObjectId>35539</ObjectId>
  179 + <ObjectId>47060</ObjectId>
180 180 <ColNames>id</ColNames>
181 181 <Unique>1</Unique>
182 182 </index>
183 183 <key id="37" parent="12" name="map_pkey">
184   - <ObjectId>35540</ObjectId>
  184 + <ObjectId>47061</ObjectId>
185 185 <ColNames>id</ColNames>
186 186 <UnderlyingIndexName>map_pkey</UnderlyingIndexName>
187 187 <Primary>1</Primary>
188 188 </key>
189   - <column id="38" parent="13" name="accesspointid">
  189 + <column id="38" parent="13" name="id">
190 190 <Position>1</Position>
191 191 <DataType>integer|0</DataType>
192 192 <NotNull>1</NotNull>
193   - <StateNumber>11281</StateNumber>
  193 + <StateNumber>17252</StateNumber>
194 194 </column>
195   - <column id="39" parent="13" name="locationid">
  195 + <column id="39" parent="13" name="occurences">
196 196 <Position>2</Position>
197 197 <DataType>integer|0</DataType>
198 198 <NotNull>1</NotNull>
199   - <StateNumber>11281</StateNumber>
  199 + <StateNumber>17252</StateNumber>
200 200 </column>
201   - <column id="40" parent="13" name="occurences">
  201 + <column id="40" parent="13" name="value">
202 202 <Position>3</Position>
203   - <DataType>integer|0</DataType>
204   - <NotNull>1</NotNull>
205   - <StateNumber>11281</StateNumber>
206   - </column>
207   - <column id="41" parent="13" name="value">
208   - <Position>4</Position>
209 203 <DataType>double precision|0</DataType>
210 204 <NotNull>1</NotNull>
211   - <StateNumber>11281</StateNumber>
  205 + <StateNumber>17252</StateNumber>
212 206 </column>
213   - <column id="42" parent="13" name="accesspoint_id">
214   - <Position>5</Position>
  207 + <column id="41" parent="13" name="accesspoint_id">
  208 + <Position>4</Position>
215 209 <DataType>integer|0</DataType>
216   - <StateNumber>11281</StateNumber>
  210 + <StateNumber>17252</StateNumber>
217 211 </column>
218   - <column id="43" parent="13" name="location_id">
219   - <Position>6</Position>
  212 + <column id="42" parent="13" name="location_id">
  213 + <Position>5</Position>
220 214 <DataType>integer|0</DataType>
221   - <StateNumber>11281</StateNumber>
  215 + <StateNumber>17252</StateNumber>
222 216 </column>
223   - <index id="44" parent="13" name="rssi_pkey">
224   - <ObjectId>35544</ObjectId>
225   - <ColNames>accesspointid
226   -locationid</ColNames>
  217 + <index id="43" parent="13" name="rssi_pkey">
  218 + <ObjectId>47065</ObjectId>
  219 + <ColNames>id</ColNames>
227 220 <Unique>1</Unique>
228 221 </index>
229   - <key id="45" parent="13" name="rssi_pkey">
230   - <ObjectId>35545</ObjectId>
231   - <ColNames>accesspointid
232   -locationid</ColNames>
  222 + <key id="44" parent="13" name="rssi_pkey">
  223 + <ObjectId>47066</ObjectId>
  224 + <ColNames>id</ColNames>
233 225 <UnderlyingIndexName>rssi_pkey</UnderlyingIndexName>
234 226 <Primary>1</Primary>
235 227 </key>
236   - <foreign-key id="46" parent="13" name="fk6g5r08ytgt65j1ge02na9qnbh">
237   - <ObjectId>35558</ObjectId>
  228 + <foreign-key id="45" parent="13" name="fk6g5r08ytgt65j1ge02na9qnbh">
  229 + <ObjectId>47079</ObjectId>
238 230 <ColNames>accesspoint_id</ColNames>
239 231 <RefTableName>accesspoint</RefTableName>
240 232 <RefKeyName>accesspoint_pkey</RefKeyName>
241 233 <RefColNames>id</RefColNames>
242 234 </foreign-key>
243   - <foreign-key id="47" parent="13" name="fk8s4vdy24a1d8idnwoxi0njnko">
244   - <ObjectId>35563</ObjectId>
  235 + <foreign-key id="46" parent="13" name="fk8s4vdy24a1d8idnwoxi0njnko">
  236 + <ObjectId>47084</ObjectId>
245 237 <ColNames>location_id</ColNames>
246 238 <RefTableName>location</RefTableName>
247 239 <RefKeyName>location_pkey</RefKeyName>
... ...
.idea/dataSources/767b098c-c5bc-42ee-b3bc-d02e521ecc23/_metadata_/metadata
No preview for this file type
.idea/dataSources/767b098c-c5bc-42ee-b3bc-d02e521ecc23/_metadata_/metadata.values.at
No preview for this file type
LO53_mobile_localization.iml
1 1 <?xml version="1.0" encoding="UTF-8"?>
2   -<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
  2 +<module classpath="eclipse" classpath-dir="$MODULE_DIR$" org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
3 3 <component name="FacetManager">
4 4 <facet type="hibernate" name="Hibernate">
5 5 <configuration>
6 6 <datasource-map>
7 7 <unit-entry name="hibernate.cfg.xml" value="767b098c-c5bc-42ee-b3bc-d02e521ecc23" />
8 8 </datasource-map>
9   - <naming-strategy-map />
  9 + <naming-strategy-map>
  10 + <unit-entry name="hibernate.cfg.xml" />
  11 + </naming-strategy-map>
10 12 <deploymentDescriptor name="hibernate.cfg.xml" url="file://$MODULE_DIR$/src/main/resources/hibernate.cfg.xml" />
11 13 </configuration>
12 14 </facet>
13 15 <facet type="web" name="Web">
14 16 <configuration>
  17 + <descriptors>
  18 + <deploymentDescriptor name="context.xml" url="file://$MODULE_DIR$/src/main/webapp/META-INF/context.xml" />
  19 + <deploymentDescriptor name="web.xml" url="file://$MODULE_DIR$/src/main/webapp/WEB-INF/web.xml" />
  20 + </descriptors>
15 21 <webroots>
16 22 <root url="file://$MODULE_DIR$/src/main/webapp" relative="/" />
17 23 </webroots>
... ... @@ -22,44 +28,4 @@
22 28 </configuration>
23 29 </facet>
24 30 </component>
25   - <component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_7" inherit-compiler-output="false">
26   - <output url="file://$MODULE_DIR$/target/classes" />
27   - <output-test url="file://$MODULE_DIR$/target/test-classes" />
28   - <content url="file://$MODULE_DIR$">
29   - <sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
30   - <sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
31   - <sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
32   - <excludeFolder url="file://$MODULE_DIR$/target" />
33   - </content>
34   - <orderEntry type="inheritedJdk" />
35   - <orderEntry type="sourceFolder" forTests="false" />
36   - <orderEntry type="library" name="Maven: org.hibernate:hibernate-core:5.2.5.Final" level="project" />
37   - <orderEntry type="library" name="Maven: org.jboss.logging:jboss-logging:3.3.0.Final" level="project" />
38   - <orderEntry type="library" name="Maven: org.hibernate.javax.persistence:hibernate-jpa-2.1-api:1.0.0.Final" level="project" />
39   - <orderEntry type="library" name="Maven: org.javassist:javassist:3.20.0-GA" level="project" />
40   - <orderEntry type="library" name="Maven: antlr:antlr:2.7.7" level="project" />
41   - <orderEntry type="library" name="Maven: org.apache.geronimo.specs:geronimo-jta_1.1_spec:1.1.1" level="project" />
42   - <orderEntry type="library" name="Maven: org.jboss:jandex:2.0.3.Final" level="project" />
43   - <orderEntry type="library" name="Maven: com.fasterxml:classmate:1.3.0" level="project" />
44   - <orderEntry type="library" name="Maven: dom4j:dom4j:1.6.1" level="project" />
45   - <orderEntry type="library" name="Maven: org.hibernate.common:hibernate-commons-annotations:5.0.1.Final" level="project" />
46   - <orderEntry type="library" name="Maven: javax.enterprise:cdi-api:1.1" level="project" />
47   - <orderEntry type="library" name="Maven: javax.el:el-api:2.2" level="project" />
48   - <orderEntry type="library" name="Maven: org.jboss.spec.javax.interceptor:jboss-interceptors-api_1.1_spec:1.0.0.Beta1" level="project" />
49   - <orderEntry type="library" name="Maven: javax.annotation:jsr250-api:1.0" level="project" />
50   - <orderEntry type="library" name="Maven: javax.inject:javax.inject:1" level="project" />
51   - <orderEntry type="library" name="Maven: org.apache.tomcat:tomcat-servlet-api:9.0.0.M15" level="project" />
52   - <orderEntry type="library" scope="RUNTIME" name="Maven: org.slf4j:slf4j-log4j12:1.5.8" level="project" />
53   - <orderEntry type="library" scope="RUNTIME" name="Maven: log4j:log4j:1.2.14" level="project" />
54   - <orderEntry type="library" name="Maven: org.slf4j:slf4j-api:1.5.8" level="project" />
55   - <orderEntry type="library" name="Maven: postgresql:postgresql:9.1-901.jdbc4" level="project" />
56   - <orderEntry type="library" name="Maven: org.hibernate:hibernate-annotations:3.5.6-Final" level="project" />
57   - <orderEntry type="library" name="Maven: org.hibernate:hibernate-commons-annotations:3.2.0.Final" level="project" />
58   - <orderEntry type="library" name="Maven: org.hibernate.javax.persistence:hibernate-jpa-2.0-api:1.0.0.Final" level="project" />
59   - <orderEntry type="library" name="Maven: commons-beanutils:commons-beanutils:1.9.3" level="project" />
60   - <orderEntry type="library" name="Maven: commons-logging:commons-logging:1.2" level="project" />
61   - <orderEntry type="library" name="Maven: commons-collections:commons-collections:3.2.2" level="project" />
62   - <orderEntry type="library" scope="TEST" name="Maven: junit:junit:4.12" level="project" />
63   - <orderEntry type="library" scope="TEST" name="Maven: org.hamcrest:hamcrest-core:1.3" level="project" />
64   - </component>
65 31 </module>
66 32 \ No newline at end of file
... ...
... ... @@ -73,6 +73,11 @@
73 73 <version>4.12</version>
74 74 <scope>test</scope>
75 75 </dependency>
  76 + <dependency>
  77 + <groupId>taglibs</groupId>
  78 + <artifactId>standard</artifactId>
  79 + <version>1.1.2</version>
  80 + </dependency>
76 81 </dependencies>
77 82  
78 83  
... ...
src/main/java/com/lo53_mobile_localization/core/entity/Rssi.java
... ... @@ -8,18 +8,15 @@ import java.io.Serializable;
8 8 */
9 9  
10 10 @Entity
11   -public class Rssi implements Serializable {
  11 +public class Rssi implements Serializable, IEntity {
12 12  
13   - @EmbeddedId
14   - private RssiID id;
  13 + @Id
  14 + @GeneratedValue
  15 + private int id;
15 16  
16   - @MapsId("locationId")
17   - @JoinColumn(name = "location_id")
18 17 @OneToOne
19 18 private Location location;
20 19  
21   - @MapsId("accessPointId")
22   - @JoinColumn(name = "accessPoint_id")
23 20 @OneToOne
24 21 private AccessPoint accessPoint;
25 22  
... ... @@ -43,10 +40,6 @@ public class Rssi implements Serializable {
43 40 this.occurences = occurences;
44 41 }
45 42  
46   - public RssiID getId() {
47   - return id;
48   - }
49   -
50 43 public Location getLocation() {
51 44 return location;
52 45 }
... ... @@ -62,4 +55,9 @@ public class Rssi implements Serializable {
62 55 public void setAccessPoint(AccessPoint accessPoint) {
63 56 this.accessPoint = accessPoint;
64 57 }
  58 +
  59 + @Override
  60 + public int getId() {
  61 + return id;
  62 + }
65 63 }
... ...
src/main/java/com/lo53_mobile_localization/core/entity/RssiID.java
... ... @@ -3,6 +3,7 @@ package com.lo53_mobile_localization.core.entity;
3 3 import javax.persistence.Column;
4 4 import javax.persistence.Embeddable;
5 5 import java.io.Serializable;
  6 +import java.util.Objects;
6 7  
7 8 /**
8 9 * Created by Thomas on 18/05/2017.
... ... @@ -11,8 +12,10 @@ import java.io.Serializable;
11 12 @Embeddable
12 13 public class RssiID implements Serializable {
13 14  
  15 +
14 16 @Column(name = "location_id")
15 17 private int locationId;
  18 +
16 19 @Column(name = "accessPoint_id")
17 20 private int accessPointId;
18 21  
... ... @@ -31,4 +34,18 @@ public class RssiID implements Serializable {
31 34 public void setAccessPointId(int accessPointId) {
32 35 this.accessPointId = accessPointId;
33 36 }
  37 +
  38 + @Override
  39 + public boolean equals(Object o) {
  40 + if (this == o) return true;
  41 + if (!(o instanceof RssiID)) return false;
  42 + RssiID that = (RssiID) o;
  43 + return Objects.equals(getLocationId(), that.getLocationId()) &&
  44 + Objects.equals(getAccessPointId(), that.getAccessPointId());
  45 + }
  46 +
  47 + @Override
  48 + public int hashCode() {
  49 + return Objects.hash(getAccessPointId(), getLocationId());
  50 + }
34 51 }
... ...
src/main/java/com/lo53_mobile_localization/core/repository/RSSIDAO.java
1 1 package com.lo53_mobile_localization.core.repository;
2 2  
  3 +import com.lo53_mobile_localization.core.entity.AccessPoint;
  4 +import com.lo53_mobile_localization.core.entity.Location;
3 5 import com.lo53_mobile_localization.core.entity.Rssi;
4 6 import com.lo53_mobile_localization.core.entity.RssiID;
5 7 import com.lo53_mobile_localization.core.util.HibernateUtil;
... ... @@ -21,136 +23,10 @@ import java.util.List;
21 23 /**
22 24 * Created by Thomas on 10/05/2017.
23 25 */
24   -public class RSSIDAO {
25   -
26   - protected Logger LOGGER;
27   - protected EntityManagerFactory emf = Persistence.createEntityManagerFactory("rssi");
28   - protected EntityManager em = emf.createEntityManager();
  26 +public class RSSIDAO extends DefaultDAO<Rssi>{
29 27  
30 28 public RSSIDAO() {
31 29 super();
  30 + entityType = Rssi.class;
32 31 }
33   -
34   - /**
35   - * To insert an entity into the database
36   - * @param entity
37   - */
38   - public void insertEntity(Rssi entity) {
39   - Session session = HibernateUtil.getSession();
40   - EntityTransaction entr = em.getTransaction();
41   - try {
42   - entr.begin();
43   - session.persist(entity);
44   - entr.commit();
45   - } catch(Exception e) {
46   - LOGGER.error("error in insertEntity: " + e);
47   - if(entr != null)
48   - entr.rollback();
49   - throw e;
50   - }
51   - }
52   -
53   - /**
54   - * To update an entity into the database
55   - * @param id
56   - * @param entity
57   - */
58   - public void updateEntity(RssiID id, Rssi entity) throws Exception {
59   -
60   - Rssi storedEntity = getEntity(id);
61   -
62   - try {
63   - BeanUtils.copyProperties(storedEntity, entity);
64   - } catch (IllegalAccessException|InvocationTargetException e) {
65   - LOGGER.error("error in updateEntity: " + e);
66   - throw e;
67   - }
68   -
69   - Session session = HibernateUtil.getSession();
70   - Transaction tr = session.getTransaction();
71   - try {
72   - tr.begin();
73   - session.update(entity);
74   - tr.commit();
75   - } catch(Exception e) {
76   - LOGGER.error("error in updateEntity: " + e);
77   - if(tr != null)
78   - tr.rollback();
79   - throw e;
80   - }
81   - }
82   -
83   - /**
84   - * To remove an entity into the database
85   - * @param id
86   - */
87   - public void removeEntity(RssiID id) throws Exception {
88   -
89   - Rssi entity = getEntity(id);
90   -
91   - Session session = HibernateUtil.getSession();
92   - Transaction tr = session.getTransaction();
93   - try {
94   - tr.begin();
95   - session.delete(entity);
96   - tr.commit();
97   - } catch(Exception e) {
98   - LOGGER.error("error in removeEntity: " + e);
99   - if(tr != null)
100   - tr.rollback();
101   - throw e;
102   - }
103   - }
104   -
105   - /**
106   - * To get an entity from its id and class
107   - * @param id
108   - * @return
109   - */
110   - @SuppressWarnings(value="unchecked")
111   - public Rssi getEntity(RssiID id) throws Exception {
112   - Rssi entity = null;
113   -
114   - Session session = HibernateUtil.getSession();
115   - Transaction tr = session.getTransaction();
116   - try {
117   - tr.begin();
118   - String hql = "From Rssi r where r.id.locationId = :locationId AND r.id.accessPointId = :accessPointId";
119   -
120   -
121   -
122   - String strLocId = Integer.toString(id.getLocationId());
123   - String strApId = Integer.toString(id.getAccessPointId());
124   - Query query = HibernateUtil.getSession().createQuery(hql);
125   - query.setParameter("locationId",strApId);
126   - query.setParameter("accessPointId", strApId);
127   - entity = (Rssi)query.getSingleResult();
128   - tr.commit();
129   - } catch(Exception e) {
130   - LOGGER.error("error in getEntity: " + e);
131   - if(tr != null)
132   - tr.rollback();
133   - throw e;
134   - }
135   - return entity;
136   - }
137   -
138   - /**
139   - * To get all entities
140   - * @return
141   - */
142   - public List getEntities() throws Exception {
143   - List listEntities = null;
144   -
145   - Session session = HibernateUtil.getSession();
146   - try {
147   - Query query = session.createQuery("from Rssi");
148   - listEntities = query.list();
149   - }catch (HibernateException e) {
150   - LOGGER.error("error in getEntities: " + e);
151   - throw e;
152   - }
153   - return listEntities;
154   - }
155   -
156 32 }
... ...
src/main/java/com/lo53_mobile_localization/core/service/AccessPointService.java
... ... @@ -2,7 +2,12 @@ package com.lo53_mobile_localization.core.service;
2 2  
3 3 import com.lo53_mobile_localization.core.entity.AccessPoint;
4 4 import com.lo53_mobile_localization.core.entity.IEntity;
  5 +import com.lo53_mobile_localization.core.entity.Location;
  6 +import com.lo53_mobile_localization.core.entity.Rssi;
5 7 import com.lo53_mobile_localization.core.repository.AccessPointDAO;
  8 +import com.lo53_mobile_localization.core.util.HibernateUtil;
  9 +import org.hibernate.Session;
  10 +import org.hibernate.query.Query;
6 11  
7 12 import java.util.List;
8 13  
... ... @@ -37,4 +42,35 @@ public class AccessPointService implements IService{
37 42 public List getEntities() throws Exception {
38 43 return this.accessPointDAO.getEntities();
39 44 }
  45 +
  46 + public AccessPoint getSingleAccessPointFromMacAdress(String mac){
  47 +
  48 + Session session = HibernateUtil.getSession();
  49 + session.beginTransaction();
  50 +
  51 + String hql= "from " + AccessPoint.class.getCanonicalName() + " ap where ap.mac_address = :mac";
  52 +
  53 + Query query = session.createQuery(hql);
  54 + query.setParameter("mac", mac);
  55 +
  56 + AccessPoint result = (AccessPoint) query.getSingleResult();
  57 +
  58 + return result;
  59 + }
  60 +
  61 + public List<AccessPoint> getAccessPointFromMacAdress(String mac){
  62 +
  63 + Session session = HibernateUtil.getSession();
  64 + session.beginTransaction();
  65 +
  66 + String hql= "from " + AccessPoint.class.getCanonicalName() + " ap where ap.mac_address = :mac";
  67 +
  68 + Query query = session.createQuery(hql);
  69 + query.setParameter("mac", mac);
  70 +
  71 + List<AccessPoint> result = query.list();
  72 +
  73 + return result;
  74 + }
  75 +
40 76 }
... ...
src/main/java/com/lo53_mobile_localization/core/service/LocationService.java
1 1 package com.lo53_mobile_localization.core.service;
2 2  
  3 +import com.lo53_mobile_localization.core.entity.AccessPoint;
3 4 import com.lo53_mobile_localization.core.entity.IEntity;
4 5 import com.lo53_mobile_localization.core.entity.Location;
  6 +import com.lo53_mobile_localization.core.entity.Rssi;
5 7 import com.lo53_mobile_localization.core.repository.LocationDAO;
  8 +import com.lo53_mobile_localization.core.util.HibernateUtil;
  9 +import org.hibernate.Session;
  10 +import org.hibernate.query.Query;
6 11  
7 12 import java.util.List;
8 13  
... ... @@ -37,4 +42,20 @@ public class LocationService implements IService {
37 42 public List getEntities() throws Exception {
38 43 return this.locationDAO.getEntities();
39 44 }
  45 +
  46 + public Location getLocationFromCoordinates(double x, double y){
  47 +
  48 + Session session = HibernateUtil.getSession();
  49 + session.beginTransaction();
  50 +
  51 + String hql= "from " + Location.class.getCanonicalName() + " l where l.x = :x and l.y = :y";
  52 +
  53 + Query query = session.createQuery(hql);
  54 + query.setParameter("x", x);
  55 + query.setParameter("y",y);
  56 +
  57 + Location result = (Location) query.getSingleResult();
  58 +
  59 + return result;
  60 + }
40 61 }
... ...
src/main/java/com/lo53_mobile_localization/core/service/RSSIService.java
1 1 package com.lo53_mobile_localization.core.service;
2 2  
3   -import com.lo53_mobile_localization.core.entity.IEntity;
4   -import com.lo53_mobile_localization.core.entity.Rssi;
5   -import com.lo53_mobile_localization.core.entity.RssiID;
  3 +import com.lo53_mobile_localization.core.entity.*;
6 4 import com.lo53_mobile_localization.core.repository.RSSIDAO;
  5 +import com.lo53_mobile_localization.core.util.HibernateUtil;
  6 +import org.hibernate.Session;
  7 +import org.hibernate.query.Query;
7 8  
8 9 import java.util.List;
9 10  
... ... @@ -19,23 +20,56 @@ public class RSSIService {
19 20 this.rssi_recordDAO = new RSSIDAO();
20 21 }
21 22  
22   - public void storeEntity(Rssi entity) {
  23 + public void storeEntity(IEntity entity) {
23 24 this.rssi_recordDAO.insertEntity((Rssi) entity);
24 25 }
25 26  
26   - public void updateEntity(RssiID id, Rssi entity) throws Exception {
  27 + public void updateEntity(int id, IEntity entity) throws Exception {
27 28 this.rssi_recordDAO.updateEntity(id, (Rssi) entity);
28 29 }
29 30  
30   - public void removeEntity(RssiID id) throws Exception {
  31 + public void removeEntity(int id) throws Exception {
31 32 this.rssi_recordDAO.removeEntity(id);
32 33 }
33 34  
34   - public Rssi getEntity(RssiID id) throws Exception {
  35 + public Rssi getEntity(int id) throws Exception {
35 36 return this.rssi_recordDAO.getEntity(id);
36 37 }
37 38  
38 39 public List getEntities() throws Exception {
39 40 return this.rssi_recordDAO.getEntities();
40 41 }
  42 +
  43 + public Rssi getRssiWithLocationAndAP(Location location, AccessPoint ap){
  44 +
  45 + Session session = HibernateUtil.getSession();
  46 + session.beginTransaction();
  47 +
  48 + String hql= "from " + Rssi.class.getCanonicalName() + " r where r.location.id = :loc and r.accessPoint.id = :accesspoint";
  49 +
  50 + Query query = session.createQuery(hql);
  51 + query.setParameter("loc", location.getId());
  52 + query.setParameter("accesspoint",ap.getId());
  53 +
  54 + Rssi result = (Rssi)query.getSingleResult();
  55 +
  56 + return result;
  57 + }
  58 +
  59 + public List<Rssi> getRssiWithMacAdress(String mac){
  60 +
  61 + Session session = HibernateUtil.getSession();
  62 + session.beginTransaction();
  63 +
  64 + String hql= "from " + Rssi.class.getCanonicalName() + " r where r.accessPoint.mac_address = :macAddress";
  65 +
  66 + Query query = session.createQuery(hql);
  67 + query.setParameter("macAddress", mac);
  68 +
  69 + List<Rssi> result = query.list();
  70 +
  71 + return result;
  72 + }
  73 +
  74 +
41 75 }
... ...
src/main/java/com/lo53_mobile_localization/core/servlet/CalibrationServlet.java
1 1 package com.lo53_mobile_localization.core.servlet;
2 2  
  3 +import com.lo53_mobile_localization.core.entity.Location;
  4 +import com.lo53_mobile_localization.core.service.LocationService;
  5 +import com.lo53_mobile_localization.core.servlet.util.Param;
  6 +
  7 +import javax.servlet.ServletException;
  8 +import javax.servlet.annotation.WebServlet;
3 9 import javax.servlet.http.HttpServlet;
  10 +import javax.servlet.http.HttpServletRequest;
  11 +import javax.servlet.http.HttpServletResponse;
4 12 import java.io.BufferedReader;
5 13 import java.io.FileReader;
6 14 import java.io.IOException;
  15 +import java.net.DatagramPacket;
  16 +import java.net.DatagramSocket;
  17 +import java.net.InetAddress;
  18 +import java.nio.charset.StandardCharsets;
7 19  
8 20 /**
9 21 * Created by Thomas on 18/05/2017.
10 22 */
  23 +@WebServlet(
  24 + name = "CalibrationServlet",
  25 + urlPatterns = {"/calibration"}
  26 +)
11 27 public class CalibrationServlet extends HttpServlet {
12 28  
13 29  
  30 + public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
  31 +
  32 + response.setContentType(Param.CONTENT_TYPE);
  33 +
  34 + request.getRequestDispatcher(Param.PATH_CALIBRATION).forward(request, response);
  35 +
  36 +
  37 + }
  38 + public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
  39 +
  40 + String apRequestIp = request.getRemoteAddr();
  41 + System.out.println("Request from " + apRequestIp + " received");
  42 +
  43 + int x = -1;
  44 + int y = -1;
  45 + try{
  46 + x = Integer.parseInt(request.getParameter("positionX"));
  47 + y = Integer.parseInt(request.getParameter("positionY"));
  48 +
  49 + System.out.println("x = " + x + " y = " + y);
  50 + }catch (NumberFormatException nfe){
  51 + System.out.println("Wrong parameters");
  52 + }
  53 +
  54 + if (x != -1 && y != -1){
14 55  
  56 + //String macAddr = getMacAddressFromArpTable(apRequestIp);
  57 + String macAddr = "12:12:12:12:12:12";
15 58  
  59 + if (macAddr != null){
  60 + System.out.println("MAC Address found : "+macAddr);
  61 + DatagramSocket socket = null;
  62 + try{
  63 + for (int i = 0 ; i < Param.AP_IPS.length ; i++){
  64 +
  65 + InetAddress address = InetAddress.getByAddress(Param.AP_IPS[i]);
  66 + socket = new DatagramSocket(Param.AP_COMM_PORT);
  67 +
  68 + String msg = buildRssiRequestMessage(Param.AP_IPS[i], Param.AP_COMM_PORT);
  69 +
  70 + DatagramPacket packet = new DatagramPacket(msg.getBytes(), msg.length(), address, Param.AP_COMM_PORT);
  71 + socket.send(packet);
  72 + System.out.println("Sending "+msg+" to AP number " + i);
  73 + }
  74 + socket.close();
  75 + } catch (IOException iox){
  76 + System.out.println(iox+" [Calibration Servlet] IOException");
  77 + }finally{
  78 + if (socket != null) socket.close();
  79 + }
  80 + }else{
  81 + System.out.println("MAC Address not found !");
  82 + }
  83 + }else{
  84 + System.out.println("Coordinates not found");
  85 + }
  86 + request.getRequestDispatcher(Param.PATH_CALIBRATION).forward(request, response);
  87 + }
  88 +
  89 + private String getMacAddressFromArpTable(String ip) throws IOException {
16 90  
17   - private String getMacAdressFromArpTable(String ip) throws IOException {
18   - // Open the ARP table too look up for this IP
19 91 BufferedReader in = new BufferedReader(new FileReader("/proc/net/arp"));
20 92 String strLine;
21 93 String macAddr = null;
22 94  
23   - // Read File Line By Line
24 95 while ((strLine = in.readLine()) != null) {
25   - // Find the matching IP
26 96 System.out.println(strLine);
27 97 if (strLine.contains(ip)) {
28   - // Split the line
29 98 String[] table = strLine.split(" ");
30   - // Retrieve the MAC Address
31   - //macAddr = table[24];
32 99 for (int i = 0; i < table.length; i++) {
33 100 if (table[i].length() == 17)
34 101 macAddr = table[i];
35   - //System.out.println("Table["+i+"] : "+table[i]);
36 102 }
37 103 }
38 104 }
39 105 return macAddr;
40 106 }
41 107  
  108 + private String buildRssiRequestMessage(byte [] apIp, int port){
  109 +
  110 + String request = "http://";
  111 +
  112 + String ip = new String(apIp, StandardCharsets.UTF_8);
  113 +
  114 + String macaddress = (String) getServletContext().getAttribute("macaddress");
  115 + String map_id = "1";
  116 + String get = "/get";
  117 + String macReq = "macs=";
  118 +
  119 + request += ip + ":" + port + get + "?";
  120 + request += macReq + macaddress;
  121 +
  122 + System.out.println(request);
  123 +
  124 + return request;
  125 + }
  126 +
42 127 }
... ...
src/main/java/com/lo53_mobile_localization/core/servlet/PositionServlet.java 0 → 100644
  1 +package com.lo53_mobile_localization.core.servlet;
  2 +
  3 +import com.lo53_mobile_localization.core.entity.Rssi;
  4 +import com.lo53_mobile_localization.core.service.RSSIService;
  5 +import com.lo53_mobile_localization.core.servlet.util.Param;
  6 +
  7 +import java.io.BufferedReader;
  8 +
  9 +import java.io.FileReader;
  10 +import java.io.IOException;
  11 +import java.net.DatagramPacket;
  12 +import java.net.DatagramSocket;
  13 +import java.net.InetAddress;
  14 +import java.nio.charset.StandardCharsets;
  15 +import java.util.List;
  16 +
  17 +import javax.servlet.ServletException;
  18 +import javax.servlet.annotation.WebServlet;
  19 +import javax.servlet.http.HttpServlet;
  20 +import javax.servlet.http.HttpServletRequest;
  21 +import javax.servlet.http.HttpServletResponse;
  22 +
  23 +
  24 +@WebServlet(
  25 + name = "PositionServlet",
  26 + urlPatterns = {"/position"}
  27 +)public class PositionServlet extends HttpServlet {
  28 +
  29 + protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  30 +
  31 + String requestIp = request.getRemoteAddr();
  32 + System.out.println("Request from ip : " + requestIp);
  33 +
  34 + //String macAddr = getMacAdressFromArpTable(requestIp);
  35 + String macAddr = "12:12:12:12:12:12";
  36 +
  37 + if (macAddr != null) {
  38 +
  39 + // Send Get request to all APs
  40 + DatagramSocket socket = null;
  41 + try {
  42 + for (int i = 0; i < Param.AP_IPS.length; i++) {
  43 + InetAddress address = InetAddress.getByAddress(Param.AP_IPS[i]);
  44 + socket = new DatagramSocket(Param.AP_COMM_PORT);
  45 +
  46 + String msg = buildMessage(macAddr, Param.AP_IPS[i]);
  47 +
  48 + DatagramPacket packet = new DatagramPacket(msg.getBytes(), msg.length(), address, Param.AP_COMM_PORT);
  49 + socket.send(packet);
  50 + System.out.println("Sending " + msg + " to AP number " + i);
  51 + }
  52 + socket.close();
  53 + } catch (IOException iox) {
  54 + System.out.println("[Positioning Servlet:Sending GET message to APs] IOException");
  55 + } finally {
  56 + if (socket != null) socket.close();
  57 + }
  58 +
  59 + // Sleep during 500ms
  60 + try {
  61 + Thread.sleep(500);
  62 + } catch (InterruptedException e1) {
  63 + e1.printStackTrace();
  64 + }
  65 +
  66 + RSSIService rssiService = new RSSIService();
  67 +
  68 + List<Rssi> rssis = rssiService.getRssiWithMacAdress(macAddr);
  69 +
  70 + int nbRes = 0;
  71 + for (Rssi r : rssis) {
  72 + nbRes++;
  73 + }
  74 +
  75 +
  76 + }
  77 + }
  78 +
  79 +
  80 + protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  81 + }
  82 +
  83 + private String getMacAdressFromArpTable(String ip) throws IOException {
  84 +
  85 + BufferedReader in = new BufferedReader(new FileReader("/proc/net/arp"));
  86 + String strLine;
  87 + String macAddr = null;
  88 +
  89 + while ((strLine = in.readLine()) != null) {
  90 + System.out.println(strLine);
  91 + if (strLine.contains(ip)) {
  92 + String[] table = strLine.split(" ");
  93 + //macAddr = table[24];
  94 + for (int i = 0; i < table.length; i++) {
  95 + if (table[i].length() == 17)
  96 + macAddr = table[i];
  97 + }
  98 + }
  99 + }
  100 + return macAddr;
  101 + }
  102 +
  103 + private String buildMessage(String mac, byte[] apIp){
  104 +
  105 + //String msg = http://<AP IP>:<PORT>/get?macs=XX:XX:XX:XX:XX
  106 +
  107 + String request = "http://";
  108 +
  109 + String ip = new String(apIp, StandardCharsets.UTF_8);
  110 + int port = Param.AP_COMM_PORT;
  111 + String map_id = "1";
  112 + String positionServlet = "/position";
  113 +
  114 + request += ip + ":" + port + positionServlet + "?";
  115 + request += "macs=" + mac;
  116 +
  117 + System.out.println(request);
  118 +
  119 + return request;
  120 + }
  121 +
  122 +}
0 123 \ No newline at end of file
... ...
src/main/java/com/lo53_mobile_localization/core/servlet/PreferencesServlet.java 0 → 100644
  1 +package com.lo53_mobile_localization.core.servlet;
  2 +
  3 +import com.lo53_mobile_localization.core.servlet.util.Param;
  4 +
  5 +import javax.servlet.ServletException;
  6 +import javax.servlet.annotation.WebServlet;
  7 +import javax.servlet.http.HttpServlet;
  8 +import javax.servlet.http.HttpServletRequest;
  9 +import javax.servlet.http.HttpServletResponse;
  10 +import java.io.IOException;
  11 +import java.util.regex.Matcher;
  12 +import java.util.regex.Pattern;
  13 +
  14 +/**
  15 + * Created by Thomas on 03/06/2017.
  16 + */
  17 +@WebServlet(
  18 + name = "PreferencesServlet",
  19 + urlPatterns = {"/preferences"}
  20 +)
  21 +public class PreferencesServlet extends HttpServlet {
  22 +
  23 + public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
  24 + response.setContentType(Param.CONTENT_TYPE);
  25 + request.setAttribute("message", "HELLO THERE");
  26 + request.getRequestDispatcher(Param.PATH_PREFERENCES).forward(request,response);
  27 +
  28 + }
  29 +
  30 + public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
  31 +
  32 + response.setContentType(Param.CONTENT_TYPE);
  33 +
  34 + String macAddress = request.getParameter(Param.AP_MAC_ADDRESS);
  35 + String ip = request.getParameter(Param.ATTRIBUTE_IP);
  36 + String port = request.getParameter(Param.ATTRIBUTE_PORT);
  37 +
  38 + String IP_PATTERN = "^([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\."
  39 + + "([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\."
  40 + + "([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\."
  41 + + "([01]?\\d\\d?|2[0-4]\\d|25[0-5])$";
  42 +
  43 + String MAC_PATTERN = "^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$";
  44 +
  45 + String PORT_PATTERN = "[0-9]{4}";
  46 +
  47 + Pattern patternMac = Pattern.compile(MAC_PATTERN);
  48 + Matcher matchMac = patternMac.matcher(macAddress);
  49 +
  50 + Pattern patternIP = Pattern.compile(IP_PATTERN);
  51 + Matcher matchIp = patternIP.matcher(ip);
  52 +
  53 + Pattern patternPort = Pattern.compile(PORT_PATTERN);
  54 + Matcher matchPort = patternPort.matcher(port);
  55 +
  56 + if (!matchIp.find() || !matchMac.find() || !matchPort.find()) {
  57 + System.out.println("ERROR IN SETTINGS");
  58 + request.setAttribute("message", "ERROR IN ONE OF THE FIELDS");
  59 + request.getRequestDispatcher(Param.PATH_PREFERENCES).forward(request, response);
  60 +
  61 + } else {
  62 +
  63 + System.out.println("MAC ADDRESS = " + macAddress + " IP = " + ip + " PORT = " + port);
  64 +
  65 + getServletContext().setAttribute("macaddress", macAddress);
  66 + getServletContext().setAttribute("ip", ip);
  67 + getServletContext().setAttribute("port", port);
  68 +
  69 + request.getRequestDispatcher(Param.PATH_HOME).forward(request, response);
  70 + }
  71 + }
  72 +
  73 +}
... ...
src/main/java/com/lo53_mobile_localization/core/servlet/util/Param.java 0 → 100644
  1 +package com.lo53_mobile_localization.core.servlet.util;
  2 +
  3 +/**
  4 + * Created by Thomas on 03/06/2017.
  5 + */
  6 +public class Param{
  7 +
  8 +
  9 + public static final String ATTRIBUTE_IP = "ip";
  10 + public static final String ATTRIBUTE_PORT = "port";
  11 +
  12 + public static final String AP_MAC_ADDRESS = "macaddress";
  13 +
  14 + public static final String PATH_PREFERENCES= "/jsp/preferences.jsp";
  15 + public static final String PATH_POSITION= "/jsp/position.jsp";
  16 + public static final String PATH_CALIBRATION="/jsp/calibration.jsp";
  17 +
  18 + public static final String PATH_HOME = "/index.jsp";
  19 +
  20 + public static final String CONTENT_TYPE = "text/html;charset=UTF-8";
  21 +
  22 + public static final int AP_COMM_PORT = 7777;
  23 +
  24 + public static final byte[][] AP_IPS = {
  25 + {(byte)192,(byte)168,(byte)1,(byte)1},
  26 + {(byte)192,(byte)168,(byte)1,(byte)2},
  27 + {(byte)192,(byte)168,(byte)1,(byte)3}
  28 + };
  29 +
  30 + public static final int DATAG_LISTENING_PORT = 8080;
  31 +
  32 + public static final String CALIBRATION = "calibration";
  33 + public static final String POSITION = "position";
  34 +
  35 +
  36 +}
... ...
src/test/java/com/lo53_mobile_localization/core/service/RssiServiceTest.java
... ... @@ -2,9 +2,6 @@ package com.lo53_mobile_localization.core.service;
2 2  
3 3 import com.lo53_mobile_localization.core.entity.*;
4 4 import com.lo53_mobile_localization.core.helpers.HibernateTestHelper;
5   -import com.lo53_mobile_localization.core.repository.AccessPointDAO;
6   -import com.lo53_mobile_localization.core.repository.LocationDAO;
7   -import com.lo53_mobile_localization.core.repository.RSSIDAO;
8 5 import org.junit.Before;
9 6 import org.junit.Test;
10 7  
... ... @@ -18,8 +15,8 @@ import static org.junit.Assert.assertTrue;
18 15 */
19 16 public class RssiServiceTest extends HibernateTestHelper{
20 17  
21   - Rssi item = null;
22   - RSSIService service;
  18 + private Rssi item = null;
  19 + private RSSIService service;
23 20  
24 21 @Before
25 22 public void setUp() throws Exception {
... ... @@ -31,19 +28,18 @@ public class RssiServiceTest extends HibernateTestHelper{
31 28 Location loc = new Location();
32 29 AccessPoint ap = new AccessPoint();
33 30  
34   - LocationDAO locationDAO = new LocationDAO();
35   - AccessPointDAO accessPointDAO = new AccessPointDAO();
  31 + LocationService locationService = new LocationService();
  32 + AccessPointService apService = new AccessPointService();
36 33  
37   - locationDAO.insertEntity(loc);
38   - accessPointDAO.insertEntity(ap);
  34 + locationService.storeEntity(loc);
  35 + apService.storeEntity(ap);
39 36  
40   - rssi.getId().setAccessPointId(ap.getId());
41   - rssi.getId().setLocationId(loc.getId());
  37 + rssi.setAccessPoint(ap);
  38 + rssi.setLocation(loc);
42 39 rssi.setValue(10);
43 40 rssi.setOccurences(6);
44 41  
45   - RSSIDAO rssiDao = new RSSIDAO();
46   - rssiDao.insertEntity(rssi);
  42 + service.storeEntity(rssi);
47 43  
48 44 item = rssi;
49 45 }
... ... @@ -62,8 +58,14 @@ public class RssiServiceTest extends HibernateTestHelper{
62 58 Location loc = new Location();
63 59 AccessPoint ap = new AccessPoint();
64 60  
65   - testingRssi.getId().setAccessPointId(ap.getId());
66   - testingRssi.getId().setLocationId(loc.getId());
  61 + AccessPointService apService = new AccessPointService();
  62 + LocationService locationService = new LocationService();
  63 +
  64 + locationService.storeEntity(loc);
  65 + apService.storeEntity(ap);
  66 +
  67 + testingRssi.setAccessPoint(ap);
  68 + testingRssi.setLocation(loc);
67 69  
68 70 service.storeEntity(testingRssi);
69 71  
... ... @@ -116,5 +118,14 @@ public class RssiServiceTest extends HibernateTestHelper{
116 118 assertTrue(storedItems.containsAll(addedItems));
117 119 }
118 120  
  121 + @Test
  122 + public void getRssiWithLocationAndAP(){
  123 +
  124 + Rssi testRssi = service.getRssiWithLocationAndAP(item.getLocation(), item.getAccessPoint());
  125 +
  126 + assertEquals(item, testRssi);
  127 +
  128 + }
  129 +
119 130  
120 131 }
... ...