Search in sources :

Example 11 with DataAccessConfig

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

the class DataAccessEntityService method sendAttachmentsUpdatedNotificationEmail.

protected void sendAttachmentsUpdatedNotificationEmail(T request) {
    DataAccessConfig dataAccessConfig = dataAccessConfigService.getOrCreateConfig();
    if (dataAccessConfig.isNotifyAttachment()) {
        Map<String, String> ctx = getNotificationEmailContext(request);
        mailService.sendEmailToUsers(mailService.getSubject(dataAccessConfig.getAttachmentSubject(), ctx, DataAccessRequestUtilService.DEFAULT_NOTIFICATION_SUBJECT), "dataAccessRequestAttachmentsUpdated", ctx, request.getApplicant());
        mailService.sendEmailToGroups(mailService.getSubject(dataAccessConfig.getAttachmentSubject(), ctx, DataAccessRequestUtilService.DEFAULT_NOTIFICATION_SUBJECT), "dataAccessRequestAttachmentsUpdated", ctx, Roles.MICA_DAO);
    }
}
Also used : DataAccessConfig(org.obiba.mica.micaConfig.domain.DataAccessConfig)

Example 12 with DataAccessConfig

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

the class DataAccessEntityService method generateId.

protected String generateId() {
    DataAccessConfig dataAccessConfig = dataAccessConfigService.getOrCreateConfig();
    Object exclusions = YamlClassPathResourceReader.read(EXCLUSION_IDS_YAML_RESOURCE_PATH, Map.class).get("exclusions");
    IdentifierGenerator.Builder builder = IdentifierGenerator.newBuilder().prefix(dataAccessConfig.getIdPrefix()).size(dataAccessConfig.getIdLength());
    if (dataAccessConfig.isAllowIdWithLeadingZeros()) {
        builder.zeros();
    }
    if (exclusions instanceof List) {
        log.info("Using exclusions {} to generate DAR id", exclusions.toString());
        builder.exclusions((List) exclusions);
    }
    IdentifierGenerator idGenerator = builder.build();
    int tries = 0;
    while (tries < 100) {
        tries++;
        String id = idGenerator.generateIdentifier();
        if (getRepository().findOne(id) == null)
            return id;
    }
    throw new DataAccessRequestGenerationException("Exceeded 100 id generation tries");
}
Also used : DataAccessConfig(org.obiba.mica.micaConfig.domain.DataAccessConfig) DataAccessRequestGenerationException(org.obiba.mica.access.DataAccessRequestGenerationException) List(java.util.List) Map(java.util.Map) IdentifierGenerator(org.obiba.mica.core.support.IdentifierGenerator)

Example 13 with DataAccessConfig

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

the class DataAccessRequestCommentMailNotification method send.

@Override
public void send(Comment comment) {
    if (comment == null)
        return;
    DataAccessConfig dataAccessConfig = dataAccessConfigService.getOrCreateConfig();
    if (!dataAccessConfig.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());
    if (comment.getAdmin()) {
        List<SubjectAcl> privateCommentsAcls = getPrivateCommentsAcls();
        mailService.sendEmailToGroupsAndUsers(dataAccessConfig.getCommentedSubject(), "dataAccessRequestCommentAdded", ctx, getAclForType(privateCommentsAcls, Type.GROUP), getAclForType(privateCommentsAcls, Type.USER));
    } else {
        mailService.sendEmailToUsers(mailService.getSubject(dataAccessConfig.getCommentedSubject(), ctx, DataAccessRequestUtilService.DEFAULT_NOTIFICATION_SUBJECT), "dataAccessRequestCommentAdded", ctx, request.getApplicant());
    }
    mailService.sendEmailToGroups(mailService.getSubject(dataAccessConfig.getCommentedSubject(), ctx, DataAccessRequestUtilService.DEFAULT_NOTIFICATION_SUBJECT), "dataAccessRequestCommentAdded", ctx, Roles.MICA_DAO);
}
Also used : DataAccessConfig(org.obiba.mica.micaConfig.domain.DataAccessConfig) DataAccessRequest(org.obiba.mica.access.domain.DataAccessRequest) SubjectAcl(org.obiba.mica.security.domain.SubjectAcl)

