Browse Source

Add scada field to widgets bundles and widget types.

pull/11391/head
Igor Kulikov 2 years ago
parent
commit
00800f36f0
  1. 32
      application/src/main/data/upgrade/3.7.0/schema_update.sql
  2. 17
      application/src/main/java/org/thingsboard/server/controller/WidgetsBundleController.java
  3. 7
      common/dao-api/src/main/java/org/thingsboard/server/dao/widget/WidgetsBundleService.java
  4. 4
      common/data/src/main/java/org/thingsboard/server/common/data/widget/BaseWidgetType.java
  5. 6
      common/data/src/main/java/org/thingsboard/server/common/data/widget/WidgetsBundle.java
  6. 38
      common/data/src/main/java/org/thingsboard/server/common/data/widget/WidgetsBundleFilter.java
  7. 3
      dao/src/main/java/org/thingsboard/server/dao/model/ModelConstants.java
  8. 11
      dao/src/main/java/org/thingsboard/server/dao/model/sql/AbstractWidgetTypeEntity.java
  9. 11
      dao/src/main/java/org/thingsboard/server/dao/model/sql/WidgetsBundleEntity.java
  10. 18
      dao/src/main/java/org/thingsboard/server/dao/sql/widget/JpaWidgetsBundleDao.java
  11. 7
      dao/src/main/java/org/thingsboard/server/dao/sql/widget/WidgetsBundleRepository.java
  12. 7
      dao/src/main/java/org/thingsboard/server/dao/widget/WidgetsBundleDao.java
  13. 25
      dao/src/main/java/org/thingsboard/server/dao/widget/WidgetsBundleServiceImpl.java
  14. 2
      dao/src/main/resources/sql/schema-entities.sql
  15. 9
      dao/src/test/java/org/thingsboard/server/dao/service/WidgetsBundleServiceTest.java
  16. 41
      dao/src/test/java/org/thingsboard/server/dao/sql/widget/JpaWidgetsBundleDaoTest.java
  17. 2
      dao/src/test/resources/sql-test.properties

32
application/src/main/data/upgrade/3.7.0/schema_update.sql

@ -30,3 +30,35 @@ $$
$$; $$;
-- UPDATE RESOURCE SUB TYPE END -- UPDATE RESOURCE SUB TYPE END
-- UPDATE WIDGETS BUNDLE START
DO
$$
BEGIN
IF NOT EXISTS (
SELECT FROM information_schema.columns
WHERE table_name = 'widgets_bundle' AND column_name = 'scada'
) THEN
ALTER TABLE widgets_bundle ADD COLUMN scada boolean NOT NULL DEFAULT false;
END IF;
END;
$$;
-- UPDATE WIDGETS BUNDLE END
-- UPDATE WIDGET TYPE START
DO
$$
BEGIN
IF NOT EXISTS (
SELECT FROM information_schema.columns
WHERE table_name = 'widget_type' AND column_name = 'scada'
) THEN
ALTER TABLE widget_type ADD COLUMN scada boolean NOT NULL DEFAULT false;
END IF;
END;
$$;
-- UPDATE WIDGET TYPE END

17
application/src/main/java/org/thingsboard/server/controller/WidgetsBundleController.java

