1

I've been trying to create a new repository on a remote GraphDB server using RDF4J, but I'm having problems.

This runs, but is seemingly not correct

HTTPRepositoryConfig implConfig = new HTTPRepositoryConfig(address);
RepositoryConfig repoConfig = new RepositoryConfig("test", "test", implConfig);
Model m = new

However, based on the info I get from "edit repository" in the workbench, the result doesn't look right. All the values are empty, except for id and title.

This fails

I tried to copy the settings from an existing repository that I created on the workbench, but that failed with:

org.eclipse.rdf4j.repository.config.RepositoryConfigException: 
                         Unsupported repository type: owlim:MonitorRepository

The code for that attempt is inspired by the one found here . Except that the config file is based on an existing repo, as explained above. I also tried to config file provided in the example, but that failed aswell:

org.eclipse.rdf4j.repository.config.RepositoryConfigException: 
       Unsupported Sail type: graphdb:FreeSail

Anyone got any tips?

UPDATE As Henriette Harmse correctly pointed out, I should have provided my code, not simply linked to it. That way I might have discovered that I hadn't done a complete copy after all, but changed the important first bits that she points out in her answer. Full code below:

String address = "serveradr";
RemoteRepositoryManager repositoryManager = new RemoteRepositoryManager( address);
repositoryManager.initialize();

// Instantiate a repository graph model
TreeModel graph = new TreeModel();
InputStream config = Rdf4jHelper.class.getResourceAsStream("/repoconf2.ttl");
RDFParser rdfParser = Rio.createParser(RDFFormat.TURTLE);
rdfParser.setRDFHandler(new StatementCollector(graph));
rdfParser.parse(config, RepositoryConfigSchema.NAMESPACE);
config.close();

// Retrieve the repository node as a resource
Resource repositoryNode = graph.filter(null, RDF.TYPE, RepositoryConfigSchema.REPOSITORY).subjects().iterator().next();

// Create a repository configuration object and add it to the repositoryManager
RepositoryConfig repositoryConfig = RepositoryConfig.create(graph, repositoryNode);

It fails on the last line.

ANSWERED @HenrietteHarmse gives the correct method in her answer below. The error is caused by missing dependencies. Instead of using RDF4J directly, I should have used the graphdb-free-runtime.

  • Please add your complete code example and pom.xml files. The code at the link you provided can change, which will limit the benefit of your question to other SO users. – Henriette Harmse Apr 07 '18 at 09:01

2 Answers2

1

There are a number of issues here:

(1) RepositoryManager repositoryManager = new LocalRepositoryManager(new File(".")); will create a repository where ever your Java application is running from.

(2) Changing to new LocalRepositoryManager(new File("$GraphDBInstall/data/repositories")) will cause the repository to be created under the control of GraphDB (assuming you have a local GraphDB instance) only if GraphDB is not running. If you start GraphDB after running your program, you will be able to see the repository in GraphDB workbench.

(3) What you need to do is get the repository manager of the remote GraphDB, which can be done with RepositoryManager repositoryManager = RepositoryProvider.getRepositoryManager("http://IPAddressOfGraphDB:7200");.

(4) In the way you have specified the config, you cause the RDF graph config to be lost. The correct way to specify it is:

RepositoryConfig repositoryConfig = RepositoryConfig.create(graph, repositoryNode);
repositoryManager.addRepositoryConfig(repositoryConfig);

(5) A minor issue is that GraphUtil.getUniqueSubject(...) has been deprecated, for which you can use something like the following:

Model model = graph.filter(null, RDF.TYPE, RepositoryConfigSchema.REPOSITORY);
Iterator<Statement> iterator = model.iterator(); 
if (!iterator.hasNext()) 
   throw new RuntimeException("Oops, no <http://www.openrdf.org/config/repository#> subject found!");
Statement statement = iterator.next();
Resource repositoryNode =  statement.getSubject();

EDIT on 20180408:

(5) Or you can use the compact option as @JeenBroekstra suggested in the comments:

Models.subject(
    graph.filter(null, RDF.TYPE, RepositoryConfigSchema.REPOSITORY))
    .orElseThrow(() -> new RuntimeException("Oops, no <http://www.openrdf.org/config/repository#> subject found!")); 

EDIT on 20180409:

For convenience I have added the complete code example here.

EDIT on 20180410:

So the actual culprit turned out to be an incorrect pom.xml. The correct version is as below:

