Skip to content

Commit

Permalink
build: added nullaway (#177)
Browse files Browse the repository at this point in the history
* build: added nullaway

* applied nullaway recommendations

* setup coverage analysis for sonarcloud integration
  • Loading branch information
chgl authored Nov 5, 2024
1 parent d16d60f commit 14949f0
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 14 deletions.
19 changes: 18 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ plugins {
id 'java'
id 'jacoco'
id 'com.diffplug.spotless' version "6.25.0"
id "net.ltgt.errorprone" version "4.1.0"
id "net.ltgt.errorprone" version "4.1.0"
id "org.sonarqube" version "5.1.0.4882"
}

group = "org.miracum.etl"
Expand Down Expand Up @@ -53,6 +54,7 @@ dependencies {
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'

errorprone("com.google.errorprone:error_prone_core:2.34.0")
errorprone("com.uber.nullaway:nullaway:0.12.0")
}

dependencyManagement {
Expand Down Expand Up @@ -84,3 +86,18 @@ spotless {
googleJavaFormat()
}
}

import net.ltgt.gradle.errorprone.CheckSeverity

tasks.withType(JavaCompile).configureEach {
options.errorprone {
check("NullAway", CheckSeverity.ERROR)
option("NullAway:AnnotatedPackages", "org.miracum")
}
// Include to disable NullAway on test code
if (name.toLowerCase().contains("test")) {
options.errorprone {
disable("NullAway")
}
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
package org.miracum.etl.fhirgateway;

import jakarta.annotation.Nullable;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;

@Configuration
@ConfigurationProperties(prefix = "fhir.systems")
public class FhirSystemsConfig {

private String loinc;
@Nullable private String loinc;

@Nullable
public String getLoinc() {
return loinc;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,35 @@
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import jakarta.annotation.Nullable;
import java.math.BigDecimal;

@JsonInclude(JsonInclude.Include.NON_NULL)
public class LoincConversion {

@JsonProperty("loinc")
@Nullable
private String loinc;

@JsonProperty("unit")
@Nullable
private String unit;

@JsonProperty("value")
@JsonFormat(shape = JsonFormat.Shape.STRING)
@Nullable
private BigDecimal value;

@JsonProperty("id")
@Nullable
private String id;

@JsonProperty("display")
@Nullable
private String display;

@JsonProperty("loinc")
@Nullable
public String getLoinc() {
return loinc;
}
Expand All @@ -36,6 +43,7 @@ public LoincConversion setLoinc(String loinc) {
}

@JsonProperty("unit")
@Nullable
public String getUnit() {
return unit;
}
Expand All @@ -47,6 +55,7 @@ public LoincConversion setUnit(String unit) {
}

@JsonProperty("value")
@Nullable
public BigDecimal getValue() {
return value;
}
Expand All @@ -58,6 +67,7 @@ public LoincConversion setValue(BigDecimal value) {
}

@JsonProperty("id")
@Nullable
public String getId() {
return id;
}
Expand All @@ -69,6 +79,7 @@ public LoincConversion setId(String id) {
}

@JsonProperty("display")
@Nullable
public String getDisplay() {
return display;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import static net.logstash.logback.argument.StructuredArguments.kv;

import jakarta.annotation.Nullable;
import java.util.UUID;
import org.hl7.fhir.r4.model.Bundle;
import org.hl7.fhir.r4.model.Bundle.BundleType;
Expand All @@ -24,6 +25,7 @@ protected BaseKafkaProcessor(ResourcePipeline pipeline) {
this.pipeline = pipeline;
}

@Nullable
public Bundle process(Message<Resource> message) {

if (message == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import static net.logstash.logback.argument.StructuredArguments.kv;

import jakarta.annotation.Nullable;
import java.util.Objects;
import java.util.Optional;
import java.util.function.Function;
Expand All @@ -24,7 +25,7 @@ public class KafkaProcessor extends BaseKafkaProcessor {
private final String generateTopicMatchExpression;
private final String generateTopicReplacement;
private final KafkaProcessorConfig config;
private HmacUtils hmac;
@Nullable private HmacUtils hmac;

public KafkaProcessor(ResourcePipeline pipeline, KafkaProcessorConfig config) {
super(pipeline);
Expand All @@ -46,7 +47,7 @@ Function<Message<Resource>, Message<Bundle>> process() {

var messageKey = message.getHeaders().getOrDefault(KafkaHeaders.RECEIVED_KEY, "").toString();

if (config.cryptoHashMessageKeys().enabled()) {
if (config.cryptoHashMessageKeys().enabled() && hmac != null) {
messageKey = hmac.hmacHex(messageKey);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import java.time.Duration;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import org.hl7.fhir.r4.model.Coding;
import org.hl7.fhir.r4.model.Observation;
import org.hl7.fhir.r4.model.Quantity;
Expand Down Expand Up @@ -81,9 +82,9 @@ private Observation harmonizeObservation(final Observation originalObservation)
// harmonize the observation's main code/value
var result = getHarmonizedQuantity(originalObservation.getValueQuantity(), originalCode);

if (result != null) {
harmonized.setValue(result.getFirst());
Pair<Quantity, LoincConversion> finalResult = result;
if (result.isPresent()) {
harmonized.setValue(result.get().getFirst());
Pair<Quantity, LoincConversion> finalResult = result.get();
harmonized.getCode().getCoding().stream()
.filter(obs -> obs.getSystem().equals(fhirSystems.getLoinc()))
.findFirst()
Expand All @@ -105,8 +106,8 @@ private Observation harmonizeObservation(final Observation originalObservation)

result = getHarmonizedQuantity(rangeLow, originalCode);

if (result != null) {
rangeComponent.setLow(result.getFirst());
if (result.isPresent()) {
rangeComponent.setLow(result.get().getFirst());
}
}

Expand All @@ -115,8 +116,8 @@ private Observation harmonizeObservation(final Observation originalObservation)

result = getHarmonizedQuantity(rangeHigh, originalCode);

if (result != null) {
rangeComponent.setHigh(result.getFirst());
if (result.isPresent()) {
rangeComponent.setHigh(result.get().getFirst());
}
}
}
Expand Down Expand Up @@ -144,7 +145,8 @@ private Observation harmonizeObservation(final Observation originalObservation)
return harmonized;
}

private Pair<Quantity, LoincConversion> getHarmonizedQuantity(Quantity input, String loincCode) {
private Optional<Pair<Quantity, LoincConversion>> getHarmonizedQuantity(
Quantity input, String loincCode) {

var requestUrl =
UriComponentsBuilder.fromUri(loincConverterBaseUri)
Expand Down Expand Up @@ -176,9 +178,9 @@ private Pair<Quantity, LoincConversion> getHarmonizedQuantity(Quantity input, St
quantity.setUnit(response.getUnit());
quantity.setCode(response.getUnit());
quantity.setSystem(input.getSystem());
return Pair.of(quantity, response);
return Optional.of(Pair.of(quantity, response));
}

return null;
return Optional.empty();
}
}

0 comments on commit 14949f0

Please sign in to comment.