1 /*
2  * Copyright (C) 2022 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.service.measurement.aggregation;
18 
19 import android.annotation.Nullable;
20 
21 import com.android.adservices.service.measurement.FilterMap;
22 import com.android.adservices.service.measurement.XNetworkData;
23 
24 import java.math.BigInteger;
25 import java.util.HashSet;
26 import java.util.List;
27 import java.util.Objects;
28 import java.util.Optional;
29 import java.util.Set;
30 
31 /**
32  * POJO for AggregateTriggerData.
33  */
34 public class AggregateTriggerData {
35 
36     private BigInteger mKey;
37     private Set<String> mSourceKeys;
38     private Optional<List<FilterMap>> mFilterSet;
39     private Optional<List<FilterMap>> mNotFilterSet;
40     private Optional<XNetworkData> mXNetworkData;
41 
AggregateTriggerData()42     private AggregateTriggerData() {
43         mKey = null;
44         mSourceKeys = new HashSet<>();
45         mFilterSet = Optional.empty();
46         mNotFilterSet = Optional.empty();
47         mXNetworkData = Optional.empty();
48     }
49 
50     @Override
equals(Object obj)51     public boolean equals(Object obj) {
52         if (!(obj instanceof AggregateTriggerData)) {
53             return false;
54         }
55         AggregateTriggerData attributionTriggerData = (AggregateTriggerData) obj;
56         return Objects.equals(mKey, attributionTriggerData.mKey)
57                 && Objects.equals(mSourceKeys, attributionTriggerData.mSourceKeys)
58                 && Objects.equals(mFilterSet, attributionTriggerData.mFilterSet)
59                 && Objects.equals(mNotFilterSet, attributionTriggerData.mNotFilterSet)
60                 && Objects.equals(mXNetworkData, attributionTriggerData.mXNetworkData);
61     }
62 
63     @Override
hashCode()64     public int hashCode() {
65         return Objects.hash(mKey, mSourceKeys, mFilterSet, mNotFilterSet, mXNetworkData);
66     }
67 
68     /**
69      * Returns trigger_data's key which will be used to generate the aggregate key.
70      */
getKey()71     public BigInteger getKey() {
72         return mKey;
73     }
74 
75     /**
76      * Returns the source_key set which represent which source this dimension applies to.
77      */
getSourceKeys()78     public Set<String> getSourceKeys() {
79         return mSourceKeys;
80     }
81 
82     /**
83      * Returns the filter which controls when aggregate trigger data ise used based on impression
84      * side information.
85      */
getFilterSet()86     public Optional<List<FilterMap>> getFilterSet() {
87         return mFilterSet;
88     }
89 
90     /**
91      * Returns the not_filter, reverse of filter.
92      */
getNotFilterSet()93     public Optional<List<FilterMap>> getNotFilterSet() {
94         return mNotFilterSet;
95     }
96 
97     /** Returns the serving adtech network object */
getXNetworkData()98     public Optional<XNetworkData> getXNetworkData() {
99         return mXNetworkData;
100     }
101 
102     /**
103      * Builder for {@link AggregateTriggerData}.
104      */
105     public static final class Builder {
106         private final AggregateTriggerData mBuilding;
107 
Builder()108         public Builder() {
109             mBuilding = new AggregateTriggerData();
110         }
111 
112         /**
113          * See {@link AggregateTriggerData#getKey()}.
114          */
setKey(BigInteger key)115         public Builder setKey(BigInteger key) {
116             mBuilding.mKey = key;
117             return this;
118         }
119 
120         /**
121          * See {@link AggregateTriggerData#getSourceKeys()}.
122          */
setSourceKeys(Set<String> sourceKeys)123         public Builder setSourceKeys(Set<String> sourceKeys) {
124             mBuilding.mSourceKeys = sourceKeys;
125             return this;
126         }
127 
128         /** See {@link AggregateTriggerData#getFilterSet()}. */
setFilterSet(@ullable List<FilterMap> filterSet)129         public Builder setFilterSet(@Nullable List<FilterMap> filterSet) {
130             mBuilding.mFilterSet = Optional.ofNullable(filterSet);
131             return this;
132         }
133 
134         /** See {@link AggregateTriggerData#getNotFilterSet()} */
setNotFilterSet(@ullable List<FilterMap> notFilterSet)135         public Builder setNotFilterSet(@Nullable List<FilterMap> notFilterSet) {
136             mBuilding.mNotFilterSet = Optional.ofNullable(notFilterSet);
137             return this;
138         }
139 
140         /** See {@link AggregateTriggerData#getXNetworkData()} */
setXNetworkData(@ullable XNetworkData xNetworkData)141         public Builder setXNetworkData(@Nullable XNetworkData xNetworkData) {
142             mBuilding.mXNetworkData = Optional.ofNullable(xNetworkData);
143             return this;
144         }
145 
146         /**
147          * Build the {@link AggregateTriggerData}
148          */
build()149         public AggregateTriggerData build() {
150             return mBuilding;
151         }
152     }
153 }
154