Skip to content

Commit

Permalink
Added notifications via email
Browse files Browse the repository at this point in the history
Added notifications settings
  • Loading branch information
Abyss777 committed Jun 25, 2016
1 parent 67f46c8 commit a25e7bd
Show file tree
Hide file tree
Showing 32 changed files with 1,009 additions and 31 deletions.
1 change: 0 additions & 1 deletion checkstyle.xml
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@

<!-- Checks for common coding problems -->
<!-- See http://checkstyle.sf.net/config_coding.html -->
<module name="AvoidInlineConditionals"/>
<module name="EmptyStatement"/>
<module name="EqualsHashCode"/>
<module name="IllegalInstantiation"/>
Expand Down
36 changes: 36 additions & 0 deletions debug.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,21 @@

<entry key='event.geofenceHandler'>true</entry>


<!--<entry key='mail.smtp.host'>smtp.example.com</entry>
for STARTTLS
<entry key='mail.smtp.port'>587</entry>
<entry key='mail.smtp.starttls.enable'>true</entry>
for SSL
<entry key='mail.smtp.port'>465</entry>
<entry key='mail.smtp.ssl.enable'>true</entry>
<entry key='mail.smtp.from'>[email protected]</entry>
<entry key='mail.smtp.auth'>true</entry>
<entry key='mail.smtp.username'>[email protected]</entry>
<entry key='mail.smtp.password'>password</entry>-->

<!-- DATABASE CONFIG -->

<!--<entry key='database.driverFile'>hsqldb.jar</entry>-->
Expand Down Expand Up @@ -280,6 +295,27 @@
DELETE FROM device_geofence WHERE deviceId = :deviceId AND geofenceId = :geofenceId;
</entry>

<entry key='database.selectNotifications'>
SELECT * FROM notifications;
</entry>

<entry key='database.insertNotification'>
INSERT INTO notifications (userId, type, attributes)
VALUES (:userId, :type, :attributes);
</entry>

<entry key='database.updateNotification'>
UPDATE notifications SET
userId = :userId,
type = :type,
attributes = :attributes
WHERE id = :id;
</entry>

<entry key='database.deleteNotification'>
DELETE FROM notifications WHERE id = :id;
</entry>

<!-- PROTOCOL CONFIG -->

<entry key='gps103.port'>5001</entry>
Expand Down
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,12 @@
<artifactId>liquibase-core</artifactId>
<version>3.4.2</version>
</dependency>
<dependency>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
<version>1.4.7</version>
</dependency>

</dependencies>

<build>
Expand Down
23 changes: 23 additions & 0 deletions schema/changelog-3.6.xml
Original file line number Diff line number Diff line change
Expand Up @@ -90,5 +90,28 @@
<addForeignKeyConstraint baseTableName="device_geofence" baseColumnNames="deviceid" constraintName="fk_user_device_geofence_deviceid" referencedTableName="devices" referencedColumnNames="id" onDelete="CASCADE" />
<addForeignKeyConstraint baseTableName="device_geofence" baseColumnNames="geofenceid" constraintName="fk_user_device_geofence_geofenceid" referencedTableName="geofences" referencedColumnNames="id" onDelete="CASCADE" />

<createTable tableName="notifications">
<column name="id" type="INT" autoIncrement="true">
<constraints primaryKey="true" />
</column>
<column name="userid" type="INT">
<constraints nullable="false" />
</column>
<column name="type" type="VARCHAR(128)">
<constraints nullable="false" />
</column>
<column name="attributes" type="VARCHAR(4096)">
<constraints nullable="false" />
</column>
</createTable>

<addForeignKeyConstraint baseTableName="notifications" baseColumnNames="userid" constraintName="fk_notifications_userid" referencedTableName="users" referencedColumnNames="id" onDelete="CASCADE" />

<addColumn tableName="users">
<column name="attributes" type="VARCHAR(4096)" />
</addColumn>

<addNotNullConstraint tableName="users" columnName="attributes" columnDataType="VARCHAR(4096)" defaultNullValue="{}" />

</changeSet>
</databaseChangeLog>
35 changes: 35 additions & 0 deletions setup/unix/traccar.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,20 @@

<entry key='event.geofenceHandler'>true</entry>

<!--<entry key='mail.smtp.host'>smtp.example.com</entry>
for STARTTLS
<entry key='mail.smtp.port'>587</entry>
<entry key='mail.smtp.starttls.enable'>true</entry>
for SSL
<entry key='mail.smtp.port'>465</entry>
<entry key='mail.smtp.ssl.enable'>true</entry>
<entry key='mail.smtp.from'>[email protected]</entry>
<entry key='mail.smtp.auth'>true</entry>
<entry key='mail.smtp.username'>[email protected]</entry>
<entry key='mail.smtp.password'>password</entry>-->

<!-- DATABASE CONFIG -->

