diff --git a/application/src/main/java/org/thingsboard/mqtt/broker/service/install/SqlDatabaseUpgradeService.java b/application/src/main/java/org/thingsboard/mqtt/broker/service/install/SqlDatabaseUpgradeService.java index f10b5718c..beaa47e9c 100644 --- a/application/src/main/java/org/thingsboard/mqtt/broker/service/install/SqlDatabaseUpgradeService.java +++ b/application/src/main/java/org/thingsboard/mqtt/broker/service/install/SqlDatabaseUpgradeService.java @@ -37,6 +37,7 @@ import java.sql.SQLException; import java.sql.SQLWarning; import java.sql.Statement; +import java.util.List; import java.util.concurrent.TimeUnit; import java.util.function.Consumer; import java.util.regex.Matcher; @@ -189,7 +190,16 @@ public void upgradeDatabase(String fromVersion) { } break; case "2.0.0": - updateSchema("2.0.0", 2000000, "2.0.1", 2000001); + updateSchema("2.0.0", 2000000, "2.0.1", 2000001, conn -> { + + for (String table : List.of("broker_user", "mqtt_client_credentials", "application_shared_subscription", "websocket_connection")) { + try { + conn.createStatement().execute("ALTER TABLE " + table + " DROP COLUMN IF EXISTS search_text"); + } catch (Exception ignored) { + } + } + + }); break; default: throw new RuntimeException("Unable to upgrade SQL database, unsupported fromVersion: " + fromVersion); diff --git a/application/src/main/java/org/thingsboard/mqtt/broker/service/install/update/DefaultCacheCleanupService.java b/application/src/main/java/org/thingsboard/mqtt/broker/service/install/update/DefaultCacheCleanupService.java index abe0cea34..12a2f540e 100644 --- a/application/src/main/java/org/thingsboard/mqtt/broker/service/install/update/DefaultCacheCleanupService.java +++ b/application/src/main/java/org/thingsboard/mqtt/broker/service/install/update/DefaultCacheCleanupService.java @@ -17,6 +17,7 @@ import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Value; import org.springframework.cache.Cache; import org.springframework.cache.CacheManager; import org.springframework.context.annotation.Profile; @@ -26,6 +27,11 @@ import java.util.Objects; import java.util.Optional; +import java.util.Set; + +import static org.thingsboard.mqtt.broker.cache.CacheConstants.BASIC_CREDENTIALS_PASSWORD_CACHE; +import static org.thingsboard.mqtt.broker.cache.CacheConstants.MQTT_CLIENT_CREDENTIALS_CACHE; +import static org.thingsboard.mqtt.broker.cache.CacheConstants.SSL_REGEX_BASED_CREDENTIALS_CACHE; @RequiredArgsConstructor @Service @@ -36,6 +42,9 @@ public class DefaultCacheCleanupService implements CacheCleanupService { private final CacheManager cacheManager; private final Optional> redisTemplate; + @Value("${cache.cache-prefix:}") + private String cachePrefix; + /** * Cleanup caches that can not deserialize anymore due to schema upgrade or data update using sql scripts. * Refer to SqlDatabaseUpgradeService and /data/upgrade/*.sql @@ -48,6 +57,20 @@ public void clearCache(String fromVersion) throws Exception { log.info("Clearing cache to upgrade from version 1.3.0 to 1.4.0"); clearAll(); break; + case "2.0.0": + log.info("Clearing cache to upgrade from version 2.0.0 to 2.0.1"); + + Set cacheNamesToFlush = Set.of( + cachePrefix + MQTT_CLIENT_CREDENTIALS_CACHE, + cachePrefix + BASIC_CREDENTIALS_PASSWORD_CACHE, + cachePrefix + SSL_REGEX_BASED_CREDENTIALS_CACHE); + + cacheManager.getCacheNames().forEach(cacheName -> { + if (cacheManager.getCache(cacheName) != null && cacheNamesToFlush.contains(cacheName)) { + clearCacheByName(cacheName); + } + }); + default: //Do nothing since cache cleanup is optional. } diff --git a/common/data/src/main/java/org/thingsboard/mqtt/broker/common/data/ApplicationSharedSubscription.java b/common/data/src/main/java/org/thingsboard/mqtt/broker/common/data/ApplicationSharedSubscription.java index 49c8b2463..f5f598501 100644 --- a/common/data/src/main/java/org/thingsboard/mqtt/broker/common/data/ApplicationSharedSubscription.java +++ b/common/data/src/main/java/org/thingsboard/mqtt/broker/common/data/ApplicationSharedSubscription.java @@ -26,7 +26,7 @@ @Data @ToString @EqualsAndHashCode(callSuper = true) -public class ApplicationSharedSubscription extends SearchTextBased { +public class ApplicationSharedSubscription extends BaseData { @Serial private static final long serialVersionUID = -3332462179399001894L; @@ -44,11 +44,6 @@ public ApplicationSharedSubscription(UUID id) { super(id); } - @Override - public String getSearchText() { - return getName(); - } - public ApplicationSharedSubscription(ApplicationSharedSubscription mqttClientCredentials) { super(mqttClientCredentials); this.name = mqttClientCredentials.getName(); diff --git a/common/data/src/main/java/org/thingsboard/mqtt/broker/common/data/BaseData.java b/common/data/src/main/java/org/thingsboard/mqtt/broker/common/data/BaseData.java index b67c49383..e7852aa86 100644 --- a/common/data/src/main/java/org/thingsboard/mqtt/broker/common/data/BaseData.java +++ b/common/data/src/main/java/org/thingsboard/mqtt/broker/common/data/BaseData.java @@ -15,6 +15,7 @@ */ package org.thingsboard.mqtt.broker.common.data; +import com.fasterxml.jackson.databind.ObjectMapper; import lombok.Getter; import lombok.Setter; import org.thingsboard.mqtt.broker.common.data.id.IdBased; @@ -26,6 +27,8 @@ @Setter public abstract class BaseData extends IdBased { + public static final ObjectMapper mapper = new ObjectMapper(); + @Serial private static final long serialVersionUID = 3948809716795694300L; diff --git a/common/data/src/main/java/org/thingsboard/mqtt/broker/common/data/SearchTextBasedWithAdditionalInfo.java b/common/data/src/main/java/org/thingsboard/mqtt/broker/common/data/BaseDataWithAdditionalInfo.java similarity index 72% rename from common/data/src/main/java/org/thingsboard/mqtt/broker/common/data/SearchTextBasedWithAdditionalInfo.java rename to common/data/src/main/java/org/thingsboard/mqtt/broker/common/data/BaseDataWithAdditionalInfo.java index a44587d26..0c820910e 100644 --- a/common/data/src/main/java/org/thingsboard/mqtt/broker/common/data/SearchTextBasedWithAdditionalInfo.java +++ b/common/data/src/main/java/org/thingsboard/mqtt/broker/common/data/BaseDataWithAdditionalInfo.java @@ -18,7 +18,7 @@ import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.node.ObjectNode; import lombok.extern.slf4j.Slf4j; import org.thingsboard.mqtt.broker.common.data.validation.NoXss; @@ -29,12 +29,12 @@ import java.util.Objects; import java.util.UUID; import java.util.function.Consumer; +import java.util.function.Function; import java.util.function.Supplier; @Slf4j -public abstract class SearchTextBasedWithAdditionalInfo extends SearchTextBased implements HasAdditionalInfo { +public abstract class BaseDataWithAdditionalInfo extends BaseData implements HasAdditionalInfo { - public static final ObjectMapper mapper = new ObjectMapper(); @Serial private static final long serialVersionUID = 1019819528913153295L; @@ -43,17 +43,17 @@ public abstract class SearchTextBasedWithAdditionalInfo extends SearchTextBased @JsonIgnore private byte[] additionalInfoBytes; - public SearchTextBasedWithAdditionalInfo() { + public BaseDataWithAdditionalInfo() { super(); } - public SearchTextBasedWithAdditionalInfo(UUID id) { + public BaseDataWithAdditionalInfo(UUID id) { super(id); } - public SearchTextBasedWithAdditionalInfo(SearchTextBasedWithAdditionalInfo searchTextBased) { - super(searchTextBased); - setAdditionalInfo(searchTextBased.getAdditionalInfo()); + public BaseDataWithAdditionalInfo(BaseDataWithAdditionalInfo baseData) { + super(baseData); + setAdditionalInfo(baseData.getAdditionalInfo()); } @Override @@ -65,12 +65,29 @@ public void setAdditionalInfo(JsonNode addInfo) { setJson(addInfo, json -> this.additionalInfo = json, bytes -> this.additionalInfoBytes = bytes); } + public void setAdditionalInfoField(String field, JsonNode value) { + JsonNode additionalInfo = getAdditionalInfo(); + if (!(additionalInfo instanceof ObjectNode)) { + additionalInfo = mapper.createObjectNode(); + } + ((ObjectNode) additionalInfo).set(field, value); + setAdditionalInfo(additionalInfo); + } + + public T getAdditionalInfoField(String field, Function mapper, T defaultValue) { + JsonNode additionalInfo = getAdditionalInfo(); + if (additionalInfo != null && additionalInfo.has(field)) { + return mapper.apply(additionalInfo.get(field)); + } + return defaultValue; + } + @Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; if (!super.equals(o)) return false; - SearchTextBasedWithAdditionalInfo that = (SearchTextBasedWithAdditionalInfo) o; + BaseDataWithAdditionalInfo that = (BaseDataWithAdditionalInfo) o; return Arrays.equals(additionalInfoBytes, that.additionalInfoBytes); } diff --git a/common/data/src/main/java/org/thingsboard/mqtt/broker/common/data/SearchTextBased.java b/common/data/src/main/java/org/thingsboard/mqtt/broker/common/data/SearchTextBased.java deleted file mode 100644 index 5b2c7b0f8..000000000 --- a/common/data/src/main/java/org/thingsboard/mqtt/broker/common/data/SearchTextBased.java +++ /dev/null @@ -1,43 +0,0 @@ -/** - * Copyright © 2016-2024 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.mqtt.broker.common.data; - -import com.fasterxml.jackson.annotation.JsonIgnore; - -import java.io.Serial; -import java.util.UUID; - -public abstract class SearchTextBased extends BaseData { - - @Serial - private static final long serialVersionUID = -539812997348227609L; - - public SearchTextBased() { - super(); - } - - public SearchTextBased(UUID id) { - super(id); - } - - public SearchTextBased(SearchTextBased searchTextBased) { - super(searchTextBased); - } - - @JsonIgnore - public abstract String getSearchText(); - -} diff --git a/common/data/src/main/java/org/thingsboard/mqtt/broker/common/data/User.java b/common/data/src/main/java/org/thingsboard/mqtt/broker/common/data/User.java index 2180ac223..3a4b4317d 100644 --- a/common/data/src/main/java/org/thingsboard/mqtt/broker/common/data/User.java +++ b/common/data/src/main/java/org/thingsboard/mqtt/broker/common/data/User.java @@ -24,24 +24,18 @@ import java.io.Serial; import java.util.UUID; +@Getter +@Setter @EqualsAndHashCode(callSuper = true) -public class User extends SearchTextBasedWithAdditionalInfo { +public class User extends BaseDataWithAdditionalInfo { @Serial private static final long serialVersionUID = 8250339805336035966L; - @Getter - @Setter private String email; - @Getter - @Setter private Authority authority; - @Getter - @Setter @NoXss private String firstName; - @Getter - @Setter @NoXss private String lastName; @@ -52,11 +46,6 @@ public User(UUID id) { super(id); } - @Override - public String getSearchText() { - return getEmail(); - } - public User(User user) { super(user); this.email = user.email; @@ -65,7 +54,6 @@ public User(User user) { this.lastName = user.lastName; } - @Override public String toString() { return "User [email=" + diff --git a/common/data/src/main/java/org/thingsboard/mqtt/broker/common/data/security/MqttClientCredentials.java b/common/data/src/main/java/org/thingsboard/mqtt/broker/common/data/security/MqttClientCredentials.java index f4e9d10ba..1f24cb8c9 100644 --- a/common/data/src/main/java/org/thingsboard/mqtt/broker/common/data/security/MqttClientCredentials.java +++ b/common/data/src/main/java/org/thingsboard/mqtt/broker/common/data/security/MqttClientCredentials.java @@ -18,8 +18,8 @@ import lombok.Data; import lombok.EqualsAndHashCode; import lombok.ToString; +import org.thingsboard.mqtt.broker.common.data.BaseData; import org.thingsboard.mqtt.broker.common.data.ClientType; -import org.thingsboard.mqtt.broker.common.data.SearchTextBased; import org.thingsboard.mqtt.broker.common.data.validation.NoXss; import java.io.Serial; @@ -28,7 +28,7 @@ @Data @ToString @EqualsAndHashCode(callSuper = true) -public class MqttClientCredentials extends SearchTextBased { +public class MqttClientCredentials extends BaseData { @Serial private static final long serialVersionUID = -8551302106113554112L; @@ -51,11 +51,6 @@ public MqttClientCredentials(UUID id) { super(id); } - @Override - public String getSearchText() { - return getName(); - } - public MqttClientCredentials(MqttClientCredentials mqttClientCredentials) { super(mqttClientCredentials); this.name = mqttClientCredentials.getName(); diff --git a/common/data/src/main/java/org/thingsboard/mqtt/broker/common/data/ws/WebSocketConnection.java b/common/data/src/main/java/org/thingsboard/mqtt/broker/common/data/ws/WebSocketConnection.java index 095547fcd..a01505710 100644 --- a/common/data/src/main/java/org/thingsboard/mqtt/broker/common/data/ws/WebSocketConnection.java +++ b/common/data/src/main/java/org/thingsboard/mqtt/broker/common/data/ws/WebSocketConnection.java @@ -21,7 +21,7 @@ import lombok.Data; import lombok.EqualsAndHashCode; import lombok.extern.slf4j.Slf4j; -import org.thingsboard.mqtt.broker.common.data.SearchTextBased; +import org.thingsboard.mqtt.broker.common.data.BaseData; import org.thingsboard.mqtt.broker.common.data.validation.NoXss; import java.io.ByteArrayInputStream; @@ -29,12 +29,10 @@ import java.io.Serial; import java.util.UUID; -import static org.thingsboard.mqtt.broker.common.data.SearchTextBasedWithAdditionalInfo.mapper; - @Data @EqualsAndHashCode(callSuper = true) @Slf4j -public class WebSocketConnection extends SearchTextBased { +public class WebSocketConnection extends BaseData { @Serial private static final long serialVersionUID = -2995421139460181824L; @@ -47,11 +45,6 @@ public class WebSocketConnection extends SearchTextBased { @JsonIgnore private byte[] configurationBytes; - @Override - public String getSearchText() { - return getName(); - } - public WebSocketConnectionConfiguration getConfiguration() { if (configuration != null) { return configuration; diff --git a/common/data/src/main/java/org/thingsboard/mqtt/broker/common/data/ws/WebSocketSubscription.java b/common/data/src/main/java/org/thingsboard/mqtt/broker/common/data/ws/WebSocketSubscription.java index 9a9174f09..83b73b981 100644 --- a/common/data/src/main/java/org/thingsboard/mqtt/broker/common/data/ws/WebSocketSubscription.java +++ b/common/data/src/main/java/org/thingsboard/mqtt/broker/common/data/ws/WebSocketSubscription.java @@ -28,8 +28,6 @@ import java.io.Serial; import java.util.UUID; -import static org.thingsboard.mqtt.broker.common.data.SearchTextBasedWithAdditionalInfo.mapper; - @Data @EqualsAndHashCode(callSuper = true) @Slf4j diff --git a/dao/src/main/java/org/thingsboard/mqtt/broker/dao/AbstractDao.java b/dao/src/main/java/org/thingsboard/mqtt/broker/dao/AbstractDao.java index 27f5bc5ec..ec4b4b888 100644 --- a/dao/src/main/java/org/thingsboard/mqtt/broker/dao/AbstractDao.java +++ b/dao/src/main/java/org/thingsboard/mqtt/broker/dao/AbstractDao.java @@ -35,9 +35,6 @@ public abstract class AbstractDao, D> protected abstract CrudRepository getCrudRepository(); - protected void setSearchText(E entity) { - } - @Override @Transactional public D save(D domain) { @@ -48,7 +45,6 @@ public D save(D domain) { log.error("Can't create entity for domain object {}", domain, e); throw new IllegalArgumentException("Can't create entity for domain object {" + domain + "}", e); } - setSearchText(entity); if (log.isDebugEnabled()) { log.debug("Saving entity {}", entity); } diff --git a/dao/src/main/java/org/thingsboard/mqtt/broker/dao/AbstractSearchTextDao.java b/dao/src/main/java/org/thingsboard/mqtt/broker/dao/AbstractSearchTextDao.java deleted file mode 100644 index 38acfedb1..000000000 --- a/dao/src/main/java/org/thingsboard/mqtt/broker/dao/AbstractSearchTextDao.java +++ /dev/null @@ -1,27 +0,0 @@ -/** - * Copyright © 2016-2024 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.mqtt.broker.dao; - -import org.thingsboard.mqtt.broker.dao.model.BaseEntity; -import org.thingsboard.mqtt.broker.dao.model.SearchTextEntity; - -public abstract class AbstractSearchTextDao, D> extends AbstractDao { - - @Override - protected void setSearchText(E entity) { - ((SearchTextEntity) entity).setSearchText(((SearchTextEntity) entity).getSearchTextSource().toLowerCase()); - } -} diff --git a/dao/src/main/java/org/thingsboard/mqtt/broker/dao/client/DefaultMqttClientCredentialsDao.java b/dao/src/main/java/org/thingsboard/mqtt/broker/dao/client/DefaultMqttClientCredentialsDao.java index 3b0294596..4ca6e3388 100644 --- a/dao/src/main/java/org/thingsboard/mqtt/broker/dao/client/DefaultMqttClientCredentialsDao.java +++ b/dao/src/main/java/org/thingsboard/mqtt/broker/dao/client/DefaultMqttClientCredentialsDao.java @@ -27,7 +27,7 @@ import org.thingsboard.mqtt.broker.common.data.page.PageLink; import org.thingsboard.mqtt.broker.common.data.security.ClientCredentialsType; import org.thingsboard.mqtt.broker.common.data.security.MqttClientCredentials; -import org.thingsboard.mqtt.broker.dao.AbstractSearchTextDao; +import org.thingsboard.mqtt.broker.dao.AbstractDao; import org.thingsboard.mqtt.broker.dao.DaoUtil; import org.thingsboard.mqtt.broker.dao.model.MqttClientCredentialsEntity; @@ -39,7 +39,7 @@ @Component @RequiredArgsConstructor @Slf4j -public class DefaultMqttClientCredentialsDao extends AbstractSearchTextDao +public class DefaultMqttClientCredentialsDao extends AbstractDao implements MqttClientCredentialsDao { private final MqttClientCredentialsRepository mqttClientCredentialsRepository; diff --git a/dao/src/main/java/org/thingsboard/mqtt/broker/dao/client/MqttClientCredentialsRepository.java b/dao/src/main/java/org/thingsboard/mqtt/broker/dao/client/MqttClientCredentialsRepository.java index 075bb594a..e4e03848b 100644 --- a/dao/src/main/java/org/thingsboard/mqtt/broker/dao/client/MqttClientCredentialsRepository.java +++ b/dao/src/main/java/org/thingsboard/mqtt/broker/dao/client/MqttClientCredentialsRepository.java @@ -38,7 +38,7 @@ public interface MqttClientCredentialsRepository extends JpaRepository findAll(@Param("textSearch") String textSearch, Pageable pageable); @@ -47,7 +47,7 @@ Page findAll(@Param("textSearch") String textSearch @Query("SELECT c FROM MqttClientCredentialsEntity c WHERE " + "((:clientTypes) IS NULL OR c.clientType IN (:clientTypes)) " + "AND ((:clientCredentialsTypes) IS NULL OR c.credentialsType IN (:clientCredentialsTypes)) " + - "AND LOWER(c.searchText) LIKE LOWER(CONCAT('%', :textSearch, '%')) " + + "AND LOWER(c.name) LIKE LOWER(CONCAT('%', :textSearch, '%')) " + "AND (" + // Return all credentials if all parameters are empty " (:certificateCn = '' AND :username = '' AND :clientId = '') " + diff --git a/dao/src/main/java/org/thingsboard/mqtt/broker/dao/client/application/ApplicationSharedSubscriptionDaoImpl.java b/dao/src/main/java/org/thingsboard/mqtt/broker/dao/client/application/ApplicationSharedSubscriptionDaoImpl.java index 091dc7db5..85c46c98a 100644 --- a/dao/src/main/java/org/thingsboard/mqtt/broker/dao/client/application/ApplicationSharedSubscriptionDaoImpl.java +++ b/dao/src/main/java/org/thingsboard/mqtt/broker/dao/client/application/ApplicationSharedSubscriptionDaoImpl.java @@ -22,7 +22,7 @@ import org.thingsboard.mqtt.broker.common.data.ApplicationSharedSubscription; import org.thingsboard.mqtt.broker.common.data.page.PageData; import org.thingsboard.mqtt.broker.common.data.page.PageLink; -import org.thingsboard.mqtt.broker.dao.AbstractSearchTextDao; +import org.thingsboard.mqtt.broker.dao.AbstractDao; import org.thingsboard.mqtt.broker.dao.DaoUtil; import org.thingsboard.mqtt.broker.dao.model.ApplicationSharedSubscriptionEntity; @@ -32,7 +32,7 @@ @Component @RequiredArgsConstructor public class ApplicationSharedSubscriptionDaoImpl - extends AbstractSearchTextDao + extends AbstractDao implements ApplicationSharedSubscriptionDao { private final ApplicationSharedSubscriptionRepository applicationSharedSubscriptionRepository; diff --git a/dao/src/main/java/org/thingsboard/mqtt/broker/dao/client/application/ApplicationSharedSubscriptionRepository.java b/dao/src/main/java/org/thingsboard/mqtt/broker/dao/client/application/ApplicationSharedSubscriptionRepository.java index 408b114c5..500e2d449 100644 --- a/dao/src/main/java/org/thingsboard/mqtt/broker/dao/client/application/ApplicationSharedSubscriptionRepository.java +++ b/dao/src/main/java/org/thingsboard/mqtt/broker/dao/client/application/ApplicationSharedSubscriptionRepository.java @@ -29,7 +29,7 @@ public interface ApplicationSharedSubscriptionRepository extends JpaRepository findAll(@Param("textSearch") String textSearch, Pageable pageable); } diff --git a/dao/src/main/java/org/thingsboard/mqtt/broker/dao/model/ApplicationSharedSubscriptionEntity.java b/dao/src/main/java/org/thingsboard/mqtt/broker/dao/model/ApplicationSharedSubscriptionEntity.java index 0d9a1b0ad..44f00c825 100644 --- a/dao/src/main/java/org/thingsboard/mqtt/broker/dao/model/ApplicationSharedSubscriptionEntity.java +++ b/dao/src/main/java/org/thingsboard/mqtt/broker/dao/model/ApplicationSharedSubscriptionEntity.java @@ -26,7 +26,7 @@ @EqualsAndHashCode(callSuper = true) @Entity @Table(name = ModelConstants.APPLICATION_SHARED_SUBSCRIPTION_COLUMN_FAMILY_NAME) -public class ApplicationSharedSubscriptionEntity extends BaseSqlEntity implements SearchTextEntity { +public class ApplicationSharedSubscriptionEntity extends BaseSqlEntity implements BaseEntity { @Column(name = ModelConstants.APPLICATION_SHARED_SUBSCRIPTION_TOPIC_PROPERTY, unique = true) private String topic; @@ -37,9 +37,6 @@ public class ApplicationSharedSubscriptionEntity extends BaseSqlEntity implements SearchTextEntity { +public class MqttClientCredentialsEntity extends BaseSqlEntity implements BaseEntity { @Column(name = ModelConstants.MQTT_CLIENT_CREDENTIALS_ID_PROPERTY, unique = true) private String credentialsId; @@ -49,9 +49,6 @@ public class MqttClientCredentialsEntity extends BaseSqlEntity extends BaseEntity { - - String getSearchTextSource(); - - void setSearchText(String searchText); - -} diff --git a/dao/src/main/java/org/thingsboard/mqtt/broker/dao/model/UserEntity.java b/dao/src/main/java/org/thingsboard/mqtt/broker/dao/model/UserEntity.java index da6dc97f9..e3c27a25c 100644 --- a/dao/src/main/java/org/thingsboard/mqtt/broker/dao/model/UserEntity.java +++ b/dao/src/main/java/org/thingsboard/mqtt/broker/dao/model/UserEntity.java @@ -32,7 +32,7 @@ @EqualsAndHashCode(callSuper = true) @Entity @Table(name = ModelConstants.USER_COLUMN_FAMILY_NAME) -public class UserEntity extends BaseSqlEntity implements SearchTextEntity { +public class UserEntity extends BaseSqlEntity implements BaseEntity { @Enumerated(EnumType.STRING) @Column(name = ModelConstants.USER_AUTHORITY_PROPERTY) @@ -41,9 +41,6 @@ public class UserEntity extends BaseSqlEntity implements SearchTextEntity< @Column(name = ModelConstants.USER_EMAIL_PROPERTY, unique = true) private String email; - @Column(name = ModelConstants.SEARCH_TEXT_PROPERTY) - private String searchText; - @Column(name = ModelConstants.USER_FIRST_NAME_PROPERTY) private String firstName; @@ -69,16 +66,6 @@ public UserEntity(User user) { this.additionalInfo = user.getAdditionalInfo(); } - @Override - public String getSearchTextSource() { - return email; - } - - @Override - public void setSearchText(String searchText) { - this.searchText = searchText; - } - @Override public User toData() { User user = new User(id); diff --git a/dao/src/main/java/org/thingsboard/mqtt/broker/dao/model/WebSocketConnectionEntity.java b/dao/src/main/java/org/thingsboard/mqtt/broker/dao/model/WebSocketConnectionEntity.java index e1a35196c..34c9503fc 100644 --- a/dao/src/main/java/org/thingsboard/mqtt/broker/dao/model/WebSocketConnectionEntity.java +++ b/dao/src/main/java/org/thingsboard/mqtt/broker/dao/model/WebSocketConnectionEntity.java @@ -37,7 +37,7 @@ @Entity @Table(name = ModelConstants.WEBSOCKET_CONNECTION_COLUMN_FAMILY_NAME) -public class WebSocketConnectionEntity extends BaseSqlEntity implements SearchTextEntity { +public class WebSocketConnectionEntity extends BaseSqlEntity implements BaseEntity { @Column(name = ModelConstants.WEBSOCKET_CONNECTION_NAME_PROPERTY) private String name; @@ -50,9 +50,6 @@ public class WebSocketConnectionEntity extends BaseSqlEntity implements UserDao { +public class DefaultUserDao extends AbstractDao implements UserDao { private final UserRepository userRepository; diff --git a/dao/src/main/java/org/thingsboard/mqtt/broker/dao/user/UserRepository.java b/dao/src/main/java/org/thingsboard/mqtt/broker/dao/user/UserRepository.java index 96a855d9d..9dadb9872 100644 --- a/dao/src/main/java/org/thingsboard/mqtt/broker/dao/user/UserRepository.java +++ b/dao/src/main/java/org/thingsboard/mqtt/broker/dao/user/UserRepository.java @@ -29,7 +29,7 @@ public interface UserRepository extends JpaRepository { UserEntity findByEmail(String email); @Query("SELECT u FROM UserEntity u WHERE " + - "LOWER(u.searchText) LIKE LOWER(CONCAT('%', :textSearch, '%'))") + "LOWER(u.email) LIKE LOWER(CONCAT('%', :textSearch, '%'))") Page findAll(@Param("textSearch") String textSearch, Pageable pageable); } diff --git a/dao/src/main/java/org/thingsboard/mqtt/broker/dao/ws/WebSocketConnectionDaoImpl.java b/dao/src/main/java/org/thingsboard/mqtt/broker/dao/ws/WebSocketConnectionDaoImpl.java index f46269cf9..ded0769d6 100644 --- a/dao/src/main/java/org/thingsboard/mqtt/broker/dao/ws/WebSocketConnectionDaoImpl.java +++ b/dao/src/main/java/org/thingsboard/mqtt/broker/dao/ws/WebSocketConnectionDaoImpl.java @@ -21,7 +21,7 @@ import org.thingsboard.mqtt.broker.common.data.page.PageData; import org.thingsboard.mqtt.broker.common.data.page.PageLink; import org.thingsboard.mqtt.broker.common.data.ws.WebSocketConnection; -import org.thingsboard.mqtt.broker.dao.AbstractSearchTextDao; +import org.thingsboard.mqtt.broker.dao.AbstractDao; import org.thingsboard.mqtt.broker.dao.DaoUtil; import org.thingsboard.mqtt.broker.dao.model.WebSocketConnectionEntity; @@ -31,7 +31,7 @@ @Component @RequiredArgsConstructor public class WebSocketConnectionDaoImpl - extends AbstractSearchTextDao + extends AbstractDao implements WebSocketConnectionDao { private final WebSocketConnectionRepository webSocketConnectionRepository; diff --git a/dao/src/main/java/org/thingsboard/mqtt/broker/dao/ws/WebSocketConnectionRepository.java b/dao/src/main/java/org/thingsboard/mqtt/broker/dao/ws/WebSocketConnectionRepository.java index abaca5ea2..89bf02453 100644 --- a/dao/src/main/java/org/thingsboard/mqtt/broker/dao/ws/WebSocketConnectionRepository.java +++ b/dao/src/main/java/org/thingsboard/mqtt/broker/dao/ws/WebSocketConnectionRepository.java @@ -27,7 +27,7 @@ public interface WebSocketConnectionRepository extends JpaRepository { @Query("SELECT w FROM WebSocketConnectionEntity w WHERE w.userId = :userId " + - "AND LOWER(w.searchText) LIKE LOWER(CONCAT('%', :textSearch, '%'))") + "AND LOWER(w.name) LIKE LOWER(CONCAT('%', :textSearch, '%'))") Page findAll(@Param("userId") UUID userId, @Param("textSearch") String textSearch, Pageable pageable); diff --git a/dao/src/main/resources/sql/schema-entities.sql b/dao/src/main/resources/sql/schema-entities.sql index 10c347b8c..91bf26ecf 100644 --- a/dao/src/main/resources/sql/schema-entities.sql +++ b/dao/src/main/resources/sql/schema-entities.sql @@ -48,8 +48,7 @@ CREATE TABLE IF NOT EXISTS broker_user ( authority varchar(255), email varchar(255) UNIQUE, first_name varchar(255), - last_name varchar(255), - search_text varchar(255) + last_name varchar(255) ); CREATE TABLE IF NOT EXISTS user_credentials ( @@ -70,7 +69,6 @@ CREATE TABLE IF NOT EXISTS mqtt_client_credentials ( credentials_id varchar, credentials_type varchar(255), credentials_value varchar, - search_text varchar(255), CONSTRAINT mqtt_client_credentials_id_unq_key UNIQUE (credentials_id) ); @@ -93,7 +91,6 @@ CREATE TABLE IF NOT EXISTS application_shared_subscription ( topic varchar NOT NULL, partitions int NOT NULL, name varchar(255), - search_text varchar(255), CONSTRAINT application_shared_subscription_topic_unq_key UNIQUE (topic) ); @@ -125,7 +122,6 @@ CREATE TABLE IF NOT EXISTS websocket_connection ( name varchar (255) NOT NULL, user_id uuid NOT NULL, configuration jsonb, - search_text varchar (255), CONSTRAINT name_unq_key UNIQUE (user_id, name), CONSTRAINT fk_user_id FOREIGN KEY (user_id) REFERENCES broker_user (id) ON DELETE CASCADE