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.*;
26  import com.google.gson.Gson;
27  import org.hl7.fhir.instance.model.api.IBaseResource;
28  import org.hl7.fhir.instance.model.api.IIdType;
29  
30  import java.io.Serializable;
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 ResourceDeliveryMessage {
35  
36  	private static final long serialVersionUID = 1L;
37  
38  	@JsonIgnore
39  	private transient CanonicalSubscription mySubscription;
40  	@JsonProperty("subscription")
41  	private String mySubscriptionString;
42  	@JsonIgnore
43  	private transient IBaseResource myPayload;
44  	@JsonProperty("payload")
45  	private String myPayoadString;
46  	@JsonProperty("payloadId")
47  	private String myPayloadId;
48  	@JsonProperty("operationType")
49  	private RestOperationTypeEnum myOperationType;
50  
51  	public RestOperationTypeEnum getOperationType() {
52  		return myOperationType;
53  	}
54  
55  	public void setOperationType(RestOperationTypeEnum theOperationType) {
56  		myOperationType = theOperationType;
57  	}
58  
59  	public IBaseResource getPayload(FhirContext theCtx) {
60  		if (myPayload == null && myPayoadString != null) {
61  			myPayload = theCtx.newJsonParser().parseResource(myPayoadString);
62  		}
63  		return myPayload;
64  	}
65  
66  	public IIdType getPayloadId(FhirContext theCtx) {
67  		IIdType retVal = null;
68  		if (myPayloadId != null) {
69  			retVal = theCtx.getVersion().newIdType().setValue(myPayloadId);
70  		}
71  		return retVal;
72  	}
73  
74  	public CanonicalSubscription getSubscription() {
75  		if (mySubscription == null && mySubscriptionString != null) {
76  			mySubscription = new Gson().fromJson(mySubscriptionString, CanonicalSubscription.class);
77  		}
78  		return mySubscription;
79  	}
80  
81  	public void setSubscription(CanonicalSubscription theSubscription) {
82  		mySubscription = theSubscription;
83  		if (mySubscription != null) {
84  			mySubscriptionString = new Gson().toJson(mySubscription);
85  		}
86  	}
87  
88  	public void setPayload(FhirContext theCtx, IBaseResource thePayload) {
89  		myPayload = thePayload;
90  		myPayoadString = theCtx.newJsonParser().encodeResourceToString(thePayload);
91  	}
92  
93  	public void setPayloadId(IIdType thePayloadId) {
94  		myPayloadId = null;
95  		if (thePayloadId != null) {
96  			myPayloadId = thePayloadId.getValue();
97  		}
98  	}
99  
100 }