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.provider;
021
022import ca.uhn.fhir.jpa.api.dao.IFhirSystemDao;
023import ca.uhn.fhir.jpa.api.model.ExpungeOptions;
024import ca.uhn.fhir.jpa.api.model.ExpungeOutcome;
025import ca.uhn.fhir.jpa.model.util.JpaConstants;
026import ca.uhn.fhir.rest.annotation.Operation;
027import ca.uhn.fhir.rest.annotation.OperationParam;
028import ca.uhn.fhir.rest.api.server.RequestDetails;
029import ca.uhn.fhir.rest.server.provider.ProviderConstants;
030import org.hl7.fhir.instance.model.api.IBaseParameters;
031import org.hl7.fhir.instance.model.api.IPrimitiveType;
032
033public abstract class BaseStorageSystemProvider<T, MT> extends BaseJpaProvider {
034        protected IFhirSystemDao<T, MT> myDao;
035
036        @Operation(
037                        name = ProviderConstants.OPERATION_EXPUNGE,
038                        idempotent = false,
039                        returnParameters = {
040                                @OperationParam(name = JpaConstants.OPERATION_EXPUNGE_OUT_PARAM_EXPUNGE_COUNT, typeName = "integer")
041                        })
042        public IBaseParameters expunge(
043                        @OperationParam(name = ProviderConstants.OPERATION_EXPUNGE_PARAM_LIMIT, typeName = "integer")
044                                        IPrimitiveType<Integer> theLimit,
045                        @OperationParam(
046                                                        name = ProviderConstants.OPERATION_EXPUNGE_PARAM_EXPUNGE_DELETED_RESOURCES,
047                                                        typeName = "boolean")
048                                        IPrimitiveType<Boolean> theExpungeDeletedResources,
049                        @OperationParam(
050                                                        name = ProviderConstants.OPERATION_EXPUNGE_PARAM_EXPUNGE_PREVIOUS_VERSIONS,
051                                                        typeName = "boolean")
052                                        IPrimitiveType<Boolean> theExpungeOldVersions,
053                        @OperationParam(name = ProviderConstants.OPERATION_EXPUNGE_PARAM_EXPUNGE_EVERYTHING, typeName = "boolean")
054                                        IPrimitiveType<Boolean> theExpungeEverything,
055                        RequestDetails theRequestDetails) {
056                return doExpunge(
057                                theLimit, theExpungeDeletedResources, theExpungeOldVersions, theExpungeEverything, theRequestDetails);
058        }
059
060        protected IBaseParameters doExpunge(
061                        IPrimitiveType<? extends Integer> theLimit,
062                        IPrimitiveType<? extends Boolean> theExpungeDeletedResources,
063                        IPrimitiveType<? extends Boolean> theExpungeOldVersions,
064                        IPrimitiveType<? extends Boolean> theExpungeEverything,
065                        RequestDetails theRequestDetails) {
066                ExpungeOptions options =
067                                createExpungeOptions(theLimit, theExpungeDeletedResources, theExpungeOldVersions, theExpungeEverything);
068                ExpungeOutcome outcome = getDao().expunge(options, theRequestDetails);
069                return createExpungeResponse(outcome);
070        }
071
072        protected IFhirSystemDao<T, MT> getDao() {
073                return myDao;
074        }
075
076        public void setDao(IFhirSystemDao<T, MT> theDao) {
077                myDao = theDao;
078        }
079}