Search in sources :

Example 6 with MicaConfig

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

the class MicaConfigResource method create.

@PUT
@Timed
@RequiresRoles(Roles.MICA_ADMIN)
public Response create(@SuppressWarnings("TypeMayBeWeakened") Mica.MicaConfigDto dto) {
    MicaConfig micaConfig = dtos.fromDto(dto);
    taxonomyService.refreshTaxonomyTaxonomyIfNeeded(micaConfigService.getConfig(), micaConfig);
    micaConfigService.save(micaConfig);
    return Response.noContent().build();
}
Also used : MicaConfig(org.obiba.mica.micaConfig.domain.MicaConfig) Timed(com.codahale.metrics.annotation.Timed) RequiresRoles(org.apache.shiro.authz.annotation.RequiresRoles) PUT(javax.ws.rs.PUT)

Example 7 with MicaConfig

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

the class DatasetDtos method asContingencyDto.

public Mica.DatasetVariableContingencyDto.Builder asContingencyDto(@NotNull OpalTable opalTable, DatasetVariable variable, DatasetVariable crossVariable, @Nullable Search.QueryResultDto results) {
    Mica.DatasetVariableContingencyDto.Builder crossDto = Mica.DatasetVariableContingencyDto.newBuilder();
    if (opalTable instanceof StudyTable)
        crossDto.setStudyTable(asDto((StudyTable) opalTable, true));
    else if (opalTable instanceof HarmonizationStudyTable)
        crossDto.setHarmonizationStudyTable(asDto((HarmonizationStudyTable) opalTable));
    Mica.DatasetVariableAggregationDto.Builder allAggBuilder = Mica.DatasetVariableAggregationDto.newBuilder();
    if (results == null) {
        allAggBuilder.setN(0);
        allAggBuilder.setTotal(0);
        crossDto.setAll(allAggBuilder);
        return crossDto;
    }
    allAggBuilder.setTotal(results.getTotalHits());
    MicaConfig micaConfig = micaConfigService.getConfig();
    int privacyThreshold = micaConfig.getPrivacyThreshold();
    crossDto.setPrivacyThreshold(privacyThreshold);
    boolean privacyChecks = crossVariable.hasCategories() ? validatePrivacyThreshold(results, privacyThreshold) : true;
    boolean totalPrivacyChecks = validateTotalPrivacyThreshold(results, privacyThreshold);
    // add facet results in the same order as the variable categories
    variable.getCategories().forEach(cat -> results.getFacetsList().stream().filter(facet -> facet.hasFacet() && cat.getName().equals(facet.getFacet())).forEach(facet -> {
        boolean privacyCheck = privacyChecks && checkPrivacyThreshold(facet.getFilters(0).getCount(), privacyThreshold);
        Mica.DatasetVariableAggregationDto.Builder aggBuilder = Mica.DatasetVariableAggregationDto.newBuilder();
        aggBuilder.setTotal(totalPrivacyChecks ? results.getTotalHits() : 0);
        aggBuilder.setTerm(facet.getFacet());
        DatasetCategory category = variable.getCategory(facet.getFacet());
        aggBuilder.setMissing(category != null && category.isMissing());
        addSummaryStatistics(crossVariable, aggBuilder, facet, privacyCheck, totalPrivacyChecks);
        crossDto.addAggregations(aggBuilder);
    }));
    // add total facet for all variable categories
    results.getFacetsList().stream().filter(facet -> facet.hasFacet() && "_total".equals(facet.getFacet())).forEach(facet -> {
        boolean privacyCheck = privacyChecks && facet.getFilters(0).getCount() > micaConfig.getPrivacyThreshold();
        addSummaryStatistics(crossVariable, allAggBuilder, facet, privacyCheck, totalPrivacyChecks);
    });
    crossDto.setAll(allAggBuilder);
    return crossDto;
}
Also used : Search(org.obiba.opal.web.model.Search) OpalTable(org.obiba.mica.core.domain.OpalTable) MicaConfig(org.obiba.mica.micaConfig.domain.MicaConfig) Taxonomy(org.obiba.opal.core.domain.taxonomy.Taxonomy) HarmonizationStudyTable(org.obiba.mica.core.domain.HarmonizationStudyTable) Inject(javax.inject.Inject) Term(org.obiba.opal.core.domain.taxonomy.Term) Strings(com.google.common.base.Strings) Lists(com.google.common.collect.Lists) Map(java.util.Map) JSONUtils(org.obiba.mica.JSONUtils) Attributes(org.obiba.mica.core.domain.Attributes) HarmonizationDatasetState(org.obiba.mica.dataset.domain.HarmonizationDatasetState) StudyDataset(org.obiba.mica.dataset.domain.StudyDataset) Nullable(javax.annotation.Nullable) SubjectAclService(org.obiba.mica.security.service.SubjectAclService) Math(org.obiba.opal.web.model.Math) Collection(java.util.Collection) DatasetCategory(org.obiba.mica.dataset.domain.DatasetCategory) DatasetVariable(org.obiba.mica.dataset.domain.DatasetVariable) NotNull(javax.validation.constraints.NotNull) Dataset(org.obiba.mica.dataset.domain.Dataset) Collectors(java.util.stream.Collectors) Maps(com.google.common.collect.Maps) PublishedStudyService(org.obiba.mica.study.service.PublishedStudyService) List(java.util.List) Component(org.springframework.stereotype.Component) HarmonizationDatasetStateRepository(org.obiba.mica.dataset.HarmonizationDatasetStateRepository) StudyDatasetState(org.obiba.mica.dataset.domain.StudyDatasetState) StudyDatasetStateRepository(org.obiba.mica.dataset.StudyDatasetStateRepository) MicaConfigService(org.obiba.mica.micaConfig.service.MicaConfigService) HarmonizationDataset(org.obiba.mica.dataset.domain.HarmonizationDataset) Optional(java.util.Optional) Vocabulary(org.obiba.opal.core.domain.taxonomy.Vocabulary) Collections(java.util.Collections) StudyTable(org.obiba.mica.core.domain.StudyTable) Assert(org.springframework.util.Assert) MicaConfig(org.obiba.mica.micaConfig.domain.MicaConfig) DatasetCategory(org.obiba.mica.dataset.domain.DatasetCategory) HarmonizationStudyTable(org.obiba.mica.core.domain.HarmonizationStudyTable) StudyTable(org.obiba.mica.core.domain.StudyTable) HarmonizationStudyTable(org.obiba.mica.core.domain.HarmonizationStudyTable)

