#Automatic syncing of data between Subversion, OSLC adapters and RDF triplestore
##Instructions to demo syncing scenario
Last updated by Axel Reichwein (axel.reichwein@koneksys.com) February 26, 2016
- In Windows Explorer, perform a checkout operation of the MagicDraw repository using Tortoise.
- In MagicDraw: Open MagicDraw model named Wired_Camera_Example from the local working directory which was just checked out
- In Eclipse: Launch MagicDraw adapter (Maven configuration named oslc adapter for magicDraw tomcat run)
- In Eclipse: Launch Simulink adapter (Maven configuration named oslc adapter for simulink)
- In Eclipse: Launch AMESim adapter (Maven configuration named oslc4jamesim-wink tomcat run)
- In Eclipse: In the folder named svn hook script, copy the post-commit.bat into the hooks folder of your svn repository. Example:
C:\apps\csvn\data\repositories\magicdrawrepository\hooks
. Edit the post-commit.bat file to refer to the appropriate adapter-specific service. Example for the OSLC MagicDraw adapter
http://localhost:8080/oslc4jmagicdraw/services/svnfilepublisher/republish
. This needs to be done for each repository that should be synced with a specific OSLC adapter such that a commit operation on a svn repository triggers the OSLC adapter to reconnect to the svn repo in order to retrieve any new updates 7. Specify the location of your triplestore in the config.properties file under edu.gatech.mbsec.triplestore.tdb.clients/configuration. As an example displayed below, the location of the triplestore is specified to be
C:\Users\Axel\git\triplestore\triplestore\mytriplestore5
Note: The file path can contain backslashes. Warning: Do not put quotes around the file path and add nothing at the end! 8. In Eclipse: In project triplestore in package tdb.clients.sync.magicdraw.withrevision, run Java application MagicDrawAdapterAndTDBSubversionSyncClientWithRevision.java 9. In Browser: have tabs already open with following URLs
- http://localhost:8080/oslc4jmagicdraw/services/svnfilepublisher
- http://localhost:8181/oslc4jsimulink/services/svnfilepublisher
- http://localhost:8282/oslc4jamesim/services/svnfilepublisher
- http://localhost:8080/oslc4jmagicdraw/services/catalog/singleton
- http://localhost:8181/oslc4jsimulink/services/catalog/singleton
- http://localhost:8282/oslc4jamesim/services/catalog/singleton
- postman client already with prerecorded request (in the history tab) for MagicDraw value property resource with Accept header equal to application/rdf+xmlRDF/XML and same request but with Accept header equal to application/json
####Demo OSLC adapters supporting Subversion
This demo refers to examples using OSLC MagicDraw SysML resources. However, the same demo can be performed for Simulink and AMESIm resources. Similar Java applications can be found for realizing this syncing scenario with Simulink and AMESim OSLC resources. The respective Java applications contain then Simulink or AMESim instead of MagicDraw in their name.
- In Browser: Show Subversion repository with MagicDraw files. Example: https://koneksys1:18080/svn/repository3/
- In Browser: Show revision of Subversion repository containing Magicdraw files
- In Browser: Show MagicDraw files published by MagicDraw adapter http://localhost:8080/oslc4jmagicdraw/services/subversionfiles
- In Browser: Show revision of a specific MagicDraw file published by MagicDraw adapter. Example: http://localhost:8080/oslc4jmagicdraw/services/subversionfiles/httpskoneksys118080svnmagicdrawrepository---Wired_Camera_Example.mdzip
- In MagicDraw: show value of a MagicDraw value property
- In Browser: show how you browse from OSLC Service Provider Catalog to a specific MagicDraw value property
- In Browser: show value of MagicDraw value property as OSLC resource in HTML format
- In Browser: show with postman rest client value of MagicDraw value property as OSLC resource in RDF/XML and JSON
- In Eclipse: In project triplestore, explain that your local triplestore (RDF database) is saved in the folder mytriplestore and that it can be queried using SPARQL, which is similar to SQL. Explain that the triplestore has been populated with the resources from the running OSLC adapter (step #6 in last section). Explain that you will perform a SPARQL query to retrieve the MagicDraw value property saved in the triplestore
- In Eclipse: In project triplestore in package tdb.clients.sync.magicdraw.withrevision, run Java application QueryTriplestoreForMagicDrawValuePropertyOfSpecificModelWithRevision.java and show value of MagicDraw value property saved in the triplestore in the Eclipse console window.
- Alternatively, n project triplestore in package tdb.clients.sync.magicdraw.withrevision, run Java application QueryTriplestoreForMagicDrawBlockOfSpecificModelWithRevision.java and show names of MagicDraw SysML blocks saved in the triplestore in the Eclipse console window.
####Demo automatic syncing between Subversion, adapters and triplestore
- In MagicDraw: change value of MagicDraw value property. Alternatively, or in addition, change the name of a SysML block.
- With your SVN client, perform a commit operation. Wait for logging statement indicating correct commit operation. If you do not have a SVN commit client, update and run the Java application MagicDrawCommitClient.java located in the edu.gatech.mbsec.subversion.client project of the subversion-client repository.
- In Browser: Show Subversion repository with MagicDraw files. Example: https://koneksys1:18080/svn/repository3/
- In Browser: Show revision of Subversion repository containing Magicdraw files. Revision number should be +1
- Wait for MagicDraw adapter to finish reloading files from Subversion server
- In Browser: Show revision of specific MagicDraw file published by MagicDraw adapter. Example: http://localhost:8080/oslc4jmagicdraw/services/subversionfiles/httpskoneksys118080svnmagicdrawrepository---Wired_Camera_Example.mdzip
- In Browser: show updated value of MagicDraw value property as OSLC resource in HTML format. Example: http://localhost:8080/oslc4jmagicdraw/services/httpswdxcnd519309s.jdnet.deere.comsvnmagicdrawrepository---Wired_Camera_Example/valueproperties/Blocks::Optical_Assembly::aperture. Alternatively, you can show the updated name of MagicDraw SysML block in HTML format. Example: http://localhost:8080/oslc4jmagicdraw/services/httpswdxcnd519309s.jdnet.deere.comsvnmagicdrawrepository---Wired_Camera_Example/blocks
- In Browser: show with postman rest client value of MagicDraw value property as OSLC resource in RDF/XML and JSON
- In Eclipse: In project triplestore in package tdb.clients.sync.magicdraw.withrevision, run Java application QueryTriplestoreForMagicDrawValuePropertyOfSpecificModelWithRevision.java and show value of MagicDraw value properties saved in the triplestore.
- In Eclipse: In project triplestore, open the file fuseki.bat in the text editor. Right-Click-> Open With... -> Text Editor. Edit the location of the triplestore in the batch file. Example:
--loc=C:\Users\Axel\git\triplestore-tdb-clients-jan26-2016\edu.gatech.mbsec.triplestore.tdb.clients\mytriplestore
. Run batch file named run fuseki.bat. Right-Click-> Open With... -> System Editor. 11. In browser, go to page http://localhost:3030/ 12. In Eclipse: In project triplestore, copy SPARQL query located in file get SysML value properties.txt in the folder example sparql queries 13. In browser, at page http://localhost:3030/, go to Query and enter SPARQL query text, and click on play. 14. Example: In Eclipse, in project triplestore, copy SPARQL query located in file get all sysml blocks.txt in the folder example sparql queries. Query results will display all MagicDraw SysML blocks saved in triplestore having revision numbers 15. Example: In Eclipse, in project triplestore, copy SPARQL query located in file get specific SysML value property.txt in the folder example sparql queries. Query results will display specific MagicDraw SysML value properties saved in triplestore having revision numbers
Note: after launching Fuseki, you can no longer perform SPARQL queries against the triplestore using the Java API. Every interaction with the triplestore has to go through the SPARQL HTTP endpoint of Fuseki.
#RDF Triplestore and SPARQL HTTP endpoint
##Instructions to install and run RDF triplestore and SPARQL HTTP endpoint
###1. Downloading the triplestore-tdb-clients repository
- Open the Git Repositories View (Window -> Show View -> type “Git Repositories” in the search field)
- Click on the Clone Repository icon
- In the URI field, paste the following URL: https://github.com/ld4mbse/triplestore-tdb-clients.git
- The Host and Repository fields will autofill.
- Click Next, only select the master branch
- Click Next until Finish.
###2. Importing the edu.gatech.mbsec.triplestore.tdb.clients project into the Eclipse workspace
- In the Git repositories view, right-click triplestore-tdb-clients and select “Import Projects”. Click Next until Finish. The edu.gatech.mbsec.triplestore.tdb.clients project will be in the Eclipse workspace.
- In Eclipse, open the Project Explorer view. (Window → Show View → Project Explorer)
- Expand the edu.gatech.mbsec.triplestore.tdb.clients project
- Right click pom.xml -> Run As -> Maven clean
- Right click pom.xml -> Run As -> Maven install
- If there is a red error mark next to the edu.gatech.mbsec.triplestore.tdb.clients project, select the project. Right-click->Maven->Update Project… and click OK
###3. Configuring triplestore location
- In Eclipse, open the Project Explorer view. (Window → Show View → Project Explorer). By default, it is already visible at the left of the screen.
- Select the just created edu.gatech.mbsec.triplestore.tdb.clients project and expand it
- Choose an empty folder as triplestore location, such as the mytriplestore folder located in the Eclipse edu.gatech.mbsec.triplestore.tdb.clients project. Your user account needs to have read/write permission to that folder.
- In the Project Explorer view, expand the triplestore Eclipse project, and expand the triplestore configuration folder
- Open the config.properties file
- Specify the location of the triplestore without trailing slash at the end, for example
triplestoreDirectory = C:/Users/Axel/git/triplestore/edu.gatech.mbsec.triplestore.tdb.clients/mytriplestore
###4. Creating triplestore
- In Eclipse, open the Project Explorer view. (Window → Show View → Project Explorer)
- Expand the edu.gatech.mbsec.triplestore.tdb.clients project
- Expand the src/main/java folder
- Expand the tbd.clients package
- Right click CreateTriplestore.java -> Run As -> Java Application
- In the console view, you should see the statement “Triplestore created”
- To manually verify that the triplestore was created, you can notice the addition of new files in your triplestore folder. If you are verifying the triplestore folder content in the Eclipse Project Explorer view, you may need to right-click on your triplestore folder, and click on Refresh before verifying its content.
- If you decide to later delete the triplestore and start from scratch, one option is to delete all the files in your triplestore folder and start off with a new empty triplestore folder.
###5. Populating triplestore with Simulink Blocks
- In Eclipse, open the Project Explorer view. (Window → Show View → Project Explorer)
- Expand the edu.gatech.mbsec.triplestore.tdb.clients project
- Expand the src/main/java folder
- 2 Options
- Option A: Populate triplestore with Simulink Blocks described as RDF on file (no need to run Simulink adapter) 1. Expand the tbd.clients package 2. Right click PopulateTriplestoreWithSimulinkBlocksAsRDF.java-> Run As -> Java Application (the sample RDF file is located in the folder named sample rdf)
- Option B: Populate triplestore with Simulink Blocks from running adapter
1. Run the OSLC Simulink Adapter as described in the Instructions to install and run the OSLC Simulink Adapter
2. 2 Options
3. Option B1: Retrieve Simulink Blocks from adapter and save them on file in RDF, and then populate triplestore based on RDF document
- Expand the adapter.clients package
- Right click GETSimulinkBlocksAndSaveAsRDF.java-> Run As -> Java Application
- In the console view, you should see the statement “Simulink blocks from adapter saved as RDF on file”
- Expand the tdb.clients package
- Right click PopulateTriplestoreWithSimulinkBlocksAsRDF.java-> Run As -> Java Application 2. Option B2: Retrieve Simulink Blocks from adapter and directly populate triplestore based on in-memory POJOs
- Expand the tdb.clients package
- Right click GETSimulinkBlocksAndPopulateTriplestoreWithPOJOs.java-> Run As -> Java Application
- In the console view, you should see the statement “Simulink Blocks added to triplestore”
Warning: if you try to populate the triplestore using the TDB API while Fuseki is running, you will get the following exception: Exception in thread "main" com.hp.hpl.jena.tdb.TDBException: Can't open database at location ... as it is already locked by the process with PID 7388. TDB databases do not permit concurrent usage across JVMs so in order to prevent possible data corruption you cannot open this location from the JVM that does not own the lock for the dataset
Note: If Fuseki is running, you can only populate the triplestore through Fuseki.
###6. Populating triplestore with SysML Blocks
- In Eclipse, open the Project Explorer view. (Window → Show View → Project Explorer)
- Expand the edu.gatech.mbsec.triplestore.tdb.clients project
- Expand the src/main/java folder
- 2 Options
- Option A: Populate triplestore with SysML Blocks described as RDF on file (no need to run MagicDraw SysML adapter) 1. Expand the tbd.clients package 2. Right click PopulateTriplestoreWithSysMLBlocksAsRDF.java-> Run As -> Java Application (the sample RDF file is located in the folder named sample rdf)
- Option B: Populate triplestore with SysML Blocks from running adapter
1. Run the OSLC MagicDraw SysML Adapter as described in the Instructions to install and run the OSLC MagicDraw SysML Adapter
2. 2 Options
3. Option B1: Retrieve SysML Blocks from adapter and save them on file in RDF, and then populate triplestore based on RDF document
- Expand the adapter.clients package
- Right click GETSysMLBlocksAndSaveAsRDF.java-> Run As -> Java Application
- In the console view, you should see the statement “SysML blocks from adapter saved as RDF on file”
- Expand the tdb.clients package
- Right click PopulateTriplestoreWithSysMLBlocksAsRDF.java-> Run As -> Java Application 2. Option B2: Retrieve SysML Blocks from adapter and directly populate triplestore based on in-memory POJOs
- Expand the tdb.clients package
- Right click GETSysMLBlocksAndPopulateTriplestoreWithPOJOs.java-> Run As -> Java Application
- In the console view, you should see the statement “SysML Blocks added to triplestore”
###7. Querying triplestore for Simulink blocks
- In Eclipse, open the Project Explorer view. (Window → Show View → Project Explorer)
- Expand the edu.gatech.mbsec.triplestore.tdb.clients project
- Expand the src/main/java folder
- Expand the tbd.clients package
- Right click QueryTriplestoreForSimulinkBlocks.java-> Run As -> Java Application
- In the console view, you should see the URIs of resources of type Simulink block
###8. Querying triplestore for SysML blocks
- In Eclipse, open the Project Explorer view. (Window → Show View → Project Explorer)
- Expand the edu.gatech.mbsec.triplestore.tdb.clients project
- Expand the src/main/java folder
- Expand the tbd.clients package
- Right click QueryTriplestoreForSysMLBlocks.java-> Run As -> Java Application
- In the console view, you should see the URIs of resources of type SysML block
###9. Querying triplestore for MBSE (SysML/Simulink/AMESim) blocks
- In Eclipse, open the Project Explorer view. (Window → Show View → Project Explorer)
- Expand the edu.gatech.mbsec.triplestore.tdb.clients project
- Expand the src/main/java folder
- Expand the tbd.clients package
- Right click QueryTriplestoreForMBSEBlocks.java-> Run As -> Java Application
- In the console view, you should see the URIs of resources of type MBSE block
###10. Deleting content (triples) in triplestore
- In Eclipse, open the Project Explorer view. (Window → Show View → Project Explorer)
- Expand the edu.gatech.mbsec.triplestore.tdb.clients project
- Expand the src/main/java folder
- Expand the tbd.clients package
- Right click DeleteAllTriplesInTriplestore.java -> Run As -> Java Application
- In the console view, you should see the statement “All triples deleted in triplestore”
###11. Querying triplestore for all triples
- In Eclipse, open the Project Explorer view. (Window → Show View → Project Explorer)
- Expand the edu.gatech.mbsec.triplestore.tdb.clients project
- Expand the src/main/java folder
- Expand the tbd.clients package
- Right click QueryTriplestoreForAnyTriple.java -> Run As -> Java Application
- In the console view, you should see this if your triplestore is empty
###12. Launching Fuseki as SPARQL HTTP endpoint to the triplestore
- Before running any queries using the SPARQL endpoint, make sure that the triplestore has been populated with triples
- In Eclipse, open the Project Explorer view. (Window → Show View → Project Explorer)
- Expand the edu.gatech.mbsec.triplestore.tdb.clients project
- Expand the apache-jena-fuseki-2.3.0 folder. The batch scripts to launch Fuseki are in that folder
- Launch a command prompt (In Windows, click on Start and type cmd in the search field and selecting the application named cmd)
- Change the directory of the command prompt to the apache-jena-fuseki-2.3.0 folder using the cd command. For example type in the command prompt following command:
cd C:\Users\Axel\git\triplestore-tdb-clients\triplestore\apache-jena-fuseki-2.3.0
- Launch Fuseki by typing in following command including the location of the triplestore as well as a name for the dataset managed by that triplestore (Example: mydataset):
fuseki-server --update --loc=C:\Users\Axel\git\triplestore-tdb-clients\triplestore\mytriplestore /mydataset
- Open Fuseki by going in your browser to localhost:3030
- Click on the query button next to the name of your dataset
-
- Perform a manual query through the SPARQL endpoint by typing in following query to retrieve all Simulink blocks
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX simulink: <http://localhost:8181/oslc4jsimulink/services/rdfvocabulary#>
SELECT ?simulinkBlock
WHERE {
?simulinkBlock rdf:type simulink:Block .
}
- Launch the query by clicking on the play button
- In the result window, you should see the list of Simulink blocks
- If you want to instead seach for all SysML blocks, type this query:
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX sysml: <http://localhost:8181/oslc4jmagicdraw/services/rdfvocabulary#>
SELECT ?sysmlBlock
WHERE {
?sysmlBlock rdf:type sysml:Block .
}
- If you want to instead search for all MBSE blocks, including SysML and Simulink blocks, type this query:
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX mbse: <http://eclipse.org/MBSE/>
SELECT ?block
WHERE {
?block rdf:type mbse:Block .
}
- In the result window, you should see the list of all blocks, including SysML and Simulink blocks
###13. Querying triplestore for Simulink blocks via SPARQL endpoint using a Java client
- In Eclipse, open the Project Explorer view. (Window → Show View → Project Explorer)
- Expand the edu.gatech.mbsec.triplestore.tdb.clients project
- Expand the src/main/java folder
- Expand the fuseki.clients package
- Right click QueryTriplestoreForSimulinkBlocksThroughSPARQLEndpoint.java-> Run As -> Java Application
- In the console view, you should see the URIs of resources of type Simulink block
###14. Deleting all triples in triplestore via SPARQL endpoint using a Java client
- In Eclipse, open the Project Explorer view. (Window → Show View → Project Explorer)
- Expand the edu.gatech.mbsec.triplestore.tdb.clients project
- Expand the src/main/java folder
- Expand the fuseki.clients package
- Right click DeleteAllTriplesInTriplestoreThroughSPARQLEndpoint.java-> Run As -> Java Application
- In the console view, you should see the statement “All triples deleted in triplestore”
###15. Adding a triple to the triplestore via SPARQL endpoint using a Java client
- In Eclipse, open the Project Explorer view. (Window → Show View → Project Explorer)
- Expand the edu.gatech.mbsec.triplestore.tdb.clients project
- Expand the src/main/java folder
- Expand the fuseki.clients package
- Right click AddSimulinkBlockToTriplestoreThroughSPARQLEndpoint.java-> Run As -> Java Application
- In the console view, you should see the statement “Triple added to triplestore”
###16. Closing Fuseki as SPARQL HTTP endpoint to the triplestore
- In the command prompt which launched Fuseki, type Ctrl +C
- Confirm that you want to stop Fuseki by typing Y