Package org.openrdf.repository.event.base

Examples of org.openrdf.repository.event.base.InterceptingRepositoryConnectionWrapper


        Repository triples = new SailRepository(new MemoryStore());
        triples.initialize();

        InterceptingRepositoryConnection con =
                new InterceptingRepositoryConnectionWrapper(triples,triples.getConnection());

        con.addRepositoryConnectionInterceptor(new RepositoryConnectionInterceptorAdapter() {
            @Override
            public boolean add(RepositoryConnection conn, Resource s, org.openrdf.model.URI p, Value o, Resource... contexts) {
                if(s instanceof org.openrdf.model.URI) {
                    // if s is a URI and subject a KiWiUriResource, return true if they are different
                    return !((org.openrdf.model.URI)s).stringValue().equals(resource.stringValue());
                } else {
                    // in all other cases, return true to filter out the triple
                    return true;
                }
            };

            @Override
            public boolean remove(RepositoryConnection conn, Resource s, org.openrdf.model.URI p, Value o, Resource... contexts) {
                if(s instanceof org.openrdf.model.URI) {
                    // if s is a URI and subject a KiWiUriResource, return true if they are different
                    return !((org.openrdf.model.URI)s).stringValue().equals(resource.stringValue());
                } else {
                    // in all other cases, return true to filter out the triple
                    return true;
                }
            }
        });



        con.add(in,resource.stringValue(),format);
        con.commit();
        con.close();

        return triples;

    }