Example 8 with MicaConfig

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

the class DatasetDtosTest method before.

@Before
public void before() {
    MicaConfig config = new MicaConfig();
    config.setLocales(Arrays.asList(Locale.ENGLISH, Locale.FRENCH));
    when(micaConfigService.getConfig()).thenReturn(config);
    when(subjectAclService.isPermitted(anyString(), anyString(), anyString())).thenReturn(true);
    when(publishedStudyService.findById(anyString())).thenReturn(new HarmonizationStudy());
    when(studySummaryDtos.asHarmoStudyDto(anyString())).thenReturn(Mica.StudySummaryDto.newBuilder().setId("123").setPublished(true).build());
    when(studySummaryDtos.asDto(anyString())).thenReturn(Mica.StudySummaryDto.newBuilder().setId("123").setPublished(true).build());
    when(permissionsDtos.asDto(any(StudyDataset.class))).thenReturn(Mica.PermissionsDto.getDefaultInstance());
    when(permissionsDtos.asDto(any(HarmonizationDataset.class))).thenReturn(Mica.PermissionsDto.getDefaultInstance());
}
Also used : MicaConfig(org.obiba.mica.micaConfig.domain.MicaConfig) HarmonizationStudy(org.obiba.mica.study.domain.HarmonizationStudy) StudyDataset(org.obiba.mica.dataset.domain.StudyDataset) HarmonizationDataset(org.obiba.mica.dataset.domain.HarmonizationDataset) Before(org.junit.Before)

Example 9 with MicaConfig

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

the class MicaConfigDtosTest method test_with_values.

@Test
public void test_with_values() {
    MicaConfig config = new MicaConfig();
    config.setName("Test");
    config.setPublicUrl("http://localhost/mica-test");
    config.setDefaultCharacterSet("utf-8");
    config.getLocales().add(Locale.CHINESE);
    config.getLocales().add(Locale.GERMAN);
    Mica.MicaConfigDto dto = dtos.asDto(config);
    assertThat(dto).isNotNull();
    MicaConfig fromDto = dtos.fromDto(dto);
    assertThat(fromDto).isEqualToIgnoringGivenFields(config, "createdDate");
}
Also used : MicaConfig(org.obiba.mica.micaConfig.domain.MicaConfig) Test(org.junit.Test)

Example 10 with MicaConfig

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

the class CustomTranslationsResource method getTranslations.

private JsonNode getTranslations(@NotNull String locale) {
    MicaConfig config = micaConfigService.getConfig();
    JsonNode node = objectMapper.createObjectNode();
    if (config.hasTranslations() && config.getTranslations().get(locale) != null) {
        try {
            node = objectMapper.readTree(config.getTranslations().get(locale));
        } catch (IOException e) {
            logger.warn("Cannot read custom translations tree for locale {0}", locale, e);
        }
    }
    return node;
}
Also used : MicaConfig(org.obiba.mica.micaConfig.domain.MicaConfig) JsonNode(com.fasterxml.jackson.databind.JsonNode) IOException(java.io.IOException)

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