diff --git a/src/main/java/org/ohdsi/webapi/achilles/service/AchillesCacheService.java b/src/main/java/org/ohdsi/webapi/achilles/service/AchillesCacheService.java index 4502dd07f..023f6d7d6 100644 --- a/src/main/java/org/ohdsi/webapi/achilles/service/AchillesCacheService.java +++ b/src/main/java/org/ohdsi/webapi/achilles/service/AchillesCacheService.java @@ -102,7 +102,8 @@ public void clearCache() { sources.stream().forEach(this::clearCache); } - private void clearCache(Source source) { + @Transactional() + public void clearCache(Source source) { if (sourceAccessor.hasAccess(source)) { cacheRepository.deleteBySource(source); } diff --git a/src/main/java/org/ohdsi/webapi/cdmresults/service/CDMCacheService.java b/src/main/java/org/ohdsi/webapi/cdmresults/service/CDMCacheService.java index 14855bc5f..8b7a6e520 100644 --- a/src/main/java/org/ohdsi/webapi/cdmresults/service/CDMCacheService.java +++ b/src/main/java/org/ohdsi/webapi/cdmresults/service/CDMCacheService.java @@ -107,7 +107,8 @@ public void clearCache() { sources.stream().forEach(this::clearCache); } - private void clearCache(Source source) { + @Transactional() + public void clearCache(Source source) { if (sourceAccessor.hasAccess(source)) { cdmCacheRepository.deleteBySource(source.getSourceId()); } diff --git a/src/main/java/org/ohdsi/webapi/security/model/SourcePermissionSchema.java b/src/main/java/org/ohdsi/webapi/security/model/SourcePermissionSchema.java index c510776be..ae457d252 100644 --- a/src/main/java/org/ohdsi/webapi/security/model/SourcePermissionSchema.java +++ b/src/main/java/org/ohdsi/webapi/security/model/SourcePermissionSchema.java @@ -33,6 +33,7 @@ public class SourcePermissionSchema extends EntityPermissionSchema { put("cdmresults:%s:*:get", "Get Achilles reports on Source with SourceKey = %s"); put("cdmresults:%s:conceptRecordCount:post", "Get Achilles concept counts on Source with SourceKey = %s"); put("cdmresults:%s:*:*:get", "Get Achilles reports details on Source with SourceKey = %s"); + put("cdmresults:%s:clearcache:post", "Clear the Achilles and CDM results caches on Source with SourceKey = %s"); put("cohortresults:%s:*:*:get", "Get cohort results on Source with SourceKey = %s"); put("cohortresults:%s:*:*:*:get", "Get cohort results details on Source with SourceKey = %s"); put("cohortresults:%s:*:healthcareutilization:*:*:get", "Get cohort results baseline on period for Source with SourceKey = %s"); diff --git a/src/main/java/org/ohdsi/webapi/service/CDMResultsService.java b/src/main/java/org/ohdsi/webapi/service/CDMResultsService.java index f44353a01..c887962d1 100644 --- a/src/main/java/org/ohdsi/webapi/service/CDMResultsService.java +++ b/src/main/java/org/ohdsi/webapi/service/CDMResultsService.java @@ -284,6 +284,25 @@ public JobExecutionResource refreshCache(@PathParam("sourceKey") final String so } return new JobExecutionResource(); } + + /** + * Clear the cdm_cache and achilles_cache for all sources + * + * @summary Clear the cdm_cache and achilles_cache for all sources + * @return void + * @throws ForbiddenException if the user is not an admin + */ + @POST + @Path("{sourceKey}/clearCache") + @Transactional() + public void clearCacheForSource(@PathParam("sourceKey") final String sourceKey) { + if (!isSecured() || !isAdmin()) { + throw new ForbiddenException(); + } + Source source = getSourceRepository().findBySourceKey(sourceKey); + cacheService.clearCache(source); + cdmCacheService.clearCache(source); + } /** * Clear the cdm_cache and achilles_cache for all sources diff --git a/src/main/resources/db/migration/postgresql/V2.15.0.20241113115700__add_clearcache_permission.sql b/src/main/resources/db/migration/postgresql/V2.15.0.20241113115700__add_clearcache_permission.sql index b2ba6fc69..080e45593 100644 --- a/src/main/resources/db/migration/postgresql/V2.15.0.20241113115700__add_clearcache_permission.sql +++ b/src/main/resources/db/migration/postgresql/V2.15.0.20241113115700__add_clearcache_permission.sql @@ -1,7 +1,7 @@ INSERT INTO ${ohdsiSchema}.sec_permission (id, value, description) SELECT nextval('${ohdsiSchema}.sec_permission_id_seq'), 'cdmresults:clearcache:post', - 'Clear the achilles and cdm results caches'; + 'Clear the Achilles and CDM results caches'; INSERT INTO ${ohdsiSchema}.sec_role_permission (role_id, permission_id) SELECT sr.id, sp.id @@ -12,3 +12,18 @@ WHERE sp."value" in 'cdmresults:clearcache:post' ) AND sr.name IN ('admin'); + +INSERT INTO ${ohdsiSchema}.sec_permission (id, value, description) +SELECT nextval('${ohdsiSchema}.sec_permission_id_seq'), + 'cdmresults:*:clearcache:post', + 'Clear the Achilles and CDM results caches'; + +INSERT INTO ${ohdsiSchema}.sec_role_permission (role_id, permission_id) +SELECT sr.id, sp.id +FROM ${ohdsiSchema}.sec_permission sp, + ${ohdsiSchema}.sec_role sr +WHERE sp."value" in + ( + 'cdmresults:*:clearcache:post' + ) + AND sr.name IN ('admin');