use of io.gravitee.rest.api.model.alert.AlertTriggerEntity in project gravitee-management-rest-api by gravitee-io.
the class ApplicationAlertsResource method createApplicationAlert.
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Permissions({ @Permission(value = RolePermission.APPLICATION_ALERT, acls = RolePermissionAction.CREATE) })
public Response createApplicationAlert(@PathParam("applicationId") String applicationId, @Valid @NotNull(message = "Input must not be null.") AlertInput alertInput) {
checkPlugins();
if (applicationAlertService.findByApplication(applicationId).size() == 10) {
throw new ApplicationAlertMaximumException(applicationId, 10);
}
final NewAlertTriggerEntity newAlertTriggerEntity = alertMapper.convert(alertInput);
final AlertTriggerEntity alert = applicationAlertService.create(applicationId, newAlertTriggerEntity);
return Response.created(this.getLocationHeader(alert.getId())).entity(alertMapper.convert(alert)).build();
}
use of io.gravitee.rest.api.model.alert.AlertTriggerEntity in project gravitee-management-rest-api by gravitee-io.
the class ApplicationAlertResource method updateAlert.
@PUT
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Permissions({ @Permission(value = RolePermission.APPLICATION_ALERT, acls = RolePermissionAction.UPDATE) })
public Response updateAlert(@PathParam("applicationId") String applicationId, @PathParam("alertId") String alertId, @Valid @NotNull(message = "Input must not be null.") AlertInput alertInput) {
LOGGER.info("Updating alert {}", alertId);
checkPlugins();
final UpdateAlertTriggerEntity updateAlertTriggerEntity = alertMapper.convertToUpdate(alertInput);
updateAlertTriggerEntity.setId(alertId);
final AlertTriggerEntity updated = applicationAlertService.update(applicationId, updateAlertTriggerEntity);
Alert alert = alertMapper.convert(updated);
return Response.ok(alert).build();
}
use of io.gravitee.rest.api.model.alert.AlertTriggerEntity in project gravitee-management-rest-api by gravitee-io.
the class ApplicationAlertServiceImpl method update.
@Override
public AlertTriggerEntity update(String applicationId, UpdateAlertTriggerEntity alert) {
final AlertTriggerEntity alertTrigger = alertService.findById(alert.getId());
alert.setName(alertTrigger.getName());
alert.setReferenceType(AlertReferenceType.APPLICATION);
alert.setReferenceId(alertTrigger.getReferenceId());
alert.setSource("REQUEST");
alert.setSeverity(Trigger.Severity.INFO);
alert.setDampening(Dampening.strictCount(1));
alert.setNotifications(alertTrigger.getNotifications());
alert.setFilters(alertTrigger.getFilters());
return alertService.update(alert);
}
use of io.gravitee.rest.api.model.alert.AlertTriggerEntity in project gravitee-management-rest-api by gravitee-io.
the class ApplicationAlertServiceTest method shouldNotDeleteMemberMappingError.
@Test(expected = TechnicalManagementException.class)
public void shouldNotDeleteMemberMappingError() throws Exception {
AlertTriggerEntity trigger1 = mock(AlertTriggerEntity.class);
Notification notification = new Notification();
notification.setType("default-email");
notification.setConfiguration("");
when(trigger1.getNotifications()).thenReturn(Collections.singletonList(notification));
List<AlertTriggerEntity> triggers = new ArrayList<>();
triggers.add(trigger1);
when(alertService.findByReference(AlertReferenceType.APPLICATION, APPLICATION_ID)).thenReturn(triggers);
when(mapper.readTree(notification.getConfiguration())).thenThrow(JsonProcessingException.class);
cut.deleteMemberFromApplication(APPLICATION_ID, "delete@mail.gio");
}
use of io.gravitee.rest.api.model.alert.AlertTriggerEntity in project gravitee-management-rest-api by gravitee-io.
the class ApplicationAlertServiceTest method shouldAddMember.
@Test
public void shouldAddMember() throws Exception {
AlertTriggerEntity trigger1 = mock(AlertTriggerEntity.class);
Notification notification = new Notification();
notification.setType("default-email");
notification.setConfiguration("");
Notification notification2 = new Notification();
notification2.setType("default-email");
notification2.setConfiguration("");
when(trigger1.getNotifications()).thenReturn(Collections.singletonList(notification));
AlertTriggerEntity trigger2 = mock(AlertTriggerEntity.class);
when(trigger2.getNotifications()).thenReturn(Collections.singletonList(notification2));
List<AlertTriggerEntity> triggers = new ArrayList<>();
triggers.add(trigger1);
triggers.add(trigger2);
when(alertService.findByReference(AlertReferenceType.APPLICATION, APPLICATION_ID)).thenReturn(triggers);
JsonNode emailNode = JsonNodeFactory.instance.objectNode().put("to", "to").put("from", "from").put("subject", "subject").put("body", "body");
when(mapper.readTree(notification.getConfiguration())).thenReturn(emailNode);
when(mapper.readTree(notification2.getConfiguration())).thenReturn(emailNode);
cut.addMemberToApplication(APPLICATION_ID, "add@mail.gio");
ArgumentCaptor<UpdateAlertTriggerEntity> updatingCaptor = ArgumentCaptor.forClass(UpdateAlertTriggerEntity.class);
verify(alertService, times(2)).update(updatingCaptor.capture());
final UpdateAlertTriggerEntity updating = updatingCaptor.getValue();
assertThat(updating.getNotifications().get(0).getConfiguration()).contains("to,add@mail.gio");
}
Aggregations