aboutsummaryrefslogtreecommitdiff
path: root/src/org
diff options
context:
space:
mode:
authorAbyss777 <abyss@fox5.ru>2017-07-24 17:02:39 +0500
committerAbyss777 <abyss@fox5.ru>2017-07-24 17:02:39 +0500
commitaf00329fd0addf84071927dbc18cb0b4e5345f2b (patch)
tree8a8def831332ed70e63544b54c70bcf82e777fbb /src/org
parentd6c7cdf1e103c977ed94b737dc838d7ac22b9fa7 (diff)
downloadtraccar-server-af00329fd0addf84071927dbc18cb0b4e5345f2b.tar.gz
traccar-server-af00329fd0addf84071927dbc18cb0b4e5345f2b.tar.bz2
traccar-server-af00329fd0addf84071927dbc18cb0b4e5345f2b.zip
Use Permission instead of Map
Diffstat (limited to 'src/org')
-rw-r--r--src/org/traccar/database/DataManager.java8
-rw-r--r--src/org/traccar/database/ExtendedObjectManager.java20
-rw-r--r--src/org/traccar/database/PermissionsManager.java28
-rw-r--r--src/org/traccar/database/QueryBuilder.java11
-rw-r--r--src/org/traccar/database/SimpleObjectManager.java8
5 files changed, 35 insertions, 40 deletions
diff --git a/src/org/traccar/database/DataManager.java b/src/org/traccar/database/DataManager.java
index 80b9f98e9..862efbc91 100644
--- a/src/org/traccar/database/DataManager.java
+++ b/src/org/traccar/database/DataManager.java
@@ -23,7 +23,6 @@ import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.Collection;
import java.util.Date;
-import java.util.Map;
import javax.naming.InitialContext;
import javax.sql.DataSource;
@@ -41,6 +40,7 @@ import org.traccar.helper.Log;
import org.traccar.model.AttributeAlias;
import org.traccar.model.Device;
import org.traccar.model.Event;
+import org.traccar.model.Permission;
import org.traccar.model.BaseModel;
import org.traccar.model.Position;
import org.traccar.model.Server;
@@ -293,10 +293,10 @@ public class DataManager {
return QueryBuilder.create(dataSource, getQuery(query)).executeQuery(clazz);
}
- public Collection<Map<String, Long>> getPermissions(Class<? extends BaseModel> owner,
- Class<? extends BaseModel> property) throws SQLException {
+ public Collection<Permission> getPermissions(Class<? extends BaseModel> owner,
+ Class<? extends BaseModel> property) throws SQLException, ClassNotFoundException {
String query = "database.select" + owner.getSimpleName() + property.getSimpleName() + "s";
- return QueryBuilder.create(dataSource, getQuery(query)).executeMapQuery(Long.class);
+ return QueryBuilder.create(dataSource, getQuery(query)).executePermissionsQuery();
}
public void addObject(BaseModel entity) throws SQLException {
diff --git a/src/org/traccar/database/ExtendedObjectManager.java b/src/org/traccar/database/ExtendedObjectManager.java
index a9dc7d28a..2833b3bae 100644
--- a/src/org/traccar/database/ExtendedObjectManager.java
+++ b/src/org/traccar/database/ExtendedObjectManager.java
@@ -27,6 +27,7 @@ import org.traccar.Context;
import org.traccar.helper.Log;
import org.traccar.model.Device;
import org.traccar.model.Group;
+import org.traccar.model.Permission;
import org.traccar.model.BaseModel;
public abstract class ExtendedObjectManager extends SimpleObjectManager {
@@ -79,27 +80,24 @@ public abstract class ExtendedObjectManager extends SimpleObjectManager {
if (getDataManager() != null) {
try {
- Collection<Map<String, Long>> databaseGroupPermissions =
+ Collection<Permission> databaseGroupPermissions =
getDataManager().getPermissions(Group.class, getBaseClass());
clearGroupItems();
- for (Map<String, Long> groupPermission : databaseGroupPermissions) {
- getGroupItems(groupPermission.get(DataManager.makeNameId(Group.class)))
- .add(groupPermission.get(getBaseClassIdName()));
+ for (Permission groupPermission : databaseGroupPermissions) {
+ getGroupItems(groupPermission.getOwnerId()).add(groupPermission.getPropertyId());
}
- Collection<Map<String, Long>> databaseDevicePermissions =
+ Collection<Permission> databaseDevicePermissions =
getDataManager().getPermissions(Device.class, getBaseClass());
Collection<Device> allDevices = Context.getDeviceManager().getAllDevices();
clearDeviceItems();
deviceItemsWithGroups.clear();
- for (Map<String, Long> devicePermission : databaseDevicePermissions) {
- getDeviceItems(devicePermission.get(DataManager.makeNameId(Device.class)))
- .add(devicePermission.get(getBaseClassIdName()));
- getAllDeviceItems(devicePermission.get(DataManager.makeNameId(Device.class)))
- .add(devicePermission.get(getBaseClassIdName()));
+ for (Permission devicePermission : databaseDevicePermissions) {
+ getDeviceItems(devicePermission.getOwnerId()).add(devicePermission.getPropertyId());
+ getAllDeviceItems(devicePermission.getOwnerId()).add(devicePermission.getPropertyId());
}
for (Device device : allDevices) {
@@ -114,7 +112,7 @@ public abstract class ExtendedObjectManager extends SimpleObjectManager {
}
}
- } catch (SQLException error) {
+ } catch (SQLException | ClassNotFoundException error) {
Log.warning(error);
}
}
diff --git a/src/org/traccar/database/PermissionsManager.java b/src/org/traccar/database/PermissionsManager.java
index b9cdfc36b..70969d749 100644
--- a/src/org/traccar/database/PermissionsManager.java
+++ b/src/org/traccar/database/PermissionsManager.java
@@ -115,11 +115,10 @@ public class PermissionsManager {
public final void refreshUserPermissions() {
userPermissions.clear();
try {
- for (Map<String, Long> permission : dataManager.getPermissions(User.class, User.class)) {
- getUserPermissions(permission.get(DataManager.makeNameId(User.class)))
- .add(permission.get(DataManager.makeNameId(ManagedUser.class)));
+ for (Permission permission : dataManager.getPermissions(User.class, User.class)) {
+ getUserPermissions(permission.getOwnerId()).add(permission.getPropertyId());
}
- } catch (SQLException error) {
+ } catch (SQLException | ClassNotFoundException error) {
Log.warning(error);
}
}
@@ -130,23 +129,20 @@ public class PermissionsManager {
try {
GroupTree groupTree = new GroupTree(Context.getDeviceManager().getAllGroups(),
Context.getDeviceManager().getAllDevices());
- for (Map<String, Long> groupPermission : dataManager.getPermissions(User.class, Group.class)) {
- Set<Long> userGroupPermissions = getGroupPermissions(groupPermission
- .get(DataManager.makeNameId(User.class)));
- Set<Long> userDevicePermissions = getDevicePermissions(groupPermission
- .get(DataManager.makeNameId(User.class)));
- userGroupPermissions.add(groupPermission.get(DataManager.makeNameId(Group.class)));
- for (Group group : groupTree.getGroups(groupPermission.get(DataManager.makeNameId(Group.class)))) {
+ for (Permission groupPermission : dataManager.getPermissions(User.class, Group.class)) {
+ Set<Long> userGroupPermissions = getGroupPermissions(groupPermission.getOwnerId());
+ Set<Long> userDevicePermissions = getDevicePermissions(groupPermission.getOwnerId());
+ userGroupPermissions.add(groupPermission.getPropertyId());
+ for (Group group : groupTree.getGroups(groupPermission.getPropertyId())) {
userGroupPermissions.add(group.getId());
}
- for (Device device : groupTree.getDevices(groupPermission.get(DataManager.makeNameId(Group.class)))) {
+ for (Device device : groupTree.getDevices(groupPermission.getPropertyId())) {
userDevicePermissions.add(device.getId());
}
}
- for (Map<String, Long> devicePermission : dataManager.getPermissions(User.class, Device.class)) {
- getDevicePermissions(devicePermission.get(DataManager.makeNameId(User.class)))
- .add(devicePermission.get(DataManager.makeNameId(Device.class)));
+ for (Permission devicePermission : dataManager.getPermissions(User.class, Device.class)) {
+ getDevicePermissions(devicePermission.getOwnerId()).add(devicePermission.getPropertyId());
}
groupDevices.clear();
@@ -156,7 +152,7 @@ public class PermissionsManager {
}
}
- } catch (SQLException error) {
+ } catch (SQLException | ClassNotFoundException error) {
Log.warning(error);
}
diff --git a/src/org/traccar/database/QueryBuilder.java b/src/org/traccar/database/QueryBuilder.java
index 440690a76..af33458a8 100644
--- a/src/org/traccar/database/QueryBuilder.java
+++ b/src/org/traccar/database/QueryBuilder.java
@@ -19,6 +19,7 @@ import com.fasterxml.jackson.core.JsonProcessingException;
import org.traccar.Context;
import org.traccar.helper.Log;
import org.traccar.model.MiscFormatter;
+import org.traccar.model.Permission;
import javax.sql.DataSource;
import java.io.IOException;
@@ -488,19 +489,19 @@ public final class QueryBuilder {
return 0;
}
- public <T> Collection<Map<String, T>> executeMapQuery(Class<T> clazz) throws SQLException {
- List<Map<String, T>> result = new LinkedList<>();
+ public Collection<Permission> executePermissionsQuery() throws SQLException, ClassNotFoundException {
+ List<Permission> result = new LinkedList<>();
if (query != null) {
try {
try (ResultSet resultSet = statement.executeQuery()) {
ResultSetMetaData resultMetaData = resultSet.getMetaData();
while (resultSet.next()) {
- LinkedHashMap<String, T> map = new LinkedHashMap<>();
+ LinkedHashMap<String, Long> map = new LinkedHashMap<>();
for (int i = 1; i <= resultMetaData.getColumnCount(); i++) {
String label = resultMetaData.getColumnLabel(i);
- map.put(label, resultSet.getObject(label, clazz));
+ map.put(label, resultSet.getLong(label));
}
- result.add(map);
+ result.add(new Permission(map));
}
}
} finally {
diff --git a/src/org/traccar/database/SimpleObjectManager.java b/src/org/traccar/database/SimpleObjectManager.java
index 49ad4707c..031f91fc5 100644
--- a/src/org/traccar/database/SimpleObjectManager.java
+++ b/src/org/traccar/database/SimpleObjectManager.java
@@ -27,6 +27,7 @@ import java.util.concurrent.ConcurrentHashMap;
import org.traccar.Context;
import org.traccar.helper.Log;
import org.traccar.model.BaseModel;
+import org.traccar.model.Permission;
import org.traccar.model.User;
public abstract class SimpleObjectManager {
@@ -117,11 +118,10 @@ public abstract class SimpleObjectManager {
if (dataManager != null) {
try {
clearUserItems();
- for (Map<String, Long> permission : dataManager.getPermissions(User.class, baseClass)) {
- getUserItems(permission.get(DataManager.makeNameId(User.class)))
- .add(permission.get(baseClassIdName));
+ for (Permission permission : dataManager.getPermissions(User.class, baseClass)) {
+ getUserItems(permission.getOwnerId()).add(permission.getPropertyId());
}
- } catch (SQLException error) {
+ } catch (SQLException | ClassNotFoundException error) {
Log.warning(error);
}
}