use of org.obiba.opal.rest.client.magma.OpalJavaClient in project mica2 by obiba.
the class OpalService method getOpalJavaClient.
private OpalJavaClient getOpalJavaClient(String opalUrl) throws URISyntaxException {
String alias = opalUrl;
OpalCredential opalCredential = getOpalCredential(opalUrl);
if (opalCredential.getAuthType() == AuthType.CERTIFICATE) {
KeyStoreManager kms = keyStoreService.getKeyStore(OPAL_KEYSTORE);
if (!kms.aliasExists(alias))
throw new IllegalStateException("Trying to use opal certificate credential but could not be found in keystore.");
return new OpalJavaClient(cleanupOpalUrl(opalUrl), kms.getKeyStore(), alias, micaConfigService.getConfig().getSecretKey());
} else if (opalCredential.getAuthType() == AuthType.TOKEN)
return new OpalJavaClient(cleanupOpalUrl(opalCredential.getOpalUrl()), opalCredential.getToken());
return new OpalJavaClient(cleanupOpalUrl(opalCredential.getOpalUrl()), opalCredential.getUsername(), opalCredential.getPassword());
}
use of org.obiba.opal.rest.client.magma.OpalJavaClient in project mica2 by obiba.
the class OpalService method getProjectDtos.
public List<Projects.ProjectDto> getProjectDtos(String opalUrl) throws URISyntaxException {
if (Strings.isNullOrEmpty(opalUrl))
opalUrl = getDefaultOpal();
OpalJavaClient opalJavaClient = getOpalJavaClient(opalUrl);
URI uri = opalJavaClient.newUri().segment("projects").build();
return opalJavaClient.getResources(Projects.ProjectDto.class, uri, Projects.ProjectDto.newBuilder());
}
use of org.obiba.opal.rest.client.magma.OpalJavaClient in project mica2 by obiba.
the class OpalServiceHelper method getTaxonomies.
// opal root url as key
@Cacheable(value = "opal-taxonomies", key = "#opalJavaClient.newUri().build()")
public Map<String, Taxonomy> getTaxonomies(OpalJavaClient opalJavaClient) {
log.info("Fetching opal taxonomies");
URI uri = opalJavaClient.newUri().segment("system", "conf", "taxonomies").build();
List<Opal.TaxonomyDto> taxonomies = opalJavaClient.getResources(Opal.TaxonomyDto.class, uri, Opal.TaxonomyDto.newBuilder());
ConcurrentMap<String, Taxonomy> taxonomiesList = taxonomies.stream().map(taxonomyDto -> {
Taxonomy taxonomy = fromDto(taxonomyDto);
String defaultTermsSortOrder = opalTaxonomiesProperties.getProperty("defaultTermsSortOrder");
if (!Strings.isNullOrEmpty(defaultTermsSortOrder)) {
taxonomy.getVocabularies().forEach(vocabulary -> vocabulary.addAttribute("termsSortKey", defaultTermsSortOrder));
}
return taxonomy;
}).collect(Collectors.toConcurrentMap(TaxonomyEntity::getName, taxonomy -> taxonomy));
eventBus.post(new OpalTaxonomiesUpdatedEvent(taxonomiesList));
return taxonomiesList;
}
Aggregations