001package ca.uhn.fhir.subscription.api;
002
003/*-
004 * #%L
005 * HAPI FHIR Storage api
006 * %%
007 * Copyright (C) 2014 - 2024 Smile CDR, Inc.
008 * %%
009 * Licensed under the Apache License, Version 2.0 (the "License");
010 * you may not use this file except in compliance with the License.
011 * You may obtain a copy of the License at
012 *
013 *      http://www.apache.org/licenses/LICENSE-2.0
014 *
015 * Unless required by applicable law or agreed to in writing, software
016 * distributed under the License is distributed on an "AS IS" BASIS,
017 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
018 * See the License for the specific language governing permissions and
019 * limitations under the License.
020 * #L%
021 */
022
023import ca.uhn.fhir.jpa.model.entity.IPersistedResourceModifiedMessage;
024import ca.uhn.fhir.jpa.model.entity.IPersistedResourceModifiedMessagePK;
025import ca.uhn.fhir.jpa.subscription.model.ResourceModifiedMessage;
026
027import java.util.List;
028import java.util.Optional;
029
030/**
031 * An implementer of this interface will provide {@link ResourceModifiedMessage} persistence services.
032 *
033 * Client of this interface should persist ResourceModifiedMessage as part of the processing of an operation on
034 * a resource.  Upon a successful submission to the subscription pipeline, the persisted message should be deleted.
035 * When submission fails, the message should be left un-altered for re-submission at a later time (see {@link IResourceModifiedConsumerWithRetries}).
036 */
037public interface IResourceModifiedMessagePersistenceSvc {
038
039        /**
040         * Find all persistedResourceModifiedMessage sorted by ascending created dates (oldest to newest).
041         *
042         * @return A sorted list of persistedResourceModifiedMessage needing submission.
043         */
044        List<IPersistedResourceModifiedMessage> findAllOrderedByCreatedTime();
045
046        /**
047         * Delete a persistedResourceModifiedMessage by its primary key.
048         *
049         * @param thePersistedResourceModifiedMessagePK The primary key of the persistedResourceModifiedMessage to delete.
050         * @return Whether the persistedResourceModifiedMessage pointed to by <code>theResourceModifiedPK</code> was deleted.
051         */
052        boolean deleteByPK(IPersistedResourceModifiedMessagePK thePersistedResourceModifiedMessagePK);
053
054        /**
055         * Persist a resourceModifiedMessage and return its resulting persisted representation.
056         *
057         * @param theMsg The resourceModifiedMessage to persist.
058         * @return The persisted representation of <code>theMsg</code>.
059         */
060        IPersistedResourceModifiedMessage persist(ResourceModifiedMessage theMsg);
061
062        /**
063         * Restore a resourceModifiedMessage to its pre persistence representation.
064         *
065         * @param theResourceModifiedMessage The message needing restoration.
066         * @return The resourceModifiedMessage in its pre persistence form.
067         */
068        ResourceModifiedMessage inflatePersistedResourceModifiedMessage(ResourceModifiedMessage theResourceModifiedMessage);
069
070        /**
071         * Restore a resourceModifiedMessage to its pre persistence representation or null if the resource does not exist.
072         *
073         * @param theResourceModifiedMessage
074         * @return An Optional containing The resourceModifiedMessage in its pre persistence form or null when the resource
075         * does not exist
076         */
077        Optional<ResourceModifiedMessage> inflatePersistedResourceModifiedMessageOrNull(
078                        ResourceModifiedMessage theResourceModifiedMessage);
079
080        /**
081         * Create a ResourceModifiedMessage without its pre persistence representation, i.e. without the resource body in
082         * payload
083         *
084         * @param thePersistedResourceModifiedMessage The message needing creation
085         * @return The resourceModifiedMessage without its pre persistence form
086         */
087        ResourceModifiedMessage createResourceModifiedMessageFromEntityWithoutInflation(
088                        IPersistedResourceModifiedMessage thePersistedResourceModifiedMessage);
089
090        /**
091         *
092         * @return the number of persisted resourceModifiedMessage.
093         */
094        long getMessagePersistedCount();
095}