001package ca.uhn.fhir.interceptor.model; 002 003/*- 004 * #%L 005 * HAPI FHIR - Core Library 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.rest.api.RestOperationTypeEnum; 024import org.hl7.fhir.instance.model.api.IBaseResource; 025import org.hl7.fhir.instance.model.api.IIdType; 026 027import javax.annotation.Nullable; 028 029public class ReadPartitionIdRequestDetails { 030 031 private final String myResourceType; 032 private final RestOperationTypeEnum myRestOperationType; 033 private final IIdType myReadResourceId; 034 private final Object mySearchParams; 035 private final IBaseResource myConditionalTargetOrNull; 036 037 public ReadPartitionIdRequestDetails(String theResourceType, RestOperationTypeEnum theRestOperationType, IIdType theReadResourceId, Object theSearchParams, @Nullable IBaseResource theConditionalTargetOrNull) { 038 myResourceType = theResourceType; 039 myRestOperationType = theRestOperationType; 040 myReadResourceId = theReadResourceId; 041 mySearchParams = theSearchParams; 042 myConditionalTargetOrNull = theConditionalTargetOrNull; 043 } 044 045 public static ReadPartitionIdRequestDetails forRead(String theResourceType, IIdType theId, boolean theIsVread) { 046 RestOperationTypeEnum op = theIsVread ? RestOperationTypeEnum.VREAD : RestOperationTypeEnum.READ; 047 return new ReadPartitionIdRequestDetails(theResourceType, op, theId.withResourceType(theResourceType), null, null); 048 } 049 050 public String getResourceType() { 051 return myResourceType; 052 } 053 054 public RestOperationTypeEnum getRestOperationType() { 055 return myRestOperationType; 056 } 057 058 public IIdType getReadResourceId() { 059 return myReadResourceId; 060 } 061 062 public Object getSearchParams() { 063 return mySearchParams; 064 } 065 066 public IBaseResource getConditionalTargetOrNull() { 067 return myConditionalTargetOrNull; 068 } 069 070 public static ReadPartitionIdRequestDetails forSearchType(String theResourceType, Object theParams, IBaseResource theConditionalOperationTargetOrNull) { 071 return new ReadPartitionIdRequestDetails(theResourceType, RestOperationTypeEnum.SEARCH_TYPE, null, theParams, theConditionalOperationTargetOrNull); 072 } 073 074 public static ReadPartitionIdRequestDetails forHistory(String theResourceType, IIdType theIdType) { 075 RestOperationTypeEnum restOperationTypeEnum; 076 if (theIdType != null) { 077 restOperationTypeEnum = RestOperationTypeEnum.HISTORY_INSTANCE; 078 } else if (theResourceType != null) { 079 restOperationTypeEnum = RestOperationTypeEnum.HISTORY_TYPE; 080 } else { 081 restOperationTypeEnum = RestOperationTypeEnum.HISTORY_SYSTEM; 082 } 083 return new ReadPartitionIdRequestDetails(theResourceType, restOperationTypeEnum, theIdType, null, null); 084 } 085}