Search in sources :

Example 26 with Connection

use of won.protocol.model.Connection in project webofneeds by researchstudio-sat.

the class BAAtomicCCCoordinatorFacetImpl method canFirstPhaseFinish.

private boolean canFirstPhaseFinish(Connection con) {
    List<Connection> listOfCons = getAllCoordinatorParticipantConnections(con);
    URI ownerUri = null;
    URI needUri = null;
    URI currentStateUri = null;
    for (Connection tmpCon : listOfCons) {
        ownerUri = tmpCon.getNeedURI();
        needUri = tmpCon.getRemoteNeedURI();
        currentStateUri = BACCState.parseString(stateManager.getStateForNeedUri(ownerUri, needUri, getFacetType().getURI()).toString()).getURI();
        if (currentStateUri.toString().equals(WON_TX.STATE_ACTIVE.getURI().toString()) || currentStateUri.toString().equals(WON_TX.STATE_COMPLETING.getURI().toString()))
            return false;
    }
    return true;
}
Also used : Connection(won.protocol.model.Connection) URI(java.net.URI)

Example 27 with Connection

use of won.protocol.model.Connection in project webofneeds by researchstudio-sat.

the class BAAtomicCCCoordinatorFacetImpl method propagateSecondPhase.

private void propagateSecondPhase(Connection con) {
    List<Connection> listOfCons = getAllCoordinatorParticipantConnections(con);
    BACCState state;
    for (Connection currentCon : listOfCons) {
        state = BACCState.parseString(stateManager.getStateForNeedUri(currentCon.getNeedURI(), currentCon.getRemoteNeedURI(), getFacetType().getURI()).toString());
        if (state.getPhase() == BACCState.Phase.FIRST) {
            state.setPhase(BACCState.Phase.SECOND);
            stateManager.setStateForNeedUri(state.getURI(), URI.create(WON_TX.PHASE_SECOND.getURI().toString()), currentCon.getNeedURI(), currentCon.getRemoteNeedURI(), getFacetType().getURI());
            storeBAStateForConnection(currentCon, state.getURI());
        }
    }
}
Also used : Connection(won.protocol.model.Connection) BACCState(won.node.facet.businessactivity.coordinatorcompletion.BACCState)

Example 28 with Connection

use of won.protocol.model.Connection in project webofneeds by researchstudio-sat.

the class BAAtomicPCCoordinatorFacetImpl method canFirstPhaseFinish.

private boolean canFirstPhaseFinish(Connection con) {
    List<Connection> listOfCons = getAllCoordinatorParticipantConnections(con);
    URI ownerUri = null;
    URI needUri = null;
    URI currentStateUri = null;
    for (Connection tmpCon : listOfCons) {
        ownerUri = tmpCon.getNeedURI();
        needUri = tmpCon.getRemoteNeedURI();
        currentStateUri = stateManager.getStateForNeedUri(ownerUri, needUri, getFacetType().getURI());
        if (currentStateUri.toString().equals(WON_TX.STATE_ACTIVE.getURI().toString()))
            return false;
    }
    return true;
}
Also used : Connection(won.protocol.model.Connection) URI(java.net.URI)

Example 29 with Connection

use of won.protocol.model.Connection in project webofneeds by researchstudio-sat.

the class BAAtomicPCCoordinatorFacetImpl method propagateSecondPhase.

private void propagateSecondPhase(Connection con) {
    List<Connection> listOfCons = getAllCoordinatorParticipantConnections(con);
    BAPCState state;
    for (Connection currentCon : listOfCons) {
        state = BAPCState.parseString(stateManager.getStateForNeedUri(currentCon.getNeedURI(), currentCon.getRemoteNeedURI(), getFacetType().getURI()).toString());
        BAPCState.Phase phase = BAPCState.parsePhase(stateManager.getStatePhaseForNeedUri(currentCon.getNeedURI(), currentCon.getRemoteNeedURI(), getFacetType().getURI()).toString());
        if (BAPCState.getPhaseURI(phase).toString().equals(WON_TX.PHASE_FIRST.getURI().toString())) {
            state.setPhase(BAPCState.Phase.SECOND);
            stateManager.setStateForNeedUri(state.getURI(), URI.create(WON_TX.PHASE_SECOND.getURI().toString()), currentCon.getNeedURI(), currentCon.getRemoteNeedURI(), getFacetType().getURI());
            storeBAStateForConnection(currentCon, state.getURI());
        }
    }
}
Also used : Connection(won.protocol.model.Connection) BAPCState(won.node.facet.businessactivity.participantcompletion.BAPCState)

