Showing
15 changed files
with
230 additions
and
43 deletions
... | ... | @@ -21,6 +21,8 @@ import org.thingsboard.server.service.telemetry.cmd.v1.GetHistoryCmd; |
21 | 21 | import org.thingsboard.server.service.telemetry.cmd.v1.TimeseriesSubscriptionCmd; |
22 | 22 | import org.thingsboard.server.service.telemetry.cmd.v2.AlarmDataCmd; |
23 | 23 | import org.thingsboard.server.service.telemetry.cmd.v2.AlarmDataUnsubscribeCmd; |
24 | +import org.thingsboard.server.service.telemetry.cmd.v2.EntityCountCmd; | |
25 | +import org.thingsboard.server.service.telemetry.cmd.v2.EntityCountUnsubscribeCmd; | |
24 | 26 | import org.thingsboard.server.service.telemetry.cmd.v2.EntityDataCmd; |
25 | 27 | import org.thingsboard.server.service.telemetry.cmd.v2.EntityDataUnsubscribeCmd; |
26 | 28 | |
... | ... | @@ -46,4 +48,8 @@ public class TelemetryPluginCmdsWrapper { |
46 | 48 | |
47 | 49 | private List<AlarmDataUnsubscribeCmd> alarmDataUnsubscribeCmds; |
48 | 50 | |
51 | + private List<EntityCountCmd> entityCountCmds; | |
52 | + | |
53 | + private List<EntityCountUnsubscribeCmd> entityCountUnsubscribeCmds; | |
54 | + | |
49 | 55 | } | ... | ... |
... | ... | @@ -18,14 +18,14 @@ package org.thingsboard.server.service.telemetry.cmd.v2; |
18 | 18 | import com.fasterxml.jackson.annotation.JsonCreator; |
19 | 19 | import com.fasterxml.jackson.annotation.JsonProperty; |
20 | 20 | import lombok.Getter; |
21 | -import lombok.NoArgsConstructor; | |
21 | +import lombok.ToString; | |
22 | 22 | import org.thingsboard.server.common.data.page.PageData; |
23 | 23 | import org.thingsboard.server.common.data.query.AlarmData; |
24 | -import org.thingsboard.server.common.data.query.EntityData; | |
25 | 24 | import org.thingsboard.server.service.telemetry.sub.SubscriptionErrorCode; |
26 | 25 | |
27 | 26 | import java.util.List; |
28 | 27 | |
28 | +@ToString | |
29 | 29 | public class AlarmDataUpdate extends DataUpdate<AlarmData> { |
30 | 30 | |
31 | 31 | @Getter |
... | ... | @@ -44,8 +44,8 @@ public class AlarmDataUpdate extends DataUpdate<AlarmData> { |
44 | 44 | } |
45 | 45 | |
46 | 46 | @Override |
47 | - public DataUpdateType getDataUpdateType() { | |
48 | - return DataUpdateType.ALARM_DATA; | |
47 | + public CmdUpdateType getCmdUpdateType() { | |
48 | + return CmdUpdateType.ALARM_DATA; | |
49 | 49 | } |
50 | 50 | |
51 | 51 | @JsonCreator | ... | ... |
1 | +/** | |
2 | + * Copyright © 2016-2021 The Thingsboard Authors | |
3 | + * | |
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | |
5 | + * you may not use this file except in compliance with the License. | |
6 | + * You may obtain a copy of the License at | |
7 | + * | |
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | |
9 | + * | |
10 | + * Unless required by applicable law or agreed to in writing, software | |
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | |
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
13 | + * See the License for the specific language governing permissions and | |
14 | + * limitations under the License. | |
15 | + */ | |
16 | +package org.thingsboard.server.service.telemetry.cmd.v2; | |
17 | + | |
18 | +import lombok.AllArgsConstructor; | |
19 | +import lombok.Data; | |
20 | + | |
21 | +@Data | |
22 | +@AllArgsConstructor | |
23 | +public abstract class CmdUpdate { | |
24 | + | |
25 | + private final int cmdId; | |
26 | + private final int errorCode; | |
27 | + private final String errorMsg; | |
28 | + | |
29 | + public abstract CmdUpdateType getCmdUpdateType(); | |
30 | + | |
31 | +} | ... | ... |
application/src/main/java/org/thingsboard/server/service/telemetry/cmd/v2/CmdUpdateType.java
renamed from
application/src/main/java/org/thingsboard/server/service/telemetry/cmd/v2/DataUpdateType.java
... | ... | @@ -18,21 +18,27 @@ package org.thingsboard.server.service.telemetry.cmd.v2; |
18 | 18 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; |
19 | 19 | import lombok.AllArgsConstructor; |
20 | 20 | import lombok.Data; |
21 | +import lombok.EqualsAndHashCode; | |
22 | +import lombok.Getter; | |
23 | +import lombok.ToString; | |
21 | 24 | import org.thingsboard.server.common.data.page.PageData; |
22 | 25 | import org.thingsboard.server.service.telemetry.sub.SubscriptionErrorCode; |
23 | 26 | |
24 | 27 | import java.util.List; |
25 | 28 | |
26 | -@Data | |
27 | -@AllArgsConstructor | |
28 | 29 | @JsonIgnoreProperties(ignoreUnknown = true) |
29 | -public abstract class DataUpdate<T> { | |
30 | +public abstract class DataUpdate<T> extends CmdUpdate { | |
30 | 31 | |
31 | - private final int cmdId; | |
32 | + @Getter | |
32 | 33 | private final PageData<T> data; |
34 | + @Getter | |
33 | 35 | private final List<T> update; |
34 | - private final int errorCode; | |
35 | - private final String errorMsg; | |
36 | + | |
37 | + public DataUpdate(int cmdId, PageData<T> data, List<T> update, int errorCode, String errorMsg) { | |
38 | + super(cmdId, errorCode, errorMsg); | |
39 | + this.data = data; | |
40 | + this.update = update; | |
41 | + } | |
36 | 42 | |
37 | 43 | public DataUpdate(int cmdId, PageData<T> data, List<T> update) { |
38 | 44 | this(cmdId, data, update, SubscriptionErrorCode.NO_ERROR.getCode(), null); |
... | ... | @@ -42,5 +48,4 @@ public abstract class DataUpdate<T> { |
42 | 48 | this(cmdId, null, null, errorCode, errorMsg); |
43 | 49 | } |
44 | 50 | |
45 | - public abstract DataUpdateType getDataUpdateType(); | |
46 | 51 | } | ... | ... |
application/src/main/java/org/thingsboard/server/service/telemetry/cmd/v2/EntityCountCmd.java
0 → 100644
1 | +/** | |
2 | + * Copyright © 2016-2021 The Thingsboard Authors | |
3 | + * | |
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | |
5 | + * you may not use this file except in compliance with the License. | |
6 | + * You may obtain a copy of the License at | |
7 | + * | |
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | |
9 | + * | |
10 | + * Unless required by applicable law or agreed to in writing, software | |
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | |
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
13 | + * See the License for the specific language governing permissions and | |
14 | + * limitations under the License. | |
15 | + */ | |
16 | +package org.thingsboard.server.service.telemetry.cmd.v2; | |
17 | + | |
18 | +import com.fasterxml.jackson.annotation.JsonCreator; | |
19 | +import com.fasterxml.jackson.annotation.JsonProperty; | |
20 | +import lombok.Getter; | |
21 | +import org.thingsboard.server.common.data.query.EntityCountQuery; | |
22 | +import org.thingsboard.server.common.data.query.EntityDataQuery; | |
23 | + | |
24 | +public class EntityCountCmd extends DataCmd { | |
25 | + | |
26 | + @Getter | |
27 | + private final EntityCountQuery query; | |
28 | + | |
29 | + @JsonCreator | |
30 | + public EntityCountCmd(@JsonProperty("cmdId") int cmdId, | |
31 | + @JsonProperty("query") EntityCountQuery query) { | |
32 | + super(cmdId); | |
33 | + this.query = query; | |
34 | + } | |
35 | +} | ... | ... |
1 | +/** | |
2 | + * Copyright © 2016-2021 The Thingsboard Authors | |
3 | + * | |
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | |
5 | + * you may not use this file except in compliance with the License. | |
6 | + * You may obtain a copy of the License at | |
7 | + * | |
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | |
9 | + * | |
10 | + * Unless required by applicable law or agreed to in writing, software | |
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | |
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
13 | + * See the License for the specific language governing permissions and | |
14 | + * limitations under the License. | |
15 | + */ | |
16 | +package org.thingsboard.server.service.telemetry.cmd.v2; | |
17 | + | |
18 | +import lombok.Data; | |
19 | + | |
20 | +@Data | |
21 | +public class EntityCountUnsubscribeCmd implements UnsubscribeCmd { | |
22 | + | |
23 | + private final int cmdId; | |
24 | + | |
25 | +} | ... | ... |
application/src/main/java/org/thingsboard/server/service/telemetry/cmd/v2/EntityCountUpdate.java
0 → 100644
1 | +/** | |
2 | + * Copyright © 2016-2021 The Thingsboard Authors | |
3 | + * | |
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | |
5 | + * you may not use this file except in compliance with the License. | |
6 | + * You may obtain a copy of the License at | |
7 | + * | |
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | |
9 | + * | |
10 | + * Unless required by applicable law or agreed to in writing, software | |
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | |
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
13 | + * See the License for the specific language governing permissions and | |
14 | + * limitations under the License. | |
15 | + */ | |
16 | +package org.thingsboard.server.service.telemetry.cmd.v2; | |
17 | + | |
18 | +import com.fasterxml.jackson.annotation.JsonCreator; | |
19 | +import com.fasterxml.jackson.annotation.JsonProperty; | |
20 | +import lombok.Getter; | |
21 | +import lombok.ToString; | |
22 | +import org.thingsboard.server.common.data.page.PageData; | |
23 | +import org.thingsboard.server.common.data.query.EntityData; | |
24 | +import org.thingsboard.server.service.telemetry.sub.SubscriptionErrorCode; | |
25 | + | |
26 | +import java.util.List; | |
27 | + | |
28 | +@ToString | |
29 | +public class EntityCountUpdate extends CmdUpdate { | |
30 | + | |
31 | + @Getter | |
32 | + private int count; | |
33 | + | |
34 | + public EntityCountUpdate(int cmdId, int count) { | |
35 | + super(cmdId, SubscriptionErrorCode.NO_ERROR.getCode(), null); | |
36 | + this.count = count; | |
37 | + } | |
38 | + | |
39 | + public EntityCountUpdate(int cmdId, int errorCode, String errorMsg) { | |
40 | + super(cmdId, errorCode, errorMsg); | |
41 | + } | |
42 | + | |
43 | + @Override | |
44 | + public CmdUpdateType getCmdUpdateType() { | |
45 | + return CmdUpdateType.COUNT_DATA; | |
46 | + } | |
47 | + | |
48 | + @JsonCreator | |
49 | + public EntityCountUpdate(@JsonProperty("cmdId") int cmdId, | |
50 | + @JsonProperty("count") int count, | |
51 | + @JsonProperty("errorCode") int errorCode, | |
52 | + @JsonProperty("errorMsg") String errorMsg) { | |
53 | + super(cmdId, errorCode, errorMsg); | |
54 | + this.count = count; | |
55 | + } | |
56 | + | |
57 | +} | ... | ... |
... | ... | @@ -16,16 +16,16 @@ |
16 | 16 | package org.thingsboard.server.service.telemetry.cmd.v2; |
17 | 17 | |
18 | 18 | import com.fasterxml.jackson.annotation.JsonCreator; |
19 | -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; | |
20 | 19 | import com.fasterxml.jackson.annotation.JsonProperty; |
21 | 20 | import lombok.Getter; |
21 | +import lombok.ToString; | |
22 | 22 | import org.thingsboard.server.common.data.page.PageData; |
23 | 23 | import org.thingsboard.server.common.data.query.EntityData; |
24 | 24 | import org.thingsboard.server.service.telemetry.sub.SubscriptionErrorCode; |
25 | 25 | |
26 | 26 | import java.util.List; |
27 | 27 | |
28 | - | |
28 | +@ToString | |
29 | 29 | public class EntityDataUpdate extends DataUpdate<EntityData> { |
30 | 30 | |
31 | 31 | @Getter |
... | ... | @@ -41,8 +41,8 @@ public class EntityDataUpdate extends DataUpdate<EntityData> { |
41 | 41 | } |
42 | 42 | |
43 | 43 | @Override |
44 | - public DataUpdateType getDataUpdateType() { | |
45 | - return DataUpdateType.ENTITY_DATA; | |
44 | + public CmdUpdateType getCmdUpdateType() { | |
45 | + return CmdUpdateType.ENTITY_DATA; | |
46 | 46 | } |
47 | 47 | |
48 | 48 | @JsonCreator | ... | ... |
... | ... | @@ -29,15 +29,13 @@ public abstract class AbstractDataQuery<T extends EntityDataPageLink> extends En |
29 | 29 | protected List<EntityKey> entityFields; |
30 | 30 | @Getter |
31 | 31 | protected List<EntityKey> latestValues; |
32 | - @Getter | |
33 | - protected List<KeyFilter> keyFilters; | |
34 | 32 | |
35 | 33 | public AbstractDataQuery() { |
36 | 34 | super(); |
37 | 35 | } |
38 | 36 | |
39 | - public AbstractDataQuery(EntityFilter entityFilter) { | |
40 | - super(entityFilter); | |
37 | + public AbstractDataQuery(EntityFilter entityFilter, List<KeyFilter> keyFilters) { | |
38 | + super(entityFilter, keyFilters); | |
41 | 39 | } |
42 | 40 | |
43 | 41 | public AbstractDataQuery(EntityFilter entityFilter, |
... | ... | @@ -45,11 +43,10 @@ public abstract class AbstractDataQuery<T extends EntityDataPageLink> extends En |
45 | 43 | List<EntityKey> entityFields, |
46 | 44 | List<EntityKey> latestValues, |
47 | 45 | List<KeyFilter> keyFilters) { |
48 | - super(entityFilter); | |
46 | + super(entityFilter, keyFilters); | |
49 | 47 | this.pageLink = pageLink; |
50 | 48 | this.entityFields = entityFields; |
51 | 49 | this.latestValues = latestValues; |
52 | - this.keyFilters = keyFilters; | |
53 | 50 | } |
54 | 51 | |
55 | 52 | } | ... | ... |
... | ... | @@ -30,8 +30,8 @@ public class AlarmDataQuery extends AbstractDataQuery<AlarmDataPageLink> { |
30 | 30 | public AlarmDataQuery() { |
31 | 31 | } |
32 | 32 | |
33 | - public AlarmDataQuery(EntityFilter entityFilter) { | |
34 | - super(entityFilter); | |
33 | + public AlarmDataQuery(EntityFilter entityFilter, List<KeyFilter> keyFilters) { | |
34 | + super(entityFilter, keyFilters); | |
35 | 35 | } |
36 | 36 | |
37 | 37 | public AlarmDataQuery(EntityFilter entityFilter, AlarmDataPageLink pageLink, List<EntityKey> entityFields, List<EntityKey> latestValues, List<KeyFilter> keyFilters, List<EntityKey> alarmFields) { | ... | ... |
... | ... | @@ -17,14 +17,26 @@ package org.thingsboard.server.common.data.query; |
17 | 17 | |
18 | 18 | import lombok.Getter; |
19 | 19 | |
20 | +import java.util.Collections; | |
21 | +import java.util.List; | |
22 | + | |
20 | 23 | public class EntityCountQuery { |
21 | 24 | |
22 | 25 | @Getter |
23 | 26 | private EntityFilter entityFilter; |
24 | 27 | |
25 | - public EntityCountQuery() {} | |
28 | + @Getter | |
29 | + protected List<KeyFilter> keyFilters; | |
30 | + | |
31 | + public EntityCountQuery() { | |
32 | + } | |
26 | 33 | |
27 | 34 | public EntityCountQuery(EntityFilter entityFilter) { |
35 | + this(entityFilter, Collections.emptyList()); | |
36 | + } | |
37 | + | |
38 | + public EntityCountQuery(EntityFilter entityFilter, List<KeyFilter> keyFilters) { | |
28 | 39 | this.entityFilter = entityFilter; |
40 | + this.keyFilters = keyFilters; | |
29 | 41 | } |
30 | 42 | } | ... | ... |
... | ... | @@ -27,8 +27,8 @@ public class EntityDataQuery extends AbstractDataQuery<EntityDataPageLink> { |
27 | 27 | public EntityDataQuery() { |
28 | 28 | } |
29 | 29 | |
30 | - public EntityDataQuery(EntityFilter entityFilter) { | |
31 | - super(entityFilter); | |
30 | + public EntityDataQuery(EntityFilter entityFilter, List<KeyFilter> keyFilters) { | |
31 | + super(entityFilter, keyFilters); | |
32 | 32 | } |
33 | 33 | |
34 | 34 | public EntityDataQuery(EntityFilter entityFilter, EntityDataPageLink pageLink, List<EntityKey> entityFields, List<EntityKey> latestValues, List<KeyFilter> keyFilters) { | ... | ... |
... | ... | @@ -15,9 +15,6 @@ |
15 | 15 | */ |
16 | 16 | package org.thingsboard.server.dao.service; |
17 | 17 | |
18 | -import com.fasterxml.jackson.core.JsonProcessingException; | |
19 | -import com.fasterxml.jackson.databind.JsonMappingException; | |
20 | -import com.fasterxml.jackson.databind.ObjectMapper; | |
21 | 18 | import com.google.common.util.concurrent.Futures; |
22 | 19 | import com.google.common.util.concurrent.ListenableFuture; |
23 | 20 | import org.junit.After; |
... | ... | @@ -31,25 +28,48 @@ import org.thingsboard.server.common.data.Device; |
31 | 28 | import org.thingsboard.server.common.data.EntityType; |
32 | 29 | import org.thingsboard.server.common.data.Tenant; |
33 | 30 | import org.thingsboard.server.common.data.asset.Asset; |
34 | -import org.thingsboard.server.common.data.id.*; | |
35 | -import org.thingsboard.server.common.data.kv.*; | |
31 | +import org.thingsboard.server.common.data.id.CustomerId; | |
32 | +import org.thingsboard.server.common.data.id.DeviceId; | |
33 | +import org.thingsboard.server.common.data.id.EntityId; | |
34 | +import org.thingsboard.server.common.data.id.TenantId; | |
35 | +import org.thingsboard.server.common.data.kv.AttributeKvEntry; | |
36 | +import org.thingsboard.server.common.data.kv.BaseAttributeKvEntry; | |
37 | +import org.thingsboard.server.common.data.kv.BasicTsKvEntry; | |
38 | +import org.thingsboard.server.common.data.kv.DoubleDataEntry; | |
39 | +import org.thingsboard.server.common.data.kv.KvEntry; | |
40 | +import org.thingsboard.server.common.data.kv.LongDataEntry; | |
41 | +import org.thingsboard.server.common.data.kv.StringDataEntry; | |
36 | 42 | import org.thingsboard.server.common.data.page.PageData; |
37 | -import org.thingsboard.server.common.data.query.*; | |
43 | +import org.thingsboard.server.common.data.query.AssetSearchQueryFilter; | |
44 | +import org.thingsboard.server.common.data.query.DeviceSearchQueryFilter; | |
45 | +import org.thingsboard.server.common.data.query.DeviceTypeFilter; | |
46 | +import org.thingsboard.server.common.data.query.EntityCountQuery; | |
47 | +import org.thingsboard.server.common.data.query.EntityData; | |
48 | +import org.thingsboard.server.common.data.query.EntityDataPageLink; | |
49 | +import org.thingsboard.server.common.data.query.EntityDataQuery; | |
50 | +import org.thingsboard.server.common.data.query.EntityDataSortOrder; | |
51 | +import org.thingsboard.server.common.data.query.EntityKey; | |
52 | +import org.thingsboard.server.common.data.query.EntityKeyType; | |
53 | +import org.thingsboard.server.common.data.query.EntityListFilter; | |
54 | +import org.thingsboard.server.common.data.query.FilterPredicateValue; | |
55 | +import org.thingsboard.server.common.data.query.KeyFilter; | |
56 | +import org.thingsboard.server.common.data.query.NumericFilterPredicate; | |
57 | +import org.thingsboard.server.common.data.query.RelationsQueryFilter; | |
58 | +import org.thingsboard.server.common.data.query.StringFilterPredicate; | |
38 | 59 | import org.thingsboard.server.common.data.relation.EntityRelation; |
39 | 60 | import org.thingsboard.server.common.data.relation.EntitySearchDirection; |
40 | 61 | import org.thingsboard.server.common.data.relation.EntityTypeFilter; |
41 | 62 | import org.thingsboard.server.common.data.relation.RelationTypeGroup; |
42 | -import org.thingsboard.server.common.data.rule.RuleChain; | |
43 | -import org.thingsboard.server.common.data.rule.RuleChainMetaData; | |
44 | -import org.thingsboard.server.common.data.rule.RuleNode; | |
45 | 63 | import org.thingsboard.server.dao.attributes.AttributesService; |
46 | 64 | import org.thingsboard.server.dao.model.sqlts.ts.TsKvEntity; |
47 | -import org.thingsboard.server.dao.rule.RuleChainService; | |
48 | 65 | import org.thingsboard.server.dao.timeseries.TimeseriesService; |
49 | -import org.thingsboard.server.dao.util.DaoTestUtil; | |
50 | -import org.thingsboard.server.dao.util.SqlDbType; | |
51 | 66 | |
52 | -import java.util.*; | |
67 | +import java.util.ArrayList; | |
68 | +import java.util.Arrays; | |
69 | +import java.util.Collections; | |
70 | +import java.util.Comparator; | |
71 | +import java.util.List; | |
72 | +import java.util.Random; | |
53 | 73 | import java.util.concurrent.ExecutionException; |
54 | 74 | import java.util.stream.Collectors; |
55 | 75 | ... | ... |