001package ca.uhn.fhir.rest.server.exceptions;
002
003/*
004 * #%L
005 * HAPI FHIR - Core Library
006 * %%
007 * Copyright (C) 2014 - 2022 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.model.base.composite.BaseIdentifierDt;
024import ca.uhn.fhir.rest.api.Constants;
025import ca.uhn.fhir.util.CoverageIgnore;
026import org.hl7.fhir.instance.model.api.IBaseOperationOutcome;
027import org.hl7.fhir.instance.model.api.IBaseResource;
028import org.hl7.fhir.instance.model.api.IIdType;
029
030/**
031 * Represents an <b>HTTP 410 Resource Gone</b> response, which geenerally
032 * indicates that the resource has been deleted
033 */
034@CoverageIgnore
035public class ResourceGoneException extends BaseServerResponseException {
036
037        public static final int STATUS_CODE = Constants.STATUS_HTTP_410_GONE;
038        private static final long serialVersionUID = 1L;
039        private IIdType myResourceId;
040
041        /**
042         * Constructor which creates an error message based on a given resource ID
043         *
044         * @param theResourceId The ID of the resource that could not be found
045         */
046        public ResourceGoneException(IIdType theResourceId) {
047                super(STATUS_CODE, "Resource " + (theResourceId != null ? theResourceId.getValue() : "") + " is gone/deleted");
048                myResourceId = theResourceId;
049        }
050
051        /**
052         * @deprecated This constructor has a dependency on a specific model version and will be removed. Deprecated in HAPI
053         * 1.6 - 2016-07-02
054         */
055        @Deprecated
056        public ResourceGoneException(Class<? extends IBaseResource> theClass, BaseIdentifierDt thePatientId) {
057                super(STATUS_CODE, "Resource of type " + theClass.getSimpleName() + " with ID " + thePatientId + " is gone/deleted");
058                myResourceId = null;
059        }
060
061        /**
062         * Constructor which creates an error message based on a given resource ID
063         *
064         * @param theClass      The type of resource that could not be found
065         * @param theResourceId The ID of the resource that could not be found
066         */
067        public ResourceGoneException(Class<? extends IBaseResource> theClass, IIdType theResourceId) {
068                super(STATUS_CODE, "Resource of type " + theClass.getSimpleName() + " with ID " + theResourceId + " is gone/deleted");
069                myResourceId = theResourceId;
070        }
071
072        /**
073         * Constructor
074         *
075         * @param theMessage          The message
076         * @param theOperationOutcome The OperationOutcome resource to return to the client
077         */
078        public ResourceGoneException(String theMessage, IBaseOperationOutcome theOperationOutcome) {
079                super(STATUS_CODE, theMessage, theOperationOutcome);
080        }
081
082        /**
083         * Constructor
084         *
085         * @param theMessage The message
086         */
087        public ResourceGoneException(String theMessage) {
088                super(STATUS_CODE, theMessage);
089        }
090
091        public IIdType getResourceId() {
092                return myResourceId;
093        }
094
095        public void setResourceId(IIdType theResourceId) {
096                myResourceId = theResourceId;
097        }
098
099}