Skip to content

Commit

Permalink
Issue #2503 - Check resource type on $reindex operation
Browse files Browse the repository at this point in the history
Signed-off-by: Troy Biesterfeld <tbieste@us.ibm.com>
  • Loading branch information
tbieste committed Jun 21, 2021
1 parent be5af2b commit 4b2416e
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,31 @@ public void testReindexWithType() {
assertEquals(r.getStatus(), Status.OK.getStatusCode());
}

@Test(groups = { "reindex" })
public void testReindexWithInvalidType() {
List<Parameter> parameters = new ArrayList<>();
parameters.add(Parameter.builder()
.name(string("resourceCount"))
.value(of(5))
.build());

Parameters.Builder builder = Parameters.builder();
builder.id(UUID.randomUUID().toString());
builder.parameter(parameters);
Parameters ps = builder.build();

Entity<Parameters> entity = Entity.entity(ps, FHIRMediaType.APPLICATION_FHIR_JSON);

Response r = getWebTarget()
.path("/DomainResource/$reindex")
.request(FHIRMediaType.APPLICATION_FHIR_JSON)
.header("X-FHIR-TENANT-ID", "default")
.header("X-FHIR-DSID", "default")
.post(entity, Response.class);

assertEquals(r.getStatus(), Status.BAD_REQUEST.getStatusCode());
}

@Test(groups = { "reindex" })
public void testReindexWithType_BadResourceLogicalIdParameter() {
List<Parameter> parameters = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,13 @@ protected Parameters doInvoke(FHIROperationContext operationContext, Class<? ext
int resourceCount = 10;
String resourceLogicalId = null;

boolean hasSpecificResourceType = false;
String specificResourceType = null;
if (resourceType != null) {
resourceLogicalId = resourceType.getSimpleName();
specificResourceType = resourceType.getSimpleName();
resourceLogicalId = specificResourceType;
if (logicalId != null) {
resourceLogicalId += "/" + logicalId;
}
hasSpecificResourceType = true;
}

if (parameters != null) {
Expand Down Expand Up @@ -116,23 +116,25 @@ protected Parameters doInvoke(FHIROperationContext operationContext, Class<? ext
resourceCount = val;
}
} else if (PARAM_RESOURCE_LOGICAL_ID.equals(parameter.getName().getValue())) {
if (hasSpecificResourceType) {
if (specificResourceType != null) {
throw FHIROperationUtil.buildExceptionWithIssue("resourceLogicalId already specified using call to Operation on Type or Instance", IssueType.INVALID);
}
// reindex a specific resource or resourceType
resourceLogicalId = parameter.getValue().as(com.ibm.fhir.model.type.String.class).getValue();
String rt = resourceLogicalId;
specificResourceType = resourceLogicalId;
if (resourceLogicalId.contains("/")) {
String[] parts = resourceLogicalId.split("/");
rt = parts[0];
}
if (!ModelSupport.isConcreteResourceType(rt)) {
throw FHIROperationUtil.buildExceptionWithIssue("ResourceType is not valid", IssueType.INVALID);
specificResourceType = parts[0];
}
}
}
}

// Check resource type
if (specificResourceType != null && !ModelSupport.isConcreteResourceType(specificResourceType)) {
throw FHIROperationUtil.buildExceptionWithIssue("Resource type '" + specificResourceType + "' is not valid", IssueType.INVALID);
}

// Delegate the heavy lifting to the helper
OperationOutcome.Builder result = OperationOutcome.builder();
int totalProcessed = 0;
Expand Down

0 comments on commit 4b2416e

Please sign in to comment.