aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/traccar/storage
diff options
context:
space:
mode:
authorAnton Tananaev <anton@traccar.org>2022-05-22 10:55:48 -0700
committerAnton Tananaev <anton@traccar.org>2022-05-22 10:55:48 -0700
commit9f8a78e5b7afddc6ccb0a54f4b3e59e1395de8eb (patch)
tree26356ca17e21d626843671aac23bf775c6451359 /src/main/java/org/traccar/storage
parentd9f51795058399e85ae83a8e308a0c2bc1d13e4b (diff)
parent9c9f5d66147cfa428ea18dd29103b9c82e529dca (diff)
downloadtrackermap-server-9f8a78e5b7afddc6ccb0a54f4b3e59e1395de8eb.tar.gz
trackermap-server-9f8a78e5b7afddc6ccb0a54f4b3e59e1395de8eb.tar.bz2
trackermap-server-9f8a78e5b7afddc6ccb0a54f4b3e59e1395de8eb.zip
Merge branch 'storage'
Diffstat (limited to 'src/main/java/org/traccar/storage')
-rw-r--r--src/main/java/org/traccar/storage/DatabaseStorage.java151
-rw-r--r--src/main/java/org/traccar/storage/MemoryStorage.java20
-rw-r--r--src/main/java/org/traccar/storage/QueryBuilder.java20
-rw-r--r--src/main/java/org/traccar/storage/Storage.java32
-rw-r--r--src/main/java/org/traccar/storage/StorageException.java15
-rw-r--r--src/main/java/org/traccar/storage/StorageName.java15
-rw-r--r--src/main/java/org/traccar/storage/query/Columns.java15
-rw-r--r--src/main/java/org/traccar/storage/query/Condition.java82
-rw-r--r--src/main/java/org/traccar/storage/query/Limit.java15
-rw-r--r--src/main/java/org/traccar/storage/query/Order.java15
-rw-r--r--src/main/java/org/traccar/storage/query/Request.java15
11 files changed, 370 insertions, 25 deletions
diff --git a/src/main/java/org/traccar/storage/DatabaseStorage.java b/src/main/java/org/traccar/storage/DatabaseStorage.java
index d73dc7b25..ff77ff8a8 100644
--- a/src/main/java/org/traccar/storage/DatabaseStorage.java
+++ b/src/main/java/org/traccar/storage/DatabaseStorage.java
@@ -1,5 +1,23 @@
+/*
+ * Copyright 2022 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.storage;
+import org.traccar.model.Device;
+import org.traccar.model.Group;
+import org.traccar.model.GroupedModel;
import org.traccar.model.Permission;
import org.traccar.storage.query.Columns;
import org.traccar.storage.query.Condition;
@@ -10,6 +28,7 @@ import org.traccar.storage.query.Request;
import javax.sql.DataSource;
import java.sql.SQLException;
import java.util.HashMap;
+import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
@@ -27,7 +46,7 @@ public class DatabaseStorage extends Storage {
public <T> List<T> getObjects(Class<T> clazz, Request request) throws StorageException {
StringBuilder query = new StringBuilder("SELECT ");
query.append(formatColumns(request.getColumns(), clazz, "get", c -> c));
- query.append(" FROM ").append(getTableName(clazz));
+ query.append(" FROM ").append(getStorageName(clazz));
query.append(formatCondition(request.getCondition()));
query.append(formatOrder(request.getOrder()));
query.append(formatLimit(request.getLimit()));
@@ -45,7 +64,7 @@ public class DatabaseStorage extends Storage {
@Override
public <T> long addObject(T entity, Request request) throws StorageException {
StringBuilder query = new StringBuilder("INSERT INTO ");
- query.append(getTableName(entity.getClass()));
+ query.append(getStorageName(entity.getClass()));
query.append("(");
query.append(formatColumns(request.getColumns(), entity.getClass(), "set", c -> c));
query.append(") VALUES (");
@@ -63,7 +82,7 @@ public class DatabaseStorage extends Storage {
@Override
public <T> void updateObject(T entity, Request request) throws StorageException {
StringBuilder query = new StringBuilder("UPDATE ");
- query.append(getTableName(entity.getClass()));
+ query.append(getStorageName(entity.getClass()));
query.append(" SET ");
query.append(formatColumns(request.getColumns(), entity.getClass(), "set", c -> c + " = :" + c));
query.append(formatCondition(request.getCondition()));
@@ -82,7 +101,7 @@ public class DatabaseStorage extends Storage {
@Override
public void removeObject(Class<?> clazz, Request request) throws StorageException {
StringBuilder query = new StringBuilder("DELETE FROM ");
- query.append(getTableName(clazz));
+ query.append(getStorageName(clazz));
query.append(formatCondition(request.getCondition()));
try {
QueryBuilder builder = QueryBuilder.create(dataSource, query.toString());
@@ -96,9 +115,20 @@ public class DatabaseStorage extends Storage {
}
@Override
- public List<Permission> getPermissions(Class<?> ownerClass, Class<?> propertyClass) throws StorageException {
+ public List<Permission> getPermissions(
+ Class<?> ownerClass, long ownerId, Class<?> propertyClass, long propertyId) throws StorageException {
StringBuilder query = new StringBuilder("SELECT * FROM ");
query.append(Permission.getStorageName(ownerClass, propertyClass));
+ var conditions = new LinkedList<Condition>();
+ if (ownerId > 0) {
+ conditions.add(new Condition.Equals(
+ Permission.getKey(ownerClass), Permission.getKey(ownerClass), ownerId));
+ }
+ if (propertyId > 0) {
+ conditions.add(new Condition.Equals(
+ Permission.getKey(propertyClass), Permission.getKey(propertyClass), propertyId));
+ }
+ query.append(formatCondition(Condition.merge(conditions)));
try {
QueryBuilder builder = QueryBuilder.create(dataSource, query.toString());
return builder.executePermissionsQuery();
@@ -143,7 +173,7 @@ public class DatabaseStorage extends Storage {
}
}
- private String getTableName(Class<?> clazz) throws StorageException {
+ private String getStorageName(Class<?> clazz) throws StorageException {
StorageName storageName = clazz.getAnnotation(StorageName.class);
if (storageName == null) {
throw new StorageException("StorageName annotation is missing");
@@ -154,18 +184,25 @@ public class DatabaseStorage extends Storage {
private Map<String, Object> getConditionVariables(Condition genericCondition) {
Map<String, Object> results = new HashMap<>();
if (genericCondition instanceof Condition.Compare) {
- Condition.Compare condition = (Condition.Compare) genericCondition;
+ var condition = (Condition.Compare) genericCondition;
if (condition.getValue() != null) {
results.put(condition.getVariable(), condition.getValue());
}
} else if (genericCondition instanceof Condition.Between) {
- Condition.Between condition = (Condition.Between) genericCondition;
+ var condition = (Condition.Between) genericCondition;
results.put(condition.getFromVariable(), condition.getFromValue());
results.put(condition.getToVariable(), condition.getToValue());
} else if (genericCondition instanceof Condition.Binary) {
- Condition.Binary condition = (Condition.Binary) genericCondition;
+ var condition = (Condition.Binary) genericCondition;
results.putAll(getConditionVariables(condition.getFirst()));
results.putAll(getConditionVariables(condition.getSecond()));
+ } else if (genericCondition instanceof Condition.Permission) {
+ var condition = (Condition.Permission) genericCondition;
+ if (condition.getOwnerId() > 0) {
+ results.put(Permission.getKey(condition.getOwnerClass()), condition.getOwnerId());
+ } else {
+ results.put(Permission.getKey(condition.getPropertyClass()), condition.getPropertyId());
+ }
}
return results;
}
@@ -175,11 +212,11 @@ public class DatabaseStorage extends Storage {
return columns.getColumns(clazz, type).stream().map(mapper).collect(Collectors.joining(", "));
}
- private String formatCondition(Condition genericCondition) {
+ private String formatCondition(Condition genericCondition) throws StorageException {
return formatCondition(genericCondition, true);
}
- private String formatCondition(Condition genericCondition, boolean appendWhere) {
+ private String formatCondition(Condition genericCondition, boolean appendWhere) throws StorageException {
StringBuilder result = new StringBuilder();
if (genericCondition != null) {
if (appendWhere) {
@@ -187,7 +224,7 @@ public class DatabaseStorage extends Storage {
}
if (genericCondition instanceof Condition.Compare) {
- Condition.Compare condition = (Condition.Compare) genericCondition;
+ var condition = (Condition.Compare) genericCondition;
result.append(condition.getColumn());
result.append(" ");
result.append(condition.getOperator());
@@ -196,7 +233,7 @@ public class DatabaseStorage extends Storage {
} else if (genericCondition instanceof Condition.Between) {
- Condition.Between condition = (Condition.Between) genericCondition;
+ var condition = (Condition.Between) genericCondition;
result.append(condition.getColumn());
result.append(" BETWEEN :");
result.append(condition.getFromVariable());
@@ -205,13 +242,20 @@ public class DatabaseStorage extends Storage {
} else if (genericCondition instanceof Condition.Binary) {
- Condition.Binary condition = (Condition.Binary) genericCondition;
+ var condition = (Condition.Binary) genericCondition;
result.append(formatCondition(condition.getFirst(), false));
result.append(" ");
result.append(condition.getOperator());
result.append(" ");
result.append(formatCondition(condition.getSecond(), false));
+ } else if (genericCondition instanceof Condition.Permission) {
+
+ var condition = (Condition.Permission) genericCondition;
+ result.append("id IN (");
+ result.append(formatPermissionQuery(condition));
+ result.append(")");
+
}
}
return result.toString();
@@ -238,4 +282,83 @@ public class DatabaseStorage extends Storage {
return result.toString();
}
+ private String formatPermissionQuery(Condition.Permission condition) throws StorageException {
+ StringBuilder result = new StringBuilder();
+
+ String outputKey;
+ String conditionKey;
+ if (condition.getOwnerId() > 0) {
+ outputKey = Permission.getKey(condition.getPropertyClass());
+ conditionKey = Permission.getKey(condition.getOwnerClass());
+ } else {
+ outputKey = Permission.getKey(condition.getOwnerClass());
+ conditionKey = Permission.getKey(condition.getPropertyClass());
+ }
+
+ result.append("SELECT ");
+ result.append(outputKey);
+ result.append(" FROM ");
+ result.append(Permission.getStorageName(condition.getOwnerClass(), condition.getPropertyClass()));
+ result.append(" WHERE ");
+ result.append(conditionKey);
+ result.append(" = :");
+ result.append(conditionKey);
+
+ if (condition.getIncludeGroups()) {
+
+ boolean expandDevices;
+ String groupStorageName;
+ if (GroupedModel.class.isAssignableFrom(condition.getOwnerClass())) {
+ expandDevices = Device.class.isAssignableFrom(condition.getOwnerClass());
+ groupStorageName = Permission.getStorageName(Group.class, condition.getPropertyClass());
+ } else {
+ expandDevices = Device.class.isAssignableFrom(condition.getPropertyClass());
+ groupStorageName = Permission.getStorageName(condition.getOwnerClass(), Group.class);
+ }
+
+ result.append(" UNION ");
+
+ result.append("SELECT DISTINCT ");
+ result.append(expandDevices? "devices." : "groups."); // TODO handle reverse search (e.g. users by device)
+ result.append(outputKey);
+ result.append(" FROM ");
+ result.append(groupStorageName);
+
+ result.append(" INNER JOIN (");
+ result.append("SELECT id as parentid, id as groupid FROM ");
+ result.append(getStorageName(Group.class));
+ result.append(" UNION ");
+ result.append("SELECT groupid as parentid, id as groupid FROM ");
+ result.append(getStorageName(Group.class));
+ result.append(" WHERE groupid IS NOT NULL");
+ result.append(" UNION ");
+ result.append("SELECT g2.groupid as parentid, g1.id as groupid FROM ");
+ result.append(getStorageName(Group.class));
+ result.append(" AS g2");
+ result.append(" INNER JOIN ");
+ result.append(getStorageName(Group.class));
+ result.append(" AS g1 ON g2.id = g1.groupid");
+ result.append(" WHERE g2.groupid IS NOT NULL");
+ result.append(") AS groups ON ");
+ result.append(groupStorageName);
+ result.append(".groupid = groups.parentid");
+
+ if (expandDevices) {
+ result.append(" INNER JOIN (");
+ result.append("SELECT groupid as parentid, id as deviceid FROM ");
+ result.append(getStorageName(Device.class));
+ result.append(" WHERE groupid IS NOT NULL");
+ result.append(") AS devices ON groups.groupid = devices.parentid");
+ }
+
+ result.append(" WHERE ");
+ result.append(conditionKey); // TODO handle search for device / group
+ result.append(" = :");
+ result.append(conditionKey);
+
+ }
+
+ return result.toString();
+ }
+
}
diff --git a/src/main/java/org/traccar/storage/MemoryStorage.java b/src/main/java/org/traccar/storage/MemoryStorage.java
index 9cfe30a2b..71e895428 100644
--- a/src/main/java/org/traccar/storage/MemoryStorage.java
+++ b/src/main/java/org/traccar/storage/MemoryStorage.java
@@ -1,3 +1,18 @@
+/*
+ * Copyright 2022 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.storage;
import org.traccar.model.Pair;
@@ -38,8 +53,11 @@ public class MemoryStorage extends Storage {
}
@Override
- public List<Permission> getPermissions(Class<?> ownerClass, Class<?> propertyClass) {
+ public List<Permission> getPermissions(
+ Class<?> ownerClass, long ownerId, Class<?> propertyClass, long propertyId) {
return getPermissionsSet(ownerClass, propertyClass).stream()
+ .filter(pair -> ownerId == 0 || pair.getFirst().equals(ownerId))
+ .filter(pair -> propertyId == 0 || pair.getSecond().equals(propertyId))
.map(pair -> new Permission(ownerClass, pair.getFirst(), propertyClass, pair.getSecond()))
.collect(Collectors.toList());
}
diff --git a/src/main/java/org/traccar/storage/QueryBuilder.java b/src/main/java/org/traccar/storage/QueryBuilder.java
index da8002f0b..874a046b4 100644
--- a/src/main/java/org/traccar/storage/QueryBuilder.java
+++ b/src/main/java/org/traccar/storage/QueryBuilder.java
@@ -19,6 +19,7 @@ import com.fasterxml.jackson.core.JsonProcessingException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.traccar.Context;
+import org.traccar.config.Keys;
import org.traccar.model.Permission;
import javax.sql.DataSource;
@@ -309,15 +310,6 @@ public final class QueryBuilder {
void process(T object, ResultSet resultSet) throws SQLException;
}
- public <T> T executeQuerySingle(Class<T> clazz) throws SQLException {
- List<T> result = executeQuery(clazz);
- if (!result.isEmpty()) {
- return result.iterator().next();
- } else {
- return null;
- }
- }
-
private <T> void addProcessors(
List<ResultSetProcessor<T>> processors,
final Class<?> parameterType, final Method method, final String name) {
@@ -395,6 +387,12 @@ public final class QueryBuilder {
}
}
+ private void logQuery() {
+ if (Context.getConfig().getBoolean(Keys.LOGGER_QUERIES)) {
+ LOGGER.info(query);
+ }
+ }
+
public <T> List<T> executeQuery(Class<T> clazz) throws SQLException {
List<T> result = new LinkedList<>();
@@ -402,6 +400,8 @@ public final class QueryBuilder {
try {
+ logQuery();
+
try (ResultSet resultSet = statement.executeQuery()) {
ResultSetMetaData resultMetaData = resultSet.getMetaData();
@@ -457,6 +457,7 @@ public final class QueryBuilder {
if (query != null) {
try {
+ logQuery();
statement.execute();
if (returnGeneratedKeys) {
ResultSet resultSet = statement.getGeneratedKeys();
@@ -476,6 +477,7 @@ public final class QueryBuilder {
List<Permission> result = new LinkedList<>();
if (query != null) {
try {
+ logQuery();
try (ResultSet resultSet = statement.executeQuery()) {
ResultSetMetaData resultMetaData = resultSet.getMetaData();
while (resultSet.next()) {
diff --git a/src/main/java/org/traccar/storage/Storage.java b/src/main/java/org/traccar/storage/Storage.java
index 22c48cae0..22b5aaedc 100644
--- a/src/main/java/org/traccar/storage/Storage.java
+++ b/src/main/java/org/traccar/storage/Storage.java
@@ -1,3 +1,18 @@
+/*
+ * Copyright 2022 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.storage;
import org.traccar.model.Permission;
@@ -16,12 +31,27 @@ public abstract class Storage {
public abstract void removeObject(Class<?> clazz, Request request) throws StorageException;
public abstract List<Permission> getPermissions(
- Class<?> ownerClass, Class<?> propertyClass) throws StorageException;
+ Class<?> ownerClass, long ownerId, Class<?> propertyClass, long propertyId) throws StorageException;
public abstract void addPermission(Permission permission) throws StorageException;
public abstract void removePermission(Permission permission) throws StorageException;
+ public List<Permission> getPermissions(
+ Class<?> ownerClass, Class<?> propertyClass) throws StorageException {
+ return getPermissions(ownerClass, 0, propertyClass, 0);
+ }
+
+ public List<Permission> getPermissions(
+ Class<?> ownerClass, long ownerId, Class<?> propertyClass) throws StorageException {
+ return getPermissions(ownerClass, ownerId, propertyClass, 0);
+ }
+
+ public List<Permission> getPermissions(
+ Class<?> ownerClass, Class<?> propertyClass, long propertyId) throws StorageException {
+ return getPermissions(ownerClass, 0, propertyClass, propertyId);
+ }
+
public <T> T getObject(Class<T> clazz, Request request) throws StorageException {
var objects = getObjects(clazz, request);
return objects.isEmpty() ? null : objects.get(0);
diff --git a/src/main/java/org/traccar/storage/StorageException.java b/src/main/java/org/traccar/storage/StorageException.java
index 6c1e9c2ff..3f066cae6 100644
--- a/src/main/java/org/traccar/storage/StorageException.java
+++ b/src/main/java/org/traccar/storage/StorageException.java
@@ -1,3 +1,18 @@
+/*
+ * Copyright 2022 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.storage;
public class StorageException extends Exception {
diff --git a/src/main/java/org/traccar/storage/StorageName.java b/src/main/java/org/traccar/storage/StorageName.java
index b6fa55e02..bf824c333 100644
--- a/src/main/java/org/traccar/storage/StorageName.java
+++ b/src/main/java/org/traccar/storage/StorageName.java
@@ -1,3 +1,18 @@
+/*
+ * Copyright 2022 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.storage;
import java.lang.annotation.ElementType;
diff --git a/src/main/java/org/traccar/storage/query/Columns.java b/src/main/java/org/traccar/storage/query/Columns.java
index 196d2281c..97ca13be9 100644
--- a/src/main/java/org/traccar/storage/query/Columns.java
+++ b/src/main/java/org/traccar/storage/query/Columns.java
@@ -1,3 +1,18 @@
+/*
+ * Copyright 2022 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.storage.query;
import org.traccar.storage.QueryExtended;
diff --git a/src/main/java/org/traccar/storage/query/Condition.java b/src/main/java/org/traccar/storage/query/Condition.java
index 82c8e8479..91ede236c 100644
--- a/src/main/java/org/traccar/storage/query/Condition.java
+++ b/src/main/java/org/traccar/storage/query/Condition.java
@@ -1,7 +1,38 @@
+/*
+ * Copyright 2022 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.storage.query;
+import org.traccar.model.GroupedModel;
+
+import java.util.List;
+
public interface Condition {
+ static Condition merge(List<Condition> conditions) {
+ Condition result = null;
+ var iterator = conditions.iterator();
+ if (iterator.hasNext()) {
+ result = iterator.next();
+ while (iterator.hasNext()) {
+ result = new Condition.And(result, iterator.next());
+ }
+ }
+ return result;
+ }
+
class Equals extends Compare {
public Equals(String column, String variable) {
this(column, variable, null);
@@ -114,4 +145,55 @@ public interface Condition {
}
}
+ class Permission implements Condition {
+ private final Class<?> ownerClass;
+ private final long ownerId;
+ private final Class<?> propertyClass;
+ private final long propertyId;
+ private final boolean excludeGroups;
+
+ private Permission(
+ Class<?> ownerClass, long ownerId, Class<?> propertyClass, long propertyId, boolean excludeGroups) {
+ this.ownerClass = ownerClass;
+ this.ownerId = ownerId;
+ this.propertyClass = propertyClass;
+ this.propertyId = propertyId;
+ this.excludeGroups = excludeGroups;
+ }
+
+ public Permission(Class<?> ownerClass, long ownerId, Class<?> propertyClass) {
+ this(ownerClass, ownerId, propertyClass, 0, false);
+ }
+
+ public Permission(Class<?> ownerClass, Class<?> propertyClass, long propertyId) {
+ this(ownerClass, 0, propertyClass, propertyId, false);
+ }
+
+ public Permission excludeGroups() {
+ return new Permission(this.ownerClass, this.ownerId, this.propertyClass, this.propertyId, true);
+ }
+
+ public Class<?> getOwnerClass() {
+ return ownerClass;
+ }
+
+ public long getOwnerId() {
+ return ownerId;
+ }
+
+ public Class<?> getPropertyClass() {
+ return propertyClass;
+ }
+
+ public long getPropertyId() {
+ return propertyId;
+ }
+
+ public boolean getIncludeGroups() {
+ boolean ownerGroupModel = GroupedModel.class.isAssignableFrom(ownerClass);
+ boolean propertyGroupModel = GroupedModel.class.isAssignableFrom(propertyClass);
+ return (ownerGroupModel || propertyGroupModel) && !excludeGroups;
+ }
+ }
+
}
diff --git a/src/main/java/org/traccar/storage/query/Limit.java b/src/main/java/org/traccar/storage/query/Limit.java
index 4a20f0ce2..9673e5426 100644
--- a/src/main/java/org/traccar/storage/query/Limit.java
+++ b/src/main/java/org/traccar/storage/query/Limit.java
@@ -1,3 +1,18 @@
+/*
+ * Copyright 2022 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.storage.query;
public class Limit {
diff --git a/src/main/java/org/traccar/storage/query/Order.java b/src/main/java/org/traccar/storage/query/Order.java
index 6852c5ba8..d12acc83b 100644
--- a/src/main/java/org/traccar/storage/query/Order.java
+++ b/src/main/java/org/traccar/storage/query/Order.java
@@ -1,3 +1,18 @@
+/*
+ * Copyright 2022 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.storage.query;
public class Order {
diff --git a/src/main/java/org/traccar/storage/query/Request.java b/src/main/java/org/traccar/storage/query/Request.java
index a98dd48f7..41aa37bf1 100644
--- a/src/main/java/org/traccar/storage/query/Request.java
+++ b/src/main/java/org/traccar/storage/query/Request.java
@@ -1,3 +1,18 @@
+/*
+ * Copyright 2022 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.storage.query;
public class Request {