Skip to content

Commit

Permalink
Refactor internal metadata step to use generics instead of empty inte…
Browse files Browse the repository at this point in the history
…rface (#681)

* Removed MetaDataStep interface and refactored code to use generics instead

* EtorMetaDataStep is not implementing an interface any more
  • Loading branch information
basiliskus authored Nov 27, 2023
1 parent 55f0e7d commit 63786e9
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 19 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package gov.hhs.cdc.trustedintermediary.etor.metadata;

import gov.hhs.cdc.trustedintermediary.metadata.MetaDataStep;

/** Etor specific steps from the general shared metadata steps */
public enum EtorMetaDataStep implements MetaDataStep {
public enum EtorMetaDataStep {
RECEIVED_FROM_REPORT_STREAM,

ORDER_CONVERTED_TO_OML,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package gov.hhs.cdc.trustedintermediary.external.inmemory;

import gov.hhs.cdc.trustedintermediary.metadata.MetaDataEntry;
import gov.hhs.cdc.trustedintermediary.metadata.MetaDataStep;
import gov.hhs.cdc.trustedintermediary.wrappers.Logger;
import gov.hhs.cdc.trustedintermediary.wrappers.MetricMetaData;
import java.util.Map;
Expand All @@ -23,8 +22,8 @@ public static LoggingMetricMetaData getInstance() {
private LoggingMetricMetaData() {}

@Override
public void put(String bundleId, MetaDataStep step) {
MetaDataEntry entry = extractMetricsFromBundle(bundleId, step);
public <T> void put(String bundleId, T step) {
MetaDataEntry<T> entry = extractMetricsFromBundle(bundleId, step);
var metadataMap =
Map.of(
"BundleId",
Expand All @@ -37,7 +36,7 @@ public void put(String bundleId, MetaDataStep step) {
logger.logMap("MetaData Event Occurred:", metadataMap);
}

private MetaDataEntry extractMetricsFromBundle(String bundleId, MetaDataStep step) {
return new MetaDataEntry(bundleId, step);
private <T> MetaDataEntry<T> extractMetricsFromBundle(String bundleId, T step) {
return new MetaDataEntry<>(bundleId, step);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
import java.time.Instant;

/** An instance of a metadata event to be used for internal troubleshooting of messages */
public record MetaDataEntry(String bundleId, MetaDataStep entryStep, Instant entryTime) {
public record MetaDataEntry<T>(String bundleId, T entryStep, Instant entryTime) {

public MetaDataEntry(String bundleId, MetaDataStep entryStep) {
public MetaDataEntry(String bundleId, T entryStep) {
this(bundleId, entryStep, Instant.now());
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package gov.hhs.cdc.trustedintermediary.wrappers;

import gov.hhs.cdc.trustedintermediary.metadata.MetaDataStep;

/** Interface to provide a blueprint for working with metadate */
public interface MetricMetaData {

void put(String value, MetaDataStep step);
<T> void put(String value, T step);
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package gov.hhs.cdc.trustedintermediary.external.inmemory

import gov.hhs.cdc.trustedintermediary.context.TestApplicationContext
import gov.hhs.cdc.trustedintermediary.metadata.MetaDataStep
import gov.hhs.cdc.trustedintermediary.wrappers.Logger
import gov.hhs.cdc.trustedintermediary.wrappers.MetricMetaData
import spock.lang.Specification
Expand All @@ -22,7 +21,7 @@ class LoggingMetricMetaDataTest extends Specification {
TestApplicationContext.injectRegisteredImplementations()

when:
LoggingMetricMetaData.getInstance().put("Key", _ as MetaDataStep)
LoggingMetricMetaData.getInstance().put("Key", _)

then:
1 * logger.logMap(_ as String, _ as Map) >> { String message, Map keyValue ->
Expand Down

0 comments on commit 63786e9

Please sign in to comment.