Package org.rhq.core.domain.alert.notification

Examples of org.rhq.core.domain.alert.notification.AlertNotification


        assertEquals("Failed to find the previously created template level alert definition.", 1, foundDefs.size());

        AlertDefinition foundDef = foundDefs.get(0);

        AlertNotification newNotif = createAlertNotificationForTest(foundDef, false);

        AlertTemplateManagerLocal atm = LookupUtil.getAlertTemplateManager();
        atm.updateAlertTemplate(subject, foundDef, true);

        //notice that the validation should be called just once, even though in effect we're creating 11 notifs
View Full Code Here


        return def;
    }

    private AlertNotification createAlertNotificationForTest(AlertDefinition alertDefinition, boolean precanned) {
        AlertNotification notif = new AlertNotification(TestAlertSender.NAME);

        Configuration alertConfig = new Configuration();

        //generate random property so that the notifications are distinguishable from each other
        //and are saved separately
        Random randomGenerator = new Random();
        String randomValue = randomGenerator.nextInt(100) + " - " + randomGenerator.nextInt(200);
        alertConfig.put(new PropertySimple(randomValue, randomValue));

        if (precanned) {
            alertConfig.put(new PropertySimple(TestAlertSender.PERSISTENT_PROPERTY_NAME,
                TestAlertSender.PERSISTEN_PROPERTY_EXPECTED_VALUE));
        } else {
            alertConfig.put(new PropertySimple(TestAlertSender.PERSISTENT_PROPERTY_NAME, "persistent"));
            alertConfig.put(new PropertySimple(TestAlertSender.EPHEMERAL_PROPERTY_NAME, "ephemeral"));
        }

        Configuration extraConfig = new Configuration();

        if (precanned) {
            extraConfig.put(new PropertySimple(TestAlertSender.PERSISTENT_PROPERTY_NAME,
                TestAlertSender.PERSISTEN_PROPERTY_EXPECTED_VALUE));
        } else {
            extraConfig.put(new PropertySimple(TestAlertSender.PERSISTENT_PROPERTY_NAME, "persistent"));
            extraConfig.put(new PropertySimple(TestAlertSender.EPHEMERAL_PROPERTY_NAME, "ephemeral"));
        }

        notif.setConfiguration(alertConfig);
        notif.setExtraConfiguration(extraConfig);

        alertDefinition.addAlertNotification(notif);
        notif.setAlertDefinition(alertDefinition);

        return notif;
    }
View Full Code Here

        // check if the sender by name exists
        AlertSenderPluginManager pluginManager = alertManager.getAlertPluginManager();

        for (AlertNotificationRest anr : adr.getNotifications()) {

            AlertNotification notification = notificationRestToNotification(alertDefinition, anr);

            notifications.add(notification);
        }

        alertDefinition.setAlertNotifications(notifications);
View Full Code Here

        alertDefinition.setAlertDampening(dampening);
    }

    private AlertNotification notificationRestToNotification(AlertDefinition alertDefinition,
                                                             AlertNotificationRest anr) {
        AlertNotification notification = new AlertNotification(anr.getSenderName());
        if (notificationMgr.getAlertInfoForSender(anr.getSenderName()) == null) {
            throw new StuffNotFoundException("AlertSender with name [" + anr.getSenderName() + "]");
        }
        notification.setAlertDefinition(alertDefinition);
        notification.setConfiguration(ConfigurationHelper.mapToConfiguration(anr.getConfig()));
        notification.setExtraConfiguration(ConfigurationHelper.mapToConfiguration(anr.getExtraConfig()));
        return notification;
    }
