use of org.traccar.database.DeviceManager in project traccar by tananaev.
the class Context method init.
public static void init(String[] arguments) throws Exception {
config = new Config();
if (arguments.length <= 0) {
throw new RuntimeException("Configuration file is not provided");
}
config.load(arguments[0]);
loggerEnabled = config.getBoolean("logger.enable");
if (loggerEnabled) {
Log.setupLogger(config);
}
objectMapper = new ObjectMapper();
objectMapper.setConfig(objectMapper.getSerializationConfig().without(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS));
if (Context.getConfig().getBoolean("mapper.prettyPrintedJson")) {
objectMapper.enable(SerializationFeature.INDENT_OUTPUT);
}
if (config.hasKey("database.url")) {
dataManager = new DataManager(config);
}
if (config.getBoolean("ldap.enable")) {
ldapProvider = new LdapProvider(config);
}
mediaManager = new MediaManager(config.getString("media.path"));
if (dataManager != null) {
usersManager = new UsersManager(dataManager);
groupsManager = new GroupsManager(dataManager);
deviceManager = new DeviceManager(dataManager);
}
identityManager = deviceManager;
if (config.getBoolean("geocoder.enable")) {
geocoder = initGeocoder();
}
if (config.getBoolean("geolocation.enable")) {
initGeolocationModule();
}
if (config.getBoolean("web.enable")) {
webServer = new WebServer(config, dataManager.getDataSource());
}
permissionsManager = new PermissionsManager(dataManager, usersManager);
connectionManager = new ConnectionManager();
tripsConfig = initTripsConfig();
if (config.getBoolean("event.enable")) {
initEventsModule();
}
serverManager = new ServerManager();
if (config.getBoolean("event.forward.enable")) {
if (Context.getConfig().getBoolean("event.forward.payloadAsParamMode")) {
eventForwarder = new MultiPartEventForwarder();
} else {
eventForwarder = new JsonTypeEventForwarder();
}
}
attributesManager = new AttributesManager(dataManager);
driversManager = new DriversManager(dataManager);
commandsManager = new CommandsManager(dataManager);
statisticsManager = new StatisticsManager();
if (config.getBoolean("sms.smpp.enable")) {
smppClient = new SmppClient();
}
}
use of org.traccar.database.DeviceManager in project traccar by tananaev.
the class DeviceResource method get.
@GET
public Collection<Device> get(@QueryParam("all") boolean all, @QueryParam("userId") long userId, @QueryParam("uniqueId") List<String> uniqueIds, @QueryParam("id") List<Long> deviceIds) throws SQLException {
DeviceManager deviceManager = Context.getDeviceManager();
Set<Long> result = null;
if (all) {
if (Context.getPermissionsManager().getUserAdmin(getUserId())) {
result = deviceManager.getAllItems();
} else {
Context.getPermissionsManager().checkManager(getUserId());
result = deviceManager.getManagedItems(getUserId());
}
} else if (uniqueIds.isEmpty() && deviceIds.isEmpty()) {
if (userId == 0) {
userId = getUserId();
}
Context.getPermissionsManager().checkUser(getUserId(), userId);
if (Context.getPermissionsManager().getUserAdmin(getUserId())) {
result = deviceManager.getAllUserItems(userId);
} else {
result = deviceManager.getUserItems(userId);
}
} else {
result = new HashSet<>();
for (String uniqueId : uniqueIds) {
Device device = deviceManager.getByUniqueId(uniqueId);
Context.getPermissionsManager().checkDevice(getUserId(), device.getId());
result.add(device.getId());
}
for (Long deviceId : deviceIds) {
Context.getPermissionsManager().checkDevice(getUserId(), deviceId);
result.add(deviceId);
}
}
return deviceManager.getItems(result);
}
Aggregations