Fix #1855 - StructureDefinition search not working (#1858)

This commit is contained in:
James Agnew 2020-05-21 09:35:37 -04:00 committed by GitHub
parent e07e071130
commit ce5ade53d9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
18 changed files with 49 additions and 596 deletions

View File

@ -0,0 +1,11 @@
---
type: remove
issue: 1855
title: "A very old feature that is not believed to be used anywhere has been removed: The ServerProfileProvider is
a special resource provider that was automatically registered to HAPI FHIR REST servers, and served up StructureDefinitions
that were registered to the FhirContext. Registering custom StructureDefinitions against the FhirContext for exposure through
the REST API (as what was then the /Profile endpoint) was planned to be a common feature during the DSTU1 lifecycle but
did not turn out to be a useful approach. This feature was mostly forgotten about until the logic for selecting resource
provider handler methods was revamped and the old mechanism suddenly became the default resource provider for StructureDefinition
resources in the JPA server. We don't expect any negative impact by this change, please post in our mailing list if you
disagree."

View File

@ -4,13 +4,16 @@ import ca.uhn.fhir.jpa.model.util.JpaConstants;
import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException;
import ca.uhn.fhir.util.TestUtil;
import org.hl7.fhir.instance.model.api.IIdType;
import org.hl7.fhir.r4.model.Bundle;
import org.hl7.fhir.r4.model.IdType;
import org.hl7.fhir.r4.model.Parameters;
import org.hl7.fhir.r4.model.StringType;
import org.hl7.fhir.r4.model.StructureDefinition;
import org.hl7.fhir.instance.model.api.IIdType;
import org.junit.AfterClass;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
@ -18,9 +21,22 @@ import static org.junit.Assert.assertEquals;
public class ResourceProviderR4StructureDefinitionTest extends BaseResourceProviderR4Test {
@AfterClass
public static void afterClassClearContext() {
TestUtil.clearAllStaticFieldsForUnitTest();
private static final Logger ourLog = LoggerFactory.getLogger(ResourceProviderR4StructureDefinitionTest.class);
@Test
public void testSearchAllStructureDefinitions() throws IOException {
StructureDefinition sd = loadResource(myFhirCtx, StructureDefinition.class, "/r4/sd-david-dhtest7.json");
myStructureDefinitionDao.update(sd);
Bundle response = ourClient
.search()
.forResource(StructureDefinition.class)
.returnBundle(Bundle.class)
.execute();
ourLog.info(myFhirCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(response));
assertEquals(1, response.getEntry().size());
assertEquals("dhtest7", response.getEntry().get(0).getResource().getIdElement().getIdPart());
}
@Test
@ -37,7 +53,6 @@ public class ResourceProviderR4StructureDefinitionTest extends BaseResourceProvi
assertEquals(51, response.getSnapshot().getElement().size());
}
@Test
public void testSnapshotWithId() throws IOException {
StructureDefinition sd = loadResourceFromClasspath(StructureDefinition.class, "/r4/profile-differential-patient-r4.json");
@ -53,7 +68,6 @@ public class ResourceProviderR4StructureDefinitionTest extends BaseResourceProvi
assertEquals(51, response.getSnapshot().getElement().size());
}
@Test
public void testSnapshotWithUrl() throws IOException {
StructureDefinition sd = loadResourceFromClasspath(StructureDefinition.class, "/r4/profile-differential-patient-r4.json");
@ -98,4 +112,9 @@ public class ResourceProviderR4StructureDefinitionTest extends BaseResourceProvi
assertEquals("HTTP 404 Not Found: No StructureDefiniton found with url = 'http://hl7.org/fhir/StructureDefinition/FOO'", e.getMessage());
}
}
@AfterClass
public static void afterClassClearContext() {
TestUtil.clearAllStaticFieldsForUnitTest();
}
}

View File

@ -34,6 +34,4 @@ public interface IFhirVersionServer {
IServerConformanceProvider<? extends IBaseResource> createServerConformanceProvider(RestfulServer theRestfulServer);
IResourceProvider createServerProfilesProvider(RestfulServer theRestfulServer);
}

