use of io.gravitee.rest.api.model.application.ApplicationListItem in project gravitee-management-rest-api by gravitee-io.
the class FilteringServiceImpl method getCurrentUserSubscribedApis.
private FilteredEntities<ApiEntity> getCurrentUserSubscribedApis(Collection<ApiEntity> apis, boolean excluded) {
// get Current user applications
List<String> currentUserApplicationsId = applicationService.findByUser(getAuthenticatedUser().getUsername()).stream().map(ApplicationListItem::getId).collect(Collectors.toList());
// find all subscribed apis for these applications
SubscriptionQuery subscriptionQuery = new SubscriptionQuery();
subscriptionQuery.setApplications(currentUserApplicationsId);
List<String> subscribedApis = subscriptionService.search(subscriptionQuery).stream().map(SubscriptionEntity::getApi).distinct().collect(Collectors.toList());
// filter apis list with subscribed apis list
return new FilteredEntities<>(apis.stream().filter(api -> (!excluded && subscribedApis.contains(api.getId())) || (excluded && !subscribedApis.contains(api.getId()))).sorted((a1, a2) -> String.CASE_INSENSITIVE_ORDER.compare(a1.getName(), a2.getName())).collect(Collectors.toList()), null);
}
use of io.gravitee.rest.api.model.application.ApplicationListItem in project gravitee-management-rest-api by gravitee-io.
the class ApplicationMapperTest method init.
@Before
public void init() {
now = Instant.now();
Date nowDate = Date.from(now);
applicationEntity = new ApplicationEntity();
applicationListItem = new ApplicationListItem();
// init
reset(groupService);
reset(userService);
reset(userMapper);
GroupEntity grpEntity = new GroupEntity();
grpEntity.setId(APPLICATION_GROUP_ID);
grpEntity.setName(APPLICATION_GROUP_NAME);
when(groupService.findById(APPLICATION_GROUP_ID)).thenReturn(grpEntity);
UserEntity userEntity = Mockito.mock(UserEntity.class);
when(userEntity.getDisplayName()).thenReturn(APPLICATION_USER_DISPLAYNAME);
when(userEntity.getEmail()).thenReturn(APPLICATION_USER_EMAIL);
when(userEntity.getId()).thenReturn(APPLICATION_USER_ID);
when(userService.findById(APPLICATION_USER_ID)).thenReturn(userEntity);
when(userMapper.convert(userEntity)).thenCallRealMethod();
when(userMapper.computeUserLinks(anyString(), any())).thenCallRealMethod();
PrimaryOwnerEntity primaryOwner = new PrimaryOwnerEntity(userEntity);
when(uriInfo.getBaseUriBuilder()).thenReturn(UriBuilder.fromPath(""));
applicationEntity.setCreatedAt(nowDate);
applicationEntity.setDescription(APPLICATION_DESCRIPTION);
applicationEntity.setGroups(new HashSet<String>(Arrays.asList(APPLICATION_GROUP_ID)));
applicationEntity.setId(APPLICATION_ID);
applicationEntity.setName(APPLICATION_NAME);
applicationEntity.setPrimaryOwner(primaryOwner);
applicationEntity.setStatus(APPLICATION_STATUS);
applicationEntity.setType(APPLICATION_TYPE);
applicationEntity.setUpdatedAt(nowDate);
applicationListItem.setCreatedAt(nowDate);
applicationListItem.setDescription(APPLICATION_DESCRIPTION);
applicationListItem.setGroups(new HashSet<String>(Arrays.asList(APPLICATION_GROUP_ID)));
applicationListItem.setId(APPLICATION_ID);
applicationListItem.setName(APPLICATION_NAME);
applicationListItem.setPrimaryOwner(primaryOwner);
applicationListItem.setStatus(APPLICATION_STATUS);
applicationListItem.setType(APPLICATION_TYPE);
applicationListItem.setUpdatedAt(nowDate);
}
use of io.gravitee.rest.api.model.application.ApplicationListItem in project gravitee-management-rest-api by gravitee-io.
the class ApplicationAlertServiceTest method shouldHandleNotificationTemplateUpdatedEventResponseTimeAlert.
@Test
public void shouldHandleNotificationTemplateUpdatedEventResponseTimeAlert() throws Exception {
NotificationTemplateEntity notificationTemplate = new NotificationTemplateEntity();
notificationTemplate.setHook(AlertHook.CONSUMER_RESPONSE_TIME.name());
notificationTemplate.setTitle("notification-template-title");
notificationTemplate.setContent("notification-template-content");
NotificationTemplateEvent notificationTemplateEvent = new NotificationTemplateEvent("org-id", notificationTemplate);
final SimpleEvent<ApplicationAlertEventType, Object> event = new SimpleEvent<>(ApplicationAlertEventType.NOTIFICATION_TEMPLATE_UPDATE, notificationTemplateEvent);
ApplicationListItem app1 = new ApplicationListItem();
app1.setId("app1");
ApplicationListItem app2 = new ApplicationListItem();
app2.setId("app2");
when(applicationService.findByOrganization("org-id")).thenReturn(new HashSet<>(Arrays.asList(app1, app2)));
final AlertTriggerEntity alertTrigger = mock(AlertTriggerEntity.class);
when(alertTrigger.getType()).thenReturn("METRICS_AGGREGATION");
when(alertService.findByReferenceAndReferenceIds(AlertReferenceType.APPLICATION, Arrays.asList("app1", "app2"))).thenReturn(Collections.singletonList(alertTrigger));
Notification notification = new Notification();
notification.setType("default-email");
notification.setConfiguration("");
when(alertTrigger.getNotifications()).thenReturn(Collections.singletonList(notification));
JsonNode emailNode = JsonNodeFactory.instance.objectNode().put("to", "to").put("from", "from").put("subject", "subject").put("body", "body");
when(mapper.readTree(notification.getConfiguration())).thenReturn(emailNode);
cut.handleEvent(event);
ArgumentCaptor<UpdateAlertTriggerEntity> updatingCaptor = ArgumentCaptor.forClass(UpdateAlertTriggerEntity.class);
verify(alertService, times(1)).update(updatingCaptor.capture());
final UpdateAlertTriggerEntity updating = updatingCaptor.getValue();
assertThat(updating.getNotifications().get(0).getConfiguration()).contains("notification-template-content");
assertThat(updating.getNotifications().get(0).getConfiguration()).contains("notification-template-title");
}
use of io.gravitee.rest.api.model.application.ApplicationListItem in project gravitee-management-rest-api by gravitee-io.
the class ApplicationService_FindAllTest method shouldTryFindAll.
@Test
public void shouldTryFindAll() throws Exception {
Application application = new Application();
application.setId("appId");
application.setType(ApplicationType.SIMPLE);
application.setStatus(ApplicationStatus.ACTIVE);
when(applicationRepository.findAllByEnvironment(eq("DEFAULT"), eq(ApplicationStatus.ACTIVE))).thenReturn(new HashSet<>(Collections.singletonList(application)));
when(roleService.findPrimaryOwnerRoleByOrganization(any(), any())).thenReturn(new RoleEntity());
when(membershipService.getMembershipsByReferencesAndRole(any(), any(), any())).thenReturn(new HashSet<>(Collections.singletonList(new MembershipEntity())));
when(userService.findByIds(any())).thenReturn(Collections.emptySet());
Set<ApplicationListItem> set = applicationService.findAll();
assertThat(set).hasSize(1);
verify(applicationRepository, times(1)).findAllByEnvironment("DEFAULT", ApplicationStatus.ACTIVE);
}
use of io.gravitee.rest.api.model.application.ApplicationListItem in project gravitee-management-rest-api by gravitee-io.
the class ApplicationMapper method convert.
public Application convert(ApplicationListItem applicationListItem, UriInfo uriInfo) {
final Application application = new Application();
application.setApplicationType(applicationListItem.getType());
application.setCreatedAt(applicationListItem.getCreatedAt().toInstant().atOffset(ZoneOffset.UTC));
application.setDescription(applicationListItem.getDescription());
Set<String> groupEntities = applicationListItem.getGroups();
if (groupEntities != null && !groupEntities.isEmpty()) {
List<Group> groups = groupEntities.stream().map(groupService::findById).map(groupEntity -> new Group().id(groupEntity.getId()).name(groupEntity.getName())).collect(Collectors.toList());
application.setGroups(groups);
}
application.setId(applicationListItem.getId());
application.setName(applicationListItem.getName());
UserEntity primaryOwnerUserEntity = userService.findById(applicationListItem.getPrimaryOwner().getId());
User owner = userMapper.convert(primaryOwnerUserEntity);
owner.setLinks(userMapper.computeUserLinks(usersURL(uriInfo.getBaseUriBuilder(), primaryOwnerUserEntity.getId()), primaryOwnerUserEntity.getUpdatedAt()));
application.setOwner(owner);
application.setUpdatedAt(applicationListItem.getUpdatedAt().toInstant().atOffset(ZoneOffset.UTC));
ApplicationSettings settings = applicationListItem.getSettings();
application.setHasClientId(settings != null && ((settings.getoAuthClient() != null && settings.getoAuthClient().getClientId() != null && !settings.getoAuthClient().getClientId().isEmpty()) || (settings.getApp() != null && settings.getApp().getClientId() != null && !settings.getApp().getClientId().isEmpty())));
return application;
}
Aggregations