View Javadoc
1   package ca.uhn.fhir.jpa.subscription;
2   
3   /*-
4    * #%L
5    * HAPI FHIR JPA Server
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 ca.uhn.fhir.context.FhirContext;
24  import ca.uhn.fhir.rest.api.RestOperationTypeEnum;
25  import com.fasterxml.jackson.annotation.JsonAutoDetect;
26  import com.fasterxml.jackson.annotation.JsonIgnore;
27  import com.fasterxml.jackson.annotation.JsonInclude;
28  import com.fasterxml.jackson.annotation.JsonProperty;
29  import org.hl7.fhir.instance.model.api.IBaseResource;
30  import org.hl7.fhir.instance.model.api.IIdType;
31  
32  @JsonInclude(JsonInclude.Include.NON_NULL)
33  @JsonAutoDetect(creatorVisibility = JsonAutoDetect.Visibility.NONE, fieldVisibility = JsonAutoDetect.Visibility.NONE, getterVisibility = JsonAutoDetect.Visibility.NONE, isGetterVisibility = JsonAutoDetect.Visibility.NONE, setterVisibility = JsonAutoDetect.Visibility.NONE)
34  public class ResourceModifiedMessage {
35  
36  	private static final long serialVersionUID = 1L;
37  
38  	@JsonProperty("resourceId")
39  	private String myId;
40  	@JsonProperty("operationType")
41  	private RestOperationTypeEnum myOperationType;
42  	@JsonProperty("newPayload")
43  	private String myNewPayloadEncoded;
44  	@JsonIgnore
45  	private transient IBaseResource myNewPayload;
46  
47  	public IIdType getId(FhirContext theCtx) {
48  		IIdType retVal = null;
49  		if (myId != null) {
50  			retVal = theCtx.getVersion().newIdType().setValue(myId);
51  		}
52  		return retVal;
53  	}
54  
55  	public IBaseResource getNewPayload(FhirContext theCtx) {
56  		if (myNewPayload == null && myNewPayloadEncoded != null) {
57  			myNewPayload = theCtx.newJsonParser().parseResource(myNewPayloadEncoded);
58  		}
59  		return myNewPayload;
60  	}
61  
62  	public RestOperationTypeEnum getOperationType() {
63  		return myOperationType;
64  	}
65  
66  	public void setOperationType(RestOperationTypeEnum theOperationType) {
67  		myOperationType = theOperationType;
68  	}
69  
70  	public void setId(IIdType theId) {
71  		myId = null;
72  		if (theId != null) {
73  			myId = theId.getValue();
74  		}
75  	}
76  
77  	public void setNewPayload(FhirContext theCtx, IBaseResource theNewPayload) {
78  		myNewPayload = theNewPayload;
79  		myNewPayloadEncoded = theCtx.newJsonParser().encodeResourceToString(theNewPayload);
80  	}
81  }