View File

@ -859,11 +859,6 @@ public class RestfulServer extends HttpServlet implements IRestfulServer<Servlet
myServerName = theServerName;
}
public IResourceProvider getServerProfilesProvider() {
IFhirVersionServer versionServer = (IFhirVersionServer) getFhirContext().getVersion().getServerVersion();
return versionServer.createServerProfilesProvider(this);
}
/**
* Gets the server's version, as exported in conformance profiles exported by the server. This is informational only,
* but can be helpful to set with something appropriate.
@ -1243,8 +1238,6 @@ public class RestfulServer extends HttpServlet implements IRestfulServer<Servlet
// this call is part of initialization
registerProviders(providers, true);
findResourceMethods(getServerProfilesProvider());
confProvider = getServerConformanceProvider();
if (confProvider == null) {
IFhirVersionServer versionServer = (IFhirVersionServer) getFhirContext().getVersion().getServerVersion();

View File

@ -37,10 +37,10 @@ public class SimpleBundleProvider implements IBundleProvider {
private Integer myPreferredPageSize;
private Integer mySize;
private IPrimitiveType<Date> myPublished = InstantDt.withCurrentTime();
public SimpleBundleProvider(List<? extends IBaseResource> theList) {
this(theList, null);
}
/**
* Constructor
*/
public SimpleBundleProvider(IBaseResource theResource) {
this(Collections.singletonList(theResource));
}
@ -52,6 +52,13 @@ public class SimpleBundleProvider implements IBundleProvider {
this(Collections.emptyList());
}
/**
* Constructor
*/
public SimpleBundleProvider(List<? extends IBaseResource> theList) {
this(theList, null);
}
public SimpleBundleProvider(List<? extends IBaseResource> theList, String theUuid) {
myList = theList;
myUuid = theUuid;

View File

@ -102,10 +102,6 @@ public class RestfulServerTest {
};
}
@Override
public IResourceProvider createServerProfilesProvider(RestfulServer theRestfulServer) {
return new MyResourceProvider();
}
}
@SuppressWarnings("unused")

View File

@ -1,11 +1,8 @@
package org.hl7.fhir.dstu2016may.hapi.ctx;
import org.hl7.fhir.dstu2016may.hapi.rest.server.ServerConformanceProvider;
import org.hl7.fhir.dstu2016may.hapi.rest.server.ServerProfileProvider;
import ca.uhn.fhir.rest.api.server.IFhirVersionServer;
import ca.uhn.fhir.rest.server.IResourceProvider;
import ca.uhn.fhir.rest.server.RestfulServer;
import org.hl7.fhir.dstu2016may.hapi.rest.server.ServerConformanceProvider;
public class FhirServerDstu2_1 implements IFhirVersionServer {
@ -14,9 +11,4 @@ public class FhirServerDstu2_1 implements IFhirVersionServer {
return new ServerConformanceProvider(theServer);
}
@Override
public IResourceProvider createServerProfilesProvider(RestfulServer theRestfulServer) {
return new ServerProfileProvider(theRestfulServer);
}
}

View File

