001/*-
002 * #%L
003 * HAPI FHIR JPA Server
004 * %%
005 * Copyright (C) 2014 - 2025 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.model.cross;
021
022import ca.uhn.fhir.jpa.model.dao.JpaPid;
023import ca.uhn.fhir.jpa.model.entity.PartitionablePartitionId;
024import org.apache.commons.lang3.builder.ToStringBuilder;
025import org.apache.commons.lang3.builder.ToStringStyle;
026
027import java.util.Date;
028
029public class JpaResourceLookup implements IResourceLookup<JpaPid> {
030
031        private final String myResourceType;
032        private final JpaPid myResourcePid;
033        private final Date myDeletedAt;
034        private final PartitionablePartitionId myPartitionablePartitionId;
035        private final String myFhirId;
036
037        public JpaResourceLookup(
038                        String theResourceType,
039                        String theFhirId,
040                        Long theResourcePid,
041                        Date theDeletedAt,
042                        PartitionablePartitionId thePartitionablePartitionId) {
043                myResourceType = theResourceType;
044                myFhirId = theFhirId;
045                myDeletedAt = theDeletedAt;
046                myPartitionablePartitionId = thePartitionablePartitionId;
047
048                myResourcePid = JpaPid.fromId(theResourcePid, myPartitionablePartitionId);
049        }
050
051        public JpaResourceLookup(
052                        String theResourceType,
053                        String theFhirId,
054                        JpaPid theResourcePid,
055                        Date theDeletedAt,
056                        PartitionablePartitionId thePartitionablePartitionId) {
057                myResourceType = theResourceType;
058                myFhirId = theFhirId;
059                myResourcePid = theResourcePid;
060                myDeletedAt = theDeletedAt;
061                myPartitionablePartitionId = thePartitionablePartitionId;
062        }
063
064        @Override
065        public String getResourceType() {
066                return myResourceType;
067        }
068
069        @Override
070        public String getFhirId() {
071                return myFhirId;
072        }
073
074        @Override
075        public Date getDeleted() {
076                return myDeletedAt;
077        }
078
079        @Override
080        public JpaPid getPersistentId() {
081                return myResourcePid;
082        }
083
084        @Override
085        public String toString() {
086                return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE)
087                                .append("resType", myResourceType)
088                                .append("resPid", myResourcePid)
089                                .append("deletedAt", myDeletedAt)
090                                .append("partId", myPartitionablePartitionId)
091                                .toString();
092        }
093
094        @Override
095        public PartitionablePartitionId getPartitionId() {
096                return myPartitionablePartitionId;
097        }
098}