Search in sources :

Example 11 with NoSuchConnectionException

use of won.protocol.exception.NoSuchConnectionException in project webofneeds by researchstudio-sat.

the class LinkedDataWebController method showConnectionURIListPage.

// webmvc controller method
@RequestMapping("${uri.path.page.connection}")
public String showConnectionURIListPage(@RequestParam(value = "p", required = false) Integer page, @RequestParam(value = "deep", defaultValue = "false") boolean deep, @RequestParam(value = "resumebefore", required = false) String beforeId, @RequestParam(value = "resumeafter", required = false) String afterId, @RequestParam(value = "timeof", required = false) String timestamp, HttpServletRequest request, Model model, HttpServletResponse response) {
    try {
        DateParameter dateParam = new DateParameter(timestamp);
        Dataset rdfDataset;
        if (page != null) {
            rdfDataset = linkedDataService.listConnectionURIs(page, null, dateParam.getDate(), deep).getContent();
        } else if (beforeId != null) {
            URI connURI = uriService.createConnectionURIForId(beforeId);
            rdfDataset = linkedDataService.listConnectionURIsBefore(connURI, null, dateParam.getDate(), deep).getContent();
        } else if (afterId != null) {
            URI connURI = uriService.createConnectionURIForId(afterId);
            rdfDataset = linkedDataService.listConnectionURIsAfter(connURI, null, dateParam.getDate(), deep).getContent();
        } else {
            // all the connections; does not support date filtering for clients that do not
            // support paging
            rdfDataset = linkedDataService.listConnectionURIs(deep);
        }
        model.addAttribute("rdfDataset", rdfDataset);
        model.addAttribute("resourceURI", uriService.toResourceURIIfPossible(URI.create(request.getRequestURI())).toString());
        model.addAttribute("dataURI", uriService.toDataURIIfPossible(URI.create(request.getRequestURI())).toString());
        return "rdfDatasetView";
    } catch (ParseException e) {
        model.addAttribute("error", "could not parse timestamp parameter");
        return "notFoundView";
    } catch (NoSuchConnectionException e) {
        model.addAttribute("error", "could not add connection data for " + e.getUnknownConnectionURI().toString());
        return "notFoundView";
    }
}
Also used : NoSuchConnectionException(won.protocol.exception.NoSuchConnectionException) Dataset(org.apache.jena.query.Dataset) ParseException(java.text.ParseException) URI(java.net.URI) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 12 with NoSuchConnectionException

use of won.protocol.exception.NoSuchConnectionException in project webofneeds by researchstudio-sat.

the class BAAtomicCCCoordinatorFacetImpl method sendMessageFromOwner.

