View Javadoc
1   package ca.uhn.fhir.rest.api;
2   
3   /*
4    * #%L
5    * HAPI FHIR - Core Library
6    * %%
7    * Copyright (C) 2014 - 2018 University Health Network
8    * %%
9    * Licensed under the Apache License, Version 2.0 (the "License");
10   * you may not use this file except in compliance with the License.
11   * You may obtain a copy of the License at
12   * 
13   *      http://www.apache.org/licenses/LICENSE-2.0
14   * 
15   * Unless required by applicable law or agreed to in writing, software
16   * distributed under the License is distributed on an "AS IS" BASIS,
17   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18   * See the License for the specific language governing permissions and
19   * limitations under the License.
20   * #L%
21   */
22  
23  import org.hl7.fhir.instance.model.api.IBaseOperationOutcome;
24  import org.hl7.fhir.instance.model.api.IBaseResource;
25  import org.hl7.fhir.instance.model.api.IIdType;
26  
27  import ca.uhn.fhir.util.CoverageIgnore;
28  
29  public class MethodOutcome {
30  
31  	private Boolean myCreated;
32  	private IIdType myId;
33  	private IBaseOperationOutcome myOperationOutcome;
34  	private IBaseResource myResource;
35  
36  	/**
37  	 * Constructor
38  	 */
39  	public MethodOutcome() {
40  		super();
41  	}
42  
43  	/**
44  	 * Constructor
45  	 * 
46  	 * @param theId
47  	 *            The ID of the created/updated resource
48  	 * 
49  	 * @param theCreated
50  	 *            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
51  	 *            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.
52  	 */
53  	@CoverageIgnore
54  	public MethodOutcome(IIdType theId, Boolean theCreated) {
55  		myId = theId;
56  		myCreated = theCreated;
57  	}
58  
59  	/**
60  	 * Constructor
61  	 * 
62  	 * @param theId
63  	 *            The ID of the created/updated resource
64  	 * 
65  	 * @param theBaseOperationOutcome
66  	 *            The operation outcome to return with the response (or null for none)
67  	 */
68  	public MethodOutcome(IIdType theId, IBaseOperationOutcome theBaseOperationOutcome) {
69  		myId = theId;
70  		myOperationOutcome = theBaseOperationOutcome;
71  	}
72  
73  	/**
74  	 * Constructor
75  	 * 
76  	 * @param theId
77  	 *            The ID of the created/updated resource
78  	 * 
79  	 * @param theBaseOperationOutcome
80  	 *            The operation outcome to return with the response (or null for none)
81  	 * 
82  	 * @param theCreated
83  	 *            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
84  	 *            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.
85  	 */
86  	public MethodOutcome(IIdType theId, IBaseOperationOutcome theBaseOperationOutcome, Boolean theCreated) {
87  		myId = theId;
88  		myOperationOutcome = theBaseOperationOutcome;
89  		myCreated = theCreated;
90  	}
91  
92  	/**
93  	 * Constructor
94  	 * 
95  	 * @param theId
96  	 *            The ID of the created/updated resource
97  	 */
98  	public MethodOutcome(IIdType theId) {
99  		myId = theId;
100 	}
101 
102 	/**
103 	 * Constructor
104 	 * 
105 	 * @param theOperationOutcome
106 	 *            The operation outcome resource to return
107 	 */
108 	public MethodOutcome(IBaseOperationOutcome theOperationOutcome) {
109 		myOperationOutcome = theOperationOutcome;
110 	}
111 
112 	/**
113 	 * This will be set to {@link Boolean#TRUE} for instance of MethodOutcome which are
114 	 * returned to client instances, if the server has responded with an HTTP 201 Created.
115 	 */
116 	public Boolean getCreated() {
117 		return myCreated;
118 	}
119 
120 	public IIdType getId() {
121 		return myId;
122 	}
123 
124 	/**
125 	 * Returns the {@link IBaseOperationOutcome} resource to return to the client or <code>null</code> if none.
126 	 * 
127 	 * @return This method <b>will return null</b>, unlike many methods in the API.
128 	 */
129 	public IBaseOperationOutcome getOperationOutcome() {
130 		return myOperationOutcome;
131 	}
132 
133 	/**
134 	 * <b>From a client response:</b> If the method returned an actual resource body (e.g. a create/update with
135 	 * "Prefer: return=representation") this field will be populated with the
136 	 * resource itself.
137 	 */
138 	public IBaseResource getResource() {
139 		return myResource;
140 	}
141 
142 	/**
143 	 * 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
144 	 * 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.
145 	 * <p>
146 	 * Users of HAPI should only interact with this method in Server applications
147 	 * </p>
148 	 * 
149 	 * @param theCreated
150 	 *            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
151 	 *            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.
152 	 * @return Returns a reference to <code>this</code> for easy method chaining
153 	 */
154 	public MethodOutcome setCreated(Boolean theCreated) {
155 		myCreated = theCreated;
156 		return this;
157 	}
158 
159 	/**
160 	 * @param theId
161 	 *            The ID of the created/updated resource
162 	 * @return Returns a reference to <code>this</code> for easy method chaining
163 	 */
164 	public MethodOutcome setId(IIdType theId) {
165 		myId = theId;
166 		return this;
167 	}
168 
169 	/**
170 	 * Sets the {@link IBaseOperationOutcome} resource to return to the client. Set to <code>null</code> (which is the default) if none.
171 	 * @return Returns a reference to <code>this</code> for easy method chaining
172 	 */
173 	public MethodOutcome setOperationOutcome(IBaseOperationOutcome theBaseOperationOutcome) {
174 		myOperationOutcome = theBaseOperationOutcome;
175 		return this;
176 	}
177 
178 	/**
179 	 * <b>In a server response</b>: This field may be populated in server code with the final resource for operations
180 	 * where a resource body is being created/updated. E.g. for an update method, this field could be populated with
181 	 * the resource after the update is applied, with the new version ID, lastUpdate time, etc. 
182 	 * <p>
183 	 * This field is optional, but if it is populated the server will return the resource body if requested to
184 	 * do so via the HTTP Prefer header.
185 	 * </p> 
186 	 * @return Returns a reference to <code>this</code> for easy method chaining
187 	 */
188 	public MethodOutcome setResource(IBaseResource theResource) {
189 		myResource = theResource;
190 		return this;
191 	}
192 
193 }