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;
}
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);
}
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;
}
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;
}
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";
}
}
Aggregations