1
|
package eu.dnetlib.administration.uis.modules.repos;
|
2
|
|
3
|
import java.util.HashMap;
|
4
|
import java.util.List;
|
5
|
import java.util.Map;
|
6
|
import java.util.stream.Collectors;
|
7
|
|
8
|
import org.springframework.beans.factory.annotation.Autowired;
|
9
|
|
10
|
import com.google.gson.Gson;
|
11
|
|
12
|
import eu.dnetlib.administration.uis.modules.UIModule;
|
13
|
import eu.dnetlib.clients.is.InformationServiceClient;
|
14
|
import eu.dnetlib.clients.msro.MsroClient;
|
15
|
import eu.dnetlib.clients.msro.ProtocolParameter;
|
16
|
import eu.dnetlib.exceptions.InformationServiceException;
|
17
|
|
18
|
public abstract class AbstractRepoModule extends UIModule {
|
19
|
|
20
|
private final Map<String, List<ProtocolParameter>> parametersMap = new HashMap<>();
|
21
|
|
22
|
@Autowired
|
23
|
private InformationServiceClient isClient;
|
24
|
|
25
|
@Autowired
|
26
|
private MsroClient msroClient;
|
27
|
|
28
|
protected List<VocabularyEntry> fetchVocabularyTerms(final String voc) throws InformationServiceException {
|
29
|
final String xquery = "for $x in collection('/db/DRIVER/VocabularyDSResources/VocabularyDSResourceType')[.//VOCABULARY_NAME/@code = '"
|
30
|
+ voc.trim() + "']//TERM return concat($x/@code, ' @@@ ', $x/@english_name)";
|
31
|
|
32
|
return isClient.find(xquery)
|
33
|
.stream()
|
34
|
.map(s -> s.split("@@@"))
|
35
|
.map(arr -> new VocabularyEntry(arr[0].trim(), arr[1].trim()))
|
36
|
.sorted()
|
37
|
.collect(Collectors.toList());
|
38
|
}
|
39
|
|
40
|
protected String fetchVocabularyTermsAsJson(final String voc) throws InformationServiceException {
|
41
|
return (new Gson()).toJson(fetchVocabularyTerms(voc));
|
42
|
|
43
|
}
|
44
|
|
45
|
protected List<ProtocolParameter> listParametersForProtocol(final String protocol) {
|
46
|
return getMapProtocolParameters().get(protocol.toLowerCase());
|
47
|
}
|
48
|
|
49
|
protected Map<String, List<ProtocolParameter>> getMapProtocolParameters() {
|
50
|
if (parametersMap.isEmpty()) {
|
51
|
msroClient.listProtocols().forEach(d -> parametersMap.put(d.getName().toLowerCase(), d.getParams()));
|
52
|
}
|
53
|
return parametersMap;
|
54
|
}
|
55
|
|
56
|
}
|