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