1 |
62395
|
konstantin
|
package eu.dnetlib.uoaadmintools.controllers;
|
2 |
|
|
|
3 |
|
|
import eu.dnetlib.uoaadmintools.configuration.properties.BrowserCacheConfig;
|
4 |
|
|
import org.apache.log4j.Logger;
|
5 |
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
6 |
|
|
import org.springframework.security.access.prepost.PreAuthorize;
|
7 |
|
|
import org.springframework.web.bind.annotation.*;
|
8 |
|
|
import org.springframework.web.client.HttpClientErrorException;
|
9 |
|
|
import org.springframework.web.client.ResourceAccessException;
|
10 |
|
|
import org.springframework.web.client.RestTemplate;
|
11 |
|
|
|
12 |
|
|
@RestController
|
13 |
|
|
@RequestMapping("/cache")
|
14 |
|
|
@CrossOrigin(origins = "*")
|
15 |
|
|
public class BrowserCacheController {
|
16 |
|
|
private final Logger log = Logger.getLogger(this.getClass());
|
17 |
|
|
|
18 |
|
|
@Autowired
|
19 |
|
|
private RestTemplate restTemplate;
|
20 |
|
|
|
21 |
|
|
@Autowired
|
22 |
|
|
private BrowserCacheConfig config;
|
23 |
|
|
|
24 |
|
|
@PreAuthorize("hasAnyAuthority(" +
|
25 |
|
|
"@AuthorizationService.PORTAL_ADMIN, " +
|
26 |
|
|
"@AuthorizationService.curator('community'), @AuthorizationService.manager('community', #pid))")
|
27 |
|
|
@RequestMapping(value = "/{pid}", method = RequestMethod.GET)
|
28 |
|
|
public boolean purge(@PathVariable(value = "pid") String pid) {
|
29 |
62397
|
konstantin
|
// try {
|
30 |
|
|
restTemplate.getForEntity(config.getUrl().replace("{community}", pid), String.class);
|
31 |
|
|
// } catch(HttpClientErrorException httpClientErrorException) {
|
32 |
|
|
// log.debug("Purge browser cache: HttpClientErrorException for "+pid + " - code: " + httpClientErrorException.getStatusCode());
|
33 |
|
|
// return false;
|
34 |
|
|
// } catch(ResourceAccessException resourceAccessException) {
|
35 |
|
|
// log.debug("Purge browser cache: ResourceAccessException for "+pid);
|
36 |
|
|
// return false;
|
37 |
|
|
// } catch(Exception exception) {
|
38 |
|
|
// log.debug("Purge browser cache: " + exception.getClass() + " for "+pid);
|
39 |
|
|
// return false;
|
40 |
|
|
// }
|
41 |
62395
|
konstantin
|
return true;
|
42 |
|
|
}
|
43 |
|
|
}
|