Search in sources :

Example 21 with ApplicationEntity

use of io.gravitee.rest.api.model.ApplicationEntity in project gravitee-management-rest-api by gravitee-io.

the class ApplicationResource method getApplicationType.

@GET
@Path("configuration")
@Produces(MediaType.APPLICATION_JSON)
@Permissions({ @Permission(value = RolePermission.APPLICATION_DEFINITION, acls = RolePermissionAction.READ) })
public Response getApplicationType(@PathParam("applicationId") String applicationId) {
    ApplicationEntity applicationEntity = applicationService.findById(applicationId);
    ApplicationTypeEntity applicationType = applicationTypeService.getApplicationType(applicationEntity.getType());
    return Response.ok(applicationType).build();
}
Also used : ApplicationTypeEntity(io.gravitee.rest.api.model.configuration.application.ApplicationTypeEntity) UpdateApplicationEntity(io.gravitee.rest.api.model.UpdateApplicationEntity) ApplicationEntity(io.gravitee.rest.api.model.ApplicationEntity) Permissions(io.gravitee.rest.api.portal.rest.security.Permissions)

Example 22 with ApplicationEntity

use of io.gravitee.rest.api.model.ApplicationEntity in project gravitee-management-rest-api by gravitee-io.

the class ApplicationsResource method createApplication.

@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Permissions({ @Permission(value = RolePermission.ENVIRONMENT_APPLICATION, acls = RolePermissionAction.CREATE) })
public Response createApplication(@Valid @NotNull(message = "Input must not be null.") ApplicationInput applicationInput) {
    NewApplicationEntity newApplicationEntity = new NewApplicationEntity();
    newApplicationEntity.setDescription(applicationInput.getDescription());
    newApplicationEntity.setGroups(applicationInput.getGroups() != null ? new HashSet<>(applicationInput.getGroups()) : new HashSet<>());
    newApplicationEntity.setName(applicationInput.getName());
    newApplicationEntity.setPicture(applicationInput.getPicture());
    final io.gravitee.rest.api.portal.rest.model.ApplicationSettings settings = applicationInput.getSettings();
    ApplicationSettings newApplicationEntitySettings = new ApplicationSettings();
    if (settings == null || (settings.getApp() == null && settings.getOauth() == null)) {
        newApplicationEntity.setSettings(newApplicationEntitySettings);
    } else {
        final io.gravitee.rest.api.portal.rest.model.SimpleApplicationSettings simpleAppInput = settings.getApp();
        if (simpleAppInput != null) {
            SimpleApplicationSettings sas = new SimpleApplicationSettings();
            sas.setClientId(simpleAppInput.getClientId());
            sas.setType(simpleAppInput.getType());
            newApplicationEntitySettings.setApp(sas);
        }
        final io.gravitee.rest.api.portal.rest.model.OAuthClientSettings oauthAppInput = settings.getOauth();
        if (oauthAppInput != null) {
            OAuthClientSettings ocs = new OAuthClientSettings();
            ocs.setApplicationType(oauthAppInput.getApplicationType());
            ocs.setGrantTypes(oauthAppInput.getGrantTypes());
            ocs.setRedirectUris(oauthAppInput.getRedirectUris());
            newApplicationEntitySettings.setoAuthClient(ocs);
        }
    }
    newApplicationEntity.setSettings(newApplicationEntitySettings);
    ApplicationEntity createdApplicationEntity = applicationService.create(newApplicationEntity, getAuthenticatedUser());
    return Response.created(this.getLocationHeader(createdApplicationEntity.getId())).entity(applicationMapper.convert(createdApplicationEntity, uriInfo)).build();
}
Also used : NewApplicationEntity(io.gravitee.rest.api.model.NewApplicationEntity) ApplicationSettings(io.gravitee.rest.api.model.application.ApplicationSettings) SimpleApplicationSettings(io.gravitee.rest.api.model.application.SimpleApplicationSettings) SimpleApplicationSettings(io.gravitee.rest.api.model.application.SimpleApplicationSettings) OAuthClientSettings(io.gravitee.rest.api.model.application.OAuthClientSettings) NewApplicationEntity(io.gravitee.rest.api.model.NewApplicationEntity) ApplicationEntity(io.gravitee.rest.api.model.ApplicationEntity) Permissions(io.gravitee.rest.api.portal.rest.security.Permissions)

Example 23 with ApplicationEntity

use of io.gravitee.rest.api.model.ApplicationEntity in project gravitee-management-rest-api by gravitee-io.

the class ApplicationsResource method createApplication.

/**
 * Create a new application for the authenticated user.
 *
 * @param application
 * @return
 */
