Search in sources :

Example 16 with Form

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);
}
Also used : Form(io.gravitee.am.model.Form) Test(org.junit.Test) AbstractManagementTest(io.gravitee.am.repository.management.AbstractManagementTest)

Example 17 with Form

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();
}
Also used : Form(io.gravitee.am.model.Form) Test(org.junit.Test) AbstractManagementTest(io.gravitee.am.repository.management.AbstractManagementTest)

Example 18 with Form

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);
}
Also used : Form(io.gravitee.am.model.Form) List(java.util.List) Test(org.junit.Test) AbstractManagementTest(io.gravitee.am.repository.management.AbstractManagementTest)

Example 19 with Form

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);
    }
}
Also used : Form(io.gravitee.am.model.Form)

Example 20 with Form

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)));
}
Also used : Date(java.util.Date) FormRepository(io.gravitee.am.repository.management.api.FormRepository) Completable(io.reactivex.Completable) Maybe(io.reactivex.Maybe) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) AuditService(io.gravitee.am.service.AuditService) Single(io.reactivex.Single) Event(io.gravitee.am.model.common.event.Event) Type(io.gravitee.am.common.event.Type) FormAlreadyExistsException(io.gravitee.am.service.exception.FormAlreadyExistsException) TechnicalManagementException(io.gravitee.am.service.exception.TechnicalManagementException) Flowable(io.reactivex.Flowable) User(io.gravitee.am.identityprovider.api.User) Form(io.gravitee.am.model.Form) AuditBuilder(io.gravitee.am.service.reporter.builder.AuditBuilder) ReferenceType(io.gravitee.am.model.ReferenceType) EventService(io.gravitee.am.service.EventService) NewForm(io.gravitee.am.service.model.NewForm) Action(io.gravitee.am.common.event.Action) Logger(org.slf4j.Logger) FormTemplateAuditBuilder(io.gravitee.am.service.reporter.builder.management.FormTemplateAuditBuilder) EventType(io.gravitee.am.common.audit.EventType) AbstractManagementException(io.gravitee.am.service.exception.AbstractManagementException) RandomString(io.gravitee.am.common.utils.RandomString) Component(org.springframework.stereotype.Component) List(java.util.List) FormNotFoundException(io.gravitee.am.service.exception.FormNotFoundException) Template(io.gravitee.am.model.Template) Payload(io.gravitee.am.model.common.event.Payload) UpdateForm(io.gravitee.am.service.model.UpdateForm) FormService(io.gravitee.am.service.FormService) Lazy(org.springframework.context.annotation.Lazy) AbstractManagementException(io.gravitee.am.service.exception.AbstractManagementException) Form(io.gravitee.am.model.Form) NewForm(io.gravitee.am.service.model.NewForm) UpdateForm(io.gravitee.am.service.model.UpdateForm) Event(io.gravitee.am.model.common.event.Event) Payload(io.gravitee.am.model.common.event.Payload) RandomString(io.gravitee.am.common.utils.RandomString) FormTemplateAuditBuilder(io.gravitee.am.service.reporter.builder.management.FormTemplateAuditBuilder) Date(java.util.Date) TechnicalManagementException(io.gravitee.am.service.exception.TechnicalManagementException)

Aggregations

Form (io.gravitee.am.model.Form)22 Test (org.junit.Test)15 AbstractManagementTest (io.gravitee.am.repository.management.AbstractManagementTest)8 User (io.gravitee.am.identityprovider.api.User)5 NewForm (io.gravitee.am.service.model.NewForm)5 List (java.util.List)5 Response (javax.ws.rs.core.Response)5 JerseySpringTest (io.gravitee.am.management.handlers.management.api.JerseySpringTest)3 Domain (io.gravitee.am.model.Domain)3 ReferenceType (io.gravitee.am.model.ReferenceType)3 Template (io.gravitee.am.model.Template)3 FormService (io.gravitee.am.service.FormService)3 Maybe (io.reactivex.Maybe)3 Autowired (org.springframework.beans.factory.annotation.Autowired)3 AbstractResource (io.gravitee.am.management.handlers.management.api.resources.AbstractResource)2 Acl (io.gravitee.am.model.Acl)2 Event (io.gravitee.am.model.common.event.Event)2 Permission (io.gravitee.am.model.permissions.Permission)2 DomainService (io.gravitee.am.service.DomainService)2 DomainNotFoundException (io.gravitee.am.service.exception.DomainNotFoundException)2