use of won.protocol.exception.WonMessageProcessingException in project webofneeds by researchstudio-sat.
the class DeleteAtomMessageProcessor method process.
@Override
public void process(final Exchange exchange) throws Exception {
WonMessage wonMessage = (WonMessage) exchange.getIn().getHeader(WonCamelConstants.RESPONSE_HEADER);
WonMessage focalMessage = wonMessage.getFocalMessage();
if (focalMessage.getMessageType() == WonMessageType.SUCCESS_RESPONSE && focalMessage.getRespondingToMessageType() == WonMessageType.DELETE) {
URI recipientAtomURI = focalMessage.getRecipientAtomURI();
if (recipientAtomURI == null) {
throw new WonMessageProcessingException("recipientAtomURI is not set");
}
Atom atom = DataAccessUtils.loadAtom(atomRepository, recipientAtomURI);
if (atom.getState() == AtomState.DELETED) {
// Delete Atom
logger.debug("Set atom to state DELETED. atomURI:{}", recipientAtomURI);
Collection<Connection> conns = connectionRepository.findByAtomURIAndNotState(atom.getAtomURI(), ConnectionState.CLOSED);
if (conns.size() > 0) {
// Still not closed connections
logger.debug("Still open connections for atom. atomURI{}", recipientAtomURI);
// TODO: Handle!
}
messageEventRepository.deleteByParentURI(atom.getAtomURI());
atom.resetAllAtomData();
} else {
// First Step: Delete message to set atom in DELETED state and start delete
// process
logger.debug("DELETING atom. atomURI:{}", recipientAtomURI);
atom.setState(AtomState.DELETED);
}
atomRepository.save(atom);
}
}
use of won.protocol.exception.WonMessageProcessingException in project webofneeds by researchstudio-sat.
the class EagerlyCachePopulatingMessageProcessor method process.
@Override
public WonMessage process(WonMessage message) throws WonMessageProcessingException {
if (this.linkedDataSourceOnBehalfOfAtom != null && this.linkedDataSourceOnBehalfOfAtom instanceof CachingLinkedDataSource) {
logger.debug("eagerly fetching delivery chain for mesasge {} into cache", message.getMessageURI());
URI requester = message.getRecipientAtomURI();
((CachingLinkedDataSource) linkedDataSourceOnBehalfOfAtom).addToCache(message.getCompleteDataset(), message.getMessageURI(), requester);
// load the original message(s) into cache, too
Set<URI> toLoad = new HashSet<URI>();
addIfNotNull(toLoad, message.getRespondingToMessageURI());
List<URI> previous = WonRdfUtils.MessageUtils.getPreviousMessageUrisIncludingRemote(message);
addIfNotNull(toLoad, previous);
parallelRequestsThreadpool.submit(() -> toLoad.parallelStream().forEach(uri -> {
try {
linkedDataSourceOnBehalfOfAtom.getDataForResource(uri, requester);
} catch (Exception e) {
logger.debug("Error fetching {}, omitting", uri, e);
}
}));
}
return message;
}
use of won.protocol.exception.WonMessageProcessingException in project webofneeds by researchstudio-sat.
the class LinkedDataCacheInvalidator method process.
@Override
public WonMessage process(final WonMessage message) throws WonMessageProcessingException {
WonMessageType type = message.getMessageType();
if (type == WonMessageType.SUCCESS_RESPONSE) {
type = message.getRespondingToMessageType();
}
URI webId = message.getRecipientAtomURI();
if (type.isConnectionSpecificMessage()) {
Optional<URI> connectionURI = WonLinkedDataUtils.getConnectionURIForIncomingMessage(message, linkedDataSource);
if (connectionURI.isPresent()) {
// message was created
try {
logger.debug("invalidating events list for atom " + message.getRecipientAtomURI() + " for connection " + connectionURI.get());
URI messageContainerUri = WonRelativeUriHelper.createMessageContainerURIForConnection(connectionURI.get());
invalidate(messageContainerUri, webId);
if (type.causesConnectionStateChange()) {
invalidate(connectionURI.get(), webId);
}
} catch (Exception e) {
logger.info("Error occurred while trying to invalidate cache for {}: {}", message.getRecipientAtomURI(), e.getMessage());
}
}
}
if (type.causesNewConnection()) {
// the list of connections of the receiver atom should be invalidated, since
// these type
// of messages mean that the new connection has been created recently
logger.debug("invalidating connections list for atom " + message.getRecipientAtomURI());
try {
URI connectionsListUri = WonRelativeUriHelper.createConnectionContainerURIForAtom(message.getRecipientAtomURI());
invalidate(connectionsListUri, webId);
} catch (Exception e) {
logger.info("Error occurred while trying to invalidate cache for {}: {}", message.getRecipientAtomURI(), e.getMessage());
}
}
if (type.causesAtomStateChange()) {
invalidate(message.getRecipientAtomURI(), webId);
}
return message;
}
Aggregations