Package org.rhq.core.domain.alert

Examples of org.rhq.core.domain.alert.AlertDefinition


            @Override
            public void onDoubleClick(DoubleClickEvent event) {
                ListGrid lg = (ListGrid) event.getSource();
                ListGridRecord selected = lg.getSelectedRecord();
                if (selected != null) {
                    AlertDefinition alertDef = getDataSource().copyValues(selected);
                    int resourceId = alertDef.getResource().getId();
                    int alertDefId = alertDef.getId();
                    String link = LinkManager.getSubsystemAlertDefinitionLink(resourceId, alertDefId);
                    CoreGUI.goToView(link);
                }
            }
        });
View Full Code Here


                    field.setHidden(true);
                } else if (fieldName.equals(FIELD_NAME)) {
                    field.setCellFormatter(new CellFormatter() {
                        @Override
                        public String format(Object value, ListGridRecord record, int rowNum, int colNum) {
                            AlertDefinition alertDef = copyValues(record);
                            int resourceId = alertDef.getResource().getId();
                            int alertDefId = alertDef.getId();
                            String link = LinkManager.getSubsystemAlertDefinitionLink(resourceId, alertDefId);
                            return "<a href=\"" + link + "\">" + StringUtility.escapeHtml(alertDef.getName()) + "</a>";
                        }
                    });
                }
            }

            // add more columns
            ListGridField parentField = new ListGridField(FIELD_PARENT, MSG.view_alerts_field_parent());
            parentField.setWidth(100);
            parentField.setShowHover(true);
            parentField.setHoverCustomizer(new HoverCustomizer() {
                @Override
                public String hoverHTML(Object value, ListGridRecord record, int rowNum, int colNum) {
                    if (record.getAttribute(FIELD_PARENT) != null) {
                        return MSG.view_reports_alertDefinitions_parentHover();
                    }
                    return MSG.common_val_na();
                }
            });
            parentField.addRecordClickHandler(new RecordClickHandler() {
                @Override
                public void onRecordClick(RecordClickEvent event) {
                    // we only do something if we really have a parent.
                    // if we have a template parent, we have to get the resource's type and go to the template page for that type
                    // if we have a group parent, we can directly go to the group's alert def page
                    Record record = event.getRecord();
                    AlertDefinition alertDef = copyValues(record);
                    if (alertDef.getParentId() != null && alertDef.getParentId().intValue() > 0) {
                        final Integer templateId = alertDef.getParentId().intValue();
                        final Integer resourceId = alertDef.getResource().getId();

                        ResourceCriteria resCriteria = new ResourceCriteria();
                        resCriteria.addFilterId(resourceId);
                        resCriteria.fetchResourceType(true);

                        GWTServiceLookup.getResourceService().findResourcesByCriteria(resCriteria,
                            new AsyncCallback<PageList<Resource>>() {
                                @Override
                                public void onSuccess(PageList<Resource> result) {
                                    if (result == null || result.size() != 1) {
                                        CoreGUI.getErrorHandler().handleError(
                                            MSG.view_reports_alertDefinitions_resTypeLoadError());
                                    } else {
                                        int typeId = result.get(0).getResourceType().getId();
                                        CoreGUI.goToView(LinkManager.getAdminTemplatesEditLink(
                                            AlertDefinitionTemplateTypeView.VIEW_ID.getName(), typeId)
                                            + "/"
                                            + templateId);
                                    }
                                }

                                @Override
                                public void onFailure(Throwable caught) {
                                    CoreGUI.getErrorHandler().handleError(
                                        MSG.view_reports_alertDefinitions_resTypeLoadError(), caught);
                                }
                            });

                    } else if (alertDef.getParentId() != null && alertDef.getParentId() == 0) {
                        // handle "View Group Definition"
                        int resourceId = alertDef.getResource().getId();
                        int alertDefId = alertDef.getId();
                        CoreGUI.goToView(LinkManager.getSubsystemAlertDefinitionLink(resourceId, alertDefId));
                    } else if (alertDef.getGroupAlertDefinition() != null) {
                        AlertDefinition groupAlertDef = alertDef.getGroupAlertDefinition();
                        CoreGUI.goToView(LinkManager.getEntityTabLink(EntityContext.forGroup(groupAlertDef.getGroup()),
                            "Alert", "Definitions") + "/" + groupAlertDef.getId());
                    }

                }
            });
            fields.add(parentField);
