[Admin tools | Trunk]: Added endpoing for purging browser cache.

1. admintools.properties: Added property "admintool.cache.url".
2. BrowserCacheConfig.java: Added config for browser cache properties.
3. UoaAdminToolsApplication.java: In EnableConfigurationProperties added BrowserCacheConfig.
4. BrowserCacheController.java: Added class and method "purge()" (/cache/{pid}) for purging browser cache for a specific community.
This commit is contained in:
Konstantina Galouni 2022-08-11 12:50:59 +00:00
parent b5de59ee75
commit 6e14c0b41b
4 changed files with 60 additions and 1 deletions

View File

@ -2,6 +2,7 @@ package eu.dnetlib.uoaadmintools;
import com.fasterxml.jackson.databind.ObjectMapper;
import eu.dnetlib.uoaadmintools.configuration.GlobalVars;
import eu.dnetlib.uoaadmintools.configuration.properties.BrowserCacheConfig;
import eu.dnetlib.uoaadmintools.configuration.properties.ManagersApiConfig;
import eu.dnetlib.uoaadmintools.configuration.properties.MongoConfig;
import eu.dnetlib.uoaadmintoolslibrary.UoaAdminToolsLibraryConfiguration;
@ -23,7 +24,7 @@ import org.springframework.web.client.RestTemplate;
@PropertySource("classpath:admintools.properties"),
@PropertySource(value = "classpath:dnet-override.properties", ignoreResourceNotFound = true)
})
@EnableConfigurationProperties({MongoConfig.class, ManagersApiConfig.class, GlobalVars.class})
@EnableConfigurationProperties({MongoConfig.class, ManagersApiConfig.class, BrowserCacheConfig.class, GlobalVars.class})
@Import({AuthorizationConfiguration.class, UoaAdminToolsLibraryConfiguration.class})
public class UoaAdminToolsApplication {

View File

@ -0,0 +1,16 @@
package eu.dnetlib.uoaadmintools.configuration.properties;
import org.springframework.boot.context.properties.ConfigurationProperties;
@ConfigurationProperties("admintool.cache")
public class BrowserCacheConfig {
private String url;
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
}

View File

@ -0,0 +1,41 @@
package eu.dnetlib.uoaadmintools.controllers;
import eu.dnetlib.uoaadmintools.configuration.properties.BrowserCacheConfig;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.HttpClientErrorException;
import org.springframework.web.client.ResourceAccessException;
import org.springframework.web.client.RestTemplate;
@RestController
@RequestMapping("/cache")
@CrossOrigin(origins = "*")
public class BrowserCacheController {
private final Logger log = Logger.getLogger(this.getClass());
@Autowired
private RestTemplate restTemplate;
@Autowired
private BrowserCacheConfig config;
@PreAuthorize("hasAnyAuthority(" +
"@AuthorizationService.PORTAL_ADMIN, " +
"@AuthorizationService.curator('community'), @AuthorizationService.manager('community', #pid))")
@RequestMapping(value = "/{pid}", method = RequestMethod.GET)
public boolean purge(@PathVariable(value = "pid") String pid) {
try {
ResponseEntity<Object> responseEntity = restTemplate.getForEntity(config.getUrl().replace("{community}", pid), Object.class);
} catch(HttpClientErrorException httpClientErrorException) {
log.debug("Purge browser cache: HttpClientErrorException for "+pid + " - code: " + httpClientErrorException.getStatusCode());
} catch(ResourceAccessException resourceAccessException) {
log.debug("Purge browser cache: ResourceAccessException for "+pid);
} catch(Exception exception) {
log.debug("Purge browser cache: " + exception.getClass() + " for "+pid);
}
return true;
}
}

View File

@ -16,6 +16,7 @@ admintool.managers.api.id = http://dl170.madgik.di.uoa.gr:8180/dnet-openaire-use
admintool.managers.api.email = http://dl170.madgik.di.uoa.gr:8180/dnet-openaire-users-1.0.0-SNAPSHOT/api/registry/community/{community}/managers/email
admintool.globalVars.buildDate=@timestamp@
admintool.globalVars.version=@project.version@
admintool.cache.url = https://beta.{community}.openaire.eu/purge/
#beta
#admintool.security.userInfoUrl = https://beta.services.openaire.eu/uoa-user-management/api/users/getUserInfo?accessToken=