-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#451: Fixed translation of FilterSets between DSMLv2 and JSON
- Loading branch information
Showing
9 changed files
with
377 additions
and
21 deletions.
There are no files selected for viewing
93 changes: 93 additions & 0 deletions
93
...src/main/groovy/org/openehealth/ipf/commons/ihe/hpd/stub/json/FilterIntermediaries.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
/* | ||
* Copyright 2024 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.openehealth.ipf.commons.ihe.hpd.stub.json | ||
|
||
import com.fasterxml.jackson.annotation.JsonTypeInfo | ||
import groovy.transform.CompileStatic | ||
import org.openehealth.ipf.commons.ihe.hpd.stub.dsmlv2.* | ||
|
||
/** | ||
* @author Dmytro Rud | ||
*/ | ||
@CompileStatic | ||
@JsonTypeInfo(use = JsonTypeInfo.Id.MINIMAL_CLASS) | ||
interface FilterIntermediary<T> { | ||
T toDsml() | ||
//... and there must be a static method with the signature "static Filter2 fromDsml(T dsml)" | ||
} | ||
|
||
@CompileStatic | ||
class And implements FilterIntermediary<FilterSet> { | ||
List<FilterIntermediary> nested | ||
FilterSet toDsml() { return FilterIntermediaryUtils.toFilterSet(nested) } | ||
static FilterIntermediary fromDsml(FilterSet fs) { return new And(nested: FilterIntermediaryUtils.fromFilterSet(fs)) } | ||
} | ||
|
||
@CompileStatic | ||
class Or implements FilterIntermediary<FilterSet> { | ||
List<FilterIntermediary> nested | ||
FilterSet toDsml() { return FilterIntermediaryUtils.toFilterSet(nested) } | ||
static FilterIntermediary fromDsml(FilterSet fs) { return new Or(nested: FilterIntermediaryUtils.fromFilterSet(fs)) } | ||
} | ||
|
||
@CompileStatic | ||
class Not implements FilterIntermediary<Filter> { | ||
FilterIntermediary nested | ||
Filter toDsml() { return FilterIntermediaryUtils.toFilter(nested) } | ||
static FilterIntermediary fromDsml(Filter f) { return new Not(nested: FilterIntermediaryUtils.fromFilter(f)) } | ||
} | ||
|
||
@CompileStatic | ||
class EqualityMatch extends AttributeValueAssertion implements FilterIntermediary<AttributeValueAssertion> { | ||
AttributeValueAssertion toDsml() { return this } | ||
static FilterIntermediary fromDsml(AttributeValueAssertion ava) { return new EqualityMatch(name: ava.name, value: ava.value) } | ||
} | ||
|
||
@CompileStatic | ||
class Substrings extends SubstringFilter implements FilterIntermediary<SubstringFilter> { | ||
SubstringFilter toDsml() { return this } | ||
static FilterIntermediary fromDsml(SubstringFilter sf) { return new Substrings(name: sf.name, initial: sf.initial, any: sf.any, final: sf.final) } | ||
} | ||
|
||
@CompileStatic | ||
class GreaterOrEqual extends AttributeValueAssertion implements FilterIntermediary<AttributeValueAssertion> { | ||
AttributeValueAssertion toDsml() { return this } | ||
static FilterIntermediary fromDsml(AttributeValueAssertion ava) { return new GreaterOrEqual(name: ava.name, value: ava.value) } | ||
} | ||
|
||
@CompileStatic | ||
class LessOrEqual extends AttributeValueAssertion implements FilterIntermediary<AttributeValueAssertion> { | ||
AttributeValueAssertion toDsml() { return this } | ||
static FilterIntermediary fromDsml(AttributeValueAssertion ava) { return new LessOrEqual(name: ava.name, value: ava.value) } | ||
} | ||
|
||
@CompileStatic | ||
class Present extends AttributeDescription implements FilterIntermediary<AttributeDescription> { | ||
AttributeDescription toDsml() { return this } | ||
static FilterIntermediary fromDsml(AttributeDescription ad) { return new Present(name: ad.name) } | ||
} | ||
|
||
@CompileStatic | ||
class ApproxMatch extends AttributeValueAssertion implements FilterIntermediary<AttributeValueAssertion> { | ||
AttributeValueAssertion toDsml() { return this } | ||
static FilterIntermediary fromDsml(AttributeValueAssertion ava) { return new ApproxMatch(name: ava.name, value: ava.value) } | ||
} | ||
|
||
@CompileStatic | ||
class ExtensibleMatch extends MatchingRuleAssertion implements FilterIntermediary<MatchingRuleAssertion> { | ||
MatchingRuleAssertion toDsml() { return this } | ||
static FilterIntermediary fromDsml(MatchingRuleAssertion mra) { return new ExtensibleMatch(name: mra.name, value: mra.value, dnAttributes: mra.dnAttributes, matchingRule: mra.matchingRule) } | ||
} |
61 changes: 61 additions & 0 deletions
61
.../main/groovy/org/openehealth/ipf/commons/ihe/hpd/stub/json/FilterIntermediaryUtils.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* | ||
* Copyright 2024 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.openehealth.ipf.commons.ihe.hpd.stub.json | ||
|
||
import org.openehealth.ipf.commons.ihe.hpd.stub.dsmlv2.Filter | ||
import org.openehealth.ipf.commons.ihe.hpd.stub.dsmlv2.FilterSet | ||
import org.openehealth.ipf.commons.ihe.hpd.stub.dsmlv2.ObjectFactory | ||
|
||
import javax.xml.bind.JAXBElement | ||
|
||
/** | ||
* @author Dmytro Rud | ||
*/ | ||
class FilterIntermediaryUtils { | ||
|
||
static final ObjectFactory OBJECT_FACTORY = new ObjectFactory() | ||
|
||
static final List<String> FILTER_TYPES = ['and', 'or', 'not', 'equalityMatch', 'substring', 'greaterOrEqual', 'lessOrEqual', 'present', 'approxMatch', 'extensibleMatch'] | ||
|
||
static FilterIntermediary fromDsml(String filterType, Object dsml) { | ||
return Class.forName("${FilterIntermediaryUtils.packageName + '.' + filterType.capitalize()}").declaredMethods.find { it.name == 'fromDsml' }.invoke(null, dsml) as FilterIntermediary | ||
} | ||
|
||
static FilterIntermediary fromFilter(Filter f) { | ||
for (fieldName in FILTER_TYPES) { | ||
def fieldValue = f."${fieldName}" | ||
if (fieldValue) { | ||
return fromDsml(fieldName, fieldValue) | ||
} | ||
} | ||
return null | ||
} | ||
|
||
static Filter toFilter(FilterIntermediary fi) { | ||
return new Filter("${fi.class.simpleName.uncapitalize()}": fi.toDsml()) | ||
} | ||
|
||
static List<FilterIntermediary> fromFilterSet(FilterSet fs) { | ||
return fs.filterGroup.collect { jaxbElement -> fromDsml(jaxbElement.name.localPart, jaxbElement.value) } | ||
} | ||
|
||
static FilterSet toFilterSet(List<FilterIntermediary> fis) { | ||
return new FilterSet(filterGroup: fis.collect { fi -> | ||
OBJECT_FACTORY."${'createFilterSet' + fi.class.simpleName}"(fi.toDsml()) as JAXBElement | ||
}) | ||
} | ||
|
||
} |
56 changes: 56 additions & 0 deletions
56
...roovy/org/openehealth/ipf/commons/ihe/hpd/stub/json/SearchBatchRequestIntermediary.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* Copyright 2024 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.openehealth.ipf.commons.ihe.hpd.stub.json | ||
|
||
import groovy.transform.CompileStatic | ||
import org.openehealth.ipf.commons.ihe.hpd.stub.dsmlv2.* | ||
|
||
/** | ||
* @author Dmytro Rud | ||
*/ | ||
@CompileStatic | ||
class SearchBatchRequestIntermediary { | ||
|
||
String requestId | ||
AuthRequest authRequest | ||
List<SearchRequestIntermediary> searchRequests | ||
BatchRequest.RequestProcessingType processing | ||
BatchRequest.RequestResponseOrder responseOrder | ||
BatchRequest.RequestErrorHandlingType onError | ||
|
||
static SearchBatchRequestIntermediary fromBatchRequest(BatchRequest batchRequest) { | ||
return new SearchBatchRequestIntermediary( | ||
requestId: batchRequest.requestID, | ||
authRequest: batchRequest.authRequest, | ||
searchRequests: batchRequest.batchRequests.collect { SearchRequestIntermediary.fromSearchRequest(it as SearchRequest) }, | ||
processing: batchRequest.processing, | ||
responseOrder: batchRequest.responseOrder, | ||
onError: batchRequest.onError, | ||
) | ||
} | ||
|
||
BatchRequest toBatchRequest() { | ||
return new BatchRequest( | ||
requestID: requestId, | ||
authRequest: authRequest, | ||
batchRequests: searchRequests.collect { it.toSearchRequest() as DsmlMessage }, | ||
processing: processing, | ||
responseOrder: responseOrder, | ||
onError: onError, | ||
) | ||
} | ||
|
||
} |
68 changes: 68 additions & 0 deletions
68
...ain/groovy/org/openehealth/ipf/commons/ihe/hpd/stub/json/SearchRequestIntermediary.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* | ||
* Copyright 2024 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.openehealth.ipf.commons.ihe.hpd.stub.json | ||
|
||
import groovy.transform.CompileStatic | ||
import org.openehealth.ipf.commons.ihe.hpd.stub.dsmlv2.* | ||
|
||
/** | ||
* @author Dmytro Rud | ||
*/ | ||
@CompileStatic | ||
class SearchRequestIntermediary { | ||
|
||
String requestId | ||
List<Control> controls | ||
FilterIntermediary filter | ||
List<String> attributes | ||
String dn | ||
SearchRequest.SearchScope scope | ||
SearchRequest.DerefAliasesType derefAliases | ||
long sizeLimit | ||
long timeLimit | ||
boolean typesOnly | ||
|
||
static SearchRequestIntermediary fromSearchRequest(SearchRequest searchRequest) { | ||
return new SearchRequestIntermediary( | ||
requestId: searchRequest.requestID, | ||
controls: searchRequest.control, | ||
filter: FilterIntermediaryUtils.fromFilter(searchRequest.filter), | ||
attributes: searchRequest.attributes.attribute.collect { it.name }, | ||
dn: searchRequest.dn, | ||
scope: searchRequest.scope, | ||
derefAliases: searchRequest.derefAliases, | ||
sizeLimit: searchRequest.sizeLimit, | ||
timeLimit: searchRequest.timeLimit, | ||
typesOnly: searchRequest.typesOnly, | ||
) | ||
} | ||
|
||
SearchRequest toSearchRequest() { | ||
return new SearchRequest( | ||
requestID: requestId, | ||
control: controls, | ||
filter: FilterIntermediaryUtils.toFilter(filter), | ||
attributes: new AttributeDescriptions(attribute: attributes.collect { new AttributeDescription(name: it) }), | ||
dn: dn, | ||
scope: scope, | ||
derefAliases: derefAliases, | ||
sizeLimit: sizeLimit, | ||
timeLimit: timeLimit, | ||
typesOnly: typesOnly, | ||
) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.