@ -1,88 +0,0 @@
package org.hl7.fhir.dstu2016may.hapi.rest.server;
/*
* #%L
* HAPI FHIR Structures - DSTU2 (FHIR v1.0.0)
* %%
* Copyright (C) 2014 - 2015 University Health Network
* %%
* 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.
* #L%
*/
import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.context.RuntimeResourceDefinition;
import ca.uhn.fhir.rest.annotation.IdParam;
import ca.uhn.fhir.rest.annotation.Read;
import ca.uhn.fhir.rest.annotation.Search;
import ca.uhn.fhir.rest.server.IResourceProvider;
import ca.uhn.fhir.rest.server.RestfulServer;
import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails;
import org.hl7.fhir.dstu2016may.model.IdType;
import org.hl7.fhir.dstu2016may.model.StructureDefinition;
import org.hl7.fhir.instance.model.api.IBaseResource;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
public class ServerProfileProvider implements IResourceProvider {
private final FhirContext myContext;
private final RestfulServer myRestfulServer;
public ServerProfileProvider(RestfulServer theServer) {
myContext = theServer.getFhirContext();
myRestfulServer = theServer;
}
@Override
public Class<? extends IBaseResource> getResourceType() {
return StructureDefinition.class;
}
@Read()
public StructureDefinition getProfileById(ServletRequestDetails theRequest, @IdParam IdType theId) {
RuntimeResourceDefinition retVal = myContext.getResourceDefinitionById(theId.getIdPart());
if (retVal==null) {
return null;
}
String serverBase = getServerBase(theRequest);
return (StructureDefinition) retVal.toProfile(serverBase);
}
@Search()
public List<StructureDefinition> getAllProfiles(ServletRequestDetails theRequest) {
final String serverBase = getServerBase(theRequest);
List<RuntimeResourceDefinition> defs = new ArrayList<>(myContext.getResourceDefinitionsWithExplicitId());
Collections.sort(defs, new Comparator<RuntimeResourceDefinition>() {
@Override
public int compare(RuntimeResourceDefinition theO1, RuntimeResourceDefinition theO2) {
int cmp = theO1.getName().compareTo(theO2.getName());
if (cmp==0) {
cmp=theO1.getResourceProfile(serverBase).compareTo(theO2.getResourceProfile(serverBase));
}
return cmp;
}});
ArrayList<StructureDefinition> retVal = new ArrayList<>();
for (RuntimeResourceDefinition next : defs) {
retVal.add((StructureDefinition) next.toProfile(serverBase));
}
return retVal;
}
private String getServerBase(ServletRequestDetails theHttpRequest) {
return myRestfulServer.getServerBaseForRequest(theHttpRequest);
}
}

View File

@ -21,10 +21,8 @@ package ca.uhn.fhir.model.dstu2;
*/
import ca.uhn.fhir.rest.api.server.IFhirVersionServer;
import ca.uhn.fhir.rest.server.IResourceProvider;
import ca.uhn.fhir.rest.server.RestfulServer;
import ca.uhn.fhir.rest.server.provider.dstu2.ServerConformanceProvider;
import ca.uhn.fhir.rest.server.provider.dstu2.ServerProfileProvider;
public class FhirServerDstu2 implements IFhirVersionServer {
@ -33,9 +31,4 @@ public class FhirServerDstu2 implements IFhirVersionServer {
return new ServerConformanceProvider(theServer);
}
@Override
public IResourceProvider createServerProfilesProvider(RestfulServer theRestfulServer) {
return new ServerProfileProvider(theRestfulServer);
}
}

View File

