Search in sources :

Example 1 with DeviceManager

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();
    }
}
Also used : MultiPartEventForwarder(org.traccar.notification.MultiPartEventForwarder) TripsConfig(org.traccar.reports.model.TripsConfig) DriversManager(org.traccar.database.DriversManager) AttributesManager(org.traccar.database.AttributesManager) DataManager(org.traccar.database.DataManager) DeviceManager(org.traccar.database.DeviceManager) LdapProvider(org.traccar.database.LdapProvider) SmppClient(org.traccar.smpp.SmppClient) JsonTypeEventForwarder(org.traccar.notification.JsonTypeEventForwarder) UsersManager(org.traccar.database.UsersManager) ConnectionManager(org.traccar.database.ConnectionManager) StatisticsManager(org.traccar.database.StatisticsManager) WebServer(org.traccar.web.WebServer) MediaManager(org.traccar.database.MediaManager) PermissionsManager(org.traccar.database.PermissionsManager) CommandsManager(org.traccar.database.CommandsManager) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) GroupsManager(org.traccar.database.GroupsManager)

Example 2 with DeviceManager

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);
}
Also used : Device(org.traccar.model.Device) DeviceManager(org.traccar.database.DeviceManager) HashSet(java.util.HashSet) GET(javax.ws.rs.GET)

Aggregations

DeviceManager (org.traccar.database.DeviceManager)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 HashSet (java.util.HashSet)1 GET (javax.ws.rs.GET)1 AttributesManager (org.traccar.database.AttributesManager)1 CommandsManager (org.traccar.database.CommandsManager)1 ConnectionManager (org.traccar.database.ConnectionManager)1 DataManager (org.traccar.database.DataManager)1 DriversManager (org.traccar.database.DriversManager)1 GroupsManager (org.traccar.database.GroupsManager)1 LdapProvider (org.traccar.database.LdapProvider)1 MediaManager (org.traccar.database.MediaManager)1 PermissionsManager (org.traccar.database.PermissionsManager)1 StatisticsManager (org.traccar.database.StatisticsManager)1 UsersManager (org.traccar.database.UsersManager)1 Device (org.traccar.model.Device)1 JsonTypeEventForwarder (org.traccar.notification.JsonTypeEventForwarder)1 MultiPartEventForwarder (org.traccar.notification.MultiPartEventForwarder)1 TripsConfig (org.traccar.reports.model.TripsConfig)1 SmppClient (org.traccar.smpp.SmppClient)1