[3020] add $partition-management-lists-partitions

This commit is contained in:
katie_smilecdr 2021-09-23 16:08:56 -04:00
parent 2489702ab9
commit 8bd14ae024
5 changed files with 78 additions and 0 deletions

View File

@ -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();
}

View File

@ -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,14 @@ public class PartitionLookupSvcImpl implements IPartitionLookupSvc {
clearCaches();
}
@Override
@Transactional
public List<PartitionEntity> listPartitions() {
List<PartitionEntity> allPartitions = myPartitionDao.findAll();
clearCaches();
return allPartitions;
}
private void validatePartitionNameDoesntAlreadyExist(String theName) {
if (myPartitionDao.findForName(theName).isPresent()) {
String msg = myFhirCtx.getLocalizer().getMessageSanitized(PartitionLookupSvcImpl.class, "cantCreateDuplicatePartitionName", theName);

View File

@ -33,6 +33,9 @@ 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 +46,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 +147,20 @@ public class PartitionManagementProvider {
return retVal;
}
/**
* Add Partition:
* <code>
* $partition-management-read-partition
* </code>
*/
@Operation(name = ProviderConstants.PARTITION_MANAGEMENT_LIST_PARTITIONS, idempotent = true)
public List<IBaseParameters> listPartitions(
@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 +171,14 @@ public class PartitionManagementProvider {
return retVal;
}
private List<IBaseParameters> prepareOutputList(List<PartitionEntity> theOutput) {
List<IBaseParameters> retVal = new ArrayList<IBaseParameters>();
for (PartitionEntity partitionEntity : theOutput) {
retVal.add(prepareOutput(partitionEntity));
}
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();

View File

@ -28,6 +28,8 @@ import org.springframework.test.context.junit.jupiter.SpringExtension;
import javax.annotation.Nonnull;
import java.util.List;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.fail;
import static org.mockito.ArgumentMatchers.any;
@ -233,6 +235,39 @@ 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");
when(myPartitionConfigSvc.getPartitionById(eq(1))).thenReturn(partition1);
PartitionEntity partition2 = new PartitionEntity();
partition1.setId(2);
partition1.setName("PARTITION-2");
partition1.setDescription("a description2");
when(myPartitionConfigSvc.getPartitionById(eq(2))).thenReturn(partition2);
List<Parameters> response = (List<Parameters>) myClient
.operation()
.onServer()
.named(ProviderConstants.PARTITION_MANAGEMENT_LIST_PARTITIONS)
.withNoParameters(Parameters.class)
.encodedXml()
.execute();
System.out.println(response);
// ourLog.info("Response:\n{}", ourCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(response.get(0)));
// verify(myPartitionConfigSvc, times(1)).getPartitionById(any());
// verifyNoMoreInteractions(myPartitionConfigSvc);
//
// assertEquals(1, ((IntegerType) response.get(0).getParameter(ProviderConstants.PARTITION_MANAGEMENT_PARTITION_ID)).getValue().intValue());
// assertEquals("PARTITION-1", ((StringType) response.get(0).getParameter(ProviderConstants.PARTITION_MANAGEMENT_PARTITION_NAME)).getValue());
// assertEquals("a description1", ((StringType) response.get(0).getParameter(ProviderConstants.PARTITION_MANAGEMENT_PARTITION_DESC)).getValue());
}
@Configuration
public static class MyConfig {

View File

@ -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";