diff --git a/src/main/kotlin/org/wfanet/measurement/reporting/service/api/v1alpha/EventGroupsService.kt b/src/main/kotlin/org/wfanet/measurement/reporting/service/api/v1alpha/EventGroupsService.kt index e180f567cb7..fda2f380710 100644 --- a/src/main/kotlin/org/wfanet/measurement/reporting/service/api/v1alpha/EventGroupsService.kt +++ b/src/main/kotlin/org/wfanet/measurement/reporting/service/api/v1alpha/EventGroupsService.kt @@ -164,16 +164,19 @@ class EventGroupsService( // TODO(projectnessie/cel-java#295): Remove when fixed. if (eventGroup.hasMetadata()) { val metadata: com.google.protobuf.Any = eventGroup.metadata.metadata - put( - METADATA_FIELD, + println("metadatametadatametadata $metadata") + println("typeRegistrytypeRegistrytypeRegistry $typeRegistry") + val dyn = DynamicMessage.parseFrom( typeRegistry.getDescriptorForTypeUrl(metadata.typeUrl), metadata.value, - ), - ) + ) + println("dyndyndyn : $dyn") + put(METADATA_FIELD, dyn) } } val result: Val = program.eval(variables).`val` + println("resultresultresult : $result") if (result is Err) { // For when the field in the filter doesn't exist in the event group. if (result.toString().contains("undeclared reference to")) { diff --git a/src/main/proto/wfa/measurement/api/v2alpha/event_group_metadata/testing/test_metadata_message.proto b/src/main/proto/wfa/measurement/api/v2alpha/event_group_metadata/testing/test_metadata_message.proto index 4b0ed525522..c6bde4bb256 100644 --- a/src/main/proto/wfa/measurement/api/v2alpha/event_group_metadata/testing/test_metadata_message.proto +++ b/src/main/proto/wfa/measurement/api/v2alpha/event_group_metadata/testing/test_metadata_message.proto @@ -12,13 +12,50 @@ // See the License for the specific language governing permissions and // limitations under the License. +// syntax = "proto3"; + +// package wfa.measurement.api.v2alpha.event_group_metadata.testing; + +// option java_package = +// "org.wfanet.measurement.api.v2alpha.event_group_metadata.testing"; option +// java_multiple_files = true; + +// message TestMetadataMessage { +// int32 publisher_id = 1; +// } + syntax = "proto3"; -package wfa.measurement.api.v2alpha.event_group_metadata.testing; +package wfa.measurement.api.v2alpha; -option java_package = "org.wfanet.measurement.api.v2alpha.event_group_metadata.testing"; option java_multiple_files = true; +option java_package = "org.wfanet.measurement.api.v2alpha"; message TestMetadataMessage { - int32 publisher_id = 1; + message Date { + int32 year = 1; + int32 month = 2; + int32 day = 3; + } + + message CampaignStartDate { + Date value = 1; + } + + message Brand { + string value = 1; + } + + message DisplayName { + string value = 1; + } + + message CampaignEndDate { + Date value = 1; + } + + CampaignStartDate campaign_start_date = 1; + Brand brand = 2; + DisplayName display_name = 3; + CampaignEndDate campaign_end_date = 4; } diff --git a/src/test/kotlin/org/wfanet/measurement/reporting/service/api/v1alpha/BUILD.bazel b/src/test/kotlin/org/wfanet/measurement/reporting/service/api/v1alpha/BUILD.bazel index b7e72ce8ea5..3b5066edccd 100644 --- a/src/test/kotlin/org/wfanet/measurement/reporting/service/api/v1alpha/BUILD.bazel +++ b/src/test/kotlin/org/wfanet/measurement/reporting/service/api/v1alpha/BUILD.bazel @@ -50,6 +50,8 @@ kt_jvm_test( ], test_class = "org.wfanet.measurement.reporting.service.api.v1alpha.EventGroupsServiceTest", deps = [ + "@wfa_common_jvm//imports/java/com/google/protobuf", + "@wfa_common_jvm//imports/kotlin/com/google/protobuf/kotlin", "//src/main/kotlin/org/wfanet/measurement/reporting/service/api:cel_env_provider", "//src/main/kotlin/org/wfanet/measurement/reporting/service/api/v1alpha:event_groups_service", "//src/main/kotlin/org/wfanet/measurement/reporting/service/api/v1alpha:principal_server_interceptor", diff --git a/src/test/kotlin/org/wfanet/measurement/reporting/service/api/v1alpha/EventGroupsServiceTest.kt b/src/test/kotlin/org/wfanet/measurement/reporting/service/api/v1alpha/EventGroupsServiceTest.kt index 90e4c89b3e2..cfd44067d16 100644 --- a/src/test/kotlin/org/wfanet/measurement/reporting/service/api/v1alpha/EventGroupsServiceTest.kt +++ b/src/test/kotlin/org/wfanet/measurement/reporting/service/api/v1alpha/EventGroupsServiceTest.kt @@ -17,6 +17,8 @@ package org.wfanet.measurement.reporting.service.api.v1alpha import com.google.common.truth.Truth.assertThat import com.google.common.truth.extensions.proto.ProtoTruth.assertThat import com.google.protobuf.ByteString +import com.google.protobuf.DescriptorProtos.FileDescriptorSet +import com.google.protobuf.Descriptors import io.grpc.Status import io.grpc.StatusRuntimeException import java.nio.file.Path @@ -45,12 +47,14 @@ import org.wfanet.measurement.api.v2alpha.copy import org.wfanet.measurement.api.v2alpha.encryptionPublicKey import org.wfanet.measurement.api.v2alpha.eventGroup as cmmsEventGroup import org.wfanet.measurement.api.v2alpha.eventGroupMetadataDescriptor -import org.wfanet.measurement.api.v2alpha.event_group_metadata.testing.testMetadataMessage +import org.wfanet.measurement.api.v2alpha.TestMetadataMessageKt.brand +import org.wfanet.measurement.api.v2alpha.TestMetadataMessageKt.campaignStartDate +import org.wfanet.measurement.api.v2alpha.TestMetadataMessageKt.date +import org.wfanet.measurement.api.v2alpha.testMetadataMessage import org.wfanet.measurement.api.v2alpha.event_group_metadata.testing.testParentMetadataMessage import org.wfanet.measurement.api.v2alpha.listEventGroupMetadataDescriptorsResponse import org.wfanet.measurement.api.v2alpha.listEventGroupsRequest as cmmsListEventGroupsRequest import org.wfanet.measurement.api.v2alpha.listEventGroupsResponse as cmmsListEventGroupsResponse -import org.wfanet.measurement.common.ProtoReflection import org.wfanet.measurement.common.crypto.tink.TinkPrivateKeyHandle import org.wfanet.measurement.common.crypto.tink.TinkPublicKeyHandle import org.wfanet.measurement.common.crypto.tink.loadPrivateKey @@ -94,7 +98,16 @@ private val ENCRYPTION_KEY_PAIR_STORE = listOf(ENCRYPTION_PUBLIC_KEY.data to ENCRYPTION_PRIVATE_KEY_HANDLE) ) ) -private val TEST_MESSAGE = testMetadataMessage { publisherId = 15 } +private val TEST_MESSAGE = testMetadataMessage { + brand = brand { value = "unilever" } + campaignStartDate = campaignStartDate { + value = date { + year = 2024 + month = 1 + day = 1 + } + } +} private const val CMMS_EVENT_GROUP_ID = "AAAAAAAAAHs" private val CMMS_EVENT_GROUP = cmmsEventGroup { name = "$DATA_PROVIDER_NAME/eventGroups/$CMMS_EVENT_GROUP_ID" @@ -110,7 +123,7 @@ private val CMMS_EVENT_GROUP = cmmsEventGroup { ENCRYPTION_PUBLIC_KEY, ) } -private val TEST_MESSAGE_2 = testMetadataMessage { publisherId = 5 } +private val TEST_MESSAGE_2 = testMetadataMessage { brand = brand { value = "unilever2" } } private const val CMMS_EVENT_GROUP_ID_2 = "AAAAAAAAAGs" private val CMMS_EVENT_GROUP_2 = CMMS_EVENT_GROUP.copy { @@ -148,9 +161,11 @@ private const val EVENT_GROUP_REFERENCE_ID = "edpRefId1" private const val EVENT_GROUP_PARENT = "measurementConsumers/$MEASUREMENT_CONSUMER_REFERENCE_ID/dataProviders/$DATA_PROVIDER_REFERENCE_ID" private const val METADATA_NAME = "$DATA_PROVIDER_NAME/eventGroupMetadataDescriptors/abc" +// TEST_MESSAGE.descriptorForType.getFileDescriptorSet() +// descriptorSet = ProtoReflection.buildFileDescriptorSet(TEST_MESSAGE.descriptorForType) private val EVENT_GROUP_METADATA_DESCRIPTOR = eventGroupMetadataDescriptor { name = METADATA_NAME - descriptorSet = ProtoReflection.buildFileDescriptorSet(TEST_MESSAGE.descriptorForType) + descriptorSet = TEST_MESSAGE.descriptorForType.getFileDescriptorSet() } @RunWith(JUnit4::class) @@ -273,13 +288,14 @@ class EventGroupsServiceTest { service.listEventGroups( listEventGroupsRequest { parent = EVENT_GROUP_PARENT - filter = "metadata.metadata.publisher_id > 10" + filter = "metadata.metadata.campaign_start_date.value.year >2021 " + pageToken = PAGE_TOKEN } ) } } - + // filter = "metadata.metadata.brand.value == 'unilever' " assertThat(result) .isEqualTo( listEventGroupsResponse { @@ -337,7 +353,7 @@ class EventGroupsServiceTest { service.listEventGroups( listEventGroupsRequest { parent = EVENT_GROUP_PARENT - filter = "metadata.metadata.publisher_id > 10" + filter = "metadata.metadata.brand.value == 'unilever' " pageToken = PAGE_TOKEN } ) @@ -488,3 +504,20 @@ private fun loadEncryptionPrivateKey(fileName: String): TinkPrivateKeyHandle { private fun loadEncryptionPublicKey(fileName: String): TinkPublicKeyHandle { return loadPublicKey(SECRET_FILES_PATH.resolve(fileName).toFile()) } + +private fun Descriptors.Descriptor.getFileDescriptorSet(): FileDescriptorSet { + val fileDescriptors = mutableSetOf() + val toVisit = mutableListOf(file) + while (toVisit.isNotEmpty()) { + val fileDescriptor = toVisit.removeLast() + if (!fileDescriptors.contains(fileDescriptor)) { + fileDescriptors.add(fileDescriptor) + for (dependency in fileDescriptor.dependencies) { + if (!fileDescriptors.contains(dependency)) { + toVisit.add(dependency) + } + } + } + } + return FileDescriptorSet.newBuilder().addAllFile(fileDescriptors.map { it.toProto() }).build() +}