Example 14 with DataAccessConfig

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

the class DataAccessConfigService method getOrCreateConfig.

public synchronized DataAccessConfig getOrCreateConfig() {
    if (dataAccessConfigRepository.count() == 0) {
        DataAccessConfig config = new DataAccessConfig();
        dataAccessConfigRepository.save(config);
    }
    DataAccessConfig config = dataAccessConfigRepository.findAll().get(0);
    boolean modified = false;
    if (StringUtils.isEmpty(config.getCsvExportFormat())) {
        config.setCsvExportFormat(dataAccessFormService.getDefaultDataAccessFormResourceAsString("export-csv-schema.json"));
        modified = true;
    }
    if (StringUtils.isEmpty(config.getFeasibilityCsvExportFormat())) {
        config.setFeasibilityCsvExportFormat(dataAccessFeasibilityFormService.getDefaultDataAccessFormResourceAsString("export-csv-schema.json"));
        modified = true;
    }
    if (StringUtils.isEmpty(config.getAmendmentCsvExportFormat())) {
        config.setAmendmentCsvExportFormat(dataAccessAmendmentFormService.getDefaultDataAccessFormResourceAsString("export-csv-schema.json"));
        modified = true;
    }
    if (modified) {
        dataAccessConfigRepository.save(config);
    }
    return config;
}
Also used : DataAccessConfig(org.obiba.mica.micaConfig.domain.DataAccessConfig)

Example 15 with DataAccessConfig

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

the class DataAccessRequestsResource method exportCsv.

@GET
@Timed
@Path("/csv")
@Produces("text/csv")
public Response exportCsv(@QueryParam("lang") String lang) {
    DataAccessConfig dataAccessConfig = dataAccessConfigService.getOrCreateConfig();
    Map<DataAccessRequest, List<DataAccessAmendment>> dataAccessRequestListMap = listAllWithAmendments();
    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
    new CsvReportGenerator(dataAccessRequestListMap, dataAccessConfig.getCsvExportFormat(), dataAccessConfig.getAmendmentCsvExportFormat(), lang).write(byteArrayOutputStream);
    String date = new DateTime().toString("YYYY-MM-dd");
    return Response.ok(byteArrayOutputStream.toByteArray()).header("Content-Disposition", String.format("attachment; filename=\"Access-Requests-Report_%s.csv\"", date)).build();
}
Also used : DataAccessConfig(org.obiba.mica.micaConfig.domain.DataAccessConfig) DataAccessRequest(org.obiba.mica.access.domain.DataAccessRequest) List(java.util.List) ByteArrayOutputStream(org.apache.commons.io.output.ByteArrayOutputStream) DateTime(org.joda.time.DateTime) Timed(com.codahale.metrics.annotation.Timed)

Aggregations

DataAccessConfig (org.obiba.mica.micaConfig.domain.DataAccessConfig)15 DataAccessRequest (org.obiba.mica.access.domain.DataAccessRequest)3 List (java.util.List)2 Timed (com.codahale.metrics.annotation.Timed)1 LocalDate (java.time.LocalDate)1 Date (java.util.Date)1 Map (java.util.Map)1 ByteArrayOutputStream (org.apache.commons.io.output.ByteArrayOutputStream)1 DateTime (org.joda.time.DateTime)1 DataAccessRequestGenerationException (org.obiba.mica.access.DataAccessRequestGenerationException)1 DataAccessRequestTimeline (org.obiba.mica.access.domain.DataAccessRequestTimeline)1 IdentifierGenerator (org.obiba.mica.core.support.IdentifierGenerator)1 DataAccessConfigUpdatedEvent (org.obiba.mica.micaConfig.event.DataAccessConfigUpdatedEvent)1 SubjectAcl (org.obiba.mica.security.domain.SubjectAcl)1 Async (org.springframework.scheduling.annotation.Async)1 Scheduled (org.springframework.scheduling.annotation.Scheduled)1