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