Skip to content

Commit

Permalink
fix(mrcm): Support paging, update endpoint names
Browse files Browse the repository at this point in the history
  • Loading branch information
AAAlinaaa committed Nov 30, 2022
1 parent 031f412 commit ab252c7
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
/**
* @since 8.8.0
*/
@Tag(description="Rules", name = "rules")
@Tag(description="MRCM Rules", name = "mrcm")
@RestController
public class SnomedMrcmRestService extends AbstractRestService {

Expand All @@ -48,7 +48,7 @@ public class SnomedMrcmRestService extends AbstractRestService {
@ApiResponse(responseCode = "400", description = "Bad Request"),
@ApiResponse(responseCode = "404", description = "Not found"),
})
@GetMapping(value = "/{path:**}/types", produces = { AbstractRestService.JSON_MEDIA_TYPE })
@GetMapping(value = "/{path:**}/mrcm/attribute/domains", produces = { AbstractRestService.JSON_MEDIA_TYPE })
public @ResponseBody Promise<SnomedReferenceSetMembers> getApplicableTypes(
@Parameter(description = "The resource path", required = true)
@PathVariable(name ="path")
Expand All @@ -72,15 +72,24 @@ public class SnomedMrcmRestService extends AbstractRestService {

@Parameter(name = "moduleIds", description = "List of applicable modules refining the scope of returned rules", required = false)
@RequestParam(name = "moduleIds", required = false)
final List<String> moduleIds
) {
final List<String> moduleIds,

@RequestParam(name = "searchAfter", required = false)
@Parameter(name = "searchAfter", description = "The search key to use for retrieving the next page of results")
final String searchAfter,

@RequestParam(name = "limit", required = false, defaultValue = "50")
@Parameter(name = "limit",description = "The maximum number of items to return")
int limit) {

return SnomedRequests.prepareGetMrcmTypeRules()
.setAttributeType(MrcmAttributeType.getByNameIgnoreCase(attributeType))
.setModuleIds(moduleIds)
.setParentIds(parentIds)
.setRefSetIds(refsetIds)
.setSelfIds(selfIds)
.setLimit(limit)
.setSearchAfter(searchAfter)
.build(path)
.execute(getBus());
}
Expand All @@ -93,7 +102,7 @@ public class SnomedMrcmRestService extends AbstractRestService {
@ApiResponse(responseCode = "400", description = "Bad Request"),
@ApiResponse(responseCode = "404", description = "Not found"),
})
@GetMapping(value = "/{path:**}/ranges", produces = { AbstractRestService.JSON_MEDIA_TYPE })
@GetMapping(value = "/{path:**}/mrcm/attribute/ranges", produces = { AbstractRestService.JSON_MEDIA_TYPE })
public @ResponseBody Promise<SnomedReferenceSetMembers> getApplicableRanges(
@Parameter(description = "The resource path", required = true)
@PathVariable(name ="path")
Expand All @@ -117,15 +126,24 @@ public class SnomedMrcmRestService extends AbstractRestService {

@Parameter(name = "moduleIds", description = "List of applicable modules refining the scope of returned rules", required = false)
@RequestParam(name = "moduleIds", required = false)
final List<String> moduleIds
) {
final List<String> moduleIds,

@RequestParam(name = "searchAfter", required = false)
@Parameter(name = "searchAfter", description = "The search key to use for retrieving the next page of results")
final String searchAfter,

@RequestParam(name = "limit", required = false, defaultValue = "50")
@Parameter(name = "limit",description = "The maximum number of items to return")
int limit) {

return SnomedRequests.prepareGetMrcmRangeRules()
.setAttributeType(MrcmAttributeType.getByNameIgnoreCase(attributeType))
.setModuleIds(moduleIds)
.setParentIds(parentIds)
.setRefSetIds(refsetIds)
.setSelfIds(selfIds)
.setLimit(limit)
.setSearchAfter(searchAfter)
.build(path)
.execute(getBus());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,7 @@
import static com.b2international.snowowl.snomed.common.SnomedRf2Headers.FIELD_MRCM_RULE_REFSET_ID;
import static com.b2international.snowowl.snomed.core.domain.refset.SnomedRefSetType.MRCM_ATTRIBUTE_RANGE;
import static com.b2international.snowowl.snomed.core.domain.refset.SnomedRefSetType.MRCM_MODULE_SCOPE;
import static com.b2international.snowowl.snomed.datastore.index.entry.SnomedRefSetMemberIndexEntry.Fields.MRCM_CONTENT_TYPE_ID;
import static com.b2international.snowowl.snomed.datastore.index.entry.SnomedRefSetMemberIndexEntry.Fields.MRCM_RANGE_CONSTRAINT;
import static com.b2international.snowowl.snomed.datastore.index.entry.SnomedRefSetMemberIndexEntry.Fields.MRCM_RULE_REFSET_ID;
import static com.b2international.snowowl.snomed.datastore.index.entry.SnomedRefSetMemberIndexEntry.Fields.REFERENCED_COMPONENT_ID;

import java.util.HashMap;
import java.util.List;
Expand All @@ -33,15 +30,15 @@
import java.util.stream.Collectors;

import com.b2international.snowowl.core.domain.BranchContext;
import com.b2international.snowowl.core.events.Request;
import com.b2international.snowowl.core.request.SearchResourceRequest;
import com.b2international.snowowl.snomed.core.MrcmAttributeType;
import com.b2international.snowowl.snomed.core.domain.refset.SnomedReferenceSetMember;
import com.b2international.snowowl.snomed.core.domain.refset.SnomedReferenceSetMembers;

/**
* @since 8.8.0
*/
final class SnomedMrcmRangeRequest implements Request<BranchContext, SnomedReferenceSetMembers> {
final class SnomedMrcmRangeRequest extends SearchResourceRequest<BranchContext, SnomedReferenceSetMembers> {

private static final long serialVersionUID = 1L;

Expand Down Expand Up @@ -72,16 +69,14 @@ public void setAttributeType(MrcmAttributeType attributeType) {
}

@Override
public SnomedReferenceSetMembers execute(BranchContext context) {
public SnomedReferenceSetMembers doExecute(BranchContext context) {
Set<String> inScopeRefSetIds = SnomedRequests.prepareSearchMember()
.all()
.filterByActive(true)
.filterByRefSetType(MRCM_MODULE_SCOPE)
.filterByReferencedComponent(moduleIds)
.setFields(ID, MRCM_RULE_REFSET_ID)
.build()
.execute(context)
.stream()
.stream(context)
.flatMap(members -> members.stream())
.map(m -> (String) m.getProperties().get(FIELD_MRCM_RULE_REFSET_ID))
.collect(Collectors.toSet());

Expand All @@ -107,12 +102,12 @@ public SnomedReferenceSetMembers execute(BranchContext context) {

Map<String, SnomedReferenceSetMember> rangeConstraintMembers = new HashMap<>();
SnomedRequests.prepareSearchMember()
.all()
.filterByActive(true)
.filterByRefSetType(MRCM_ATTRIBUTE_RANGE)
.filterByReferencedComponent(typeIds)
.filterByRefSet(inScopeRefSetIds)
.setFields(ID, REFERENCED_COMPONENT_ID, MRCM_RANGE_CONSTRAINT, MRCM_CONTENT_TYPE_ID)
.setLimit(limit())
.setSearchAfter(searchAfter())
.build()
.execute(context)
.forEach(m -> {
Expand All @@ -124,5 +119,10 @@ public SnomedReferenceSetMembers execute(BranchContext context) {

return new SnomedReferenceSetMembers(List.copyOf(rangeConstraintMembers.values()), null, rangeConstraintMembers.size(), rangeConstraintMembers.size());
}

@Override
protected SnomedReferenceSetMembers createEmptyResult(int limit) {
return new SnomedReferenceSetMembers(limit, 0);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,14 @@
import java.util.Set;

import com.b2international.snowowl.core.domain.BranchContext;
import com.b2international.snowowl.core.events.BaseRequestBuilder;
import com.b2international.snowowl.core.events.Request;
import com.b2international.snowowl.core.request.SearchResourceRequest;
import com.b2international.snowowl.snomed.core.MrcmAttributeType;
import com.b2international.snowowl.snomed.core.domain.refset.SnomedReferenceSetMembers;

/**
* @since 8.8.0
*/
public class SnomedMrcmRangeRequestBuilder extends BaseRequestBuilder<SnomedMrcmRangeRequestBuilder, BranchContext, SnomedReferenceSetMembers>
implements SnomedContentRequestBuilder<SnomedReferenceSetMembers> {
public class SnomedMrcmRangeRequestBuilder extends SnomedSearchRequestBuilder<SnomedMrcmRangeRequestBuilder, SnomedReferenceSetMembers> {

private Set<String> selfIds;
private Set<String> parentIds;
Expand Down Expand Up @@ -62,7 +60,7 @@ public SnomedMrcmRangeRequestBuilder setAttributeType(MrcmAttributeType attribut
}

@Override
protected Request<BranchContext, SnomedReferenceSetMembers> doBuild() {
protected SearchResourceRequest<BranchContext, SnomedReferenceSetMembers> createSearch() {
SnomedMrcmRangeRequest request = new SnomedMrcmRangeRequest();
request.setAttributeType(attributeType);
request.setModuleIds(moduleIds);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

import com.b2international.commons.options.Options;
import com.b2international.snowowl.core.domain.BranchContext;
import com.b2international.snowowl.core.events.Request;
import com.b2international.snowowl.core.request.SearchResourceRequest;
import com.b2international.snowowl.snomed.common.SnomedRf2Headers;
import com.b2international.snowowl.snomed.core.MrcmAttributeType;
import com.b2international.snowowl.snomed.core.domain.SnomedConcept;
Expand All @@ -39,7 +39,7 @@
/**
* @since 8.8.0
*/
final class SnomedMrcmTypeRequest implements Request<BranchContext, SnomedReferenceSetMembers> {
final class SnomedMrcmTypeRequest extends SearchResourceRequest<BranchContext, SnomedReferenceSetMembers> {

private static final long serialVersionUID = 1L;

Expand Down Expand Up @@ -70,16 +70,14 @@ public void setAttributeType(MrcmAttributeType attributeType) {
}

@Override
public SnomedReferenceSetMembers execute(BranchContext context) {
public SnomedReferenceSetMembers doExecute(BranchContext context) {
Set<String> inScopeRefSetIds = SnomedRequests.prepareSearchMember()
.all()
.filterByActive(true)
.filterByRefSetType(SnomedRefSetType.MRCM_MODULE_SCOPE)
.filterByReferencedComponent(moduleIds)
.setFields(ID, MRCM_RULE_REFSET_ID)
.build()
.execute(context)
.stream()
.stream(context)
.flatMap(members -> members.stream())
.map(m -> (String) m.getProperties().get(SnomedRf2Headers.FIELD_MRCM_RULE_REFSET_ID))
.collect(Collectors.toSet());

Expand All @@ -104,13 +102,11 @@ public SnomedReferenceSetMembers execute(BranchContext context) {
};

final Set<String> typeIds = SnomedRequests.prepareSearchConcept()
.all()
.filterByActive(true)
.filterByEcl(eclConstraint)
.setFields(SnomedConceptDocument.Fields.ID)
.build()
.execute(context)
.stream()
.stream(context)
.flatMap(concepts -> concepts.stream())
.map(SnomedConcept::getId)
.collect(Collectors.toSet());

Expand All @@ -133,7 +129,6 @@ public SnomedReferenceSetMembers execute(BranchContext context) {
}

SnomedRefSetMemberSearchRequestBuilder requestBuilder = SnomedRequests.prepareSearchMember()
.all()
.filterByActive(true)
.filterByRefSetType(SnomedRefSetType.MRCM_ATTRIBUTE_DOMAIN)
.filterByRefSet(inScopeRefSetIds)
Expand All @@ -143,7 +138,16 @@ public SnomedReferenceSetMembers execute(BranchContext context) {
requestBuilder.filterByProps(Options.from(Map.of(SnomedRf2Headers.FIELD_MRCM_DOMAIN_ID, domainIds)));
}

return requestBuilder.build().execute(context);
return requestBuilder
.setLimit(limit())
.setSearchAfter(searchAfter())
.build()
.execute(context);
}

@Override
protected SnomedReferenceSetMembers createEmptyResult(int limit) {
return new SnomedReferenceSetMembers(limit, 0);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,14 @@
import java.util.Set;

import com.b2international.snowowl.core.domain.BranchContext;
import com.b2international.snowowl.core.events.BaseRequestBuilder;
import com.b2international.snowowl.core.events.Request;
import com.b2international.snowowl.core.request.SearchResourceRequest;
import com.b2international.snowowl.snomed.core.MrcmAttributeType;
import com.b2international.snowowl.snomed.core.domain.refset.SnomedReferenceSetMembers;

/**
* @since 8.8.0
*/
public class SnomedMrcmTypeRequestBuilder extends BaseRequestBuilder<SnomedMrcmTypeRequestBuilder, BranchContext, SnomedReferenceSetMembers>
implements SnomedContentRequestBuilder<SnomedReferenceSetMembers> {
public class SnomedMrcmTypeRequestBuilder extends SnomedSearchRequestBuilder<SnomedMrcmTypeRequestBuilder, SnomedReferenceSetMembers> {

private Set<String> selfIds;
private Set<String> parentIds;
Expand Down Expand Up @@ -62,7 +60,7 @@ public SnomedMrcmTypeRequestBuilder setAttributeType(MrcmAttributeType attribute
}

@Override
protected Request<BranchContext, SnomedReferenceSetMembers> doBuild() {
protected SearchResourceRequest<BranchContext, SnomedReferenceSetMembers> createSearch() {
SnomedMrcmTypeRequest request = new SnomedMrcmTypeRequest();
request.setAttributeType(attributeType);
request.setModuleIds(moduleIds);
Expand Down

0 comments on commit ab252c7

Please sign in to comment.