// Coordinator sends message to Participant
public void sendMessageFromOwner(final Connection con, final Model message, final WonMessage wonMessage) throws NoSuchConnectionException, IllegalMessageForConnectionStateException {
    final URI remoteConnectionURI = con.getRemoteConnectionURI();
    // inform the other side
    executorService.execute(new Runnable() {

        @Override
        public void run() {
            try {
                String messageForSending = new String();
                BACCEventType eventType = null;
                Model myContent = null;
                Resource r = null;
                // message (event) for sending
                // message as TEXT
                messageForSending = WonRdfUtils.MessageUtils.getTextMessage(message);
                if (messageForSending != null) {
                    eventType = BACCEventType.getCoordinationEventTypeFromString(messageForSending);
                    logger.debug("Coordinator sends the text message: {}", eventType);
                } else // message as MODEL
                {
                    NodeIterator ni = message.listObjectsOfProperty(message.getProperty(WON_TX.COORDINATION_MESSAGE.getURI().toString()));
                    if (ni.hasNext()) {
                        String eventTypeURI = ni.toList().get(0).asResource().getURI().toString();
                        eventType = BACCEventType.getBAEventTypeFromURI(eventTypeURI);
                        logger.debug("Coordinator sends the RDF: {}", eventType.getURI());
                    } else {
                        logger.debug("Message {} does not contain a proper content.", message.toString());
                        return;
                    }
                }
                myContent = ModelFactory.createDefaultModel();
                myContent.setNsPrefix("", "no:uri");
                Resource baseResource = myContent.createResource("no:uri");
                if ((eventType != null)) {
                    if (eventType.isBACCCoordinatorEventType(eventType)) {
                        if (isCoordinatorInFirstPhase(con) && eventType.getURI().toString().equals(WON_TX.MESSAGE_CLOSE.getURI().toString())) {
                            // if no -> wait for other participants to vote
                            if (canFirstPhaseFinish(con)) {
                                logger.debug("First phase can be finished.");
                                BACCState state = BACCState.parseString(stateManager.getStateForNeedUri(con.getNeedURI(), con.getRemoteNeedURI(), getFacetType().getURI()).toString());
                                logger.debug("Current state of the Coordinator {} for participant {}: ", state.getURI().toString(), con.getRemoteNeedURI().toString());
                                logger.debug("This Coordinator state phase: {}", BACCState.parsePhase(stateManager.getStateForNeedUri(con.getNeedURI(), con.getRemoteNeedURI(), getFacetType().getURI()).toString()));
                                state = state.transit(eventType);
                                // Second phase is starting!
                                state.setPhase(BACCState.Phase.SECOND);
                                stateManager.setStateForNeedUri(state.getURI(), URI.create(WON_TX.PHASE_SECOND.getURI().toString()), con.getNeedURI(), con.getRemoteNeedURI(), getFacetType().getURI());
                                storeBAStateForConnection(con, state.getURI());
                                logger.debug("New state of the Coordinator:" + stateManager.getStateForNeedUri(con.getNeedURI(), con.getRemoteNeedURI(), getFacetType().getURI()));
                                logger.debug("This Coordinator state phase: {}", BACCState.parsePhase(stateManager.getStateForNeedUri(con.getNeedURI(), con.getRemoteNeedURI(), getFacetType().getURI()).toString()));
                                // eventType -> URI Resource
                                r = myContent.createResource(eventType.getURI().toString());
                                baseResource.addProperty(WON_TX.COORDINATION_MESSAGE, r);
                                // TODO: use new system
                                // needFacingConnectionClient.sendMessage(con, myContent, wonMessage);
                                // trigger the second phase in the corresponding states
                                propagateSecondPhase(con);
                            } else {
                                logger.debug("Not all votes are received from Participants!");
                            }
                        } else {
                            BACCState state = BACCState.parseString(stateManager.getStateForNeedUri(con.getNeedURI(), con.getRemoteNeedURI(), getFacetType().getURI()).toString());
                            BACCState newState = null;
                            logger.debug("Current state of the Coordinator {} for participant {}: ", state.getURI().toString(), con.getRemoteNeedURI());
                            logger.debug("This Coordinator state phase: {}", BACCState.parsePhase(stateManager.getStateForNeedUri(con.getNeedURI(), con.getRemoteNeedURI(), getFacetType().getURI()).toString()));
                            newState = state.transit(eventType);
                            BACCState.Phase newPhase;
                            if (!(isCoordinatorInFirstPhase(con) && eventType.getURI().toString().equals(WON_TX.MESSAGE_CANCEL.getURI().toString())))
                                newPhase = BACCState.parsePhase(stateManager.getStatePhaseForNeedUri(con.getNeedURI(), con.getRemoteNeedURI(), getFacetType().getURI()).toString());
                            else
                                // propagate phase,
                                newPhase = BACCState.Phase.CANCELED_FROM_COORDINATOR;
                            newState.setPhase(newPhase);
                            stateManager.setStateForNeedUri(newState.getURI(), BACCState.getPhaseURI(newPhase), con.getNeedURI(), con.getRemoteNeedURI(), getFacetType().getURI());
                            storeBAStateForConnection(con, newState.getURI());
                            logger.debug("New state of the Coordinator:" + stateManager.getStateForNeedUri(con.getNeedURI(), con.getRemoteNeedURI(), getFacetType().getURI()));
                            logger.debug("Coordinator phase: {}", BACCState.parsePhase(stateManager.getStateForNeedUri(con.getNeedURI(), con.getRemoteNeedURI(), getFacetType().getURI()).toString()));
                            // eventType -> URI Resource
                            r = myContent.createResource(eventType.getURI().toString());
                            baseResource.addProperty(WON_TX.COORDINATION_MESSAGE, r);
                        // TODO: use new system
                        // needFacingConnectionClient.sendMessage(con, myContent, wonMessage);
                        }
                    } else {
                        logger.debug("The eventType: " + eventType.getURI().toString() + " can not be triggered by Coordinator.");
                    }
                } else {
                    logger.debug("The event type denoted by " + messageForSending + " is not allowed.");
                }
            } catch (Exception e) {
                logger.debug("caught Exception", e);
            }
        }
    });
}
Also used : BACCEventType(won.node.facet.businessactivity.coordinatorcompletion.BACCEventType) URI(java.net.URI) BACCState(won.node.facet.businessactivity.coordinatorcompletion.BACCState) IllegalMessageForConnectionStateException(won.protocol.exception.IllegalMessageForConnectionStateException) NoSuchConnectionException(won.protocol.exception.NoSuchConnectionException)

