api clients

This commit is contained in:
Michele Artini 2023-10-13 15:15:23 +02:00
parent 17a874d744
commit 823cc424a7
2 changed files with 29 additions and 35 deletions

View File

@ -23,6 +23,7 @@ import eu.dnetlib.domain.common.KeyValue;
import eu.dnetlib.domain.dsm.Api;
import eu.dnetlib.domain.dsm.BrowseTerm;
import eu.dnetlib.domain.dsm.readonly.SimpleDsWithApis;
import eu.dnetlib.domain.vocabulary.VocabularyTerm;
import eu.dnetlib.errors.DsmException;
import eu.dnetlib.services.dsm.service.DsmService;
import eu.dnetlib.services.dsm.service.ProtocolService;
@ -55,8 +56,17 @@ public class DsmAjaxController extends DnetRestController {
final VocabularyClient vocabularyClient = clientFactory.getClient(VocabularyClient.class);
map.put("protocols", protocolService.listProtocols());
map.put("compatibilityLevels", vocabularyClient.findTermsByVocabulary("dnet:compatibilityLevel"));
map.put("contentDescTypes", vocabularyClient.findTermsByVocabulary("dnet:content_description_typologies"));
map.put("compatibilityLevels", vocabularyClient.listTerms("dnet:compatibilityLevel")
.stream()
.map(VocabularyTerm::getCode)
.sorted()
.collect(Collectors.toList()));
map.put("contentDescTypes", vocabularyClient.listTerms("dnet:content_description_typologies")
.stream()
.map(VocabularyTerm::getCode)
.sorted()
.collect(Collectors.toList()));
return map;
}

View File

@ -1,5 +1,12 @@
package eu.dnetlib.common.clients;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.List;
import org.springframework.cache.annotation.Cacheable;
import eu.dnetlib.domain.vocabulary.Vocabulary;
import eu.dnetlib.domain.vocabulary.VocabularyTerm;
@ -7,46 +14,23 @@ public class VocabularyClient extends DnetServiceClient {
public VocabularyClient(final String baseUrl) {
super(baseUrl);
// TODO (HIGH PRIORITY) Auto-generated constructor stub
}
// TODO (HIGH PRIORITY)
// Forse inutile,
// se serve solo per la UI conviene fare le chiamate direttamente al servizio dei vocabolari
public void dropCache() {
// TODO (HIGH PRIORITY) Auto-generated method stub
@Cacheable("vocabulary_list")
public List<Vocabulary> listVocs() {
return Arrays.asList(httpGet("/api/vocs", Vocabulary[].class));
}
public Vocabulary getCountries() {
// TODO (HIGH PRIORITY) Auto-generated method stub
return null;
@Cacheable("vocabulary_terms")
public List<VocabularyTerm> listTerms(final String vocId) {
return Arrays.asList(httpGet("/api/vocs/" + URLEncoder.encode(vocId, StandardCharsets.UTF_8) + "/terms", VocabularyTerm[].class));
}
public Vocabulary getDatasourceTypologies() {
// TODO (HIGH PRIORITY) Auto-generated method stub
return null;
}
public boolean isValidTerm(final String string, final String type) {
// TODO (HIGH PRIORITY) Auto-generated method stub
public boolean isValidTerm(final String vocId, final String termCode) {
for (final VocabularyTerm t : listTerms(vocId)) {
if (t.getCode().equals(termCode)) { return true; }
}
return false;
}
public Iterable<?> findTermsByVocabulary(final String vocabulary) {
// TODO (HIGH PRIORITY) Auto-generated method stub
return null;
}
public Iterable<Vocabulary> listVocs() {
// TODO (HIGH PRIORITY) Auto-generated method stub
return null;
}
public Iterable<VocabularyTerm> listTerms(final String id) {
// TODO (HIGH PRIORITY) Auto-generated method stub
return null;
}
}