001package ca.uhn.fhir.rest.api; 002 003/* 004 * #%L 005 * HAPI FHIR - Core Library 006 * %% 007 * Copyright (C) 2014 - 2016 University Health Network 008 * %% 009 * Licensed under the Apache License, Version 2.0 (the "License"); 010 * you may not use this file except in compliance with the License. 011 * You may obtain a copy of the License at 012 * 013 * http://www.apache.org/licenses/LICENSE-2.0 014 * 015 * Unless required by applicable law or agreed to in writing, software 016 * distributed under the License is distributed on an "AS IS" BASIS, 017 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 018 * See the License for the specific language governing permissions and 019 * limitations under the License. 020 * #L% 021 */ 022 023import org.hl7.fhir.instance.model.api.IBaseOperationOutcome; 024import org.hl7.fhir.instance.model.api.IBaseResource; 025import org.hl7.fhir.instance.model.api.IIdType; 026 027import ca.uhn.fhir.model.primitive.IdDt; 028 029public class MethodOutcome { 030 031 private Boolean myCreated; 032 private IIdType myId; 033 private IBaseOperationOutcome myOperationOutcome; 034 private IBaseResource myResource; 035 private IdDt myVersionId; 036 037 /** 038 * Constructor 039 */ 040 public MethodOutcome() { 041 super(); 042 } 043 044 /** 045 * Constructor 046 * 047 * @param theId 048 * The ID of the created/updated resource 049 * 050 * @param theCreated 051 * If not null, indicates whether the resource was created (as opposed to being updated). This is generally not needed, since the server can assume based on the method being called 052 * whether the result was a creation or an update. However, it can be useful if you are implementing an update method that does a create if the ID doesn't already exist. 053 */ 054 public MethodOutcome(IIdType theId, Boolean theCreated) { 055 myId = theId; 056 myCreated = theCreated; 057 } 058 059 /** 060 * Constructor 061 * 062 * @param theId 063 * The ID of the created/updated resource 064 * 065 * @param theBaseOperationOutcome 066 * The operation outcome to return with the response (or null for none) 067 */ 068 public MethodOutcome(IIdType theId, IBaseOperationOutcome theBaseOperationOutcome) { 069 myId = theId; 070 myOperationOutcome = theBaseOperationOutcome; 071 } 072 073 /** 074 * Constructor 075 * 076 * @param theId 077 * The ID of the created/updated resource 078 * 079 * @param theBaseOperationOutcome 080 * The operation outcome to return with the response (or null for none) 081 * 082 * @param theCreated 083 * If not null, indicates whether the resource was created (as opposed to being updated). This is generally not needed, since the server can assume based on the method being called 084 * whether the result was a creation or an update. However, it can be useful if you are implementing an update method that does a create if the ID doesn't already exist. 085 */ 086 public MethodOutcome(IIdType theId, IBaseOperationOutcome theBaseOperationOutcome, Boolean theCreated) { 087 myId = theId; 088 myOperationOutcome = theBaseOperationOutcome; 089 myCreated = theCreated; 090 } 091 092 /** 093 * @deprecated Use the constructor which accepts a single IIdType parameter, and include the logical ID and version ID in that IIdType instance 094 */ 095 @Deprecated 096 public MethodOutcome(IIdType theId, IdDt theVersionId) { 097 myId = theId; 098 myVersionId = theVersionId; 099 } 100 101 /** 102 * @deprecated Use the constructor which accepts a single IdDt parameter, and include the logical ID and version ID in that IdDt instance 103 */ 104 @Deprecated 105 public MethodOutcome(IIdType theId, IdDt theVersionId, IBaseOperationOutcome theBaseOperationOutcome) { 106 myId = theId; 107 myVersionId = theVersionId; 108 myOperationOutcome = theBaseOperationOutcome; 109 } 110 111 /** 112 * Constructor 113 * 114 * @param theId 115 * The ID of the created/updated resource 116 */ 117 public MethodOutcome(IIdType theId) { 118 myId = theId; 119 } 120 121 /** 122 * This will be set to {@link Boolean#TRUE} for instance of MethodOutcome which are 123 * returned to client instances, if the server has responded with an HTTP 201 Created. 124 */ 125 public Boolean getCreated() { 126 return myCreated; 127 } 128 129 public IIdType getId() { 130 return myId; 131 } 132 133 /** 134 * Returns the {@link IBaseOperationOutcome} resource to return to the client or <code>null</code> if none. 135 * 136 * @return This method <b>will return null</b>, unlike many methods in the API. 137 */ 138 public IBaseOperationOutcome getOperationOutcome() { 139 return myOperationOutcome; 140 } 141 142 /** 143 * <b>From a client response:</b> If the method returned an actual resource body (e.g. a create/update with 144 * "Prefer: return=representation") this field will be populated with the 145 * resource itself. 146 */ 147 public IBaseResource getResource() { 148 return myResource; 149 } 150 151 /** 152 * @deprecated {@link MethodOutcome#getId()} should return the complete ID including version if it is available 153 */ 154 @Deprecated 155 public IdDt getVersionId() { 156 return myVersionId; 157 } 158 159 /** 160 * If not null, indicates whether the resource was created (as opposed to being updated). This is generally not needed, since the server can assume based on the method being called whether the 161 * result was a creation or an update. However, it can be useful if you are implementing an update method that does a create if the ID doesn't already exist. 162 * <p> 163 * Users of HAPI should only interact with this method in Server applications 164 * </p> 165 * 166 * @param theCreated 167 * If not null, indicates whether the resource was created (as opposed to being updated). This is generally not needed, since the server can assume based on the method being called 168 * whether the result was a creation or an update. However, it can be useful if you are implementing an update method that does a create if the ID doesn't already exist. 169 */ 170 public MethodOutcome setCreated(Boolean theCreated) { 171 myCreated = theCreated; 172 return this; 173 } 174 175 /** 176 * @param theId 177 * The ID of the created/updated resource 178 */ 179 public void setId(IIdType theId) { 180 myId = theId; 181 } 182 183 /** 184 * Sets the {@link IBaseOperationOutcome} resource to return to the client. Set to <code>null</code> (which is the default) if none. 185 */ 186 public void setOperationOutcome(IBaseOperationOutcome theBaseOperationOutcome) { 187 myOperationOutcome = theBaseOperationOutcome; 188 } 189 190 /** 191 * <b>In a server response</b>: This field may be populated in server code with the final resource for operations 192 * where a resource body is being created/updated. E.g. for an update method, this field could be populated with 193 * the resource after the update is applied, with the new version ID, lastUpdate time, etc. 194 * <p> 195 * This field is optional, but if it is populated the server will return the resource body if requested to 196 * do so via the HTTP Prefer header. 197 * </p> 198 */ 199 public void setResource(IBaseResource theResource) { 200 myResource = theResource; 201 } 202 203 /** 204 * @deprecated Put the ID and version ID into the same IdDt instance and pass it to {@link #setId(IIdType)} 205 */ 206 @Deprecated 207 public void setVersionId(IdDt theVersionId) { 208 myVersionId = theVersionId; 209 } 210 211}