@POST
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Create an application", notes = "User must have MANAGEMENT_APPLICATION[CREATE] permission to create an application.")
@ApiResponses({ @ApiResponse(code = 201, message = "Application successfully created", response = ApplicationEntity.class), @ApiResponse(code = 500, message = "Internal server error") })
@Permissions({ @Permission(value = RolePermission.ENVIRONMENT_APPLICATION, acls = RolePermissionAction.CREATE) })
public Response createApplication(@ApiParam(name = "application", required = true) @Valid @NotNull(message = "An application must be provided") final NewApplicationEntity application) {
    // To preserve backward compatibility, ensure that we have at least default settings for simple application type
    if (application.getSettings() == null || (application.getSettings().getoAuthClient() == null && application.getSettings().getApp() == null)) {
        ApplicationSettings settings = new ApplicationSettings();
        SimpleApplicationSettings simpleAppSettings = new SimpleApplicationSettings();
        simpleAppSettings.setType(application.getType());
        simpleAppSettings.setClientId(application.getClientId());
        settings.setApp(simpleAppSettings);
        application.setSettings(settings);
    }
    ApplicationEntity newApplication = applicationService.create(application, getAuthenticatedUser());
    if (newApplication != null) {
        return Response.created(this.getLocationHeader(newApplication.getId())).entity(newApplication).build();
    }
    return Response.serverError().build();
}
Also used : ApplicationSettings(io.gravitee.rest.api.model.application.ApplicationSettings) SimpleApplicationSettings(io.gravitee.rest.api.model.application.SimpleApplicationSettings) SimpleApplicationSettings(io.gravitee.rest.api.model.application.SimpleApplicationSettings) NewApplicationEntity(io.gravitee.rest.api.model.NewApplicationEntity) ApplicationEntity(io.gravitee.rest.api.model.ApplicationEntity) Permissions(io.gravitee.rest.api.management.rest.security.Permissions)

Example 24 with ApplicationEntity

use of io.gravitee.rest.api.model.ApplicationEntity in project gravitee-management-rest-api by gravitee-io.

the class ApplicationsResourceTest method shouldNotCreateApplication_emptyName.

@Test
public void shouldNotCreateApplication_emptyName() {
    final NewApplicationEntity appEntity = new NewApplicationEntity();
    appEntity.setName("");
    appEntity.setDescription("my description");
    ApplicationEntity returnedApp = new ApplicationEntity();
    returnedApp.setId("my-beautiful-application");
    doReturn(returnedApp).when(applicationService).create(any(NewApplicationEntity.class), Mockito.eq(JerseySpringTest.USER_NAME));
    final Response response = envTarget().request().post(Entity.json(appEntity));
    assertEquals(HttpStatusCode.BAD_REQUEST_400, response.getStatus());
}
Also used : Response(javax.ws.rs.core.Response) NewApplicationEntity(io.gravitee.rest.api.model.NewApplicationEntity) ApplicationEntity(io.gravitee.rest.api.model.ApplicationEntity) NewApplicationEntity(io.gravitee.rest.api.model.NewApplicationEntity) JerseySpringTest(io.gravitee.rest.api.management.rest.JerseySpringTest) Test(org.junit.Test)

Example 25 with ApplicationEntity

use of io.gravitee.rest.api.model.ApplicationEntity in project gravitee-management-rest-api by gravitee-io.

the class ApplicationsResourceTest method shouldCreateApplication.

@Test
public void shouldCreateApplication() {
    reset(applicationService);
    NewApplicationEntity newApplicationEntity = new NewApplicationEntity();
    newApplicationEntity.setName("My beautiful application");
    newApplicationEntity.setDescription("my description");
    ApplicationEntity createdApplication = new ApplicationEntity();
    createdApplication.setId("my-beautiful-application");
    doReturn(createdApplication).when(applicationService).create(any(NewApplicationEntity.class), Mockito.eq(USER_NAME));
    final Response response = envTarget().request().post(Entity.json(newApplicationEntity));
    assertEquals(HttpStatusCode.CREATED_201, response.getStatus());
    assertEquals(envTarget().path("my-beautiful-application").getUri().toString(), response.getHeaders().getFirst(HttpHeaders.LOCATION));
}
Also used : Response(javax.ws.rs.core.Response) NewApplicationEntity(io.gravitee.rest.api.model.NewApplicationEntity) ApplicationEntity(io.gravitee.rest.api.model.ApplicationEntity) NewApplicationEntity(io.gravitee.rest.api.model.NewApplicationEntity) JerseySpringTest(io.gravitee.rest.api.management.rest.JerseySpringTest) Test(org.junit.Test)

Aggregations

ApplicationEntity (io.gravitee.rest.api.model.ApplicationEntity)38 Test (org.junit.Test)19 Response (javax.ws.rs.core.Response)8 ApplicationSettings (io.gravitee.rest.api.model.application.ApplicationSettings)7 SimpleApplicationSettings (io.gravitee.rest.api.model.application.SimpleApplicationSettings)7 NewApplicationEntity (io.gravitee.rest.api.model.NewApplicationEntity)6 ApplicationListItem (io.gravitee.rest.api.model.application.ApplicationListItem)6 UserEntity (io.gravitee.rest.api.model.UserEntity)5 ApiEntity (io.gravitee.rest.api.model.api.ApiEntity)5 Application (io.gravitee.rest.api.portal.rest.model.Application)5 UpdateApplicationEntity (io.gravitee.rest.api.model.UpdateApplicationEntity)4 Before (org.junit.Before)4 SubscriptionEntity (io.gravitee.rest.api.model.SubscriptionEntity)3 NewAlertTriggerEntity (io.gravitee.rest.api.model.alert.NewAlertTriggerEntity)3 OAuthClientSettings (io.gravitee.rest.api.model.application.OAuthClientSettings)3 Permissions (io.gravitee.rest.api.portal.rest.security.Permissions)3 UserService (io.gravitee.rest.api.service.UserService)3 ApplicationNotFoundException (io.gravitee.rest.api.service.exceptions.ApplicationNotFoundException)3 ForbiddenAccessException (io.gravitee.rest.api.service.exceptions.ForbiddenAccessException)3 MediaType (io.gravitee.common.http.MediaType)2