SearchParameterMap deep cloning via serialization/deserialization (#6104)

This commit is contained in:
Roman Surkov 2024-07-18 23:36:11 +02:00
parent d68a71abb4
commit 434281c0ef
1 changed files with 3 additions and 30 deletions

View File

@ -38,6 +38,7 @@ import ca.uhn.fhir.rest.param.TokenParamModifier;
import ca.uhn.fhir.util.UrlUtil;
import com.fasterxml.jackson.annotation.JsonIgnore;
import jakarta.annotation.Nonnull;
import org.apache.commons.lang3.SerializationUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.Validate;
import org.apache.commons.lang3.builder.CompareToBuilder;
@ -101,40 +102,12 @@ public class SearchParameterMap implements Serializable {
}
/**
* Creates and returns a copy of this map
* Creates and returns a deep clone of this map
*/
@JsonIgnore
@Override
public SearchParameterMap clone() {
SearchParameterMap map = new SearchParameterMap();
map.setSummaryMode(getSummaryMode());
map.setSort(getSort());
map.setSearchTotalMode(getSearchTotalMode());
map.setRevIncludes(getRevIncludes());
map.setIncludes(getIncludes());
map.setEverythingMode(getEverythingMode());
map.setCount(getCount());
map.setDeleteExpunge(isDeleteExpunge());
map.setLastN(isLastN());
map.setLastNMax(getLastNMax());
map.setLastUpdated(getLastUpdated());
map.setLoadSynchronous(isLoadSynchronous());
map.setNearDistanceParam(getNearDistanceParam());
map.setLoadSynchronousUpTo(getLoadSynchronousUpTo());
map.setOffset(getOffset());
map.setSearchContainedMode(getSearchContainedMode());
for (Map.Entry<String, List<List<IQueryParameterType>>> entry : mySearchParameterMap.entrySet()) {
List<List<IQueryParameterType>> andParams = entry.getValue();
List<List<IQueryParameterType>> newAndParams = new ArrayList<>();
for (List<IQueryParameterType> orParams : andParams) {
List<IQueryParameterType> newOrParams = new ArrayList<>(orParams);
newAndParams.add(newOrParams);
}
map.put(entry.getKey(), newAndParams);
}
return map;
return SerializationUtils.clone(this);
}
public SummaryEnum getSummaryMode() {