Fix NPE in IdHelperService (#2819)
This commit is contained in:
parent
8b8db82666
commit
d78fef6732
|
@ -36,6 +36,7 @@ import ca.uhn.fhir.model.primitive.IdDt;
|
|||
import ca.uhn.fhir.rest.api.server.storage.ResourcePersistentId;
|
||||
import ca.uhn.fhir.rest.server.exceptions.PreconditionFailedException;
|
||||
import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException;
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import com.google.common.collect.ListMultimap;
|
||||
import com.google.common.collect.MultimapBuilder;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
@ -389,9 +390,9 @@ public class IdHelperService {
|
|||
return retVal;
|
||||
}
|
||||
|
||||
private RequestPartitionId replaceDefault(RequestPartitionId theRequestPartitionId) {
|
||||
RequestPartitionId replaceDefault(RequestPartitionId theRequestPartitionId) {
|
||||
if (myPartitionSettings.getDefaultPartitionId() != null) {
|
||||
if (theRequestPartitionId.hasDefaultPartitionId()) {
|
||||
if (!theRequestPartitionId.isAllPartitions() && theRequestPartitionId.hasDefaultPartitionId()) {
|
||||
List<Integer> partitionIds = theRequestPartitionId
|
||||
.getPartitionIds()
|
||||
.stream()
|
||||
|
@ -577,6 +578,11 @@ public class IdHelperService {
|
|||
}
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
void setPartitionSettingsForUnitTest(PartitionSettings thePartitionSettings) {
|
||||
myPartitionSettings = thePartitionSettings;
|
||||
}
|
||||
|
||||
public static boolean isValidPid(IIdType theId) {
|
||||
if (theId == null) {
|
||||
return false;
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
package ca.uhn.fhir.jpa.dao.index;
|
||||
|
||||
import ca.uhn.fhir.interceptor.model.RequestPartitionId;
|
||||
import ca.uhn.fhir.jpa.model.config.PartitionSettings;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
public class IdHelperServiceTest {
|
||||
|
||||
@Test
|
||||
public void testReplaceDefault_AllPartitions() {
|
||||
|
||||
IdHelperService svc = new IdHelperService();
|
||||
PartitionSettings partitionSettings = new PartitionSettings();
|
||||
partitionSettings.setDefaultPartitionId(1);
|
||||
svc.setPartitionSettingsForUnitTest(partitionSettings);
|
||||
|
||||
RequestPartitionId outcome = svc.replaceDefault(RequestPartitionId.allPartitions());
|
||||
assertSame(RequestPartitionId.allPartitions(), outcome);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReplaceDefault_DefaultPartition() {
|
||||
|
||||
IdHelperService svc = new IdHelperService();
|
||||
PartitionSettings partitionSettings = new PartitionSettings();
|
||||
partitionSettings.setDefaultPartitionId(1);
|
||||
svc.setPartitionSettingsForUnitTest(partitionSettings);
|
||||
|
||||
RequestPartitionId outcome = svc.replaceDefault(RequestPartitionId.defaultPartition());
|
||||
assertEquals(1, outcome.getPartitionIds().get(0));
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue