Search in sources :

Example 1 with MicaConfig

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

the class CommentMailNotification method send.

@Override
public void send(Comment comment) {
    MicaConfig config = micaConfigService.getConfig();
    if (comment == null || !config.isCommentNotificationsEnabled())
        return;
    List<SubjectAcl> acls = Lists.newArrayList(SubjectAcl.newBuilder(Roles.MICA_REVIEWER, SubjectAcl.Type.GROUP).action(PermissionsUtils.asActions("REVIEWER")).build(), SubjectAcl.newBuilder(Roles.MICA_EDITOR, SubjectAcl.Type.GROUP).action(PermissionsUtils.asActions("EDITOR")).build());
    acls.addAll(subjectAclService.findByResourceInstance(comment.getResourceId(), comment.getInstanceId()));
    List<String> users = acls.stream().filter(s -> s.hasAction("VIEW") && s.getType() == SubjectAcl.Type.USER && !s.getPrincipal().equals(comment.getCreatedBy())).map(SubjectAcl::getPrincipal).collect(toList());
    List<String> groups = acls.stream().filter(s -> s.hasAction("VIEW") && s.getType() == SubjectAcl.Type.GROUP).map(SubjectAcl::getPrincipal).collect(toList());
    if (users.isEmpty() && groups.isEmpty())
        return;
    Map<String, String> ctx = Maps.newHashMap();
    ctx.put("organization", config.getName());
    ctx.put("publicUrl", micaConfigService.getPublicUrl());
    ctx.put("documentType", comment.getResourceId().replaceFirst("/draft/", ""));
    ctx.put("documentId", comment.getInstanceId());
    ctx.put("createdBy", comment.getCreatedBy());
    ctx.put("message", comment.getMessage());
    ctx.put("status", comment.isNew() ? "CREATED" : "UPDATED");
    String commentNotificationSubject = micaConfigService.getConfig().getCommentNotificationsSubject();
    mailService.sendEmailToGroupsAndUsers(mailService.getSubject(commentNotificationSubject, ctx, DEFAULT_NOTIFICATION_SUBJECT), "commentAdded", ctx, groups, users);
}
Also used : MicaConfig(org.obiba.mica.micaConfig.domain.MicaConfig) SubjectAcl(org.obiba.mica.security.domain.SubjectAcl)

Example 2 with MicaConfig

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

the class MicaConfigService method getTranslations.

public String getTranslations(@NotNull String locale, boolean _default) throws IOException {
    File translations;
    try {
        translations = getTranslationsResource(locale).getFile();
    } catch (IOException e) {
        locale = "en";
        translations = getTranslationsResource(locale).getFile();
    }
    if (_default) {
        return FileUtils.readFileToString(translations, "utf-8");
    }
    MicaConfig config = getOrCreateMicaConfig();
    JsonNode builtTranslations = objectMapper.readTree(translations);
    builtTranslations = addTaxonomies(builtTranslations, locale);
    if (config.hasTranslations() && config.getTranslations().get(locale) != null) {
        JsonNode custom = objectMapper.readTree(config.getTranslations().get(locale));
        return mergeJson(builtTranslations, custom).toString();
    }
    return builtTranslations.toString();
}
Also used : MicaConfig(org.obiba.mica.micaConfig.domain.MicaConfig) JsonNode(com.fasterxml.jackson.databind.JsonNode) IOException(java.io.IOException) File(java.io.File)

Example 3 with MicaConfig

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

the class MicaConfigDtosTest method test_default_values.

@Test
public void test_default_values() {
    MicaConfig config = new MicaConfig();
    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 4 with MicaConfig

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

the class StudyDtosTest method before.

@Before
public void before() {
    MicaConfig config = new MicaConfig();
    config.setLocales(Arrays.asList(Locale.ENGLISH, Locale.FRENCH));
    when(micaConfigService.getConfig()).thenReturn(config);
    when(permissionsDtos.asDto(any(Study.class))).thenReturn(Mica.PermissionsDto.getDefaultInstance());
    when(individualStudyService.isPublished(anyString())).thenReturn(true);
}
Also used : MicaConfig(org.obiba.mica.micaConfig.domain.MicaConfig) Study(org.obiba.mica.study.domain.Study) Before(org.junit.Before)

Example 5 with MicaConfig

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

the class CustomTranslationsResource method importTranslations.

@PUT
@Path("/import")
@Consumes("application/json")
public Response importTranslations(String translations, @QueryParam("merge") @DefaultValue("false") boolean merge) throws IOException {
    MicaConfig config = micaConfigService.getConfig();
    JsonNode node = objectMapper.readTree(translations);
    List<String> locales = config.getLocalesAsString();
    if (!config.hasTranslations()) {
        config.setTranslations(new LocalizedString());
    }
    if (merge) {
        locales.forEach(l -> {
            JsonNode merged = micaConfigService.mergeJson(getTranslations(l), node.get(l));
            config.getTranslations().put(l, merged.toString());
        });
    } else {
        locales.forEach(l -> config.getTranslations().put(l, node.get(l).toString()));
    }
    micaConfigService.save(config);
    return Response.ok().build();
}
Also used : MicaConfig(org.obiba.mica.micaConfig.domain.MicaConfig) JsonNode(com.fasterxml.jackson.databind.JsonNode) LocalizedString(org.obiba.mica.core.domain.LocalizedString) LocalizedString(org.obiba.mica.core.domain.LocalizedString)

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