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();
}
Aggregations