use of won.protocol.message.WonMessageType in project webofneeds by researchstudio-sat.
the class LinkedDataWebController method readConnectionsOfAtom.
/**
* Get the RDF for the connections of the specified atom.
*
* @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 resumeBefore taken into account only if client supports paging; in
* that case the page with connections URIs that precede the connection having
* resumeBefore is returned
* @param resumeAfter taken into account only if client supports paging; in that
* case the page with connections URIs that follow the connection having
* resumeAfter 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}/atom/{identifier}/c", method = RequestMethod.GET, produces = { "application/ld+json", "application/trig", "application/n-quads" })
public ResponseEntity<Dataset> readConnectionsOfAtom(HttpServletRequest request, HttpServletResponse response, @PathVariable(value = "identifier") String identifier, @RequestParam(value = "socket", required = false) String socket, @RequestParam(value = "targetSocket", required = false) String targetSocket, @RequestParam(value = "deep", defaultValue = "false") boolean deep, @RequestParam(value = "p", required = false) Integer page, @RequestParam(value = "resumebefore", required = false) String resumeBefore, @RequestParam(value = "resumeafter", required = false) String resumeAfter, @RequestParam(value = "type", required = false) String type, @RequestParam(value = "timeof", required = false) String timestamp, @RequestParam(value = "state", required = false) String state) {
logger.debug("readConnectionsOfAtom() called");
// TODO: pass aclevaluator and operationRequest down to linkeddataservice as an
// additional filter
URI atomUri = uriService.createAtomURIForId(identifier);
Dataset rdfDataset;
HttpHeaders headers = new HttpHeaders();
Integer preferedSize = getPreferredSize(request);
URI connectionsURI = URI.create(atomUri.toString() + "/c");
try {
ConnectionState connectionState = getConnectionState(state);
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 (socket != null && targetSocket != null) {
rdfDataset = linkedDataService.listConnection(URI.create(socket), URI.create(targetSocket), deep);
} else if (preferedSize == null) {
// does not support date and type filtering for clients that do not support
// paging
rdfDataset = linkedDataService.listConnections(atomUri, deep, true, connectionState).getContent();
// if no page or resume parameter is specified, display the latest connections:
} else if (page == null && resumeBefore == null && resumeAfter == null) {
AtomInformationService.PagedResource<Dataset, Connection> resource = linkedDataService.listConnections(1, atomUri, preferedSize, eventsType, dateParam.getDate(), deep, true, connectionState);
rdfDataset = resource.getContent();
addPagedConnectionResourceInSequenceHeader(headers, connectionsURI, resource, passableQuery);
} else if (page != null) {
AtomInformationService.PagedResource<Dataset, Connection> resource = linkedDataService.listConnections(page, atomUri, preferedSize, eventsType, dateParam.getDate(), deep, true, connectionState);
rdfDataset = resource.getContent();
addPagedConnectionResourceInSequenceHeader(headers, connectionsURI, resource, page, passableQuery);
} else {
// before the specified event id:
if (resumeBefore != null) {
URI resumeConnURI;
try {
resumeConnURI = new URI(resumeBefore);
} catch (URISyntaxException e) {
throw new IllegalArgumentException("resumeBefore must be a full, valid connection URI");
}
AtomInformationService.PagedResource<Dataset, Connection> resource = linkedDataService.listConnectionsAfter(atomUri, resumeConnURI, preferedSize, eventsType, dateParam.getDate(), deep, true, connectionState);
rdfDataset = resource.getContent();
addPagedConnectionResourceInSequenceHeader(headers, connectionsURI, resource, passableQuery);
// resume after parameter specified - display the connections with activities
// after the specified event id:
} else {
// if (resumeAfter != null)
URI resumeConnURI;
try {
resumeConnURI = new URI(resumeAfter);
} catch (URISyntaxException e) {
throw new IllegalArgumentException("resumeAfter must be a full, valid connection URI");
}
AtomInformationService.PagedResource<Dataset, Connection> resource = linkedDataService.listConnectionsBefore(atomUri, resumeConnURI, preferedSize, eventsType, dateParam.getDate(), deep, true, connectionState);
rdfDataset = resource.getContent();
addPagedConnectionResourceInSequenceHeader(headers, connectionsURI, resource, passableQuery);
}
}
WonAclEvalContext ec = WonAclRequestHelper.getWonAclEvaluationContext(request);
// check if the dataset contains any connections
if (ec.isModeFilter() && !RdfUtils.toStatementStream(rdfDataset).anyMatch(p -> p.getPredicate().equals(RDFS.member))) {
// the dataset may be empty because no connections are allowed
// we don't have a position for all connections in the ACL, so we say: if the
// user
// is allowed to see the top level, we show the empty container, otherwise deny
OperationRequest or = ec.getOperationRequest();
or.setReqPosition(POSITION_ROOT);
AclEvalResult result = ec.decideAndRemember(or);
if (ACCESS_DENIED.equals(result.getDecision())) {
int statusCode = HttpStatus.FORBIDDEN.value();
Optional<AclEvalResult> accResult = WonAclRequestHelper.getWonAclEvaluationContext(request).getCombinedResults();
if (accResult.isPresent()) {
WonAclRequestHelper.setAuthInfoAsResponseHeader(response, accResult.get());
statusCode = WonAclRequestHelper.getHttpStatusCodeForAclEvaluationResult(accResult.get());
}
HttpStatus status = HttpStatus.valueOf(statusCode);
logger.debug("sending status {}", status);
// append the required headers
addMutableResourceHeaders(headers);
addLocationHeaderIfNecessary(headers, URI.create(request.getRequestURI()), connectionsURI);
return new ResponseEntity<>(null, headers, status);
}
}
// 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 (NoSuchAtomException e) {
logger.warn("did not find atom {}", e.getUnknownAtomURI());
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
} catch (NoSuchConnectionException e) {
logger.warn("did not find connection that should be connected to atom. connection:{}", e.getUnknownConnectionURI());
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
}
}
use of won.protocol.message.WonMessageType in project webofneeds by researchstudio-sat.
the class IsResponseMessagePredicate method matches.
@Override
public boolean matches(final Exchange exchange) {
WonMessage wonMessage = (WonMessage) exchange.getIn().getHeader(WonCamelConstants.MESSAGE_HEADER);
WonMessageType messageType = wonMessage.getMessageType();
switch(messageType) {
case SUCCESS_RESPONSE:
return true;
case FAILURE_RESPONSE:
return true;
}
return false;
}
use of won.protocol.message.WonMessageType in project webofneeds by researchstudio-sat.
the class FailureResponseFromExternalProcessor method process.
public void process(final Exchange exchange) throws Exception {
WonMessage responseMessage = getMessageRequired(exchange);
assert responseMessage != null : "wonMessage header must not be null";
WonMessageType responseToType = responseMessage.getRespondingToMessageType();
// TODO: forward to owners and delete delivery chain
logger.warn("TODO: forward to owners and delete the whole delivery chain");
if (WonMessageType.CONNECT.equals(responseToType)) {
// TODO: define what to do if the connect fails remotely option: create a system
// message of type CLOSE,
// and forward it only to the owner. Add an explanation (a reference to the
// failure response and some
// expplanation text.
logger.warn("The remote end responded with a failure message. Our behaviour is now undefined.");
}
}
use of won.protocol.message.WonMessageType in project webofneeds by researchstudio-sat.
the class LinkedDataWebController method showConnectionEventsPage.
// webmvc controller method
@RequestMapping("${uri.path.page}/atom/{atomId}/c/{identifier}/msg")
public String showConnectionEventsPage(@PathVariable String atomId, @PathVariable String identifier, @RequestParam(value = "p", required = false) Integer page, @RequestParam(value = "resumebefore", required = false) String resumeBefore, @RequestParam(value = "resumeafter", required = false) String resumeAfter, @RequestParam(value = "type", required = false) String type, @RequestParam(value = "deep", required = false, defaultValue = "false") boolean deep, Model model, HttpServletRequest request, HttpServletResponse response) {
try {
URI connectionURI = uriService.createConnectionURIForId(atomId, identifier);
String eventsURI = connectionURI.toString() + "/msg";
Dataset rdfDataset;
WonMessageType msgType = getMessageType(type);
if (page == null && resumeBefore == null && resumeAfter == null) {
// all events, does not support type filtering for clients that do not support
// paging
rdfDataset = linkedDataService.listConnectionEventURIs(connectionURI, deep);
} else if (page != null) {
// a page having particular page number is requested
AtomInformationService.PagedResource<Dataset, URI> resource = linkedDataService.listConnectionEventURIs(connectionURI, page, null, msgType, deep);
rdfDataset = resource.getContent();
} else if (resumeBefore != null) {
// a page that precedes the item identified by the resumeBefore is requested
URI referenceEvent;
try {
referenceEvent = new URI(resumeBefore);
} catch (URISyntaxException e) {
throw new IllegalArgumentException("resumeBefore must be a full, valid message URI");
}
AtomInformationService.PagedResource<Dataset, URI> resource = linkedDataService.listConnectionEventURIsAfter(connectionURI, referenceEvent, null, msgType, deep);
rdfDataset = resource.getContent();
} else {
// a page that follows the item identified by the resumeAfter is requested
URI referenceEvent;
try {
referenceEvent = new URI(resumeAfter);
} catch (URISyntaxException e) {
throw new IllegalArgumentException("resumeAfter must be a full, valid message URI");
}
AtomInformationService.PagedResource<Dataset, URI> resource = linkedDataService.listConnectionEventURIsBefore(connectionURI, referenceEvent, null, msgType, deep);
rdfDataset = resource.getContent();
}
model.addAttribute("rdfDataset", rdfDataset);
model.addAttribute("resourceURI", eventsURI);
model.addAttribute("dataURI", uriService.toDataURIIfPossible(URI.create(eventsURI)).toString());
return "rdfDatasetView";
} catch (NoSuchConnectionException e) {
response.setStatus(HttpServletResponse.SC_NOT_FOUND);
return "notFoundView";
}
}
use of won.protocol.message.WonMessageType in project webofneeds by researchstudio-sat.
the class SocketTypeSlipComputer method evaluate.
@Override
public <T> T evaluate(final Exchange exchange, final Class<T> type) {
WonMessage message = WonCamelHelper.getMessageRequired(exchange);
assert message != null : "wonMessage header must not be null";
// exchange.getIn().setHeader();
WonMessageType messageType = WonCamelHelper.getMessageTypeRequired(exchange);
assert messageType != null : "messageType header must not be null";
WonMessageDirection direction = WonCamelHelper.getDirectionRequired(exchange);
if (direction.isFromSystem()) {
direction = WonMessageDirection.FROM_OWNER;
}
assert direction != null : "direction header must not be null";
URI socketType = WonCamelHelper.getSocketTypeURIRequired(exchange);
String slip = "bean:" + computeSocketSlip(messageType.getURI(), socketType, direction.getURI()) + "?method=process";
return type.cast(slip);
}
Aggregations