<dependency>
  <groupId>com.ontotext.graphdb</groupId>
  <artifactId>graphdb-free-runtime</artifactId>
  <version>8.4.1</version>
</dependency>
Henriette Harmse
  • 4,167
  • 1
  • 13
  • 22
  • 1
    Point 5 can be done in a single line of code, bit easier perhaps: `Resource repositoryNode = Models.subject(graph.filter(null, RDF.TYPE, RepositoryConfigSchema.REPOSITORY)).orElseThrow(() -> new RuntimeException("Oops, no subject found!"));` – Jeen Broekstra Apr 08 '18 at 00:53
  • I updated the question to include the actual code I use. This makes your points 1,2 and 3 solved. I use different code in 4, but using your line also makes it fail. I kept my uncool and not-production-ready way of getting the resource subject. – Seymoure Frye Apr 09 '18 at 03:07
  • It would be either be a problem with your `repoconfig2.ttl` file or your `pom.xml`. – Henriette Harmse Apr 09 '18 at 05:51
  • @SeymoureFrye For convenience I added a working complete config and code example. – Henriette Harmse Apr 09 '18 at 09:22
  • @HenrietteHarmse Thank you very much for helping me with this. I couldn't get your example to work, it fails in the same way as my code did: when trying to create a RepositoryConfig with the file you provided. Your file gave another but similar error: "Unsupported repository type: graphdb:FreeSailRepository". I managed to do what I wanted using the GraphDB rest API, using JSON and PUT instead of ttl and RDF4J. To see if it was my server causing the error, I moved your code about so that the RepositoryConfig creation was before any servers were mentioned. But the error was still there. – Seymoure Frye Apr 09 '18 at 11:45
  • What version of GraphDB are you using? What version is `pom.xml` pointing to? – Henriette Harmse Apr 09 '18 at 11:50
  • 1
    I was using org.eclipse.rdf4j/rdf4j-runtime-2.2-4 . And that was the culprit, as you suspected. I ran your program again with the correct POM and it worked. Thank you again! I should have checked your POM, and not only your code. As an aside, I failed to find mention of the graphdb-free-runtime in the GraphDB documentation. Nor did I find any downloadable examples with a POM file. The documentation only mentions RDF4J and links to javadoc for the latest version. If someone from Ontotext reads this, consider making that information easier to find. – Seymoure Frye Apr 10 '18 at 12:46
  • @SeymoureFrye I am glad we could eventually figure out the actual culprit! – Henriette Harmse Apr 10 '18 at 13:38
0

I believe I just had the same issue. I used the example code from GraphDB Free for running with RDF4J as a remote service and ran into the same exception as you (Unsupported Sail type: graphdb:FreeSail). Henriette Harmse's answer does not directly address this issue but one should follow the suggestions given there to avoid running into issues later. In addition, based on a look into the RDF4J code you need the following dependency in your pom.xml file (assuming GraphDB 8.5):

<dependency>
    <groupId>com.ontotext.graphdb</groupId>
    <artifactId>graphdb-free-runtime</artifactId>
    <version>8.5.0</version>
</dependency>

This seems to be because there is some kind of service loading going on with META-INF, which I frankly am not familiar with. Maybe someone can provide more details in the comments. The requirement for adding this dependency in also seems to be absent from the instructions, so if this works for you, please let me know. Others who followed the same steps we did should be able to resolve this issue as well then.

dnleng
  • 1
  • I have run the example code I provided again GraphDB 8.4.1 and 8.5.0 without any problems. Mind to share a full stacktrace of the problem? – Henriette Harmse Apr 10 '18 at 10:08
  • 1
    Your code works fine with the `pom.xml` you specified. However, if you use a dependency on rdf4j-runtime instead of graphdb-free-runtime, you end up with a org.eclipse.rdf4j.repository.config.RepositoryConfigException exception for "Unsupported repository type: graphdb:FreeSailRepository". The character limit prevents me from listing the stack trace in its entirety. – dnleng Apr 10 '18 at 11:46
  • Ok, that make sense. I suspected something like that, but with partial info it is difficult to guess what is missing. Hence, why I requested the `pom.xml`. – Henriette Harmse Apr 10 '18 at 11:53
  • @HenrietteHarmse, since I can't respond to your answer I'll do it here: When you copied my answer into your update you used an incorrect version number. The latest is 8.5.0. – dnleng Apr 11 '18 at 11:17