Search in sources :

Example 1 with ServiceRegistry

use of com.bigdata.rdf.sparql.ast.service.ServiceRegistry in project wikidata-query-rdf by wikimedia.

the class MWApiServiceFactory method register.

/**
 * Register the service so it is recognized by Blazegraph.
 */
public static void register(Timer requestTimer) {
    ServiceRegistry reg = ServiceRegistry.getInstance();
    try {
        Path path = Paths.get(CONFIG_FILE);
        log.info("Loading MWAPI service configuration from {}", path.toAbsolutePath());
        Reader configReader = Files.newBufferedReader(path, StandardCharsets.UTF_8);
        final ServiceConfig config = new ServiceConfig(configReader);
        reg.add(SERVICE_KEY, new MWApiServiceFactory(config, requestTimer));
        log.info("Registered {} services.", config.size());
    } catch (IOException e) {
        // Do not add to whitelist if init failed.
        log.warn("MW Service registration failed.", e);
        return;
    }
    reg.addWhitelistURL(SERVICE_KEY.toString());
}
Also used : Path(java.nio.file.Path) Reader(java.io.Reader) ServiceRegistry(com.bigdata.rdf.sparql.ast.service.ServiceRegistry) IOException(java.io.IOException)

Example 2 with ServiceRegistry

use of com.bigdata.rdf.sparql.ast.service.ServiceRegistry in project wikidata-query-rdf by wikimedia.

the class LabelService method register.

/**
 * Register the service so it is recognized by Blazegraph.
 */
public static void register() {
    final ServiceRegistry reg = ServiceRegistry.getInstance();
    reg.add(SERVICE_KEY, new LabelService());
    reg.addWhitelistURL(SERVICE_KEY.toString());
}
Also used : ServiceRegistry(com.bigdata.rdf.sparql.ast.service.ServiceRegistry)

Example 3 with ServiceRegistry

use of com.bigdata.rdf.sparql.ast.service.ServiceRegistry in project wikidata-query-rdf by wikimedia.

the class MWApiServiceFactory method register.

/**
 * Register the service so it is recognized by Blazegraph.
 */
public static void register() {
    ServiceRegistry reg = ServiceRegistry.getInstance();
    try {
        reg.add(SERVICE_KEY, new MWApiServiceFactory());
    } catch (IOException e) {
        // Do not add to whitelist if init failed.
        log.warn("MW Service registration failed.", e);
        return;
    }
    reg.addWhitelistURL(SERVICE_KEY.toString());
}
Also used : ServiceRegistry(com.bigdata.rdf.sparql.ast.service.ServiceRegistry) IOException(java.io.IOException)

Example 4 with ServiceRegistry

use of com.bigdata.rdf.sparql.ast.service.ServiceRegistry in project wikidata-query-rdf by wikimedia.

the class WikibaseContextListener method initializeServices.

/**
 * Initializes BG service setup to allow whitelisted services.
 * Also add additional custom services and functions.
 */
