Skip to content

feat(sdk): add shorthand enum constants for policy types#357

Merged
marythought merged 1 commit intomainfrom
feat/enum-helpers
Apr 29, 2026
Merged

feat(sdk): add shorthand enum constants for policy types#357
marythought merged 1 commit intomainfrom
feat/enum-helpers

Conversation

@marythought
Copy link
Copy Markdown
Contributor

@marythought marythought commented Apr 28, 2026

Summary

  • Add PolicyEnums utility class with readable constant aliases for verbose protobuf enum names so developers can write PolicyEnums.OPERATOR_IN instead of SubjectMappingOperatorEnum.SUBJECT_MAPPING_OPERATOR_ENUM_IN
  • Update all examples to use the new shorthand constants via static imports
  • Companion to feat(sdk): add shorthand enum constants for policy types platform#3408 (Go SDK equivalent)

Constants added

Shorthand Full proto name
OPERATOR_IN SUBJECT_MAPPING_OPERATOR_ENUM_IN
OPERATOR_NOT_IN SUBJECT_MAPPING_OPERATOR_ENUM_NOT_IN
OPERATOR_IN_CONTAINS SUBJECT_MAPPING_OPERATOR_ENUM_IN_CONTAINS
BOOLEAN_AND CONDITION_BOOLEAN_TYPE_ENUM_AND
BOOLEAN_OR CONDITION_BOOLEAN_TYPE_ENUM_OR
RULE_ALL_OF ATTRIBUTE_RULE_TYPE_ENUM_ALL_OF
RULE_ANY_OF ATTRIBUTE_RULE_TYPE_ENUM_ANY_OF
RULE_HIERARCHY ATTRIBUTE_RULE_TYPE_ENUM_HIERARCHY
STATE_ACTIVE ACTIVE_STATE_ENUM_ACTIVE
STATE_INACTIVE ACTIVE_STATE_ENUM_INACTIVE
STATE_ANY ACTIVE_STATE_ENUM_ANY

Before / After

// Before
ConditionGroup.newBuilder()
    .setBooleanOperator(ConditionBooleanTypeEnum.CONDITION_BOOLEAN_TYPE_ENUM_AND)
    .addConditions(Condition.newBuilder()
        .setOperator(SubjectMappingOperatorEnum.SUBJECT_MAPPING_OPERATOR_ENUM_IN));

// After
import static io.opentdf.platform.sdk.PolicyEnums.*;

ConditionGroup.newBuilder()
    .setBooleanOperator(BOOLEAN_AND)
    .addConditions(Condition.newBuilder()
        .setOperator(OPERATOR_IN));

Test plan

  • mvn compile passes (full project including examples)
  • mvn test -Dtest=PolicyEnumsTest — 4 tests, all pass
  • CI passes

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Introduced simplified static constants for policy configuration, making attribute rules, operators, and boolean conditions more readable and intuitive to use.
  • Documentation

    • Updated example code to demonstrate the new simplified policy constants.
  • Tests

    • Added test coverage validating the new policy configuration constants.

Add PolicyEnums utility class with readable constant aliases for verbose
protobuf enum names so developers can write PolicyEnums.OPERATOR_IN
instead of SubjectMappingOperatorEnum.SUBJECT_MAPPING_OPERATOR_ENUM_IN.

Constants added for SubjectMappingOperatorEnum, ConditionBooleanTypeEnum,
AttributeRuleTypeEnum, and ActiveStateEnum. Examples updated to use the
new shorthand via static imports.

Companion to opentdf/platform#3408 (Go SDK equivalent).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Mary Dickson <mary.dickson@virtru.com>
@marythought marythought requested review from a team as code owners April 28, 2026 16:14
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 28, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 0540e7ca-6df7-4c46-bf58-ad580b93b4f3

📥 Commits

Reviewing files that changed from the base of the PR and between 1d2fde6 and 4b5aa4e.

📒 Files selected for processing (5)
  • examples/src/main/java/io/opentdf/platform/CreateAttribute.java
  • examples/src/main/java/io/opentdf/platform/CreateSubjectConditionSet.java
  • examples/src/main/java/io/opentdf/platform/CreateSubjectMapping.java
  • sdk/src/main/java/io/opentdf/platform/sdk/PolicyEnums.java
  • sdk/src/test/java/io/opentdf/platform/sdk/PolicyEnumsTest.java

📝 Walkthrough

Walkthrough

This PR introduces a new PolicyEnums utility class that exposes readable static constant aliases for policy-related protobuf enums, then refactors example code to use these cleaner constants instead of direct enum references.

Changes

