Search in sources :

Example 11 with Device

use of org.traccar.model.Device in project traccar by tananaev.

the class BaseProtocolEncoder method initDevicePassword.

protected void initDevicePassword(Command command, String defaultPassword) {
    if (!command.getAttributes().containsKey(Command.KEY_DEVICE_PASSWORD)) {
        Device device = Context.getIdentityManager().getById(command.getDeviceId());
        String password = device.getString(Command.KEY_DEVICE_PASSWORD);
        if (password != null) {
            command.set(Command.KEY_DEVICE_PASSWORD, password);
        } else {
            command.set(Command.KEY_DEVICE_PASSWORD, defaultPassword);
        }
    }
}
Also used : Device(org.traccar.model.Device)

Example 12 with Device

use of org.traccar.model.Device in project traccar by tananaev.

the class MediaFilter method doFilter.

@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
    HttpServletResponse httpResponse = (HttpServletResponse) response;
    try {
        HttpSession session = ((HttpServletRequest) request).getSession(false);
        Long userId = null;
        if (session != null) {
            userId = (Long) session.getAttribute(SessionResource.USER_ID_KEY);
            if (userId != null) {
                Context.getPermissionsManager().checkUserEnabled(userId);
                Context.getStatisticsManager().registerRequest(userId);
            }
        }
        if (userId == null) {
            httpResponse.sendError(HttpServletResponse.SC_UNAUTHORIZED);
            return;
        }
        String path = ((HttpServletRequest) request).getPathInfo();
        String[] parts = path.split("/");
        if (parts.length < 2 || parts.length == 2 && !path.endsWith("/")) {
            Context.getPermissionsManager().checkAdmin(userId);
        } else {
            Device device = Context.getDeviceManager().getByUniqueId(parts[1]);
            if (device != null) {
                Context.getPermissionsManager().checkDevice(userId, device.getId());
            } else {
                httpResponse.sendError(HttpServletResponse.SC_NOT_FOUND);
                return;
            }
        }
        chain.doFilter(request, response);
    } catch (SecurityException e) {
        httpResponse.setStatus(HttpServletResponse.SC_FORBIDDEN);
        httpResponse.getWriter().println(Log.exceptionStack(e));
    } catch (SQLException e) {
        httpResponse.setStatus(HttpServletResponse.SC_BAD_REQUEST);
        httpResponse.getWriter().println(Log.exceptionStack(e));
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) SQLException(java.sql.SQLException) HttpSession(javax.servlet.http.HttpSession) Device(org.traccar.model.Device) HttpServletResponse(javax.servlet.http.HttpServletResponse)

Example 13 with Device

use of org.traccar.model.Device in project traccar by tananaev.

the class DeviceManager method updateCachedItem.

@Override
protected void updateCachedItem(Device device) {
    Device cachedDevice = getById(device.getId());
    cachedDevice.setName(device.getName());
    cachedDevice.setGroupId(device.getGroupId());
    cachedDevice.setCategory(device.getCategory());
    cachedDevice.setContact(device.getContact());
    cachedDevice.setModel(device.getModel());
    cachedDevice.setDisabled(device.getDisabled());
    cachedDevice.setAttributes(device.getAttributes());
    if (!device.getUniqueId().equals(cachedDevice.getUniqueId())) {
        devicesByUniqueId.remove(cachedDevice.getUniqueId());
        cachedDevice.setUniqueId(device.getUniqueId());
        putUniqueDeviceId(cachedDevice);
    }
    if (device.getPhone() != null && !device.getPhone().isEmpty() && !device.getPhone().equals(cachedDevice.getPhone())) {
        String phone = cachedDevice.getPhone();
        if (phone != null && !phone.isEmpty()) {
            devicesByPhone.remove(phone);
        }
        cachedDevice.setPhone(device.getPhone());
        putPhone(cachedDevice);
    }
}
Also used : Device(org.traccar.model.Device)

Example 14 with Device

use of org.traccar.model.Device in project traccar by tananaev.

the class DeviceManager method updateLatestPosition.

public void updateLatestPosition(Position position) throws SQLException {
    if (isLatestPosition(position)) {
        getDataManager().updateLatestPosition(position);
        Device device = getById(position.getDeviceId());
        if (device != null) {
            device.setPositionId(position.getId());
        }
        positions.put(position.getDeviceId(), position);
        if (Context.getConnectionManager() != null) {
            Context.getConnectionManager().updatePosition(position);
        }
    }
}
Also used : Device(org.traccar.model.Device)

Example 15 with Device

use of org.traccar.model.Device in project traccar by tananaev.

the class DeviceManager method removeCachedItem.

@Override
protected void removeCachedItem(long deviceId) {
    Device cachedDevice = getById(deviceId);
    if (cachedDevice != null) {
        String deviceUniqueId = cachedDevice.getUniqueId();
        String phone = cachedDevice.getPhone();
        super.removeCachedItem(deviceId);
        devicesByUniqueId.remove(deviceUniqueId);
        if (phone != null && !phone.isEmpty()) {
            devicesByPhone.remove(phone);
        }
    }
    positions.remove(deviceId);
}
Also used : Device(org.traccar.model.Device)

Aggregations

Device (org.traccar.model.Device)33 Position (org.traccar.model.Position)10 Event (org.traccar.model.Event)9 Group (org.traccar.model.Group)7 SQLException (java.sql.SQLException)6 HashMap (java.util.HashMap)6 ArrayList (java.util.ArrayList)5 FileInputStream (java.io.FileInputStream)4 InputStream (java.io.InputStream)4 DeviceReport (org.traccar.reports.model.DeviceReport)4 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)3 HashSet (java.util.HashSet)3 Map (java.util.Map)2 DeviceState (org.traccar.model.DeviceState)2 Geofence (org.traccar.model.Geofence)2 Permission (org.traccar.model.Permission)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1 InetSocketAddress (java.net.InetSocketAddress)1