@ -1,88 +0,0 @@
package ca.uhn.fhir.rest.server.provider.dstu2;
/*
* #%L
* HAPI FHIR Structures - DSTU2 (FHIR v1.0.0)
* %%
* Copyright (C) 2014 - 2020 University Health Network
* %%
* 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.
* #L%
*/
import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.context.RuntimeResourceDefinition;
import ca.uhn.fhir.model.api.IResource;
import ca.uhn.fhir.model.dstu2.resource.StructureDefinition;
import ca.uhn.fhir.model.primitive.IdDt;
import ca.uhn.fhir.rest.annotation.IdParam;
import ca.uhn.fhir.rest.annotation.Read;
import ca.uhn.fhir.rest.annotation.Search;
import ca.uhn.fhir.rest.server.IResourceProvider;
import ca.uhn.fhir.rest.server.RestfulServer;
import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
public class ServerProfileProvider implements IResourceProvider {
private final FhirContext myContext;
private final RestfulServer myRestfulServer;
public ServerProfileProvider(RestfulServer theServer) {
myContext = theServer.getFhirContext();
myRestfulServer = theServer;
}
@Override
public Class<? extends IResource> getResourceType() {
return StructureDefinition.class;
}
@Read()
public StructureDefinition getProfileById(ServletRequestDetails theRequest, @IdParam IdDt theId) {
RuntimeResourceDefinition retVal = myContext.getResourceDefinitionById(theId.getIdPart());
if (retVal==null) {
return null;
}
String serverBase = getServerBase(theRequest);
return (StructureDefinition) retVal.toProfile(serverBase);
}
@Search()
public List<StructureDefinition> getAllProfiles(ServletRequestDetails theRequest) {
final String serverBase = getServerBase(theRequest);
List<RuntimeResourceDefinition> defs = new ArrayList<>(myContext.getResourceDefinitionsWithExplicitId());
Collections.sort(defs, new Comparator<RuntimeResourceDefinition>() {
@Override
public int compare(RuntimeResourceDefinition theO1, RuntimeResourceDefinition theO2) {
int cmp = theO1.getName().compareTo(theO2.getName());
if (cmp==0) {
cmp=theO1.getResourceProfile(serverBase).compareTo(theO2.getResourceProfile(serverBase));
}
return cmp;
}});
ArrayList<StructureDefinition> retVal = new ArrayList<>();
for (RuntimeResourceDefinition next : defs) {
retVal.add((StructureDefinition) next.toProfile(serverBase));
}
return retVal;
}
private String getServerBase(ServletRequestDetails theHttpRequest) {
return myRestfulServer.getServerBaseForRequest(theHttpRequest);
}
}

View File

@ -1,11 +1,8 @@
package org.hl7.fhir.dstu3.hapi.ctx;
import org.hl7.fhir.dstu3.hapi.rest.server.ServerCapabilityStatementProvider;
import org.hl7.fhir.dstu3.hapi.rest.server.ServerProfileProvider;
import ca.uhn.fhir.rest.api.server.IFhirVersionServer;
import ca.uhn.fhir.rest.server.IResourceProvider;
import ca.uhn.fhir.rest.server.RestfulServer;
import org.hl7.fhir.dstu3.hapi.rest.server.ServerCapabilityStatementProvider;
public class FhirServerDstu3 implements IFhirVersionServer {
@Override
@ -13,9 +10,4 @@ public class FhirServerDstu3 implements IFhirVersionServer {
return new ServerCapabilityStatementProvider(theServer);
}
@Override
public IResourceProvider createServerProfilesProvider(RestfulServer theRestfulServer) {
return new ServerProfileProvider(theRestfulServer);
}
}

View File

@ -1,88 +0,0 @@
package org.hl7.fhir.dstu3.hapi.rest.server;
/*
* #%L
* HAPI FHIR Structures - DSTU2 (FHIR v1.0.0)
* %%
* Copyright (C) 2014 - 2015 University Health Network
* %%
* 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.
* #L%
*/
import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.context.RuntimeResourceDefinition;
import ca.uhn.fhir.rest.annotation.IdParam;
import ca.uhn.fhir.rest.annotation.Read;
import ca.uhn.fhir.rest.annotation.Search;
import ca.uhn.fhir.rest.server.IResourceProvider;
import ca.uhn.fhir.rest.server.RestfulServer;
import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails;
import org.hl7.fhir.dstu3.model.IdType;
import org.hl7.fhir.dstu3.model.StructureDefinition;
import org.hl7.fhir.instance.model.api.IBaseResource;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
public class ServerProfileProvider implements IResourceProvider {
private final FhirContext myContext;
private final RestfulServer myRestfulServer;
public ServerProfileProvider(RestfulServer theServer) {
myContext = theServer.getFhirContext();
myRestfulServer = theServer;
}
@Override
public Class<? extends IBaseResource> getResourceType() {
return StructureDefinition.class;
}
@Read()
public StructureDefinition getProfileById(ServletRequestDetails theRequest, @IdParam IdType theId) {
RuntimeResourceDefinition retVal = myContext.getResourceDefinitionById(theId.getIdPart());
if (retVal==null) {
return null;
}
String serverBase = getServerBase(theRequest);
return (StructureDefinition) retVal.toProfile(serverBase);
}
@Search()
public List<StructureDefinition> getAllProfiles(ServletRequestDetails theRequest) {
final String serverBase = getServerBase(theRequest);
List<RuntimeResourceDefinition> defs = new ArrayList<>(myContext.getResourceDefinitionsWithExplicitId());
Collections.sort(defs, new Comparator<RuntimeResourceDefinition>() {
@Override
public int compare(RuntimeResourceDefinition theO1, RuntimeResourceDefinition theO2) {
int cmp = theO1.getName().compareTo(theO2.getName());
if (cmp==0) {
cmp=theO1.getResourceProfile(serverBase).compareTo(theO2.getResourceProfile(serverBase));
}
return cmp;
}});
ArrayList<StructureDefinition> retVal = new ArrayList<>();
for (RuntimeResourceDefinition next : defs) {
retVal.add((StructureDefinition) next.toProfile(serverBase));
}
return retVal;
}
private String getServerBase(ServletRequestDetails theHttpRequest) {
return myRestfulServer.getServerBaseForRequest(theHttpRequest);
}
}

