Search in sources :

Example 1 with Form

use of io.gravitee.am.model.Form in project gravitee-access-management by gravitee-io.

the class FormServiceTest method copyFromClient_duplicateFound.

@Test
public void copyFromClient_duplicateFound() {
    final String sourceUid = "sourceUid";
    final String targetUid = "targetUid";
    Form formOne = new Form();
    formOne.setId("templateId");
    formOne.setEnabled(true);
    formOne.setReferenceType(ReferenceType.DOMAIN);
    formOne.setReferenceId(DOMAIN);
    formOne.setClient(sourceUid);
    formOne.setTemplate("login");
    formOne.setContent("formContent");
    formOne.setAssets("formAsset");
    when(formRepository.findByClientAndTemplate(ReferenceType.DOMAIN, DOMAIN, targetUid, "login")).thenReturn(Maybe.just(new Form()));
    when(formRepository.findByClient(ReferenceType.DOMAIN, DOMAIN, sourceUid)).thenReturn(Flowable.just(formOne));
    TestObserver<List<Form>> testObserver = formService.copyFromClient(DOMAIN, sourceUid, targetUid).test();
    testObserver.assertNotComplete();
    testObserver.assertError(FormAlreadyExistsException.class);
}
Also used : Form(io.gravitee.am.model.Form) List(java.util.List) Test(org.junit.Test)

Example 2 with Form

use of io.gravitee.am.model.Form in project gravitee-access-management by gravitee-io.

the class ApplicationFormsResource method create.

@POST
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Create a form for an application", notes = "User must have APPLICATION_FORM[CREATE] permission on the specified application " + "or APPLICATION_FORM[CREATE] permission on the specified domain " + "or APPLICATION_FORM[CREATE] permission on the specified environment " + "or APPLICATION_FORM[CREATE] permission on the specified organization")
@ApiResponses({ @ApiResponse(code = 201, message = "Form successfully created"), @ApiResponse(code = 500, message = "Internal server error") })
public void create(@PathParam("organizationId") String organizationId, @PathParam("environmentId") String environmentId, @PathParam("domain") String domain, @PathParam("application") String application, @ApiParam(name = "email", required = true) @Valid @NotNull final NewForm newForm, @Suspended final AsyncResponse response) {
    final User authenticatedUser = getAuthenticatedUser();
    checkAnyPermission(organizationId, environmentId, domain, application, Permission.APPLICATION_FORM, Acl.CREATE).andThen(domainService.findById(domain).switchIfEmpty(Maybe.error(new DomainNotFoundException(domain))).flatMap(irrelevant -> applicationService.findById(application)).switchIfEmpty(Maybe.error(new ApplicationNotFoundException(application))).flatMapSingle(irrelevant -> formService.create(domain, application, newForm, authenticatedUser)).map(form -> Response.created(URI.create("/organizations/" + organizationId + "/environments/" + environmentId + "/domains/" + domain + "/applications/" + application + "/forms/" + form.getId())).entity(form).build())).subscribe(response::resume, response::resume);
}
Also used : ApplicationService(io.gravitee.am.service.ApplicationService) Permission(io.gravitee.am.model.permissions.Permission) Maybe(io.reactivex.Maybe) DomainService(io.gravitee.am.service.DomainService) ApiParam(io.swagger.annotations.ApiParam) Autowired(org.springframework.beans.factory.annotation.Autowired) AbstractResource(io.gravitee.am.management.handlers.management.api.resources.AbstractResource) ApiResponses(io.swagger.annotations.ApiResponses) Valid(javax.validation.Valid) Acl(io.gravitee.am.model.Acl) ApiOperation(io.swagger.annotations.ApiOperation) User(io.gravitee.am.identityprovider.api.User) Form(io.gravitee.am.model.Form) ReferenceType(io.gravitee.am.model.ReferenceType) Api(io.swagger.annotations.Api) URI(java.net.URI) NewForm(io.gravitee.am.service.model.NewForm) Context(javax.ws.rs.core.Context) AsyncResponse(javax.ws.rs.container.AsyncResponse) DomainNotFoundException(io.gravitee.am.service.exception.DomainNotFoundException) NotNull(javax.validation.constraints.NotNull) Suspended(javax.ws.rs.container.Suspended) MediaType(io.gravitee.common.http.MediaType) javax.ws.rs(javax.ws.rs) Response(javax.ws.rs.core.Response) Template(io.gravitee.am.model.Template) ApiResponse(io.swagger.annotations.ApiResponse) ResourceContext(javax.ws.rs.container.ResourceContext) FormService(io.gravitee.am.service.FormService) ApplicationNotFoundException(io.gravitee.am.service.exception.ApplicationNotFoundException) User(io.gravitee.am.identityprovider.api.User) ApplicationNotFoundException(io.gravitee.am.service.exception.ApplicationNotFoundException) DomainNotFoundException(io.gravitee.am.service.exception.DomainNotFoundException) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 3 with Form

