Skip to content

Commit

Permalink
Refactors variables from List to Set
Browse files Browse the repository at this point in the history
Signed-off-by: Darshit Chanpura <[email protected]>
  • Loading branch information
DarshitChanpura committed Dec 5, 2024
1 parent 274c64f commit 014be82
Showing 1 changed file with 19 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@
import org.opensearch.core.xcontent.XContentParser;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.HashSet;
import java.util.Set;

/**
* Defines the scope and who this scope is shared with
Expand Down Expand Up @@ -95,45 +94,45 @@ public static class SharedWithPerScope implements ToXContentFragment, NamedWrite
private static final String ROLES_FIELD = EntityType.ROLES.toString();
private static final String BACKEND_ROLES_FIELD = EntityType.BACKEND_ROLES.toString();

Check warning on line 95 in server/src/main/java/org/opensearch/accesscontrol/resources/SharedWithScope.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/accesscontrol/resources/SharedWithScope.java#L93-L95

Added lines #L93 - L95 were not covered by tests

private List<String> users;
private Set<String> users;

private List<String> roles;
private Set<String> roles;

private List<String> backendRoles;
private Set<String> backendRoles;

public SharedWithPerScope(List<String> users, List<String> roles, List<String> backendRoles) {
public SharedWithPerScope(Set<String> users, Set<String> roles, Set<String> backendRoles) {
this.users = users;
this.roles = roles;
this.backendRoles = backendRoles;
}

Check warning on line 107 in server/src/main/java/org/opensearch/accesscontrol/resources/SharedWithScope.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/accesscontrol/resources/SharedWithScope.java#L103-L107

Added lines #L103 - L107 were not covered by tests

public SharedWithPerScope(StreamInput in) throws IOException {
this.users = Arrays.asList(in.readStringArray());
this.roles = Arrays.asList(in.readStringArray());
this.backendRoles = Arrays.asList(in.readStringArray());
this.users = Set.of(in.readStringArray());
this.roles = Set.of(in.readStringArray());
this.backendRoles = Set.of(in.readStringArray());
}

Check warning on line 113 in server/src/main/java/org/opensearch/accesscontrol/resources/SharedWithScope.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/accesscontrol/resources/SharedWithScope.java#L109-L113

Added lines #L109 - L113 were not covered by tests

public List<String> getUsers() {
public Set<String> getUsers() {
return users;

Check warning on line 116 in server/src/main/java/org/opensearch/accesscontrol/resources/SharedWithScope.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/accesscontrol/resources/SharedWithScope.java#L116

Added line #L116 was not covered by tests
}

public void setUsers(List<String> users) {
public void setUsers(Set<String> users) {
this.users = users;
}

Check warning on line 121 in server/src/main/java/org/opensearch/accesscontrol/resources/SharedWithScope.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/accesscontrol/resources/SharedWithScope.java#L120-L121

Added lines #L120 - L121 were not covered by tests

public List<String> getRoles() {
public Set<String> getRoles() {
return roles;

Check warning on line 124 in server/src/main/java/org/opensearch/accesscontrol/resources/SharedWithScope.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/accesscontrol/resources/SharedWithScope.java#L124

Added line #L124 was not covered by tests
}

public void setRoles(List<String> roles) {
public void setRoles(Set<String> roles) {
this.roles = roles;
}

Check warning on line 129 in server/src/main/java/org/opensearch/accesscontrol/resources/SharedWithScope.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/accesscontrol/resources/SharedWithScope.java#L128-L129

Added lines #L128 - L129 were not covered by tests

public List<String> getBackendRoles() {
public Set<String> getBackendRoles() {
return backendRoles;

Check warning on line 132 in server/src/main/java/org/opensearch/accesscontrol/resources/SharedWithScope.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/accesscontrol/resources/SharedWithScope.java#L132

Added line #L132 was not covered by tests
}

public void setBackendRoles(List<String> backendRoles) {
public void setBackendRoles(Set<String> backendRoles) {
this.backendRoles = backendRoles;
}

Check warning on line 137 in server/src/main/java/org/opensearch/accesscontrol/resources/SharedWithScope.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/accesscontrol/resources/SharedWithScope.java#L136-L137

Added lines #L136 - L137 were not covered by tests

Expand Down Expand Up @@ -163,9 +162,9 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
}

public static SharedWithPerScope fromXContent(XContentParser parser) throws IOException {
List<String> users = new ArrayList<>();
List<String> roles = new ArrayList<>();
List<String> backendRoles = new ArrayList<>();
Set<String> users = new HashSet<>();
Set<String> roles = new HashSet<>();
Set<String> backendRoles = new HashSet<>();

Check warning on line 167 in server/src/main/java/org/opensearch/accesscontrol/resources/SharedWithScope.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/accesscontrol/resources/SharedWithScope.java#L165-L167

Added lines #L165 - L167 were not covered by tests

XContentParser.Token token;
String currentFieldName = null;

Check warning on line 170 in server/src/main/java/org/opensearch/accesscontrol/resources/SharedWithScope.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/accesscontrol/resources/SharedWithScope.java#L170

Added line #L170 was not covered by tests
Expand Down Expand Up @@ -194,7 +193,7 @@ public static SharedWithPerScope fromXContent(XContentParser parser) throws IOEx
return new SharedWithPerScope(users, roles, backendRoles);

Check warning on line 193 in server/src/main/java/org/opensearch/accesscontrol/resources/SharedWithScope.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/accesscontrol/resources/SharedWithScope.java#L193

Added line #L193 was not covered by tests
}

private void writeFieldOrEmptyArray(XContentBuilder builder, String fieldName, List<String> values) throws IOException {
private void writeFieldOrEmptyArray(XContentBuilder builder, String fieldName, Set<String> values) throws IOException {
if (values != null) {
builder.field(fieldName, values);

Check warning on line 198 in server/src/main/java/org/opensearch/accesscontrol/resources/SharedWithScope.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/accesscontrol/resources/SharedWithScope.java#L198

Added line #L198 was not covered by tests
} else {
Expand Down

0 comments on commit 014be82

Please sign in to comment.