diff options
author | jcardus <asklocation.net@gmail.com> | 2021-07-08 02:15:00 +0100 |
---|---|---|
committer | jcardus <asklocation.net@gmail.com> | 2021-07-08 02:15:00 +0100 |
commit | 88dfb5313003eb9ba246cab3cfa700ad5c0137de (patch) | |
tree | 515fc5fd4dc3f4ac5d4b4f63be282f74ed1797d7 /src/main/java/org/traccar/api | |
parent | c56851eac17d29b858f1ecd4ec4d5815e1a01b16 (diff) | |
download | trackermap-server-88dfb5313003eb9ba246cab3cfa700ad5c0137de.tar.gz trackermap-server-88dfb5313003eb9ba246cab3cfa700ad5c0137de.tar.bz2 trackermap-server-88dfb5313003eb9ba246cab3cfa700ad5c0137de.zip |
remove stream api
assume permissions are of same type
Diffstat (limited to 'src/main/java/org/traccar/api')
-rw-r--r-- | src/main/java/org/traccar/api/resource/PermissionsResource.java | 37 |
1 files changed, 12 insertions, 25 deletions
diff --git a/src/main/java/org/traccar/api/resource/PermissionsResource.java b/src/main/java/org/traccar/api/resource/PermissionsResource.java index d6048d81b..ef1e16e29 100644 --- a/src/main/java/org/traccar/api/resource/PermissionsResource.java +++ b/src/main/java/org/traccar/api/resource/PermissionsResource.java @@ -17,13 +17,9 @@ package org.traccar.api.resource; import java.sql.SQLException; -import java.util.HashSet; +import java.util.ArrayList; import java.util.LinkedHashMap; import java.util.List; -import java.util.Objects; -import java.util.Set; -import java.util.stream.Collectors; -import java.util.stream.Stream; import javax.ws.rs.Consumes; import javax.ws.rs.DELETE; @@ -61,25 +57,11 @@ public class PermissionsResource extends BaseResource { permission.getPropertyClass(), getUserId(), permission.getPropertyId()); } - private void refreshPermissions(List<LinkedHashMap<String, Long>> entities) { - Set<String> ownerProperty = new HashSet<>(); - entities.stream() - .map(e -> { - try { - return new Permission(e); - } catch (ClassNotFoundException classNotFoundException) { - classNotFoundException.printStackTrace(); - return null; - } - }) - .filter(Objects::nonNull) - .filter(p -> ownerProperty.add(p.getOwnerClass().getName() + p.getPropertyClass().getName())) - .forEach(p -> Context.getPermissionsManager().refreshPermissions(p)); - } - @POST public Response add(LinkedHashMap<String, Long> entity) throws SQLException, ClassNotFoundException { - return add(Stream.of(entity).collect(Collectors.toList())); + List<LinkedHashMap<String, Long>> list = new ArrayList<>(); + list.add(entity); + return add(list); } @Path("bulk") @@ -94,13 +76,17 @@ public class PermissionsResource extends BaseResource { LogAction.link(getUserId(), permission.getOwnerClass(), permission.getOwnerId(), permission.getPropertyClass(), permission.getPropertyId()); } - refreshPermissions(entities); + // we assume all permissions are of same type so we use the first one for refreshing + if (!entities.isEmpty()) + Context.getPermissionsManager().refreshPermissions(new Permission(entities.get(0))); return Response.noContent().build(); } @DELETE public Response remove(LinkedHashMap<String, Long> entity) throws SQLException, ClassNotFoundException { - return remove(Stream.of(entity).collect(Collectors.toList())); + List<LinkedHashMap<String, Long>> list = new ArrayList<>(); + list.add(entity); + return remove(list); } @DELETE @@ -115,7 +101,8 @@ public class PermissionsResource extends BaseResource { LogAction.unlink(getUserId(), permission.getOwnerClass(), permission.getOwnerId(), permission.getPropertyClass(), permission.getPropertyId()); } - refreshPermissions(entities); + if (!entities.isEmpty()) + Context.getPermissionsManager().refreshPermissions(new Permission(entities.get(0))); return Response.noContent().build(); } } |