Revision 49396
Added by Alessia Bardi over 6 years ago
modules/dnet-parthenos-publisher/trunk/src/main/java/eu/dnetlib/parthenos/registry/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 |
} |
modules/dnet-parthenos-publisher/trunk/src/main/java/eu/dnetlib/parthenos/registry/GCubeResourceRegistrator.java | ||
---|---|---|
5 | 5 |
import java.util.Map; |
6 | 6 |
import java.util.Set; |
7 | 7 |
import java.util.UUID; |
8 |
import javax.annotation.PostConstruct; |
|
8 | 9 |
|
9 | 10 |
import com.fasterxml.jackson.core.JsonFactory; |
10 | 11 |
import com.fasterxml.jackson.core.JsonGenerator; |
... | ... | |
24 | 25 |
import org.apache.jena.ontology.OntModelSpec; |
25 | 26 |
import org.apache.jena.rdf.model.*; |
26 | 27 |
import org.apache.jena.vocabulary.RDF; |
28 |
import org.gcube.common.authorization.client.Constants; |
|
29 |
import org.gcube.common.authorization.library.AuthorizationEntry; |
|
30 |
import org.gcube.common.authorization.library.provider.SecurityTokenProvider; |
|
31 |
import org.gcube.common.scope.api.ScopeProvider; |
|
27 | 32 |
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException; |
33 |
import org.gcube.informationsystem.resourceregistry.client.ParthenosRegistryClientSetter; |
|
28 | 34 |
import org.gcube.informationsystem.resourceregistry.client.ResourceRegistryClient; |
29 | 35 |
import org.gcube.informationsystem.resourceregistry.client.ResourceRegistryClientFactory; |
36 |
import org.gcube.informationsystem.resourceregistry.publisher.ParthenosRegistryPublisherSetter; |
|
30 | 37 |
import org.gcube.informationsystem.resourceregistry.publisher.ResourceRegistryPublisher; |
31 | 38 |
import org.gcube.informationsystem.resourceregistry.publisher.ResourceRegistryPublisherFactory; |
32 | 39 |
import org.springframework.beans.factory.annotation.Autowired; |
40 |
import org.springframework.beans.factory.annotation.Value; |
|
33 | 41 |
import org.springframework.stereotype.Component; |
34 | 42 |
|
35 | 43 |
/** |
... | ... | |
42 | 50 |
|
43 | 51 |
private static final Log log = LogFactory.getLog(GCubeResourceRegistrator.class); |
44 | 52 |
|
45 |
private OntModel baseModel; |
|
53 |
@Value("${gcube.registry.baseurl}") |
|
54 |
private String registryBaseURL; |
|
55 |
@Value("${gcube.registry.application.token}") |
|
56 |
private String applicationToken; |
|
46 | 57 |
|
47 | 58 |
@Autowired |
48 | 59 |
private FacetWriter facetWriter; |
... | ... | |
52 | 63 |
private ResourceRegistryPublisher resourceRegistryPublisher; |
53 | 64 |
private ResourceRegistryClient resourceRegistryClient; |
54 | 65 |
|
55 |
public GCubeResourceRegistrator() { |
|
66 |
private OntModel baseModel; |
|
67 |
|
|
68 |
@PostConstruct |
|
69 |
public void init() throws Exception { |
|
70 |
ParthenosRegistryClientSetter.forceToURL(getRegistryBaseURL()); |
|
71 |
ParthenosRegistryPublisherSetter.forceToURL(getRegistryBaseURL()); |
|
72 |
log.info("Registry URL forced to "+getRegistryBaseURL()); |
|
73 |
if(StringUtils.isNotBlank(getApplicationToken())) { |
|
74 |
GCubeResourceRegistrator.setContext(getApplicationToken()); |
|
75 |
log.info("GCube Context set"); |
|
76 |
} |
|
77 |
else{ |
|
78 |
log.fatal("GCube context cannot be configured without a value in gcube.registry.application.token"); |
|
79 |
} |
|
56 | 80 |
this.resourceRegistryPublisher = ResourceRegistryPublisherFactory.create(); |
57 | 81 |
this.resourceRegistryClient = ResourceRegistryClientFactory.create(); |
58 | 82 |
baseModel = ModelFactory.createOntologyModel(OntModelSpec.RDFS_MEM_TRANS_INF); |
... | ... | |
61 | 85 |
baseModel.read(CRMdig.RDFS_URL); |
62 | 86 |
} |
63 | 87 |
|
88 |
protected static String getCurrentScope(String token) throws Exception { |
|
89 |
AuthorizationEntry authorizationEntry = Constants.authorizationService().get(token); |
|
90 |
String context = authorizationEntry.getContext(); |
|
91 |
log.info("Context of token "+token+" is: "+context); |
|
92 |
return context; |
|
93 |
} |
|
94 |
|
|
95 |
protected static void setContext(String token) throws Exception { |
|
96 |
SecurityTokenProvider.instance.set(token); |
|
97 |
ScopeProvider.instance.set(getCurrentScope(token)); |
|
98 |
} |
|
99 |
|
|
100 |
|
|
101 |
|
|
64 | 102 |
public int unregister(final String datasourceApi){ |
65 | 103 |
//TODO: implement me |
66 | 104 |
return -1; |
... | ... | |
474 | 512 |
public void setFacetWriter(final FacetWriter facetWriter) { |
475 | 513 |
this.facetWriter = facetWriter; |
476 | 514 |
} |
515 |
|
|
516 |
public String getApplicationToken() { |
|
517 |
return applicationToken; |
|
518 |
} |
|
519 |
|
|
520 |
public void setApplicationToken(final String applicationToken) { |
|
521 |
this.applicationToken = applicationToken; |
|
522 |
} |
|
523 |
|
|
524 |
public String getRegistryBaseURL() { |
|
525 |
return registryBaseURL; |
|
526 |
} |
|
527 |
|
|
528 |
public void setRegistryBaseURL(final String registryBaseURL) { |
|
529 |
this.registryBaseURL = registryBaseURL; |
|
530 |
} |
|
477 | 531 |
} |
modules/dnet-parthenos-publisher/trunk/src/main/java/eu/dnetlib/parthenos/registry/RegistryClient.java | ||
---|---|---|
40 | 40 |
|
41 | 41 |
private ResourceRegistryPublisher resourceRegistryPublisher; |
42 | 42 |
private ResourceRegistryClient resourceRegistryClient; |
43 |
private String registryBaseURL; |
|
43 |
//private String registryBaseURL;
|
|
44 | 44 |
private String defaultBaseURI; |
45 | 45 |
|
46 |
protected RegistryClient(final String registryBaseURL, |
|
47 |
final SaxonHelper saxonHelper, |
|
46 |
protected RegistryClient(final SaxonHelper saxonHelper, |
|
48 | 47 |
final String defaultBaseURI, |
49 | 48 |
final GCubeResourceRegistrator gCubeResourceRegistrator) |
50 | 49 |
throws ParthenosPublisherException { |
51 |
this.registryBaseURL = registryBaseURL; |
|
50 |
//this.registryBaseURL = registryBaseURL;
|
|
52 | 51 |
this.saxonHelper = saxonHelper; |
53 | 52 |
this.defaultBaseURI = defaultBaseURI; |
54 | 53 |
this.resourceRegistryPublisher = ResourceRegistryPublisherFactory.create(); |
... | ... | |
107 | 106 |
this.saxonHelper = saxonHelper; |
108 | 107 |
} |
109 | 108 |
|
110 |
public String getRegistryBaseURL() { |
|
111 |
return registryBaseURL; |
|
112 |
} |
|
109 |
// public String getRegistryBaseURL() { |
|
110 |
// return registryBaseURL; |
|
111 |
// } |
|
112 |
// |
|
113 |
// public void setRegistryBaseURL(final String registryBaseURL) { |
|
114 |
// this.registryBaseURL = registryBaseURL; |
|
115 |
// } |
|
113 | 116 |
|
114 |
public void setRegistryBaseURL(final String registryBaseURL) { |
|
115 |
this.registryBaseURL = registryBaseURL; |
|
116 |
} |
|
117 |
|
|
118 | 117 |
public void setDefaultBaseURI(final String defaultBaseURI) { |
119 | 118 |
this.defaultBaseURI = defaultBaseURI; |
120 | 119 |
} |
Also available in: Unified diff
Fixed circular dependency