21
21
import com .google .api .core .ApiFunction ;
22
22
import com .google .api .services .bigquery .model .Dataset .Access ;
23
23
import com .google .api .services .bigquery .model .DatasetAccessEntry ;
24
+ import com .google .api .services .bigquery .model .Expr ;
24
25
import com .google .cloud .StringEnumType ;
25
26
import com .google .cloud .StringEnumValue ;
26
27
import java .io .Serializable ;
@@ -41,6 +42,7 @@ public final class Acl implements Serializable {
41
42
42
43
private final Entity entity ;
43
44
private final Role role ;
45
+ private final Expr condition ;
44
46
45
47
/**
46
48
* Dataset roles supported by BigQuery.
@@ -568,9 +570,147 @@ Access toPb() {
568
570
}
569
571
}
570
572
573
+ /** Expr represents the conditional information related to dataset access policies. */
574
+ public static final class Expr implements Serializable {
575
+ // Textual representation of an expression in Common Expression Language syntax.
576
+ private final String expression ;
577
+ /**
578
+ * Optional. Title for the expression, i.e. a short string describing its purpose. This can be
579
+ * used e.g. in UIs which allow to enter the expression.
580
+ */
581
+ private final String title ;
582
+ /**
583
+ * Optional. Description of the expression. This is a longer text which describes the
584
+ * expression, e.g. when hovered over it in a UI.
585
+ */
586
+ private final String description ;
587
+ /**
588
+ * Optional. String indicating the location of the expression for error reporting, e.g. a file
589
+ * name and a position in the file.
590
+ */
591
+ private final String location ;
592
+
593
+ private static final long serialVersionUID = 7358264726377291156L ;
594
+
595
+ static final class Builder {
596
+ private String expression ;
597
+ private String title ;
598
+ private String description ;
599
+ private String location ;
600
+
601
+ Builder () {}
602
+
603
+ Builder (Expr expr ) {
604
+ this .expression = expr .expression ;
605
+ this .title = expr .title ;
606
+ this .description = expr .description ;
607
+ this .location = expr .location ;
608
+ }
609
+
610
+ Builder (com .google .api .services .bigquery .model .Expr bqExpr ) {
611
+ this .expression = bqExpr .getExpression ();
612
+ if (bqExpr .getTitle () != null ) {
613
+ this .title = bqExpr .getTitle ();
614
+ }
615
+ if (bqExpr .getDescription () != null ) {
616
+ this .description = bqExpr .getDescription ();
617
+ }
618
+ if (bqExpr .getLocation () != null ) {
619
+ this .location = bqExpr .getLocation ();
620
+ }
621
+ }
622
+
623
+ public Builder setExpression (String expression ) {
624
+ this .expression = expression ;
625
+ return this ;
626
+ }
627
+
628
+ public Builder setTitle (String title ) {
629
+ this .title = title ;
630
+ return this ;
631
+ }
632
+
633
+ public Builder setDescription (String description ) {
634
+ this .description = description ;
635
+ return this ;
636
+ }
637
+
638
+ public Builder setLocation (String location ) {
639
+ this .location = location ;
640
+ return this ;
641
+ }
642
+
643
+ public Expr build () {
644
+ return new Expr (this );
645
+ }
646
+ }
647
+
648
+ public Expr (Builder builder ) {
649
+ this .expression = builder .expression ;
650
+ this .title = builder .title ;
651
+ this .description = builder .description ;
652
+ this .location = builder .location ;
653
+ }
654
+
655
+ public Expr (String expression , String title , String description , String location ) {
656
+ this .expression = expression ;
657
+ this .title = title ;
658
+ this .description = description ;
659
+ this .location = location ;
660
+ }
661
+
662
+ com .google .api .services .bigquery .model .Expr toPb () {
663
+ com .google .api .services .bigquery .model .Expr bqExpr =
664
+ new com .google .api .services .bigquery .model .Expr ();
665
+ bqExpr .setExpression (this .expression );
666
+ bqExpr .setTitle (this .title );
667
+ bqExpr .setDescription (this .description );
668
+ bqExpr .setLocation (this .location );
669
+ return bqExpr ;
670
+ }
671
+
672
+ static Expr fromPb (com .google .api .services .bigquery .model .Expr bqExpr ) {
673
+ return new Builder (bqExpr ).build ();
674
+ }
675
+
676
+ public Builder toBuilder () {
677
+ return new Builder (this );
678
+ }
679
+
680
+ @ Override
681
+ public int hashCode () {
682
+ return Objects .hash (expression , title , description , location );
683
+ }
684
+
685
+ @ Override
686
+ public boolean equals (Object obj ) {
687
+ if (this == obj ) {
688
+ return true ;
689
+ }
690
+ if (obj == null || getClass () != obj .getClass ()) {
691
+ return false ;
692
+ }
693
+ final Expr other = (Expr ) obj ;
694
+ return Objects .equals (this .expression , other .expression )
695
+ && Objects .equals (this .title , other .title )
696
+ && Objects .equals (this .description , other .description )
697
+ && Objects .equals (this .location , other .location );
698
+ }
699
+
700
+ @ Override
701
+ public String toString () {
702
+ return toPb ().toString ();
703
+ }
704
+ }
705
+
571
706
private Acl (Entity entity , Role role ) {
707
+ this (entity , role , null );
708
+ }
709
+
710
+ private Acl (Entity entity , Role role , Expr condition ) {
572
711
this .entity = checkNotNull (entity );
573
712
this .role = role ;
713
+ this .condition = condition ;
574
714
}
575
715
576
716
/** @return Returns the entity for this ACL. */
@@ -582,6 +722,10 @@ public Entity getEntity() {
582
722
public Role getRole () {
583
723
return role ;
584
724
}
725
+ /** @return Returns the condition specified by this ACL. */
726
+ public Expr getCondition () {
727
+ return condition ;
728
+ }
585
729
586
730
/**
587
731
* @return Returns an Acl object.
@@ -592,6 +736,10 @@ public static Acl of(Entity entity, Role role) {
592
736
return new Acl (entity , role );
593
737
}
594
738
739
+ public static Acl of (Entity entity , Role role , Expr condition ) {
740
+ return new Acl (entity , role , condition );
741
+ }
742
+
595
743
/**
596
744
* @param datasetAclEntity
597
745
* @return Returns an Acl object for a datasetAclEntity.
@@ -618,7 +766,7 @@ public static Acl of(Routine routine) {
618
766
619
767
@ Override
620
768
public int hashCode () {
621
- return Objects .hash (entity , role );
769
+ return Objects .hash (entity , role , condition );
622
770
}
623
771
624
772
@ Override
@@ -635,19 +783,26 @@ public boolean equals(Object obj) {
635
783
return false ;
636
784
}
637
785
final Acl other = (Acl ) obj ;
638
- return Objects .equals (this .entity , other .entity ) && Objects .equals (this .role , other .role );
786
+ return Objects .equals (this .entity , other .entity )
787
+ && Objects .equals (this .role , other .role )
788
+ && Objects .equals (this .condition , other .condition );
639
789
}
640
790
641
791
Access toPb () {
642
792
Access accessPb = entity .toPb ();
643
793
if (role != null ) {
644
794
accessPb .setRole (role .name ());
645
795
}
796
+ if (condition != null ) {
797
+ accessPb .setCondition (condition .toPb ());
798
+ }
646
799
return accessPb ;
647
800
}
648
801
649
802
static Acl fromPb (Access access ) {
650
803
return Acl .of (
651
- Entity .fromPb (access ), access .getRole () != null ? Role .valueOf (access .getRole ()) : null );
804
+ Entity .fromPb (access ),
805
+ access .getRole () != null ? Role .valueOf (access .getRole ()) : null ,
806
+ access .getCondition () != null ? Expr .fromPb (access .getCondition ()) : null );
652
807
}
653
808
}
0 commit comments