use of won.protocol.message.WonMessageType in project webofneeds by researchstudio-sat.
the class ShouldCallSocketImplForMessagePredicate 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 DEACTIVATE:
return false;
case ACTIVATE:
return false;
case DELETE:
return false;
case CREATE_ATOM:
return false;
case REPLACE:
return false;
case CHANGE_NOTIFICATION:
return false;
default:
break;
}
return true;
}
use of won.protocol.message.WonMessageType 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.message.WonMessageType in project webofneeds by researchstudio-sat.
the class ShouldCallFacetImplForMessagePredicate 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 DEACTIVATE:
return false;
case ACTIVATE:
return false;
case CREATE_NEED:
return false;
case SUCCESS_RESPONSE:
return false;
case FAILURE_RESPONSE:
return false;
}
return true;
}
use of won.protocol.message.WonMessageType in project webofneeds by researchstudio-sat.
the class PersistingWonMessageProcessor method loadOrCreateEventContainer.
private EventContainer loadOrCreateEventContainer(final WonMessage wonMessage, final URI parent) {
WonMessageType type = wonMessage.getMessageType();
if (WonMessageType.CREATE_NEED.equals(type)) {
// create a need event container with null parent (because it will only be persisted at a later point in time)
EventContainer container = needEventContainerRepository.findOneByParentUriForUpdate(parent);
if (container != null)
return container;
NeedEventContainer nec = new NeedEventContainer(null, parent);
needEventContainerRepository.saveAndFlush(nec);
return nec;
} else if (WonMessageType.CONNECT.equals(type) || WonMessageType.HINT_MESSAGE.equals(type)) {
// create a connection event container witn null parent (because it will only be persisted at a later point in
// time)
EventContainer container = connectionEventContainerRepository.findOneByParentUriForUpdate(parent);
if (container != null)
return container;
ConnectionEventContainer cec = new ConnectionEventContainer(null, parent);
connectionEventContainerRepository.saveAndFlush(cec);
return cec;
}
EventContainer container = needEventContainerRepository.findOneByParentUriForUpdate(parent);
if (container != null)
return container;
container = connectionEventContainerRepository.findOneByParentUriForUpdate(parent);
if (container != null)
return container;
// let's see if we can find the event conta
throw new IllegalArgumentException("Cannot store '" + type + "' event '" + wonMessage.getMessageURI() + "': unable to find " + "event container with parent URI '" + parent + "'");
}
use of won.protocol.message.WonMessageType in project webofneeds by researchstudio-sat.
the class LinkedDataWebController method showConnectionURIListPage.
// webmvc controller method
@RequestMapping("${uri.path.page}/atom/{identifier}/c")
public String showConnectionURIListPage(@PathVariable String identifier, @RequestParam(value = "p", required = false) Integer page, @RequestParam(value = "deep", defaultValue = "false") boolean deep, @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, HttpServletRequest request, Model model, HttpServletResponse response) {
URI atomURI = uriService.createAtomURIForId(identifier);
try {
// TODO: post-filter returned connections
ConnectionState connectionState = getConnectionState(state);
DateParameter dateParam = new DateParameter(timestamp);
WonMessageType eventsType = getMessageType(type);
Dataset rdfDataset;
if (page != null) {
rdfDataset = linkedDataService.listConnections(page, atomURI, null, eventsType, dateParam.getDate(), deep, true, connectionState).getContent();
} else if (resumeBefore != null) {
URI connURI;
try {
connURI = new URI(resumeBefore);
} catch (URISyntaxException e) {
throw new IllegalArgumentException("resumeBefore must be a full, valid connection URI");
}
rdfDataset = linkedDataService.listConnectionsAfter(atomURI, connURI, null, eventsType, dateParam.getDate(), deep, true, connectionState).getContent();
} else if (resumeAfter != null) {
URI connURI;
try {
connURI = new URI(resumeAfter);
} catch (URISyntaxException e) {
throw new IllegalArgumentException("resumeAfter must be a full, valid connection URI");
}
rdfDataset = linkedDataService.listConnectionsBefore(atomURI, connURI, null, eventsType, dateParam.getDate(), deep, true, connectionState).getContent();
} else {
// all the connections of the atom; does not support type and date filtering for
// clients that do not support
// paging
rdfDataset = linkedDataService.listConnections(atomURI, deep, true, connectionState).getContent();
}
model.addAttribute("rdfDataset", rdfDataset);
model.addAttribute("resourceURI", uriService.toResourceURIIfPossible(URI.create(request.getRequestURI())).toString());
model.addAttribute("dataURI", uriService.toDataURIIfPossible(URI.create(request.getRequestURI())).toString());
return "rdfDatasetView";
} catch (ParseException e) {
model.addAttribute("error", "could not parse timestamp parameter");
return "notFoundView";
} catch (NoSuchAtomException e) {
response.setStatus(HttpServletResponse.SC_NOT_FOUND);
return "notFoundView";
} catch (NoSuchConnectionException e) {
logger.warn("did not find connection that should be connected to atom. connection:{}", e.getUnknownConnectionURI());
// TODO: should display an error view
return "notFoundView";
}
}
Aggregations