View Full Code Here


     * @HTTP 404 resource or resource metadata not found
     */
    @DELETE
    public Response deleteMetaRemote(@QueryParam("uri") @NotNull String uri) throws UnsupportedEncodingException {
        try {
            InterceptingRepositoryConnection connection = new InterceptingRepositoryConnectionWrapper(sesameService.getRepository(), sesameService.getConnection());
            connection.begin();
            final Resource subject = connection.getValueFactory().createURI(uri);

            try {
                connection.addRepositoryConnectionInterceptor(new ResourceSubjectMetadata(subject));

                // delete all triples for given subject
                connection.remove(subject,null,null);

                return Response.ok().build();
            } finally {
                connection.commit();
                connection.close();
            }

        } catch (RepositoryException e) {
            return ResourceWebServiceHelper.buildErrorPage(uri, configurationService.getBaseUri(), Status.INTERNAL_SERVER_ERROR, e.getMessage(), configurationService, templatingService);
        }
View Full Code Here

            if (request.getContentLength() == 0)
                return ResourceWebServiceHelper.buildErrorPage(uri, configurationService.getBaseUri(), Status.BAD_REQUEST, "content may not be empty in resource update", configurationService, templatingService);

            // a intercepting connection that filters out all triples that have
            // the wrong subject
            InterceptingRepositoryConnection connection = new InterceptingRepositoryConnectionWrapper(sesameService.getRepository(), sesameService.getConnection());
            //RepositoryConnection connection = sesameService.getConnection();
            try {
                connection.begin();
                final Resource subject = connection.getValueFactory().createURI(uri);

                connection.addRepositoryConnectionInterceptor(new ResourceSubjectMetadata(subject));

                // delete all triples for given subject
                connection.remove(subject, null, null, (Resource)null);

                // add RDF data from input to the suject
                connection.add(request.getReader(), configurationService.getBaseUri(), parser, contextService.getDefaultContext());
            } finally {
                connection.commit();
                connection.close();
            }
            return Response.ok().build();
        } catch (RepositoryException e) {
            return ResourceWebServiceHelper.buildErrorPage(uri, configurationService.getBaseUri(), Status.INTERNAL_SERVER_ERROR, e.getMessage(), configurationService, templatingService);
        } catch (IOException e) {
View Full Code Here

    public List<String> parseResponse(final String resourceUri, String requestUrl, Repository triples, InputStream in, String contentType) throws DataRetrievalException {
        RDFFormat format = RDFParserRegistry.getInstance().getFileFormatForMIMEType(contentType, RDFFormat.RDFXML);

        try {
            InterceptingRepositoryConnection con =
                    new InterceptingRepositoryConnectionWrapper(triples,triples.getConnection());

            con.addRepositoryConnectionInterceptor(new RepositoryConnectionInterceptorAdapter() {
                @Override
                public boolean add(RepositoryConnection conn, Resource s, org.openrdf.model.URI p, Value o, Resource... contexts) {
                    if(s instanceof org.openrdf.model.URI) {
                        // if s is a URI and subject a KiWiUriResource, return true if they are different
                        return !s.stringValue().equals(resourceUri);
                    } else {
                        // in all other cases, return true to filter out the triple
                        return true;
                    }
                };

                @Override
                public boolean remove(RepositoryConnection conn, Resource s, org.openrdf.model.URI p, Value o, Resource... contexts) {
                    if(s instanceof org.openrdf.model.URI) {
                        // if s is a URI and subject a KiWiUriResource, return true if they are different
                        return !s.stringValue().equals(resourceUri);
                    } else {
                        // in all other cases, return true to filter out the triple
                        return true;
                    }
                }
            });

            con.add(in, resourceUri,format);
            con.commit();
            con.close();

            return Collections.emptyList();
        } catch (RepositoryException e) {
            throw new DataRetrievalException("error while initializing temporary RDF store",e);
        } catch (RDFParseException e) {
View Full Code Here

     * @HTTP 404 resource or resource metadata not found
     */
    @DELETE
    public Response deleteMetaRemote(@QueryParam("uri") @NotNull String uri) throws UnsupportedEncodingException, HttpErrorException {
        try {
            InterceptingRepositoryConnection connection = new InterceptingRepositoryConnectionWrapper(sesameService.getRepository(), sesameService.getConnection());
            connection.begin();
            final Resource subject = connection.getValueFactory().createURI(uri);

            try {
                connection.addRepositoryConnectionInterceptor(new ResourceSubjectMetadata(subject));

                // delete all triples for given subject
                connection.remove(subject, null, null);

                return Response.ok().build();
            } finally {
                connection.commit();
                connection.close();
            }

        } catch (RepositoryException e) {
            throw new HttpErrorException(Status.INTERNAL_SERVER_ERROR, uri, e.getMessage());
        }
View Full Code Here

                throw new HttpErrorException(Status.BAD_REQUEST, uri, "content may not be empty in resource update");
            }

            // a intercepting connection that filters out all triples that have
            // the wrong subject
            InterceptingRepositoryConnection connection = new InterceptingRepositoryConnectionWrapper(sesameService.getRepository(), sesameService.getConnection());
            //RepositoryConnection connection = sesameService.getConnection();
            try {
                connection.begin();
                final Resource subject = connection.getValueFactory().createURI(uri);

                connection.addRepositoryConnectionInterceptor(new ResourceSubjectMetadata(subject));

                // delete all triples for given subject
                connection.remove(subject, null, null, (Resource) null);

                // add RDF data from input to the suject
                connection.add(request.getReader(), configurationService.getBaseUri(), parser, contextService.getDefaultContext());
            } finally {
                connection.commit();
                connection.close();
            }
            return Response.ok().build();
        } catch (URISyntaxException e) {
            throw new HttpErrorException(Status.INTERNAL_SERVER_ERROR, uri, "invalid target context");
        } catch (IOException | RDFParseException e) {
View Full Code Here

        Repository triples = new SailRepository(new MemoryStore());
        triples.initialize();

        InterceptingRepositoryConnection con =
                new InterceptingRepositoryConnectionWrapper(triples,triples.getConnection());

        con.addRepositoryConnectionInterceptor(new RepositoryConnectionInterceptorAdapter() {
            @Override
            public boolean add(RepositoryConnection conn, Resource s, org.openrdf.model.URI p, Value o, Resource... contexts) {
                if(s instanceof org.openrdf.model.URI) {
                    // if s is a URI and subject a KiWiUriResource, return true if they are different
                    return !((org.openrdf.model.URI)s).stringValue().equals(resource.stringValue());
                } else {
                    // in all other cases, return true to filter out the triple
                    return true;
                }
            };

            @Override
            public boolean remove(RepositoryConnection conn, Resource s, org.openrdf.model.URI p, Value o, Resource... contexts) {
                if(s instanceof org.openrdf.model.URI) {
                    // if s is a URI and subject a KiWiUriResource, return true if they are different
                    return !((org.openrdf.model.URI)s).stringValue().equals(resource.stringValue());
                } else {
                    // in all other cases, return true to filter out the triple
                    return true;
                }
            }
        });



        con.add(in,resource.stringValue(),format);
        con.commit();
        con.close();

        return triples;

    }
View Full Code Here

     * @HTTP 404 resource or resource metadata not found
     */
    @DELETE
    public Response deleteMetaRemote(@QueryParam("uri") @NotNull String uri) throws UnsupportedEncodingException {
        try {
            InterceptingRepositoryConnection connection = new InterceptingRepositoryConnectionWrapper(sesameService.getRepository(), sesameService.getConnection());
            connection.begin();
            final Resource subject = connection.getValueFactory().createURI(uri);

            try {
                connection.addRepositoryConnectionInterceptor(new ResourceSubjectMetadata(subject));

                // delete all triples for given subject
                connection.remove(subject,null,null);

                return Response.ok().build();
            } finally {
                connection.commit();
                connection.close();
            }

        } catch (RepositoryException e) {
            return ResourceWebServiceHelper.buildErrorPage(uri, configurationService.getBaseUri(), Status.INTERNAL_SERVER_ERROR, e.getMessage(), configurationService, templatingService);
        }
View Full Code Here

            if (request.getContentLength() == 0)
                return ResourceWebServiceHelper.buildErrorPage(uri, configurationService.getBaseUri(), Status.BAD_REQUEST, "content may not be empty in resource update", configurationService, templatingService);

            // a intercepting connection that filters out all triples that have
            // the wrong subject
            InterceptingRepositoryConnection connection = new InterceptingRepositoryConnectionWrapper(sesameService.getRepository(), sesameService.getConnection());
            //RepositoryConnection connection = sesameService.getConnection();
            try {
                connection.begin();
                final Resource subject = connection.getValueFactory().createURI(uri);

                connection.addRepositoryConnectionInterceptor(new ResourceSubjectMetadata(subject));

                // delete all triples for given subject
                connection.remove(subject, null, null, (Resource)null);

                // add RDF data from input to the suject
                connection.add(request.getReader(), configurationService.getBaseUri(), parser, contextService.getDefaultContext());
            } finally {
                connection.commit();
                connection.close();
            }
            return Response.ok().build();
        } catch (RepositoryException e) {
            return ResourceWebServiceHelper.buildErrorPage(uri, configurationService.getBaseUri(), Status.INTERNAL_SERVER_ERROR, e.getMessage(), configurationService, templatingService);
        } catch (IOException e) {
View Full Code Here

TOP

Related Classes of org.openrdf.repository.event.base.InterceptingRepositoryConnectionWrapper

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.