Skip to content

Commit

Permalink
[Fix partially kbss-cvut/23ava-distribution#120] Fix failing tests by…
Browse files Browse the repository at this point in the history
… reverting optimization, wrapping where clause in named graphs, for record export as JSON
  • Loading branch information
kostobog committed Jul 11, 2024
1 parent 432926c commit 49643ab
Showing 1 changed file with 21 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ private <T> Page<T> findRecords(RecordFilterParams filters, Pageable pageSpec, C

public Page<RawRecord> findAllRecordsRaw(RecordFilterParams filters, Pageable pageSpec){
final Map<String, Object> queryParams = new HashMap<>();
final String whereClause = constructWhereClause(filters, queryParams);
final String whereClause = constructWhereClauseWithGraphs(filters, queryParams);

final String queryStringNoPaging = Utils.loadQuery(FIND_ALL_RAW_PATIENT_RECORDS)
.replaceFirst(RECORDS_CLAUSE_TEMPLATE_VAR, whereClause);
Expand Down Expand Up @@ -284,12 +284,27 @@ private void setQueryParameters(Query query, Map<String, Object> queryParams) {
URI.create(Vocabulary.s_p_was_treated_at))
.setParameter("hasKey", URI.create(Vocabulary.s_p_key))
.setParameter("hasCreatedDate", URI.create(Vocabulary.s_p_created))
.setParameter("hasLastModified", URI.create(Vocabulary.s_p_modified))
.setParameter("institutionGraph", URI.create(Vocabulary.s_c_institution + "s"));
.setParameter("hasLastModified", URI.create(Vocabulary.s_p_modified));
queryParams.forEach(query::setParameter);
}

private static String constructWhereClause(RecordFilterParams filters, Map<String, Object> queryParams) {
// Could not use Criteria API because it does not support OPTIONAL
String whereClause = "{" +
"?r a ?type ; " +
"?hasCreatedDate ?created ; " +
"?hasInstitution ?institution . " +
"?institution ?hasKey ?institutionKey ." +
"OPTIONAL { ?r ?hasPhase ?phase . } " +
"OPTIONAL { ?r ?hasFormTemplate ?formTemplate . } " +
"OPTIONAL { ?r ?hasLastModified ?lastModified . } " +
"BIND (COALESCE(?lastModified, ?created) AS ?date) ";
whereClause += mapParamsToQuery(filters, queryParams);
whereClause += "}";
return whereClause;
}

private static String constructWhereClauseWithGraphs(RecordFilterParams filters, Map<String, Object> queryParams) {
// Could not use Criteria API because it does not support OPTIONAL
String whereClause = "{GRAPH ?r{" +
"?r a ?type ; " +
Expand All @@ -304,6 +319,9 @@ private static String constructWhereClause(RecordFilterParams filters, Map<Strin
"GRAPH ?institutionGraph{" +
"?institution ?hasKey ?institutionKey ." +
"}}";

queryParams.put("institutionGraph", URI.create(Vocabulary.s_c_institution + "s"));

return whereClause;
}

Expand Down

0 comments on commit 49643ab

Please sign in to comment.