use of io.gravitee.rest.api.model.notification.PortalNotificationConfigEntity in project gravitee-management-rest-api by gravitee-io.
the class ApplicationNotificationResource method get.
@GET
@Produces(MediaType.APPLICATION_JSON)
@Permissions({ @Permission(value = RolePermission.APPLICATION_NOTIFICATION, acls = RolePermissionAction.READ) })
public Response get(@PathParam("applicationId") String applicationId) {
// Does application exists ?
applicationService.findById(applicationId);
final PortalNotificationConfigEntity portalConfig = portalNotificationConfigService.findById(getAuthenticatedUser(), NotificationReferenceType.APPLICATION, applicationId);
final Set<String> hooks = new HashSet<>(portalConfig.getHooks());
genericNotificationConfigService.findByReference(NotificationReferenceType.APPLICATION, applicationId).forEach(genericNotif -> hooks.addAll(genericNotif.getHooks()));
return Response.ok(hooks).build();
}
use of io.gravitee.rest.api.model.notification.PortalNotificationConfigEntity in project gravitee-management-rest-api by gravitee-io.
the class PortalNotificationConfigServiceImpl method getDefaultEmpty.
private PortalNotificationConfigEntity getDefaultEmpty(String user, NotificationReferenceType referenceType, String referenceId) {
PortalNotificationConfigEntity portalNotificationConfigEntity = new PortalNotificationConfigEntity();
portalNotificationConfigEntity.setConfigType(NotificationConfigType.PORTAL);
portalNotificationConfigEntity.setReferenceType(referenceType.name());
portalNotificationConfigEntity.setReferenceId(referenceId);
portalNotificationConfigEntity.setUser(user);
portalNotificationConfigEntity.setHooks(Collections.emptyList());
return portalNotificationConfigEntity;
}
use of io.gravitee.rest.api.model.notification.PortalNotificationConfigEntity in project gravitee-management-rest-api by gravitee-io.
the class PortalNotificationConfigService_SaveTest method shouldCreate.
@Test
public void shouldCreate() throws TechnicalException {
PortalNotificationConfig cfg = mock(PortalNotificationConfig.class);
when(cfg.getReferenceType()).thenReturn(NotificationReferenceType.API);
when(cfg.getReferenceId()).thenReturn("123");
when(cfg.getUser()).thenReturn("user");
when(cfg.getHooks()).thenReturn(Arrays.asList("A", "B", "C"));
PortalNotificationConfigEntity cfgEntity = mock(PortalNotificationConfigEntity.class);
when(cfgEntity.getReferenceType()).thenReturn(NotificationReferenceType.API.name());
when(cfgEntity.getReferenceId()).thenReturn("123");
when(cfgEntity.getUser()).thenReturn("user");
when(cfgEntity.getHooks()).thenReturn(Arrays.asList("A", "B", "C"));
when(portalNotificationConfigRepository.findById("user", NotificationReferenceType.API, "123")).thenReturn(empty());
when(portalNotificationConfigRepository.create(any(PortalNotificationConfig.class))).thenReturn(cfg);
final PortalNotificationConfigEntity entity = portalNotificationConfigService.save(cfgEntity);
assertNotNull(entity);
assertEquals("referenceId", cfgEntity.getReferenceId(), entity.getReferenceId());
assertEquals("referenceType", cfgEntity.getReferenceType(), entity.getReferenceType());
assertEquals("user", cfgEntity.getUser(), entity.getUser());
assertEquals("hooks", cfgEntity.getHooks(), entity.getHooks());
verify(portalNotificationConfigRepository, times(1)).findById("user", NotificationReferenceType.API, "123");
verify(portalNotificationConfigRepository, times(1)).create(any());
verify(portalNotificationConfigRepository, never()).delete(any());
verify(portalNotificationConfigRepository, never()).update(any());
}
use of io.gravitee.rest.api.model.notification.PortalNotificationConfigEntity in project gravitee-management-rest-api by gravitee-io.
the class PortalNotificationConfigService_SaveTest method shouldUpdate.
@Test
public void shouldUpdate() throws TechnicalException {
PortalNotificationConfig cfg = mock(PortalNotificationConfig.class);
when(cfg.getReferenceType()).thenReturn(NotificationReferenceType.API);
when(cfg.getReferenceId()).thenReturn("123");
when(cfg.getUser()).thenReturn("user");
when(cfg.getHooks()).thenReturn(Arrays.asList("A", "B", "C"));
PortalNotificationConfigEntity cfgEntity = mock(PortalNotificationConfigEntity.class);
when(cfgEntity.getReferenceType()).thenReturn(NotificationReferenceType.API.name());
when(cfgEntity.getReferenceId()).thenReturn("123");
when(cfgEntity.getUser()).thenReturn("user");
when(cfgEntity.getHooks()).thenReturn(Arrays.asList("A", "B", "C"));
when(portalNotificationConfigRepository.findById("user", NotificationReferenceType.API, "123")).thenReturn(of(cfg));
when(portalNotificationConfigRepository.update(any(PortalNotificationConfig.class))).thenReturn(cfg);
final PortalNotificationConfigEntity entity = portalNotificationConfigService.save(cfgEntity);
assertNotNull(entity);
assertEquals("referenceId", cfgEntity.getReferenceId(), entity.getReferenceId());
assertEquals("referenceType", cfgEntity.getReferenceType(), entity.getReferenceType());
assertEquals("user", cfgEntity.getUser(), entity.getUser());
assertEquals("hooks", cfgEntity.getHooks(), entity.getHooks());
verify(portalNotificationConfigRepository, times(1)).findById("user", NotificationReferenceType.API, "123");
verify(portalNotificationConfigRepository, times(1)).update(any());
verify(portalNotificationConfigRepository, never()).delete(any());
verify(portalNotificationConfigRepository, never()).create(any());
}
use of io.gravitee.rest.api.model.notification.PortalNotificationConfigEntity in project gravitee-management-rest-api by gravitee-io.
the class PortalNotificationConfigService_SaveTest method shouldDelete.
@Test
public void shouldDelete() throws TechnicalException {
PortalNotificationConfigEntity cfgEntity = mock(PortalNotificationConfigEntity.class);
when(cfgEntity.getReferenceType()).thenReturn(NotificationReferenceType.API.name());
when(cfgEntity.getReferenceId()).thenReturn("123");
when(cfgEntity.getUser()).thenReturn("user");
when(cfgEntity.getHooks()).thenReturn(Collections.emptyList());
final PortalNotificationConfigEntity entity = portalNotificationConfigService.save(cfgEntity);
assertNotNull(entity);
assertEquals("referenceId", cfgEntity.getReferenceId(), entity.getReferenceId());
assertEquals("referenceType", cfgEntity.getReferenceType(), entity.getReferenceType());
assertEquals("userId", cfgEntity.getUser(), entity.getUser());
assertEquals("hooks", cfgEntity.getHooks(), entity.getHooks());
verify(portalNotificationConfigRepository, never()).findById(any(), any(), any());
verify(portalNotificationConfigRepository, times(1)).delete(any());
}
Aggregations