-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ARC-1700: Spicegen: Add permission factory methods (#4)
* ARC-1700: Add generation for 'check' methods. * ARC-1700: cleanup * ARC-1700: Wrap error. * ARC-1700: Cleanup * ARC-1700: Rename Mapper * ARC-1700: Pull impls into internal records. * ARC-1700: Recordify models & Remove Compose
- Loading branch information
1 parent
365d857
commit 2337d7d
Showing
41 changed files
with
1,089 additions
and
507 deletions.
There are no files selected for viewing
30 changes: 30 additions & 0 deletions
30
api/src/main/java/com/oviva/spicegen/api/CheckPermission.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package com.oviva.spicegen.api; | ||
|
||
import com.oviva.spicegen.api.internal.CheckPermissionImpl; | ||
|
||
public interface CheckPermission { | ||
|
||
static Builder newBuilder() { | ||
return new CheckPermissionImpl.Builder(); | ||
} | ||
|
||
ObjectRef resource(); | ||
|
||
String permission(); | ||
|
||
SubjectRef subject(); | ||
|
||
Consistency consistency(); | ||
|
||
interface Builder { | ||
Builder resource(ObjectRef resource); | ||
|
||
Builder permission(String permission); | ||
|
||
Builder subject(SubjectRef subject); | ||
|
||
Builder consistency(Consistency consistency); | ||
|
||
CheckPermission build(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.oviva.spicegen.api; | ||
|
||
import com.oviva.spicegen.api.internal.ConsistencyImpl; | ||
|
||
public interface Consistency { | ||
|
||
String consistencyToken(); | ||
|
||
Requirement requirement(); | ||
|
||
static Consistency fullyConsistent() { | ||
return ConsistencyImpl.fullyConsistent(); | ||
} | ||
|
||
static Consistency atLeastAsFreshAs(String consistencyToken) { | ||
if (consistencyToken == null) { | ||
return ConsistencyImpl.fullyConsistent(); | ||
} | ||
return new ConsistencyImpl(Consistency.Requirement.AT_LEAST_AS_FRESH, consistencyToken); | ||
} | ||
|
||
enum Requirement { | ||
FULLY_CONSISTENT, | ||
AT_LEAST_AS_FRESH | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,20 @@ | ||
package com.oviva.spicegen.api; | ||
|
||
import com.oviva.spicegen.api.internal.ObjectRefImpl; | ||
|
||
public interface ObjectRef { | ||
String kind(); | ||
|
||
String id(); | ||
|
||
static ObjectRef of(String kind, String id) { | ||
return new ObjectRef() { | ||
@Override | ||
public String kind() { | ||
return kind; | ||
} | ||
if (kind == null) { | ||
throw new IllegalArgumentException("kind must not be null"); | ||
} | ||
if (id == null) { | ||
throw new IllegalArgumentException("id must not be null"); | ||
} | ||
|
||
@Override | ||
public String id() { | ||
return id; | ||
} | ||
}; | ||
return new ObjectRefImpl(kind, id); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 16 additions & 43 deletions
59
api/src/main/java/com/oviva/spicegen/api/Precondition.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,63 +1,36 @@ | ||
package com.oviva.spicegen.api; | ||
|
||
public final class Precondition { | ||
import com.oviva.spicegen.api.internal.PreconditionImpl; | ||
|
||
private final Condition condition; | ||
private final RelationshipFilter filter; | ||
public interface Precondition { | ||
|
||
private Precondition(Builder builder) { | ||
condition = builder.condition; | ||
filter = builder.filter; | ||
} | ||
Condition condition(); | ||
|
||
public static Precondition mustMatch(RelationshipFilter filter) { | ||
return new Precondition(Condition.MUST_MATCH, filter); | ||
} | ||
RelationshipFilter filter(); | ||
|
||
public static Precondition mustNotMatch(RelationshipFilter filter) { | ||
return new Precondition(Condition.MUST_NOT_MATCH, filter); | ||
static Precondition mustMatch(RelationshipFilter filter) { | ||
return new PreconditionImpl(Condition.MUST_MATCH, filter); | ||
} | ||
|
||
public static Builder newBuilder() { | ||
return new Builder(); | ||
static Precondition mustNotMatch(RelationshipFilter filter) { | ||
return new PreconditionImpl(Condition.MUST_NOT_MATCH, filter); | ||
} | ||
|
||
private Precondition(Condition condition, RelationshipFilter filter) { | ||
this.condition = condition; | ||
this.filter = filter; | ||
} | ||
|
||
public Condition condition() { | ||
return condition; | ||
} | ||
|
||
public RelationshipFilter filter() { | ||
return filter; | ||
} | ||
|
||
public enum Condition { | ||
enum Condition { | ||
MUST_MATCH, | ||
MUST_NOT_MATCH | ||
} | ||
|
||
public static final class Builder { | ||
private Condition condition; | ||
private RelationshipFilter filter; | ||
static Builder newBuilder() { | ||
return new PreconditionImpl.Builder(); | ||
} | ||
|
||
private Builder() {} | ||
interface Builder { | ||
|
||
public Builder withCondition(Condition val) { | ||
condition = val; | ||
return this; | ||
} | ||
Precondition.Builder condition(Condition condition); | ||
|
||
public Builder withFilter(RelationshipFilter val) { | ||
filter = val; | ||
return this; | ||
} | ||
Precondition.Builder filter(RelationshipFilter filter); | ||
|
||
public Precondition build() { | ||
return new Precondition(this); | ||
} | ||
Precondition build(); | ||
} | ||
} |
131 changes: 25 additions & 106 deletions
131
api/src/main/java/com/oviva/spicegen/api/RelationshipFilter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,137 +1,56 @@ | ||
package com.oviva.spicegen.api; | ||
|
||
import com.oviva.spicegen.api.internal.RelationshipFilterImpl; | ||
import java.util.Optional; | ||
|
||
public final class RelationshipFilter { | ||
public interface RelationshipFilter { | ||
|
||
private final String resourceKind; | ||
|
||
/** optional */ | ||
private final String resourceId; | ||
|
||
/** optional */ | ||
private final String relation; | ||
|
||
/** optional */ | ||
private final SubjectFilter subjectFilter; | ||
|
||
private RelationshipFilter(Builder builder) { | ||
resourceKind = builder.resourceKind; | ||
resourceId = builder.resourceId; | ||
relation = builder.relation; | ||
subjectFilter = builder.subjectFilter; | ||
static Builder newBuilder() { | ||
return new RelationshipFilterImpl.Builder(); | ||
} | ||
|
||
public static Builder newBuilder() { | ||
return new Builder(); | ||
} | ||
|
||
public String resourceKind() { | ||
return resourceKind; | ||
} | ||
|
||
public Optional<String> resourceId() { | ||
return Optional.ofNullable(resourceId); | ||
} | ||
|
||
public Optional<String> relation() { | ||
return Optional.ofNullable(relation); | ||
} | ||
|
||
public Optional<SubjectFilter> subjectFilter() { | ||
return Optional.ofNullable(subjectFilter); | ||
} | ||
String resourceKind(); | ||
|
||
public static class SubjectFilter { | ||
Optional<String> resourceId(); | ||
|
||
private final String subjectKind; | ||
Optional<String> relation(); | ||
|
||
/** optional */ | ||
private final String subjectId; | ||
Optional<SubjectFilter> subjectFilter(); | ||
|
||
/** optional */ | ||
private final String relation; | ||
interface SubjectFilter { | ||
|
||
private SubjectFilter(Builder builder) { | ||
subjectKind = builder.subjectKind; | ||
subjectId = builder.subjectId; | ||
relation = builder.relation; | ||
static Builder newBuilder() { | ||
return new RelationshipFilterImpl.SubjectFilterImpl.Builder(); | ||
} | ||
|
||
public static Builder newBuilder() { | ||
return new Builder(); | ||
} | ||
|
||
public String subjectKind() { | ||
return subjectKind; | ||
} | ||
String subjectKind(); | ||
|
||
public Optional<String> subjectId() { | ||
return Optional.ofNullable(subjectId); | ||
} | ||
|
||
public Optional<String> relation() { | ||
return Optional.ofNullable(relation); | ||
} | ||
Optional<String> subjectId(); | ||
|
||
public static final class Builder { | ||
private String subjectKind; | ||
private String subjectId; | ||
private String relation; | ||
Optional<String> relation(); | ||
|
||
private Builder() {} | ||
interface Builder { | ||
|
||
public Builder withSubjectKind(String val) { | ||
subjectKind = val; | ||
return this; | ||
} | ||
Builder subjectKind(String val); | ||
|
||
public Builder withSubjectId(String val) { | ||
subjectId = val; | ||
return this; | ||
} | ||
Builder subjectId(String val); | ||
|
||
public Builder withRelation(String val) { | ||
relation = val; | ||
return this; | ||
} | ||
Builder relation(String val); | ||
|
||
public SubjectFilter build() { | ||
return new SubjectFilter(this); | ||
} | ||
SubjectFilter build(); | ||
} | ||
} | ||
|
||
public static final class Builder { | ||
private String resourceKind; | ||
private String resourceId; | ||
private String relation; | ||
private SubjectFilter subjectFilter; | ||
interface Builder { | ||
|
||
private Builder() {} | ||
Builder resourceKind(String val); | ||
|
||
public Builder withResourceKind(String val) { | ||
resourceKind = val; | ||
return this; | ||
} | ||
|
||
public Builder withResourceId(String val) { | ||
resourceId = val; | ||
return this; | ||
} | ||
Builder resourceId(String val); | ||
|
||
public Builder withRelation(String val) { | ||
relation = val; | ||
return this; | ||
} | ||
Builder relation(String val); | ||
|
||
public Builder withSubjectFilter(SubjectFilter val) { | ||
subjectFilter = val; | ||
return this; | ||
} | ||
Builder subjectFilter(SubjectFilter val); | ||
|
||
public RelationshipFilter build() { | ||
return new RelationshipFilter(this); | ||
} | ||
RelationshipFilter build(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,16 @@ | ||
package com.oviva.spicegen.api; | ||
|
||
import com.oviva.spicegen.api.internal.SubjectRefImpl; | ||
|
||
public interface SubjectRef { | ||
String kind(); | ||
|
||
String id(); | ||
|
||
static SubjectRef ofObject(ObjectRef o) { | ||
return new SubjectRef() { | ||
@Override | ||
public String kind() { | ||
return o.kind(); | ||
} | ||
|
||
@Override | ||
public String id() { | ||
return o.id(); | ||
} | ||
}; | ||
if (o == null) { | ||
return null; | ||
} | ||
return new SubjectRefImpl(o.kind(), o.id()); | ||
} | ||
} |
Oops, something went wrong.