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
13
14
15
16
17 public class BranchDraft extends ReferenceDraft {
18
19
20 private Logger logger = LogManager.getLogger(BranchDraft.class);
21
22
23
24
25
26
27
28
29
30
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
39
40
41
42
43 protected Branch createInTripleStore() throws InternalErrorException {
44 logger.info("Create new branch for graph " + getRevisionGraph().getGraphName() + ".");
45
46
47
48 getTripleStoreInterface().executeCreateGraph(getReferencedFullGraphURI());
49
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
59
60
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 }