aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/BaseEventHandler.java
blob: 3c2016af0cd3ccf5c0333f0a2792f308717007c9 (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
package org.traccar;

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) {

        Position lastPosition = Context.getConnectionManager().getLastPosition(position.getDeviceId());
        if (lastPosition == null || position.getFixTime().compareTo(lastPosition.getFixTime()) >= 0) {
            isLastPosition = true;
        }

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

    protected abstract Event analizePosition(Position position);

}