From 03f7e1e757b4666a578ce224554961d54cef3273 Mon Sep 17 00:00:00 2001 From: Madhuram Jajoo Date: Sat, 8 Jun 2024 17:30:24 +0530 Subject: [PATCH] Fixing errors --- buildSrc/src/main/kotlin/LicenseeConfig.kt | 16 ++- .../IGInputStreamStructureRepository.kt | 98 +++++++++---------- .../fhir/workflow/testing/PlanDefinition.kt | 4 - .../testing/TestRepositoryFactory.java | 12 +-- 4 files changed, 58 insertions(+), 72 deletions(-) diff --git a/buildSrc/src/main/kotlin/LicenseeConfig.kt b/buildSrc/src/main/kotlin/LicenseeConfig.kt index 0beaf453c8..bbf5b3739c 100644 --- a/buildSrc/src/main/kotlin/LicenseeConfig.kt +++ b/buildSrc/src/main/kotlin/LicenseeConfig.kt @@ -25,10 +25,12 @@ fun Project.configureLicensee() { allow("BSD-2-Clause") allow("BSD-3-Clause") allow("MIT") + allow("EPL-1.0") + allow("LGPL-2.1-only") ignoreDependencies("com.ibm.icu", "icu4j") { because( - "ICU uses an ICU license that was mispaced and cannot be loaded by this tool right now", + "ICU uses an ICU license that was misplaced and cannot be loaded by this tool right now", ) } @@ -72,17 +74,23 @@ fun Project.configureLicensee() { } // Jakarta XML Binding API - allowDependency("jakarta.xml.bind", "jakarta.xml.bind-api", "2.3.3") { + allowDependency("jakarta.xml.bind", "jakarta.xml.bind-api", "4.0.1") { because("BSD 3-clause.") } // Jakarta Activation API 2.1 Specification - allowDependency("jakarta.activation", "jakarta.activation-api", "1.2.2") { + allowDependency("jakarta.activation", "jakarta.activation-api", "2.1.2") { because( "Licensed under Eclipse Distribution License 1.0. http://www.eclipse.org/org/documents/edl-v10.php", ) } + allowDependency("jakarta.annotation", "jakarta.annotation-api", "2.1.1") { + because( + "Licensed under Eclipse EPL-2.0 license http://www.eclipse.org/legal/epl-2.0'", + ) + } + // Javax Annotation API allowDependency("javax.annotation", "javax.annotation-api", "1.3.2") { because("Dual-licensed under CDDL 1.1 and GPL v2 with classpath exception.") @@ -108,7 +116,7 @@ fun Project.configureLicensee() { because("BSD 3-clause. http://www.antlr.org/license.html") } // ANTLR 4 - allowDependency("org.antlr", "antlr4-runtime", "4.10.1") { + allowDependency("org.antlr", "antlr4-runtime", "4.13.1") { because("BSD 3-clause. http://www.antlr.org/license.html") } diff --git a/workflow-testing/src/main/java/com/google/android/fhir/workflow/testing/IGInputStreamStructureRepository.kt b/workflow-testing/src/main/java/com/google/android/fhir/workflow/testing/IGInputStreamStructureRepository.kt index dfd2a924ae..0a127e6372 100644 --- a/workflow-testing/src/main/java/com/google/android/fhir/workflow/testing/IGInputStreamStructureRepository.kt +++ b/workflow-testing/src/main/java/com/google/android/fhir/workflow/testing/IGInputStreamStructureRepository.kt @@ -1,5 +1,5 @@ /* - * Copyright 2023 Google LLC + * Copyright 2023-2024 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,15 +20,14 @@ import ca.uhn.fhir.context.FhirContext import ca.uhn.fhir.context.FhirVersionEnum import ca.uhn.fhir.model.api.IQueryParameterType import ca.uhn.fhir.parser.IParser -import ca.uhn.fhir.rest.api.EncodingEnum import ca.uhn.fhir.rest.api.MethodOutcome import ca.uhn.fhir.rest.param.TokenParam import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException import ca.uhn.fhir.util.BundleBuilder import com.google.common.collect.ImmutableMap +import com.google.common.collect.Sets import java.io.File import java.io.FileNotFoundException -import java.util.Locale import java.util.Objects import java.util.function.Consumer import org.hl7.fhir.instance.model.api.IBaseBundle @@ -40,9 +39,7 @@ import org.opencds.cqf.fhir.api.Repository import org.opencds.cqf.fhir.utility.Ids import org.opencds.cqf.fhir.utility.dstu3.AttachmentUtil import org.opencds.cqf.fhir.utility.matcher.ResourceMatcher -import org.opencds.cqf.fhir.utility.repository.IGLayoutMode import org.opencds.cqf.fhir.utility.repository.Repositories -import org.opencds.cqf.fhir.utility.repository.ResourceCategory /** * This class implements the Repository interface on onto a directory structure that matches the @@ -51,11 +48,9 @@ import org.opencds.cqf.fhir.utility.repository.ResourceCategory class IGInputStreamStructureRepository( private val fhirContext: FhirContext, private val root: String? = null, - private val layoutMode: IGLayoutMode = IGLayoutMode.DIRECTORY, - private val encodingEnum: EncodingEnum = EncodingEnum.JSON, ) : Loadable(), Repository { private val resourceCache: MutableMap = HashMap() - private val parser: IParser = parserForEncoding(fhirContext, encodingEnum) + private val parser: IParser = fhirContext.newJsonParser() private val resourceMatcher: ResourceMatcher = Repositories.getResourceMatcher(fhirContext) fun clearCache() { @@ -71,13 +66,8 @@ class IGInputStreamStructureRepository( } protected fun fileNameForLayoutAndEncoding(resourceType: String, resourceId: String): String { - val name = resourceId + fileExtensions[encodingEnum] - return if (layoutMode === IGLayoutMode.DIRECTORY) { - // TODO: case sensitivity!! - resourceType.lowercase(Locale.getDefault()) + "/" + name - } else { - "$resourceType-$name" - } + val name = "$resourceId.json" + return "$resourceType-$name" } protected fun directoryForType(resourceType: Class): String { @@ -89,12 +79,7 @@ class IGInputStreamStructureRepository( } protected fun directoryForResource(resourceType: Class): String { - val directory = directoryForType(resourceType) - return if (layoutMode === IGLayoutMode.DIRECTORY) { - directory + "/" + resourceType.simpleName.lowercase(Locale.getDefault()) - } else { - directory - } + return directoryForType(resourceType) } protected fun readLocation( @@ -178,19 +163,13 @@ class IGInputStreamStructureRepository( val inputFiles = listFiles(location) for (file in inputFiles) { - if ( - layoutMode.equals(IGLayoutMode.DIRECTORY) || - (layoutMode.equals(IGLayoutMode.TYPE_PREFIX) && - file.startsWith(resourceClass.simpleName + "-")) - ) { - try { - val r = this.readLocation(resourceClass, "$location/$file") - if (r.fhirType() == resourceClass.simpleName) { - resources[r.idElement.toUnqualifiedVersionless()] = r - } - } catch (e: RuntimeException) { - e.printStackTrace() + try { + val r = this.readLocation(resourceClass, "$location/$file") + if (r.fhirType() == resourceClass.simpleName) { + resources[r.idElement.toUnqualifiedVersionless()] = r } + } catch (e: RuntimeException) { + e.printStackTrace() } } return resources @@ -282,7 +261,7 @@ class IGInputStreamStructureRepository( ): B { val builder = BundleBuilder(fhirContext) val resourceIdMap = readLocation(resourceType) - if (searchParameters == null || searchParameters.isEmpty()) { + if (searchParameters.isEmpty()) { resourceIdMap.values.forEach( Consumer { theResource: T -> builder.addCollectionEntry( @@ -442,30 +421,43 @@ class IGInputStreamStructureRepository( } companion object { + + enum class ResourceCategory { + DATA, + TERMINOLOGY, + CONTENT, + ; + + companion object { + private val TERMINOLOGY_RESOURCES: Set = + Sets.newHashSet(*arrayOf("ValueSet", "CodeSystem")) + private val CONTENT_RESOURCES: Set = + Sets.newHashSet( + *arrayOf( + "Library", + "Questionnaire", + "Measure", + "PlanDefinition", + "StructureDefinition", + "ActivityDefinition", + ), + ) + + fun forType(resourceType: String): ResourceCategory { + return if (TERMINOLOGY_RESOURCES.contains(resourceType)) { + TERMINOLOGY + } else { + if (CONTENT_RESOURCES.contains(resourceType)) CONTENT else DATA + } + } + } + } + private val categoryDirectories: Map = ImmutableMap.Builder() .put(ResourceCategory.CONTENT, "resources") .put(ResourceCategory.DATA, "tests") .put(ResourceCategory.TERMINOLOGY, "vocabulary") .build() - private val fileExtensions: Map = - ImmutableMap.Builder() - .put(EncodingEnum.JSON, ".json") - .put(EncodingEnum.XML, ".xml") - .put(EncodingEnum.RDF, ".rdf") - .build() - - private fun parserForEncoding( - fhirContext: FhirContext, - encodingEnum: EncodingEnum?, - ): IParser { - return when (encodingEnum) { - EncodingEnum.JSON -> fhirContext.newJsonParser() - EncodingEnum.XML -> fhirContext.newXmlParser() - EncodingEnum.RDF -> fhirContext.newRDFParser() - EncodingEnum.NDJSON -> throw IllegalArgumentException("NDJSON is not supported") - else -> throw IllegalArgumentException("NDJSON is not supported") - } - } } } diff --git a/workflow-testing/src/main/java/com/google/android/fhir/workflow/testing/PlanDefinition.kt b/workflow-testing/src/main/java/com/google/android/fhir/workflow/testing/PlanDefinition.kt index 1dedf83a33..2385c57c4f 100644 --- a/workflow-testing/src/main/java/com/google/android/fhir/workflow/testing/PlanDefinition.kt +++ b/workflow-testing/src/main/java/com/google/android/fhir/workflow/testing/PlanDefinition.kt @@ -18,7 +18,6 @@ package com.google.android.fhir.workflow.testing import ca.uhn.fhir.context.FhirContext import ca.uhn.fhir.context.FhirVersionEnum -import ca.uhn.fhir.rest.api.EncodingEnum import java.io.IOException import org.hl7.fhir.instance.model.api.IBaseResource import org.hl7.fhir.r4.model.Bundle @@ -41,7 +40,6 @@ import org.opencds.cqf.fhir.cr.plandefinition.PlanDefinitionProcessor import org.opencds.cqf.fhir.utility.monad.Eithers import org.opencds.cqf.fhir.utility.repository.InMemoryFhirRepository import org.opencds.cqf.fhir.utility.repository.Repositories -import org.opencds.cqf.fhir.utility.repository.ig.IgConventions import org.skyscreamer.jsonassert.JSONAssert object PlanDefinition : Loadable() { @@ -152,8 +150,6 @@ object PlanDefinition : Loadable() { IGInputStreamStructureRepository( fhirContext, repositoryPath ?: ".", - IgConventions.FLAT, // ===>>> Not sure is this is right. - EncodingEnum.JSON, ) if (dataRepository == null && contentRepository == null && terminologyRepository == null) { return local diff --git a/workflow-testing/src/main/java/com/google/android/fhir/workflow/testing/TestRepositoryFactory.java b/workflow-testing/src/main/java/com/google/android/fhir/workflow/testing/TestRepositoryFactory.java index b14ff3ff13..d1e6b8809d 100644 --- a/workflow-testing/src/main/java/com/google/android/fhir/workflow/testing/TestRepositoryFactory.java +++ b/workflow-testing/src/main/java/com/google/android/fhir/workflow/testing/TestRepositoryFactory.java @@ -1,11 +1,8 @@ package com.google.android.fhir.workflow.testing; import org.opencds.cqf.fhir.api.Repository; -import org.opencds.cqf.fhir.utility.repository.IGFileStructureRepository; -import org.opencds.cqf.fhir.utility.repository.IGLayoutMode; import ca.uhn.fhir.context.FhirContext; -import ca.uhn.fhir.rest.api.EncodingEnum; public class TestRepositoryFactory { private TestRepositoryFactory() { @@ -13,16 +10,9 @@ private TestRepositoryFactory() { } public static Repository createRepository(FhirContext fhirContext, String path) { - return createRepository(fhirContext, path, IGLayoutMode.TYPE_PREFIX); - } - - public static Repository createRepository( - FhirContext fhirContext, String path, IGLayoutMode layoutMode) { return new IGInputStreamStructureRepository( fhirContext, - path, - layoutMode, - EncodingEnum.JSON + path ); } } \ No newline at end of file