Search in sources :

Example 1 with NoSuchAtomException

use of won.protocol.exception.NoSuchAtomException in project webofneeds by researchstudio-sat.

the class LinkedDataServiceImpl method getAtomDatasetForFilter.

@Override
@Transactional(propagation = Propagation.REQUIRED, isolation = Isolation.READ_COMMITTED, readOnly = true)
public Dataset getAtomDatasetForFilter(final URI atomUri) {
    Instant start = logger.isDebugEnabled() ? Instant.now() : null;
    DataWithEtag<Atom> atomDataWithEtag;
    try {
        atomDataWithEtag = atomInformationService.readAtom(atomUri, null);
    } catch (NoSuchAtomException e) {
        if (logger.isDebugEnabled() && start != null) {
            Instant finish = Instant.now();
            logger.debug("getAtomDatasetForfilter({}) took {}ms", atomUri, Duration.between(start, finish).toMillis());
        }
        return null;
    }
    if (atomDataWithEtag.isNotFound()) {
        if (logger.isDebugEnabled() && start != null) {
            Instant finish = Instant.now();
            logger.debug("getAtomDatasetForfilter({}) took {}ms", atomUri, Duration.between(start, finish).toMillis());
        }
        return null;
    }
    Atom atom = atomDataWithEtag.getData();
    // load the dataset from storage
    boolean isDeleted = (atom.getState() == AtomState.DELETED);
    Dataset dataset = isDeleted ? DatasetFactory.createGeneral() : atom.getDatatsetHolder().getDataset();
    Model metaModel = atomModelMapper.toModel(atom);
    Resource atomResource = metaModel.getResource(atomUri.toString());
    String atomMetaInformationURI = uriService.createSysInfoGraphURIForAtomURI(atomUri).toString();
    Resource atomMetaInformationResource = metaModel.getResource(atomMetaInformationURI);
    // link atomMetaInformationURI to atom via rdfg:subGraphOf
    atomMetaInformationResource.addProperty(RDFG.SUBGRAPH_OF, atomResource);
    // add WON node link
    atomResource.addProperty(WON.wonNode, metaModel.createResource(this.resourceURIPrefix));
    // link all atom graphs taken from the create message to atom uri:
    Iterator<String> namesIt = dataset.listNames();
    while (namesIt.hasNext()) {
        String name = namesIt.next();
        Resource atomGraphResource = metaModel.getResource(name);
        atomResource.addProperty(WON.contentGraph, atomGraphResource);
    }
    // add meta model to dataset
    dataset.addNamedModel(atomMetaInformationURI, metaModel);
    addBaseUriAndDefaultPrefixes(dataset);
    if (logger.isDebugEnabled() && start != null) {
        Instant finish = Instant.now();
        logger.debug("getAtomDatasetForfilter({}) took {}ms", atomUri, Duration.between(start, finish).toMillis());
    }
    return dataset;
}
Also used : NoSuchAtomException(won.protocol.exception.NoSuchAtomException) Dataset(org.apache.jena.query.Dataset) Instant(java.time.Instant) Model(org.apache.jena.rdf.model.Model) Resource(org.apache.jena.rdf.model.Resource) UnreadMessageInfoForAtom(won.protocol.model.unread.UnreadMessageInfoForAtom) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with NoSuchAtomException

use of won.protocol.exception.NoSuchAtomException in project webofneeds by researchstudio-sat.

the class LinkedDataServiceImpl method getAtomDataset.

