@@ -47,14 +47,15 @@ public boolean isAllowed(String action) {
4747 return false ;
4848 }
4949
50- return this .entry .getActionsMap ().getOrDefault (action , EffectOuterClass . Effect . EFFECT_DENY )
51- == EffectOuterClass .Effect .EFFECT_ALLOW ;
50+ return this .entry .getActionsMap ().getOrDefault (action ,
51+ EffectOuterClass . Effect . EFFECT_DENY ) == EffectOuterClass .Effect .EFFECT_ALLOW ;
5252 }
5353
5454 /**
5555 * Return all actions and effects in this instance.
5656 *
57- * @return Map of action to boolean indicating whether the action is allowed or not
57+ * @return Map of action to boolean indicating whether the action is allowed or
58+ * not
5859 */
5960 public Map <String , Boolean > getAll () {
6061 if (this .entry == null ) {
@@ -83,7 +84,8 @@ public boolean hasValidationErrors() {
8384 /**
8485 * Returns the list of validation errors if there are any.
8586 *
86- * @return List of {@link dev.cerbos.api.v1.schema.SchemaOuterClass.ValidationError}
87+ * @return List of
88+ * {@link dev.cerbos.api.v1.schema.SchemaOuterClass.ValidationError}
8789 */
8890 public List <SchemaOuterClass .ValidationError > getValidationErrors () {
8991 if (this .entry == null ) {
@@ -170,11 +172,54 @@ public int size() {
170172 * @return Map of output rule names and {@link Value}
171173 */
172174 public Map <String , Value > asMap () {
173- return this .outputs .stream ().collect (Collectors .toUnmodifiableMap (Engine .OutputEntry ::getSrc , Engine .OutputEntry ::getVal ));
175+ return this .outputs .stream ()
176+ .collect (Collectors .toUnmodifiableMap (Engine .OutputEntry ::getSrc , Engine .OutputEntry ::getVal ));
177+ }
178+
179+ /**
180+ * Returns the output entries as a map keyed by rule name.
181+ *
182+ * @return Map of output rule names and {@link Entry}
183+ */
184+ public Map <String , Entry > entriesAsMap () {
185+ return this .outputs .stream ()
186+ .collect (Collectors .toUnmodifiableMap (Engine .OutputEntry ::getSrc , (entry ) -> {
187+ return new Entry (entry .getSrc (), entry .getVal (), entry .getAction (), entry .getError ());
188+ }));
174189 }
175190
176191 public List <Engine .OutputEntry > getRaw () {
177192 return this .outputs ;
178193 }
194+
195+ public static final class Entry {
196+ private final String source ;
197+ private final Value value ;
198+ private final String action ;
199+ private final Optional <String > error ;
200+
201+ Entry (String source , Value value , String action , String error ) {
202+ this .source = source ;
203+ this .value = value ;
204+ this .action = action ;
205+ this .error = Optional .ofNullable (error );
206+ }
207+
208+ public String getSource () {
209+ return source ;
210+ }
211+
212+ public Value getValue () {
213+ return value ;
214+ }
215+
216+ public String getAction () {
217+ return action ;
218+ }
219+
220+ public Optional <String > getError () {
221+ return error ;
222+ }
223+ }
179224 }
180225}
0 commit comments