diff options
-rw-r--r-- | pom.xml | 34 | ||||
-rw-r--r-- | src/main/java/org/traccar/web/client/Traccar.java | 32 | ||||
-rw-r--r-- | src/main/java/org/traccar/web/client/database/DatabaseService.java | 11 | ||||
-rw-r--r-- | src/main/java/org/traccar/web/client/database/DatabaseServiceAsync.java | 10 | ||||
-rw-r--r-- | src/main/java/org/traccar/web/server/database/DatabaseServiceImpl.java | 34 | ||||
-rw-r--r-- | src/main/java/org/traccar/web/shared/model/Device.java | 38 | ||||
-rw-r--r-- | src/main/java/org/traccar/web/shared/model/Position.java | 46 | ||||
-rw-r--r-- | src/main/java/org/traccar/web/shared/model/User.java | 44 | ||||
-rw-r--r-- | src/main/resources/META-INF/persistence.xml | 17 | ||||
-rw-r--r-- | src/main/webapp/WEB-INF/classes/org/traccar/web/Traccar.gwt.xml | 4 | ||||
-rw-r--r-- | src/main/webapp/WEB-INF/web.xml | 10 |
11 files changed, 265 insertions, 15 deletions
@@ -13,7 +13,7 @@ <name>GWT Maven Archetype</name> <properties> - <gwtVersion>2.4.0</gwtVersion> + <gwtVersion>2.5.0</gwtVersion> <smartGwtVersion>3.0</smartGwtVersion> <webappDirectory>${project.build.directory}/${project.build.finalName}</webappDirectory> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> @@ -69,6 +69,32 @@ <artifactId>gwt-openlayers-client</artifactId> <version>0.8</version> </dependency> + <dependency> + <groupId>mysql</groupId> + <artifactId>mysql-connector-java</artifactId> + <version>5.1.21</version> + </dependency> + + <dependency> + <groupId>org.hibernate</groupId> + <artifactId>hibernate-core</artifactId> + <version>4.1.7.Final</version> + </dependency> + <dependency> + <groupId>org.hibernate</groupId> + <artifactId>hibernate-annotations</artifactId> + <version>3.5.6-Final</version> + </dependency> + <dependency> + <groupId>org.hibernate</groupId> + <artifactId>hibernate-entitymanager</artifactId> + <version>4.1.7.Final</version> + </dependency> + <dependency> + <groupId>org.hibernate.javax.persistence</groupId> + <artifactId>hibernate-jpa-2.0-api</artifactId> + <version>1.0.0.Final</version> + </dependency> </dependencies> <build> @@ -81,7 +107,7 @@ <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>gwt-maven-plugin</artifactId> - <version>${gwtVersion}</version> + <version>2.5.0</version> <executions> <execution> <goals> @@ -92,6 +118,8 @@ </goals> </execution> </executions> + <!-- Plugin configuration. There are many available options, see + gwt-maven-plugin documentation at codehaus.org --> <configuration> <runTarget>traccar.html</runTarget> <hostedWebapp>${webappDirectory}</hostedWebapp> @@ -116,7 +144,6 @@ <webappDirectory>${webappDirectory}</webappDirectory> </configuration> </plugin> - <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> @@ -126,7 +153,6 @@ <target>1.5</target> </configuration> </plugin> - </plugins> </build> 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> |