Search in sources :

Example 16 with Atom

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

the class OwnerApplicationAuthorizer method process.

@Override
public void process(Exchange exchange) throws Exception {
    Message message = exchange.getIn();
    WonMessage wonMessage = (WonMessage) message.getHeader(WonCamelConstants.MESSAGE_HEADER);
    if (wonMessage.getEnvelopeTypeRequired().isFromOwner() && !wonMessage.getMessageType().isCreateAtom()) {
        Optional<String> ownerAppIdOpt = WonCamelHelper.getOwnerApplicationId(exchange);
        URI atomUri = wonMessage.getSenderAtomURI();
        if (atomUri != null && ownerAppIdOpt.isPresent()) {
            Optional<Atom> atomOpt = atomService.lockAtom(atomUri);
            if (atomOpt.isPresent()) {
                atomService.authorizeOwnerApplicationForAtom(ownerAppIdOpt.get(), atomOpt.get());
            }
        }
    }
}
Also used : Message(org.apache.camel.Message) WonMessage(won.protocol.message.WonMessage) WonMessage(won.protocol.message.WonMessage) URI(java.net.URI) Atom(won.protocol.model.Atom)

Example 17 with Atom

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

the class DeleteAtomMessageFromOwnerReactionProcessor method process.

public void process(final Exchange exchange) throws Exception {
    WonMessage wonMessage = (WonMessage) exchange.getIn().getHeader(WonCamelConstants.MESSAGE_HEADER);
    URI recipientAtomURI = wonMessage.getRecipientAtomURI();
    logger.debug("DELETING atom. atomURI:{}", recipientAtomURI);
    if (recipientAtomURI == null) {
        throw new WonMessageProcessingException("recipientAtomURI is not set");
    }
    Atom atom = atomService.getAtomRequired(recipientAtomURI);
    matcherProtocolMatcherClient.atomDeleted(atom.getAtomURI(), wonMessage);
    // Check if atom already in State DELETED
    if (atom.getState() == AtomState.DELETED) {
        // Get all connections of this atom
        Collection<Connection> conns = connectionRepository.findByAtomURIAndNotState(atom.getAtomURI(), ConnectionState.DELETED);
        for (Connection con : conns) {
            entityManager.refresh(con);
            // Delete all connection data
            messageEventRepository.deleteByParentURI(con.getConnectionURI());
            connectionRepository.delete(con);
        }
    } else {
        // Get only not closed connections of this atom to close them
        Collection<Connection> conns = connectionRepository.findByAtomURIAndNotState(atom.getAtomURI(), ConnectionState.CLOSED);
        // Close open connections
        for (Connection con : conns) {
            entityManager.refresh(con);
            closeConnection(atom, con);
        }
    }
}
Also used : WonMessageProcessingException(won.protocol.exception.WonMessageProcessingException) WonMessage(won.protocol.message.WonMessage) Connection(won.protocol.model.Connection) URI(java.net.URI) Atom(won.protocol.model.Atom)

Example 18 with Atom

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

the class AtomManagementService method deactivateAtom.

public void deactivateAtom(URI atomURI, String optionalMessage) {
    if (atomURI == null) {
        logger.warn("deactivateAtom called but atomUri is null - doing nothing");
        return;
    }
    logger.debug("Deactivating atom {}", atomURI);
    // check if we have that atom (e.g. it's not an atom living on another node, or
    // does not exist at all)
    Atom atom = atomService.getAtomRequired(atomURI);
    if (atom == null) {
        logger.debug("deactivateAtom called for atom {} but that atom was not found in the repository - doing nothing", atomURI);
        return;
    }
    URI wonNodeURI = wonNodeInformationService.getWonNodeUri(atomURI);
    if (wonNodeURI == null) {
        logger.debug("deactivateAtom called for atom {} but we could not find a WonNodeURI for that atom - doing nothing", atomURI);
        return;
    }
    WonMessage msg = WonMessageBuilder.deactivate().atom(atomURI).content().text(optionalMessage).direction().fromSystem().build();
    sendSystemMessage(msg);
}
Also used : WonMessage(won.protocol.message.WonMessage) URI(java.net.URI) Atom(won.protocol.model.Atom)