@VisibleForTesting
public void initializeServices() {
    MetricRegistry metricRegistry = createMetricRegistry();
    // Enable service whitelisting
    final ServiceRegistry reg = ServiceRegistry.getInstance();
    reg.setWhitelistEnabled(ENABLE_WHITELIST);
    LabelService.register();
    GeoService.register();
    MWApiServiceFactory.register(metricRegistry.timer(name(MWApiServiceCall.class, MW_API_REQUEST)));
    CategoriesStoredQuery.register();
    // Whitelist services we like by default
    reg.addWhitelistURL(GASService.Options.SERVICE_KEY.toString());
    reg.addWhitelistURL(ValuesServiceFactory.SERVICE_KEY.toString());
    reg.addWhitelistURL(BDS.SEARCH_IN_SEARCH.toString());
    reg.addWhitelistURL(SliceServiceFactory.SERVICE_KEY.toString());
    reg.addWhitelistURL(SampleServiceFactory.SERVICE_KEY.toString());
    loadWhitelist(reg);
    // Initialize remote services
    reg.setDefaultServiceFactory(getDefaultServiceFactory(metricRegistry.timer(name(RemoteServiceFactoryImpl.class, REMOTE_REQUEST))));
    // Override date functions so that we can handle them
    // via WikibaseDate
    FunctionRegistry.remove(FunctionRegistry.YEAR);
    FunctionRegistry.add(FunctionRegistry.YEAR, getWikibaseDateBOpFactory(DateOp.YEAR));
    FunctionRegistry.remove(FunctionRegistry.MONTH);
    FunctionRegistry.add(FunctionRegistry.MONTH, getWikibaseDateBOpFactory(DateOp.MONTH));
    FunctionRegistry.remove(FunctionRegistry.DAY);
    FunctionRegistry.add(FunctionRegistry.DAY, getWikibaseDateBOpFactory(DateOp.DAY));
    FunctionRegistry.remove(FunctionRegistry.HOURS);
    FunctionRegistry.add(FunctionRegistry.HOURS, getWikibaseDateBOpFactory(DateOp.HOURS));
    FunctionRegistry.remove(FunctionRegistry.MINUTES);
    FunctionRegistry.add(FunctionRegistry.MINUTES, getWikibaseDateBOpFactory(DateOp.MINUTES));
    FunctionRegistry.remove(FunctionRegistry.SECONDS);
    FunctionRegistry.add(FunctionRegistry.SECONDS, getWikibaseDateBOpFactory(DateOp.SECONDS));
    FunctionRegistry.remove(FunctionRegistry.NOW);
    FunctionRegistry.add(FunctionRegistry.NOW, (context, globals, scalarValues, args) -> {
        if (args != null && args.length > 0)
            throw new IllegalArgumentException("no args for NOW()");
        return new WikibaseNowBOp(globals);
    });
    // Geospatial distance function
    FunctionRegistry.add(new URIImpl(GeoSparql.FUNCTION_NAMESPACE + "distance"), getDistanceBOPFactory());
    // Geospatial functions
    FunctionRegistry.add(new URIImpl(GeoSparql.NORTH_EAST_FUNCTION), getCornersBOPFactory(WikibaseCornerBOp.Corners.NE));
    FunctionRegistry.add(new URIImpl(GeoSparql.SOUTH_WEST_FUNCTION), getCornersBOPFactory(WikibaseCornerBOp.Corners.SW));
    FunctionRegistry.add(new URIImpl(GeoSparql.GLOBE_FUNCTION), getCoordinatePartBOpFactory(CoordinatePartBOp.Parts.GLOBE));
    FunctionRegistry.add(new URIImpl(GeoSparql.LON_FUNCTION), getCoordinatePartBOpFactory(CoordinatePartBOp.Parts.LON));
    FunctionRegistry.add(new URIImpl(GeoSparql.LAT_FUNCTION), getCoordinatePartBOpFactory(CoordinatePartBOp.Parts.LAT));
    // wikibase:decodeUri
    FunctionRegistry.add(new URIImpl(Ontology.NAMESPACE + "decodeUri"), getDecodeUriBOpFactory());
    IsSomeValueFunctionFactory.SomeValueMode mode = IsSomeValueFunctionFactory.SomeValueMode.lookup(System.getProperty("wikibaseSomeValueMode", "blank"));
    UrisScheme uris = UrisSchemeFactory.getURISystem();
    registerIsSomeValueFunction(FunctionRegistry::add, mode, uris.wellKnownBNodeIRIPrefix());
    addPrefixes(uris);
    log.info("Wikibase services initialized.");
}
Also used : WikibaseNowBOp(org.wikidata.query.rdf.blazegraph.constraints.WikibaseNowBOp) FunctionRegistry(com.bigdata.rdf.sparql.ast.FunctionRegistry) RemoteServiceFactoryImpl(com.bigdata.rdf.sparql.ast.service.RemoteServiceFactoryImpl) IsSomeValueFunctionFactory(org.wikidata.query.rdf.blazegraph.constraints.IsSomeValueFunctionFactory) UrisScheme(org.wikidata.query.rdf.common.uri.UrisScheme) MetricRegistry(com.codahale.metrics.MetricRegistry) URIImpl(org.openrdf.model.impl.URIImpl) ServiceRegistry(com.bigdata.rdf.sparql.ast.service.ServiceRegistry) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 5 with ServiceRegistry

use of com.bigdata.rdf.sparql.ast.service.ServiceRegistry in project wikidata-query-rdf by wikimedia.

the class CategoriesStoredQuery method register.

/**
 * Register the service so it is recognized by Blazegraph.
 */
public static void register() {
    ServiceRegistry reg = ServiceRegistry.getInstance();
    reg.add(SERVICE_KEY, new CategoriesStoredQuery());
    reg.addWhitelistURL(SERVICE_KEY.toString());
}
Also used : ServiceRegistry(com.bigdata.rdf.sparql.ast.service.ServiceRegistry)

Aggregations

ServiceRegistry (com.bigdata.rdf.sparql.ast.service.ServiceRegistry)6 IOException (java.io.IOException)2 FunctionRegistry (com.bigdata.rdf.sparql.ast.FunctionRegistry)1 RemoteServiceFactoryImpl (com.bigdata.rdf.sparql.ast.service.RemoteServiceFactoryImpl)1 MetricRegistry (com.codahale.metrics.MetricRegistry)1 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Reader (java.io.Reader)1 Path (java.nio.file.Path)1 URIImpl (org.openrdf.model.impl.URIImpl)1 IsSomeValueFunctionFactory (org.wikidata.query.rdf.blazegraph.constraints.IsSomeValueFunctionFactory)1 WikibaseNowBOp (org.wikidata.query.rdf.blazegraph.constraints.WikibaseNowBOp)1 UrisScheme (org.wikidata.query.rdf.common.uri.UrisScheme)1