Search in sources :

Example 6 with DataAccessForm

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

the class DataAccessFormService method find.

public Optional<DataAccessForm> find() {
    DataAccessForm form = dataAccessFormRepository.findOne(DataAccessForm.DEFAULT_ID);
    if (form == null) {
        createOrUpdate(createDefaultDataAccessForm());
        form = dataAccessFormRepository.findOne(DataAccessForm.DEFAULT_ID);
    }
    if (StringUtils.isEmpty(form.getCsvExportFormat())) {
        form.setCsvExportFormat(getDefaultDataAccessFormResourceAsString("export-csv-schema.json"));
        form = createOrUpdate(form);
    }
    return Optional.ofNullable(form);
}
Also used : DataAccessForm(org.obiba.mica.micaConfig.domain.DataAccessForm)

Example 7 with DataAccessForm

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

the class DataAccessResource method getDataAccessPdf.

@GET
@Path("/pdf")
public FileResource getDataAccessPdf(@QueryParam("lang") String lang) {
    Optional<DataAccessForm> d = dataAccessFormService.find();
    if (!d.isPresent())
        throw NoSuchDataAccessFormException.withDefaultMessage();
    DataAccessForm dataAccessForm = d.get();
    Locale locale = Locale.forLanguageTag(!Strings.isNullOrEmpty(lang) ? Locale.forLanguageTag(lang).toLanguageTag() : LanguageTag.UNDETERMINED);
    if (!dataAccessForm.getPdfTemplates().containsKey(locale))
        throw NoSuchDataAccessFormException.withDefaultMessage();
    fileResource.setAttachment(dataAccessForm.getPdfTemplates().get(locale));
    return fileResource;
}
Also used : Locale(java.util.Locale) DataAccessForm(org.obiba.mica.micaConfig.domain.DataAccessForm) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 8 with DataAccessForm

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

the class DataAccessRequestCommentMailNotification method send.

@Override
public void send(Comment comment) {
    if (comment == null)
        return;
    DataAccessForm dataAccessForm = dataAccessFormService.find().get();
    if (!dataAccessForm.isNotifyCommented())
        return;
    DataAccessRequest request = dataAccessRequestService.findById(comment.getInstanceId());
    Map<String, String> ctx = Maps.newHashMap();
    String organization = micaConfigService.getConfig().getName();
    String id = request.getId();
    String title = dataAccessRequestUtilService.getRequestTitle(request);
    ctx.put("organization", organization);
    ctx.put("publicUrl", micaConfigService.getPublicUrl());
    ctx.put("id", id);
    if (Strings.isNullOrEmpty(title))
        title = id;
    ctx.put("title", title);
    ctx.put("applicant", request.getApplicant());
    ctx.put("status", request.getStatus().name());
    mailService.sendEmailToUsers(mailService.getSubject(dataAccessForm.getCommentedSubject(), ctx, DataAccessRequestUtilService.DEFAULT_NOTIFICATION_SUBJECT), "dataAccessRequestCommentAdded", ctx, request.getApplicant());
    mailService.sendEmailToGroups(mailService.getSubject(dataAccessForm.getCommentedSubject(), ctx, DataAccessRequestUtilService.DEFAULT_NOTIFICATION_SUBJECT), "dataAccessRequestCommentAdded", ctx, Roles.MICA_DAO);
}
Also used : DataAccessRequest(org.obiba.mica.access.domain.DataAccessRequest) DataAccessForm(org.obiba.mica.micaConfig.domain.DataAccessForm)

Example 9 with DataAccessForm

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

the class DataAccessRequestService method sendApprovedNotificationEmail.

private void sendApprovedNotificationEmail(DataAccessRequest request) {
    DataAccessForm dataAccessForm = dataAccessFormService.find().get();
    if (dataAccessForm.isNotifyApproved()) {
        Map<String, String> ctx = getNotificationEmailContext(request);
        mailService.sendEmailToUsers(mailService.getSubject(dataAccessForm.getApprovedSubject(), ctx, DataAccessRequestUtilService.DEFAULT_NOTIFICATION_SUBJECT), "dataAccessRequestApprovedApplicantEmail", ctx, request.getApplicant());
    }
}
Also used : DataAccessForm(org.obiba.mica.micaConfig.domain.DataAccessForm)

Example 10 with DataAccessForm

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

the class DataAccessRequestService method sendSubmittedNotificationEmail.

private void sendSubmittedNotificationEmail(DataAccessRequest request) {
    DataAccessForm dataAccessForm = dataAccessFormService.find().get();
    if (dataAccessForm.isNotifySubmitted()) {
        Map<String, String> ctx = getNotificationEmailContext(request);
        mailService.sendEmailToUsers(mailService.getSubject(dataAccessForm.getSubmittedSubject(), ctx, DataAccessRequestUtilService.DEFAULT_NOTIFICATION_SUBJECT), "dataAccessRequestSubmittedApplicantEmail", ctx, request.getApplicant());
        mailService.sendEmailToGroups(mailService.getSubject(dataAccessForm.getSubmittedSubject(), ctx, DataAccessRequestUtilService.DEFAULT_NOTIFICATION_SUBJECT), "dataAccessRequestSubmittedDAOEmail", ctx, Roles.MICA_DAO);
    }
}
Also used : DataAccessForm(org.obiba.mica.micaConfig.domain.DataAccessForm)

Aggregations

DataAccessForm (org.obiba.mica.micaConfig.domain.DataAccessForm)17 Locale (java.util.Locale)3 Timed (com.codahale.metrics.annotation.Timed)2 GET (javax.ws.rs.GET)2 Path (javax.ws.rs.Path)2 DataAccessRequest (org.obiba.mica.access.domain.DataAccessRequest)2 Strings (com.google.common.base.Strings)1 Maps (com.google.common.collect.Maps)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Collectors.toMap (java.util.stream.Collectors.toMap)1 Inject (javax.inject.Inject)1 QueryParam (javax.ws.rs.QueryParam)1 ByteArrayOutputStream (org.apache.commons.io.output.ByteArrayOutputStream)1 RequiresAuthentication (org.apache.shiro.authz.annotation.RequiresAuthentication)1 DateTime (org.joda.time.DateTime)1 LocalizedString (org.obiba.mica.core.domain.LocalizedString)1 IdentifierGenerator (org.obiba.mica.core.support.IdentifierGenerator)1 Attachment (org.obiba.mica.file.Attachment)1 FileResource (org.obiba.mica.file.rest.FileResource)1