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());
}
}
}
}
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);
}
}
}
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);
}
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));
}
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);
}
}
Aggregations