@ -36,6 +36,7 @@ import org.thingsboard.server.common.data.page.PageData;
import org.thingsboard.server.common.data.page.PageLink; import org.thingsboard.server.common.data.page.PageLink;
import org.thingsboard.server.common.data.security.Authority; import org.thingsboard.server.common.data.security.Authority;
import org.thingsboard.server.common.data.widget.WidgetsBundle; import org.thingsboard.server.common.data.widget.WidgetsBundle;
import org.thingsboard.server.common.data.widget.WidgetsBundleFilter;
import org.thingsboard.server.dao.resource.ImageService; import org.thingsboard.server.dao.resource.ImageService;
import org.thingsboard.server.config.annotations.ApiOperation; import org.thingsboard.server.config.annotations.ApiOperation;
import org.thingsboard.server.queue.util.TbCoreComponent; import org.thingsboard.server.queue.util.TbCoreComponent;
@ -72,6 +73,7 @@ public class WidgetsBundleController extends BaseController {
private static final String WIDGET_BUNDLE_DESCRIPTION = "Widget Bundle represents a group(bundle) of widgets. Widgets are grouped into bundle by type or use case. "; private static final String WIDGET_BUNDLE_DESCRIPTION = "Widget Bundle represents a group(bundle) of widgets. Widgets are grouped into bundle by type or use case. ";
private static final String FULL_SEARCH_PARAM_DESCRIPTION = "Optional boolean parameter indicating extended search of widget bundles by description and by name / description of related widget types"; private static final String FULL_SEARCH_PARAM_DESCRIPTION = "Optional boolean parameter indicating extended search of widget bundles by description and by name / description of related widget types";
private static final String SCADA_FIRST_PARAM_DESCRIPTION = "Optional boolean parameter indicating whether to fetch widgets bundles with SCADA symbols first. Works only when fullSearch parameter is enabled";
private static final String TENANT_BUNDLES_ONLY_DESCRIPTION = "Optional boolean parameter to include only tenant-level bundles without system"; private static final String TENANT_BUNDLES_ONLY_DESCRIPTION = "Optional boolean parameter to include only tenant-level bundles without system";
@ApiOperation(value = "Get Widget Bundle (getWidgetsBundleById)", @ApiOperation(value = "Get Widget Bundle (getWidgetsBundleById)",
@ -198,16 +200,23 @@ public class WidgetsBundleController extends BaseController {
@Parameter(description = TENANT_BUNDLES_ONLY_DESCRIPTION) @Parameter(description = TENANT_BUNDLES_ONLY_DESCRIPTION)
@RequestParam(required = false) Boolean tenantOnly, @RequestParam(required = false) Boolean tenantOnly,
@Parameter(description = FULL_SEARCH_PARAM_DESCRIPTION) @Parameter(description = FULL_SEARCH_PARAM_DESCRIPTION)
@RequestParam(required = false) Boolean fullSearch) throws ThingsboardException { @RequestParam(required = false) Boolean fullSearch,
@Parameter(description = SCADA_FIRST_PARAM_DESCRIPTION)
@RequestParam(required = false) Boolean scadaFirst) throws ThingsboardException {
PageLink pageLink = createPageLink(pageSize, page, textSearch, sortProperty, sortOrder); PageLink pageLink = createPageLink(pageSize, page, textSearch, sortProperty, sortOrder);
WidgetsBundleFilter widgetsBundleFilter = WidgetsBundleFilter.builder()
.tenantId(getTenantId())
.fullSearch(fullSearch != null && fullSearch)
.scadaFirst(scadaFirst != null && scadaFirst)
.build();
if (Authority.SYS_ADMIN.equals(getCurrentUser().getAuthority())) { if (Authority.SYS_ADMIN.equals(getCurrentUser().getAuthority())) {
return checkNotNull(widgetsBundleService.findSystemWidgetsBundlesByPageLink(getTenantId(), fullSearch != null && fullSearch, pageLink)); return checkNotNull(widgetsBundleService.findSystemWidgetsBundlesByPageLink(widgetsBundleFilter, pageLink));
} else { } else {
TenantId tenantId = getCurrentUser().getTenantId(); TenantId tenantId = getCurrentUser().getTenantId();
if (tenantOnly != null && tenantOnly) { if (tenantOnly != null && tenantOnly) {
return checkNotNull(widgetsBundleService.findTenantWidgetsBundlesByTenantIdAndPageLink(tenantId, fullSearch != null && fullSearch, pageLink)); return checkNotNull(widgetsBundleService.findTenantWidgetsBundlesByTenantIdAndPageLink(widgetsBundleFilter, pageLink));
} else { } else {
return checkNotNull(widgetsBundleService.findAllTenantWidgetsBundlesByTenantIdAndPageLink(tenantId, fullSearch != null && fullSearch, pageLink)); return checkNotNull(widgetsBundleService.findAllTenantWidgetsBundlesByTenantIdAndPageLink(widgetsBundleFilter, pageLink));
} }
} }
} }

7
common/dao-api/src/main/java/org/thingsboard/server/dao/widget/WidgetsBundleService.java

@ -20,6 +20,7 @@ import org.thingsboard.server.common.data.id.WidgetsBundleId;
import org.thingsboard.server.common.data.page.PageData; import org.thingsboard.server.common.data.page.PageData;
import org.thingsboard.server.common.data.page.PageLink; import org.thingsboard.server.common.data.page.PageLink;
import org.thingsboard.server.common.data.widget.WidgetsBundle; import org.thingsboard.server.common.data.widget.WidgetsBundle;
import org.thingsboard.server.common.data.widget.WidgetsBundleFilter;
import org.thingsboard.server.dao.entity.EntityDaoService; import org.thingsboard.server.dao.entity.EntityDaoService;
import java.util.List; import java.util.List;
@ -34,15 +35,15 @@ public interface WidgetsBundleService extends EntityDaoService {
WidgetsBundle findWidgetsBundleByTenantIdAndAlias(TenantId tenantId, String alias); WidgetsBundle findWidgetsBundleByTenantIdAndAlias(TenantId tenantId, String alias);
PageData<WidgetsBundle> findSystemWidgetsBundlesByPageLink(TenantId tenantId, boolean fullSearch, PageLink pageLink); PageData<WidgetsBundle> findSystemWidgetsBundlesByPageLink(WidgetsBundleFilter widgetsBundleFilter, PageLink pageLink);
List<WidgetsBundle> findSystemWidgetsBundles(TenantId tenantId); List<WidgetsBundle> findSystemWidgetsBundles(TenantId tenantId);
PageData<WidgetsBundle> findTenantWidgetsBundlesByTenantId(TenantId tenantId, PageLink pageLink); PageData<WidgetsBundle> findTenantWidgetsBundlesByTenantId(TenantId tenantId, PageLink pageLink);
PageData<WidgetsBundle> findAllTenantWidgetsBundlesByTenantIdAndPageLink(TenantId tenantId, boolean fullSearch, PageLink pageLink); PageData<WidgetsBundle> findAllTenantWidgetsBundlesByTenantIdAndPageLink(WidgetsBundleFilter widgetsBundleFilter, PageLink pageLink);
PageData<WidgetsBundle> findTenantWidgetsBundlesByTenantIdAndPageLink(TenantId tenantId, boolean fullSearch, PageLink pageLink); PageData<WidgetsBundle> findTenantWidgetsBundlesByTenantIdAndPageLink(WidgetsBundleFilter widgetsBundleFilter, PageLink pageLink);
List<WidgetsBundle> findAllTenantWidgetsBundlesByTenantId(TenantId tenantId); List<WidgetsBundle> findAllTenantWidgetsBundlesByTenantId(TenantId tenantId);

4
common/data/src/main/java/org/thingsboard/server/common/data/widget/BaseWidgetType.java

@ -44,6 +44,9 @@ public class BaseWidgetType extends BaseData<WidgetTypeId> implements HasName, H
@Schema(description = "Whether widget type is deprecated.", example = "true") @Schema(description = "Whether widget type is deprecated.", example = "true")
private boolean deprecated; private boolean deprecated;
@Schema(description = "Whether widget type is SCADA symbol.", example = "true")
private boolean scada;
public BaseWidgetType() { public BaseWidgetType() {
super(); super();
} }
@ -58,6 +61,7 @@ public class BaseWidgetType extends BaseData<WidgetTypeId> implements HasName, H
this.fqn = widgetType.getFqn(); this.fqn = widgetType.getFqn();
this.name = widgetType.getName(); this.name = widgetType.getName();
this.deprecated = widgetType.isDeprecated(); this.deprecated = widgetType.isDeprecated();
this.scada = widgetType.isScada();
} }
@Schema(description = "JSON object with the Widget Type Id. " + @Schema(description = "JSON object with the Widget Type Id. " +

6
common/data/src/main/java/org/thingsboard/server/common/data/widget/WidgetsBundle.java

@ -61,6 +61,11 @@ public class WidgetsBundle extends BaseData<WidgetsBundleId> implements HasName,
@Schema(description = "Relative or external image URL. Replaced with image data URL (Base64) in case of relative URL and 'inlineImages' option enabled.", accessMode = Schema.AccessMode.READ_ONLY) @Schema(description = "Relative or external image URL. Replaced with image data URL (Base64) in case of relative URL and 'inlineImages' option enabled.", accessMode = Schema.AccessMode.READ_ONLY)
private String image; private String image;
@Getter
@Setter
@Schema(description = "Whether widgets bundle contains SCADA symbol widget types.", accessMode = Schema.AccessMode.READ_ONLY)
private boolean scada;
@NoXss @NoXss
@Length(fieldName = "description", max = 1024) @Length(fieldName = "description", max = 1024)
@Getter @Getter
@ -91,6 +96,7 @@ public class WidgetsBundle extends BaseData<WidgetsBundleId> implements HasName,
this.alias = widgetsBundle.getAlias(); this.alias = widgetsBundle.getAlias();
this.title = widgetsBundle.getTitle(); this.title = widgetsBundle.getTitle();
this.image = widgetsBundle.getImage(); this.image = widgetsBundle.getImage();
this.scada = widgetsBundle.isScada();
this.description = widgetsBundle.getDescription(); this.description = widgetsBundle.getDescription();
this.order = widgetsBundle.getOrder(); this.order = widgetsBundle.getOrder();
this.externalId = widgetsBundle.getExternalId(); this.externalId = widgetsBundle.getExternalId();

38
common/data/src/main/java/org/thingsboard/server/common/data/widget/WidgetsBundleFilter.java

@ -0,0 +1,38 @@
/**
* 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.server.common.data.widget;
import lombok.Builder;
import lombok.Data;
import org.thingsboard.server.common.data.id.TenantId;
@Data
@Builder
public class WidgetsBundleFilter {
private TenantId tenantId;
private boolean fullSearch;
private boolean scadaFirst;
public static WidgetsBundleFilter fromTenantId(TenantId tenantId) {
return WidgetsBundleFilter.builder().tenantId(tenantId).fullSearch(false).scadaFirst(false).build();
}
public static WidgetsBundleFilter fullSearchFromTenantId(TenantId tenantId) {
return WidgetsBundleFilter.builder().tenantId(tenantId).fullSearch(true).scadaFirst(false).build();
}
}

3
dao/src/main/java/org/thingsboard/server/dao/model/ModelConstants.java

@ -302,6 +302,7 @@ public class ModelConstants {
public static final String WIDGETS_BUNDLE_ALIAS_PROPERTY = ALIAS_PROPERTY; public static final String WIDGETS_BUNDLE_ALIAS_PROPERTY = ALIAS_PROPERTY;
public static final String WIDGETS_BUNDLE_TITLE_PROPERTY = TITLE_PROPERTY; public static final String WIDGETS_BUNDLE_TITLE_PROPERTY = TITLE_PROPERTY;
public static final String WIDGETS_BUNDLE_IMAGE_PROPERTY = "image"; public static final String WIDGETS_BUNDLE_IMAGE_PROPERTY = "image";
public static final String WIDGETS_BUNDLE_SCADA_PROPERTY = "scada";
public static final String WIDGETS_BUNDLE_DESCRIPTION = "description"; public static final String WIDGETS_BUNDLE_DESCRIPTION = "description";
public static final String WIDGETS_BUNDLE_ORDER = "widgets_bundle_order"; public static final String WIDGETS_BUNDLE_ORDER = "widgets_bundle_order";
@ -320,6 +321,8 @@ public class ModelConstants {
public static final String WIDGET_TYPE_DEPRECATED_PROPERTY = "deprecated"; public static final String WIDGET_TYPE_DEPRECATED_PROPERTY = "deprecated";
public static final String WIDGET_TYPE_SCADA_PROPERTY = "scada";
public static final String WIDGET_TYPE_WIDGET_TYPE_PROPERTY = "widget_type"; public static final String WIDGET_TYPE_WIDGET_TYPE_PROPERTY = "widget_type";
public static final String WIDGET_TYPE_INFO_VIEW_TABLE_NAME = "widget_type_info_view"; public static final String WIDGET_TYPE_INFO_VIEW_TABLE_NAME = "widget_type_info_view";

11
dao/src/main/java/org/thingsboard/server/dao/model/sql/AbstractWidgetTypeEntity.java

@ -15,17 +15,16 @@
*/ */
package org.thingsboard.server.dao.model.sql; package org.thingsboard.server.dao.model.sql;
import jakarta.persistence.Column;
import jakarta.persistence.MappedSuperclass;
import lombok.Data; import lombok.Data;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;
import org.thingsboard.server.common.data.id.TenantId; import org.thingsboard.server.common.data.id.TenantId;
import org.thingsboard.server.common.data.id.WidgetTypeId; import org.thingsboard.server.common.data.id.WidgetTypeId;
import org.thingsboard.server.common.data.widget.BaseWidgetType; import org.thingsboard.server.common.data.widget.BaseWidgetType;
import org.thingsboard.server.dao.model.BaseEntity;
import org.thingsboard.server.dao.model.BaseSqlEntity; import org.thingsboard.server.dao.model.BaseSqlEntity;
import org.thingsboard.server.dao.model.ModelConstants; import org.thingsboard.server.dao.model.ModelConstants;
import jakarta.persistence.Column;
import jakarta.persistence.MappedSuperclass;
import java.util.UUID; import java.util.UUID;
@Data @Data
@ -45,6 +44,9 @@ public abstract class AbstractWidgetTypeEntity<T extends BaseWidgetType> extends
@Column(name = ModelConstants.WIDGET_TYPE_DEPRECATED_PROPERTY) @Column(name = ModelConstants.WIDGET_TYPE_DEPRECATED_PROPERTY)
private boolean deprecated; private boolean deprecated;
@Column(name = ModelConstants.WIDGET_TYPE_SCADA_PROPERTY)
private boolean scada;
public AbstractWidgetTypeEntity() { public AbstractWidgetTypeEntity() {
super(); super();
} }
@ -60,6 +62,7 @@ public abstract class AbstractWidgetTypeEntity<T extends BaseWidgetType> extends
this.fqn = widgetType.getFqn(); this.fqn = widgetType.getFqn();
this.name = widgetType.getName(); this.name = widgetType.getName();
this.deprecated = widgetType.isDeprecated(); this.deprecated = widgetType.isDeprecated();
this.scada = widgetType.isScada();
} }
public AbstractWidgetTypeEntity(AbstractWidgetTypeEntity widgetTypeEntity) { public AbstractWidgetTypeEntity(AbstractWidgetTypeEntity widgetTypeEntity) {
@ -69,6 +72,7 @@ public abstract class AbstractWidgetTypeEntity<T extends BaseWidgetType> extends
this.fqn = widgetTypeEntity.getFqn(); this.fqn = widgetTypeEntity.getFqn();
this.name = widgetTypeEntity.getName(); this.name = widgetTypeEntity.getName();
this.deprecated = widgetTypeEntity.isDeprecated(); this.deprecated = widgetTypeEntity.isDeprecated();
this.scada = widgetTypeEntity.isScada();
} }
protected BaseWidgetType toBaseWidgetType() { protected BaseWidgetType toBaseWidgetType() {
@ -80,6 +84,7 @@ public abstract class AbstractWidgetTypeEntity<T extends BaseWidgetType> extends
widgetType.setFqn(fqn); widgetType.setFqn(fqn);
widgetType.setName(name); widgetType.setName(name);
widgetType.setDeprecated(deprecated); widgetType.setDeprecated(deprecated);
widgetType.setScada(scada);
return widgetType; return widgetType;
} }

11
dao/src/main/java/org/thingsboard/server/dao/model/sql/WidgetsBundleEntity.java

@ -16,6 +16,9 @@
package org.thingsboard.server.dao.model.sql; package org.thingsboard.server.dao.model.sql;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.Table;
import lombok.Data; import lombok.Data;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;
import org.thingsboard.server.common.data.id.TenantId; import org.thingsboard.server.common.data.id.TenantId;
@ -24,9 +27,6 @@ import org.thingsboard.server.common.data.widget.WidgetsBundle;
import org.thingsboard.server.dao.model.BaseSqlEntity; import org.thingsboard.server.dao.model.BaseSqlEntity;
import org.thingsboard.server.dao.model.ModelConstants; import org.thingsboard.server.dao.model.ModelConstants;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.Table;
import java.util.UUID; import java.util.UUID;
@Data @Data
@ -47,6 +47,9 @@ public final class WidgetsBundleEntity extends BaseSqlEntity<WidgetsBundle> {
@Column(name = ModelConstants.WIDGETS_BUNDLE_IMAGE_PROPERTY) @Column(name = ModelConstants.WIDGETS_BUNDLE_IMAGE_PROPERTY)
private String image; private String image;
@Column(name = ModelConstants.WIDGETS_BUNDLE_SCADA_PROPERTY)
private boolean scada;
@Column(name = ModelConstants.WIDGETS_BUNDLE_DESCRIPTION) @Column(name = ModelConstants.WIDGETS_BUNDLE_DESCRIPTION)
private String description; private String description;
@ -71,6 +74,7 @@ public final class WidgetsBundleEntity extends BaseSqlEntity<WidgetsBundle> {
this.alias = widgetsBundle.getAlias(); this.alias = widgetsBundle.getAlias();
this.title = widgetsBundle.getTitle(); this.title = widgetsBundle.getTitle();
this.image = widgetsBundle.getImage(); this.image = widgetsBundle.getImage();
this.scada = widgetsBundle.isScada();
this.description = widgetsBundle.getDescription(); this.description = widgetsBundle.getDescription();
this.order = widgetsBundle.getOrder(); this.order = widgetsBundle.getOrder();
if (widgetsBundle.getExternalId() != null) { if (widgetsBundle.getExternalId() != null) {
@ -88,6 +92,7 @@ public final class WidgetsBundleEntity extends BaseSqlEntity<WidgetsBundle> {
widgetsBundle.setAlias(alias); widgetsBundle.setAlias(alias);
widgetsBundle.setTitle(title); widgetsBundle.setTitle(title);
widgetsBundle.setImage(image); widgetsBundle.setImage(image);
widgetsBundle.setScada(scada);
widgetsBundle.setDescription(description); widgetsBundle.setDescription(description);
widgetsBundle.setOrder(order); widgetsBundle.setOrder(order);
if (externalId != null) { if (externalId != null) {

18
dao/src/main/java/org/thingsboard/server/dao/sql/widget/JpaWidgetsBundleDao.java

@ -24,6 +24,7 @@ import org.thingsboard.server.common.data.id.WidgetsBundleId;
import org.thingsboard.server.common.data.page.PageData; import org.thingsboard.server.common.data.page.PageData;
import org.thingsboard.server.common.data.page.PageLink; import org.thingsboard.server.common.data.page.PageLink;
import org.thingsboard.server.common.data.widget.WidgetsBundle; import org.thingsboard.server.common.data.widget.WidgetsBundle;
import org.thingsboard.server.common.data.widget.WidgetsBundleFilter;
import org.thingsboard.server.dao.DaoUtil; import org.thingsboard.server.dao.DaoUtil;
import org.thingsboard.server.dao.model.sql.WidgetsBundleEntity; import org.thingsboard.server.dao.model.sql.WidgetsBundleEntity;
import org.thingsboard.server.dao.sql.JpaAbstractDao; import org.thingsboard.server.dao.sql.JpaAbstractDao;
@ -64,8 +65,8 @@ public class JpaWidgetsBundleDao extends JpaAbstractDao<WidgetsBundleEntity, Wid
} }
@Override @Override
public PageData<WidgetsBundle> findSystemWidgetsBundles(TenantId tenantId, boolean fullSearch, PageLink pageLink) { public PageData<WidgetsBundle> findSystemWidgetsBundles(WidgetsBundleFilter widgetsBundleFilter, PageLink pageLink) {
if (fullSearch) { if (widgetsBundleFilter.isFullSearch()) {
return DaoUtil.toPageData( return DaoUtil.toPageData(
widgetsBundleRepository widgetsBundleRepository
.findSystemWidgetsBundlesFullSearch( .findSystemWidgetsBundlesFullSearch(
@ -93,13 +94,13 @@ public class JpaWidgetsBundleDao extends JpaAbstractDao<WidgetsBundleEntity, Wid
} }
@Override @Override
public PageData<WidgetsBundle> findAllTenantWidgetsBundlesByTenantId(UUID tenantId, boolean fullSearch, PageLink pageLink) { public PageData<WidgetsBundle> findAllTenantWidgetsBundlesByTenantId(WidgetsBundleFilter widgetsBundleFilter, PageLink pageLink) {
return findTenantWidgetsBundlesByTenantIds(Arrays.asList(tenantId, NULL_UUID), fullSearch, pageLink); return findTenantWidgetsBundlesByTenantIds(Arrays.asList(widgetsBundleFilter.getTenantId().getId(), NULL_UUID), widgetsBundleFilter, pageLink);
} }
@Override @Override
public PageData<WidgetsBundle> findTenantWidgetsBundlesByTenantId(UUID tenantId, boolean fullSearch, PageLink pageLink) { public PageData<WidgetsBundle> findTenantWidgetsBundlesByTenantId(WidgetsBundleFilter widgetsBundleFilter, PageLink pageLink) {
return findTenantWidgetsBundlesByTenantIds(Collections.singletonList(tenantId), fullSearch, pageLink); return findTenantWidgetsBundlesByTenantIds(Collections.singletonList(widgetsBundleFilter.getTenantId().getId()), widgetsBundleFilter, pageLink);
} }
@Override @Override
@ -107,13 +108,14 @@ public class JpaWidgetsBundleDao extends JpaAbstractDao<WidgetsBundleEntity, Wid
return DaoUtil.toPageData(widgetsBundleRepository.findAll(DaoUtil.toPageable(pageLink))); return DaoUtil.toPageData(widgetsBundleRepository.findAll(DaoUtil.toPageable(pageLink)));
} }
private PageData<WidgetsBundle> findTenantWidgetsBundlesByTenantIds(List<UUID> tenantIds, boolean fullSearch, PageLink pageLink) { private PageData<WidgetsBundle> findTenantWidgetsBundlesByTenantIds(List<UUID> tenantIds, WidgetsBundleFilter widgetsBundleFilter, PageLink pageLink) {
if (fullSearch) { if (widgetsBundleFilter.isFullSearch()) {
return DaoUtil.toPageData( return DaoUtil.toPageData(
widgetsBundleRepository widgetsBundleRepository
.findAllTenantWidgetsBundlesByTenantIdsFullSearch( .findAllTenantWidgetsBundlesByTenantIdsFullSearch(
tenantIds, tenantIds,
pageLink.getTextSearch(), pageLink.getTextSearch(),
widgetsBundleFilter.isScadaFirst(),
DaoUtil.toPageable(pageLink))); DaoUtil.toPageable(pageLink)));
} else { } else {
return DaoUtil.toPageData( return DaoUtil.toPageData(

7
dao/src/main/java/org/thingsboard/server/dao/sql/widget/WidgetsBundleRepository.java

@ -107,7 +107,7 @@ public interface WidgetsBundleRepository extends JpaRepository<WidgetsBundleEnti
"OR :textSearch ILIKE '% ' || currentTag " + "OR :textSearch ILIKE '% ' || currentTag " +
"OR :textSearch ILIKE '% ' || currentTag || ' %')" + "OR :textSearch ILIKE '% ' || currentTag || ' %')" +
")))) " + ")))) " +
"ORDER BY wb.widgets_bundle_order ASC NULLS LAST", "ORDER BY CASE WHEN :scadaFirst then wb.scada END ASC, wb.widgets_bundle_order ASC NULLS LAST",
countQuery = "SELECT count(*) FROM widgets_bundle wb WHERE wb.tenant_id IN (:tenantIds) " + countQuery = "SELECT count(*) FROM widgets_bundle wb WHERE wb.tenant_id IN (:tenantIds) " +
"AND (:textSearch IS NULL OR wb.title ILIKE CONCAT('%', :textSearch, '%') " + "AND (:textSearch IS NULL OR wb.title ILIKE CONCAT('%', :textSearch, '%') " +
"OR wb.description ILIKE CONCAT('%', :textSearch, '%') " + "OR wb.description ILIKE CONCAT('%', :textSearch, '%') " +
@ -126,8 +126,9 @@ public interface WidgetsBundleRepository extends JpaRepository<WidgetsBundleEnti
"))))" "))))"
) )
Page<WidgetsBundleEntity> findAllTenantWidgetsBundlesByTenantIdsFullSearch(@Param("tenantIds") List<UUID> tenantIds, Page<WidgetsBundleEntity> findAllTenantWidgetsBundlesByTenantIdsFullSearch(@Param("tenantIds") List<UUID> tenantIds,
@Param("textSearch") String textSearch, @Param("textSearch") String textSearch,
Pageable pageable); @Param("scadaFirst") boolean scadaFirst,
Pageable pageable);
WidgetsBundleEntity findFirstByTenantIdAndTitle(UUID tenantId, String title); WidgetsBundleEntity findFirstByTenantIdAndTitle(UUID tenantId, String title);

7
dao/src/main/java/org/thingsboard/server/dao/widget/WidgetsBundleDao.java

@ -21,6 +21,7 @@ import org.thingsboard.server.common.data.id.WidgetsBundleId;
import org.thingsboard.server.common.data.page.PageData; import org.thingsboard.server.common.data.page.PageData;
import org.thingsboard.server.common.data.page.PageLink; import org.thingsboard.server.common.data.page.PageLink;
import org.thingsboard.server.common.data.widget.WidgetsBundle; import org.thingsboard.server.common.data.widget.WidgetsBundle;
import org.thingsboard.server.common.data.widget.WidgetsBundleFilter;
import org.thingsboard.server.dao.Dao; import org.thingsboard.server.dao.Dao;
import org.thingsboard.server.dao.ExportableEntityDao; import org.thingsboard.server.dao.ExportableEntityDao;
import org.thingsboard.server.dao.ImageContainerDao; import org.thingsboard.server.dao.ImageContainerDao;
@ -56,7 +57,7 @@ public interface WidgetsBundleDao extends Dao<WidgetsBundle>, ExportableEntityDa
* @param pageLink the page link * @param pageLink the page link
* @return the list of widgets bundles objects * @return the list of widgets bundles objects
*/ */
PageData<WidgetsBundle> findSystemWidgetsBundles(TenantId tenantId, boolean fullSearch, PageLink pageLink); PageData<WidgetsBundle> findSystemWidgetsBundles(WidgetsBundleFilter widgetsBundleFilter, PageLink pageLink);
/** /**
* Find tenant widgets bundles by tenantId and page link. * Find tenant widgets bundles by tenantId and page link.
@ -74,7 +75,7 @@ public interface WidgetsBundleDao extends Dao<WidgetsBundle>, ExportableEntityDa
* @param pageLink the page link * @param pageLink the page link
* @return the list of widgets bundles objects * @return the list of widgets bundles objects
*/ */
PageData<WidgetsBundle> findAllTenantWidgetsBundlesByTenantId(UUID tenantId, boolean fullSearch, PageLink pageLink); PageData<WidgetsBundle> findAllTenantWidgetsBundlesByTenantId(WidgetsBundleFilter widgetsBundleFilter, PageLink pageLink);
/** /**
* Find all tenant widgets bundles (does not include system) by tenantId and page link. * Find all tenant widgets bundles (does not include system) by tenantId and page link.
@ -83,7 +84,7 @@ public interface WidgetsBundleDao extends Dao<WidgetsBundle>, ExportableEntityDa
* @param pageLink the page link * @param pageLink the page link
* @return the list of widgets bundles objects * @return the list of widgets bundles objects
*/ */
PageData<WidgetsBundle> findTenantWidgetsBundlesByTenantId(UUID tenantId, boolean fullSearch, PageLink pageLink); PageData<WidgetsBundle> findTenantWidgetsBundlesByTenantId(WidgetsBundleFilter widgetsBundleFilter, PageLink pageLink);
PageData<WidgetsBundle> findAllWidgetsBundles(PageLink pageLink); PageData<WidgetsBundle> findAllWidgetsBundles(PageLink pageLink);

25
dao/src/main/java/org/thingsboard/server/dao/widget/WidgetsBundleServiceImpl.java

@ -27,6 +27,7 @@ import org.thingsboard.server.common.data.id.WidgetsBundleId;
import org.thingsboard.server.common.data.page.PageData; import org.thingsboard.server.common.data.page.PageData;
import org.thingsboard.server.common.data.page.PageLink; import org.thingsboard.server.common.data.page.PageLink;
import org.thingsboard.server.common.data.widget.WidgetsBundle; import org.thingsboard.server.common.data.widget.WidgetsBundle;
import org.thingsboard.server.common.data.widget.WidgetsBundleFilter;
import org.thingsboard.server.dao.entity.AbstractCachedEntityService; import org.thingsboard.server.dao.entity.AbstractCachedEntityService;
import org.thingsboard.server.dao.eventsourcing.DeleteEntityEvent; import org.thingsboard.server.dao.eventsourcing.DeleteEntityEvent;
import org.thingsboard.server.dao.eventsourcing.SaveEntityEvent; import org.thingsboard.server.dao.eventsourcing.SaveEntityEvent;
@ -118,10 +119,10 @@ public class WidgetsBundleServiceImpl implements WidgetsBundleService {
} }
@Override @Override
public PageData<WidgetsBundle> findSystemWidgetsBundlesByPageLink(TenantId tenantId, boolean fullSearch, PageLink pageLink) { public PageData<WidgetsBundle> findSystemWidgetsBundlesByPageLink(WidgetsBundleFilter widgetsBundleFilter, PageLink pageLink) {
log.trace("Executing findSystemWidgetsBundles, fullSearch [{}], pageLink [{}]", fullSearch, pageLink); log.trace("Executing findSystemWidgetsBundles, widgetsBundleFilter [{}], pageLink [{}]", widgetsBundleFilter, pageLink);
Validator.validatePageLink(pageLink); Validator.validatePageLink(pageLink);
return widgetsBundleDao.findSystemWidgetsBundles(tenantId, fullSearch, pageLink); return widgetsBundleDao.findSystemWidgetsBundles(widgetsBundleFilter, pageLink);
} }
@Override @Override
@ -131,7 +132,7 @@ public class WidgetsBundleServiceImpl implements WidgetsBundleService {
PageLink pageLink = new PageLink(DEFAULT_WIDGETS_BUNDLE_LIMIT); PageLink pageLink = new PageLink(DEFAULT_WIDGETS_BUNDLE_LIMIT);
PageData<WidgetsBundle> pageData; PageData<WidgetsBundle> pageData;
do { do {
pageData = findSystemWidgetsBundlesByPageLink(tenantId, false, pageLink); pageData = findSystemWidgetsBundlesByPageLink(WidgetsBundleFilter.fromTenantId(tenantId), pageLink);
widgetsBundles.addAll(pageData.getData()); widgetsBundles.addAll(pageData.getData());
if (pageData.hasNext()) { if (pageData.hasNext()) {
pageLink = pageLink.nextPageLink(); pageLink = pageLink.nextPageLink();
@ -149,19 +150,21 @@ public class WidgetsBundleServiceImpl implements WidgetsBundleService {
} }
@Override @Override
public PageData<WidgetsBundle> findAllTenantWidgetsBundlesByTenantIdAndPageLink(TenantId tenantId, boolean fullSearch, PageLink pageLink) { public PageData<WidgetsBundle> findAllTenantWidgetsBundlesByTenantIdAndPageLink(WidgetsBundleFilter widgetsBundleFilter, PageLink pageLink) {
log.trace("Executing findAllTenantWidgetsBundlesByTenantIdAndPageLink, tenantId [{}], fullSearch [{}], pageLink [{}]", tenantId, fullSearch, pageLink); TenantId tenantId = widgetsBundleFilter.getTenantId();
log.trace("Executing findAllTenantWidgetsBundlesByTenantIdAndPageLink, tenantId [{}], pageLink [{}]", tenantId, pageLink);
Validator.validateId(tenantId, id -> INCORRECT_TENANT_ID + id); Validator.validateId(tenantId, id -> INCORRECT_TENANT_ID + id);
Validator.validatePageLink(pageLink); Validator.validatePageLink(pageLink);
return widgetsBundleDao.findAllTenantWidgetsBundlesByTenantId(tenantId.getId(), fullSearch, pageLink); return widgetsBundleDao.findAllTenantWidgetsBundlesByTenantId(widgetsBundleFilter, pageLink);
} }
@Override @Override
public PageData<WidgetsBundle> findTenantWidgetsBundlesByTenantIdAndPageLink(TenantId tenantId, boolean fullSearch, PageLink pageLink) { public PageData<WidgetsBundle> findTenantWidgetsBundlesByTenantIdAndPageLink(WidgetsBundleFilter widgetsBundleFilter, PageLink pageLink) {
log.trace("Executing findTenantWidgetsBundlesByTenantIdAndPageLink, tenantId [{}], fullSearch [{}], pageLink [{}]", tenantId, fullSearch, pageLink); TenantId tenantId = widgetsBundleFilter.getTenantId();
log.trace("Executing findTenantWidgetsBundlesByTenantIdAndPageLink, tenantId [{}], pageLink [{}]", tenantId, pageLink);
Validator.validateId(tenantId, id -> INCORRECT_TENANT_ID + id); Validator.validateId(tenantId, id -> INCORRECT_TENANT_ID + id);
Validator.validatePageLink(pageLink); Validator.validatePageLink(pageLink);
return widgetsBundleDao.findTenantWidgetsBundlesByTenantId(tenantId.getId(), fullSearch, pageLink); return widgetsBundleDao.findTenantWidgetsBundlesByTenantId(widgetsBundleFilter, pageLink);
} }
@Override @Override
@ -172,7 +175,7 @@ public class WidgetsBundleServiceImpl implements WidgetsBundleService {
PageLink pageLink = new PageLink(DEFAULT_WIDGETS_BUNDLE_LIMIT); PageLink pageLink = new PageLink(DEFAULT_WIDGETS_BUNDLE_LIMIT);
PageData<WidgetsBundle> pageData; PageData<WidgetsBundle> pageData;
do { do {
pageData = findAllTenantWidgetsBundlesByTenantIdAndPageLink(tenantId, false, pageLink); pageData = findAllTenantWidgetsBundlesByTenantIdAndPageLink(WidgetsBundleFilter.fromTenantId(tenantId), pageLink);
widgetsBundles.addAll(pageData.getData()); widgetsBundles.addAll(pageData.getData());
if (pageData.hasNext()) { if (pageData.hasNext()) {
pageLink = pageLink.nextPageLink(); pageLink = pageLink.nextPageLink();

2
dao/src/main/resources/sql/schema-entities.sql

@ -490,6 +490,7 @@ CREATE TABLE IF NOT EXISTS widget_type (
name varchar(255), name varchar(255),
tenant_id uuid, tenant_id uuid,
image varchar(1000000), image varchar(1000000),
scada boolean NOT NULL DEFAULT false,
deprecated boolean NOT NULL DEFAULT false, deprecated boolean NOT NULL DEFAULT false,
description varchar(1024), description varchar(1024),
tags text[], tags text[],
@ -505,6 +506,7 @@ CREATE TABLE IF NOT EXISTS widgets_bundle (
tenant_id uuid, tenant_id uuid,
title varchar(255), title varchar(255),
image varchar(1000000), image varchar(1000000),
scada boolean NOT NULL DEFAULT false,
description varchar(1024), description varchar(1024),
widgets_bundle_order int, widgets_bundle_order int,
external_id uuid, external_id uuid,

9
dao/src/test/java/org/thingsboard/server/dao/service/WidgetsBundleServiceTest.java

@ -24,6 +24,7 @@ import org.thingsboard.server.common.data.id.TenantId;
import org.thingsboard.server.common.data.page.PageData; import org.thingsboard.server.common.data.page.PageData;
import org.thingsboard.server.common.data.page.PageLink; import org.thingsboard.server.common.data.page.PageLink;
import org.thingsboard.server.common.data.widget.WidgetsBundle; import org.thingsboard.server.common.data.widget.WidgetsBundle;
import org.thingsboard.server.common.data.widget.WidgetsBundleFilter;
import org.thingsboard.server.dao.exception.DataValidationException; import org.thingsboard.server.dao.exception.DataValidationException;
import org.thingsboard.server.dao.model.ModelConstants; import org.thingsboard.server.dao.model.ModelConstants;
import org.thingsboard.server.dao.widget.WidgetsBundleService; import org.thingsboard.server.dao.widget.WidgetsBundleService;
@ -174,7 +175,7 @@ public class WidgetsBundleServiceTest extends AbstractServiceTest {
PageLink pageLink = new PageLink(19); PageLink pageLink = new PageLink(19);
PageData<WidgetsBundle> pageData = null; PageData<WidgetsBundle> pageData = null;
do { do {
pageData = widgetsBundleService.findSystemWidgetsBundlesByPageLink(tenantId, false, pageLink); pageData = widgetsBundleService.findSystemWidgetsBundlesByPageLink(WidgetsBundleFilter.fromTenantId(tenantId), pageLink);
loadedWidgetsBundles.addAll(pageData.getData()); loadedWidgetsBundles.addAll(pageData.getData());
if (pageData.hasNext()) { if (pageData.hasNext()) {
pageLink = pageLink.nextPageLink(); pageLink = pageLink.nextPageLink();
@ -297,7 +298,7 @@ public class WidgetsBundleServiceTest extends AbstractServiceTest {
PageLink pageLink = new PageLink(17); PageLink pageLink = new PageLink(17);
PageData<WidgetsBundle> pageData = null; PageData<WidgetsBundle> pageData = null;
do { do {
pageData = widgetsBundleService.findAllTenantWidgetsBundlesByTenantIdAndPageLink(tenantId, false, pageLink); pageData = widgetsBundleService.findAllTenantWidgetsBundlesByTenantIdAndPageLink(WidgetsBundleFilter.fromTenantId(tenantId), pageLink);
loadedWidgetsBundles.addAll(pageData.getData()); loadedWidgetsBundles.addAll(pageData.getData());
if (pageData.hasNext()) { if (pageData.hasNext()) {
pageLink = pageLink.nextPageLink(); pageLink = pageLink.nextPageLink();
@ -314,7 +315,7 @@ public class WidgetsBundleServiceTest extends AbstractServiceTest {
loadedWidgetsBundles.clear(); loadedWidgetsBundles.clear();
pageLink = new PageLink(14); pageLink = new PageLink(14);
do { do {
pageData = widgetsBundleService.findAllTenantWidgetsBundlesByTenantIdAndPageLink(tenantId, false, pageLink); pageData = widgetsBundleService.findAllTenantWidgetsBundlesByTenantIdAndPageLink(WidgetsBundleFilter.fromTenantId(tenantId), pageLink);
loadedWidgetsBundles.addAll(pageData.getData()); loadedWidgetsBundles.addAll(pageData.getData());
if (pageData.hasNext()) { if (pageData.hasNext()) {
pageLink = pageLink.nextPageLink(); pageLink = pageLink.nextPageLink();
@ -336,7 +337,7 @@ public class WidgetsBundleServiceTest extends AbstractServiceTest {
loadedWidgetsBundles.clear(); loadedWidgetsBundles.clear();
pageLink = new PageLink(18); pageLink = new PageLink(18);
do { do {
pageData = widgetsBundleService.findAllTenantWidgetsBundlesByTenantIdAndPageLink(tenantId, false, pageLink); pageData = widgetsBundleService.findAllTenantWidgetsBundlesByTenantIdAndPageLink(WidgetsBundleFilter.fromTenantId(tenantId), pageLink);
loadedWidgetsBundles.addAll(pageData.getData()); loadedWidgetsBundles.addAll(pageData.getData());
if (pageData.hasNext()) { if (pageData.hasNext()) {
pageLink = pageLink.nextPageLink(); pageLink = pageLink.nextPageLink();

41
dao/src/test/java/org/thingsboard/server/dao/sql/widget/JpaWidgetsBundleDaoTest.java

@ -28,6 +28,7 @@ import org.thingsboard.server.common.data.page.SortOrder;
import org.thingsboard.server.common.data.widget.WidgetType; import org.thingsboard.server.common.data.widget.WidgetType;
import org.thingsboard.server.common.data.widget.WidgetTypeDetails; import org.thingsboard.server.common.data.widget.WidgetTypeDetails;
import org.thingsboard.server.common.data.widget.WidgetsBundle; import org.thingsboard.server.common.data.widget.WidgetsBundle;
import org.thingsboard.server.common.data.widget.WidgetsBundleFilter;
import org.thingsboard.server.common.data.widget.WidgetsBundleWidget; import org.thingsboard.server.common.data.widget.WidgetsBundleWidget;
import org.thingsboard.server.dao.AbstractJpaDaoTest; import org.thingsboard.server.dao.AbstractJpaDaoTest;
import org.thingsboard.server.dao.widget.WidgetTypeDao; import org.thingsboard.server.dao.widget.WidgetTypeDao;
@ -113,11 +114,11 @@ public class JpaWidgetsBundleDaoTest extends AbstractJpaDaoTest {
assertEquals(30, widgetsBundles.size()); assertEquals(30, widgetsBundles.size());
// Get first page // Get first page
PageLink pageLink = new PageLink(10, 0, "WB"); PageLink pageLink = new PageLink(10, 0, "WB");
PageData<WidgetsBundle> widgetsBundles1 = widgetsBundleDao.findSystemWidgetsBundles(TenantId.SYS_TENANT_ID, false, pageLink); PageData<WidgetsBundle> widgetsBundles1 = widgetsBundleDao.findSystemWidgetsBundles(WidgetsBundleFilter.fromTenantId(TenantId.SYS_TENANT_ID), pageLink);
assertEquals(10, widgetsBundles1.getData().size()); assertEquals(10, widgetsBundles1.getData().size());
// Get next page // Get next page
pageLink = pageLink.nextPageLink(); pageLink = pageLink.nextPageLink();
PageData<WidgetsBundle> widgetsBundles2 = widgetsBundleDao.findSystemWidgetsBundles(TenantId.SYS_TENANT_ID, false, pageLink); PageData<WidgetsBundle> widgetsBundles2 = widgetsBundleDao.findSystemWidgetsBundles(WidgetsBundleFilter.fromTenantId(TenantId.SYS_TENANT_ID), pageLink);
assertEquals(10, widgetsBundles2.getData().size()); assertEquals(10, widgetsBundles2.getData().size());
} }
@ -142,19 +143,19 @@ public class JpaWidgetsBundleDaoTest extends AbstractJpaDaoTest {
widgetTypeDao.saveWidgetsBundleWidget(new WidgetsBundleWidget(widgetsBundle3.getId(), widgetType2.getId(), 1)); widgetTypeDao.saveWidgetsBundleWidget(new WidgetsBundleWidget(widgetsBundle3.getId(), widgetType2.getId(), 1));
PageLink pageLink = new PageLink(10, 0, "widget type 1", new SortOrder("title")); PageLink pageLink = new PageLink(10, 0, "widget type 1", new SortOrder("title"));
PageData<WidgetsBundle> widgetsBundles1 = widgetsBundleDao.findSystemWidgetsBundles(TenantId.SYS_TENANT_ID, true, pageLink); PageData<WidgetsBundle> widgetsBundles1 = widgetsBundleDao.findSystemWidgetsBundles(WidgetsBundleFilter.fullSearchFromTenantId(TenantId.SYS_TENANT_ID), pageLink);
assertEquals(2, widgetsBundles1.getData().size()); assertEquals(2, widgetsBundles1.getData().size());
assertEquals(widgetsBundle1, widgetsBundles1.getData().get(0)); assertEquals(widgetsBundle1, widgetsBundles1.getData().get(0));
assertEquals(widgetsBundle3, widgetsBundles1.getData().get(1)); assertEquals(widgetsBundle3, widgetsBundles1.getData().get(1));
pageLink = new PageLink(10, 0, "Test widget type 2", new SortOrder("title")); pageLink = new PageLink(10, 0, "Test widget type 2", new SortOrder("title"));
PageData<WidgetsBundle> widgetsBundles2 = widgetsBundleDao.findSystemWidgetsBundles(TenantId.SYS_TENANT_ID, true, pageLink); PageData<WidgetsBundle> widgetsBundles2 = widgetsBundleDao.findSystemWidgetsBundles(WidgetsBundleFilter.fullSearchFromTenantId(TenantId.SYS_TENANT_ID), pageLink);
assertEquals(2, widgetsBundles2.getData().size()); assertEquals(2, widgetsBundles2.getData().size());
assertEquals(widgetsBundle2, widgetsBundles2.getData().get(0)); assertEquals(widgetsBundle2, widgetsBundles2.getData().get(0));
assertEquals(widgetsBundle3, widgetsBundles2.getData().get(1)); assertEquals(widgetsBundle3, widgetsBundles2.getData().get(1));
pageLink = new PageLink(10, 0, "ppp Fd v TAG1 tt", new SortOrder("title")); pageLink = new PageLink(10, 0, "ppp Fd v TAG1 tt", new SortOrder("title"));
PageData<WidgetsBundle> widgetsBundles3 = widgetsBundleDao.findSystemWidgetsBundles(TenantId.SYS_TENANT_ID, true, pageLink); PageData<WidgetsBundle> widgetsBundles3 = widgetsBundleDao.findSystemWidgetsBundles(WidgetsBundleFilter.fullSearchFromTenantId(TenantId.SYS_TENANT_ID), pageLink);
assertEquals(2, widgetsBundles3.getData().size()); assertEquals(2, widgetsBundles3.getData().size());
assertEquals(widgetsBundle1, widgetsBundles3.getData().get(0)); assertEquals(widgetsBundle1, widgetsBundles3.getData().get(0));
assertEquals(widgetsBundle3, widgetsBundles3.getData().get(1)); assertEquals(widgetsBundle3, widgetsBundles3.getData().get(1));
@ -171,7 +172,7 @@ public class JpaWidgetsBundleDaoTest extends AbstractJpaDaoTest {
widgetTypeDao.saveWidgetsBundleWidget(new WidgetsBundleWidget(systemWidgetBundle.getId(), widgetType.getId(), 0)); widgetTypeDao.saveWidgetsBundleWidget(new WidgetsBundleWidget(systemWidgetBundle.getId(), widgetType.getId(), 0));
PageData<WidgetsBundle> widgetTypes = widgetsBundleDao.findSystemWidgetsBundles( PageData<WidgetsBundle> widgetTypes = widgetsBundleDao.findSystemWidgetsBundles(
TenantId.SYS_TENANT_ID, true, new PageLink(10, 0, searchText) WidgetsBundleFilter.fullSearchFromTenantId(TenantId.SYS_TENANT_ID), new PageLink(10, 0, searchText)
); );
assertThat(widgetTypes.getData()).hasSize(1); assertThat(widgetTypes.getData()).hasSize(1);
@ -191,7 +192,7 @@ public class JpaWidgetsBundleDaoTest extends AbstractJpaDaoTest {
widgetTypeDao.saveWidgetsBundleWidget(new WidgetsBundleWidget(systemWidgetBundle.getId(), widgetType.getId(), 0)); widgetTypeDao.saveWidgetsBundleWidget(new WidgetsBundleWidget(systemWidgetBundle.getId(), widgetType.getId(), 0));
PageData<WidgetsBundle> widgetTypes = widgetsBundleDao.findSystemWidgetsBundles( PageData<WidgetsBundle> widgetTypes = widgetsBundleDao.findSystemWidgetsBundles(
TenantId.SYS_TENANT_ID, true, new PageLink(10, 0, searchText) WidgetsBundleFilter.fullSearchFromTenantId(TenantId.SYS_TENANT_ID), new PageLink(10, 0, searchText)
); );
assertThat(widgetTypes.getData()).hasSize(0); assertThat(widgetTypes.getData()).hasSize(0);
@ -245,19 +246,19 @@ public class JpaWidgetsBundleDaoTest extends AbstractJpaDaoTest {
assertEquals(100, widgetsBundleDao.find(TenantId.SYS_TENANT_ID).size()); assertEquals(100, widgetsBundleDao.find(TenantId.SYS_TENANT_ID).size());
PageLink pageLink = new PageLink(30, 0, "WB"); PageLink pageLink = new PageLink(30, 0, "WB");
PageData<WidgetsBundle> widgetsBundles1 = widgetsBundleDao.findAllTenantWidgetsBundlesByTenantId(tenantId1, false, pageLink); PageData<WidgetsBundle> widgetsBundles1 = widgetsBundleDao.findAllTenantWidgetsBundlesByTenantId(WidgetsBundleFilter.fromTenantId(TenantId.fromUUID(tenantId1)), pageLink);
assertEquals(30, widgetsBundles1.getData().size()); assertEquals(30, widgetsBundles1.getData().size());
pageLink = pageLink.nextPageLink(); pageLink = pageLink.nextPageLink();
PageData<WidgetsBundle> widgetsBundles2 = widgetsBundleDao.findAllTenantWidgetsBundlesByTenantId(tenantId1, false, pageLink); PageData<WidgetsBundle> widgetsBundles2 = widgetsBundleDao.findAllTenantWidgetsBundlesByTenantId(WidgetsBundleFilter.fromTenantId(TenantId.fromUUID(tenantId1)), pageLink);
assertEquals(30, widgetsBundles2.getData().size()); assertEquals(30, widgetsBundles2.getData().size());
pageLink = pageLink.nextPageLink(); pageLink = pageLink.nextPageLink();
PageData<WidgetsBundle> widgetsBundles3 = widgetsBundleDao.findAllTenantWidgetsBundlesByTenantId(tenantId1, false, pageLink); PageData<WidgetsBundle> widgetsBundles3 = widgetsBundleDao.findAllTenantWidgetsBundlesByTenantId(WidgetsBundleFilter.fromTenantId(TenantId.fromUUID(tenantId1)), pageLink);
assertEquals(10, widgetsBundles3.getData().size()); assertEquals(10, widgetsBundles3.getData().size());
pageLink = pageLink.nextPageLink(); pageLink = pageLink.nextPageLink();
PageData<WidgetsBundle> widgetsBundles4 = widgetsBundleDao.findAllTenantWidgetsBundlesByTenantId(tenantId1, false, pageLink); PageData<WidgetsBundle> widgetsBundles4 = widgetsBundleDao.findAllTenantWidgetsBundlesByTenantId(WidgetsBundleFilter.fromTenantId(TenantId.fromUUID(tenantId1)), pageLink);
assertEquals(0, widgetsBundles4.getData().size()); assertEquals(0, widgetsBundles4.getData().size());
} }
@ -287,25 +288,25 @@ public class JpaWidgetsBundleDaoTest extends AbstractJpaDaoTest {
widgetTypeDao.saveWidgetsBundleWidget(new WidgetsBundleWidget(widgetsBundle3.getId(), widgetType2.getId(), 1)); widgetTypeDao.saveWidgetsBundleWidget(new WidgetsBundleWidget(widgetsBundle3.getId(), widgetType2.getId(), 1));
PageLink pageLink = new PageLink(10, 0, "widget type 1", new SortOrder("title")); PageLink pageLink = new PageLink(10, 0, "widget type 1", new SortOrder("title"));
PageData<WidgetsBundle> widgetsBundles1 = widgetsBundleDao.findAllTenantWidgetsBundlesByTenantId(tenantId1, true, pageLink); PageData<WidgetsBundle> widgetsBundles1 = widgetsBundleDao.findAllTenantWidgetsBundlesByTenantId(WidgetsBundleFilter.fullSearchFromTenantId(TenantId.fromUUID(tenantId1)), pageLink);
assertEquals(1, widgetsBundles1.getData().size()); assertEquals(1, widgetsBundles1.getData().size());
assertEquals(widgetsBundle1, widgetsBundles1.getData().get(0)); assertEquals(widgetsBundle1, widgetsBundles1.getData().get(0));
pageLink = new PageLink(10, 0, "Test widget type 2", new SortOrder("title")); pageLink = new PageLink(10, 0, "Test widget type 2", new SortOrder("title"));
PageData<WidgetsBundle> widgetsBundles2 = widgetsBundleDao.findAllTenantWidgetsBundlesByTenantId(tenantId1, true, pageLink); PageData<WidgetsBundle> widgetsBundles2 = widgetsBundleDao.findAllTenantWidgetsBundlesByTenantId(WidgetsBundleFilter.fullSearchFromTenantId(TenantId.fromUUID(tenantId1)), pageLink);
assertEquals(0, widgetsBundles2.getData().size()); assertEquals(0, widgetsBundles2.getData().size());
PageData<WidgetsBundle> widgetsBundles3 = widgetsBundleDao.findAllTenantWidgetsBundlesByTenantId(tenantId2, true, pageLink); PageData<WidgetsBundle> widgetsBundles3 = widgetsBundleDao.findAllTenantWidgetsBundlesByTenantId(WidgetsBundleFilter.fullSearchFromTenantId(TenantId.fromUUID(tenantId2)), pageLink);
assertEquals(2, widgetsBundles3.getData().size()); assertEquals(2, widgetsBundles3.getData().size());
assertEquals(widgetsBundle2, widgetsBundles3.getData().get(0)); assertEquals(widgetsBundle2, widgetsBundles3.getData().get(0));
assertEquals(widgetsBundle3, widgetsBundles3.getData().get(1)); assertEquals(widgetsBundle3, widgetsBundles3.getData().get(1));
pageLink = new PageLink(10, 0, "ttt Tag2 ffff hhhh", new SortOrder("title")); pageLink = new PageLink(10, 0, "ttt Tag2 ffff hhhh", new SortOrder("title"));
PageData<WidgetsBundle> widgetsBundles4 = widgetsBundleDao.findAllTenantWidgetsBundlesByTenantId(tenantId1, true, pageLink); PageData<WidgetsBundle> widgetsBundles4 = widgetsBundleDao.findAllTenantWidgetsBundlesByTenantId(WidgetsBundleFilter.fullSearchFromTenantId(TenantId.fromUUID(tenantId1)), pageLink);
assertEquals(1, widgetsBundles4.getData().size()); assertEquals(1, widgetsBundles4.getData().size());
assertEquals(widgetsBundle1, widgetsBundles4.getData().get(0)); assertEquals(widgetsBundle1, widgetsBundles4.getData().get(0));
PageData<WidgetsBundle> widgetsBundles5 = widgetsBundleDao.findAllTenantWidgetsBundlesByTenantId(tenantId2, true, pageLink); PageData<WidgetsBundle> widgetsBundles5 = widgetsBundleDao.findAllTenantWidgetsBundlesByTenantId(WidgetsBundleFilter.fullSearchFromTenantId(TenantId.fromUUID(tenantId2)), pageLink);
assertEquals(1, widgetsBundles5.getData().size()); assertEquals(1, widgetsBundles5.getData().size());
assertEquals(widgetsBundle3, widgetsBundles5.getData().get(0)); assertEquals(widgetsBundle3, widgetsBundles5.getData().get(0));
} }
@ -321,7 +322,7 @@ public class JpaWidgetsBundleDaoTest extends AbstractJpaDaoTest {
widgetTypeDao.saveWidgetsBundleWidget(new WidgetsBundleWidget(systemWidgetBundle.getId(), widgetType.getId(), 0)); widgetTypeDao.saveWidgetsBundleWidget(new WidgetsBundleWidget(systemWidgetBundle.getId(), widgetType.getId(), 0));
PageData<WidgetsBundle> widgetTypes = widgetsBundleDao.findAllTenantWidgetsBundlesByTenantId( PageData<WidgetsBundle> widgetTypes = widgetsBundleDao.findAllTenantWidgetsBundlesByTenantId(
TenantId.SYS_TENANT_ID.getId(), true, new PageLink(10, 0, searchText) WidgetsBundleFilter.fullSearchFromTenantId(TenantId.SYS_TENANT_ID), new PageLink(10, 0, searchText)
); );
assertThat(widgetTypes.getData()).hasSize(1); assertThat(widgetTypes.getData()).hasSize(1);
@ -341,7 +342,7 @@ public class JpaWidgetsBundleDaoTest extends AbstractJpaDaoTest {
widgetTypeDao.saveWidgetsBundleWidget(new WidgetsBundleWidget(systemWidgetBundle.getId(), widgetType.getId(), 0)); widgetTypeDao.saveWidgetsBundleWidget(new WidgetsBundleWidget(systemWidgetBundle.getId(), widgetType.getId(), 0));
PageData<WidgetsBundle> widgetTypes = widgetsBundleDao.findAllTenantWidgetsBundlesByTenantId( PageData<WidgetsBundle> widgetTypes = widgetsBundleDao.findAllTenantWidgetsBundlesByTenantId(
TenantId.SYS_TENANT_ID.getId(), true, new PageLink(10, 0, searchText) WidgetsBundleFilter.fullSearchFromTenantId(TenantId.SYS_TENANT_ID), new PageLink(10, 0, searchText)
); );
assertThat(widgetTypes.getData()).hasSize(0); assertThat(widgetTypes.getData()).hasSize(0);
@ -378,7 +379,7 @@ public class JpaWidgetsBundleDaoTest extends AbstractJpaDaoTest {
}).collect(Collectors.toList());; }).collect(Collectors.toList());;
assertEquals(20, widgetsBundles.size()); assertEquals(20, widgetsBundles.size());
PageLink pageLink = new PageLink(100, 0, "", new SortOrder("title")); PageLink pageLink = new PageLink(100, 0, "", new SortOrder("title"));
PageData<WidgetsBundle> widgetsBundlesData = widgetsBundleDao.findAllTenantWidgetsBundlesByTenantId(tenantId1, true, pageLink); PageData<WidgetsBundle> widgetsBundlesData = widgetsBundleDao.findAllTenantWidgetsBundlesByTenantId(WidgetsBundleFilter.fullSearchFromTenantId(TenantId.fromUUID(tenantId1)), pageLink);
assertEquals(20, widgetsBundlesData.getData().size()); assertEquals(20, widgetsBundlesData.getData().size());
assertEquals(widgetsBundles, widgetsBundlesData.getData()); assertEquals(widgetsBundles, widgetsBundlesData.getData());
} }
@ -391,7 +392,7 @@ public class JpaWidgetsBundleDaoTest extends AbstractJpaDaoTest {
widgetsBundles = widgetsBundleDao.find(TenantId.SYS_TENANT_ID); widgetsBundles = widgetsBundleDao.find(TenantId.SYS_TENANT_ID);
assertEquals(10, widgetsBundleDao.find(TenantId.SYS_TENANT_ID).size()); assertEquals(10, widgetsBundleDao.find(TenantId.SYS_TENANT_ID).size());
PageLink textPageLink = new PageLink(30, 0, "TEXT_NOT_FOUND"); PageLink textPageLink = new PageLink(30, 0, "TEXT_NOT_FOUND");
PageData<WidgetsBundle> widgetsBundles4 = widgetsBundleDao.findAllTenantWidgetsBundlesByTenantId(tenantId, false, textPageLink); PageData<WidgetsBundle> widgetsBundles4 = widgetsBundleDao.findAllTenantWidgetsBundlesByTenantId(WidgetsBundleFilter.fromTenantId(TenantId.fromUUID(tenantId)), textPageLink);
assertEquals(0, widgetsBundles4.getData().size()); assertEquals(0, widgetsBundles4.getData().size());
} }

2
dao/src/test/resources/sql-test.properties

@ -14,7 +14,7 @@ spring.jpa.show-sql=false
spring.jpa.hibernate.ddl-auto=none spring.jpa.hibernate.ddl-auto=none
spring.datasource.username=postgres spring.datasource.username=postgres
spring.datasource.password=postgres spring.datasource.password=postgres
spring.datasource.url=jdbc:tc:postgresql:12.8:///thingsboard?TC_DAEMON=true&TC_TMPFS=/testtmpfs:rw&?TC_INITFUNCTION=org.thingsboard.server.dao.PostgreSqlInitializer::initDb spring.datasource.url=jdbc:tc:postgresql:12.19:///thingsboard?TC_DAEMON=true&TC_TMPFS=/testtmpfs:rw&?TC_INITFUNCTION=org.thingsboard.server.dao.PostgreSqlInitializer::initDb
spring.datasource.driverClassName=org.testcontainers.jdbc.ContainerDatabaseDriver spring.datasource.driverClassName=org.testcontainers.jdbc.ContainerDatabaseDriver
spring.datasource.hikari.maximumPoolSize=16 spring.datasource.hikari.maximumPoolSize=16

Loading…
Cancel
Save