use of org.traccar.model.Geofence in project traccar by traccar.
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 StorageException, IOException {
ReportUtils.checkPeriodLimit(from, to);
ArrayList<DeviceReport> devicesEvents = new ArrayList<>();
ArrayList<String> sheetNames = new ArrayList<>();
HashMap<Long, String> geofenceNames = new HashMap<>();
HashMap<Long, String> maintenanceNames = 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();
long maintenanceId = event.getMaintenanceId();
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 if (maintenanceId != 0) {
if (Context.getMaintenancesManager().checkItemPermission(userId, maintenanceId)) {
Maintenance maintenance = Context.getMaintenancesManager().getById(maintenanceId);
if (maintenance != null) {
maintenanceNames.put(maintenanceId, maintenance.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("maintenanceNames", maintenanceNames);
jxlsContext.putVar("from", from);
jxlsContext.putVar("to", to);
ReportUtils.processTemplateWithSheets(inputStream, outputStream, jxlsContext);
}
}
use of org.traccar.model.Geofence in project traccar by traccar.
the class EventForwarder method prepareJsonPayload.
protected String prepareJsonPayload(Event event, Position position, Set<Long> users) {
Map<String, Object> data = new HashMap<>();
data.put(KEY_EVENT, event);
if (position != null) {
data.put(KEY_POSITION, position);
}
Device device = Context.getIdentityManager().getById(event.getDeviceId());
if (device != null) {
data.put(KEY_DEVICE, device);
}
if (event.getGeofenceId() != 0) {
Geofence geofence = Context.getGeofenceManager().getById(event.getGeofenceId());
if (geofence != null) {
data.put(KEY_GEOFENCE, geofence);
}
}
data.put(KEY_USERS, Context.getUsersManager().getItems(users));
try {
return Context.getObjectMapper().writeValueAsString(data);
} catch (JsonProcessingException e) {
Log.warning(e);
return null;
}
}
use of org.traccar.model.Geofence in project traccar by traccar.
the class EventForwarder method preparePayload.
protected Map<String, Object> preparePayload(Event event, Position position, Set<Long> users) {
Map<String, Object> data = new HashMap<>();
data.put(KEY_EVENT, event);
if (position != null) {
data.put(KEY_POSITION, position);
}
Device device = Context.getIdentityManager().getById(event.getDeviceId());
if (device != null) {
data.put(KEY_DEVICE, device);
}
if (event.getGeofenceId() != 0) {
Geofence geofence = Context.getGeofenceManager().getById(event.getGeofenceId());
if (geofence != null) {
data.put(KEY_GEOFENCE, geofence);
}
}
if (event.getMaintenanceId() != 0) {
Maintenance maintenance = Context.getMaintenancesManager().getById(event.getMaintenanceId());
if (maintenance != null) {
data.put(KEY_MAINTENANCE, maintenance);
}
}
data.put(KEY_USERS, Context.getUsersManager().getItems(users));
return data;
}
Aggregations