View File

@ -1,11 +1,8 @@
package org.hl7.fhir.dstu2.hapi.ctx;
import org.hl7.fhir.dstu2.hapi.rest.server.ServerConformanceProvider;
import org.hl7.fhir.dstu2.hapi.rest.server.ServerProfileProvider;
import ca.uhn.fhir.rest.api.server.IFhirVersionServer;
import ca.uhn.fhir.rest.server.IResourceProvider;
import ca.uhn.fhir.rest.server.RestfulServer;
import org.hl7.fhir.dstu2.hapi.rest.server.ServerConformanceProvider;
public class FhirServerDstu2Hl7Org2 implements IFhirVersionServer {
@ -14,9 +11,4 @@ public class FhirServerDstu2Hl7Org2 implements IFhirVersionServer {
return new ServerConformanceProvider(theServer);
}
@Override
public IResourceProvider createServerProfilesProvider(RestfulServer theRestfulServer) {
return new ServerProfileProvider(theRestfulServer);
}
}

View File

@ -1,88 +0,0 @@
package org.hl7.fhir.dstu2.hapi.rest.server;
/*
* #%L
* HAPI FHIR Structures - HL7.org DSTU2
* %%
* Copyright (C) 2014 - 2015 University Health Network
* %%
* 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.
* #L%
*/
import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.context.RuntimeResourceDefinition;
import ca.uhn.fhir.rest.annotation.IdParam;
import ca.uhn.fhir.rest.annotation.Read;
import ca.uhn.fhir.rest.annotation.Search;
import ca.uhn.fhir.rest.server.IResourceProvider;
import ca.uhn.fhir.rest.server.RestfulServer;
import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails;
import org.hl7.fhir.dstu2.model.IdType;
import org.hl7.fhir.dstu2.model.StructureDefinition;
import org.hl7.fhir.instance.model.api.IBaseResource;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
public class ServerProfileProvider implements IResourceProvider {
private final FhirContext myContext;
private final RestfulServer myRestfulServer;
public ServerProfileProvider(RestfulServer theServer) {
myContext = theServer.getFhirContext();
myRestfulServer = theServer;
}
@Override
public Class<? extends IBaseResource> getResourceType() {
return StructureDefinition.class;
}
@Read()
public StructureDefinition getProfileById(ServletRequestDetails theRequest, @IdParam IdType theId) {
RuntimeResourceDefinition retVal = myContext.getResourceDefinitionById(theId.getIdPart());
if (retVal==null) {
return null;
}
String serverBase = getServerBase(theRequest);
return (StructureDefinition) retVal.toProfile(serverBase);
}
@Search()
public List<StructureDefinition> getAllProfiles(ServletRequestDetails theRequest) {
final String serverBase = getServerBase(theRequest);
List<RuntimeResourceDefinition> defs = new ArrayList<>(myContext.getResourceDefinitionsWithExplicitId());
Collections.sort(defs, new Comparator<RuntimeResourceDefinition>() {
@Override
public int compare(RuntimeResourceDefinition theO1, RuntimeResourceDefinition theO2) {
int cmp = theO1.getName().compareTo(theO2.getName());
if (cmp==0) {
cmp=theO1.getResourceProfile(serverBase).compareTo(theO2.getResourceProfile(serverBase));
}
return cmp;
}});
ArrayList<StructureDefinition> retVal = new ArrayList<>();
for (RuntimeResourceDefinition next : defs) {
retVal.add((StructureDefinition) next.toProfile(serverBase));
}
return retVal;
}
private String getServerBase(ServletRequestDetails theHttpRequest) {
return myRestfulServer.getServerBaseForRequest(theHttpRequest);
}
}