Example 19 with Atom

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

the class ReplaceAtomMessageProcessor method process.

@Override
public void process(final Exchange exchange) throws Exception {
    Message message = exchange.getIn();
    WonMessage wonMessage = (WonMessage) message.getHeader(WonCamelConstants.MESSAGE_HEADER);
    Atom atom = atomService.replaceAtom(wonMessage, WonCamelHelper.getWonAclEvaluator(exchange).orElse(null), WonCamelHelper.getWonAclOperationRequest(exchange).orElse(null));
}
Also used : Message(org.apache.camel.Message) WonMessage(won.protocol.message.WonMessage) WonMessage(won.protocol.message.WonMessage) Atom(won.protocol.model.Atom)

Example 20 with Atom

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

the class ConnectionStateChangeReactionProcessor method process.

@Override
public void process(Exchange exchange) throws Exception {
    WonMessage wonMessage = (WonMessage) exchange.getIn().getHeader(WonCamelConstants.MESSAGE_HEADER);
    String msgTypeDir = "[message type: " + wonMessage.getMessageType() + ", direction: " + wonMessage.getEnvelopeType() + "]";
    ConnectionStateChangeBuilder stateChangeBuilder = (ConnectionStateChangeBuilder) exchange.getIn().getHeader(WonCamelConstants.CONNECTION_STATE_CHANGE_BUILDER_HEADER);
    if (stateChangeBuilder == null) {
        if (logger.isDebugEnabled()) {
            logger.debug("no stateChangeBuilder found in exchange header, cannot check for state change " + msgTypeDir);
        }
        return;
    }
    Optional<Connection> con = getConnection(exchange, connectionService);
    if (con.isPresent()) {
        if (!stateChangeBuilder.canBuild()) {
            stateChangeBuilder.newState(con.get().getState());
        }
    }
    // derivation service.
    if (stateChangeBuilder.canBuild()) {
        ConnectionStateChange connectionStateChange = stateChangeBuilder.build();
        Atom atom = atomService.getAtomRequired(con.get().getAtomURI());
        if ((connectionStateChange.isConnect() || connectionStateChange.isDisconnect()) && atom.getState() == AtomState.ACTIVE) {
            // trigger rematch
            matcherProtocolMatcherClient.atomModified(atom.getAtomURI(), null);
            logger.debug("matchers notified of connection state change {}", msgTypeDir);
        } else {
            logger.debug("no relevant connection state change, not notifying matchers {}", msgTypeDir);
        }
    } else {
        logger.debug("Could not collect ConnectionStateChange information, not checking for state change {}", msgTypeDir);
    }
}
Also used : WonMessage(won.protocol.message.WonMessage) ConnectionStateChangeBuilder(won.node.camel.processor.general.ConnectionStateChangeBuilder) ConnectionStateChange(won.node.service.nodebehaviour.ConnectionStateChange) Connection(won.protocol.model.Connection) WonCamelHelper.getConnection(won.node.camel.service.WonCamelHelper.getConnection) Atom(won.protocol.model.Atom)

Aggregations

Atom (won.protocol.model.Atom)24 URI (java.net.URI)17 WonMessage (won.protocol.message.WonMessage)15 Connection (won.protocol.model.Connection)11 Graph (org.apache.jena.graph.Graph)5 Message (org.apache.camel.Message)4 WonMessageProcessingException (won.protocol.exception.WonMessageProcessingException)4 Dataset (org.apache.jena.query.Dataset)3 WonAclEvaluator (won.auth.WonAclEvaluator)3 URISyntaxException (java.net.URISyntaxException)2 java.util (java.util)2 Collectors (java.util.stream.Collectors)2 Logger (org.slf4j.Logger)2 LoggerFactory (org.slf4j.LoggerFactory)2 Autowired (org.springframework.beans.factory.annotation.Autowired)2 MethodHandles (java.lang.invoke.MethodHandles)1 Date (java.util.Date)1 Optional (java.util.Optional)1 Supplier (java.util.function.Supplier)1 Transactional (javax.transaction.Transactional)1