Skip to content

Commit

Permalink
Adds fromValue method to EntityType
Browse files Browse the repository at this point in the history
Signed-off-by: Darshit Chanpura <[email protected]>
  • Loading branch information
DarshitChanpura committed Dec 4, 2024
1 parent 4107407 commit 274c64f
Showing 1 changed file with 16 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@

package org.opensearch.accesscontrol.resources;

import java.util.Arrays;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;

/**
* This enum contains the type of entities a resource can be shared with.
*
Expand All @@ -19,6 +24,9 @@ public enum EntityType {
ROLES("roles"),
BACKEND_ROLES("backend_roles");

Check warning on line 25 in server/src/main/java/org/opensearch/accesscontrol/resources/EntityType.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/accesscontrol/resources/EntityType.java#L23-L25

Added lines #L23 - L25 were not covered by tests

private static final Map<String, EntityType> VALUE_MAP = Arrays.stream(values())
.collect(Collectors.toMap(EntityType::toString, Function.identity()));

Check warning on line 28 in server/src/main/java/org/opensearch/accesscontrol/resources/EntityType.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/accesscontrol/resources/EntityType.java#L27-L28

Added lines #L27 - L28 were not covered by tests

private final String value;

EntityType(String value) {
Expand All @@ -29,4 +37,12 @@ public enum EntityType {
public String toString() {
return value;

Check warning on line 38 in server/src/main/java/org/opensearch/accesscontrol/resources/EntityType.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/accesscontrol/resources/EntityType.java#L38

Added line #L38 was not covered by tests
}

public static EntityType fromValue(String value) {
EntityType type = VALUE_MAP.get(value);

Check warning on line 42 in server/src/main/java/org/opensearch/accesscontrol/resources/EntityType.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/accesscontrol/resources/EntityType.java#L42

Added line #L42 was not covered by tests
if (type == null) {
throw new IllegalArgumentException("No enum constant with value: " + value);

Check warning on line 44 in server/src/main/java/org/opensearch/accesscontrol/resources/EntityType.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/accesscontrol/resources/EntityType.java#L44

Added line #L44 was not covered by tests
}
return type;

Check warning on line 46 in server/src/main/java/org/opensearch/accesscontrol/resources/EntityType.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/accesscontrol/resources/EntityType.java#L46

Added line #L46 was not covered by tests
}
}

0 comments on commit 274c64f

Please sign in to comment.