001/*- 002 * #%L 003 * HAPI FHIR Storage api 004 * %% 005 * Copyright (C) 2014 - 2024 Smile CDR, Inc. 006 * %% 007 * Licensed under the Apache License, Version 2.0 (the "License"); 008 * you may not use this file except in compliance with the License. 009 * You may obtain a copy of the License at 010 * 011 * http://www.apache.org/licenses/LICENSE-2.0 012 * 013 * Unless required by applicable law or agreed to in writing, software 014 * distributed under the License is distributed on an "AS IS" BASIS, 015 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 016 * See the License for the specific language governing permissions and 017 * limitations under the License. 018 * #L% 019 */ 020package ca.uhn.fhir.jpa.subscription.model; 021 022import ca.uhn.fhir.context.FhirContext; 023import ca.uhn.fhir.interceptor.model.RequestPartitionId; 024import ca.uhn.fhir.rest.api.server.RequestDetails; 025import ca.uhn.fhir.rest.server.messaging.BaseResourceModifiedMessage; 026import com.fasterxml.jackson.annotation.JsonProperty; 027import org.apache.commons.lang3.builder.ToStringBuilder; 028import org.hl7.fhir.instance.model.api.IBaseResource; 029import org.hl7.fhir.instance.model.api.IIdType; 030 031/** 032 * Most of this class has been moved to ResourceModifiedMessage in the hapi-fhir-server project, for a reusable channel ResourceModifiedMessage 033 * that doesn't require knowledge of subscriptions. 034 */ 035public class ResourceModifiedMessage extends BaseResourceModifiedMessage { 036 037 /** 038 * This will only be set if the resource is being triggered for a specific 039 * subscription 040 */ 041 @JsonProperty(value = "subscriptionId") 042 private String mySubscriptionId; 043 044 /** 045 * Constructor 046 */ 047 public ResourceModifiedMessage() { 048 super(); 049 } 050 051 public ResourceModifiedMessage(IIdType theIdType, OperationTypeEnum theOperationType) { 052 super(theIdType, theOperationType); 053 setPartitionId(RequestPartitionId.defaultPartition()); 054 } 055 056 public ResourceModifiedMessage( 057 FhirContext theFhirContext, IBaseResource theResource, OperationTypeEnum theOperationType) { 058 super(theFhirContext, theResource, theOperationType); 059 setPartitionId(RequestPartitionId.defaultPartition()); 060 } 061 062 public ResourceModifiedMessage( 063 FhirContext theFhirContext, 064 IBaseResource theResource, 065 OperationTypeEnum theOperationType, 066 RequestPartitionId theRequestPartitionId) { 067 super(theFhirContext, theResource, theOperationType); 068 setPartitionId(theRequestPartitionId); 069 } 070 071 public ResourceModifiedMessage( 072 FhirContext theFhirContext, 073 IBaseResource theNewResource, 074 OperationTypeEnum theOperationType, 075 RequestDetails theRequest) { 076 super(theFhirContext, theNewResource, theOperationType, theRequest); 077 setPartitionId(RequestPartitionId.defaultPartition()); 078 } 079 080 public ResourceModifiedMessage( 081 FhirContext theFhirContext, 082 IBaseResource theNewResource, 083 OperationTypeEnum theOperationType, 084 RequestDetails theRequest, 085 RequestPartitionId theRequestPartitionId) { 086 super(theFhirContext, theNewResource, theOperationType, theRequest, theRequestPartitionId); 087 } 088 089 public String getSubscriptionId() { 090 return mySubscriptionId; 091 } 092 093 public void setSubscriptionId(String theSubscriptionId) { 094 mySubscriptionId = theSubscriptionId; 095 } 096 097 public void setPayloadToNull() { 098 myPayload = null; 099 } 100 101 @Override 102 public String toString() { 103 return new ToStringBuilder(this) 104 .append("operationType", myOperationType) 105 .append("subscriptionId", mySubscriptionId) 106 .append("payloadId", myPayloadId) 107 .append("partitionId", myPartitionId) 108 .toString(); 109 } 110}