Search in sources :

Example 6 with Atom

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);
    }
}
Also used : WonMessage(won.protocol.message.WonMessage) Connection(won.protocol.model.Connection) URI(java.net.URI) Atom(won.protocol.model.Atom)

Example 7 with Atom

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;
}
Also used : UriAlreadyInUseException(won.protocol.exception.UriAlreadyInUseException) URI(java.net.URI) Atom(won.protocol.model.Atom)

Example 8 with Atom

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);
}
Also used : WonMessage(won.protocol.message.WonMessage) URI(java.net.URI) Atom(won.protocol.model.Atom)

Example 9 with Atom

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);
}
Also used : Dataset(org.apache.jena.query.Dataset) Statement(org.apache.jena.rdf.model.Statement) Model(org.apache.jena.rdf.model.Model) Resource(org.apache.jena.rdf.model.Resource) Property(org.apache.jena.rdf.model.Property) Atom(won.protocol.model.Atom)

Example 10 with Atom

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();
}
Also used : Connection(won.protocol.model.Connection) URI(java.net.URI) 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