Skip to content

Commit

Permalink
try
Browse files Browse the repository at this point in the history
  • Loading branch information
uakyol committed Feb 23, 2024
1 parent d38fcf3 commit d4dcd26
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand All @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}
)
Expand Down Expand Up @@ -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<Descriptors.FileDescriptor>()
val toVisit = mutableListOf<Descriptors.FileDescriptor>(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()
}

0 comments on commit d4dcd26

Please sign in to comment.