Cohort / File(s) Summary
New PolicyEnums Utility
sdk/src/main/java/io/opentdf/platform/sdk/PolicyEnums.java, sdk/src/test/java/io/opentdf/platform/sdk/PolicyEnumsTest.java
Introduces final utility class with 11 static constant aliases for operator, boolean, rule, and active-state enum types. Includes comprehensive JUnit 5 tests validating all constant mappings.
Example Code Refactoring
examples/src/main/java/io/opentdf/platform/CreateAttribute.java, examples/src/main/java/io/opentdf/platform/CreateSubjectConditionSet.java, examples/src/main/java/io/opentdf/platform/CreateSubjectMapping.java
Updated to use static constants from PolicyEnums instead of referencing protobuf enum types directly; imports simplified with wildcard static imports.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested reviewers

  • mkleene

Poem

🐰 Constants hop into view, so clean and bright,
No more enum paths, just names that feel right!
From OPERATOR_IN to RULE_ALL_OF, hooray—
PolicyEnums makes the code dance today! 🌟

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'feat(sdk): add shorthand enum constants for policy types' clearly and specifically describes the main change: introducing shorthand enum constants for policy types in the SDK.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/enum-helpers

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a new utility class, PolicyEnums, which provides shorthand constants for commonly used policy enum values to improve code readability. The existing example classes have been updated to utilize these constants via static imports, and a corresponding test suite has been added to verify the enum mappings. I have no feedback to provide as the changes are clean and well-structured.

@sonarqubecloud
Copy link
Copy Markdown

@github-actions
Copy link
Copy Markdown
Contributor

marythought added a commit to opentdf/docs that referenced this pull request Apr 28, 2026
… badges

- Update JS imports to use barrel exports from @opentdf/sdk instead of
  deep proto paths
- Update policy.mdx Java example to use PolicyEnums shorthand constants
- Update policy.mdx JS example to use enum values instead of strings
- Add SdkVersion badges with NEXT placeholders to code samples
  (replace with actual versions once SDK releases ship)

Note: Java code_samples/java/ files are pulled from the java-sdk repo
at build time via remote-content plugin. They will update automatically
once javaSdkVersion is bumped in docusaurus.config.ts after the
java-sdk release containing opentdf/java-sdk#357.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Mary Dickson <mary.dickson@virtru.com>
marythought added a commit to opentdf/docs that referenced this pull request Apr 28, 2026
… badges

- Update JS imports to use barrel exports from @opentdf/sdk instead of
  deep proto paths
- Update policy.mdx Java example to use PolicyEnums shorthand constants
- Update policy.mdx JS example to use enum values instead of strings
- Add SdkVersion badges with NEXT placeholders to code samples
  (replace with actual versions once SDK releases ship)

Note: Java code_samples/java/ files are pulled from the java-sdk repo
at build time via remote-content plugin. They will update automatically
once javaSdkVersion is bumped in docusaurus.config.ts after the
java-sdk release containing opentdf/java-sdk#357.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Mary Dickson <mary.dickson@virtru.com>
marythought added a commit to opentdf/web-sdk that referenced this pull request Apr 28, 2026
…928)

Re-export SubjectMappingOperatorEnum, ConditionBooleanTypeEnum,
AttributeRuleTypeEnum, and ActiveStateEnum from the main @opentdf/sdk
entry point so users can import them directly instead of reaching into
generated proto paths.

Companion to opentdf/platform#3408 (Go SDK) and opentdf/java-sdk#357
(Java SDK).

Signed-off-by: Mary Dickson <mary.dickson@virtru.com>
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown
Member

@dmihalcik-virtru dmihalcik-virtru left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to wire up a formatter with import sorting for examples, it seems

@marythought marythought merged commit a1d4651 into main Apr 29, 2026
19 checks passed
@marythought marythought deleted the feat/enum-helpers branch April 29, 2026 14:44
marythought pushed a commit that referenced this pull request Apr 29, 2026
🤖 I have created a release *beep* *boop*
---


<details><summary>0.15.0</summary>

##
[0.15.0](v0.14.0...v0.15.0)
(2026-04-29)


### Features

* **sdk:** add shorthand enum constants for policy types
([#357](#357))
([a1d4651](a1d4651))
</details>

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: opentdf-automation[bot] <149537512+opentdf-automation[bot]@users.noreply.github.com>
marythought added a commit to opentdf/docs that referenced this pull request Apr 29, 2026
… badges

- Update JS imports to use barrel exports from @opentdf/sdk instead of
  deep proto paths
- Update policy.mdx Java example to use PolicyEnums shorthand constants
- Update policy.mdx JS example to use enum values instead of strings
- Add SdkVersion badges with NEXT placeholders to code samples
  (replace with actual versions once SDK releases ship)

Note: Java code_samples/java/ files are pulled from the java-sdk repo
at build time via remote-content plugin. They will update automatically
once javaSdkVersion is bumped in docusaurus.config.ts after the
java-sdk release containing opentdf/java-sdk#357.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Mary Dickson <mary.dickson@virtru.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants