Skip to content

Commit

Permalink
add roleSchemes end point
Browse files Browse the repository at this point in the history
  • Loading branch information
culmat committed Apr 18, 2024
1 parent d897749 commit 1d72e6b
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
5 changes: 4 additions & 1 deletion src/main/java/com/baloise/azure/FunctionalOrgEndpoint.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,13 @@ public HttpResponseMessage v1(
try {
List<String> path = asList(request.getUri().getPath().split("/"));
path = path.subList(path.indexOf("V1")+1, path.size());
if(path.size() ==2 && "avatar".equals(path.get(0))) {
if(path.size() ==1 && "~rolesSchemes".equals(path.get(0))) {
return createJSONResponse(request, Map.of("default", graph().getDefaultRoleScheme(), "roleSchemes", graph().getRoleSchemes()));
} else if(path.size() ==2 && "~avatar".equals(path.get(0))) {
return createAvatarResponse(request, path.get(1));
}


if(request.getQueryParameters().containsKey("clear")) graph().clear();
final StringTree child = graph().getOrg().getChild(path.toArray(new String[0]));

Expand Down
13 changes: 11 additions & 2 deletions src/main/java/com/baloise/azure/Graph.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.TreeMap;
import java.util.TreeSet;
Expand All @@ -32,7 +33,7 @@

public class Graph {
private final String SCRUM_ROLES = "~SCRUM";
private final Map<String, Set<String>> rolesSchemes = new HashMap<>(of(SCRUM_ROLES, new TreeSet<String>(asList("Member", "ScrumMaster", "ProductOwner"))));
final Map<String, Set<String>> rolesSchemes = new HashMap<>(of(SCRUM_ROLES, new TreeSet<String>(asList("Member", "ScrumMaster", "ProductOwner"))));
final String teamMarker = "👨‍👨‍👦‍👦";
final String orgMarker = "🏢";
final String orgSeparator = "-";
Expand Down Expand Up @@ -125,12 +126,16 @@ private Map<String, String> getTags(String teamId) {

Set<String> expandRoles(String ... rolesNames) {
return rolesNames == null || rolesNames.length == 0 ?
expandRoles(SCRUM_ROLES) :
expandRoles(getDefaultRoleScheme()) :
stream(rolesNames)
.flatMap((name)-> rolesSchemes.computeIfAbsent(name, Collections::singleton).stream())
.collect(toSet());
}

public String getDefaultRoleScheme() {
return SCRUM_ROLES;
}

String parseName(String input) {
return input.replaceAll(teamMarker, "").trim();
}
Expand All @@ -140,5 +145,9 @@ StringTree parseOrg(String description) {
Matcher matcher = orgPattern.matcher(description);
return matcher.find() ? org.addChild(matcher.group(1).split(orgSeparator)) : org;
}

public Map<String, Set<String>> getRoleSchemes() {
return rolesSchemes.entrySet().stream().filter(e->e.getValue().size()>1).collect(toMap(Entry::getKey,Entry::getValue));
}

}
10 changes: 6 additions & 4 deletions src/test/java/com/baloise/azure/GraphTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import static java.util.Arrays.asList;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals;

import java.util.TreeSet;

Expand All @@ -20,10 +21,11 @@ public void testExpandRoles() {
}

@Test
public void testParseOrg() {
// assertEquals(new Org(), null);
g.parseOrg("");

public void testGetRoleSchemes() {
g.expandRoles("bla");
final Graph expected = new Graph();
assertNotEquals(expected.rolesSchemes, g.rolesSchemes);
assertEquals(expected.getRoleSchemes(), g.getRoleSchemes());
}

}

0 comments on commit 1d72e6b

Please sign in to comment.