Search in sources :

Example 16 with ApplicationEntity

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

the class ApplicationAlertServiceTest method shouldCreateStatusAlert.

@Test
public void shouldCreateStatusAlert() {
    NewAlertTriggerEntity newAlert = new NewAlertTriggerEntity();
    newAlert.setId(ALERT_ID);
    newAlert.setType("METRICS_RATE");
    ApplicationEntity application = getApplication();
    prepareForCreation(newAlert);
    when(applicationService.findById(APPLICATION_ID)).thenReturn(application);
    cut.create(APPLICATION_ID, newAlert);
    verify(alertService, times(1)).create(newAlert);
    verify(notificationTemplateService, times(1)).findByHookAndScope(AlertHook.CONSUMER_HTTP_STATUS.name(), HookScope.TEMPLATES_FOR_ALERT.name());
}
Also used : NewAlertTriggerEntity(io.gravitee.rest.api.model.alert.NewAlertTriggerEntity) ApplicationEntity(io.gravitee.rest.api.model.ApplicationEntity) Test(org.junit.Test)

Example 17 with ApplicationEntity

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

the class ApplicationService_FindByIdTest method shouldFindById.

@Test
public void shouldFindById() throws TechnicalException {
    when(applicationRepository.findById(APPLICATION_ID)).thenReturn(Optional.of(application));
    when(application.getStatus()).thenReturn(ApplicationStatus.ACTIVE);
    when(application.getType()).thenReturn(ApplicationType.SIMPLE);
    final ApplicationEntity applicationEntity = applicationService.findById(APPLICATION_ID);
    assertNotNull(applicationEntity);
}
Also used : ApplicationEntity(io.gravitee.rest.api.model.ApplicationEntity) Test(org.junit.Test)

Example 18 with ApplicationEntity

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

the class ApplicationService_RestoreTest method shouldRestoreApp.

@Test
public void shouldRestoreApp() throws TechnicalException {
    Application app = fakeApp(false);
    app.setStatus(ApplicationStatus.ARCHIVED);
    when(applicationRepository.findById(APP)).thenReturn(Optional.of(app));
    when(applicationRepository.update(app)).thenReturn(fakeApp(true));
    when(subscriptionService.findByApplicationAndPlan(any(), any())).thenReturn(Collections.emptyList());
    when(userService.findById(any())).thenReturn(new UserEntity());
    ApplicationEntity result = applicationService.restore(APP);
    verify(membershipService, times(1)).deleteReference(MembershipReferenceType.APPLICATION, APP);
    verify(membershipService, times(1)).addRoleToMemberOnReference(any(), any(), any());
    verify(genericNotificationConfigService, times(1)).deleteReference(NotificationReferenceType.APPLICATION, APP);
    verify(portalNotificationConfigService, times(1)).deleteReference(NotificationReferenceType.APPLICATION, APP);
    verify(auditService, times(1)).createApplicationAuditLog(any(), any(), any(), any(), any(), any());
    Assertions.assertThat(result.getStatus()).isEqualTo(ApplicationStatus.ACTIVE.name());
}
Also used : ApplicationEntity(io.gravitee.rest.api.model.ApplicationEntity) Application(io.gravitee.repository.management.model.Application) UserEntity(io.gravitee.rest.api.model.UserEntity) Test(org.junit.Test)

Example 19 with ApplicationEntity

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

the class PermissionsResource method getCurrentUserPermissions.

