Search in sources :

Example 1 with OpalJavaClient

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());
}
Also used : KeyStoreManager(org.obiba.security.KeyStoreManager) OpalCredential(org.obiba.mica.micaConfig.domain.OpalCredential) OpalJavaClient(org.obiba.opal.rest.client.magma.OpalJavaClient)

Example 2 with OpalJavaClient

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());
}
Also used : Projects(org.obiba.opal.web.model.Projects) URI(java.net.URI) OpalJavaClient(org.obiba.opal.rest.client.magma.OpalJavaClient)

Example 3 with OpalJavaClient

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;
}
Also used : Search(org.obiba.opal.web.model.Search) Logger(org.slf4j.Logger) OpalTaxonomiesUpdatedEvent(org.obiba.mica.micaConfig.event.OpalTaxonomiesUpdatedEvent) Cacheable(org.springframework.cache.annotation.Cacheable) Taxonomy(org.obiba.opal.core.domain.taxonomy.Taxonomy) Dtos(org.obiba.opal.web.taxonomy.Dtos) LoggerFactory(org.slf4j.LoggerFactory) AttributeKey(org.obiba.mica.spi.search.support.AttributeKey) Opal(org.obiba.opal.web.model.Opal) Collectors(java.util.stream.Collectors) ConcurrentMap(java.util.concurrent.ConcurrentMap) Inject(javax.inject.Inject) EventBus(com.google.common.eventbus.EventBus) Strings(com.google.common.base.Strings) List(java.util.List) RelaxedPropertyResolver(org.springframework.boot.bind.RelaxedPropertyResolver) Component(org.springframework.stereotype.Component) EnvironmentAware(org.springframework.context.EnvironmentAware) Environment(org.springframework.core.env.Environment) Map(java.util.Map) URI(java.net.URI) TaxonomyEntity(org.obiba.opal.core.domain.taxonomy.TaxonomyEntity) OpalJavaClient(org.obiba.opal.rest.client.magma.OpalJavaClient) Taxonomy(org.obiba.opal.core.domain.taxonomy.Taxonomy) Opal(org.obiba.opal.web.model.Opal) URI(java.net.URI) OpalTaxonomiesUpdatedEvent(org.obiba.mica.micaConfig.event.OpalTaxonomiesUpdatedEvent) Cacheable(org.springframework.cache.annotation.Cacheable)

Aggregations

OpalJavaClient (org.obiba.opal.rest.client.magma.OpalJavaClient)3 URI (java.net.URI)2 Strings (com.google.common.base.Strings)1 EventBus (com.google.common.eventbus.EventBus)1 List (java.util.List)1 Map (java.util.Map)1 ConcurrentMap (java.util.concurrent.ConcurrentMap)1 Collectors (java.util.stream.Collectors)1 Inject (javax.inject.Inject)1 OpalCredential (org.obiba.mica.micaConfig.domain.OpalCredential)1 OpalTaxonomiesUpdatedEvent (org.obiba.mica.micaConfig.event.OpalTaxonomiesUpdatedEvent)1 AttributeKey (org.obiba.mica.spi.search.support.AttributeKey)1 Taxonomy (org.obiba.opal.core.domain.taxonomy.Taxonomy)1 TaxonomyEntity (org.obiba.opal.core.domain.taxonomy.TaxonomyEntity)1 Opal (org.obiba.opal.web.model.Opal)1 Projects (org.obiba.opal.web.model.Projects)1 Search (org.obiba.opal.web.model.Search)1 Dtos (org.obiba.opal.web.taxonomy.Dtos)1 KeyStoreManager (org.obiba.security.KeyStoreManager)1 Logger (org.slf4j.Logger)1