use of won.protocol.model.Atom in project webofneeds by researchstudio-sat.
the class ReplaceAtomMessageFromOwnerReactionProcessor method process.
public void process(final Exchange exchange) throws Exception {
WonMessage wonMessage = (WonMessage) exchange.getIn().getHeader(WonCamelConstants.MESSAGE_HEADER);
URI atomURI = wonMessage.getSenderAtomURI();
if (atomURI == null)
throw new IllegalArgumentException("senderAtomURI not found!");
logger.debug("Reacting to atom replacement. AtomURI:{}", atomURI);
Atom atom = atomService.getAtomRequired(atomURI);
matcherProtocolMatcherClient.atomModified(atom.getAtomURI(), wonMessage);
// notify all connections
Collection<Connection> conns = connectionRepository.findByAtomURIAndState(atom.getAtomURI(), ConnectionState.CONNECTED);
for (Connection con : conns) {
sendChangeNotificationMessage(atom, con);
}
}
use of won.protocol.model.Atom in project webofneeds by researchstudio-sat.
the class UriAlreadyUsedCheckingWonMessageProcessor method checkAtomURI.
private void checkAtomURI(final WonMessage message) {
if (message.getMessageType() == WonMessageType.CREATE_ATOM) {
URI atomURI = WonRdfUtils.AtomUtils.getAtomURI(message.getCompleteDataset());
Optional<Atom> atom = atomService.getAtom(atomURI);
if (!atom.isPresent()) {
return;
} else {
throw new UriAlreadyInUseException(message.getSenderAtomURI().toString());
}
}
return;
}
use of won.protocol.model.Atom in project webofneeds by researchstudio-sat.
the class AtomManagementService method sendTextMessageToOwner.
public void sendTextMessageToOwner(URI atomURI, String message) {
if (atomURI == null) {
logger.warn("sendTextMessageToOwner called but atomUri is null - doing nothing");
return;
}
if (message == null || message.trim().length() == 0) {
logger.warn("sendTextMessageToOwner called for atom {}, but message is null or empty - doing nothing", atomURI);
return;
}
logger.debug("Sending FromSystem text message to 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.atomMessage().atom(atomURI).content().text(message).build();
sendSystemMessage(msg);
}
use of won.protocol.model.Atom in project webofneeds by researchstudio-sat.
the class ConnectFromNodeReviewSocketImpl method addReviewToAtom.
private void addReviewToAtom(Map<Property, String> reviewData, URI connectionUri) throws IllegalArgumentException {
String aboutAtomURI = reviewData.get(SCHEMA.ABOUT);
Double rating = Double.parseDouble(reviewData.get(SCHEMA.RATING_VALUE)) > 0.0 ? Double.parseDouble(reviewData.get(SCHEMA.RATING_VALUE)) : 0.0;
Atom aboutAtom = atomService.getAtomRequired(URI.create(aboutAtomURI));
Dataset atomDataset = aboutAtom.getDatatsetHolder().getDataset();
Model derivationModel = atomDataset.getNamedModel(aboutAtom.getAtomURI() + "#derivedData");
Resource aboutAtomResource = derivationModel.getResource(aboutAtomURI);
Resource conRes = derivationModel.getResource(connectionUri.toString());
Statement reviewdConnectionsProperty = derivationModel.getProperty(aboutAtomResource, WXREVIEW.reviewedConnection);
if (reviewdConnectionsProperty == null) {
derivationModel.add(aboutAtomResource, WXREVIEW.reviewedConnection, conRes);
reviewdConnectionsProperty = derivationModel.getProperty(aboutAtomResource, WXREVIEW.reviewedConnection);
} else {
Property ratedConnections = derivationModel.getProperty(WXREVIEW.reviewedConnection.toString());
if (derivationModel.contains(aboutAtomResource, ratedConnections, conRes)) {
logger.debug("Connection already reviewed {}", connectionUri.toString());
throw new IllegalArgumentException("Connection already reviewed");
} else {
derivationModel.add(aboutAtomResource, ratedConnections, conRes);
}
}
Statement aggregateRatingProperty = derivationModel.getProperty(aboutAtomResource, SCHEMA.AGGREGATE_RATING);
if (aggregateRatingProperty == null) {
derivationModel.addLiteral(aboutAtomResource, SCHEMA.AGGREGATE_RATING, rating);
aggregateRatingProperty = derivationModel.getProperty(aboutAtomResource, SCHEMA.AGGREGATE_RATING);
}
int ratingCount = 0;
Statement reviewCountProperty = derivationModel.getProperty(aboutAtomResource, SCHEMA.REVIEW_COUNT);
if (reviewCountProperty != null) {
ratingCount = reviewCountProperty.getInt();
} else {
derivationModel.addLiteral(aboutAtomResource, SCHEMA.REVIEW_COUNT, 0.0);
reviewCountProperty = derivationModel.getProperty(aboutAtomResource, SCHEMA.REVIEW_COUNT);
}
Double aggregateRating = aggregateRatingProperty.getDouble();
Double ratingSum = 0.0;
if (ratingCount < 1) {
ratingSum = aggregateRating;
} else {
ratingSum = (aggregateRating * ratingCount) + rating;
}
ratingCount++;
Double newAggregateRating = ratingSum / ratingCount;
aggregateRatingProperty.changeLiteralObject(newAggregateRating);
reviewCountProperty.changeLiteralObject(ratingCount);
aboutAtom.getDatatsetHolder().setDataset(atomDataset);
atomRepository.save(aboutAtom);
}
use of won.protocol.model.Atom in project webofneeds by researchstudio-sat.
the class OwnerProtocolCommunicationServiceImpl method getWonNodeUriWithConnectionUri.
@Override
public synchronized URI getWonNodeUriWithConnectionUri(URI connectionUri) throws NoSuchConnectionException {
// TODO: make this more efficient
Connection con = DataAccessUtils.loadConnection(connectionRepository, connectionUri);
URI atomURI = con.getAtomURI();
Atom atom = atomRepository.findByAtomURI(atomURI).get(0);
return atom.getWonNodeURI();
}
Aggregations