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