Search in sources :

Example 6 with WonMessageType

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;
}
Also used : WonMessage(won.protocol.message.WonMessage) WonMessageType(won.protocol.message.WonMessageType)

Example 7 with WonMessageType

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);
    }
}
Also used : NeedInformationService(won.protocol.service.NeedInformationService) HttpHeaders(org.springframework.http.HttpHeaders) NoSuchConnectionException(won.protocol.exception.NoSuchConnectionException) Dataset(org.apache.jena.query.Dataset) WonMessageType(won.protocol.message.WonMessageType) URI(java.net.URI) ResponseEntity(org.springframework.http.ResponseEntity) NoSuchNeedException(won.protocol.exception.NoSuchNeedException) ParseException(java.text.ParseException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 8 with WonMessageType

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;
}
Also used : WonMessage(won.protocol.message.WonMessage) WonMessageType(won.protocol.message.WonMessageType)

Example 9 with WonMessageType

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 + "'");
}
Also used : WonMessageType(won.protocol.message.WonMessageType)

Example 10 with WonMessageType

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";
    }
}
Also used : NoSuchConnectionException(won.protocol.exception.NoSuchConnectionException) Dataset(org.apache.jena.query.Dataset) NoSuchAtomException(won.protocol.exception.NoSuchAtomException) WonMessageType(won.protocol.message.WonMessageType) ConnectionState(won.protocol.model.ConnectionState) URISyntaxException(java.net.URISyntaxException) ParseException(java.text.ParseException) URI(java.net.URI) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

WonMessageType (won.protocol.message.WonMessageType)20 URI (java.net.URI)12 WonMessage (won.protocol.message.WonMessage)9 Dataset (org.apache.jena.query.Dataset)6 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)6 NoSuchConnectionException (won.protocol.exception.NoSuchConnectionException)6 URISyntaxException (java.net.URISyntaxException)4 ParseException (java.text.ParseException)3 HttpHeaders (org.springframework.http.HttpHeaders)3 ResponseEntity (org.springframework.http.ResponseEntity)3 AtomInformationService (won.node.service.persistence.AtomInformationService)3 Connection (won.protocol.model.Connection)3 StopWatch (org.springframework.util.StopWatch)2 NoSuchAtomException (won.protocol.exception.NoSuchAtomException)2 WonMessageProcessingException (won.protocol.exception.WonMessageProcessingException)2 ConnectionState (won.protocol.model.ConnectionState)2 NeedInformationService (won.protocol.service.NeedInformationService)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 NoSuchProviderException (java.security.NoSuchProviderException)1