Skip to content

Commit

Permalink
Added: Human Readable Bridgehead for frontend dto
Browse files Browse the repository at this point in the history
  • Loading branch information
djuarezgf committed Nov 8, 2024
1 parent 21d6127 commit a8a5967
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 14 deletions.
7 changes: 5 additions & 2 deletions src/main/java/de/samply/document/DocumentService.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public class DocumentService {
private final String applicationFormFile;
private final String timestampFormat;
private final SessionUser sessionUser;
private final DtoFactory dtoFactory;

public DocumentService(NotificationService notificationService,
ProjectDocumentRepository projectDocumentRepository,
Expand All @@ -45,7 +46,8 @@ public DocumentService(NotificationService notificationService,
@Value(ProjectManagerConst.PUBLIC_DOCUMENTS_DIRECTORY_SV) String publicDocumentsDirectory,
@Value(ProjectManagerConst.APPLICATION_FORM_FILENAME_SV) String applicationFormFile,
@Value(ProjectManagerConst.PROJECT_DOCUMENTS_DIRECTORY_TIMESTAMP_FORMAT_SV) String timestampFormat,
SessionUser sessionUser) throws IOException {
SessionUser sessionUser,
DtoFactory dtoFactory) throws IOException {
this.notificationService = notificationService;
this.projectDocumentRepository = projectDocumentRepository;
this.projectRepository = projectRepository;
Expand All @@ -54,6 +56,7 @@ public DocumentService(NotificationService notificationService,
this.applicationFormFile = applicationFormFile;
this.timestampFormat = timestampFormat;
this.sessionUser = sessionUser;
this.dtoFactory = dtoFactory;
}

public void uploadDocument(String projectCode, Optional<String> bridgeheadOptional, MultipartFile document, DocumentType documentType, Optional<String> labelOptional) throws DocumentServiceException {
Expand Down Expand Up @@ -206,7 +209,7 @@ public List<de.samply.frontend.dto.ProjectDocument> fetchPublications(String pro
}

private List<de.samply.frontend.dto.ProjectDocument> convertToDto(List<ProjectDocument> projectDocumentList) {
return projectDocumentList.stream().map(DtoFactory::convert).toList();
return projectDocumentList.stream().map(dtoFactory::convert).toList();
}

public List<de.samply.frontend.dto.ProjectDocument> fetchOtherDocuments(String projectCode, Optional<String> bridgehead) {
Expand Down
20 changes: 14 additions & 6 deletions src/main/java/de/samply/frontend/dto/DtoFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,14 @@ public static de.samply.db.model.Project convert(@NotNull Project projectConfigu
return project;
}

public static Notification convert(@NotNull de.samply.db.model.Notification notification, Supplier<NotificationUserAction> userActionSupplier) {
public Notification convert(@NotNull de.samply.db.model.Notification notification, Supplier<NotificationUserAction> userActionSupplier) {
return new Notification(
notification.getId(),
notification.getEmail(),
notification.getTimestamp(),
notification.getProject().getCode(),
notification.getBridgehead(),
fetchHumanReadableBridgehead(notification.getBridgehead()),
notification.getOperationType(),
notification.getDetails(),
notification.getError(),
Expand All @@ -83,13 +84,14 @@ public static Notification convert(@NotNull de.samply.db.model.Notification noti
);
}

public static ProjectDocument convert(@NotNull de.samply.db.model.ProjectDocument projectDocument) {
public ProjectDocument convert(@NotNull de.samply.db.model.ProjectDocument projectDocument) {
return new ProjectDocument(
projectDocument.getProject().getCode(),
projectDocument.getOriginalFilename(),
projectDocument.getUrl(),
projectDocument.getCreatedAt(),
projectDocument.getBridgehead(),
fetchHumanReadableBridgehead(projectDocument.getBridgehead()),
projectDocument.getCreatorEmail(),
projectDocument.getLabel(),
projectDocument.getDocumentType()
Expand All @@ -108,23 +110,29 @@ public ProjectBridgehead convert(@NotNull de.samply.db.model.ProjectBridgehead p
}

public String fetchHumanReadableBridgehead(@NotNull de.samply.db.model.ProjectBridgehead projectBridgehead) {
Optional<String> humanReadable = bridgeheadConfiguration.getHumanReadable(projectBridgehead.getBridgehead());
return (humanReadable.isPresent()) ? humanReadable.get() : projectBridgehead.getBridgehead();
return fetchHumanReadableBridgehead(projectBridgehead.getBridgehead());
}

public static User convert(@NotNull de.samply.db.model.ProjectBridgeheadUser projectBridgeheadUser) {
public String fetchHumanReadableBridgehead(@NotNull String bridgehead) {
Optional<String> humanReadable = bridgeheadConfiguration.getHumanReadable(bridgehead);
return (humanReadable.isPresent()) ? humanReadable.get() : bridgehead;
}

public User convert(@NotNull de.samply.db.model.ProjectBridgeheadUser projectBridgeheadUser) {
return new User(
projectBridgeheadUser.getEmail(),
projectBridgeheadUser.getProjectBridgehead().getBridgehead(),
fetchHumanReadableBridgehead(projectBridgeheadUser.getProjectBridgehead()),
projectBridgeheadUser.getProjectRole(),
projectBridgeheadUser.getProjectState()
);
}

public static User convertFilteringProjectRoleAndState(@NotNull de.samply.db.model.ProjectBridgeheadUser projectBridgeheadUser) {
public User convertFilteringProjectRoleAndState(@NotNull de.samply.db.model.ProjectBridgeheadUser projectBridgeheadUser) {
return new User(
projectBridgeheadUser.getEmail(),
projectBridgeheadUser.getProjectBridgehead().getBridgehead(),
fetchHumanReadableBridgehead(projectBridgeheadUser.getProjectBridgehead()),
null,
null
);
Expand Down
1 change: 1 addition & 0 deletions src/main/java/de/samply/frontend/dto/Notification.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public record Notification(
Instant timestamp,
String projectCode,
String bridgehead,
String humanReadableBridgehead,
OperationType operationType,
String details,
String error,
Expand Down
1 change: 1 addition & 0 deletions src/main/java/de/samply/frontend/dto/ProjectDocument.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public record ProjectDocument(
String url,
Instant createdAt,
String bridgehead,
String humanReadableBridgehead,
String creatorEmail,
String label,
DocumentType type
Expand Down
1 change: 1 addition & 0 deletions src/main/java/de/samply/frontend/dto/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
public record User(
String email,
String bridgehead,
String humanReadableBridgehead,
ProjectRole projectRole,
UserProjectState projectState
) {
Expand Down
7 changes: 5 additions & 2 deletions src/main/java/de/samply/notification/NotificationService.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,18 @@ public class NotificationService {
private final NotificationUserActionRepository notificationUserActionRepository;
private final ProjectRepository projectRepository;
private final SessionUser sessionUser;
private final DtoFactory dtoFactory;

public NotificationService(NotificationRepository notificationRepository,
NotificationUserActionRepository notificationUserActionRepository,
ProjectRepository projectRepository,
SessionUser sessionUser) {
SessionUser sessionUser,
DtoFactory dtoFactory) {
this.notificationRepository = notificationRepository;
this.notificationUserActionRepository = notificationUserActionRepository;
this.projectRepository = projectRepository;
this.sessionUser = sessionUser;
this.dtoFactory = dtoFactory;
}

public void createNotification(@NotNull String projectCode, String bridgehead, String email,
Expand Down Expand Up @@ -79,7 +82,7 @@ public List<de.samply.frontend.dto.Notification> fetchUserVisibleNotifications(
}
});
return result.stream().map(notification ->
DtoFactory.convert(notification, () -> fetchNotificationUserAction(notification))).toList();
dtoFactory.convert(notification, () -> fetchNotificationUserAction(notification))).toList();
}

private List<String> fetchUserVisibleBridgeheads(Optional<String> requestedBridgehead) {
Expand Down
11 changes: 7 additions & 4 deletions src/main/java/de/samply/user/UserService.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public class UserService {
private final ProjectBridgeheadRepository projectBridgeheadRepository;
private final SessionUser sessionUser;
private final OrganisationRoleToProjectRoleMapper organisationRoleToProjectRoleMapper;
private final DtoFactory dtoFactory;

public UserService(NotificationService notificationService,
BridgeheadAdminUserRepository bridgeheadAdminUserRepository,
Expand All @@ -41,7 +42,8 @@ public UserService(NotificationService notificationService,
ProjectRepository projectRepository,
ProjectBridgeheadRepository projectBridgeheadRepository,
SessionUser sessionUser,
OrganisationRoleToProjectRoleMapper organisationRoleToProjectRoleMapper) {
OrganisationRoleToProjectRoleMapper organisationRoleToProjectRoleMapper,
DtoFactory dtoFactory) {
this.notificationService = notificationService;
this.bridgeheadAdminUserRepository = bridgeheadAdminUserRepository;
this.projectManagerAdminUserRepository = projectManagerAdminUserRepository;
Expand All @@ -50,6 +52,7 @@ public UserService(NotificationService notificationService,
this.projectBridgeheadRepository = projectBridgeheadRepository;
this.sessionUser = sessionUser;
this.organisationRoleToProjectRoleMapper = organisationRoleToProjectRoleMapper;
this.dtoFactory = dtoFactory;
}

public BridgeheadAdminUser createBridgeheadAdminUserIfNotExists(@NotNull String email, @NotNull String bridgehead) {
Expand Down Expand Up @@ -146,8 +149,8 @@ private void changeProjectState(@NotNull String projectCode, @NotNull String bri
}

public Set<User> fetchUsersForAutocomplete(@NotNull String projectCode, @NotNull String partialEmail, @NotNull String bridgehead) {
Set<User> allUsers = projectBridgeheadUserRepository.getDistinctByEmailContainingAndProjectBridgehead_Bridgehead(partialEmail, bridgehead).stream().map(DtoFactory::convertFilteringProjectRoleAndState).collect(Collectors.toSet());
Set<User> alreadySetUsers = projectBridgeheadUserRepository.getDistinctByEmailContainingAndProjectBridgehead_BridgeheadAndUserAlreadySetForThisProjectInThisRole(partialEmail, bridgehead, projectCode).stream().map(DtoFactory::convertFilteringProjectRoleAndState).collect(Collectors.toSet());
Set<User> allUsers = projectBridgeheadUserRepository.getDistinctByEmailContainingAndProjectBridgehead_Bridgehead(partialEmail, bridgehead).stream().map(dtoFactory::convertFilteringProjectRoleAndState).collect(Collectors.toSet());
Set<User> alreadySetUsers = projectBridgeheadUserRepository.getDistinctByEmailContainingAndProjectBridgehead_BridgeheadAndUserAlreadySetForThisProjectInThisRole(partialEmail, bridgehead, projectCode).stream().map(dtoFactory::convertFilteringProjectRoleAndState).collect(Collectors.toSet());
allUsers.removeAll(alreadySetUsers);
return allUsers;
}
Expand All @@ -162,7 +165,7 @@ public Set<User> fetchProjectUsers(@NotNull String projectCode, @NotNull String
case FINAL ->
this.projectBridgeheadUserRepository.getDistinctByProjectRoleAndProjectBridgehead(ProjectRole.FINAL, projectBridgehead);
default -> new ArrayList<ProjectBridgeheadUser>();
}).stream().map(DtoFactory::convert).collect(Collectors.toSet());
}).stream().map(dtoFactory::convert).collect(Collectors.toSet());
}

public boolean existInvatedUsers(@NotNull String projectCode, @NotNull String bridgehead) throws UserServiceException {
Expand Down

0 comments on commit a8a5967

Please sign in to comment.