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
031import java.util.Objects;
032
033/**
034 * Most of this class has been moved to ResourceModifiedMessage in the hapi-fhir-server project, for a reusable channel ResourceModifiedMessage
035 * that doesn't require knowledge of subscriptions.
036 */
037public class ResourceModifiedMessage extends BaseResourceModifiedMessage {
038
039        /**
040         * This will only be set if the resource is being triggered for a specific
041         * subscription
042         */
043        @JsonProperty(value = "subscriptionId")
044        private String mySubscriptionId;
045
046        /**
047         * Constructor
048         */
049        public ResourceModifiedMessage() {
050                super();
051        }
052
053        public ResourceModifiedMessage(IIdType theIdType, OperationTypeEnum theOperationType) {
054                super(theIdType, theOperationType);
055                setPartitionId(RequestPartitionId.defaultPartition());
056        }
057
058        public ResourceModifiedMessage(
059                        FhirContext theFhirContext, IBaseResource theResource, OperationTypeEnum theOperationType) {
060                super(theFhirContext, theResource, theOperationType);
061                setPartitionId(RequestPartitionId.defaultPartition());
062        }
063
064        public ResourceModifiedMessage(
065                        FhirContext theFhirContext,
066                        IBaseResource theResource,
067                        OperationTypeEnum theOperationType,
068                        RequestPartitionId theRequestPartitionId) {
069                super(theFhirContext, theResource, theOperationType);
070                setPartitionId(theRequestPartitionId);
071        }
072
073        public ResourceModifiedMessage(
074                        FhirContext theFhirContext,
075                        IBaseResource theNewResource,
076                        OperationTypeEnum theOperationType,
077                        RequestDetails theRequest) {
078                super(theFhirContext, theNewResource, theOperationType, theRequest);
079                setPartitionId(RequestPartitionId.defaultPartition());
080        }
081
082        public ResourceModifiedMessage(
083                        FhirContext theFhirContext,
084                        IBaseResource theNewResource,
085                        OperationTypeEnum theOperationType,
086                        RequestDetails theRequest,
087                        RequestPartitionId theRequestPartitionId) {
088                super(theFhirContext, theNewResource, theOperationType, theRequest, theRequestPartitionId);
089        }
090
091        public String getSubscriptionId() {
092                return mySubscriptionId;
093        }
094
095        public void setSubscriptionId(String theSubscriptionId) {
096                mySubscriptionId = theSubscriptionId;
097        }
098
099        public void setPayloadToNull() {
100                myPayload = null;
101        }
102
103        @Override
104        public String toString() {
105                return new ToStringBuilder(this)
106                                .append("operationType", myOperationType)
107                                .append("subscriptionId", mySubscriptionId)
108                                .append("payloadId", myPayloadId)
109                                .append("partitionId", myPartitionId)
110                                .toString();
111        }
112
113        @Override
114        public boolean equals(Object theO) {
115                if (this == theO) return true;
116                if (theO == null || getClass() != theO.getClass()) return false;
117                if (!super.equals(theO)) return false;
118                ResourceModifiedMessage that = (ResourceModifiedMessage) theO;
119                return Objects.equals(getSubscriptionId(), that.getSubscriptionId());
120        }
121
122        @Override
123        public int hashCode() {
124                return Objects.hash(super.hashCode(), getSubscriptionId());
125        }
126}