1 package de.tud.plt.r43ples.existentobjects;
2
3 import de.tud.plt.r43ples.exception.InternalErrorException;
4 import de.tud.plt.r43ples.management.Config;
5 import de.tud.plt.r43ples.triplestoreInterface.TripleStoreInterfaceSingleton;
6 import org.apache.jena.query.QuerySolution;
7 import org.apache.jena.query.ResultSet;
8 import org.apache.logging.log4j.LogManager;
9 import org.apache.logging.log4j.Logger;
10
11
12
13
14
15
16 public class Statement {
17
18
19 private Logger logger = LogManager.getLogger(Statement.class);
20
21
22 private String statementURI;
23
24 private String subject;
25
26 private String predicate;
27
28 private String object;
29
30 private boolean isResource;
31
32
33 private String revisionGraphURI;
34
35 private RevisionGraph revisionGraph;
36
37
38
39
40
41
42
43
44
45 public Statement(RevisionGraph revisionGraph, String statementURI) throws InternalErrorException {
46 this.revisionGraph = revisionGraph;
47 this.revisionGraphURI = this.revisionGraph.getRevisionGraphUri();
48 this.statementURI = statementURI;
49
50 retrieveAdditionalInformation();
51 }
52
53
54
55
56
57
58
59
60
61
62
63 public Statement(RevisionGraph revisionGraph, String statementURI, String subject, String predicate, String object, boolean isResource) {
64 this.revisionGraph = revisionGraph;
65 this.revisionGraphURI = this.revisionGraph.getRevisionGraphUri();
66 this.statementURI = statementURI;
67 this.subject = subject;
68 this.predicate = predicate;
69 this.object = object;
70 this.isResource = isResource;
71 }
72
73
74
75
76
77
78 private void retrieveAdditionalInformation() throws InternalErrorException {
79 logger.info("Get additional information of current statement URI " + statementURI + ".");
80 String query = Config.prefixes + String.format(""
81 + "SELECT ?subject ?predicate ?object "
82 + "WHERE { GRAPH <%s> {"
83 + " <%s> a rdf:Statement; "
84 + " rdf:subject ?subject; "
85 + " rdf:predicate ?predicate; "
86 + " rdf:object ?object. "
87 + "} }", revisionGraphURI, statementURI);
88 this.logger.debug(query);
89 ResultSet resultSet = TripleStoreInterfaceSingleton.get().executeSelectQuery(query);
90 if (resultSet.hasNext()) {
91 QuerySolution qs = resultSet.next();
92 subject = qs.getResource("?subject").toString();
93 predicate = qs.getResource("?predicate").toString();
94 if (qs.getResource("?object") != null) {
95 object = qs.getResource("?object").toString();
96 isResource = true;
97 } else {
98 if (qs.getLiteral("?object") != null) {
99 object = qs.getLiteral("?object").toString();
100 isResource = false;
101 }
102 }
103 } else {
104 throw new InternalErrorException("No additional information found for statement URI " + statementURI + ".");
105 }
106 }
107
108
109
110
111
112
113 public String getStatementURI() {
114 return statementURI;
115 }
116
117
118
119
120
121
122 public String getSubject() {
123 return subject;
124 }
125
126
127
128
129
130
131 public String getPredicate() {
132 return predicate;
133 }
134
135
136
137
138
139
140 public String getObject() {
141 return object;
142 }
143
144
145
146
147
148
149 public boolean isResource() {
150 return isResource;
151 }
152
153
154
155
156
157
158 public RevisionGraph getRevisionGraph() {
159 return revisionGraph;
160 }
161
162 }