Search in sources :

Example 36 with AtomModelWrapper

use of won.protocol.util.AtomModelWrapper in project webofneeds by researchstudio-sat.

the class AtomService method createAtom.

public Atom createAtom(final WonMessage wonMessage) {
    acquireOwnerApplicationLock();
    wonMessage.getMessageType().requireType(WonMessageType.CREATE_ATOM);
    Dataset atomContent = wonMessage.getMessageContent();
    List<WonMessage.AttachmentHolder> attachmentHolders = wonMessage.getAttachments();
    // remove attachment and its signature from the atomContent
    removeAttachmentsFromAtomContent(atomContent, attachmentHolders);
    URI messageURI = wonMessage.getMessageURI();
    final AtomModelWrapper atomModelWrapper = new AtomModelWrapper(atomContent);
    URI atomURI = getAtomURIAndCheck(atomModelWrapper);
    // rename the content graphs and signature graphs so they start with the atom
    // uri
    Collection<String> sockets = getSocketsAndCheck(atomModelWrapper, atomURI);
    Set<Socket> socketEntities = sockets.stream().map(socketUri -> {
        Optional<String> socketType = getSocketTypeAndCheck(atomModelWrapper, socketUri);
        Socket f = new Socket();
        f.setAtomURI(atomURI);
        f.setSocketURI(URI.create(socketUri));
        f.setTypeURI(URI.create(socketType.get()));
        return f;
    }).collect(Collectors.toSet());
    checkResourcesInAtomContent(atomModelWrapper);
    Dataset atomDataset = atomModelWrapper.getDataset();
    socketAclService.addLocalSocketAcls(atomURI, socketEntities, atomDataset);
    // add everything to the atom model class and save it
    checkCanThisMessageCreateOrModifyThisAtom(wonMessage, atomURI);
    Atom atom = new Atom();
    atom.setState(AtomState.ACTIVE);
    atom.setAtomURI(atomURI);
    // make a new wrapper because we just changed the underlying dataset
    atom.setWonNodeURI(URI.create(uriService.getResourceURIPrefix()));
    ConnectionContainer connectionContainer = new ConnectionContainer(atom);
    atom.setConnectionContainer(connectionContainer);
    AtomMessageContainer atomMessageContainer = atomMessageContainerRepository.findOneByParentUri(atomURI);
    if (atomMessageContainer == null) {
        atomMessageContainer = new AtomMessageContainer(atom, atom.getAtomURI());
    } else {
        throw new UriAlreadyInUseException("Found an AtomMessageContainer for the atom we're about to create (" + atomURI + ") - aborting");
    }
    atom.setMessageContainer(atomMessageContainer);
    // store the atom content
    atomModelWrapper.renameResourceWithPrefix(messageURI.toString(), atomURI.toString());
    DatasetHolder datasetHolder = new DatasetHolder(atomURI, atomModelWrapper.getDataset());
    // store attachments
    List<DatasetHolder> attachments = new ArrayList<>(attachmentHolders.size());
    for (WonMessage.AttachmentHolder attachmentHolder : attachmentHolders) {
        datasetHolder = new DatasetHolder(attachmentHolder.getDestinationUri(), attachmentHolder.getAttachmentDataset());
        attachments.add(datasetHolder);
    }
    atom.setDatatsetHolder(datasetHolder);
    atom.setAttachmentDatasetHolders(attachments);
    atom = atomRepository.save(atom);
    connectionContainerRepository.save(connectionContainer);
    socketEntities.forEach(socket -> socketRepository.save(socket));
    dataDerivationService.deriveDataIfNecessary(atom);
    return atom;
}
Also used : java.util(java.util) Split(org.javasimon.Split) URISyntaxException(java.net.URISyntaxException) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) WONMSG(won.protocol.vocabulary.WONMSG) Stopwatch(org.javasimon.Stopwatch) WonAclEvaluator(won.auth.WonAclEvaluator) WonMessageDirection(won.protocol.message.WonMessageDirection) OperationRequest(won.auth.model.OperationRequest) WonMessage(won.protocol.message.WonMessage) AuthUtils(won.auth.AuthUtils) URI(java.net.URI) URIService(won.node.service.nodeconfig.URIService) Dataset(org.apache.jena.query.Dataset) POSITION_ATOM_GRAPH(won.auth.model.Individuals.POSITION_ATOM_GRAPH) GraphType(won.auth.model.GraphType) Logger(org.slf4j.Logger) WonMessageType(won.protocol.message.WonMessageType) MethodHandles(java.lang.invoke.MethodHandles) won.protocol.repository(won.protocol.repository) EntityManager(javax.persistence.EntityManager) Collectors(java.util.stream.Collectors) WonRelativeUriHelper(won.protocol.util.linkeddata.uriresolver.WonRelativeUriHelper) DecisionValue(won.auth.model.DecisionValue) won.protocol.exception(won.protocol.exception) AclEvalResult(won.auth.model.AclEvalResult) AtomModelWrapper(won.protocol.util.AtomModelWrapper) Component(org.springframework.stereotype.Component) SimonManager(org.javasimon.SimonManager) won.protocol.model(won.protocol.model) RdfUtils(won.protocol.util.RdfUtils) SocketAuthorizationSource(won.auth.socket.SocketAuthorizationSource) Dataset(org.apache.jena.query.Dataset) URI(java.net.URI) WonMessage(won.protocol.message.WonMessage) AtomModelWrapper(won.protocol.util.AtomModelWrapper)

Example 37 with AtomModelWrapper

use of won.protocol.util.AtomModelWrapper in project webofneeds by researchstudio-sat.

the class WonMessageRoutesTest method loadDatasetAndReplaceAtomURI.

protected Dataset loadDatasetAndReplaceAtomURI(String file, URI atomURI) throws IOException {
    Dataset atomDataset = loadDataset(file);
    AtomModelWrapper amw = new AtomModelWrapper(atomDataset);
    amw.setAtomURI(atomURI);
    return atomDataset;
}
Also used : Dataset(org.apache.jena.query.Dataset) AtomModelWrapper(won.protocol.util.AtomModelWrapper)

Aggregations

AtomModelWrapper (won.protocol.util.AtomModelWrapper)37 Dataset (org.apache.jena.query.Dataset)19 Resource (org.apache.jena.rdf.model.Resource)15 URI (java.net.URI)9 Model (org.apache.jena.rdf.model.Model)8 WonMessage (won.protocol.message.WonMessage)6 RdfUtils (won.protocol.util.RdfUtils)6 IOException (java.io.IOException)5 MethodHandles (java.lang.invoke.MethodHandles)5 LinkedList (java.util.LinkedList)5 Test (org.junit.Test)5 Logger (org.slf4j.Logger)5 LoggerFactory (org.slf4j.LoggerFactory)5 GoalInstantiationProducer (won.utils.goals.GoalInstantiationProducer)5 GoalInstantiationResult (won.utils.goals.GoalInstantiationResult)5 DistributedPubSubMediator (akka.cluster.pubsub.DistributedPubSubMediator)4 java.util (java.util)4 Collectors (java.util.stream.Collectors)4 StringUtils (org.apache.commons.lang3.StringUtils)4 ActorRef (akka.actor.ActorRef)3