aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2021-08-24 23:14:30 -0700
committerAnton Tananaev <anton.tananaev@gmail.com>2021-08-24 23:14:30 -0700
commit297e330ead69b92a4723369098e7c4dbf7aa5694 (patch)
tree9643153ca03841a76e76789750e2d6769b673225
parent0a98b2b5471526d9d166c4b81f1500fd1edb60df (diff)
downloadtrackermap-server-297e330ead69b92a4723369098e7c4dbf7aa5694.tar.gz
trackermap-server-297e330ead69b92a4723369098e7c4dbf7aa5694.tar.bz2
trackermap-server-297e330ead69b92a4723369098e7c4dbf7aa5694.zip
Implement orders functionality
-rw-r--r--schema/changelog-4.15.xml66
-rw-r--r--schema/changelog-master.xml1
-rw-r--r--src/main/java/org/traccar/Context.java14
-rw-r--r--src/main/java/org/traccar/api/resource/OrderResource.java35
-rw-r--r--src/main/java/org/traccar/database/DataManager.java3
-rw-r--r--src/main/java/org/traccar/database/OrderManager.java26
-rw-r--r--src/main/java/org/traccar/database/PermissionsManager.java9
-rw-r--r--src/main/java/org/traccar/model/Order.java60
8 files changed, 212 insertions, 2 deletions
diff --git a/schema/changelog-4.15.xml b/schema/changelog-4.15.xml
new file mode 100644
index 000000000..e8dd15bb5
--- /dev/null
+++ b/schema/changelog-4.15.xml
@@ -0,0 +1,66 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<databaseChangeLog
+ xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
+ http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.4.xsd"
+ logicalFilePath="changelog-4.15">
+
+ <changeSet author="author" id="changelog-4.15">
+
+ <createTable tableName="tc_orders">
+ <column name="id" type="INT" autoIncrement="true">
+ <constraints primaryKey="true" />
+ </column>
+ <column name="uniqueid" type="VARCHAR(128)">
+ <constraints nullable="false" />
+ </column>
+ <column name="description" type="VARCHAR(512)" />
+ <column name="fromAddress" type="VARCHAR(512)" />
+ <column name="toAddress" type="VARCHAR(512)" />
+ <column name="attributes" type="VARCHAR(4000)">
+ <constraints nullable="false" />
+ </column>
+ </createTable>
+
+ <addUniqueConstraint tableName="tc_orders" columnNames="uniqueid" constraintName="uk_orders_uniqueid" />
+
+ <createTable tableName="tc_user_order">
+ <column name="userid" type="INT">
+ <constraints nullable="false" />
+ </column>
+ <column name="orderid" type="INT">
+ <constraints nullable="false" />
+ </column>
+ </createTable>
+
+ <addForeignKeyConstraint baseTableName="tc_user_order" baseColumnNames="userid" constraintName="fk_user_order_userid" referencedTableName="tc_users" referencedColumnNames="id" onDelete="CASCADE" />
+ <addForeignKeyConstraint baseTableName="tc_user_order" baseColumnNames="orderid" constraintName="fk_user_order_orderid" referencedTableName="tc_orders" referencedColumnNames="id" onDelete="CASCADE" />
+
+ <createTable tableName="tc_group_order">
+ <column name="groupid" type="INT">
+ <constraints nullable="false" />
+ </column>
+ <column name="orderid" type="INT">
+ <constraints nullable="false" />
+ </column>
+ </createTable>
+
+ <addForeignKeyConstraint baseTableName="tc_group_order" baseColumnNames="groupid" constraintName="fk_group_order_groupid" referencedTableName="tc_groups" referencedColumnNames="id" onDelete="CASCADE" />
+ <addForeignKeyConstraint baseTableName="tc_group_order" baseColumnNames="orderid" constraintName="fk_group_order_orderid" referencedTableName="tc_orders" referencedColumnNames="id" onDelete="CASCADE" />
+
+ <createTable tableName="tc_device_order">
+ <column name="deviceid" type="INT">
+ <constraints nullable="false" />
+ </column>
+ <column name="orderid" type="INT">
+ <constraints nullable="false" />
+ </column>
+ </createTable>
+
+ <addForeignKeyConstraint baseTableName="tc_device_order" baseColumnNames="deviceid" constraintName="fk_device_order_deviceid" referencedTableName="tc_devices" referencedColumnNames="id" onDelete="CASCADE" />
+ <addForeignKeyConstraint baseTableName="tc_device_order" baseColumnNames="orderid" constraintName="fk_device_order_orderid" referencedTableName="tc_orders" referencedColumnNames="id" onDelete="CASCADE" />
+
+ </changeSet>
+
+</databaseChangeLog>
diff --git a/schema/changelog-master.xml b/schema/changelog-master.xml
index df54737a2..245367de3 100644
--- a/schema/changelog-master.xml
+++ b/schema/changelog-master.xml
@@ -28,5 +28,6 @@
<include file="changelog-4.10.xml" relativeToChangelogFile="true" />
<include file="changelog-4.11.xml" relativeToChangelogFile="true" />
<include file="changelog-4.13.xml" relativeToChangelogFile="true" />
+ <include file="changelog-4.15.xml" relativeToChangelogFile="true" />
</databaseChangeLog>
diff --git a/src/main/java/org/traccar/Context.java b/src/main/java/org/traccar/Context.java
index fe494dabf..aeba9c4c9 100644
--- a/src/main/java/org/traccar/Context.java
+++ b/src/main/java/org/traccar/Context.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 - 2020 Anton Tananaev (anton@traccar.org)
+ * Copyright 2015 - 2021 Anton Tananaev (anton@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -38,6 +38,7 @@ import org.traccar.database.MailManager;
import org.traccar.database.MaintenancesManager;
import org.traccar.database.MediaManager;
import org.traccar.database.NotificationManager;
+import org.traccar.database.OrderManager;
import org.traccar.database.PermissionsManager;
import org.traccar.database.UsersManager;
import org.traccar.geocoder.Geocoder;
@@ -53,6 +54,7 @@ import org.traccar.model.Geofence;
import org.traccar.model.Group;
import org.traccar.model.Maintenance;
import org.traccar.model.Notification;
+import org.traccar.model.Order;
import org.traccar.model.User;
import org.traccar.notification.EventForwarder;
import org.traccar.notification.NotificatorManager;
@@ -235,6 +237,12 @@ public final class Context {
return maintenancesManager;
}
+ private static OrderManager orderManager;
+
+ public static OrderManager getOrderManager() {
+ return orderManager;
+ }
+
private static SmsManager smsManager;
public static SmsManager getSmsManager() {
@@ -337,6 +345,8 @@ public final class Context {
commandsManager = new CommandsManager(dataManager, config.getBoolean(Keys.COMMANDS_QUEUEING));
+ orderManager = new OrderManager(dataManager);
+
}
private static void initEventsModule() {
@@ -397,6 +407,8 @@ public final class Context {
return (BaseObjectManager<T>) maintenancesManager;
} else if (clazz.equals(Notification.class)) {
return (BaseObjectManager<T>) notificationManager;
+ } else if (clazz.equals(Order.class)) {
+ return (BaseObjectManager<T>) orderManager;
}
return null;
}
diff --git a/src/main/java/org/traccar/api/resource/OrderResource.java b/src/main/java/org/traccar/api/resource/OrderResource.java
new file mode 100644
index 000000000..77608a508
--- /dev/null
+++ b/src/main/java/org/traccar/api/resource/OrderResource.java
@@ -0,0 +1,35 @@
+/*
+ * Copyright 2021 Anton Tananaev (anton@traccar.org)
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.traccar.api.resource;
+
+import org.traccar.api.SimpleObjectResource;
+import org.traccar.model.Order;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+
+@Path("orders")
+@Produces(MediaType.APPLICATION_JSON)
+@Consumes(MediaType.APPLICATION_JSON)
+public class OrderResource extends SimpleObjectResource<Order> {
+
+ public OrderResource() {
+ super(Order.class);
+ }
+
+}
diff --git a/src/main/java/org/traccar/database/DataManager.java b/src/main/java/org/traccar/database/DataManager.java
index de6da8f23..00c802fde 100644
--- a/src/main/java/org/traccar/database/DataManager.java
+++ b/src/main/java/org/traccar/database/DataManager.java
@@ -41,6 +41,7 @@ import org.traccar.model.Group;
import org.traccar.model.Maintenance;
import org.traccar.model.ManagedUser;
import org.traccar.model.Notification;
+import org.traccar.model.Order;
import org.traccar.model.Permission;
import org.traccar.model.Position;
import org.traccar.model.Server;
@@ -388,6 +389,8 @@ public class DataManager {
return Maintenance.class;
case "notification":
return Notification.class;
+ case "order":
+ return Order.class;
default:
throw new ClassNotFoundException();
}
diff --git a/src/main/java/org/traccar/database/OrderManager.java b/src/main/java/org/traccar/database/OrderManager.java
new file mode 100644
index 000000000..c3253e52f
--- /dev/null
+++ b/src/main/java/org/traccar/database/OrderManager.java
@@ -0,0 +1,26 @@
+/*
+ * Copyright 2021 Anton Tananaev (anton@traccar.org)
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.traccar.database;
+
+import org.traccar.model.Order;
+
+public class OrderManager extends ExtendedObjectManager<Order> {
+
+ public OrderManager(DataManager dataManager) {
+ super(dataManager, Order.class);
+ }
+
+}
diff --git a/src/main/java/org/traccar/database/PermissionsManager.java b/src/main/java/org/traccar/database/PermissionsManager.java
index a27eac069..32464cf90 100644
--- a/src/main/java/org/traccar/database/PermissionsManager.java
+++ b/src/main/java/org/traccar/database/PermissionsManager.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 - 2018 Anton Tananaev (anton@traccar.org)
+ * Copyright 2015 - 2021 Anton Tananaev (anton@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -29,6 +29,7 @@ import org.traccar.model.Group;
import org.traccar.model.Maintenance;
import org.traccar.model.ManagedUser;
import org.traccar.model.Notification;
+import org.traccar.model.Order;
import org.traccar.model.Permission;
import org.traccar.model.Server;
import org.traccar.model.User;
@@ -395,6 +396,8 @@ public class PermissionsManager {
manager = Context.getMaintenancesManager();
} else if (object.equals(Notification.class)) {
manager = Context.getNotificationManager();
+ } else if (object.equals(Order.class)) {
+ manager = Context.getOrderManager();
} else {
throw new IllegalArgumentException("Unknown object type");
}
@@ -454,6 +457,8 @@ public class PermissionsManager {
Context.getCommandsManager().refreshUserItems();
} else if (permission.getPropertyClass().equals(Maintenance.class)) {
Context.getMaintenancesManager().refreshUserItems();
+ } else if (permission.getPropertyClass().equals(Order.class)) {
+ Context.getOrderManager().refreshUserItems();
} else if (permission.getPropertyClass().equals(Notification.class)
&& Context.getNotificationManager() != null) {
Context.getNotificationManager().refreshUserItems();
@@ -469,6 +474,8 @@ public class PermissionsManager {
Context.getCommandsManager().refreshExtendedPermissions();
} else if (permission.getPropertyClass().equals(Maintenance.class)) {
Context.getMaintenancesManager().refreshExtendedPermissions();
+ } else if (permission.getPropertyClass().equals(Order.class)) {
+ Context.getOrderManager().refreshExtendedPermissions();
} else if (permission.getPropertyClass().equals(Notification.class)
&& Context.getNotificationManager() != null) {
Context.getNotificationManager().refreshExtendedPermissions();
diff --git a/src/main/java/org/traccar/model/Order.java b/src/main/java/org/traccar/model/Order.java
new file mode 100644
index 000000000..fe6d926b8
--- /dev/null
+++ b/src/main/java/org/traccar/model/Order.java
@@ -0,0 +1,60 @@
+/*
+ * Copyright 2021 Anton Tananaev (anton@traccar.org)
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.traccar.model;
+
+public class Order extends ExtendedModel {
+
+ private String uniqueId;
+
+ public String getUniqueId() {
+ return uniqueId;
+ }
+
+ public void setUniqueId(String uniqueId) {
+ this.uniqueId = uniqueId;
+ }
+
+ private String description;
+
+ public String getDescription() {
+ return description;
+ }
+
+ public void setDescription(String description) {
+ this.description = description;
+ }
+
+ private String fromAddress;
+
+ public String getFromAddress() {
+ return fromAddress;
+ }
+
+ public void setFromAddress(String fromAddress) {
+ this.fromAddress = fromAddress;
+ }
+
+ private String toAddress;
+
+ public String getToAddress() {
+ return toAddress;
+ }
+
+ public void setToAddress(String toAddress) {
+ this.toAddress = toAddress;
+ }
+
+}