Skip to content

Commit 0d8227b

Browse files
fix[backend](data-sources): fixed data sources variable source selection on filter
1 parent 65062e8 commit 0d8227b

File tree

4 files changed

+38
-23
lines changed

4 files changed

+38
-23
lines changed

backend/mvnw

100644100755
File mode changed.

backend/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
<groupId>com.atlasinside</groupId>
99
<artifactId>utmstack</artifactId>
1010
<version>${revision}</version>
11+
<!-- <version>4.0.0</version> -->
1112
<packaging>war</packaging>
1213
<name>UTMStack-API</name>
1314

backend/src/main/java/com/park/utmstack/repository/network_scan/UtmNetworkScanRepository.java

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -43,43 +43,54 @@ public interface UtmNetworkScanRepository extends JpaRepository<UtmNetworkScan,
4343
"AND ((:ports) IS NULL OR ns.id IN (SELECT DISTINCT ins.id FROM UtmNetworkScan ins INNER JOIN UtmPorts p ON ins.id = p.scanId WHERE p.port IN :ports))")*/
4444
@Query("SELECT DISTINCT ns FROM UtmNetworkScan ns " +
4545
"WHERE (:assetIpMacName IS NULL OR (ns.assetIp LIKE :assetIpMacName OR lower(ns.assetMac) LIKE lower(:assetIpMacName) OR lower(ns.assetName) LIKE lower(:assetIpMacName))) " +
46-
"AND (:assetOs IS NULL OR ns.assetOs IN :assetOs) " +
47-
"AND (:assetType IS NULL OR ns.assetTypeId IN (SELECT types.id FROM UtmAssetTypes types WHERE types.typeName IN :assetType)) " +
48-
"AND (:groups IS NULL OR ns.groupId IN (SELECT group.id FROM UtmAssetGroup group WHERE group.groupName IN :groups)) " +
49-
"AND (:assetAlive IS NULL OR ns.assetAlive IN :assetAlive) " +
50-
"AND (:assetStatus IS NULL OR ns.assetStatus IN :assetStatus) " +
46+
"AND (:hasAssetOs = false OR ns.assetOs IN :assetOs) " +
47+
"AND (:hasAssetType = false OR ns.assetTypeId IN (SELECT types.id FROM UtmAssetTypes types WHERE types.typeName IN :assetType)) " +
48+
"AND (:hasGroups = false OR ns.groupId IN (SELECT group.id FROM UtmAssetGroup group WHERE group.groupName IN :groups)) " +
49+
"AND (:hasAssetAlive = false OR ns.assetAlive IN :assetAlive) " +
50+
"AND (:hasAssetStatus = false OR ns.assetStatus IN :assetStatus) " +
5151
"AND (:registeredMode IS NULL OR ns.registeredMode = :registeredMode) " +
52-
"AND (:assetAlias IS NULL OR ns.assetAlias IN :assetAlias) " +
53-
"AND (:serverName IS NULL OR ns.serverName IN :serverName) " +
54-
"AND (:isAgent IS NULL OR ns.isAgent IN :isAgent) " +
55-
"AND (:assetOsPlatform IS NULL OR ns.assetOsPlatform IN :assetOsPlatform) " +
52+
"AND (:hasAssetAlias = false OR ns.assetAlias IN :assetAlias) " +
53+
"AND (:hasServerName = false OR ns.serverName IN :serverName) " +
54+
"AND (:hasIsAgent = false OR ns.isAgent IN :isAgent) " +
55+
"AND (:hasAssetOsPlatform = false OR ns.assetOsPlatform IN :assetOsPlatform) " +
5656
"AND ((cast(:initDate as timestamp) is null) or (cast(:endDate as timestamp) is null) or (ns.discoveredAt BETWEEN :initDate AND :endDate)) " +
57-
"AND (:dataTypes IS NULL OR EXISTS (\n" +
57+
"AND (:hasDataTypes = false OR EXISTS (\n" +
5858
" SELECT 1 FROM UtmDataInputStatus ip\n" +
5959
" WHERE ip.source = ns.assetIp AND ip.dataType IN :dataTypes\n" +
6060
" ) \n" +
6161
" OR EXISTS (\n" +
6262
" SELECT 1 FROM UtmDataInputStatus src\n" +
6363
" WHERE src.source = ns.assetName AND src.dataType IN :dataTypes\n" +
6464
" ))" +
65-
"AND (:ports IS NULL OR ns.id IN (" +
65+
"AND (:hasPorts = false OR ns.id IN (" +
6666
" SELECT p.scanId FROM UtmPorts p WHERE p.port IN :ports))")
6767
@QueryHints(@QueryHint(name = org.hibernate.jpa.QueryHints.HINT_PASS_DISTINCT_THROUGH, value = "false"))
6868
Page<UtmNetworkScan> searchByFilters(@Param("assetIpMacName") String assetIpMacName,
6969
@Param("assetOs") List<String> assetOs,
70+
@Param("hasAssetOs") boolean hasAssetOs,
7071
@Param("assetAlias") List<String> assetAlias,
72+
@Param("hasAssetAlias") boolean hasAssetAlias,
7173
@Param("assetType") List<String> assetType,
74+
@Param("hasAssetType") boolean hasAssetType,
7275
@Param("assetAlive") List<Boolean> assetAlive,
76+
@Param("hasAssetAlive") boolean hasAssetAlive,
7377
@Param("assetStatus") List<AssetStatus> assetStatus,
78+
@Param("hasAssetStatus") boolean hasAssetStatus,
7479
@Param("serverName") List<String> serverName,
80+
@Param("hasServerName") boolean hasServerName,
7581
@Param("ports") List<Integer> ports,
82+
@Param("hasPorts") boolean hasPorts,
7683
@Param("initDate") Instant initDate,
7784
@Param("endDate") Instant endDate,
7885
@Param("groups") List<String> groups,
86+
@Param("hasGroups") boolean hasGroups,
7987
@Param("registeredMode") AssetRegisteredMode registeredMode,
8088
@Param("isAgent") List<Boolean> isAgent,
89+
@Param("hasIsAgent") boolean hasIsAgent,
8190
@Param("assetOsPlatform") List<String> assetOsPlatform,
91+
@Param("hasAssetOsPlatform") boolean hasAssetOsPlatform,
8292
@Param("dataTypes") List<String> dataTypes,
93+
@Param("hasDataTypes") boolean hasDataTypes,
8394
Pageable pageable);
8495

