aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/BaseEventHandler.java
blob: 3e3317f0a247860360fcb6a5a0665ab829033ff8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package org.traccar;

import org.traccar.model.Device;
import org.traccar.model.Event;
import org.traccar.model.Position;

public abstract class BaseEventHandler extends BaseDataHandler {

    private boolean isLastPosition = false;

    public boolean isLastPosition() {
        return isLastPosition;
    }

    @Override
    protected Position handlePosition(Position position) {

        Device device = Context.getDataManager().getDeviceById(position.getDeviceId());
        if (device != null) {
            long lastPositionId = device.getPositionId();
            if (position.getId() == lastPositionId) {
                isLastPosition = true;
            }
        }

        Event event = analizePosition(position);
        if (event != null) {
            Context.getConnectionManager().updateEvent(event, position);
        }
        return position;
    }

    protected abstract Event analizePosition(Position position);

}