2121import org .eclipse .rdf4j .model .Model ;
2222import org .eclipse .rdf4j .model .Resource ;
2323import org .eclipse .rdf4j .model .Value ;
24+ import org .eclipse .rdf4j .model .vocabulary .RDF ;
2425import org .slf4j .Logger ;
2526import org .slf4j .LoggerFactory ;
2627
@@ -42,7 +43,6 @@ public class Configurations {
4243 *
4344 * @return <code>true</code> if <code>org.eclipse.rdf4j.model.vocabulary.useLegacyConfig</code> system property is
4445 * set to <code>true</code>, <code>false</code> otherwise.
45- *
4646 * @since 5.0.0
4747 */
4848 public static boolean useLegacyConfig () {
@@ -117,6 +117,33 @@ public static Optional<Literal> getLiteralValue(Model model, Resource subject, I
117117 return fallbackResult ;
118118 }
119119
120+ /**
121+ * Retrieve a property value for the supplied subject as a {@link Value} if present, falling back to a supplied
122+ * legacy property .
123+ * <p>
124+ * This method allows querying repository config models with a mix of old and new namespaces.
125+ *
126+ * @param model the model to retrieve property values from.
127+ * @param subject the subject of the property.
128+ * @param property the property to retrieve the value of.
129+ * @param legacyProperty legacy property to use if the supplied property has no value in the model.
130+ * @return the literal value for supplied subject and property (or the legacy property ), if present.
131+ */
132+ @ InternalUseOnly
133+ public static Optional <Value > getValue (Model model , Resource subject , IRI property , IRI legacyProperty ) {
134+ var preferredProperty = useLegacyConfig () ? legacyProperty : property ;
135+ var fallbackProperty = useLegacyConfig () ? property : legacyProperty ;
136+
137+ var preferredResult = Models .object (model .getStatements (subject , preferredProperty , null ));
138+ var fallbackResult = Models .object (model .getStatements (subject , fallbackProperty , null ));
139+
140+ logDiscrepancyWarning (preferredResult , fallbackResult );
141+ if (preferredResult .isPresent ()) {
142+ return preferredResult ;
143+ }
144+ return fallbackResult ;
145+ }
146+
120147 /**
121148 * Retrieve all property values for the supplied subject as a Set of values and include all values for any legacy
122149 * property.
@@ -181,6 +208,30 @@ public static Optional<IRI> getIRIValue(Model model, Resource subject, IRI prope
181208 return fallbackResult ;
182209 }
183210
211+ /**
212+ * Retrieve the subject of the supplied type, falling back to a supplied legacy type.
213+ *
214+ * @param model the model to retrieve property values from.
215+ * @param type the type to retrieve the value of.
216+ * @param legacyType legacy type to use if the supplied type has no value in the model.
217+ * @return The subject of the supplied type (or the legacy type), if present.
218+ */
219+ @ InternalUseOnly
220+ public static Optional <Resource > getSubjectByType (Model model , IRI type , IRI legacyType ) {
221+ var preferredType = useLegacyConfig () ? legacyType : type ;
222+ var fallbackType = useLegacyConfig () ? type : legacyType ;
223+
224+ var preferredResult = Models .subject (model .getStatements (null , RDF .TYPE , preferredType ));
225+ var fallbackResult = Models .subject (model .getStatements (null , RDF .TYPE , fallbackType ));
226+
227+ logDiscrepancyWarning (preferredResult , fallbackResult );
228+ if (preferredResult .isPresent ()) {
229+ return preferredResult ;
230+ }
231+
232+ return fallbackResult ;
233+ }
234+
184235 private static void logDiscrepancyWarning (Optional <? extends Value > preferred ,
185236 Optional <? extends Value > fallback ) {
186237 if (!fallback .isEmpty () && !preferred .equals (fallback )) {
0 commit comments