aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/traccar/api
diff options
context:
space:
mode:
authorAnton Tananaev <anton@traccar.org>2024-07-06 17:46:17 -0700
committerAnton Tananaev <anton@traccar.org>2024-07-06 17:46:17 -0700
commitb8390005722dd1cdb24d762797ef3f98ebc37755 (patch)
treecaabf1a7541aebc4e81565e95ee78e2d8afe3d75 /src/main/java/org/traccar/api
parent75e3c6a6bbb028b2f99b06faac66d5b53cf59900 (diff)
downloadtrackermap-server-b8390005722dd1cdb24d762797ef3f98ebc37755.tar.gz
trackermap-server-b8390005722dd1cdb24d762797ef3f98ebc37755.tar.bz2
trackermap-server-b8390005722dd1cdb24d762797ef3f98ebc37755.zip
Update instanceof expressions
Diffstat (limited to 'src/main/java/org/traccar/api')
-rw-r--r--src/main/java/org/traccar/api/BaseObjectResource.java9
-rw-r--r--src/main/java/org/traccar/api/ResourceErrorHandler.java3
-rw-r--r--src/main/java/org/traccar/api/security/PermissionsService.java9
3 files changed, 7 insertions, 14 deletions
diff --git a/src/main/java/org/traccar/api/BaseObjectResource.java b/src/main/java/org/traccar/api/BaseObjectResource.java
index 3c97dd1f8..e35850e1f 100644
--- a/src/main/java/org/traccar/api/BaseObjectResource.java
+++ b/src/main/java/org/traccar/api/BaseObjectResource.java
@@ -89,15 +89,13 @@ public abstract class BaseObjectResource<T extends BaseModel> extends BaseResour
permissionsService.checkPermission(baseClass, getUserId(), entity.getId());
boolean skipReadonly = false;
- if (entity instanceof User) {
- User after = (User) entity;
+ if (entity instanceof User after) {
User before = storage.getObject(User.class, new Request(
new Columns.All(), new Condition.Equals("id", entity.getId())));
permissionsService.checkUserUpdate(getUserId(), before, (User) entity);
skipReadonly = permissionsService.getUser(getUserId())
.compare(after, "notificationTokens", "termsAccepted");
- } else if (entity instanceof Group) {
- Group group = (Group) entity;
+ } else if (entity instanceof Group group) {
if (group.getId() == group.getGroupId()) {
throw new IllegalArgumentException("Cycle in group hierarchy");
}
@@ -108,8 +106,7 @@ public abstract class BaseObjectResource<T extends BaseModel> extends BaseResour
storage.updateObject(entity, new Request(
new Columns.Exclude("id"),
new Condition.Equals("id", entity.getId())));
- if (entity instanceof User) {
- User user = (User) entity;
+ if (entity instanceof User user) {
if (user.getHashedPassword() != null) {
storage.updateObject(entity, new Request(
new Columns.Include("hashedPassword", "salt"),
diff --git a/src/main/java/org/traccar/api/ResourceErrorHandler.java b/src/main/java/org/traccar/api/ResourceErrorHandler.java
index 387f3db6a..5f5e70632 100644
--- a/src/main/java/org/traccar/api/ResourceErrorHandler.java
+++ b/src/main/java/org/traccar/api/ResourceErrorHandler.java
@@ -25,8 +25,7 @@ public class ResourceErrorHandler implements ExceptionMapper<Exception> {
@Override
public Response toResponse(Exception e) {
- if (e instanceof WebApplicationException) {
- WebApplicationException webException = (WebApplicationException) e;
+ if (e instanceof WebApplicationException webException) {
return Response.fromResponse(webException.getResponse()).entity(Log.exceptionStack(webException)).build();
} else {
return Response.status(Response.Status.BAD_REQUEST).entity(Log.exceptionStack(e)).build();
diff --git a/src/main/java/org/traccar/api/security/PermissionsService.java b/src/main/java/org/traccar/api/security/PermissionsService.java
index d4a6fba1a..721793c2f 100644
--- a/src/main/java/org/traccar/api/security/PermissionsService.java
+++ b/src/main/java/org/traccar/api/security/PermissionsService.java
@@ -128,8 +128,7 @@ public class PermissionsService {
throws StorageException, SecurityException {
if (!getUser(userId).getAdministrator()) {
checkEdit(userId, object.getClass(), addition, skipReadonly);
- if (object instanceof GroupedModel) {
- GroupedModel after = ((GroupedModel) object);
+ if (object instanceof GroupedModel after) {
if (after.getGroupId() > 0) {
GroupedModel before = null;
if (!addition) {
@@ -141,8 +140,7 @@ public class PermissionsService {
}
}
}
- if (object instanceof Schedulable) {
- Schedulable after = ((Schedulable) object);
+ if (object instanceof Schedulable after) {
if (after.getCalendarId() > 0) {
Schedulable before = null;
if (!addition) {
@@ -154,8 +152,7 @@ public class PermissionsService {
}
}
}
- if (object instanceof Notification) {
- Notification after = ((Notification) object);
+ if (object instanceof Notification after) {
if (after.getCommandId() > 0) {
Notification before = null;
if (!addition) {