added api request parameter to retrieve all tenant bundles without system
This commit is contained in:
parent
94278a401e
commit
1e53280ca8
@ -69,6 +69,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 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)",
|
||||||
notes = "Get the Widget Bundle based on the provided Widget Bundle Id. " + WIDGET_BUNDLE_DESCRIPTION + AVAILABLE_FOR_ANY_AUTHORIZED_USER)
|
notes = "Get the Widget Bundle based on the provided Widget Bundle Id. " + WIDGET_BUNDLE_DESCRIPTION + AVAILABLE_FOR_ANY_AUTHORIZED_USER)
|
||||||
@ -185,6 +186,8 @@ public class WidgetsBundleController extends BaseController {
|
|||||||
@RequestParam(required = false) String sortProperty,
|
@RequestParam(required = false) String sortProperty,
|
||||||
@ApiParam(value = SORT_ORDER_DESCRIPTION, allowableValues = SORT_ORDER_ALLOWABLE_VALUES)
|
@ApiParam(value = SORT_ORDER_DESCRIPTION, allowableValues = SORT_ORDER_ALLOWABLE_VALUES)
|
||||||
@RequestParam(required = false) String sortOrder,
|
@RequestParam(required = false) String sortOrder,
|
||||||
|
@ApiParam(value = TENANT_BUNDLES_ONLY_DESCRIPTION)
|
||||||
|
@RequestParam(required = false) Boolean tenantOnly,
|
||||||
@ApiParam(value = FULL_SEARCH_PARAM_DESCRIPTION)
|
@ApiParam(value = FULL_SEARCH_PARAM_DESCRIPTION)
|
||||||
@RequestParam(required = false) Boolean fullSearch) throws ThingsboardException {
|
@RequestParam(required = false) Boolean fullSearch) throws ThingsboardException {
|
||||||
PageLink pageLink = createPageLink(pageSize, page, textSearch, sortProperty, sortOrder);
|
PageLink pageLink = createPageLink(pageSize, page, textSearch, sortProperty, sortOrder);
|
||||||
@ -192,9 +195,13 @@ public class WidgetsBundleController extends BaseController {
|
|||||||
return checkNotNull(widgetsBundleService.findSystemWidgetsBundlesByPageLink(getTenantId(), fullSearch != null && fullSearch, pageLink));
|
return checkNotNull(widgetsBundleService.findSystemWidgetsBundlesByPageLink(getTenantId(), fullSearch != null && fullSearch, pageLink));
|
||||||
} else {
|
} else {
|
||||||
TenantId tenantId = getCurrentUser().getTenantId();
|
TenantId tenantId = getCurrentUser().getTenantId();
|
||||||
|
if (tenantOnly != null && tenantOnly) {
|
||||||
|
return checkNotNull(widgetsBundleService.findTenantWidgetsBundlesByTenantIdAndPageLink(tenantId, fullSearch != null && fullSearch, pageLink));
|
||||||
|
} else {
|
||||||
return checkNotNull(widgetsBundleService.findAllTenantWidgetsBundlesByTenantIdAndPageLink(tenantId, fullSearch != null && fullSearch, pageLink));
|
return checkNotNull(widgetsBundleService.findAllTenantWidgetsBundlesByTenantIdAndPageLink(tenantId, fullSearch != null && fullSearch, pageLink));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@ApiOperation(value = "Get all Widget Bundles (getWidgetsBundles)",
|
@ApiOperation(value = "Get all Widget Bundles (getWidgetsBundles)",
|
||||||
notes = "Returns an array of Widget Bundle objects that are available for current user." + WIDGET_BUNDLE_DESCRIPTION + " " + AVAILABLE_FOR_ANY_AUTHORIZED_USER)
|
notes = "Returns an array of Widget Bundle objects that are available for current user." + WIDGET_BUNDLE_DESCRIPTION + " " + AVAILABLE_FOR_ANY_AUTHORIZED_USER)
|
||||||
|
|||||||
@ -42,6 +42,8 @@ public interface WidgetsBundleService extends EntityDaoService {
|
|||||||
|
|
||||||
PageData<WidgetsBundle> findAllTenantWidgetsBundlesByTenantIdAndPageLink(TenantId tenantId, boolean fullSearch, PageLink pageLink);
|
PageData<WidgetsBundle> findAllTenantWidgetsBundlesByTenantIdAndPageLink(TenantId tenantId, boolean fullSearch, PageLink pageLink);
|
||||||
|
|
||||||
|
PageData<WidgetsBundle> findTenantWidgetsBundlesByTenantIdAndPageLink(TenantId tenantId, boolean fullSearch, PageLink pageLink);
|
||||||
|
|
||||||
List<WidgetsBundle> findAllTenantWidgetsBundlesByTenantId(TenantId tenantId);
|
List<WidgetsBundle> findAllTenantWidgetsBundlesByTenantId(TenantId tenantId);
|
||||||
|
|
||||||
void deleteWidgetsBundlesByTenantId(TenantId tenantId);
|
void deleteWidgetsBundlesByTenantId(TenantId tenantId);
|
||||||
|
|||||||
@ -111,6 +111,25 @@ public class JpaWidgetsBundleDao extends JpaAbstractDao<WidgetsBundleEntity, Wid
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PageData<WidgetsBundle> findTenantWidgetsBundlesByTenantId(UUID tenantId, boolean fullSearch, PageLink pageLink) {
|
||||||
|
if (fullSearch) {
|
||||||
|
return DaoUtil.toPageData(
|
||||||
|
widgetsBundleRepository
|
||||||
|
.findTenantWidgetsBundlesByTenantIdFullSearch(
|
||||||
|
tenantId,
|
||||||
|
Objects.toString(pageLink.getTextSearch(), ""),
|
||||||
|
DaoUtil.toPageable(pageLink)));
|
||||||
|
} else {
|
||||||
|
return DaoUtil.toPageData(
|
||||||
|
widgetsBundleRepository
|
||||||
|
.findTenantWidgetsBundlesByTenantId(
|
||||||
|
tenantId,
|
||||||
|
Objects.toString(pageLink.getTextSearch(), ""),
|
||||||
|
DaoUtil.toPageable(pageLink)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public WidgetsBundle findByTenantIdAndExternalId(UUID tenantId, UUID externalId) {
|
public WidgetsBundle findByTenantIdAndExternalId(UUID tenantId, UUID externalId) {
|
||||||
return DaoUtil.getData(widgetsBundleRepository.findByTenantIdAndExternalId(tenantId, externalId));
|
return DaoUtil.getData(widgetsBundleRepository.findByTenantIdAndExternalId(tenantId, externalId));
|
||||||
|
|||||||
@ -96,6 +96,28 @@ public interface WidgetsBundleRepository extends JpaRepository<WidgetsBundleEnti
|
|||||||
@Param("textSearch") String textSearch,
|
@Param("textSearch") String textSearch,
|
||||||
Pageable pageable);
|
Pageable pageable);
|
||||||
|
|
||||||
|
@Query(nativeQuery = true,
|
||||||
|
value = "SELECT * FROM widgets_bundle wb WHERE wb.tenant_id IN (:tenantId) " +
|
||||||
|
"AND (wb.title ILIKE CONCAT('%', :textSearch, '%') " +
|
||||||
|
"OR wb.description ILIKE CONCAT('%', :textSearch, '%') " +
|
||||||
|
"OR wb.id in (SELECT wbw.widgets_bundle_id FROM widgets_bundle_widget wbw, widget_type wtd " +
|
||||||
|
"WHERE wtd.id = wbw.widget_type_id " +
|
||||||
|
"AND (wtd.name ILIKE CONCAT('%', :textSearch, '%') " +
|
||||||
|
"OR wtd.description ILIKE CONCAT('%', :textSearch, '%') " +
|
||||||
|
"OR lower(wtd.tags\\:\\:text)\\:\\:text[] && string_to_array(lower(:textSearch), ' '))))",
|
||||||
|
countQuery = "SELECT count(*) FROM widgets_bundle wb WHERE wb.tenant_id IN (:tenantId, :nullTenantId) " +
|
||||||
|
"AND (wb.title ILIKE CONCAT('%', :textSearch, '%') " +
|
||||||
|
"OR wb.description ILIKE CONCAT('%', :textSearch, '%') " +
|
||||||
|
"OR wb.id in (SELECT wbw.widgets_bundle_id FROM widgets_bundle_widget wbw, widget_type wtd " +
|
||||||
|
"WHERE wtd.id = wbw.widget_type_id " +
|
||||||
|
"AND (wtd.name ILIKE CONCAT('%', :textSearch, '%') " +
|
||||||
|
"OR wtd.description ILIKE CONCAT('%', :textSearch, '%') " +
|
||||||
|
"OR lower(wtd.tags\\:\\:text)\\:\\:text[] && string_to_array(lower(:textSearch), ' '))))"
|
||||||
|
)
|
||||||
|
Page<WidgetsBundleEntity> findTenantWidgetsBundlesByTenantIdFullSearch(@Param("tenantId") UUID tenantId,
|
||||||
|
@Param("textSearch") String textSearch,
|
||||||
|
Pageable pageable);
|
||||||
|
|
||||||
WidgetsBundleEntity findFirstByTenantIdAndTitle(UUID tenantId, String title);
|
WidgetsBundleEntity findFirstByTenantIdAndTitle(UUID tenantId, String title);
|
||||||
|
|
||||||
@Query("SELECT externalId FROM WidgetsBundleEntity WHERE id = :id")
|
@Query("SELECT externalId FROM WidgetsBundleEntity WHERE id = :id")
|
||||||
|
|||||||
@ -74,5 +74,14 @@ public interface WidgetsBundleDao extends Dao<WidgetsBundle>, ExportableEntityDa
|
|||||||
*/
|
*/
|
||||||
PageData<WidgetsBundle> findAllTenantWidgetsBundlesByTenantId(UUID tenantId, boolean fullSearch, PageLink pageLink);
|
PageData<WidgetsBundle> findAllTenantWidgetsBundlesByTenantId(UUID tenantId, boolean fullSearch, PageLink pageLink);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Find all tenant widgets bundles (does not include system) by tenantId and page link.
|
||||||
|
*
|
||||||
|
* @param tenantId the tenantId
|
||||||
|
* @param pageLink the page link
|
||||||
|
* @return the list of widgets bundles objects
|
||||||
|
*/
|
||||||
|
PageData<WidgetsBundle> findTenantWidgetsBundlesByTenantId(UUID tenantId, boolean fullSearch, PageLink pageLink);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -142,6 +142,14 @@ public class WidgetsBundleServiceImpl implements WidgetsBundleService {
|
|||||||
return widgetsBundleDao.findAllTenantWidgetsBundlesByTenantId(tenantId.getId(), fullSearch, pageLink);
|
return widgetsBundleDao.findAllTenantWidgetsBundlesByTenantId(tenantId.getId(), fullSearch, pageLink);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PageData<WidgetsBundle> findTenantWidgetsBundlesByTenantIdAndPageLink(TenantId tenantId, boolean fullSearch, PageLink pageLink) {
|
||||||
|
log.trace("Executing findTenantWidgetsBundlesByTenantIdAndPageLink, tenantId [{}], fullSearch [{}], pageLink [{}]", tenantId, fullSearch, pageLink);
|
||||||
|
Validator.validateId(tenantId, INCORRECT_TENANT_ID + tenantId);
|
||||||
|
Validator.validatePageLink(pageLink);
|
||||||
|
return widgetsBundleDao.findTenantWidgetsBundlesByTenantId(tenantId.getId(), fullSearch, pageLink);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<WidgetsBundle> findAllTenantWidgetsBundlesByTenantId(TenantId tenantId) {
|
public List<WidgetsBundle> findAllTenantWidgetsBundlesByTenantId(TenantId tenantId) {
|
||||||
log.trace("Executing findAllTenantWidgetsBundlesByTenantId, tenantId [{}]", tenantId);
|
log.trace("Executing findAllTenantWidgetsBundlesByTenantId, tenantId [{}]", tenantId);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user