More versions work

This commit is contained in:
James Agnew 2014-10-16 11:46:25 -04:00
parent abecee2766
commit dbc07dcb50
23 changed files with 507 additions and 87 deletions

View File

@ -7,20 +7,26 @@ import ca.uhn.fhir.model.api.BaseResource;
import ca.uhn.fhir.model.api.IResource; import ca.uhn.fhir.model.api.IResource;
import ca.uhn.fhir.model.api.IResourceBlock; import ca.uhn.fhir.model.api.IResourceBlock;
import ca.uhn.fhir.model.base.composite.BaseCodingDt; import ca.uhn.fhir.model.base.composite.BaseCodingDt;
import ca.uhn.fhir.model.dstu.valueset.IssueSeverityEnum;
import ca.uhn.fhir.model.primitive.BoundCodeDt;
import ca.uhn.fhir.model.primitive.StringDt; import ca.uhn.fhir.model.primitive.StringDt;
public abstract class BaseOperationOutcome extends BaseResource implements IResource { public abstract class BaseOperationOutcome extends BaseResource implements IResource {
public abstract BaseIssue addIssue();
public abstract List<? extends BaseIssue> getIssue(); public abstract List<? extends BaseIssue> getIssue();
public static abstract class BaseIssue extends BaseIdentifiableElement implements IResourceBlock {
public abstract BaseCodingDt getType();
public abstract StringDt getDetails();
}
public abstract BaseIssue getIssueFirstRep(); public abstract BaseIssue getIssueFirstRep();
public static abstract class BaseIssue extends BaseIdentifiableElement implements IResourceBlock {
public abstract BoundCodeDt<IssueSeverityEnum> getSeverity();
public abstract StringDt getDetails();
public abstract BaseCodingDt getType();
}
} }

View File

