Search in sources :

Example 6 with Application

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

the class ApplicationMapperTest method testConvertFromAppListItem.

@Test
public void testConvertFromAppListItem() {
    Application responseApplication = applicationMapper.convert(applicationListItem, uriInfo);
    checkApplication(now, responseApplication, AppSettingsEnum.NO_SETTINGS);
}
Also used : Application(io.gravitee.rest.api.portal.rest.model.Application) Test(org.junit.Test)

Example 7 with Application

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

the class ApplicationMapperTest method testConvertFromAppEntityOAuthClient.

@Test
public void testConvertFromAppEntityOAuthClient() {
    ApplicationSettings settings = new ApplicationSettings();
    OAuthClientSettings oAuthClientEntitySettings = new OAuthClientSettings();
    oAuthClientEntitySettings.setApplicationType(APPLICATION_OAUTH_APPLICATION_TYPE);
    oAuthClientEntitySettings.setClientId(APPLICATION_OAUTH_CLIENT_ID);
    oAuthClientEntitySettings.setClientSecret(APPLICATION_OAUTH_CLIENT_SECRET);
    oAuthClientEntitySettings.setClientUri(APPLICATION_OAUTH_CLIENT_URI);
    oAuthClientEntitySettings.setGrantTypes(Arrays.asList(APPLICATION_OAUTH_GRANT_TYPE));
    oAuthClientEntitySettings.setLogoUri(APPLICATION_OAUTH_LOGO_URI);
    oAuthClientEntitySettings.setRedirectUris(Arrays.asList(APPLICATION_OAUTH_REDIRECT_URI));
    oAuthClientEntitySettings.setRenewClientSecretSupported(true);
    oAuthClientEntitySettings.setResponseTypes(Arrays.asList(APPLICATION_OAUTH_RESPONSE_TYPE));
    settings.setoAuthClient(oAuthClientEntitySettings);
    applicationEntity.setSettings(settings);
    Application responseApplication = applicationMapper.convert(applicationEntity, uriInfo);
    checkApplication(now, responseApplication, AppSettingsEnum.OAUTH_SETTINGS);
}
Also used : ApplicationSettings(io.gravitee.rest.api.model.application.ApplicationSettings) SimpleApplicationSettings(io.gravitee.rest.api.model.application.SimpleApplicationSettings) OAuthClientSettings(io.gravitee.rest.api.model.application.OAuthClientSettings) Application(io.gravitee.rest.api.portal.rest.model.Application) Test(org.junit.Test)

Example 8 with Application

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

the class ApiSubscribersResource method getSubscriberApplicationsByApiId.

@GET
@Produces({ MediaType.APPLICATION_JSON })
public Response getSubscriberApplicationsByApiId(@BeanParam PaginationParam paginationParam, @PathParam("apiId") String apiId, @QueryParam("statuses") List<SubscriptionStatus> statuses) {
    String currentUser = getAuthenticatedUserOrNull();
    final ApiQuery apiQuery = new ApiQuery();
    apiQuery.setIds(Collections.singletonList(apiId));
    Collection<ApiEntity> userApis = apiService.findPublishedByUser(currentUser, apiQuery);
    Optional<ApiEntity> optionalApi = userApis.stream().filter(a -> a.getId().equals(apiId)).findFirst();
    if (optionalApi.isPresent()) {
        SubscriptionQuery subscriptionQuery = new SubscriptionQuery();
        subscriptionQuery.setApi(apiId);
        subscriptionQuery.setStatuses(statuses);
        ApiEntity api = optionalApi.get();
        if (!api.getPrimaryOwner().getId().equals(currentUser)) {
            Set<ApplicationListItem> userApplications = this.applicationService.findByUser(currentUser);
            if (userApplications == null || userApplications.isEmpty()) {
                return createListResponse(Collections.emptyList(), paginationParam);
            }
            subscriptionQuery.setApplications(userApplications.stream().map(ApplicationListItem::getId).collect(Collectors.toList()));
        }
        Map<String, Long> nbHitsByApp = getNbHitsByApplication(apiId);
        Collection<SubscriptionEntity> subscriptions = subscriptionService.search(subscriptionQuery);
        List<Application> subscribersApplication = subscriptions.stream().map(SubscriptionEntity::getApplication).distinct().map(application -> applicationService.findById(application)).map(application -> applicationMapper.convert(application, uriInfo)).sorted((o1, o2) -> compareApp(nbHitsByApp, o1, o2)).collect(Collectors.toList());
        return createListResponse(subscribersApplication, paginationParam);
    }
    throw new ApiNotFoundException(apiId);
}
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) java.util(java.util) SubscriptionStatus(io.gravitee.rest.api.model.SubscriptionStatus) ApiNotFoundException(io.gravitee.rest.api.service.exceptions.ApiNotFoundException) SubscriptionEntity(io.gravitee.rest.api.model.SubscriptionEntity) ApplicationMapper(io.gravitee.rest.api.portal.rest.mapper.ApplicationMapper) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) Application(io.gravitee.rest.api.portal.rest.model.Application) GroupByQuery(io.gravitee.rest.api.model.analytics.query.GroupByQuery) Inject(javax.inject.Inject) SubscriptionService(io.gravitee.rest.api.service.SubscriptionService) MediaType(io.gravitee.common.http.MediaType) ChronoUnit(java.time.temporal.ChronoUnit) javax.ws.rs(javax.ws.rs) Response(javax.ws.rs.core.Response) PaginationParam(io.gravitee.rest.api.portal.rest.resource.param.PaginationParam) ApplicationService(io.gravitee.rest.api.service.ApplicationService) TopHitsAnalytics(io.gravitee.rest.api.model.analytics.TopHitsAnalytics) AnalyticsService(io.gravitee.rest.api.service.AnalyticsService) SubscriptionQuery(io.gravitee.rest.api.model.subscription.SubscriptionQuery) ApiNotFoundException(io.gravitee.rest.api.service.exceptions.ApiNotFoundException) ApiEntity(io.gravitee.rest.api.model.api.ApiEntity) SubscriptionEntity(io.gravitee.rest.api.model.SubscriptionEntity) SubscriptionQuery(io.gravitee.rest.api.model.subscription.SubscriptionQuery) ApiQuery(io.gravitee.rest.api.model.api.ApiQuery) ApplicationListItem(io.gravitee.rest.api.model.application.ApplicationListItem) Application(io.gravitee.rest.api.portal.rest.model.Application)