@Transactional(propagation = Propagation.REQUIRED, isolation = Isolation.READ_COMMITTED, readOnly = true)
public DataWithEtag<Dataset> getAtomDataset(final URI atomUri, String etag, WonAclEvalContext wonAclEvalContext) {
    if (wonAclEvalContext == null) {
        wonAclEvalContext = WonAclEvalContext.allowAll();
    }
    Instant start = logger.isDebugEnabled() ? Instant.now() : null;
    DataWithEtag<Atom> atomDataWithEtag;
    try {
        atomDataWithEtag = atomInformationService.readAtom(atomUri, etag);
    } catch (NoSuchAtomException e) {
        if (logger.isDebugEnabled() && start != null) {
            Instant finish = Instant.now();
            logger.debug("getAtomDataset({}) took {}ms", atomUri, Duration.between(start, finish).toMillis());
        }
        return DataWithEtag.dataNotFound();
    }
    if (atomDataWithEtag.isNotFound()) {
        if (logger.isDebugEnabled() && start != null) {
            Instant finish = Instant.now();
            logger.debug("getAtomDataset({}) took {}ms", atomUri, Duration.between(start, finish).toMillis());
        }
        return DataWithEtag.dataNotFound();
    }
    if (!atomDataWithEtag.isChanged()) {
        if (logger.isDebugEnabled() && start != null) {
            Instant finish = Instant.now();
            logger.debug("getAtomDataset({}) took {}ms", atomUri, Duration.between(start, finish).toMillis());
        }
        return DataWithEtag.dataNotChanged(atomDataWithEtag);
    }
    Atom atom = atomDataWithEtag.getData();
    String newEtag = atomDataWithEtag.getEtag();
    // load the dataset from storage or use empty one
    boolean isDeleted = (atom.getState() == AtomState.DELETED);
    Dataset dataset = isDeleted ? DatasetFactory.createGeneral() : atom.getDatatsetHolder().getDataset();
    // filter by acl
    if (!isDeleted && wonAclEvalContext.isModeFilter()) {
        dataset = filterByAcl(atom.getAtomURI(), dataset, wonAclEvalContext);
    }
    // check acl: should we add sysinfo graph?
    AclEvalResult result = null;
    if (wonAclEvalContext.isModeFilter()) {
        URI sysInfoGraphUri = uriService.createSysInfoGraphURIForAtomURI(atomUri);
        OperationRequest operationRequest = AuthUtils.cloneShallow(wonAclEvalContext.getOperationRequest());
        operationRequest.setReqPosition(POSITION_ATOM_GRAPH);
        operationRequest.setReqGraphs(Collections.singleton(sysInfoGraphUri));
        result = wonAclEvalContext.decideAndRemember(operationRequest);
    }
    if (wonAclEvalContext.isModeAllowAll() || DecisionValue.ACCESS_GRANTED.equals(result.getDecision())) {
        addSysInfoGraph(atom, dataset);
    }
    // add prefixes
    addBaseUriAndDefaultPrefixes(dataset);
    if (logger.isDebugEnabled() && start != null) {
        Instant finish = Instant.now();
        logger.debug("getAtomDataset({}) took {} ms", atomUri, Duration.between(start, finish).toMillis());
    }
    if (dataset.isEmpty()) {
        return DataWithEtag.accessDenied();
    }
    return new DataWithEtag<>(dataset, newEtag, etag, isDeleted);
}
Also used : NoSuchAtomException(won.protocol.exception.NoSuchAtomException) Dataset(org.apache.jena.query.Dataset) Instant(java.time.Instant) OperationRequest(won.auth.model.OperationRequest) AclEvalResult(won.auth.model.AclEvalResult) URI(java.net.URI) UnreadMessageInfoForAtom(won.protocol.model.unread.UnreadMessageInfoForAtom) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with NoSuchAtomException

use of won.protocol.exception.NoSuchAtomException in project webofneeds by researchstudio-sat.

the class AtomInformationServiceImpl method listPagedAtomURIsAfter.

@Override
public Slice<URI> listPagedAtomURIsAfter(URI atomURI, Integer preferedPageSize, AtomState atomState) {
    Atom referenceAtom = atomRepository.findOneByAtomURI(atomURI).orElseThrow(() -> new NoSuchAtomException(atomURI));
    Date referenceDate = referenceAtom.getCreationDate();
    int pageSize = this.pageSize;
    if (preferedPageSize != null && preferedPageSize < this.pageSize) {
        pageSize = preferedPageSize;
    }
    Slice<URI> slice = null;
    if (atomState == null) {
        // use 'creationDate' to keep a constant atom order over requests
        slice = atomRepository.getAtomURIsAfter(referenceDate, PageRequest.of(0, pageSize, Sort.by(Sort.Direction.DESC, "creationDate")));
    } else {
        // use 'creationDate' to keep a constant atom order over requests
        slice = atomRepository.getAtomURIsAfter(referenceDate, atomState, PageRequest.of(0, pageSize, Sort.by(Sort.Direction.DESC, "creationDate")));
    }
    return slice;
}
Also used : NoSuchAtomException(won.protocol.exception.NoSuchAtomException) URI(java.net.URI) Date(java.util.Date)

Example 4 with NoSuchAtomException

use of won.protocol.exception.NoSuchAtomException in project webofneeds by researchstudio-sat.

the class AtomInformationServiceImpl method listPagedAtomURIsBefore.

