Skip to content

Commit 71d8ad0

Browse files
author
James Leigh
committed
Fix #859: Use config.ttl files when available instead of SYSTEM repository for RepositoryConfigs
Signed-off-by: James Leigh <james.leigh@ontotext.com>
1 parent 0d39fa7 commit 71d8ad0

6 files changed

Lines changed: 344 additions & 125 deletions

File tree

core/repository/api/src/main/java/org/eclipse/rdf4j/repository/config/RepositoryConfig.java

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111
import static org.eclipse.rdf4j.repository.config.RepositoryConfigSchema.REPOSITORYID;
1212
import static org.eclipse.rdf4j.repository.config.RepositoryConfigSchema.REPOSITORYIMPL;
1313

14-
import org.eclipse.rdf4j.model.BNode;
15-
import org.eclipse.rdf4j.model.Graph;
1614
import org.eclipse.rdf4j.model.Model;
1715
import org.eclipse.rdf4j.model.Resource;
1816
import org.eclipse.rdf4j.model.ValueFactory;
@@ -114,11 +112,25 @@ public void validate()
114112
implConfig.validate();
115113
}
116114

115+
/**
116+
* @deprecated use {@link #export(Model, Resource)}
117+
*/
118+
@Deprecated
117119
public void export(Model model) {
118120
ValueFactory vf = SimpleValueFactory.getInstance();
121+
export(model, vf.createBNode());
122+
}
119123

120-
BNode repositoryNode = vf.createBNode();
121-
124+
/**
125+
* Exports the configuration into RDF using the given repositoryNode
126+
*
127+
* @param model
128+
* target RDF collection
129+
* @param repositoryNode
130+
* @since 2.3
131+
*/
132+
public void export(Model model, Resource repositoryNode) {
133+
ValueFactory vf = SimpleValueFactory.getInstance();
122134
model.add(repositoryNode, RDF.TYPE, REPOSITORY);
123135

124136
if (id != null) {
@@ -152,7 +164,7 @@ public void parse(Model model, Resource repositoryNode)
152164

153165
/**
154166
* Creates a new {@link RepositoryConfig} object and initializes it by supplying the {@code model} and
155-
* {@code repositoryNode} to its {@link #parse(Graph, Resource) parse} method.
167+
* {@code repositoryNode} to its {@link #parse(Model, Resource) parse} method.
156168
*
157169
* @param model
158170
* the {@link Model} to read initialization data from.

core/repository/api/src/main/java/org/eclipse/rdf4j/repository/config/RepositoryConfigUtil.java

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import org.eclipse.rdf4j.model.Statement;
2222
import org.eclipse.rdf4j.model.ValueFactory;
2323
import org.eclipse.rdf4j.model.impl.LinkedHashModel;
24+
import org.eclipse.rdf4j.model.impl.SimpleValueFactory;
2425
import org.eclipse.rdf4j.model.vocabulary.RDF;
2526
import org.eclipse.rdf4j.query.QueryResults;
2627
import org.eclipse.rdf4j.repository.Repository;
@@ -30,6 +31,56 @@
3031

3132
public class RepositoryConfigUtil {
3233

34+
public static RepositoryConfig getRepositoryConfig(Model model, String repositoryID) {
35+
Statement idStatement = getIDStatement(model, repositoryID);
36+
if (idStatement == null) {
37+
// No such config
38+
return null;
39+
}
40+
Resource repositoryNode = idStatement.getSubject();
41+
Resource context = idStatement.getContext();
42+
Model contextGraph = model.filter(null, null, null, context);
43+
return RepositoryConfig.create(contextGraph, repositoryNode);
44+
}
45+
46+
public static Model getRepositoryConfigModel(Model model, String repositoryID) {
47+
Statement idStatement = getIDStatement(model, repositoryID);
48+
if (idStatement == null) {
49+
// No such config
50+
return null;
51+
}
52+
return model.filter(null, null, null, idStatement.getContext());
53+
}
54+
55+
public static Set<String> getRepositoryIDs(Model model)
56+
throws RepositoryException
57+
{
58+
Set<String> idSet = new LinkedHashSet<String>();
59+
model.filter(null, REPOSITORYID, null).forEach(idStatement -> {
60+
if (idStatement.getObject() instanceof Literal) {
61+
Literal idLiteral = (Literal)idStatement.getObject();
62+
idSet.add(idLiteral.getLabel());
63+
}
64+
});
65+
return idSet;
66+
}
67+
68+
private static Statement getIDStatement(Model model, String repositoryID) {
69+
Literal idLiteral = SimpleValueFactory.getInstance().createLiteral(repositoryID);
70+
Model idStatementList = model.filter(null, REPOSITORYID, idLiteral);
71+
72+
if (idStatementList.size() == 1) {
73+
return idStatementList.iterator().next();
74+
}
75+
else if (idStatementList.isEmpty()) {
76+
return null;
77+
}
78+
else {
79+
throw new RepositoryConfigException("Multiple ID-statements for repository ID " + repositoryID);
80+
}
81+
}
82+
83+
@Deprecated
3384
public static Set<String> getRepositoryIDs(Repository repository)
3485
throws RepositoryException
3586
{
@@ -71,6 +122,7 @@ public static Set<String> getRepositoryIDs(Repository repository)
71122
* if an error occurred while trying to retrieve information from the (system) repository
72123
* @throws RepositoryConfigException
73124
*/
125+
@Deprecated
74126
public static boolean hasRepositoryConfig(Repository repository, String repositoryID)
75127
throws RepositoryException, RepositoryConfigException
76128
{
@@ -83,6 +135,7 @@ public static boolean hasRepositoryConfig(Repository repository, String reposito
83135
}
84136
}
85137

138+
@Deprecated
86139
public static RepositoryConfig getRepositoryConfig(Repository repository, String repositoryID)
87140
throws RepositoryConfigException, RepositoryException
88141
{
@@ -125,6 +178,7 @@ public static RepositoryConfig getRepositoryConfig(Repository repository, String
125178
* When access to the Repository's RepositoryConnection causes a RepositoryException.
126179
* @throws RepositoryConfigException
127180
*/
181+
@Deprecated
128182
public static void updateRepositoryConfigs(Repository repository, RepositoryConfig... configs)
129183
throws RepositoryException, RepositoryConfigException
130184
{
@@ -152,6 +206,7 @@ public static void updateRepositoryConfigs(Repository repository, RepositoryConf
152206
* @throws RepositoryException
153207
* @throws RepositoryConfigException
154208
*/
209+
@Deprecated
155210
public static void updateRepositoryConfigs(RepositoryConnection con, RepositoryConfig... configs)
156211
throws RepositoryException, RepositoryConfigException
157212
{
@@ -191,6 +246,7 @@ public static void updateRepositoryConfigs(RepositoryConnection con, RepositoryC
191246
* Whenever access to the Repository's RepositoryConnection causes a RepositoryException.
192247
* @throws RepositoryConfigException
193248
*/
249+
@Deprecated
194250
public static boolean removeRepositoryConfigs(Repository repository, String... repositoryIDs)
195251
throws RepositoryException, RepositoryConfigException
196252
{
@@ -218,6 +274,7 @@ public static boolean removeRepositoryConfigs(Repository repository, String... r
218274
return changed;
219275
}
220276

277+
@Deprecated
221278
public static Resource getContext(RepositoryConnection con, String repositoryID)
222279
throws RepositoryException, RepositoryConfigException
223280
{

0 commit comments

Comments
 (0)