View Full Code Here

    @ApiOperation("Return a notification definition by its id")
    @ApiError(code = 404, reason = "No notification with the passed id found")
    public Response getNotification(
        @ApiParam("The id of the notification definition to retrieve") @PathParam("nid") int notificationId) {

        AlertNotification notification = notificationMgr.getAlertNotification(caller,notificationId);
        if (notification==null) {
            throw new StuffNotFoundException("No notification with id " + notificationId);
        }
        AlertNotificationRest anr = notificationToNotificationRest(notification);
View Full Code Here

    })
    public Response deleteNotification(
        @ApiParam("The id of the notification definition to remove") @PathParam("nid") int notificationId,
        @ApiParam("Validate if the notification exists") @QueryParam("validate") @DefaultValue("false") boolean validate) {

        AlertNotification notification = notificationMgr.getAlertNotification(caller,notificationId);
        if (notification!=null) {
            AlertDefinition definition = alertDefinitionManager.getAlertDefinition(caller,notification.getAlertDefinition().getId());

            definition.getAlertNotifications().remove(notification);

            alertDefinitionManager.updateAlertDefinitionInternal(caller,definition.getId(),definition,true,true,true);
View Full Code Here

    @ApiError(code = 404, reason = "There is no notification with the passed id")
    public Response updateNotification(
        @ApiParam("The id of the notification definition to update") @PathParam("nid") int notificationId,
        @ApiParam("The updated notification definition to use") AlertNotificationRest notificationRest) {

        AlertNotification notification = notificationMgr.getAlertNotification(caller,notificationId);
        if (notification==null) {
            throw new StuffNotFoundException("No notification with id " + notificationId);
        }

        AlertDefinition definition = alertDefinitionManager.getAlertDefinition(caller,notification.getAlertDefinition().getId());

        AlertNotification newNotif = notificationRestToNotification(definition,notificationRest);
        notification.setConfiguration(newNotif.getConfiguration());
        notification.setExtraConfiguration(newNotif.getExtraConfiguration());
        // id and sender need to stay the same

        alertDefinitionManager.updateAlertDefinitionInternal(caller,definition.getId(),definition,true,true,true);
        entityManager.flush();

        List<AlertNotification> notifications = definition.getAlertNotifications();
        int newNotifId = 0;
        for (AlertNotification n : notifications) {
            if (n.getSenderName().equals(notification.getSenderName())) {
                newNotifId = n.getId();
            }
        }

        AlertNotification result = notificationMgr.getAlertNotification(caller,newNotifId);
        AlertNotificationRest resultRest = notificationToNotificationRest(result);

        return Response.ok(resultRest).build(); // TODO
    }
View Full Code Here

        AlertDefinition definition = alertDefinitionManager.getAlertDefinition(caller,definitionId);
        if (definition==null) {
            throw new StuffNotFoundException("AlertDefinition with id " + definitionId);
        }

        AlertNotification notification = notificationRestToNotification(definition, notificationRest);

        // definition and sender are valid, continue
        int existingNotificationCount = definition.getAlertNotifications().size();

//        notification.setAlertDefinition(definition); setting this will result in duplicated notifications
        definition.addAlertNotification(notification);

        alertDefinitionManager.updateAlertDefinitionInternal(caller, definitionId, definition, false, true, true);


        alertDefinitionManager.getAlertDefinition(caller,definitionId);

        entityManager.flush();

        AlertDefinition updatedDefinition = alertDefinitionManager.getAlertDefinitionById(caller,definitionId);

        List<AlertNotification> notifs = updatedDefinition.getAlertNotifications();

        assert notifs.size() == existingNotificationCount +1;

        AlertNotification updatedNotification = notifs.get(existingNotificationCount);
        AlertNotificationRest updatedNotificationRest = notificationToNotificationRest(updatedNotification);

        int notificationId = updatedNotification.getId();

        UriBuilder uriBuilder = uriInfo.getBaseUriBuilder();
        uriBuilder.path("/alert/notification/{nid}");
        URI uri = uriBuilder.build(notificationId );
View Full Code Here

                @Override
                public void onDoubleClick(DoubleClickEvent event) {
                    ListGrid listGrid = (ListGrid) event.getSource();
                    ListGridRecord[] selectedRows = listGrid.getSelectedRecords();
                    if (selectedRows != null && selectedRows.length == 1) {
                        AlertNotification notif = (getDataSource()).copyValues(selectedRows[0]);
                        popupNotificationEditor(notif);
                    }
                }
            });

            addTableAction(MSG.common_button_add(), null, ButtonColor.BLUE, new AbstractTableAction() {
                @Override
                public void executeAction(ListGridRecord[] selection, Object actionValue) {
                    popupNotificationEditor(null);
                }
            });

            addTableAction(MSG.common_button_delete(), MSG.view_alert_definition_notification_editor_delete_confirm(),
                ButtonColor.RED, new AbstractTableAction(TableActionEnablement.ANY) {
                    @Override
                    public void executeAction(ListGridRecord[] selection, Object actionValue) {
                        for (ListGridRecord record : selection) {
                            AlertNotification notif = (getDataSource()).copyValues(record);
                            notifications.remove(notif);
                        }
                        table.refresh();
                    }
                });
View Full Code Here

        return null;
    }

    public String getAsString(FacesContext context, UIComponent component, Object notificationObject) {
        AlertNotification notification = (AlertNotification) notificationObject;

        return Integer.toString(notification.getId());
    }
View Full Code Here

TOP

Related Classes of org.rhq.core.domain.alert.notification.AlertNotification

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.