use of io.gravitee.am.model.Form in project gravitee-access-management by gravitee-io.

the class MongoFormRepository method convert.

private Form convert(FormMongo pageMongo) {
    if (pageMongo == null) {
        return null;
    }
    Form page = new Form();
    page.setId(pageMongo.getId());
    page.setEnabled(pageMongo.isEnabled());
    page.setReferenceType(ReferenceType.valueOf(pageMongo.getReferenceType()));
    page.setReferenceId(pageMongo.getReferenceId());
    page.setClient(pageMongo.getClient());
    page.setTemplate(pageMongo.getTemplate());
    page.setContent(pageMongo.getContent());
    page.setAssets(pageMongo.getAssets());
    page.setCreatedAt(pageMongo.getCreatedAt());
    page.setUpdatedAt(pageMongo.getUpdatedAt());
    return page;
}
Also used : Form(io.gravitee.am.model.Form)

Example 4 with Form

use of io.gravitee.am.model.Form in project gravitee-access-management by gravitee-io.

the class FormsResourceTest method shouldCreate.

@Test
@Ignore
public void shouldCreate() {
    final String domainId = "domain-1";
    final Domain mockDomain = new Domain();
    mockDomain.setId(domainId);
    NewForm newForm = new NewForm();
    newForm.setTemplate(Template.LOGIN);
    newForm.setContent("content");
    doReturn(Maybe.just(mockDomain)).when(domainService).findById(domainId);
    doReturn(Single.just(new Form())).when(formService).create(eq(domainId), any(), any(User.class));
    final Response response = target("domains").path(domainId).path("forms").request().post(Entity.json(newForm));
    assertEquals(HttpStatusCode.CREATED_201, response.getStatus());
}
Also used : Response(javax.ws.rs.core.Response) User(io.gravitee.am.identityprovider.api.User) Form(io.gravitee.am.model.Form) NewForm(io.gravitee.am.service.model.NewForm) NewForm(io.gravitee.am.service.model.NewForm) Domain(io.gravitee.am.model.Domain) Ignore(org.junit.Ignore) Test(org.junit.Test) JerseySpringTest(io.gravitee.am.management.handlers.management.api.JerseySpringTest)

Example 5 with Form

use of io.gravitee.am.model.Form in project gravitee-access-management by gravitee-io.

the class FormRepositoryTest method shouldFindByClientAndTemplate.

@Test
public void shouldFindByClientAndTemplate() {
    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();
    }
    final Form form = buildForm();
    form.setReferenceId(FIXED_REF_ID);
    form.setClient(FIXED_CLI_ID);
    form.setTemplate("MyTemplateId");
    Form templateForm = repository.create(form).blockingGet();
    TestObserver<Form> testMaybe = repository.findByClientAndTemplate(ReferenceType.DOMAIN, FIXED_REF_ID, FIXED_CLI_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)

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