use of org.traccar.model.Event in project traccar by tananaev.
the class Events method getExcel.
public static void getExcel(OutputStream outputStream, long userId, Collection<Long> deviceIds, Collection<Long> groupIds, Collection<String> types, Date from, Date to) throws SQLException, IOException {
ReportUtils.checkPeriodLimit(from, to);
ArrayList<DeviceReport> devicesEvents = new ArrayList<>();
ArrayList<String> sheetNames = new ArrayList<>();
HashMap<Long, String> geofenceNames = new HashMap<>();
for (long deviceId : ReportUtils.getDeviceList(deviceIds, groupIds)) {
Context.getPermissionsManager().checkDevice(userId, deviceId);
Collection<Event> events = Context.getDataManager().getEvents(deviceId, from, to);
boolean all = types.isEmpty() || types.contains(Event.ALL_EVENTS);
for (Iterator<Event> iterator = events.iterator(); iterator.hasNext(); ) {
Event event = iterator.next();
if (all || types.contains(event.getType())) {
long geofenceId = event.getGeofenceId();
if (geofenceId != 0) {
if (Context.getGeofenceManager().checkItemPermission(userId, geofenceId)) {
Geofence geofence = Context.getGeofenceManager().getById(geofenceId);
if (geofence != null) {
geofenceNames.put(geofenceId, geofence.getName());
}
} else {
iterator.remove();
}
}
} else {
iterator.remove();
}
}
DeviceReport deviceEvents = new DeviceReport();
Device device = Context.getIdentityManager().getById(deviceId);
deviceEvents.setDeviceName(device.getName());
sheetNames.add(WorkbookUtil.createSafeSheetName(deviceEvents.getDeviceName()));
if (device.getGroupId() != 0) {
Group group = Context.getGroupsManager().getById(device.getGroupId());
if (group != null) {
deviceEvents.setGroupName(group.getName());
}
}
deviceEvents.setObjects(events);
devicesEvents.add(deviceEvents);
}
String templatePath = Context.getConfig().getString("report.templatesPath", "templates/export/");
try (InputStream inputStream = new FileInputStream(templatePath + "/events.xlsx")) {
org.jxls.common.Context jxlsContext = ReportUtils.initializeContext(userId);
jxlsContext.putVar("devices", devicesEvents);
jxlsContext.putVar("sheetNames", sheetNames);
jxlsContext.putVar("geofenceNames", geofenceNames);
jxlsContext.putVar("from", from);
jxlsContext.putVar("to", to);
ReportUtils.processTemplateWithSheets(inputStream, outputStream, jxlsContext);
}
}
use of org.traccar.model.Event in project traccar by tananaev.
the class CommandResultEventHandlerTest method testCommandResultEventHandler.
@Test
public void testCommandResultEventHandler() throws Exception {
CommandResultEventHandler commandResultEventHandler = new CommandResultEventHandler();
Position position = new Position();
position.set(Position.KEY_RESULT, "Test Result");
Map<Event, Position> events = commandResultEventHandler.analyzePosition(position);
assertNotNull(events);
Event event = events.keySet().iterator().next();
assertEquals(Event.TYPE_COMMAND_RESULT, event.getType());
}
use of org.traccar.model.Event in project traccar by tananaev.
the class IgnitionEventHandlerTest method testIgnitionEventHandler.
@Test
public void testIgnitionEventHandler() throws Exception {
IgnitionEventHandler ignitionEventHandler = new IgnitionEventHandler();
Position position = new Position();
position.set(Position.KEY_IGNITION, true);
position.setValid(true);
Map<Event, Position> events = ignitionEventHandler.analyzePosition(position);
assertEquals(events, null);
}
use of org.traccar.model.Event in project traccar by tananaev.
the class MotionEventHandlerTest method testStopWithPositionIgnition.
@Test
public void testStopWithPositionIgnition() throws Exception {
MotionEventHandler motionEventHandler = new MotionEventHandler(new TripsConfig(500, 300 * 1000, 300 * 1000, 0, true, false, 0.01));
Position position = new Position();
position.setTime(date("2017-01-01 00:00:00"));
position.set(Position.KEY_MOTION, false);
position.set(Position.KEY_IGNITION, true);
DeviceState deviceState = new DeviceState();
deviceState.setMotionState(true);
deviceState.setMotionPosition(position);
Position nextPosition = new Position();
nextPosition.setTime(date("2017-01-01 00:02:00"));
nextPosition.set(Position.KEY_MOTION, false);
nextPosition.set(Position.KEY_IGNITION, false);
Map<Event, Position> events = motionEventHandler.updateMotionState(deviceState, nextPosition);
assertNotNull(events);
Event event = events.keySet().iterator().next();
assertEquals(Event.TYPE_DEVICE_STOPPED, event.getType());
assertFalse(deviceState.getMotionState());
assertNull(deviceState.getMotionPosition());
}
use of org.traccar.model.Event in project traccar by tananaev.
the class OverspeedEventHandlerTest method testOverspeedWithStatus.
private void testOverspeedWithStatus(boolean notRepeat) throws Exception {
OverspeedEventHandler overspeedEventHandler = new OverspeedEventHandler(15000, notRepeat);
Position position = new Position();
position.setTime(new Date(System.currentTimeMillis() - 30000));
position.setSpeed(50);
DeviceState deviceState = new DeviceState();
deviceState.setOverspeedState(false);
deviceState.setOverspeedPosition(position);
Map<Event, Position> events = overspeedEventHandler.updateOverspeedState(deviceState, 40);
assertNotNull(events);
Event event = events.keySet().iterator().next();
assertEquals(Event.TYPE_DEVICE_OVERSPEED, event.getType());
assertEquals(notRepeat, deviceState.getOverspeedState());
}
Aggregations