001/* 002 * #%L 003 * HAPI FHIR JPA - Search Parameters 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.searchparam.util; 021 022import ca.uhn.fhir.rest.api.Constants; 023 024import static org.apache.commons.lang3.StringUtils.defaultString; 025import static org.apache.commons.lang3.StringUtils.left; 026 027/** 028 * Model of the _source parameter 029 */ 030public class SourceParam { 031 032 private static final long serialVersionUID = 1L; 033 private final String myParameterValue; 034 private final String mySourceUri; 035 private final String myRequestId; 036 037 public SourceParam(String theParameterValue) { 038 myParameterValue = defaultString(theParameterValue); 039 String requestId; 040 int lastHashValueIndex = myParameterValue.lastIndexOf('#'); 041 if (lastHashValueIndex == -1) { 042 mySourceUri = myParameterValue; 043 requestId = null; 044 } else { 045 if (lastHashValueIndex == 0) { 046 mySourceUri = null; 047 } else { 048 mySourceUri = myParameterValue.substring(0, lastHashValueIndex); 049 } 050 requestId = myParameterValue.substring(lastHashValueIndex + 1); 051 } 052 myRequestId = left(requestId, Constants.REQUEST_ID_LENGTH); 053 } 054 055 public String getSourceUri() { 056 return mySourceUri; 057 } 058 059 public String getRequestId() { 060 return myRequestId; 061 } 062}