001/*-
002 * #%L
003 * HAPI FHIR Storage api
004 * %%
005 * Copyright (C) 2014 - 2023 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;
032import org.springframework.beans.factory.annotation.Required;
033
034public abstract class BaseStorageSystemProvider<T, MT> extends BaseJpaProvider {
035        protected IFhirSystemDao<T, MT> myDao;
036
037        @Operation(name = ProviderConstants.OPERATION_EXPUNGE, idempotent = false, returnParameters = {
038                @OperationParam(name = JpaConstants.OPERATION_EXPUNGE_OUT_PARAM_EXPUNGE_COUNT, typeName = "integer")
039        })
040        public IBaseParameters expunge(
041                @OperationParam(name = ProviderConstants.OPERATION_EXPUNGE_PARAM_LIMIT, typeName = "integer") IPrimitiveType<Integer> theLimit,
042                @OperationParam(name = ProviderConstants.OPERATION_EXPUNGE_PARAM_EXPUNGE_DELETED_RESOURCES, typeName = "boolean") IPrimitiveType<Boolean> theExpungeDeletedResources,
043                @OperationParam(name = ProviderConstants.OPERATION_EXPUNGE_PARAM_EXPUNGE_PREVIOUS_VERSIONS, typeName = "boolean") IPrimitiveType<Boolean> theExpungeOldVersions,
044                @OperationParam(name = ProviderConstants.OPERATION_EXPUNGE_PARAM_EXPUNGE_EVERYTHING, typeName = "boolean") IPrimitiveType<Boolean> theExpungeEverything,
045                RequestDetails theRequestDetails
046        ) {
047                return doExpunge(theLimit, theExpungeDeletedResources, theExpungeOldVersions, theExpungeEverything, theRequestDetails);
048        }
049
050        protected IBaseParameters doExpunge(IPrimitiveType<? extends Integer> theLimit, IPrimitiveType<? extends Boolean> theExpungeDeletedResources, IPrimitiveType<? extends Boolean> theExpungeOldVersions, IPrimitiveType<? extends Boolean> theExpungeEverything, RequestDetails theRequestDetails) {
051                ExpungeOptions options = createExpungeOptions(theLimit, theExpungeDeletedResources, theExpungeOldVersions, theExpungeEverything);
052                ExpungeOutcome outcome = getDao().expunge(options, theRequestDetails);
053                return createExpungeResponse(outcome);
054        }
055
056        protected IFhirSystemDao<T, MT> getDao() {
057                return myDao;
058        }
059
060        @Required
061        public void setDao(IFhirSystemDao<T, MT> theDao) {
062                myDao = theDao;
063        }
064}