use of io.gravitee.am.model.Template in project gravitee-access-management by gravitee-io.
the class EmailTemplateServiceImpl method create0.
private Single<Email> create0(ReferenceType referenceType, String referenceId, String client, NewEmail newEmail, User principal) {
String emailId = RandomString.generate();
// check if email is unique
return checkEmailUniqueness(referenceType, referenceId, client, newEmail.getTemplate().template()).flatMap(irrelevant -> {
Email email = new Email();
email.setId(emailId);
email.setReferenceType(referenceType);
email.setReferenceId(referenceId);
email.setClient(client);
email.setEnabled(newEmail.isEnabled());
email.setTemplate(newEmail.getTemplate().template());
email.setFrom(newEmail.getFrom());
email.setFromName(newEmail.getFromName());
email.setSubject(newEmail.getSubject());
email.setContent(newEmail.getContent());
email.setExpiresAfter(newEmail.getExpiresAfter());
email.setCreatedAt(new Date());
email.setUpdatedAt(email.getCreatedAt());
return emailRepository.create(email);
}).flatMap(email -> {
// create event for sync process
Event event = new Event(Type.EMAIL, new Payload(email.getId(), email.getReferenceType(), email.getReferenceId(), Action.CREATE));
return eventService.create(event).flatMap(__ -> Single.just(email));
}).onErrorResumeNext(ex -> {
if (ex instanceof AbstractManagementException) {
return Single.error(ex);
}
LOGGER.error("An error occurs while trying to create a email", ex);
return Single.error(new TechnicalManagementException("An error occurs while trying to create a email", ex));
}).doOnSuccess(email -> auditService.report(AuditBuilder.builder(EmailTemplateAuditBuilder.class).principal(principal).type(EventType.EMAIL_TEMPLATE_CREATED).email(email))).doOnError(throwable -> auditService.report(AuditBuilder.builder(EmailTemplateAuditBuilder.class).principal(principal).type(EventType.EMAIL_TEMPLATE_CREATED).throwable(throwable)));
}
use of io.gravitee.am.model.Template in project gravitee-access-management by gravitee-io.
the class FormServiceImpl method create0.
private Single<Form> create0(ReferenceType referenceType, String referenceId, String client, NewForm newForm, User principal) {
String formId = RandomString.generate();
// check if form is unique
return checkFormUniqueness(referenceType, referenceId, client, newForm.getTemplate().template()).flatMap(irrelevant -> {
Form form = new Form();
form.setId(formId);
form.setReferenceType(referenceType);
form.setReferenceId(referenceId);
form.setClient(client);
form.setEnabled(newForm.isEnabled());
form.setTemplate(newForm.getTemplate().template());
form.setContent(newForm.getContent());
form.setAssets(newForm.getAssets());
form.setCreatedAt(new Date());
form.setUpdatedAt(form.getCreatedAt());
return formRepository.create(form);
}).flatMap(page -> {
// create event for sync process
Event event = new Event(Type.FORM, new Payload(page.getId(), page.getReferenceType(), page.getReferenceId(), Action.CREATE));
return eventService.create(event).flatMap(__ -> Single.just(page));
}).onErrorResumeNext(ex -> {
if (ex instanceof AbstractManagementException) {
return Single.error(ex);
}
LOGGER.error("An error occurs while trying to create a form", ex);
return Single.error(new TechnicalManagementException("An error occurs while trying to create a form", ex));
}).doOnSuccess(form -> auditService.report(AuditBuilder.builder(FormTemplateAuditBuilder.class).principal(principal).type(EventType.FORM_TEMPLATE_CREATED).form(form))).doOnError(throwable -> auditService.report(AuditBuilder.builder(FormTemplateAuditBuilder.class).principal(principal).type(EventType.FORM_TEMPLATE_CREATED).throwable(throwable)));
}
Aggregations