1 /*
2  * Copyright (C) 2023 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.adservices.data.adselection;
18 
19 import static androidx.room.ForeignKey.CASCADE;
20 
21 import android.annotation.Nullable;
22 import android.net.Uri;
23 
24 import androidx.annotation.NonNull;
25 import androidx.room.ColumnInfo;
26 import androidx.room.Entity;
27 import androidx.room.ForeignKey;
28 import androidx.room.Index;
29 import androidx.room.TypeConverters;
30 
31 import com.android.adservices.data.common.FledgeRoomConverters;
32 
33 import com.google.auto.value.AutoValue;
34 
35 import java.util.Objects;
36 
37 /** Table for records related to auction result reporting of an ad selection run. */
38 @AutoValue
39 @AutoValue.CopyAnnotations
40 @Entity(
41         tableName = "reporting_data",
42         indices = {@Index(value = {"ad_selection_id"})},
43         foreignKeys =
44                 @ForeignKey(
45                         entity = DBAdSelectionInitialization.class,
46                         parentColumns = "ad_selection_id",
47                         childColumns = "ad_selection_id",
48                         onDelete = CASCADE),
49         primaryKeys = {"ad_selection_id"})
50 @TypeConverters({FledgeRoomConverters.class})
51 public abstract class DBReportingData {
52     /** The id associated with this auction. */
53     @AutoValue.CopyAnnotations
54     @ColumnInfo(name = "ad_selection_id")
getAdSelectionId()55     public abstract long getAdSelectionId();
56 
57     /** The reporting uri associated with seller. */
58     @AutoValue.CopyAnnotations
59     @Nullable
60     @ColumnInfo(name = "seller_reporting_uri")
getSellerReportingUri()61     public abstract Uri getSellerReportingUri();
62 
63     /** The reporting uri associated with auction winner/buyer. */
64     @AutoValue.CopyAnnotations
65     @Nullable
66     @ColumnInfo(name = "buyer_reporting_uri")
getBuyerReportingUri()67     public abstract Uri getBuyerReportingUri();
68 
69     /** Returns an AutoValue builder for a {@link DBReportingData} entity. */
70     @NonNull
builder()71     public static DBReportingData.Builder builder() {
72         return new AutoValue_DBReportingData.Builder();
73     }
74 
75     /**
76      * Creates a {@link DBReportingData} object using the builder.
77      *
78      * <p>Required for Room SQLite integration.
79      */
80     @NonNull
create( long adSelectionId, @Nullable Uri sellerReportingUri, @Nullable Uri buyerReportingUri)81     public static DBReportingData create(
82             long adSelectionId, @Nullable Uri sellerReportingUri, @Nullable Uri buyerReportingUri) {
83         Objects.requireNonNull(sellerReportingUri);
84         Objects.requireNonNull(buyerReportingUri);
85 
86         return builder()
87                 .setAdSelectionId(adSelectionId)
88                 .setSellerReportingUri(sellerReportingUri)
89                 .setBuyerReportingUri(buyerReportingUri)
90                 .build();
91     }
92 
93     /** Builder class for a {@link DBReportingData}. */
94     @AutoValue.Builder
95     public abstract static class Builder {
96         /** Sets ad selection id. */
setAdSelectionId(long adSelectionId)97         public abstract DBReportingData.Builder setAdSelectionId(long adSelectionId);
98 
99         /** Sets seller reporting uri. */
setSellerReportingUri( @ullable Uri sellerReportingUri)100         public abstract DBReportingData.Builder setSellerReportingUri(
101                 @Nullable Uri sellerReportingUri);
102 
103         /** Sets buyer reporting uri. */
setBuyerReportingUri( @ullable Uri buyerReportingUri)104         public abstract DBReportingData.Builder setBuyerReportingUri(
105                 @Nullable Uri buyerReportingUri);
106 
107         /** Builds the {@link DBReportingData}. */
build()108         public abstract DBReportingData build();
109     }
110 }
111