2121import org .eclipse .rdf4j .model .Statement ;
2222import org .eclipse .rdf4j .model .ValueFactory ;
2323import org .eclipse .rdf4j .model .impl .LinkedHashModel ;
24+ import org .eclipse .rdf4j .model .impl .SimpleValueFactory ;
2425import org .eclipse .rdf4j .model .vocabulary .RDF ;
2526import org .eclipse .rdf4j .query .QueryResults ;
2627import org .eclipse .rdf4j .repository .Repository ;
3031
3132public 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