@GET
@Produces(MediaType.APPLICATION_JSON)
public Response getCurrentUserPermissions(@QueryParam("apiId") String apiId, @QueryParam("applicationId") String applicationId) {
    final String userId = getAuthenticatedUser();
    if (apiId != null) {
        ApiQuery apiQuery = new ApiQuery();
        apiQuery.setIds(Collections.singletonList(apiId));
        Set<ApiEntity> publishedByUser = apiService.findPublishedByUser(getAuthenticatedUserOrNull(), apiQuery);
        ApiEntity apiEntity = publishedByUser.stream().filter(a -> a.getId().equals(apiId)).findFirst().orElseThrow(() -> new ApiNotFoundException(apiId));
        Map<String, char[]> permissions;
        permissions = membershipService.getUserMemberPermissions(apiEntity, userId);
        return Response.ok(permissions).build();
    } else if (applicationId != null) {
        ApplicationListItem applicationListItem = applicationService.findByUser(getAuthenticatedUser()).stream().filter(a -> a.getId().equals(applicationId)).findFirst().orElseThrow(() -> new ApplicationNotFoundException(applicationId));
        ApplicationEntity application = applicationService.findById(applicationListItem.getId());
        Map<String, char[]> permissions;
        permissions = membershipService.getUserMemberPermissions(application, userId);
        return Response.ok(permissions).build();
    }
    throw new BadRequestException("One of the two parameters appId or applicationId must not be null.");
}
Also used : ApiQuery(io.gravitee.rest.api.model.api.ApiQuery) ApplicationListItem(io.gravitee.rest.api.model.application.ApplicationListItem) ApiEntity(io.gravitee.rest.api.model.api.ApiEntity) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) MembershipService(io.gravitee.rest.api.service.MembershipService) ApiNotFoundException(io.gravitee.rest.api.service.exceptions.ApiNotFoundException) Set(java.util.Set) ApiService(io.gravitee.rest.api.service.ApiService) Inject(javax.inject.Inject) MediaType(io.gravitee.common.http.MediaType) QueryParam(javax.ws.rs.QueryParam) Response(javax.ws.rs.core.Response) Map(java.util.Map) ApplicationService(io.gravitee.rest.api.service.ApplicationService) BadRequestException(javax.ws.rs.BadRequestException) ApplicationNotFoundException(io.gravitee.rest.api.service.exceptions.ApplicationNotFoundException) Collections(java.util.Collections) ApplicationEntity(io.gravitee.rest.api.model.ApplicationEntity) ApiQuery(io.gravitee.rest.api.model.api.ApiQuery) ApplicationListItem(io.gravitee.rest.api.model.application.ApplicationListItem) ApplicationNotFoundException(io.gravitee.rest.api.service.exceptions.ApplicationNotFoundException) ApplicationEntity(io.gravitee.rest.api.model.ApplicationEntity) ApiNotFoundException(io.gravitee.rest.api.service.exceptions.ApiNotFoundException) ApiEntity(io.gravitee.rest.api.model.api.ApiEntity) BadRequestException(javax.ws.rs.BadRequestException) Map(java.util.Map) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 20 with ApplicationEntity

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

the class ApplicationResource method updateApplicationByApplicationId.

@PUT
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Permissions({ @Permission(value = RolePermission.APPLICATION_DEFINITION, acls = RolePermissionAction.UPDATE) })
public Response updateApplicationByApplicationId(@PathParam("applicationId") String applicationId, @Valid @NotNull(message = "Input must not be null.") Application application) {
    if (!applicationId.equalsIgnoreCase(application.getId())) {
        throw new BadRequestException("'applicationId' is not the same that the application in payload");
    }
    ApplicationEntity appEntity = applicationService.findById(applicationId);
    UpdateApplicationEntity updateApplicationEntity = new UpdateApplicationEntity();
    updateApplicationEntity.setDescription(application.getDescription());
    updateApplicationEntity.setName(application.getName());
    updateApplicationEntity.setPicture(checkAndScaleImage(application.getPicture()));
    checkImageFormat(application.getBackground());
    updateApplicationEntity.setBackground(application.getBackground());
    updateApplicationEntity.setGroups(appEntity.getGroups());
    if (application.getSettings() != null) {
        ApplicationSettings settings = new ApplicationSettings();
        if (application.getSettings().getApp() != null) {
            SimpleApplicationSettings sas = appEntity.getSettings().getApp();
            sas.setClientId(application.getSettings().getApp().getClientId());
            sas.setType(application.getSettings().getApp().getType());
            settings.setApp(sas);
        } else if (application.getSettings().getOauth() != null) {
            OAuthClientSettings oacs = appEntity.getSettings().getoAuthClient();
            oacs.setGrantTypes(application.getSettings().getOauth().getGrantTypes());
            oacs.setRedirectUris(application.getSettings().getOauth().getRedirectUris());
            settings.setoAuthClient(oacs);
        }
        updateApplicationEntity.setSettings(settings);
    }
    Application updatedApp = applicationMapper.convert(applicationService.update(applicationId, updateApplicationEntity), uriInfo);
    return Response.ok(addApplicationLinks(updatedApp)).tag(Long.toString(updatedApp.getUpdatedAt().toInstant().toEpochMilli())).lastModified(Date.from(updatedApp.getUpdatedAt().toInstant())).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) OAuthClientSettings(io.gravitee.rest.api.model.application.OAuthClientSettings) UpdateApplicationEntity(io.gravitee.rest.api.model.UpdateApplicationEntity) ApplicationEntity(io.gravitee.rest.api.model.ApplicationEntity) Application(io.gravitee.rest.api.portal.rest.model.Application) UpdateApplicationEntity(io.gravitee.rest.api.model.UpdateApplicationEntity) Permissions(io.gravitee.rest.api.portal.rest.security.Permissions)

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