Search in sources :

Example 1 with EventSubscriptionParametesBase

use of org.ovirt.engine.core.common.action.EventSubscriptionParametesBase in project ovirt-engine by oVirt.

the class UserEventNotifierListModel method onSave.

public void onSave() {
    EventNotificationModel model = (EventNotificationModel) getWindow();
    if (!model.validate()) {
        return;
    }
    ArrayList<ActionParametersBase> toAddList = new ArrayList<>();
    ArrayList<ActionParametersBase> toRemoveList = new ArrayList<>();
    // var selected = model.EventGroupModels.SelectMany(a => a.Children).Where(a => a.IsSelected == true);
    ArrayList<SelectionTreeNodeModel> selected = new ArrayList<>();
    for (SelectionTreeNodeModel node : model.getEventGroupModels()) {
        for (SelectionTreeNodeModel child : node.getChildren()) {
            if (child.getIsSelectedNullable() != null && child.getIsSelectedNullable().equals(true)) {
                selected.add(child);
            }
        }
    }
    Collection<EventSubscriber> existing = getItems() != null ? getItems() : new ArrayList<EventSubscriber>();
    ArrayList<SelectionTreeNodeModel> added = new ArrayList<>();
    ArrayList<EventSubscriber> removed = new ArrayList<>();
    // check what has been added:
    for (SelectionTreeNodeModel selectedEvent : selected) {
        boolean selectedInExisting = false;
        for (EventSubscriber existingEvent : existing) {
            if (selectedEvent.getTitle().equals(existingEvent.getEventUpName())) {
                selectedInExisting = true;
                break;
            }
        }
        if (!selectedInExisting) {
            added.add(selectedEvent);
        }
    }
    // check what has been deleted:
    for (EventSubscriber existingEvent : existing) {
        boolean existingInSelected = false;
        for (SelectionTreeNodeModel selectedEvent : selected) {
            if (selectedEvent.getTitle().equals(existingEvent.getEventUpName())) {
                existingInSelected = true;
                break;
            }
        }
        if (!existingInSelected) {
            removed.add(existingEvent);
        }
    }
    if (!StringHelper.isNullOrEmpty(model.getOldEmail()) && !model.getOldEmail().equals(model.getEmail().getEntity())) {
        for (EventSubscriber a : existing) {
            toRemoveList.add(new EventSubscriptionParametesBase(new EventSubscriber(a.getEventUpName(), EventNotificationMethod.SMTP, a.getMethodAddress(), a.getSubscriberId(), ""), // $NON-NLS-1$ //$NON-NLS-2$
            ""));
        }
        for (SelectionTreeNodeModel a : selected) {
            toAddList.add(new EventSubscriptionParametesBase(new EventSubscriber(a.getTitle(), EventNotificationMethod.SMTP, model.getEmail().getEntity(), getEntity().getId(), ""), // $NON-NLS-1$ //$NON-NLS-2$
            ""));
        }
    } else {
        for (SelectionTreeNodeModel a : added) {
            toAddList.add(new EventSubscriptionParametesBase(new EventSubscriber(a.getTitle(), EventNotificationMethod.SMTP, model.getEmail().getEntity(), getEntity().getId(), ""), // $NON-NLS-1$ //$NON-NLS-2$
            ""));
        }
        for (EventSubscriber a : removed) {
            toRemoveList.add(new EventSubscriptionParametesBase(new EventSubscriber(a.getEventUpName(), EventNotificationMethod.SMTP, a.getMethodAddress(), a.getSubscriberId(), ""), // $NON-NLS-1$ //$NON-NLS-2$
            ""));
        }
    }
    if (toRemoveList.size() > 0) {
        EventSubscriptionFrontendActionAsyncCallback callback = new EventSubscriptionFrontendActionAsyncCallback(toAddList, toRemoveList);
        for (ActionParametersBase param : toRemoveList) {
            Frontend.getInstance().runAction(ActionType.RemoveEventSubscription, param, callback);
        }
    } else if (toAddList.size() > 0) {
        Frontend.getInstance().runMultipleAction(ActionType.AddEventSubscription, toAddList);
    }
    cancel();
}
Also used : SelectionTreeNodeModel(org.ovirt.engine.ui.uicommonweb.models.common.SelectionTreeNodeModel) EventSubscriptionParametesBase(org.ovirt.engine.core.common.action.EventSubscriptionParametesBase) EventSubscriber(org.ovirt.engine.core.common.businessentities.EventSubscriber) ArrayList(java.util.ArrayList) ActionParametersBase(org.ovirt.engine.core.common.action.ActionParametersBase)

Aggregations

ArrayList (java.util.ArrayList)1 ActionParametersBase (org.ovirt.engine.core.common.action.ActionParametersBase)1 EventSubscriptionParametesBase (org.ovirt.engine.core.common.action.EventSubscriptionParametesBase)1 EventSubscriber (org.ovirt.engine.core.common.businessentities.EventSubscriber)1 SelectionTreeNodeModel (org.ovirt.engine.ui.uicommonweb.models.common.SelectionTreeNodeModel)1