001package ca.uhn.fhir.util.bundle;
002
003/*-
004 * #%L
005 * HAPI FHIR - Core Library
006 * %%
007 * Copyright (C) 2014 - 2020 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 ca.uhn.fhir.context.BaseRuntimeChildDefinition;
024import ca.uhn.fhir.context.BaseRuntimeElementCompositeDefinition;
025import ca.uhn.fhir.context.FhirContext;
026import ca.uhn.fhir.util.ParametersUtil;
027import org.hl7.fhir.instance.model.api.IBase;
028import org.hl7.fhir.instance.model.api.IPrimitiveType;
029
030public class BundleEntryMutator {
031        private final IBase myEntry;
032        private final BaseRuntimeChildDefinition myRequestChildDef;
033        private final BaseRuntimeElementCompositeDefinition<?> myRequestChildContentsDef;
034
035        public BundleEntryMutator(IBase theEntry, BaseRuntimeChildDefinition theRequestChildDef, BaseRuntimeElementCompositeDefinition<?> theRequestChildContentsDef) {
036                myEntry = theEntry;
037                myRequestChildDef = theRequestChildDef;
038                myRequestChildContentsDef = theRequestChildContentsDef;
039        }
040
041        void setRequestUrl(FhirContext theFhirContext, String theRequestUrl) {
042                BaseRuntimeChildDefinition requestUrlChildDef = myRequestChildContentsDef.getChildByName("url");
043                IPrimitiveType<?> url = ParametersUtil.createUri(theFhirContext, theRequestUrl);
044                for (IBase nextRequest : myRequestChildDef.getAccessor().getValues(myEntry)) {
045                        requestUrlChildDef.getMutator().addValue(nextRequest, url);
046                }
047        }
048}