aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/org')
-rw-r--r--src/main/java/org/traccar/api/resource/CommandResource.java3
-rw-r--r--src/main/java/org/traccar/api/resource/ReportResource.java22
-rw-r--r--src/main/java/org/traccar/helper/LogAction.java31
-rw-r--r--src/main/java/org/traccar/schedule/TaskReports.java2
4 files changed, 36 insertions, 22 deletions
diff --git a/src/main/java/org/traccar/api/resource/CommandResource.java b/src/main/java/org/traccar/api/resource/CommandResource.java
index c23d91e77..66ec0f8a3 100644
--- a/src/main/java/org/traccar/api/resource/CommandResource.java
+++ b/src/main/java/org/traccar/api/resource/CommandResource.java
@@ -23,6 +23,7 @@ import org.traccar.BaseProtocol;
import org.traccar.ServerManager;
import org.traccar.api.ExtendedObjectResource;
import org.traccar.database.CommandsManager;
+import org.traccar.helper.LogAction;
import org.traccar.helper.model.DeviceUtil;
import org.traccar.model.Command;
import org.traccar.model.Device;
@@ -140,6 +141,8 @@ public class CommandResource extends ExtendedObjectResource<Command> {
return Response.accepted(queuedCommand).build();
}
}
+
+ LogAction.command(getUserId(), groupId, entity.getDeviceId(), entity.getType());
return Response.ok(entity).build();
}
diff --git a/src/main/java/org/traccar/api/resource/ReportResource.java b/src/main/java/org/traccar/api/resource/ReportResource.java
index 2ed119298..81f409c0f 100644
--- a/src/main/java/org/traccar/api/resource/ReportResource.java
+++ b/src/main/java/org/traccar/api/resource/ReportResource.java
@@ -113,7 +113,7 @@ public class ReportResource extends SimpleObjectResource<Report> {
@QueryParam("from") Date from,
@QueryParam("to") Date to) throws StorageException {
permissionsService.checkRestriction(getUserId(), UserRestrictions::getDisableReports);
- LogAction.logReport(getUserId(), false, "combined", from, to, deviceIds, groupIds);
+ LogAction.report(getUserId(), false, "combined", from, to, deviceIds, groupIds);
return combinedReportProvider.getObjects(getUserId(), deviceIds, groupIds, from, to);
}
@@ -125,7 +125,7 @@ public class ReportResource extends SimpleObjectResource<Report> {
@QueryParam("from") Date from,
@QueryParam("to") Date to) throws StorageException {
permissionsService.checkRestriction(getUserId(), UserRestrictions::getDisableReports);
- LogAction.logReport(getUserId(), false, "route", from, to, deviceIds, groupIds);
+ LogAction.report(getUserId(), false, "route", from, to, deviceIds, groupIds);
return routeReportProvider.getObjects(getUserId(), deviceIds, groupIds, from, to);
}
@@ -140,7 +140,7 @@ public class ReportResource extends SimpleObjectResource<Report> {
@QueryParam("mail") boolean mail) throws StorageException {
permissionsService.checkRestriction(getUserId(), UserRestrictions::getDisableReports);
return executeReport(getUserId(), mail, stream -> {
- LogAction.logReport(getUserId(), false, "route", from, to, deviceIds, groupIds);
+ LogAction.report(getUserId(), false, "route", from, to, deviceIds, groupIds);
routeReportProvider.getExcel(stream, getUserId(), deviceIds, groupIds, from, to);
});
}
@@ -166,7 +166,7 @@ public class ReportResource extends SimpleObjectResource<Report> {
@QueryParam("from") Date from,
@QueryParam("to") Date to) throws StorageException {
permissionsService.checkRestriction(getUserId(), UserRestrictions::getDisableReports);
- LogAction.logReport(getUserId(), false, "events", from, to, deviceIds, groupIds);
+ LogAction.report(getUserId(), false, "events", from, to, deviceIds, groupIds);
return eventsReportProvider.getObjects(getUserId(), deviceIds, groupIds, types, from, to);
}
@@ -182,7 +182,7 @@ public class ReportResource extends SimpleObjectResource<Report> {
@QueryParam("mail") boolean mail) throws StorageException {
permissionsService.checkRestriction(getUserId(), UserRestrictions::getDisableReports);
return executeReport(getUserId(), mail, stream -> {
- LogAction.logReport(getUserId(), false, "events", from, to, deviceIds, groupIds);
+ LogAction.report(getUserId(), false, "events", from, to, deviceIds, groupIds);
eventsReportProvider.getExcel(stream, getUserId(), deviceIds, groupIds, types, from, to);
});
}
@@ -209,7 +209,7 @@ public class ReportResource extends SimpleObjectResource<Report> {
@QueryParam("to") Date to,
@QueryParam("daily") boolean daily) throws StorageException {
permissionsService.checkRestriction(getUserId(), UserRestrictions::getDisableReports);
- LogAction.logReport(getUserId(), false, "summary", from, to, deviceIds, groupIds);
+ LogAction.report(getUserId(), false, "summary", from, to, deviceIds, groupIds);
return summaryReportProvider.getObjects(getUserId(), deviceIds, groupIds, from, to, daily);
}
@@ -225,7 +225,7 @@ public class ReportResource extends SimpleObjectResource<Report> {
@QueryParam("mail") boolean mail) throws StorageException {
permissionsService.checkRestriction(getUserId(), UserRestrictions::getDisableReports);
return executeReport(getUserId(), mail, stream -> {
- LogAction.logReport(getUserId(), false, "summary", from, to, deviceIds, groupIds);
+ LogAction.report(getUserId(), false, "summary", from, to, deviceIds, groupIds);
summaryReportProvider.getExcel(stream, getUserId(), deviceIds, groupIds, from, to, daily);
});
}
@@ -251,7 +251,7 @@ public class ReportResource extends SimpleObjectResource<Report> {
@QueryParam("from") Date from,
@QueryParam("to") Date to) throws StorageException {
permissionsService.checkRestriction(getUserId(), UserRestrictions::getDisableReports);
- LogAction.logReport(getUserId(), false, "trips", from, to, deviceIds, groupIds);
+ LogAction.report(getUserId(), false, "trips", from, to, deviceIds, groupIds);
return tripsReportProvider.getObjects(getUserId(), deviceIds, groupIds, from, to);
}
@@ -266,7 +266,7 @@ public class ReportResource extends SimpleObjectResource<Report> {
@QueryParam("mail") boolean mail) throws StorageException {
permissionsService.checkRestriction(getUserId(), UserRestrictions::getDisableReports);
return executeReport(getUserId(), mail, stream -> {
- LogAction.logReport(getUserId(), false, "trips", from, to, deviceIds, groupIds);
+ LogAction.report(getUserId(), false, "trips", from, to, deviceIds, groupIds);
tripsReportProvider.getExcel(stream, getUserId(), deviceIds, groupIds, from, to);
});
}
@@ -291,7 +291,7 @@ public class ReportResource extends SimpleObjectResource<Report> {
@QueryParam("from") Date from,
@QueryParam("to") Date to) throws StorageException {
permissionsService.checkRestriction(getUserId(), UserRestrictions::getDisableReports);
- LogAction.logReport(getUserId(), false, "stops", from, to, deviceIds, groupIds);
+ LogAction.report(getUserId(), false, "stops", from, to, deviceIds, groupIds);
return stopsReportProvider.getObjects(getUserId(), deviceIds, groupIds, from, to);
}
@@ -306,7 +306,7 @@ public class ReportResource extends SimpleObjectResource<Report> {
@QueryParam("mail") boolean mail) throws StorageException {
permissionsService.checkRestriction(getUserId(), UserRestrictions::getDisableReports);
return executeReport(getUserId(), mail, stream -> {
- LogAction.logReport(getUserId(), false, "stops", from, to, deviceIds, groupIds);
+ LogAction.report(getUserId(), false, "stops", from, to, deviceIds, groupIds);
stopsReportProvider.getExcel(stream, getUserId(), deviceIds, groupIds, from, to);
});
}
diff --git a/src/main/java/org/traccar/helper/LogAction.java b/src/main/java/org/traccar/helper/LogAction.java
index adbe33916..3c4b69a2e 100644
--- a/src/main/java/org/traccar/helper/LogAction.java
+++ b/src/main/java/org/traccar/helper/LogAction.java
@@ -44,12 +44,15 @@ public final class LogAction {
private static final String ACTION_LOGOUT = "logout";
private static final String ACTION_ACCUMULATORS = "accumulators";
+ private static final String ACTION_COMMAND = "command";
private static final String PATTERN_OBJECT = "user: %d, action: %s, object: %s, id: %d";
private static final String PATTERN_LINK = "user: %d, action: %s, owner: %s, id: %d, property: %s, id: %d";
private static final String PATTERN_LOGIN = "user: %d, action: %s, from: %s";
private static final String PATTERN_LOGIN_FAILED = "login failed from: %s";
private static final String PATTERN_ACCUMULATORS = "user: %d, action: %s, deviceId: %d";
+ private static final String PATTERN_COMMAND_DEVICE = "user: %d, action: %s, deviceId: %d, type: %s";
+ private static final String PATTERN_COMMAND_GROUP = "user: %d, action: %s, groupId: %d, type: %s";
private static final String PATTERN_REPORT = "user: %d, %s: %s, from: %s, to: %s, devices: %s, groups: %s";
public static void create(long userId, BaseModel object) {
@@ -92,6 +95,24 @@ public final class LogAction {
PATTERN_ACCUMULATORS, userId, ACTION_ACCUMULATORS, deviceId));
}
+ public static void command(long userId, long groupId, long deviceId, String type) {
+ if (groupId > 0) {
+ LOGGER.info(String.format(PATTERN_COMMAND_GROUP, userId, ACTION_COMMAND, groupId, type));
+ } else {
+ LOGGER.info(String.format(PATTERN_COMMAND_DEVICE, userId, ACTION_COMMAND, deviceId, type));
+ }
+ }
+
+ public static void report(
+ long userId, boolean scheduled, String report,
+ Date from, Date to, List<Long> deviceIds, List<Long> groupIds) {
+ DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm");
+ LOGGER.info(String.format(
+ PATTERN_REPORT, userId, scheduled ? "scheduled" : "report", report,
+ dateFormat.format(from), dateFormat.format(to),
+ deviceIds.toString(), groupIds.toString()));
+ }
+
private static void logObjectAction(String action, long userId, Class<?> clazz, long objectId) {
LOGGER.info(String.format(
PATTERN_OBJECT, userId, action, Introspector.decapitalize(clazz.getSimpleName()), objectId));
@@ -112,14 +133,4 @@ public final class LogAction {
LOGGER.info(String.format(PATTERN_LOGIN, userId, action, remoteAddress));
}
- public static void logReport(
- long userId, boolean scheduled, String report,
- Date from, Date to, List<Long> deviceIds, List<Long> groupIds) {
- DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm");
- LOGGER.info(String.format(
- PATTERN_REPORT, userId, scheduled ? "scheduled" : "report", report,
- dateFormat.format(from), dateFormat.format(to),
- deviceIds.toString(), groupIds.toString()));
- }
-
}
diff --git a/src/main/java/org/traccar/schedule/TaskReports.java b/src/main/java/org/traccar/schedule/TaskReports.java
index 1d074214c..070fa9d2b 100644
--- a/src/main/java/org/traccar/schedule/TaskReports.java
+++ b/src/main/java/org/traccar/schedule/TaskReports.java
@@ -114,7 +114,7 @@ public class TaskReports implements ScheduleTask {
ReportMailer reportMailer = injector.getInstance(ReportMailer.class);
for (User user : users) {
- LogAction.logReport(user.getId(), true, report.getType(), from, to, deviceIds, groupIds);
+ LogAction.report(user.getId(), true, report.getType(), from, to, deviceIds, groupIds);
switch (report.getType()) {
case "events":
var eventsReportProvider = injector.getInstance(EventsReportProvider.class);