View File

@ -1,10 +1,8 @@
package org.hl7.fhir.r4.hapi.ctx;
import ca.uhn.fhir.rest.api.server.IFhirVersionServer;
import ca.uhn.fhir.rest.server.IResourceProvider;
import ca.uhn.fhir.rest.server.RestfulServer;
import org.hl7.fhir.r4.hapi.rest.server.ServerCapabilityStatementProvider;
import org.hl7.fhir.r4.hapi.rest.server.ServerProfileProvider;
public class FhirServerR4 implements IFhirVersionServer {
@Override
@ -12,9 +10,4 @@ public class FhirServerR4 implements IFhirVersionServer {
return new ServerCapabilityStatementProvider(theServer);
}
@Override
public IResourceProvider createServerProfilesProvider(RestfulServer theRestfulServer) {
return new ServerProfileProvider(theRestfulServer);
}
}

View File

@ -1,86 +0,0 @@
package org.hl7.fhir.r4.hapi.rest.server;
/*
* #%L
* HAPI FHIR Structures - DSTU2 (FHIR v1.0.0)
* %%
* Copyright (C) 2014 - 2015 University Health Network
* %%
* 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.
* #L%
*/
import java.util.*;
import javax.servlet.http.HttpServletRequest;
import ca.uhn.fhir.rest.api.server.RequestDetails;
import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails;
import org.hl7.fhir.instance.model.api.IBaseResource;
import org.hl7.fhir.r4.model.IdType;
import org.hl7.fhir.r4.model.StructureDefinition;
import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.context.RuntimeResourceDefinition;
import ca.uhn.fhir.rest.annotation.*;
import ca.uhn.fhir.rest.server.IResourceProvider;
import ca.uhn.fhir.rest.server.RestfulServer;
public class ServerProfileProvider implements IResourceProvider {
private final FhirContext myContext;
private final RestfulServer myRestfulServer;
public ServerProfileProvider(RestfulServer theServer) {
myContext = theServer.getFhirContext();
myRestfulServer = theServer;
}
@Override
public Class<? extends IBaseResource> getResourceType() {
return StructureDefinition.class;
}
@Read()
public StructureDefinition getProfileById(ServletRequestDetails theRequest, @IdParam IdType theId) {
RuntimeResourceDefinition retVal = myContext.getResourceDefinitionById(theId.getIdPart());
if (retVal==null) {
return null;
}
String serverBase = getServerBase(theRequest);
return (StructureDefinition) retVal.toProfile(serverBase);
}
@Search()
public List<StructureDefinition> getAllProfiles(ServletRequestDetails theRequest) {
final String serverBase = getServerBase(theRequest);
List<RuntimeResourceDefinition> defs = new ArrayList<RuntimeResourceDefinition>(myContext.getResourceDefinitionsWithExplicitId());
Collections.sort(defs, new Comparator<RuntimeResourceDefinition>() {
@Override
public int compare(RuntimeResourceDefinition theO1, RuntimeResourceDefinition theO2) {
int cmp = theO1.getName().compareTo(theO2.getName());
if (cmp==0) {
cmp=theO1.getResourceProfile(serverBase).compareTo(theO2.getResourceProfile(serverBase));
}
return cmp;
}});
ArrayList<StructureDefinition> retVal = new ArrayList<StructureDefinition>();
for (RuntimeResourceDefinition next : defs) {
retVal.add((StructureDefinition) next.toProfile(serverBase));
}
return retVal;
}
private String getServerBase(ServletRequestDetails theHttpRequest) {
return myRestfulServer.getServerBaseForRequest(theHttpRequest);
}
}

