use of org.traccar.model.Permission in project traccar by tananaev.
the class PermissionsManager method refreshDeviceAndGroupPermissions.
public final void refreshDeviceAndGroupPermissions() {
groupPermissions.clear();
devicePermissions.clear();
try {
GroupTree groupTree = new GroupTree(Context.getGroupsManager().getItems(Context.getGroupsManager().getAllItems()), Context.getDeviceManager().getAllDevices());
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.getPropertyId())) {
userDevicePermissions.add(device.getId());
}
}
for (Permission devicePermission : dataManager.getPermissions(User.class, Device.class)) {
getDevicePermissions(devicePermission.getOwnerId()).add(devicePermission.getPropertyId());
}
groupDevices.clear();
for (long groupId : Context.getGroupsManager().getAllItems()) {
for (Device device : groupTree.getDevices(groupId)) {
getGroupDevices(groupId).add(device.getId());
}
}
} catch (SQLException | ClassNotFoundException error) {
Log.warning(error);
}
deviceUsers.clear();
for (Map.Entry<Long, Set<Long>> entry : devicePermissions.entrySet()) {
for (long deviceId : entry.getValue()) {
getAllDeviceUsers(deviceId).add(entry.getKey());
}
}
}
use of org.traccar.model.Permission in project traccar by tananaev.
the class ExtendedObjectManager method refreshExtendedPermissions.
public void refreshExtendedPermissions() {
if (getDataManager() != null) {
try {
Collection<Permission> databaseGroupPermissions = getDataManager().getPermissions(Group.class, getBaseClass());
groupItems.clear();
for (Permission groupPermission : databaseGroupPermissions) {
getGroupItems(groupPermission.getOwnerId()).add(groupPermission.getPropertyId());
}
Collection<Permission> databaseDevicePermissions = getDataManager().getPermissions(Device.class, getBaseClass());
deviceItems.clear();
deviceItemsWithGroups.clear();
for (Permission devicePermission : databaseDevicePermissions) {
getDeviceItems(devicePermission.getOwnerId()).add(devicePermission.getPropertyId());
getAllDeviceItems(devicePermission.getOwnerId()).add(devicePermission.getPropertyId());
}
for (Device device : Context.getDeviceManager().getAllDevices()) {
long groupId = device.getGroupId();
while (groupId != 0) {
getAllDeviceItems(device.getId()).addAll(getGroupItems(groupId));
Group group = Context.getGroupsManager().getById(groupId);
if (group != null) {
groupId = group.getGroupId();
} else {
groupId = 0;
}
}
}
} catch (SQLException | ClassNotFoundException error) {
Log.warning(error);
}
}
}
use of org.traccar.model.Permission in project traccar by tananaev.
the class QueryBuilder method executePermissionsQuery.
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, Long> map = new LinkedHashMap<>();
for (int i = 1; i <= resultMetaData.getColumnCount(); i++) {
String label = resultMetaData.getColumnLabel(i);
map.put(label, resultSet.getLong(label));
}
result.add(new Permission(map));
}
}
} finally {
statement.close();
connection.close();
}
}
return result;
}
use of org.traccar.model.Permission in project traccar by tananaev.
the class PermissionsResource method add.
@POST
public Response add(LinkedHashMap<String, Long> entity) throws SQLException, ClassNotFoundException {
Context.getPermissionsManager().checkReadonly(getUserId());
Permission permission = new Permission(entity);
checkPermission(permission, true);
Context.getDataManager().linkObject(permission.getOwnerClass(), permission.getOwnerId(), permission.getPropertyClass(), permission.getPropertyId(), true);
LogAction.link(getUserId(), permission.getOwnerClass(), permission.getOwnerId(), permission.getPropertyClass(), permission.getPropertyId());
Context.getPermissionsManager().refreshPermissions(permission);
return Response.noContent().build();
}
use of org.traccar.model.Permission in project traccar by tananaev.
the class PermissionsResource method remove.
@DELETE
public Response remove(LinkedHashMap<String, Long> entity) throws SQLException, ClassNotFoundException {
Context.getPermissionsManager().checkReadonly(getUserId());
Permission permission = new Permission(entity);
checkPermission(permission, false);
Context.getDataManager().linkObject(permission.getOwnerClass(), permission.getOwnerId(), permission.getPropertyClass(), permission.getPropertyId(), false);
LogAction.unlink(getUserId(), permission.getOwnerClass(), permission.getOwnerId(), permission.getPropertyClass(), permission.getPropertyId());
Context.getPermissionsManager().refreshPermissions(permission);
return Response.noContent().build();
}
Aggregations