...
Match all xpaths that contain "public" in fragment table
Code Block | ||
---|---|---|
| ||
SELECT xpath, attributes #>> '{}' AS attributes FROM fragment WHERE fragment.xpath LIKE '%public%' |
...
Iterate over the list and retrieve all attributes
- Iterate over the attributes and collect those instances that match
- Return collected list of cm handles
Code Block | ||||
---|---|---|---|---|
| ||||
/**
* Retrieve public properties for given cm handle.
*
* @param publicProperties the public properties to match
* @return lit of cm handles that match
*/
@Override
public List<String> getCmHandlesForMatchingPublicProperties(final Map<String, String> publicProperties) {
final String retrievePublicFragments =
"SELECT xpath, attributes #>> '{}' AS attributes FROM fragment WHERE fragment.xpath LIKE '%public%';";
final List<Object[]> resultsAsObjects =
entityManager.createNativeQuery(retrievePublicFragments).getResultList();
final Set<String> cmHandlesThatMatch = new TreeSet<>();
final Set<String> allCmHandles = new TreeSet<>();
for (final Object[] row : resultsAsObjects) {
final String xpath = (String) row[0];
final String attributes = (String) row[1];
allCmHandles.add(getCmHandle(xpath));
try {
final String attributesAsJsonString = getAttributesAsJsonString(attributes);
final JsonObject attributesAsJsonObject = new JsonParser().parse(attributesAsJsonString)
.getAsJsonObject();
if (nameAndValueMatch(publicProperties, attributesAsJsonObject)) {
cmHandlesThatMatch.add(getCmHandle(xpath));
}
} catch (final JsonProcessingException jsonProcessingException) {
jsonProcessingException.getMessage();
}
}
if (publicProperties.get("name").isEmpty() && publicProperties.get("value").isEmpty()) {
return List.copyOf(allCmHandles);
}
return List.copyOf(cmHandlesThatMatch);
}
private String getAttributesAsJsonString(final String attributes) throws JsonProcessingException {
final ObjectMapper objectMapper = new ObjectMapper();
String attributesAsJsonString = objectMapper.writeValueAsString(attributes);
attributesAsJsonString = attributesAsJsonString.replace("\\", "");
attributesAsJsonString = attributesAsJsonString.replaceFirst("\"", "");
attributesAsJsonString = attributesAsJsonString.substring(0, attributesAsJsonString.length() - 1);
return attributesAsJsonString;
}
private boolean nameAndValueMatch(final Map<String, String> publicProperties,
final JsonObject attributesAsJsonObject) {
return attributesAsJsonObject.get("value").getAsString().equals(publicProperties.get("value"))
&& attributesAsJsonObject.get("name").getAsString().equals(publicProperties.get("name"));
}
private String getCmHandle(final String xpath) {
if (xpath.indexOf("\'") > - 1) {
return xpath.substring(xpath.indexOf("\'") + 1, xpath.indexOf("]") - 1);
}
return xpath.substring(xpath.indexOf("\"") + 1, xpath.indexOf("]") - 1);
} |
Interface Proposal
# | URI | Design Notes | Comment(s) | |||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | POST /ncmp/v1/data/ch/searches | Scenario : Request received to return all cm handles matching properties given Request Body
Response Body
|
...