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);
}
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);
}
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);
}
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();
}
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());
}
Aggregations