Search in sources :

Example 1 with OpalTaxonomiesUpdatedEvent

use of org.obiba.mica.micaConfig.event.OpalTaxonomiesUpdatedEvent 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

Strings (com.google.common.base.Strings)1 EventBus (com.google.common.eventbus.EventBus)1 URI (java.net.URI)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 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 OpalJavaClient (org.obiba.opal.rest.client.magma.OpalJavaClient)1 Opal (org.obiba.opal.web.model.Opal)1 Search (org.obiba.opal.web.model.Search)1 Dtos (org.obiba.opal.web.taxonomy.Dtos)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1 RelaxedPropertyResolver (org.springframework.boot.bind.RelaxedPropertyResolver)1 Cacheable (org.springframework.cache.annotation.Cacheable)1