Merge branch 'master' into remove-parallel-non-gets
This commit is contained in:
commit
ad05a5ec09
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
type: add
|
||||
issue: 3020
|
||||
jira: SMILE-685,SMILE-3146
|
||||
title: "Added documentation for `$partition-management-read-partition`. Added `$partition-management-list-partitions` operation and documentation."
|
|
@ -186,3 +186,92 @@ The following request body could be used:
|
|||
}
|
||||
```
|
||||
|
||||
# Reading a Partition
|
||||
|
||||
The `$partition-management-read-partition` operation can be used to read an existing partition. This operation takes the following parameters:
|
||||
|
||||
<table class="table table-striped table-condensed">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Name</th>
|
||||
<th>Type</th>
|
||||
<th>Cardinality</th>
|
||||
<th>Description</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>id</td>
|
||||
<td>Integer</td>
|
||||
<td>1..1</td>
|
||||
<td>
|
||||
The numeric ID for the partition to update. This ID must already exist.
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
## Example
|
||||
|
||||
An HTTP POST to the following URL would be used to invoke this operation:
|
||||
|
||||
```url
|
||||
http://example.com/DEFAULT/$partition-management-read-partition
|
||||
```
|
||||
|
||||
The following request body could be used:
|
||||
|
||||
```json
|
||||
{
|
||||
"resourceType": "Parameters",
|
||||
"parameter": [ {
|
||||
"name": "id",
|
||||
"valueInteger": 123
|
||||
} ]
|
||||
}
|
||||
```
|
||||
|
||||
# Listing all Partitions
|
||||
|
||||
The `$partition-management-list-partitions` operation can be used to list all existing partitions.
|
||||
|
||||
## Example
|
||||
|
||||
An HTTP POST to the following URL would be used to invoke this operation:
|
||||
|
||||
```url
|
||||
http://example.com/DEFAULT/$partition-management-list-partitions
|
||||
```
|
||||
|
||||
This operation returns a `Parameters` resource that looks like the following:
|
||||
```json
|
||||
{
|
||||
"resourceType": "Parameters",
|
||||
"parameter": [ {
|
||||
"name": "partition",
|
||||
"part": [ {
|
||||
"name": "id",
|
||||
"valueInteger": 1
|
||||
}, {
|
||||
"name": "name",
|
||||
"valueCode": "PARTITION-1"
|
||||
}, {
|
||||
"name": "description",
|
||||
"valueString": "a description1"
|
||||
} ]
|
||||
}, {
|
||||
"name": "partition",
|
||||
"part": [ {
|
||||
"name": "id",
|
||||
"valueInteger": 2
|
||||
}, {
|
||||
"name": "name",
|
||||
"valueCode": "PARTITION-2"
|
||||
}, {
|
||||
"name": "description",
|
||||
"valueString": "a description2"
|
||||
} ]
|
||||
} ]
|
||||
}
|
||||
```
|
||||
|
||||
|
|
|
@ -24,6 +24,7 @@ import ca.uhn.fhir.jpa.entity.PartitionEntity;
|
|||
import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.List;
|
||||
|
||||
public interface IPartitionLookupSvc {
|
||||
|
||||
|
@ -51,4 +52,5 @@ public interface IPartitionLookupSvc {
|
|||
|
||||
void deletePartition(Integer thePartitionId);
|
||||
|
||||
List<PartitionEntity> listPartitions();
|
||||
}
|
||||
|
|
|
@ -42,6 +42,7 @@ import org.springframework.transaction.support.TransactionTemplate;
|
|||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.transaction.Transactional;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.regex.Pattern;
|
||||
|
@ -169,6 +170,12 @@ public class PartitionLookupSvcImpl implements IPartitionLookupSvc {
|
|||
clearCaches();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<PartitionEntity> listPartitions() {
|
||||
List<PartitionEntity> allPartitions = myPartitionDao.findAll();
|
||||
return allPartitions;
|
||||
}
|
||||
|
||||
private void validatePartitionNameDoesntAlreadyExist(String theName) {
|
||||
if (myPartitionDao.findForName(theName).isPresent()) {
|
||||
String msg = myFhirCtx.getLocalizer().getMessageSanitized(PartitionLookupSvcImpl.class, "cantCreateDuplicatePartitionName", theName);
|
||||
|
|
|
@ -25,14 +25,19 @@ import ca.uhn.fhir.jpa.entity.PartitionEntity;
|
|||
import ca.uhn.fhir.rest.annotation.Operation;
|
||||
import ca.uhn.fhir.rest.annotation.OperationParam;
|
||||
import ca.uhn.fhir.rest.annotation.ResourceParam;
|
||||
import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException;
|
||||
import ca.uhn.fhir.rest.server.provider.ProviderConstants;
|
||||
import ca.uhn.fhir.util.ParametersUtil;
|
||||
import org.hl7.fhir.instance.model.api.IBase;
|
||||
import org.hl7.fhir.instance.model.api.IBaseParameters;
|
||||
import org.hl7.fhir.instance.model.api.IPrimitiveType;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static ca.uhn.fhir.jpa.partition.PartitionLookupSvcImpl.validatePartitionIdSupplied;
|
||||
import static org.apache.commons.lang3.StringUtils.isNotBlank;
|
||||
import static org.hl7.fhir.instance.model.api.IPrimitiveType.toValueOrNull;
|
||||
|
@ -43,6 +48,8 @@ import static org.hl7.fhir.instance.model.api.IPrimitiveType.toValueOrNull;
|
|||
* <li><code>partition-management-create-partition</code></li>
|
||||
* <li><code>partition-management-update-partition</code></li>
|
||||
* <li><code>partition-management-delete-partition</code></li>
|
||||
* <li><code>partition-management-read-partition</code></li>
|
||||
* <li><code>partition-management-list-partitions</code></li>
|
||||
* </ul>
|
||||
*/
|
||||
public class PartitionManagementProvider {
|
||||
|
@ -142,6 +149,20 @@ public class PartitionManagementProvider {
|
|||
return retVal;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add Partition:
|
||||
* <code>
|
||||
* $partition-management-list-partitions
|
||||
* </code>
|
||||
*/
|
||||
@Operation(name = ProviderConstants.PARTITION_MANAGEMENT_LIST_PARTITIONS, idempotent = true)
|
||||
public IBaseParameters addPartitions(
|
||||
@ResourceParam IBaseParameters theRequest
|
||||
) {
|
||||
List<PartitionEntity> output = myPartitionLookupSvc.listPartitions();
|
||||
return prepareOutputList(output);
|
||||
}
|
||||
|
||||
private IBaseParameters prepareOutput(PartitionEntity theOutput) {
|
||||
IBaseParameters retVal = ParametersUtil.newInstance(myCtx);
|
||||
ParametersUtil.addParameterToParametersInteger(myCtx, retVal, ProviderConstants.PARTITION_MANAGEMENT_PARTITION_ID, theOutput.getId());
|
||||
|
@ -152,6 +173,19 @@ public class PartitionManagementProvider {
|
|||
return retVal;
|
||||
}
|
||||
|
||||
private IBaseParameters prepareOutputList(List<PartitionEntity> theOutput) {
|
||||
IBaseParameters retVal = ParametersUtil.newInstance(myCtx);
|
||||
for (PartitionEntity partitionEntity : theOutput) {
|
||||
IBase resultPart = ParametersUtil.addParameterToParameters(myCtx, retVal, "partition");
|
||||
ParametersUtil.addPartInteger(myCtx, resultPart, ProviderConstants.PARTITION_MANAGEMENT_PARTITION_ID, partitionEntity.getId());
|
||||
ParametersUtil.addPartCode(myCtx, resultPart, ProviderConstants.PARTITION_MANAGEMENT_PARTITION_NAME, partitionEntity.getName());
|
||||
if (isNotBlank(partitionEntity.getDescription())) {
|
||||
ParametersUtil.addPartString(myCtx, resultPart, ProviderConstants.PARTITION_MANAGEMENT_PARTITION_DESC, partitionEntity.getDescription());
|
||||
}
|
||||
}
|
||||
return retVal;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
private PartitionEntity parseInput(@OperationParam(name = ProviderConstants.PARTITION_MANAGEMENT_PARTITION_ID, min = 1, max = 1, typeName = "integer") IPrimitiveType<Integer> thePartitionId, @OperationParam(name = ProviderConstants.PARTITION_MANAGEMENT_PARTITION_NAME, min = 1, max = 1, typeName = "code") IPrimitiveType<String> thePartitionName, @OperationParam(name = ProviderConstants.PARTITION_MANAGEMENT_PARTITION_DESC, min = 0, max = 1, typeName = "string") IPrimitiveType<String> thePartitionDescription) {
|
||||
PartitionEntity input = new PartitionEntity();
|
||||
|
|
|
@ -28,6 +28,13 @@ import org.springframework.test.context.junit.jupiter.SpringExtension;
|
|||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.hasSize;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
|
@ -233,6 +240,55 @@ public class PartitionManagementProviderTest {
|
|||
verify(myPartitionConfigSvc, times(0)).createPartition(any());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testListPartitions() {
|
||||
PartitionEntity partition1 = new PartitionEntity();
|
||||
partition1.setId(1);
|
||||
partition1.setName("PARTITION-1");
|
||||
partition1.setDescription("a description1");
|
||||
|
||||
PartitionEntity partition2 = new PartitionEntity();
|
||||
partition2.setId(2);
|
||||
partition2.setName("PARTITION-2");
|
||||
partition2.setDescription("a description2");
|
||||
|
||||
List<PartitionEntity> partitionList = new ArrayList<PartitionEntity>();
|
||||
partitionList.add(partition1);
|
||||
partitionList.add(partition2);
|
||||
when(myPartitionConfigSvc.listPartitions()).thenReturn(partitionList);
|
||||
|
||||
Parameters response = myClient
|
||||
.operation()
|
||||
.onServer()
|
||||
.named(ProviderConstants.PARTITION_MANAGEMENT_LIST_PARTITIONS)
|
||||
.withNoParameters(Parameters.class)
|
||||
.useHttpGet()
|
||||
.encodedXml()
|
||||
.execute();
|
||||
|
||||
ourLog.info("Response:\n{}", ourCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(response));
|
||||
verify(myPartitionConfigSvc, times(1)).listPartitions();
|
||||
verifyNoMoreInteractions(myPartitionConfigSvc);
|
||||
|
||||
List<Parameters.ParametersParameterComponent> list = getParametersByName(response, "partition");
|
||||
assertThat(list, hasSize(2));
|
||||
List<Parameters.ParametersParameterComponent> part = list.get(0).getPart();
|
||||
assertThat(part.get(0).getName(), is(ProviderConstants.PARTITION_MANAGEMENT_PARTITION_ID));
|
||||
assertEquals(1, ((IntegerType) part.get(0).getValue()).getValue().intValue());
|
||||
assertThat(part.get(1).getName(), is(ProviderConstants.PARTITION_MANAGEMENT_PARTITION_NAME));
|
||||
assertEquals("PARTITION-1", part.get(1).getValue().toString());
|
||||
assertThat(part.get(2).getName(), is(ProviderConstants.PARTITION_MANAGEMENT_PARTITION_DESC));
|
||||
assertEquals("a description1", part.get(2).getValue().toString());
|
||||
|
||||
part = list.get(1).getPart();
|
||||
assertThat(part.get(0).getName(), is(ProviderConstants.PARTITION_MANAGEMENT_PARTITION_ID));
|
||||
assertEquals(2, ((IntegerType) part.get(0).getValue()).getValue().intValue());
|
||||
assertThat(part.get(1).getName(), is(ProviderConstants.PARTITION_MANAGEMENT_PARTITION_NAME));
|
||||
assertEquals("PARTITION-2", part.get(1).getValue().toString());
|
||||
assertThat(part.get(2).getName(), is(ProviderConstants.PARTITION_MANAGEMENT_PARTITION_DESC));
|
||||
assertEquals("a description2", part.get(2).getValue().toString());
|
||||
}
|
||||
|
||||
@Configuration
|
||||
public static class MyConfig {
|
||||
|
||||
|
@ -253,4 +309,7 @@ public class PartitionManagementProviderTest {
|
|||
return t -> t.getArgument(0, PartitionEntity.class);
|
||||
}
|
||||
|
||||
private List<Parameters.ParametersParameterComponent> getParametersByName(Parameters theParams, String theName) {
|
||||
return theParams.getParameter().stream().filter(p -> p.getName().equals(theName)).collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,7 +8,10 @@ import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException;
|
|||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
|
||||
public class PartitionSettingsSvcImplTest extends BaseJpaR4Test {
|
||||
|
@ -166,4 +169,25 @@ public class PartitionSettingsSvcImplTest extends BaseJpaR4Test {
|
|||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testListPartitions() {
|
||||
PartitionEntity partition1 = new PartitionEntity();
|
||||
partition1.setId(1);
|
||||
partition1.setName("PARTITION-1");
|
||||
partition1.setDescription("a description1");
|
||||
|
||||
PartitionEntity partition2 = new PartitionEntity();
|
||||
partition2.setId(2);
|
||||
partition2.setName("PARTITION-2");
|
||||
partition2.setDescription("a description2");
|
||||
|
||||
myPartitionConfigSvc.createPartition(partition1);
|
||||
myPartitionConfigSvc.createPartition(partition2);
|
||||
|
||||
List<PartitionEntity> actual = myPartitionConfigSvc.listPartitions();
|
||||
|
||||
assertEquals(2, actual.size());
|
||||
assertTrue(actual.stream().anyMatch(item -> "PARTITION-1".equals(item.getName())));
|
||||
assertTrue(actual.stream().anyMatch(item -> "PARTITION-2".equals(item.getName())));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -44,6 +44,11 @@ public class ProviderConstants {
|
|||
*/
|
||||
public static final String PARTITION_MANAGEMENT_READ_PARTITION = "$partition-management-read-partition";
|
||||
|
||||
/**
|
||||
* Operation name: list partitions
|
||||
*/
|
||||
public static final String PARTITION_MANAGEMENT_LIST_PARTITIONS = "$partition-management-list-partitions";
|
||||
|
||||
public static final String PARTITION_MANAGEMENT_PARTITION_ID = "id";
|
||||
public static final String PARTITION_MANAGEMENT_PARTITION_NAME = "name";
|
||||
public static final String PARTITION_MANAGEMENT_PARTITION_DESC = "description";
|
||||
|
|
Loading…
Reference in New Issue