Search in sources :

Example 1 with EventSubscriber

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

the class EventDaoTest method testGetAllForSubscriber.

/**
 * Ensures that all subscriptions are returned.
 */
@Test
public void testGetAllForSubscriber() {
    List<EventSubscriber> result = dao.getAllForSubscriber(existingSubscriber);
    assertNotNull(result);
    assertFalse(result.isEmpty());
    for (EventSubscriber subscription : result) {
        assertEquals(existingSubscriber, subscription.getSubscriberId());
    }
}
Also used : EventSubscriber(org.ovirt.engine.core.common.businessentities.EventSubscriber) Test(org.junit.Test)

Example 2 with EventSubscriber

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

the class EventDaoTest method setUp.

@Override
public void setUp() throws Exception {
    super.setUp();
    dao = dbFacade.getEventDao();
    existingSubscriber = new Guid("9bf7c640-b620-456f-a550-0348f366544a");
    newSubscriber = new Guid("9bf7c640-b620-456f-a550-0348f366544b");
    newSubscription = new EventSubscriber();
    newSubscription.setSubscriberId(newSubscriber);
    newSubscription.setEventNotificationMethod(EventNotificationMethod.SMTP);
    newSubscription.setEventUpName("TestRun");
    newSubscription.setTagName("farkle");
    newHistory = new EventNotificationHist();
    newHistory.setAuditLogId(FREE_AUDIT_LOG_ID);
    newHistory.setEventName("Failure");
    newHistory.setMethodType("Email");
    newHistory.setReason("Dunno");
    newHistory.setSentAt(new Date());
    newHistory.setStatus(false);
    newHistory.setSubscriberId(existingSubscriber);
}
Also used : EventSubscriber(org.ovirt.engine.core.common.businessentities.EventSubscriber) EventNotificationHist(org.ovirt.engine.core.common.businessentities.EventNotificationHist) Guid(org.ovirt.engine.core.compat.Guid) Date(java.util.Date)

Example 3 with EventSubscriber

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

the class EventDaoTest method testSubscribe.

/**
 * Ensures that subscribing a user works as expected.
 */
@Test
public void testSubscribe() {
    dao.subscribe(newSubscription);
    List<EventSubscriber> result = dao.getAllForSubscriber(newSubscription.getSubscriberId());
    assertNotNull(result);
    assertFalse(result.isEmpty());
    for (EventSubscriber subscription : result) {
        assertEquals(newSubscriber, subscription.getSubscriberId());
    }
}
Also used : EventSubscriber(org.ovirt.engine.core.common.businessentities.EventSubscriber) Test(org.junit.Test)

Example 4 with EventSubscriber

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

the class EventDaoTest method testUnsubscribe.

/**
 * Ensures that unsubscribing a user works as expected.
 */
@Test
public void testUnsubscribe() {
    List<EventSubscriber> before = dao.getAllForSubscriber(existingSubscriber);
    // ensure we have subscriptions
    assertFalse(before.isEmpty());
    for (EventSubscriber subscriber : before) {
        dao.unsubscribe(subscriber);
    }
    List<EventSubscriber> after = dao.getAllForSubscriber(existingSubscriber);
    assertNotNull(after);
    assertTrue(after.isEmpty());
}
Also used : EventSubscriber(org.ovirt.engine.core.common.businessentities.EventSubscriber) Test(org.junit.Test)

Example 5 with EventSubscriber

use of org.ovirt.engine.core.common.businessentities.EventSubscriber 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

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