Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added: User Autocomplete #12

Merged
merged 1 commit into from
Feb 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## [0.0.1 - 2024-02-09]
## [0.0.1 - 2024-02-12]
### Added
- First version of the project
- Spring Application
Expand Down Expand Up @@ -97,3 +97,4 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- Allow required headers
- Project Constraints: Project Type
- Email template for Accept/Reject/Request changes in project
- User Autocomplete
3 changes: 3 additions & 0 deletions src/main/java/de/samply/app/ProjectManagerConst.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ public class ProjectManagerConst {
public final static String FETCH_PROJECT_STATES_ACTION = "FETCH_PROJECT_STATES";
public final static String FETCH_ALL_REGISTERED_BRIDGEHEADS_ACTION = "FETCH_ALL_REGISTERED_BRIDGEHEADS";
public final static String FETCH_DATASHIELD_STATUS_ACTION = "FETCH_DATASHIELD_STATUS";
public final static String FETCH_USERS_FOR_AUTOCOMPLETE_ACTION = "FETCH_USERS_FOR_AUTOCOMPLETE";


// REST Services
Expand Down Expand Up @@ -132,12 +133,14 @@ public class ProjectManagerConst {
public final static String FETCH_NOTIFICATIONS = "/notifications";
public final static String SET_NOTIFICATION_AS_READ = "/read-notification";
public final static String FETCH_ALL_REGISTERED_BRIDGEHEADS = "/bridgeheads";
public final static String FETCH_USERS_FOR_AUTOCOMPLETE = "/autocomplete-users";

// REST Parameters
public final static String PROJECT_CODE = "project-code";
public final static String NOTIFICATION_ID = "notification-id";
public final static String BRIDGEHEAD = "bridgehead";
public final static String BRIDGEHEADS = "bridgeheads";
public final static String PARTIAL_EMAIL = "partial-email";
public final static String SITE = "site";
public final static String EMAIL = "email";
public final static String QUERY_FORMAT = "query-format";
Expand Down
15 changes: 15 additions & 0 deletions src/main/java/de/samply/app/ProjectManagerController.java
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ public ResponseEntity<String> createQueryAndDesignProject(
) throws ProjectEventActionsException {
String queryCode = this.queryService.createQuery(
query, queryFormat, label, description, outputFormat, templateId, humanReadable, explorerUrl, queryContext);
// Explorer Ids / BK
String projectCode = this.projectEventService.draft(bridgeheads, queryCode, projectType);
return convertToResponseEntity(() -> this.frontendService.fetchUrl(
ProjectManagerConst.PROJECT_VIEW_SITE,
Expand Down Expand Up @@ -880,6 +881,20 @@ public ResponseEntity<Resource> fetchAllRegisteredBridgeheads() {
return convertToResponseEntity(() -> bridgeheadConfiguration.getRegisteredBridgeheads());
}

@RoleConstraints(organisationRoles = {OrganisationRole.PROJECT_MANAGER_ADMIN})
@StateConstraints(projectStates = {ProjectState.DEVELOP, ProjectState.PILOT, ProjectState.FINAL})
@FrontendSiteModule(site = ProjectManagerConst.PROJECT_VIEW_SITE, module = ProjectManagerConst.USER_MODULE)
@FrontendAction(action = ProjectManagerConst.FETCH_USERS_FOR_AUTOCOMPLETE_ACTION)
@GetMapping(value = ProjectManagerConst.FETCH_USERS_FOR_AUTOCOMPLETE)
public ResponseEntity<String> fetchUsersForAutocomplete(
// Project Code Required for state constraints
@ProjectCode @RequestParam(name = ProjectManagerConst.PROJECT_CODE) String projectCode,
@Bridgehead @RequestParam(name = ProjectManagerConst.BRIDGEHEAD) String bridgehead,
@RequestParam(name = ProjectManagerConst.PARTIAL_EMAIL) String partialEmail
) {
return convertToResponseEntity(() -> this.userService.fetchUsersForAutocomplete(partialEmail, bridgehead));
}


private ResponseEntity convertToResponseEntity(RunnableWithException runnable) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,6 @@ public interface ProjectBridgeheadUserRepository extends JpaRepository<ProjectBr
@Query("SELECT DISTINCT pbu FROM ProjectBridgeheadUser pbu WHERE pbu.projectBridgehead.project.type = :projectType AND pbu.projectBridgehead.project.state NOT IN :projectStates")
List<ProjectBridgeheadUser> getByProjectTypeAndNotProjectState(ProjectType projectType, Set<ProjectState> projectStates);

List<ProjectBridgeheadUser> getByEmailContainingAndProjectBridgehead_Bridgehead(String email, String bridgehead);

}
7 changes: 7 additions & 0 deletions src/main/java/de/samply/frontend/dto/DtoFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,11 @@ public static ProjectBridgehead convert(@NotNull de.samply.db.model.ProjectBridg
);
}

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

}
7 changes: 7 additions & 0 deletions src/main/java/de/samply/frontend/dto/User.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package de.samply.frontend.dto;

public record User(
String email,
String bridgehead
) {
}
7 changes: 7 additions & 0 deletions src/main/java/de/samply/user/UserService.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import de.samply.db.model.*;
import de.samply.db.repository.*;
import de.samply.frontend.dto.DtoFactory;
import de.samply.frontend.dto.User;
import de.samply.notification.NotificationService;
import de.samply.notification.OperationType;
import de.samply.project.state.UserProjectState;
Expand All @@ -11,6 +13,7 @@
import org.springframework.stereotype.Service;

import java.time.Instant;
import java.util.List;
import java.util.Optional;

@Service
Expand Down Expand Up @@ -139,4 +142,8 @@ private void changeProjectState(@NotNull String projectCode, @NotNull String bri
"Set project bridgehead user evaluation to " + state, null, null);
}

public List<User> fetchUsersForAutocomplete(@NotNull String partialEmail, @NotNull String bridgehead) {
return projectBridgeheadUserRepository.getByEmailContainingAndProjectBridgehead_Bridgehead(partialEmail, bridgehead).stream().map(DtoFactory::convert).toList();
}

}
Loading