8596
@Modifying

backend/src/main/java/com/park/utmstack/service/network_scan/UtmNetworkScanService.java

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -274,20 +274,23 @@ public ByteArrayOutputStream getNetworkScanReport(NetworkScanFilter f, Pageable
274274
private Page<UtmNetworkScan> filter(NetworkScanFilter f, Pageable p) throws Exception {
275275
final String ctx = CLASSNAME + ".filter";
276276
try {
277-
278-
/*if (page.getTotalPages() > 0) {
279-
List<UtmDataInputStatus> utmDataInputStatuses = utmDataInputStatusRepository.findAll().stream().sorted(Comparator.comparing(UtmDataInputStatus::getSource)).collect(Collectors.toList());
280-
page.forEach(m -> m.setMetrics(assetMetricsRepository.findAllByAssetName(m.getAssetName())));
281-
page.forEach(m -> m.setDataInputList(utmDataInputStatuses.stream().filter(
282-
inputStatus -> inputStatus.getSource().equalsIgnoreCase(m.getAssetName()) ||
283-
inputStatus.getSource().equalsIgnoreCase(m.getAssetIp())).collect(Collectors.toList())));
284-
}*/
285-
286277
return networkScanRepository.searchByFilters(
287278
f.getAssetIpMacName() == null ? null : "%" + f.getAssetIpMacName() + "%",
288-
f.getOs(), f.getAlias(), f.getType(), f.getAlive(), f.getStatus(),
289-
f.getProbe(), f.getOpenPorts(), f.getDiscoveredInitDate(),
290-
f.getDiscoveredEndDate(), f.getGroups(), f.getRegisteredMode(), f.getAgent(), f.getOsPlatform(), f.getDataTypes(), p);
279+
f.getOs(), !CollectionUtils.isEmpty(f.getOs()),
280+
f.getAlias(), !CollectionUtils.isEmpty(f.getAlias()),
281+
f.getType(), !CollectionUtils.isEmpty(f.getType()),
282+
f.getAlive(), !CollectionUtils.isEmpty(f.getAlive()),
283+
f.getStatus(), !CollectionUtils.isEmpty(f.getStatus()),
284+
f.getProbe(), !CollectionUtils.isEmpty(f.getProbe()),
285+
f.getOpenPorts(), !CollectionUtils.isEmpty(f.getOpenPorts()),
286+
f.getDiscoveredInitDate(),
287+
f.getDiscoveredEndDate(),
288+
f.getGroups(), !CollectionUtils.isEmpty(f.getGroups()),
289+
f.getRegisteredMode(),
290+
f.getAgent(), !CollectionUtils.isEmpty(f.getAgent()),
291+
f.getOsPlatform(), !CollectionUtils.isEmpty(f.getOsPlatform()),
292+
f.getDataTypes(), !CollectionUtils.isEmpty(f.getDataTypes()),
293+
p);
291294
} catch (InvalidDataAccessResourceUsageException e) {
292295
String msg = ctx + ": " + e.getMostSpecificCause().getMessage().replaceAll("\n", "");
293296
throw new Exception(msg);

0 commit comments

Comments
 (0)