Skip to content

Commit

Permalink
Apply spotless
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris0296 committed Oct 16, 2024
1 parent 774921a commit 1d9d684
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
package org.opencds.cqf.fhir.utility.visitor;

import ca.uhn.fhir.rest.server.exceptions.PreconditionFailedException;
import java.util.ArrayList;
import org.hl7.fhir.instance.model.api.IBase;
import org.hl7.fhir.instance.model.api.IBaseParameters;
import org.hl7.fhir.instance.model.api.IDomainResource;
import org.opencds.cqf.fhir.api.Repository;
import org.opencds.cqf.fhir.utility.BundleHelper;
import org.opencds.cqf.fhir.utility.PackageHelper;
import org.opencds.cqf.fhir.utility.adapter.KnowledgeArtifactAdapter;
import java.util.ArrayList;

public class DeleteVisitor extends AbstractKnowledgeArtifactVisitor {

public static final String RETIRED_STATUS = "retired";

@Override
public IBase visit(KnowledgeArtifactAdapter rootAdapter, Repository repository,
IBaseParameters operationParams) {
public IBase visit(KnowledgeArtifactAdapter rootAdapter, Repository repository, IBaseParameters operationParams) {
if (!rootAdapter.getStatus().equals(RETIRED_STATUS)) {
throw new PreconditionFailedException("Cannot delete an artifact that is not in retired status");
}
Expand All @@ -29,7 +28,7 @@ public IBase visit(KnowledgeArtifactAdapter rootAdapter, Repository repository,

var resourcesToUpdate = getComponents(rootAdapter, repository, resToUpdate);

for (var res: resourcesToUpdate) {
for (var res : resourcesToUpdate) {
var entry = PackageHelper.deleteEntry(res);
BundleHelper.addEntry(transactionBundle, entry);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package org.opencds.cqf.fhir.utility.visitor.r4;

import static org.junit.jupiter.api.Assertions.fail;
import static org.opencds.cqf.fhir.utility.r4.Parameters.parameters;
import static org.opencds.cqf.fhir.utility.r4.Parameters.part;

import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.parser.IParser;
import ca.uhn.fhir.rest.server.exceptions.PreconditionFailedException;
Expand All @@ -17,10 +21,6 @@
import org.opencds.cqf.fhir.utility.visitor.DeleteVisitor;
import org.opencds.cqf.fhir.utility.visitor.IKnowledgeArtifactVisitor;

import static org.junit.jupiter.api.Assertions.fail;
import static org.opencds.cqf.fhir.utility.r4.Parameters.parameters;
import static org.opencds.cqf.fhir.utility.r4.Parameters.part;

public class DeleteVisitorTests {

private final FhirContext fhirContext = FhirContext.forR4Cached();
Expand All @@ -30,15 +30,15 @@ public class DeleteVisitorTests {
@BeforeEach
void setup() {
SearchParameter sp = (SearchParameter) jsonParser.parseResource(
ReleaseVisitorTests.class.getResourceAsStream("SearchParameter-artifactAssessment.json"));
ReleaseVisitorTests.class.getResourceAsStream("SearchParameter-artifactAssessment.json"));
repo = new InMemoryFhirRepository(fhirContext);
repo.update(sp);
}

@Test
void library_delete_test() {
Bundle bundle = (Bundle)
jsonParser.parseResource(DeleteVisitorTests.class.getResourceAsStream("Bundle-delete.json"));
Bundle bundle =
(Bundle) jsonParser.parseResource(DeleteVisitorTests.class.getResourceAsStream("Bundle-delete.json"));
Bundle tsBundle = repo.transaction(bundle);
// Resource is uploaded using POST - need to get id like this
String id = tsBundle.getEntry().get(0).getResponse().getLocation();
Expand All @@ -58,10 +58,11 @@ void library_delete_test() {
void library_delete_active_test() {
try {
Bundle bundle = (Bundle)
jsonParser.parseResource(DeleteVisitorTests.class.getResourceAsStream("Bundle-ersd-example.json"));
jsonParser.parseResource(DeleteVisitorTests.class.getResourceAsStream("Bundle-ersd-example.json"));
repo.transaction(bundle);
String version = "1.0.0";
Library library = repo.read(Library.class, new IdType("Library/SpecificationLibrary")).copy();
Library library = repo.read(Library.class, new IdType("Library/SpecificationLibrary"))
.copy();
LibraryAdapter libraryAdapter = new AdapterFactory().createLibrary(library);
IKnowledgeArtifactVisitor deleteVisitor = new DeleteVisitor();
Parameters params = parameters(part("version", version));
Expand All @@ -77,7 +78,7 @@ void library_delete_active_test() {
void library_delete_draft_test() {
try {
Bundle bundle = (Bundle)
jsonParser.parseResource(DeleteVisitorTests.class.getResourceAsStream("Bundle-withdraw.json"));
jsonParser.parseResource(DeleteVisitorTests.class.getResourceAsStream("Bundle-withdraw.json"));
Bundle tsBundle = repo.transaction(bundle);
String id = tsBundle.getEntry().get(0).getResponse().getLocation();
String version = "1.1.0-draft";
Expand All @@ -92,5 +93,4 @@ void library_delete_draft_test() {
assert (e.getMessage().contains("Cannot delete an artifact that is not in retired status"));
}
}

}

0 comments on commit 1d9d684

Please sign in to comment.