Example 13 with NoSuchConnectionException

use of won.protocol.exception.NoSuchConnectionException in project webofneeds by researchstudio-sat.

the class BAAtomicPCCoordinatorFacetImpl method sendMessageFromOwner.

// Coordinator sends message to Participant
public void sendMessageFromOwner(final Connection con, final Model message, final WonMessage wonMessage) throws NoSuchConnectionException, IllegalMessageForConnectionStateException {
    final URI remoteConnectionURI = con.getRemoteConnectionURI();
    // inform the other side
    executorService.execute(new Runnable() {

        @Override
        public void run() {
            try {
                String messageForSending = new String();
                BAPCEventType eventType = null;
                Model myContent = null;
                Resource r = null;
                // message (event) for sending
                // message as TEXT
                messageForSending = WonRdfUtils.MessageUtils.getTextMessage(message);
                if (messageForSending != null) {
                    eventType = BAPCEventType.getCoordinationEventTypeFromString(messageForSending);
                    logger.debug("Coordinator sends the text message:" + eventType + " coordinator:" + con.getNeedURI() + " participant:" + con.getRemoteNeedURI() + " con:" + con.getConnectionURI() + " baState:" + stateManager.getStateForNeedUri(con.getNeedURI(), con.getRemoteNeedURI(), getFacetType().getURI()).toString() + " phase:" + BAPCState.parsePhase(stateManager.getStatePhaseForNeedUri(con.getNeedURI(), con.getRemoteNeedURI(), getFacetType().getURI()).toString()));
                } else // message as MODEL
                {
                    NodeIterator ni = message.listObjectsOfProperty(message.getProperty(WON_TX.COORDINATION_MESSAGE.getURI().toString()));
                    if (ni.hasNext()) {
                        String eventTypeURI = ni.toList().get(0).asResource().getURI().toString();
                        eventType = BAPCEventType.getBAEventTypeFromURI(eventTypeURI);
                        logger.debug("Coordinator sends the RDF message:" + eventType.getURI() + " coordinator:" + con.getNeedURI() + " participant:" + con.getRemoteNeedURI() + " con:" + con.getConnectionURI() + " baState:" + stateManager.getStateForNeedUri(con.getNeedURI(), con.getRemoteNeedURI(), getFacetType().getURI()).toString() + " phase:" + BAPCState.parsePhase(stateManager.getStatePhaseForNeedUri(con.getNeedURI(), con.getRemoteNeedURI(), getFacetType().getURI()).toString()));
                    } else {
                        logger.debug("Message {} does not contain a proper content.", message.toString());
                        return;
                    }
                }
                myContent = ModelFactory.createDefaultModel();
                myContent.setNsPrefix("", "no:uri");
                Resource baseResource = myContent.createResource("no:uri");
                if ((eventType != null)) {
                    if (eventType.isBAPCCoordinatorEventType(eventType)) {
                        if (isCoordinatorInFirstPhase(con) && eventType.getURI().toString().equals(WON_TX.MESSAGE_CLOSE.getURI().toString())) {
                            // if no -> wait for other participants to vote
                            if (canFirstPhaseFinish(con)) {
                                BAPCState state = BAPCState.parseString(stateManager.getStateForNeedUri(con.getNeedURI(), con.getRemoteNeedURI(), getFacetType().getURI()).toString());
                                state = state.transit(eventType);
                                // Second phase is starting!
                                state.setPhase(BAPCState.Phase.SECOND);
                                stateManager.setStateForNeedUri(state.getURI(), URI.create(WON_TX.PHASE_SECOND.getURI().toString()), con.getNeedURI(), con.getRemoteNeedURI(), getFacetType().getURI());
                                storeBAStateForConnection(con, state.getURI());
                                logger.debug("New state = coordinator:" + con.getNeedURI() + " participant:" + con.getRemoteNeedURI() + " con:" + con.getConnectionURI() + " baState:" + stateManager.getStateForNeedUri(con.getNeedURI(), con.getRemoteNeedURI(), getFacetType().getURI()).toString() + " phase:" + BAPCState.parsePhase(stateManager.getStatePhaseForNeedUri(con.getNeedURI(), con.getRemoteNeedURI(), getFacetType().getURI()).toString()));
                                // eventType -> URI Resource
                                r = myContent.createResource(eventType.getURI().toString());
                                baseResource.addProperty(WON_TX.COORDINATION_MESSAGE, r);
                                // TODO: use new system
                                // needFacingConnectionClient.sendMessage(con, myContent, wonMessage);
                                logger.debug("Coordinator sent message to participant");
                                // trigger the second phase in the corresponding states
                                propagateSecondPhase(con);
                            } else {
                                logger.debug("Not all votes are received from Participants! First phase can not finish.");
                            }
                        } else {
                            BAPCState state = BAPCState.parseString(stateManager.getStateForNeedUri(con.getNeedURI(), con.getRemoteNeedURI(), getFacetType().getURI()).toString());
                            BAPCState newState = null;
                            newState = state.transit(eventType);
                            BAPCState.Phase newPhase;
                            if (!(isCoordinatorInFirstPhase(con) && eventType.getURI().toString().equals(WON_TX.MESSAGE_CANCEL.getURI().toString())))
                                newPhase = BAPCState.parsePhase(stateManager.getStatePhaseForNeedUri(con.getNeedURI(), con.getRemoteNeedURI(), getFacetType().getURI()).toString());
                            else
                                // propagate phase,
                                newPhase = BAPCState.Phase.CANCELED_FROM_COORDINATOR;
                            newState.setPhase(newPhase);
                            stateManager.setStateForNeedUri(newState.getURI(), BAPCState.getPhaseURI(newPhase), con.getNeedURI(), con.getRemoteNeedURI(), getFacetType().getURI());
                            storeBAStateForConnection(con, newState.getURI());
                            logger.debug("New state = coordinator:" + con.getNeedURI() + " participant:" + con.getRemoteNeedURI() + " con:" + con.getConnectionURI() + " baState:" + stateManager.getStateForNeedUri(con.getNeedURI(), con.getRemoteNeedURI(), getFacetType().getURI()).toString() + " phase:" + BAPCState.parsePhase(stateManager.getStatePhaseForNeedUri(con.getNeedURI(), con.getRemoteNeedURI(), getFacetType().getURI()).toString()));
                            // eventType -> URI Resource
                            r = myContent.createResource(eventType.getURI().toString());
                            baseResource.addProperty(WON_TX.COORDINATION_MESSAGE, r);
                            // TODO: use new system
                            // needFacingConnectionClient.sendMessage(con, myContent, wonMessage);
                            logger.debug("Coordinator sent message to participant");
                        }
                    } else {
                        logger.debug("The eventType: {} can not be triggered by Coordinator.", eventType.getURI().toString());
                    }
                } else {
                    logger.debug("The event type denoted by {} is not allowed.", messageForSending);
                }
            } catch (Exception e) {
                logger.debug("caught Exception", e);
            }
        }
    });
}
Also used : BAPCEventType(won.node.facet.businessactivity.participantcompletion.BAPCEventType) URI(java.net.URI) WonProtocolException(won.protocol.exception.WonProtocolException) IllegalMessageForConnectionStateException(won.protocol.exception.IllegalMessageForConnectionStateException) NoSuchConnectionException(won.protocol.exception.NoSuchConnectionException) BAPCState(won.node.facet.businessactivity.participantcompletion.BAPCState)

