From d962543cc6a1f40fd91fc073b4e434c4392c6da7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Pil=C3=A1r?= <xpilar3@fi.muni.cz> Date: Wed, 24 Feb 2021 14:17:05 +0100 Subject: [PATCH] UserRef renamed to User. --- .../domain/{UserRef.java => User.java} | 30 ++++++++-------- .../phase/questions/QuestionAnswer.java | 2 -- .../domain/training/TrainingDefinition.java | 14 ++++---- .../domain/training/TrainingInstance.java | 20 +++++------ .../adaptive/domain/training/TrainingRun.java | 10 +++--- .../adaptive/facade/ExportImportFacade.java | 4 +-- .../facade/TrainingDefinitionFacade.java | 16 ++++----- .../facade/TrainingInstanceFacade.java | 16 ++++----- .../mapping/mapstruct/UserRefMapper.java | 28 +++++++-------- .../repository/UserRefRepository.java | 16 ++++----- .../TrainingDefinitionRepositoryImpl.java | 4 +-- .../TrainingInstanceRepositoryImpl.java | 4 +-- .../adaptive/service/UserService.java | 34 ++++++------------- .../service/api/UserManagementServiceApi.java | 4 +-- .../training/TrainingDefinitionService.java | 6 ++-- .../training/TrainingInstanceService.java | 12 +++---- .../service/training/TrainingRunService.java | 6 ++-- .../V1__db_adaptive_trainings_schema.sql | 30 ++++++++-------- .../V2__db_adaptive_trainings_sequences.sql | 2 +- 19 files changed, 121 insertions(+), 137 deletions(-) rename src/main/java/cz/muni/ics/kypo/training/adaptive/domain/{UserRef.java => User.java} (84%) diff --git a/src/main/java/cz/muni/ics/kypo/training/adaptive/domain/UserRef.java b/src/main/java/cz/muni/ics/kypo/training/adaptive/domain/User.java similarity index 84% rename from src/main/java/cz/muni/ics/kypo/training/adaptive/domain/UserRef.java rename to src/main/java/cz/muni/ics/kypo/training/adaptive/domain/User.java index ab89e57c..0f124b11 100644 --- a/src/main/java/cz/muni/ics/kypo/training/adaptive/domain/UserRef.java +++ b/src/main/java/cz/muni/ics/kypo/training/adaptive/domain/User.java @@ -13,30 +13,30 @@ import java.util.Set; * Class representing DB reference for user and training instances and definition they can access */ @Entity -@Table(name = "user_ref", uniqueConstraints = @UniqueConstraint(columnNames = {"user_ref_id"})) +@Table(name = "user", uniqueConstraints = @UniqueConstraint(columnNames = {"user_ref_id"})) @NamedQueries({ @NamedQuery( - name = "UserRef.findUsers", - query = "SELECT ur FROM UserRef ur WHERE ur.userRefId IN :userRefId" + name = "User.findUsers", + query = "SELECT u FROM User u WHERE u.userRefId IN :userRefId" ), @NamedQuery( - name = "UserRef.findUserByUserRefId", - query = "SELECT ur FROM UserRef ur WHERE ur.userRefId = :userRefId" + name = "User.findUserByUserRefId", + query = "SELECT u FROM User u WHERE u.userRefId = :userRefId" ), @NamedQuery( - name = "UserRef.findParticipantsRefByTrainingInstanceId", + name = "User.findParticipantsRefByTrainingInstanceId", query = "SELECT pr.userRefId FROM TrainingRun tr " + "INNER JOIN tr.participantRef pr " + "INNER JOIN tr.trainingInstance ti " + "WHERE ti.id = :trainingInstanceId" ) }) -public class UserRef { +public class User { @Id - @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "userRefGenerator") - @SequenceGenerator(name = "userRefGenerator", sequenceName = "user_ref_seq") - @Column(name = "id", nullable = false, unique = true) + @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "userGenerator") + @SequenceGenerator(name = "userGenerator", sequenceName = "user_seq") + @Column(name = "user_id", nullable = false, unique = true) private Long id; @Column(name = "user_ref_id", nullable = false) private Long userRefId; @@ -48,14 +48,14 @@ public class UserRef { /** * Instantiates a new user reference */ - public UserRef() { + public User() { } /** * Instantiates a new user reference * @param userRefId id of the user stored in user management service */ - public UserRef(Long userRefId) { + public User(Long userRefId) { this.userRefId = userRefId; } @@ -170,9 +170,9 @@ public class UserRef { @Override public boolean equals(Object o) { if (this == o) return true; - if (!(o instanceof UserRef)) return false; - UserRef userRef = (UserRef) o; - return Objects.equals(getUserRefId(), userRef.getUserRefId()); + if (!(o instanceof User)) return false; + User user = (User) o; + return Objects.equals(getUserRefId(), user.getUserRefId()); } @Override diff --git a/src/main/java/cz/muni/ics/kypo/training/adaptive/domain/phase/questions/QuestionAnswer.java b/src/main/java/cz/muni/ics/kypo/training/adaptive/domain/phase/questions/QuestionAnswer.java index 1e5a94ba..e70f6274 100644 --- a/src/main/java/cz/muni/ics/kypo/training/adaptive/domain/phase/questions/QuestionAnswer.java +++ b/src/main/java/cz/muni/ics/kypo/training/adaptive/domain/phase/questions/QuestionAnswer.java @@ -1,7 +1,5 @@ package cz.muni.ics.kypo.training.adaptive.domain.phase.questions; -import cz.muni.ics.kypo.training.adaptive.domain.UserRef; - import javax.persistence.EmbeddedId; import javax.persistence.Entity; import javax.persistence.Table; diff --git a/src/main/java/cz/muni/ics/kypo/training/adaptive/domain/training/TrainingDefinition.java b/src/main/java/cz/muni/ics/kypo/training/adaptive/domain/training/TrainingDefinition.java index 760f0eeb..bd64521a 100644 --- a/src/main/java/cz/muni/ics/kypo/training/adaptive/domain/training/TrainingDefinition.java +++ b/src/main/java/cz/muni/ics/kypo/training/adaptive/domain/training/TrainingDefinition.java @@ -1,6 +1,6 @@ package cz.muni.ics.kypo.training.adaptive.domain.training; -import cz.muni.ics.kypo.training.adaptive.domain.UserRef; +import cz.muni.ics.kypo.training.adaptive.domain.User; import cz.muni.ics.kypo.training.adaptive.enums.TDState; import javax.persistence.*; @@ -44,11 +44,11 @@ public class TrainingDefinition { @Enumerated(EnumType.STRING) private TDState state; @ManyToMany(fetch = FetchType.LAZY, cascade = CascadeType.PERSIST) - @JoinTable(name = "training_definition_user_ref", + @JoinTable(name = "training_definition_user", joinColumns = @JoinColumn(name = "training_definition_id"), - inverseJoinColumns = @JoinColumn(name = "user_ref_id") + inverseJoinColumns = @JoinColumn(name = "user_id") ) - private Set<UserRef> authors = new HashSet<>(); + private Set<User> authors = new HashSet<>(); @Column(name = "show_stepper_bar", nullable = false) private boolean showStepperBar; @Column(name = "estimated_duration", nullable = true) @@ -173,7 +173,7 @@ public class TrainingDefinition { * * @return the authors */ - public Set<UserRef> getAuthors() { + public Set<User> getAuthors() { return Collections.unmodifiableSet(authors); } @@ -182,7 +182,7 @@ public class TrainingDefinition { * * @param authors the authors */ - public void setAuthors(Set<UserRef> authors) { + public void setAuthors(Set<User> authors) { this.authors = authors; } @@ -191,7 +191,7 @@ public class TrainingDefinition { * * @param authorRef the author ref */ - public void addAuthor(UserRef authorRef) { + public void addAuthor(User authorRef) { this.authors.add(authorRef); authorRef.addTrainingDefinition(this); } diff --git a/src/main/java/cz/muni/ics/kypo/training/adaptive/domain/training/TrainingInstance.java b/src/main/java/cz/muni/ics/kypo/training/adaptive/domain/training/TrainingInstance.java index e69604c4..17250ec7 100644 --- a/src/main/java/cz/muni/ics/kypo/training/adaptive/domain/training/TrainingInstance.java +++ b/src/main/java/cz/muni/ics/kypo/training/adaptive/domain/training/TrainingInstance.java @@ -1,6 +1,6 @@ package cz.muni.ics.kypo.training.adaptive.domain.training; -import cz.muni.ics.kypo.training.adaptive.domain.UserRef; +import cz.muni.ics.kypo.training.adaptive.domain.User; import javax.persistence.*; import java.time.LocalDateTime; @@ -90,11 +90,11 @@ public class TrainingInstance { @JoinColumn(name = "training_definition_id") private TrainingDefinition trainingDefinition; @ManyToMany(fetch = FetchType.LAZY, cascade = CascadeType.PERSIST) - @JoinTable(name = "training_instance_user_ref", + @JoinTable(name = "training_instance_user", joinColumns = @JoinColumn(name = "training_instance_id"), - inverseJoinColumns = @JoinColumn(name = "user_ref_id") + inverseJoinColumns = @JoinColumn(name = "user_id") ) - private Set<UserRef> organizers = new HashSet<>(); + private Set<User> organizers = new HashSet<>(); /** * Gets unique identification number of Training instance @@ -227,7 +227,7 @@ public class TrainingInstance { * * @return the organizers */ - public Set<UserRef> getOrganizers() { + public Set<User> getOrganizers() { return Collections.unmodifiableSet(organizers); } @@ -236,18 +236,18 @@ public class TrainingInstance { * * @param organizers the organizers */ - public void setOrganizers(Set<UserRef> organizers) { + public void setOrganizers(Set<User> organizers) { this.organizers = organizers; } /** * Adds user to the set of users that can make changes to the Training instance * - * @param userRef the user ref + * @param user the user ref */ - public void addOrganizer(UserRef userRef) { - this.organizers.add(userRef); - userRef.addTrainingInstance(this); + public void addOrganizer(User user) { + this.organizers.add(user); + user.addTrainingInstance(this); } /** diff --git a/src/main/java/cz/muni/ics/kypo/training/adaptive/domain/training/TrainingRun.java b/src/main/java/cz/muni/ics/kypo/training/adaptive/domain/training/TrainingRun.java index 7f0e4c91..21941ef3 100644 --- a/src/main/java/cz/muni/ics/kypo/training/adaptive/domain/training/TrainingRun.java +++ b/src/main/java/cz/muni/ics/kypo/training/adaptive/domain/training/TrainingRun.java @@ -1,6 +1,6 @@ package cz.muni.ics.kypo.training.adaptive.domain.training; -import cz.muni.ics.kypo.training.adaptive.domain.UserRef; +import cz.muni.ics.kypo.training.adaptive.domain.User; import cz.muni.ics.kypo.training.adaptive.domain.phase.AbstractPhase; import cz.muni.ics.kypo.training.adaptive.domain.phase.InfoPhase; import cz.muni.ics.kypo.training.adaptive.domain.phase.Task; @@ -122,8 +122,8 @@ public class TrainingRun { @Column(name = "sandbox_instance_ref_id") private Long sandboxInstanceRefId; @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "user_ref_id", nullable = false) - private UserRef participantRef; + @JoinColumn(name = "user_id", nullable = false) + private User participantRef; @Column(name = "phase_answered") private boolean phaseAnswered; @Column(name = "previous_sandbox_instance_ref_id") @@ -309,7 +309,7 @@ public class TrainingRun { * * @return the participant ref */ - public UserRef getParticipantRef() { + public User getParticipantRef() { return participantRef; } @@ -318,7 +318,7 @@ public class TrainingRun { * * @param participantRef the participant ref */ - public void setParticipantRef(UserRef participantRef) { + public void setParticipantRef(User participantRef) { this.participantRef = participantRef; } diff --git a/src/main/java/cz/muni/ics/kypo/training/adaptive/facade/ExportImportFacade.java b/src/main/java/cz/muni/ics/kypo/training/adaptive/facade/ExportImportFacade.java index df6210bd..26cc6d17 100644 --- a/src/main/java/cz/muni/ics/kypo/training/adaptive/facade/ExportImportFacade.java +++ b/src/main/java/cz/muni/ics/kypo/training/adaptive/facade/ExportImportFacade.java @@ -8,7 +8,7 @@ import cz.muni.ics.kypo.training.adaptive.annotations.security.IsDesignerOrOrgan import cz.muni.ics.kypo.training.adaptive.annotations.security.IsOrganizerOrAdmin; import cz.muni.ics.kypo.training.adaptive.annotations.transactions.TransactionalRO; import cz.muni.ics.kypo.training.adaptive.annotations.transactions.TransactionalWO; -import cz.muni.ics.kypo.training.adaptive.domain.UserRef; +import cz.muni.ics.kypo.training.adaptive.domain.User; import cz.muni.ics.kypo.training.adaptive.domain.phase.AbstractPhase; import cz.muni.ics.kypo.training.adaptive.domain.phase.QuestionnairePhase; import cz.muni.ics.kypo.training.adaptive.domain.training.TrainingDefinition; @@ -204,7 +204,7 @@ public class ExportImportFacade { TrainingInstanceArchiveDTO archivedInstance = exportImportMapper.mapToDTO(trainingInstance); archivedInstance.setDefinitionId(trainingInstance.getTrainingDefinition().getId()); Set<Long> organizersRefIds = trainingInstance.getOrganizers().stream() - .map(UserRef::getUserRefId) + .map(User::getUserRefId) .collect(Collectors.toSet()); archivedInstance.setOrganizersRefIds(new HashSet<>(organizersRefIds)); diff --git a/src/main/java/cz/muni/ics/kypo/training/adaptive/facade/TrainingDefinitionFacade.java b/src/main/java/cz/muni/ics/kypo/training/adaptive/facade/TrainingDefinitionFacade.java index 2bbb7f45..ecb0fd79 100644 --- a/src/main/java/cz/muni/ics/kypo/training/adaptive/facade/TrainingDefinitionFacade.java +++ b/src/main/java/cz/muni/ics/kypo/training/adaptive/facade/TrainingDefinitionFacade.java @@ -6,7 +6,7 @@ import cz.muni.ics.kypo.training.adaptive.annotations.security.IsDesignerOrOrgan import cz.muni.ics.kypo.training.adaptive.annotations.security.IsOrganizerOrAdmin; import cz.muni.ics.kypo.training.adaptive.annotations.transactions.TransactionalRO; import cz.muni.ics.kypo.training.adaptive.annotations.transactions.TransactionalWO; -import cz.muni.ics.kypo.training.adaptive.domain.UserRef; +import cz.muni.ics.kypo.training.adaptive.domain.User; import cz.muni.ics.kypo.training.adaptive.domain.phase.AbstractPhase; import cz.muni.ics.kypo.training.adaptive.domain.training.TrainingDefinition; import cz.muni.ics.kypo.training.adaptive.domain.training.TrainingInstance; @@ -183,10 +183,10 @@ public class TrainingDefinitionFacade { trainingDefinitionService.update(mappedTrainingDefinition); } - private UserRef createUserRefFromDTO(UserRefDTO userToBeCreated) { - UserRef userRef = new UserRef(); - userRef.setUserRefId(userToBeCreated.getUserRefId()); - return userRef; + private User createUserRefFromDTO(UserRefDTO userToBeCreated) { + User user = new User(); + user.setUserRefId(userToBeCreated.getUserRefId()); + return user; } /** @@ -266,7 +266,7 @@ public class TrainingDefinitionFacade { public PageResultResource<UserRefDTO> getAuthors(Long trainingDefinitionId, Pageable pageable, String givenName, String familyName) { TrainingDefinition trainingDefinition = trainingDefinitionService.findById(trainingDefinitionId); return userManagementServiceApi.getUserRefDTOsByUserIds(trainingDefinition.getAuthors().stream() - .map(UserRef::getUserRefId) + .map(User::getUserRefId) .collect(Collectors.toSet()), pageable, givenName, familyName); } @@ -285,7 +285,7 @@ public class TrainingDefinitionFacade { public PageResultResource<UserRefDTO> getDesignersNotInGivenTrainingDefinition(Long trainingDefinitionId, Pageable pageable, String givenName, String familyName) { TrainingDefinition trainingDefinition = trainingDefinitionService.findById(trainingDefinitionId); Set<Long> excludedUsers = trainingDefinition.getAuthors().stream() - .map(UserRef::getUserRefId) + .map(User::getUserRefId) .collect(Collectors.toSet()); return userManagementServiceApi.getUserRefsByRoleAndNotWithIds(RoleType.ROLE_TRAINING_DESIGNER, excludedUsers, pageable, givenName, familyName); } @@ -317,7 +317,7 @@ public class TrainingDefinitionFacade { do { authors = userManagementServiceApi.getUserRefDTOsByUserIds(userRefIds, PageRequest.of(page, 999), null, null); Set<Long> actualAuthorsIds = trainingDefinition.getAuthors().stream() - .map(UserRef::getUserRefId) + .map(User::getUserRefId) .collect(Collectors.toSet()); page++; for (UserRefDTO author : authors.getContent()) { diff --git a/src/main/java/cz/muni/ics/kypo/training/adaptive/facade/TrainingInstanceFacade.java b/src/main/java/cz/muni/ics/kypo/training/adaptive/facade/TrainingInstanceFacade.java index 9064ff46..45b48114 100644 --- a/src/main/java/cz/muni/ics/kypo/training/adaptive/facade/TrainingInstanceFacade.java +++ b/src/main/java/cz/muni/ics/kypo/training/adaptive/facade/TrainingInstanceFacade.java @@ -4,7 +4,7 @@ import com.querydsl.core.types.Predicate; import cz.muni.ics.kypo.training.adaptive.annotations.security.IsOrganizerOrAdmin; import cz.muni.ics.kypo.training.adaptive.annotations.transactions.TransactionalRO; import cz.muni.ics.kypo.training.adaptive.annotations.transactions.TransactionalWO; -import cz.muni.ics.kypo.training.adaptive.domain.UserRef; +import cz.muni.ics.kypo.training.adaptive.domain.User; import cz.muni.ics.kypo.training.adaptive.domain.training.TrainingInstance; import cz.muni.ics.kypo.training.adaptive.domain.training.TrainingRun; import cz.muni.ics.kypo.training.adaptive.dto.UserRefDTO; @@ -165,7 +165,7 @@ public class TrainingInstanceFacade { do { organizers = userManagementServiceApi.getUserRefDTOsByUserIds(userRefIdsOfOrganizers, PageRequest.of(page, 999), null, null); Set<Long> actualOrganizersIds = trainingInstance.getOrganizers().stream() - .map(UserRef::getUserRefId) + .map(User::getUserRefId) .collect(Collectors.toSet()); page++; for (UserRefDTO organizer : organizers.getContent()) { @@ -181,10 +181,10 @@ public class TrainingInstanceFacade { } while (organizers.getPagination().getTotalPages() != page); } - private UserRef createUserRefFromDTO(UserRefDTO userToBeCreated) { - UserRef userRef = new UserRef(); - userRef.setUserRefId(userToBeCreated.getUserRefId()); - return userRef; + private User createUserRefFromDTO(UserRefDTO userToBeCreated) { + User user = new User(); + user.setUserRefId(userToBeCreated.getUserRefId()); + return user; } /** @@ -331,7 +331,7 @@ public class TrainingInstanceFacade { public PageResultResource<UserRefDTO> getOrganizersOfTrainingInstance(Long trainingInstanceId, Pageable pageable, String givenName, String familyName) { TrainingInstance trainingInstance = trainingInstanceService.findById(trainingInstanceId); return userManagementServiceApi.getUserRefDTOsByUserIds(trainingInstance.getOrganizers().stream() - .map(UserRef::getUserRefId) + .map(User::getUserRefId) .collect(Collectors.toSet()), pageable, givenName, familyName); } @@ -350,7 +350,7 @@ public class TrainingInstanceFacade { public PageResultResource<UserRefDTO> getOrganizersNotInGivenTrainingInstance(Long trainingInstanceId, Pageable pageable, String givenName, String familyName) { TrainingInstance trainingInstance = trainingInstanceService.findById(trainingInstanceId); Set<Long> excludedOrganizers = trainingInstance.getOrganizers().stream() - .map(UserRef::getUserRefId) + .map(User::getUserRefId) .collect(Collectors.toSet()); return userManagementServiceApi.getUserRefsByRoleAndNotWithIds(RoleType.ROLE_TRAINING_ORGANIZER, excludedOrganizers, pageable, givenName, familyName); } diff --git a/src/main/java/cz/muni/ics/kypo/training/adaptive/mapping/mapstruct/UserRefMapper.java b/src/main/java/cz/muni/ics/kypo/training/adaptive/mapping/mapstruct/UserRefMapper.java index bd878297..064ab87c 100644 --- a/src/main/java/cz/muni/ics/kypo/training/adaptive/mapping/mapstruct/UserRefMapper.java +++ b/src/main/java/cz/muni/ics/kypo/training/adaptive/mapping/mapstruct/UserRefMapper.java @@ -1,6 +1,6 @@ package cz.muni.ics.kypo.training.adaptive.mapping.mapstruct; -import cz.muni.ics.kypo.training.adaptive.domain.UserRef; +import cz.muni.ics.kypo.training.adaptive.domain.User; import cz.muni.ics.kypo.training.adaptive.dto.UserRefDTO; import cz.muni.ics.kypo.training.adaptive.dto.export.UserRefExportDTO; import cz.muni.ics.kypo.training.adaptive.dto.responses.PageResultResource; @@ -18,39 +18,39 @@ import java.util.*; @Mapper(componentModel = "spring", uses = {TrainingInstanceMapper.class}, unmappedTargetPolicy = ReportingPolicy.IGNORE) public interface UserRefMapper extends ParentMapper { - UserRef mapToEntity(UserRefDTO dto); + User mapToEntity(UserRefDTO dto); - UserRefDTO mapToDTO(UserRef entity); + UserRefDTO mapToDTO(User entity); - List<UserRef> mapToList(Collection<UserRefDTO> dtos); + List<User> mapToList(Collection<UserRefDTO> dtos); - List<UserRefDTO> mapToListDTO(Collection<UserRef> entities); + List<UserRefDTO> mapToListDTO(Collection<User> entities); - Set<UserRef> mapToSet(Collection<UserRefDTO> dtos); + Set<User> mapToSet(Collection<UserRefDTO> dtos); - Set<UserRefDTO> mapToSetDTO(Collection<UserRef> entities); + Set<UserRefDTO> mapToSetDTO(Collection<User> entities); - List<UserRefExportDTO> mapUserRefExportDTOToUserRefDTO(Collection<UserRefDTO> userRefDTOs); + List<UserRefExportDTO> mapUserRefExportDTOToUserRefDTO(Collection<UserRefDTO> userRefDTOS); - default Optional<UserRef> mapToOptional(UserRefDTO dto) { + default Optional<User> mapToOptional(UserRefDTO dto) { return Optional.ofNullable(mapToEntity(dto)); } - default Optional<UserRefDTO> mapToOptional(UserRef entity) { + default Optional<UserRefDTO> mapToOptional(User entity) { return Optional.ofNullable(mapToDTO(entity)); } - default Page<UserRefDTO> mapToPageDTO(Page<UserRef> objects) { + default Page<UserRefDTO> mapToPageDTO(Page<User> objects) { List<UserRefDTO> mapped = mapToListDTO(objects.getContent()); return new PageImpl<>(mapped, objects.getPageable(), mapped.size()); } - default Page<UserRef> mapToPage(Page<UserRefDTO> objects) { - List<UserRef> mapped = mapToList(objects.getContent()); + default Page<User> mapToPage(Page<UserRefDTO> objects) { + List<User> mapped = mapToList(objects.getContent()); return new PageImpl<>(mapped, objects.getPageable(), mapped.size()); } - default PageResultResource<UserRefDTO> mapToPageResultResource(Page<UserRef> objects) { + default PageResultResource<UserRefDTO> mapToPageResultResource(Page<User> objects) { List<UserRefDTO> mapped = new ArrayList<>(); objects.forEach(object -> mapped.add(mapToDTO(object))); return new PageResultResource<>(mapped, createPagination(objects)); diff --git a/src/main/java/cz/muni/ics/kypo/training/adaptive/repository/UserRefRepository.java b/src/main/java/cz/muni/ics/kypo/training/adaptive/repository/UserRefRepository.java index e8fe2b8b..c44943f6 100644 --- a/src/main/java/cz/muni/ics/kypo/training/adaptive/repository/UserRefRepository.java +++ b/src/main/java/cz/muni/ics/kypo/training/adaptive/repository/UserRefRepository.java @@ -1,6 +1,6 @@ package cz.muni.ics.kypo.training.adaptive.repository; -import cz.muni.ics.kypo.training.adaptive.domain.UserRef; +import cz.muni.ics.kypo.training.adaptive.domain.User; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.querydsl.QuerydslPredicateExecutor; import org.springframework.data.repository.query.Param; @@ -10,32 +10,32 @@ import java.util.Optional; import java.util.Set; /** - * The JPA repository interface to manage {@link UserRef} instances. + * The JPA repository interface to manage {@link User} instances. */ @Repository -public interface UserRefRepository extends JpaRepository<UserRef, Long>, QuerydslPredicateExecutor<UserRef> { +public interface UserRefRepository extends JpaRepository<User, Long>, QuerydslPredicateExecutor<User> { /** * Find all users by userRefIds. * * @param userRefId the user ref id - * @return the set of {@link UserRef} + * @return the set of {@link User} */ - Set<UserRef> findUsers(@Param("userRefId") Set<Long> userRefId); + Set<User> findUsers(@Param("userRefId") Set<Long> userRefId); /** * Find user by user ref id. * * @param userRefId the user id - * @return the {@link UserRef} + * @return the {@link User} */ - Optional<UserRef> findUserByUserRefId(@Param("userRefId") Long userRefId); + Optional<User> findUserByUserRefId(@Param("userRefId") Long userRefId); /** * Find all participants of given training instance. * * @param trainingInstanceId id of the training instance - * @return the {@link UserRef} + * @return the {@link User} */ Set<Long> findParticipantsRefByTrainingInstanceId(@Param("trainingInstanceId") Long trainingInstanceId); diff --git a/src/main/java/cz/muni/ics/kypo/training/adaptive/repository/training/TrainingDefinitionRepositoryImpl.java b/src/main/java/cz/muni/ics/kypo/training/adaptive/repository/training/TrainingDefinitionRepositoryImpl.java index cb3313a9..69f20045 100644 --- a/src/main/java/cz/muni/ics/kypo/training/adaptive/repository/training/TrainingDefinitionRepositoryImpl.java +++ b/src/main/java/cz/muni/ics/kypo/training/adaptive/repository/training/TrainingDefinitionRepositoryImpl.java @@ -3,7 +3,7 @@ package cz.muni.ics.kypo.training.adaptive.repository.training; import com.querydsl.core.types.Predicate; import com.querydsl.jpa.JPQLQuery; import com.querydsl.jpa.impl.JPAQueryFactory; -import cz.muni.ics.kypo.training.adaptive.domain.QUserRef; +import cz.muni.ics.kypo.training.adaptive.domain.QUser; import cz.muni.ics.kypo.training.adaptive.domain.training.QTrainingDefinition; import cz.muni.ics.kypo.training.adaptive.domain.training.TrainingDefinition; import org.springframework.data.domain.Page; @@ -39,7 +39,7 @@ public class TrainingDefinitionRepositoryImpl extends QuerydslRepositorySupport public Page<TrainingDefinition> findAll(Predicate predicate, Pageable pageable, Long loggedInUserId) { Objects.requireNonNull(loggedInUserId, "Input logged in user ID must not be null."); QTrainingDefinition trainingDefinition = QTrainingDefinition.trainingDefinition; - QUserRef authors = new QUserRef("authors"); + QUser authors = new QUser("authors"); JPQLQuery<TrainingDefinition> query = new JPAQueryFactory(entityManager).selectFrom(trainingDefinition).distinct() .leftJoin(trainingDefinition.authors, authors) diff --git a/src/main/java/cz/muni/ics/kypo/training/adaptive/repository/training/TrainingInstanceRepositoryImpl.java b/src/main/java/cz/muni/ics/kypo/training/adaptive/repository/training/TrainingInstanceRepositoryImpl.java index eeb6fa7d..5c0352ba 100644 --- a/src/main/java/cz/muni/ics/kypo/training/adaptive/repository/training/TrainingInstanceRepositoryImpl.java +++ b/src/main/java/cz/muni/ics/kypo/training/adaptive/repository/training/TrainingInstanceRepositoryImpl.java @@ -3,7 +3,7 @@ package cz.muni.ics.kypo.training.adaptive.repository.training; import com.querydsl.core.types.Predicate; import com.querydsl.jpa.JPQLQuery; import com.querydsl.jpa.impl.JPAQueryFactory; -import cz.muni.ics.kypo.training.adaptive.domain.QUserRef; +import cz.muni.ics.kypo.training.adaptive.domain.QUser; import cz.muni.ics.kypo.training.adaptive.domain.training.QTrainingInstance; import cz.muni.ics.kypo.training.adaptive.domain.training.TrainingInstance; import org.springframework.data.domain.Page; @@ -39,7 +39,7 @@ public class TrainingInstanceRepositoryImpl extends QuerydslRepositorySupport im public Page<TrainingInstance> findAll(Predicate predicate, Pageable pageable, Long loggedInUserId) { Objects.requireNonNull(loggedInUserId, "Input logged in user ID must not be null."); QTrainingInstance trainingInstance = QTrainingInstance.trainingInstance; - QUserRef organizers = new QUserRef("organizers"); + QUser organizers = new QUser("organizers"); JPQLQuery<TrainingInstance> query = new JPAQueryFactory(entityManager).selectFrom(trainingInstance).distinct() .leftJoin(trainingInstance.organizers, organizers) diff --git a/src/main/java/cz/muni/ics/kypo/training/adaptive/service/UserService.java b/src/main/java/cz/muni/ics/kypo/training/adaptive/service/UserService.java index 23d48fd7..e9ede232 100644 --- a/src/main/java/cz/muni/ics/kypo/training/adaptive/service/UserService.java +++ b/src/main/java/cz/muni/ics/kypo/training/adaptive/service/UserService.java @@ -1,28 +1,14 @@ package cz.muni.ics.kypo.training.adaptive.service; import cz.muni.ics.kypo.training.adaptive.annotations.transactions.TransactionalWO; -import cz.muni.ics.kypo.training.adaptive.domain.UserRef; -import cz.muni.ics.kypo.training.adaptive.dto.UserRefDTO; -import cz.muni.ics.kypo.training.adaptive.dto.responses.PageResultResource; -import cz.muni.ics.kypo.training.adaptive.enums.RoleType; -import cz.muni.ics.kypo.training.adaptive.exceptions.CustomWebClientException; +import cz.muni.ics.kypo.training.adaptive.domain.User; import cz.muni.ics.kypo.training.adaptive.exceptions.EntityErrorDetail; import cz.muni.ics.kypo.training.adaptive.exceptions.EntityNotFoundException; -import cz.muni.ics.kypo.training.adaptive.exceptions.MicroserviceApiException; import cz.muni.ics.kypo.training.adaptive.repository.UserRefRepository; import cz.muni.ics.kypo.training.adaptive.service.api.UserManagementServiceApi; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.core.ParameterizedTypeReference; -import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Service; -import org.springframework.util.StringUtils; -import org.springframework.web.reactive.function.client.WebClient; -import org.springframework.web.util.UriBuilder; - -import java.util.Collections; -import java.util.Set; /** * The type User service. @@ -50,24 +36,24 @@ public class UserService { * Finds specific User reference by login * * @param userRefId of wanted User reference - * @return {@link UserRef} with corresponding login + * @return {@link User} with corresponding login * @throws EntityNotFoundException UserRef was not found */ - public UserRef getUserByUserRefId(Long userRefId) { + public User getUserByUserRefId(Long userRefId) { return userRefRepository.findUserByUserRefId(userRefId) - .orElseThrow(() -> new EntityNotFoundException(new EntityErrorDetail(UserRef.class, "id", userRefId.getClass(), userRefId))); + .orElseThrow(() -> new EntityNotFoundException(new EntityErrorDetail(User.class, "id", userRefId.getClass(), userRefId))); } /** * Create new user reference * - * @param userRefToCreate user reference to be created - * @return created {@link UserRef} + * @param userToCreate user reference to be created + * @return created {@link User} */ @TransactionalWO - public UserRef createUserRef(UserRef userRefToCreate) { - UserRef userRef = userRefRepository.save(userRefToCreate); - LOG.info("User ref with user_ref_id: {} created.", userRef.getUserRefId()); - return userRef; + public User createUserRef(User userToCreate) { + User user = userRefRepository.save(userToCreate); + LOG.info("User ref with user_ref_id: {} created.", user.getUserRefId()); + return user; } } diff --git a/src/main/java/cz/muni/ics/kypo/training/adaptive/service/api/UserManagementServiceApi.java b/src/main/java/cz/muni/ics/kypo/training/adaptive/service/api/UserManagementServiceApi.java index b61b56d0..c5d2c95e 100644 --- a/src/main/java/cz/muni/ics/kypo/training/adaptive/service/api/UserManagementServiceApi.java +++ b/src/main/java/cz/muni/ics/kypo/training/adaptive/service/api/UserManagementServiceApi.java @@ -1,6 +1,6 @@ package cz.muni.ics.kypo.training.adaptive.service.api; -import cz.muni.ics.kypo.training.adaptive.domain.UserRef; +import cz.muni.ics.kypo.training.adaptive.domain.User; import cz.muni.ics.kypo.training.adaptive.dto.UserRefDTO; import cz.muni.ics.kypo.training.adaptive.dto.responses.PageResultResource; import cz.muni.ics.kypo.training.adaptive.enums.RoleType; @@ -42,7 +42,7 @@ public class UserManagementServiceApi { * Finds specific User reference by login * * @param id of wanted User reference - * @return {@link UserRef} with corresponding login + * @return {@link User} with corresponding login * @throws EntityNotFoundException UserRef was not found */ public UserRefDTO getUserRefDTOByUserRefId(Long id) { diff --git a/src/main/java/cz/muni/ics/kypo/training/adaptive/service/training/TrainingDefinitionService.java b/src/main/java/cz/muni/ics/kypo/training/adaptive/service/training/TrainingDefinitionService.java index 6ab5b96c..f0c12618 100644 --- a/src/main/java/cz/muni/ics/kypo/training/adaptive/service/training/TrainingDefinitionService.java +++ b/src/main/java/cz/muni/ics/kypo/training/adaptive/service/training/TrainingDefinitionService.java @@ -1,7 +1,7 @@ package cz.muni.ics.kypo.training.adaptive.service.training; import com.querydsl.core.types.Predicate; -import cz.muni.ics.kypo.training.adaptive.domain.UserRef; +import cz.muni.ics.kypo.training.adaptive.domain.User; import cz.muni.ics.kypo.training.adaptive.domain.phase.*; import cz.muni.ics.kypo.training.adaptive.domain.phase.questions.Question; import cz.muni.ics.kypo.training.adaptive.domain.phase.questions.QuestionChoice; @@ -421,11 +421,11 @@ public class TrainingDefinitionService { } private void addLoggedInUserToTrainingDefinitionAsAuthor(TrainingDefinition trainingDefinition) { - Optional<UserRef> user = userRefRepository.findUserByUserRefId(userManagementServiceApi.getLoggedInUserRefId()); + Optional<User> user = userRefRepository.findUserByUserRefId(userManagementServiceApi.getLoggedInUserRefId()); if (user.isPresent()) { trainingDefinition.addAuthor(user.get()); } else { - UserRef newUser = new UserRef(userManagementServiceApi.getLoggedInUserRefId()); + User newUser = new User(userManagementServiceApi.getLoggedInUserRefId()); trainingDefinition.addAuthor(newUser); } trainingDefinition.setLastEdited(getCurrentTimeInUTC()); diff --git a/src/main/java/cz/muni/ics/kypo/training/adaptive/service/training/TrainingInstanceService.java b/src/main/java/cz/muni/ics/kypo/training/adaptive/service/training/TrainingInstanceService.java index 18c0ac6f..f314aed2 100644 --- a/src/main/java/cz/muni/ics/kypo/training/adaptive/service/training/TrainingInstanceService.java +++ b/src/main/java/cz/muni/ics/kypo/training/adaptive/service/training/TrainingInstanceService.java @@ -2,7 +2,7 @@ package cz.muni.ics.kypo.training.adaptive.service.training; import com.querydsl.core.types.Predicate; import cz.muni.ics.kypo.training.adaptive.domain.AccessToken; -import cz.muni.ics.kypo.training.adaptive.domain.UserRef; +import cz.muni.ics.kypo.training.adaptive.domain.User; import cz.muni.ics.kypo.training.adaptive.domain.training.TrainingInstance; import cz.muni.ics.kypo.training.adaptive.domain.training.TrainingRun; import cz.muni.ics.kypo.training.adaptive.exceptions.EntityConflictException; @@ -203,12 +203,12 @@ public class TrainingInstanceService { } private void addLoggedInUserAsOrganizerToTrainingInstance(TrainingInstance trainingInstance) { - Optional<UserRef> authorOfTrainingInstance = organizerRefRepository.findUserByUserRefId(userManagementServiceApi.getLoggedInUserRefId()); + Optional<User> authorOfTrainingInstance = organizerRefRepository.findUserByUserRefId(userManagementServiceApi.getLoggedInUserRefId()); if (authorOfTrainingInstance.isPresent()) { trainingInstance.addOrganizer(authorOfTrainingInstance.get()); } else { - UserRef userRef = new UserRef(userManagementServiceApi.getLoggedInUserRefId()); - trainingInstance.addOrganizer(organizerRefRepository.save(userRef)); + User user = new User(userManagementServiceApi.getLoggedInUserRefId()); + trainingInstance.addOrganizer(organizerRefRepository.save(user)); } } @@ -270,9 +270,9 @@ public class TrainingInstanceService { * Find UserRefs by userRefId * * @param usersRefId of wanted UserRefs - * @return {@link UserRef}s with corresponding userRefIds + * @return {@link User}s with corresponding userRefIds */ - public Set<UserRef> findUserRefsByUserRefIds(Set<Long> usersRefId) { + public Set<User> findUserRefsByUserRefIds(Set<Long> usersRefId) { return organizerRefRepository.findUsers(usersRefId); } diff --git a/src/main/java/cz/muni/ics/kypo/training/adaptive/service/training/TrainingRunService.java b/src/main/java/cz/muni/ics/kypo/training/adaptive/service/training/TrainingRunService.java index 88d7e2ca..ea908359 100644 --- a/src/main/java/cz/muni/ics/kypo/training/adaptive/service/training/TrainingRunService.java +++ b/src/main/java/cz/muni/ics/kypo/training/adaptive/service/training/TrainingRunService.java @@ -3,7 +3,7 @@ package cz.muni.ics.kypo.training.adaptive.service.training; import com.querydsl.core.types.Predicate; import cz.muni.ics.kypo.training.adaptive.annotations.transactions.TransactionalWO; import cz.muni.ics.kypo.training.adaptive.domain.TRAcquisitionLock; -import cz.muni.ics.kypo.training.adaptive.domain.UserRef; +import cz.muni.ics.kypo.training.adaptive.domain.User; import cz.muni.ics.kypo.training.adaptive.domain.phase.*; import cz.muni.ics.kypo.training.adaptive.domain.training.TrainingDefinition; import cz.muni.ics.kypo.training.adaptive.domain.training.TrainingInstance; @@ -316,11 +316,11 @@ public class TrainingRunService { TrainingRun newTrainingRun = new TrainingRun(); newTrainingRun.setCurrentPhase(currentPhase); - Optional<UserRef> userRefOpt = participantRefRepository.findUserByUserRefId(participantRefId); + Optional<User> userRefOpt = participantRefRepository.findUserByUserRefId(participantRefId); if (userRefOpt.isPresent()) { newTrainingRun.setParticipantRef(userRefOpt.get()); } else { - newTrainingRun.setParticipantRef(participantRefRepository.save(new UserRef(userManagementServiceApi.getLoggedInUserRefId()))); + newTrainingRun.setParticipantRef(participantRefRepository.save(new User(userManagementServiceApi.getLoggedInUserRefId()))); } newTrainingRun.setState(TRState.RUNNING); newTrainingRun.setTrainingInstance(trainingInstance); diff --git a/src/main/resources/db/migration/V1__db_adaptive_trainings_schema.sql b/src/main/resources/db/migration/V1__db_adaptive_trainings_schema.sql index 4067d602..34d3d1f6 100644 --- a/src/main/resources/db/migration/V1__db_adaptive_trainings_schema.sql +++ b/src/main/resources/db/migration/V1__db_adaptive_trainings_schema.sql @@ -1,8 +1,8 @@ --- USER_REF -create table user_ref ( - id bigserial not null, +-- USER +create table "user" ( + user_id bigserial not null, user_ref_id int8 not null, - primary key (id) + primary key (user_id) ); -- TRAINING @@ -19,12 +19,12 @@ create table training_definition ( primary key (training_definition_id) ); -create table training_definition_user_ref ( +create table training_definition_user ( training_definition_id int8 not null, - user_ref_id int8 not null, - primary key (training_definition_id, user_ref_id), + user_id int8 not null, + primary key (training_definition_id, user_id), foreign key (training_definition_id) references training_definition, - foreign key (user_ref_id) references user_ref + foreign key (user_id) references "user" ); create table training_instance ( @@ -40,12 +40,12 @@ create table training_instance ( ); -create table training_instance_user_ref ( +create table training_instance_user ( training_instance_id int8 not null, - user_ref_id int8 not null, - primary key (training_instance_id, user_ref_id), + user_id int8 not null, + primary key (training_instance_id, user_id), foreign key (training_instance_id) references training_instance, - foreign key (user_ref_id) references user_ref + foreign key (user_id) references "user" ); @@ -60,13 +60,13 @@ create table training_run ( state varchar(128) not null, current_phase_id int8 not null, current_task_id int8 null, - user_ref_id int8 not null, + user_id int8 not null, sandbox_instance_ref_id int8 null, training_instance_id int8 not null, previous_sandbox_instance_ref_id int8 null, primary key (training_instance_id), foreign key (training_instance_id) references training_instance, - foreign key (user_ref_id) references user_ref + foreign key (user_id) references "user" ); -- PHASES @@ -205,7 +205,7 @@ create table training_run_acquisition_lock ( training_instance_id int8 not null, creation_time timestamp not null, primary key (training_run_acquisition_lock_id), - foreign key (participant_ref_id) references user_ref, + foreign key (participant_ref_id) references "user", foreign key (training_instance_id) references training_instance ); diff --git a/src/main/resources/db/migration/V2__db_adaptive_trainings_sequences.sql b/src/main/resources/db/migration/V2__db_adaptive_trainings_sequences.sql index 09188e55..74badbf0 100644 --- a/src/main/resources/db/migration/V2__db_adaptive_trainings_sequences.sql +++ b/src/main/resources/db/migration/V2__db_adaptive_trainings_sequences.sql @@ -10,4 +10,4 @@ CREATE SEQUENCE training_instance_seq AS bigint INCREMENT 50 MINVALUE 1; CREATE SEQUENCE training_run_seq AS bigint INCREMENT 50 MINVALUE 1; CREATE SEQUENCE access_token_seq AS bigint INCREMENT 50 MINVALUE 1; CREATE SEQUENCE tr_acquisition_lock_seq AS bigint INCREMENT 50 MINVALUE 1; -CREATE SEQUENCE user_ref_seq AS bigint INCREMENT 50 MINVALUE 1; +CREATE SEQUENCE user_seq AS bigint INCREMENT 50 MINVALUE 1; -- GitLab