1919import java .util .Optional ;
2020import java .util .function .Predicate ;
2121import java .util .stream .Collectors ;
22+ import javax .annotation .Nullable ;
23+ import javax .cache .Cache ;
24+ import javax .cache .CacheManager ;
2225import org .ohdsi .webapi .analysis .AnalysisConceptSet ;
2326import org .ohdsi .webapi .conceptset .ConceptSetItem ;
2427import org .ohdsi .webapi .service .ConceptSetService ;
2528import org .ohdsi .webapi .service .dto .ConceptSetDTO ;
29+ import org .ohdsi .webapi .shiro .PermissionManager ;
2630import org .springframework .core .convert .ConversionService ;
2731
2832@ Service
@@ -34,17 +38,20 @@ public class DesignImportService {
3438 private final ConversionService conversionService ;
3539 private final ConceptSetService conceptSetService ;
3640 private final CohortDefinitionService cohortDefinitionService ;
41+ private final CacheManager cacheManager ;
3742
3843 public DesignImportService (Security security , UserRepository userRepository , CohortDefinitionRepository cohortRepository ,
3944 CohortDefinitionDetailsRepository detailsRepository , ConceptSetService conceptSetService ,
40- ConversionService conversionService , CohortDefinitionService cohortDefinitionService ) {
45+ ConversionService conversionService , CohortDefinitionService cohortDefinitionService ,
46+ @ Nullable CacheManager cacheManager ) {
4147 this .security = security ;
4248 this .userRepository = userRepository ;
4349 this .cohortRepository = cohortRepository ;
4450 this .detailsRepository = detailsRepository ;
4551 this .conceptSetService = conceptSetService ;
4652 this .conversionService = conversionService ;
4753 this .cohortDefinitionService = cohortDefinitionService ;
54+ this .cacheManager = cacheManager ;
4855 }
4956
5057 public ConceptSetDTO persistConceptSet (final AnalysisConceptSet analysisConceptSet ) {
@@ -75,6 +82,16 @@ public CohortDefinition persistCohortOrGetExisting(final CohortDefinition cohort
7582 cohort .setName (NameUtils .getNameWithSuffix (cohort .getName (), this ::getCdNamesLike ));
7683 final CohortDefinition savedCohort = cohortRepository .save (cohort );
7784 detailsRepository .save (details );
85+
86+ // if this is new, we will need to decache the cohort definition list
87+ if (this .cacheManager != null ) {
88+ Cache cohortDefCache = cacheManager .getCache (CohortDefinitionService .CachingSetup .COHORT_DEFINITION_LIST_CACHE );
89+ if (cohortDefCache != null ) {
90+ cohortDefCache .clear (); // wipes all entries in cohort definition list cache cache
91+ }
92+ }
93+ // permission caching is handled via the EntityInsertEventListener and EntityPermissionSchema.onInsert
94+
7895 return savedCohort ;
7996 });
8097 }
0 commit comments