001package ca.uhn.fhir.rest.server.interceptor;
002
003/*
004 * #%L
005 * HAPI FHIR - Server Framework
006 * %%
007 * Copyright (C) 2014 - 2021 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.interceptor.api.Hook;
024import ca.uhn.fhir.interceptor.api.Pointcut;
025import ca.uhn.fhir.rest.api.server.RequestDetails;
026import org.hl7.fhir.instance.model.api.IBaseResource;
027
028/**
029 * Server interceptor with added methods which can be called within the lifecycle of
030 * write operations (create/update/delete) or within transaction and batch
031 * operations that call these sub-operations.
032 *
033 * @see ServerOperationInterceptorAdapter
034 * @deprecated Ths interface is no longer neccessary as of HAPI FHIR 3.8.0 - You can create
035 * interceptor methods that are declared using the {@link Hook} annotation without needing
036 * to implement any interceptor
037 */
038@Deprecated
039public interface IServerOperationInterceptor extends IServerInterceptor {
040
041        /**
042         * This method is called by the server immediately after a resource has
043         * been created, within the database transaction scope of the operation.
044         * <p>
045         * If an exception is thrown by an interceptor during this method,
046         * the transaction will be rolled back.
047         * </p>
048         */
049        @Hook(Pointcut.STORAGE_PRECOMMIT_RESOURCE_CREATED)
050        void resourceCreated(RequestDetails theRequest, IBaseResource theResource);
051
052        /**
053         * This method is called by the server immediately after a resource has
054         * been deleted, within the database transaction scope of the operation.
055         * <p>
056         * If an exception is thrown by an interceptor during this method,
057         * the transaction will be rolled back.
058         * </p>
059         */
060        @Hook(Pointcut.STORAGE_PRECOMMIT_RESOURCE_DELETED)
061        void resourceDeleted(RequestDetails theRequest, IBaseResource theResource);
062
063        /**
064         * This method is called by the server immediately before a resource is about
065         * to be created, within the database transaction scope of the operation.
066         * <p>
067         * This method may be used to modify the resource
068         * </p>
069         * <p>
070         * If an exception is thrown by an interceptor during this method,
071         * the transaction will be rolled back.
072         * </p>
073         *
074         * @param theResource The resource that has been provided by the client as the payload
075         *                    to create. Interceptors may modify this
076         *                    resource, and modifications will affect what is saved in the database.
077         */
078        @Hook(Pointcut.STORAGE_PRESTORAGE_RESOURCE_CREATED)
079        void resourcePreCreate(RequestDetails theRequest, IBaseResource theResource);
080
081        /**
082         * This method is called by the server immediately before a resource is about
083         * to be deleted, within the database transaction scope of the operation.
084         * <p>
085         * If an exception is thrown by an interceptor during this method,
086         * the transaction will be rolled back.
087         * </p>
088         *
089         * @param theResource The resource which is about to be deleted
090         */
091        @Hook(Pointcut.STORAGE_PRESTORAGE_RESOURCE_DELETED)
092        void resourcePreDelete(RequestDetails theRequest, IBaseResource theResource);
093
094        /**
095         * This method is called by the server immediately before a resource is about
096         * to be updated, within the database transaction scope of the operation.
097         * <p>
098         * This method may be used to modify the resource
099         * </p>
100         * <p>
101         * If an exception is thrown by an interceptor during this method,
102         * the transaction will be rolled back.
103         * </p>
104         *
105         * @param theOldResource The previous version of the resource, or <code>null</code> if this is not available. Interceptors should be able to handle situations where this is null, since it is not always
106         *                       convenient or possible to provide a value for this field, but servers should try to populate it.
107         * @param theNewResource The resource that has been provided by the client as the payload
108         *                       to update to the resource to. Interceptors may modify this
109         *                       resource, and modifications will affect what is saved in the database.
110         */
111        @Hook(Pointcut.STORAGE_PRESTORAGE_RESOURCE_UPDATED)
112        void resourcePreUpdate(RequestDetails theRequest, IBaseResource theOldResource, IBaseResource theNewResource);
113
114        /**
115         * @deprecated Deprecated in HAPI FHIR 3.0.0 in favour of {@link #resourceUpdated(RequestDetails, IBaseResource, IBaseResource)}
116         */
117        @Deprecated
118        @Hook(Pointcut.STORAGE_PRECOMMIT_RESOURCE_UPDATED)
119        void resourceUpdated(RequestDetails theRequest, IBaseResource theResource);
120
121        /**
122         * This method is called by the server immediately after a resource has
123         * been created, within the database transaction scope of the operation.
124         * <p>
125         * If an exception is thrown by an interceptor during this method,
126         * the transaction will be rolled back.
127         * </p>
128         *
129         * @param theOldResource The resource as it was before the update, or <code>null</code> if this is not available. Interceptors should be able to handle situations where this is null, since it is not always
130         *                       convenient or possible to provide a value for this field, but servers should try to populate it.
131         * @param theNewResource The resource as it will be after the update
132         */
133        @Hook(Pointcut.STORAGE_PRECOMMIT_RESOURCE_UPDATED)
134        void resourceUpdated(RequestDetails theRequest, IBaseResource theOldResource, IBaseResource theNewResource);
135
136}