Skip to content

Commit 0da1e8a

Browse files
committed
GH-4932 add getValue method
1 parent 4e7a05d commit 0da1e8a

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

core/model/src/main/java/org/eclipse/rdf4j/model/util/Configurations.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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.

0 commit comments

Comments
 (0)