Search in sources :

Example 1 with EventNotificationMethod

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

the class RemoveEventSubscriptionCommand method validate.

@Override
protected boolean validate() {
    boolean retValue;
    // get notification method
    EventNotificationMethod event_notification_method = getParameters().getEventSubscriber().getEventNotificationMethod();
    if (event_notification_method != null) {
        // Validate user
        DbUser user = dbUserDao.get(getParameters().getEventSubscriber().getSubscriberId());
        if (user == null) {
            addValidationMessage(EngineMessage.USER_MUST_EXIST_IN_DB);
            retValue = false;
        } else {
            retValue = validateRemove(event_notification_method, getParameters().getEventSubscriber(), user);
        }
    } else {
        addValidationMessage(EngineMessage.EN_UNKNOWN_NOTIFICATION_METHOD);
        retValue = false;
    }
    return retValue;
}
Also used : EventNotificationMethod(org.ovirt.engine.core.common.EventNotificationMethod) DbUser(org.ovirt.engine.core.common.businessentities.aaa.DbUser)

Example 2 with EventNotificationMethod

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

Example 3 with EventNotificationMethod

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

the class EventSubscriptionCommandBase method validateNotificationMethod.

/**
 * Validates the notification method.
 *
 * @param eventNotificationMethod
 *            The eventNotificationMethods.
 * @param eventSubscriber
 *            The eventSubscriber.
 * @param user
 *            The user.
 */
protected boolean validateNotificationMethod(EventNotificationMethod eventNotificationMethod, EventSubscriber eventSubscriber, DbUser user) {
    boolean retValue = true;
    EventNotificationMethod notificationMethod = eventNotificationMethod;
    switch(notificationMethod) {
        case SMTP:
            String mailAddress = StringUtils.isEmpty(eventSubscriber.getMethodAddress()) ? user.getEmail() : eventSubscriber.getMethodAddress();
            if (!isEmailValid(mailAddress)) {
                addValidationMessage(EngineMessage.USER_DOES_NOT_HAVE_A_VALID_EMAIL);
                retValue = false;
            }
            break;
        default:
            addValidationMessage(EngineMessage.EN_UNKNOWN_NOTIFICATION_METHOD);
            retValue = false;
            break;
    }
    return retValue;
}
Also used : EventNotificationMethod(org.ovirt.engine.core.common.EventNotificationMethod)

Aggregations

EventNotificationMethod (org.ovirt.engine.core.common.EventNotificationMethod)3 DbUser (org.ovirt.engine.core.common.businessentities.aaa.DbUser)2 EventSubscriber (org.ovirt.engine.core.common.businessentities.EventSubscriber)1 Guid (org.ovirt.engine.core.compat.Guid)1