View Javadoc
1   package de.tud.plt.r43ples.existentobjects;
2   
3   import org.apache.jena.query.QuerySolution;
4   import org.apache.jena.query.ResultSet;
5   import de.tud.plt.r43ples.management.Config;
6   import de.tud.plt.r43ples.triplestoreInterface.TripleStoreInterfaceSingleton;
7   import org.apache.logging.log4j.LogManager;
8   import org.apache.logging.log4j.Logger;
9   
10  import java.util.HashMap;
11  
12  /**
13   * Provides information of all revised graphs.
14   *
15   * @author Stephan Hensel
16   */
17  public class RevisionControl {
18  
19      /** The logger. **/
20      private Logger logger = LogManager.getLogger(RevisionControl.class);
21  
22  
23      /**
24       * Get a hash map of all revised graphs in R43ples.
25       * Key is the corresponding graph name.
26       *
27       * @return the hash map of revised graphs
28       */
29      public HashMap<String, RevisionGraph> getRevisedGraphs() {
30          // As new graphs can be added there is no private variable storing the currently revised graphs
31          HashMap<String, RevisionGraph> revisionGraphMap = new HashMap<>();
32          String sparqlQuery = Config.prefixes
33                  + String.format(""
34                  + "SELECT DISTINCT ?graph "
35                  + "WHERE {"
36                  + " GRAPH <%s> {  ?graph a rmo:RevisionGraph }"
37                  + "} ORDER BY ?graph", Config.revision_graph);
38          ResultSet results = TripleStoreInterfaceSingleton.get().executeSelectQuery(sparqlQuery);
39          while (results.hasNext()) {
40              QuerySolution qs = results.next();
41              String graphName = qs.getResource("graph").toString();
42              RevisionGraph revisionGraph = new RevisionGraph(graphName);
43              revisionGraphMap.put(graphName, revisionGraph);
44          }
45  
46          return revisionGraphMap;
47      }
48  
49  }