Example 14 with NoSuchConnectionException

use of won.protocol.exception.NoSuchConnectionException in project webofneeds by researchstudio-sat.

the class BACCCoordinatorFacetImpl method sendMessageFromOwner.

// Coordinator sends message to Participant
public void sendMessageFromOwner(final Connection con, final Model message, final WonMessage wonMessage) throws NoSuchConnectionException, IllegalMessageForConnectionStateException {
    final URI remoteConnectionURI = con.getRemoteConnectionURI();
    // inform the other side
    executorService.execute(new Runnable() {

        @Override
        public void run() {
            try {
                String messageForSending = new String();
                BACCEventType eventType = null;
                Model myContent = null;
                Resource r = null;
                // message (event) for sending
                // message as TEXT
                messageForSending = WonRdfUtils.MessageUtils.getTextMessage(message);
                if (messageForSending != null) {
                    eventType = BACCEventType.getCoordinationEventTypeFromString(messageForSending);
                    logger.debug("Coordinator sends the text message: {}", eventType);
                } else // message as MODEL
                {
                    NodeIterator ni = message.listObjectsOfProperty(message.getProperty(WON_TX.COORDINATION_MESSAGE.getURI().toString()));
                    if (ni.hasNext()) {
                        String eventTypeURI = ni.toList().get(0).asResource().getURI().toString();
                        eventType = BACCEventType.getBAEventTypeFromURI(eventTypeURI);
                        logger.debug("Coordinator sends the RDF: {}", eventType.getURI());
                    } else {
                        logger.debug("Message {} does not contain a proper content.", message.toString());
                        return;
                    }
                }
                myContent = ModelFactory.createDefaultModel();
                myContent.setNsPrefix("", "no:uri");
                Resource baseResource = myContent.createResource("no:uri");
                if ((eventType != null)) {
                    if (eventType.isBACCCoordinatorEventType(eventType)) {
                        BACCState state, newState;
                        state = BACCState.parseString(stateManager.getStateForNeedUri(con.getNeedURI(), con.getRemoteNeedURI(), getFacetType().getURI()).toString());
                        logger.debug("Current state of the Coordinator: " + state.getURI().toString());
                        newState = state.transit(eventType);
                        stateManager.setStateForNeedUri(newState.getURI(), con.getNeedURI(), con.getRemoteNeedURI(), getFacetType().getURI());
                        storeBAStateForConnection(con, newState.getURI());
                        logger.debug("New state of the Coordinator:" + stateManager.getStateForNeedUri(con.getNeedURI(), con.getRemoteNeedURI(), getFacetType().getURI()));
                        // eventType -> URI Resource
                        r = myContent.createResource(eventType.getURI().toString());
                        baseResource.addProperty(WON_TX.COORDINATION_MESSAGE, r);
                    // TODO: use new system
                    // needFacingConnectionClient.sendMessage(con, myContent, wonMessage);
                    } else {
                        logger.debug("The eventType: " + eventType.getURI().toString() + " can not be triggered by Coordinator.");
                    }
                } else {
                    logger.debug("The event type denoted by " + messageForSending + " is not allowed.");
                }
            } catch (Exception e) {
                logger.warn("caught Exception", e);
            }
        }
    });
}
Also used : BACCEventType(won.node.facet.businessactivity.coordinatorcompletion.BACCEventType) URI(java.net.URI) BACCState(won.node.facet.businessactivity.coordinatorcompletion.BACCState) IllegalMessageForConnectionStateException(won.protocol.exception.IllegalMessageForConnectionStateException) NoSuchConnectionException(won.protocol.exception.NoSuchConnectionException)

