Search in sources :

Example 1 with NoSuchNeedException

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);
}
Also used : UnreadMessageInfoForNeed(won.protocol.model.unread.UnreadMessageInfoForNeed) Need(won.protocol.model.Need) Dataset(org.apache.jena.query.Dataset) Model(org.apache.jena.rdf.model.Model) Resource(org.apache.jena.rdf.model.Resource) NoSuchNeedException(won.protocol.exception.NoSuchNeedException) DataWithEtag(won.protocol.model.DataWithEtag) MessageEventPlaceholder(won.protocol.model.MessageEventPlaceholder) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with NoSuchNeedException

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

Example 3 with NoSuchNeedException

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);
    }
}
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 4 with NoSuchNeedException

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";
    }
}
Also used : NoSuchMessageException(org.springframework.context.NoSuchMessageException) NoSuchConnectionException(won.protocol.exception.NoSuchConnectionException) Dataset(org.apache.jena.query.Dataset) NoSuchNeedException(won.protocol.exception.NoSuchNeedException) URI(java.net.URI) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 5 with NoSuchNeedException

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*/
}
Also used : Need(won.protocol.model.Need) PrefixMapping(org.apache.jena.shared.PrefixMapping) Model(org.apache.jena.rdf.model.Model) Resource(org.apache.jena.rdf.model.Resource) ConnectionAlreadyExistsException(won.protocol.exception.ConnectionAlreadyExistsException) IllegalMessageForNeedStateException(won.protocol.exception.IllegalMessageForNeedStateException) NoSuchNeedException(won.protocol.exception.NoSuchNeedException)

Aggregations

NoSuchNeedException (won.protocol.exception.NoSuchNeedException)5 Dataset (org.apache.jena.query.Dataset)4 URI (java.net.URI)3 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)3 NoSuchConnectionException (won.protocol.exception.NoSuchConnectionException)3 Model (org.apache.jena.rdf.model.Model)2 Resource (org.apache.jena.rdf.model.Resource)2 NoSuchMessageException (org.springframework.context.NoSuchMessageException)2 HttpHeaders (org.springframework.http.HttpHeaders)2 ResponseEntity (org.springframework.http.ResponseEntity)2 Need (won.protocol.model.Need)2 ParseException (java.text.ParseException)1 PrefixMapping (org.apache.jena.shared.PrefixMapping)1 Transactional (org.springframework.transaction.annotation.Transactional)1 ConnectionAlreadyExistsException (won.protocol.exception.ConnectionAlreadyExistsException)1 IllegalMessageForNeedStateException (won.protocol.exception.IllegalMessageForNeedStateException)1 WonMessageType (won.protocol.message.WonMessageType)1 DataWithEtag (won.protocol.model.DataWithEtag)1 MessageEventPlaceholder (won.protocol.model.MessageEventPlaceholder)1 UnreadMessageInfoForNeed (won.protocol.model.unread.UnreadMessageInfoForNeed)1