Set<RestfulOperationSystemEnum> systemOps = new HashSet<RestfulOperationSystemEnum>();
for (ResourceBinding next : myRestfulServer.getResourceBindings()) {
Set<RestfulOperationTypeEnum> resourceOps = new HashSet<RestfulOperationTypeEnum>();
RestResource resource = rest.addResource();
String resourceName = next.getResourceName();
RuntimeResourceDefinition def = myRestfulServer.getFhirContext().getResourceDefinition(resourceName);
resource.getType().setValue(def.getName());
resource.getProfile().setId(new IdDt(def.getResourceProfile()));
Map<String, Conformance.RestResourceSearchParam> nameToSearchParam = new HashMap<String, Conformance.RestResourceSearchParam>();
for (BaseMethodBinding nextMethodBinding : next.getMethodBindings()) {
RestfulOperationTypeEnum resOp = nextMethodBinding.getResourceOperationType();
if (resOp != null) {
if (resourceOps.contains(resOp) == false) {
resourceOps.add(resOp);
resource.addOperation().setCode(resOp);
}
}
RestfulOperationSystemEnum sysOp = nextMethodBinding.getSystemOperationType();
if (sysOp != null) {
if (systemOps.contains(sysOp) == false) {
systemOps.add(sysOp);
rest.addOperation().setCode(sysOp);
}
}
if (nextMethodBinding instanceof SearchMethodBinding) {
List<IParameter> params = ((SearchMethodBinding) nextMethodBinding).getParameters();
// TODO: this would probably work best if we sorted these by required first, then optional
RestResourceSearchParam searchParam = null;
StringDt searchParamChain = null;
for (IParameter nextParameterObj : params) {
if (!(nextParameterObj instanceof IQueryParameter)) {
continue;
}
IQueryParameter nextParameter = (IQueryParameter)nextParameterObj;
if (nextParameter.getName().startsWith("_")) {
continue;
}
if (searchParam == null) {
if (!nameToSearchParam.containsKey(nextParameter.getName())) {
RestResourceSearchParam param = resource.addSearchParam();
param.setName(nextParameter.getName());
searchParam = param;
} else {
searchParam = nameToSearchParam.get(nextParameter.getName());
}