Example 15 with NoSuchConnectionException

use of won.protocol.exception.NoSuchConnectionException in project webofneeds by researchstudio-sat.

the class ConnectMessageFromNodeProcessor method process.

public void process(final Exchange exchange) throws Exception {
    Message message = exchange.getIn();
    WonMessage wonMessage = (WonMessage) message.getHeader(WonCamelConstants.MESSAGE_HEADER);
    // a need wants to connect.
    // get the required data from the message and create a connection
    URI needUri = wonMessage.getReceiverNeedURI();
    URI wonNodeUriFromWonMessage = wonMessage.getReceiverNodeURI();
    URI remoteNeedUri = wonMessage.getSenderNeedURI();
    URI remoteConnectionUri = wonMessage.getSenderURI();
    URI facetURI = WonRdfUtils.FacetUtils.getFacet(wonMessage);
    // if the uri is known already, we can load the connection!
    URI connectionURI = wonMessage.getReceiverURI();
    if (remoteConnectionUri == null)
        throw new MissingMessagePropertyException(URI.create(WONMSG.SENDER_PROPERTY.getURI().toString()));
    Connection con = null;
    if (connectionURI != null) {
        con = connectionRepository.findOneByConnectionURIForUpdate(connectionURI);
        if (con == null)
            throw new NoSuchConnectionException(connectionURI);
    } else {
        con = connectionRepository.findOneByNeedURIAndRemoteNeedURIAndTypeURIForUpdate(needUri, remoteNeedUri, facetURI);
    }
    if (con == null) {
        // create Connection in Database
        URI connectionUri = wonNodeInformationService.generateConnectionURI(wonNodeUriFromWonMessage);
        con = dataService.createConnection(connectionUri, needUri, remoteNeedUri, remoteConnectionUri, facetURI, ConnectionState.REQUEST_RECEIVED, ConnectionEventType.PARTNER_OPEN);
    }
    con.setRemoteConnectionURI(remoteConnectionUri);
    con.setState(con.getState().transit(ConnectionEventType.PARTNER_OPEN));
    connectionRepository.save(con);
    // set the receiver to the newly generated connection uri
    wonMessage.addMessageProperty(WONMSG.RECEIVER_PROPERTY, con.getConnectionURI());
}
Also used : Message(org.apache.camel.Message) WonMessage(won.protocol.message.WonMessage) MissingMessagePropertyException(won.protocol.message.processor.exception.MissingMessagePropertyException) NoSuchConnectionException(won.protocol.exception.NoSuchConnectionException) WonMessage(won.protocol.message.WonMessage) Connection(won.protocol.model.Connection) URI(java.net.URI)