@ -26,7 +26,7 @@ import ca.uhn.fhir.model.primitive.IdDt;
public class MethodOutcome { public class MethodOutcome {
private IdDt myId; private IdDt myId;
private BaseOperationOutcome myBaseOperationOutcome; private BaseOperationOutcome myOperationOutcome;
private IdDt myVersionId; private IdDt myVersionId;
private Boolean myCreated; private Boolean myCreated;
@ -72,7 +72,7 @@ public class MethodOutcome {
*/ */
public MethodOutcome(IdDt theId, BaseOperationOutcome theBaseOperationOutcome) { public MethodOutcome(IdDt theId, BaseOperationOutcome theBaseOperationOutcome) {
myId = theId; myId = theId;
myBaseOperationOutcome = theBaseOperationOutcome; myOperationOutcome = theBaseOperationOutcome;
} }
/** /**
@ -90,7 +90,7 @@ public class MethodOutcome {
*/ */
public MethodOutcome(IdDt theId, BaseOperationOutcome theBaseOperationOutcome, Boolean theCreated) { public MethodOutcome(IdDt theId, BaseOperationOutcome theBaseOperationOutcome, Boolean theCreated) {
myId = theId; myId = theId;
myBaseOperationOutcome = theBaseOperationOutcome; myOperationOutcome = theBaseOperationOutcome;
myCreated = theCreated; myCreated = theCreated;
} }
@ -108,7 +108,7 @@ public class MethodOutcome {
public MethodOutcome(IdDt theId, IdDt theVersionId, BaseOperationOutcome theBaseOperationOutcome) { public MethodOutcome(IdDt theId, IdDt theVersionId, BaseOperationOutcome theBaseOperationOutcome) {
myId = theId; myId = theId;
myVersionId = theVersionId; myVersionId = theVersionId;
myBaseOperationOutcome = theBaseOperationOutcome; myOperationOutcome = theBaseOperationOutcome;
} }
public IdDt getId() { public IdDt getId() {
@ -120,8 +120,8 @@ public class MethodOutcome {
* *
* @return This method <b>will return null</b>, unlike many methods in the API. * @return This method <b>will return null</b>, unlike many methods in the API.
*/ */
public BaseOperationOutcome getBaseOperationOutcome() { public BaseOperationOutcome getOperationOutcome() {
return myBaseOperationOutcome; return myOperationOutcome;
} }
/** /**
@ -158,8 +158,8 @@ public class MethodOutcome {
/** /**
* Sets the {@link BaseOperationOutcome} resource to return to the client. Set to <code>null</code> (which is the default) if none. * Sets the {@link BaseOperationOutcome} resource to return to the client. Set to <code>null</code> (which is the default) if none.
*/ */
public void setBaseOperationOutcome(BaseOperationOutcome theBaseOperationOutcome) { public void setOperationOutcome(BaseOperationOutcome theBaseOperationOutcome) {
myBaseOperationOutcome = theBaseOperationOutcome; myOperationOutcome = theBaseOperationOutcome;
} }
/** /**

View File

@ -41,7 +41,6 @@ import ca.uhn.fhir.model.api.Bundle;
import ca.uhn.fhir.model.api.IResource; import ca.uhn.fhir.model.api.IResource;
import ca.uhn.fhir.model.api.TagList; import ca.uhn.fhir.model.api.TagList;
import ca.uhn.fhir.model.base.resource.BaseOperationOutcome; import ca.uhn.fhir.model.base.resource.BaseOperationOutcome;
import ca.uhn.fhir.model.dstu.resource.OperationOutcome;
import ca.uhn.fhir.model.dstu.valueset.RestfulOperationSystemEnum; import ca.uhn.fhir.model.dstu.valueset.RestfulOperationSystemEnum;
import ca.uhn.fhir.model.dstu.valueset.RestfulOperationTypeEnum; import ca.uhn.fhir.model.dstu.valueset.RestfulOperationTypeEnum;
import ca.uhn.fhir.parser.IParser; import ca.uhn.fhir.parser.IParser;

View File

@ -38,7 +38,7 @@ import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.model.api.IResource; import ca.uhn.fhir.model.api.IResource;
import ca.uhn.fhir.model.api.ResourceMetadataKeyEnum; import ca.uhn.fhir.model.api.ResourceMetadataKeyEnum;
import ca.uhn.fhir.model.api.TagList; import ca.uhn.fhir.model.api.TagList;
import ca.uhn.fhir.model.dstu.resource.OperationOutcome; import ca.uhn.fhir.model.base.resource.BaseOperationOutcome;
import ca.uhn.fhir.model.primitive.IdDt; import ca.uhn.fhir.model.primitive.IdDt;
import ca.uhn.fhir.parser.IParser; import ca.uhn.fhir.parser.IParser;
import ca.uhn.fhir.rest.api.MethodOutcome; import ca.uhn.fhir.rest.api.MethodOutcome;
@ -146,7 +146,7 @@ abstract class BaseOutcomeReturningMethodBinding extends BaseMethodBinding<Metho
} }
} }
OperationOutcome outcome = response != null ? response.getOperationOutcome() : null; BaseOperationOutcome outcome = response != null ? response.getOperationOutcome() : null;
for (int i = theServer.getInterceptors().size() - 1; i >= 0; i--) { for (int i = theServer.getInterceptors().size() - 1; i >= 0; i--) {
IServerInterceptor next = theServer.getInterceptors().get(i); IServerInterceptor next = theServer.getInterceptors().get(i);
boolean continueProcessing = next.outgoingResponse(theRequest, outcome, theRequest.getServletRequest(), theRequest.getServletResponse()); boolean continueProcessing = next.outgoingResponse(theRequest, outcome, theRequest.getServletRequest(), theRequest.getServletResponse());

View File

@ -1,6 +1,7 @@
package ca.uhn.fhir.rest.method; package ca.uhn.fhir.rest.method;
import static org.apache.commons.lang3.StringUtils.*; import static org.apache.commons.lang3.StringUtils.isBlank;
import static org.apache.commons.lang3.StringUtils.isNotBlank;
import java.io.IOException; import java.io.IOException;
import java.io.PushbackReader; import java.io.PushbackReader;
@ -34,7 +35,7 @@ import ca.uhn.fhir.model.api.ResourceMetadataKeyEnum;
import ca.uhn.fhir.model.api.Tag; import ca.uhn.fhir.model.api.Tag;
import ca.uhn.fhir.model.api.TagList; import ca.uhn.fhir.model.api.TagList;
import ca.uhn.fhir.model.api.annotation.Description; import ca.uhn.fhir.model.api.annotation.Description;
import ca.uhn.fhir.model.dstu.resource.OperationOutcome; import ca.uhn.fhir.model.base.resource.BaseOperationOutcome;
import ca.uhn.fhir.model.primitive.IdDt; import ca.uhn.fhir.model.primitive.IdDt;
import ca.uhn.fhir.model.primitive.InstantDt; import ca.uhn.fhir.model.primitive.InstantDt;
import ca.uhn.fhir.parser.IParser; import ca.uhn.fhir.parser.IParser;
@ -303,8 +304,8 @@ public class MethodUtil {
if (reader != null) { if (reader != null) {
IParser parser = ct.newParser(theContext); IParser parser = ct.newParser(theContext);
IResource outcome = parser.parseResource(reader); IResource outcome = parser.parseResource(reader);
if (outcome instanceof OperationOutcome) { if (outcome instanceof BaseOperationOutcome) {
retVal.setOperationOutcome((OperationOutcome) outcome); retVal.setOperationOutcome((BaseOperationOutcome) outcome);
} }
} }

View File

@ -43,7 +43,6 @@ import ca.uhn.fhir.model.dstu.valueset.SearchParamTypeEnum;
import ca.uhn.fhir.model.primitive.StringDt; import ca.uhn.fhir.model.primitive.StringDt;
import ca.uhn.fhir.rest.annotation.OptionalParam; import ca.uhn.fhir.rest.annotation.OptionalParam;
import ca.uhn.fhir.rest.param.BaseQueryParameter; import ca.uhn.fhir.rest.param.BaseQueryParameter;
import ca.uhn.fhir.rest.param.CodingListParam;
import ca.uhn.fhir.rest.param.CompositeAndListParam; import ca.uhn.fhir.rest.param.CompositeAndListParam;
import ca.uhn.fhir.rest.param.CompositeOrListParam; import ca.uhn.fhir.rest.param.CompositeOrListParam;
import ca.uhn.fhir.rest.param.CompositeParam; import ca.uhn.fhir.rest.param.CompositeParam;
@ -51,7 +50,6 @@ import ca.uhn.fhir.rest.param.DateAndListParam;
import ca.uhn.fhir.rest.param.DateOrListParam; import ca.uhn.fhir.rest.param.DateOrListParam;
import ca.uhn.fhir.rest.param.DateParam; import ca.uhn.fhir.rest.param.DateParam;
import ca.uhn.fhir.rest.param.DateRangeParam; import ca.uhn.fhir.rest.param.DateRangeParam;
import ca.uhn.fhir.rest.param.IdentifierListParam;
import ca.uhn.fhir.rest.param.NumberAndListParam; import ca.uhn.fhir.rest.param.NumberAndListParam;
import ca.uhn.fhir.rest.param.NumberOrListParam; import ca.uhn.fhir.rest.param.NumberOrListParam;
import ca.uhn.fhir.rest.param.NumberParam; import ca.uhn.fhir.rest.param.NumberParam;
@ -306,16 +304,12 @@ public class SearchParameter extends BaseQueryParameter {
myParamType = SearchParamTypeEnum.STRING; myParamType = SearchParamTypeEnum.STRING;
} else if (QualifiedDateParam.class.isAssignableFrom(type)) { } else if (QualifiedDateParam.class.isAssignableFrom(type)) {
myParamType = SearchParamTypeEnum.DATE; myParamType = SearchParamTypeEnum.DATE;
} else if (CodingListParam.class.isAssignableFrom(type)) {
myParamType = SearchParamTypeEnum.TOKEN;
} else if (BaseIdentifierDt.class.isAssignableFrom(type)) { } else if (BaseIdentifierDt.class.isAssignableFrom(type)) {
myParamType = SearchParamTypeEnum.TOKEN; myParamType = SearchParamTypeEnum.TOKEN;
} else if (BaseQuantityDt.class.isAssignableFrom(type)) { } else if (BaseQuantityDt.class.isAssignableFrom(type)) {
myParamType = SearchParamTypeEnum.QUANTITY; myParamType = SearchParamTypeEnum.QUANTITY;
} else if (ReferenceParam.class.isAssignableFrom(type)) { } else if (ReferenceParam.class.isAssignableFrom(type)) {
myParamType = SearchParamTypeEnum.REFERENCE; myParamType = SearchParamTypeEnum.REFERENCE;
} else if (IdentifierListParam.class.isAssignableFrom(type)) {
myParamType = SearchParamTypeEnum.TOKEN;
} else { } else {
throw new ConfigurationException("Unknown search parameter type: " + type); throw new ConfigurationException("Unknown search parameter type: " + type);
} }

View File

@ -20,7 +20,7 @@ package ca.uhn.fhir.rest.method;
* #L% * #L%
*/ */
import static org.apache.commons.lang3.StringUtils.*; import static org.apache.commons.lang3.StringUtils.isNotBlank;
import java.io.IOException; import java.io.IOException;
import java.lang.reflect.Method; import java.lang.reflect.Method;
@ -32,7 +32,7 @@ import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.model.api.Bundle; import ca.uhn.fhir.model.api.Bundle;
import ca.uhn.fhir.model.api.IResource; import ca.uhn.fhir.model.api.IResource;
import ca.uhn.fhir.model.api.ResourceMetadataKeyEnum; import ca.uhn.fhir.model.api.ResourceMetadataKeyEnum;
import ca.uhn.fhir.model.dstu.resource.OperationOutcome; import ca.uhn.fhir.model.base.resource.BaseOperationOutcome;
import ca.uhn.fhir.model.dstu.valueset.RestfulOperationSystemEnum; import ca.uhn.fhir.model.dstu.valueset.RestfulOperationSystemEnum;
import ca.uhn.fhir.model.dstu.valueset.RestfulOperationTypeEnum; import ca.uhn.fhir.model.dstu.valueset.RestfulOperationTypeEnum;
import ca.uhn.fhir.model.primitive.IdDt; import ca.uhn.fhir.model.primitive.IdDt;
@ -127,7 +127,7 @@ public class TransactionMethodBinding extends BaseResourceReturningMethodBinding
IdDt oldId = oldIds.get(retResources.get(i)); IdDt oldId = oldIds.get(retResources.get(i));
IResource newRes = retResources.get(i); IResource newRes = retResources.get(i);
if (newRes.getId() == null || newRes.getId().isEmpty()) { if (newRes.getId() == null || newRes.getId().isEmpty()) {
if (!(newRes instanceof OperationOutcome)) { if (!(newRes instanceof BaseOperationOutcome)) {
throw new InternalErrorException("Transaction method returned resource at index " + i + " with no id specified - IResource#setId(IdDt)"); throw new InternalErrorException("Transaction method returned resource at index " + i + " with no id specified - IResource#setId(IdDt)");
} }
} }

View File

@ -50,7 +50,7 @@ import ca.uhn.fhir.model.primitive.CodeDt;
import ca.uhn.fhir.model.primitive.StringDt; import ca.uhn.fhir.model.primitive.StringDt;
import ca.uhn.fhir.model.primitive.UriDt; import ca.uhn.fhir.model.primitive.UriDt;
class InternalCodingDt public class InternalCodingDt
extends BaseCodingDt implements ICompositeDatatype extends BaseCodingDt implements ICompositeDatatype
{ {

View File

@ -20,7 +20,7 @@ package ca.uhn.fhir.rest.server;
* #L% * #L%
*/ */
import static org.apache.commons.lang3.StringUtils.*; import static org.apache.commons.lang3.StringUtils.isNotBlank;
import java.io.IOException; import java.io.IOException;
import java.io.OutputStreamWriter; import java.io.OutputStreamWriter;
@ -61,10 +61,10 @@ import ca.uhn.fhir.model.api.IResource;
import ca.uhn.fhir.model.api.ResourceMetadataKeyEnum; import ca.uhn.fhir.model.api.ResourceMetadataKeyEnum;
import ca.uhn.fhir.model.api.Tag; import ca.uhn.fhir.model.api.Tag;
import ca.uhn.fhir.model.api.TagList; import ca.uhn.fhir.model.api.TagList;
import ca.uhn.fhir.model.base.resource.BaseOperationOutcome;
import ca.uhn.fhir.model.base.resource.BaseOperationOutcome.BaseIssue;
import ca.uhn.fhir.model.dstu.composite.ResourceReferenceDt; import ca.uhn.fhir.model.dstu.composite.ResourceReferenceDt;
import ca.uhn.fhir.model.dstu.resource.Binary; import ca.uhn.fhir.model.dstu.resource.Binary;
import ca.uhn.fhir.model.dstu.resource.OperationOutcome;
import ca.uhn.fhir.model.dstu.resource.OperationOutcome.Issue;
import ca.uhn.fhir.model.dstu.valueset.IssueSeverityEnum; import ca.uhn.fhir.model.dstu.valueset.IssueSeverityEnum;
import ca.uhn.fhir.model.primitive.IdDt; import ca.uhn.fhir.model.primitive.IdDt;
import ca.uhn.fhir.model.primitive.InstantDt; import ca.uhn.fhir.model.primitive.InstantDt;
@ -638,7 +638,7 @@ public class RestfulServer extends HttpServlet {
} catch (Throwable e) { } catch (Throwable e) {
OperationOutcome oo = null; BaseOperationOutcome oo = null;
int statusCode = 500; int statusCode = 500;
if (e instanceof BaseServerResponseException) { if (e instanceof BaseServerResponseException) {
@ -647,8 +647,14 @@ public class RestfulServer extends HttpServlet {
} }
if (oo == null) { if (oo == null) {
oo = new OperationOutcome(); try {
Issue issue = oo.addIssue(); oo = (BaseOperationOutcome) myFhirContext.getResourceDefinition("OperationOutcome").getImplementingClass().newInstance();
} catch (Exception e1) {
ourLog.error("Failed to instantiate OperationOutcome resource instance", e1);
throw new ServletException("Failed to instantiate OperationOutcome resource instance", e1);
}
BaseIssue issue = oo.addIssue();
issue.getSeverity().setValueAsEnum(IssueSeverityEnum.ERROR); issue.getSeverity().setValueAsEnum(IssueSeverityEnum.ERROR);
if (e instanceof InternalErrorException) { if (e instanceof InternalErrorException) {
ourLog.error("Failure during REST processing", e); ourLog.error("Failure during REST processing", e);
@ -979,7 +985,7 @@ public class RestfulServer extends HttpServlet {
for (IResource next : resourceList) { for (IResource next : resourceList) {
if (next.getId() == null || next.getId().isEmpty()) { if (next.getId() == null || next.getId().isEmpty()) {
if (!(next instanceof OperationOutcome)) { if (!(next instanceof BaseOperationOutcome)) {
throw new InternalErrorException("Server method returned resource of type[" + next.getClass().getSimpleName() + "] with no ID specified (IResource#setId(IdDt) must be called)"); throw new InternalErrorException("Server method returned resource of type[" + next.getClass().getSimpleName() + "] with no ID specified (IResource#setId(IdDt) must be called)");
} }
} }

View File

@ -1,6 +1,6 @@
package ca.uhn.fhir.rest.server.exceptions; package ca.uhn.fhir.rest.server.exceptions;
import ca.uhn.fhir.model.dstu.resource.OperationOutcome; import ca.uhn.fhir.model.base.resource.BaseOperationOutcome;
import ca.uhn.fhir.rest.server.Constants; import ca.uhn.fhir.rest.server.Constants;
/* /*
@ -52,7 +52,7 @@ public class InternalErrorException extends BaseServerResponseException {
* The message * The message
* @param theOperationOutcome The OperationOutcome resource to return to the client * @param theOperationOutcome The OperationOutcome resource to return to the client
*/ */
public InternalErrorException(String theMessage, OperationOutcome theOperationOutcome) { public InternalErrorException(String theMessage, BaseOperationOutcome theOperationOutcome) {
super(STATUS_CODE, theMessage, theOperationOutcome); super(STATUS_CODE, theMessage, theOperationOutcome);
} }

View File

@ -1,6 +1,6 @@
package ca.uhn.fhir.rest.server.exceptions; package ca.uhn.fhir.rest.server.exceptions;
import ca.uhn.fhir.model.dstu.resource.OperationOutcome; import ca.uhn.fhir.model.base.resource.BaseOperationOutcome;
import ca.uhn.fhir.rest.server.Constants; import ca.uhn.fhir.rest.server.Constants;
/* /*
@ -52,7 +52,7 @@ public class InvalidRequestException extends BaseServerResponseException {
* The message * The message
* @param theOperationOutcome The OperationOutcome resource to return to the client * @param theOperationOutcome The OperationOutcome resource to return to the client
*/ */
public InvalidRequestException(String theMessage, OperationOutcome theOperationOutcome) { public InvalidRequestException(String theMessage, BaseOperationOutcome theOperationOutcome) {
super(STATUS_CODE, theMessage, theOperationOutcome); super(STATUS_CODE, theMessage, theOperationOutcome);
} }

View File

@ -1,6 +1,6 @@
package ca.uhn.fhir.rest.server.exceptions; package ca.uhn.fhir.rest.server.exceptions;
import ca.uhn.fhir.model.dstu.resource.OperationOutcome; import ca.uhn.fhir.model.base.resource.BaseOperationOutcome;
import ca.uhn.fhir.rest.server.Constants; import ca.uhn.fhir.rest.server.Constants;
/* /*
@ -44,7 +44,7 @@ public class MethodNotAllowedException extends BaseServerResponseException {
* The message * The message
* @param theOperationOutcome The OperationOutcome resource to return to the client * @param theOperationOutcome The OperationOutcome resource to return to the client
*/ */
public MethodNotAllowedException(String theMessage, OperationOutcome theOperationOutcome) { public MethodNotAllowedException(String theMessage, BaseOperationOutcome theOperationOutcome) {
super(STATUS_CODE, theMessage, theOperationOutcome); super(STATUS_CODE, theMessage, theOperationOutcome);
} }

View File

@ -1,5 +1,5 @@
package ca.uhn.fhir.rest.server.exceptions; package ca.uhn.fhir.rest.server.exceptions;
import ca.uhn.fhir.model.dstu.resource.OperationOutcome; import ca.uhn.fhir.model.base.resource.BaseOperationOutcome;
import ca.uhn.fhir.rest.server.Constants; import ca.uhn.fhir.rest.server.Constants;
/* /*
@ -54,7 +54,7 @@ public static final int STATUS_CODE = Constants.STATUS_HTTP_501_NOT_IMPLEMENTED;
* The message * The message
* @param theOperationOutcome The OperationOutcome resource to return to the client * @param theOperationOutcome The OperationOutcome resource to return to the client
*/ */
public NotImplementedOperationException(String theMessage, OperationOutcome theOperationOutcome) { public NotImplementedOperationException(String theMessage, BaseOperationOutcome theOperationOutcome) {
super(STATUS_CODE, theMessage, theOperationOutcome); super(STATUS_CODE, theMessage, theOperationOutcome);
} }

View File

@ -21,8 +21,8 @@ package ca.uhn.fhir.rest.server.exceptions;
*/ */
import ca.uhn.fhir.model.api.IResource; import ca.uhn.fhir.model.api.IResource;
import ca.uhn.fhir.model.dstu.composite.IdentifierDt; import ca.uhn.fhir.model.base.composite.BaseIdentifierDt;
import ca.uhn.fhir.model.dstu.resource.OperationOutcome; import ca.uhn.fhir.model.base.resource.BaseOperationOutcome;
import ca.uhn.fhir.model.primitive.IdDt; import ca.uhn.fhir.model.primitive.IdDt;
import ca.uhn.fhir.rest.server.Constants; import ca.uhn.fhir.rest.server.Constants;
@ -38,7 +38,7 @@ public class ResourceGoneException extends BaseServerResponseException {
super(STATUS_CODE, "Resource " + (theId != null ? theId.getValue() : "") + " is gone/deleted"); super(STATUS_CODE, "Resource " + (theId != null ? theId.getValue() : "") + " is gone/deleted");
} }
public ResourceGoneException(Class<? extends IResource> theClass, IdentifierDt thePatientId) { public ResourceGoneException(Class<? extends IResource> theClass, BaseIdentifierDt thePatientId) {
super(STATUS_CODE, "Resource of type " + theClass.getSimpleName() + " with ID " + thePatientId + " is gone/deleted"); super(STATUS_CODE, "Resource of type " + theClass.getSimpleName() + " with ID " + thePatientId + " is gone/deleted");
} }
@ -53,7 +53,7 @@ public class ResourceGoneException extends BaseServerResponseException {
* The message * The message
* @param theOperationOutcome The OperationOutcome resource to return to the client * @param theOperationOutcome The OperationOutcome resource to return to the client
*/ */
public ResourceGoneException(String theMessage, OperationOutcome theOperationOutcome) { public ResourceGoneException(String theMessage, BaseOperationOutcome theOperationOutcome) {
super(STATUS_CODE, theMessage, theOperationOutcome); super(STATUS_CODE, theMessage, theOperationOutcome);
} }

View File

@ -21,8 +21,8 @@ package ca.uhn.fhir.rest.server.exceptions;
*/ */
import ca.uhn.fhir.model.api.IResource; import ca.uhn.fhir.model.api.IResource;
import ca.uhn.fhir.model.dstu.composite.IdentifierDt; import ca.uhn.fhir.model.base.composite.BaseIdentifierDt;
import ca.uhn.fhir.model.dstu.resource.OperationOutcome; import ca.uhn.fhir.model.base.resource.BaseOperationOutcome;
import ca.uhn.fhir.model.primitive.IdDt; import ca.uhn.fhir.model.primitive.IdDt;
import ca.uhn.fhir.rest.server.Constants; import ca.uhn.fhir.rest.server.Constants;
@ -39,7 +39,7 @@ public class ResourceNotFoundException extends BaseServerResponseException {
super(STATUS_CODE, createErrorMessage(theClass, theId)); super(STATUS_CODE, createErrorMessage(theClass, theId));
} }
public ResourceNotFoundException(Class<? extends IResource> theClass, IdDt theId, OperationOutcome theOperationOutcome) { public ResourceNotFoundException(Class<? extends IResource> theClass, IdDt theId, BaseOperationOutcome theOperationOutcome) {
super(STATUS_CODE, createErrorMessage(theClass, theId), theOperationOutcome); super(STATUS_CODE, createErrorMessage(theClass, theId), theOperationOutcome);
} }
@ -50,14 +50,14 @@ public class ResourceNotFoundException extends BaseServerResponseException {
* The message * The message
* @param theOperationOutcome The OperationOutcome resource to return to the client * @param theOperationOutcome The OperationOutcome resource to return to the client
*/ */
public ResourceNotFoundException(String theMessage, OperationOutcome theOperationOutcome) { public ResourceNotFoundException(String theMessage, BaseOperationOutcome theOperationOutcome) {
super(STATUS_CODE, theMessage, theOperationOutcome); super(STATUS_CODE, theMessage, theOperationOutcome);
} }
/** /**
* @deprecated This doesn't make sense, since an identifier is not a resource ID and shouldn't generate a 404 if it isn't found - Should be removed * @deprecated This doesn't make sense, since an identifier is not a resource ID and shouldn't generate a 404 if it isn't found - Should be removed
*/ */
public ResourceNotFoundException(Class<? extends IResource> theClass, IdentifierDt theId) { public ResourceNotFoundException(Class<? extends IResource> theClass, BaseIdentifierDt theId) {
super(STATUS_CODE, "Resource of type " + theClass.getSimpleName() + " with ID " + theId + " is not known"); super(STATUS_CODE, "Resource of type " + theClass.getSimpleName() + " with ID " + theId + " is not known");
} }
@ -65,7 +65,7 @@ public class ResourceNotFoundException extends BaseServerResponseException {
super(STATUS_CODE, createErrorMessage(theId)); super(STATUS_CODE, createErrorMessage(theId));
} }
public ResourceNotFoundException(IdDt theId, OperationOutcome theOperationOutcome) { public ResourceNotFoundException(IdDt theId, BaseOperationOutcome theOperationOutcome) {
super(STATUS_CODE, createErrorMessage(theId), theOperationOutcome); super(STATUS_CODE, createErrorMessage(theId), theOperationOutcome);
} }

View File

@ -20,7 +20,7 @@ package ca.uhn.fhir.rest.server.exceptions;
* #L% * #L%
*/ */
import ca.uhn.fhir.model.dstu.resource.OperationOutcome; import ca.uhn.fhir.model.base.resource.BaseOperationOutcome;
import ca.uhn.fhir.rest.annotation.Delete; import ca.uhn.fhir.rest.annotation.Delete;
import ca.uhn.fhir.rest.annotation.Update; import ca.uhn.fhir.rest.annotation.Update;
import ca.uhn.fhir.rest.server.Constants; import ca.uhn.fhir.rest.server.Constants;
@ -45,7 +45,7 @@ public class ResourceVersionConflictException extends BaseServerResponseExceptio
* The message * The message
* @param theOperationOutcome The OperationOutcome resource to return to the client * @param theOperationOutcome The OperationOutcome resource to return to the client
*/ */
public ResourceVersionConflictException(String theMessage, OperationOutcome theOperationOutcome) { public ResourceVersionConflictException(String theMessage, BaseOperationOutcome theOperationOutcome) {
super(STATUS_CODE, theMessage, theOperationOutcome); super(STATUS_CODE, theMessage, theOperationOutcome);
} }

View File

@ -20,7 +20,7 @@ package ca.uhn.fhir.rest.server.exceptions;
* #L% * #L%
*/ */
import ca.uhn.fhir.model.dstu.resource.OperationOutcome; import ca.uhn.fhir.model.base.resource.BaseOperationOutcome;
import ca.uhn.fhir.rest.annotation.Update; import ca.uhn.fhir.rest.annotation.Update;
import ca.uhn.fhir.rest.server.Constants; import ca.uhn.fhir.rest.server.Constants;
@ -44,7 +44,7 @@ public class ResourceVersionNotSpecifiedException extends BaseServerResponseExce
* The message * The message
* @param theOperationOutcome The OperationOutcome resource to return to the client * @param theOperationOutcome The OperationOutcome resource to return to the client
*/ */
public ResourceVersionNotSpecifiedException(String theMessage, OperationOutcome theOperationOutcome) { public ResourceVersionNotSpecifiedException(String theMessage, BaseOperationOutcome theOperationOutcome) {
super(STATUS_CODE, theMessage, theOperationOutcome); super(STATUS_CODE, theMessage, theOperationOutcome);
} }

View File

@ -1,6 +1,6 @@
package ca.uhn.fhir.rest.server.exceptions; package ca.uhn.fhir.rest.server.exceptions;
import ca.uhn.fhir.model.dstu.resource.OperationOutcome; import ca.uhn.fhir.model.base.resource.BaseOperationOutcome;
/* /*
* #%L * #%L
@ -49,7 +49,7 @@ public class UnclassifiedServerFailureException extends BaseServerResponseExcept
* The message to add to the status line * The message to add to the status line
* @param theOperationOutcome The OperationOutcome resource to return to the client * @param theOperationOutcome The OperationOutcome resource to return to the client
*/ */
public UnclassifiedServerFailureException(int theStatusCode, String theMessage, OperationOutcome theOperationOutcome) { public UnclassifiedServerFailureException(int theStatusCode, String theMessage, BaseOperationOutcome theOperationOutcome) {
super(theStatusCode, theMessage, theOperationOutcome); super(theStatusCode, theMessage, theOperationOutcome);
} }

View File

@ -63,38 +63,21 @@ public class UnprocessableEntityException extends BaseServerResponseException {
* Constructor which accepts an {@link BaseOperationOutcome} resource which will be supplied in the response * Constructor which accepts an {@link BaseOperationOutcome} resource which will be supplied in the response
*/ */
public UnprocessableEntityException(BaseOperationOutcome theOperationOutcome) { public UnprocessableEntityException(BaseOperationOutcome theOperationOutcome) {
super(STATUS_CODE, DEFAULT_MESSAGE, theOperationOutcome == null ? new BaseOperationOutcome() : theOperationOutcome); super(STATUS_CODE, DEFAULT_MESSAGE, theOperationOutcome);
} }
/** /**
* Constructor which accepts a String describing the issue. This string will be translated into an {@link BaseOperationOutcome} resource which will be supplied in the response. * Constructor which accepts a String describing the issue. This string will be translated into an {@link BaseOperationOutcome} resource which will be supplied in the response.
*/ */
public UnprocessableEntityException(String theMessage) { public UnprocessableEntityException(String theMessage) {
super(STATUS_CODE, DEFAULT_MESSAGE, toOperationOutcome(theMessage)); super(STATUS_CODE, theMessage);
} }
/** /**
* Constructor which accepts an array of Strings describing the issue. This strings will be translated into an {@link BaseOperationOutcome} resource which will be supplied in the response. * Constructor which accepts an array of Strings describing the issue. This strings will be translated into an {@link BaseOperationOutcome} resource which will be supplied in the response.
*/ */
public UnprocessableEntityException(String... theMessage) { public UnprocessableEntityException(String... theMessage) {
super(STATUS_CODE, DEFAULT_MESSAGE, toOperationOutcome(theMessage)); super(STATUS_CODE, theMessage[0]); // TODO: this used to generate an OperationOutcome - why?
}
private static BaseOperationOutcome toOperationOutcome(String... theMessage) {
BaseOperationOutcome BaseOperationOutcome = new BaseOperationOutcome();
if (theMessage != null) {
for (String next : theMessage) {
BaseOperationOutcome.addIssue().setDetails(next);
}
}
return BaseOperationOutcome;
}
private static class MyOperationOutcome extends BaseOperationOutcome
{
} }
} }

View File

@ -33,12 +33,6 @@ import org.apache.commons.lang3.StringUtils;
import ca.uhn.fhir.context.RuntimeResourceDefinition; import ca.uhn.fhir.context.RuntimeResourceDefinition;
import ca.uhn.fhir.context.RuntimeSearchParam; import ca.uhn.fhir.context.RuntimeSearchParam;
import ca.uhn.fhir.model.api.IResource; import ca.uhn.fhir.model.api.IResource;
import ca.uhn.fhir.model.dstu.resource.Conformance;
import ca.uhn.fhir.model.dstu.resource.Conformance.Rest;
import ca.uhn.fhir.model.dstu.resource.Conformance.RestQuery;
import ca.uhn.fhir.model.dstu.resource.Conformance.RestResource;
import ca.uhn.fhir.model.dstu.resource.Conformance.RestResourceOperation;
import ca.uhn.fhir.model.dstu.resource.Conformance.RestResourceSearchParam;
import ca.uhn.fhir.model.dstu.valueset.ResourceTypeEnum; import ca.uhn.fhir.model.dstu.valueset.ResourceTypeEnum;
import ca.uhn.fhir.model.dstu.valueset.RestfulConformanceModeEnum; import ca.uhn.fhir.model.dstu.valueset.RestfulConformanceModeEnum;
import ca.uhn.fhir.model.dstu.valueset.RestfulOperationSystemEnum; import ca.uhn.fhir.model.dstu.valueset.RestfulOperationSystemEnum;

View File

@ -1,4 +1,4 @@
package ca.uhn.fhir.model.primitive; package ca.uhn.fhir.model.dstu.composite;
/* /*
* #%L * #%L

View File

@ -0,0 +1,358 @@
package ca.uhn.fhir.rest.server.provider;
/*
* #%L
* HAPI FHIR - Core Library
* %%
* Copyright (C) 2014 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.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.TreeSet;
import org.apache.commons.lang3.StringUtils;
import ca.uhn.fhir.context.RuntimeResourceDefinition;
import ca.uhn.fhir.context.RuntimeSearchParam;
import ca.uhn.fhir.model.api.IResource;
import ca.uhn.fhir.model.dstu.resource.Conformance;
import ca.uhn.fhir.model.dstu.resource.Conformance.Rest;
import ca.uhn.fhir.model.dstu.resource.Conformance.RestQuery;
import ca.uhn.fhir.model.dstu.resource.Conformance.RestResource;
import ca.uhn.fhir.model.dstu.resource.Conformance.RestResourceOperation;
import ca.uhn.fhir.model.dstu.resource.Conformance.RestResourceSearchParam;
import ca.uhn.fhir.model.dstu.valueset.ResourceTypeEnum;
import ca.uhn.fhir.model.dstu.valueset.RestfulConformanceModeEnum;
import ca.uhn.fhir.model.dstu.valueset.RestfulOperationSystemEnum;
import ca.uhn.fhir.model.dstu.valueset.RestfulOperationTypeEnum;
import ca.uhn.fhir.model.primitive.BooleanDt;
import ca.uhn.fhir.model.primitive.CodeDt;
import ca.uhn.fhir.model.primitive.DateTimeDt;
import ca.uhn.fhir.model.primitive.IdDt;
import ca.uhn.fhir.model.primitive.StringDt;
import ca.uhn.fhir.rest.annotation.Metadata;
import ca.uhn.fhir.rest.method.BaseMethodBinding;
import ca.uhn.fhir.rest.method.DynamicSearchMethodBinding;
import ca.uhn.fhir.rest.method.IParameter;
import ca.uhn.fhir.rest.method.SearchMethodBinding;
import ca.uhn.fhir.rest.method.SearchParameter;
import ca.uhn.fhir.rest.server.Constants;
import ca.uhn.fhir.rest.server.ResourceBinding;
import ca.uhn.fhir.rest.server.RestfulServer;
import ca.uhn.fhir.util.ExtensionConstants;
/**
* Server FHIR Provider which serves the conformance statement for a RESTful server implementation
*
* <p>
* Note: This class is safe to extend, but it is important to note that the same instance of {@link Conformance} is
* always returned unless {@link #setCache(boolean)} is called with a value of <code>false</code>. This means that if
* you are adding anything to the returned conformance instance on each call you should call
* <code>setCache(false)</code> in your provider constructor.
* </p>
*/
public class ServerConformanceProvider {
private boolean myCache = true;
private volatile Conformance myConformance;
private String myPublisher = "Not provided";
private final RestfulServer myRestfulServer;
public ServerConformanceProvider(RestfulServer theRestfulServer) {
myRestfulServer = theRestfulServer;
}
/**
* Gets the value of the "publisher" that will be placed in the generated conformance statement. As this
* is a mandatory element, the value should not be null (although this is not enforced). The value defaults
* to "Not provided" but may be set to null, which will cause this element to be omitted.
*/
public String getPublisher() {
return myPublisher;
}
/**
* Actually create and return the conformance statement
*
* See the class documentation for an important note if you are extending this class
*/
@Metadata
public Conformance getServerConformance() {
if (myConformance != null && myCache) {
return myConformance;
}
Conformance retVal = new Conformance();
retVal.setPublisher(myPublisher);
retVal.setDate(DateTimeDt.withCurrentTime());
retVal.setFhirVersion("0.80"); // TODO: pull from model
retVal.setAcceptUnknown(false); // TODO: make this configurable - this is a fairly big effort since the parser needs to be modified to actually allow it
retVal.getImplementation().setDescription(myRestfulServer.getImplementationDescription());
retVal.getSoftware().setName(myRestfulServer.getServerName());
retVal.getSoftware().setVersion(myRestfulServer.getServerVersion());
retVal.addFormat(Constants.CT_FHIR_XML);
retVal.addFormat(Constants.CT_FHIR_JSON);
Rest rest = retVal.addRest();
rest.setMode(RestfulConformanceModeEnum.SERVER);
Set<RestfulOperationSystemEnum> systemOps = new HashSet<RestfulOperationSystemEnum>();
List<ResourceBinding> bindings = new ArrayList<ResourceBinding>(myRestfulServer.getResourceBindings());
Collections.sort(bindings, new Comparator<ResourceBinding>() {
@Override
public int compare(ResourceBinding theArg0, ResourceBinding theArg1) {
return theArg0.getResourceName().compareToIgnoreCase(theArg1.getResourceName());
}
});
for (ResourceBinding next : bindings) {
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().setReference(new IdDt(def.getResourceProfile()));
TreeSet<String> includes = new TreeSet<String>();
// 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) {
handleSearchMethodBinding(rest, resource, resourceName, def, includes, (SearchMethodBinding) nextMethodBinding);
} else if (nextMethodBinding instanceof DynamicSearchMethodBinding) {
handleDynamicSearchMethodBinding(resource, def, includes, (DynamicSearchMethodBinding) nextMethodBinding);
}
Collections.sort(resource.getOperation(), new Comparator<RestResourceOperation>() {
@Override
public int compare(RestResourceOperation theO1, RestResourceOperation theO2) {
RestfulOperationTypeEnum o1 = theO1.getCode().getValueAsEnum();
RestfulOperationTypeEnum o2 = theO2.getCode().getValueAsEnum();
if (o1 == null && o2 == null) {
return 0;
}
if (o1 == null) {
return 1;
}
if (o2 == null) {
return -1;
}
return o1.ordinal() - o2.ordinal();
}
});
}
for (String nextInclude : includes) {
resource.addSearchInclude(nextInclude);
}
}
myConformance = retVal;
return retVal;
}
private void handleDynamicSearchMethodBinding(RestResource resource, RuntimeResourceDefinition def, TreeSet<String> includes, DynamicSearchMethodBinding searchMethodBinding) {
includes.addAll(searchMethodBinding.getIncludes());
List<RuntimeSearchParam> searchParameters = new ArrayList<RuntimeSearchParam>();
searchParameters.addAll(searchMethodBinding.getSearchParams());
sortRuntimeSearchParameters(searchParameters);
if (!searchParameters.isEmpty()) {
for (RuntimeSearchParam nextParameter : searchParameters) {
String nextParamName = nextParameter.getName();
// String chain = null;
String nextParamUnchainedName = nextParamName;
if (nextParamName.contains(".")) {
// chain = nextParamName.substring(nextParamName.indexOf('.') + 1);
nextParamUnchainedName = nextParamName.substring(0, nextParamName.indexOf('.'));
}
String nextParamDescription = nextParameter.getDescription();
/*
* If the parameter has no description, default to the one from the resource
*/
if (StringUtils.isBlank(nextParamDescription)) {
RuntimeSearchParam paramDef = def.getSearchParam(nextParamUnchainedName);
if (paramDef != null) {
nextParamDescription = paramDef.getDescription();
}
}
RestResourceSearchParam param;
param = resource.addSearchParam();
param.setName(nextParamName);
// if (StringUtils.isNotBlank(chain)) {
// param.addChain(chain);
// }
param.setDocumentation(nextParamDescription);
param.setType(nextParameter.getParamType());
}
}
}
private void handleSearchMethodBinding(Rest rest, RestResource resource, String resourceName, RuntimeResourceDefinition def, TreeSet<String> includes, SearchMethodBinding searchMethodBinding) {
includes.addAll(searchMethodBinding.getIncludes());
List<IParameter> params = searchMethodBinding.getParameters();
List<SearchParameter> searchParameters = new ArrayList<SearchParameter>();
for (IParameter nextParameter : params) {
if ((nextParameter instanceof SearchParameter)) {
searchParameters.add((SearchParameter) nextParameter);
}
}
sortSearchParameters(searchParameters);
if (!searchParameters.isEmpty()) {
boolean allOptional = searchParameters.get(0).isRequired() == false;
RestQuery query = null;
if (!allOptional) {
query = rest.addQuery();
query.getDocumentation().setValue(searchMethodBinding.getDescription());
query.addUndeclaredExtension(false, ExtensionConstants.QUERY_RETURN_TYPE, new CodeDt(resourceName));
for (String nextInclude : searchMethodBinding.getIncludes()) {
query.addUndeclaredExtension(false, ExtensionConstants.QUERY_ALLOWED_INCLUDE, new StringDt(nextInclude));
}
}
for (SearchParameter nextParameter : searchParameters) {
String nextParamName = nextParameter.getName();
// String chain = null;
String nextParamUnchainedName = nextParamName;
if (nextParamName.contains(".")) {
// chain = nextParamName.substring(nextParamName.indexOf('.') + 1);
nextParamUnchainedName = nextParamName.substring(0, nextParamName.indexOf('.'));
}
String nextParamDescription = nextParameter.getDescription();
/*
* If the parameter has no description, default to the one from the resource
*/
if (StringUtils.isBlank(nextParamDescription)) {
RuntimeSearchParam paramDef = def.getSearchParam(nextParamUnchainedName);
if (paramDef != null) {
nextParamDescription = paramDef.getDescription();
}
}
RestResourceSearchParam param;
if (query == null) {
param = resource.addSearchParam();
} else {
param = query.addParameter();
param.addUndeclaredExtension(false, ExtensionConstants.PARAM_IS_REQUIRED, new BooleanDt(nextParameter.isRequired()));
}
param.setName(nextParamName);
// if (StringUtils.isNotBlank(chain)) {
// param.addChain(chain);
// }
param.setDocumentation(nextParamDescription);
param.setType(nextParameter.getParamType());
for (Class<? extends IResource> nextTarget : nextParameter.getDeclaredTypes()) {
RuntimeResourceDefinition targetDef = myRestfulServer.getFhirContext().getResourceDefinition(nextTarget);
if (targetDef != null) {
ResourceTypeEnum code = ResourceTypeEnum.VALUESET_BINDER.fromCodeString(targetDef.getName());
if (code != null) {
param.addTarget(code);
}
}
}
}
}
}
/**
* Sets the cache property (default is true). If set to true, the same response will be returned for each
* invocation.
* <p>
* See the class documentation for an important note if you are extending this class
* </p>
*/
public void setCache(boolean theCache) {
myCache = theCache;
}
/**
* Sets the value of the "publisher" that will be placed in the generated conformance statement. As this
* is a mandatory element, the value should not be null (although this is not enforced). The value defaults
* to "Not provided" but may be set to null, which will cause this element to be omitted.
*/
public void setPublisher(String thePublisher) {
myPublisher = thePublisher;
}
private void sortRuntimeSearchParameters(List<RuntimeSearchParam> searchParameters) {
Collections.sort(searchParameters, new Comparator<RuntimeSearchParam>() {
@Override
public int compare(RuntimeSearchParam theO1, RuntimeSearchParam theO2) {
return theO1.getName().compareTo(theO2.getName());
}
});
}
private void sortSearchParameters(List<SearchParameter> searchParameters) {
Collections.sort(searchParameters, new Comparator<SearchParameter>() {
@Override
public int compare(SearchParameter theO1, SearchParameter theO2) {
if (theO1.isRequired() == theO2.isRequired()) {
return theO1.getName().compareTo(theO2.getName());
}
if (theO1.isRequired()) {
return -1;
}
return 1;
}
});
}
}

View File

@ -0,0 +1,79 @@
package ca.uhn.fhir.rest.server.provider;
/*
* #%L
* HAPI FHIR - Core Library
* %%
* Copyright (C) 2014 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.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.context.RuntimeResourceDefinition;
import ca.uhn.fhir.model.api.IResource;
import ca.uhn.fhir.model.dstu.resource.Profile;
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;
public class ServerProfileProvider implements IResourceProvider {
private FhirContext myContext;
public ServerProfileProvider(FhirContext theContext) {
myContext = theContext;
}
@Override
public Class<? extends IResource> getResourceType() {
return Profile.class;
}
@Read()
public Profile getProfileById(@IdParam IdDt theId) {
RuntimeResourceDefinition retVal = myContext.getResourceDefinitionById(theId.getValue());
if (retVal==null) {
return null;
}
return (Profile) retVal.toProfile();
}
@Search()
public List<Profile> getAllProfiles() {
List<RuntimeResourceDefinition> defs = new ArrayList<RuntimeResourceDefinition>(myContext.getResourceDefinitions());
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().compareTo(theO2.getResourceProfile());
}
return cmp;
}});
ArrayList<Profile> retVal = new ArrayList<Profile>();
for (RuntimeResourceDefinition next : defs) {
retVal.add((Profile) next.toProfile());
}
return retVal;
}
}