Commit 55fb8d68fded9d5e3fe02b563e246c6e25fb46da
Merge branch 'master' of github.com:thingsboard/thingsboard
Showing
4 changed files
with
45 additions
and
57 deletions
@@ -130,10 +130,8 @@ public class DefaultActorService implements ActorService { | @@ -130,10 +130,8 @@ public class DefaultActorService implements ActorService { | ||
130 | 130 | ||
131 | @Override | 131 | @Override |
132 | public void process(SessionAwareMsg msg) { | 132 | public void process(SessionAwareMsg msg) { |
133 | - if (msg instanceof SessionAwareMsg) { | ||
134 | - log.debug("Processing session aware msg: {}", msg); | ||
135 | - sessionManagerActor.tell(msg, ActorRef.noSender()); | ||
136 | - } | 133 | + log.debug("Processing session aware msg: {}", msg); |
134 | + sessionManagerActor.tell(msg, ActorRef.noSender()); | ||
137 | } | 135 | } |
138 | 136 | ||
139 | @Override | 137 | @Override |
@@ -50,7 +50,9 @@ public class SessionManagerActor extends ContextAwareActor { | @@ -50,7 +50,9 @@ public class SessionManagerActor extends ContextAwareActor { | ||
50 | 50 | ||
51 | @Override | 51 | @Override |
52 | public void onReceive(Object msg) throws Exception { | 52 | public void onReceive(Object msg) throws Exception { |
53 | - if (msg instanceof SessionAwareMsg) { | 53 | + if (msg instanceof SessionCtrlMsg) { |
54 | + onSessionCtrlMsg((SessionCtrlMsg) msg); | ||
55 | + } else if (msg instanceof SessionAwareMsg) { | ||
54 | forwardToSessionActor((SessionAwareMsg) msg); | 56 | forwardToSessionActor((SessionAwareMsg) msg); |
55 | } else if (msg instanceof SessionTerminationMsg) { | 57 | } else if (msg instanceof SessionTerminationMsg) { |
56 | onSessionTermination((SessionTerminationMsg) msg); | 58 | onSessionTermination((SessionTerminationMsg) msg); |
@@ -58,8 +60,6 @@ public class SessionManagerActor extends ContextAwareActor { | @@ -58,8 +60,6 @@ public class SessionManagerActor extends ContextAwareActor { | ||
58 | onTermination((Terminated) msg); | 60 | onTermination((Terminated) msg); |
59 | } else if (msg instanceof SessionTimeoutMsg) { | 61 | } else if (msg instanceof SessionTimeoutMsg) { |
60 | onSessionTimeout((SessionTimeoutMsg) msg); | 62 | onSessionTimeout((SessionTimeoutMsg) msg); |
61 | - } else if (msg instanceof SessionCtrlMsg) { | ||
62 | - onSessionCtrlMsg((SessionCtrlMsg) msg); | ||
63 | } else if (msg instanceof ClusterEventMsg) { | 63 | } else if (msg instanceof ClusterEventMsg) { |
64 | broadcast(msg); | 64 | broadcast(msg); |
65 | } | 65 | } |
@@ -102,7 +102,7 @@ public class JpaBaseEventDao extends JpaAbstractSearchTimeDao<EventEntity, Event | @@ -102,7 +102,7 @@ public class JpaBaseEventDao extends JpaAbstractSearchTimeDao<EventEntity, Event | ||
102 | 102 | ||
103 | @Override | 103 | @Override |
104 | public List<Event> findEvents(UUID tenantId, EntityId entityId, String eventType, TimePageLink pageLink) { | 104 | public List<Event> findEvents(UUID tenantId, EntityId entityId, String eventType, TimePageLink pageLink) { |
105 | - Specification<EventEntity> timeSearchSpec = JpaAbstractSearchTimeDao.<EventEntity>getTimeSearchPageSpec(pageLink, "id"); | 105 | + Specification<EventEntity> timeSearchSpec = JpaAbstractSearchTimeDao.getTimeSearchPageSpec(pageLink, "id"); |
106 | Specification<EventEntity> fieldsSpec = getEntityFieldsSpec(tenantId, entityId, eventType); | 106 | Specification<EventEntity> fieldsSpec = getEntityFieldsSpec(tenantId, entityId, eventType); |
107 | Sort.Direction sortDirection = pageLink.isAscOrder() ? Sort.Direction.ASC : Sort.Direction.DESC; | 107 | Sort.Direction sortDirection = pageLink.isAscOrder() ? Sort.Direction.ASC : Sort.Direction.DESC; |
108 | Pageable pageable = new PageRequest(0, pageLink.getLimit(), sortDirection, ID_PROPERTY); | 108 | Pageable pageable = new PageRequest(0, pageLink.getLimit(), sortDirection, ID_PROPERTY); |
@@ -129,26 +129,23 @@ public class JpaBaseEventDao extends JpaAbstractSearchTimeDao<EventEntity, Event | @@ -129,26 +129,23 @@ public class JpaBaseEventDao extends JpaAbstractSearchTimeDao<EventEntity, Event | ||
129 | } | 129 | } |
130 | 130 | ||
131 | private Specification<EventEntity> getEntityFieldsSpec(UUID tenantId, EntityId entityId, String eventType) { | 131 | private Specification<EventEntity> getEntityFieldsSpec(UUID tenantId, EntityId entityId, String eventType) { |
132 | - return new Specification<EventEntity>() { | ||
133 | - @Override | ||
134 | - public Predicate toPredicate(Root<EventEntity> root, CriteriaQuery<?> criteriaQuery, CriteriaBuilder criteriaBuilder) { | ||
135 | - List<Predicate> predicates = new ArrayList<Predicate>(); | ||
136 | - if (tenantId != null) { | ||
137 | - Predicate tenantIdPredicate = criteriaBuilder.equal(root.get("tenantId"), UUIDConverter.fromTimeUUID(tenantId)); | ||
138 | - predicates.add(tenantIdPredicate); | ||
139 | - } | ||
140 | - if (entityId != null) { | ||
141 | - Predicate entityTypePredicate = criteriaBuilder.equal(root.get("entityType"), entityId.getEntityType()); | ||
142 | - predicates.add(entityTypePredicate); | ||
143 | - Predicate entityIdPredicate = criteriaBuilder.equal(root.get("entityId"), UUIDConverter.fromTimeUUID(entityId.getId())); | ||
144 | - predicates.add(entityIdPredicate); | ||
145 | - } | ||
146 | - if (eventType != null) { | ||
147 | - Predicate eventTypePredicate = criteriaBuilder.equal(root.get("eventType"), eventType); | ||
148 | - predicates.add(eventTypePredicate); | ||
149 | - } | ||
150 | - return criteriaBuilder.and(predicates.toArray(new Predicate[]{})); | 132 | + return (root, criteriaQuery, criteriaBuilder) -> { |
133 | + List<Predicate> predicates = new ArrayList<>(); | ||
134 | + if (tenantId != null) { | ||
135 | + Predicate tenantIdPredicate = criteriaBuilder.equal(root.get("tenantId"), UUIDConverter.fromTimeUUID(tenantId)); | ||
136 | + predicates.add(tenantIdPredicate); | ||
151 | } | 137 | } |
138 | + if (entityId != null) { | ||
139 | + Predicate entityTypePredicate = criteriaBuilder.equal(root.get("entityType"), entityId.getEntityType()); | ||
140 | + predicates.add(entityTypePredicate); | ||
141 | + Predicate entityIdPredicate = criteriaBuilder.equal(root.get("entityId"), UUIDConverter.fromTimeUUID(entityId.getId())); | ||
142 | + predicates.add(entityIdPredicate); | ||
143 | + } | ||
144 | + if (eventType != null) { | ||
145 | + Predicate eventTypePredicate = criteriaBuilder.equal(root.get("eventType"), eventType); | ||
146 | + predicates.add(eventTypePredicate); | ||
147 | + } | ||
148 | + return criteriaBuilder.and(predicates.toArray(new Predicate[]{})); | ||
152 | }; | 149 | }; |
153 | } | 150 | } |
154 | } | 151 | } |
@@ -160,43 +160,36 @@ public class JpaRelationDao extends JpaAbstractDaoListeningExecutorService imple | @@ -160,43 +160,36 @@ public class JpaRelationDao extends JpaAbstractDaoListeningExecutorService imple | ||
160 | 160 | ||
161 | @Override | 161 | @Override |
162 | public ListenableFuture<List<EntityRelation>> findRelations(EntityId from, String relationType, RelationTypeGroup typeGroup, EntityType childType, TimePageLink pageLink) { | 162 | public ListenableFuture<List<EntityRelation>> findRelations(EntityId from, String relationType, RelationTypeGroup typeGroup, EntityType childType, TimePageLink pageLink) { |
163 | - Specification<RelationEntity> timeSearchSpec = JpaAbstractSearchTimeDao.<RelationEntity>getTimeSearchPageSpec(pageLink, "toId"); | 163 | + Specification<RelationEntity> timeSearchSpec = JpaAbstractSearchTimeDao.getTimeSearchPageSpec(pageLink, "toId"); |
164 | Specification<RelationEntity> fieldsSpec = getEntityFieldsSpec(from, relationType, typeGroup, childType); | 164 | Specification<RelationEntity> fieldsSpec = getEntityFieldsSpec(from, relationType, typeGroup, childType); |
165 | - Pageable pageable = new PageRequest(0, pageLink.getLimit(), | ||
166 | - new Sort( | ||
167 | - new Order(ASC, "relationTypeGroup"), | ||
168 | - new Order(ASC, "relationType"), | ||
169 | - new Order(ASC, "toType")) | ||
170 | - ); | 165 | + Sort.Direction sortDirection = pageLink.isAscOrder() ? Sort.Direction.ASC : Sort.Direction.DESC; |
166 | + Pageable pageable = new PageRequest(0, pageLink.getLimit(), sortDirection, "toId"); | ||
171 | return service.submit(() -> | 167 | return service.submit(() -> |
172 | DaoUtil.convertDataList(relationRepository.findAll(where(timeSearchSpec).and(fieldsSpec), pageable).getContent())); | 168 | DaoUtil.convertDataList(relationRepository.findAll(where(timeSearchSpec).and(fieldsSpec), pageable).getContent())); |
173 | } | 169 | } |
174 | 170 | ||
175 | private Specification<RelationEntity> getEntityFieldsSpec(EntityId from, String relationType, RelationTypeGroup typeGroup, EntityType childType) { | 171 | private Specification<RelationEntity> getEntityFieldsSpec(EntityId from, String relationType, RelationTypeGroup typeGroup, EntityType childType) { |
176 | - return new Specification<RelationEntity>() { | ||
177 | - @Override | ||
178 | - public Predicate toPredicate(Root<RelationEntity> root, CriteriaQuery<?> criteriaQuery, CriteriaBuilder criteriaBuilder) { | ||
179 | - List<Predicate> predicates = new ArrayList<>(); | ||
180 | - if (from != null) { | ||
181 | - Predicate fromIdPredicate = criteriaBuilder.equal(root.get("fromId"), UUIDConverter.fromTimeUUID(from.getId())); | ||
182 | - predicates.add(fromIdPredicate); | ||
183 | - Predicate fromEntityTypePredicate = criteriaBuilder.equal(root.get("fromType"), from.getEntityType().name()); | ||
184 | - predicates.add(fromEntityTypePredicate); | ||
185 | - } | ||
186 | - if (relationType != null) { | ||
187 | - Predicate relationTypePredicate = criteriaBuilder.equal(root.get("relationType"), relationType); | ||
188 | - predicates.add(relationTypePredicate); | ||
189 | - } | ||
190 | - if (typeGroup != null) { | ||
191 | - Predicate typeGroupPredicate = criteriaBuilder.equal(root.get("relationTypeGroup"), typeGroup.name()); | ||
192 | - predicates.add(typeGroupPredicate); | ||
193 | - } | ||
194 | - if (childType != null) { | ||
195 | - Predicate childTypePredicate = criteriaBuilder.equal(root.get("toType"), childType.name()); | ||
196 | - predicates.add(childTypePredicate); | ||
197 | - } | ||
198 | - return criteriaBuilder.and(predicates.toArray(new Predicate[0])); | 172 | + return (root, criteriaQuery, criteriaBuilder) -> { |
173 | + List<Predicate> predicates = new ArrayList<>(); | ||
174 | + if (from != null) { | ||
175 | + Predicate fromIdPredicate = criteriaBuilder.equal(root.get("fromId"), UUIDConverter.fromTimeUUID(from.getId())); | ||
176 | + predicates.add(fromIdPredicate); | ||
177 | + Predicate fromEntityTypePredicate = criteriaBuilder.equal(root.get("fromType"), from.getEntityType().name()); | ||
178 | + predicates.add(fromEntityTypePredicate); | ||
199 | } | 179 | } |
180 | + if (relationType != null) { | ||
181 | + Predicate relationTypePredicate = criteriaBuilder.equal(root.get("relationType"), relationType); | ||
182 | + predicates.add(relationTypePredicate); | ||
183 | + } | ||
184 | + if (typeGroup != null) { | ||
185 | + Predicate typeGroupPredicate = criteriaBuilder.equal(root.get("relationTypeGroup"), typeGroup.name()); | ||
186 | + predicates.add(typeGroupPredicate); | ||
187 | + } | ||
188 | + if (childType != null) { | ||
189 | + Predicate childTypePredicate = criteriaBuilder.equal(root.get("toType"), childType.name()); | ||
190 | + predicates.add(childTypePredicate); | ||
191 | + } | ||
192 | + return criteriaBuilder.and(predicates.toArray(new Predicate[0])); | ||
200 | }; | 193 | }; |
201 | } | 194 | } |
202 | } | 195 | } |