Commit 08f7e48f94da6e45505b85a8d838b3579ff5fb32

Authored by Volodymyr Babak
1 parent 4351c30a

Fixed JPA alarm impl

... ... @@ -106,8 +106,8 @@ public class CassandraAlarmDao extends CassandraAbstractModelDao<AlarmEntity, Al
106 106 List<ListenableFuture<AlarmInfo>> alarmFutures = new ArrayList<>(input.size());
107 107 for (EntityRelation relation : input) {
108 108 alarmFutures.add(Futures.transform(
109   - findAlarmByIdAsync(relation.getTo().getId()), (Function<Alarm, AlarmInfo>)
110   - alarm1 -> new AlarmInfo(alarm1)));
  109 + findAlarmByIdAsync(relation.getTo().getId()),
  110 + (Function<Alarm, AlarmInfo>) AlarmInfo::new));
111 111 }
112 112 return Futures.successfulAsList(alarmFutures);
113 113 });
... ...
... ... @@ -15,6 +15,7 @@
15 15 */
16 16 package org.thingsboard.server.dao.sql.alarm;
17 17
  18 +import com.google.common.base.Function;
18 19 import com.google.common.util.concurrent.AsyncFunction;
19 20 import com.google.common.util.concurrent.Futures;
20 21 import com.google.common.util.concurrent.ListenableFuture;
... ... @@ -26,7 +27,9 @@ import org.springframework.stereotype.Component;
26 27 import org.springframework.transaction.annotation.Transactional;
27 28 import org.thingsboard.server.common.data.EntityType;
28 29 import org.thingsboard.server.common.data.alarm.Alarm;
  30 +import org.thingsboard.server.common.data.alarm.AlarmInfo;
29 31 import org.thingsboard.server.common.data.alarm.AlarmQuery;
  32 +import org.thingsboard.server.common.data.alarm.AlarmSearchStatus;
30 33 import org.thingsboard.server.common.data.id.EntityId;
31 34 import org.thingsboard.server.common.data.id.TenantId;
32 35 import org.thingsboard.server.common.data.relation.EntityRelation;
... ... @@ -85,15 +88,25 @@ public class JpaAlarmDao extends JpaAbstractDao<AlarmEntity, Alarm> implements A
85 88 }
86 89
87 90 @Override
88   - public ListenableFuture<List<Alarm>> findAlarms(AlarmQuery query) {
  91 + public ListenableFuture<List<AlarmInfo>> findAlarms(AlarmQuery query) {
89 92 log.trace("Try to find alarms by entity [{}], status [{}] and pageLink [{}]", query.getAffectedEntityId(), query.getStatus(), query.getPageLink());
90 93 EntityId affectedEntity = query.getAffectedEntityId();
91   - String relationType = query.getStatus() == null ? BaseAlarmService.ALARM_RELATION : BaseAlarmService.ALARM_RELATION_PREFIX + query.getStatus().name();
  94 + String searchStatusName;
  95 + if (query.getSearchStatus() == null && query.getStatus() == null) {
  96 + searchStatusName = AlarmSearchStatus.ANY.name();
  97 + } else if (query.getSearchStatus() != null) {
  98 + searchStatusName = query.getSearchStatus().name();
  99 + } else {
  100 + searchStatusName = query.getStatus().name();
  101 + }
  102 + String relationType = BaseAlarmService.ALARM_RELATION_PREFIX + searchStatusName;
92 103 ListenableFuture<List<EntityRelation>> relations = relationDao.findRelations(affectedEntity, relationType, RelationTypeGroup.ALARM, EntityType.ALARM, query.getPageLink());
93   - return Futures.transform(relations, (AsyncFunction<List<EntityRelation>, List<Alarm>>) input -> {
94   - List<ListenableFuture<Alarm>> alarmFutures = new ArrayList<>(input.size());
  104 + return Futures.transform(relations, (AsyncFunction<List<EntityRelation>, List<AlarmInfo>>) input -> {
  105 + List<ListenableFuture<AlarmInfo>> alarmFutures = new ArrayList<>(input.size());
95 106 for (EntityRelation relation : input) {
96   - alarmFutures.add(findAlarmByIdAsync(relation.getTo().getId()));
  107 + alarmFutures.add(Futures.transform(
  108 + findAlarmByIdAsync(relation.getTo().getId()),
  109 + (Function<Alarm, AlarmInfo>) AlarmInfo::new));
97 110 }
98 111 return Futures.successfulAsList(alarmFutures);
99 112 });
... ...