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);
}
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();
}
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");
}
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);
}
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();
}
Aggregations