@@ -88,36 +88,61 @@ public Optional<UtmModuleGroup> findOne(Long id) {
8888 return moduleGroupRepository .findById (id );
8989 }
9090
91- /**
92- * Delete the utmConfigurationGroup by id.
93- *
94- * @param id the id of the entity
95- */
96-
97- public UtmModule delete (Long id ) {
98- final String ctx = CLASSNAME + ".delete" ;
99- long start = System .currentTimeMillis ();
91+ @ Transactional
92+ public void deleteGroup (Long id ) {
10093
10194 UtmModuleGroup moduleGroup = this .moduleGroupRepository .findById (id )
10295 .orElseThrow (() -> new EntityNotFoundException ("Configuration group not found with ID: " + id ));
10396
97+ Long moduleId = moduleGroup .getModule ().getId ();
10498 String moduleName = String .valueOf (moduleGroup .getModule ().getModuleName ());
99+
105100 Map <String , Object > extra = Map .of (
106- "ModuleId" , moduleGroup . getModule (). getId () ,
101+ "ModuleId" , moduleId ,
107102 "ModuleName" , moduleName ,
108103 "GroupId" , id
109104 );
110105
111- String attemptMsg = String .format ("Initiating deletion of configuration group (ID: %d) for module '%s'" , id , moduleName );
106+ String attemptMsg = String .format (
107+ "Initiating deletion of configuration group (ID: %d) for module '%s'" ,
108+ id , moduleName
109+ );
112110 applicationEventService .createEvent (attemptMsg , ApplicationEventType .CONFIG_GROUP_DELETE_ATTEMPT , extra );
113111
114112 moduleGroupRepository .deleteById (id );
115113
116- long duration = System .currentTimeMillis () - start ;
117- String successMsg = String .format ("Configuration group (ID: %d) for module '%s' deleted successfully in %dms" , id , moduleName , duration );
114+ String successMsg = String .format (
115+ "Configuration group (ID: %d) for module '%s' deleted successfully" ,
116+ id , moduleName
117+ );
118118 applicationEventService .createEvent (successMsg , ApplicationEventType .CONFIG_GROUP_DELETE_SUCCESS , extra );
119+ }
120+
121+ public void deleteAndFetch (Long id ) {
122+
123+ try {
124+ Long moduleId = moduleGroupRepository .findById (id )
125+ .orElseThrow (() -> new EntityNotFoundException ("Configuration group not found with ID: " + id ))
126+ .getModule ()
127+ .getId ();
128+
129+ deleteGroup (id );
130+
131+ UtmModule module = moduleService .findOne (moduleId )
132+ .orElseThrow (() -> new EntityNotFoundException ("Module not found with id " + moduleId ));
133+
134+ ModuleDTO moduleDTO = moduleMapper .toDto (module , false );
135+
136+ moduleDTO .setModuleGroups (
137+ moduleDTO .getModuleGroups ().stream ().filter (g -> !g .getId ().equals (id )).collect (Collectors .toSet ())
138+ );
139+ eventProcessorManagerService .updateModule (moduleDTO );
140+
141+ } catch (Exception e ) {
142+ log .error ("{}: Error deleting configuration group with ID {}: {}" , CLASSNAME , id , e .getMessage ());
143+ throw new ApiException (String .format ("%s: Error deleting configuration group with ID %d" , CLASSNAME , id ), HttpStatus .INTERNAL_SERVER_ERROR );
144+ }
119145
120- return moduleGroup .getModule ();
121146 }
122147
123148
@@ -150,7 +175,7 @@ public List<UtmModuleGroup> findAllByModuleId(Long moduleId) throws Exception {
150175 public List <UtmModuleGroup > findAllByCollectorId (String collectorId ) {
151176 String ctx = CLASSNAME + ".findAllByCollectorId" ;
152177 try {
153- return moduleGroupRepository .findAllByCollector (collectorId );
178+ return moduleGroupRepository .findAllByCollector (collectorId );
154179 } catch (Exception e ) {
155180 log .error ("{}: Error finding module groups by collector id {}: {}" , ctx , collectorId , e .getMessage ());
156181 throw new ApiException (String .format ("%s: Error finding module groups by collector id %s" , ctx , collectorId ), HttpStatus .INTERNAL_SERVER_ERROR );
@@ -224,7 +249,7 @@ public void updateCollectorConfigurationKeys(CollectorConfigDTO collectorConfig)
224249 moduleGroupRepository .deleteAll (dbConfigs );
225250 } else {
226251 for (UtmModuleGroupConfiguration key : keys ) {
227- if (key .getConfDataType ().equals ("password" )){
252+ if (key .getConfDataType ().equals ("password" )) {
228253 key .setConfValue (CipherUtil .encrypt (key .getConfValue (), System .getenv (Constants .ENV_ENCRYPTION_KEY )));
229254 }
230255 }
0 commit comments