use of io.gravitee.am.model.common.event.Payload in project gravitee-access-management by gravitee-io.
the class AlertTriggerManager method onAlertNotifierEvent.
void onAlertNotifierEvent(Event<AlertNotifierEvent, ?> event) {
LOGGER.debug("Received alert notifier event {}", event);
final Payload payload = (Payload) event.content();
final AlertTriggerCriteria alertTriggerCriteria = new AlertTriggerCriteria();
alertTriggerCriteria.setEnabled(true);
alertTriggerCriteria.setAlertNotifierIds(Collections.singletonList(payload.getId()));
domainService.findById(payload.getReferenceId()).filter(domain -> domain.isEnabled() && domain.isAlertEnabled()).flatMapPublisher(domain -> this.alertTriggerService.findByDomainAndCriteria(domain.getId(), alertTriggerCriteria).flatMapSingle(alertTrigger -> prepareAETrigger(domain, alertTrigger)).flatMapSingle(this::registerAETrigger)).count().subscribe(count -> LOGGER.info("{} alert triggers synchronized with the alerting system for domain [{}] after the update of alert notifier [{}].", count, payload.getReferenceId(), payload.getId()), throwable -> LOGGER.error("An error occurred when trying to synchronize alert triggers with alerting system for domain [{}] after the alert notifier {} event [{}].", payload.getReferenceId(), event.type().name().toLowerCase(), payload.getId(), throwable));
}
use of io.gravitee.am.model.common.event.Payload in project gravitee-access-management by gravitee-io.
the class SyncManagerTest method test_twiceWithTwoDomains_domainToRemove.
@Test
public void test_twiceWithTwoDomains_domainToRemove() throws Exception {
final Domain domain = new Domain();
domain.setId("domain-1");
domain.setReferenceId("env-1");
domain.setEnabled(true);
when(domainRepository.findAll()).thenReturn(Flowable.just(domain));
syncManager.refresh();
Event event = new Event();
event.setType(Type.DOMAIN);
event.setPayload(new Payload("domain-1", ReferenceType.DOMAIN, "domain-1", Action.DELETE));
when(eventRepository.findByTimeFrame(any(Long.class), any(Long.class))).thenReturn(Flowable.just(event));
syncManager.refresh();
verify(securityDomainManager, times(1)).deploy(any());
verify(securityDomainManager, never()).update(any());
verify(securityDomainManager, times(1)).undeploy(domain.getId());
}
use of io.gravitee.am.model.common.event.Payload in project gravitee-access-management by gravitee-io.
the class SyncManagerTest method test_twiceWithTwoDomains_domainToUpdate.
@Test
public void test_twiceWithTwoDomains_domainToUpdate() throws Exception {
final Domain domain = new Domain();
domain.setId("domain-1");
domain.setReferenceId("env-1");
domain.setEnabled(true);
domain.setUpdatedAt(new Date(System.currentTimeMillis() - 60 * 1000));
when(domainRepository.findAll()).thenReturn(Flowable.just(domain));
syncManager.refresh();
Event event = new Event();
event.setType(Type.DOMAIN);
event.setPayload(new Payload("domain-1", ReferenceType.DOMAIN, "domain-1", Action.UPDATE));
final Domain domainToUpdate = new Domain();
domainToUpdate.setId("domain-1");
domainToUpdate.setReferenceId("env-1");
domainToUpdate.setEnabled(true);
domainToUpdate.setUpdatedAt(new Date());
when(eventRepository.findByTimeFrame(any(Long.class), any(Long.class))).thenReturn(Flowable.just(event));
when(domainRepository.findById(domainToUpdate.getId())).thenReturn(Maybe.just(domainToUpdate));
when(securityDomainManager.get(domainToUpdate.getId())).thenReturn(domain);
syncManager.refresh();
verify(securityDomainManager, times(1)).deploy(any());
verify(securityDomainManager, times(1)).update(any());
verify(securityDomainManager, never()).undeploy(domain.getId());
}
use of io.gravitee.am.model.common.event.Payload in project gravitee-access-management by gravitee-io.
the class SyncManagerTest method shouldPropagateEvents.
@Test
public void shouldPropagateEvents() {
when(domainRepository.findAll()).thenReturn(Flowable.empty());
syncManager.refresh();
Event event = new Event();
event.setType(Type.IDENTITY_PROVIDER);
event.setPayload(new Payload("idp-1", ReferenceType.DOMAIN, "domain-1", Action.UPDATE));
when(eventRepository.findByTimeFrame(any(Long.class), any(Long.class))).thenReturn(Flowable.just(event));
syncManager.refresh();
verify(eventManager, times(1)).publishEvent(any(), any());
verify(securityDomainManager, never()).deploy(any(Domain.class));
verify(securityDomainManager, never()).update(any(Domain.class));
verify(securityDomainManager, never()).undeploy(any(String.class));
}
use of io.gravitee.am.model.common.event.Payload in project gravitee-access-management by gravitee-io.
the class MongoEventRepository method convert.
private Payload convert(Document document) {
if (document == null) {
return null;
}
Payload content = new Payload(document.get("content", Map.class));
content.put("action", Action.valueOf((String) content.get("action")));
return content;
}
Aggregations