Example 30 with Connection

use of won.protocol.model.Connection in project webofneeds by researchstudio-sat.

the class CloseMessageFromSystemProcessor method process.

public void process(final Exchange exchange) throws Exception {
    Message message = exchange.getIn();
    WonMessage wonMessage = (WonMessage) message.getHeader(WonCamelConstants.MESSAGE_HEADER);
    logger.debug("CLOSE received from the system side for connection {}", wonMessage.getSenderURI());
    Connection con = connectionRepository.findOneByConnectionURIForUpdate(wonMessage.getSenderURI());
    ConnectionState originalState = con.getState();
    // TODO: we could introduce SYSTEM_CLOSE here
    con = dataService.nextConnectionState(con, ConnectionEventType.OWNER_CLOSE);
    // if we know the remote connection, send a close message to the remote connection
    if (con.getRemoteConnectionURI() != null) {
        URI remoteNodeURI = wonNodeInformationService.getWonNodeUri(con.getRemoteConnectionURI());
        URI remoteMessageUri = wonNodeInformationService.generateEventURI(remoteNodeURI);
        // put the factory into the outbound message factory header. It will be used to generate the outbound message
        // after the wonMessage has been processed and saved, to make sure that the outbound message contains
        // all the data that we also store locally
        OutboundMessageFactory outboundMessageFactory = new OutboundMessageFactory(remoteMessageUri, con);
        message.setHeader(WonCamelConstants.OUTBOUND_MESSAGE_FACTORY_HEADER, outboundMessageFactory);
        // set the sender uri in the envelope TODO: TwoMsgs: do not set sender here
        wonMessage.addMessageProperty(WONMSG.SENDER_PROPERTY, con.getConnectionURI());
        // add the information about the corresponding message to the local one
        wonMessage.addMessageProperty(WONMSG.HAS_CORRESPONDING_REMOTE_MESSAGE, remoteMessageUri);
    // the persister will pick it up later
    }
// because the FromSystem message is now in the message header, it will be
// picked up by the routing system and delivered to the owner.
// the message for the remote connection is in the outbound message header and will be
// sent to the remote connection.
}
Also used : Message(org.apache.camel.Message) WonMessage(won.protocol.message.WonMessage) WonMessage(won.protocol.message.WonMessage) Connection(won.protocol.model.Connection) ConnectionState(won.protocol.model.ConnectionState) URI(java.net.URI)

Aggregations

Connection (won.protocol.model.Connection)50 URI (java.net.URI)30 WonMessage (won.protocol.message.WonMessage)20 Message (org.apache.camel.Message)12 Model (org.apache.jena.rdf.model.Model)12 EventListenerContext (won.bot.framework.eventbot.EventListenerContext)9 Dataset (org.apache.jena.query.Dataset)6 WonURI (won.bot.framework.eventbot.action.impl.mail.model.WonURI)6 Resource (org.apache.jena.rdf.model.Resource)5 ConnectionMessageCommandEvent (won.bot.framework.eventbot.event.impl.command.connectionmessage.ConnectionMessageCommandEvent)5 MissingMessagePropertyException (won.protocol.message.processor.exception.MissingMessagePropertyException)5 BaseEventBotAction (won.bot.framework.eventbot.action.BaseEventBotAction)4 EventBus (won.bot.framework.eventbot.bus.EventBus)4 Event (won.bot.framework.eventbot.event.Event)4 CloseCommandEvent (won.bot.framework.eventbot.event.impl.command.close.CloseCommandEvent)4 EventListener (won.bot.framework.eventbot.listener.EventListener)4 WonRdfUtils (won.protocol.util.WonRdfUtils)4 Message (org.telegram.telegrambots.api.objects.Message)3 TelegramBotContextWrapper (won.bot.framework.bot.context.TelegramBotContextWrapper)3 BaseNeedAndConnectionSpecificEvent (won.bot.framework.eventbot.event.BaseNeedAndConnectionSpecificEvent)3