use of io.gravitee.am.model.Form in project gravitee-access-management by gravitee-io.
the class FormRepositoryTest method shouldFindByTemplate.
@Test
public void shouldFindByTemplate() {
final int loop = 10;
for (int i = 0; i < loop; i++) {
final Form form = buildForm();
form.setReferenceId(FIXED_REF_ID);
repository.create(form).blockingGet();
}
final Form form = buildForm();
form.setReferenceId(FIXED_REF_ID);
form.setTemplate("MyTemplateId");
form.setClient(null);
Form templateForm = repository.create(form).blockingGet();
TestObserver<Form> testMaybe = repository.findByTemplate(ReferenceType.DOMAIN, FIXED_REF_ID, "MyTemplateId").test();
testMaybe.awaitTerminalEvent();
testMaybe.assertNoErrors();
assertEqualsTo(templateForm, templateForm.getId(), testMaybe);
}
use of io.gravitee.am.model.Form in project gravitee-access-management by gravitee-io.
the class FormRepositoryTest method shouldDeleteById.
@Test
public void shouldDeleteById() {
Form form = buildForm();
Form createdForm = repository.create(form).blockingGet();
TestObserver<Form> testObserver = repository.findById(createdForm.getId()).test();
testObserver.awaitTerminalEvent();
testObserver.assertComplete();
testObserver.assertNoErrors();
assertEqualsTo(form, createdForm.getId(), testObserver);
repository.delete(createdForm.getId()).blockingGet();
testObserver = repository.findById(createdForm.getId()).test();
testObserver.awaitTerminalEvent();
testObserver.assertComplete();
testObserver.assertNoValues();
}
use of io.gravitee.am.model.Form in project gravitee-access-management by gravitee-io.
the class FormRepositoryTest method shouldFindByClient.
@Test
public void shouldFindByClient() {
final int loop = 10;
for (int i = 0; i < loop; i++) {
final Form form = buildForm();
form.setReferenceId(FIXED_REF_ID);
form.setClient(FIXED_CLI_ID);
repository.create(form).blockingGet();
}
for (int i = 0; i < loop; i++) {
final Form form = buildForm();
form.setReferenceId(FIXED_REF_ID);
repository.create(form).blockingGet();
}
TestObserver<List<Form>> testObserver = repository.findByClient(ReferenceType.DOMAIN, FIXED_REF_ID, FIXED_CLI_ID).toList().test();
testObserver.awaitTerminalEvent();
testObserver.assertNoErrors();
testObserver.assertValue(l -> l.size() == loop);
testObserver.assertValue(l -> l.stream().map(Form::getId).distinct().count() == loop);
}
use of io.gravitee.am.model.Form in project gravitee-access-management by gravitee-io.
the class FormManagerImpl method removeForm.
private void removeForm(String formId) {
logger.info("Received form event, delete form {}", formId);
Form deletedForm = forms.remove(formId);
if (deletedForm != null) {
templateResolver.removeForm(deletedForm);
}
}
use of io.gravitee.am.model.Form 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