001package ca.uhn.fhir.rest.client.method; 002 003/* 004 * #%L 005 * HAPI FHIR - Client Framework 006 * %% 007 * Copyright (C) 2014 - 2019 University Health Network 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 java.util.List; 024import java.util.Map; 025 026import org.hl7.fhir.instance.model.api.IIdType; 027 028import ca.uhn.fhir.context.FhirContext; 029import ca.uhn.fhir.rest.api.EncodingEnum; 030import ca.uhn.fhir.rest.api.RequestTypeEnum; 031import ca.uhn.fhir.rest.client.api.IHttpClient; 032import ca.uhn.fhir.rest.client.api.IHttpRequest; 033import ca.uhn.fhir.rest.client.impl.BaseHttpClientInvocation; 034 035public class HttpPatchClientInvocation extends BaseHttpClientInvocation { 036 037 private String myUrlPath; 038 private Map<String, List<String>> myParams; 039 private String myContents; 040 private String myContentType; 041 042 public HttpPatchClientInvocation(FhirContext theContext, IIdType theId, String theContentType, String theContents) { 043 super(theContext); 044 myUrlPath = theId.toUnqualifiedVersionless().getValue(); 045 myContentType = theContentType; 046 myContents = theContents; 047 } 048 049 public HttpPatchClientInvocation(FhirContext theContext, String theUrlPath, String theContentType, String theContents) { 050 super(theContext); 051 myUrlPath = theUrlPath; 052 myContentType = theContentType; 053 myContents = theContents; 054 } 055 056 @Override 057 public IHttpRequest asHttpRequest(String theUrlBase, Map<String, List<String>> theExtraParams, EncodingEnum theEncoding, Boolean thePrettyPrint) { 058 StringBuilder b = new StringBuilder(); 059 b.append(theUrlBase); 060 if (!theUrlBase.endsWith("/")) { 061 b.append('/'); 062 } 063 b.append(myUrlPath); 064 065 appendExtraParamsWithQuestionMark(myParams, b, b.indexOf("?") == -1); 066 appendExtraParamsWithQuestionMark(theExtraParams, b, b.indexOf("?") == -1); 067 068 069 070 return createHttpRequest(b.toString(), theEncoding, RequestTypeEnum.PATCH); 071 } 072 073 @Override 074 protected IHttpRequest createHttpRequest(String theUrl, EncodingEnum theEncoding, RequestTypeEnum theRequestType) { 075 IHttpClient httpClient = getRestfulClientFactory().getHttpClient(new StringBuilder(theUrl), null, null, theRequestType, getHeaders()); 076 return httpClient.createByteRequest(getContext(), myContents, myContentType, null); 077 } 078 079 080}