<entry key='database.driver'>org.h2.Driver</entry>
Expand Down Expand Up @@ -252,6 +266,27 @@
DELETE FROM device_geofence WHERE deviceId = :deviceId AND geofenceId = :geofenceId;
</entry>

<entry key='database.selectNotifications'>
SELECT * FROM notifications;
</entry>

<entry key='database.insertNotification'>
INSERT INTO notifications (userId, type, attributes)
VALUES (:userId, :type, :attributes);
</entry>

<entry key='database.updateNotification'>
UPDATE notifications SET
userId = :userId,
type = :type,
attributes = :attributes
WHERE id = :id;
</entry>

<entry key='database.deleteNotification'>
DELETE FROM notifications WHERE id = :id;
</entry>

<!-- PROTOCOL CONFIG -->

<entry key='gps103.port'>5001</entry>
Expand Down
35 changes: 35 additions & 0 deletions setup/windows/traccar.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,20 @@

<entry key='event.geofenceHandler'>true</entry>

<!--<entry key='mail.smtp.host'>smtp.example.com</entry>
for STARTTLS
<entry key='mail.smtp.port'>587</entry>
<entry key='mail.smtp.starttls.enable'>true</entry>
for SSL
<entry key='mail.smtp.port'>465</entry>
<entry key='mail.smtp.ssl.enable'>true</entry>
<entry key='mail.smtp.from'>[email protected]</entry>
<entry key='mail.smtp.auth'>true</entry>
<entry key='mail.smtp.username'>[email protected]</entry>
<entry key='mail.smtp.password'>password</entry>-->

<!-- DATABASE CONFIG -->

<entry key='database.driver'>org.h2.Driver</entry>
Expand Down Expand Up @@ -252,6 +266,27 @@
DELETE FROM device_geofence WHERE deviceId = :deviceId AND geofenceId = :geofenceId;
</entry>

<entry key='database.selectNotifications'>
SELECT * FROM notifications;
</entry>

<entry key='database.insertNotification'>
INSERT INTO notifications (userId, type, attributes)
VALUES (:userId, :type, :attributes);
</entry>

<entry key='database.updateNotification'>
UPDATE notifications SET
userId = :userId,
type = :type,
attributes = :attributes
WHERE id = :id;
</entry>

<entry key='database.deleteNotification'>
DELETE FROM notifications WHERE id = :id;
</entry>

<!-- PROTOCOL CONFIG -->

<entry key='gps103.port'>5001</entry>
Expand Down
8 changes: 6 additions & 2 deletions src/org/traccar/api/resource/DevicePermissionResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ public Response add(DevicePermission entity) throws SQLException {
Context.getPermissionsManager().checkAdmin(getUserId());
Context.getDataManager().linkDevice(entity.getUserId(), entity.getDeviceId());
Context.getPermissionsManager().refresh();
Context.getGeofenceManager().refresh();
if (Context.getGeofenceManager() != null) {
Context.getGeofenceManager().refresh();
}
return Response.ok(entity).build();
}

Expand All @@ -47,7 +49,9 @@ public Response remove(DevicePermission entity) throws SQLException {
Context.getPermissionsManager().checkAdmin(getUserId());
Context.getDataManager().unlinkDevice(entity.getUserId(), entity.getDeviceId());
Context.getPermissionsManager().refresh();
Context.getGeofenceManager().refresh();
if (Context.getGeofenceManager() != null) {
Context.getGeofenceManager().refresh();
}
return Response.noContent().build();
}

Expand Down
11 changes: 9 additions & 2 deletions src/org/traccar/api/resource/DeviceResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ public Response add(Device entity) throws SQLException {
Context.getDataManager().addDevice(entity);
Context.getDataManager().linkDevice(getUserId(), entity.getId());
Context.getPermissionsManager().refresh();
Context.getGeofenceManager().refresh();
if (Context.getGeofenceManager() != null) {
Context.getGeofenceManager().refresh();
}
return Response.ok(entity).build();
}

Expand All @@ -70,6 +72,9 @@ public Response update(@PathParam("id") long id, Device entity) throws SQLExcept
Context.getPermissionsManager().checkReadonly(getUserId());
Context.getPermissionsManager().checkDevice(getUserId(), id);
Context.getDataManager().updateDevice(entity);
if (Context.getGeofenceManager() != null) {
Context.getGeofenceManager().refresh();
}
return Response.ok(entity).build();
}

Expand All @@ -80,7 +85,9 @@ public Response remove(@PathParam("id") long id) throws SQLException {
Context.getPermissionsManager().checkDevice(getUserId(), id);
Context.getDataManager().removeDevice(id);
Context.getPermissionsManager().refresh();
Context.getGeofenceManager().refresh();
if (Context.getGeofenceManager() != null) {
Context.getGeofenceManager().refresh();
}
return Response.noContent().build();
}

