use of won.protocol.exception.NoSuchNeedException in project webofneeds by researchstudio-sat.
the class LinkedDataServiceImpl method getNeedDataset.
@Transactional
public DataWithEtag<Dataset> getNeedDataset(final URI needUri, String etag) {
DataWithEtag<Need> data = null;
try {
data = needInformationService.readNeed(needUri, etag);
} catch (NoSuchNeedException e) {
return DataWithEtag.dataNotFound();
}
if (data.isNotFound()) {
return DataWithEtag.dataNotFound();
}
if (!data.isChanged()) {
return DataWithEtag.dataNotChanged(data);
}
Need need = data.getData();
String newEtag = data.getEtag();
// load the dataset from storage
Dataset dataset = need.getDatatsetHolder().getDataset();
Model metaModel = needModelMapper.toModel(need);
Resource needResource = metaModel.getResource(needUri.toString());
// add connections
Resource connectionsContainer = metaModel.createResource(need.getNeedURI().toString() + "/connections");
metaModel.add(metaModel.createStatement(needResource, WON.HAS_CONNECTIONS, connectionsContainer));
// add need event container
Resource needEventContainer = metaModel.createResource(need.getNeedURI().toString() + "#events", WON.EVENT_CONTAINER);
metaModel.add(metaModel.createStatement(needResource, WON.HAS_EVENT_CONTAINER, needEventContainer));
// add need event URIs
Collection<MessageEventPlaceholder> messageEvents = need.getEventContainer().getEvents();
for (MessageEventPlaceholder messageEvent : messageEvents) {
metaModel.add(metaModel.createStatement(needEventContainer, RDFS.member, metaModel.getResource(messageEvent.getMessageURI().toString())));
}
// add WON node link
needResource.addProperty(WON.HAS_WON_NODE, metaModel.createResource(this.resourceURIPrefix));
// add meta model to dataset
String needMetaInformationURI = uriService.createNeedSysInfoGraphURI(needUri).toString();
dataset.addNamedModel(needMetaInformationURI, metaModel);
addBaseUriAndDefaultPrefixes(dataset);
return new DataWithEtag<>(dataset, newEtag, etag);
}
use of won.protocol.exception.NoSuchNeedException in project webofneeds by researchstudio-sat.
the class LinkedDataWebController method readNeedDeep.
/**
* 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 request
* @param identifier
* @return
*/
@RequestMapping(value = "${uri.path.data.need}/{identifier}/deep", method = RequestMethod.GET, produces = { "application/ld+json", "application/trig", "application/n-quads" })
public ResponseEntity<Dataset> readNeedDeep(HttpServletRequest request, @PathVariable(value = "identifier") String identifier, @RequestParam(value = "layer-size", required = false) Integer layerSize) {
logger.debug("readNeed() called");
URI needUri = URI.create(this.needResourceURIPrefix + "/" + identifier);
try {
Dataset dataset = linkedDataService.getNeedDataset(needUri, true, layerSize);
// TODO: need information does change over time. The immutable need information
// should never expire, the mutable should
HttpHeaders headers = new HttpHeaders();
addCORSHeader(headers);
return new ResponseEntity<>(dataset, headers, HttpStatus.OK);
} catch (NoSuchNeedException | NoSuchConnectionException | NoSuchMessageException e) {
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
}
}
use of won.protocol.exception.NoSuchNeedException in project webofneeds by researchstudio-sat.
the class LinkedDataWebController method readConnectionsOfNeed.
/**
* Get the RDF for the connections of the specified need.
*
* @param request
* @param identifier
* @param deep
* If true, connection data is added to the model (not only
* connection URIs). Default: false.
* @param page
* taken into account only if client supports paging; in that case
* the specified page is returned
* @param beforeId
* taken into account only if client supports paging; in that case
* the page with connections URIs that precede the connection having
* beforeId is returned
* @param afterId
* taken into account only if client supports paging; in that case
* the page with connections URIs that follow the connection having
* afterId are returned
* @param type
* only connection events of the given type are considered when
* ordering returned connections. Default: all event types.
* @param timestamp
* only connection events that where created before the given time
* are considered when ordering returned connections. Default:
* current time.
* @return
*/
@RequestMapping(value = "${uri.path.data.need}/{identifier}/connections", method = RequestMethod.GET, produces = { "application/ld+json", "application/trig", "application/n-quads" })
public ResponseEntity<Dataset> readConnectionsOfNeed(HttpServletRequest request, @PathVariable(value = "identifier") String identifier, @RequestParam(value = "deep", defaultValue = "false") boolean deep, @RequestParam(value = "p", required = false) Integer page, @RequestParam(value = "resumebefore", required = false) String beforeId, @RequestParam(value = "resumeafter", required = false) String afterId, @RequestParam(value = "type", required = false) String type, @RequestParam(value = "timeof", required = false) String timestamp) {
logger.debug("readConnectionsOfNeed() called");
URI needUri = URI.create(this.needResourceURIPrefix + "/" + identifier);
Dataset rdfDataset;
HttpHeaders headers = new HttpHeaders();
Integer preferedSize = getPreferredSize(request);
URI connectionsURI = URI.create(needUri.toString() + "/connections");
try {
WonMessageType eventsType = getMessageType(type);
DateParameter dateParam = new DateParameter(timestamp);
String passableQuery = getPassableQueryMap("type", type, "timeof", dateParam.getTimestamp(), "deep", Boolean.toString(deep));
// paging, return everything:
if (preferedSize == null) {
// does not support date and type filtering for clients that do not support
// paging
rdfDataset = linkedDataService.listConnectionURIs(needUri, deep, true);
// if no page or resume parameter is specified, display the latest connections:
} else if (page == null && beforeId == null && afterId == null) {
NeedInformationService.PagedResource<Dataset, URI> resource = linkedDataService.listConnectionURIs(1, needUri, preferedSize, eventsType, dateParam.getDate(), deep, true);
rdfDataset = resource.getContent();
addPagedResourceInSequenceHeader(headers, connectionsURI, resource, passableQuery);
} else if (page != null) {
NeedInformationService.PagedResource<Dataset, URI> resource = linkedDataService.listConnectionURIs(page, needUri, preferedSize, eventsType, dateParam.getDate(), deep, true);
rdfDataset = resource.getContent();
addPagedResourceInSequenceHeader(headers, connectionsURI, resource, page, passableQuery);
} else {
// before the specified event id:
if (beforeId != null) {
URI resumeConnURI = uriService.createConnectionURIForId(beforeId);
NeedInformationService.PagedResource<Dataset, URI> resource = linkedDataService.listConnectionURIsBefore(needUri, resumeConnURI, preferedSize, eventsType, dateParam.getDate(), deep, true);
rdfDataset = resource.getContent();
addPagedResourceInSequenceHeader(headers, connectionsURI, resource, passableQuery);
// resume after parameter specified - display the connections with activities
// after the specified event id:
} else {
// if (afterId != null)
URI resumeConnURI = uriService.createConnectionURIForId(afterId);
NeedInformationService.PagedResource<Dataset, URI> resource = linkedDataService.listConnectionURIsAfter(needUri, resumeConnURI, preferedSize, eventsType, dateParam.getDate(), deep, true);
rdfDataset = resource.getContent();
addPagedResourceInSequenceHeader(headers, connectionsURI, resource, passableQuery);
}
}
// append the required headers
addMutableResourceHeaders(headers);
addLocationHeaderIfNecessary(headers, URI.create(request.getRequestURI()), connectionsURI);
addCORSHeader(headers);
return new ResponseEntity<>(rdfDataset, headers, HttpStatus.OK);
} catch (ParseException e) {
logger.warn("could not parse timestamp into Date:{}", timestamp);
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
} catch (NoSuchNeedException e) {
logger.warn("did not find need {}", e.getUnknownNeedURI());
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
} catch (NoSuchConnectionException e) {
logger.warn("did not find connection that should be connected to need. connection:{}", e.getUnknownConnectionURI());
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
}
}
use of won.protocol.exception.NoSuchNeedException in project webofneeds by researchstudio-sat.
the class LinkedDataWebController method showDeepNeedPage.
/**
* 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.need}/{identifier}/deep")
public String showDeepNeedPage(@PathVariable String identifier, Model model, HttpServletResponse response, @RequestParam(value = "layer-size", required = false) Integer layerSize) {
try {
URI needURI = uriService.createNeedURIForId(identifier);
Dataset rdfDataset = linkedDataService.getNeedDataset(needURI, true, layerSize);
model.addAttribute("rdfDataset", rdfDataset);
model.addAttribute("resourceURI", needURI.toString());
model.addAttribute("dataURI", uriService.toDataURIIfPossible(needURI).toString());
return "rdfDatasetView";
} catch (NoSuchNeedException | NoSuchConnectionException | NoSuchMessageException e) {
response.setStatus(HttpServletResponse.SC_NOT_FOUND);
return "notFoundView";
}
}
use of won.protocol.exception.NoSuchNeedException in project webofneeds by researchstudio-sat.
the class CommentUnrestrictedFacet method connectFromNeed.
@Override
public void connectFromNeed(Connection con, Model content, WonMessage wonMessage) throws NoSuchNeedException, IllegalMessageForNeedStateException, ConnectionAlreadyExistsException {
super.connectFromNeed(con, content, wonMessage);
/* send a connect back */
try {
// TODO: use new system
// needFacingConnectionClient.open(con, content, null);
Need need = needRepository.findOneByNeedURI(con.getNeedURI());
Model needContent = need.getDatatsetHolder().getDataset().getDefaultModel();
PrefixMapping prefixMapping = PrefixMapping.Factory.create();
// prefixMapping.setNsPrefix(SIOC.getURI(),"sioc");
needContent.withDefaultMappings(prefixMapping);
needContent.setNsPrefix("sioc", SIOC.getURI());
Resource post = needContent.createResource(con.getNeedURI().toString(), SIOC.POST);
Resource reply = needContent.createResource(con.getRemoteNeedURI().toString(), SIOC.POST);
needContent.add(needContent.createStatement(needContent.getResource(con.getNeedURI().toString()), SIOC.HAS_REPLY, needContent.getResource(con.getRemoteNeedURI().toString())));
// add WON node link
logger.debug("linked data:" + RdfUtils.toString(needContent));
need.getDatatsetHolder().getDataset().setDefaultModel(needContent);
needRepository.save(need);
// } catch (NoSuchConnectionException e) {
// e.printStackTrace();
// } catch (IllegalMessageForConnectionStateException e) {
// e.printStackTrace();
} catch (Exception e) {
// To change body of catch statement use File | Settings | File Templates.
e.printStackTrace();
}
/* when connected change linked data*/
}
Aggregations