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);
|
AssetInfoEntity findAssetInfoById(@Param("assetId") UUID assetId);
|
||||||
|
|
||||||
@Query("SELECT a FROM AssetEntity a WHERE a.tenantId = :tenantId " +
|
@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,
|
Page<AssetEntity> findByTenantId(@Param("tenantId") UUID tenantId,
|
||||||
@Param("textSearch") String textSearch,
|
@Param("textSearch") String textSearch,
|
||||||
Pageable pageable);
|
Pageable pageable);
|
||||||
@ -61,7 +62,8 @@ public interface AssetRepository extends JpaRepository<AssetEntity, UUID>, Expor
|
|||||||
|
|
||||||
@Query("SELECT a FROM AssetEntity a WHERE a.tenantId = :tenantId " +
|
@Query("SELECT a FROM AssetEntity a WHERE a.tenantId = :tenantId " +
|
||||||
"AND a.customerId = :customerId " +
|
"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,
|
Page<AssetEntity> findByTenantIdAndCustomerId(@Param("tenantId") UUID tenantId,
|
||||||
@Param("customerId") UUID customerId,
|
@Param("customerId") UUID customerId,
|
||||||
@Param("textSearch") String textSearch,
|
@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 " +
|
@Query("SELECT a FROM AssetEntity a WHERE a.tenantId = :tenantId " +
|
||||||
"AND a.assetProfileId = :profileId " +
|
"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,
|
Page<AssetEntity> findByTenantIdAndProfileId(@Param("tenantId") UUID tenantId,
|
||||||
@Param("profileId") UUID profileId,
|
@Param("profileId") UUID profileId,
|
||||||
@Param("searchText") String searchText,
|
@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 " +
|
"LEFT JOIN AssetProfileEntity p on p.id = a.assetProfileId " +
|
||||||
"WHERE a.tenantId = :tenantId " +
|
"WHERE a.tenantId = :tenantId " +
|
||||||
"AND a.customerId = :customerId " +
|
"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,
|
Page<AssetInfoEntity> findAssetInfosByTenantIdAndCustomerId(@Param("tenantId") UUID tenantId,
|
||||||
@Param("customerId") UUID customerId,
|
@Param("customerId") UUID customerId,
|
||||||
@Param("searchText") String searchText,
|
@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 " +
|
@Query("SELECT a FROM AssetEntity a WHERE a.tenantId = :tenantId " +
|
||||||
"AND a.type = :type " +
|
"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,
|
Page<AssetEntity> findByTenantIdAndType(@Param("tenantId") UUID tenantId,
|
||||||
@Param("type") String type,
|
@Param("type") String type,
|
||||||
@Param("textSearch") String textSearch,
|
@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 " +
|
@Query("SELECT a FROM AssetEntity a WHERE a.tenantId = :tenantId " +
|
||||||
"AND a.customerId = :customerId AND a.type = :type " +
|
"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,
|
Page<AssetEntity> findByTenantIdAndCustomerIdAndType(@Param("tenantId") UUID tenantId,
|
||||||
@Param("customerId") UUID customerId,
|
@Param("customerId") UUID customerId,
|
||||||
@Param("type") String type,
|
@Param("type") String type,
|
||||||
@ -146,7 +153,9 @@ public interface AssetRepository extends JpaRepository<AssetEntity, UUID>, Expor
|
|||||||
"WHERE a.tenantId = :tenantId " +
|
"WHERE a.tenantId = :tenantId " +
|
||||||
"AND a.customerId = :customerId " +
|
"AND a.customerId = :customerId " +
|
||||||
"AND a.type = :type " +
|
"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,
|
Page<AssetInfoEntity> findAssetInfosByTenantIdAndCustomerIdAndType(@Param("tenantId") UUID tenantId,
|
||||||
@Param("customerId") UUID customerId,
|
@Param("customerId") UUID customerId,
|
||||||
@Param("type") String type,
|
@Param("type") String type,
|
||||||
@ -160,7 +169,9 @@ public interface AssetRepository extends JpaRepository<AssetEntity, UUID>, Expor
|
|||||||
"WHERE a.tenantId = :tenantId " +
|
"WHERE a.tenantId = :tenantId " +
|
||||||
"AND a.customerId = :customerId " +
|
"AND a.customerId = :customerId " +
|
||||||
"AND a.assetProfileId = :assetProfileId " +
|
"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,
|
Page<AssetInfoEntity> findAssetInfosByTenantIdAndCustomerIdAndAssetProfileId(@Param("tenantId") UUID tenantId,
|
||||||
@Param("customerId") UUID customerId,
|
@Param("customerId") UUID customerId,
|
||||||
@Param("assetProfileId") UUID assetProfileId,
|
@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 " +
|
@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 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 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,
|
Page<AssetEntity> findByTenantIdAndEdgeId(@Param("tenantId") UUID tenantId,
|
||||||
@Param("edgeId") UUID edgeId,
|
@Param("edgeId") UUID edgeId,
|
||||||
@Param("searchText") String searchText,
|
@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 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 re.relationType = 'Contains' AND re.fromId = :edgeId AND re.fromType = 'EDGE' " +
|
||||||
"AND a.type = :type " +
|
"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,
|
Page<AssetEntity> findByTenantIdAndEdgeIdAndType(@Param("tenantId") UUID tenantId,
|
||||||
@Param("edgeId") UUID edgeId,
|
@Param("edgeId") UUID edgeId,
|
||||||
@Param("type") String type,
|
@Param("type") String type,
|
||||||
|
|||||||
@ -78,7 +78,7 @@ public class JpaAssetDaoTest extends AbstractJpaDaoTest {
|
|||||||
UUID assetId = Uuids.timeBased();
|
UUID assetId = Uuids.timeBased();
|
||||||
UUID tenantId = i % 2 == 0 ? tenantId1 : tenantId2;
|
UUID tenantId = i % 2 == 0 ? tenantId1 : tenantId2;
|
||||||
UUID customerId = i % 2 == 0 ? customerId1 : customerId2;
|
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());
|
assertEquals(assets.size(), assetDao.find(TenantId.fromUUID(tenantId1)).size());
|
||||||
}
|
}
|
||||||
@ -131,6 +131,21 @@ public class JpaAssetDaoTest extends AbstractJpaDaoTest {
|
|||||||
assertEquals(0, assets3.getData().size());
|
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
|
@Test
|
||||||
public void testFindAssetsByTenantIdAndIdsAsync() throws ExecutionException, InterruptedException, TimeoutException {
|
public void testFindAssetsByTenantIdAndIdsAsync() throws ExecutionException, InterruptedException, TimeoutException {
|
||||||
List<UUID> searchIds = getAssetsUuids(tenantId1);
|
List<UUID> searchIds = getAssetsUuids(tenantId1);
|
||||||
@ -180,21 +195,31 @@ public class JpaAssetDaoTest extends AbstractJpaDaoTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testFindAssetsByTenantIdAndType() {
|
public void testFindAssetsByTenantIdAndType() {
|
||||||
String type = "TYPE_2";
|
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
|
List<Asset> foundedAssetsByType = assetDao
|
||||||
.findAssetsByTenantIdAndType(tenantId2, type, new PageLink(3)).getData();
|
.findAssetsByTenantIdAndType(tenantId2, type, new PageLink(3)).getData();
|
||||||
compareFoundedAssetByType(foundedAssetsByType, type);
|
compareFoundedAssetByType(foundedAssetsByType, type);
|
||||||
|
|
||||||
|
List<Asset> foundedAssetsByTypeAndLabel = assetDao
|
||||||
|
.findAssetsByTenantIdAndType(tenantId2, type, new PageLink(3, 0, testLabel)).getData();
|
||||||
|
assertEquals(1, foundedAssetsByTypeAndLabel.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFindAssetsByTenantIdAndCustomerIdAndType() {
|
public void testFindAssetsByTenantIdAndCustomerIdAndType() {
|
||||||
String type = "TYPE_2";
|
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
|
List<Asset> foundedAssetsByType = assetDao
|
||||||
.findAssetsByTenantIdAndCustomerIdAndType(tenantId2, customerId2, type, new PageLink(3)).getData();
|
.findAssetsByTenantIdAndCustomerIdAndType(tenantId2, customerId2, type, new PageLink(3)).getData();
|
||||||
compareFoundedAssetByType(foundedAssetsByType, type);
|
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) {
|
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) {
|
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) {
|
if (type == null) {
|
||||||
type = "default";
|
type = "default";
|
||||||
}
|
}
|
||||||
@ -241,6 +270,7 @@ public class JpaAssetDaoTest extends AbstractJpaDaoTest {
|
|||||||
asset.setCustomerId(new CustomerId(customerId));
|
asset.setCustomerId(new CustomerId(customerId));
|
||||||
asset.setName(name);
|
asset.setName(name);
|
||||||
asset.setType(type);
|
asset.setType(type);
|
||||||
|
asset.setLabel(label);
|
||||||
asset.setAssetProfileId(assetProfileId(type));
|
asset.setAssetProfileId(assetProfileId(type));
|
||||||
return assetDao.save(TenantId.fromUUID(tenantId), asset);
|
return assetDao.save(TenantId.fromUUID(tenantId), asset);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user