Example 9 with Application

use of io.gravitee.rest.api.portal.rest.model.Application 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)

Example 10 with Application

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

the class ApiSubscribersResourceTest method shouldGetApiSubscribersAsPrimaryOwnerAlphaSorted.

@Test
public void shouldGetApiSubscribersAsPrimaryOwnerAlphaSorted() {
    TopHitsAnalytics mockAnalytics = new TopHitsAnalytics();
    Map<String, Long> mockedValues = new HashMap<>();
    mockedValues.put("A", 0L);
    mockedValues.put("C", 0L);
    mockedValues.put("B", 0L);
    mockAnalytics.setValues(mockedValues);
    doReturn(mockAnalytics).when(analyticsService).execute(any(GroupByQuery.class));
    SubscriptionEntity subA1 = new SubscriptionEntity();
    subA1.setApplication("A");
    subA1.setApi(API);
    SubscriptionEntity subB1 = new SubscriptionEntity();
    subB1.setApplication("B");
    subB1.setApi(API);
    SubscriptionEntity subC1 = new SubscriptionEntity();
    subC1.setApplication("C");
    subC1.setApi(API);
    doReturn(Arrays.asList(subB1, subC1, subA1)).when(subscriptionService).search(any());
    ApplicationEntity appA = new ApplicationEntity();
    appA.setId("A");
    appA.setName("A");
    doReturn(appA).when(applicationService).findById("A");
    doReturn(new Application().id("A").name("A")).when(applicationMapper).convert(eq(appA), any());
    ApplicationEntity appB = new ApplicationEntity();
    appB.setId("B");
    appB.setName("B");
    doReturn(appB).when(applicationService).findById("B");
    doReturn(new Application().id("B").name("B")).when(applicationMapper).convert(eq(appB), any());
    ApplicationEntity appC = new ApplicationEntity();
    appC.setId("C");
    appC.setName("C");
    doReturn(appC).when(applicationService).findById("C");
    doReturn(new Application().id("C").name("C")).when(applicationMapper).convert(eq(appC), any());
    final Response response = target(API).path("subscribers").request().get();
    assertEquals(OK_200, response.getStatus());
    final ApplicationsResponse applicationsResponse = response.readEntity(ApplicationsResponse.class);
    assertNotNull(applicationsResponse);
    assertEquals(3, applicationsResponse.getData().size());
    assertEquals("A", applicationsResponse.getData().get(0).getId());
    assertEquals("B", applicationsResponse.getData().get(1).getId());
    assertEquals("C", applicationsResponse.getData().get(2).getId());
}
Also used : ApplicationsResponse(io.gravitee.rest.api.portal.rest.model.ApplicationsResponse) ErrorResponse(io.gravitee.rest.api.portal.rest.model.ErrorResponse) Response(javax.ws.rs.core.Response) GroupByQuery(io.gravitee.rest.api.model.analytics.query.GroupByQuery) ApplicationEntity(io.gravitee.rest.api.model.ApplicationEntity) TopHitsAnalytics(io.gravitee.rest.api.model.analytics.TopHitsAnalytics) SubscriptionEntity(io.gravitee.rest.api.model.SubscriptionEntity) Application(io.gravitee.rest.api.portal.rest.model.Application) ApplicationsResponse(io.gravitee.rest.api.portal.rest.model.ApplicationsResponse) Test(org.junit.Test)

Aggregations

Application (io.gravitee.rest.api.portal.rest.model.Application)11 Test (org.junit.Test)7 ApplicationEntity (io.gravitee.rest.api.model.ApplicationEntity)6 ApplicationSettings (io.gravitee.rest.api.model.application.ApplicationSettings)5 SimpleApplicationSettings (io.gravitee.rest.api.model.application.SimpleApplicationSettings)5 SubscriptionEntity (io.gravitee.rest.api.model.SubscriptionEntity)4 TopHitsAnalytics (io.gravitee.rest.api.model.analytics.TopHitsAnalytics)4 GroupByQuery (io.gravitee.rest.api.model.analytics.query.GroupByQuery)4 ApplicationListItem (io.gravitee.rest.api.model.application.ApplicationListItem)4 OAuthClientSettings (io.gravitee.rest.api.model.application.OAuthClientSettings)4 Response (javax.ws.rs.core.Response)4 UserEntity (io.gravitee.rest.api.model.UserEntity)3 ApplicationsResponse (io.gravitee.rest.api.portal.rest.model.ApplicationsResponse)3 ErrorResponse (io.gravitee.rest.api.portal.rest.model.ErrorResponse)3 Collectors (java.util.stream.Collectors)3 ApiEntity (io.gravitee.rest.api.model.api.ApiEntity)2 ApiQuery (io.gravitee.rest.api.model.api.ApiQuery)2 SubscriptionQuery (io.gravitee.rest.api.model.subscription.SubscriptionQuery)2 ApplicationLinks (io.gravitee.rest.api.portal.rest.model.ApplicationLinks)2 Group (io.gravitee.rest.api.portal.rest.model.Group)2