Aggregations

URI (java.net.URI)15 NoSuchConnectionException (won.protocol.exception.NoSuchConnectionException)15 Dataset (org.apache.jena.query.Dataset)7 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)7 IllegalMessageForConnectionStateException (won.protocol.exception.IllegalMessageForConnectionStateException)6 HttpHeaders (org.springframework.http.HttpHeaders)4 ResponseEntity (org.springframework.http.ResponseEntity)4 WonProtocolException (won.protocol.exception.WonProtocolException)4 NeedInformationService (won.protocol.service.NeedInformationService)4 ParseException (java.text.ParseException)3 BACCEventType (won.node.facet.businessactivity.coordinatorcompletion.BACCEventType)3 BACCState (won.node.facet.businessactivity.coordinatorcompletion.BACCState)3 BAPCEventType (won.node.facet.businessactivity.participantcompletion.BAPCEventType)3 BAPCState (won.node.facet.businessactivity.participantcompletion.BAPCState)3 NoSuchNeedException (won.protocol.exception.NoSuchNeedException)3 WonMessageType (won.protocol.message.WonMessageType)3 Message (org.apache.camel.Message)2 NoSuchMessageException (org.springframework.context.NoSuchMessageException)2 WonMessage (won.protocol.message.WonMessage)2 Connection (won.protocol.model.Connection)2