View Javadoc
1   package de.tud.plt.r43ples.core;
2   
3   import de.tud.plt.r43ples.exception.InternalErrorException;
4   import de.tud.plt.r43ples.existentobjects.Branch;
5   import de.tud.plt.r43ples.existentobjects.Revision;
6   import de.tud.plt.r43ples.existentobjects.RevisionGraph;
7   import de.tud.plt.r43ples.management.Config;
8   import org.apache.logging.log4j.LogManager;
9   import org.apache.logging.log4j.Logger;
10  
11  /**
12   * Collection of information for creating a new branch.
13   *
14   * @author Stephan Hensel
15   *
16   */
17  public class BranchDraft extends ReferenceDraft {
18  
19      /** The logger. **/
20      private Logger logger = LogManager.getLogger(BranchDraft.class);
21  
22  
23      /**
24       * The constructor.
25       *
26       * @param uriCalculator the current URI calculator instance
27       * @param revisionGraph the revision graph
28       * @param referencedRevision the referenced revision
29       * @param referenceIdentifier the reference identifier
30       * @throws InternalErrorException
31       */
32      protected BranchDraft(URICalculator uriCalculator, RevisionGraph revisionGraph, Revision referencedRevision, String referenceIdentifier) throws InternalErrorException {
33          super(uriCalculator, revisionGraph, referencedRevision, referenceIdentifier, uriCalculator.getNewFullGraphURI(revisionGraph, referenceIdentifier), uriCalculator.getNewBranchURI(revisionGraph, referenceIdentifier));
34  	}
35  
36  
37      /**
38       * Creates the change set draft with all meta data and named graphs in the triplestore.
39       * Creates add and delete sets, strips the resulting sets if necessary, updates the referenced full graph and adds meta information.
40       *
41       * @return the created change set
42       */
43      protected Branch createInTripleStore() throws InternalErrorException {
44          logger.info("Create new branch for graph " + getRevisionGraph().getGraphName() + ".");
45  
46  
47          // Create full graph
48          getTripleStoreInterface().executeCreateGraph(getReferencedFullGraphURI());
49          // Create full graph for this branch
50          FullGraph fullGraph = new FullGraph(getRevisionGraph(), this.getReferencedRevision(), this.getReferencedFullGraphURI());
51  
52          addMetaInformation();
53  
54          return new Branch(getRevisionGraph(), getReferenceIdentifier(), getReferenceURI(), getReferencedFullGraphURI());
55      }
56  
57      /**
58       * Adds meta information of the created revision to the revision graph.
59       *
60       * @throws InternalErrorException
61       */
62      private void addMetaInformation() {
63          String queryContent = String.format(
64                      "<%s> a rmo:Branch, rmo:Reference, rmo:Entity ;"
65                              + "	rmo:references <%s> ;"
66                              + "	rmo:fullContent <%s> ;"
67                              + "	rmo:referenceIdentifier \"%s\" .",
68                      getReferenceURI(), getReferencedRevision().getRevisionURI(), getReferencedFullGraphURI(), getReferenceIdentifier());
69  
70          String queryRevision = Config.prefixes + String.format("INSERT DATA { GRAPH <%s> {%s} }", getRevisionGraph().getRevisionGraphUri(), queryContent);
71  
72          getTripleStoreInterface().executeUpdateQuery(queryRevision);
73      }
74  
75  }