Revision 49396
Added by Alessia Bardi over 6 years ago
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 |
} |
Also available in: Unified diff
Fixed circular dependency