Search in sources :

Example 1 with ServiceAtomContext

use of won.bot.framework.extensions.serviceatom.ServiceAtomContext in project webofneeds by researchstudio-sat.

the class ServiceAtomCreatedAtomRelationFilter method accept.

@Override
public boolean accept(Event event) {
    BotContextWrapper botContextWrapper = getContext().getBotContextWrapper();
    if (botContextWrapper instanceof ServiceAtomContext && event instanceof MessageEvent) {
        ServiceAtomContext serviceAtomContext = (ServiceAtomContext) botContextWrapper;
        URI serviceAtomUri = serviceAtomContext.getServiceAtomUri();
        if (Objects.nonNull(serviceAtomUri)) {
            MessageEvent messageEvent = (MessageEvent) event;
            WonMessage wonMessage = messageEvent.getWonMessage();
            if (Objects.equals(wonMessage.getRecipientAtomURI(), serviceAtomUri)) {
                URI senderAtomUri = wonMessage.getSenderAtomURI();
                return getContext().getBotContextWrapper().isAtomKnown(senderAtomUri);
            } else if (Objects.equals(wonMessage.getSenderAtomURI(), serviceAtomUri)) {
                URI recipientAtomUri = wonMessage.getRecipientAtomURI();
                return getContext().getBotContextWrapper().isAtomKnown(recipientAtomUri);
            }
            return false;
        }
    }
    return false;
}
Also used : MessageEvent(won.bot.framework.eventbot.event.MessageEvent) WonMessage(won.protocol.message.WonMessage) BotContextWrapper(won.bot.framework.bot.context.BotContextWrapper) URI(java.net.URI) ServiceAtomContext(won.bot.framework.extensions.serviceatom.ServiceAtomContext)

Example 2 with ServiceAtomContext

use of won.bot.framework.extensions.serviceatom.ServiceAtomContext in project webofneeds by researchstudio-sat.

the class ServiceAtomFilter method accept.

@Override
public boolean accept(Event event) {
    BotContextWrapper botContextWrapper = getContext().getBotContextWrapper();
    if (botContextWrapper instanceof ServiceAtomContext) {
        ServiceAtomContext serviceAtomContext = (ServiceAtomContext) botContextWrapper;
        URI serviceAtomUri = serviceAtomContext.getServiceAtomUri();
        if (Objects.nonNull(serviceAtomUri)) {
            if (event instanceof MessageEvent) {
                MessageEvent messageEvent = (MessageEvent) event;
                WonMessage wonMessage = messageEvent.getWonMessage();
                return Objects.equals(wonMessage.getSenderAtomURI(), serviceAtomUri) || Objects.equals(wonMessage.getRecipientAtomURI(), serviceAtomUri);
            }
            boolean accept = false;
            if (event instanceof AtomSpecificEvent) {
                AtomSpecificEvent specificEvent = (AtomSpecificEvent) event;
                accept = Objects.equals(specificEvent.getAtomURI(), serviceAtomUri);
            }
            if (!accept && event instanceof TargetAtomSpecificEvent) {
                TargetAtomSpecificEvent specificEvent = (TargetAtomSpecificEvent) event;
                accept = Objects.equals(specificEvent.getTargetAtomURI(), serviceAtomUri);
            }
            return accept;
        }
    }
    return false;
}
Also used : WonMessage(won.protocol.message.WonMessage) BotContextWrapper(won.bot.framework.bot.context.BotContextWrapper) URI(java.net.URI) ServiceAtomContext(won.bot.framework.extensions.serviceatom.ServiceAtomContext)

Aggregations

URI (java.net.URI)2 BotContextWrapper (won.bot.framework.bot.context.BotContextWrapper)2 ServiceAtomContext (won.bot.framework.extensions.serviceatom.ServiceAtomContext)2 WonMessage (won.protocol.message.WonMessage)2 MessageEvent (won.bot.framework.eventbot.event.MessageEvent)1