diff --git a/src/main/kotlin/org/wfanet/measurement/reporting/postprocessing/README.md b/src/main/kotlin/org/wfanet/measurement/reporting/postprocessing/README.md new file mode 100644 index 00000000000..96b7438af82 --- /dev/null +++ b/src/main/kotlin/org/wfanet/measurement/reporting/postprocessing/README.md @@ -0,0 +1,9 @@ +# Report Post Processing Library + +## Maven Artifact + +This library is available as a Maven artifact from a GitHub Packages Maven +registry. See +[Installing a package](https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-apache-maven-registry#installing-a-package) +from the GitHub documentation. The primary artifact is +`org.wfanet.measurement.eventdataprovider:postprocessing-v2alpha`. diff --git a/src/main/kotlin/org/wfanet/measurement/reporting/postprocessing/v2alpha/BUILD.bazel b/src/main/kotlin/org/wfanet/measurement/reporting/postprocessing/v2alpha/BUILD.bazel new file mode 100644 index 00000000000..4498a075819 --- /dev/null +++ b/src/main/kotlin/org/wfanet/measurement/reporting/postprocessing/v2alpha/BUILD.bazel @@ -0,0 +1,21 @@ +load("@rules_jvm_external//:defs.bzl", "maven_export") +load("@wfa_common_jvm//build/maven:defs.bzl", "artifact_version") +load("@wfa_rules_kotlin_jvm//kotlin:defs.bzl", "kt_jvm_library") + +package(default_visibility = ["//visibility:public"]) + +MAVEN_COORDINATES = "org.wfanet.measurement.reporting:postprocessing-v2alpha:" + artifact_version() + +kt_jvm_library( + name = "postprocessing", + srcs = glob(["*.kt"]), + tags = ["maven_coordinates=" + MAVEN_COORDINATES], +) + +maven_export( + name = "postprocessing_maven", + lib_name = "postprocessing", + maven_coordinates = MAVEN_COORDINATES, + tags = ["no-javadocs"], + visibility = ["//visibility:private"], +) diff --git a/src/main/kotlin/org/wfanet/measurement/reporting/postprocessing/v2alpha/NoOpReportProcessor.kt b/src/main/kotlin/org/wfanet/measurement/reporting/postprocessing/v2alpha/NoOpReportProcessor.kt new file mode 100644 index 00000000000..ec9a7efe27a --- /dev/null +++ b/src/main/kotlin/org/wfanet/measurement/reporting/postprocessing/v2alpha/NoOpReportProcessor.kt @@ -0,0 +1,26 @@ +// Copyright 2024 The Cross-Media Measurement Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package org.wfanet.measurement.reporting.postprocessing.v2alpha + +/** + * A no-op implementation of [ReportProcessor] that takes a serialized [Report] in JSON format and + * returns the same [Report] without any modifications. + */ +class NoOpReportProcessor : ReportProcessor { + /** Returns the input [report] without any modifications. */ + override fun processReportJson(report: String): String { + return report + } +} diff --git a/src/main/kotlin/org/wfanet/measurement/reporting/postprocessing/v2alpha/ReportProcessor.kt b/src/main/kotlin/org/wfanet/measurement/reporting/postprocessing/v2alpha/ReportProcessor.kt new file mode 100644 index 00000000000..e66f9995685 --- /dev/null +++ b/src/main/kotlin/org/wfanet/measurement/reporting/postprocessing/v2alpha/ReportProcessor.kt @@ -0,0 +1,26 @@ +// Copyright 2024 The Cross-Media Measurement Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package org.wfanet.measurement.reporting.postprocessing.v2alpha + +/** Corrects the inconsistent measurements in a serialized [Report]. */ +interface ReportProcessor { + /** + * Processes a serialized [Report] and outputs a consistent one. + * + * @param report The serialized [Report] in JSON format. + * @return The corrected serialized [Report] in JSON format. + */ + fun processReportJson(report: String): String +} diff --git a/src/test/kotlin/org/wfanet/measurement/reporting/postprocessing/v2alpha/BUILD.bazel b/src/test/kotlin/org/wfanet/measurement/reporting/postprocessing/v2alpha/BUILD.bazel new file mode 100644 index 00000000000..31b7fbe0276 --- /dev/null +++ b/src/test/kotlin/org/wfanet/measurement/reporting/postprocessing/v2alpha/BUILD.bazel @@ -0,0 +1,16 @@ +load("@wfa_rules_kotlin_jvm//kotlin:defs.bzl", "kt_jvm_test") + +package(default_testonly = True) + +kt_jvm_test( + name = "no_op_report_processor_test", + srcs = ["NoOpReportProcessorTest.kt"], + test_class = "org.wfanet.measurement.reporting.postprocessing.v2alpha.NoOpReportProcessorTest", + deps = [ + "//src/main/kotlin/org/wfanet/measurement/reporting/postprocessing/v2alpha:postprocessing", + "@wfa_common_jvm//imports/java/com/google/common/truth", + "@wfa_common_jvm//imports/java/com/google/common/truth/extensions/proto", + "@wfa_common_jvm//imports/java/org/junit", + "@wfa_common_jvm//imports/kotlin/kotlin/test", + ], +) diff --git a/src/test/kotlin/org/wfanet/measurement/reporting/postprocessing/v2alpha/NoOpReportProcessorTest.kt b/src/test/kotlin/org/wfanet/measurement/reporting/postprocessing/v2alpha/NoOpReportProcessorTest.kt new file mode 100644 index 00000000000..17be41f32a4 --- /dev/null +++ b/src/test/kotlin/org/wfanet/measurement/reporting/postprocessing/v2alpha/NoOpReportProcessorTest.kt @@ -0,0 +1,46 @@ +// Copyright 2024 The Cross-Media Measurement Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package org.wfanet.measurement.reporting.postprocessing.v2alpha + +import com.google.common.truth.Truth.assertThat +import com.google.common.truth.extensions.proto.ProtoTruth.assertThat +import org.junit.Test +import org.junit.runner.RunWith +import org.junit.runners.JUnit4 + +@RunWith(JUnit4::class) +class NoOpReportProcessorTest { + @Test + fun `The default report processor successfully processes a report`() { + val reportProcessor = NoOpReportProcessor() + val processedReport = reportProcessor.processReportJson(SAMPLE_REPORT) + assertThat(processedReport).isEqualTo(SAMPLE_REPORT) + } + + companion object { + private val SAMPLE_REPORT = + """ + { + "name": "Sample report", + "reportingMetricEntries": [], + "state": "STATE_UNSPECIFIED", + "metricCalculationResults": [], + "reportSchedule": "", + "tags": {}, + "reportingInterval": {} + } + """ + } +}