Search in sources :

Example 6 with EventSubscriber

use of org.ovirt.engine.core.common.businessentities.EventSubscriber in project ovirt-engine by oVirt.

the class UserEventNotifierListModel method manageEvents.

public void manageEvents() {
    EventNotificationModel model = new EventNotificationModel();
    setWindow(model);
    model.setTitle(ConstantsManager.getInstance().getConstants().addEventNotificationTitle());
    model.setHelpTag(HelpTag.add_event_notification);
    // $NON-NLS-1$
    model.setHashName("add_event_notification");
    ArrayList<EventNotificationEntity> eventTypes = ApplicationModeHelper.getModeSpecificEventNotificationTypeList();
    Map<EventNotificationEntity, HashSet<AuditLogType>> availableEvents = AsyncDataProvider.getInstance().getAvailableNotificationEvents();
    Translator translator = EnumTranslator.getInstance();
    ArrayList<SelectionTreeNodeModel> list = new ArrayList<>();
    Collection<EventSubscriber> items = getItems() == null ? new ArrayList<EventSubscriber>() : getItems();
    for (EventNotificationEntity eventType : eventTypes) {
        SelectionTreeNodeModel stnm = new SelectionTreeNodeModel();
        stnm.setTitle(eventType.toString());
        stnm.setDescription(translator.translate(eventType));
        list.add(stnm);
        for (AuditLogType logtype : availableEvents.get(eventType)) {
            SelectionTreeNodeModel eventGrp = new SelectionTreeNodeModel();
            String description;
            try {
                description = translator.translate(logtype);
            } catch (MissingResourceException e) {
                description = logtype.toString();
            }
            eventGrp.setTitle(logtype.toString());
            eventGrp.setDescription(description);
            eventGrp.setParent(list.get(list.size() - 1));
            eventGrp.setIsSelectedNotificationPrevent(true);
            eventGrp.setIsSelectedNullable(false);
            for (EventSubscriber es : items) {
                if (es.getEventUpName().equals(logtype.toString())) {
                    eventGrp.setIsSelectedNullable(true);
                    break;
                }
            }
            list.get(list.size() - 1).getChildren().add(eventGrp);
            eventGrp.setIsSelectedNotificationPrevent(false);
        }
        if (list.get(list.size() - 1).getChildren().size() > 0) {
            list.get(list.size() - 1).getChildren().get(0).updateParentSelection();
        }
    }
    model.setEventGroupModels(list);
    if (!StringHelper.isNullOrEmpty(getEntity().getEmail())) {
        model.getEmail().setEntity(getEntity().getEmail());
    } else if (items.size() > 0) {
        model.getEmail().setEntity(items.iterator().next().getMethodAddress());
    }
    model.setOldEmail(model.getEmail().getEntity());
    // $NON-NLS-1$
    UICommand tempVar = UICommand.createDefaultOkUiCommand("OnSave", this);
    model.getCommands().add(tempVar);
    // $NON-NLS-1$
    UICommand tempVar2 = UICommand.createCancelUiCommand("Cancel", this);
    model.getCommands().add(tempVar2);
}
Also used : SelectionTreeNodeModel(org.ovirt.engine.ui.uicommonweb.models.common.SelectionTreeNodeModel) EventSubscriber(org.ovirt.engine.core.common.businessentities.EventSubscriber) AuditLogType(org.ovirt.engine.core.common.AuditLogType) EventNotificationEntity(org.ovirt.engine.core.common.EventNotificationEntity) MissingResourceException(java.util.MissingResourceException) ArrayList(java.util.ArrayList) EnumTranslator(org.ovirt.engine.ui.uicompat.EnumTranslator) Translator(org.ovirt.engine.ui.uicompat.Translator) UICommand(org.ovirt.engine.ui.uicommonweb.UICommand) HashSet(java.util.HashSet)

Example 7 with EventSubscriber

use of org.ovirt.engine.core.common.businessentities.EventSubscriber in project ovirt-engine by oVirt.

the class GetEventSubscribersBySubscriberIdGroupedQuery method executeQueryCommand.

