# baseURI: http://extensionsamples.topbraid.org/config/CustomConfigExample.init

@prefix dash: <http://datashapes.org/dash#> .
@prefix exconf: <http://extensionsamples.topbraid.org/config/CustomConfigExample#> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix sh: <http://www.w3.org/ns/shacl#> .
@prefix tosh: <http://topbraid.org/tosh#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .

exconf:InstallMySettingsCustomization
  a tosh:InitScript ;
  dash:js """const customConfigShapes = graph.namedNode("http://extensionsamples.topbraid.org/config/CustomConfigExample.shapes")
const configGraphUri = graph.eval("tbladmin:systemConfigGraph()")
const graphMetadata = graph.namedNode(configGraphUri)
const owlImports = graph.namedNode({qname: 'owl:imports'})
graph.transaction(configGraphUri, "Installing customization", () => {
  // Import the custom shape into the config graph
  graphMetadata.add(owlImports, customConfigShapes)

  // Optional (not recommended): Set a default value for the setting.
  // A better way to provide a default value is to check for an
  // absent value when reading the setting, and fall back to a sensible
  // default value there.
  const instance = graph.namedNode("http://server.topbraidlive.org/web/2009/config#ConfigurationInstance");
  const setting = graph.namedNode("http://server.topbraidlive.org/web/2009/config#myCustomConfigurationOption");
  if(!instance.hasObject(setting)) {
    instance.add(setting, "Default value");
  }
})""" ;
  tosh:projectDeleteJS """const customConfigShapes = graph.namedNode("http://extensionsamples.topbraid.org/config/CustomConfigExample.shapes")
const configGraphUri = graph.eval("tbladmin:systemConfigGraph()")
const graphMetadata = graph.namedNode(configGraphUri)
const owlImports = graph.namedNode({qname: "owl:imports"})
const instance = graph.namedNode("http://server.topbraidlive.org/web/2009/config#ConfigurationInstance");
const setting = graph.namedNode("http://server.topbraidlive.org/web/2009/config#myCustomConfigurationOption");
graph.transaction(configGraphUri, "Uninstalling customization", () => {
	// Remove import of the custom shape from the config graph
	graphMetadata.remove(owlImports, customConfigShapes)
	// Delete any value of the custom configuration setting
	instance.remove(setting)
})""" ;
  rdfs:label "Install My Settings customization" ;
.
<http://extensionsamples.topbraid.org/custom-config-example.init>
  a owl:Ontology ;
  <http://topbraid.org/swa#defaultNamespace> "http://extensionsamples.topbraid.org/config/CustomConfigExample#" ;
  rdfs:label "Custom Configuration Example: Init file" ;
  owl:imports <http://datashapes.org/dash> ;
.
