From 0de4ce0445b832290cb7374d9c5b7def245d3bd5 Mon Sep 17 00:00:00 2001 From: montesm Date: Mon, 4 Dec 2023 14:13:00 -0600 Subject: [PATCH] Add application/topic admins to payload for detail pages Signed-off-by: montesm --- .../actioninterval/ActionIntervalService.java | 4 +++- .../actioninterval/dto/ActionIntervalDTO.java | 22 ++++++++++--------- .../model/application/ApplicationDTO.java | 11 ++++++++++ .../model/application/ApplicationService.java | 2 ++ .../ApplicationGrantService.java | 6 ++++- .../model/applicationgrant/dto/GrantDTO.java | 11 ++++++++++ .../grantduration/GrantDurationService.java | 8 +++---- .../grantduration/dto/GrantDurationDTO.java | 14 +++++++++++- .../model/groupuser/GroupUserRepository.java | 3 +++ .../model/groupuser/GroupUserService.java | 10 +++++++++ .../manager/model/topic/TopicDTO.java | 10 +++++++++ .../manager/model/topic/TopicService.java | 2 ++ .../model/topicset/TopicSetService.java | 6 ++++- .../model/topicset/dto/TopicSetDTO.java | 10 +++++++++ 14 files changed, 101 insertions(+), 18 deletions(-) diff --git a/app/src/main/java/io/unityfoundation/dds/permissions/manager/model/actioninterval/ActionIntervalService.java b/app/src/main/java/io/unityfoundation/dds/permissions/manager/model/actioninterval/ActionIntervalService.java index 92c88f1e..f091a598 100644 --- a/app/src/main/java/io/unityfoundation/dds/permissions/manager/model/actioninterval/ActionIntervalService.java +++ b/app/src/main/java/io/unityfoundation/dds/permissions/manager/model/actioninterval/ActionIntervalService.java @@ -185,13 +185,15 @@ public HttpResponse deleteById(Long actionIntervalId) { } public ActionIntervalDTO createDTO(ActionInterval actionInterval) { + List admins = groupUserService.getAllTopicAdminsOfGroup(actionInterval.getPermissionsGroup().getId()); return new ActionIntervalDTO( actionInterval.getId(), actionInterval.getName(), actionInterval.getPermissionsGroup().getId(), actionInterval.getPermissionsGroup().getName(), actionInterval.getStartDate(), - actionInterval.getEndDate()); + actionInterval.getEndDate(), + admins); } private void checkExistenceAndAdminAuthorization(Optional actionIntervalOptional) { diff --git a/app/src/main/java/io/unityfoundation/dds/permissions/manager/model/actioninterval/dto/ActionIntervalDTO.java b/app/src/main/java/io/unityfoundation/dds/permissions/manager/model/actioninterval/dto/ActionIntervalDTO.java index d792caf6..149b88dc 100644 --- a/app/src/main/java/io/unityfoundation/dds/permissions/manager/model/actioninterval/dto/ActionIntervalDTO.java +++ b/app/src/main/java/io/unityfoundation/dds/permissions/manager/model/actioninterval/dto/ActionIntervalDTO.java @@ -22,6 +22,7 @@ import javax.validation.constraints.NotNull; import javax.validation.constraints.Size; import java.time.Instant; +import java.util.List; @Introspected public class ActionIntervalDTO implements EntityDTO { @@ -34,6 +35,7 @@ public class ActionIntervalDTO implements EntityDTO { private String name; private Long groupId; private String groupName; + private List admins; @NotNull @JsonFormat(shape = JsonFormat.Shape.STRING) @@ -46,22 +48,14 @@ public class ActionIntervalDTO implements EntityDTO { public ActionIntervalDTO() { } - public ActionIntervalDTO(Long id, String name, Long groupId, String groupName, Instant startDate, Instant endDate) { + public ActionIntervalDTO(Long id, String name, Long groupId, String groupName, Instant startDate, Instant endDate, List admins) { this.id = id; this.name = name; this.groupId = groupId; this.groupName = groupName; this.startDate = startDate; this.endDate = endDate; - } - - public ActionIntervalDTO(ActionInterval actionInterval) { - this.id = actionInterval.getId(); - this.name = actionInterval.getName(); - this.groupId = actionInterval.getPermissionsGroup().getId(); - this.groupName = actionInterval.getPermissionsGroup().getName(); - this.startDate = actionInterval.getStartDate(); - this.endDate = actionInterval.getEndDate(); + this.admins = admins; } public Long getId() { @@ -92,6 +86,14 @@ public String getGroupName() { return groupName; } + public List getAdmins() { + return admins; + } + + public void setAdmins(List admins) { + this.admins = admins; + } + public void setGroupName(String groupName) { this.groupName = groupName; } diff --git a/app/src/main/java/io/unityfoundation/dds/permissions/manager/model/application/ApplicationDTO.java b/app/src/main/java/io/unityfoundation/dds/permissions/manager/model/application/ApplicationDTO.java index 94112f3a..0d838554 100644 --- a/app/src/main/java/io/unityfoundation/dds/permissions/manager/model/application/ApplicationDTO.java +++ b/app/src/main/java/io/unityfoundation/dds/permissions/manager/model/application/ApplicationDTO.java @@ -21,6 +21,7 @@ import javax.validation.constraints.NotNull; import javax.validation.constraints.Size; import java.time.Instant; +import java.util.List; @Introspected public class ApplicationDTO implements EntityDTO { @@ -42,6 +43,8 @@ public class ApplicationDTO implements EntityDTO { @JsonFormat(shape = JsonFormat.Shape.STRING) private Instant dateUpdated; + private List admins; + public ApplicationDTO() { } @@ -119,4 +122,12 @@ public Instant getDateUpdated() { public void setDateUpdated(Instant dateUpdated) { this.dateUpdated = dateUpdated; } + + public List getAdmins() { + return admins; + } + + public void setAdmins(List admins) { + this.admins = admins; + } } diff --git a/app/src/main/java/io/unityfoundation/dds/permissions/manager/model/application/ApplicationService.java b/app/src/main/java/io/unityfoundation/dds/permissions/manager/model/application/ApplicationService.java index 56454d6d..44e48539 100644 --- a/app/src/main/java/io/unityfoundation/dds/permissions/manager/model/application/ApplicationService.java +++ b/app/src/main/java/io/unityfoundation/dds/permissions/manager/model/application/ApplicationService.java @@ -342,6 +342,8 @@ public HttpResponse show(Long id) { throw new DPMException(ResponseStatusCodes.UNAUTHORIZED, HttpStatus.UNAUTHORIZED); } ApplicationDTO applicationDTO = new ApplicationDTO(application); + List applicationAdmins = groupUserService.getAllApplicationAdminsOfGroup(application.getPermissionsGroup().getId()); + applicationDTO.setAdmins(applicationAdmins); return HttpResponse.ok(applicationDTO); } diff --git a/app/src/main/java/io/unityfoundation/dds/permissions/manager/model/applicationgrant/ApplicationGrantService.java b/app/src/main/java/io/unityfoundation/dds/permissions/manager/model/applicationgrant/ApplicationGrantService.java index a6a23a3d..ca53f028 100644 --- a/app/src/main/java/io/unityfoundation/dds/permissions/manager/model/applicationgrant/ApplicationGrantService.java +++ b/app/src/main/java/io/unityfoundation/dds/permissions/manager/model/applicationgrant/ApplicationGrantService.java @@ -166,7 +166,11 @@ public GrantDTO findById(Long grantId) { } } - return createDTO(grantOptional.get()); + GrantDTO grantDTO = createDTO(grantOptional.get()); + List admins = groupUserService.getAllTopicAdminsOfGroup(grantOptional.get().getId()); + grantDTO.setAdmins(admins); + + return grantDTO; } public Publisher> create(String grantToken, CreateGrantDTO createGrantDTO) { diff --git a/app/src/main/java/io/unityfoundation/dds/permissions/manager/model/applicationgrant/dto/GrantDTO.java b/app/src/main/java/io/unityfoundation/dds/permissions/manager/model/applicationgrant/dto/GrantDTO.java index 8ba960cc..a52c7127 100644 --- a/app/src/main/java/io/unityfoundation/dds/permissions/manager/model/applicationgrant/dto/GrantDTO.java +++ b/app/src/main/java/io/unityfoundation/dds/permissions/manager/model/applicationgrant/dto/GrantDTO.java @@ -16,6 +16,8 @@ import io.micronaut.core.annotation.Introspected; import io.unityfoundation.dds.permissions.manager.model.EntityDTO; +import java.util.List; + @Introspected public class GrantDTO implements EntityDTO { private final Long id; @@ -27,6 +29,7 @@ public class GrantDTO implements EntityDTO { private final String groupName; private final Long durationInMilliseconds; private final String durationMetadata; + private List admins; public GrantDTO(Long id, String name, Long applicationId, String applicationName, String applicationGroupName, Long groupId, String groupName, Long durationInMilliseconds, String durationMetadata) { this.id = id; @@ -77,4 +80,12 @@ public Long getDurationInMilliseconds() { public String getDurationMetadata() { return durationMetadata; } + + public List getAdmins() { + return admins; + } + + public void setAdmins(List admins) { + this.admins = admins; + } } diff --git a/app/src/main/java/io/unityfoundation/dds/permissions/manager/model/grantduration/GrantDurationService.java b/app/src/main/java/io/unityfoundation/dds/permissions/manager/model/grantduration/GrantDurationService.java index 359f6470..9137e4a4 100644 --- a/app/src/main/java/io/unityfoundation/dds/permissions/manager/model/grantduration/GrantDurationService.java +++ b/app/src/main/java/io/unityfoundation/dds/permissions/manager/model/grantduration/GrantDurationService.java @@ -186,14 +186,14 @@ public HttpResponse deleteById(Long grantDurationId) { } public GrantDurationDTO createDTO(GrantDuration grantDuration) { - return new GrantDurationDTO( - grantDuration.getId(), + List admins = groupUserService.getAllTopicAdminsOfGroup(grantDuration.getPermissionsGroup().getId()); + return new GrantDurationDTO(grantDuration.getId(), grantDuration.getName(), grantDuration.getPermissionsGroup().getId(), grantDuration.getPermissionsGroup().getName(), grantDuration.getDurationInMilliseconds(), - grantDuration.getDurationMetadata() - ); + grantDuration.getDurationMetadata(), + admins); } private void checkExistenceAndAdminAuthorization(Optional grantDurationOptional) { diff --git a/app/src/main/java/io/unityfoundation/dds/permissions/manager/model/grantduration/dto/GrantDurationDTO.java b/app/src/main/java/io/unityfoundation/dds/permissions/manager/model/grantduration/dto/GrantDurationDTO.java index 556b3c3a..f88bbcc3 100644 --- a/app/src/main/java/io/unityfoundation/dds/permissions/manager/model/grantduration/dto/GrantDurationDTO.java +++ b/app/src/main/java/io/unityfoundation/dds/permissions/manager/model/grantduration/dto/GrantDurationDTO.java @@ -19,6 +19,7 @@ import javax.validation.constraints.NotBlank; import javax.validation.constraints.NotNull; import javax.validation.constraints.Size; +import java.util.List; @Introspected public class GrantDurationDTO implements EntityDTO { @@ -37,16 +38,19 @@ public class GrantDurationDTO implements EntityDTO { private String durationMetadata; + private List admins; + public GrantDurationDTO() { } - public GrantDurationDTO(Long id, String name, Long groupId, String groupName, Long durationInMilliseconds, String durationMetadata) { + public GrantDurationDTO(Long id, String name, Long groupId, String groupName, Long durationInMilliseconds, String durationMetadata, List admins) { this.id = id; this.name = name; this.groupId = groupId; this.groupName = groupName; this.durationInMilliseconds = durationInMilliseconds; this.durationMetadata = durationMetadata; + this.admins = admins; } public Long getId() { @@ -96,4 +100,12 @@ public String getDurationMetadata() { public void setDurationMetadata(String durationMetadata) { this.durationMetadata = durationMetadata; } + + public List getAdmins() { + return admins; + } + + public void setAdmins(List admins) { + this.admins = admins; + } } diff --git a/app/src/main/java/io/unityfoundation/dds/permissions/manager/model/groupuser/GroupUserRepository.java b/app/src/main/java/io/unityfoundation/dds/permissions/manager/model/groupuser/GroupUserRepository.java index 54bad70d..8c77a067 100644 --- a/app/src/main/java/io/unityfoundation/dds/permissions/manager/model/groupuser/GroupUserRepository.java +++ b/app/src/main/java/io/unityfoundation/dds/permissions/manager/model/groupuser/GroupUserRepository.java @@ -60,4 +60,7 @@ public interface GroupUserRepository extends PageableRepository Page findPermissionsGroupByPermissionsUserEqualsAndPermissionsGroupNameContainsIgnoreCaseAndGroupAdminTrue(User permissionsUser, String group, Pageable pageable); Page findPermissionsGroupByPermissionsUserEqualsAndPermissionsGroupNameContainsIgnoreCaseAndTopicAdminTrue(User permissionsUser, String group, Pageable pageable); Page findPermissionsGroupByPermissionsUserEqualsAndPermissionsGroupNameContainsIgnoreCaseAndApplicationAdminTrue(User permissionsUser, String group, Pageable pageable); + + List findPermissionsUserByPermissionsGroupIdAndTopicAdminTrue(Long groupId); + List findPermissionsUserByPermissionsGroupIdAndApplicationAdminTrue(Long groupId); } diff --git a/app/src/main/java/io/unityfoundation/dds/permissions/manager/model/groupuser/GroupUserService.java b/app/src/main/java/io/unityfoundation/dds/permissions/manager/model/groupuser/GroupUserService.java index bf846de5..0d48cbd5 100644 --- a/app/src/main/java/io/unityfoundation/dds/permissions/manager/model/groupuser/GroupUserService.java +++ b/app/src/main/java/io/unityfoundation/dds/permissions/manager/model/groupuser/GroupUserService.java @@ -334,4 +334,14 @@ public HttpResponse checkUserExists(Long id) { } throw new DPMException(ResponseStatusCodes.USER_NOT_FOUND, HttpStatus.NOT_FOUND); } + + public List getAllTopicAdminsOfGroup(Long groupId) { + return groupUserRepository.findPermissionsUserByPermissionsGroupIdAndTopicAdminTrue(groupId).stream() + .map(User::getEmail).collect(Collectors.toList()); + } + + public List getAllApplicationAdminsOfGroup(Long groupId) { + return groupUserRepository.findPermissionsUserByPermissionsGroupIdAndApplicationAdminTrue(groupId).stream() + .map(User::getEmail).collect(Collectors.toList()); + } } \ No newline at end of file diff --git a/app/src/main/java/io/unityfoundation/dds/permissions/manager/model/topic/TopicDTO.java b/app/src/main/java/io/unityfoundation/dds/permissions/manager/model/topic/TopicDTO.java index 672c602b..01d41448 100644 --- a/app/src/main/java/io/unityfoundation/dds/permissions/manager/model/topic/TopicDTO.java +++ b/app/src/main/java/io/unityfoundation/dds/permissions/manager/model/topic/TopicDTO.java @@ -22,6 +22,7 @@ import javax.validation.constraints.NotNull; import javax.validation.constraints.Size; import java.time.Instant; +import java.util.List; @Introspected public class TopicDTO implements EntityDTO { @@ -38,6 +39,7 @@ public class TopicDTO implements EntityDTO { private Long group; private String groupName; private String canonicalName; + private List admins; @JsonFormat(shape = JsonFormat.Shape.STRING) private Instant dateCreated; @@ -141,4 +143,12 @@ public Instant getDateUpdated() { public void setDateUpdated(Instant dateUpdated) { this.dateUpdated = dateUpdated; } + + public List getAdmins() { + return admins; + } + + public void setAdmins(List admins) { + this.admins = admins; + } } diff --git a/app/src/main/java/io/unityfoundation/dds/permissions/manager/model/topic/TopicService.java b/app/src/main/java/io/unityfoundation/dds/permissions/manager/model/topic/TopicService.java index 8c739e51..c760eb71 100644 --- a/app/src/main/java/io/unityfoundation/dds/permissions/manager/model/topic/TopicService.java +++ b/app/src/main/java/io/unityfoundation/dds/permissions/manager/model/topic/TopicService.java @@ -194,6 +194,8 @@ public HttpResponse show(Long id) { throw new DPMException(ResponseStatusCodes.UNAUTHORIZED, HttpStatus.UNAUTHORIZED); } TopicDTO topicResponseDTO = new TopicDTO(topic); + List adminEmails = groupUserService.getAllTopicAdminsOfGroup(topic.getPermissionsGroup().getId()); + topicResponseDTO.setAdmins(adminEmails); return HttpResponse.ok(topicResponseDTO); } diff --git a/app/src/main/java/io/unityfoundation/dds/permissions/manager/model/topicset/TopicSetService.java b/app/src/main/java/io/unityfoundation/dds/permissions/manager/model/topicset/TopicSetService.java index 90bf23a1..092d5a4c 100644 --- a/app/src/main/java/io/unityfoundation/dds/permissions/manager/model/topicset/TopicSetService.java +++ b/app/src/main/java/io/unityfoundation/dds/permissions/manager/model/topicset/TopicSetService.java @@ -116,7 +116,11 @@ public TopicSetDTO findById(Long topicSetId) { checkExistenceAndAuthorization(topicSetOptional); - return createDTO(topicSetOptional.get()); + TopicSetDTO topicSetDTO = createDTO(topicSetOptional.get()); + List admins = groupUserService.getAllTopicAdminsOfGroup(topicSetOptional.get().getId()); + topicSetDTO.setAdmins(admins); + + return topicSetDTO; } // POST /topic-set diff --git a/app/src/main/java/io/unityfoundation/dds/permissions/manager/model/topicset/dto/TopicSetDTO.java b/app/src/main/java/io/unityfoundation/dds/permissions/manager/model/topicset/dto/TopicSetDTO.java index 1f2a3169..bc032e4d 100644 --- a/app/src/main/java/io/unityfoundation/dds/permissions/manager/model/topicset/dto/TopicSetDTO.java +++ b/app/src/main/java/io/unityfoundation/dds/permissions/manager/model/topicset/dto/TopicSetDTO.java @@ -18,6 +18,7 @@ import io.unityfoundation.dds.permissions.manager.model.EntityDTO; import java.time.Instant; +import java.util.List; import java.util.Map; import java.util.Set; @@ -29,6 +30,7 @@ public class TopicSetDTO implements EntityDTO { private Long groupId; private String groupName; private Set> topics; + private List admins; @JsonFormat(shape = JsonFormat.Shape.STRING) private Instant dateCreated; @@ -86,6 +88,14 @@ public void setTopics(Set> topics) { this.topics = topics; } + public List getAdmins() { + return admins; + } + + public void setAdmins(List admins) { + this.admins = admins; + } + public Instant getDateCreated() { return dateCreated; }