@@ -50,7 +50,7 @@ public class DefinitionSyncService implements CommandLineRunner {
5050 public void run (String ... args ) {
5151 log .info ("Starting definition sync from filesystem... ---" );
5252 try {
53- Set <String > filesystemFilters = syncFilters ();
53+ Set <Long > filesystemFilters = syncFilters ();
5454 Set <String > filesystemRules = syncRules ();
5555
5656 cleanupOrphanedFilters (filesystemFilters );
@@ -62,12 +62,12 @@ public void run(String... args) {
6262 }
6363 }
6464
65- private Set <String > syncFilters () {
66- Set <String > foundModules = new HashSet <>();
65+ private Set <Long > syncFilters () {
66+ Set <Long > foundFilters = new HashSet <>();
6767 Path filtersPath = Paths .get ("." ,Constants .APP_FILTER_DEFINITIONS );
6868 if (!Files .exists (filtersPath ) || !Files .isDirectory (filtersPath )) {
6969 log .warn ("Filters directory not found: {}" , Constants .APP_FILTER_DEFINITIONS );
70- return foundModules ;
70+ return foundFilters ;
7171 }
7272
7373 // Regex to extract the first dataType from the pipeline structure:
@@ -104,12 +104,12 @@ private Set<String> syncFilters() {
104104 return ;
105105 }
106106
107- foundModules .add (moduleName );
108107
109108 Optional <UtmLogstashFilter > filterOpt = filterRepository .findFirstByLogstashFilterAndSystemOwnerIsTrue (content );
110109
111110 if (filterOpt .isPresent ()) {
112111 UtmLogstashFilter filter = filterOpt .get ();
112+ foundFilters .add (filter .getId ());
113113 if (!content .equals (filter .getLogstashFilter ())) {
114114 log .info ("Updating existing filter for module: {}" , moduleName );
115115 filter .setLogstashFilter (content );
@@ -125,6 +125,7 @@ private Set<String> syncFilters() {
125125 filter .setSystemOwner (true );
126126 filter .setActive (true );
127127 filter .setUpdatedAt (Instant .now ());
128+ foundFilters .add (filter .getId ());
128129
129130
130131 if (dataTypeEntity .isPresent ()) {
@@ -143,7 +144,7 @@ private Set<String> syncFilters() {
143144 } catch (IOException e ) {
144145 log .error ("Error listing filters directory: {}" , e .getMessage ());
145146 }
146- return foundModules ;
147+ return foundFilters ;
147148 }
148149
149150 private Set <String > syncRules () {
@@ -223,12 +224,11 @@ private Set<String> syncRules() {
223224 return foundRules ;
224225 }
225226
226- private void cleanupOrphanedFilters (Set <String > currentFilesystemModules ) {
227- if (currentFilesystemModules .isEmpty ()) return ;
228-
227+ private void cleanupOrphanedFilters (Set <Long > currentFilterIds ) {
228+ if (currentFilterIds .isEmpty ()) return ;
229229 List <UtmLogstashFilter > systemFilters = filterRepository .findAllBySystemOwnerIsTrue ();
230230 systemFilters .stream ()
231- .filter (filter -> !currentFilesystemModules .contains (filter .getModuleName ()))
231+ .filter (filter -> !currentFilterIds .contains (filter .getId ()))
232232 .forEach (filter -> {
233233 log .info ("Deleting orphaned system filter: {}" , filter .getModuleName ());
234234 filterService .delete (filter .getId ());
0 commit comments