aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2012-11-17 18:04:47 +1300
committerAnton Tananaev <anton.tananaev@gmail.com>2012-11-17 18:04:47 +1300
commit3d63b73061d7ae7b56f6c1f5bfc265ef41981bbb (patch)
tree70ce974ad4c02e1b5f666ed65f283692522349f0 /src
parentefc59ab19fc92242d3532f990d129908f79be480 (diff)
downloadtrackermap-web-3d63b73061d7ae7b56f6c1f5bfc265ef41981bbb.tar.gz
trackermap-web-3d63b73061d7ae7b56f6c1f5bfc265ef41981bbb.tar.bz2
trackermap-web-3d63b73061d7ae7b56f6c1f5bfc265ef41981bbb.zip
Add database model
Diffstat (limited to 'src')
-rw-r--r--src/main/java/org/traccar/web/client/Traccar.java32
-rw-r--r--src/main/java/org/traccar/web/client/database/DatabaseService.java11
-rw-r--r--src/main/java/org/traccar/web/client/database/DatabaseServiceAsync.java10
-rw-r--r--src/main/java/org/traccar/web/server/database/DatabaseServiceImpl.java34
-rw-r--r--src/main/java/org/traccar/web/shared/model/Device.java38
-rw-r--r--src/main/java/org/traccar/web/shared/model/Position.java46
-rw-r--r--src/main/java/org/traccar/web/shared/model/User.java44
-rw-r--r--src/main/resources/META-INF/persistence.xml17
-rw-r--r--src/main/webapp/WEB-INF/classes/org/traccar/web/Traccar.gwt.xml4
-rw-r--r--src/main/webapp/WEB-INF/web.xml10
10 files changed, 235 insertions, 11 deletions
diff --git a/src/main/java/org/traccar/web/client/Traccar.java b/src/main/java/org/traccar/web/client/Traccar.java
index 9ba3e774..fdd8dac4 100644
--- a/src/main/java/org/traccar/web/client/Traccar.java
+++ b/src/main/java/org/traccar/web/client/Traccar.java
@@ -1,14 +1,12 @@
package org.traccar.web.client;
-import com.google.gwt.core.client.EntryPoint;
-import com.smartgwt.client.types.Alignment;
-import com.smartgwt.client.types.Overflow;
-import com.smartgwt.client.widgets.Canvas;
-import com.smartgwt.client.widgets.Label;
-import com.smartgwt.client.widgets.layout.HLayout;
-import com.smartgwt.client.widgets.layout.VLayout;
+import org.traccar.web.client.database.DatabaseService;
+import org.traccar.web.client.database.DatabaseServiceAsync;
-import org.traccar.web.client.login.LoginDialog;
+import com.google.gwt.core.client.EntryPoint;
+import com.google.gwt.core.client.GWT;
+import com.google.gwt.user.client.rpc.AsyncCallback;
+import com.smartgwt.client.util.SC;
/**
* Entry point class
@@ -24,11 +22,25 @@ public class Traccar implements EntryPoint {
*/
public void onModuleLoad() {
+ DatabaseServiceAsync databaseService = GWT.create(DatabaseService.class);
+
+ AsyncCallback<Boolean> callback = new AsyncCallback<Boolean>() {
+ public void onFailure(Throwable caught) {
+ SC.say("onFailure: " + caught.toString());
+ }
+
+ public void onSuccess(Boolean result) {
+ SC.say("onSuccess: " + result);
+ }
+ };
+
+ databaseService.authenticate("test", "test", callback);
+
/*LoginDialog loginDialog = new LoginDialog();
loginDialog.draw();
loginDialog.centerInPage();*/
- devicePanel = new DevicePanel();
+ /*devicePanel = new DevicePanel();
devicePanel.setWidth("20%");
devicePanel.setShowResizeBar(true);
@@ -50,6 +62,6 @@ public class Traccar implements EntryPoint {
mainLayout.setHeight100();
mainLayout.addMember(hLayout);
mainLayout.addMember(archivePanel);
- mainLayout.draw();
+ mainLayout.draw();*/
}
}
diff --git a/src/main/java/org/traccar/web/client/database/DatabaseService.java b/src/main/java/org/traccar/web/client/database/DatabaseService.java
new file mode 100644
index 00000000..6d08a5ca
--- /dev/null
+++ b/src/main/java/org/traccar/web/client/database/DatabaseService.java
@@ -0,0 +1,11 @@
+package org.traccar.web.client.database;
+
+import com.google.gwt.user.client.rpc.RemoteService;
+import com.google.gwt.user.client.rpc.RemoteServiceRelativePath;
+
+@RemoteServiceRelativePath("databaseService")
+public interface DatabaseService extends RemoteService {
+
+ boolean authenticate(String login, String password);
+
+}
diff --git a/src/main/java/org/traccar/web/client/database/DatabaseServiceAsync.java b/src/main/java/org/traccar/web/client/database/DatabaseServiceAsync.java
new file mode 100644
index 00000000..471edf00
--- /dev/null
+++ b/src/main/java/org/traccar/web/client/database/DatabaseServiceAsync.java
@@ -0,0 +1,10 @@
+package org.traccar.web.client.database;
+
+import com.google.gwt.user.client.rpc.AsyncCallback;
+
+public interface DatabaseServiceAsync {
+
+ void authenticate(String login, String password,
+ AsyncCallback<Boolean> callback);
+
+}
diff --git a/src/main/java/org/traccar/web/server/database/DatabaseServiceImpl.java b/src/main/java/org/traccar/web/server/database/DatabaseServiceImpl.java
new file mode 100644
index 00000000..89f72e6c
--- /dev/null
+++ b/src/main/java/org/traccar/web/server/database/DatabaseServiceImpl.java
@@ -0,0 +1,34 @@
+package org.traccar.web.server.database;
+
+import javax.persistence.EntityManager;
+import javax.persistence.Persistence;
+
+import org.traccar.web.client.database.DatabaseService;
+import org.traccar.web.shared.model.User;
+
+import com.google.gwt.user.server.rpc.RemoteServiceServlet;
+
+public class DatabaseServiceImpl extends RemoteServiceServlet implements DatabaseService {
+
+ public boolean authenticate(String login, String password) {
+
+ EntityManager entityManager = Persistence.createEntityManagerFactory("traccar").createEntityManager();
+ entityManager.getTransaction().begin();
+
+ User user = new User();
+ user.setLogin("test");
+ user.setPassword("1");
+
+ entityManager.persist(user);
+ entityManager.getTransaction().commit();
+
+ //User foundUser = entityManager.find(User.class, user.getId());
+ entityManager.close();
+
+ if (login.equals("test") && password.equals("test")) {
+ return true;
+ }
+ return false;
+ }
+
+}
diff --git a/src/main/java/org/traccar/web/shared/model/Device.java b/src/main/java/org/traccar/web/shared/model/Device.java
new file mode 100644
index 00000000..17bfae29
--- /dev/null
+++ b/src/main/java/org/traccar/web/shared/model/Device.java
@@ -0,0 +1,38 @@
+package org.traccar.web.shared.model;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.Table;
+
+@Entity
+@Table(name="devices")
+public class Device {
+
+ @Id
+ @GeneratedValue
+ long id;
+
+ @Column(unique = true)
+ private String uniqueId;
+
+ public void setUniqueId(String uniqueId) {
+ this.uniqueId = uniqueId;
+ }
+
+ public String getUniqueId() {
+ return uniqueId;
+ }
+
+ private String name;
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+}
diff --git a/src/main/java/org/traccar/web/shared/model/Position.java b/src/main/java/org/traccar/web/shared/model/Position.java
new file mode 100644
index 00000000..4ceb1714
--- /dev/null
+++ b/src/main/java/org/traccar/web/shared/model/Position.java
@@ -0,0 +1,46 @@
+package org.traccar.web.shared.model;
+
+import java.util.Date;
+
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.ManyToOne;
+import javax.persistence.Table;
+
+import org.hibernate.annotations.Index;
+
+@Entity
+@Table(name = "positions")
+public class Position {
+
+ @Id
+ @GeneratedValue
+ long id;
+
+ @ManyToOne
+ @Index(name = "positionsIndex")
+ private Device device;
+
+ public void setDevice(Device device) {
+ this.device = device;
+ }
+
+ public Device getDevice() {
+ return device;
+ }
+
+ @Index(name = "positionsIndex")
+ private Date time;
+
+ public void setTime(Date time) {
+ this.time = time;
+ }
+
+ public Date getTime() {
+ return time;
+ }
+
+ // TODO: other
+
+}
diff --git a/src/main/java/org/traccar/web/shared/model/User.java b/src/main/java/org/traccar/web/shared/model/User.java
new file mode 100644
index 00000000..b82dd8e7
--- /dev/null
+++ b/src/main/java/org/traccar/web/shared/model/User.java
@@ -0,0 +1,44 @@
+package org.traccar.web.shared.model;
+
+import java.util.List;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.ManyToMany;
+import javax.persistence.Table;
+
+@Entity
+@Table(name="users")
+public class User {
+
+ @Id
+ @GeneratedValue
+ long id;
+
+ @Column(unique = true)
+ private String login;
+
+ public void setLogin(String login) {
+ this.login = login;
+ }
+
+ public String getLogin() {
+ return login;
+ }
+
+ private String password;
+
+ public void setPassword(String password) {
+ this.password = password;
+ }
+
+ public String getPassword() {
+ return password;
+ }
+
+ @ManyToMany
+ private List<Device> devices;
+
+}
diff --git a/src/main/resources/META-INF/persistence.xml b/src/main/resources/META-INF/persistence.xml
new file mode 100644
index 00000000..a89d96d1
--- /dev/null
+++ b/src/main/resources/META-INF/persistence.xml
@@ -0,0 +1,17 @@
+<persistence xmlns="http://java.sun.com/xml/ns/persistence"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
+ version="2.0">
+ <persistence-unit name="traccar">
+ <provider>org.hibernate.ejb.HibernatePersistence</provider>
+ <properties>
+ <property name="hibernate.show_sql" value="true"/>
+ <property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"/>
+ <property name="hibernate.connection.url" value="jdbc:mysql://localhost/test"/>
+ <property name="hibernate.connection.username" value="root"/>
+ <property name="hibernate.connection.password" value="root"/>
+ <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
+ <property name="hibernate.hbm2ddl.auto" value="create-drop"/>
+ </properties>
+ </persistence-unit>
+</persistence>
diff --git a/src/main/webapp/WEB-INF/classes/org/traccar/web/Traccar.gwt.xml b/src/main/webapp/WEB-INF/classes/org/traccar/web/Traccar.gwt.xml
index ff123394..086d2a48 100644
--- a/src/main/webapp/WEB-INF/classes/org/traccar/web/Traccar.gwt.xml
+++ b/src/main/webapp/WEB-INF/classes/org/traccar/web/Traccar.gwt.xml
@@ -10,11 +10,13 @@
<!-- Inherit the default GWT style sheet. You can change -->
<!-- the theme of your GWT application by uncommenting -->
<!-- any one of the following lines. -->
- <inherits name='com.google.gwt.user.theme.standard.Standard' />
+ <!-- <inherits name='com.google.gwt.user.theme.standard.Standard' /> -->
<!-- <inherits name='com.google.gwt.user.theme.chrome.Chrome'/> -->
<!-- <inherits name='com.google.gwt.user.theme.dark.Dark'/> -->
<!-- Other module inherits -->
+ <inherits name='com.smartgwt.SmartGwt' />
+ <inherits name='org.gwtopenmaps.openlayers.OpenLayers' />
<!-- Specify the app entry point class. -->
<entry-point class='org.traccar.web.client.Traccar' />
diff --git a/src/main/webapp/WEB-INF/web.xml b/src/main/webapp/WEB-INF/web.xml
index 81fa375a..a7412ce9 100644
--- a/src/main/webapp/WEB-INF/web.xml
+++ b/src/main/webapp/WEB-INF/web.xml
@@ -25,6 +25,16 @@
<login-config>
<auth-method>BASIC</auth-method>
</login-config>-->
+
+ <servlet>
+ <servlet-name>databaseService</servlet-name>
+ <servlet-class>org.traccar.web.server.database.DatabaseServiceImpl</servlet-class>
+ </servlet>
+
+ <servlet-mapping>
+ <servlet-name>databaseService</servlet-name>
+ <url-pattern>/Traccar/databaseService</url-pattern>
+ </servlet-mapping>
<welcome-file-list>
<welcome-file>traccar.html</welcome-file>