Search in sources :

Example 11 with MicaConfig

use of org.obiba.mica.micaConfig.domain.MicaConfig in project mica2 by obiba.

the class CustomTranslationsResource method save.

@PUT
@Path("/{locale}.json")
@Consumes("application/json")
public Response save(String translations, @PathParam("locale") String locale, @QueryParam("merge") @DefaultValue("false") boolean merge) throws IOException {
    MicaConfig config = micaConfigService.getConfig();
    if (merge) {
        micaConfigService.mergeJson(getTranslations(locale), objectMapper.readTree(translations));
    } else {
        config.getTranslations().put(locale, translations);
    }
    micaConfigService.save(config);
    return Response.ok().build();
}
Also used : MicaConfig(org.obiba.mica.micaConfig.domain.MicaConfig)

Example 12 with MicaConfig

use of org.obiba.mica.micaConfig.domain.MicaConfig in project mica2 by obiba.

the class MicaVersionModifier method setVersion.

@Override
public void setVersion(Version version) {
    MicaConfig config = micaConfigService.getConfig();
    config.setMicaVersion(version);
    micaConfigService.save(config);
}
Also used : MicaConfig(org.obiba.mica.micaConfig.domain.MicaConfig)

Example 13 with MicaConfig

use of org.obiba.mica.micaConfig.domain.MicaConfig in project mica2 by obiba.

the class MicaConfigService method save.

@CacheEvict(value = "micaConfig", allEntries = true)
public void save(@NotNull @Valid MicaConfig micaConfig) {
    MicaConfig savedConfig = getOrCreateMicaConfig();
    ArrayList<String> removedRoles = Lists.newArrayList(Sets.difference(Sets.newHashSet(savedConfig.getRoles()), Sets.newHashSet(micaConfig.getRoles())));
    BeanUtils.copyProperties(micaConfig, savedConfig, "id", "version", "createdBy", "createdDate", "lastModifiedBy", "lastModifiedDate", "secretKey", "micaVersion");
    if (micaConfig.getMicaVersion() != null)
        savedConfig.setMicaVersion(micaConfig.getMicaVersion());
    micaConfigRepository.save(savedConfig);
    eventBus.post(new MicaConfigUpdatedEvent(getConfig(), removedRoles));
}
Also used : MicaConfig(org.obiba.mica.micaConfig.domain.MicaConfig) MicaConfigUpdatedEvent(org.obiba.mica.micaConfig.event.MicaConfigUpdatedEvent) CacheEvict(org.springframework.cache.annotation.CacheEvict)

Example 14 with MicaConfig

use of org.obiba.mica.micaConfig.domain.MicaConfig in project mica2 by obiba.

the class MicaConfigService method getPublicUrl.

/**
 * Get the public url, statically defined if not part of the {@link org.obiba.mica.micaConfig.domain.MicaConfig}.
 *
 * @return
 */
public String getPublicUrl() {
    MicaConfig config = getConfig();
    if (config.hasPublicUrl()) {
        return config.getPublicUrl();
    } else {
        String host = env.getProperty("server.address");
        String port = env.getProperty("https.port");
        return "https://" + host + ":" + port;
    }
}
Also used : MicaConfig(org.obiba.mica.micaConfig.domain.MicaConfig)

Example 15 with MicaConfig

use of org.obiba.mica.micaConfig.domain.MicaConfig in project mica2 by obiba.

the class MicaConfigService method getOrCreateMicaConfig.

private MicaConfig getOrCreateMicaConfig() {
    if (micaConfigRepository.count() == 0) {
        MicaConfig micaConfig = new MicaConfig();
        micaConfig.getLocales().add(MicaConfig.DEFAULT_LOCALE);
        micaConfig.setSecretKey(generateSecretKey());
        micaConfigRepository.save(micaConfig);
        return getConfig();
    }
    return micaConfigRepository.findAll().get(0);
}
Also used : MicaConfig(org.obiba.mica.micaConfig.domain.MicaConfig)

Aggregations

MicaConfig (org.obiba.mica.micaConfig.domain.MicaConfig)16 JsonNode (com.fasterxml.jackson.databind.JsonNode)3 IOException (java.io.IOException)2 Before (org.junit.Before)2 Test (org.junit.Test)2 HarmonizationDataset (org.obiba.mica.dataset.domain.HarmonizationDataset)2 StudyDataset (org.obiba.mica.dataset.domain.StudyDataset)2 Timed (com.codahale.metrics.annotation.Timed)1 Strings (com.google.common.base.Strings)1 Lists (com.google.common.collect.Lists)1 Maps (com.google.common.collect.Maps)1 File (java.io.File)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Collectors (java.util.stream.Collectors)1 Nullable (javax.annotation.Nullable)1 Inject (javax.inject.Inject)1