Revision 49396
Added by Alessia Bardi over 6 years ago
RegistryClientFactory.java | ||
---|---|---|
2 | 2 |
|
3 | 3 |
import eu.dnetlib.parthenos.publisher.ParthenosPublisherException; |
4 | 4 |
import eu.dnetlib.parthenos.publisher.SaxonHelper; |
5 |
import org.apache.commons.lang3.StringUtils; |
|
6 | 5 |
import org.apache.commons.logging.Log; |
7 | 6 |
import org.apache.commons.logging.LogFactory; |
8 |
import org.gcube.common.authorization.client.Constants; |
|
9 |
import org.gcube.common.authorization.library.AuthorizationEntry; |
|
10 |
import org.gcube.common.authorization.library.provider.SecurityTokenProvider; |
|
11 |
import org.gcube.common.scope.api.ScopeProvider; |
|
12 |
import org.gcube.informationsystem.resourceregistry.client.ParthenosRegistryClientSetter; |
|
13 |
import org.gcube.informationsystem.resourceregistry.publisher.ParthenosRegistryPublisherSetter; |
|
14 | 7 |
import org.springframework.beans.factory.annotation.Autowired; |
15 | 8 |
import org.springframework.beans.factory.annotation.Value; |
16 | 9 |
import org.springframework.stereotype.Component; |
... | ... | |
25 | 18 |
|
26 | 19 |
private static final Log log = LogFactory.getLog(RegistryClientFactory.class); |
27 | 20 |
|
28 |
@Value("${gcube.registry.baseurl}") |
|
29 |
private String registryBaseURL; |
|
30 | 21 |
@Value("${gcube.registry.uri.base.default}") |
31 | 22 |
private String defaultBaseURI; |
32 |
@Value("${gcube.registry.application.token}") |
|
33 |
private String applicationToken; |
|
34 | 23 |
|
35 | 24 |
@Autowired |
36 | 25 |
private SaxonHelper saxonHelper; |
37 | 26 |
@Autowired |
38 |
private GCubeResourceRegistrator resourceGenerator;
|
|
27 |
private GCubeResourceRegistrator gCubeResourceRegistrator;
|
|
39 | 28 |
|
40 | 29 |
public RegistryClient getRegistryClient() throws ParthenosPublisherException { |
41 |
log.debug("Creating RegistryClient for "+registryBaseURL);
|
|
42 |
return new RegistryClient(registryBaseURL, getSaxonHelper(), defaultBaseURI, getResourceGenerator());
|
|
30 |
log.debug("Creating RegistryClient");
|
|
31 |
return new RegistryClient(getSaxonHelper(), defaultBaseURI, getgCubeResourceRegistrator());
|
|
43 | 32 |
} |
44 | 33 |
|
45 |
public RegistryClientFactory() throws Exception { |
|
46 |
log.info("Creating RegistryClientFactory"); |
|
47 |
ParthenosRegistryClientSetter.forceToURL(registryBaseURL); |
|
48 |
ParthenosRegistryPublisherSetter.forceToURL(registryBaseURL); |
|
49 |
log.info("Registry URL forced to "+registryBaseURL); |
|
50 |
if(StringUtils.isNotBlank(getApplicationToken())) { |
|
51 |
RegistryClientFactory.setContext(getApplicationToken()); |
|
52 |
log.info("GCube Context set"); |
|
53 |
} |
|
54 |
else{ |
|
55 |
log.fatal("GCube context cannot be configured without a value in gcube.registry.application.token"); |
|
56 |
} |
|
57 |
} |
|
58 |
|
|
59 |
public static String getCurrentScope(String token) throws Exception { |
|
60 |
AuthorizationEntry authorizationEntry = Constants.authorizationService().get(token); |
|
61 |
String context = authorizationEntry.getContext(); |
|
62 |
log.info("Context of token "+token+" is: "+context); |
|
63 |
return context; |
|
64 |
} |
|
65 |
|
|
66 |
public static void setContext(String token) throws Exception { |
|
67 |
SecurityTokenProvider.instance.set(token); |
|
68 |
ScopeProvider.instance.set(getCurrentScope(token)); |
|
69 |
} |
|
70 |
|
|
71 |
public String getApplicationToken() { |
|
72 |
return applicationToken; |
|
73 |
} |
|
74 |
|
|
75 |
public void setApplicationToken(final String applicationToken) { |
|
76 |
this.applicationToken = applicationToken; |
|
77 |
} |
|
78 |
|
|
79 |
|
|
80 |
public String getRegistryBaseURL() { |
|
81 |
return registryBaseURL; |
|
82 |
} |
|
83 |
|
|
84 |
public void setRegistryBaseURL(final String registryBaseURL) { |
|
85 |
this.registryBaseURL = registryBaseURL; |
|
86 |
} |
|
87 |
|
|
88 | 34 |
public SaxonHelper getSaxonHelper() { |
89 | 35 |
return saxonHelper; |
90 | 36 |
} |
... | ... | |
101 | 47 |
this.defaultBaseURI = defaultBaseURI; |
102 | 48 |
} |
103 | 49 |
|
104 |
public GCubeResourceRegistrator getResourceGenerator() {
|
|
105 |
return resourceGenerator;
|
|
50 |
public GCubeResourceRegistrator getgCubeResourceRegistrator() {
|
|
51 |
return gCubeResourceRegistrator;
|
|
106 | 52 |
} |
107 | 53 |
|
108 |
public void setResourceGenerator(final GCubeResourceRegistrator resourceGenerator) {
|
|
109 |
this.resourceGenerator = resourceGenerator;
|
|
54 |
public void setgCubeResourceRegistrator(final GCubeResourceRegistrator gCubeResourceRegistrator) {
|
|
55 |
this.gCubeResourceRegistrator = gCubeResourceRegistrator;
|
|
110 | 56 |
} |
111 | 57 |
} |
Also available in: Unified diff
Fixed circular dependency