asset search text is being applied to name, label and customer title where possible
This commit is contained in:
parent
299ecd1cb8
commit
ff640448e0
@ -41,7 +41,8 @@ public interface AssetRepository extends JpaRepository<AssetEntity, UUID>, Expor
|
||||
AssetInfoEntity findAssetInfoById(@Param("assetId") UUID assetId);
|
||||
|
||||
@Query("SELECT a FROM AssetEntity a WHERE a.tenantId = :tenantId " +
|
||||
"AND (:textSearch IS NULL OR ilike(a.name, CONCAT('%', :textSearch, '%')) = true)")
|
||||
"AND (:textSearch IS NULL OR ilike(a.name, CONCAT('%', :textSearch, '%')) = true " +
|
||||
" OR ilike(a.label, CONCAT('%', :textSearch, '%')) = true) ")
|
||||
Page<AssetEntity> findByTenantId(@Param("tenantId") UUID tenantId,
|
||||
@Param("textSearch") String textSearch,
|
||||
Pageable pageable);
|
||||
@ -61,7 +62,8 @@ public interface AssetRepository extends JpaRepository<AssetEntity, UUID>, Expor
|
||||
|
||||
@Query("SELECT a FROM AssetEntity a WHERE a.tenantId = :tenantId " +
|
||||
"AND a.customerId = :customerId " +
|
||||
"AND (:textSearch IS NULL OR ilike(a.name, CONCAT('%', :textSearch, '%')) = true)")
|
||||
"AND (:textSearch IS NULL OR ilike(a.name, CONCAT('%', :textSearch, '%')) = true " +
|
||||
" OR ilike(a.label, CONCAT('%', :textSearch, '%')) = true) ")
|
||||
Page<AssetEntity> findByTenantIdAndCustomerId(@Param("tenantId") UUID tenantId,
|
||||
@Param("customerId") UUID customerId,
|
||||
@Param("textSearch") String textSearch,
|
||||
@ -69,7 +71,8 @@ public interface AssetRepository extends JpaRepository<AssetEntity, UUID>, Expor
|
||||
|
||||
@Query("SELECT a FROM AssetEntity a WHERE a.tenantId = :tenantId " +
|
||||
"AND a.assetProfileId = :profileId " +
|
||||
"AND (:searchText IS NULL OR ilike(a.name, CONCAT('%', :searchText, '%')) = true)")
|
||||
"AND (:searchText IS NULL OR ilike(a.name, CONCAT('%', :searchText, '%')) = true " +
|
||||
" OR ilike(a.label, CONCAT('%', :searchText, '%')) = true) ")
|
||||
Page<AssetEntity> findByTenantIdAndProfileId(@Param("tenantId") UUID tenantId,
|
||||
@Param("profileId") UUID profileId,
|
||||
@Param("searchText") String searchText,
|
||||
@ -81,7 +84,9 @@ public interface AssetRepository extends JpaRepository<AssetEntity, UUID>, Expor
|
||||
"LEFT JOIN AssetProfileEntity p on p.id = a.assetProfileId " +
|
||||
"WHERE a.tenantId = :tenantId " +
|
||||
"AND a.customerId = :customerId " +
|
||||
"AND (:searchText IS NULL OR ilike(a.name, CONCAT('%', :searchText, '%')) = true)")
|
||||
"AND (:searchText IS NULL OR ilike(a.name, CONCAT('%', :searchText, '%')) = true " +
|
||||
" OR ilike(a.label, CONCAT('%', :searchText, '%')) = true " +
|
||||
" OR ilike(c.title, CONCAT('%', :searchText, '%')) = true) ")
|
||||
Page<AssetInfoEntity> findAssetInfosByTenantIdAndCustomerId(@Param("tenantId") UUID tenantId,
|
||||
@Param("customerId") UUID customerId,
|
||||
@Param("searchText") String searchText,
|
||||
@ -95,7 +100,8 @@ public interface AssetRepository extends JpaRepository<AssetEntity, UUID>, Expor
|
||||
|
||||
@Query("SELECT a FROM AssetEntity a WHERE a.tenantId = :tenantId " +
|
||||
"AND a.type = :type " +
|
||||
"AND (:textSearch IS NULL OR ilike(a.name, CONCAT('%', :textSearch, '%')) = true)")
|
||||
"AND (:textSearch IS NULL OR ilike(a.name, CONCAT('%', :textSearch, '%')) = true " +
|
||||
" OR ilike(a.label, CONCAT('%', :textSearch, '%')) = true) ")
|
||||
Page<AssetEntity> findByTenantIdAndType(@Param("tenantId") UUID tenantId,
|
||||
@Param("type") String type,
|
||||
@Param("textSearch") String textSearch,
|
||||
@ -132,7 +138,8 @@ public interface AssetRepository extends JpaRepository<AssetEntity, UUID>, Expor
|
||||
|
||||
@Query("SELECT a FROM AssetEntity a WHERE a.tenantId = :tenantId " +
|
||||
"AND a.customerId = :customerId AND a.type = :type " +
|
||||
"AND (:textSearch IS NULL OR ilike(a.name, CONCAT('%', :textSearch, '%')) = true)")
|
||||
"AND (:textSearch IS NULL OR ilike(a.name, CONCAT('%', :textSearch, '%')) = true " +
|
||||
" OR ilike(a.label, CONCAT('%', :textSearch, '%')) = true) ")
|
||||
Page<AssetEntity> findByTenantIdAndCustomerIdAndType(@Param("tenantId") UUID tenantId,
|
||||
@Param("customerId") UUID customerId,
|
||||
@Param("type") String type,
|
||||
@ -146,7 +153,9 @@ public interface AssetRepository extends JpaRepository<AssetEntity, UUID>, Expor
|
||||
"WHERE a.tenantId = :tenantId " +
|
||||
"AND a.customerId = :customerId " +
|
||||
"AND a.type = :type " +
|
||||
"AND (:textSearch IS NULL OR ilike(a.name, CONCAT('%', :textSearch, '%')) = true)")
|
||||
"AND (:textSearch IS NULL OR ilike(a.name, CONCAT('%', :textSearch, '%')) = true " +
|
||||
" OR ilike(a.label, CONCAT('%', :textSearch, '%')) = true " +
|
||||
" OR ilike(c.title, CONCAT('%', :textSearch, '%')) = true) ")
|
||||
Page<AssetInfoEntity> findAssetInfosByTenantIdAndCustomerIdAndType(@Param("tenantId") UUID tenantId,
|
||||
@Param("customerId") UUID customerId,
|
||||
@Param("type") String type,
|
||||
@ -160,7 +169,9 @@ public interface AssetRepository extends JpaRepository<AssetEntity, UUID>, Expor
|
||||
"WHERE a.tenantId = :tenantId " +
|
||||
"AND a.customerId = :customerId " +
|
||||
"AND a.assetProfileId = :assetProfileId " +
|
||||
"AND (:textSearch IS NULL OR ilike(a.name, CONCAT('%', :textSearch, '%')) = true)")
|
||||
"AND (:textSearch IS NULL OR ilike(a.name, CONCAT('%', :textSearch, '%')) = true " +
|
||||
" OR ilike(a.label, CONCAT('%', :textSearch, '%')) = true " +
|
||||
" OR ilike(c.title, CONCAT('%', :textSearch, '%')) = true) ")
|
||||
Page<AssetInfoEntity> findAssetInfosByTenantIdAndCustomerIdAndAssetProfileId(@Param("tenantId") UUID tenantId,
|
||||
@Param("customerId") UUID customerId,
|
||||
@Param("assetProfileId") UUID assetProfileId,
|
||||
@ -172,7 +183,8 @@ public interface AssetRepository extends JpaRepository<AssetEntity, UUID>, Expor
|
||||
@Query("SELECT a FROM AssetEntity a, RelationEntity re WHERE a.tenantId = :tenantId " +
|
||||
"AND a.id = re.toId AND re.toType = 'ASSET' AND re.relationTypeGroup = 'EDGE' " +
|
||||
"AND re.relationType = 'Contains' AND re.fromId = :edgeId AND re.fromType = 'EDGE' " +
|
||||
"AND (:searchText IS NULL OR ilike(a.name, CONCAT('%', :searchText, '%')) = true)")
|
||||
"AND (:searchText IS NULL OR ilike(a.name, CONCAT('%', :searchText, '%')) = true " +
|
||||
" OR ilike(a.label, CONCAT('%', :searchText, '%')) = true) ")
|
||||
Page<AssetEntity> findByTenantIdAndEdgeId(@Param("tenantId") UUID tenantId,
|
||||
@Param("edgeId") UUID edgeId,
|
||||
@Param("searchText") String searchText,
|
||||
@ -182,7 +194,8 @@ public interface AssetRepository extends JpaRepository<AssetEntity, UUID>, Expor
|
||||
"AND a.id = re.toId AND re.toType = 'ASSET' AND re.relationTypeGroup = 'EDGE' " +
|
||||
"AND re.relationType = 'Contains' AND re.fromId = :edgeId AND re.fromType = 'EDGE' " +
|
||||
"AND a.type = :type " +
|
||||
"AND (:searchText IS NULL OR ilike(a.name, CONCAT('%', :searchText, '%')) = true)")
|
||||
"AND (:searchText IS NULL OR ilike(a.name, CONCAT('%', :searchText, '%')) = true " +
|
||||
" OR ilike(a.label, CONCAT('%', :searchText, '%')) = true) ")
|
||||
Page<AssetEntity> findByTenantIdAndEdgeIdAndType(@Param("tenantId") UUID tenantId,
|
||||
@Param("edgeId") UUID edgeId,
|
||||
@Param("type") String type,
|
||||
|
||||
@ -78,7 +78,7 @@ public class JpaAssetDaoTest extends AbstractJpaDaoTest {
|
||||
UUID assetId = Uuids.timeBased();
|
||||
UUID tenantId = i % 2 == 0 ? tenantId1 : tenantId2;
|
||||
UUID customerId = i % 2 == 0 ? customerId1 : customerId2;
|
||||
assets.add(saveAsset(assetId, tenantId, customerId, "ASSET_" + i));
|
||||
assets.add(saveAsset(assetId, tenantId, customerId, "ASSET_" + i, "label_" + i));
|
||||
}
|
||||
assertEquals(assets.size(), assetDao.find(TenantId.fromUUID(tenantId1)).size());
|
||||
}
|
||||
@ -131,6 +131,21 @@ public class JpaAssetDaoTest extends AbstractJpaDaoTest {
|
||||
assertEquals(0, assets3.getData().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFindAssetsByTenantIdAndCustomerIdByLabel() {
|
||||
PageLink pageLink = new PageLink(20, 0, "label_");
|
||||
PageData<Asset> assets1 = assetDao.findAssetsByTenantIdAndCustomerId(tenantId1, customerId1, pageLink);
|
||||
assertEquals(20, assets1.getData().size());
|
||||
|
||||
pageLink = pageLink.nextPageLink();
|
||||
PageData<Asset> assets2 = assetDao.findAssetsByTenantIdAndCustomerId(tenantId1, customerId1, pageLink);
|
||||
assertEquals(10, assets2.getData().size());
|
||||
|
||||
pageLink = pageLink.nextPageLink();
|
||||
PageData<Asset> assets3 = assetDao.findAssetsByTenantIdAndCustomerId(tenantId1, customerId1, pageLink);
|
||||
assertEquals(0, assets3.getData().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFindAssetsByTenantIdAndIdsAsync() throws ExecutionException, InterruptedException, TimeoutException {
|
||||
List<UUID> searchIds = getAssetsUuids(tenantId1);
|
||||
@ -180,21 +195,31 @@ public class JpaAssetDaoTest extends AbstractJpaDaoTest {
|
||||
@Test
|
||||
public void testFindAssetsByTenantIdAndType() {
|
||||
String type = "TYPE_2";
|
||||
assets.add(saveAsset(Uuids.timeBased(), tenantId2, customerId2, "TEST_ASSET", type));
|
||||
String testLabel = "test_label";
|
||||
assets.add(saveAsset(Uuids.timeBased(), tenantId2, customerId2, "TEST_ASSET", type, testLabel));
|
||||
|
||||
List<Asset> foundedAssetsByType = assetDao
|
||||
.findAssetsByTenantIdAndType(tenantId2, type, new PageLink(3)).getData();
|
||||
compareFoundedAssetByType(foundedAssetsByType, type);
|
||||
|
||||
List<Asset> foundedAssetsByTypeAndLabel = assetDao
|
||||
.findAssetsByTenantIdAndType(tenantId2, type, new PageLink(3, 0, testLabel)).getData();
|
||||
assertEquals(1, foundedAssetsByTypeAndLabel.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFindAssetsByTenantIdAndCustomerIdAndType() {
|
||||
String type = "TYPE_2";
|
||||
assets.add(saveAsset(Uuids.timeBased(), tenantId2, customerId2, "TEST_ASSET", type));
|
||||
String testLabel = "test_label";
|
||||
assets.add(saveAsset(Uuids.timeBased(), tenantId2, customerId2, "TEST_ASSET", type, testLabel));
|
||||
|
||||
List<Asset> foundedAssetsByType = assetDao
|
||||
.findAssetsByTenantIdAndCustomerIdAndType(tenantId2, customerId2, type, new PageLink(3)).getData();
|
||||
compareFoundedAssetByType(foundedAssetsByType, type);
|
||||
|
||||
List<Asset> foundedAssetsByTypeAndLabel = assetDao
|
||||
.findAssetsByTenantIdAndCustomerIdAndType(tenantId2, customerId2, type, new PageLink(3, 0, testLabel)).getData();
|
||||
assertEquals(1, foundedAssetsByTypeAndLabel.size());
|
||||
}
|
||||
|
||||
private void compareFoundedAssetByType(List<Asset> foundedAssetsByType, String type) {
|
||||
@ -228,10 +253,14 @@ public class JpaAssetDaoTest extends AbstractJpaDaoTest {
|
||||
}
|
||||
|
||||
private Asset saveAsset(UUID id, UUID tenantId, UUID customerId, String name) {
|
||||
return saveAsset(id, tenantId, customerId, name, null);
|
||||
return saveAsset(id, tenantId, customerId, name, null, null);
|
||||
}
|
||||
|
||||
private Asset saveAsset(UUID id, UUID tenantId, UUID customerId, String name, String type) {
|
||||
private Asset saveAsset(UUID id, UUID tenantId, UUID customerId, String name, String label) {
|
||||
return saveAsset(id, tenantId, customerId, name, null, label);
|
||||
}
|
||||
|
||||
private Asset saveAsset(UUID id, UUID tenantId, UUID customerId, String name, String type, String label) {
|
||||
if (type == null) {
|
||||
type = "default";
|
||||
}
|
||||
@ -241,6 +270,7 @@ public class JpaAssetDaoTest extends AbstractJpaDaoTest {
|
||||
asset.setCustomerId(new CustomerId(customerId));
|
||||
asset.setName(name);
|
||||
asset.setType(type);
|
||||
asset.setLabel(label);
|
||||
asset.setAssetProfileId(assetProfileId(type));
|
||||
return assetDao.save(TenantId.fromUUID(tenantId), asset);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user