20
20
21
21
import com .google .api .core .ApiFunction ;
22
22
import com .google .api .services .bigquery .model .Dataset .Access ;
23
+ import com .google .api .services .bigquery .model .DatasetAccessEntry ;
23
24
import com .google .cloud .StringEnumType ;
24
25
import com .google .cloud .StringEnumValue ;
25
26
import java .io .Serializable ;
27
+ import java .util .List ;
26
28
import java .util .Objects ;
27
29
28
30
/**
@@ -105,7 +107,8 @@ public enum Type {
105
107
USER ,
106
108
VIEW ,
107
109
IAM_MEMBER ,
108
- ROUTINE
110
+ ROUTINE ,
111
+ DATASET
109
112
}
110
113
111
114
Entity (Type type ) {
@@ -119,6 +122,11 @@ public Type getType() {
119
122
abstract Access toPb ();
120
123
121
124
static Entity fromPb (Access access ) {
125
+ if (access .getDataset () != null ) {
126
+ return new DatasetAclEntity (
127
+ DatasetId .fromPb (access .getDataset ().getDataset ()),
128
+ access .getDataset ().getTargetTypes ());
129
+ }
122
130
if (access .getDomain () != null ) {
123
131
return new Domain (access .getDomain ());
124
132
}
@@ -146,6 +154,65 @@ static Entity fromPb(Access access) {
146
154
}
147
155
}
148
156
157
+ /**
158
+ * Class for a BigQuery DatasetAclEntity ACL entity. Objects of this class represent a
159
+ * DatasetAclEntity from a different DatasetAclEntity to grant access to. Only views are supported
160
+ * for now. The role field is not required when this field is set. If that DatasetAclEntity is
161
+ * deleted and re-created, its access needs to be granted again via an update operation.
162
+ */
163
+ public static final class DatasetAclEntity extends Entity {
164
+
165
+ private static final long serialVersionUID = -8392885851733136526L ;
166
+
167
+ private final DatasetId id ;
168
+ private final List <String > targetTypes ;
169
+
170
+ /** Creates a DatasetAclEntity given the DatasetAclEntity's id. */
171
+ public DatasetAclEntity (DatasetId id , List <String > targetTypes ) {
172
+ super (Type .DATASET );
173
+ this .id = id ;
174
+ this .targetTypes = targetTypes ;
175
+ }
176
+
177
+ /** Returns DatasetAclEntity's identity. */
178
+ public DatasetId getId () {
179
+ return id ;
180
+ }
181
+
182
+ public List <String > getTargetTypes () {
183
+ return targetTypes ;
184
+ }
185
+
186
+ @ Override
187
+ public boolean equals (Object obj ) {
188
+ if (this == obj ) {
189
+ return true ;
190
+ }
191
+ if (obj == null || getClass () != obj .getClass ()) {
192
+ return false ;
193
+ }
194
+ DatasetAclEntity datasetAclEntity = (DatasetAclEntity ) obj ;
195
+ return Objects .equals (getType (), datasetAclEntity .getType ())
196
+ && Objects .equals (id , datasetAclEntity .id );
197
+ }
198
+
199
+ @ Override
200
+ public int hashCode () {
201
+ return Objects .hash (getType (), id );
202
+ }
203
+
204
+ @ Override
205
+ public String toString () {
206
+ return toPb ().toString ();
207
+ }
208
+
209
+ @ Override
210
+ Access toPb () {
211
+ return new Access ()
212
+ .setDataset (new DatasetAccessEntry ().setDataset (id .toPb ()).setTargetTypes (targetTypes ));
213
+ }
214
+ }
215
+
149
216
/**
150
217
* Class for a BigQuery Domain entity. Objects of this class represent a domain to grant access
151
218
* to. Any users signed in with the domain specified will be granted the specified access.
@@ -342,9 +409,10 @@ Access toPb() {
342
409
343
410
/**
344
411
* Class for a BigQuery View entity. Objects of this class represent a view from a different
345
- * dataset to grant access to. Queries executed against that view will have read access to tables
346
- * in this dataset. The role field is not required when this field is set. If that view is updated
347
- * by any user, access to the view needs to be granted again via an update operation.
412
+ * datasetAclEntity to grant access to. Queries executed against that view will have read access
413
+ * to tables in this datasetAclEntity. The role field is not required when this field is set. If
414
+ * that view is updated by any user, access to the view needs to be granted again via an update
415
+ * operation.
348
416
*/
349
417
public static final class View extends Entity {
350
418
@@ -393,10 +461,10 @@ Access toPb() {
393
461
394
462
/**
395
463
* Class for a BigQuery Routine entity. Objects of this class represent a routine from a different
396
- * dataset to grant access to. Queries executed against that routine will have read access to
397
- * views/tables/routines in this dataset . Only UDF is supported for now. The role field is not
398
- * required when this field is set. If that routine is updated by any user, access to the routine
399
- * needs to be granted again via an update operation.
464
+ * datasetAclEntity to grant access to. Queries executed against that routine will have read
465
+ * access to views/tables/routines in this datasetAclEntity . Only UDF is supported for now. The
466
+ * role field is not required when this field is set. If that routine is updated by any user,
467
+ * access to the routine needs to be granted again via an update operation.
400
468
*/
401
469
public static final class Routine extends Entity {
402
470
@@ -516,6 +584,11 @@ public static Acl of(Entity entity, Role role) {
516
584
return new Acl (entity , role );
517
585
}
518
586
587
+ /** Returns an Acl object for a datasetAclEntity. */
588
+ public static Acl of (DatasetAclEntity datasetAclEntity ) {
589
+ return new Acl (datasetAclEntity , null );
590
+ }
591
+
519
592
/** Returns an Acl object for a view entity. */
520
593
public static Acl of (View view ) {
521
594
return new Acl (view , null );
0 commit comments