View Full Code Here

            Resource resource = from.getResource();

            record.setAttribute(FIELD_RESOURCE, resource.getName());

            Integer parentId = from.getParentId(); // a valid non-zero number means the alert def came from a template
            AlertDefinition groupAlertDefinition = from.getGroupAlertDefinition();

            if (parentId != null && parentId.intValue() > 0) {
                record.setAttribute(FIELD_PARENT, "<b>" + MSG.view_alert_definition_for_type() + "</b>");
            } else if (groupAlertDefinition != null) {
                record.setAttribute(FIELD_PARENT, "<b>" + MSG.view_alert_definition_for_group() + "</b>");
View Full Code Here

    }

    @Override
    protected void commitAlertDefinition(final AlertDefinition alertDefinition, boolean purgeInternals,
        final AsyncCallback<AlertDefinition> resultReceiver) {
        AlertDefinition newAlertDefinition = new AlertDefinition(alertDefinition);
        newAlertDefinition.setId(alertDefinition.getId());
        newAlertDefinition.setResource(null); // this was causing the serialization issues in GWT 2.5.0 (bz1058318)
        // the 3 lines above can go away after update to >= GWT 2.6.0 rc3

        if (newAlertDefinition.getId() == 0) {
            Log.info("calling createAlertDefinition()");
            GWTServiceLookup.getAlertDefinitionService().createAlertDefinition(newAlertDefinition,
                Integer.valueOf(resource.getId()), new AsyncCallback<AlertDefinition>() {
                    @Override
                    public void onSuccess(AlertDefinition result) {
View Full Code Here

    }

    @Override
    protected void commitAlertDefinition(final AlertDefinition alertDefinition, boolean purgeInternals,
        final AsyncCallback<AlertDefinition> resultReceiver) {
        AlertDefinition newAlertDefinition = new AlertDefinition(alertDefinition);
        newAlertDefinition.setId(alertDefinition.getId());
        newAlertDefinition.setResource(null);
        newAlertDefinition.setGroup(null); // this was causing the serialization issues in GWT 2.5.0 (bz1058318)
        // the 3 lines above can go away after update to >= GWT 2.6.0 rc3
        if (alertDefinition.getId() == 0) {
            GWTServiceLookup.getGroupAlertDefinitionService().createGroupAlertDefinitions(alertDefinition,
                Integer.valueOf(this.group.getId()), new AsyncCallback<Integer>() {
                    @Override
View Full Code Here

        junk.addAll(foundAlertDefs);

        assertEquals("The new resource should have an alert definition obtained from the template.", 1,
            foundAlertDefs.size());

        AlertDefinition defWithNotifications = foundAlertDefs.get(0);

        testSingleDependentAlertDefinition(defWithNotifications, ParentType.TEMPLATE,
            defWithNotifications.getParentId());
    }
View Full Code Here

    @ApiError(code = 404, reason = "No definition found with the passed id.")
    public Response getAlertDefinition(@ApiParam("Id of the alert definition to retrieve") @PathParam("id") int definitionId,
                                       @ApiParam("Should conditions and notifications be returned too?") @QueryParam("full") @DefaultValue("true") boolean full,
            @Context Request request, @Context UriInfo uriInfo) {

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

        EntityTag eTag = new EntityTag(Integer.toHexString(def.hashCode()));
        Response.ResponseBuilder builder = request.evaluatePreconditions(eTag);
        if (builder==null) {
            AlertDefinitionRest adr = definitionToDomain(def, full, uriInfo);
            builder = Response.ok(adr);
        }
View Full Code Here

        //1 from the group, 1 from the template
        assertEquals("The new resource should have an alert definition obtained from the group.", 2,
            foundAlertDefs.size());

        AlertDefinition groupOriginatingDef = null;
        for (AlertDefinition d : foundAlertDefs) {
            if ((universalName + ":group").equals(d.getName())) {
                groupOriginatingDef = d;
                break;
            }
        }

        assertNotNull("The alert definition originating from the group not present on the resource.",
            groupOriginatingDef);

        testSingleDependentAlertDefinition(groupOriginatingDef, ParentType.GROUP, groupOriginatingDef
            .getGroupAlertDefinition().getId());
    }
View Full Code Here

        if (i!=1) {
            throw new BadArgumentException("query param","You must give exactly one query param out of 'resourceId', 'groupId' or 'resourceTypeId'");
        }

        AlertDefinition alertDefinition = new AlertDefinition();
        alertDefinition.setName(adr.getName());
        alertDefinition.setEnabled(adr.isEnabled());
        if (adr.getPriority()==null) {
            adr.setPriority("LOW");
        }
        alertDefinition.setPriority(AlertPriority.valueOf(adr.getPriority().toUpperCase()));
        alertDefinition.setConditionExpression(BooleanExpression.valueOf(adr.getConditionMode().toUpperCase()));
        alertDefinition.setRecoveryId(adr.getRecoveryId());

        Resource resource = null;
        if (resourceId!= null) {
            resource = fetchResource(resourceId);
        }

        ResourceType resourceType=null;
        if (groupId!=null) {
            ResourceGroup group = resourceGroupMgr.getResourceGroup(caller,groupId);
            alertDefinition.setGroup(group);
            if (group.getGroupCategory()== GroupCategory.MIXED) {
                throw new BadArgumentException("Group with id " + +groupId + " is a mixed group");
            }
            resourceType = group.getResourceType(); // TODO this may be null -> check 1st resource
        }

        if (resourceTypeId!=null) {
            resourceType = resourceTypeMgr.getResourceTypeById(caller,resourceTypeId);
            alertDefinition.setResourceType(resourceType);
        }

        Set<AlertCondition> conditions = new HashSet<AlertCondition>(adr.getConditions().size());
        for (AlertConditionRest acr : adr.getConditions()) {
            AlertCondition condition = conditionRestToCondition(acr, resource, resourceType);
            conditions.add(condition);
        }
        alertDefinition.setConditions(conditions);

        List<AlertNotification> notifications = new ArrayList<AlertNotification>(adr.getNotifications().size());
        // 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);
        setDampeningFromRest(alertDefinition, adr);

        // Set the recovery id if such a definition exists at all
        if (adr.getRecoveryId()>0) {
            AlertDefinition recoveryDef = alertDefinitionManager.getAlertDefinition(caller,adr.getRecoveryId());
            if (recoveryDef!=null)
                alertDefinition.setRecoveryId(adr.getRecoveryId());
            else
                throw new StuffNotFoundException("Recovery alert with id " + adr.getRecoveryId());
        }

        AlertDefinition updatedDefinition = alertDefinitionManager.createAlertDefinitionInNewTransaction(caller,
            alertDefinition, resourceId, false);
        int definitionId = updatedDefinition.getId();
        AlertDefinitionRest uadr = definitionToDomain(updatedDefinition,true, uriInfo) ; // TODO param 'full' ?

        uadr.setId(definitionId);

        UriBuilder uriBuilder = uriInfo.getBaseUriBuilder();
View Full Code Here

        AlertDefinitionManagerLocal adm = LookupUtil.getAlertDefinitionManager();

        Resource res = resources.iterator().next();

        AlertDefinition def = createDefinitionForTest("testCorrectSubjectPassedOnResourceLevelAlertDef", false);
        def.setResource(res);

        def = adm.createAlertDefinitionInNewTransaction(subject, def, res.getId(), true);

        resourceLevelAlertDefinitionId = def.getId();

        junk.add(def);

        testMainAlertDefinition(resourceLevelAlertDefinitionId);
    }
View Full Code Here

TOP

Related Classes of org.rhq.core.domain.alert.AlertDefinition

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.