package example; import gr.forth.ics.rdfsuite.services.Data; import gr.forth.ics.rdfsuite.services.Deps; import gr.forth.ics.rdfsuite.services.Format; import gr.forth.ics.rdfsuite.services.RdfDocument; import gr.forth.ics.rdfsuite.services.VersionManager; import gr.forth.ics.rdfsuite.services.VersionedUri; import gr.forth.ics.rdfsuite.services.util.IOUtils; import gr.forth.ics.swkmclient.Client; import gr.forth.ics.swkmclient.ClientFactory; import java.io.File; import java.util.Arrays; import java.util.Collections; import java.util.Map; public class VersioningExample { public static void main(String[] args) { //Create a client by reading services.properties from classpath //and using the default database configuration of the server Client c = ClientFactory.newClientByConfiguration().withDefaultSettings(); //Start with a clean database, for demonstration purposes. //Of course, this functionality can be disabled through configuration c.debug().eraseDatabase(); RdfDocument firstVersion = new RdfDocument("http://example.org#", IOUtils.readFileAsString(new File("data/diff/AddClass1_a.rdf")), Format.RDF_XML); //Get a handle to the VersionManager interface VersionManager vm = c.versionManager(); //Store the first version. It has no parents. VersionedUri v1 = vm.importVersion(firstVersion, Collections.emptySet()); RdfDocument secondVersion = new RdfDocument("http://example.org#", IOUtils.readFileAsString(new File("data/diff/AddClass1_b.rdf")), Format.RDF_XML); //Store the second version. It is marked as a subsequent (child) version of the previous one. VersionedUri v2 = vm.importVersion(secondVersion, Arrays.asList(v1)); //Get both versions through the Exporter service Map docs = c.exporter().fetch( Arrays.asList(v1.toString(), v2.toString()), Format.TRIG, Deps.WITHOUT, Data.WITHOUT); //Simply print the URIs of the documents. They should be: //http://example.org~_~1# //http://example.org~_~2# System.out.println(docs.keySet()); } }