use of won.protocol.exception.NoSuchConnectionException in project webofneeds by researchstudio-sat.
the class BAPCParticipantFacetImpl method sendMessageFromOwner.
// Participant sends message to Coordinator
public void sendMessageFromOwner(final Connection con, final Model message, final WonMessage wonMessage) throws NoSuchConnectionException, IllegalMessageForConnectionStateException {
final URI remoteConnectionURI = con.getRemoteConnectionURI();
// inform the other side
executorService.execute(new Runnable() {
@Override
public void run() {
try {
String messageForSending = new String();
BAPCEventType eventType = null;
Model myContent = null;
Resource r = null;
// message (event) for sending
messageForSending = WonRdfUtils.MessageUtils.getTextMessage(message);
if (messageForSending != null) {
eventType = BAPCEventType.getCoordinationEventTypeFromString(messageForSending);
logger.debug("*** Participant sends the text message:" + eventType + " coordinator:" + con.getRemoteNeedURI() + " participant:" + con.getNeedURI() + " con:" + con.getConnectionURI() + " baState:" + stateManager.getStateForNeedUri(con.getNeedURI(), con.getRemoteNeedURI(), getFacetType().getURI()).toString());
} else // message as MODEL
{
NodeIterator ni = message.listObjectsOfProperty(message.getProperty(WON_TX.COORDINATION_MESSAGE.getURI().toString()));
if (ni.hasNext()) {
String eventTypeURI = ni.toList().get(0).asResource().getURI().toString();
eventType = BAPCEventType.getBAEventTypeFromURI(eventTypeURI);
logger.debug("*** Participant sends the RDF message:" + eventType.getURI() + " coordinator:" + con.getRemoteNeedURI() + " participant:" + con.getNeedURI() + " con:" + con.getConnectionURI() + " baState:" + stateManager.getStateForNeedUri(con.getNeedURI(), con.getRemoteNeedURI(), getFacetType().getURI()).toString());
}
}
myContent = ModelFactory.createDefaultModel();
myContent.setNsPrefix("", "no:uri");
Resource baseResource = myContent.createResource("no:uri");
// message -> eventType
if ((eventType != null)) {
if (eventType.isBAPCParticipantEventType(eventType)) {
BAPCState state, newState;
state = BAPCState.parseString(stateManager.getStateForNeedUri(con.getNeedURI(), con.getRemoteNeedURI(), getFacetType().getURI()).toString());
newState = state.transit(eventType);
stateManager.setStateForNeedUri(newState.getURI(), con.getNeedURI(), con.getRemoteNeedURI(), getFacetType().getURI());
storeBAStateForConnection(con, newState.getURI());
logger.debug("New state = coordinator:" + con.getRemoteNeedURI() + " participant:" + con.getNeedURI() + " con:" + con.getConnectionURI() + " baState:" + stateManager.getStateForNeedUri(con.getNeedURI(), con.getRemoteNeedURI(), getFacetType().getURI()).toString());
// eventType -> URI Resource
r = myContent.createResource(eventType.getURI().toString());
baseResource.addProperty(WON_TX.COORDINATION_MESSAGE, r);
// TODO: use new system
// needFacingConnectionClient.sendMessage(con, myContent, wonMessage);
logger.debug("Participant sent the message.");
} else {
logger.info("The eventType: {} can not be triggered by Participant.", eventType.getURI().toString());
}
} else {
logger.info("The event type denoted by {} is not allowed.", messageForSending);
}
} catch (Exception e) {
logger.debug("caught Exception", e);
}
}
});
}
use of won.protocol.exception.NoSuchConnectionException 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.NoSuchConnectionException in project webofneeds by researchstudio-sat.
the class LinkedDataWebController method listConnectionURIs.
@RequestMapping(value = "${uri.path.data.connection}", method = RequestMethod.GET, produces = { "application/ld+json", "application/trig", "application/n-quads" })
public ResponseEntity<Dataset> listConnectionURIs(HttpServletRequest request, @RequestParam(value = "p", required = false) Integer page, @RequestParam(value = "resumebefore", required = false) String beforeId, @RequestParam(value = "resumeafter", required = false) String afterId, @RequestParam(value = "timeof", required = false) String timestamp, @RequestParam(value = "modifiedafter", required = false) String modifiedAfter, @RequestParam(value = "deep", defaultValue = "false") boolean deep) {
logger.debug("listConnectionURIs() called");
Dataset rdfDataset;
HttpHeaders headers = new HttpHeaders();
Integer preferedSize = getPreferredSize(request);
try {
// even when the timestamp is not provided (null), we need to fix the time (if
// null, then to current),
// because we will return prev/next links which make no sense if the time is not
// fixed
DateParameter dateParam = new DateParameter(timestamp);
String passableMap = getPassableQueryMap("timeof", dateParam.getTimestamp(), "deep", Boolean.toString(deep));
// paging, return everything:
if (preferedSize == null && modifiedAfter == null) {
// all connections; does not support date filtering for clients that do not
// support paging
rdfDataset = linkedDataService.listConnectionURIs(deep);
} else if (modifiedAfter != null) {
// paging is not implemented for modified connections for now!
rdfDataset = linkedDataService.listModifiedConnectionURIsAfter(new DateParameter(modifiedAfter).getDate(), deep);
} else if (page != null) {
// return latest by the given timestamp
NeedInformationService.PagedResource<Dataset, URI> resource = linkedDataService.listConnectionURIs(page, preferedSize, dateParam.getDate(), deep);
rdfDataset = resource.getContent();
addPagedResourceInSequenceHeader(headers, URI.create(this.connectionResourceURIPrefix), resource, page, passableMap);
// resume before parameter specified - display the connections with activities
// before the specified event id
} else if (beforeId == null && afterId == null) {
// return latest by the given timestamp
NeedInformationService.PagedResource<Dataset, URI> resource = linkedDataService.listConnectionURIs(1, preferedSize, dateParam.getDate(), deep);
rdfDataset = resource.getContent();
addPagedResourceInSequenceHeader(headers, URI.create(this.connectionResourceURIPrefix), resource, passableMap);
// resume before parameter specified - display the connections with activities
// before the specified event id
} else {
if (beforeId != null) {
URI resumeConnURI = uriService.createConnectionURIForId(beforeId);
NeedInformationService.PagedResource<Dataset, URI> resource = linkedDataService.listConnectionURIsBefore(resumeConnURI, preferedSize, dateParam.getDate(), deep);
rdfDataset = resource.getContent();
addPagedResourceInSequenceHeader(headers, URI.create(this.connectionResourceURIPrefix), resource, passableMap);
// 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(resumeConnURI, preferedSize, dateParam.getDate(), deep);
rdfDataset = resource.getContent();
addPagedResourceInSequenceHeader(headers, URI.create(this.connectionResourceURIPrefix), resource, passableMap);
}
}
} catch (ParseException e) {
logger.warn("could not parse timestamp into Date:{}", timestamp);
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);
}
addLocationHeaderIfNecessary(headers, URI.create(request.getRequestURI()), URI.create(this.connectionResourceURIPrefix));
addMutableResourceHeaders(headers);
addCORSHeader(headers);
return new ResponseEntity<>(rdfDataset, headers, HttpStatus.OK);
}
use of won.protocol.exception.NoSuchConnectionException 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.NoSuchConnectionException 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";
}
}
Aggregations