27 changed files with 1376 additions and 54 deletions
@ -0,0 +1,93 @@ |
|||
-- |
|||
-- Copyright © 2016-2018 The Thingsboard Authors |
|||
-- |
|||
-- Licensed under the Apache License, Version 2.0 (the "License"); |
|||
-- you may not use this file except in compliance with the License. |
|||
-- You may obtain a copy of the License at |
|||
-- |
|||
-- http://www.apache.org/licenses/LICENSE-2.0 |
|||
-- |
|||
-- Unless required by applicable law or agreed to in writing, software |
|||
-- distributed under the License is distributed on an "AS IS" BASIS, |
|||
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|||
-- See the License for the specific language governing permissions and |
|||
-- limitations under the License. |
|||
-- |
|||
|
|||
CREATE TABLE IF NOT EXISTS thingsboard.msg_queue ( |
|||
node_id timeuuid, |
|||
clustered_hash bigint, |
|||
partition bigint, |
|||
ts bigint, |
|||
msg blob, |
|||
PRIMARY KEY ((node_id, clustered_hash, partition), ts)) |
|||
WITH CLUSTERING ORDER BY (ts DESC) |
|||
AND compaction = { |
|||
'class': 'org.apache.cassandra.db.compaction.DateTieredCompactionStrategy', |
|||
'min_threshold': '5', |
|||
'base_time_seconds': '43200', |
|||
'max_window_size_seconds': '43200', |
|||
'tombstone_threshold': '0.9', |
|||
'unchecked_tombstone_compaction': 'true' |
|||
}; |
|||
|
|||
CREATE TABLE IF NOT EXISTS thingsboard.msg_ack_queue ( |
|||
node_id timeuuid, |
|||
clustered_hash bigint, |
|||
partition bigint, |
|||
msg_id timeuuid, |
|||
PRIMARY KEY ((node_id, clustered_hash, partition), msg_id)) |
|||
WITH CLUSTERING ORDER BY (msg_id DESC) |
|||
AND compaction = { |
|||
'class': 'org.apache.cassandra.db.compaction.DateTieredCompactionStrategy', |
|||
'min_threshold': '5', |
|||
'base_time_seconds': '43200', |
|||
'max_window_size_seconds': '43200', |
|||
'tombstone_threshold': '0.9', |
|||
'unchecked_tombstone_compaction': 'true' |
|||
}; |
|||
|
|||
CREATE TABLE IF NOT EXISTS thingsboard.processed_msg_partitions ( |
|||
node_id timeuuid, |
|||
clustered_hash bigint, |
|||
partition bigint, |
|||
PRIMARY KEY ((node_id, clustered_hash), partition)) |
|||
WITH CLUSTERING ORDER BY (partition DESC) |
|||
AND compaction = { |
|||
'class': 'org.apache.cassandra.db.compaction.DateTieredCompactionStrategy', |
|||
'min_threshold': '5', |
|||
'base_time_seconds': '43200', |
|||
'max_window_size_seconds': '43200', |
|||
'tombstone_threshold': '0.9', |
|||
'unchecked_tombstone_compaction': 'true' |
|||
}; |
|||
|
|||
CREATE TABLE IF NOT EXISTS thingsboard.rule_chain ( |
|||
id uuid, |
|||
tenant_id uuid, |
|||
name text, |
|||
search_text text, |
|||
first_rule_node_id uuid, |
|||
is_root boolean, |
|||
configuration text, |
|||
additional_info text, |
|||
PRIMARY KEY (id, tenant_id) |
|||
); |
|||
|
|||
CREATE MATERIALIZED VIEW IF NOT EXISTS thingsboard.rule_chain_by_tenant_and_search_text AS |
|||
SELECT * |
|||
from thingsboard.rule_chain |
|||
WHERE tenant_id IS NOT NULL AND search_text IS NOT NULL AND id IS NOT NULL |
|||
PRIMARY KEY ( tenant_id, search_text, id ) |
|||
WITH CLUSTERING ORDER BY ( search_text ASC, id DESC ); |
|||
|
|||
CREATE TABLE IF NOT EXISTS thingsboard.rule_node ( |
|||
id uuid, |
|||
type text, |
|||
name text, |
|||
search_text text, |
|||
configuration text, |
|||
additional_info text, |
|||
PRIMARY KEY (id) |
|||
); |
|||
|
|||
@ -0,0 +1,35 @@ |
|||
-- |
|||
-- Copyright © 2016-2018 The Thingsboard Authors |
|||
-- |
|||
-- Licensed under the Apache License, Version 2.0 (the "License"); |
|||
-- you may not use this file except in compliance with the License. |
|||
-- You may obtain a copy of the License at |
|||
-- |
|||
-- http://www.apache.org/licenses/LICENSE-2.0 |
|||
-- |
|||
-- Unless required by applicable law or agreed to in writing, software |
|||
-- distributed under the License is distributed on an "AS IS" BASIS, |
|||
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|||
-- See the License for the specific language governing permissions and |
|||
-- limitations under the License. |
|||
-- |
|||
|
|||
CREATE TABLE IF NOT EXISTS rule_chain ( |
|||
id varchar(31) NOT NULL CONSTRAINT rule_chain_pkey PRIMARY KEY, |
|||
additional_info varchar, |
|||
configuration varchar(10000000), |
|||
name varchar(255), |
|||
first_rule_node_id varchar(31), |
|||
is_root boolean, |
|||
search_text varchar(255), |
|||
tenant_id varchar(31) |
|||
); |
|||
|
|||
CREATE TABLE IF NOT EXISTS rule_node ( |
|||
id varchar(31) NOT NULL CONSTRAINT rule_node_pkey PRIMARY KEY, |
|||
additional_info varchar, |
|||
configuration varchar(10000000), |
|||
type varchar(255), |
|||
name varchar(255), |
|||
search_text varchar(255) |
|||
); |
|||
@ -0,0 +1,37 @@ |
|||
/** |
|||
* Copyright © 2016-2018 The Thingsboard Authors |
|||
* |
|||
* Licensed under the Apache License, Version 2.0 (the "License"); |
|||
* you may not use this file except in compliance with the License. |
|||
* You may obtain a copy of the License at |
|||
* |
|||
* http://www.apache.org/licenses/LICENSE-2.0
|
|||
* |
|||
* Unless required by applicable law or agreed to in writing, software |
|||
* distributed under the License is distributed on an "AS IS" BASIS, |
|||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|||
* See the License for the specific language governing permissions and |
|||
* limitations under the License. |
|||
*/ |
|||
package org.thingsboard.server.common.data.id; |
|||
|
|||
import com.fasterxml.jackson.annotation.JsonCreator; |
|||
import com.fasterxml.jackson.annotation.JsonIgnore; |
|||
import com.fasterxml.jackson.annotation.JsonProperty; |
|||
import org.thingsboard.server.common.data.EntityType; |
|||
|
|||
import java.util.UUID; |
|||
|
|||
public class RuleChainId extends UUIDBased implements EntityId { |
|||
|
|||
@JsonCreator |
|||
public RuleChainId(@JsonProperty("id") UUID id) { |
|||
super(id); |
|||
} |
|||
|
|||
@JsonIgnore |
|||
@Override |
|||
public EntityType getEntityType() { |
|||
return EntityType.RULE_CHAIN; |
|||
} |
|||
} |
|||
@ -0,0 +1,37 @@ |
|||
/** |
|||
* Copyright © 2016-2018 The Thingsboard Authors |
|||
* |
|||
* Licensed under the Apache License, Version 2.0 (the "License"); |
|||
* you may not use this file except in compliance with the License. |
|||
* You may obtain a copy of the License at |
|||
* |
|||
* http://www.apache.org/licenses/LICENSE-2.0
|
|||
* |
|||
* Unless required by applicable law or agreed to in writing, software |
|||
* distributed under the License is distributed on an "AS IS" BASIS, |
|||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|||
* See the License for the specific language governing permissions and |
|||
* limitations under the License. |
|||
*/ |
|||
package org.thingsboard.server.common.data.id; |
|||
|
|||
import com.fasterxml.jackson.annotation.JsonCreator; |
|||
import com.fasterxml.jackson.annotation.JsonIgnore; |
|||
import com.fasterxml.jackson.annotation.JsonProperty; |
|||
import org.thingsboard.server.common.data.EntityType; |
|||
|
|||
import java.util.UUID; |
|||
|
|||
public class RuleNodeId extends UUIDBased implements EntityId { |
|||
|
|||
@JsonCreator |
|||
public RuleNodeId(@JsonProperty("id") UUID id) { |
|||
super(id); |
|||
} |
|||
|
|||
@JsonIgnore |
|||
@Override |
|||
public EntityType getEntityType() { |
|||
return EntityType.RULE_NODE; |
|||
} |
|||
} |
|||
@ -0,0 +1,79 @@ |
|||
/** |
|||
* Copyright © 2016-2018 The Thingsboard Authors |
|||
* |
|||
* Licensed under the Apache License, Version 2.0 (the "License"); |
|||
* you may not use this file except in compliance with the License. |
|||
* You may obtain a copy of the License at |
|||
* |
|||
* http://www.apache.org/licenses/LICENSE-2.0
|
|||
* |
|||
* Unless required by applicable law or agreed to in writing, software |
|||
* distributed under the License is distributed on an "AS IS" BASIS, |
|||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|||
* See the License for the specific language governing permissions and |
|||
* limitations under the License. |
|||
*/ |
|||
package org.thingsboard.server.common.data.rule; |
|||
|
|||
import com.fasterxml.jackson.annotation.JsonIgnore; |
|||
import com.fasterxml.jackson.databind.JsonNode; |
|||
import lombok.Data; |
|||
import lombok.EqualsAndHashCode; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.thingsboard.server.common.data.HasName; |
|||
import org.thingsboard.server.common.data.SearchTextBasedWithAdditionalInfo; |
|||
import org.thingsboard.server.common.data.id.RuleChainId; |
|||
import org.thingsboard.server.common.data.id.RuleNodeId; |
|||
import org.thingsboard.server.common.data.id.TenantId; |
|||
|
|||
@Data |
|||
@EqualsAndHashCode(callSuper = true) |
|||
@Slf4j |
|||
public class RuleChain extends SearchTextBasedWithAdditionalInfo<RuleChainId> implements HasName { |
|||
|
|||
private static final long serialVersionUID = -5656679015121935465L; |
|||
|
|||
private TenantId tenantId; |
|||
private String name; |
|||
private RuleNodeId firstRuleNodeId; |
|||
private boolean isRoot; |
|||
private transient JsonNode configuration; |
|||
@JsonIgnore |
|||
private byte[] configurationBytes; |
|||
|
|||
public RuleChain() { |
|||
super(); |
|||
} |
|||
|
|||
public RuleChain(RuleChainId id) { |
|||
super(id); |
|||
} |
|||
|
|||
public RuleChain(RuleChain ruleChain) { |
|||
super(ruleChain); |
|||
this.tenantId = ruleChain.getTenantId(); |
|||
this.name = ruleChain.getName(); |
|||
this.firstRuleNodeId = ruleChain.getFirstRuleNodeId(); |
|||
this.isRoot = ruleChain.isRoot(); |
|||
this.setConfiguration(ruleChain.getConfiguration()); |
|||
} |
|||
|
|||
@Override |
|||
public String getSearchText() { |
|||
return getName(); |
|||
} |
|||
|
|||
@Override |
|||
public String getName() { |
|||
return name; |
|||
} |
|||
|
|||
public JsonNode getConfiguration() { |
|||
return SearchTextBasedWithAdditionalInfo.getJson(() -> configuration, () -> configurationBytes); |
|||
} |
|||
|
|||
public void setConfiguration(JsonNode data) { |
|||
setJson(data, json -> this.configuration = json, bytes -> this.configurationBytes = bytes); |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,74 @@ |
|||
/** |
|||
* Copyright © 2016-2018 The Thingsboard Authors |
|||
* |
|||
* Licensed under the Apache License, Version 2.0 (the "License"); |
|||
* you may not use this file except in compliance with the License. |
|||
* You may obtain a copy of the License at |
|||
* |
|||
* http://www.apache.org/licenses/LICENSE-2.0
|
|||
* |
|||
* Unless required by applicable law or agreed to in writing, software |
|||
* distributed under the License is distributed on an "AS IS" BASIS, |
|||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|||
* See the License for the specific language governing permissions and |
|||
* limitations under the License. |
|||
*/ |
|||
package org.thingsboard.server.common.data.rule; |
|||
|
|||
import com.fasterxml.jackson.annotation.JsonIgnore; |
|||
import com.fasterxml.jackson.databind.JsonNode; |
|||
import lombok.Data; |
|||
import lombok.EqualsAndHashCode; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.thingsboard.server.common.data.HasName; |
|||
import org.thingsboard.server.common.data.SearchTextBasedWithAdditionalInfo; |
|||
import org.thingsboard.server.common.data.id.RuleNodeId; |
|||
import org.thingsboard.server.common.data.id.TenantId; |
|||
|
|||
@Data |
|||
@EqualsAndHashCode(callSuper = true) |
|||
@Slf4j |
|||
public class RuleNode extends SearchTextBasedWithAdditionalInfo<RuleNodeId> implements HasName { |
|||
|
|||
private static final long serialVersionUID = -5656679015121235465L; |
|||
|
|||
private String type; |
|||
private String name; |
|||
private transient JsonNode configuration; |
|||
@JsonIgnore |
|||
private byte[] configurationBytes; |
|||
|
|||
public RuleNode() { |
|||
super(); |
|||
} |
|||
|
|||
public RuleNode(RuleNodeId id) { |
|||
super(id); |
|||
} |
|||
|
|||
public RuleNode(RuleNode ruleNode) { |
|||
super(ruleNode); |
|||
this.type = ruleNode.getType(); |
|||
this.name = ruleNode.getName(); |
|||
this.setConfiguration(ruleNode.getConfiguration()); |
|||
} |
|||
|
|||
@Override |
|||
public String getSearchText() { |
|||
return getName(); |
|||
} |
|||
|
|||
@Override |
|||
public String getName() { |
|||
return name; |
|||
} |
|||
|
|||
public JsonNode getConfiguration() { |
|||
return SearchTextBasedWithAdditionalInfo.getJson(() -> configuration, () -> configurationBytes); |
|||
} |
|||
|
|||
public void setConfiguration(JsonNode data) { |
|||
setJson(data, json -> this.configuration = json, bytes -> this.configurationBytes = bytes); |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,165 @@ |
|||
/** |
|||
* Copyright © 2016-2018 The Thingsboard Authors |
|||
* |
|||
* Licensed under the Apache License, Version 2.0 (the "License"); |
|||
* you may not use this file except in compliance with the License. |
|||
* You may obtain a copy of the License at |
|||
* |
|||
* http://www.apache.org/licenses/LICENSE-2.0
|
|||
* |
|||
* Unless required by applicable law or agreed to in writing, software |
|||
* distributed under the License is distributed on an "AS IS" BASIS, |
|||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|||
* See the License for the specific language governing permissions and |
|||
* limitations under the License. |
|||
*/ |
|||
package org.thingsboard.server.dao.model.nosql; |
|||
|
|||
import com.datastax.driver.core.utils.UUIDs; |
|||
import com.datastax.driver.mapping.annotations.ClusteringColumn; |
|||
import com.datastax.driver.mapping.annotations.Column; |
|||
import com.datastax.driver.mapping.annotations.PartitionKey; |
|||
import com.datastax.driver.mapping.annotations.Table; |
|||
import com.fasterxml.jackson.databind.JsonNode; |
|||
import lombok.EqualsAndHashCode; |
|||
import lombok.ToString; |
|||
import org.thingsboard.server.common.data.id.RuleChainId; |
|||
import org.thingsboard.server.common.data.id.RuleNodeId; |
|||
import org.thingsboard.server.common.data.id.TenantId; |
|||
import org.thingsboard.server.common.data.rule.RuleChain; |
|||
import org.thingsboard.server.dao.DaoUtil; |
|||
import org.thingsboard.server.dao.model.SearchTextEntity; |
|||
import org.thingsboard.server.dao.model.type.JsonCodec; |
|||
|
|||
import java.util.UUID; |
|||
|
|||
import static org.thingsboard.server.dao.model.ModelConstants.*; |
|||
|
|||
@Table(name = RULE_CHAIN_COLUMN_FAMILY_NAME) |
|||
@EqualsAndHashCode |
|||
@ToString |
|||
public class RuleChainEntity implements SearchTextEntity<RuleChain> { |
|||
|
|||
@PartitionKey |
|||
@Column(name = ID_PROPERTY) |
|||
private UUID id; |
|||
@ClusteringColumn |
|||
@Column(name = RULE_CHAIN_TENANT_ID_PROPERTY) |
|||
private UUID tenantId; |
|||
@Column(name = RULE_CHAIN_NAME_PROPERTY) |
|||
private String name; |
|||
@Column(name = SEARCH_TEXT_PROPERTY) |
|||
private String searchText; |
|||
@Column(name = RULE_CHAIN_FIRST_RULE_NODE_ID_PROPERTY) |
|||
private UUID firstRuleNodeId; |
|||
@Column(name = RULE_CHAIN_IS_ROOT_PROPERTY) |
|||
private boolean isRoot; |
|||
@Column(name = RULE_CHAIN_CONFIGURATION_PROPERTY, codec = JsonCodec.class) |
|||
private JsonNode configuration; |
|||
@Column(name = ADDITIONAL_INFO_PROPERTY, codec = JsonCodec.class) |
|||
private JsonNode additionalInfo; |
|||
|
|||
public RuleChainEntity() { |
|||
} |
|||
|
|||
public RuleChainEntity(RuleChain ruleChain) { |
|||
if (ruleChain.getId() != null) { |
|||
this.id = ruleChain.getUuidId(); |
|||
} |
|||
this.tenantId = DaoUtil.getId(ruleChain.getTenantId()); |
|||
this.name = ruleChain.getName(); |
|||
this.searchText = ruleChain.getName(); |
|||
this.firstRuleNodeId = DaoUtil.getId(ruleChain.getFirstRuleNodeId()); |
|||
this.isRoot = ruleChain.isRoot(); |
|||
this.configuration = ruleChain.getConfiguration(); |
|||
this.additionalInfo = ruleChain.getAdditionalInfo(); |
|||
} |
|||
|
|||
@Override |
|||
public String getSearchTextSource() { |
|||
return getSearchText(); |
|||
} |
|||
|
|||
@Override |
|||
public void setSearchText(String searchText) { |
|||
this.searchText = searchText; |
|||
} |
|||
|
|||
@Override |
|||
public UUID getId() { |
|||
return id; |
|||
} |
|||
|
|||
@Override |
|||
public void setId(UUID id) { |
|||
this.id = id; |
|||
} |
|||
|
|||
public UUID getTenantId() { |
|||
return tenantId; |
|||
} |
|||
|
|||
public void setTenantId(UUID tenantId) { |
|||
this.tenantId = tenantId; |
|||
} |
|||
|
|||
public String getName() { |
|||
return name; |
|||
} |
|||
|
|||
public void setName(String name) { |
|||
this.name = name; |
|||
} |
|||
|
|||
public UUID getFirstRuleNodeId() { |
|||
return firstRuleNodeId; |
|||
} |
|||
|
|||
public void setFirstRuleNodeId(UUID firstRuleNodeId) { |
|||
this.firstRuleNodeId = firstRuleNodeId; |
|||
} |
|||
|
|||
public boolean isRoot() { |
|||
return isRoot; |
|||
} |
|||
|
|||
public void setRoot(boolean isRoot) { |
|||
this.isRoot = isRoot; |
|||
} |
|||
|
|||
public String getSearchText() { |
|||
return searchText; |
|||
} |
|||
|
|||
public JsonNode getConfiguration() { |
|||
return configuration; |
|||
} |
|||
|
|||
public void setConfiguration(JsonNode configuration) { |
|||
this.configuration = configuration; |
|||
} |
|||
|
|||
public JsonNode getAdditionalInfo() { |
|||
return additionalInfo; |
|||
} |
|||
|
|||
public void setAdditionalInfo(JsonNode additionalInfo) { |
|||
this.additionalInfo = additionalInfo; |
|||
} |
|||
|
|||
@Override |
|||
public RuleChain toData() { |
|||
RuleChain ruleChain = new RuleChain(new RuleChainId(id)); |
|||
ruleChain.setCreatedTime(UUIDs.unixTimestamp(id)); |
|||
ruleChain.setTenantId(new TenantId(tenantId)); |
|||
ruleChain.setName(name); |
|||
if (this.firstRuleNodeId != null) { |
|||
ruleChain.setFirstRuleNodeId(new RuleNodeId(this.firstRuleNodeId)); |
|||
} |
|||
ruleChain.setRoot(this.isRoot); |
|||
ruleChain.setConfiguration(this.configuration); |
|||
ruleChain.setAdditionalInfo(this.additionalInfo); |
|||
return ruleChain; |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,134 @@ |
|||
/** |
|||
* Copyright © 2016-2018 The Thingsboard Authors |
|||
* |
|||
* Licensed under the Apache License, Version 2.0 (the "License"); |
|||
* you may not use this file except in compliance with the License. |
|||
* You may obtain a copy of the License at |
|||
* |
|||
* http://www.apache.org/licenses/LICENSE-2.0
|
|||
* |
|||
* Unless required by applicable law or agreed to in writing, software |
|||
* distributed under the License is distributed on an "AS IS" BASIS, |
|||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|||
* See the License for the specific language governing permissions and |
|||
* limitations under the License. |
|||
*/ |
|||
package org.thingsboard.server.dao.model.nosql; |
|||
|
|||
import com.datastax.driver.core.utils.UUIDs; |
|||
import com.datastax.driver.mapping.annotations.Column; |
|||
import com.datastax.driver.mapping.annotations.PartitionKey; |
|||
import com.datastax.driver.mapping.annotations.Table; |
|||
import com.fasterxml.jackson.databind.JsonNode; |
|||
import lombok.EqualsAndHashCode; |
|||
import lombok.ToString; |
|||
import org.thingsboard.server.common.data.id.RuleNodeId; |
|||
import org.thingsboard.server.common.data.rule.RuleNode; |
|||
import org.thingsboard.server.dao.model.SearchTextEntity; |
|||
import org.thingsboard.server.dao.model.type.JsonCodec; |
|||
|
|||
import java.util.UUID; |
|||
|
|||
import static org.thingsboard.server.dao.model.ModelConstants.*; |
|||
|
|||
@Table(name = RULE_NODE_COLUMN_FAMILY_NAME) |
|||
@EqualsAndHashCode |
|||
@ToString |
|||
public class RuleNodeEntity implements SearchTextEntity<RuleNode> { |
|||
|
|||
@PartitionKey |
|||
@Column(name = ID_PROPERTY) |
|||
private UUID id; |
|||
@Column(name = RULE_NODE_TYPE_PROPERTY) |
|||
private String type; |
|||
@Column(name = RULE_NODE_NAME_PROPERTY) |
|||
private String name; |
|||
@Column(name = SEARCH_TEXT_PROPERTY) |
|||
private String searchText; |
|||
@Column(name = RULE_NODE_CONFIGURATION_PROPERTY, codec = JsonCodec.class) |
|||
private JsonNode configuration; |
|||
@Column(name = ADDITIONAL_INFO_PROPERTY, codec = JsonCodec.class) |
|||
private JsonNode additionalInfo; |
|||
|
|||
public RuleNodeEntity() { |
|||
} |
|||
|
|||
public RuleNodeEntity(RuleNode ruleNode) { |
|||
if (ruleNode.getId() != null) { |
|||
this.id = ruleNode.getUuidId(); |
|||
} |
|||
this.type = ruleNode.getType(); |
|||
this.name = ruleNode.getName(); |
|||
this.searchText = ruleNode.getName(); |
|||
this.configuration = ruleNode.getConfiguration(); |
|||
this.additionalInfo = ruleNode.getAdditionalInfo(); |
|||
} |
|||
|
|||
@Override |
|||
public String getSearchTextSource() { |
|||
return getSearchText(); |
|||
} |
|||
|
|||
@Override |
|||
public void setSearchText(String searchText) { |
|||
this.searchText = searchText; |
|||
} |
|||
|
|||
@Override |
|||
public UUID getId() { |
|||
return id; |
|||
} |
|||
|
|||
@Override |
|||
public void setId(UUID id) { |
|||
this.id = id; |
|||
} |
|||
|
|||
public String getType() { |
|||
return type; |
|||
} |
|||
|
|||
public void setType(String type) { |
|||
this.type = type; |
|||
} |
|||
|
|||
public String getName() { |
|||
return name; |
|||
} |
|||
|
|||
public void setName(String name) { |
|||
this.name = name; |
|||
} |
|||
|
|||
public String getSearchText() { |
|||
return searchText; |
|||
} |
|||
|
|||
public JsonNode getConfiguration() { |
|||
return configuration; |
|||
} |
|||
|
|||
public void setConfiguration(JsonNode configuration) { |
|||
this.configuration = configuration; |
|||
} |
|||
|
|||
public JsonNode getAdditionalInfo() { |
|||
return additionalInfo; |
|||
} |
|||
|
|||
public void setAdditionalInfo(JsonNode additionalInfo) { |
|||
this.additionalInfo = additionalInfo; |
|||
} |
|||
|
|||
@Override |
|||
public RuleNode toData() { |
|||
RuleNode ruleNode = new RuleNode(new RuleNodeId(id)); |
|||
ruleNode.setCreatedTime(UUIDs.unixTimestamp(id)); |
|||
ruleNode.setType(this.type); |
|||
ruleNode.setName(this.name); |
|||
ruleNode.setConfiguration(this.configuration); |
|||
ruleNode.setAdditionalInfo(this.additionalInfo); |
|||
return ruleNode; |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,111 @@ |
|||
/** |
|||
* Copyright © 2016-2018 The Thingsboard Authors |
|||
* |
|||
* Licensed under the Apache License, Version 2.0 (the "License"); |
|||
* you may not use this file except in compliance with the License. |
|||
* You may obtain a copy of the License at |
|||
* |
|||
* http://www.apache.org/licenses/LICENSE-2.0
|
|||
* |
|||
* Unless required by applicable law or agreed to in writing, software |
|||
* distributed under the License is distributed on an "AS IS" BASIS, |
|||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|||
* See the License for the specific language governing permissions and |
|||
* limitations under the License. |
|||
*/ |
|||
package org.thingsboard.server.dao.model.sql; |
|||
|
|||
import com.datastax.driver.core.utils.UUIDs; |
|||
import com.fasterxml.jackson.databind.JsonNode; |
|||
import lombok.Data; |
|||
import lombok.EqualsAndHashCode; |
|||
import org.hibernate.annotations.Type; |
|||
import org.hibernate.annotations.TypeDef; |
|||
import org.thingsboard.server.common.data.UUIDConverter; |
|||
import org.thingsboard.server.common.data.id.RuleChainId; |
|||
import org.thingsboard.server.common.data.id.RuleNodeId; |
|||
import org.thingsboard.server.common.data.id.TenantId; |
|||
import org.thingsboard.server.common.data.rule.RuleChain; |
|||
import org.thingsboard.server.dao.DaoUtil; |
|||
import org.thingsboard.server.dao.model.BaseSqlEntity; |
|||
import org.thingsboard.server.dao.model.ModelConstants; |
|||
import org.thingsboard.server.dao.model.SearchTextEntity; |
|||
import org.thingsboard.server.dao.util.mapping.JsonStringType; |
|||
|
|||
import javax.persistence.Column; |
|||
import javax.persistence.Entity; |
|||
import javax.persistence.Table; |
|||
|
|||
@Data |
|||
@EqualsAndHashCode(callSuper = true) |
|||
@Entity |
|||
@TypeDef(name = "json", typeClass = JsonStringType.class) |
|||
@Table(name = ModelConstants.RULE_CHAIN_COLUMN_FAMILY_NAME) |
|||
public class RuleChainEntity extends BaseSqlEntity<RuleChain> implements SearchTextEntity<RuleChain> { |
|||
|
|||
@Column(name = ModelConstants.RULE_CHAIN_TENANT_ID_PROPERTY) |
|||
private String tenantId; |
|||
|
|||
@Column(name = ModelConstants.RULE_CHAIN_NAME_PROPERTY) |
|||
private String name; |
|||
|
|||
@Column(name = ModelConstants.SEARCH_TEXT_PROPERTY) |
|||
private String searchText; |
|||
|
|||
@Column(name = ModelConstants.RULE_CHAIN_FIRST_RULE_NODE_ID_PROPERTY) |
|||
private String firstRuleNodeId; |
|||
|
|||
@Column(name = ModelConstants.RULE_CHAIN_IS_ROOT_PROPERTY) |
|||
private boolean isRoot; |
|||
|
|||
@Type(type = "json") |
|||
@Column(name = ModelConstants.RULE_CHAIN_CONFIGURATION_PROPERTY) |
|||
private JsonNode configuration; |
|||
|
|||
@Type(type = "json") |
|||
@Column(name = ModelConstants.ADDITIONAL_INFO_PROPERTY) |
|||
private JsonNode additionalInfo; |
|||
|
|||
public RuleChainEntity() { |
|||
} |
|||
|
|||
public RuleChainEntity(RuleChain ruleChain) { |
|||
if (ruleChain.getId() != null) { |
|||
this.setId(ruleChain.getUuidId()); |
|||
} |
|||
this.tenantId = toString(DaoUtil.getId(ruleChain.getTenantId())); |
|||
this.name = ruleChain.getName(); |
|||
this.searchText = ruleChain.getName(); |
|||
if (ruleChain.getFirstRuleNodeId() != null) { |
|||
this.firstRuleNodeId = UUIDConverter.fromTimeUUID(ruleChain.getFirstRuleNodeId().getId()); |
|||
} |
|||
this.isRoot = ruleChain.isRoot(); |
|||
this.configuration = ruleChain.getConfiguration(); |
|||
this.additionalInfo = ruleChain.getAdditionalInfo(); |
|||
} |
|||
|
|||
@Override |
|||
public String getSearchTextSource() { |
|||
return searchText; |
|||
} |
|||
|
|||
@Override |
|||
public void setSearchText(String searchText) { |
|||
this.searchText = searchText; |
|||
} |
|||
|
|||
@Override |
|||
public RuleChain toData() { |
|||
RuleChain ruleChain = new RuleChain(new RuleChainId(getId())); |
|||
ruleChain.setCreatedTime(UUIDs.unixTimestamp(getId())); |
|||
ruleChain.setTenantId(new TenantId(toUUID(tenantId))); |
|||
ruleChain.setName(name); |
|||
if (firstRuleNodeId != null) { |
|||
ruleChain.setFirstRuleNodeId(new RuleNodeId(UUIDConverter.fromString(firstRuleNodeId))); |
|||
} |
|||
ruleChain.setRoot(isRoot); |
|||
ruleChain.setConfiguration(configuration); |
|||
ruleChain.setAdditionalInfo(additionalInfo); |
|||
return ruleChain; |
|||
} |
|||
} |
|||
@ -0,0 +1,93 @@ |
|||
/** |
|||
* Copyright © 2016-2018 The Thingsboard Authors |
|||
* |
|||
* Licensed under the Apache License, Version 2.0 (the "License"); |
|||
* you may not use this file except in compliance with the License. |
|||
* You may obtain a copy of the License at |
|||
* |
|||
* http://www.apache.org/licenses/LICENSE-2.0
|
|||
* |
|||
* Unless required by applicable law or agreed to in writing, software |
|||
* distributed under the License is distributed on an "AS IS" BASIS, |
|||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|||
* See the License for the specific language governing permissions and |
|||
* limitations under the License. |
|||
*/ |
|||
package org.thingsboard.server.dao.model.sql; |
|||
|
|||
import com.datastax.driver.core.utils.UUIDs; |
|||
import com.fasterxml.jackson.databind.JsonNode; |
|||
import lombok.Data; |
|||
import lombok.EqualsAndHashCode; |
|||
import org.hibernate.annotations.Type; |
|||
import org.hibernate.annotations.TypeDef; |
|||
import org.thingsboard.server.common.data.id.RuleNodeId; |
|||
import org.thingsboard.server.common.data.rule.RuleNode; |
|||
import org.thingsboard.server.dao.model.BaseSqlEntity; |
|||
import org.thingsboard.server.dao.model.ModelConstants; |
|||
import org.thingsboard.server.dao.model.SearchTextEntity; |
|||
import org.thingsboard.server.dao.util.mapping.JsonStringType; |
|||
|
|||
import javax.persistence.Column; |
|||
import javax.persistence.Entity; |
|||
import javax.persistence.Table; |
|||
|
|||
@Data |
|||
@EqualsAndHashCode(callSuper = true) |
|||
@Entity |
|||
@TypeDef(name = "json", typeClass = JsonStringType.class) |
|||
@Table(name = ModelConstants.RULE_NODE_COLUMN_FAMILY_NAME) |
|||
public class RuleNodeEntity extends BaseSqlEntity<RuleNode> implements SearchTextEntity<RuleNode> { |
|||
|
|||
@Column(name = ModelConstants.RULE_NODE_TYPE_PROPERTY) |
|||
private String type; |
|||
|
|||
@Column(name = ModelConstants.RULE_NODE_NAME_PROPERTY) |
|||
private String name; |
|||
|
|||
@Column(name = ModelConstants.SEARCH_TEXT_PROPERTY) |
|||
private String searchText; |
|||
|
|||
@Type(type = "json") |
|||
@Column(name = ModelConstants.RULE_NODE_CONFIGURATION_PROPERTY) |
|||
private JsonNode configuration; |
|||
|
|||
@Type(type = "json") |
|||
@Column(name = ModelConstants.ADDITIONAL_INFO_PROPERTY) |
|||
private JsonNode additionalInfo; |
|||
|
|||
public RuleNodeEntity() { |
|||
} |
|||
|
|||
public RuleNodeEntity(RuleNode ruleNode) { |
|||
if (ruleNode.getId() != null) { |
|||
this.setId(ruleNode.getUuidId()); |
|||
} |
|||
this.type = ruleNode.getType(); |
|||
this.name = ruleNode.getName(); |
|||
this.searchText = ruleNode.getName(); |
|||
this.configuration = ruleNode.getConfiguration(); |
|||
this.additionalInfo = ruleNode.getAdditionalInfo(); |
|||
} |
|||
|
|||
@Override |
|||
public String getSearchTextSource() { |
|||
return searchText; |
|||
} |
|||
|
|||
@Override |
|||
public void setSearchText(String searchText) { |
|||
this.searchText = searchText; |
|||
} |
|||
|
|||
@Override |
|||
public RuleNode toData() { |
|||
RuleNode ruleNode = new RuleNode(new RuleNodeId(getId())); |
|||
ruleNode.setCreatedTime(UUIDs.unixTimestamp(getId())); |
|||
ruleNode.setType(type); |
|||
ruleNode.setName(name); |
|||
ruleNode.setConfiguration(configuration); |
|||
ruleNode.setAdditionalInfo(additionalInfo); |
|||
return ruleNode; |
|||
} |
|||
} |
|||
@ -0,0 +1,60 @@ |
|||
/** |
|||
* Copyright © 2016-2018 The Thingsboard Authors |
|||
* |
|||
* Licensed under the Apache License, Version 2.0 (the "License"); |
|||
* you may not use this file except in compliance with the License. |
|||
* You may obtain a copy of the License at |
|||
* |
|||
* http://www.apache.org/licenses/LICENSE-2.0
|
|||
* |
|||
* Unless required by applicable law or agreed to in writing, software |
|||
* distributed under the License is distributed on an "AS IS" BASIS, |
|||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|||
* See the License for the specific language governing permissions and |
|||
* limitations under the License. |
|||
*/ |
|||
package org.thingsboard.server.dao.rule; |
|||
|
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.springframework.stereotype.Component; |
|||
import org.thingsboard.server.common.data.page.TextPageLink; |
|||
import org.thingsboard.server.common.data.rule.RuleChain; |
|||
import org.thingsboard.server.dao.DaoUtil; |
|||
import org.thingsboard.server.dao.model.nosql.RuleChainEntity; |
|||
import org.thingsboard.server.dao.nosql.CassandraAbstractSearchTextDao; |
|||
import org.thingsboard.server.dao.util.NoSqlDao; |
|||
|
|||
import java.util.Collections; |
|||
import java.util.List; |
|||
import java.util.UUID; |
|||
|
|||
import static com.datastax.driver.core.querybuilder.QueryBuilder.eq; |
|||
import static org.thingsboard.server.dao.model.ModelConstants.*; |
|||
|
|||
@Component |
|||
@Slf4j |
|||
@NoSqlDao |
|||
public class CassandraRuleChainDao extends CassandraAbstractSearchTextDao<RuleChainEntity, RuleChain> implements RuleChainDao { |
|||
|
|||
@Override |
|||
protected Class<RuleChainEntity> getColumnFamilyClass() { |
|||
return RuleChainEntity.class; |
|||
} |
|||
|
|||
@Override |
|||
protected String getColumnFamilyName() { |
|||
return RULE_CHAIN_COLUMN_FAMILY_NAME; |
|||
} |
|||
|
|||
@Override |
|||
public List<RuleChain> findRuleChainsByTenantId(UUID tenantId, TextPageLink pageLink) { |
|||
log.debug("Try to find rule chains by tenantId [{}] and pageLink [{}]", tenantId, pageLink); |
|||
List<RuleChainEntity> ruleChainEntities = findPageWithTextSearch(RULE_CHAIN_BY_TENANT_AND_SEARCH_TEXT_COLUMN_FAMILY_NAME, |
|||
Collections.singletonList(eq(RULE_CHAIN_TENANT_ID_PROPERTY, tenantId)), |
|||
pageLink); |
|||
|
|||
log.trace("Found rule chains [{}] by tenantId [{}] and pageLink [{}]", ruleChainEntities, tenantId, pageLink); |
|||
return DaoUtil.convertDataList(ruleChainEntities); |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,42 @@ |
|||
/** |
|||
* Copyright © 2016-2018 The Thingsboard Authors |
|||
* |
|||
* Licensed under the Apache License, Version 2.0 (the "License"); |
|||
* you may not use this file except in compliance with the License. |
|||
* You may obtain a copy of the License at |
|||
* |
|||
* http://www.apache.org/licenses/LICENSE-2.0
|
|||
* |
|||
* Unless required by applicable law or agreed to in writing, software |
|||
* distributed under the License is distributed on an "AS IS" BASIS, |
|||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|||
* See the License for the specific language governing permissions and |
|||
* limitations under the License. |
|||
*/ |
|||
package org.thingsboard.server.dao.rule; |
|||
|
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.springframework.stereotype.Component; |
|||
import org.thingsboard.server.common.data.rule.RuleNode; |
|||
import org.thingsboard.server.dao.model.nosql.RuleNodeEntity; |
|||
import org.thingsboard.server.dao.nosql.CassandraAbstractSearchTextDao; |
|||
import org.thingsboard.server.dao.util.NoSqlDao; |
|||
|
|||
import static org.thingsboard.server.dao.model.ModelConstants.RULE_NODE_COLUMN_FAMILY_NAME; |
|||
|
|||
@Component |
|||
@Slf4j |
|||
@NoSqlDao |
|||
public class CassandraRuleNodeDao extends CassandraAbstractSearchTextDao<RuleNodeEntity, RuleNode> implements RuleNodeDao { |
|||
|
|||
@Override |
|||
protected Class<RuleNodeEntity> getColumnFamilyClass() { |
|||
return RuleNodeEntity.class; |
|||
} |
|||
|
|||
@Override |
|||
protected String getColumnFamilyName() { |
|||
return RULE_NODE_COLUMN_FAMILY_NAME; |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,40 @@ |
|||
/** |
|||
* Copyright © 2016-2018 The Thingsboard Authors |
|||
* |
|||
* Licensed under the Apache License, Version 2.0 (the "License"); |
|||
* you may not use this file except in compliance with the License. |
|||
* You may obtain a copy of the License at |
|||
* |
|||
* http://www.apache.org/licenses/LICENSE-2.0
|
|||
* |
|||
* Unless required by applicable law or agreed to in writing, software |
|||
* distributed under the License is distributed on an "AS IS" BASIS, |
|||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|||
* See the License for the specific language governing permissions and |
|||
* limitations under the License. |
|||
*/ |
|||
|
|||
package org.thingsboard.server.dao.rule; |
|||
|
|||
import org.thingsboard.server.common.data.page.TextPageLink; |
|||
import org.thingsboard.server.common.data.rule.RuleChain; |
|||
import org.thingsboard.server.dao.Dao; |
|||
|
|||
import java.util.List; |
|||
import java.util.UUID; |
|||
|
|||
/** |
|||
* Created by igor on 3/12/18. |
|||
*/ |
|||
public interface RuleChainDao extends Dao<RuleChain> { |
|||
|
|||
/** |
|||
* Find rule chains by tenantId and page link. |
|||
* |
|||
* @param tenantId the tenantId |
|||
* @param pageLink the page link |
|||
* @return the list of rule chain objects |
|||
*/ |
|||
List<RuleChain> findRuleChainsByTenantId(UUID tenantId, TextPageLink pageLink); |
|||
|
|||
} |
|||
@ -0,0 +1,28 @@ |
|||
/** |
|||
* Copyright © 2016-2018 The Thingsboard Authors |
|||
* |
|||
* Licensed under the Apache License, Version 2.0 (the "License"); |
|||
* you may not use this file except in compliance with the License. |
|||
* You may obtain a copy of the License at |
|||
* |
|||
* http://www.apache.org/licenses/LICENSE-2.0
|
|||
* |
|||
* Unless required by applicable law or agreed to in writing, software |
|||
* distributed under the License is distributed on an "AS IS" BASIS, |
|||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|||
* See the License for the specific language governing permissions and |
|||
* limitations under the License. |
|||
*/ |
|||
|
|||
package org.thingsboard.server.dao.rule; |
|||
|
|||
import org.thingsboard.server.common.data.rule.RuleChain; |
|||
|
|||
/** |
|||
* Created by igor on 3/12/18. |
|||
*/ |
|||
public interface RuleChainService { |
|||
|
|||
RuleChain saveRuleChain(RuleChain ruleChain); |
|||
|
|||
} |
|||
@ -0,0 +1,27 @@ |
|||
/** |
|||
* Copyright © 2016-2018 The Thingsboard Authors |
|||
* |
|||
* Licensed under the Apache License, Version 2.0 (the "License"); |
|||
* you may not use this file except in compliance with the License. |
|||
* You may obtain a copy of the License at |
|||
* |
|||
* http://www.apache.org/licenses/LICENSE-2.0
|
|||
* |
|||
* Unless required by applicable law or agreed to in writing, software |
|||
* distributed under the License is distributed on an "AS IS" BASIS, |
|||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|||
* See the License for the specific language governing permissions and |
|||
* limitations under the License. |
|||
*/ |
|||
|
|||
package org.thingsboard.server.dao.rule; |
|||
|
|||
import org.thingsboard.server.common.data.rule.RuleNode; |
|||
import org.thingsboard.server.dao.Dao; |
|||
|
|||
/** |
|||
* Created by igor on 3/12/18. |
|||
*/ |
|||
public interface RuleNodeDao extends Dao<RuleNode> { |
|||
|
|||
} |
|||
@ -0,0 +1,66 @@ |
|||
/** |
|||
* Copyright © 2016-2018 The Thingsboard Authors |
|||
* |
|||
* Licensed under the Apache License, Version 2.0 (the "License"); |
|||
* you may not use this file except in compliance with the License. |
|||
* You may obtain a copy of the License at |
|||
* |
|||
* http://www.apache.org/licenses/LICENSE-2.0
|
|||
* |
|||
* Unless required by applicable law or agreed to in writing, software |
|||
* distributed under the License is distributed on an "AS IS" BASIS, |
|||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|||
* See the License for the specific language governing permissions and |
|||
* limitations under the License. |
|||
*/ |
|||
package org.thingsboard.server.dao.sql.rule; |
|||
|
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.data.domain.PageRequest; |
|||
import org.springframework.data.repository.CrudRepository; |
|||
import org.springframework.stereotype.Component; |
|||
import org.thingsboard.server.common.data.UUIDConverter; |
|||
import org.thingsboard.server.common.data.page.TextPageLink; |
|||
import org.thingsboard.server.common.data.rule.RuleChain; |
|||
import org.thingsboard.server.dao.DaoUtil; |
|||
import org.thingsboard.server.dao.model.sql.RuleChainEntity; |
|||
import org.thingsboard.server.dao.rule.RuleChainDao; |
|||
import org.thingsboard.server.dao.sql.JpaAbstractSearchTextDao; |
|||
import org.thingsboard.server.dao.util.SqlDao; |
|||
|
|||
import java.util.List; |
|||
import java.util.Objects; |
|||
import java.util.UUID; |
|||
|
|||
import static org.thingsboard.server.dao.model.ModelConstants.NULL_UUID_STR; |
|||
|
|||
@Slf4j |
|||
@Component |
|||
@SqlDao |
|||
public class JpaRuleChainDao extends JpaAbstractSearchTextDao<RuleChainEntity, RuleChain> implements RuleChainDao { |
|||
|
|||
@Autowired |
|||
private RuleChainRepository ruleChainRepository; |
|||
|
|||
@Override |
|||
protected Class getEntityClass() { |
|||
return RuleChainEntity.class; |
|||
} |
|||
|
|||
@Override |
|||
protected CrudRepository getCrudRepository() { |
|||
return ruleChainRepository; |
|||
} |
|||
|
|||
@Override |
|||
public List<RuleChain> findRuleChainsByTenantId(UUID tenantId, TextPageLink pageLink) { |
|||
return DaoUtil.convertDataList(ruleChainRepository |
|||
.findByTenantId( |
|||
UUIDConverter.fromTimeUUID(tenantId), |
|||
Objects.toString(pageLink.getTextSearch(), ""), |
|||
pageLink.getIdOffset() == null ? NULL_UUID_STR : UUIDConverter.fromTimeUUID(pageLink.getIdOffset()), |
|||
new PageRequest(0, pageLink.getLimit()))); |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,46 @@ |
|||
/** |
|||
* Copyright © 2016-2018 The Thingsboard Authors |
|||
* |
|||
* Licensed under the Apache License, Version 2.0 (the "License"); |
|||
* you may not use this file except in compliance with the License. |
|||
* You may obtain a copy of the License at |
|||
* |
|||
* http://www.apache.org/licenses/LICENSE-2.0
|
|||
* |
|||
* Unless required by applicable law or agreed to in writing, software |
|||
* distributed under the License is distributed on an "AS IS" BASIS, |
|||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|||
* See the License for the specific language governing permissions and |
|||
* limitations under the License. |
|||
*/ |
|||
package org.thingsboard.server.dao.sql.rule; |
|||
|
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.data.repository.CrudRepository; |
|||
import org.springframework.stereotype.Component; |
|||
import org.thingsboard.server.common.data.rule.RuleNode; |
|||
import org.thingsboard.server.dao.model.sql.RuleNodeEntity; |
|||
import org.thingsboard.server.dao.rule.RuleNodeDao; |
|||
import org.thingsboard.server.dao.sql.JpaAbstractSearchTextDao; |
|||
import org.thingsboard.server.dao.util.SqlDao; |
|||
|
|||
@Slf4j |
|||
@Component |
|||
@SqlDao |
|||
public class JpaRuleNodeDao extends JpaAbstractSearchTextDao<RuleNodeEntity, RuleNode> implements RuleNodeDao { |
|||
|
|||
@Autowired |
|||
private RuleNodeRepository ruleNodeRepository; |
|||
|
|||
@Override |
|||
protected Class getEntityClass() { |
|||
return RuleNodeEntity.class; |
|||
} |
|||
|
|||
@Override |
|||
protected CrudRepository getCrudRepository() { |
|||
return ruleNodeRepository; |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,38 @@ |
|||
/** |
|||
* Copyright © 2016-2018 The Thingsboard Authors |
|||
* |
|||
* Licensed under the Apache License, Version 2.0 (the "License"); |
|||
* you may not use this file except in compliance with the License. |
|||
* You may obtain a copy of the License at |
|||
* |
|||
* http://www.apache.org/licenses/LICENSE-2.0
|
|||
* |
|||
* Unless required by applicable law or agreed to in writing, software |
|||
* distributed under the License is distributed on an "AS IS" BASIS, |
|||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|||
* See the License for the specific language governing permissions and |
|||
* limitations under the License. |
|||
*/ |
|||
package org.thingsboard.server.dao.sql.rule; |
|||
|
|||
import org.springframework.data.domain.Pageable; |
|||
import org.springframework.data.jpa.repository.Query; |
|||
import org.springframework.data.repository.CrudRepository; |
|||
import org.springframework.data.repository.query.Param; |
|||
import org.thingsboard.server.dao.model.sql.RuleChainEntity; |
|||
import org.thingsboard.server.dao.util.SqlDao; |
|||
|
|||
import java.util.List; |
|||
|
|||
@SqlDao |
|||
public interface RuleChainRepository extends CrudRepository<RuleChainEntity, String> { |
|||
|
|||
@Query("SELECT rc FROM RuleChainEntity rc WHERE rc.tenantId = :tenantId " + |
|||
"AND LOWER(rc.searchText) LIKE LOWER(CONCAT(:searchText, '%')) " + |
|||
"AND rc.id > :idOffset ORDER BY rc.id") |
|||
List<RuleChainEntity> findByTenantId(@Param("tenantId") String tenantId, |
|||
@Param("searchText") String searchText, |
|||
@Param("idOffset") String idOffset, |
|||
Pageable pageable); |
|||
|
|||
} |
|||
@ -0,0 +1,25 @@ |
|||
/** |
|||
* Copyright © 2016-2018 The Thingsboard Authors |
|||
* |
|||
* Licensed under the Apache License, Version 2.0 (the "License"); |
|||
* you may not use this file except in compliance with the License. |
|||
* You may obtain a copy of the License at |
|||
* |
|||
* http://www.apache.org/licenses/LICENSE-2.0
|
|||
* |
|||
* Unless required by applicable law or agreed to in writing, software |
|||
* distributed under the License is distributed on an "AS IS" BASIS, |
|||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|||
* See the License for the specific language governing permissions and |
|||
* limitations under the License. |
|||
*/ |
|||
package org.thingsboard.server.dao.sql.rule; |
|||
|
|||
import org.springframework.data.repository.CrudRepository; |
|||
import org.thingsboard.server.dao.model.sql.RuleNodeEntity; |
|||
import org.thingsboard.server.dao.util.SqlDao; |
|||
|
|||
@SqlDao |
|||
public interface RuleNodeRepository extends CrudRepository<RuleNodeEntity, String> { |
|||
|
|||
} |
|||
Loading…
Reference in new issue