Showing
21 changed files
with
837 additions
and
235 deletions
... | ... | @@ -33,7 +33,7 @@ public class ModelConstants { |
33 | 33 | */ |
34 | 34 | public static final String ID_PROPERTY = "id"; |
35 | 35 | public static final String USER_ID_PROPERTY = "user_id"; |
36 | - public static final String TENTANT_ID_PROPERTY = "tenant_id"; | |
36 | + public static final String TENANT_ID_PROPERTY = "tenant_id"; | |
37 | 37 | public static final String CUSTOMER_ID_PROPERTY = "customer_id"; |
38 | 38 | public static final String DEVICE_ID_PROPERTY = "device_id"; |
39 | 39 | public static final String TITLE_PROPERTY = "title"; |
... | ... | @@ -45,7 +45,7 @@ public class ModelConstants { |
45 | 45 | * Cassandra user constants. |
46 | 46 | */ |
47 | 47 | public static final String USER_COLUMN_FAMILY_NAME = "user"; |
48 | - public static final String USER_TENANT_ID_PROPERTY = TENTANT_ID_PROPERTY; | |
48 | + public static final String USER_TENANT_ID_PROPERTY = TENANT_ID_PROPERTY; | |
49 | 49 | public static final String USER_CUSTOMER_ID_PROPERTY = CUSTOMER_ID_PROPERTY; |
50 | 50 | public static final String USER_EMAIL_PROPERTY = "email"; |
51 | 51 | public static final String USER_AUTHORITY_PROPERTY = "authority"; |
... | ... | @@ -106,7 +106,7 @@ public class ModelConstants { |
106 | 106 | * Cassandra customer constants. |
107 | 107 | */ |
108 | 108 | public static final String CUSTOMER_COLUMN_FAMILY_NAME = "customer"; |
109 | - public static final String CUSTOMER_TENANT_ID_PROPERTY = TENTANT_ID_PROPERTY; | |
109 | + public static final String CUSTOMER_TENANT_ID_PROPERTY = TENANT_ID_PROPERTY; | |
110 | 110 | public static final String CUSTOMER_TITLE_PROPERTY = TITLE_PROPERTY; |
111 | 111 | public static final String CUSTOMER_ADDITIONAL_INFO_PROPERTY = ADDITIONAL_INFO_PROPERTY; |
112 | 112 | |
... | ... | @@ -116,7 +116,7 @@ public class ModelConstants { |
116 | 116 | * Cassandra device constants. |
117 | 117 | */ |
118 | 118 | public static final String DEVICE_COLUMN_FAMILY_NAME = "device"; |
119 | - public static final String DEVICE_TENANT_ID_PROPERTY = TENTANT_ID_PROPERTY; | |
119 | + public static final String DEVICE_TENANT_ID_PROPERTY = TENANT_ID_PROPERTY; | |
120 | 120 | public static final String DEVICE_CUSTOMER_ID_PROPERTY = CUSTOMER_ID_PROPERTY; |
121 | 121 | public static final String DEVICE_NAME_PROPERTY = "name"; |
122 | 122 | public static final String DEVICE_ADDITIONAL_INFO_PROPERTY = ADDITIONAL_INFO_PROPERTY; |
... | ... | @@ -142,7 +142,7 @@ public class ModelConstants { |
142 | 142 | * Cassandra widgets_bundle constants. |
143 | 143 | */ |
144 | 144 | public static final String WIDGETS_BUNDLE_COLUMN_FAMILY_NAME = "widgets_bundle"; |
145 | - public static final String WIDGETS_BUNDLE_TENANT_ID_PROPERTY = TENTANT_ID_PROPERTY; | |
145 | + public static final String WIDGETS_BUNDLE_TENANT_ID_PROPERTY = TENANT_ID_PROPERTY; | |
146 | 146 | public static final String WIDGETS_BUNDLE_ALIAS_PROPERTY = ALIAS_PROPERTY; |
147 | 147 | public static final String WIDGETS_BUNDLE_TITLE_PROPERTY = TITLE_PROPERTY; |
148 | 148 | public static final String WIDGETS_BUNDLE_IMAGE_PROPERTY = "image"; |
... | ... | @@ -154,7 +154,7 @@ public class ModelConstants { |
154 | 154 | * Cassandra widget_type constants. |
155 | 155 | */ |
156 | 156 | public static final String WIDGET_TYPE_COLUMN_FAMILY_NAME = "widget_type"; |
157 | - public static final String WIDGET_TYPE_TENANT_ID_PROPERTY = TENTANT_ID_PROPERTY; | |
157 | + public static final String WIDGET_TYPE_TENANT_ID_PROPERTY = TENANT_ID_PROPERTY; | |
158 | 158 | public static final String WIDGET_TYPE_BUNDLE_ALIAS_PROPERTY = "bundle_alias"; |
159 | 159 | public static final String WIDGET_TYPE_ALIAS_PROPERTY = ALIAS_PROPERTY; |
160 | 160 | public static final String WIDGET_TYPE_NAME_PROPERTY = "name"; |
... | ... | @@ -166,7 +166,7 @@ public class ModelConstants { |
166 | 166 | * Cassandra dashboard constants. |
167 | 167 | */ |
168 | 168 | public static final String DASHBOARD_COLUMN_FAMILY_NAME = "dashboard"; |
169 | - public static final String DASHBOARD_TENANT_ID_PROPERTY = TENTANT_ID_PROPERTY; | |
169 | + public static final String DASHBOARD_TENANT_ID_PROPERTY = TENANT_ID_PROPERTY; | |
170 | 170 | public static final String DASHBOARD_CUSTOMER_ID_PROPERTY = CUSTOMER_ID_PROPERTY; |
171 | 171 | public static final String DASHBOARD_TITLE_PROPERTY = TITLE_PROPERTY; |
172 | 172 | public static final String DASHBOARD_CONFIGURATION_PROPERTY = "configuration"; |
... | ... | @@ -179,7 +179,7 @@ public class ModelConstants { |
179 | 179 | * Cassandra plugin metadata constants. |
180 | 180 | */ |
181 | 181 | public static final String PLUGIN_COLUMN_FAMILY_NAME = "plugin"; |
182 | - public static final String PLUGIN_TENANT_ID_PROPERTY = TENTANT_ID_PROPERTY; | |
182 | + public static final String PLUGIN_TENANT_ID_PROPERTY = TENANT_ID_PROPERTY; | |
183 | 183 | public static final String PLUGIN_NAME_PROPERTY = "name"; |
184 | 184 | public static final String PLUGIN_API_TOKEN_PROPERTY = "api_token"; |
185 | 185 | public static final String PLUGIN_CLASS_PROPERTY = "plugin_class"; |
... | ... | @@ -209,7 +209,7 @@ public class ModelConstants { |
209 | 209 | * Cassandra rule metadata constants. |
210 | 210 | */ |
211 | 211 | public static final String RULE_COLUMN_FAMILY_NAME = "rule"; |
212 | - public static final String RULE_TENANT_ID_PROPERTY = TENTANT_ID_PROPERTY; | |
212 | + public static final String RULE_TENANT_ID_PROPERTY = TENANT_ID_PROPERTY; | |
213 | 213 | public static final String RULE_NAME_PROPERTY = "name"; |
214 | 214 | public static final String RULE_STATE_PROPERTY = "state"; |
215 | 215 | public static final String RULE_WEIGHT_PROPERTY = "weight"; |
... | ... | @@ -225,7 +225,7 @@ public class ModelConstants { |
225 | 225 | * Cassandra event constants. |
226 | 226 | */ |
227 | 227 | public static final String EVENT_COLUMN_FAMILY_NAME = "event"; |
228 | - public static final String EVENT_TENANT_ID_PROPERTY = TENTANT_ID_PROPERTY; | |
228 | + public static final String EVENT_TENANT_ID_PROPERTY = TENANT_ID_PROPERTY; | |
229 | 229 | public static final String EVENT_TYPE_PROPERTY = "event_type"; |
230 | 230 | public static final String EVENT_UID_PROPERTY = "event_uid"; |
231 | 231 | public static final String EVENT_ENTITY_TYPE_PROPERTY = "entity_type"; | ... | ... |
... | ... | @@ -22,6 +22,9 @@ import javax.persistence.Id; |
22 | 22 | import javax.persistence.Table; |
23 | 23 | import javax.persistence.Transient; |
24 | 24 | import com.fasterxml.jackson.databind.JsonNode; |
25 | +import com.fasterxml.jackson.databind.ObjectMapper; | |
26 | +import lombok.Data; | |
27 | +import lombok.extern.slf4j.Slf4j; | |
25 | 28 | import org.thingsboard.server.common.data.id.PluginId; |
26 | 29 | import org.thingsboard.server.common.data.id.TenantId; |
27 | 30 | import org.thingsboard.server.common.data.plugin.ComponentLifecycleState; |
... | ... | @@ -29,23 +32,25 @@ import org.thingsboard.server.common.data.plugin.PluginMetaData; |
29 | 32 | import org.thingsboard.server.dao.model.ModelConstants; |
30 | 33 | import org.thingsboard.server.dao.model.SearchTextEntity; |
31 | 34 | |
35 | +import java.io.IOException; | |
32 | 36 | import java.util.Objects; |
33 | 37 | import java.util.UUID; |
34 | - | |
35 | -//@Entity | |
38 | +@Slf4j | |
39 | +@Data | |
40 | +@Entity | |
36 | 41 | @Table(name = ModelConstants.PLUGIN_COLUMN_FAMILY_NAME) |
37 | 42 | public class PluginMetaDataEntity implements SearchTextEntity<PluginMetaData> { |
38 | 43 | |
39 | 44 | @Transient |
40 | 45 | private static final long serialVersionUID = -6164321050824823149L; |
41 | 46 | @Id |
42 | - @Column(name = ModelConstants.ID_PROPERTY) | |
47 | + @Column(name = ModelConstants.ID_PROPERTY, columnDefinition = "BINARY(16)") | |
43 | 48 | private UUID id; |
44 | 49 | |
45 | 50 | @Column(name = ModelConstants.PLUGIN_API_TOKEN_PROPERTY) |
46 | 51 | private String apiToken; |
47 | 52 | |
48 | - @Column(name = ModelConstants.PLUGIN_TENANT_ID_PROPERTY) | |
53 | + @Column(name = ModelConstants.PLUGIN_TENANT_ID_PROPERTY, columnDefinition = "BINARY(16)") | |
49 | 54 | private UUID tenantId; |
50 | 55 | |
51 | 56 | @Column(name = ModelConstants.PLUGIN_NAME_PROPERTY) |
... | ... | @@ -61,13 +66,13 @@ public class PluginMetaDataEntity implements SearchTextEntity<PluginMetaData> { |
61 | 66 | private ComponentLifecycleState state; |
62 | 67 | |
63 | 68 | @Column(name = ModelConstants.PLUGIN_CONFIGURATION_PROPERTY) |
64 | - private JsonNode configuration; | |
69 | + private String configuration; | |
65 | 70 | |
66 | 71 | @Column(name = ModelConstants.SEARCH_TEXT_PROPERTY) |
67 | 72 | private String searchText; |
68 | 73 | |
69 | 74 | @Column(name = ModelConstants.ADDITIONAL_INFO_PROPERTY) |
70 | - private JsonNode additionalInfo; | |
75 | + private String additionalInfo; | |
71 | 76 | |
72 | 77 | public PluginMetaDataEntity() { |
73 | 78 | } |
... | ... | @@ -82,9 +87,13 @@ public class PluginMetaDataEntity implements SearchTextEntity<PluginMetaData> { |
82 | 87 | this.name = pluginMetaData.getName(); |
83 | 88 | this.publicAccess = pluginMetaData.isPublicAccess(); |
84 | 89 | this.state = pluginMetaData.getState(); |
85 | - this.configuration = pluginMetaData.getConfiguration(); | |
86 | 90 | this.searchText = pluginMetaData.getName(); |
87 | - this.additionalInfo = pluginMetaData.getAdditionalInfo(); | |
91 | + if (pluginMetaData.getConfiguration() != null) { | |
92 | + this.configuration = pluginMetaData.getConfiguration().toString(); | |
93 | + } | |
94 | + if (pluginMetaData.getAdditionalInfo() != null) { | |
95 | + this.additionalInfo = pluginMetaData.getAdditionalInfo().toString(); | |
96 | + } | |
88 | 97 | } |
89 | 98 | |
90 | 99 | @Override |
... | ... | @@ -107,86 +116,33 @@ public class PluginMetaDataEntity implements SearchTextEntity<PluginMetaData> { |
107 | 116 | this.id = id; |
108 | 117 | } |
109 | 118 | |
110 | - public String getApiToken() { | |
111 | - return apiToken; | |
112 | - } | |
113 | - | |
114 | - public void setApiToken(String apiToken) { | |
115 | - this.apiToken = apiToken; | |
116 | - } | |
117 | - | |
118 | - public UUID getTenantId() { | |
119 | - return tenantId; | |
120 | - } | |
121 | - | |
122 | - public void setTenantId(UUID tenantId) { | |
123 | - this.tenantId = tenantId; | |
124 | - } | |
125 | - | |
126 | - public String getName() { | |
127 | - return name; | |
128 | - } | |
129 | - | |
130 | - public void setName(String name) { | |
131 | - this.name = name; | |
132 | - } | |
133 | - | |
134 | - public String getClazz() { | |
135 | - return clazz; | |
136 | - } | |
137 | - | |
138 | - public void setClazz(String clazz) { | |
139 | - this.clazz = clazz; | |
140 | - } | |
141 | - | |
142 | - public JsonNode getConfiguration() { | |
143 | - return configuration; | |
144 | - } | |
145 | - | |
146 | - public void setConfiguration(JsonNode configuration) { | |
147 | - this.configuration = configuration; | |
148 | - } | |
149 | - | |
150 | - public boolean isPublicAccess() { | |
151 | - return publicAccess; | |
152 | - } | |
153 | - | |
154 | - public void setPublicAccess(boolean publicAccess) { | |
155 | - this.publicAccess = publicAccess; | |
156 | - } | |
157 | - | |
158 | - public ComponentLifecycleState getState() { | |
159 | - return state; | |
160 | - } | |
161 | - | |
162 | - public void setState(ComponentLifecycleState state) { | |
163 | - this.state = state; | |
164 | - } | |
165 | - | |
166 | - public String getSearchText() { | |
167 | - return searchText; | |
168 | - } | |
169 | - | |
170 | - public JsonNode getAdditionalInfo() { | |
171 | - return additionalInfo; | |
172 | - } | |
173 | - | |
174 | - public void setAdditionalInfo(JsonNode additionalInfo) { | |
175 | - this.additionalInfo = additionalInfo; | |
176 | - } | |
177 | - | |
178 | 119 | @Override |
179 | 120 | public PluginMetaData toData() { |
180 | 121 | PluginMetaData data = new PluginMetaData(new PluginId(id)); |
181 | 122 | data.setTenantId(new TenantId(tenantId)); |
182 | 123 | data.setCreatedTime(UUIDs.unixTimestamp(id)); |
183 | 124 | data.setName(name); |
184 | - data.setConfiguration(configuration); | |
185 | 125 | data.setClazz(clazz); |
186 | 126 | data.setPublicAccess(publicAccess); |
187 | 127 | data.setState(state); |
188 | 128 | data.setApiToken(apiToken); |
189 | - data.setAdditionalInfo(additionalInfo); | |
129 | + ObjectMapper mapper = new ObjectMapper(); | |
130 | + if (configuration != null) { | |
131 | + try { | |
132 | + JsonNode jsonNode = mapper.readTree(configuration); | |
133 | + data.setConfiguration(jsonNode); | |
134 | + } catch (IOException e) { | |
135 | + log.warn(String.format("Error parsing JsonNode: %s. Reason: %s ", configuration, e.getMessage()), e); | |
136 | + } | |
137 | + } | |
138 | + if (additionalInfo != null) { | |
139 | + try { | |
140 | + JsonNode jsonNode = mapper.readTree(additionalInfo); | |
141 | + data.setAdditionalInfo(jsonNode); | |
142 | + } catch (IOException e) { | |
143 | + log.warn(String.format("Error parsing JsonNode: %s. Reason: %s ", additionalInfo, e.getMessage()), e); | |
144 | + } | |
145 | + } | |
190 | 146 | return data; |
191 | 147 | } |
192 | 148 | ... | ... |
... | ... | @@ -16,12 +16,17 @@ |
16 | 16 | package org.thingsboard.server.dao.model.sql; |
17 | 17 | |
18 | 18 | import com.datastax.driver.core.utils.UUIDs; |
19 | + | |
19 | 20 | import javax.persistence.Column; |
20 | 21 | import javax.persistence.Entity; |
21 | 22 | import javax.persistence.Id; |
22 | 23 | import javax.persistence.Table; |
23 | 24 | import javax.persistence.Transient; |
25 | + | |
24 | 26 | import com.fasterxml.jackson.databind.JsonNode; |
27 | +import com.fasterxml.jackson.databind.ObjectMapper; | |
28 | +import lombok.Data; | |
29 | +import lombok.extern.slf4j.Slf4j; | |
25 | 30 | import org.thingsboard.server.common.data.id.RuleId; |
26 | 31 | import org.thingsboard.server.common.data.id.TenantId; |
27 | 32 | import org.thingsboard.server.common.data.plugin.ComponentLifecycleState; |
... | ... | @@ -30,19 +35,22 @@ import org.thingsboard.server.dao.DaoUtil; |
30 | 35 | import org.thingsboard.server.dao.model.ModelConstants; |
31 | 36 | import org.thingsboard.server.dao.model.SearchTextEntity; |
32 | 37 | |
38 | +import java.io.IOException; | |
33 | 39 | import java.util.Objects; |
34 | 40 | import java.util.UUID; |
35 | 41 | |
36 | -//@Entity | |
42 | +@Slf4j | |
43 | +@Data | |
44 | +@Entity | |
37 | 45 | @Table(name = ModelConstants.RULE_COLUMN_FAMILY_NAME) |
38 | 46 | public class RuleMetaDataEntity implements SearchTextEntity<RuleMetaData> { |
39 | 47 | |
40 | 48 | @Transient |
41 | 49 | private static final long serialVersionUID = -1506905644259463884L; |
42 | 50 | @Id |
43 | - @Column(name = ModelConstants.ID_PROPERTY) | |
51 | + @Column(name = ModelConstants.ID_PROPERTY, columnDefinition = "BINARY(16)") | |
44 | 52 | private UUID id; |
45 | - @Column(name = ModelConstants.RULE_TENANT_ID_PROPERTY) | |
53 | + @Column(name = ModelConstants.RULE_TENANT_ID_PROPERTY, columnDefinition = "BINARY(16)") | |
46 | 54 | private UUID tenantId; |
47 | 55 | @Column(name = ModelConstants.RULE_NAME_PROPERTY) |
48 | 56 | private String name; |
... | ... | @@ -55,13 +63,13 @@ public class RuleMetaDataEntity implements SearchTextEntity<RuleMetaData> { |
55 | 63 | @Column(name = ModelConstants.RULE_PLUGIN_TOKEN_PROPERTY) |
56 | 64 | private String pluginToken; |
57 | 65 | @Column(name = ModelConstants.RULE_FILTERS) |
58 | - private JsonNode filters; | |
66 | + private String filters; | |
59 | 67 | @Column(name = ModelConstants.RULE_PROCESSOR) |
60 | - private JsonNode processor; | |
68 | + private String processor; | |
61 | 69 | @Column(name = ModelConstants.RULE_ACTION) |
62 | - private JsonNode action; | |
70 | + private String action; | |
63 | 71 | @Column(name = ModelConstants.ADDITIONAL_INFO_PROPERTY) |
64 | - private JsonNode additionalInfo; | |
72 | + private String additionalInfo; | |
65 | 73 | |
66 | 74 | public RuleMetaDataEntity() { |
67 | 75 | } |
... | ... | @@ -76,10 +84,18 @@ public class RuleMetaDataEntity implements SearchTextEntity<RuleMetaData> { |
76 | 84 | this.state = rule.getState(); |
77 | 85 | this.weight = rule.getWeight(); |
78 | 86 | this.searchText = rule.getName(); |
79 | - this.filters = rule.getFilters(); | |
80 | - this.processor = rule.getProcessor(); | |
81 | - this.action = rule.getAction(); | |
82 | - this.additionalInfo = rule.getAdditionalInfo(); | |
87 | + if (rule.getFilters() != null) { | |
88 | + this.filters = rule.getFilters().toString(); | |
89 | + } | |
90 | + if (rule.getProcessor() != null) { | |
91 | + this.processor = rule.getProcessor().toString(); | |
92 | + } | |
93 | + if (rule.getAction() != null) { | |
94 | + this.action = rule.getAction().toString(); | |
95 | + } | |
96 | + if (rule.getAdditionalInfo() != null) { | |
97 | + this.additionalInfo = rule.getAdditionalInfo().toString(); | |
98 | + } | |
83 | 99 | } |
84 | 100 | |
85 | 101 | @Override |
... | ... | @@ -102,82 +118,6 @@ public class RuleMetaDataEntity implements SearchTextEntity<RuleMetaData> { |
102 | 118 | this.id = id; |
103 | 119 | } |
104 | 120 | |
105 | - public UUID getTenantId() { | |
106 | - return tenantId; | |
107 | - } | |
108 | - | |
109 | - public void setTenantId(UUID tenantId) { | |
110 | - this.tenantId = tenantId; | |
111 | - } | |
112 | - | |
113 | - public String getName() { | |
114 | - return name; | |
115 | - } | |
116 | - | |
117 | - public void setName(String name) { | |
118 | - this.name = name; | |
119 | - } | |
120 | - | |
121 | - public ComponentLifecycleState getState() { | |
122 | - return state; | |
123 | - } | |
124 | - | |
125 | - public void setState(ComponentLifecycleState state) { | |
126 | - this.state = state; | |
127 | - } | |
128 | - | |
129 | - public int getWeight() { | |
130 | - return weight; | |
131 | - } | |
132 | - | |
133 | - public void setWeight(int weight) { | |
134 | - this.weight = weight; | |
135 | - } | |
136 | - | |
137 | - public String getPluginToken() { | |
138 | - return pluginToken; | |
139 | - } | |
140 | - | |
141 | - public void setPluginToken(String pluginToken) { | |
142 | - this.pluginToken = pluginToken; | |
143 | - } | |
144 | - | |
145 | - public String getSearchText() { | |
146 | - return searchText; | |
147 | - } | |
148 | - | |
149 | - public JsonNode getFilters() { | |
150 | - return filters; | |
151 | - } | |
152 | - | |
153 | - public void setFilters(JsonNode filters) { | |
154 | - this.filters = filters; | |
155 | - } | |
156 | - | |
157 | - public JsonNode getProcessor() { | |
158 | - return processor; | |
159 | - } | |
160 | - | |
161 | - public void setProcessor(JsonNode processor) { | |
162 | - this.processor = processor; | |
163 | - } | |
164 | - | |
165 | - public JsonNode getAction() { | |
166 | - return action; | |
167 | - } | |
168 | - | |
169 | - public void setAction(JsonNode action) { | |
170 | - this.action = action; | |
171 | - } | |
172 | - | |
173 | - public JsonNode getAdditionalInfo() { | |
174 | - return additionalInfo; | |
175 | - } | |
176 | - | |
177 | - public void setAdditionalInfo(JsonNode additionalInfo) { | |
178 | - this.additionalInfo = additionalInfo; | |
179 | - } | |
180 | - | |
181 | 121 | @Override |
182 | 122 | public RuleMetaData toData() { |
183 | 123 | RuleMetaData rule = new RuleMetaData(new RuleId(id)); |
... | ... | @@ -187,10 +127,39 @@ public class RuleMetaDataEntity implements SearchTextEntity<RuleMetaData> { |
187 | 127 | rule.setWeight(weight); |
188 | 128 | rule.setCreatedTime(UUIDs.unixTimestamp(id)); |
189 | 129 | rule.setPluginToken(pluginToken); |
190 | - rule.setFilters(filters); | |
191 | - rule.setProcessor(processor); | |
192 | - rule.setAction(action); | |
193 | - rule.setAdditionalInfo(additionalInfo); | |
130 | + ObjectMapper mapper = new ObjectMapper(); | |
131 | + if (filters != null) { | |
132 | + try { | |
133 | + JsonNode jsonNode = mapper.readTree(filters); | |
134 | + rule.setFilters(jsonNode); | |
135 | + } catch (IOException e) { | |
136 | + log.warn(String.format("Error parsing JsonNode: %s. Reason: %s ", filters, e.getMessage()), e); | |
137 | + } | |
138 | + } | |
139 | + if (processor != null) { | |
140 | + try { | |
141 | + JsonNode jsonNode = mapper.readTree(processor); | |
142 | + rule.setProcessor(jsonNode); | |
143 | + } catch (IOException e) { | |
144 | + log.warn(String.format("Error parsing JsonNode: %s. Reason: %s ", processor, e.getMessage()), e); | |
145 | + } | |
146 | + } | |
147 | + if (action != null) { | |
148 | + try { | |
149 | + JsonNode jsonNode = mapper.readTree(action); | |
150 | + rule.setAction(jsonNode); | |
151 | + } catch (IOException e) { | |
152 | + log.warn(String.format("Error parsing JsonNode: %s. Reason: %s ", action, e.getMessage()), e); | |
153 | + } | |
154 | + } | |
155 | + if (additionalInfo != null) { | |
156 | + try { | |
157 | + JsonNode jsonNode = mapper.readTree(additionalInfo); | |
158 | + rule.setAdditionalInfo(jsonNode); | |
159 | + } catch (IOException e) { | |
160 | + log.warn(String.format("Error parsing JsonNode: %s. Reason: %s ", additionalInfo, e.getMessage()), e); | |
161 | + } | |
162 | + } | |
194 | 163 | return rule; |
195 | 164 | } |
196 | 165 | ... | ... |
1 | 1 | /** |
2 | 2 | * Copyright © 2016-2017 The Thingsboard Authors |
3 | - * <p> | |
3 | + * | |
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | 5 | * you may not use this file except in compliance with the License. |
6 | 6 | * You may obtain a copy of the License at |
7 | - * <p> | |
8 | - * http://www.apache.org/licenses/LICENSE-2.0 | |
9 | - * <p> | |
7 | + * | |
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | |
9 | + * | |
10 | 10 | * Unless required by applicable law or agreed to in writing, software |
11 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
12 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ... | ... |
... | ... | @@ -25,6 +25,7 @@ import javax.persistence.Transient; |
25 | 25 | import com.datastax.driver.mapping.annotations.PartitionKey; |
26 | 26 | import com.fasterxml.jackson.databind.JsonNode; |
27 | 27 | import com.fasterxml.jackson.databind.ObjectMapper; |
28 | +import lombok.Data; | |
28 | 29 | import lombok.extern.slf4j.Slf4j; |
29 | 30 | import org.thingsboard.server.common.data.id.TenantId; |
30 | 31 | import org.thingsboard.server.common.data.id.WidgetTypeId; |
... | ... | @@ -36,6 +37,7 @@ import java.io.IOException; |
36 | 37 | import java.util.UUID; |
37 | 38 | |
38 | 39 | @Slf4j |
40 | +@Data | |
39 | 41 | @Entity |
40 | 42 | @Table(name = ModelConstants.WIDGET_TYPE_COLUMN_FAMILY_NAME) |
41 | 43 | public final class WidgetTypeEntity implements BaseEntity<WidgetType> { |
... | ... | @@ -93,46 +95,6 @@ public final class WidgetTypeEntity implements BaseEntity<WidgetType> { |
93 | 95 | this.id = id; |
94 | 96 | } |
95 | 97 | |
96 | - public UUID getTenantId() { | |
97 | - return tenantId; | |
98 | - } | |
99 | - | |
100 | - public void setTenantId(UUID tenantId) { | |
101 | - this.tenantId = tenantId; | |
102 | - } | |
103 | - | |
104 | - public String getBundleAlias() { | |
105 | - return bundleAlias; | |
106 | - } | |
107 | - | |
108 | - public void setBundleAlias(String bundleAlias) { | |
109 | - this.bundleAlias = bundleAlias; | |
110 | - } | |
111 | - | |
112 | - public String getAlias() { | |
113 | - return alias; | |
114 | - } | |
115 | - | |
116 | - public void setAlias(String alias) { | |
117 | - this.alias = alias; | |
118 | - } | |
119 | - | |
120 | - public String getName() { | |
121 | - return name; | |
122 | - } | |
123 | - | |
124 | - public void setName(String name) { | |
125 | - this.name = name; | |
126 | - } | |
127 | - | |
128 | - public String getDescriptor() { | |
129 | - return descriptor; | |
130 | - } | |
131 | - | |
132 | - public void setDescriptor(String descriptor) { | |
133 | - this.descriptor = descriptor; | |
134 | - } | |
135 | - | |
136 | 98 | @Override |
137 | 99 | public int hashCode() { |
138 | 100 | int result = id != null ? id.hashCode() : 0; | ... | ... |
1 | 1 | /** |
2 | 2 | * Copyright © 2016-2017 The Thingsboard Authors |
3 | - * <p> | |
3 | + * | |
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | 5 | * you may not use this file except in compliance with the License. |
6 | 6 | * You may obtain a copy of the License at |
7 | - * <p> | |
8 | - * http://www.apache.org/licenses/LICENSE-2.0 | |
9 | - * <p> | |
7 | + * | |
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | |
9 | + * | |
10 | 10 | * Unless required by applicable law or agreed to in writing, software |
11 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
12 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ... | ... |
1 | +/** | |
2 | + * Copyright © 2016-2017 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.dao.sql.plugin; | |
17 | + | |
18 | +import lombok.extern.slf4j.Slf4j; | |
19 | +import org.springframework.beans.factory.annotation.Autowired; | |
20 | +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; | |
21 | +import org.springframework.data.repository.CrudRepository; | |
22 | +import org.springframework.stereotype.Component; | |
23 | +import org.thingsboard.server.common.data.id.PluginId; | |
24 | +import org.thingsboard.server.common.data.id.TenantId; | |
25 | +import org.thingsboard.server.common.data.page.TextPageLink; | |
26 | +import org.thingsboard.server.common.data.plugin.PluginMetaData; | |
27 | +import org.thingsboard.server.dao.DaoUtil; | |
28 | +import org.thingsboard.server.dao.model.ModelConstants; | |
29 | +import org.thingsboard.server.dao.model.sql.PluginMetaDataEntity; | |
30 | +import org.thingsboard.server.dao.plugin.PluginDao; | |
31 | +import org.thingsboard.server.dao.sql.JpaAbstractDao; | |
32 | + | |
33 | +import java.util.Arrays; | |
34 | +import java.util.List; | |
35 | +import java.util.UUID; | |
36 | + | |
37 | +/** | |
38 | + * Created by Valerii Sosliuk on 5/1/2017. | |
39 | + */ | |
40 | +@Slf4j | |
41 | +@Component | |
42 | +@ConditionalOnProperty(prefix = "sql", value = "enabled", havingValue = "true", matchIfMissing = false) | |
43 | +public class JpaBasePluginDao extends JpaAbstractDao<PluginMetaDataEntity, PluginMetaData> implements PluginDao { | |
44 | + | |
45 | + @Autowired | |
46 | + private PluginMetaDataRepository pluginMetaDataRepository; | |
47 | + | |
48 | + @Override | |
49 | + protected Class<PluginMetaDataEntity> getEntityClass() { | |
50 | + return PluginMetaDataEntity.class; | |
51 | + } | |
52 | + | |
53 | + @Override | |
54 | + protected String getColumnFamilyName() { | |
55 | + return ModelConstants.PLUGIN_COLUMN_FAMILY_NAME; | |
56 | + } | |
57 | + | |
58 | + @Override | |
59 | + protected CrudRepository<PluginMetaDataEntity, UUID> getCrudRepository() { | |
60 | + return pluginMetaDataRepository; | |
61 | + } | |
62 | + | |
63 | + @Override | |
64 | + protected boolean isSearchTextDao() { | |
65 | + return true; | |
66 | + } | |
67 | + | |
68 | + @Override | |
69 | + public PluginMetaData findById(PluginId pluginId) { | |
70 | + log.debug("Search plugin meta-data entity by id [{}]", pluginId); | |
71 | + PluginMetaData pluginMetaData = super.findById(pluginId.getId()); | |
72 | + if (log.isTraceEnabled()) { | |
73 | + log.trace("Search result: [{}] for plugin entity [{}]", pluginMetaData != null, pluginMetaData); | |
74 | + } else { | |
75 | + log.debug("Search result: [{}]", pluginMetaData != null); | |
76 | + } | |
77 | + return pluginMetaData; | |
78 | + } | |
79 | + | |
80 | + @Override | |
81 | + public PluginMetaData findByApiToken(String apiToken) { | |
82 | + log.debug("Search plugin meta-data entity by api token [{}]", apiToken); | |
83 | + PluginMetaDataEntity entity = pluginMetaDataRepository.findByApiToken(apiToken); | |
84 | + if (log.isTraceEnabled()) { | |
85 | + log.trace("Search result: [{}] for plugin entity [{}]", entity != null, entity); | |
86 | + } else { | |
87 | + log.debug("Search result: [{}]", entity != null); | |
88 | + } | |
89 | + return DaoUtil.getData(entity); | |
90 | + } | |
91 | + | |
92 | + @Override | |
93 | + public void deleteById(UUID id) { | |
94 | + log.debug("Delete plugin meta-data entity by id [{}]", id); | |
95 | + pluginMetaDataRepository.delete(id); | |
96 | + } | |
97 | + | |
98 | + @Override | |
99 | + public void deleteById(PluginId pluginId) { | |
100 | + deleteById(pluginId.getId()); | |
101 | + } | |
102 | + | |
103 | + @Override | |
104 | + public List<PluginMetaData> findByTenantIdAndPageLink(TenantId tenantId, TextPageLink pageLink) { | |
105 | + log.debug("Try to find здгпшты by tenantId [{}] and pageLink [{}]", tenantId, pageLink); | |
106 | + List<PluginMetaDataEntity> entities; | |
107 | + if (pageLink.getIdOffset() == null) { | |
108 | + entities = pluginMetaDataRepository | |
109 | + .findByTenantIdAndPageLinkFirstPage(pageLink.getLimit(), tenantId.getId(), pageLink.getTextSearch()); | |
110 | + } else { | |
111 | + entities = pluginMetaDataRepository | |
112 | + .findByTenantIdAndPageLinkNextPage(pageLink.getLimit(), tenantId.getId(), pageLink.getTextSearch(), pageLink.getIdOffset()); | |
113 | + } | |
114 | + if (log.isTraceEnabled()) { | |
115 | + log.trace("Search result: [{}]", Arrays.toString(entities.toArray())); | |
116 | + } else { | |
117 | + log.debug("Search result: [{}]", entities.size()); | |
118 | + } | |
119 | + return DaoUtil.convertDataList(entities); | |
120 | + } | |
121 | + | |
122 | + @Override | |
123 | + public List<PluginMetaData> findAllTenantPluginsByTenantId(UUID tenantId, TextPageLink pageLink) { | |
124 | + log.debug("Try to find all tenant plugins by tenantId [{}] and pageLink [{}]", tenantId, pageLink); | |
125 | + List<PluginMetaDataEntity> entities; | |
126 | + if (pageLink.getIdOffset() == null) { | |
127 | + entities = pluginMetaDataRepository | |
128 | + .findAllTenantPluginsByTenantIdFirstPage(pageLink.getLimit(), tenantId, pageLink.getTextSearch()); | |
129 | + } else { | |
130 | + entities = pluginMetaDataRepository | |
131 | + .findAllTenantPluginsByTenantIdNextPage(pageLink.getLimit(), tenantId, pageLink.getTextSearch(), pageLink.getIdOffset()); | |
132 | + } | |
133 | + if (log.isTraceEnabled()) { | |
134 | + log.trace("Search result: [{}]", Arrays.toString(entities.toArray())); | |
135 | + } else { | |
136 | + log.debug("Search result: [{}]", entities.size()); | |
137 | + } | |
138 | + return DaoUtil.convertDataList(entities); | |
139 | + } | |
140 | +} | ... | ... |
1 | +/** | |
2 | + * Copyright © 2016-2017 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.dao.sql.plugin; | |
17 | + | |
18 | +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; | |
19 | +import org.springframework.data.jpa.repository.Query; | |
20 | +import org.springframework.data.repository.CrudRepository; | |
21 | +import org.thingsboard.server.common.data.plugin.PluginMetaData; | |
22 | +import org.thingsboard.server.dao.model.sql.PluginMetaDataEntity; | |
23 | +import org.thingsboard.server.dao.model.sql.RuleMetaDataEntity; | |
24 | + | |
25 | +import java.util.List; | |
26 | +import java.util.UUID; | |
27 | + | |
28 | +/** | |
29 | + * Created by Valerii Sosliuk on 5/1/2017. | |
30 | + */ | |
31 | +@ConditionalOnProperty(prefix = "sql", value = "enabled", havingValue = "true", matchIfMissing = false) | |
32 | +public interface PluginMetaDataRepository extends CrudRepository<PluginMetaDataEntity, UUID> { | |
33 | + | |
34 | + PluginMetaDataEntity findByApiToken(String apiToken); | |
35 | + | |
36 | + @Query(nativeQuery = true, value = "SELECT * FROM PLUGIN WHERE TENANT_ID = ?2 " + | |
37 | + "AND LOWER(SEARCH_TEXT) LIKE LOWER(CONCAT(?3, '%')) " + | |
38 | + "ORDER BY ID LIMIT ?1") | |
39 | + List<PluginMetaDataEntity> findByTenantIdAndPageLinkFirstPage(int limit, UUID tenantId, String textSearch); | |
40 | + | |
41 | + @Query(nativeQuery = true, value = "SELECT * FROM PLUGIN WHERE TENANT_ID = ?2 " + | |
42 | + "AND LOWER(SEARCH_TEXT) LIKE LOWER(CONCAT(?3, '%')) " + | |
43 | + "AND ID > ?4 ORDER BY ID LIMIT ?1") | |
44 | + List<PluginMetaDataEntity> findByTenantIdAndPageLinkNextPage(int limit, UUID tenantId, String textSearch, UUID idOffset); | |
45 | + | |
46 | + @Query(nativeQuery = true, value = "SELECT * FROM PLUGIN WHERE (TENANT_ID = ?2 OR TENANT_ID IS NULL) " + | |
47 | + "AND LOWER(SEARCH_TEXT) LIKE LOWER(CONCAT(?3, '%')) " + | |
48 | + "ORDER BY ID LIMIT ?1") | |
49 | + List<PluginMetaDataEntity> findAllTenantPluginsByTenantIdFirstPage(int limit, UUID tenantId, String textSearch); | |
50 | + | |
51 | + @Query(nativeQuery = true, value = "SELECT * FROM PLUGIN WHERE (TENANT_ID = ?2 OR TENANT_ID IS NULL) " + | |
52 | + "AND LOWER(SEARCH_TEXT) LIKE LOWER(CONCAT(?3, '%')) " + | |
53 | + "AND ID > ?4 ORDER BY ID LIMIT ?1") | |
54 | + List<PluginMetaDataEntity> findAllTenantPluginsByTenantIdNextPage(int limit, UUID tenantId, String textSearch, UUID idOffset); | |
55 | +} | ... | ... |
1 | +/** | |
2 | + * Copyright © 2016-2017 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.dao.sql.rule; | |
17 | + | |
18 | +import lombok.extern.slf4j.Slf4j; | |
19 | +import org.springframework.beans.factory.annotation.Autowired; | |
20 | +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; | |
21 | +import org.springframework.data.repository.CrudRepository; | |
22 | +import org.springframework.stereotype.Component; | |
23 | +import org.thingsboard.server.common.data.id.RuleId; | |
24 | +import org.thingsboard.server.common.data.id.TenantId; | |
25 | +import org.thingsboard.server.common.data.page.TextPageLink; | |
26 | +import org.thingsboard.server.common.data.rule.RuleMetaData; | |
27 | +import org.thingsboard.server.dao.DaoUtil; | |
28 | +import org.thingsboard.server.dao.model.ModelConstants; | |
29 | +import org.thingsboard.server.dao.model.sql.RuleMetaDataEntity; | |
30 | +import org.thingsboard.server.dao.rule.RuleDao; | |
31 | +import org.thingsboard.server.dao.sql.JpaAbstractDao; | |
32 | + | |
33 | +import java.util.Arrays; | |
34 | +import java.util.List; | |
35 | +import java.util.UUID; | |
36 | + | |
37 | +/** | |
38 | + * Created by Valerii Sosliuk on 4/30/2017. | |
39 | + */ | |
40 | +@Slf4j | |
41 | +@Component | |
42 | +@ConditionalOnProperty(prefix = "sql", value = "enabled", havingValue = "true", matchIfMissing = false) | |
43 | +public class JpaBaseRuleDao extends JpaAbstractDao<RuleMetaDataEntity, RuleMetaData> implements RuleDao { | |
44 | + | |
45 | + @Autowired | |
46 | + private RuleMetaDataRepository ruleMetaDataRepository; | |
47 | + | |
48 | + @Override | |
49 | + protected Class<RuleMetaDataEntity> getEntityClass() { | |
50 | + return RuleMetaDataEntity.class; | |
51 | + } | |
52 | + @Override | |
53 | + protected String getColumnFamilyName() { | |
54 | + return ModelConstants.RULE_COLUMN_FAMILY_NAME; | |
55 | + } | |
56 | + | |
57 | + @Override | |
58 | + protected CrudRepository<RuleMetaDataEntity, UUID> getCrudRepository() { | |
59 | + return ruleMetaDataRepository; | |
60 | + } | |
61 | + | |
62 | + @Override | |
63 | + protected boolean isSearchTextDao() { | |
64 | + return true; | |
65 | + } | |
66 | + | |
67 | + @Override | |
68 | + public RuleMetaData findById(RuleId ruleId) { | |
69 | + return findById(ruleId.getId()); | |
70 | + } | |
71 | + | |
72 | + @Override | |
73 | + public List<RuleMetaData> findRulesByPlugin(String pluginToken) { | |
74 | + log.debug("Search rules by api token [{}]", pluginToken); | |
75 | + return DaoUtil.convertDataList(ruleMetaDataRepository.findByPluginToken(pluginToken)); | |
76 | + } | |
77 | + | |
78 | + @Override | |
79 | + public List<RuleMetaData> findByTenantIdAndPageLink(TenantId tenantId, TextPageLink pageLink) { | |
80 | + log.debug("Try to find rules by tenantId [{}] and pageLink [{}]", tenantId, pageLink); | |
81 | + List<RuleMetaDataEntity> entities; | |
82 | + if (pageLink.getIdOffset() == null) { | |
83 | + entities = ruleMetaDataRepository | |
84 | + .findByTenantIdAndPageLinkFirstPage(pageLink.getLimit(), tenantId.getId(), pageLink.getTextSearch()); | |
85 | + } else { | |
86 | + entities = ruleMetaDataRepository | |
87 | + .findByTenantIdAndPageLinkNextPage(pageLink.getLimit(), tenantId.getId(), pageLink.getTextSearch(), pageLink.getIdOffset()); | |
88 | + } | |
89 | + if (log.isTraceEnabled()) { | |
90 | + log.trace("Search result: [{}]", Arrays.toString(entities.toArray())); | |
91 | + } else { | |
92 | + log.debug("Search result: [{}]", entities.size()); | |
93 | + } | |
94 | + return DaoUtil.convertDataList(entities); | |
95 | + } | |
96 | + | |
97 | + @Override | |
98 | + public List<RuleMetaData> findAllTenantRulesByTenantId(UUID tenantId, TextPageLink pageLink) { | |
99 | + log.debug("Try to find all tenant rules by tenantId [{}] and pageLink [{}]", tenantId, pageLink); | |
100 | + List<RuleMetaDataEntity> entities; | |
101 | + if (pageLink.getIdOffset() == null) { | |
102 | + entities = ruleMetaDataRepository | |
103 | + .findAllTenantRulesByTenantIdFirstPage(pageLink.getLimit(), tenantId, pageLink.getTextSearch()); | |
104 | + } else { | |
105 | + entities = ruleMetaDataRepository | |
106 | + .findAllTenantRulesByTenantIdNextPage(pageLink.getLimit(), tenantId, pageLink.getTextSearch(), pageLink.getIdOffset()); | |
107 | + } | |
108 | + if (log.isTraceEnabled()) { | |
109 | + log.trace("Search result: [{}]", Arrays.toString(entities.toArray())); | |
110 | + } else { | |
111 | + log.debug("Search result: [{}]", entities.size()); | |
112 | + } | |
113 | + return DaoUtil.convertDataList(entities); | |
114 | + } | |
115 | + | |
116 | + @Override | |
117 | + public void deleteById(UUID id) { | |
118 | + log.debug("Delete rule meta-data entity by id [{}]", id); | |
119 | + ruleMetaDataRepository.delete(id); | |
120 | + } | |
121 | + | |
122 | + @Override | |
123 | + public void deleteById(RuleId ruleId) { | |
124 | + deleteById(ruleId.getId()); | |
125 | + } | |
126 | +} | ... | ... |
1 | +/** | |
2 | + * Copyright © 2016-2017 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.dao.sql.rule; | |
17 | + | |
18 | +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; | |
19 | +import org.springframework.data.jpa.repository.Query; | |
20 | +import org.springframework.data.repository.CrudRepository; | |
21 | +import org.thingsboard.server.common.data.id.TenantId; | |
22 | +import org.thingsboard.server.dao.model.ToData; | |
23 | +import org.thingsboard.server.dao.model.sql.RuleMetaDataEntity; | |
24 | + | |
25 | +import java.util.Collection; | |
26 | +import java.util.List; | |
27 | +import java.util.UUID; | |
28 | + | |
29 | +/** | |
30 | + * Created by Valerii Sosliuk on 4/30/2017. | |
31 | + */ | |
32 | +@ConditionalOnProperty(prefix = "sql", value = "enabled", havingValue = "true", matchIfMissing = false) | |
33 | +public interface RuleMetaDataRepository extends CrudRepository<RuleMetaDataEntity, UUID> { | |
34 | + | |
35 | + List<RuleMetaDataEntity> findByPluginToken(String pluginToken); | |
36 | + | |
37 | + @Query(nativeQuery = true, value = "SELECT * FROM RULE WHERE TENANT_ID = ?2 " + | |
38 | + "AND LOWER(SEARCH_TEXT) LIKE LOWER(CONCAT(?3, '%')) " + | |
39 | + "ORDER BY ID LIMIT ?1") | |
40 | + List<RuleMetaDataEntity> findByTenantIdAndPageLinkFirstPage(int limit, UUID tenantId, String textSearch); | |
41 | + | |
42 | + @Query(nativeQuery = true, value = "SELECT * FROM RULE WHERE TENANT_ID = ?2 " + | |
43 | + "AND LOWER(SEARCH_TEXT) LIKE LOWER(CONCAT(?3, '%')) " + | |
44 | + "AND ID > ?4 ORDER BY ID LIMIT ?1") | |
45 | + List<RuleMetaDataEntity> findByTenantIdAndPageLinkNextPage(int limit, UUID tenantId, String textSearch, UUID idOffset); | |
46 | + | |
47 | + @Query(nativeQuery = true, value = "SELECT * FROM RULE WHERE (TENANT_ID = ?2 OR TENANT_ID IS NULL) " + | |
48 | + "AND LOWER(SEARCH_TEXT) LIKE LOWER(CONCAT(?3, '%')) " + | |
49 | + "ORDER BY ID LIMIT ?1") | |
50 | + List<RuleMetaDataEntity> findAllTenantRulesByTenantIdFirstPage(int limit, UUID tenantId, String textSearch); | |
51 | + | |
52 | + @Query(nativeQuery = true, value = "SELECT * FROM RULE WHERE (TENANT_ID = ?2 OR TENANT_ID IS NULL) " + | |
53 | + "AND LOWER(SEARCH_TEXT) LIKE LOWER(CONCAT(?3, '%')) " + | |
54 | + "AND ID > ?4 ORDER BY ID LIMIT ?1") | |
55 | + List<RuleMetaDataEntity> findAllTenantRulesByTenantIdNextPage(int limit, UUID tenantId, String textSearch, UUID idOffset); | |
56 | +} | ... | ... |
1 | +/** | |
2 | + * Copyright © 2016-2017 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 | + */ | |
1 | 16 | package org.thingsboard.server.dao.sql.tenant; |
2 | 17 | |
3 | 18 | import org.springframework.beans.factory.annotation.Autowired; | ... | ... |
1 | +/** | |
2 | + * Copyright © 2016-2017 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 | + */ | |
1 | 16 | package org.thingsboard.server.dao.sql.tenant; |
2 | 17 | |
3 | 18 | import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; | ... | ... |
1 | 1 | /** |
2 | 2 | * Copyright © 2016-2017 The Thingsboard Authors |
3 | - * <p> | |
3 | + * | |
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | 5 | * you may not use this file except in compliance with the License. |
6 | 6 | * You may obtain a copy of the License at |
7 | - * <p> | |
8 | - * http://www.apache.org/licenses/LICENSE-2.0 | |
9 | - * <p> | |
7 | + * | |
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | |
9 | + * | |
10 | 10 | * Unless required by applicable law or agreed to in writing, software |
11 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
12 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ... | ... |
1 | 1 | /** |
2 | 2 | * Copyright © 2016-2017 The Thingsboard Authors |
3 | - * <p> | |
3 | + * | |
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | 5 | * you may not use this file except in compliance with the License. |
6 | 6 | * You may obtain a copy of the License at |
7 | - * <p> | |
8 | - * http://www.apache.org/licenses/LICENSE-2.0 | |
9 | - * <p> | |
7 | + * | |
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | |
9 | + * | |
10 | 10 | * Unless required by applicable law or agreed to in writing, software |
11 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
12 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ... | ... |
1 | +/** | |
2 | + * Copyright © 2016-2017 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 | + */ | |
1 | 16 | package org.thingsboard.server.dao.sql.widget; |
2 | 17 | |
3 | 18 | import org.springframework.beans.factory.annotation.Autowired; | ... | ... |
1 | +/** | |
2 | + * Copyright © 2016-2017 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 | + */ | |
1 | 16 | package org.thingsboard.server.dao.sql.widget; |
2 | 17 | |
3 | 18 | import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; | ... | ... |
1 | +/** | |
2 | + * Copyright © 2016-2017 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.dao.sql.plugin; | |
17 | + | |
18 | +import com.datastax.driver.core.utils.UUIDs; | |
19 | +import com.github.springtestdbunit.annotation.DatabaseSetup; | |
20 | +import org.junit.Test; | |
21 | +import org.springframework.beans.factory.annotation.Autowired; | |
22 | +import org.thingsboard.server.common.data.id.PluginId; | |
23 | +import org.thingsboard.server.common.data.id.TenantId; | |
24 | +import org.thingsboard.server.common.data.page.TextPageLink; | |
25 | +import org.thingsboard.server.common.data.plugin.PluginMetaData; | |
26 | +import org.thingsboard.server.common.data.rule.RuleMetaData; | |
27 | +import org.thingsboard.server.dao.AbstractJpaDaoTest; | |
28 | +import org.thingsboard.server.dao.plugin.PluginDao; | |
29 | + | |
30 | +import java.util.List; | |
31 | +import java.util.UUID; | |
32 | + | |
33 | +import static org.junit.Assert.assertEquals; | |
34 | + | |
35 | +/** | |
36 | + * Created by Valerii Sosliuk on 5/1/2017. | |
37 | + */ | |
38 | +public class JpaBasePluginDaoTest extends AbstractJpaDaoTest { | |
39 | + | |
40 | + @Autowired | |
41 | + private PluginDao pluginDao; | |
42 | + | |
43 | + @Test | |
44 | + @DatabaseSetup("classpath:dbunit/empty_dataset.xml") | |
45 | + public void testFindByTenantIdAndPageLink() { | |
46 | + UUID tenantId1 = UUIDs.timeBased(); | |
47 | + UUID tenantId2 = UUIDs.timeBased(); | |
48 | + createPluginsTwoTenants(tenantId1, tenantId2, "plugin_"); | |
49 | + assertEquals(60, pluginDao.find().size()); | |
50 | + List<PluginMetaData> rules1 = pluginDao.findByTenantIdAndPageLink( | |
51 | + new TenantId(tenantId1), new TextPageLink(20, "plugin_")); | |
52 | + assertEquals(20, rules1.size()); | |
53 | + | |
54 | + List<PluginMetaData> rules2 = pluginDao.findByTenantIdAndPageLink(new TenantId(tenantId1), | |
55 | + new TextPageLink(20, "plugin_", rules1.get(19).getId().getId(), null)); | |
56 | + assertEquals(10, rules2.size()); | |
57 | + | |
58 | + List<PluginMetaData> rules3 = pluginDao.findByTenantIdAndPageLink(new TenantId(tenantId1), | |
59 | + new TextPageLink(20, "plugin_", rules2.get(9).getId().getId(), null)); | |
60 | + assertEquals(0, rules3.size()); | |
61 | + } | |
62 | + | |
63 | + @Test | |
64 | + @DatabaseSetup("classpath:dbunit/empty_dataset.xml") | |
65 | + public void testFindAllTenantRulesByTenantId() { | |
66 | + UUID tenantId1 = UUIDs.timeBased(); | |
67 | + UUID tenantId2 = UUIDs.timeBased(); | |
68 | + createTenantsAndSystemPlugins(tenantId1, tenantId2, "name_"); | |
69 | + List<PluginMetaData> rules1 = pluginDao.findAllTenantPluginsByTenantId( | |
70 | + tenantId1, new TextPageLink(40, "name_")); | |
71 | + assertEquals(40, rules1.size()); | |
72 | + | |
73 | + List<PluginMetaData> rules2 = pluginDao.findAllTenantPluginsByTenantId(tenantId1, | |
74 | + new TextPageLink(40, "name_", rules1.get(39).getId().getId(), null)); | |
75 | + assertEquals(20, rules2.size()); | |
76 | + | |
77 | + List<PluginMetaData> rules3 = pluginDao.findAllTenantPluginsByTenantId(tenantId1, | |
78 | + new TextPageLink(40, "name_", rules2.get(19).getId().getId(), null)); | |
79 | + assertEquals(0, rules3.size()); | |
80 | + } | |
81 | + | |
82 | + private void createTenantsAndSystemPlugins(UUID tenantId1, UUID tenantId2, String namePrefix) { | |
83 | + for (int i = 0; i < 30; i++) { | |
84 | + createPlugin(tenantId1, namePrefix, i); | |
85 | + createPlugin(tenantId2, namePrefix, i); | |
86 | + createPlugin(null, namePrefix, i); | |
87 | + } | |
88 | + } | |
89 | + | |
90 | + private void createPluginsTwoTenants(UUID tenantId1, UUID tenantId2, String namePrefix) { | |
91 | + for (int i = 0; i < 30; i++) { | |
92 | + createPlugin(tenantId1, namePrefix, i); | |
93 | + createPlugin(tenantId2, namePrefix, i); | |
94 | + } | |
95 | + } | |
96 | + | |
97 | + private void createPlugin(UUID tenantId, String namePrefix, int i) { | |
98 | + PluginMetaData plugin = new PluginMetaData(); | |
99 | + plugin.setId(new PluginId(UUIDs.timeBased())); | |
100 | + plugin.setTenantId(new TenantId(tenantId)); | |
101 | + plugin.setName(namePrefix + i); | |
102 | + pluginDao.save(plugin); | |
103 | + } | |
104 | +} | ... | ... |
1 | +/** | |
2 | + * Copyright © 2016-2017 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.dao.sql.rule; | |
17 | + | |
18 | +import com.datastax.driver.core.utils.UUIDs; | |
19 | +import com.github.springtestdbunit.annotation.DatabaseSetup; | |
20 | +import org.junit.Test; | |
21 | +import org.springframework.beans.factory.annotation.Autowired; | |
22 | +import org.thingsboard.server.common.data.id.RuleId; | |
23 | +import org.thingsboard.server.common.data.id.TenantId; | |
24 | +import org.thingsboard.server.common.data.page.TextPageLink; | |
25 | +import org.thingsboard.server.common.data.rule.RuleMetaData; | |
26 | +import org.thingsboard.server.dao.AbstractJpaDaoTest; | |
27 | +import org.thingsboard.server.dao.rule.RuleDao; | |
28 | + | |
29 | +import java.util.List; | |
30 | +import java.util.UUID; | |
31 | + | |
32 | +import static org.junit.Assert.assertEquals; | |
33 | +import static org.junit.Assert.assertNotNull; | |
34 | + | |
35 | +/** | |
36 | + * Created by Valerii Sosliuk on 4/30/2017. | |
37 | + */ | |
38 | +public class JpaBaseRuleDaoTest extends AbstractJpaDaoTest { | |
39 | + | |
40 | + @Autowired | |
41 | + private RuleDao jpaBaseRuleDao; | |
42 | + | |
43 | + @Test | |
44 | + @DatabaseSetup("classpath:dbunit/rule.xml") | |
45 | + public void testFindRulesByPlugin() { | |
46 | + assertEquals(3, jpaBaseRuleDao.findRulesByPlugin("token_1").size()); | |
47 | + } | |
48 | + | |
49 | + @Test | |
50 | + @DatabaseSetup("classpath:dbunit/empty_dataset.xml") | |
51 | + public void testFindByTenantIdAndPageLink() { | |
52 | + UUID tenantId1 = UUIDs.timeBased(); | |
53 | + UUID tenantId2 = UUIDs.timeBased(); | |
54 | + createRulesTwoTenants(tenantId1, tenantId2, "name_", "token"); | |
55 | + List<RuleMetaData> rules1 = jpaBaseRuleDao.findByTenantIdAndPageLink( | |
56 | + new TenantId(tenantId1), new TextPageLink(20, "name_")); | |
57 | + assertEquals(20, rules1.size()); | |
58 | + | |
59 | + List<RuleMetaData> rules2 = jpaBaseRuleDao.findByTenantIdAndPageLink(new TenantId(tenantId1), | |
60 | + new TextPageLink(20, "name_", rules1.get(19).getId().getId(), null)); | |
61 | + assertEquals(10, rules2.size()); | |
62 | + | |
63 | + List<RuleMetaData> rules3 = jpaBaseRuleDao.findByTenantIdAndPageLink(new TenantId(tenantId1), | |
64 | + new TextPageLink(20, "name_", rules2.get(9).getId().getId(), null)); | |
65 | + assertEquals(0, rules3.size()); | |
66 | + } | |
67 | + | |
68 | + @Test | |
69 | + @DatabaseSetup("classpath:dbunit/empty_dataset.xml") | |
70 | + public void testFindAllTenantRulesByTenantId() { | |
71 | + UUID tenantId1 = UUIDs.timeBased(); | |
72 | + UUID tenantId2 = UUIDs.timeBased(); | |
73 | + createTenantsAndSystemRules(tenantId1, tenantId2, "name_", "token"); | |
74 | + List<RuleMetaData> rules1 = jpaBaseRuleDao.findAllTenantRulesByTenantId( | |
75 | + tenantId1, new TextPageLink(40, "name_")); | |
76 | + assertEquals(40, rules1.size()); | |
77 | + | |
78 | + List<RuleMetaData> rules2 = jpaBaseRuleDao.findAllTenantRulesByTenantId(tenantId1, | |
79 | + new TextPageLink(40, "name_", rules1.get(39).getId().getId(), null)); | |
80 | + assertEquals(20, rules2.size()); | |
81 | + | |
82 | + List<RuleMetaData> rules3 = jpaBaseRuleDao.findAllTenantRulesByTenantId(tenantId1, | |
83 | + new TextPageLink(40, "name_", rules2.get(19).getId().getId(), null)); | |
84 | + assertEquals(0, rules3.size()); | |
85 | + } | |
86 | + | |
87 | + private void createRulesTwoTenants(UUID tenantId1, UUID tenantId2, String namePrefix, String pluginToken) { | |
88 | + for (int i = 0; i < 30; i++) { | |
89 | + createRule(tenantId1, namePrefix, pluginToken, i); | |
90 | + createRule(tenantId2, namePrefix, pluginToken, i); | |
91 | + } | |
92 | + } | |
93 | + | |
94 | + private void createTenantsAndSystemRules(UUID tenantId1, UUID tenantId2, String namePrefix, String pluginToken) { | |
95 | + for (int i = 0; i < 30; i++) { | |
96 | + createRule(tenantId1, namePrefix, pluginToken, i); | |
97 | + createRule(tenantId2, namePrefix, pluginToken, i); | |
98 | + createRule(null, namePrefix, pluginToken, i); | |
99 | + } | |
100 | + } | |
101 | + | |
102 | + private void createRule(UUID tenantId, String namePrefix, String pluginToken, int i) { | |
103 | + RuleMetaData ruleMetaData = new RuleMetaData(); | |
104 | + ruleMetaData.setId(new RuleId(UUIDs.timeBased())); | |
105 | + ruleMetaData.setTenantId(new TenantId(tenantId)); | |
106 | + ruleMetaData.setName(namePrefix + i); | |
107 | + ruleMetaData.setPluginToken(pluginToken); | |
108 | + jpaBaseRuleDao.save(ruleMetaData); | |
109 | + } | |
110 | +} | ... | ... |
1 | +/** | |
2 | + * Copyright © 2016-2017 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 | + */ | |
1 | 16 | package org.thingsboard.server.dao.sql.tenant; |
2 | 17 | |
3 | 18 | import com.datastax.driver.core.utils.UUIDs; | ... | ... |
1 | +/** | |
2 | + * Copyright © 2016-2017 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 | + */ | |
1 | 16 | package org.thingsboard.server.dao.sql.widget; |
2 | 17 | |
3 | 18 | import com.datastax.driver.core.utils.UUIDs; | ... | ... |
dao/src/test/resources/dbunit/rule.xml
0 → 100644
1 | +<dataset> | |
2 | + <rule | |
3 | + id="uuid'8e834e11-2e0a-11e7-83ec-f7f6dbfb4833'" | |
4 | + tenant_id="uuid'8e834e10-2e0a-11e7-83ec-f7f6dbfb4833'" | |
5 | + name="RULE_11" | |
6 | + weight="1" | |
7 | + search_text="rule_11" | |
8 | + plugin_token="token_1" | |
9 | + /> | |
10 | + <rule | |
11 | + id="uuid'8e834e12-2e0a-11e7-83ec-f7f6dbfb4833'" | |
12 | + tenant_id="uuid'8e834e10-2e0a-11e7-83ec-f7f6dbfb4833'" | |
13 | + name="RULE_12" | |
14 | + weight="1" | |
15 | + search_text="rule_12" | |
16 | + plugin_token="token_1" | |
17 | + /> | |
18 | + <rule | |
19 | + id="uuid'8e834e13-2e0a-11e7-83ec-f7f6dbfb4833'" | |
20 | + tenant_id="uuid'8e834e10-2e0a-11e7-83ec-f7f6dbfb4833'" | |
21 | + name="RULE_13" | |
22 | + weight="1" | |
23 | + search_text="rule_13" | |
24 | + plugin_token="token_1" | |
25 | + /> | |
26 | + <rule | |
27 | + id="uuid'8e834e14-2e0a-11e7-83ec-f7f6dbfb4833'" | |
28 | + tenant_id="uuid'8e834e10-2e0a-11e7-83ec-f7f6dbfb4833'" | |
29 | + name="RULE_14" | |
30 | + weight="2" | |
31 | + search_text="rule_14" | |
32 | + plugin_token="token_2" | |
33 | + /> | |
34 | +</dataset> | |
\ No newline at end of file | ... | ... |