31
31
import org .springframework .util .CollectionUtils ;
32
32
import org .springframework .web .client .HttpClientErrorException ;
33
33
34
- import java .io .*;
34
+ import java .io .IOException ;
35
+ import java .io .InputStream ;
35
36
import java .nio .file .Files ;
36
37
import java .nio .file .Path ;
37
38
import java .nio .file .Paths ;
@@ -171,26 +172,31 @@ public String getAutomatonDefinitions() {
171
172
}
172
173
173
174
@ Override
175
+ @ Transactional (readOnly = true )
174
176
public List <SimpleModel > getModels () {
175
- return modelRepository .findAll ().stream ().map (modelEntity -> new SimpleModel (new Model (modelEntity ))).collect ( Collectors . toList () );
177
+ return modelRepository .findAll ().stream ().map (modelEntity -> new SimpleModel (new Model (modelEntity ))).toList ();
176
178
}
177
179
178
180
@ Override
181
+ @ Transactional (readOnly = true )
179
182
public List <ModelParameter > getParameters () {
180
183
return modelParameterRepository .findAll ().stream ().map (ModelParameter ::new ).toList ();
181
184
}
182
185
183
186
@ Override
187
+ @ Transactional (readOnly = true )
184
188
public List <ParametersSetsGroup > getParametersSetsGroups () {
185
189
return modelSetsGroupRepository .findAll ().stream ().map (ParametersSetsGroup ::new ).toList ();
186
190
}
187
191
188
192
@ Override
193
+ @ Transactional (readOnly = true )
189
194
public List <ParametersSet > getParametersSets () {
190
195
return modelParameterSetRepository .findAll ().stream ().map (ParametersSet ::new ).toList ();
191
196
}
192
197
193
198
@ Override
199
+ @ Transactional (readOnly = true )
194
200
public List <ParametersSet > getSetsFromGroup (String modelName , String groupName , SetGroupType groupType ) {
195
201
Optional <ModelEntity > foundModelOpt = modelRepository .findById (modelName );
196
202
@@ -201,7 +207,7 @@ public List<ParametersSet> getSetsFromGroup(String modelName, String groupName,
201
207
.findAny ();
202
208
ModelSetsGroupEntity setsGroup = getSetsGroupFromOptional ("[" + groupName + "," + groupType .name () + "]" , modelSetsGroupOpt );
203
209
204
- return setsGroup .getSets ().stream ().map (ParametersSet ::new ).collect ( Collectors . toList () );
210
+ return setsGroup .getSets ().stream ().map (ParametersSet ::new ).toList ();
205
211
}
206
212
207
213
@ Override
@@ -220,9 +226,7 @@ public ParametersSetsGroup saveParametersSetsGroup(String modelName, ParametersS
220
226
savedGroups .add (groupToAdd );
221
227
} else {
222
228
// If additional checks are required here, ensure that set erasure cannot happen here with sets merging.
223
- groupToAdd .getSets ().forEach (set ->
224
- previousGroup .addParameterSet (set )
225
- );
229
+ groupToAdd .getSets ().forEach (previousGroup ::addParameterSet );
226
230
}
227
231
228
232
if (new Model (modelToUpdate ).isParameterSetGroupValid (setsGroup .getName (), strict )) {
@@ -302,6 +306,7 @@ public List<String> deleteModels(List<String> modelNames) {
302
306
}
303
307
304
308
@ Override
309
+ @ Transactional
305
310
public ParametersSetsGroup deleteSet (String modelName , String groupName , SetGroupType groupType , String setName ) {
306
311
Optional <ModelEntity > foundModelOpt = modelRepository .findById (modelName );
307
312
@@ -327,11 +332,13 @@ public ParametersSetsGroup deleteSet(String modelName, String groupName, SetGrou
327
332
// --- BEGIN parameter definition-related service methods --- //
328
333
329
334
@ Override
335
+ @ Transactional (readOnly = true )
330
336
public List <String > getParameterDefinitionNames () {
331
337
return modelParameterDefinitionRepository .findAll ().stream ().map (ModelParameterDefinitionEntity ::getName ).toList ();
332
338
}
333
339
334
340
@ Override
341
+ @ Transactional (readOnly = true )
335
342
public List <ModelParameterDefinition > getParameterDefinitions (List <String > parameterDefinitionNames ) {
336
343
return modelParameterDefinitionRepository .findAllById (parameterDefinitionNames ).stream ()
337
344
.map (parameterDefinitionEntity -> new ModelParameterDefinition (parameterDefinitionEntity , null , null )).toList ();
@@ -382,8 +389,8 @@ public Model addExistingParameterDefinitionsToModel(String modelName, List<Strin
382
389
// check whether found all, fail fast
383
390
if (foundParameterDefinitionEntities .size () != parameterDefinitionNames .size ()) {
384
391
List <String > foundNames = foundParameterDefinitionEntities .stream ()
385
- .map (ModelParameterDefinitionEntity ::getName ).collect ( Collectors . toList () );
386
- List <String > notFoundNames = parameterDefinitionNames .stream ().filter (name -> !foundNames .contains (name )).collect ( Collectors . toList () );
392
+ .map (ModelParameterDefinitionEntity ::getName ).toList ();
393
+ List <String > notFoundNames = parameterDefinitionNames .stream ().filter (name -> !foundNames .contains (name )).toList ();
387
394
throw new HttpClientErrorException (HttpStatus .NOT_FOUND , "Some parameter definition not found: " + notFoundNames );
388
395
}
389
396
@@ -430,7 +437,7 @@ public Model removeAllParameterDefinitionsOnModel(String modelName) {
430
437
431
438
// clear the existing list
432
439
modelToUpdate .removeAllParameterDefinition (modelToUpdate .getParameterDefinitions ().stream ()
433
- .map (ModelModelParameterDefinitionEntity ::getParameterDefinition ).collect ( Collectors . toList () ));
440
+ .map (ModelModelParameterDefinitionEntity ::getParameterDefinition ).toList ());
434
441
435
442
// save modified existing model entity
436
443
modelRepository .save (modelToUpdate );
@@ -446,7 +453,7 @@ public List<ModelParameterDefinition> saveNewParameterDefinitions(List<ModelPara
446
453
.map (ModelParameterDefinitionEntity ::new )
447
454
.collect (Collectors .toCollection (LinkedHashSet ::new ));
448
455
List <ModelParameterDefinitionEntity > savedParameterDefinitionEntities = modelParameterDefinitionRepository .saveAll (parameterDefinitionEntities );
449
- return savedParameterDefinitionEntities .stream ().map (entity -> new ModelParameterDefinition (entity , null , null )).collect ( Collectors . toList () );
456
+ return savedParameterDefinitionEntities .stream ().map (entity -> new ModelParameterDefinition (entity , null , null )).toList ();
450
457
}
451
458
452
459
return Collections .emptyList ();
@@ -476,10 +483,12 @@ public List<ModelVariableDefinition> getVariableDefinitionsFromModel(String mode
476
483
}
477
484
478
485
@ Override
486
+ @ Transactional (readOnly = true )
479
487
public List <String > getVariableDefinitionNames () {
480
488
return modelVariableRepository .findAll ().stream ().map (ModelVariableDefinitionEntity ::getName ).toList ();
481
489
}
482
490
491
+ @ Transactional (readOnly = true )
483
492
@ Override
484
493
public List <ModelVariableDefinition > getVariableDefinitions (List <String > variableNames ) {
485
494
return modelVariableRepository .findAllById (variableNames ).stream ().map (ModelVariableDefinition ::new ).toList ();
@@ -497,7 +506,7 @@ public Model addNewVariableDefinitionsToModel(String modelName, List<ModelVariab
497
506
// do merge with existing list
498
507
List <ModelVariableDefinitionEntity > variableDefinitionEntities = variableDefinitions .stream ()
499
508
.map (variableDefinition -> new ModelVariableDefinitionEntity (modelToUpdate , null , variableDefinition ))
500
- .collect ( Collectors . toList () );
509
+ .toList ();
501
510
modelToUpdate .addAllVariableDefinition (variableDefinitionEntities );
502
511
// save modified existing model entity
503
512
modelRepository .save (modelToUpdate );
@@ -522,8 +531,8 @@ public Model addExistingVariableDefinitionsToModel(String modelName, List<String
522
531
// check whether found all, fail fast
523
532
if (foundVariableDefinitionEntities .size () != variableDefinitionNames .size ()) {
524
533
List <String > foundNames = foundVariableDefinitionEntities .stream ()
525
- .map (ModelVariableDefinitionEntity ::getName ).collect ( Collectors . toList () );
526
- List <String > notFoundNames = variableDefinitionNames .stream ().filter (name -> !foundNames .contains (name )).collect ( Collectors . toList () );
534
+ .map (ModelVariableDefinitionEntity ::getName ).toList ();
535
+ List <String > notFoundNames = variableDefinitionNames .stream ().filter (name -> !foundNames .contains (name )).toList ();
527
536
throw new HttpClientErrorException (HttpStatus .NOT_FOUND , "Some variable definition not found: " + notFoundNames );
528
537
}
529
538
@@ -567,7 +576,7 @@ public List<ModelVariableDefinition> saveNewVariableDefinitions(List<ModelVariab
567
576
.map (variableDefinition -> new ModelVariableDefinitionEntity (null , null , variableDefinition ))
568
577
.collect (Collectors .toCollection (LinkedHashSet ::new ));
569
578
List <ModelVariableDefinitionEntity > savedVariableDefinitionEntities = modelVariableRepository .saveAll (variableDefinitionEntities );
570
- return savedVariableDefinitionEntities .stream ().map (ModelVariableDefinition ::new ).collect ( Collectors . toList () );
579
+ return savedVariableDefinitionEntities .stream ().map (ModelVariableDefinition ::new ).toList ();
571
580
}
572
581
return Collections .emptyList ();
573
582
}
@@ -589,6 +598,7 @@ public Model removeAllVariableDefinitionsOnModel(String modelName) {
589
598
}
590
599
591
600
@ Override
601
+ @ Transactional (readOnly = true )
592
602
public List <String > getVariablesSetNames () {
593
603
return modelVariablesSetRepository .findAll ().stream ().map (ModelVariableSetEntity ::getName ).toList ();
594
604
}
@@ -640,7 +650,7 @@ public VariablesSet addNewVariableDefinitionToVariablesSet(String variableSetNam
640
650
// do merge with existing list
641
651
List <ModelVariableDefinitionEntity > variableDefinitionEntities = variableDefinitions .stream ()
642
652
.map (variableDefinition -> new ModelVariableDefinitionEntity (null , variableSetToUpdate , variableDefinition ))
643
- .collect ( Collectors . toList () );
653
+ .toList ();
644
654
variableSetToUpdate .addAllVariableDefinition (variableDefinitionEntities );
645
655
// save modified existing variables set entity
646
656
modelVariablesSetRepository .save (variableSetToUpdate );
@@ -697,7 +707,7 @@ public Model addNewVariablesSetsToModel(String modelName, List<VariablesSet> var
697
707
// do merge with existing list
698
708
List <ModelVariableSetEntity > variablesSetEntities = variableSets .stream ()
699
709
.map (variablesSet -> new ModelVariableSetEntity (modelToUpdate , variablesSet ))
700
- .collect ( Collectors . toList () );
710
+ .toList ();
701
711
modelToUpdate .addAllVariablesSet (variablesSetEntities );
702
712
// save modified existing model entity
703
713
modelRepository .save (modelToUpdate );
@@ -720,8 +730,8 @@ public Model addExistingVariablesSetsToModel(String modelName, List<String> vari
720
730
721
731
// check whether found all
722
732
if (foundVariablesSetEntities .size () != variablesSetNames .size ()) {
723
- List <String > foundNames = foundVariablesSetEntities .stream ().map (ModelVariableSetEntity ::getName ).collect ( Collectors . toList () );
724
- List <String > notFoundNames = variablesSetNames .stream ().filter (name -> !foundNames .contains (name )).collect ( Collectors . toList () );
733
+ List <String > foundNames = foundVariablesSetEntities .stream ().map (ModelVariableSetEntity ::getName ).toList ();
734
+ List <String > notFoundNames = variablesSetNames .stream ().filter (name -> !foundNames .contains (name )).toList ();
725
735
throw new HttpClientErrorException (HttpStatus .NOT_FOUND , "Some variables set not found: " + notFoundNames );
726
736
}
727
737
0 commit comments