Expand Down
8 changes: 6 additions & 2 deletions src/org/traccar/api/resource/GroupPermissionResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ public Response add(GroupPermission entity) throws SQLException {
Context.getPermissionsManager().checkAdmin(getUserId());
Context.getDataManager().linkGroup(entity.getUserId(), entity.getGroupId());
Context.getPermissionsManager().refresh();
Context.getGeofenceManager().refresh();
if (Context.getGeofenceManager() != null) {
Context.getGeofenceManager().refresh();
}
return Response.ok(entity).build();
}

Expand All @@ -47,7 +49,9 @@ public Response remove(GroupPermission entity) throws SQLException {
Context.getPermissionsManager().checkAdmin(getUserId());
Context.getDataManager().unlinkGroup(entity.getUserId(), entity.getGroupId());
Context.getPermissionsManager().refresh();
Context.getGeofenceManager().refresh();
if (Context.getGeofenceManager() != null) {
Context.getGeofenceManager().refresh();
}
return Response.noContent().build();
}

Expand Down
11 changes: 9 additions & 2 deletions src/org/traccar/api/resource/GroupResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ public Response add(Group entity) throws SQLException {
Context.getDataManager().addGroup(entity);
Context.getDataManager().linkGroup(getUserId(), entity.getId());
Context.getPermissionsManager().refresh();
Context.getGeofenceManager().refresh();
if (Context.getGeofenceManager() != null) {
Context.getGeofenceManager().refresh();
}
return Response.ok(entity).build();
}

Expand All @@ -69,6 +71,9 @@ public Response update(@PathParam("id") long id, Group entity) throws SQLExcepti
Context.getPermissionsManager().checkReadonly(getUserId());
Context.getPermissionsManager().checkGroup(getUserId(), id);
Context.getDataManager().updateGroup(entity);
if (Context.getGeofenceManager() != null) {
Context.getGeofenceManager().refresh();
}
return Response.ok(entity).build();
}

Expand All @@ -79,7 +84,9 @@ public Response remove(@PathParam("id") long id) throws SQLException {
Context.getPermissionsManager().checkGroup(getUserId(), id);
Context.getDataManager().removeGroup(id);
Context.getPermissionsManager().refresh();
Context.getGeofenceManager().refresh();
if (Context.getGeofenceManager() != null) {
Context.getGeofenceManager().refresh();
}
return Response.noContent().build();
}

Expand Down
44 changes: 44 additions & 0 deletions src/org/traccar/api/resource/NotificationResource.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package org.traccar.api.resource;

import java.sql.SQLException;
import java.util.Collection;

import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

import org.traccar.Context;
import org.traccar.api.BaseResource;
import org.traccar.model.Notification;

@Path("users/notifications")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public class NotificationResource extends BaseResource {

@GET
public Collection<Notification> get(@QueryParam("all") boolean all,
@QueryParam("userId") long userId) throws SQLException {
if (all) {
return Context.getNotificationManager().getAllNotifications();
}
if (userId == 0) {
userId = getUserId();
}
Context.getPermissionsManager().checkUser(getUserId(), userId);
return Context.getNotificationManager().getUserNotifications(userId);
}

@POST
public Response update(Notification entity) throws SQLException {
Context.getPermissionsManager().checkReadonly(getUserId());
Context.getPermissionsManager().checkUser(getUserId(), entity.getUserId());
Context.getNotificationManager().updateNotification(entity);
return Response.ok(entity).build();
}
}
21 changes: 18 additions & 3 deletions src/org/traccar/api/resource/UserResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,12 @@ public Response add(User entity) throws SQLException {
}
Context.getDataManager().addUser(entity);
Context.getPermissionsManager().refresh();
Context.getGeofenceManager().refresh();
if (Context.getGeofenceManager() != null) {
Context.getGeofenceManager().refresh();
}
if (Context.getNotificationManager() != null) {
Context.getNotificationManager().refresh();
}
return Response.ok(entity).build();
}

Expand All @@ -66,7 +71,12 @@ public Response update(@PathParam("id") long id, User entity) throws SQLExceptio
}
Context.getDataManager().updateUser(entity);
Context.getPermissionsManager().refresh();
Context.getGeofenceManager().refresh();
if (Context.getGeofenceManager() != null) {
Context.getGeofenceManager().refresh();
}
if (Context.getNotificationManager() != null) {
Context.getNotificationManager().refresh();
}
return Response.ok(entity).build();
}

Expand All @@ -76,7 +86,12 @@ public Response remove(@PathParam("id") long id) throws SQLException {
Context.getPermissionsManager().checkUser(getUserId(), id);
Context.getDataManager().removeUser(id);
Context.getPermissionsManager().refresh();
Context.getGeofenceManager().refresh();
if (Context.getGeofenceManager() != null) {
Context.getGeofenceManager().refresh();
}
if (Context.getNotificationManager() != null) {
Context.getNotificationManager().refresh();
}
return Response.noContent().build();
}

Expand Down
Loading

0 comments on commit a25e7bd

Please sign in to comment.