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