Skip to content

Commit

Permalink
Fixing errors
Browse files Browse the repository at this point in the history
  • Loading branch information
MJ1998 committed Jun 8, 2024
1 parent 1b8fc18 commit 03f7e1e
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 72 deletions.
16 changes: 12 additions & 4 deletions buildSrc/src/main/kotlin/LicenseeConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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",
)
}

Expand Down Expand Up @@ -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.")
Expand All @@ -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")
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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<String, IBaseResource> = HashMap()
private val parser: IParser = parserForEncoding(fhirContext, encodingEnum)
private val parser: IParser = fhirContext.newJsonParser()
private val resourceMatcher: ResourceMatcher = Repositories.getResourceMatcher(fhirContext)

fun clearCache() {
Expand All @@ -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 <T : IBaseResource?> directoryForType(resourceType: Class<T>): String {
Expand All @@ -89,12 +79,7 @@ class IGInputStreamStructureRepository(
}

protected fun <T : IBaseResource?> directoryForResource(resourceType: Class<T>): String {
val directory = directoryForType(resourceType)
return if (layoutMode === IGLayoutMode.DIRECTORY) {
directory + "/" + resourceType.simpleName.lowercase(Locale.getDefault())
} else {
directory
}
return directoryForType(resourceType)
}

protected fun <T : IBaseResource, I : IIdType> readLocation(
Expand Down Expand Up @@ -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<T, IIdType>(resourceClass, "$location/$file")
if (r.fhirType() == resourceClass.simpleName) {
resources[r.idElement.toUnqualifiedVersionless()] = r
}
} catch (e: RuntimeException) {
e.printStackTrace()
try {
val r = this.readLocation<T, IIdType>(resourceClass, "$location/$file")
if (r.fhirType() == resourceClass.simpleName) {
resources[r.idElement.toUnqualifiedVersionless()] = r
}
} catch (e: RuntimeException) {
e.printStackTrace()
}
}
return resources
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -442,30 +421,43 @@ class IGInputStreamStructureRepository(
}

companion object {

enum class ResourceCategory {
DATA,
TERMINOLOGY,
CONTENT,
;

companion object {
private val TERMINOLOGY_RESOURCES: Set<String> =
Sets.newHashSet(*arrayOf("ValueSet", "CodeSystem"))
private val CONTENT_RESOURCES: Set<String> =
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<ResourceCategory, String> =
ImmutableMap.Builder<ResourceCategory, String>()
.put(ResourceCategory.CONTENT, "resources")
.put(ResourceCategory.DATA, "tests")
.put(ResourceCategory.TERMINOLOGY, "vocabulary")
.build()
private val fileExtensions: Map<EncodingEnum?, String> =
ImmutableMap.Builder<EncodingEnum?, String>()
.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")
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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() {
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,28 +1,18 @@
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() {
// intentionally empty
}

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

0 comments on commit 03f7e1e

Please sign in to comment.