Commit 96361f84 authored by Sonia Zorba's avatar Sonia Zorba
Browse files

Added is_leaf property on GroupEntity

parent cf908b5b
......@@ -6,7 +6,7 @@ import java.util.Arrays;
public enum IdentityType {
EDU_GAIN("EduGAIN"),
EDU_GAIN("eduGAIN"),
X509("X.509"),
ORCID("OrcID"),
GOOGLE("Google"),
......@@ -27,7 +27,8 @@ public enum IdentityType {
@JsonCreator
public static IdentityType forValue(String value) {
return Arrays.stream(IdentityType.values())
.filter(it -> value.equals(it.value)).findFirst().get();
.filter(it -> value.equals(it.value)).findFirst()
.orElseThrow(() -> new IllegalArgumentException("Unsupported IdentityType " + value));
}
@JsonValue
......
......@@ -65,7 +65,7 @@ public class GroupsDAO {
public Optional<GroupEntity> findGroupById(String groupId) {
String sql = "SELECT id, name, path from gms_group WHERE id = ?";
String sql = "SELECT id, name, path, is_leaf from gms_group WHERE id = ?";
return jdbcTemplate.query(conn -> {
PreparedStatement ps = conn.prepareStatement(sql);
......@@ -77,6 +77,7 @@ public class GroupsDAO {
group.setId(resultSet.getString("id"));
group.setName(resultSet.getString("name"));
group.setPath(resultSet.getString("path"));
group.setLeaf(resultSet.getBoolean("is_leaf"));
return Optional.of(group);
}
return Optional.empty();
......@@ -85,7 +86,7 @@ public class GroupsDAO {
public Optional<GroupEntity> findGroupByPath(String path) {
String sql = "SELECT id, name from gms_group WHERE path = ?";
String sql = "SELECT id, name, is_leaf from gms_group WHERE path = ?";
return jdbcTemplate.query(conn -> {
PreparedStatement ps = conn.prepareStatement(sql);
......@@ -96,6 +97,7 @@ public class GroupsDAO {
GroupEntity group = new GroupEntity();
group.setId(resultSet.getString("id"));
group.setName(resultSet.getString("name"));
group.setLeaf(resultSet.getBoolean("is_leaf"));
group.setPath(path);
return Optional.of(group);
}
......@@ -111,7 +113,7 @@ public class GroupsDAO {
return jdbcTemplate.query(conn -> {
String sql = "SELECT id, name, path from gms_group WHERE id IN (";
String sql = "SELECT id, name, path, is_leaf from gms_group WHERE id IN (";
sql += String.join(",", identifiers.stream().map(p -> "?").collect(Collectors.toList()));
sql += ")";
......@@ -128,6 +130,7 @@ public class GroupsDAO {
group.setId(resultSet.getString("id"));
group.setName(resultSet.getString("name"));
group.setPath(resultSet.getString("path"));
group.setLeaf(resultSet.getBoolean("is_leaf"));
groups.add(group);
}
return groups;
......@@ -136,7 +139,7 @@ public class GroupsDAO {
public Optional<GroupEntity> findGroupByParentAndName(String parentPath, String childName) {
String sql = "SELECT id, path from gms_group WHERE name = ? AND path ~ ?";
String sql = "SELECT id, path, is_leaf from gms_group WHERE name = ? AND path ~ ?";
return jdbcTemplate.query(conn -> {
PreparedStatement ps = conn.prepareStatement(sql);
......@@ -149,6 +152,7 @@ public class GroupsDAO {
group.setId(resultSet.getString("id"));
group.setName(childName);
group.setPath(resultSet.getString("path"));
group.setLeaf(resultSet.getBoolean("is_leaf"));
return Optional.of(group);
}
return Optional.empty();
......@@ -168,9 +172,9 @@ public class GroupsDAO {
String sql;
if (hasSearchFilter) {
sql = "SELECT id, name, path FROM gms_group WHERE path ~ ? AND name ILIKE ? ORDER BY name";
sql = "SELECT id, name, path, is_leaf FROM gms_group WHERE path ~ ? AND name ILIKE ? ORDER BY name";
} else {
sql = "SELECT id, name, path FROM gms_group WHERE path ~ ? ORDER BY name";
sql = "SELECT id, name, path, is_leaf FROM gms_group WHERE path ~ ? ORDER BY name";
}
return jdbcTemplate.query(conn -> {
......@@ -195,7 +199,7 @@ public class GroupsDAO {
public List<GroupEntity> getAllChildren(String path) {
String sql = "SELECT id, name, path FROM gms_group WHERE path <@ ? AND path <> ? ORDER BY nlevel(path) DESC";
String sql = "SELECT id, name, path, is_leaf FROM gms_group WHERE path <@ ? AND path <> ? ORDER BY nlevel(path) DESC";
return jdbcTemplate.query(conn -> {
PreparedStatement ps = conn.prepareStatement(sql);
......@@ -209,7 +213,7 @@ public class GroupsDAO {
public List<GroupEntity> findGroupsByNames(List<String> names) {
String sql = "SELECT id, name, path from gms_group WHERE name IN ("
String sql = "SELECT id, name, path, is_leaf from gms_group WHERE name IN ("
+ String.join(",", names.stream().map(g -> "?").collect(Collectors.toList()))
+ ")";
......@@ -232,6 +236,7 @@ public class GroupsDAO {
group.setId(resultSet.getString("id"));
group.setName(resultSet.getString("name"));
group.setPath(resultSet.getString("path"));
group.setLeaf(resultSet.getBoolean("is_leaf"));
groups.add(group);
}
return groups;
......@@ -302,7 +307,7 @@ public class GroupsDAO {
public List<GroupEntity> searchGroups(String searchText) {
String sql = "SELECT id, name, path from gms_group WHERE name ILIKE ?";
String sql = "SELECT id, name, path, is_leaf from gms_group WHERE name ILIKE ?";
return jdbcTemplate.query(conn -> {
PreparedStatement ps = conn.prepareStatement(sql);
......
......@@ -43,7 +43,7 @@ public class MembershipsDAO {
public List<GroupEntity> getUserMemberships(String userId) {
String sql = "SELECT g.id, g.name, g.path FROM "
String sql = "SELECT g.id, g.name, g.path, g.is_leaf FROM "
+ " gms_membership m "
+ " JOIN gms_group g ON g.id = m.group_id"
+ " WHERE m.user_id = ?";
......@@ -59,6 +59,7 @@ public class MembershipsDAO {
group.setId(resultSet.getString("id"));
group.setName(resultSet.getString("name"));
group.setPath(resultSet.getString("path"));
group.setLeaf(resultSet.getBoolean("is_leaf"));
memberships.add(group);
}
return memberships;
......
......@@ -7,6 +7,7 @@ public class GroupEntity {
private String id;
private String name;
private String path;
private boolean leaf;
public String getId() {
return id;
......@@ -32,6 +33,14 @@ public class GroupEntity {
this.path = path;
}
public boolean isLeaf() {
return leaf;
}
public void setLeaf(boolean leaf) {
this.leaf = leaf;
}
public String getParentPath() {
if (path.isEmpty()) {
return null;
......
......@@ -4,6 +4,7 @@ CREATE TABLE gms_group (
id varchar NOT NULL,
name text NOT NULL,
path ltree NOT NULL,
is_leaf boolean,
primary key(id)
);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment