Search in sources :

Example 31 with ApplicationEntity

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

the class ApplicationMetadataServiceImpl method checkReferenceMetadataFormat.

@Override
protected void checkReferenceMetadataFormat(MetadataFormat format, String value, MetadataReferenceType referenceType, String referenceId) {
    final ApplicationEntity applicationEntity = applicationService.findById(referenceId);
    metadataService.checkMetadataFormat(format, value, referenceType, applicationEntity);
}
Also used : ApplicationEntity(io.gravitee.rest.api.model.ApplicationEntity)

Example 32 with ApplicationEntity

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

Example 33 with ApplicationEntity

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

the class ApiSubscribersResourceTest method shouldGetApiSubscribersAsPrimaryOwner.

@Test
public void shouldGetApiSubscribersAsPrimaryOwner() {
    TopHitsAnalytics mockAnalytics = new TopHitsAnalytics();
    Map<String, Long> mockedValues = new HashMap<>();
    mockedValues.put("A", 10L);
    mockedValues.put("B", 20L);
    mockedValues.put("C", 30L);
    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");
    doReturn(appA).when(applicationService).findById("A");
    doReturn(new Application().id("A")).when(applicationMapper).convert(eq(appA), any());
    ApplicationEntity appB = new ApplicationEntity();
    appB.setId("B");
    doReturn(appB).when(applicationService).findById("B");
    doReturn(new Application().id("B")).when(applicationMapper).convert(eq(appB), any());
    ApplicationEntity appC = new ApplicationEntity();
    appC.setId("C");
    doReturn(appC).when(applicationService).findById("C");
    doReturn(new Application().id("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("C", applicationsResponse.getData().get(0).getId());
    assertEquals("B", applicationsResponse.getData().get(1).getId());
    assertEquals("A", 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)

Example 34 with ApplicationEntity

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

the class AnalyticsServiceImpl method getApplicationMetadata.

private Map<String, String> getApplicationMetadata(String application) {
    Map<String, String> metadata = new HashMap<>();
    try {
        if (application.equals(UNKNOWN_SERVICE) || application.equals(UNKNOWN_SERVICE_MAPPED)) {
            metadata.put(METADATA_NAME, METADATA_UNKNOWN_APPLICATION_NAME);
            metadata.put(METADATA_UNKNOWN, Boolean.TRUE.toString());
        } else {
            ApplicationEntity applicationEntity = applicationService.findById(application);
            metadata.put(METADATA_NAME, applicationEntity.getName());
            if (ApplicationStatus.ARCHIVED.toString().equals(applicationEntity.getStatus())) {
                metadata.put(METADATA_DELETED, Boolean.TRUE.toString());
            }
        }
    } catch (ApplicationNotFoundException anfe) {
        metadata.put(METADATA_DELETED, Boolean.TRUE.toString());
        metadata.put(METADATA_NAME, METADATA_DELETED_APPLICATION_NAME);
    }
    return metadata;
}
Also used : ApplicationEntity(io.gravitee.rest.api.model.ApplicationEntity)

Example 35 with ApplicationEntity

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

the class ApplicationAlertServiceTest method getApplication.

private ApplicationEntity getApplication() {
    ApplicationEntity application = new ApplicationEntity();
    application.setId(APPLICATION_ID);
    application.setName(APPLICATION_NAME);
    application.setGroups(new HashSet<>());
    return application;
}
Also used : ApplicationEntity(io.gravitee.rest.api.model.ApplicationEntity)

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