Search in sources :

Example 6 with AlertTriggerEntity

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();
}
Also used : ApplicationAlertMaximumException(io.gravitee.rest.api.service.exceptions.ApplicationAlertMaximumException) NewAlertTriggerEntity(io.gravitee.rest.api.model.alert.NewAlertTriggerEntity) AlertTriggerEntity(io.gravitee.rest.api.model.alert.AlertTriggerEntity) NewAlertTriggerEntity(io.gravitee.rest.api.model.alert.NewAlertTriggerEntity) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) Permissions(io.gravitee.rest.api.portal.rest.security.Permissions)

Example 7 with AlertTriggerEntity

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();
}
Also used : UpdateAlertTriggerEntity(io.gravitee.rest.api.model.alert.UpdateAlertTriggerEntity) Alert(io.gravitee.rest.api.portal.rest.model.Alert) UpdateAlertTriggerEntity(io.gravitee.rest.api.model.alert.UpdateAlertTriggerEntity) AlertTriggerEntity(io.gravitee.rest.api.model.alert.AlertTriggerEntity) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) Permissions(io.gravitee.rest.api.portal.rest.security.Permissions) PUT(javax.ws.rs.PUT)

Example 8 with AlertTriggerEntity

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);
}
Also used : UpdateAlertTriggerEntity(io.gravitee.rest.api.model.alert.UpdateAlertTriggerEntity) NewAlertTriggerEntity(io.gravitee.rest.api.model.alert.NewAlertTriggerEntity) AlertTriggerEntity(io.gravitee.rest.api.model.alert.AlertTriggerEntity)

Example 9 with AlertTriggerEntity

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");
}
Also used : ArrayList(java.util.ArrayList) UpdateAlertTriggerEntity(io.gravitee.rest.api.model.alert.UpdateAlertTriggerEntity) NewAlertTriggerEntity(io.gravitee.rest.api.model.alert.NewAlertTriggerEntity) AlertTriggerEntity(io.gravitee.rest.api.model.alert.AlertTriggerEntity) Notification(io.gravitee.notifier.api.Notification) Test(org.junit.Test)

Example 10 with AlertTriggerEntity

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");
}
Also used : UpdateAlertTriggerEntity(io.gravitee.rest.api.model.alert.UpdateAlertTriggerEntity) ArrayList(java.util.ArrayList) JsonNode(com.fasterxml.jackson.databind.JsonNode) UpdateAlertTriggerEntity(io.gravitee.rest.api.model.alert.UpdateAlertTriggerEntity) NewAlertTriggerEntity(io.gravitee.rest.api.model.alert.NewAlertTriggerEntity) AlertTriggerEntity(io.gravitee.rest.api.model.alert.AlertTriggerEntity) Notification(io.gravitee.notifier.api.Notification) Test(org.junit.Test)

Aggregations

AlertTriggerEntity (io.gravitee.rest.api.model.alert.AlertTriggerEntity)15 NewAlertTriggerEntity (io.gravitee.rest.api.model.alert.NewAlertTriggerEntity)14 UpdateAlertTriggerEntity (io.gravitee.rest.api.model.alert.UpdateAlertTriggerEntity)14 Test (org.junit.Test)12 Notification (io.gravitee.notifier.api.Notification)7 ArrayList (java.util.ArrayList)5 JsonNode (com.fasterxml.jackson.databind.JsonNode)4 Alert (io.gravitee.rest.api.portal.rest.model.Alert)4 SimpleEvent (io.gravitee.common.event.impl.SimpleEvent)3 ApplicationAlertEventType (io.gravitee.rest.api.model.alert.ApplicationAlertEventType)3 ApplicationListItem (io.gravitee.rest.api.model.application.ApplicationListItem)3 NotificationTemplateEntity (io.gravitee.rest.api.model.notification.NotificationTemplateEntity)3 NotificationTemplateEvent (io.gravitee.rest.api.model.notification.NotificationTemplateEvent)3 RateCondition (io.gravitee.alert.api.condition.RateCondition)2 ThresholdRangeCondition (io.gravitee.alert.api.condition.ThresholdRangeCondition)2 Permissions (io.gravitee.rest.api.portal.rest.security.Permissions)2 Consumes (javax.ws.rs.Consumes)2 Produces (javax.ws.rs.Produces)2 AggregationCondition (io.gravitee.alert.api.condition.AggregationCondition)1 ApplicationAlertMaximumException (io.gravitee.rest.api.service.exceptions.ApplicationAlertMaximumException)1