@Override
public Slice<URI> listPagedAtomURIsBefore(URI atomURI, Integer preferedPageSize, AtomState atomState) {
    Atom referenceAtom = atomRepository.findOneByAtomURI(atomURI).orElseThrow(() -> new NoSuchAtomException(atomURI));
    Date referenceDate = referenceAtom.getCreationDate();
    int pageSize = this.pageSize;
    if (preferedPageSize != null && preferedPageSize < this.pageSize) {
        pageSize = preferedPageSize;
    }
    Slice<URI> slice = null;
    if (atomState == null) {
        // use 'creationDate' to keep a constant atom order over requests
        slice = atomRepository.getAtomURIsBefore(referenceDate, PageRequest.of(0, pageSize, Sort.by(Sort.Direction.DESC, "creationDate")));
    } else {
        // use 'creationDate' to keep a constant atom order over requests
        slice = atomRepository.getAtomURIsBefore(referenceDate, atomState, PageRequest.of(0, pageSize, Sort.by(Sort.Direction.DESC, "creationDate")));
    }
    return slice;
}
Also used : NoSuchAtomException(won.protocol.exception.NoSuchAtomException) URI(java.net.URI) Date(java.util.Date)

Example 5 with NoSuchAtomException

use of won.protocol.exception.NoSuchAtomException in project webofneeds by researchstudio-sat.

the class LinkedDataWebController method showDeepAtomPage.

/**
 * This request URL should be protected by WebID filter because the result
 * contains events data - which is data with restricted access. See
 * filterChainProxy in node-context.xml.
 *
 * @param identifier
 * @param model
 * @param response
 * @return
 */
// webmvc controller method
@RequestMapping("${uri.path.page}/atom/{identifier}/deep")
public String showDeepAtomPage(@PathVariable String identifier, Model model, HttpServletRequest request, HttpServletResponse response, @RequestParam(value = "layer-size", required = false) Integer layerSize) {
    try {
        URI atomURI = uriService.createAtomURIForId(identifier);
        WonAclEvalContext waeCtx = WonAclRequestHelper.getWonAclEvaluationContext(request);
        Dataset rdfDataset = linkedDataService.getAtomDataset(atomURI, true, layerSize, waeCtx);
        // TODO AUTH: extract acl graph and interpret
        // TODO AUTH: Research how to handle lower layers
        logger.warn("TODO: apply ACLs to atom/{identifier}/deep request!");
        if (rdfDataset == null || rdfDataset.isEmpty()) {
            Optional<AclEvalResult> result = waeCtx.getCombinedResults();
            if (result.isPresent()) {
                WonAclRequestHelper.setAuthInfoAsResponseHeader(response, result.get());
                response.setStatus(WonAclRequestHelper.getHttpStatusCodeForAclEvaluationResult(result.get()));
            }
        }
        model.addAttribute("rdfDataset", rdfDataset);
        model.addAttribute("resourceURI", atomURI.toString());
        model.addAttribute("dataURI", uriService.toDataURIIfPossible(atomURI).toString());
        return "rdfDatasetView";
    } catch (NoSuchAtomException | NoSuchConnectionException | NoSuchMessageException e) {
        response.setStatus(HttpServletResponse.SC_NOT_FOUND);
        return "notFoundView";
    }
}
Also used : NoSuchMessageException(org.springframework.context.NoSuchMessageException) NoSuchConnectionException(won.protocol.exception.NoSuchConnectionException) WonAclEvalContext(won.node.springsecurity.acl.WonAclEvalContext) Dataset(org.apache.jena.query.Dataset) NoSuchAtomException(won.protocol.exception.NoSuchAtomException) AclEvalResult(won.auth.model.AclEvalResult) URI(java.net.URI) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

NoSuchAtomException (won.protocol.exception.NoSuchAtomException)10 URI (java.net.URI)8 Dataset (org.apache.jena.query.Dataset)6 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)4 NoSuchConnectionException (won.protocol.exception.NoSuchConnectionException)4 URISyntaxException (java.net.URISyntaxException)3 AclEvalResult (won.auth.model.AclEvalResult)3 ParseException (java.text.ParseException)2 Instant (java.time.Instant)2 Date (java.util.Date)2 NoSuchMessageException (org.springframework.context.NoSuchMessageException)2 HttpHeaders (org.springframework.http.HttpHeaders)2 ResponseEntity (org.springframework.http.ResponseEntity)2 Transactional (org.springframework.transaction.annotation.Transactional)2 OperationRequest (won.auth.model.OperationRequest)2 WonAclEvalContext (won.node.springsecurity.acl.WonAclEvalContext)2 IllegalMessageForAtomStateException (won.protocol.exception.IllegalMessageForAtomStateException)2 WonMessageType (won.protocol.message.WonMessageType)2 ConnectionState (won.protocol.model.ConnectionState)2 UnreadMessageInfoForAtom (won.protocol.model.unread.UnreadMessageInfoForAtom)2