@Override
protected void executeQueryCommand() {
    List<EventSubscriber> list = eventDao.getAllForSubscriber(getParameters().getId());
    if (list.size() > 0) {
        HashMap<String, EventSubscriber> dic = new HashMap<>();
        for (EventSubscriber ev : list) {
            if (dic.containsKey(ev.getEventUpName())) {
                dic.get(ev.getEventUpName()).setTagName(dic.get(ev.getEventUpName()).getTagName() + ", " + ev.getTagName());
            } else {
                dic.put(ev.getEventUpName(), ev);
            }
        }
        ArrayList<EventSubscriber> groupedList = new ArrayList<>(dic.values());
        for (EventSubscriber event : groupedList) {
            event.setTagName(StringUtils.strip(event.getTagName(), ", "));
        }
        getQueryReturnValue().setReturnValue(groupedList);
    } else {
        getQueryReturnValue().setReturnValue(list);
    }
}
Also used : EventSubscriber(org.ovirt.engine.core.common.businessentities.EventSubscriber) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList)

Example 8 with EventSubscriber

use of org.ovirt.engine.core.common.businessentities.EventSubscriber in project ovirt-engine by oVirt.

the class AddEventSubscriptionCommand method validate.

@Override
protected boolean validate() {
    boolean retValue;
    // check if user is not already subscribed to this event with same
    // method and address
    Guid subscriberId = getParameters().getEventSubscriber().getSubscriberId();
    String eventName = getParameters().getEventSubscriber().getEventUpName();
    EventNotificationMethod eventNotificationMethod = getParameters().getEventSubscriber().getEventNotificationMethod();
    List<EventSubscriber> subscriptions = eventDao.getAllForSubscriber(subscriberId);
    if (isAlreadySubscribed(subscriptions, subscriberId, eventName, eventNotificationMethod)) {
        addValidationMessage(EngineMessage.EN_ALREADY_SUBSCRIBED);
        retValue = false;
    } else if (!eventExists(eventName)) {
        addValidationMessage(EngineMessage.EN_UNSUPPORTED_NOTIFICATION_EVENT);
        retValue = false;
    } else {
        // get notification method
        if (eventNotificationMethod != null) {
            // Validate user
            DbUser user = dbUserDao.get(subscriberId);
            if (user == null) {
                addValidationMessage(EngineMessage.USER_MUST_EXIST_IN_DB);
                retValue = false;
            } else {
                retValue = validateAdd(eventNotificationMethod, getParameters().getEventSubscriber(), user);
            }
        } else {
            addValidationMessage(EngineMessage.EN_UNKNOWN_NOTIFICATION_METHOD);
            retValue = false;
        }
    }
    return retValue;
}
Also used : EventSubscriber(org.ovirt.engine.core.common.businessentities.EventSubscriber) EventNotificationMethod(org.ovirt.engine.core.common.EventNotificationMethod) Guid(org.ovirt.engine.core.compat.Guid) DbUser(org.ovirt.engine.core.common.businessentities.aaa.DbUser)

Aggregations

EventSubscriber (org.ovirt.engine.core.common.businessentities.EventSubscriber)8 ArrayList (java.util.ArrayList)3 Test (org.junit.Test)3 Guid (org.ovirt.engine.core.compat.Guid)2 SelectionTreeNodeModel (org.ovirt.engine.ui.uicommonweb.models.common.SelectionTreeNodeModel)2 Date (java.util.Date)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 MissingResourceException (java.util.MissingResourceException)1 AuditLogType (org.ovirt.engine.core.common.AuditLogType)1 EventNotificationEntity (org.ovirt.engine.core.common.EventNotificationEntity)1 EventNotificationMethod (org.ovirt.engine.core.common.EventNotificationMethod)1 ActionParametersBase (org.ovirt.engine.core.common.action.ActionParametersBase)1 EventSubscriptionParametesBase (org.ovirt.engine.core.common.action.EventSubscriptionParametesBase)1 EventNotificationHist (org.ovirt.engine.core.common.businessentities.EventNotificationHist)1 DbUser (org.ovirt.engine.core.common.businessentities.aaa.DbUser)1 UICommand (org.ovirt.engine.ui.uicommonweb.UICommand)1 EnumTranslator (org.ovirt.engine.ui.uicompat.EnumTranslator)1 Translator (org.ovirt.engine.ui.uicompat.Translator)1