View File

@ -1,10 +1,8 @@
package org.hl7.fhir.r5.hapi.ctx;
import ca.uhn.fhir.rest.api.server.IFhirVersionServer;
import ca.uhn.fhir.rest.server.IResourceProvider;
import ca.uhn.fhir.rest.server.RestfulServer;
import org.hl7.fhir.r5.hapi.rest.server.ServerCapabilityStatementProvider;
import org.hl7.fhir.r5.hapi.rest.server.ServerProfileProvider;
public class FhirServerR5 implements IFhirVersionServer {
@Override
@ -12,9 +10,4 @@ public class FhirServerR5 implements IFhirVersionServer {
return new ServerCapabilityStatementProvider();
}
@Override
public IResourceProvider createServerProfilesProvider(RestfulServer theRestfulServer) {
return new ServerProfileProvider(theRestfulServer);
}
}

View File

@ -1,88 +0,0 @@
package org.hl7.fhir.r5.hapi.rest.server;
/*
* #%L
* HAPI FHIR Structures - DSTU2 (FHIR v1.0.0)
* %%
* Copyright (C) 2014 - 2015 University Health Network
* %%
* 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.
* #L%
*/
import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.context.RuntimeResourceDefinition;
import ca.uhn.fhir.rest.annotation.IdParam;
import ca.uhn.fhir.rest.annotation.Read;
import ca.uhn.fhir.rest.annotation.Search;
import ca.uhn.fhir.rest.server.IResourceProvider;
import ca.uhn.fhir.rest.server.RestfulServer;
import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails;
import org.hl7.fhir.instance.model.api.IBaseResource;
import org.hl7.fhir.r5.model.IdType;
import org.hl7.fhir.r5.model.StructureDefinition;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
public class ServerProfileProvider implements IResourceProvider {
private final FhirContext myContext;
private final RestfulServer myRestfulServer;
public ServerProfileProvider(RestfulServer theServer) {
myContext = theServer.getFhirContext();
myRestfulServer = theServer;
}
@Override
public Class<? extends IBaseResource> getResourceType() {
return StructureDefinition.class;
}
@Read()
public StructureDefinition getProfileById(ServletRequestDetails theRequest, @IdParam IdType theId) {
RuntimeResourceDefinition retVal = myContext.getResourceDefinitionById(theId.getIdPart());
if (retVal==null) {
return null;
}
String serverBase = getServerBase(theRequest);
return (StructureDefinition) retVal.toProfile(serverBase);
}
@Search()
public List<StructureDefinition> getAllProfiles(ServletRequestDetails theRequest) {
final String serverBase = getServerBase(theRequest);
List<RuntimeResourceDefinition> defs = new ArrayList<RuntimeResourceDefinition>(myContext.getResourceDefinitionsWithExplicitId());
Collections.sort(defs, new Comparator<RuntimeResourceDefinition>() {
@Override
public int compare(RuntimeResourceDefinition theO1, RuntimeResourceDefinition theO2) {
int cmp = theO1.getName().compareTo(theO2.getName());
if (cmp==0) {
cmp=theO1.getResourceProfile(serverBase).compareTo(theO2.getResourceProfile(serverBase));
}
return cmp;
}});
ArrayList<StructureDefinition> retVal = new ArrayList<StructureDefinition>();
for (RuntimeResourceDefinition next : defs) {
retVal.add((StructureDefinition) next.toProfile(serverBase));
}
return retVal;
}
private String getServerBase(ServletRequestDetails theHttpRequest) {
return myRestfulServer.getServerBaseForRequest(theHttpRequest);
}
}