diff --git a/api/useradminservice.yaml b/api/useradminservice.yaml index ccfd03d44..8c1accc29 100644 --- a/api/useradminservice.yaml +++ b/api/useradminservice.yaml @@ -369,7 +369,9 @@ paths: summary: 'Change an agency from team-agency to default and vice-versa and switch the associated consultant accounts to team consultant or default consultant. Ongoing team counselings change to 1:1 when converting agency to default status. 1:1 counselings remain - single counselings when swapping the agency to team-agency. [Authorization: Role: user-admin]' + single counselings when swapping the agency to team-agency. This endpoint must be used only + internally from AgencyService to ensure the regarding agency has been flagged correctly too. + [Authorization: Role: user-admin]' operationId: changeAgencyType parameters: - name: agencyId @@ -779,6 +781,19 @@ components: updateDate: type: string example: "2019-08-23T08:52:05" + deleteDate: + type: string + example: "2019-08-23T08:52:05" + _links: + $ref: '#/components/schemas/ConsultantAgencyLinks' + + ConsultantAgencyLinks: + type: object + required: + - delete + properties: + delete: + $ref: '#/components/schemas/HalLink' CreateConsultantAgencyDTO: type: object diff --git a/src/main/java/de/caritas/cob/userservice/api/admin/controller/UserAdminController.java b/src/main/java/de/caritas/cob/userservice/api/admin/controller/UserAdminController.java index 703a3172d..ab7224280 100644 --- a/src/main/java/de/caritas/cob/userservice/api/admin/controller/UserAdminController.java +++ b/src/main/java/de/caritas/cob/userservice/api/admin/controller/UserAdminController.java @@ -122,6 +122,18 @@ public ResponseEntity createConsultantAgency(@PathVariable String consulta return new ResponseEntity<>(HttpStatus.CREATED); } + /** + * Entry point to delete a consultant agency relation. + * + * @param consultantId Consultant Id (required) + * @param agencyId Agency Id (required) + */ + @Override + public ResponseEntity deleteConsultantAgency(String consultantId, Long agencyId) { + this.consultantAdminFacade.markConsultantAgencyForDeletion(consultantId, agencyId); + return new ResponseEntity<>(HttpStatus.OK); + } + /** * Entry point to mark a consultant for deletion. * diff --git a/src/main/java/de/caritas/cob/userservice/api/admin/facade/ConsultantAdminFacade.java b/src/main/java/de/caritas/cob/userservice/api/admin/facade/ConsultantAdminFacade.java index a4c0349d1..b3985a179 100644 --- a/src/main/java/de/caritas/cob/userservice/api/admin/facade/ConsultantAdminFacade.java +++ b/src/main/java/de/caritas/cob/userservice/api/admin/facade/ConsultantAdminFacade.java @@ -17,7 +17,7 @@ import de.caritas.cob.userservice.api.model.CreateConsultantDTO; import de.caritas.cob.userservice.api.model.UpdateConsultantDTO; import de.caritas.cob.userservice.api.repository.consultant.Consultant; -import de.caritas.cob.userservice.api.repository.consultantAgency.ConsultantAgency; +import de.caritas.cob.userservice.api.repository.consultantagency.ConsultantAgency; import lombok.NonNull; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; @@ -121,4 +121,13 @@ public void changeAgencyType(Long agencyId, AgencyTypeDTO agencyTypeDTO) { } } + /** + * Marks the {@link ConsultantAgency} as deleted. + * + * @param consultantId the consultant id + * @param agencyId the agency id + */ + public void markConsultantAgencyForDeletion(String consultantId, Long agencyId) { + this.consultantAgencyAdminService.markConsultantAgencyForDeletion(consultantId, agencyId); + } } diff --git a/src/main/java/de/caritas/cob/userservice/api/admin/report/rule/ConsultantWithWrongTeamConsultantFlagViolationReportRule.java b/src/main/java/de/caritas/cob/userservice/api/admin/report/rule/ConsultantWithWrongTeamConsultantFlagViolationReportRule.java index 5f23eb2a3..f3fea1c29 100644 --- a/src/main/java/de/caritas/cob/userservice/api/admin/report/rule/ConsultantWithWrongTeamConsultantFlagViolationReportRule.java +++ b/src/main/java/de/caritas/cob/userservice/api/admin/report/rule/ConsultantWithWrongTeamConsultantFlagViolationReportRule.java @@ -8,8 +8,8 @@ import de.caritas.cob.userservice.api.model.ViolationDTO; import de.caritas.cob.userservice.api.repository.consultant.Consultant; import de.caritas.cob.userservice.api.repository.consultant.ConsultantRepository; -import de.caritas.cob.userservice.api.repository.consultantAgency.ConsultantAgency; -import de.caritas.cob.userservice.api.repository.consultantAgency.ConsultantAgencyRepository; +import de.caritas.cob.userservice.api.repository.consultantagency.ConsultantAgency; +import de.caritas.cob.userservice.api.repository.consultantagency.ConsultantAgencyRepository; import java.util.List; import java.util.stream.Collectors; import java.util.stream.StreamSupport; diff --git a/src/main/java/de/caritas/cob/userservice/api/admin/report/rule/InvalidAgencyForConsultantViolationReportRule.java b/src/main/java/de/caritas/cob/userservice/api/admin/report/rule/InvalidAgencyForConsultantViolationReportRule.java index da94b03b1..6fb1a0b3d 100644 --- a/src/main/java/de/caritas/cob/userservice/api/admin/report/rule/InvalidAgencyForConsultantViolationReportRule.java +++ b/src/main/java/de/caritas/cob/userservice/api/admin/report/rule/InvalidAgencyForConsultantViolationReportRule.java @@ -6,8 +6,8 @@ import de.caritas.cob.userservice.api.admin.report.service.AgencyAdminService; import de.caritas.cob.userservice.api.model.ViolationDTO; import de.caritas.cob.userservice.api.repository.consultant.Consultant; -import de.caritas.cob.userservice.api.repository.consultantAgency.ConsultantAgency; -import de.caritas.cob.userservice.api.repository.consultantAgency.ConsultantAgencyRepository; +import de.caritas.cob.userservice.api.repository.consultantagency.ConsultantAgency; +import de.caritas.cob.userservice.api.repository.consultantagency.ConsultantAgencyRepository; import java.util.Collection; import java.util.List; import java.util.stream.Collectors; diff --git a/src/main/java/de/caritas/cob/userservice/api/admin/report/rule/MissingRocketChatRoomForConsultantViolationReportRule.java b/src/main/java/de/caritas/cob/userservice/api/admin/report/rule/MissingRocketChatRoomForConsultantViolationReportRule.java index b412550a6..728704417 100644 --- a/src/main/java/de/caritas/cob/userservice/api/admin/report/rule/MissingRocketChatRoomForConsultantViolationReportRule.java +++ b/src/main/java/de/caritas/cob/userservice/api/admin/report/rule/MissingRocketChatRoomForConsultantViolationReportRule.java @@ -12,7 +12,7 @@ import de.caritas.cob.userservice.api.repository.session.Session; import de.caritas.cob.userservice.api.repository.session.SessionRepository; import de.caritas.cob.userservice.api.repository.session.SessionStatus; -import de.caritas.cob.userservice.api.service.RocketChatService; +import de.caritas.cob.userservice.api.service.rocketchat.RocketChatService; import java.util.Collection; import java.util.List; import java.util.Objects; diff --git a/src/main/java/de/caritas/cob/userservice/api/admin/report/rule/MissingSessionAndChatForAskerViolationReportRule.java b/src/main/java/de/caritas/cob/userservice/api/admin/report/rule/MissingSessionAndChatForAskerViolationReportRule.java index c972bd826..f57ba22b7 100644 --- a/src/main/java/de/caritas/cob/userservice/api/admin/report/rule/MissingSessionAndChatForAskerViolationReportRule.java +++ b/src/main/java/de/caritas/cob/userservice/api/admin/report/rule/MissingSessionAndChatForAskerViolationReportRule.java @@ -7,7 +7,7 @@ import de.caritas.cob.userservice.api.model.ViolationDTO; import de.caritas.cob.userservice.api.repository.user.User; import de.caritas.cob.userservice.api.repository.user.UserRepository; -import de.caritas.cob.userservice.api.repository.userAgency.UserAgencyRepository; +import de.caritas.cob.userservice.api.repository.useragency.UserAgencyRepository; import java.util.List; import java.util.stream.Collectors; import java.util.stream.StreamSupport; diff --git a/src/main/java/de/caritas/cob/userservice/api/admin/report/rule/TeamConsultantWithoutRequiredFlagViolationReportRule.java b/src/main/java/de/caritas/cob/userservice/api/admin/report/rule/TeamConsultantWithoutRequiredFlagViolationReportRule.java index dfc7073b6..105664b72 100644 --- a/src/main/java/de/caritas/cob/userservice/api/admin/report/rule/TeamConsultantWithoutRequiredFlagViolationReportRule.java +++ b/src/main/java/de/caritas/cob/userservice/api/admin/report/rule/TeamConsultantWithoutRequiredFlagViolationReportRule.java @@ -8,8 +8,8 @@ import de.caritas.cob.userservice.api.admin.report.service.AgencyAdminService; import de.caritas.cob.userservice.api.model.ViolationDTO; import de.caritas.cob.userservice.api.repository.consultant.Consultant; -import de.caritas.cob.userservice.api.repository.consultantAgency.ConsultantAgency; -import de.caritas.cob.userservice.api.repository.consultantAgency.ConsultantAgencyRepository; +import de.caritas.cob.userservice.api.repository.consultantagency.ConsultantAgency; +import de.caritas.cob.userservice.api.repository.consultantagency.ConsultantAgencyRepository; import java.util.Collection; import java.util.List; import java.util.stream.Collectors; diff --git a/src/main/java/de/caritas/cob/userservice/api/admin/report/rule/analyzer/ConsultantAgencyAnalyzer.java b/src/main/java/de/caritas/cob/userservice/api/admin/report/rule/analyzer/ConsultantAgencyAnalyzer.java index 8ed10370d..043fd19ed 100644 --- a/src/main/java/de/caritas/cob/userservice/api/admin/report/rule/analyzer/ConsultantAgencyAnalyzer.java +++ b/src/main/java/de/caritas/cob/userservice/api/admin/report/rule/analyzer/ConsultantAgencyAnalyzer.java @@ -4,7 +4,7 @@ import de.caritas.cob.userservice.agencyadminserivce.generated.web.model.AgencyAdminResponseDTO; import de.caritas.cob.userservice.api.repository.consultant.Consultant; -import de.caritas.cob.userservice.api.repository.consultantAgency.ConsultantAgency; +import de.caritas.cob.userservice.api.repository.consultantagency.ConsultantAgency; import java.util.List; import java.util.Objects; import java.util.function.Predicate; diff --git a/src/main/java/de/caritas/cob/userservice/api/admin/service/agency/ConsultantAgencyAdminResultDTOBuilder.java b/src/main/java/de/caritas/cob/userservice/api/admin/service/agency/ConsultantAgencyAdminResultDTOBuilder.java index 2ff2fd9aa..808e3f9da 100644 --- a/src/main/java/de/caritas/cob/userservice/api/admin/service/agency/ConsultantAgencyAdminResultDTOBuilder.java +++ b/src/main/java/de/caritas/cob/userservice/api/admin/service/agency/ConsultantAgencyAdminResultDTOBuilder.java @@ -4,14 +4,15 @@ import static java.util.Objects.isNull; import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.methodOn; -import de.caritas.cob.userservice.api.admin.controller.UserAdminController; import de.caritas.cob.userservice.api.admin.hallink.HalLinkBuilder; import de.caritas.cob.userservice.api.model.ConsultantAgencyAdminDTO; import de.caritas.cob.userservice.api.model.ConsultantAgencyAdminResultDTO; import de.caritas.cob.userservice.api.model.ConsultantAgencyAdminResultLinks; +import de.caritas.cob.userservice.api.model.ConsultantAgencyLinks; import de.caritas.cob.userservice.api.model.HalLink; import de.caritas.cob.userservice.api.model.HalLink.MethodEnum; -import de.caritas.cob.userservice.api.repository.consultantAgency.ConsultantAgency; +import de.caritas.cob.userservice.api.repository.consultantagency.ConsultantAgency; +import de.caritas.cob.userservice.generated.api.admin.controller.UseradminApi; import java.util.List; import java.util.stream.Collectors; @@ -78,12 +79,21 @@ private List buildSessionAdminResult() { } private ConsultantAgencyAdminDTO fromConsultantAgency(ConsultantAgency consultantAgency) { - + ConsultantAgencyLinks consultantAgencyLinks = new ConsultantAgencyLinks() + .delete(buildDeleteConsultantAgencyLink(consultantAgency)); return new ConsultantAgencyAdminDTO() .agencyId(consultantAgency.getAgencyId()) .consultantId(consultantAgency.getConsultant().getId()) .createDate(String.valueOf(consultantAgency.getCreateDate())) - .updateDate((String.valueOf(consultantAgency.getUpdateDate()))); + .updateDate((String.valueOf(consultantAgency.getUpdateDate()))) + .deleteDate(String.valueOf(consultantAgency.getDeleteDate())) + .links(consultantAgencyLinks); + } + + private HalLink buildDeleteConsultantAgencyLink(ConsultantAgency consultantAgency) { + return buildHalLink(methodOn(UseradminApi.class) + .deleteConsultantAgency(consultantAgency.getConsultant().getId(), + consultantAgency.getAgencyId()), MethodEnum.DELETE); } private ConsultantAgencyAdminResultLinks buildResultLinks() { @@ -92,7 +102,7 @@ private ConsultantAgencyAdminResultLinks buildResultLinks() { } private HalLink buildSelfLink() { - return buildHalLink(methodOn(UserAdminController.class).getConsultantAgency(consultantId), + return buildHalLink(methodOn(UseradminApi.class).getConsultantAgency(consultantId), MethodEnum.GET); } diff --git a/src/main/java/de/caritas/cob/userservice/api/admin/service/agency/ConsultantAgencyAdminService.java b/src/main/java/de/caritas/cob/userservice/api/admin/service/agency/ConsultantAgencyAdminService.java index 4d24c44b0..2bd69dfd9 100644 --- a/src/main/java/de/caritas/cob/userservice/api/admin/service/agency/ConsultantAgencyAdminService.java +++ b/src/main/java/de/caritas/cob/userservice/api/admin/service/agency/ConsultantAgencyAdminService.java @@ -1,18 +1,27 @@ package de.caritas.cob.userservice.api.admin.service.agency; +import static de.caritas.cob.userservice.api.exception.httpresponses.customheader.HttpStatusExceptionReason.CONSULTANT_AGENCY_RELATION_DOES_NOT_EXIST; +import static de.caritas.cob.userservice.api.exception.httpresponses.customheader.HttpStatusExceptionReason.CONSULTANT_IS_THE_LAST_OF_AGENCY_AND_AGENCY_HAS_OPEN_ENQUIRIES; +import static de.caritas.cob.userservice.api.exception.httpresponses.customheader.HttpStatusExceptionReason.CONSULTANT_IS_THE_LAST_OF_AGENCY_AND_AGENCY_IS_STILL_ACTIVE; +import static de.caritas.cob.userservice.api.repository.session.SessionStatus.INITIAL; +import static de.caritas.cob.userservice.api.repository.session.SessionStatus.NEW; +import static de.caritas.cob.userservice.localdatetime.CustomLocalDateTime.nowInUtc; import static java.util.Collections.singletonList; +import static java.util.Objects.isNull; import static org.apache.commons.collections.CollectionUtils.isEmpty; +import static org.apache.commons.lang3.BooleanUtils.isFalse; import de.caritas.cob.userservice.api.exception.AgencyServiceHelperException; import de.caritas.cob.userservice.api.exception.httpresponses.BadRequestException; +import de.caritas.cob.userservice.api.exception.httpresponses.CustomValidationHttpStatusException; import de.caritas.cob.userservice.api.exception.httpresponses.InternalServerErrorException; import de.caritas.cob.userservice.api.exception.httpresponses.NotFoundException; import de.caritas.cob.userservice.api.model.AgencyDTO; import de.caritas.cob.userservice.api.model.ConsultantAgencyAdminResultDTO; import de.caritas.cob.userservice.api.repository.consultant.Consultant; import de.caritas.cob.userservice.api.repository.consultant.ConsultantRepository; -import de.caritas.cob.userservice.api.repository.consultantAgency.ConsultantAgency; -import de.caritas.cob.userservice.api.repository.consultantAgency.ConsultantAgencyRepository; +import de.caritas.cob.userservice.api.repository.consultantagency.ConsultantAgency; +import de.caritas.cob.userservice.api.repository.consultantagency.ConsultantAgencyRepository; import de.caritas.cob.userservice.api.repository.session.Session; import de.caritas.cob.userservice.api.repository.session.SessionRepository; import de.caritas.cob.userservice.api.repository.session.SessionStatus; @@ -20,6 +29,7 @@ import de.caritas.cob.userservice.api.service.helper.AgencyServiceHelper; import java.util.List; import java.util.Optional; +import java.util.function.Predicate; import lombok.NonNull; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; @@ -130,4 +140,72 @@ private void removeTeamConsultantFlag(Consultant consultant) { this.consultantRepository.save(consultant); } + /** + * Marks an {@link ConsultantAgency} as deleted if consultant is not the last in agency or agency + * is offline and no open enquiries are assigned. + * + * @param consultantId the consultant id + * @param agencyId the agency id + */ + public void markConsultantAgencyForDeletion(String consultantId, Long agencyId) { + List consultantAgencies = + this.consultantAgencyRepository.findByConsultantIdAndAgencyId(consultantId, agencyId); + if (isEmpty(consultantAgencies)) { + throw new CustomValidationHttpStatusException(CONSULTANT_AGENCY_RELATION_DOES_NOT_EXIST); + } + consultantAgencies.stream() + .filter(consultantAgency -> isNull(consultantAgency.getDeleteDate())) + .forEach(this::markAsDeleted); + } + + private void markAsDeleted(ConsultantAgency consultantAgency) { + validateForDeletion(consultantAgency); + consultantAgency.setDeleteDate(nowInUtc()); + this.consultantAgencyRepository.save(consultantAgency); + } + + private void validateForDeletion(ConsultantAgency consultantAgency) { + if (isTheLastConsultantInAgency(consultantAgency)) { + if (isAgencyStillActive(consultantAgency)) { + throw new CustomValidationHttpStatusException( + CONSULTANT_IS_THE_LAST_OF_AGENCY_AND_AGENCY_IS_STILL_ACTIVE); + } + if (hasOpenEnquiries(consultantAgency)) { + throw new CustomValidationHttpStatusException( + CONSULTANT_IS_THE_LAST_OF_AGENCY_AND_AGENCY_HAS_OPEN_ENQUIRIES); + } + } + } + + private boolean isTheLastConsultantInAgency(ConsultantAgency consultantAgency) { + return this.consultantAgencyRepository.findByAgencyId(consultantAgency.getAgencyId()) + .stream() + .filter(relation -> isNull(relation.getDeleteDate())) + .allMatch(sameConsultantAgencyRelation(consultantAgency)); + } + + private Predicate sameConsultantAgencyRelation( + ConsultantAgency consultantAgency) { + return relation -> relation.equals(consultantAgency); + } + + private boolean isAgencyStillActive(ConsultantAgency consultantAgency) { + try { + AgencyDTO agency = this.agencyServiceHelper.getAgency(consultantAgency.getAgencyId()); + return isFalse(agency.getOffline()); + } catch (AgencyServiceHelperException e) { + throw new InternalServerErrorException(e.getMessage()); + } + } + + private boolean hasOpenEnquiries(ConsultantAgency consultantAgency) { + Long agencyId = consultantAgency.getAgencyId(); + return hasSessionWithStatus(agencyId, NEW) || hasSessionWithStatus(agencyId, INITIAL); + } + + private boolean hasSessionWithStatus(Long agencyId, SessionStatus status) { + return !this.sessionRepository.findByAgencyIdAndStatusAndConsultantIsNull(agencyId, status) + .isEmpty(); + } + } diff --git a/src/main/java/de/caritas/cob/userservice/api/admin/service/agency/RemoveConsultantFromRocketChatService.java b/src/main/java/de/caritas/cob/userservice/api/admin/service/agency/RemoveConsultantFromRocketChatService.java index f21ddcbc5..21b465722 100644 --- a/src/main/java/de/caritas/cob/userservice/api/admin/service/agency/RemoveConsultantFromRocketChatService.java +++ b/src/main/java/de/caritas/cob/userservice/api/admin/service/agency/RemoveConsultantFromRocketChatService.java @@ -9,7 +9,7 @@ import de.caritas.cob.userservice.api.repository.consultant.ConsultantRepository; import de.caritas.cob.userservice.api.repository.session.Session; import de.caritas.cob.userservice.api.service.LogService; -import de.caritas.cob.userservice.api.service.RocketChatService; +import de.caritas.cob.userservice.api.service.rocketchat.RocketChatService; import de.caritas.cob.userservice.api.service.helper.KeycloakAdminClientService; import java.util.List; import java.util.Map; diff --git a/src/main/java/de/caritas/cob/userservice/api/admin/service/consultant/create/ConsultantCreationInput.java b/src/main/java/de/caritas/cob/userservice/api/admin/service/consultant/create/ConsultantCreationInput.java index 5d2f1ba36..374af3908 100644 --- a/src/main/java/de/caritas/cob/userservice/api/admin/service/consultant/create/ConsultantCreationInput.java +++ b/src/main/java/de/caritas/cob/userservice/api/admin/service/consultant/create/ConsultantCreationInput.java @@ -1,5 +1,7 @@ package de.caritas.cob.userservice.api.admin.service.consultant.create; +import static de.caritas.cob.userservice.localdatetime.CustomLocalDateTime.nowInUtc; + import java.time.LocalDateTime; /** @@ -27,8 +29,12 @@ interface ConsultantCreationInput { boolean isLanguageFormal(); - LocalDateTime getCreateDate(); + default LocalDateTime getCreateDate() { + return nowInUtc(); + } - LocalDateTime getUpdateDate(); + default LocalDateTime getUpdateDate() { + return nowInUtc(); + } } diff --git a/src/main/java/de/caritas/cob/userservice/api/admin/service/consultant/create/ConsultantCreatorService.java b/src/main/java/de/caritas/cob/userservice/api/admin/service/consultant/create/ConsultantCreatorService.java index 4235658af..2719296e7 100644 --- a/src/main/java/de/caritas/cob/userservice/api/admin/service/consultant/create/ConsultantCreatorService.java +++ b/src/main/java/de/caritas/cob/userservice/api/admin/service/consultant/create/ConsultantCreatorService.java @@ -15,7 +15,7 @@ import de.caritas.cob.userservice.api.repository.consultant.Consultant; import de.caritas.cob.userservice.api.service.ConsultantImportService.ImportRecord; import de.caritas.cob.userservice.api.service.ConsultantService; -import de.caritas.cob.userservice.api.service.RocketChatService; +import de.caritas.cob.userservice.api.service.rocketchat.RocketChatService; import de.caritas.cob.userservice.api.service.helper.KeycloakAdminClientService; import java.util.Set; import lombok.NonNull; diff --git a/src/main/java/de/caritas/cob/userservice/api/admin/service/consultant/create/CreateConsultantDTOCreationInputAdapter.java b/src/main/java/de/caritas/cob/userservice/api/admin/service/consultant/create/CreateConsultantDTOCreationInputAdapter.java index d2cfd5574..d84abc9b3 100644 --- a/src/main/java/de/caritas/cob/userservice/api/admin/service/consultant/create/CreateConsultantDTOCreationInputAdapter.java +++ b/src/main/java/de/caritas/cob/userservice/api/admin/service/consultant/create/CreateConsultantDTOCreationInputAdapter.java @@ -4,13 +4,12 @@ import de.caritas.cob.userservice.api.helper.UserHelper; import de.caritas.cob.userservice.api.model.CreateConsultantDTO; -import java.time.LocalDateTime; import lombok.NonNull; import lombok.RequiredArgsConstructor; /** - * Adapter class to provide a {@link ConsultantCreationInput} based on a - * {@link CreateConsultantDTO}. + * Adapter class to provide a {@link ConsultantCreationInput} based on a {@link + * CreateConsultantDTO}. */ @RequiredArgsConstructor public class CreateConsultantDTOCreationInputAdapter implements ConsultantCreationInput { @@ -118,23 +117,4 @@ public boolean isLanguageFormal() { return isTrue(this.createConsultantDTO.getFormalLanguage()); } - /** - * Provides the created date. - * - * @return the created date - */ - @Override - public LocalDateTime getCreateDate() { - return LocalDateTime.now(); - } - - /** - * Provides the updated date. - * - * @return the updated date - */ - @Override - public LocalDateTime getUpdateDate() { - return LocalDateTime.now(); - } } diff --git a/src/main/java/de/caritas/cob/userservice/api/admin/service/consultant/create/ImportRecordCreationInputAdapter.java b/src/main/java/de/caritas/cob/userservice/api/admin/service/consultant/create/ImportRecordCreationInputAdapter.java index 81c427578..22646a346 100644 --- a/src/main/java/de/caritas/cob/userservice/api/admin/service/consultant/create/ImportRecordCreationInputAdapter.java +++ b/src/main/java/de/caritas/cob/userservice/api/admin/service/consultant/create/ImportRecordCreationInputAdapter.java @@ -1,13 +1,11 @@ package de.caritas.cob.userservice.api.admin.service.consultant.create; import de.caritas.cob.userservice.api.service.ConsultantImportService.ImportRecord; -import java.time.LocalDateTime; import lombok.NonNull; import lombok.RequiredArgsConstructor; /** - * Adapter class to provide a {@link ConsultantCreationInput} based on a - * {@link ImportRecord}. + * Adapter class to provide a {@link ConsultantCreationInput} based on a {@link ImportRecord}. */ @RequiredArgsConstructor public class ImportRecordCreationInputAdapter implements ConsultantCreationInput { @@ -114,23 +112,4 @@ public boolean isLanguageFormal() { return this.importRecord.isFormalLanguage(); } - /** - * Provides the created date. - * - * @return the created date - */ - @Override - public LocalDateTime getCreateDate() { - return LocalDateTime.now(); - } - - /** - * Provides the updated date. - * - * @return the updated date - */ - @Override - public LocalDateTime getUpdateDate() { - return LocalDateTime.now(); - } } diff --git a/src/main/java/de/caritas/cob/userservice/api/admin/service/consultant/create/agencyrelation/ConsultantAgencyCreationInput.java b/src/main/java/de/caritas/cob/userservice/api/admin/service/consultant/create/agencyrelation/ConsultantAgencyCreationInput.java index 3ea46c28d..b3552cc2e 100644 --- a/src/main/java/de/caritas/cob/userservice/api/admin/service/consultant/create/agencyrelation/ConsultantAgencyCreationInput.java +++ b/src/main/java/de/caritas/cob/userservice/api/admin/service/consultant/create/agencyrelation/ConsultantAgencyCreationInput.java @@ -1,7 +1,8 @@ package de.caritas.cob.userservice.api.admin.service.consultant.create.agencyrelation; +import static de.caritas.cob.userservice.localdatetime.CustomLocalDateTime.nowInUtc; + import java.time.LocalDateTime; -import java.time.ZoneOffset; import java.util.Set; /** @@ -16,11 +17,11 @@ public interface ConsultantAgencyCreationInput { Long getAgencyId(); default LocalDateTime getCreateDate() { - return LocalDateTime.now(ZoneOffset.UTC); + return nowInUtc(); } default LocalDateTime getUpdateDate() { - return LocalDateTime.now(ZoneOffset.UTC); + return nowInUtc(); } } diff --git a/src/main/java/de/caritas/cob/userservice/api/admin/service/consultant/create/agencyrelation/ConsultantAgencyRelationCreatorService.java b/src/main/java/de/caritas/cob/userservice/api/admin/service/consultant/create/agencyrelation/ConsultantAgencyRelationCreatorService.java index 049b45325..76aaf8c0b 100644 --- a/src/main/java/de/caritas/cob/userservice/api/admin/service/consultant/create/agencyrelation/ConsultantAgencyRelationCreatorService.java +++ b/src/main/java/de/caritas/cob/userservice/api/admin/service/consultant/create/agencyrelation/ConsultantAgencyRelationCreatorService.java @@ -2,6 +2,7 @@ import static de.caritas.cob.userservice.api.repository.session.ConsultingType.KREUZBUND; import static de.caritas.cob.userservice.api.repository.session.ConsultingType.U25; +import static de.caritas.cob.userservice.localdatetime.CustomLocalDateTime.nowInUtc; import static org.apache.commons.lang3.BooleanUtils.isTrue; import de.caritas.cob.userservice.api.admin.service.rocketchat.RocketChatAddToGroupOperationService; @@ -12,7 +13,7 @@ import de.caritas.cob.userservice.api.model.CreateConsultantAgencyDTO; import de.caritas.cob.userservice.api.repository.consultant.Consultant; import de.caritas.cob.userservice.api.repository.consultant.ConsultantRepository; -import de.caritas.cob.userservice.api.repository.consultantAgency.ConsultantAgency; +import de.caritas.cob.userservice.api.repository.consultantagency.ConsultantAgency; import de.caritas.cob.userservice.api.repository.session.ConsultingType; import de.caritas.cob.userservice.api.repository.session.Session; import de.caritas.cob.userservice.api.repository.session.SessionRepository; @@ -20,11 +21,9 @@ import de.caritas.cob.userservice.api.service.ConsultantAgencyService; import de.caritas.cob.userservice.api.service.ConsultantImportService.ImportRecord; import de.caritas.cob.userservice.api.service.LogService; -import de.caritas.cob.userservice.api.service.RocketChatService; import de.caritas.cob.userservice.api.service.helper.AgencyServiceHelper; import de.caritas.cob.userservice.api.service.helper.KeycloakAdminClientService; -import java.time.LocalDateTime; -import java.time.ZoneOffset; +import de.caritas.cob.userservice.api.service.rocketchat.RocketChatService; import java.util.List; import java.util.Optional; import java.util.Set; @@ -171,8 +170,8 @@ private ConsultantAgency buildConsultantAgency(Consultant consultant, Long agenc .builder() .consultant(consultant) .agencyId(agencyId) - .createDate(LocalDateTime.now(ZoneOffset.UTC)) - .updateDate(LocalDateTime.now(ZoneOffset.UTC)) + .createDate(nowInUtc()) + .updateDate(nowInUtc()) .build(); } diff --git a/src/main/java/de/caritas/cob/userservice/api/admin/service/consultant/update/ConsultantUpdateService.java b/src/main/java/de/caritas/cob/userservice/api/admin/service/consultant/update/ConsultantUpdateService.java index 26e86a1e8..fb3244fb1 100644 --- a/src/main/java/de/caritas/cob/userservice/api/admin/service/consultant/update/ConsultantUpdateService.java +++ b/src/main/java/de/caritas/cob/userservice/api/admin/service/consultant/update/ConsultantUpdateService.java @@ -1,5 +1,7 @@ package de.caritas.cob.userservice.api.admin.service.consultant.update; +import static de.caritas.cob.userservice.localdatetime.CustomLocalDateTime.nowInUtc; + import de.caritas.cob.userservice.api.admin.service.consultant.validation.ConsultantInputValidator; import de.caritas.cob.userservice.api.admin.service.consultant.validation.UpdateConsultantDTOAbsenceInputAdapter; import de.caritas.cob.userservice.api.exception.httpresponses.BadRequestException; @@ -7,10 +9,8 @@ import de.caritas.cob.userservice.api.model.registration.UserDTO; import de.caritas.cob.userservice.api.repository.consultant.Consultant; import de.caritas.cob.userservice.api.service.ConsultantService; -import de.caritas.cob.userservice.api.service.RocketChatService; import de.caritas.cob.userservice.api.service.helper.KeycloakAdminClientService; -import java.time.LocalDateTime; -import java.time.ZoneOffset; +import de.caritas.cob.userservice.api.service.rocketchat.RocketChatService; import lombok.NonNull; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; @@ -30,7 +30,7 @@ public class ConsultantUpdateService { /** * Updates the basic data of consultant with given id. * - * @param consultantId the id of the consultant to update + * @param consultantId the id of the consultant to update * @param updateConsultantDTO the update input data * @return the updated persisted {@link Consultant} */ @@ -70,7 +70,7 @@ private Consultant updateDatabaseConsultant(UpdateConsultantDTO updateConsultant consultant.setLanguageFormal(updateConsultantDTO.getFormalLanguage()); consultant.setAbsent(updateConsultantDTO.getAbsent()); consultant.setAbsenceMessage(updateConsultantDTO.getAbsenceMessage()); - consultant.setUpdateDate(LocalDateTime.now(ZoneOffset.UTC)); + consultant.setUpdateDate(nowInUtc()); return this.consultantService.saveConsultant(consultant); } diff --git a/src/main/java/de/caritas/cob/userservice/api/admin/service/rocketchat/RocketChatAddToGroupOperationService.java b/src/main/java/de/caritas/cob/userservice/api/admin/service/rocketchat/RocketChatAddToGroupOperationService.java index 90f995b34..d3ac952d4 100644 --- a/src/main/java/de/caritas/cob/userservice/api/admin/service/rocketchat/RocketChatAddToGroupOperationService.java +++ b/src/main/java/de/caritas/cob/userservice/api/admin/service/rocketchat/RocketChatAddToGroupOperationService.java @@ -4,7 +4,7 @@ import de.caritas.cob.userservice.api.repository.consultant.Consultant; import de.caritas.cob.userservice.api.repository.session.Session; import de.caritas.cob.userservice.api.service.LogService; -import de.caritas.cob.userservice.api.service.RocketChatService; +import de.caritas.cob.userservice.api.service.rocketchat.RocketChatService; import de.caritas.cob.userservice.api.service.helper.KeycloakAdminClientService; import java.util.List; import java.util.function.Consumer; diff --git a/src/main/java/de/caritas/cob/userservice/api/admin/service/rocketchat/RocketChatGroupOperation.java b/src/main/java/de/caritas/cob/userservice/api/admin/service/rocketchat/RocketChatGroupOperation.java index cc0961ef7..14c399bd7 100644 --- a/src/main/java/de/caritas/cob/userservice/api/admin/service/rocketchat/RocketChatGroupOperation.java +++ b/src/main/java/de/caritas/cob/userservice/api/admin/service/rocketchat/RocketChatGroupOperation.java @@ -10,7 +10,7 @@ import de.caritas.cob.userservice.api.repository.session.Session; import de.caritas.cob.userservice.api.repository.session.SessionStatus; import de.caritas.cob.userservice.api.service.LogService; -import de.caritas.cob.userservice.api.service.RocketChatService; +import de.caritas.cob.userservice.api.service.rocketchat.RocketChatService; import de.caritas.cob.userservice.api.service.helper.KeycloakAdminClientService; import java.util.function.Consumer; import lombok.NonNull; diff --git a/src/main/java/de/caritas/cob/userservice/api/admin/service/rocketchat/RocketChatRemoveFromGroupOperationService.java b/src/main/java/de/caritas/cob/userservice/api/admin/service/rocketchat/RocketChatRemoveFromGroupOperationService.java index be46a2978..7704d2057 100644 --- a/src/main/java/de/caritas/cob/userservice/api/admin/service/rocketchat/RocketChatRemoveFromGroupOperationService.java +++ b/src/main/java/de/caritas/cob/userservice/api/admin/service/rocketchat/RocketChatRemoveFromGroupOperationService.java @@ -4,7 +4,7 @@ import de.caritas.cob.userservice.api.repository.consultant.Consultant; import de.caritas.cob.userservice.api.repository.session.Session; import de.caritas.cob.userservice.api.service.LogService; -import de.caritas.cob.userservice.api.service.RocketChatService; +import de.caritas.cob.userservice.api.service.rocketchat.RocketChatService; import de.caritas.cob.userservice.api.service.helper.KeycloakAdminClientService; import java.util.List; import java.util.Map; diff --git a/src/main/java/de/caritas/cob/userservice/api/exception/httpresponses/customheader/HttpStatusExceptionReason.java b/src/main/java/de/caritas/cob/userservice/api/exception/httpresponses/customheader/HttpStatusExceptionReason.java index a2ed73168..8dba0b730 100644 --- a/src/main/java/de/caritas/cob/userservice/api/exception/httpresponses/customheader/HttpStatusExceptionReason.java +++ b/src/main/java/de/caritas/cob/userservice/api/exception/httpresponses/customheader/HttpStatusExceptionReason.java @@ -5,5 +5,8 @@ public enum HttpStatusExceptionReason { USERNAME_NOT_VALID, EMAIL_NOT_AVAILABLE, EMAIL_NOT_VALID, - MISSING_ABSENCE_MESSAGE_FOR_ABSENT_USER + MISSING_ABSENCE_MESSAGE_FOR_ABSENT_USER, + CONSULTANT_AGENCY_RELATION_DOES_NOT_EXIST, + CONSULTANT_IS_THE_LAST_OF_AGENCY_AND_AGENCY_IS_STILL_ACTIVE, + CONSULTANT_IS_THE_LAST_OF_AGENCY_AND_AGENCY_HAS_OPEN_ENQUIRIES } diff --git a/src/main/java/de/caritas/cob/userservice/api/facade/CreateChatFacade.java b/src/main/java/de/caritas/cob/userservice/api/facade/CreateChatFacade.java index 969838191..bd62e61da 100644 --- a/src/main/java/de/caritas/cob/userservice/api/facade/CreateChatFacade.java +++ b/src/main/java/de/caritas/cob/userservice/api/facade/CreateChatFacade.java @@ -13,10 +13,10 @@ import de.caritas.cob.userservice.api.model.CreateChatResponseDTO; import de.caritas.cob.userservice.api.model.rocketchat.group.GroupResponseDTO; import de.caritas.cob.userservice.api.repository.chat.Chat; -import de.caritas.cob.userservice.api.repository.chatAgency.ChatAgency; +import de.caritas.cob.userservice.api.repository.chatagency.ChatAgency; import de.caritas.cob.userservice.api.repository.consultant.Consultant; import de.caritas.cob.userservice.api.service.ChatService; -import de.caritas.cob.userservice.api.service.RocketChatService; +import de.caritas.cob.userservice.api.service.rocketchat.RocketChatService; import java.util.Optional; import org.springframework.stereotype.Service; diff --git a/src/main/java/de/caritas/cob/userservice/api/facade/CreateEnquiryMessageFacade.java b/src/main/java/de/caritas/cob/userservice/api/facade/CreateEnquiryMessageFacade.java index 05d83d8f0..b1f4fd346 100644 --- a/src/main/java/de/caritas/cob/userservice/api/facade/CreateEnquiryMessageFacade.java +++ b/src/main/java/de/caritas/cob/userservice/api/facade/CreateEnquiryMessageFacade.java @@ -1,5 +1,6 @@ package de.caritas.cob.userservice.api.facade; +import static de.caritas.cob.userservice.localdatetime.CustomLocalDateTime.nowInUtc; import static java.util.Objects.nonNull; import de.caritas.cob.userservice.api.authorization.Authorities.Authority; @@ -23,14 +24,14 @@ import de.caritas.cob.userservice.api.manager.consultingtype.ConsultingTypeSettings; import de.caritas.cob.userservice.api.model.rocketchat.group.GroupResponseDTO; import de.caritas.cob.userservice.api.model.rocketchat.user.UserInfoResponseDTO; -import de.caritas.cob.userservice.api.repository.consultantAgency.ConsultantAgency; +import de.caritas.cob.userservice.api.repository.consultantagency.ConsultantAgency; import de.caritas.cob.userservice.api.repository.session.Session; import de.caritas.cob.userservice.api.repository.session.SessionStatus; import de.caritas.cob.userservice.api.repository.user.User; import de.caritas.cob.userservice.api.service.ConsultantAgencyService; import de.caritas.cob.userservice.api.service.LogService; import de.caritas.cob.userservice.api.service.MonitoringService; -import de.caritas.cob.userservice.api.service.RocketChatService; +import de.caritas.cob.userservice.api.service.rocketchat.RocketChatService; import de.caritas.cob.userservice.api.service.SessionService; import de.caritas.cob.userservice.api.service.helper.KeycloakAdminClientService; import de.caritas.cob.userservice.api.service.helper.MessageServiceHelper; @@ -155,7 +156,7 @@ private String retrieveRcGroupId(Session session, List agencyL addSystemUserToGroup(rcGroupId); addConsultantsToGroup(rcGroupId, agencyList); rocketChatService.removeSystemMessages(rcGroupId, - LocalDateTime.now().minusHours(Helper.ONE_DAY_IN_HOURS), LocalDateTime.now()); + nowInUtc().minusHours(Helper.ONE_DAY_IN_HOURS), nowInUtc()); } catch (RocketChatAddSystemUserException | RocketChatAddUserToGroupException | RocketChatRemoveSystemMessagesException | RocketChatUserNotInitializedException exception) { @@ -246,8 +247,9 @@ private String createRcFeedbackGroup(Session session, String rcGroupId, createEnquiryExceptionInformation); addSystemUserToGroup(rcFeedbackGroupId); addConsultantsToFeedbackChatGroup(agencyList, rcFeedbackGroupId); - rocketChatService.removeSystemMessages(rcFeedbackGroupId, - LocalDateTime.now().minusHours(Helper.ONE_DAY_IN_HOURS), LocalDateTime.now()); + rocketChatService + .removeSystemMessages(rcFeedbackGroupId, nowInUtc().minusHours(Helper.ONE_DAY_IN_HOURS), + nowInUtc()); } catch (RocketChatAddSystemUserException | RocketChatCreateGroupException | RocketChatAddUserToGroupException | RocketChatRemoveSystemMessagesException | RocketChatUserNotInitializedException exception) { diff --git a/src/main/java/de/caritas/cob/userservice/api/facade/CreateUserChatRelationFacade.java b/src/main/java/de/caritas/cob/userservice/api/facade/CreateUserChatRelationFacade.java index 8abbbd33e..04ee42a3c 100644 --- a/src/main/java/de/caritas/cob/userservice/api/facade/CreateUserChatRelationFacade.java +++ b/src/main/java/de/caritas/cob/userservice/api/facade/CreateUserChatRelationFacade.java @@ -16,9 +16,9 @@ import de.caritas.cob.userservice.api.model.rocketchat.login.DataDTO; import de.caritas.cob.userservice.api.model.rocketchat.login.LoginResponseDTO; import de.caritas.cob.userservice.api.repository.user.User; -import de.caritas.cob.userservice.api.repository.userAgency.UserAgency; +import de.caritas.cob.userservice.api.repository.useragency.UserAgency; import de.caritas.cob.userservice.api.service.LogService; -import de.caritas.cob.userservice.api.service.RocketChatService; +import de.caritas.cob.userservice.api.service.rocketchat.RocketChatService; import de.caritas.cob.userservice.api.service.UserAgencyService; import de.caritas.cob.userservice.api.service.UserService; import java.util.List; diff --git a/src/main/java/de/caritas/cob/userservice/api/facade/EmailNotificationFacade.java b/src/main/java/de/caritas/cob/userservice/api/facade/EmailNotificationFacade.java index c9772e788..24ef04d9c 100644 --- a/src/main/java/de/caritas/cob/userservice/api/facade/EmailNotificationFacade.java +++ b/src/main/java/de/caritas/cob/userservice/api/facade/EmailNotificationFacade.java @@ -11,12 +11,12 @@ import de.caritas.cob.userservice.api.model.mailservice.MailDTO; import de.caritas.cob.userservice.api.model.mailservice.MailsDTO; import de.caritas.cob.userservice.api.repository.consultant.Consultant; -import de.caritas.cob.userservice.api.repository.consultantAgency.ConsultantAgencyRepository; +import de.caritas.cob.userservice.api.repository.consultantagency.ConsultantAgencyRepository; import de.caritas.cob.userservice.api.repository.session.Session; import de.caritas.cob.userservice.api.service.ConsultantAgencyService; import de.caritas.cob.userservice.api.service.ConsultantService; import de.caritas.cob.userservice.api.service.LogService; -import de.caritas.cob.userservice.api.service.RocketChatService; +import de.caritas.cob.userservice.api.service.rocketchat.RocketChatService; import de.caritas.cob.userservice.api.service.SessionService; import de.caritas.cob.userservice.api.service.emailsupplier.AssignEnquiryEmailSupplier; import de.caritas.cob.userservice.api.service.emailsupplier.EmailSupplier; diff --git a/src/main/java/de/caritas/cob/userservice/api/facade/GetChatMembersFacade.java b/src/main/java/de/caritas/cob/userservice/api/facade/GetChatMembersFacade.java index a0cb62dc6..c560dd53b 100644 --- a/src/main/java/de/caritas/cob/userservice/api/facade/GetChatMembersFacade.java +++ b/src/main/java/de/caritas/cob/userservice/api/facade/GetChatMembersFacade.java @@ -1,7 +1,6 @@ package de.caritas.cob.userservice.api.facade; import static org.apache.commons.lang3.BooleanUtils.isFalse; -import static org.apache.commons.lang3.BooleanUtils.isTrue; import de.caritas.cob.userservice.api.exception.httpresponses.InternalServerErrorException; import de.caritas.cob.userservice.api.exception.rocketchat.RocketChatGetGroupMembersException; @@ -29,7 +28,7 @@ import de.caritas.cob.userservice.api.repository.user.User; import de.caritas.cob.userservice.api.service.ChatService; import de.caritas.cob.userservice.api.service.ConsultantService; -import de.caritas.cob.userservice.api.service.RocketChatService; +import de.caritas.cob.userservice.api.service.rocketchat.RocketChatService; import de.caritas.cob.userservice.api.service.UserService; /** diff --git a/src/main/java/de/caritas/cob/userservice/api/facade/JoinAndLeaveChatFacade.java b/src/main/java/de/caritas/cob/userservice/api/facade/JoinAndLeaveChatFacade.java index f7069ae87..150decdb4 100644 --- a/src/main/java/de/caritas/cob/userservice/api/facade/JoinAndLeaveChatFacade.java +++ b/src/main/java/de/caritas/cob/userservice/api/facade/JoinAndLeaveChatFacade.java @@ -1,7 +1,6 @@ package de.caritas.cob.userservice.api.facade; import static org.apache.commons.lang3.BooleanUtils.isFalse; -import static org.apache.commons.lang3.BooleanUtils.isTrue; import de.caritas.cob.userservice.api.authorization.UserRole; import de.caritas.cob.userservice.api.exception.httpresponses.ConflictException; @@ -18,7 +17,7 @@ import de.caritas.cob.userservice.api.service.ChatService; import de.caritas.cob.userservice.api.service.ConsultantService; import de.caritas.cob.userservice.api.service.LogService; -import de.caritas.cob.userservice.api.service.RocketChatService; +import de.caritas.cob.userservice.api.service.rocketchat.RocketChatService; import de.caritas.cob.userservice.api.service.UserService; import java.util.Optional; import java.util.Set; diff --git a/src/main/java/de/caritas/cob/userservice/api/facade/StartChatFacade.java b/src/main/java/de/caritas/cob/userservice/api/facade/StartChatFacade.java index 77a319a64..8aba83012 100644 --- a/src/main/java/de/caritas/cob/userservice/api/facade/StartChatFacade.java +++ b/src/main/java/de/caritas/cob/userservice/api/facade/StartChatFacade.java @@ -14,7 +14,7 @@ import de.caritas.cob.userservice.api.repository.chat.Chat; import de.caritas.cob.userservice.api.repository.consultant.Consultant; import de.caritas.cob.userservice.api.service.ChatService; -import de.caritas.cob.userservice.api.service.RocketChatService; +import de.caritas.cob.userservice.api.service.rocketchat.RocketChatService; /** * Facade for capsuling starting a chat diff --git a/src/main/java/de/caritas/cob/userservice/api/facade/StopChatFacade.java b/src/main/java/de/caritas/cob/userservice/api/facade/StopChatFacade.java index b8c5bdf47..b2ecd1b44 100644 --- a/src/main/java/de/caritas/cob/userservice/api/facade/StopChatFacade.java +++ b/src/main/java/de/caritas/cob/userservice/api/facade/StopChatFacade.java @@ -11,7 +11,6 @@ import de.caritas.cob.userservice.api.exception.rocketchat.RocketChatUserNotInitializedException; import de.caritas.cob.userservice.api.service.LogService; import java.time.LocalDateTime; -import org.apache.commons.lang3.BooleanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import de.caritas.cob.userservice.api.exception.httpresponses.ConflictException; @@ -20,7 +19,7 @@ import de.caritas.cob.userservice.api.repository.chat.Chat; import de.caritas.cob.userservice.api.repository.consultant.Consultant; import de.caritas.cob.userservice.api.service.ChatService; -import de.caritas.cob.userservice.api.service.RocketChatService; +import de.caritas.cob.userservice.api.service.rocketchat.RocketChatService; /* * Facade to encapsulate the steps to stop a running chat session. diff --git a/src/main/java/de/caritas/cob/userservice/api/facade/assignsession/AssignSessionFacade.java b/src/main/java/de/caritas/cob/userservice/api/facade/assignsession/AssignSessionFacade.java index fe9cf28ea..1109bd340 100644 --- a/src/main/java/de/caritas/cob/userservice/api/facade/assignsession/AssignSessionFacade.java +++ b/src/main/java/de/caritas/cob/userservice/api/facade/assignsession/AssignSessionFacade.java @@ -1,5 +1,6 @@ package de.caritas.cob.userservice.api.facade.assignsession; +import static de.caritas.cob.userservice.localdatetime.CustomLocalDateTime.nowInUtc; import static java.util.Objects.nonNull; import de.caritas.cob.userservice.api.authorization.Authorities.Authority; @@ -20,10 +21,10 @@ import de.caritas.cob.userservice.api.repository.session.SessionStatus; import de.caritas.cob.userservice.api.service.ConsultantService; import de.caritas.cob.userservice.api.service.LogService; -import de.caritas.cob.userservice.api.service.RocketChatService; +import de.caritas.cob.userservice.api.service.rocketchat.RocketChatService; import de.caritas.cob.userservice.api.service.SessionService; import de.caritas.cob.userservice.api.service.helper.KeycloakAdminClientService; -import de.caritas.cob.userservice.api.service.helper.RocketChatRollbackHelper; +import de.caritas.cob.userservice.api.service.rocketchat.RocketChatRollbackService; import java.time.LocalDateTime; import java.util.List; import java.util.Optional; @@ -51,7 +52,7 @@ public class AssignSessionFacade { private final @NonNull RocketChatService rocketChatService; private final @NonNull KeycloakAdminClientService keycloakAdminClientService; private final @NonNull ConsultantService consultantService; - private final @NonNull RocketChatRollbackHelper rocketChatRollbackHelper; + private final @NonNull RocketChatRollbackService rocketChatRollbackService; private final @NonNull AuthenticatedUser authenticatedUser; private final @NonNull EmailNotificationFacade emailNotificationFacade; @@ -162,7 +163,7 @@ private void rollbackSessionAndRocketChatGroup(Session session, Consultant initialConsultant, SessionStatus initialStatus, List memberList) { rollbackSessionUpdate(session, initialConsultant, initialStatus); - rocketChatRollbackHelper.rollbackRemoveUsersFromRocketChatGroup(session.getGroupId(), + rocketChatRollbackService.rollbackRemoveUsersFromRocketChatGroup(session.getGroupId(), memberList); if (nonNull(initialConsultant)) { try { @@ -185,7 +186,7 @@ private void addUserToRocketChatGroup(String groupId, String rcUserId, Session s rollbackSessionUpdate(session, initialConsultant, initialStatus); if (session.hasFeedbackChat()) { - rocketChatRollbackHelper.rollbackRemoveUsersFromRocketChatGroup(groupId, memberList); + rocketChatRollbackService.rollbackRemoveUsersFromRocketChatGroup(groupId, memberList); } String message = String.format( @@ -358,7 +359,7 @@ private void removeSystemMessagesFromRocketChatGroup(String groupId, try { rocketChatService.removeSystemMessages(groupId, - LocalDateTime.now().minusHours(Helper.ONE_DAY_IN_HOURS), LocalDateTime.now()); + nowInUtc().minusHours(Helper.ONE_DAY_IN_HOURS), nowInUtc()); } catch (RocketChatRemoveSystemMessagesException | RocketChatUserNotInitializedException e) { if (nonNull(rcUserIdToRemoveOnRollback)) { removeUserFromGroupAndRollbackSession(rcUserIdToRemoveOnRollback, session, diff --git a/src/main/java/de/caritas/cob/userservice/api/facade/assignsession/SessionToConsultantConditionProvider.java b/src/main/java/de/caritas/cob/userservice/api/facade/assignsession/SessionToConsultantConditionProvider.java index 8422bfb72..06dbf71d6 100644 --- a/src/main/java/de/caritas/cob/userservice/api/facade/assignsession/SessionToConsultantConditionProvider.java +++ b/src/main/java/de/caritas/cob/userservice/api/facade/assignsession/SessionToConsultantConditionProvider.java @@ -7,7 +7,7 @@ import static org.apache.commons.lang3.StringUtils.isBlank; import de.caritas.cob.userservice.api.repository.consultant.Consultant; -import de.caritas.cob.userservice.api.repository.consultantAgency.ConsultantAgency; +import de.caritas.cob.userservice.api.repository.consultantagency.ConsultantAgency; import de.caritas.cob.userservice.api.repository.session.Session; import de.caritas.cob.userservice.api.repository.session.SessionStatus; import lombok.Getter; diff --git a/src/main/java/de/caritas/cob/userservice/api/facade/rollback/RollbackUserAccountInformation.java b/src/main/java/de/caritas/cob/userservice/api/facade/rollback/RollbackUserAccountInformation.java index 537d5013f..47d23f108 100644 --- a/src/main/java/de/caritas/cob/userservice/api/facade/rollback/RollbackUserAccountInformation.java +++ b/src/main/java/de/caritas/cob/userservice/api/facade/rollback/RollbackUserAccountInformation.java @@ -2,7 +2,7 @@ import de.caritas.cob.userservice.api.repository.session.Session; import de.caritas.cob.userservice.api.repository.user.User; -import de.caritas.cob.userservice.api.repository.userAgency.UserAgency; +import de.caritas.cob.userservice.api.repository.useragency.UserAgency; import lombok.Builder; import lombok.Data; @@ -19,4 +19,4 @@ public class RollbackUserAccountInformation { private Session session; private UserAgency userAgency; private boolean rollBackUserAccount; -} \ No newline at end of file +} diff --git a/src/main/java/de/caritas/cob/userservice/api/facade/sessionlist/RocketChatRoomInformationProvider.java b/src/main/java/de/caritas/cob/userservice/api/facade/sessionlist/RocketChatRoomInformationProvider.java index 382093621..e6b9c0d72 100644 --- a/src/main/java/de/caritas/cob/userservice/api/facade/sessionlist/RocketChatRoomInformationProvider.java +++ b/src/main/java/de/caritas/cob/userservice/api/facade/sessionlist/RocketChatRoomInformationProvider.java @@ -14,7 +14,7 @@ import de.caritas.cob.userservice.api.model.rocketchat.room.RoomsLastMessageDTO; import de.caritas.cob.userservice.api.model.rocketchat.room.RoomsUpdateDTO; import de.caritas.cob.userservice.api.model.rocketchat.subscriptions.SubscriptionsUpdateDTO; -import de.caritas.cob.userservice.api.service.RocketChatService; +import de.caritas.cob.userservice.api.service.rocketchat.RocketChatService; @Component public class RocketChatRoomInformationProvider { diff --git a/src/main/java/de/caritas/cob/userservice/api/facade/userdata/AskerDataProvider.java b/src/main/java/de/caritas/cob/userservice/api/facade/userdata/AskerDataProvider.java index 6e27d84d5..fe2a15d83 100644 --- a/src/main/java/de/caritas/cob/userservice/api/facade/userdata/AskerDataProvider.java +++ b/src/main/java/de/caritas/cob/userservice/api/facade/userdata/AskerDataProvider.java @@ -11,12 +11,13 @@ import de.caritas.cob.userservice.api.repository.session.ConsultingType; import de.caritas.cob.userservice.api.repository.session.Session; import de.caritas.cob.userservice.api.repository.user.User; -import de.caritas.cob.userservice.api.repository.userAgency.UserAgency; +import de.caritas.cob.userservice.api.repository.useragency.UserAgency; import de.caritas.cob.userservice.api.service.helper.AgencyServiceHelper; import java.util.ArrayList; import java.util.Collections; import java.util.LinkedHashMap; import java.util.List; +import java.util.Map; import java.util.Optional; import java.util.Set; import java.util.stream.Collectors; @@ -89,7 +90,7 @@ private LinkedHashMap getConsultingTypeData(ConsultingType consu LinkedHashMap consultingTypeData = new LinkedHashMap<>(); Optional consultingTypeSession = findSessionByConsultingType(consultingType, sessionList); - Optional> consultingTypeSessionData = + Optional> consultingTypeSessionData = consultingTypeSession.map(sessionDataHelper::getSessionDataMapFromSession); Optional agency = findAgencyByConsultingType(consultingType, agencyDTOs); diff --git a/src/main/java/de/caritas/cob/userservice/api/facade/userdata/ConsultantDataProvider.java b/src/main/java/de/caritas/cob/userservice/api/facade/userdata/ConsultantDataProvider.java index 583635388..647c504d1 100644 --- a/src/main/java/de/caritas/cob/userservice/api/facade/userdata/ConsultantDataProvider.java +++ b/src/main/java/de/caritas/cob/userservice/api/facade/userdata/ConsultantDataProvider.java @@ -6,7 +6,7 @@ import de.caritas.cob.userservice.api.model.AgencyDTO; import de.caritas.cob.userservice.api.model.user.UserDataResponseDTO; import de.caritas.cob.userservice.api.repository.consultant.Consultant; -import de.caritas.cob.userservice.api.repository.consultantAgency.ConsultantAgency; +import de.caritas.cob.userservice.api.repository.consultantagency.ConsultantAgency; import de.caritas.cob.userservice.api.service.LogService; import de.caritas.cob.userservice.api.service.helper.AgencyServiceHelper; import java.util.List; diff --git a/src/main/java/de/caritas/cob/userservice/api/helper/ChatHelper.java b/src/main/java/de/caritas/cob/userservice/api/helper/ChatHelper.java index 3c0cff5ea..33e830040 100644 --- a/src/main/java/de/caritas/cob/userservice/api/helper/ChatHelper.java +++ b/src/main/java/de/caritas/cob/userservice/api/helper/ChatHelper.java @@ -8,12 +8,12 @@ import de.caritas.cob.userservice.api.model.chat.ChatDTO; import de.caritas.cob.userservice.api.repository.chat.Chat; import de.caritas.cob.userservice.api.repository.chat.ChatInterval; -import de.caritas.cob.userservice.api.repository.chatAgency.ChatAgency; +import de.caritas.cob.userservice.api.repository.chatagency.ChatAgency; import de.caritas.cob.userservice.api.repository.consultant.Consultant; -import de.caritas.cob.userservice.api.repository.consultantAgency.ConsultantAgency; +import de.caritas.cob.userservice.api.repository.consultantagency.ConsultantAgency; import de.caritas.cob.userservice.api.repository.session.ConsultingType; import de.caritas.cob.userservice.api.repository.user.User; -import de.caritas.cob.userservice.api.repository.userAgency.UserAgency; +import de.caritas.cob.userservice.api.repository.useragency.UserAgency; /** * diff --git a/src/main/java/de/caritas/cob/userservice/api/helper/MonitoringHelper.java b/src/main/java/de/caritas/cob/userservice/api/helper/MonitoringHelper.java index d3f2a5268..0a38fa32b 100644 --- a/src/main/java/de/caritas/cob/userservice/api/helper/MonitoringHelper.java +++ b/src/main/java/de/caritas/cob/userservice/api/helper/MonitoringHelper.java @@ -16,7 +16,7 @@ import de.caritas.cob.userservice.api.model.monitoring.MonitoringDTO; import de.caritas.cob.userservice.api.repository.monitoring.Monitoring; import de.caritas.cob.userservice.api.repository.monitoring.MonitoringType; -import de.caritas.cob.userservice.api.repository.monitoringOption.MonitoringOption; +import de.caritas.cob.userservice.api.repository.monitoringoption.MonitoringOption; import de.caritas.cob.userservice.api.repository.session.ConsultingType; import de.caritas.cob.userservice.api.repository.session.Session; import de.caritas.cob.userservice.api.service.LogService; diff --git a/src/main/java/de/caritas/cob/userservice/api/helper/SessionDataHelper.java b/src/main/java/de/caritas/cob/userservice/api/helper/SessionDataHelper.java index aa17aade3..e5b70edac 100644 --- a/src/main/java/de/caritas/cob/userservice/api/helper/SessionDataHelper.java +++ b/src/main/java/de/caritas/cob/userservice/api/helper/SessionDataHelper.java @@ -1,44 +1,40 @@ package de.caritas.cob.userservice.api.helper; -import java.util.ArrayList; -import java.util.LinkedHashMap; -import java.util.List; -import org.apache.commons.lang3.StringUtils; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; import de.caritas.cob.userservice.api.manager.consultingtype.ConsultingTypeManager; import de.caritas.cob.userservice.api.manager.consultingtype.SessionDataInitializing; import de.caritas.cob.userservice.api.model.registration.UserDTO; import de.caritas.cob.userservice.api.repository.session.ConsultingType; import de.caritas.cob.userservice.api.repository.session.Session; -import de.caritas.cob.userservice.api.repository.sessionData.SessionData; -import de.caritas.cob.userservice.api.repository.sessionData.SessionDataKeyRegistration; -import de.caritas.cob.userservice.api.repository.sessionData.SessionDataType; +import de.caritas.cob.userservice.api.repository.sessiondata.SessionData; +import de.caritas.cob.userservice.api.repository.sessiondata.SessionDataKeyRegistration; +import de.caritas.cob.userservice.api.repository.sessiondata.SessionDataType; +import java.util.ArrayList; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import lombok.NonNull; +import lombok.RequiredArgsConstructor; +import org.apache.commons.lang3.StringUtils; +import org.springframework.stereotype.Component; /** - * - * Helper class for {@link SessionData} - * + * Helper class for {@link SessionData}. */ @Component +@RequiredArgsConstructor public class SessionDataHelper { - private static ConsultingTypeManager consultingTypeManager; - - @Autowired - public SessionDataHelper(ConsultingTypeManager consultingTypeManager) { - SessionDataHelper.consultingTypeManager = consultingTypeManager; - } + private final @NonNull ConsultingTypeManager consultingTypeManager; /** - * Get map of session data items from registration - * + * Get map of session data items from registration. + * * @param session {@link Session} * @return a map with registration session data items of the session */ - public LinkedHashMap getSessionDataMapFromSession(Session session) { + public Map getSessionDataMapFromSession(Session session) { - LinkedHashMap sessionDataMap = new LinkedHashMap(); + Map sessionDataMap = new LinkedHashMap<>(); if (session.getSessionData() != null) { for (SessionData sessionData : session.getSessionData()) { @@ -53,15 +49,15 @@ public LinkedHashMap getSessionDataMapFromSession(Session sessio } /** - * Get list of session data items for registration - * + * Get list of session data items for registration. + * * @param session the {@link Session} - * @param user the {@link UserDTO} + * @param user the {@link UserDTO} * @return the list of session data items for registration */ public List createRegistrationSessionDataList(Session session, UserDTO user) { - List sessionDataList = new ArrayList(); + List sessionDataList = new ArrayList<>(); if (getSessionDataInitializing(session.getConsultingType()).isAddictiveDrugs()) { sessionDataList.add(createSessionData(session, SessionDataType.REGISTRATION, SessionDataKeyRegistration.ADDICTIVE_DRUGS.getValue(), @@ -92,20 +88,6 @@ private SessionDataInitializing getSessionDataInitializing(ConsultingType consul } - public String getValueOfKey(List sessionDataList, String key) { - - if (sessionDataList != null) { - SessionData sessionData = - sessionDataList.stream().filter(data -> key.equals(data.getKey())).findAny().orElse(null); - - if (sessionData != null) { - return sessionData.getValue(); - } - } - - return null; - } - private SessionData createSessionData(Session session, SessionDataType sessionDataType, String key, String value) { return new SessionData(session, sessionDataType, key, value); diff --git a/src/main/java/de/caritas/cob/userservice/api/model/user/SessionUserDTO.java b/src/main/java/de/caritas/cob/userservice/api/model/user/SessionUserDTO.java index 9efd58e32..181346858 100644 --- a/src/main/java/de/caritas/cob/userservice/api/model/user/SessionUserDTO.java +++ b/src/main/java/de/caritas/cob/userservice/api/model/user/SessionUserDTO.java @@ -1,8 +1,8 @@ package de.caritas.cob.userservice.api.model.user; -import java.util.LinkedHashMap; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; +import java.util.Map; import lombok.AllArgsConstructor; import lombok.Getter; import lombok.NoArgsConstructor; @@ -17,6 +17,6 @@ public class SessionUserDTO { @ApiModelProperty(example = "Username", position = 0) private String username; - private LinkedHashMap sessionData; + private Map sessionData; } diff --git a/src/main/java/de/caritas/cob/userservice/api/repository/chat/Chat.java b/src/main/java/de/caritas/cob/userservice/api/repository/chat/Chat.java index 585c74ae0..d42c67824 100644 --- a/src/main/java/de/caritas/cob/userservice/api/repository/chat/Chat.java +++ b/src/main/java/de/caritas/cob/userservice/api/repository/chat/Chat.java @@ -1,6 +1,7 @@ package de.caritas.cob.userservice.api.repository.chat; import java.time.LocalDateTime; +import java.util.Objects; import java.util.Set; import javax.persistence.Column; import javax.persistence.Entity; @@ -19,7 +20,7 @@ import org.hibernate.annotations.Fetch; import org.hibernate.annotations.FetchMode; import org.hibernate.annotations.Type; -import de.caritas.cob.userservice.api.repository.chatAgency.ChatAgency; +import de.caritas.cob.userservice.api.repository.chatagency.ChatAgency; import de.caritas.cob.userservice.api.repository.consultant.Consultant; import de.caritas.cob.userservice.api.repository.session.ConsultingType; import lombok.AllArgsConstructor; @@ -29,8 +30,7 @@ import lombok.Setter; /** - * Representation of a chat - * + * Representation of a chat. */ @Entity @Table(name = "chat") @@ -106,12 +106,20 @@ public Chat(String topic, ConsultingType consultingType, LocalDateTime initialSt this.chatOwner = chatOwner; } - public Chat(LocalDateTime startDate, boolean repetitive, ChatInterval chatInterval, - boolean active, String groupId) { - this.startDate = startDate; - this.repetitive = repetitive; - this.chatInterval = chatInterval; - this.active = active; - this.groupId = groupId; + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (!(o instanceof Chat)) { + return false; + } + Chat chat = (Chat) o; + return id.equals(chat.id); + } + + @Override + public int hashCode() { + return Objects.hash(id); } } diff --git a/src/main/java/de/caritas/cob/userservice/api/repository/chatAgency/ChatAgency.java b/src/main/java/de/caritas/cob/userservice/api/repository/chatagency/ChatAgency.java similarity index 77% rename from src/main/java/de/caritas/cob/userservice/api/repository/chatAgency/ChatAgency.java rename to src/main/java/de/caritas/cob/userservice/api/repository/chatagency/ChatAgency.java index b8c88d3bb..0f825eeea 100644 --- a/src/main/java/de/caritas/cob/userservice/api/repository/chatAgency/ChatAgency.java +++ b/src/main/java/de/caritas/cob/userservice/api/repository/chatagency/ChatAgency.java @@ -1,5 +1,6 @@ -package de.caritas.cob.userservice.api.repository.chatAgency; +package de.caritas.cob.userservice.api.repository.chatagency; +import java.util.Objects; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.GeneratedValue; @@ -46,9 +47,25 @@ public ChatAgency(Chat chat, Long agencyId) { this.agencyId = agencyId; } - @Override public String toString() { return "ChatAgency [id=" + id + ", chat=" + chat.toString() + ", agencyId=" + agencyId + "]"; } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (!(o instanceof ChatAgency)) { + return false; + } + ChatAgency that = (ChatAgency) o; + return id.equals(that.id); + } + + @Override + public int hashCode() { + return Objects.hash(id); + } } diff --git a/src/main/java/de/caritas/cob/userservice/api/repository/chatAgency/ChatAgencyRepository.java b/src/main/java/de/caritas/cob/userservice/api/repository/chatagency/ChatAgencyRepository.java similarity index 70% rename from src/main/java/de/caritas/cob/userservice/api/repository/chatAgency/ChatAgencyRepository.java rename to src/main/java/de/caritas/cob/userservice/api/repository/chatagency/ChatAgencyRepository.java index 401993d70..185bc2b19 100644 --- a/src/main/java/de/caritas/cob/userservice/api/repository/chatAgency/ChatAgencyRepository.java +++ b/src/main/java/de/caritas/cob/userservice/api/repository/chatagency/ChatAgencyRepository.java @@ -1,4 +1,4 @@ -package de.caritas.cob.userservice.api.repository.chatAgency; +package de.caritas.cob.userservice.api.repository.chatagency; import org.springframework.data.repository.CrudRepository; diff --git a/src/main/java/de/caritas/cob/userservice/api/repository/consultant/Consultant.java b/src/main/java/de/caritas/cob/userservice/api/repository/consultant/Consultant.java index 73ce53e50..13bc4d7a4 100644 --- a/src/main/java/de/caritas/cob/userservice/api/repository/consultant/Consultant.java +++ b/src/main/java/de/caritas/cob/userservice/api/repository/consultant/Consultant.java @@ -2,9 +2,10 @@ import static de.caritas.cob.userservice.api.repository.consultant.Consultant.EMAIL_ANALYZER; -import de.caritas.cob.userservice.api.repository.consultantAgency.ConsultantAgency; +import de.caritas.cob.userservice.api.repository.consultantagency.ConsultantAgency; import de.caritas.cob.userservice.api.repository.session.Session; import java.time.LocalDateTime; +import java.util.Objects; import java.util.Set; import javax.persistence.Column; import javax.persistence.Entity; @@ -127,73 +128,20 @@ public String getFullName() { } @Override - public boolean equals(Object obj) { - - // If i´m compared to myself => true - if (obj == this) { + public boolean equals(Object o) { + if (this == o) { return true; } - - // If the obj ist not an instance of Consultant => false - if (!(obj instanceof Consultant)) { - return false; - } - - Consultant other = (Consultant) obj; - - if (!this.id.equals(other.id)) { - return false; - } - - if (!this.rocketChatId.equals(other.rocketChatId)) { - return false; - } - - if (!this.username.equals(other.username)) { - return false; - } - - if (!this.firstName.equals(other.firstName)) { - return false; - } - - if (!this.lastName.equals(other.lastName)) { - return false; - } - - if (!this.email.equals(other.email)) { - return false; - } - - if (this.absent != other.absent) { - return false; - } - - if (this.teamConsultant != other.teamConsultant) { - return false; - } - - if (!this.absenceMessage.equals(other.absenceMessage)) { - return false; - } - - if (!this.idOld.equals(other.idOld)) { - return false; - } - - if (!this.sessions.equals(other.sessions)) { - return false; - } - - if (!this.consultantAgencies.equals(other.consultantAgencies)) { - return false; - } - - if (this.languageFormal != other.languageFormal) { + if (!(o instanceof Consultant)) { return false; } + Consultant that = (Consultant) o; + return id.equals(that.id); + } - return true; + @Override + public int hashCode() { + return Objects.hash(id); } @Override diff --git a/src/main/java/de/caritas/cob/userservice/api/repository/consultantAgency/ConsultantAgency.java b/src/main/java/de/caritas/cob/userservice/api/repository/consultantagency/ConsultantAgency.java similarity index 76% rename from src/main/java/de/caritas/cob/userservice/api/repository/consultantAgency/ConsultantAgency.java rename to src/main/java/de/caritas/cob/userservice/api/repository/consultantagency/ConsultantAgency.java index d5b4243d6..9c2fd29d7 100644 --- a/src/main/java/de/caritas/cob/userservice/api/repository/consultantAgency/ConsultantAgency.java +++ b/src/main/java/de/caritas/cob/userservice/api/repository/consultantagency/ConsultantAgency.java @@ -1,7 +1,8 @@ -package de.caritas.cob.userservice.api.repository.consultantAgency; +package de.caritas.cob.userservice.api.repository.consultantagency; import de.caritas.cob.userservice.api.repository.consultant.Consultant; import java.time.LocalDateTime; +import java.util.Objects; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.GeneratedValue; @@ -55,4 +56,23 @@ public class ConsultantAgency { @Column(name = "update_date") private LocalDateTime updateDate; + @Column(name = "delete_date") + private LocalDateTime deleteDate; + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (!(o instanceof ConsultantAgency)) { + return false; + } + ConsultantAgency that = (ConsultantAgency) o; + return id.equals(that.id); + } + + @Override + public int hashCode() { + return Objects.hash(id); + } } diff --git a/src/main/java/de/caritas/cob/userservice/api/repository/consultantAgency/ConsultantAgencyRepository.java b/src/main/java/de/caritas/cob/userservice/api/repository/consultantagency/ConsultantAgencyRepository.java similarity index 88% rename from src/main/java/de/caritas/cob/userservice/api/repository/consultantAgency/ConsultantAgencyRepository.java rename to src/main/java/de/caritas/cob/userservice/api/repository/consultantagency/ConsultantAgencyRepository.java index 590072862..912de9420 100644 --- a/src/main/java/de/caritas/cob/userservice/api/repository/consultantAgency/ConsultantAgencyRepository.java +++ b/src/main/java/de/caritas/cob/userservice/api/repository/consultantagency/ConsultantAgencyRepository.java @@ -1,4 +1,4 @@ -package de.caritas.cob.userservice.api.repository.consultantAgency; +package de.caritas.cob.userservice.api.repository.consultantagency; import java.util.List; import org.springframework.data.repository.CrudRepository; diff --git a/src/main/java/de/caritas/cob/userservice/api/repository/monitoring/Monitoring.java b/src/main/java/de/caritas/cob/userservice/api/repository/monitoring/Monitoring.java index 2f7d5eb7e..405efd9f8 100644 --- a/src/main/java/de/caritas/cob/userservice/api/repository/monitoring/Monitoring.java +++ b/src/main/java/de/caritas/cob/userservice/api/repository/monitoring/Monitoring.java @@ -1,6 +1,7 @@ package de.caritas.cob.userservice.api.repository.monitoring; import java.util.List; +import java.util.Objects; import javax.persistence.CascadeType; import javax.persistence.Column; import javax.persistence.Entity; @@ -10,7 +11,7 @@ import javax.persistence.OneToMany; import javax.persistence.Table; import javax.validation.constraints.Size; -import de.caritas.cob.userservice.api.repository.monitoringOption.MonitoringOption; +import de.caritas.cob.userservice.api.repository.monitoringoption.MonitoringOption; import lombok.AllArgsConstructor; import lombok.Getter; import lombok.NoArgsConstructor; @@ -33,7 +34,6 @@ public class Monitoring { public Monitoring(Long sessionId, MonitoringType monitoringType, @Size(max = 255) String key, Boolean value) { - super(); this.sessionId = sessionId; this.monitoringType = monitoringType; this.key = key; @@ -56,7 +56,7 @@ public Monitoring(Long sessionId, MonitoringType monitoringType, @Size(max = 255 private MonitoringType monitoringType; @Id - @Column(name = "key_name", updatable = true, nullable = true) + @Column(name = "key_name") @NonNull @Size(max = 255) private String key; @@ -66,4 +66,23 @@ public Monitoring(Long sessionId, MonitoringType monitoringType, @Size(max = 255 @OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL, mappedBy = "monitoring") private List monitoringOptionList; + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (!(o instanceof Monitoring)) { + return false; + } + Monitoring that = (Monitoring) o; + return sessionId.equals(that.sessionId) + && monitoringType == that.monitoringType + && key.equals(that.key); + } + + @Override + public int hashCode() { + return Objects.hash(sessionId, monitoringType, key); + } } diff --git a/src/main/java/de/caritas/cob/userservice/api/repository/monitoringOption/MonitoringOption.java b/src/main/java/de/caritas/cob/userservice/api/repository/monitoringoption/MonitoringOption.java similarity index 52% rename from src/main/java/de/caritas/cob/userservice/api/repository/monitoringOption/MonitoringOption.java rename to src/main/java/de/caritas/cob/userservice/api/repository/monitoringoption/MonitoringOption.java index 7bd03b354..540385a24 100644 --- a/src/main/java/de/caritas/cob/userservice/api/repository/monitoringOption/MonitoringOption.java +++ b/src/main/java/de/caritas/cob/userservice/api/repository/monitoringoption/MonitoringOption.java @@ -1,16 +1,16 @@ -package de.caritas.cob.userservice.api.repository.monitoringOption; +package de.caritas.cob.userservice.api.repository.monitoringoption; +import de.caritas.cob.userservice.api.repository.monitoring.Monitoring; +import de.caritas.cob.userservice.api.repository.monitoring.MonitoringType; +import java.util.Objects; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Id; import javax.persistence.IdClass; import javax.persistence.JoinColumn; -import javax.persistence.JoinColumns; import javax.persistence.ManyToOne; import javax.persistence.Table; import javax.validation.constraints.Size; -import de.caritas.cob.userservice.api.repository.monitoring.Monitoring; -import de.caritas.cob.userservice.api.repository.monitoring.MonitoringType; import lombok.AllArgsConstructor; import lombok.Getter; import lombok.NoArgsConstructor; @@ -19,9 +19,7 @@ /** * Represents the monitoring option of an asker - * */ - @Entity @Table(name = "session_monitoring_option") @AllArgsConstructor @@ -42,27 +40,46 @@ public class MonitoringOption { private MonitoringType monitoringType; @Id - @Column(name = "monitoring_key_name", updatable = true, nullable = true) + @Column(name = "monitoring_key_name") @NonNull @Size(max = 255) - private String monitoring_key; + private String monitoringKey; @Id - @Column(name = "key_name", updatable = true, nullable = true) + @Column(name = "key_name") @NonNull @Size(max = 255) private String key; - @Column(name = "value", updatable = true, nullable = true) + @Column(name = "value") private Boolean value; @ManyToOne - @JoinColumns({ - @JoinColumn(name = "session_id", referencedColumnName = "session_id", insertable = false, - updatable = false), - @JoinColumn(name = "monitoring_type", referencedColumnName = "type", insertable = false, - updatable = false), - @JoinColumn(name = "monitoring_key_name", referencedColumnName = "key_name", - insertable = false, updatable = false)}) + @JoinColumn(name = "session_id", referencedColumnName = "session_id", insertable = false, + updatable = false) + @JoinColumn(name = "monitoring_type", referencedColumnName = "type", insertable = false, + updatable = false) + @JoinColumn(name = "monitoring_key_name", referencedColumnName = "key_name", + insertable = false, updatable = false) private Monitoring monitoring; + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (!(o instanceof MonitoringOption)) { + return false; + } + MonitoringOption that = (MonitoringOption) o; + return sessionId.equals(that.sessionId) + && monitoringType == that.monitoringType + && monitoringKey.equals(that.monitoringKey) + && key.equals(that.key); + } + + @Override + public int hashCode() { + return Objects.hash(sessionId, monitoringType, monitoringKey, key); + } } diff --git a/src/main/java/de/caritas/cob/userservice/api/repository/monitoringOption/MonitoringOptionKey.java b/src/main/java/de/caritas/cob/userservice/api/repository/monitoringoption/MonitoringOptionKey.java similarity index 75% rename from src/main/java/de/caritas/cob/userservice/api/repository/monitoringOption/MonitoringOptionKey.java rename to src/main/java/de/caritas/cob/userservice/api/repository/monitoringoption/MonitoringOptionKey.java index 9d5ece8f6..509fe6bae 100644 --- a/src/main/java/de/caritas/cob/userservice/api/repository/monitoringOption/MonitoringOptionKey.java +++ b/src/main/java/de/caritas/cob/userservice/api/repository/monitoringoption/MonitoringOptionKey.java @@ -1,4 +1,4 @@ -package de.caritas.cob.userservice.api.repository.monitoringOption; +package de.caritas.cob.userservice.api.repository.monitoringoption; import java.io.Serializable; import de.caritas.cob.userservice.api.repository.monitoring.MonitoringType; @@ -8,10 +8,8 @@ import lombok.Setter; /** - * Composite key for {@link MonitoringOption} - * + * Composite key for {@link MonitoringOption}. */ - @SuppressWarnings("serial") @Getter @Setter @@ -21,6 +19,6 @@ public class MonitoringOptionKey implements Serializable { private Long sessionId; private MonitoringType monitoringType; - private String monitoring_key; + private String monitoringKey; private String key; } diff --git a/src/main/java/de/caritas/cob/userservice/api/repository/session/Session.java b/src/main/java/de/caritas/cob/userservice/api/repository/session/Session.java index 1c31a8c75..6e8dc4e4f 100644 --- a/src/main/java/de/caritas/cob/userservice/api/repository/session/Session.java +++ b/src/main/java/de/caritas/cob/userservice/api/repository/session/Session.java @@ -1,11 +1,14 @@ package de.caritas.cob.userservice.api.repository.session; +import static org.apache.commons.lang3.StringUtils.isNotBlank; + import de.caritas.cob.userservice.api.repository.consultant.Consultant; -import de.caritas.cob.userservice.api.repository.sessionData.SessionData; +import de.caritas.cob.userservice.api.repository.sessiondata.SessionData; import de.caritas.cob.userservice.api.repository.user.User; import java.time.LocalDateTime; import java.util.Date; import java.util.List; +import java.util.Objects; import javax.persistence.CascadeType; import javax.persistence.Column; import javax.persistence.Entity; @@ -21,6 +24,7 @@ import javax.validation.constraints.Size; import lombok.AllArgsConstructor; import lombok.Getter; +import lombok.NoArgsConstructor; import lombok.NonNull; import lombok.Setter; import lombok.ToString; @@ -31,18 +35,16 @@ /** * Represents a session of a user - * */ @Entity @Table(name = "session") @AllArgsConstructor +@NoArgsConstructor @Getter @Setter @ToString public class Session { - public Session() {} - public Session(User user, ConsultingType consultingType, String postcode, Long agencyId, SessionStatus status, boolean teamSession, boolean monitoring) { this.user = user; @@ -54,36 +56,6 @@ public Session(User user, ConsultingType consultingType, String postcode, Long a this.monitoring = monitoring; } - public Session(Long id, User user, Consultant consultant, ConsultingType consultingType, - String postcode, Long agencyId, SessionStatus status, Date messageDate, String groupId) { - this.id = id; - this.user = user; - this.consultant = consultant; - this.consultingType = consultingType; - this.postcode = postcode; - this.agencyId = agencyId; - this.status = status; - this.enquiryMessageDate = messageDate; - this.groupId = groupId; - } - - public Session(Long id, User user, Consultant consultant, ConsultingType consultingType, - @Size(max = 5) String postcode, Long agencyId, SessionStatus status, Date enquiryMessageDate, - String groupId, List sessionData, boolean teamSession, boolean monitoring) { - this.id = id; - this.user = user; - this.consultant = consultant; - this.consultingType = consultingType; - this.postcode = postcode; - this.agencyId = agencyId; - this.status = status; - this.enquiryMessageDate = enquiryMessageDate; - this.groupId = groupId; - this.sessionData = sessionData; - this.teamSession = teamSession; - this.monitoring = monitoring; - } - @Id @SequenceGenerator(name = "id_seq", allocationSize = 1, sequenceName = "sequence_session") @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "id_seq") @@ -103,25 +75,25 @@ public Session(Long id, User user, Consultant consultant, ConsultingType consult @NonNull private ConsultingType consultingType; - @Column(name = "postcode", updatable = true, nullable = false) + @Column(name = "postcode", nullable = false) @Size(max = 5) @NonNull private String postcode; - @Column(name = "agency_id", updatable = true, nullable = true) + @Column(name = "agency_id") private Long agencyId; @NonNull private SessionStatus status; - @Column(name = "message_date", updatable = true, nullable = true) + @Column(name = "message_date") @Nullable private Date enquiryMessageDate; - @Column(name = "rc_group_id", updatable = true, nullable = true) + @Column(name = "rc_group_id") private String groupId; - @Column(name = "rc_feedback_group_id", updatable = true, nullable = true) + @Column(name = "rc_feedback_group_id") private String feedbackGroupId; @OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL, mappedBy = "session") @@ -136,7 +108,7 @@ public Session(Long id, User user, Consultant consultant, ConsultingType consult private boolean monitoring; public boolean hasFeedbackChat() { - return feedbackGroupId != null; + return isNotBlank(feedbackGroupId); } @Column(name = "create_date") @@ -146,69 +118,20 @@ public boolean hasFeedbackChat() { private LocalDateTime updateDate; @Override - public boolean equals(Object obj) { - - // If i´m compared to myself => true - if (obj == this) { + public boolean equals(Object o) { + if (this == o) { return true; } - - // If the obj ist not an instance of Session => false - if (!(obj instanceof Session)) { - return false; - } - - Session otherSession = (Session) obj; - - if (this.id != otherSession.id) { - return false; - } - - if (this.agencyId != otherSession.agencyId) { - return false; - } - - if (this.teamSession != otherSession.teamSession) { - return false; - } - - if (!this.status.equals(otherSession.status)) { - return false; - } - - if (!this.consultingType.equals(otherSession.consultingType)) { - return false; - } - - if (!this.enquiryMessageDate.equals(otherSession.enquiryMessageDate)) { - return false; - } - - if (!this.postcode.equals(otherSession.postcode)) { - return false; - } - - if (!this.groupId.equals(otherSession.groupId)) { - return false; - } - - if (!this.feedbackGroupId.equals(otherSession.feedbackGroupId)) { - return false; - } - - if (!sessionData.equals(otherSession.sessionData)) { - return false; - } - - if (!consultant.equals(otherSession.consultant)) { - return false; - } - - if (!user.equals(otherSession.user)) { + if (!(o instanceof Session)) { return false; } + Session session = (Session) o; + return id.equals(session.id); + } - return true; + @Override + public int hashCode() { + return Objects.hash(id); } } diff --git a/src/main/java/de/caritas/cob/userservice/api/repository/sessionData/SessionData.java b/src/main/java/de/caritas/cob/userservice/api/repository/sessiondata/SessionData.java similarity index 68% rename from src/main/java/de/caritas/cob/userservice/api/repository/sessionData/SessionData.java rename to src/main/java/de/caritas/cob/userservice/api/repository/sessiondata/SessionData.java index 6144021c5..c4fdb2bfd 100644 --- a/src/main/java/de/caritas/cob/userservice/api/repository/sessionData/SessionData.java +++ b/src/main/java/de/caritas/cob/userservice/api/repository/sessiondata/SessionData.java @@ -1,5 +1,6 @@ -package de.caritas.cob.userservice.api.repository.sessionData; +package de.caritas.cob.userservice.api.repository.sessiondata; +import java.util.Objects; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.GeneratedValue; @@ -11,6 +12,7 @@ import javax.persistence.Table; import javax.validation.constraints.Size; import de.caritas.cob.userservice.api.repository.session.Session; +import lombok.NoArgsConstructor; import lombok.Getter; import lombok.NonNull; import lombok.Setter; @@ -19,10 +21,9 @@ @Table(name = "session_data") @Getter @Setter +@NoArgsConstructor public class SessionData { - public SessionData() {} - public SessionData(Session session, SessionDataType sessionDataType, String key, String value) { this.session = session; this.sessionDataType = sessionDataType; @@ -55,41 +56,19 @@ public SessionData(Session session, SessionDataType sessionDataType, String key, private String value; @Override - public boolean equals(Object obj) { - - // If i´m compared to myself => true - if (obj == this) { + public boolean equals(Object o) { + if (this == o) { return true; } - - // If the obj ist not an instance of SessionData => false - if (!(obj instanceof SessionData)) { - return false; - } - - SessionData other = (SessionData) obj; - - if (!this.id.equals(other.id)) { - return false; - } - - if (!this.session.equals(other.session)) { - return false; - } - - if (!this.sessionDataType.equals(other.sessionDataType)) { - return false; - } - - if (!this.key.equals(other.key)) { + if (!(o instanceof SessionData)) { return false; } - - if (!this.value.equals(other.value)) { - return false; - } - - return true; + SessionData that = (SessionData) o; + return id.equals(that.id); } + @Override + public int hashCode() { + return Objects.hash(id); + } } diff --git a/src/main/java/de/caritas/cob/userservice/api/repository/sessionData/SessionDataKeyRegistration.java b/src/main/java/de/caritas/cob/userservice/api/repository/sessiondata/SessionDataKeyRegistration.java similarity index 93% rename from src/main/java/de/caritas/cob/userservice/api/repository/sessionData/SessionDataKeyRegistration.java rename to src/main/java/de/caritas/cob/userservice/api/repository/sessiondata/SessionDataKeyRegistration.java index 9a9a66873..2318a24c3 100644 --- a/src/main/java/de/caritas/cob/userservice/api/repository/sessionData/SessionDataKeyRegistration.java +++ b/src/main/java/de/caritas/cob/userservice/api/repository/sessiondata/SessionDataKeyRegistration.java @@ -1,4 +1,4 @@ -package de.caritas.cob.userservice.api.repository.sessionData; +package de.caritas.cob.userservice.api.repository.sessiondata; /** * diff --git a/src/main/java/de/caritas/cob/userservice/api/repository/sessionData/SessionDataRepository.java b/src/main/java/de/caritas/cob/userservice/api/repository/sessiondata/SessionDataRepository.java similarity index 87% rename from src/main/java/de/caritas/cob/userservice/api/repository/sessionData/SessionDataRepository.java rename to src/main/java/de/caritas/cob/userservice/api/repository/sessiondata/SessionDataRepository.java index 28508eb69..740ed409e 100644 --- a/src/main/java/de/caritas/cob/userservice/api/repository/sessionData/SessionDataRepository.java +++ b/src/main/java/de/caritas/cob/userservice/api/repository/sessiondata/SessionDataRepository.java @@ -1,4 +1,4 @@ -package de.caritas.cob.userservice.api.repository.sessionData; +package de.caritas.cob.userservice.api.repository.sessiondata; import java.util.List; import org.springframework.data.repository.CrudRepository; diff --git a/src/main/java/de/caritas/cob/userservice/api/repository/sessionData/SessionDataType.java b/src/main/java/de/caritas/cob/userservice/api/repository/sessiondata/SessionDataType.java similarity index 82% rename from src/main/java/de/caritas/cob/userservice/api/repository/sessionData/SessionDataType.java rename to src/main/java/de/caritas/cob/userservice/api/repository/sessiondata/SessionDataType.java index 341c88912..4c9b69813 100644 --- a/src/main/java/de/caritas/cob/userservice/api/repository/sessionData/SessionDataType.java +++ b/src/main/java/de/caritas/cob/userservice/api/repository/sessiondata/SessionDataType.java @@ -1,4 +1,4 @@ -package de.caritas.cob.userservice.api.repository.sessionData; +package de.caritas.cob.userservice.api.repository.sessiondata; import com.fasterxml.jackson.annotation.JsonFormat; import lombok.AllArgsConstructor; diff --git a/src/main/java/de/caritas/cob/userservice/api/repository/user/User.java b/src/main/java/de/caritas/cob/userservice/api/repository/user/User.java index d56ad7a2d..8525d8e4a 100644 --- a/src/main/java/de/caritas/cob/userservice/api/repository/user/User.java +++ b/src/main/java/de/caritas/cob/userservice/api/repository/user/User.java @@ -1,5 +1,6 @@ package de.caritas.cob.userservice.api.repository.user; +import java.util.Objects; import java.util.Set; import javax.persistence.Column; import javax.persistence.Entity; @@ -7,9 +8,10 @@ import javax.persistence.OneToMany; import javax.persistence.Table; import javax.validation.constraints.Size; +import lombok.NoArgsConstructor; import org.hibernate.annotations.Type; import de.caritas.cob.userservice.api.repository.session.Session; -import de.caritas.cob.userservice.api.repository.userAgency.UserAgency; +import de.caritas.cob.userservice.api.repository.useragency.UserAgency; import lombok.AllArgsConstructor; import lombok.Getter; import lombok.NonNull; @@ -23,13 +25,12 @@ @Entity @Table(name = "user") @AllArgsConstructor +@NoArgsConstructor @Getter @Setter @ToString public class User { - protected User() {} - @Id @Column(name = "user_id", updatable = false, nullable = false) @Size(max = 36) @@ -62,84 +63,6 @@ protected User() {} @OneToMany(mappedBy = "user") private Set userAgencies; - @Override - public boolean equals(Object obj) { - - // If i´m compared to myself => true - if (obj == this) { - return true; - } - - // If the obj is not an instance of User => false - if (!(obj instanceof User)) { - return false; - } - - User other = (User) obj; - - if (!this.userId.equals(other.userId)) { - return false; - } - - if (this.oldId == null && other.oldId != null) { - return false; - } - - if (this.oldId != null && other.oldId == null) { - return false; - } - - if (this.oldId != null && other.oldId != null && !this.oldId.equals(other.oldId)) { - return false; - } - - if (!this.username.equals(other.username)) { - return false; - } - - if (!this.email.equals(other.email)) { - return false; - } - - if (this.rcUserId == null && other.rcUserId != null) { - return false; - } - - if (this.rcUserId != null && other.rcUserId == null) { - return false; - } - - if (this.rcUserId != null && other.rcUserId != null && !this.rcUserId.equals(other.rcUserId)) { - return false; - } - - if (this.languageFormal != other.languageFormal) { - return false; - } - - if (this.sessions == null && other.sessions != null) { - return false; - } - - if (this.sessions != null && other.sessions == null) { - return false; - } - - if (this.sessions != null && other.sessions != null && !this.sessions.equals(other.sessions)) { - return false; - } - - return true; - } - - public User(@Size(max = 36) String userId, @Size(max = 255) String username, - @Size(max = 255) String email, Set sessions) { - this.userId = userId; - this.username = username; - this.email = email; - this.sessions = sessions; - } - public User(@Size(max = 36) String userId, Long oldId, @Size(max = 255) String username, @Size(max = 255) String email, boolean languageFormal) { this.userId = userId; @@ -149,4 +72,20 @@ public User(@Size(max = 36) String userId, Long oldId, @Size(max = 255) String u this.languageFormal = languageFormal; } + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (!(o instanceof User)) { + return false; + } + User user = (User) o; + return userId.equals(user.userId); + } + + @Override + public int hashCode() { + return Objects.hash(userId); + } } diff --git a/src/main/java/de/caritas/cob/userservice/api/repository/userAgency/UserAgency.java b/src/main/java/de/caritas/cob/userservice/api/repository/useragency/UserAgency.java similarity index 75% rename from src/main/java/de/caritas/cob/userservice/api/repository/userAgency/UserAgency.java rename to src/main/java/de/caritas/cob/userservice/api/repository/useragency/UserAgency.java index 1c286f78a..13c62559b 100644 --- a/src/main/java/de/caritas/cob/userservice/api/repository/userAgency/UserAgency.java +++ b/src/main/java/de/caritas/cob/userservice/api/repository/useragency/UserAgency.java @@ -1,5 +1,6 @@ -package de.caritas.cob.userservice.api.repository.userAgency; +package de.caritas.cob.userservice.api.repository.useragency; +import java.util.Objects; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.GeneratedValue; @@ -46,4 +47,20 @@ public UserAgency(User user, Long agencyId) { this.agencyId = agencyId; } + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (!(o instanceof UserAgency)) { + return false; + } + UserAgency that = (UserAgency) o; + return id.equals(that.id); + } + + @Override + public int hashCode() { + return Objects.hash(id); + } } diff --git a/src/main/java/de/caritas/cob/userservice/api/repository/userAgency/UserAgencyRepository.java b/src/main/java/de/caritas/cob/userservice/api/repository/useragency/UserAgencyRepository.java similarity index 81% rename from src/main/java/de/caritas/cob/userservice/api/repository/userAgency/UserAgencyRepository.java rename to src/main/java/de/caritas/cob/userservice/api/repository/useragency/UserAgencyRepository.java index 1be4f7e1a..8129214c5 100644 --- a/src/main/java/de/caritas/cob/userservice/api/repository/userAgency/UserAgencyRepository.java +++ b/src/main/java/de/caritas/cob/userservice/api/repository/useragency/UserAgencyRepository.java @@ -1,4 +1,4 @@ -package de.caritas.cob.userservice.api.repository.userAgency; +package de.caritas.cob.userservice.api.repository.useragency; import java.util.List; import org.springframework.data.repository.CrudRepository; diff --git a/src/main/java/de/caritas/cob/userservice/api/service/AskerImportService.java b/src/main/java/de/caritas/cob/userservice/api/service/AskerImportService.java index 94471292d..4800b5afd 100644 --- a/src/main/java/de/caritas/cob/userservice/api/service/AskerImportService.java +++ b/src/main/java/de/caritas/cob/userservice/api/service/AskerImportService.java @@ -1,5 +1,6 @@ package de.caritas.cob.userservice.api.service; +import static de.caritas.cob.userservice.localdatetime.CustomLocalDateTime.nowInUtc; import static org.apache.commons.lang3.BooleanUtils.isTrue; import de.caritas.cob.userservice.api.authorization.Authorities.Authority; @@ -24,15 +25,17 @@ import de.caritas.cob.userservice.api.model.registration.UserDTO; import de.caritas.cob.userservice.api.model.rocketchat.login.LoginResponseDTO; import de.caritas.cob.userservice.api.repository.consultant.Consultant; -import de.caritas.cob.userservice.api.repository.consultantAgency.ConsultantAgency; +import de.caritas.cob.userservice.api.repository.consultantagency.ConsultantAgency; import de.caritas.cob.userservice.api.repository.session.ConsultingType; import de.caritas.cob.userservice.api.repository.session.Session; import de.caritas.cob.userservice.api.repository.session.SessionStatus; import de.caritas.cob.userservice.api.repository.user.User; -import de.caritas.cob.userservice.api.repository.userAgency.UserAgency; +import de.caritas.cob.userservice.api.repository.useragency.UserAgency; import de.caritas.cob.userservice.api.service.helper.AgencyServiceHelper; import de.caritas.cob.userservice.api.service.helper.KeycloakAdminClientService; import de.caritas.cob.userservice.api.service.helper.MessageServiceHelper; +import de.caritas.cob.userservice.api.service.rocketchat.RocketChatCredentialsProvider; +import de.caritas.cob.userservice.api.service.rocketchat.RocketChatService; import java.io.File; import java.io.FileReader; import java.io.IOException; @@ -50,6 +53,8 @@ import java.util.Objects; import java.util.Optional; import lombok.Getter; +import lombok.NonNull; +import lombok.RequiredArgsConstructor; import lombok.Setter; import org.apache.commons.csv.CSVFormat; import org.apache.commons.csv.CSVRecord; @@ -67,6 +72,7 @@ * Imports the askers from the created CSV file of the old Caritas system. */ @Service +@RequiredArgsConstructor public class AskerImportService { @Value("${asker.import.filename}") @@ -92,50 +98,22 @@ public class AskerImportService { private final String REPLACE_KEY_USERNAME = "username"; private final String DUMMY_POSTCODE = "00000"; - private KeycloakAdminClientService keycloakAdminClientService; - private UserService userService; - private SessionService sessionService; - private RocketChatService rocketChatService; - private SessionDataService sessionDataService; - private ConsultantService consultantService; - private ConsultantAgencyService consultantAgencyService; - private MonitoringService monitoringService; - private MessageServiceHelper messageServiceHelper; - private MonitoringHelper monitoringHelper; - private ConsultingTypeManager consultingTypeManager; - private AgencyServiceHelper agencyServiceHelper; - private UserHelper userHelper; - private UserAgencyService userAgencyService; - private RocketChatHelper rocketChatHelper; - - @Autowired - public AskerImportService(KeycloakAdminClientService keycloakHelper, UserService userService, - SessionService sessionService, RocketChatService rocketChatService, - SessionDataService sessionDataService, ConsultantService consultantService, - ConsultantAgencyService consultantAgencyService, MonitoringService monitoringService, - MessageServiceHelper messageServiceHelper, MonitoringHelper monitoringHelper, - ConsultingTypeManager consultingTypeManager, AgencyServiceHelper agencyServiceHelper, - UserHelper userHelper, UserAgencyService userAgencyService, - RocketChatHelper rocketChatHelper) { - this.keycloakAdminClientService = keycloakHelper; - this.userService = userService; - this.sessionService = sessionService; - this.rocketChatService = rocketChatService; - this.sessionDataService = sessionDataService; - this.consultantService = consultantService; - this.consultantAgencyService = consultantAgencyService; - this.monitoringService = monitoringService; - this.messageServiceHelper = messageServiceHelper; - this.monitoringHelper = monitoringHelper; - this.consultingTypeManager = consultingTypeManager; - this.agencyServiceHelper = agencyServiceHelper; - this.userHelper = userHelper; - this.userAgencyService = userAgencyService; - this.rocketChatHelper = rocketChatHelper; - } - - public AskerImportService() { - } + private final @NonNull KeycloakAdminClientService keycloakAdminClientService; + private final @NonNull UserService userService; + private final @NonNull SessionService sessionService; + private final @NonNull RocketChatService rocketChatService; + private final @NonNull SessionDataService sessionDataService; + private final @NonNull ConsultantService consultantService; + private final @NonNull ConsultantAgencyService consultantAgencyService; + private final @NonNull MonitoringService monitoringService; + private final @NonNull MessageServiceHelper messageServiceHelper; + private final @NonNull MonitoringHelper monitoringHelper; + private final @NonNull ConsultingTypeManager consultingTypeManager; + private final @NonNull AgencyServiceHelper agencyServiceHelper; + private final @NonNull UserHelper userHelper; + private final @NonNull UserAgencyService userAgencyService; + private final @NonNull RocketChatHelper rocketChatHelper; + private final @NonNull RocketChatCredentialsProvider rocketChatCredentialsProvider; /** * Imports askers without session by a predefined import list (for the format see readme.md) @@ -303,7 +281,7 @@ public void startImport() { in = new FileReader(importFilenameAsker); records = CSVFormat.DEFAULT.parse(in); - ResponseEntity rcSystemUserResonse = rocketChatService + ResponseEntity rcSystemUserResonse = rocketChatCredentialsProvider .loginUser(ROCKET_CHAT_SYSTEM_USER_USERNAME, ROCKET_CHAT_SYSTEM_USER_PASSWORD); systemUserId = rcSystemUserResonse.getBody().getData().getUserId(); systemUserToken = rcSystemUserResonse.getBody().getData().getAuthToken(); @@ -486,7 +464,7 @@ public void startImport() { // Remove all system messages from feedback group try { rocketChatService.removeSystemMessages(rcFeedbackGroupId, - LocalDateTime.now().minusHours(Helper.ONE_DAY_IN_HOURS), LocalDateTime.now()); + nowInUtc().minusHours(Helper.ONE_DAY_IN_HOURS), nowInUtc()); } catch (RocketChatRemoveSystemMessagesException e) { throw new ImportException(String.format( "Could not remove system messages from feedback group id %s for user %s", @@ -502,8 +480,8 @@ public void startImport() { session.setGroupId(rcGroupId); session.setEnquiryMessageDate(new Date()); session.setStatus(SessionStatus.IN_PROGRESS); - session.setCreateDate(LocalDateTime.now()); - session.setUpdateDate(LocalDateTime.now()); + session.setCreateDate(nowInUtc()); + session.setUpdateDate(nowInUtc()); Session updatedSession = sessionService.saveSession(session); if (updatedSession.getId() == null) { throw new ImportException( @@ -559,7 +537,7 @@ public void startImport() { // Remove all system messages from group try { rocketChatService.removeSystemMessages(rcGroupId, - LocalDateTime.now().minusHours(Helper.ONE_DAY_IN_HOURS), LocalDateTime.now()); + nowInUtc().minusHours(Helper.ONE_DAY_IN_HOURS), nowInUtc()); } catch (RocketChatRemoveSystemMessagesException e) { throw new ImportException( String.format("Could not remove system messages from group id %s for user %s", diff --git a/src/main/java/de/caritas/cob/userservice/api/service/ChatService.java b/src/main/java/de/caritas/cob/userservice/api/service/ChatService.java index 5270ca806..9157a3939 100644 --- a/src/main/java/de/caritas/cob/userservice/api/service/ChatService.java +++ b/src/main/java/de/caritas/cob/userservice/api/service/ChatService.java @@ -20,10 +20,10 @@ import de.caritas.cob.userservice.api.repository.chat.Chat; import de.caritas.cob.userservice.api.repository.chat.ChatInterval; import de.caritas.cob.userservice.api.repository.chat.ChatRepository; -import de.caritas.cob.userservice.api.repository.chatAgency.ChatAgency; -import de.caritas.cob.userservice.api.repository.chatAgency.ChatAgencyRepository; +import de.caritas.cob.userservice.api.repository.chatagency.ChatAgency; +import de.caritas.cob.userservice.api.repository.chatagency.ChatAgencyRepository; import de.caritas.cob.userservice.api.repository.consultant.Consultant; -import de.caritas.cob.userservice.api.repository.consultantAgency.ConsultantAgency; +import de.caritas.cob.userservice.api.repository.consultantagency.ConsultantAgency; import java.time.LocalDate; import java.time.LocalDateTime; import java.time.LocalTime; diff --git a/src/main/java/de/caritas/cob/userservice/api/service/ConsultantAgencyService.java b/src/main/java/de/caritas/cob/userservice/api/service/ConsultantAgencyService.java index b0650ace1..095b7f591 100644 --- a/src/main/java/de/caritas/cob/userservice/api/service/ConsultantAgencyService.java +++ b/src/main/java/de/caritas/cob/userservice/api/service/ConsultantAgencyService.java @@ -2,12 +2,11 @@ import de.caritas.cob.userservice.api.exception.httpresponses.InternalServerErrorException; import de.caritas.cob.userservice.api.model.ConsultantResponseDTO; -import de.caritas.cob.userservice.api.repository.consultantAgency.ConsultantAgency; -import de.caritas.cob.userservice.api.repository.consultantAgency.ConsultantAgencyRepository; +import de.caritas.cob.userservice.api.repository.consultantagency.ConsultantAgency; +import de.caritas.cob.userservice.api.repository.consultantagency.ConsultantAgencyRepository; import java.util.List; import java.util.stream.Collectors; -import static org.apache.commons.collections.CollectionUtils.isEmpty; import static org.apache.commons.collections.CollectionUtils.isNotEmpty; import org.springframework.beans.factory.annotation.Autowired; diff --git a/src/main/java/de/caritas/cob/userservice/api/service/ConsultantImportService.java b/src/main/java/de/caritas/cob/userservice/api/service/ConsultantImportService.java index 898ae4f76..14963ea60 100644 --- a/src/main/java/de/caritas/cob/userservice/api/service/ConsultantImportService.java +++ b/src/main/java/de/caritas/cob/userservice/api/service/ConsultantImportService.java @@ -2,8 +2,8 @@ import static org.apache.commons.lang3.BooleanUtils.isTrue; -import de.caritas.cob.userservice.api.admin.service.consultant.create.agencyrelation.ConsultantAgencyRelationCreatorService; import de.caritas.cob.userservice.api.admin.service.consultant.create.ConsultantCreatorService; +import de.caritas.cob.userservice.api.admin.service.consultant.create.agencyrelation.ConsultantAgencyRelationCreatorService; import de.caritas.cob.userservice.api.exception.AgencyServiceHelperException; import de.caritas.cob.userservice.api.exception.ImportException; import de.caritas.cob.userservice.api.exception.httpresponses.InternalServerErrorException; @@ -12,10 +12,10 @@ import de.caritas.cob.userservice.api.manager.consultingtype.ConsultingTypeSettings; import de.caritas.cob.userservice.api.model.AgencyDTO; import de.caritas.cob.userservice.api.repository.consultant.Consultant; -import de.caritas.cob.userservice.api.repository.consultantAgency.ConsultantAgency; import de.caritas.cob.userservice.api.repository.session.ConsultingType; import de.caritas.cob.userservice.api.service.helper.AgencyServiceHelper; import de.caritas.cob.userservice.api.service.helper.KeycloakAdminClientService; +import de.caritas.cob.userservice.api.service.rocketchat.RocketChatService; import java.io.FileReader; import java.io.IOException; import java.io.Reader; @@ -23,7 +23,6 @@ import java.nio.file.Files; import java.nio.file.Paths; import java.nio.file.StandardOpenOption; -import java.time.LocalDateTime; import java.util.ArrayList; import java.util.HashSet; import java.util.List; diff --git a/src/main/java/de/caritas/cob/userservice/api/service/ConsultantService.java b/src/main/java/de/caritas/cob/userservice/api/service/ConsultantService.java index 34a8338b9..dc0464fad 100644 --- a/src/main/java/de/caritas/cob/userservice/api/service/ConsultantService.java +++ b/src/main/java/de/caritas/cob/userservice/api/service/ConsultantService.java @@ -15,7 +15,7 @@ import de.caritas.cob.userservice.api.helper.Helper; import de.caritas.cob.userservice.api.helper.UserHelper; import de.caritas.cob.userservice.api.model.AbsenceDTO; -import de.caritas.cob.userservice.api.repository.chatAgency.ChatAgency; +import de.caritas.cob.userservice.api.repository.chatagency.ChatAgency; import de.caritas.cob.userservice.api.repository.consultant.Consultant; import de.caritas.cob.userservice.api.repository.consultant.ConsultantRepository; diff --git a/src/main/java/de/caritas/cob/userservice/api/service/MonitoringService.java b/src/main/java/de/caritas/cob/userservice/api/service/MonitoringService.java index 88ce53ae0..afdffc66b 100644 --- a/src/main/java/de/caritas/cob/userservice/api/service/MonitoringService.java +++ b/src/main/java/de/caritas/cob/userservice/api/service/MonitoringService.java @@ -16,7 +16,7 @@ import de.caritas.cob.userservice.api.repository.monitoring.Monitoring; import de.caritas.cob.userservice.api.repository.monitoring.MonitoringRepository; import de.caritas.cob.userservice.api.repository.monitoring.MonitoringType; -import de.caritas.cob.userservice.api.repository.monitoringOption.MonitoringOption; +import de.caritas.cob.userservice.api.repository.monitoringoption.MonitoringOption; import de.caritas.cob.userservice.api.repository.session.ConsultingType; import de.caritas.cob.userservice.api.repository.session.Session; diff --git a/src/main/java/de/caritas/cob/userservice/api/service/SessionDataService.java b/src/main/java/de/caritas/cob/userservice/api/service/SessionDataService.java index b47682cd0..acbc5bf9b 100644 --- a/src/main/java/de/caritas/cob/userservice/api/service/SessionDataService.java +++ b/src/main/java/de/caritas/cob/userservice/api/service/SessionDataService.java @@ -8,8 +8,8 @@ import de.caritas.cob.userservice.api.helper.SessionDataHelper; import de.caritas.cob.userservice.api.model.registration.UserDTO; import de.caritas.cob.userservice.api.repository.session.Session; -import de.caritas.cob.userservice.api.repository.sessionData.SessionData; -import de.caritas.cob.userservice.api.repository.sessionData.SessionDataRepository; +import de.caritas.cob.userservice.api.repository.sessiondata.SessionData; +import de.caritas.cob.userservice.api.repository.sessiondata.SessionDataRepository; /** * Service for session data diff --git a/src/main/java/de/caritas/cob/userservice/api/service/SessionService.java b/src/main/java/de/caritas/cob/userservice/api/service/SessionService.java index ceb72430c..805189485 100644 --- a/src/main/java/de/caritas/cob/userservice/api/service/SessionService.java +++ b/src/main/java/de/caritas/cob/userservice/api/service/SessionService.java @@ -1,5 +1,6 @@ package de.caritas.cob.userservice.api.service; +import static de.caritas.cob.userservice.localdatetime.CustomLocalDateTime.nowInUtc; import static java.util.Objects.nonNull; import static org.apache.commons.collections.CollectionUtils.isNotEmpty; @@ -25,7 +26,7 @@ import de.caritas.cob.userservice.api.model.user.SessionConsultantForUserDTO; import de.caritas.cob.userservice.api.model.user.SessionUserDTO; import de.caritas.cob.userservice.api.repository.consultant.Consultant; -import de.caritas.cob.userservice.api.repository.consultantAgency.ConsultantAgency; +import de.caritas.cob.userservice.api.repository.consultantagency.ConsultantAgency; import de.caritas.cob.userservice.api.repository.session.ConsultingType; import de.caritas.cob.userservice.api.repository.session.Session; import de.caritas.cob.userservice.api.repository.session.SessionRepository; @@ -198,8 +199,8 @@ public Session initializeSession(User user, UserDTO userDto, boolean isTeamSessi Session session = new Session(user, consultingTypeSettings.getConsultingType(), userDto.getPostcode(), userDto.getAgencyId(), SessionStatus.INITIAL, isTeamSession, consultingTypeSettings.isMonitoring()); - session.setCreateDate(LocalDateTime.now()); - session.setUpdateDate(LocalDateTime.now()); + session.setCreateDate(nowInUtc()); + session.setUpdateDate(nowInUtc()); return saveSession(session); } @@ -458,7 +459,7 @@ public Session getSessionByFeedbackGroupId(String feedbackGroupId) { /** * Returns a {@link ConsultantSessionDTO} for a specific session. * - * @param sessionId the session id to fetch + * @param sessionId the session id to fetch * @param consultant the calling consultant * @return {@link ConsultantSessionDTO} entity for the specific session */ @@ -488,7 +489,8 @@ private ConsultantSessionDTO toConsultantSessionDTO(Session session) { .isMonitoring(session.isMonitoring()) .postcode(session.getPostcode()) .consultantId(nonNull(session.getConsultant()) ? session.getConsultant().getId() : null) - .consultantRcId(nonNull(session.getConsultant()) ? session.getConsultant().getRocketChatId() : null); + .consultantRcId( + nonNull(session.getConsultant()) ? session.getConsultant().getRocketChatId() : null); } private void checkPermissionForConsultantSession(Session session, Consultant consultant) { diff --git a/src/main/java/de/caritas/cob/userservice/api/service/UserAgencyService.java b/src/main/java/de/caritas/cob/userservice/api/service/UserAgencyService.java index 74315863a..205f1838d 100644 --- a/src/main/java/de/caritas/cob/userservice/api/service/UserAgencyService.java +++ b/src/main/java/de/caritas/cob/userservice/api/service/UserAgencyService.java @@ -7,8 +7,8 @@ import org.springframework.dao.DataAccessException; import org.springframework.stereotype.Service; import de.caritas.cob.userservice.api.repository.user.User; -import de.caritas.cob.userservice.api.repository.userAgency.UserAgency; -import de.caritas.cob.userservice.api.repository.userAgency.UserAgencyRepository; +import de.caritas.cob.userservice.api.repository.useragency.UserAgency; +import de.caritas.cob.userservice.api.repository.useragency.UserAgencyRepository; @Service @RequiredArgsConstructor diff --git a/src/main/java/de/caritas/cob/userservice/api/service/emailsupplier/NewEnquiryEmailSupplier.java b/src/main/java/de/caritas/cob/userservice/api/service/emailsupplier/NewEnquiryEmailSupplier.java index c76f53f4f..e42926d9a 100644 --- a/src/main/java/de/caritas/cob/userservice/api/service/emailsupplier/NewEnquiryEmailSupplier.java +++ b/src/main/java/de/caritas/cob/userservice/api/service/emailsupplier/NewEnquiryEmailSupplier.java @@ -11,8 +11,8 @@ import de.caritas.cob.userservice.api.model.AgencyDTO; import de.caritas.cob.userservice.api.model.mailservice.MailDTO; import de.caritas.cob.userservice.api.model.mailservice.TemplateDataDTO; -import de.caritas.cob.userservice.api.repository.consultantAgency.ConsultantAgency; -import de.caritas.cob.userservice.api.repository.consultantAgency.ConsultantAgencyRepository; +import de.caritas.cob.userservice.api.repository.consultantagency.ConsultantAgency; +import de.caritas.cob.userservice.api.repository.consultantagency.ConsultantAgencyRepository; import de.caritas.cob.userservice.api.repository.session.Session; import de.caritas.cob.userservice.api.service.helper.AgencyServiceHelper; import java.util.List; diff --git a/src/main/java/de/caritas/cob/userservice/api/service/emailsupplier/NewFeedbackEmailSupplier.java b/src/main/java/de/caritas/cob/userservice/api/service/emailsupplier/NewFeedbackEmailSupplier.java index 717be86b6..d9d1044b8 100644 --- a/src/main/java/de/caritas/cob/userservice/api/service/emailsupplier/NewFeedbackEmailSupplier.java +++ b/src/main/java/de/caritas/cob/userservice/api/service/emailsupplier/NewFeedbackEmailSupplier.java @@ -17,7 +17,7 @@ import de.caritas.cob.userservice.api.repository.session.Session; import de.caritas.cob.userservice.api.service.ConsultantService; import de.caritas.cob.userservice.api.service.LogService; -import de.caritas.cob.userservice.api.service.RocketChatService; +import de.caritas.cob.userservice.api.service.rocketchat.RocketChatService; import java.util.List; import java.util.Objects; import java.util.Optional; diff --git a/src/main/java/de/caritas/cob/userservice/api/service/emailsupplier/NewMessageEmailSupplier.java b/src/main/java/de/caritas/cob/userservice/api/service/emailsupplier/NewMessageEmailSupplier.java index a8f2c53c9..533e29203 100644 --- a/src/main/java/de/caritas/cob/userservice/api/service/emailsupplier/NewMessageEmailSupplier.java +++ b/src/main/java/de/caritas/cob/userservice/api/service/emailsupplier/NewMessageEmailSupplier.java @@ -2,6 +2,7 @@ import static de.caritas.cob.userservice.api.helper.EmailNotificationHelper.TEMPLATE_NEW_MESSAGE_NOTIFICATION_ASKER; import static de.caritas.cob.userservice.api.helper.EmailNotificationHelper.TEMPLATE_NEW_MESSAGE_NOTIFICATION_CONSULTANT; +import static de.caritas.cob.userservice.localdatetime.CustomLocalDateTime.nowInUtc; import static java.util.Arrays.asList; import static java.util.Collections.emptyList; import static java.util.Collections.singletonList; @@ -17,12 +18,13 @@ import de.caritas.cob.userservice.api.manager.consultingtype.ConsultingTypeSettings; import de.caritas.cob.userservice.api.model.mailservice.MailDTO; import de.caritas.cob.userservice.api.model.mailservice.TemplateDataDTO; -import de.caritas.cob.userservice.api.repository.consultantAgency.ConsultantAgency; +import de.caritas.cob.userservice.api.repository.consultantagency.ConsultantAgency; import de.caritas.cob.userservice.api.repository.session.Session; import de.caritas.cob.userservice.api.repository.session.SessionStatus; import de.caritas.cob.userservice.api.service.ConsultantAgencyService; import de.caritas.cob.userservice.api.service.LogService; import java.time.LocalDateTime; +import java.time.ZoneOffset; import java.util.List; import java.util.Set; import java.util.stream.Collectors; @@ -102,7 +104,7 @@ private List retrieveDependentConsultantAgencies() { } else { if (isNotBlank(session.getConsultant().getEmail())) { return singletonList(new ConsultantAgency(null, session.getConsultant(), null, - LocalDateTime.now(), LocalDateTime.now())); + nowInUtc(), nowInUtc(), null)); } } return emptyList(); @@ -111,8 +113,9 @@ private List retrieveDependentConsultantAgencies() { private boolean shouldInformAllConsultantsOfTeamSession() { ConsultingTypeSettings consultingTypeSettings = consultingTypeManager.getConsultingTypeSettings(session.getConsultingType()); - return session.isTeamSession() && isTrue(consultingTypeSettings.getNotifications().getNewMessage() - .getTeamSession().getToConsultant().getAllTeamConsultants()); + return session.isTeamSession() && isTrue( + consultingTypeSettings.getNotifications().getNewMessage() + .getTeamSession().getToConsultant().getAllTeamConsultants()); } private MailDTO toNewConsultantMessageMailDTO(ConsultantAgency agency) { diff --git a/src/main/java/de/caritas/cob/userservice/api/service/helper/MessageServiceHelper.java b/src/main/java/de/caritas/cob/userservice/api/service/helper/MessageServiceHelper.java index 64010617e..26c2dd9be 100644 --- a/src/main/java/de/caritas/cob/userservice/api/service/helper/MessageServiceHelper.java +++ b/src/main/java/de/caritas/cob/userservice/api/service/helper/MessageServiceHelper.java @@ -1,5 +1,6 @@ package de.caritas.cob.userservice.api.service.helper; +import de.caritas.cob.userservice.api.service.rocketchat.RocketChatCredentialsProvider; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.http.HttpEntity; @@ -34,12 +35,12 @@ public class MessageServiceHelper { private final RestTemplate restTemplate; private final ServiceHelper serviceHelper; - private final RocketChatCredentialsHelper rcCredentialHelper; + private final RocketChatCredentialsProvider rcCredentialHelper; private final UserHelper userHelper; @Autowired public MessageServiceHelper(RestTemplate restTemplate, ServiceHelper serviceHelper, - RocketChatCredentialsHelper rcCredentialHelper, UserHelper userHelper) { + RocketChatCredentialsProvider rcCredentialHelper, UserHelper userHelper) { this.serviceHelper = serviceHelper; this.restTemplate = restTemplate; this.rcCredentialHelper = rcCredentialHelper; diff --git a/src/main/java/de/caritas/cob/userservice/api/service/liveevents/RelevantUserAccountIdsByChatProvider.java b/src/main/java/de/caritas/cob/userservice/api/service/liveevents/RelevantUserAccountIdsByChatProvider.java index 6da8432c8..0a5e273ed 100644 --- a/src/main/java/de/caritas/cob/userservice/api/service/liveevents/RelevantUserAccountIdsByChatProvider.java +++ b/src/main/java/de/caritas/cob/userservice/api/service/liveevents/RelevantUserAccountIdsByChatProvider.java @@ -8,7 +8,7 @@ import de.caritas.cob.userservice.api.repository.user.User; import de.caritas.cob.userservice.api.service.ConsultantService; import de.caritas.cob.userservice.api.service.LogService; -import de.caritas.cob.userservice.api.service.RocketChatService; +import de.caritas.cob.userservice.api.service.rocketchat.RocketChatService; import de.caritas.cob.userservice.api.service.UserService; import java.util.List; import java.util.Objects; diff --git a/src/main/java/de/caritas/cob/userservice/api/service/helper/RocketChatCredentialsHelper.java b/src/main/java/de/caritas/cob/userservice/api/service/rocketchat/RocketChatCredentialsProvider.java similarity index 51% rename from src/main/java/de/caritas/cob/userservice/api/service/helper/RocketChatCredentialsHelper.java rename to src/main/java/de/caritas/cob/userservice/api/service/rocketchat/RocketChatCredentialsProvider.java index d394e80b6..608703923 100644 --- a/src/main/java/de/caritas/cob/userservice/api/service/helper/RocketChatCredentialsHelper.java +++ b/src/main/java/de/caritas/cob/userservice/api/service/rocketchat/RocketChatCredentialsProvider.java @@ -1,4 +1,9 @@ -package de.caritas.cob.userservice.api.service.helper; +package de.caritas.cob.userservice.api.service.rocketchat; + +import static de.caritas.cob.userservice.localdatetime.CustomLocalDateTime.nowInUtc; +import static java.util.Objects.isNull; +import static java.util.Objects.nonNull; +import static java.util.Objects.requireNonNull; import de.caritas.cob.userservice.api.container.RocketChatCredentials; import de.caritas.cob.userservice.api.exception.rocketchat.RocketChatLoginException; @@ -6,8 +11,10 @@ import de.caritas.cob.userservice.api.model.rocketchat.login.LoginResponseDTO; import de.caritas.cob.userservice.api.model.rocketchat.logout.LogoutResponseDTO; import de.caritas.cob.userservice.api.service.LogService; -import java.time.LocalDateTime; -import org.springframework.beans.factory.annotation.Autowired; +import java.util.Optional; +import java.util.concurrent.atomic.AtomicReference; +import lombok.NonNull; +import lombok.RequiredArgsConstructor; import org.springframework.beans.factory.annotation.Value; import org.springframework.http.HttpEntity; import org.springframework.http.HttpHeaders; @@ -20,7 +27,8 @@ import org.springframework.web.client.RestTemplate; @Service -public class RocketChatCredentialsHelper { +@RequiredArgsConstructor +public class RocketChatCredentialsProvider { @Value("${rocket.technical.username}") private String technicalUsername; @@ -46,35 +54,55 @@ public class RocketChatCredentialsHelper { @Value("${rocket.chat.header.user.id}") private String rocketChatHeaderUserId; - @Autowired - private RestTemplate restTemplate; + private final @NonNull RestTemplate restTemplate; // Tokens - private RocketChatCredentials techUser_A; - private RocketChatCredentials techUser_B; - private RocketChatCredentials systemUser_A; - private RocketChatCredentials systemUser_B; + private final AtomicReference techUserA = new AtomicReference<>(); + private final AtomicReference techUserB = new AtomicReference<>(); + private final AtomicReference systemUserA = new AtomicReference<>(); + private final AtomicReference systemUserB = new AtomicReference<>(); /** * Get a valid technical Users */ public RocketChatCredentials getTechnicalUser() throws RocketChatUserNotInitializedException { - // If both are uninitialized throw Exception - if (techUser_A == null && techUser_B == null) { + return observeNonNullOrLatestUser(this.techUserA, this.techUserB); + } + + private RocketChatCredentials observeNonNullOrLatestUser( + AtomicReference firstUser, + AtomicReference secondUser) + throws RocketChatUserNotInitializedException { + if (areBothUsersNull(firstUser.get(), secondUser.get())) { throw new RocketChatUserNotInitializedException("No technical user was initialized"); } - if (techUser_A == null) { - return techUser_B; + return oneOfBothUsersNull(firstUser.get(), secondUser.get()) + .orElseGet(() -> retrieveLatestUser(firstUser.get(), secondUser.get())); + } + + private boolean areBothUsersNull(RocketChatCredentials firstUser, + RocketChatCredentials secondUser) { + return isNull(firstUser) && isNull(secondUser); + } + + private Optional oneOfBothUsersNull(RocketChatCredentials firstUser, + RocketChatCredentials secondUser) { + if (isNull(firstUser)) { + return Optional.of(secondUser); } - if (techUser_B == null) { - return techUser_A; + if (isNull(secondUser)) { + return Optional.of(firstUser); } + return Optional.empty(); + } - if (techUser_A.getTimeStampCreated().isAfter(techUser_B.getTimeStampCreated())) { - return techUser_A; + private RocketChatCredentials retrieveLatestUser(RocketChatCredentials firstUser, + RocketChatCredentials secondUser) { + if (firstUser.getTimeStampCreated().isAfter(secondUser.getTimeStampCreated())) { + return firstUser; } else { - return techUser_B; + return secondUser; } } @@ -82,87 +110,51 @@ public RocketChatCredentials getTechnicalUser() throws RocketChatUserNotInitiali * Get a valid system user */ public RocketChatCredentials getSystemUser() throws RocketChatUserNotInitializedException { - // If both are uninitialized throw Exception - if (systemUser_A == null && systemUser_B == null) { - throw new RocketChatUserNotInitializedException("No system user was initialized"); - } - - if (systemUser_A == null) { - return systemUser_B; - } - if (systemUser_B == null) { - return systemUser_A; - } - - if (systemUser_A.getTimeStampCreated().isAfter(systemUser_B.getTimeStampCreated())) { - return systemUser_A; - } else { - return systemUser_B; - } + return observeNonNullOrLatestUser(this.systemUserA, this.systemUserB); } /** * Update the Credentials */ public void updateCredentials() throws RocketChatLoginException { - if (techUser_A != null && techUser_B != null) { - if (techUser_A.getTimeStampCreated().isBefore(techUser_B.getTimeStampCreated())) { - logoutUser(techUser_A); - techUser_A = null; - } else { - logoutUser(techUser_B); - techUser_B = null; - } - } + logoutUserWithLongerLoginTime(techUserA, techUserB); + logoutUserWithLongerLoginTime(systemUserA, systemUserB); + loginNullUser(this.techUserA, this.techUserB, this.technicalUsername, this.technicalPassword); + loginNullUser(this.systemUserA, this.systemUserB, this.systemUsername, this.systemPassword); + } - if (systemUser_A != null && systemUser_B != null) { - if (systemUser_A.getTimeStampCreated().isBefore(systemUser_B.getTimeStampCreated())) { - logoutUser(systemUser_A); - systemUser_A = null; + private void logoutUserWithLongerLoginTime(AtomicReference firstUser, + AtomicReference secondUser) { + if (nonNull(firstUser.get()) && nonNull(secondUser.get())) { + if (firstUser.get().getTimeStampCreated().isBefore(secondUser.get().getTimeStampCreated())) { + logoutUser(firstUser); } else { - logoutUser(systemUser_B); - systemUser_B = null; - } - } - - if (techUser_A == null && techUser_B == null) { - techUser_A = loginUserServiceUser(technicalUsername, technicalPassword); - } else { - if (techUser_A == null) { - techUser_A = loginUserServiceUser(technicalUsername, technicalPassword); - } - - if (techUser_B == null) { - techUser_B = loginUserServiceUser(technicalUsername, technicalPassword); + logoutUser(secondUser); } } + } - if (systemUser_A == null && systemUser_B == null) { - systemUser_A = loginUserServiceUser(systemUsername, systemPassword); + private void loginNullUser(AtomicReference firstUser, + AtomicReference secondUser, String username, String password) + throws RocketChatLoginException { + if (isNull(firstUser.get()) && isNull(secondUser.get())) { + firstUser.set(obtainRocketCredentialsForUser(username, password)); } else { - if (systemUser_A == null) { - systemUser_A = loginUserServiceUser(systemUsername, systemPassword); + if (isNull(firstUser.get())) { + firstUser.set(obtainRocketCredentialsForUser(username, password)); } - if (systemUser_B == null) { - systemUser_B = loginUserServiceUser(systemUsername, systemPassword); + if (isNull(secondUser.get())) { + secondUser.set(obtainRocketCredentialsForUser(username, password)); } } - } - /** - * Login a system user and receive a RocketChatCredentials-Object. - * - * @param username the username - * @param password the password - * @return credentials of rocket chat - */ - public RocketChatCredentials loginUserServiceUser(String username, String password) + private RocketChatCredentials obtainRocketCredentialsForUser(String username, String password) throws RocketChatLoginException { RocketChatCredentials rcc = RocketChatCredentials.builder() - .timeStampCreated(LocalDateTime.now()) + .timeStampCreated(nowInUtc()) .rocketChatUsername(username) .build(); @@ -170,14 +162,14 @@ public RocketChatCredentials loginUserServiceUser(String username, String passwo ResponseEntity response = loginUser(username, password); - rcc.setRocketChatToken(response.getBody().getData().getAuthToken()); - rcc.setRocketChatUserId(response.getBody().getData().getUserId()); + rcc.setRocketChatToken(requireNonNull(response.getBody()).getData().getAuthToken()); + rcc.setRocketChatUserId(requireNonNull(response.getBody()).getData().getUserId()); } catch (Exception ex) { throw new RocketChatLoginException("Could not login " + username + " user in Rocket.Chat"); } - if (rcc.getRocketChatToken() == null || rcc.getRocketChatUserId() == null) { + if (isNull(rcc.getRocketChatToken()) || isNull(rcc.getRocketChatUserId())) { String error = "Could not login " + username + " user in Rocket.Chat correctly, no authToken or UserId received."; throw new RocketChatLoginException(error); @@ -187,11 +179,12 @@ public RocketChatCredentials loginUserServiceUser(String username, String passwo } /** - * Performs a login with the given credentials and returns the Result. + * Performs a login with the given credentials and returns the result. * * @param username the username * @param password the password - * @return a response entity with the login dto + * @return the response entity of the login dto + * @throws RocketChatLoginException on failure */ public ResponseEntity loginUser(String username, String password) throws RocketChatLoginException { @@ -200,18 +193,14 @@ public ResponseEntity loginUser(String username, String passwo HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED); - MultiValueMap map = new LinkedMultiValueMap(); + MultiValueMap map = new LinkedMultiValueMap<>(); map.add("username", username); map.add("password", password); HttpEntity> request = - new HttpEntity>(map, headers); - - ResponseEntity response = - restTemplate.postForEntity(rocketChatApiUserLogin, request, LoginResponseDTO.class); - - return response; + new HttpEntity<>(map, headers); + return restTemplate.postForEntity(rocketChatApiUserLogin, request, LoginResponseDTO.class); } catch (Exception ex) { throw new RocketChatLoginException( String.format("Could not login user (%s) in Rocket.Chat", username)); @@ -221,7 +210,7 @@ public ResponseEntity loginUser(String username, String passwo /** * Performs a logout with the given credentials and returns true on success. * - * @param rcUserId the rocket chat user id + * @param rcUserId the rocket chat user id * @param rcAuthToken the rocket chat auth token * @return true if logout was successful */ @@ -230,12 +219,12 @@ public boolean logoutUser(String rcUserId, String rcAuthToken) { try { HttpHeaders headers = getStandardHttpHeaders(rcAuthToken, rcUserId); - HttpEntity request = new HttpEntity(headers); + HttpEntity request = new HttpEntity<>(headers); ResponseEntity response = restTemplate.postForEntity(rocketChatApiUserLogout, request, LogoutResponseDTO.class); - return response != null && response.getStatusCode() == HttpStatus.OK ? true : false; + return response.getStatusCode() == HttpStatus.OK; } catch (Exception ex) { LogService.logRocketChatError( @@ -248,8 +237,9 @@ public boolean logoutUser(String rcUserId, String rcAuthToken) { /** * Logout a RocketChatCredentials-User */ - private void logoutUser(RocketChatCredentials user) { - this.logoutUser(user.getRocketChatUserId(), user.getRocketChatToken()); + private void logoutUser(AtomicReference user) { + this.logoutUser(user.get().getRocketChatUserId(), user.get().getRocketChatToken()); + user.set(null); } /** @@ -261,7 +251,7 @@ private void logoutUser(RocketChatCredentials user) { private HttpHeaders getStandardHttpHeaders(String rcToken, String rcUserId) { HttpHeaders httpHeaders = new HttpHeaders(); - httpHeaders.setContentType(MediaType.APPLICATION_JSON_UTF8); + httpHeaders.setContentType(MediaType.APPLICATION_JSON); httpHeaders.add(rocketChatHeaderAuthToken, rcToken); httpHeaders.add(rocketChatHeaderUserId, rcUserId); return httpHeaders; diff --git a/src/main/java/de/caritas/cob/userservice/api/service/helper/RocketChatRollbackHelper.java b/src/main/java/de/caritas/cob/userservice/api/service/rocketchat/RocketChatRollbackService.java similarity index 89% rename from src/main/java/de/caritas/cob/userservice/api/service/helper/RocketChatRollbackHelper.java rename to src/main/java/de/caritas/cob/userservice/api/service/rocketchat/RocketChatRollbackService.java index c1f61e035..1c67f7b1f 100644 --- a/src/main/java/de/caritas/cob/userservice/api/service/helper/RocketChatRollbackHelper.java +++ b/src/main/java/de/caritas/cob/userservice/api/service/rocketchat/RocketChatRollbackService.java @@ -1,24 +1,23 @@ -package de.caritas.cob.userservice.api.service.helper; +package de.caritas.cob.userservice.api.service.rocketchat; import de.caritas.cob.userservice.api.exception.rocketchat.RocketChatAddUserToGroupException; import de.caritas.cob.userservice.api.exception.rocketchat.RocketChatRemoveUserFromGroupException; import de.caritas.cob.userservice.api.exception.rocketchat.RocketChatUserNotInitializedException; import de.caritas.cob.userservice.api.model.rocketchat.group.GroupMemberDTO; import de.caritas.cob.userservice.api.service.LogService; -import de.caritas.cob.userservice.api.service.RocketChatService; import java.util.List; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @Service -public class RocketChatRollbackHelper { +public class RocketChatRollbackService { private final RocketChatService rocketChatService; - private final RocketChatCredentialsHelper rcCredentialsHelper; + private final RocketChatCredentialsProvider rcCredentialsHelper; @Autowired - public RocketChatRollbackHelper(RocketChatService rocketChatService, - RocketChatCredentialsHelper rcCredentialsHelper) { + public RocketChatRollbackService(RocketChatService rocketChatService, + RocketChatCredentialsProvider rcCredentialsHelper) { this.rocketChatService = rocketChatService; this.rcCredentialsHelper = rcCredentialsHelper; } diff --git a/src/main/java/de/caritas/cob/userservice/api/service/RocketChatService.java b/src/main/java/de/caritas/cob/userservice/api/service/rocketchat/RocketChatService.java similarity index 93% rename from src/main/java/de/caritas/cob/userservice/api/service/RocketChatService.java rename to src/main/java/de/caritas/cob/userservice/api/service/rocketchat/RocketChatService.java index 8278c3214..f5ef928eb 100644 --- a/src/main/java/de/caritas/cob/userservice/api/service/RocketChatService.java +++ b/src/main/java/de/caritas/cob/userservice/api/service/rocketchat/RocketChatService.java @@ -1,5 +1,6 @@ -package de.caritas.cob.userservice.api.service; +package de.caritas.cob.userservice.api.service.rocketchat; +import static de.caritas.cob.userservice.localdatetime.CustomLocalDateTime.nowInUtc; import static java.util.Objects.nonNull; import static org.apache.commons.lang3.ArrayUtils.isNotEmpty; @@ -34,7 +35,7 @@ import de.caritas.cob.userservice.api.model.rocketchat.user.UserInfoResponseDTO; import de.caritas.cob.userservice.api.model.rocketchat.user.UserUpdateDataDTO; import de.caritas.cob.userservice.api.model.rocketchat.user.UserUpdateRequestDTO; -import de.caritas.cob.userservice.api.service.helper.RocketChatCredentialsHelper; +import de.caritas.cob.userservice.api.service.LogService; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; import java.util.ArrayList; @@ -54,8 +55,6 @@ import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Service; -import org.springframework.util.LinkedMultiValueMap; -import org.springframework.util.MultiValueMap; import org.springframework.web.client.HttpStatusCodeException; import org.springframework.web.client.RestClientResponseException; import org.springframework.web.client.RestTemplate; @@ -72,9 +71,9 @@ public class RocketChatService { + "%s could not be deleted"; private static final String RC_DATE_TIME_PATTERN = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"; private static final String CHAT_ROOM_ERROR_MESSAGE = "Could not get Rocket.Chat rooms for user id %s"; - private final LocalDateTime localDateTime1900 = LocalDateTime.of(1900, 01, 01, 00, 00); + private final LocalDateTime localDateTime1900 = LocalDateTime.of(1900, 1, 1, 0, 0); - private final LocalDateTime localDateTimeFuture = LocalDateTime.now().plusYears(1L); + private final LocalDateTime localDateTimeFuture = nowInUtc().plusYears(1L); @Value("${rocket.chat.header.auth.token}") private String rocketChatHeaderAuthToken; @@ -106,7 +105,7 @@ public class RocketChatService { private String rocketChatApiCleanRoomHistory; private final @NonNull RestTemplate restTemplate; - private final @NonNull RocketChatCredentialsHelper rcCredentialHelper; + private final @NonNull RocketChatCredentialsProvider rcCredentialHelper; /** * Creation of a private Rocket.Chat group. @@ -150,7 +149,7 @@ private boolean isCreateGroupResponseSuccess(GroupResponseDTO response) { * * @param groupName the Rocket.Chat group name * @return an {@link Optional} of a {@link GroupResponseDTO} - * @throws RocketChatCreateGroupException {@link RocketChatCreateGroupException} + * @throws RocketChatCreateGroupException on failure */ public Optional createPrivateGroupWithSystemUser(String groupName) throws RocketChatCreateGroupException { @@ -181,7 +180,7 @@ public boolean deleteGroupAsSystemUser(String groupId) { /** * Deletion of a Rocket.Chat group. * - * @param groupId the group id + * @param groupId the group id * @param rocketChatCredentials {@link RocketChatCredentials} * @return true, if successfully */ @@ -227,11 +226,11 @@ private HttpHeaders getStandardHttpHeaders(RocketChatCredentials rocketChatCrede /** * Retrieves the userId for the given credentials. * - * @param username the username - * @param password the password + * @param username the username + * @param password the password * @param firstLogin true, if first login in Rocket.Chat. This requires a special API call. * @return the userid - * @throws {@link RocketChatLoginException} + * @throws RocketChatLoginException on failure */ public String getUserID(String username, String password, boolean firstLogin) throws RocketChatLoginException { @@ -241,7 +240,7 @@ public String getUserID(String username, String password, boolean firstLogin) if (firstLogin) { response = loginUserFirstTime(username, password); } else { - response = loginUser(username, password); + response = this.rcCredentialHelper.loginUser(username, password); } RocketChatCredentials rocketChatCredentials = @@ -253,6 +252,14 @@ public String getUserID(String username, String password, boolean firstLogin) return rocketChatCredentials.getRocketChatUserId(); } + /** + * Initial login to synchronize ldap and Rocket.Chat user. + * + * @param username the username + * @param password the password + * @return the login result + * @throws RocketChatLoginException on failure + */ public ResponseEntity loginUserFirstTime(String username, String password) throws RocketChatLoginException { @@ -274,34 +281,6 @@ public ResponseEntity loginUserFirstTime(String username, Stri } } - /** - * Performs a login with the given credentials and returns the Result. - * - * @param username the username - * @param password the password - * @return the response entity of the login dto - * @throws {@link RocketChatLoginException} - */ - public ResponseEntity loginUser(String username, String password) - throws RocketChatLoginException { - - try { - HttpHeaders headers = new HttpHeaders(); - headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED); - - MultiValueMap map = new LinkedMultiValueMap<>(); - map.add("username", username); - map.add("password", password); - - HttpEntity> request = new HttpEntity<>(map, headers); - - return restTemplate.postForEntity(rocketChatApiUserLogin, request, LoginResponseDTO.class); - } catch (Exception ex) { - throw new RocketChatLoginException( - String.format("Could not login user (%s) in Rocket.Chat", username)); - } - } - /** * Performs a logout with the given credentials and returns true on success. * @@ -331,7 +310,7 @@ public boolean logoutUser(RocketChatCredentials rocketChatCredentials) { /** * Adds the provided user to the Rocket.Chat group with given groupId. * - * @param rcUserId Rocket.Chat userId + * @param rcUserId Rocket.Chat userId * @param rcGroupId Rocket.Chat roomId */ public void addUserToGroup(String rcUserId, String rcGroupId) @@ -371,9 +350,9 @@ public void addTechnicalUserToGroup(String rcGroupId) /** * Removes the provided user from the Rocket.Chat group with given groupId. * - * @param rcUserId Rocket.Chat userId + * @param rcUserId Rocket.Chat userId * @param rcGroupId Rocket.Chat roomId - * @throws {@link RocketChatRemoveUserFromGroupException} + * @throws RocketChatRemoveUserFromGroupException on failure */ public void removeUserFromGroup(String rcUserId, String rcGroupId) throws RocketChatRemoveUserFromGroupException { @@ -502,8 +481,8 @@ public List getMembersOfGroup(String rcGroupId) * the last 24 hours (avoiding time zone failures). * * @param rcGroupId the rocket chat group id - * @param oldest the oldest message time - * @param latest the latest message time + * @param oldest the oldest message time + * @param latest the latest message time */ public void removeSystemMessages(String rcGroupId, LocalDateTime oldest, LocalDateTime latest) throws RocketChatRemoveSystemMessagesException, RocketChatUserNotInitializedException { diff --git a/src/main/java/de/caritas/cob/userservice/localdatetime/CustomLocalDateTime.java b/src/main/java/de/caritas/cob/userservice/localdatetime/CustomLocalDateTime.java new file mode 100644 index 000000000..88dd9f3ae --- /dev/null +++ b/src/main/java/de/caritas/cob/userservice/localdatetime/CustomLocalDateTime.java @@ -0,0 +1,23 @@ +package de.caritas.cob.userservice.localdatetime; + +import java.time.LocalDateTime; +import java.time.ZoneOffset; + +/** + * Local date time class providing now with zone offset utc. + */ +public class CustomLocalDateTime { + + private CustomLocalDateTime() { + } + + /** + * Creates a current {@link LocalDateTime} instance with {@link ZoneOffset} utc. + * + * @return the {@link LocalDateTime} instance + */ + public static LocalDateTime nowInUtc() { + return LocalDateTime.now(ZoneOffset.UTC); + } + +} diff --git a/src/main/java/de/caritas/cob/userservice/scheduler/RocketChatCredentialsHelperScheduler.java b/src/main/java/de/caritas/cob/userservice/scheduler/RocketChatCredentialsHelperScheduler.java index bd60a29e3..55337590b 100644 --- a/src/main/java/de/caritas/cob/userservice/scheduler/RocketChatCredentialsHelperScheduler.java +++ b/src/main/java/de/caritas/cob/userservice/scheduler/RocketChatCredentialsHelperScheduler.java @@ -2,7 +2,7 @@ import de.caritas.cob.userservice.api.exception.rocketchat.RocketChatLoginException; import de.caritas.cob.userservice.api.service.LogService; -import de.caritas.cob.userservice.api.service.helper.RocketChatCredentialsHelper; +import de.caritas.cob.userservice.api.service.rocketchat.RocketChatCredentialsProvider; import javax.annotation.PostConstruct; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Profile; @@ -14,7 +14,7 @@ public class RocketChatCredentialsHelperScheduler { @Autowired - private RocketChatCredentialsHelper rcCredentialsHelper; + private RocketChatCredentialsProvider rcCredentialsHelper; @PostConstruct public void postConstructInitializer() { diff --git a/src/main/resources/db/changelog/changeset/0010_delete_timestamp_for_consultant_agency/0010_changeSet.xml b/src/main/resources/db/changelog/changeset/0010_delete_timestamp_for_consultant_agency/0010_changeSet.xml new file mode 100644 index 000000000..c4865fb9c --- /dev/null +++ b/src/main/resources/db/changelog/changeset/0010_delete_timestamp_for_consultant_agency/0010_changeSet.xml @@ -0,0 +1,15 @@ + + + + + + + + + diff --git a/src/main/resources/db/changelog/changeset/0010_delete_timestamp_for_consultant_agency/delete-timestamp-for-consultant-agency-rollback.sql b/src/main/resources/db/changelog/changeset/0010_delete_timestamp_for_consultant_agency/delete-timestamp-for-consultant-agency-rollback.sql new file mode 100644 index 000000000..767c818ff --- /dev/null +++ b/src/main/resources/db/changelog/changeset/0010_delete_timestamp_for_consultant_agency/delete-timestamp-for-consultant-agency-rollback.sql @@ -0,0 +1,2 @@ +ALTER TABLE `userservice`.`consultant_agency` +DROP `delete_date`; diff --git a/src/main/resources/db/changelog/changeset/0010_delete_timestamp_for_consultant_agency/delete-timestamp-for-consultant-agency.sql b/src/main/resources/db/changelog/changeset/0010_delete_timestamp_for_consultant_agency/delete-timestamp-for-consultant-agency.sql new file mode 100644 index 000000000..a08f6f2c8 --- /dev/null +++ b/src/main/resources/db/changelog/changeset/0010_delete_timestamp_for_consultant_agency/delete-timestamp-for-consultant-agency.sql @@ -0,0 +1,2 @@ +ALTER TABLE `userservice`.`consultant_agency` +ADD `delete_date` datetime NULL DEFAULT NULL AFTER `update_date`; diff --git a/src/main/resources/db/changelog/userservice-dev-master.xml b/src/main/resources/db/changelog/userservice-dev-master.xml index be10df55c..6a2563cff 100644 --- a/src/main/resources/db/changelog/userservice-dev-master.xml +++ b/src/main/resources/db/changelog/userservice-dev-master.xml @@ -1,10 +1,10 @@ - + - + @@ -15,4 +15,5 @@ - \ No newline at end of file + + diff --git a/src/main/resources/db/changelog/userservice-local-master.xml b/src/main/resources/db/changelog/userservice-local-master.xml index 66be5750f..aa5099f03 100644 --- a/src/main/resources/db/changelog/userservice-local-master.xml +++ b/src/main/resources/db/changelog/userservice-local-master.xml @@ -15,4 +15,5 @@ - \ No newline at end of file + + diff --git a/src/main/resources/db/changelog/userservice-prod-master.xml b/src/main/resources/db/changelog/userservice-prod-master.xml index 156a66351..0ff57aa2d 100644 --- a/src/main/resources/db/changelog/userservice-prod-master.xml +++ b/src/main/resources/db/changelog/userservice-prod-master.xml @@ -13,4 +13,5 @@ - \ No newline at end of file + + diff --git a/src/main/resources/db/changelog/userservice-staging-master.xml b/src/main/resources/db/changelog/userservice-staging-master.xml index f09e31fac..1ba65c8a4 100644 --- a/src/main/resources/db/changelog/userservice-staging-master.xml +++ b/src/main/resources/db/changelog/userservice-staging-master.xml @@ -13,4 +13,5 @@ - \ No newline at end of file + + diff --git a/src/test/java/de/caritas/cob/userservice/api/admin/controller/UserAdminControllerAuthorizationIT.java b/src/test/java/de/caritas/cob/userservice/api/admin/controller/UserAdminControllerAuthorizationIT.java index e31ca24e7..f86093608 100644 --- a/src/test/java/de/caritas/cob/userservice/api/admin/controller/UserAdminControllerAuthorizationIT.java +++ b/src/test/java/de/caritas/cob/userservice/api/admin/controller/UserAdminControllerAuthorizationIT.java @@ -4,6 +4,7 @@ import static de.caritas.cob.userservice.api.admin.controller.UserAdminControllerIT.CONSULTANT_AGENCIES_PATH; import static de.caritas.cob.userservice.api.admin.controller.UserAdminControllerIT.CONSULTANT_AGENCY_PATH; import static de.caritas.cob.userservice.api.admin.controller.UserAdminControllerIT.CONSULTING_TYPE_PATH; +import static de.caritas.cob.userservice.api.admin.controller.UserAdminControllerIT.DELETE_CONSULTANT_AGENCY_PATH; import static de.caritas.cob.userservice.api.admin.controller.UserAdminControllerIT.FILTERED_CONSULTANTS_PATH; import static de.caritas.cob.userservice.api.admin.controller.UserAdminControllerIT.GET_CONSULTANT_PATH; import static de.caritas.cob.userservice.api.admin.controller.UserAdminControllerIT.PAGE_PARAM; @@ -17,6 +18,7 @@ import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyNoMoreInteractions; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.put; @@ -610,4 +612,55 @@ public void changeAgencyType_Should_ReturnCreatedAndCallConsultantAdmin_When_use verify(this.consultantAdminFacade, times(1)).changeAgencyType(any(), any()); } + @Test + public void deleteConsultantAgency_Should_ReturnForbiddenAndCallNoMethods_When_noCsrfTokenIsSet() + throws Exception { + mvc.perform(delete(String.format(DELETE_CONSULTANT_AGENCY_PATH, "1", 1L))) + .andExpect(status().isForbidden()); + + verifyNoMoreInteractions(consultantAdminFacade); + } + + @Test + public void deleteConsultantAgency_Should_ReturnUnauthorizedAndCallNoMethods_When_noKeycloakAuthorizationIsPresent() + throws Exception { + mvc.perform(delete(String.format(DELETE_CONSULTANT_AGENCY_PATH, "1", 1L)) + .cookie(CSRF_COOKIE) + .header(CSRF_HEADER, CSRF_VALUE) + .contentType(MediaType.APPLICATION_JSON)) + .andExpect(status().isUnauthorized()); + + verifyNoMoreInteractions(consultantAdminFacade); + } + + @Test + @WithMockUser( + authorities = {Authority.ASSIGN_CONSULTANT_TO_SESSION, Authority.ASSIGN_CONSULTANT_TO_ENQUIRY, + Authority.USE_FEEDBACK, Authority.TECHNICAL_DEFAULT, Authority.CONSULTANT_DEFAULT, + Authority.VIEW_AGENCY_CONSULTANTS, Authority.VIEW_ALL_PEER_SESSIONS, Authority.START_CHAT, + Authority.CREATE_NEW_CHAT, Authority.STOP_CHAT, Authority.UPDATE_CHAT}) + public void deleteConsultantAgency_Should_ReturnForbiddenAndCallNoMethods_When_noUserAdminAuthority() + throws Exception { + mvc.perform(delete(String.format(DELETE_CONSULTANT_AGENCY_PATH, "1", 1L)) + .cookie(CSRF_COOKIE) + .header(CSRF_HEADER, CSRF_VALUE) + .contentType(MediaType.APPLICATION_JSON)) + .andExpect(status().isForbidden()); + + verifyNoMoreInteractions(consultantAdminFacade); + } + + @Test + @WithMockUser(authorities = {Authority.USER_ADMIN}) + public void deleteConsultantAgency_Should_ReturnCreatedAndCallConsultantAdmin_When_userAdminAuthority() + throws Exception { + mvc.perform(delete(String.format(DELETE_CONSULTANT_AGENCY_PATH, "1", 1L)) + .cookie(CSRF_COOKIE) + .header(CSRF_HEADER, CSRF_VALUE) + .contentType(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()); + + verify(this.consultantAdminFacade, times(1)).markConsultantAgencyForDeletion(any(), any()); + } + } diff --git a/src/test/java/de/caritas/cob/userservice/api/admin/controller/UserAdminControllerIT.java b/src/test/java/de/caritas/cob/userservice/api/admin/controller/UserAdminControllerIT.java index e1214be30..1191bf2b2 100644 --- a/src/test/java/de/caritas/cob/userservice/api/admin/controller/UserAdminControllerIT.java +++ b/src/test/java/de/caritas/cob/userservice/api/admin/controller/UserAdminControllerIT.java @@ -7,6 +7,7 @@ import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.put; @@ -51,6 +52,8 @@ public class UserAdminControllerIT { protected static final String CONSULTING_TYPE_PATH = ROOT_PATH + "/consultingtypes"; protected static final String CONSULTANT_AGENCIES_PATH = ROOT_PATH + "/consultant/%s/agencies"; protected static final String CONSULTANT_AGENCY_PATH = ROOT_PATH + "/consultant/%s/agency"; + protected static final String DELETE_CONSULTANT_AGENCY_PATH = ROOT_PATH + "/consultant/%s" + + "/agency/%s"; protected static final String AGENCY_CHANGE_TYPE_PATH = ROOT_PATH + "/agency/1/changetype"; protected static final String PAGE_PARAM = "page"; protected static final String PER_PAGE_PARAM = "perPage"; @@ -264,4 +267,21 @@ public void changeAgencyType_Should_returnOk_When_parametersAreValid() throws Ex verify(this.consultantAdminFacade, times(1)).changeAgencyType(any(), any()); } + @Test + public void deleteConsultantAgency_Should_returnOk_When_requiredParamsAreGiven() + throws Exception { + String consultantId = "1da238c6-cd46-4162-80f1-bff74eafeAAA"; + Long agencyId = 1L; + + String consultantAgencyDeletePath = + String.format(DELETE_CONSULTANT_AGENCY_PATH, consultantId, agencyId); + + this.mvc.perform(delete(consultantAgencyDeletePath) + .contentType(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()); + + verify(this.consultantAdminFacade, times(1)) + .markConsultantAgencyForDeletion(eq(consultantId), eq(agencyId)); + } + } diff --git a/src/test/java/de/caritas/cob/userservice/api/admin/facade/ConsultantAdminFacadeTest.java b/src/test/java/de/caritas/cob/userservice/api/admin/facade/ConsultantAdminFacadeTest.java index 937afb83d..57fc5cc58 100644 --- a/src/test/java/de/caritas/cob/userservice/api/admin/facade/ConsultantAdminFacadeTest.java +++ b/src/test/java/de/caritas/cob/userservice/api/admin/facade/ConsultantAdminFacadeTest.java @@ -106,4 +106,12 @@ public void changeAgencyType_Should_callRemoveConsultantsFromTeamSessionsByAgenc .removeConsultantsFromTeamSessionsByAgencyId(1L); } + @Test + public void markConsultantAgencyForDeletion_Should_callMarkConsultantAgencyForDeletion() { + this.consultantAdminFacade.markConsultantAgencyForDeletion("1", 1L); + + verify(this.consultantAgencyAdminService, times(1)) + .markConsultantAgencyForDeletion("1", 1L); + } + } diff --git a/src/test/java/de/caritas/cob/userservice/api/admin/report/rule/ConsultantWithWrongTeamConsultantFlagViolationReportRuleTest.java b/src/test/java/de/caritas/cob/userservice/api/admin/report/rule/ConsultantWithWrongTeamConsultantFlagViolationReportRuleTest.java index 63b423c5d..06c829203 100644 --- a/src/test/java/de/caritas/cob/userservice/api/admin/report/rule/ConsultantWithWrongTeamConsultantFlagViolationReportRuleTest.java +++ b/src/test/java/de/caritas/cob/userservice/api/admin/report/rule/ConsultantWithWrongTeamConsultantFlagViolationReportRuleTest.java @@ -14,8 +14,8 @@ import de.caritas.cob.userservice.api.admin.report.service.AgencyAdminService; import de.caritas.cob.userservice.api.model.ViolationDTO; import de.caritas.cob.userservice.api.repository.consultant.ConsultantRepository; -import de.caritas.cob.userservice.api.repository.consultantAgency.ConsultantAgency; -import de.caritas.cob.userservice.api.repository.consultantAgency.ConsultantAgencyRepository; +import de.caritas.cob.userservice.api.repository.consultantagency.ConsultantAgency; +import de.caritas.cob.userservice.api.repository.consultantagency.ConsultantAgencyRepository; import java.util.List; import java.util.stream.Collectors; import org.jeasy.random.EasyRandom; diff --git a/src/test/java/de/caritas/cob/userservice/api/admin/report/rule/InvalidAgencyForConsultantViolationReportRuleTest.java b/src/test/java/de/caritas/cob/userservice/api/admin/report/rule/InvalidAgencyForConsultantViolationReportRuleTest.java index 4519f3905..41638ac65 100644 --- a/src/test/java/de/caritas/cob/userservice/api/admin/report/rule/InvalidAgencyForConsultantViolationReportRuleTest.java +++ b/src/test/java/de/caritas/cob/userservice/api/admin/report/rule/InvalidAgencyForConsultantViolationReportRuleTest.java @@ -13,8 +13,8 @@ import de.caritas.cob.userservice.agencyadminserivce.generated.web.model.AgencyAdminResponseDTO; import de.caritas.cob.userservice.api.admin.report.service.AgencyAdminService; import de.caritas.cob.userservice.api.model.ViolationDTO; -import de.caritas.cob.userservice.api.repository.consultantAgency.ConsultantAgency; -import de.caritas.cob.userservice.api.repository.consultantAgency.ConsultantAgencyRepository; +import de.caritas.cob.userservice.api.repository.consultantagency.ConsultantAgency; +import de.caritas.cob.userservice.api.repository.consultantagency.ConsultantAgencyRepository; import java.util.List; import java.util.stream.Collectors; import org.jeasy.random.EasyRandom; diff --git a/src/test/java/de/caritas/cob/userservice/api/admin/report/rule/MissingRocketChatRoomForConsultantViolationReportRuleTest.java b/src/test/java/de/caritas/cob/userservice/api/admin/report/rule/MissingRocketChatRoomForConsultantViolationReportRuleTest.java index 2442f2a85..aec796995 100644 --- a/src/test/java/de/caritas/cob/userservice/api/admin/report/rule/MissingRocketChatRoomForConsultantViolationReportRuleTest.java +++ b/src/test/java/de/caritas/cob/userservice/api/admin/report/rule/MissingRocketChatRoomForConsultantViolationReportRuleTest.java @@ -18,7 +18,7 @@ import de.caritas.cob.userservice.api.repository.consultant.ConsultantRepository; import de.caritas.cob.userservice.api.repository.session.Session; import de.caritas.cob.userservice.api.repository.session.SessionRepository; -import de.caritas.cob.userservice.api.service.RocketChatService; +import de.caritas.cob.userservice.api.service.rocketchat.RocketChatService; import java.util.List; import org.jeasy.random.EasyRandom; import org.junit.Test; diff --git a/src/test/java/de/caritas/cob/userservice/api/admin/report/rule/MissingSessionAndChatForAskerViolationReportRuleTest.java b/src/test/java/de/caritas/cob/userservice/api/admin/report/rule/MissingSessionAndChatForAskerViolationReportRuleTest.java index a5b27679f..1d7706a08 100644 --- a/src/test/java/de/caritas/cob/userservice/api/admin/report/rule/MissingSessionAndChatForAskerViolationReportRuleTest.java +++ b/src/test/java/de/caritas/cob/userservice/api/admin/report/rule/MissingSessionAndChatForAskerViolationReportRuleTest.java @@ -10,7 +10,7 @@ import de.caritas.cob.userservice.api.model.ViolationDTO; import de.caritas.cob.userservice.api.repository.user.User; import de.caritas.cob.userservice.api.repository.user.UserRepository; -import de.caritas.cob.userservice.api.repository.userAgency.UserAgencyRepository; +import de.caritas.cob.userservice.api.repository.useragency.UserAgencyRepository; import java.util.List; import java.util.stream.Collectors; import org.jeasy.random.EasyRandom; diff --git a/src/test/java/de/caritas/cob/userservice/api/admin/report/rule/TeamConsultantWithoutRequiredFlagViolationReportRuleTest.java b/src/test/java/de/caritas/cob/userservice/api/admin/report/rule/TeamConsultantWithoutRequiredFlagViolationReportRuleTest.java index 1b7ab5374..0ed75b482 100644 --- a/src/test/java/de/caritas/cob/userservice/api/admin/report/rule/TeamConsultantWithoutRequiredFlagViolationReportRuleTest.java +++ b/src/test/java/de/caritas/cob/userservice/api/admin/report/rule/TeamConsultantWithoutRequiredFlagViolationReportRuleTest.java @@ -13,8 +13,8 @@ import de.caritas.cob.userservice.agencyadminserivce.generated.web.model.AgencyAdminResponseDTO; import de.caritas.cob.userservice.api.admin.report.service.AgencyAdminService; import de.caritas.cob.userservice.api.model.ViolationDTO; -import de.caritas.cob.userservice.api.repository.consultantAgency.ConsultantAgency; -import de.caritas.cob.userservice.api.repository.consultantAgency.ConsultantAgencyRepository; +import de.caritas.cob.userservice.api.repository.consultantagency.ConsultantAgency; +import de.caritas.cob.userservice.api.repository.consultantagency.ConsultantAgencyRepository; import java.util.List; import java.util.stream.Collectors; import org.jeasy.random.EasyRandom; diff --git a/src/test/java/de/caritas/cob/userservice/api/admin/service/agency/ConsultantAgencyAdminResultDTOBuilderTest.java b/src/test/java/de/caritas/cob/userservice/api/admin/service/agency/ConsultantAgencyAdminResultDTOBuilderTest.java index 4f9258d80..f663cc1af 100644 --- a/src/test/java/de/caritas/cob/userservice/api/admin/service/agency/ConsultantAgencyAdminResultDTOBuilderTest.java +++ b/src/test/java/de/caritas/cob/userservice/api/admin/service/agency/ConsultantAgencyAdminResultDTOBuilderTest.java @@ -6,7 +6,8 @@ import static org.hamcrest.core.Is.is; import de.caritas.cob.userservice.api.model.ConsultantAgencyAdminResultDTO; -import de.caritas.cob.userservice.api.repository.consultantAgency.ConsultantAgency; +import de.caritas.cob.userservice.api.model.HalLink.MethodEnum; +import de.caritas.cob.userservice.api.repository.consultantagency.ConsultantAgency; import java.util.List; import java.util.stream.Collectors; import org.jeasy.random.EasyRandom; @@ -66,6 +67,9 @@ public void build_Should_returnEmptyConsultantAgencyAdminResultDTOWithContent_Wh assertThat(resultDTO, notNullValue()); assertThat(resultDTO.getEmbedded(), hasSize(MOCKED_CONSULTANT_AGENCY_LIST_SIZE)); + assertThat(resultDTO.getEmbedded().get(0).getLinks().getDelete().getHref(), notNullValue()); + assertThat(resultDTO.getEmbedded().get(0).getLinks().getDelete().getMethod(), + is(MethodEnum.DELETE)); assertThat(resultDTO.getLinks(), notNullValue()); assertThat(resultDTO.getLinks().getSelf(), notNullValue()); assertThat(resultDTO.getLinks().getSelf().getHref(), diff --git a/src/test/java/de/caritas/cob/userservice/api/admin/service/agency/ConsultantAgencyAdminServiceIT.java b/src/test/java/de/caritas/cob/userservice/api/admin/service/agency/ConsultantAgencyAdminServiceIT.java index 1b4ac5deb..882341edb 100644 --- a/src/test/java/de/caritas/cob/userservice/api/admin/service/agency/ConsultantAgencyAdminServiceIT.java +++ b/src/test/java/de/caritas/cob/userservice/api/admin/service/agency/ConsultantAgencyAdminServiceIT.java @@ -24,6 +24,8 @@ import de.caritas.cob.userservice.api.model.ConsultantAgencyAdminResultDTO; import de.caritas.cob.userservice.api.repository.consultant.Consultant; import de.caritas.cob.userservice.api.repository.consultant.ConsultantRepository; +import de.caritas.cob.userservice.api.repository.consultantagency.ConsultantAgency; +import de.caritas.cob.userservice.api.repository.consultantagency.ConsultantAgencyRepository; import de.caritas.cob.userservice.api.service.helper.AgencyServiceHelper; import org.junit.Test; import org.junit.runner.RunWith; @@ -47,6 +49,9 @@ public class ConsultantAgencyAdminServiceIT { @Autowired private ConsultantRepository consultantRepository; + @Autowired + private ConsultantAgencyRepository consultantAgencyRepository; + @MockBean private ConsultantAgencyRelationCreatorService consultantAgencyRelationCreatorService; @@ -138,4 +143,18 @@ public void removeConsultantsFromTeamSessionsByAgencyId_Should_removeTeamConsult .removeConsultantFromSessions(any()); } + @Test + public void markConsultantAgencyForDeletion_Should_setDeletedFlagIndatabase_When_consultantAgencyCanBeDeleted() { + ConsultantAgency validRelation = this.consultantAgencyRepository.findAll().iterator().next(); + String consultantId = validRelation.getConsultant().getId(); + Long agencyId = validRelation.getAgencyId(); + + this.consultantAgencyAdminService.markConsultantAgencyForDeletion(consultantId, agencyId); + + ConsultantAgency deletedConsultantAgency = + this.consultantAgencyRepository.findByConsultantIdAndAgencyId(consultantId, agencyId) + .get(0); + assertThat(deletedConsultantAgency.getDeleteDate(), notNullValue()); + } + } diff --git a/src/test/java/de/caritas/cob/userservice/api/admin/service/agency/ConsultantAgencyAdminServiceTest.java b/src/test/java/de/caritas/cob/userservice/api/admin/service/agency/ConsultantAgencyAdminServiceTest.java index 86d85acb4..de0714283 100644 --- a/src/test/java/de/caritas/cob/userservice/api/admin/service/agency/ConsultantAgencyAdminServiceTest.java +++ b/src/test/java/de/caritas/cob/userservice/api/admin/service/agency/ConsultantAgencyAdminServiceTest.java @@ -1,19 +1,30 @@ package de.caritas.cob.userservice.api.admin.service.agency; +import static de.caritas.cob.userservice.api.exception.httpresponses.customheader.HttpStatusExceptionReason.CONSULTANT_AGENCY_RELATION_DOES_NOT_EXIST; +import static de.caritas.cob.userservice.api.exception.httpresponses.customheader.HttpStatusExceptionReason.CONSULTANT_IS_THE_LAST_OF_AGENCY_AND_AGENCY_HAS_OPEN_ENQUIRIES; +import static de.caritas.cob.userservice.api.exception.httpresponses.customheader.HttpStatusExceptionReason.CONSULTANT_IS_THE_LAST_OF_AGENCY_AND_AGENCY_IS_STILL_ACTIVE; +import static java.util.Collections.emptyList; import static java.util.Collections.singletonList; +import static java.util.Objects.requireNonNull; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.notNullValue; +import static org.junit.Assert.fail; import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import de.caritas.cob.userservice.api.exception.AgencyServiceHelperException; +import de.caritas.cob.userservice.api.exception.httpresponses.CustomValidationHttpStatusException; import de.caritas.cob.userservice.api.exception.httpresponses.InternalServerErrorException; import de.caritas.cob.userservice.api.exception.httpresponses.NotFoundException; import de.caritas.cob.userservice.api.model.AgencyDTO; import de.caritas.cob.userservice.api.repository.consultant.Consultant; import de.caritas.cob.userservice.api.repository.consultant.ConsultantRepository; -import de.caritas.cob.userservice.api.repository.consultantAgency.ConsultantAgency; -import de.caritas.cob.userservice.api.repository.consultantAgency.ConsultantAgencyRepository; +import de.caritas.cob.userservice.api.repository.consultantagency.ConsultantAgency; +import de.caritas.cob.userservice.api.repository.consultantagency.ConsultantAgencyRepository; import de.caritas.cob.userservice.api.repository.session.Session; import de.caritas.cob.userservice.api.repository.session.SessionRepository; import de.caritas.cob.userservice.api.service.helper.AgencyServiceHelper; @@ -128,4 +139,91 @@ public void removeConsultantsFromTeamSessionsByAgencyId_Should_throwInternalServ this.consultantAgencyAdminService.removeConsultantsFromTeamSessionsByAgencyId(1L); } + @Test + public void markConsultantAgencyForDeletion_Should_throwCustomValidationHttpStatusException_When_relationDoesNotExist() { + try { + this.consultantAgencyAdminService.markConsultantAgencyForDeletion("", 1L); + fail("Exception was not thrown"); + } catch (CustomValidationHttpStatusException e) { + assertThat(requireNonNull(e.getCustomHttpHeader().get("X-Reason")).iterator().next(), + is(CONSULTANT_AGENCY_RELATION_DOES_NOT_EXIST.name())); + } + } + + @Test + public void markConsultantAgencyForDeletion_Should_throwCustomValidationHttpStatusException_When_consultantIsTheLastOfTheAgencyAndAgencyIsStillOnline() + throws AgencyServiceHelperException { + ConsultantAgency consultantAgency = new EasyRandom().nextObject(ConsultantAgency.class); + consultantAgency.setDeleteDate(null); + when(this.consultantAgencyRepository.findByConsultantIdAndAgencyId(any(), any())) + .thenReturn(singletonList(consultantAgency)); + when(this.consultantAgencyRepository.findByAgencyId(any())) + .thenReturn(singletonList(consultantAgency)); + when(this.agencyServiceHelper.getAgency(any())).thenReturn(new AgencyDTO().offline(false)); + + try { + this.consultantAgencyAdminService.markConsultantAgencyForDeletion("", 1L); + fail("Exception was not thrown"); + } catch (CustomValidationHttpStatusException e) { + assertThat(requireNonNull(e.getCustomHttpHeader().get("X-Reason")).iterator().next(), + is(CONSULTANT_IS_THE_LAST_OF_AGENCY_AND_AGENCY_IS_STILL_ACTIVE.name())); + } + } + + @Test(expected = InternalServerErrorException.class) + public void markConsultantAgencyForDeletion_Should_throwInternalServerErrorException_When_agencyCanNotBefetched() + throws AgencyServiceHelperException { + ConsultantAgency consultantAgency = new EasyRandom().nextObject(ConsultantAgency.class); + consultantAgency.setDeleteDate(null); + when(this.consultantAgencyRepository.findByConsultantIdAndAgencyId(any(), any())) + .thenReturn(singletonList(consultantAgency)); + when(this.consultantAgencyRepository.findByAgencyId(any())) + .thenReturn(singletonList(consultantAgency)); + when(this.agencyServiceHelper.getAgency(any())) + .thenThrow(new AgencyServiceHelperException(new Exception())); + + this.consultantAgencyAdminService.markConsultantAgencyForDeletion("", 1L); + } + + @Test + public void markConsultantAgencyForDeletion_Should_throwCustomValidationHttpStatusException_When_consultantIsTheLastOfTheAgencyAndAgencyHasOpenEnquiries() + throws AgencyServiceHelperException { + ConsultantAgency consultantAgency = new EasyRandom().nextObject(ConsultantAgency.class); + consultantAgency.setDeleteDate(null); + when(this.consultantAgencyRepository.findByConsultantIdAndAgencyId(any(), any())) + .thenReturn(singletonList(consultantAgency)); + when(this.consultantAgencyRepository.findByAgencyId(any())) + .thenReturn(singletonList(consultantAgency)); + when(this.agencyServiceHelper.getAgency(any())).thenReturn(new AgencyDTO().offline(true)); + when(this.sessionRepository.findByAgencyIdAndStatusAndConsultantIsNull(any(), any())) + .thenReturn(singletonList(mock(Session.class))); + + try { + this.consultantAgencyAdminService.markConsultantAgencyForDeletion("", 1L); + fail("Exception was not thrown"); + } catch (CustomValidationHttpStatusException e) { + assertThat(requireNonNull(e.getCustomHttpHeader().get("X-Reason")).iterator().next(), + is(CONSULTANT_IS_THE_LAST_OF_AGENCY_AND_AGENCY_HAS_OPEN_ENQUIRIES.name())); + } + } + + @Test + public void markConsultantAgencyForDeletion_Should_deleteConsultantAgency_When_consultantAgencyCanBeDeleted() + throws AgencyServiceHelperException { + ConsultantAgency consultantAgency = new EasyRandom().nextObject(ConsultantAgency.class); + consultantAgency.setDeleteDate(null); + when(this.consultantAgencyRepository.findByConsultantIdAndAgencyId(any(), any())) + .thenReturn(singletonList(consultantAgency)); + when(this.consultantAgencyRepository.findByAgencyId(any())) + .thenReturn(singletonList(consultantAgency)); + when(this.agencyServiceHelper.getAgency(any())).thenReturn(new AgencyDTO().offline(true)); + when(this.sessionRepository.findByAgencyIdAndStatusAndConsultantIsNull(any(), any())) + .thenReturn(emptyList()); + + this.consultantAgencyAdminService.markConsultantAgencyForDeletion("", 1L); + + assertThat(consultantAgency.getDeleteDate(), notNullValue()); + verify(this.consultantAgencyRepository, times(1)).save(any(ConsultantAgency.class)); + } + } diff --git a/src/test/java/de/caritas/cob/userservice/api/admin/service/agency/RemoveConsultantFromRocketChatServiceTest.java b/src/test/java/de/caritas/cob/userservice/api/admin/service/agency/RemoveConsultantFromRocketChatServiceTest.java index 97c1ba455..d6d1f98ed 100644 --- a/src/test/java/de/caritas/cob/userservice/api/admin/service/agency/RemoveConsultantFromRocketChatServiceTest.java +++ b/src/test/java/de/caritas/cob/userservice/api/admin/service/agency/RemoveConsultantFromRocketChatServiceTest.java @@ -15,7 +15,7 @@ import de.caritas.cob.userservice.api.repository.consultant.Consultant; import de.caritas.cob.userservice.api.repository.consultant.ConsultantRepository; import de.caritas.cob.userservice.api.repository.session.Session; -import de.caritas.cob.userservice.api.service.RocketChatService; +import de.caritas.cob.userservice.api.service.rocketchat.RocketChatService; import de.caritas.cob.userservice.api.service.helper.KeycloakAdminClientService; import java.util.Optional; import org.jeasy.random.EasyRandom; diff --git a/src/test/java/de/caritas/cob/userservice/api/admin/service/consultant/create/ConsultantCreatorServiceIT.java b/src/test/java/de/caritas/cob/userservice/api/admin/service/consultant/create/ConsultantCreatorServiceIT.java index 3979c312f..b82be220a 100644 --- a/src/test/java/de/caritas/cob/userservice/api/admin/service/consultant/create/ConsultantCreatorServiceIT.java +++ b/src/test/java/de/caritas/cob/userservice/api/admin/service/consultant/create/ConsultantCreatorServiceIT.java @@ -20,7 +20,7 @@ import de.caritas.cob.userservice.api.model.keycloak.KeycloakCreateUserResponseDTO; import de.caritas.cob.userservice.api.repository.consultant.Consultant; import de.caritas.cob.userservice.api.service.ConsultantImportService.ImportRecord; -import de.caritas.cob.userservice.api.service.RocketChatService; +import de.caritas.cob.userservice.api.service.rocketchat.RocketChatService; import de.caritas.cob.userservice.api.service.helper.KeycloakAdminClientService; import org.jeasy.random.EasyRandom; import org.junit.Test; diff --git a/src/test/java/de/caritas/cob/userservice/api/admin/service/consultant/create/agencyrelation/ConsultantAgencyRelationCreatorServiceIT.java b/src/test/java/de/caritas/cob/userservice/api/admin/service/consultant/create/agencyrelation/ConsultantAgencyRelationCreatorServiceIT.java index 44e4c007d..9db76dc66 100644 --- a/src/test/java/de/caritas/cob/userservice/api/admin/service/consultant/create/agencyrelation/ConsultantAgencyRelationCreatorServiceIT.java +++ b/src/test/java/de/caritas/cob/userservice/api/admin/service/consultant/create/agencyrelation/ConsultantAgencyRelationCreatorServiceIT.java @@ -24,17 +24,17 @@ import de.caritas.cob.userservice.api.model.CreateConsultantAgencyDTO; import de.caritas.cob.userservice.api.repository.consultant.Consultant; import de.caritas.cob.userservice.api.repository.consultant.ConsultantRepository; -import de.caritas.cob.userservice.api.repository.consultantAgency.ConsultantAgency; -import de.caritas.cob.userservice.api.repository.consultantAgency.ConsultantAgencyRepository; +import de.caritas.cob.userservice.api.repository.consultantagency.ConsultantAgency; +import de.caritas.cob.userservice.api.repository.consultantagency.ConsultantAgencyRepository; import de.caritas.cob.userservice.api.repository.session.ConsultingType; import de.caritas.cob.userservice.api.repository.session.Session; import de.caritas.cob.userservice.api.repository.session.SessionRepository; import de.caritas.cob.userservice.api.repository.session.SessionStatus; import de.caritas.cob.userservice.api.repository.user.User; import de.caritas.cob.userservice.api.repository.user.UserRepository; -import de.caritas.cob.userservice.api.repository.userAgency.UserAgency; -import de.caritas.cob.userservice.api.repository.userAgency.UserAgencyRepository; -import de.caritas.cob.userservice.api.service.RocketChatService; +import de.caritas.cob.userservice.api.repository.useragency.UserAgency; +import de.caritas.cob.userservice.api.repository.useragency.UserAgencyRepository; +import de.caritas.cob.userservice.api.service.rocketchat.RocketChatService; import de.caritas.cob.userservice.api.service.helper.AgencyServiceHelper; import de.caritas.cob.userservice.api.service.helper.KeycloakAdminClientService; import java.util.List; diff --git a/src/test/java/de/caritas/cob/userservice/api/admin/service/consultant/update/ConsultantUpdateServiceIT.java b/src/test/java/de/caritas/cob/userservice/api/admin/service/consultant/update/ConsultantUpdateServiceIT.java index 204ef0ac0..c8bd6d345 100644 --- a/src/test/java/de/caritas/cob/userservice/api/admin/service/consultant/update/ConsultantUpdateServiceIT.java +++ b/src/test/java/de/caritas/cob/userservice/api/admin/service/consultant/update/ConsultantUpdateServiceIT.java @@ -11,7 +11,7 @@ import de.caritas.cob.userservice.api.exception.httpresponses.CustomValidationHttpStatusException; import de.caritas.cob.userservice.api.model.UpdateConsultantDTO; import de.caritas.cob.userservice.api.repository.consultant.Consultant; -import de.caritas.cob.userservice.api.service.RocketChatService; +import de.caritas.cob.userservice.api.service.rocketchat.RocketChatService; import de.caritas.cob.userservice.api.service.helper.KeycloakAdminClientService; import org.junit.Test; import org.junit.runner.RunWith; diff --git a/src/test/java/de/caritas/cob/userservice/api/admin/service/consultant/update/ConsultantUpdateServiceTest.java b/src/test/java/de/caritas/cob/userservice/api/admin/service/consultant/update/ConsultantUpdateServiceTest.java index e0cece207..09070d20c 100644 --- a/src/test/java/de/caritas/cob/userservice/api/admin/service/consultant/update/ConsultantUpdateServiceTest.java +++ b/src/test/java/de/caritas/cob/userservice/api/admin/service/consultant/update/ConsultantUpdateServiceTest.java @@ -13,7 +13,7 @@ import de.caritas.cob.userservice.api.model.registration.UserDTO; import de.caritas.cob.userservice.api.repository.consultant.Consultant; import de.caritas.cob.userservice.api.service.ConsultantService; -import de.caritas.cob.userservice.api.service.RocketChatService; +import de.caritas.cob.userservice.api.service.rocketchat.RocketChatService; import de.caritas.cob.userservice.api.service.helper.KeycloakAdminClientService; import java.util.Optional; import org.jeasy.random.EasyRandom; diff --git a/src/test/java/de/caritas/cob/userservice/api/admin/service/rocketchat/RocketChatAddToGroupOperationServiceTest.java b/src/test/java/de/caritas/cob/userservice/api/admin/service/rocketchat/RocketChatAddToGroupOperationServiceTest.java index 1aeb81283..d99b605df 100644 --- a/src/test/java/de/caritas/cob/userservice/api/admin/service/rocketchat/RocketChatAddToGroupOperationServiceTest.java +++ b/src/test/java/de/caritas/cob/userservice/api/admin/service/rocketchat/RocketChatAddToGroupOperationServiceTest.java @@ -17,7 +17,7 @@ import de.caritas.cob.userservice.api.repository.consultant.Consultant; import de.caritas.cob.userservice.api.repository.session.Session; import de.caritas.cob.userservice.api.repository.session.SessionStatus; -import de.caritas.cob.userservice.api.service.RocketChatService; +import de.caritas.cob.userservice.api.service.rocketchat.RocketChatService; import de.caritas.cob.userservice.api.service.helper.KeycloakAdminClientService; import java.util.function.Consumer; import org.jeasy.random.EasyRandom; diff --git a/src/test/java/de/caritas/cob/userservice/api/admin/service/rocketchat/RocketChatRemoveFromGroupOperationServiceTest.java b/src/test/java/de/caritas/cob/userservice/api/admin/service/rocketchat/RocketChatRemoveFromGroupOperationServiceTest.java index f933ddd53..7ef6826fb 100644 --- a/src/test/java/de/caritas/cob/userservice/api/admin/service/rocketchat/RocketChatRemoveFromGroupOperationServiceTest.java +++ b/src/test/java/de/caritas/cob/userservice/api/admin/service/rocketchat/RocketChatRemoveFromGroupOperationServiceTest.java @@ -17,7 +17,7 @@ import de.caritas.cob.userservice.api.repository.consultant.Consultant; import de.caritas.cob.userservice.api.repository.session.Session; import de.caritas.cob.userservice.api.repository.session.SessionStatus; -import de.caritas.cob.userservice.api.service.RocketChatService; +import de.caritas.cob.userservice.api.service.rocketchat.RocketChatService; import de.caritas.cob.userservice.api.service.helper.KeycloakAdminClientService; import java.util.HashMap; import java.util.List; diff --git a/src/test/java/de/caritas/cob/userservice/api/controller/LiveProxyControllerIT.java b/src/test/java/de/caritas/cob/userservice/api/controller/LiveProxyControllerIT.java index d336adc86..5ac9c5256 100644 --- a/src/test/java/de/caritas/cob/userservice/api/controller/LiveProxyControllerIT.java +++ b/src/test/java/de/caritas/cob/userservice/api/controller/LiveProxyControllerIT.java @@ -3,7 +3,7 @@ import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.verifyZeroInteractions; +import static org.mockito.Mockito.verifyNoInteractions; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; @@ -45,7 +45,7 @@ public void sendLiveEvent_Should_returnBadRequest_When_rcGroupIdIsNotProvided() this.mockMvc.perform(post(LIVE_EVENT_PATH)) .andExpect(status().isBadRequest()); - verifyZeroInteractions(liveEventNotificationService); + verifyNoInteractions(liveEventNotificationService); } @Test diff --git a/src/test/java/de/caritas/cob/userservice/api/controller/UserControllerAuthorizationIT.java b/src/test/java/de/caritas/cob/userservice/api/controller/UserControllerAuthorizationIT.java index 996a52689..dac3d2685 100644 --- a/src/test/java/de/caritas/cob/userservice/api/controller/UserControllerAuthorizationIT.java +++ b/src/test/java/de/caritas/cob/userservice/api/controller/UserControllerAuthorizationIT.java @@ -60,7 +60,7 @@ import de.caritas.cob.userservice.api.service.KeycloakService; import de.caritas.cob.userservice.api.service.LogService; import de.caritas.cob.userservice.api.service.MonitoringService; -import de.caritas.cob.userservice.api.service.RocketChatService; +import de.caritas.cob.userservice.api.service.rocketchat.RocketChatService; import de.caritas.cob.userservice.api.service.SessionService; import de.caritas.cob.userservice.api.service.UserService; import de.caritas.cob.userservice.api.service.ValidatedUserAccountProvider; diff --git a/src/test/java/de/caritas/cob/userservice/api/controller/UserControllerIT.java b/src/test/java/de/caritas/cob/userservice/api/controller/UserControllerIT.java index 26056f81c..a4e3f76eb 100644 --- a/src/test/java/de/caritas/cob/userservice/api/controller/UserControllerIT.java +++ b/src/test/java/de/caritas/cob/userservice/api/controller/UserControllerIT.java @@ -170,7 +170,7 @@ import de.caritas.cob.userservice.api.service.KeycloakService; import de.caritas.cob.userservice.api.service.LogService; import de.caritas.cob.userservice.api.service.MonitoringService; -import de.caritas.cob.userservice.api.service.RocketChatService; +import de.caritas.cob.userservice.api.service.rocketchat.RocketChatService; import de.caritas.cob.userservice.api.service.SessionService; import de.caritas.cob.userservice.api.service.ValidatedUserAccountProvider; import java.util.ArrayList; @@ -212,7 +212,7 @@ public class UserControllerIT { private final String VALID_ENQUIRY_MESSAGE_BODY = "{\"message\": \"" + MESSAGE + "\"}"; private final String VALID_ABSENT_MESSAGE_BODY = "{\"absent\": true, \"message\": \"" + MESSAGE + "\"}"; - private final User USER = new User(USER_ID, "username", "name@domain.de", null); + private final User USER = new User(USER_ID, null, "username", "name@domain.de", false); private final Consultant TEAM_CONSULTANT = new Consultant(CONSULTANT_ID, ROCKETCHAT_ID, "consultant", "first name", "last name", "consultant@cob.de", false, true, "", false, null, null, null, null, null, null); @@ -276,19 +276,22 @@ public class UserControllerIT { private final String ERROR = "error"; private final Session SESSION = new Session(SESSION_ID, USER, TEAM_CONSULTANT, ConsultingType.SUCHT, POSTCODE, AGENCY_ID, SessionStatus.IN_PROGRESS, new Date(), RC_GROUP_ID, - null, IS_NO_TEAM_SESSION, IS_MONITORING); + null, null, IS_NO_TEAM_SESSION, IS_MONITORING, null, null); private final Session SESSION_WITHOUT_CONSULTANT = new Session(SESSION_ID, USER, null, ConsultingType.SUCHT, POSTCODE, AGENCY_ID, - SessionStatus.NEW, new Date(), RC_GROUP_ID, null, IS_NO_TEAM_SESSION, IS_MONITORING); + SessionStatus.NEW, new Date(), RC_GROUP_ID, null, null, IS_NO_TEAM_SESSION, + IS_MONITORING, null, null); private final Optional OPTIONAL_SESSION = Optional.of(SESSION); private final Optional OPTIONAL_SESSION_WITHOUT_CONSULTANT = Optional.of(SESSION_WITHOUT_CONSULTANT); private final Session TEAM_SESSION = new Session(SESSION_ID, USER, TEAM_CONSULTANT, ConsultingType.SUCHT, POSTCODE, AGENCY_ID, - SessionStatus.IN_PROGRESS, new Date(), RC_GROUP_ID, null, IS_TEAM_SESSION, IS_MONITORING); + SessionStatus.IN_PROGRESS, new Date(), RC_GROUP_ID, null, null, IS_TEAM_SESSION, + IS_MONITORING, null, null); private final Session TEAM_SESSION_WITHOUT_GROUP_ID = new Session(SESSION_ID, USER, TEAM_CONSULTANT, ConsultingType.SUCHT, POSTCODE, AGENCY_ID, - SessionStatus.IN_PROGRESS, new Date(), null, null, IS_TEAM_SESSION, IS_MONITORING); + SessionStatus.IN_PROGRESS, new Date(), null, null, null, IS_TEAM_SESSION, IS_MONITORING, + null, null); private final Optional OPTIONAL_TEAM_SESSION = Optional.of(TEAM_SESSION); private final Optional OPTIONAL_TEAM_SESSION_WITHOUT_GROUP_ID = Optional.of(TEAM_SESSION_WITHOUT_GROUP_ID); @@ -443,7 +446,8 @@ public void registerUser_Should_ReturnBadRequest_WhenProvidedWithConsultingTypeW throws Exception { when(mandatoryFieldsProvider.fetchMandatoryFieldsForConsultingType(Mockito.anyString())) - .thenReturn(CONSULTING_TYPE_SETTINGS_WITH_MANDATORY_FIELDS.getRegistration().getMandatoryFields()); + .thenReturn( + CONSULTING_TYPE_SETTINGS_WITH_MANDATORY_FIELDS.getRegistration().getMandatoryFields()); mvc.perform(post(PATH_REGISTER_USER) .content(INVALID_U25_USER_REQUEST_BODY_STATE) @@ -487,7 +491,8 @@ public void registerUser_Should_ReturnCreated_WhenProvidedWithValidRequestBodyAn KeycloakCreateUserResponseDTO response = new KeycloakCreateUserResponseDTO(USER_ID); when(createUserFacade.createUserAndInitializeAccount(Mockito.any())).thenReturn(response); when(mandatoryFieldsProvider.fetchMandatoryFieldsForConsultingType(Mockito.anyString())) - .thenReturn(CONSULTING_TYPE_SETTINGS_WITHOUT_MANDATORY_FIELDS.getRegistration().getMandatoryFields()); + .thenReturn(CONSULTING_TYPE_SETTINGS_WITHOUT_MANDATORY_FIELDS.getRegistration() + .getMandatoryFields()); mvc.perform(post(PATH_REGISTER_USER) .content(VALID_USER_REQUEST_BODY) @@ -504,7 +509,8 @@ public void registerUser_Should_ReturnCreated_WhenProvidedWithValidU25RequestBod when(createUserFacade.createUserAndInitializeAccount(Mockito.any())) .thenReturn(response); when(mandatoryFieldsProvider.fetchMandatoryFieldsForConsultingType(Mockito.anyString())) - .thenReturn(CONSULTING_TYPE_SETTINGS_WITH_MANDATORY_FIELDS.getRegistration().getMandatoryFields()); + .thenReturn( + CONSULTING_TYPE_SETTINGS_WITH_MANDATORY_FIELDS.getRegistration().getMandatoryFields()); mvc.perform(post(PATH_REGISTER_USER) .content(VALID_U25_USER_REQUEST_BODY) @@ -521,7 +527,8 @@ public void registerUser_Should_ReturnConflict_WhenProvidedWithValidRequestBodyA when(createUserFacade.createUserAndInitializeAccount(Mockito.any())) .thenReturn(response); when(mandatoryFieldsProvider.fetchMandatoryFieldsForConsultingType(Mockito.anyString())) - .thenReturn(CONSULTING_TYPE_SETTINGS_WITHOUT_MANDATORY_FIELDS.getRegistration().getMandatoryFields()); + .thenReturn(CONSULTING_TYPE_SETTINGS_WITHOUT_MANDATORY_FIELDS.getRegistration() + .getMandatoryFields()); mvc.perform(post(PATH_REGISTER_USER) .content(VALID_USER_REQUEST_BODY) @@ -679,9 +686,9 @@ public void acceptEnquiry_Should_ReturnInternalServerError_WhenNoConsultantInDbF mvc.perform( put(PATH_ACCEPT_ENQUIRY + SESSION_ID) - .header(RC_USER_ID_HEADER_PARAMETER_NAME, RC_USER_ID) - .contentType(MediaType.APPLICATION_JSON) - .accept(MediaType.APPLICATION_JSON)) + .header(RC_USER_ID_HEADER_PARAMETER_NAME, RC_USER_ID) + .contentType(MediaType.APPLICATION_JSON) + .accept(MediaType.APPLICATION_JSON)) .andExpect(status().is(HttpStatus.INTERNAL_SERVER_ERROR.value())); verify(logger, atLeastOnce()).error(anyString(), anyString(), anyString(), anyString()); @@ -700,9 +707,9 @@ public void acceptEnquiry_Should_ReturnInternalServerError_WhenSessionNotFoundIn mvc.perform( put(PATH_ACCEPT_ENQUIRY + SESSION_ID) - .header(RC_USER_ID_HEADER_PARAMETER_NAME, RC_USER_ID) - .contentType(MediaType.APPLICATION_JSON) - .accept(MediaType.APPLICATION_JSON)) + .header(RC_USER_ID_HEADER_PARAMETER_NAME, RC_USER_ID) + .contentType(MediaType.APPLICATION_JSON) + .accept(MediaType.APPLICATION_JSON)) .andExpect(status().is(HttpStatus.INTERNAL_SERVER_ERROR.value())); verify(logger, atLeastOnce()) @@ -722,9 +729,9 @@ public void acceptEnquiry_Should_ReturnInternalServerError_WhenSessionHasNoRocke mvc.perform( put(PATH_ACCEPT_ENQUIRY + SESSION_ID) - .header(RC_USER_ID_HEADER_PARAMETER_NAME, RC_USER_ID) - .contentType(MediaType.APPLICATION_JSON) - .accept(MediaType.APPLICATION_JSON)) + .header(RC_USER_ID_HEADER_PARAMETER_NAME, RC_USER_ID) + .contentType(MediaType.APPLICATION_JSON) + .accept(MediaType.APPLICATION_JSON)) .andExpect(status().is(HttpStatus.INTERNAL_SERVER_ERROR.value())); verify(logger, atLeastOnce()) @@ -743,9 +750,9 @@ public void acceptEnquiry_Should_ReturnSuccess_WhenAcceptEnquiryIsSuccessfull() mvc.perform( put(PATH_ACCEPT_ENQUIRY + SESSION_ID) - .header(RC_USER_ID_HEADER_PARAMETER_NAME, RC_USER_ID) - .contentType(MediaType.APPLICATION_JSON) - .accept(MediaType.APPLICATION_JSON)) + .header(RC_USER_ID_HEADER_PARAMETER_NAME, RC_USER_ID) + .contentType(MediaType.APPLICATION_JSON) + .accept(MediaType.APPLICATION_JSON)) .andExpect(status().is(HttpStatus.OK.value())); } @@ -763,9 +770,9 @@ public void acceptEnquiry_Should_ReturnConflict_WhenEnquiryIsAlreadyAssigned() t mvc.perform( put(PATH_ACCEPT_ENQUIRY + SESSION_ID) - .header(RC_USER_ID_HEADER_PARAMETER_NAME, RC_USER_ID) - .contentType(MediaType.APPLICATION_JSON) - .accept(MediaType.APPLICATION_JSON)) + .header(RC_USER_ID_HEADER_PARAMETER_NAME, RC_USER_ID) + .contentType(MediaType.APPLICATION_JSON) + .accept(MediaType.APPLICATION_JSON)) .andExpect(status().is(HttpStatus.CONFLICT.value())); } @@ -799,7 +806,7 @@ public void createEnquiryMessage_Should_ReturnConflict_WhenMessageIsAlreadyCreat doThrow(new ConflictException(ERROR)) .when(createEnquiryMessageFacade) .createEnquiryMessage(Mockito.any(), Mockito.any(), - Mockito.any(), Mockito.any()); + Mockito.any(), Mockito.any()); mvc.perform(post(PATH_CREATE_ENQUIRY_MESSAGE) .header(RC_TOKEN_HEADER_PARAMETER_NAME, RC_TOKEN) @@ -849,7 +856,6 @@ public void createEnquiryMessage_Should_ReturnInternalServerError_WhenAuthentica /** * Method: getSessionsForAuthenticatedUser (role: user) - * */ @Test @@ -989,7 +995,6 @@ public void updateAbsence_Should_ReturnInternalServerError_WhenAuthenticatedUser /** * Method: getSessionsForAuthenticatedConsultant (role: consultant) - * */ @Test @@ -1139,7 +1144,6 @@ public void getSessionsForAuthenticatedConsultant_Should_ReturnNotContent_WhenFi /** * Method: getUserData (role: consultant / user) - * */ @Test @@ -1239,7 +1243,6 @@ public void getUserData_ForConsultant_Should_ReturnInternalServerError_WhenAuthe /** * Method: getTeamSessionsForAuthenticatedConsultant (role: consultant) - * */ @Test @@ -1376,9 +1379,7 @@ public void getTeamSessionsForAuthenticatedConsultant_Should_ReturnNotContent_Wh } /** - * * sendNewMessageNotification() - * */ @Test @@ -1392,12 +1393,12 @@ public void sendNewMessageNotification_Should_CallEmailNotificationFacadeAndRetu .andExpect(status().is2xxSuccessful()); verify(emailNotificationFacade, atLeastOnce()) - .sendNewMessageNotification(RC_GROUP_ID, authenticatedUser.getRoles(), authenticatedUser.getUserId()); + .sendNewMessageNotification(RC_GROUP_ID, authenticatedUser.getRoles(), + authenticatedUser.getUserId()); } /** * getMonitoring() - * */ @Test @@ -1478,7 +1479,6 @@ public void getMonitoring_Should_ReturnNoContent_WhenNoMonitoringFoundForSession /** * updateMonitoring() - * */ @Test @@ -1604,7 +1604,6 @@ public void updateMonitoring_Should_ReturnBadRequest_WhenSessionDoesNotExist() t /** * Method: getConsultants (authority: VIEW_AGENCY_CONSULTANTS) - * */ @Test @@ -1654,7 +1653,6 @@ public void getConsultants_Should_ReturnOkAndValidContent_WhenConsultantAgencySe /** * Method: assignSession (role: consultant) - * */ @Test @@ -1779,7 +1777,8 @@ public void registerUser_Should_DecodePassword() throws Exception { when(createUserFacade.createUserAndInitializeAccount(Mockito.any())) .thenReturn(response); when(mandatoryFieldsProvider.fetchMandatoryFieldsForConsultingType(Mockito.anyString())) - .thenReturn(CONSULTING_TYPE_SETTINGS_WITHOUT_MANDATORY_FIELDS.getRegistration().getMandatoryFields()); + .thenReturn(CONSULTING_TYPE_SETTINGS_WITHOUT_MANDATORY_FIELDS.getRegistration() + .getMandatoryFields()); mvc.perform(post(PATH_REGISTER_USER) .content(VALID_USER_REQUEST_BODY_WITH_ENCODED_PASSWORD) @@ -1796,7 +1795,6 @@ public void registerUser_Should_DecodePassword() throws Exception { /** * updatePassword() - * */ @Test @@ -1924,7 +1922,6 @@ public void updateKey_Should_ReturnAccepted_WhenProvidedWithNewKey() throws Exce /** * Method: createChat (role: kreuzbund-consultant) - * */ @Test @@ -1976,7 +1973,6 @@ public void createChat_Should_ReturnCreated_When_ChatWasCreated() throws Excepti /** * Method: startChat - * */ @Test public void startChat_Should_ReturnBadRequest_WhenPathParamsAreInvalid() throws Exception { @@ -2026,7 +2022,6 @@ public void startChat_Should_ReturnBadRequest_When_ChatWasNotFound() throws Exce /** * Method: getChat - * */ @Test public void getChat_Should_ReturnBadRequest_WhenPathParamsAreInvalid() throws Exception { @@ -2056,7 +2051,6 @@ public void getChat_Should_ReturnOk_When_RequestOk() throws Exception { /** * Method: joinChat - * */ @Test public void joinChat_Should_ReturnBadRequest_WhenPathParamsAreInvalid() throws Exception { @@ -2141,7 +2135,6 @@ public void stopChat_Should_ReturnOk_When_ChatWasStopped() throws Exception { /** * Method: getChat - * */ @Test public void getChatMembers_Should_ReturnBadRequest_WhenPathParamsAreInvalid() throws Exception { @@ -2172,7 +2165,6 @@ public void getChatMembers_Should_ReturnOk_When_RequestOk() throws Exception { /** * Method: updateChat - * */ @Test public void updateChat_Should_ReturnBadRequest_WhenPathParamsAreInvalid() throws Exception { @@ -2200,7 +2192,6 @@ public void updateChat_Should_ReturnOk_When_RequestOk() throws Exception { /** * Method: fetchSessionForConsultant - * */ @Test public void fetchSessionForConsultant_Should_ReturnOk_WhenRequestOk() throws Exception { diff --git a/src/test/java/de/caritas/cob/userservice/api/facade/CreateChatFacadeTest.java b/src/test/java/de/caritas/cob/userservice/api/facade/CreateChatFacadeTest.java index 1507c5c7e..9a61d97a9 100644 --- a/src/test/java/de/caritas/cob/userservice/api/facade/CreateChatFacadeTest.java +++ b/src/test/java/de/caritas/cob/userservice/api/facade/CreateChatFacadeTest.java @@ -8,8 +8,8 @@ import static de.caritas.cob.userservice.testHelper.TestConstants.GROUP_CHAT_NAME; import static de.caritas.cob.userservice.testHelper.TestConstants.RC_GROUP_ID; import static org.hamcrest.CoreMatchers.instanceOf; +import static org.hamcrest.MatcherAssert.assertThat; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThat; import static org.mockito.Mockito.atLeastOnce; import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.never; @@ -30,12 +30,12 @@ import de.caritas.cob.userservice.api.model.rocketchat.group.GroupDTO; import de.caritas.cob.userservice.api.model.rocketchat.group.GroupResponseDTO; import de.caritas.cob.userservice.api.repository.chat.Chat; -import de.caritas.cob.userservice.api.repository.chatAgency.ChatAgency; +import de.caritas.cob.userservice.api.repository.chatagency.ChatAgency; import de.caritas.cob.userservice.api.repository.consultant.Consultant; import de.caritas.cob.userservice.api.repository.session.ConsultingType; import de.caritas.cob.userservice.api.service.ChatService; import de.caritas.cob.userservice.api.service.LogService; -import de.caritas.cob.userservice.api.service.RocketChatService; +import de.caritas.cob.userservice.api.service.rocketchat.RocketChatService; import java.util.Optional; import org.junit.Before; import org.junit.Test; diff --git a/src/test/java/de/caritas/cob/userservice/api/facade/CreateEnquiryMessageFacadeTest.java b/src/test/java/de/caritas/cob/userservice/api/facade/CreateEnquiryMessageFacadeTest.java index 3bbcebf37..b71888ee6 100644 --- a/src/test/java/de/caritas/cob/userservice/api/facade/CreateEnquiryMessageFacadeTest.java +++ b/src/test/java/de/caritas/cob/userservice/api/facade/CreateEnquiryMessageFacadeTest.java @@ -1,5 +1,6 @@ package de.caritas.cob.userservice.api.facade; +import static de.caritas.cob.userservice.localdatetime.CustomLocalDateTime.nowInUtc; import static de.caritas.cob.userservice.testHelper.ExceptionConstants.INTERNAL_SERVER_ERROR_EXCEPTION; import static de.caritas.cob.userservice.testHelper.ExceptionConstants.RC_ADD_USER_TO_GROUP_EXCEPTION; import static de.caritas.cob.userservice.testHelper.ExceptionConstants.RC_CHAT_REMOVE_SYSTEM_MESSAGES_EXCEPTION; @@ -64,7 +65,7 @@ import de.caritas.cob.userservice.api.model.rocketchat.group.GroupResponseDTO; import de.caritas.cob.userservice.api.model.rocketchat.user.UserInfoResponseDTO; import de.caritas.cob.userservice.api.repository.consultant.Consultant; -import de.caritas.cob.userservice.api.repository.consultantAgency.ConsultantAgency; +import de.caritas.cob.userservice.api.repository.consultantagency.ConsultantAgency; import de.caritas.cob.userservice.api.repository.session.ConsultingType; import de.caritas.cob.userservice.api.repository.session.Session; import de.caritas.cob.userservice.api.repository.session.SessionStatus; @@ -72,7 +73,7 @@ import de.caritas.cob.userservice.api.service.ConsultantAgencyService; import de.caritas.cob.userservice.api.service.LogService; import de.caritas.cob.userservice.api.service.MonitoringService; -import de.caritas.cob.userservice.api.service.RocketChatService; +import de.caritas.cob.userservice.api.service.rocketchat.RocketChatService; import de.caritas.cob.userservice.api.service.SessionService; import de.caritas.cob.userservice.api.service.helper.KeycloakAdminClientService; import de.caritas.cob.userservice.api.service.helper.MessageServiceHelper; @@ -104,11 +105,13 @@ public class CreateEnquiryMessageFacadeTest { private final GroupResponseDTO FEEDBACK_GROUP_RESPONSE_DTO_2 = new GroupResponseDTO(FEEDBACK_GROUP_DTO_2, true, null, null); private final Session SESSION_WITHOUT_ENQUIRY_MESSAGE = new Session(1L, USER, CONSULTANT, - ConsultingType.SUCHT, "99999", AGENCY_ID, SessionStatus.INITIAL, null, null); + ConsultingType.SUCHT, "99999", AGENCY_ID, SessionStatus.INITIAL, null, null, null, null, + false, false, null, null); private final Session SESSION_WITH_ENQUIRY_MESSAGE = new Session(1L, USER, CONSULTANT, - ConsultingType.SUCHT, "99999", AGENCY_ID, SessionStatus.INITIAL, new Date(), null); + ConsultingType.SUCHT, "99999", AGENCY_ID, SessionStatus.INITIAL, new Date(), null, null, null, + false, false, null, null); private final ConsultantAgency CONSULTANT_AGENCY = - new ConsultantAgency(1L, CONSULTANT, AGENCY_ID, LocalDateTime.now(), LocalDateTime.now()); + new ConsultantAgency(1L, CONSULTANT, AGENCY_ID, nowInUtc(), nowInUtc(), nowInUtc()); private final List CONSULTANT_AGENCY_LIST = Collections .singletonList(CONSULTANT_AGENCY); private final String FIELD_NAME_ROCKET_CHAT_SYSTEM_USER_ID = "rocketChatSystemUserId"; diff --git a/src/test/java/de/caritas/cob/userservice/api/facade/CreateUserChatRelationFacadeTest.java b/src/test/java/de/caritas/cob/userservice/api/facade/CreateUserChatRelationFacadeTest.java index 54567ff64..7a1d6b68b 100644 --- a/src/test/java/de/caritas/cob/userservice/api/facade/CreateUserChatRelationFacadeTest.java +++ b/src/test/java/de/caritas/cob/userservice/api/facade/CreateUserChatRelationFacadeTest.java @@ -21,8 +21,8 @@ import de.caritas.cob.userservice.api.helper.UserHelper; import de.caritas.cob.userservice.api.model.registration.UserDTO; import de.caritas.cob.userservice.api.repository.user.User; -import de.caritas.cob.userservice.api.repository.userAgency.UserAgency; -import de.caritas.cob.userservice.api.service.RocketChatService; +import de.caritas.cob.userservice.api.repository.useragency.UserAgency; +import de.caritas.cob.userservice.api.service.rocketchat.RocketChatService; import de.caritas.cob.userservice.api.service.UserAgencyService; import de.caritas.cob.userservice.api.service.UserService; import java.util.Collections; diff --git a/src/test/java/de/caritas/cob/userservice/api/facade/EmailNotificationFacadeTest.java b/src/test/java/de/caritas/cob/userservice/api/facade/EmailNotificationFacadeTest.java index f987a31cd..b5e9d8f4e 100644 --- a/src/test/java/de/caritas/cob/userservice/api/facade/EmailNotificationFacadeTest.java +++ b/src/test/java/de/caritas/cob/userservice/api/facade/EmailNotificationFacadeTest.java @@ -1,5 +1,6 @@ package de.caritas.cob.userservice.api.facade; +import static de.caritas.cob.userservice.localdatetime.CustomLocalDateTime.nowInUtc; import static de.caritas.cob.userservice.testHelper.FieldConstants.FIELD_NAME_EMAIL_DUMMY_SUFFIX; import static de.caritas.cob.userservice.testHelper.FieldConstants.FIELD_NAME_ROCKET_CHAT_SYSTEM_USER_ID; import static de.caritas.cob.userservice.testHelper.FieldConstants.FIELD_VALUE_EMAIL_DUMMY_SUFFIX; @@ -36,7 +37,7 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.verifyZeroInteractions; +import static org.mockito.Mockito.verifyNoInteractions; import static org.mockito.Mockito.when; import static org.powermock.reflect.Whitebox.setInternalState; @@ -56,8 +57,8 @@ import de.caritas.cob.userservice.api.model.mailservice.MailsDTO; import de.caritas.cob.userservice.api.model.rocketchat.group.GroupMemberDTO; import de.caritas.cob.userservice.api.repository.consultant.Consultant; -import de.caritas.cob.userservice.api.repository.consultantAgency.ConsultantAgency; -import de.caritas.cob.userservice.api.repository.consultantAgency.ConsultantAgencyRepository; +import de.caritas.cob.userservice.api.repository.consultantagency.ConsultantAgency; +import de.caritas.cob.userservice.api.repository.consultantagency.ConsultantAgencyRepository; import de.caritas.cob.userservice.api.repository.session.ConsultingType; import de.caritas.cob.userservice.api.repository.session.Session; import de.caritas.cob.userservice.api.repository.session.SessionStatus; @@ -65,7 +66,7 @@ import de.caritas.cob.userservice.api.service.ConsultantAgencyService; import de.caritas.cob.userservice.api.service.ConsultantService; import de.caritas.cob.userservice.api.service.LogService; -import de.caritas.cob.userservice.api.service.RocketChatService; +import de.caritas.cob.userservice.api.service.rocketchat.RocketChatService; import de.caritas.cob.userservice.api.service.SessionService; import de.caritas.cob.userservice.api.service.helper.AgencyServiceHelper; import de.caritas.cob.userservice.api.service.helper.MailServiceHelper; @@ -94,7 +95,8 @@ public class EmailNotificationFacadeTest { new Consultant(CONSULTANT_ID, "XXX", USERNAME_CONSULTANT_ENCODED, "consultant", "consultant", "consultant@domain.de", false, false, null, false, 1L, null, null, null, null, null); private final Consultant CONSULTANT_WITHOUT_MAIL = new Consultant(CONSULTANT_ID, "XXX", - "consultant", "consultant", "consultant", "", false, false, null, false, 1L, null, null, null, null, null); + "consultant", "consultant", "consultant", "", false, false, null, false, 1L, null, null, null, + null, null); private final Consultant CONSULTANT2 = new Consultant(CONSULTANT_ID_2, "XXX", "consultant2", "consultant2", "consultant2", "consultant2@domain.de", false, false, null, false, 1L, null, null, null, null, null); @@ -106,31 +108,30 @@ public class EmailNotificationFacadeTest { private final Consultant ABSENT_CONSULTANT = new Consultant("XXX", "XXX", "consultant", "consultant", "consultant", "consultant@domain.de", true, false, null, false, 1L, null, null, null, null, null); - private final User USER = new User(USER_ID, USERNAME_ENCODED, "email@email.de", null); - private final User USER_NO_EMAIL = new User(USER_ID, "username", "", null); + private final User USER = new User(USER_ID, null, USERNAME_ENCODED, "email@email.de", false); + private final User USER_NO_EMAIL = new User(USER_ID, null, "username", "", false); private final ConsultantAgency CONSULTANT_AGENCY = - new ConsultantAgency(1L, CONSULTANT, AGENCY_ID, LocalDateTime.now(), LocalDateTime.now()); + new ConsultantAgency(1L, CONSULTANT, AGENCY_ID, nowInUtc(), nowInUtc(), nowInUtc()); private final ConsultantAgency CONSULTANT_AGENCY_2 = - new ConsultantAgency(1L, CONSULTANT2, AGENCY_ID, LocalDateTime.now(), LocalDateTime.now()); + new ConsultantAgency(1L, CONSULTANT2, AGENCY_ID, nowInUtc(), nowInUtc(), nowInUtc()); private final ConsultantAgency ABSENT_CONSULTANT_AGENCY = - new ConsultantAgency(1L, ABSENT_CONSULTANT, AGENCY_ID, LocalDateTime.now(), - LocalDateTime.now()); + new ConsultantAgency(1L, ABSENT_CONSULTANT, AGENCY_ID, nowInUtc(), nowInUtc(), nowInUtc()); private final Session SESSION = - new Session(1L, USER, CONSULTANT, ConsultingType.SUCHT, "88045", AGENCY_ID, - SessionStatus.INITIAL, - new Date(), RC_GROUP_ID, null, IS_NO_TEAM_SESSION, IS_MONITORING); + new Session(1L, USER, CONSULTANT, ConsultingType.SUCHT, "88045", AGENCY_ID, SessionStatus.INITIAL, + new Date(), RC_GROUP_ID, null, null, IS_NO_TEAM_SESSION, IS_MONITORING, null, null); private final Session SESSION_WITHOUT_CONSULTANT = new Session(1L, USER, null, ConsultingType.SUCHT, "88045", AGENCY_ID, SessionStatus.NEW, - new Date(), RC_GROUP_ID, null, IS_NO_TEAM_SESSION, IS_MONITORING); + new Date(), RC_GROUP_ID, null, null, IS_NO_TEAM_SESSION, IS_MONITORING, null, null); private final Session SESSION_IN_PROGRESS = new Session(1L, USER, CONSULTANT, ConsultingType.SUCHT, "88045", AGENCY_ID, SessionStatus.IN_PROGRESS, new Date(), RC_GROUP_ID, - null, IS_NO_TEAM_SESSION, IS_MONITORING); + null, null, IS_NO_TEAM_SESSION, IS_MONITORING, null, null); private final Session SESSION_IN_PROGRESS_NO_EMAIL = new Session(1L, USER_NO_EMAIL, CONSULTANT_NO_EMAIL, ConsultingType.SUCHT, "88045", AGENCY_ID, SessionStatus.IN_PROGRESS, - new Date(), RC_GROUP_ID, null, IS_NO_TEAM_SESSION, IS_MONITORING); + new Date(), RC_GROUP_ID, null, null, IS_NO_TEAM_SESSION, IS_MONITORING, null, null); private final Session TEAM_SESSION = new Session(1L, USER, CONSULTANT, ConsultingType.SUCHT, "12345", AGENCY_ID, - SessionStatus.IN_PROGRESS, new Date(), RC_GROUP_ID, null, IS_TEAM_SESSION, IS_MONITORING); + SessionStatus.IN_PROGRESS, new Date(), RC_GROUP_ID, null, null, IS_TEAM_SESSION, + IS_MONITORING, null, null); private final AgencyDTO AGENCY_DTO = new AgencyDTO() .id(AGENCY_ID) .name(AGENCY_NAME) @@ -581,7 +582,7 @@ public void sendNewMessageNotification_ShouldNot_LogError_When_SessionStatusIsNe emailNotificationFacade.sendNewMessageNotification(RC_GROUP_ID, USER_ROLES, USER_ID); - verifyZeroInteractions(logger); + verifyNoInteractions(logger); } @Test diff --git a/src/test/java/de/caritas/cob/userservice/api/facade/GetChatMembersFacadeTest.java b/src/test/java/de/caritas/cob/userservice/api/facade/GetChatMembersFacadeTest.java index 8f1dcce57..b9b0a008a 100644 --- a/src/test/java/de/caritas/cob/userservice/api/facade/GetChatMembersFacadeTest.java +++ b/src/test/java/de/caritas/cob/userservice/api/facade/GetChatMembersFacadeTest.java @@ -25,7 +25,7 @@ import de.caritas.cob.userservice.api.repository.user.User; import de.caritas.cob.userservice.api.service.ChatService; import de.caritas.cob.userservice.api.service.ConsultantService; -import de.caritas.cob.userservice.api.service.RocketChatService; +import de.caritas.cob.userservice.api.service.rocketchat.RocketChatService; import de.caritas.cob.userservice.api.service.UserService; import java.util.Optional; import org.junit.Test; diff --git a/src/test/java/de/caritas/cob/userservice/api/facade/JoinAndLeaveChatFacadeTest.java b/src/test/java/de/caritas/cob/userservice/api/facade/JoinAndLeaveChatFacadeTest.java index bcc9e9d23..b7320d608 100644 --- a/src/test/java/de/caritas/cob/userservice/api/facade/JoinAndLeaveChatFacadeTest.java +++ b/src/test/java/de/caritas/cob/userservice/api/facade/JoinAndLeaveChatFacadeTest.java @@ -32,7 +32,7 @@ import de.caritas.cob.userservice.api.repository.user.User; import de.caritas.cob.userservice.api.service.ChatService; import de.caritas.cob.userservice.api.service.ConsultantService; -import de.caritas.cob.userservice.api.service.RocketChatService; +import de.caritas.cob.userservice.api.service.rocketchat.RocketChatService; import de.caritas.cob.userservice.api.service.UserService; @RunWith(MockitoJUnitRunner.class) diff --git a/src/test/java/de/caritas/cob/userservice/api/facade/StartChatFacadeTest.java b/src/test/java/de/caritas/cob/userservice/api/facade/StartChatFacadeTest.java index 3221e15dd..b13858dbd 100644 --- a/src/test/java/de/caritas/cob/userservice/api/facade/StartChatFacadeTest.java +++ b/src/test/java/de/caritas/cob/userservice/api/facade/StartChatFacadeTest.java @@ -23,7 +23,7 @@ import de.caritas.cob.userservice.api.helper.ChatHelper; import de.caritas.cob.userservice.api.repository.chat.Chat; import de.caritas.cob.userservice.api.service.ChatService; -import de.caritas.cob.userservice.api.service.RocketChatService; +import de.caritas.cob.userservice.api.service.rocketchat.RocketChatService; @RunWith(MockitoJUnitRunner.class) public class StartChatFacadeTest { diff --git a/src/test/java/de/caritas/cob/userservice/api/facade/StopChatFacadeTest.java b/src/test/java/de/caritas/cob/userservice/api/facade/StopChatFacadeTest.java index d414ec2fe..5fd9ea39f 100644 --- a/src/test/java/de/caritas/cob/userservice/api/facade/StopChatFacadeTest.java +++ b/src/test/java/de/caritas/cob/userservice/api/facade/StopChatFacadeTest.java @@ -1,12 +1,13 @@ package de.caritas.cob.userservice.api.facade; +import static de.caritas.cob.userservice.api.repository.session.ConsultingType.KREUZBUND; +import static de.caritas.cob.userservice.localdatetime.CustomLocalDateTime.nowInUtc; import static de.caritas.cob.userservice.testHelper.FieldConstants.FIELD_NAME_WEEKLY_PLUS; import static de.caritas.cob.userservice.testHelper.FieldConstants.FIELD_VALUE_WEEKLY_PLUS; import static de.caritas.cob.userservice.testHelper.TestConstants.ACTIVE_CHAT; import static de.caritas.cob.userservice.testHelper.TestConstants.CHAT_INTERVAL_WEEKLY; import static de.caritas.cob.userservice.testHelper.TestConstants.CHAT_START_DATETIME; import static de.caritas.cob.userservice.testHelper.TestConstants.CONSULTANT; -import static de.caritas.cob.userservice.testHelper.TestConstants.IS_ACTIVE; import static de.caritas.cob.userservice.testHelper.TestConstants.IS_REPETITIVE; import static de.caritas.cob.userservice.testHelper.TestConstants.RC_GROUP_ID; import static org.junit.Assert.assertEquals; @@ -24,7 +25,7 @@ import de.caritas.cob.userservice.api.helper.ChatHelper; import de.caritas.cob.userservice.api.repository.chat.Chat; import de.caritas.cob.userservice.api.service.ChatService; -import de.caritas.cob.userservice.api.service.RocketChatService; +import de.caritas.cob.userservice.api.service.rocketchat.RocketChatService; import java.time.LocalDateTime; import org.junit.Before; import org.junit.Test; @@ -173,7 +174,7 @@ public void stopChat_Should_RemoveAllMessagesAndUsersAndSetStatusAndStartDateOfC when(chat.isRepetitive()).thenReturn(true); when(chat.getChatInterval()).thenReturn(CHAT_INTERVAL_WEEKLY); when(chat.getGroupId()).thenReturn(RC_GROUP_ID); - when(chat.getStartDate()).thenReturn(LocalDateTime.now()); + when(chat.getStartDate()).thenReturn(nowInUtc()); stopChatFacade.stopChat(chat, CONSULTANT); @@ -185,11 +186,11 @@ public void stopChat_Should_RemoveAllMessagesAndUsersAndSetStatusAndStartDateOfC } @Test - public void stopChat_Should_ReturnCorrectNextStartDate_When_ChatIsRepetitive() - throws RocketChatRemoveSystemMessagesException { - - Chat chatWithDate = - new Chat(CHAT_START_DATETIME, IS_REPETITIVE, CHAT_INTERVAL_WEEKLY, IS_ACTIVE, RC_GROUP_ID); + public void stopChat_Should_ReturnCorrectNextStartDate_When_ChatIsRepetitive() { + Chat chatWithDate = new Chat("topic", KREUZBUND, CHAT_START_DATETIME, CHAT_START_DATETIME, + 1, IS_REPETITIVE, CHAT_INTERVAL_WEEKLY, CONSULTANT); + chatWithDate.setActive(true); + chatWithDate.setGroupId("groupId"); when(chatHelper.isChatAgenciesContainConsultantAgency(chatWithDate, CONSULTANT)) .thenReturn(true); diff --git a/src/test/java/de/caritas/cob/userservice/api/facade/assignsession/AssignSessionFacadeTest.java b/src/test/java/de/caritas/cob/userservice/api/facade/assignsession/AssignSessionFacadeTest.java index 29394e063..7e9f68299 100644 --- a/src/test/java/de/caritas/cob/userservice/api/facade/assignsession/AssignSessionFacadeTest.java +++ b/src/test/java/de/caritas/cob/userservice/api/facade/assignsession/AssignSessionFacadeTest.java @@ -49,10 +49,10 @@ import de.caritas.cob.userservice.api.helper.AuthenticatedUser; import de.caritas.cob.userservice.api.service.ConsultantService; import de.caritas.cob.userservice.api.service.LogService; -import de.caritas.cob.userservice.api.service.RocketChatService; +import de.caritas.cob.userservice.api.service.rocketchat.RocketChatService; import de.caritas.cob.userservice.api.service.SessionService; import de.caritas.cob.userservice.api.service.helper.KeycloakAdminClientService; -import de.caritas.cob.userservice.api.service.helper.RocketChatRollbackHelper; +import de.caritas.cob.userservice.api.service.rocketchat.RocketChatRollbackService; import java.util.Optional; import org.junit.Before; import org.junit.Test; @@ -84,7 +84,7 @@ public class AssignSessionFacadeTest { @Mock ConsultantService consultantService; @Mock - RocketChatRollbackHelper rocketChatRollbackHelper; + RocketChatRollbackService rocketChatRollbackService; @Mock LogService logService; @Mock @@ -242,7 +242,7 @@ public void assignSession_Should_ReturnInternalServerErrorAndLogErrorAndDoARollb verify(logService, times(1)).logInternalServerError(anyString(), Mockito.eq(rcAddUserEx)); - verify(rocketChatRollbackHelper, times(1)) + verify(rocketChatRollbackService, times(1)) .rollbackRemoveUsersFromRocketChatGroup(anyString(), Mockito.any()); } @@ -266,7 +266,7 @@ public void assignSession_Should_ReturnInternalServerErrorAndLogErrorAndDoARollb verify(logService, times(1)).logInternalServerError(anyString(), Mockito.eq(rcRemoveUserEx)); - verify(rocketChatRollbackHelper, times(1)) + verify(rocketChatRollbackService, times(1)) .rollbackRemoveUsersFromRocketChatGroup(anyString(), Mockito.any()); } @@ -284,7 +284,7 @@ public void assignSession_Should_ReturnInternalServerErrorAndLogErrorAndDoARollb verify(logService, times(1)).logInternalServerError(anyString(), Mockito.eq(rcaddTechUserUserEx)); - verify(rocketChatRollbackHelper, times(1)) + verify(rocketChatRollbackService, times(1)) .rollbackRemoveUsersFromRocketChatGroup(anyString(), Mockito.any()); } @@ -298,7 +298,7 @@ public void assignSession_Should_ReturnInternalServerErrorAndLogErrorAndDoARollb assignSessionFacade.assignSession(U25_SESSION_WITH_CONSULTANT, CONSULTANT_WITH_AGENCY); verify(logService, times(1)).logInternalServerError(anyString()); - verify(rocketChatRollbackHelper, times(1)) + verify(rocketChatRollbackService, times(1)) .rollbackRemoveUsersFromRocketChatGroup(anyString(), Mockito.any()); } @@ -319,7 +319,7 @@ public void assignSession_Should_ReturnInternalServerErrorAndLogErrorAndDoARollb verify(logService, times(1)).logInternalServerError(anyString(), Mockito.eq(keycloakEx)); - verify(rocketChatRollbackHelper, times(1)) + verify(rocketChatRollbackService, times(1)) .rollbackRemoveUsersFromRocketChatGroup(anyString(), Mockito.any()); } @@ -336,7 +336,7 @@ public void assignEnquiry_Should_ReturnInternalServerErrorAndLogErrorAndDoARollb verify(sessionService, times(1)).updateConsultantAndStatusForSession( FEEDBACKSESSION_WITHOUT_CONSULTANT, FEEDBACKSESSION_WITHOUT_CONSULTANT.getConsultant(), FEEDBACKSESSION_WITHOUT_CONSULTANT.getStatus()); - verify(rocketChatRollbackHelper, times(1)) + verify(rocketChatRollbackService, times(1)) .rollbackRemoveUsersFromRocketChatGroup(anyString(), Mockito.any()); } @@ -424,7 +424,7 @@ public void assignEnquiry_Should_ReturnInternalServerErrorAndLogErrorAndDoARollb verify(sessionService, times(1)).updateConsultantAndStatusForSession( U25_SESSION_WITHOUT_CONSULTANT, U25_SESSION_WITHOUT_CONSULTANT.getConsultant(), U25_SESSION_WITHOUT_CONSULTANT.getStatus()); - verify(rocketChatRollbackHelper, times(1)) + verify(rocketChatRollbackService, times(1)) .rollbackRemoveUsersFromRocketChatGroup(anyString(), Mockito.any()); } @@ -448,7 +448,7 @@ public void assignEnquiry_Should_ReturnInternalServerErrorAndLogErrorAndDoARollb verify(sessionService, times(1)).updateConsultantAndStatusForSession( U25_SESSION_WITHOUT_CONSULTANT, U25_SESSION_WITHOUT_CONSULTANT.getConsultant(), U25_SESSION_WITHOUT_CONSULTANT.getStatus()); - verify(rocketChatRollbackHelper, times(1)) + verify(rocketChatRollbackService, times(1)) .rollbackRemoveUsersFromRocketChatGroup(anyString(), Mockito.any()); } @@ -467,7 +467,7 @@ public void assignEnquiry_Should_ReturnInternalServerErrorAndDoARollback_WhenGet verify(sessionService, times(1)).updateConsultantAndStatusForSession( U25_SESSION_WITHOUT_CONSULTANT, U25_SESSION_WITHOUT_CONSULTANT.getConsultant(), U25_SESSION_WITHOUT_CONSULTANT.getStatus()); - verify(rocketChatRollbackHelper, times(1)) + verify(rocketChatRollbackService, times(1)) .rollbackRemoveUsersFromRocketChatGroup(anyString(), Mockito.any()); } @@ -504,7 +504,7 @@ public void assignEnquiry_Should_ReturnInternalServerErrorAndLogErrorAndDoARollb verify(sessionService, times(1)).updateConsultantAndStatusForSession( U25_SESSION_WITHOUT_CONSULTANT, U25_SESSION_WITHOUT_CONSULTANT.getConsultant(), U25_SESSION_WITHOUT_CONSULTANT.getStatus()); - verify(rocketChatRollbackHelper, times(1)) + verify(rocketChatRollbackService, times(1)) .rollbackRemoveUsersFromRocketChatGroup(anyString(), Mockito.any()); } @@ -523,7 +523,7 @@ public void assignEnquiry_Should_ReturnInternalServerErrorAndLogErrorAndDoARollb verify(sessionService, times(1)).updateConsultantAndStatusForSession( U25_SESSION_WITHOUT_CONSULTANT, U25_SESSION_WITHOUT_CONSULTANT.getConsultant(), U25_SESSION_WITHOUT_CONSULTANT.getStatus()); - verify(rocketChatRollbackHelper, times(1)) + verify(rocketChatRollbackService, times(1)) .rollbackRemoveUsersFromRocketChatGroup(anyString(), Mockito.any()); } @@ -542,7 +542,7 @@ public void assignEnquiry_Should_ReturnInternalServerErrorAndLogErrorAndDoARollb verify(sessionService, times(1)).updateConsultantAndStatusForSession( U25_SESSION_WITHOUT_CONSULTANT, U25_SESSION_WITHOUT_CONSULTANT.getConsultant(), U25_SESSION_WITHOUT_CONSULTANT.getStatus()); - verify(rocketChatRollbackHelper, times(1)) + verify(rocketChatRollbackService, times(1)) .rollbackRemoveUsersFromRocketChatGroup(anyString(), Mockito.any()); } diff --git a/src/test/java/de/caritas/cob/userservice/api/facade/assignsession/SessionToConsultantConditionProviderTest.java b/src/test/java/de/caritas/cob/userservice/api/facade/assignsession/SessionToConsultantConditionProviderTest.java index 43d811135..32bd1b9c5 100644 --- a/src/test/java/de/caritas/cob/userservice/api/facade/assignsession/SessionToConsultantConditionProviderTest.java +++ b/src/test/java/de/caritas/cob/userservice/api/facade/assignsession/SessionToConsultantConditionProviderTest.java @@ -1,5 +1,6 @@ package de.caritas.cob.userservice.api.facade.assignsession; +import static de.caritas.cob.userservice.localdatetime.CustomLocalDateTime.nowInUtc; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; import static org.hibernate.validator.internal.util.CollectionHelper.asSet; @@ -7,7 +8,7 @@ import static org.mockito.Mockito.when; import de.caritas.cob.userservice.api.repository.consultant.Consultant; -import de.caritas.cob.userservice.api.repository.consultantAgency.ConsultantAgency; +import de.caritas.cob.userservice.api.repository.consultantagency.ConsultantAgency; import de.caritas.cob.userservice.api.repository.session.Session; import de.caritas.cob.userservice.api.repository.session.SessionStatus; import de.caritas.cob.userservice.api.repository.user.User; @@ -207,9 +208,9 @@ public void isSessionsAgencyNotAvailableInConsultantAgencies_Should_returnTrue_W public void isSessionsAgencyNotAvailableInConsultantAgencies_Should_returnTrue_When_ConsultantAgenciesDoesNotContainSessionAgencyId() { session.setAgencyId(99L); consultant.setConsultantAgencies(asSet( - new ConsultantAgency(1L, consultant, 1L, LocalDateTime.now(), LocalDateTime.now()), - new ConsultantAgency(2L, consultant, 2L, LocalDateTime.now(), LocalDateTime.now()), - new ConsultantAgency(3L, consultant, 3L, LocalDateTime.now(), LocalDateTime.now()) + new ConsultantAgency(1L, consultant, 1L, nowInUtc(), nowInUtc(), nowInUtc()), + new ConsultantAgency(2L, consultant, 2L, nowInUtc(), nowInUtc(), nowInUtc()), + new ConsultantAgency(3L, consultant, 3L, nowInUtc(), nowInUtc(), nowInUtc()) )); boolean result = new SessionToConsultantConditionProvider(session, consultant) @@ -222,9 +223,9 @@ public void isSessionsAgencyNotAvailableInConsultantAgencies_Should_returnTrue_W public void isSessionsAgencyNotAvailableInConsultantAgencies_Should_returnFalse_When_ConsultantAgenciesContainSessionAgencyId() { session.setAgencyId(99L); consultant.setConsultantAgencies(asSet( - new ConsultantAgency(1L, consultant, 1L, LocalDateTime.now(), LocalDateTime.now()), - new ConsultantAgency(2L, consultant, 99L, LocalDateTime.now(), LocalDateTime.now()), - new ConsultantAgency(3L, consultant, 3L, LocalDateTime.now(), LocalDateTime.now()) + new ConsultantAgency(1L, consultant, 1L, nowInUtc(), nowInUtc(), nowInUtc()), + new ConsultantAgency(2L, consultant, 99L, nowInUtc(), nowInUtc(), nowInUtc()), + new ConsultantAgency(3L, consultant, 3L, nowInUtc(), nowInUtc(), nowInUtc()) )); boolean result = new SessionToConsultantConditionProvider(session, consultant) diff --git a/src/test/java/de/caritas/cob/userservice/api/facade/rollback/RollbackFacadeTest.java b/src/test/java/de/caritas/cob/userservice/api/facade/rollback/RollbackFacadeTest.java index 248e387ef..f105eb26c 100644 --- a/src/test/java/de/caritas/cob/userservice/api/facade/rollback/RollbackFacadeTest.java +++ b/src/test/java/de/caritas/cob/userservice/api/facade/rollback/RollbackFacadeTest.java @@ -7,7 +7,7 @@ import de.caritas.cob.userservice.api.repository.session.Session; import de.caritas.cob.userservice.api.repository.user.User; -import de.caritas.cob.userservice.api.repository.userAgency.UserAgency; +import de.caritas.cob.userservice.api.repository.useragency.UserAgency; import de.caritas.cob.userservice.api.service.MonitoringService; import de.caritas.cob.userservice.api.service.SessionService; import de.caritas.cob.userservice.api.service.UserAgencyService; diff --git a/src/test/java/de/caritas/cob/userservice/api/facade/sessionlist/RocketChatRoomInformationProviderTest.java b/src/test/java/de/caritas/cob/userservice/api/facade/sessionlist/RocketChatRoomInformationProviderTest.java index 17611a687..df0c498e7 100644 --- a/src/test/java/de/caritas/cob/userservice/api/facade/sessionlist/RocketChatRoomInformationProviderTest.java +++ b/src/test/java/de/caritas/cob/userservice/api/facade/sessionlist/RocketChatRoomInformationProviderTest.java @@ -24,7 +24,7 @@ import org.mockito.Mock; import org.mockito.junit.MockitoJUnitRunner; import de.caritas.cob.userservice.api.container.RocketChatRoomInformation; -import de.caritas.cob.userservice.api.service.RocketChatService; +import de.caritas.cob.userservice.api.service.rocketchat.RocketChatService; @RunWith(MockitoJUnitRunner.class) public class RocketChatRoomInformationProviderTest { diff --git a/src/test/java/de/caritas/cob/userservice/api/facade/userdata/AskerDataProviderTest.java b/src/test/java/de/caritas/cob/userservice/api/facade/userdata/AskerDataProviderTest.java index ef55dff49..19d695e6f 100644 --- a/src/test/java/de/caritas/cob/userservice/api/facade/userdata/AskerDataProviderTest.java +++ b/src/test/java/de/caritas/cob/userservice/api/facade/userdata/AskerDataProviderTest.java @@ -154,7 +154,7 @@ public void retrieveData_Should_ReturnValidData() throws AgencyServiceHelperExce .getConsultingTypes().get(String.valueOf(consultingType.getValue())); if (consultingType.getValue() == ConsultingType.SUCHT.getValue()) { assertTrue((boolean) consultingTypeEntry.get("isRegistered")); - assertEquals(AGENCY_DTO_SUCHT, (AgencyDTO) consultingTypeEntry.get("agency")); + assertEquals(AGENCY_DTO_SUCHT, consultingTypeEntry.get("agency")); assertEquals(sessionData, consultingTypeEntry.get("sessionData")); } else { assertFalse((boolean) consultingTypeEntry.get("isRegistered")); diff --git a/src/test/java/de/caritas/cob/userservice/api/facade/userdata/ConsultantDataProviderTest.java b/src/test/java/de/caritas/cob/userservice/api/facade/userdata/ConsultantDataProviderTest.java index de9e451a2..f18a71f9c 100644 --- a/src/test/java/de/caritas/cob/userservice/api/facade/userdata/ConsultantDataProviderTest.java +++ b/src/test/java/de/caritas/cob/userservice/api/facade/userdata/ConsultantDataProviderTest.java @@ -24,7 +24,7 @@ import de.caritas.cob.userservice.api.model.AgencyDTO; import de.caritas.cob.userservice.api.model.user.UserDataResponseDTO; import de.caritas.cob.userservice.api.repository.consultant.Consultant; -import de.caritas.cob.userservice.api.repository.consultantAgency.ConsultantAgency; +import de.caritas.cob.userservice.api.repository.consultantagency.ConsultantAgency; import de.caritas.cob.userservice.api.service.LogService; import de.caritas.cob.userservice.api.service.helper.AgencyServiceHelper; import java.util.List; diff --git a/src/test/java/de/caritas/cob/userservice/api/helper/AuthenticatedUserHelperTest.java b/src/test/java/de/caritas/cob/userservice/api/helper/AuthenticatedUserHelperTest.java index e38b728d1..f4a8198b0 100644 --- a/src/test/java/de/caritas/cob/userservice/api/helper/AuthenticatedUserHelperTest.java +++ b/src/test/java/de/caritas/cob/userservice/api/helper/AuthenticatedUserHelperTest.java @@ -16,17 +16,18 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import static org.mockito.Mockito.when; + +import de.caritas.cob.userservice.api.repository.consultant.Consultant; +import de.caritas.cob.userservice.api.repository.session.ConsultingType; +import de.caritas.cob.userservice.api.repository.session.Session; +import de.caritas.cob.userservice.api.repository.session.SessionStatus; +import de.caritas.cob.userservice.api.service.ConsultantAgencyService; import java.util.Date; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.junit.MockitoJUnitRunner; -import de.caritas.cob.userservice.api.repository.consultant.Consultant; -import de.caritas.cob.userservice.api.repository.session.ConsultingType; -import de.caritas.cob.userservice.api.repository.session.Session; -import de.caritas.cob.userservice.api.repository.session.SessionStatus; -import de.caritas.cob.userservice.api.service.ConsultantAgencyService; @RunWith(MockitoJUnitRunner.class) public class AuthenticatedUserHelperTest { @@ -34,18 +35,23 @@ public class AuthenticatedUserHelperTest { private final Consultant CONSULTANT = new Consultant(CONSULTANT_ID, ROCKETCHAT_ID, USERNAME, FIRST_NAME, LAST_NAME, EMAIL, false, false, null, false, null, null, null, null, null, null); private final Consultant TEAM_CONSULTANT = new Consultant(TEAM_CONSULTANT_ID, ROCKETCHAT_ID, - USERNAME, FIRST_NAME, LAST_NAME, EMAIL, false, true, null, true, null, null, null, null, null, null); + USERNAME, FIRST_NAME, LAST_NAME, EMAIL, false, true, null, true, null, null, null, null, null, + null); private final Session SESSION = new Session(SESSION_ID, null, CONSULTANT, ConsultingType.SUCHT, - POSTCODE, AGENCY_ID, SessionStatus.NEW, new Date(), null); + POSTCODE, AGENCY_ID, SessionStatus.NEW, new Date(), null, null, null, + false, false, null, null); private final Session SESSION_WITH_DIFFERENT_CONSULTANT = new Session(SESSION_ID, null, TEAM_CONSULTANT, ConsultingType.SUCHT, POSTCODE, AGENCY_ID, - SessionStatus.NEW, new Date(), null); + SessionStatus.NEW, new Date(), null, null, null, + false, false, null, null); private final Session TEAM_SESSION = new Session(TEAM_SESSION_ID, null, TEAM_CONSULTANT, ConsultingType.SUCHT, POSTCODE, AGENCY_ID, - SessionStatus.IN_PROGRESS, new Date(), null, null, IS_TEAM_SESSION, IS_MONITORING); + SessionStatus.IN_PROGRESS, new Date(), null, null, null, IS_TEAM_SESSION, IS_MONITORING, + null, null); private final Session TEAM_SESSION_WITH_DIFFERENT_CONSULTANT = new Session(TEAM_SESSION_ID, null, CONSULTANT, ConsultingType.SUCHT, POSTCODE, AGENCY_ID, - SessionStatus.IN_PROGRESS, new Date(), null, null, IS_TEAM_SESSION, IS_MONITORING); + SessionStatus.IN_PROGRESS, new Date(), null, null, null, IS_TEAM_SESSION, IS_MONITORING, + null, null); @InjectMocks private AuthenticatedUserHelper authenticatedUserHelper; diff --git a/src/test/java/de/caritas/cob/userservice/api/helper/ChatHelperTest.java b/src/test/java/de/caritas/cob/userservice/api/helper/ChatHelperTest.java index e0a784271..092f250e3 100644 --- a/src/test/java/de/caritas/cob/userservice/api/helper/ChatHelperTest.java +++ b/src/test/java/de/caritas/cob/userservice/api/helper/ChatHelperTest.java @@ -1,5 +1,6 @@ package de.caritas.cob.userservice.api.helper; +import static de.caritas.cob.userservice.localdatetime.CustomLocalDateTime.nowInUtc; import static de.caritas.cob.userservice.testHelper.TestConstants.AGENCY_ID; import static de.caritas.cob.userservice.testHelper.TestConstants.AGENCY_ID_2; import static de.caritas.cob.userservice.testHelper.TestConstants.AGENCY_ID_3; @@ -11,12 +12,12 @@ import static org.mockito.Mockito.when; import de.caritas.cob.userservice.api.repository.chat.Chat; -import de.caritas.cob.userservice.api.repository.chatAgency.ChatAgency; +import de.caritas.cob.userservice.api.repository.chatagency.ChatAgency; import de.caritas.cob.userservice.api.repository.consultant.Consultant; -import de.caritas.cob.userservice.api.repository.consultantAgency.ConsultantAgency; +import de.caritas.cob.userservice.api.repository.consultantagency.ConsultantAgency; import de.caritas.cob.userservice.api.repository.session.ConsultingType; import de.caritas.cob.userservice.api.repository.user.User; -import de.caritas.cob.userservice.api.repository.userAgency.UserAgency; +import de.caritas.cob.userservice.api.repository.useragency.UserAgency; import java.time.LocalDateTime; import java.util.Arrays; import java.util.HashSet; @@ -55,10 +56,10 @@ public void isChatAgenciesContainConsultantAgency_Should_ReturnTrue_WhenChatAgen ConsultantAgency[] consultantAgencyArray = new ConsultantAgency[]{ - new ConsultantAgency(AGENCY_ID, consultant, AGENCY_ID, LocalDateTime.now(), - LocalDateTime.now()), - new ConsultantAgency(AGENCY_ID_2, consultant, AGENCY_ID_2, LocalDateTime.now(), - LocalDateTime.now())}; + new ConsultantAgency(AGENCY_ID, consultant, AGENCY_ID, nowInUtc(), + nowInUtc(), nowInUtc()), + new ConsultantAgency(AGENCY_ID_2, consultant, AGENCY_ID_2, nowInUtc(), + nowInUtc(), nowInUtc())}; Set consultantAgencySet = new HashSet(Arrays.asList(consultantAgencyArray)); @@ -73,10 +74,10 @@ public void isChatAgenciesContainConsultantAgency_Should_ReturnFalse_WhenChatAge ConsultantAgency[] consultantAgencyArray = new ConsultantAgency[]{ - new ConsultantAgency(AGENCY_ID, consultant, AGENCY_ID, LocalDateTime.now(), - LocalDateTime.now()), - new ConsultantAgency(AGENCY_ID_3, consultant, AGENCY_ID_3, LocalDateTime.now(), - LocalDateTime.now())}; + new ConsultantAgency(AGENCY_ID, consultant, AGENCY_ID, nowInUtc(), + nowInUtc(), nowInUtc()), + new ConsultantAgency(AGENCY_ID_3, consultant, AGENCY_ID_3, nowInUtc(), + nowInUtc(), nowInUtc())}; Set consultantAgencySet = new HashSet(Arrays.asList(consultantAgencyArray)); @@ -94,7 +95,7 @@ public void isChatAgenciesContainUserAgency_Should_ReturnTrue_WhenChatAgenciesCo UserAgency[] userAgencyArray = new UserAgency[]{new UserAgency(AGENCY_ID, user, AGENCY_ID), new UserAgency(AGENCY_ID_2, user, AGENCY_ID_2)}; - Set userAgencySet = new HashSet(Arrays.asList(userAgencyArray)); + Set userAgencySet = new HashSet<>(Arrays.asList(userAgencyArray)); when(user.getUserAgencies()).thenReturn(userAgencySet); @@ -107,7 +108,7 @@ public void isChatAgenciesContainUserAgency_Should_ReturnFalse_WhenChatAgenciesN UserAgency[] userAgencyArray = new UserAgency[]{new UserAgency(AGENCY_ID, user, AGENCY_ID), new UserAgency(AGENCY_ID_3, user, AGENCY_ID_3)}; - Set userAgencySet = new HashSet(Arrays.asList(userAgencyArray)); + Set userAgencySet = new HashSet<>(Arrays.asList(userAgencyArray)); when(user.getUserAgencies()).thenReturn(userAgencySet); @@ -115,7 +116,6 @@ public void isChatAgenciesContainUserAgency_Should_ReturnFalse_WhenChatAgenciesN } - /** * Method: convertChatDTOtoChat */ diff --git a/src/test/java/de/caritas/cob/userservice/api/helper/HelperTest.java b/src/test/java/de/caritas/cob/userservice/api/helper/HelperTest.java index 749e0d7ae..61b909add 100644 --- a/src/test/java/de/caritas/cob/userservice/api/helper/HelperTest.java +++ b/src/test/java/de/caritas/cob/userservice/api/helper/HelperTest.java @@ -2,9 +2,9 @@ import static org.hamcrest.CoreMatchers.instanceOf; import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.MatcherAssert.assertThat; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertThat; import java.util.Date; import org.junit.Test; import org.junit.runner.RunWith; diff --git a/src/test/java/de/caritas/cob/userservice/api/helper/MonitoringHelperTest.java b/src/test/java/de/caritas/cob/userservice/api/helper/MonitoringHelperTest.java index c5e24ae65..166820299 100644 --- a/src/test/java/de/caritas/cob/userservice/api/helper/MonitoringHelperTest.java +++ b/src/test/java/de/caritas/cob/userservice/api/helper/MonitoringHelperTest.java @@ -15,7 +15,7 @@ import de.caritas.cob.userservice.api.model.monitoring.MonitoringDTO; import de.caritas.cob.userservice.api.repository.monitoring.Monitoring; import de.caritas.cob.userservice.api.repository.monitoring.MonitoringType; -import de.caritas.cob.userservice.api.repository.monitoringOption.MonitoringOption; +import de.caritas.cob.userservice.api.repository.monitoringoption.MonitoringOption; import de.caritas.cob.userservice.api.repository.session.ConsultingType; @RunWith(MockitoJUnitRunner.class) diff --git a/src/test/java/de/caritas/cob/userservice/api/helper/RocketChatHelperTest.java b/src/test/java/de/caritas/cob/userservice/api/helper/RocketChatHelperTest.java index d6f12d35b..e27e6c8c1 100644 --- a/src/test/java/de/caritas/cob/userservice/api/helper/RocketChatHelperTest.java +++ b/src/test/java/de/caritas/cob/userservice/api/helper/RocketChatHelperTest.java @@ -3,8 +3,9 @@ import static de.caritas.cob.userservice.testHelper.TestConstants.ACTIVE_CHAT; import static de.caritas.cob.userservice.testHelper.TestConstants.SESSION; import static org.hamcrest.CoreMatchers.startsWith; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; import static org.junit.Assert.assertTrue; + import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; diff --git a/src/test/java/de/caritas/cob/userservice/api/helper/SessionDataHelperTest.java b/src/test/java/de/caritas/cob/userservice/api/helper/SessionDataHelperTest.java index 1112b588c..1f27891a7 100644 --- a/src/test/java/de/caritas/cob/userservice/api/helper/SessionDataHelperTest.java +++ b/src/test/java/de/caritas/cob/userservice/api/helper/SessionDataHelperTest.java @@ -12,20 +12,14 @@ import static de.caritas.cob.userservice.testHelper.TestConstants.STATE; import static de.caritas.cob.userservice.testHelper.TestConstants.USERNAME; import static de.caritas.cob.userservice.testHelper.TestConstants.USER_ID; +import static java.util.Objects.nonNull; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import static org.mockito.Mockito.when; -import java.util.Arrays; -import java.util.Date; -import java.util.LinkedHashMap; -import java.util.List; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mockito; -import org.mockito.junit.MockitoJUnitRunner; + import de.caritas.cob.userservice.api.manager.consultingtype.ConsultingTypeManager; import de.caritas.cob.userservice.api.manager.consultingtype.ConsultingTypeSettings; import de.caritas.cob.userservice.api.manager.consultingtype.SessionDataInitializing; @@ -34,10 +28,19 @@ import de.caritas.cob.userservice.api.repository.session.ConsultingType; import de.caritas.cob.userservice.api.repository.session.Session; import de.caritas.cob.userservice.api.repository.session.SessionStatus; -import de.caritas.cob.userservice.api.repository.sessionData.SessionData; -import de.caritas.cob.userservice.api.repository.sessionData.SessionDataKeyRegistration; -import de.caritas.cob.userservice.api.repository.sessionData.SessionDataType; +import de.caritas.cob.userservice.api.repository.sessiondata.SessionData; +import de.caritas.cob.userservice.api.repository.sessiondata.SessionDataKeyRegistration; +import de.caritas.cob.userservice.api.repository.sessiondata.SessionDataType; import de.caritas.cob.userservice.api.repository.user.User; +import java.util.Arrays; +import java.util.Date; +import java.util.List; +import java.util.Map; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mockito; +import org.mockito.junit.MockitoJUnitRunner; @RunWith(MockitoJUnitRunner.class) public class SessionDataHelperTest { @@ -45,13 +48,16 @@ public class SessionDataHelperTest { private SessionDataHelper sessionDataHelper; private ConsultingTypeManager consultingTypeManager; - private final User USER = new User(USER_ID, USERNAME, EMAIL, null); + private final User USER = new User(USER_ID, null, USERNAME, EMAIL, false); private final Consultant CONSULTANT = new Consultant(CONSULTANT_ID, USERNAME, ROCKETCHAT_ID, - "first name", "last name", "consultant@cob.de", false, false, null, false, null, null, null, null, null, null); + "first name", "last name", "consultant@cob.de", false, false, null, false, null, null, null, + null, null, null); private final Session INITALIZED_SESSION_SUCHT = new Session(1L, USER, CONSULTANT, - ConsultingType.SUCHT, "99999", 0L, SessionStatus.INITIAL, null, null); + ConsultingType.SUCHT, "99999", 0L, SessionStatus.INITIAL, null, null, null, null, false, + false, null, null); private final Session INITALIZED_SESSION_U25 = new Session(1L, USER, CONSULTANT, - ConsultingType.U25, "99999", 0L, SessionStatus.INITIAL, null, null); + ConsultingType.U25, "99999", 0L, SessionStatus.INITIAL, null, null, null, null, false, + false, null, null); private final SessionData SESSION_DATA_ADDICTIVE_DRUGS = new SessionData(new Session(), SessionDataType.REGISTRATION, SessionDataKeyRegistration.ADDICTIVE_DRUGS.getValue(), "1"); private final SessionData SESSION_DATA_AGE = new SessionData(new Session(), @@ -61,8 +67,8 @@ public class SessionDataHelperTest { private final List SESSION_DATA = Arrays.asList(SESSION_DATA_ADDICTIVE_DRUGS, SESSION_DATA_AGE, SESSION_DATA_GENDER); private final Session INITIALIZED_SESSION_WITH_SESSION_DATA = new Session(1L, USER, CONSULTANT, - ConsultingType.SUCHT, "99999", 1L, SessionStatus.IN_PROGRESS, new Date(), null, SESSION_DATA, - IS_TEAM_SESSION, IS_MONITORING); + ConsultingType.SUCHT, "99999", 1L, SessionStatus.IN_PROGRESS, new Date(), null, + null, SESSION_DATA, IS_TEAM_SESSION, IS_MONITORING, null, null); private final UserDTO USER_DTO_WITHOUT_SESSION_DATA = new UserDTO(USERNAME, "99999", 99L, "xyz", "x@y.de", null, null, null, null, null, "true", "0", true); private final UserDTO USER_DTO_WITH_SESSION_DATA = new UserDTO(USERNAME, "99999", 99L, "xyz", @@ -102,19 +108,19 @@ public void createSessionDataList_Should_ReturnCorrectListOfSessionDataItems() { for (SessionData sessionData : result) { switch (sessionData.getKey()) { case "addictiveDrugs": - assertEquals(sessionData.getValue(), ADDICTIVE_DRUGS); + assertEquals(ADDICTIVE_DRUGS, sessionData.getValue()); break; case "age": - assertEquals(sessionData.getValue(), AGE); + assertEquals(AGE, sessionData.getValue()); break; case "gender": - assertEquals(sessionData.getValue(), GENDER); + assertEquals(GENDER, sessionData.getValue()); break; case "relation": - assertEquals(sessionData.getValue(), RELATION); + assertEquals(RELATION, sessionData.getValue()); break; case "state": - assertEquals(sessionData.getValue(), STATE); + assertEquals(STATE, sessionData.getValue()); break; default: fail("Unknown SessionData key"); @@ -147,7 +153,7 @@ public void createSessionDataList_Should_ReturnCorrectListOfSessionDataItems_Whe .createRegistrationSessionDataList(INITALIZED_SESSION_SUCHT, USER_DTO_WITHOUT_SESSION_DATA); for (SessionData sessionData : result) { - assertEquals(sessionData.getValue(), null); + assertNull(sessionData.getValue()); } } @@ -162,7 +168,7 @@ public void createSessionDataList_Should_ReturnCorrectListOfSessionDataItems_Whe INITALIZED_SESSION_SUCHT, USER_DTO_WITH_EMPTY_SESSION_DATA); for (SessionData sessionData : result) { - assertEquals(sessionData.getValue(), null); + assertNull(sessionData.getValue()); } } @@ -176,7 +182,7 @@ public void getValueOfKey_Should_ReturnCorrectValueToGivenKey() { List dataList = sessionDataHelper .createRegistrationSessionDataList(INITALIZED_SESSION_SUCHT, USER_DTO_WITH_SESSION_DATA); - assertEquals(AGE, sessionDataHelper.getValueOfKey(dataList, AGE)); + assertEquals(AGE, getValueOfKey(dataList, AGE)); } @Test @@ -188,19 +194,19 @@ public void getValueOfKey_Should_ReturnNullWhenSessionDataValueIsNull() { List dataList = sessionDataHelper .createRegistrationSessionDataList(INITALIZED_SESSION_SUCHT, USER_DTO_WITHOUT_SESSION_DATA); - assertEquals(null, sessionDataHelper.getValueOfKey(dataList, AGE)); + assertNull(getValueOfKey(dataList, AGE)); } @Test public void getValueOfKey_Should_ReturnNullWhenSessionDataListIsNull() { - assertEquals(null, sessionDataHelper.getValueOfKey(null, AGE)); + assertNull(getValueOfKey(null, AGE)); } @Test public void getSessionDataMapFromSession_Should_ReturnCorrectMapOfSessionDataItems() { - LinkedHashMap result = + Map result = sessionDataHelper.getSessionDataMapFromSession(INITIALIZED_SESSION_WITH_SESSION_DATA); assertEquals(result.get(SESSION_DATA_ADDICTIVE_DRUGS.getKey()), @@ -217,4 +223,20 @@ public void getSessionDataMapFromSession_Should_ReturnCorrectMapOfSessionDataIte } + private String getValueOfKey(List sessionDataList, String key) { + + if (nonNull(sessionDataList)) { + SessionData sessionData = sessionDataList.stream() + .filter(data -> key.equals(data.getKey())) + .findAny() + .orElse(null); + + if (nonNull(sessionData)) { + return sessionData.getValue(); + } + } + + return null; + } + } diff --git a/src/test/java/de/caritas/cob/userservice/api/repository/chat/ChatTest.java b/src/test/java/de/caritas/cob/userservice/api/repository/chat/ChatTest.java new file mode 100644 index 000000000..89e1f4da3 --- /dev/null +++ b/src/test/java/de/caritas/cob/userservice/api/repository/chat/ChatTest.java @@ -0,0 +1,51 @@ +package de.caritas.cob.userservice.api.repository.chat; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.is; + +import org.jeasy.random.EasyRandom; +import org.junit.Test; + +public class ChatTest { + + @Test + public void equals_Should_returnTrue_When_objectIsSameReference() { + Chat chat = new EasyRandom().nextObject(Chat.class); + + assertThat(chat, is(chat)); + } + + @Test + public void equals_Should_returnFalse_When_objectIsNoChatInstance() { + Chat chat = new EasyRandom().nextObject(Chat.class); + + boolean equals = chat.equals(new Object()); + + assertThat(equals, is(false)); + } + + @Test + public void equals_Should_returnFalse_When_sessionIdsAreDifferent() { + Chat chat = new EasyRandom().nextObject(Chat.class); + chat.setId(1L); + Chat otherChat = new EasyRandom().nextObject(Chat.class); + otherChat.setId(2L); + + boolean equals = chat.equals(otherChat); + + assertThat(equals, is(false)); + } + + @Test + public void equals_Should_returnTrue_When_sessionIdsAreEqual() { + Chat chat = new EasyRandom().nextObject(Chat.class); + chat.setId(1L); + Chat otherChat = new EasyRandom().nextObject(Chat.class); + otherChat.setId(1L); + + boolean equals = chat.equals(otherChat); + + assertThat(equals, is(true)); + } + +} diff --git a/src/test/java/de/caritas/cob/userservice/api/repository/chatagency/ChatAgencyTest.java b/src/test/java/de/caritas/cob/userservice/api/repository/chatagency/ChatAgencyTest.java new file mode 100644 index 000000000..aacc4c729 --- /dev/null +++ b/src/test/java/de/caritas/cob/userservice/api/repository/chatagency/ChatAgencyTest.java @@ -0,0 +1,51 @@ +package de.caritas.cob.userservice.api.repository.chatagency; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.is; + +import org.jeasy.random.EasyRandom; +import org.junit.Test; + +public class ChatAgencyTest { + + @Test + public void equals_Should_returnTrue_When_objectIsSameReference() { + ChatAgency chatAgency = new EasyRandom().nextObject(ChatAgency.class); + + assertThat(chatAgency, is(chatAgency)); + } + + @Test + public void equals_Should_returnFalse_When_objectIsNoChatAgencyInstance() { + ChatAgency chatAgency = new EasyRandom().nextObject(ChatAgency.class); + + boolean equals = chatAgency.equals(new Object()); + + assertThat(equals, is(false)); + } + + @Test + public void equals_Should_returnFalse_When_sessionIdsAreDifferent() { + ChatAgency chatAgency = new EasyRandom().nextObject(ChatAgency.class); + chatAgency.setId(1L); + ChatAgency otherChatAgency = new EasyRandom().nextObject(ChatAgency.class); + otherChatAgency.setId(2L); + + boolean equals = chatAgency.equals(otherChatAgency); + + assertThat(equals, is(false)); + } + + @Test + public void equals_Should_returnTrue_When_sessionIdsAreEqual() { + ChatAgency chatAgency = new EasyRandom().nextObject(ChatAgency.class); + chatAgency.setId(1L); + ChatAgency otherChatAgency = new EasyRandom().nextObject(ChatAgency.class); + otherChatAgency.setId(1L); + + boolean equals = chatAgency.equals(otherChatAgency); + + assertThat(equals, is(true)); + } + +} diff --git a/src/test/java/de/caritas/cob/userservice/api/repository/consultant/ConsultantTest.java b/src/test/java/de/caritas/cob/userservice/api/repository/consultant/ConsultantTest.java index 03dcd4d96..00613d7cc 100644 --- a/src/test/java/de/caritas/cob/userservice/api/repository/consultant/ConsultantTest.java +++ b/src/test/java/de/caritas/cob/userservice/api/repository/consultant/ConsultantTest.java @@ -1,6 +1,10 @@ package de.caritas.cob.userservice.api.repository.consultant; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.is; import static org.junit.Assert.assertEquals; + +import org.jeasy.random.EasyRandom; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.junit.MockitoJUnitRunner; @@ -8,20 +12,57 @@ @RunWith(MockitoJUnitRunner.class) public class ConsultantTest { - private final String CONSULTANT_ID = "yyy"; - - private final String FIRSTNAME = "firstname"; - private final String LASTNAME = "lastname"; - private final String FULL_NAME = FIRSTNAME + " " + LASTNAME; - private final Consultant CONSULTANT = new Consultant(CONSULTANT_ID, "XXX", "consultant", + private static final String FIRSTNAME = "firstname"; + private static final String LASTNAME = "lastname"; + private static final Consultant CONSULTANT = new Consultant("yyy", "XXX", "consultant", FIRSTNAME, LASTNAME, "consultant@domain.de", false, false, null, false, 1L, null, null, null, null, null); @Test public void getFullName_Should_Return_FirstnameAndLastname() { - String result = CONSULTANT.getFullName(); - assertEquals(FULL_NAME, result); + String expectedFullName = FIRSTNAME + " " + LASTNAME; + + assertEquals(expectedFullName, result); + } + + @Test + public void equals_Should_returnTrue_When_objectIsSameReference() { + Consultant consultant = new EasyRandom().nextObject(Consultant.class); + + assertThat(consultant, is(consultant)); + } + + @Test + public void equals_Should_returnFalse_When_objectIsNoConsultantInstance() { + Consultant consultant = new EasyRandom().nextObject(Consultant.class); + + boolean equals = consultant.equals(new Object()); + + assertThat(equals, is(false)); + } + + @Test + public void equals_Should_returnFalse_When_consultantIdsAreDifferent() { + Consultant consultant = new EasyRandom().nextObject(Consultant.class); + consultant.setId("1"); + Consultant otherConsultant = new EasyRandom().nextObject(Consultant.class); + otherConsultant.setId("2"); + + boolean equals = consultant.equals(otherConsultant); + + assertThat(equals, is(false)); + } + + @Test + public void equals_Should_returnTrue_When_consultantIdsAreEqual() { + Consultant consultant = new EasyRandom().nextObject(Consultant.class); + consultant.setId("1"); + Consultant otherConsultant = new EasyRandom().nextObject(Consultant.class); + otherConsultant.setId("1"); + + boolean equals = consultant.equals(otherConsultant); + assertThat(equals, is(true)); } } diff --git a/src/test/java/de/caritas/cob/userservice/api/repository/consultantagency/ConsultantAgencyTest.java b/src/test/java/de/caritas/cob/userservice/api/repository/consultantagency/ConsultantAgencyTest.java new file mode 100644 index 000000000..2f344fbe7 --- /dev/null +++ b/src/test/java/de/caritas/cob/userservice/api/repository/consultantagency/ConsultantAgencyTest.java @@ -0,0 +1,51 @@ +package de.caritas.cob.userservice.api.repository.consultantagency; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.is; + +import org.jeasy.random.EasyRandom; +import org.junit.Test; + +public class ConsultantAgencyTest { + + @Test + public void equals_Should_returnTrue_When_objectIsSameReference() { + ConsultantAgency consultantAgency = new EasyRandom().nextObject(ConsultantAgency.class); + + assertThat(consultantAgency, is(consultantAgency)); + } + + @Test + public void equals_Should_returnFalse_When_objectIsNoConsultantAgencyInstance() { + ConsultantAgency consultantAgency = new EasyRandom().nextObject(ConsultantAgency.class); + + boolean equals = consultantAgency.equals(new Object()); + + assertThat(equals, is(false)); + } + + @Test + public void equals_Should_returnFalse_When_consultantAgencyIdsAreDifferent() { + ConsultantAgency consultantAgency = new EasyRandom().nextObject(ConsultantAgency.class); + consultantAgency.setId(1L); + ConsultantAgency otherConsultantAgency = new EasyRandom().nextObject(ConsultantAgency.class); + otherConsultantAgency.setId(2L); + + boolean equals = consultantAgency.equals(otherConsultantAgency); + + assertThat(equals, is(false)); + } + + @Test + public void equals_Should_returnTrue_When_consultantAgencyIdsAreEqual() { + ConsultantAgency consultantAgency = new EasyRandom().nextObject(ConsultantAgency.class); + consultantAgency.setId(1L); + ConsultantAgency otherConsultantAgency = new EasyRandom().nextObject(ConsultantAgency.class); + otherConsultantAgency.setId(1L); + + boolean equals = consultantAgency.equals(otherConsultantAgency); + + assertThat(equals, is(true)); + } + +} diff --git a/src/test/java/de/caritas/cob/userservice/api/repository/monitoring/MonitoringTest.java b/src/test/java/de/caritas/cob/userservice/api/repository/monitoring/MonitoringTest.java new file mode 100644 index 000000000..c915c0cb7 --- /dev/null +++ b/src/test/java/de/caritas/cob/userservice/api/repository/monitoring/MonitoringTest.java @@ -0,0 +1,76 @@ +package de.caritas.cob.userservice.api.repository.monitoring; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.is; + +import org.jeasy.random.EasyRandom; +import org.junit.Test; + +public class MonitoringTest { + + @Test + public void equals_Should_returnTrue_When_objectIsSameReference() { + Monitoring monitoring = new EasyRandom().nextObject(Monitoring.class); + + assertThat(monitoring, is(monitoring)); + } + + @Test + public void equals_Should_returnFalse_When_objectIsNoMonitoringInstance() { + Monitoring monitoring = new EasyRandom().nextObject(Monitoring.class); + + boolean equals = monitoring.equals(new Object()); + + assertThat(equals, is(false)); + } + + @Test + public void equals_Should_returnFalse_When_monitoringSessionIdsAreDifferent() { + Monitoring monitoring = new EasyRandom().nextObject(Monitoring.class); + monitoring.setSessionId(1L); + Monitoring otherMonitoring = new EasyRandom().nextObject(Monitoring.class); + otherMonitoring.setSessionId(2L); + + boolean equals = monitoring.equals(otherMonitoring); + + assertThat(equals, is(false)); + } + + @Test + public void equals_Should_returnFalse_When_monitoringTypesAreDifferent() { + Monitoring monitoring = new EasyRandom().nextObject(Monitoring.class); + monitoring.setMonitoringType(MonitoringType.ADDICTIVE_DRUGS); + Monitoring otherMonitoring = new EasyRandom().nextObject(Monitoring.class); + otherMonitoring.setMonitoringType(MonitoringType.INTERVENTION); + + boolean equals = monitoring.equals(otherMonitoring); + + assertThat(equals, is(false)); + } + + @Test + public void equals_Should_returnFalse_When_monitoringKeysAreDifferent() { + Monitoring monitoring = new EasyRandom().nextObject(Monitoring.class); + monitoring.setKey("Key"); + Monitoring otherMonitoring = new EasyRandom().nextObject(Monitoring.class); + otherMonitoring.setKey("Other Key"); + + boolean equals = monitoring.equals(otherMonitoring); + + assertThat(equals, is(false)); + } + + @Test + public void equals_Should_returnTrue_When_sessionIdAndMonitoringTypeAndKeyIsEqual() { + Monitoring monitoring = new EasyRandom().nextObject(Monitoring.class); + Monitoring otherMonitoring = new EasyRandom().nextObject(Monitoring.class); + otherMonitoring.setSessionId(monitoring.getSessionId()); + otherMonitoring.setMonitoringType(monitoring.getMonitoringType()); + otherMonitoring.setKey(monitoring.getKey()); + + boolean equals = monitoring.equals(otherMonitoring); + + assertThat(equals, is(true)); + } + +} diff --git a/src/test/java/de/caritas/cob/userservice/api/repository/monitoringoption/MonitoringOptionTest.java b/src/test/java/de/caritas/cob/userservice/api/repository/monitoringoption/MonitoringOptionTest.java new file mode 100644 index 000000000..a466c65a1 --- /dev/null +++ b/src/test/java/de/caritas/cob/userservice/api/repository/monitoringoption/MonitoringOptionTest.java @@ -0,0 +1,90 @@ +package de.caritas.cob.userservice.api.repository.monitoringoption; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.is; + +import de.caritas.cob.userservice.api.repository.monitoring.MonitoringType; +import org.jeasy.random.EasyRandom; +import org.junit.Test; + +public class MonitoringOptionTest { + + @Test + public void equals_Should_returnTrue_When_objectIsSameReference() { + MonitoringOption monitoring = new EasyRandom().nextObject(MonitoringOption.class); + + assertThat(monitoring, is(monitoring)); + } + + @Test + public void equals_Should_returnFalse_When_objectIsNoMonitoringInstance() { + MonitoringOption monitoring = new EasyRandom().nextObject(MonitoringOption.class); + + boolean equals = monitoring.equals(new Object()); + + assertThat(equals, is(false)); + } + + @Test + public void equals_Should_returnFalse_When_monitoringSessionIdsAreDifferent() { + MonitoringOption monitoring = new EasyRandom().nextObject(MonitoringOption.class); + monitoring.setSessionId(1L); + MonitoringOption otherMonitoring = new EasyRandom().nextObject(MonitoringOption.class); + otherMonitoring.setSessionId(2L); + + boolean equals = monitoring.equals(otherMonitoring); + + assertThat(equals, is(false)); + } + + @Test + public void equals_Should_returnFalse_When_monitoringTypesAreDifferent() { + MonitoringOption monitoring = new EasyRandom().nextObject(MonitoringOption.class); + monitoring.setMonitoringType(MonitoringType.ADDICTIVE_DRUGS); + MonitoringOption otherMonitoring = new EasyRandom().nextObject(MonitoringOption.class); + otherMonitoring.setMonitoringType(MonitoringType.INTERVENTION); + + boolean equals = monitoring.equals(otherMonitoring); + + assertThat(equals, is(false)); + } + + @Test + public void equals_Should_returnFalse_When_monitoringKeysAreDifferent() { + MonitoringOption monitoring = new EasyRandom().nextObject(MonitoringOption.class); + monitoring.setKey("Key"); + MonitoringOption otherMonitoring = new EasyRandom().nextObject(MonitoringOption.class); + otherMonitoring.setKey("Other Key"); + + boolean equals = monitoring.equals(otherMonitoring); + + assertThat(equals, is(false)); + } + + @Test + public void equals_Should_returnFalse_When_monitoringKeysNamesAreDifferent() { + MonitoringOption monitoring = new EasyRandom().nextObject(MonitoringOption.class); + monitoring.setMonitoringKey("monitoringKey"); + MonitoringOption otherMonitoring = new EasyRandom().nextObject(MonitoringOption.class); + otherMonitoring.setMonitoringKey("Other monitoringKey"); + + boolean equals = monitoring.equals(otherMonitoring); + + assertThat(equals, is(false)); + } + + @Test + public void equals_Should_returnTrue_When_sessionIdAndMonitoringTypeAndKeyAndMonitoringKeyIsEqual() { + MonitoringOption monitoring = new EasyRandom().nextObject(MonitoringOption.class); + MonitoringOption otherMonitoring = new EasyRandom().nextObject(MonitoringOption.class); + otherMonitoring.setSessionId(monitoring.getSessionId()); + otherMonitoring.setMonitoringType(monitoring.getMonitoringType()); + otherMonitoring.setKey(monitoring.getKey()); + otherMonitoring.setMonitoringKey(monitoring.getMonitoringKey()); + + boolean equals = monitoring.equals(otherMonitoring); + + assertThat(equals, is(true)); + } + +} diff --git a/src/test/java/de/caritas/cob/userservice/api/repository/session/SessionTest.java b/src/test/java/de/caritas/cob/userservice/api/repository/session/SessionTest.java new file mode 100644 index 000000000..30fc3d235 --- /dev/null +++ b/src/test/java/de/caritas/cob/userservice/api/repository/session/SessionTest.java @@ -0,0 +1,51 @@ +package de.caritas.cob.userservice.api.repository.session; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.is; + +import org.jeasy.random.EasyRandom; +import org.junit.Test; + +public class SessionTest { + + @Test + public void equals_Should_returnTrue_When_objectIsSameReference() { + Session session = new EasyRandom().nextObject(Session.class); + + assertThat(session, is(session)); + } + + @Test + public void equals_Should_returnFalse_When_objectIsNoSessionInstance() { + Session session = new EasyRandom().nextObject(Session.class); + + boolean equals = session.equals(new Object()); + + assertThat(equals, is(false)); + } + + @Test + public void equals_Should_returnFalse_When_sessionIdsAreDifferent() { + Session session = new EasyRandom().nextObject(Session.class); + session.setId(1L); + Session otherSession = new EasyRandom().nextObject(Session.class); + otherSession.setId(2L); + + boolean equals = session.equals(otherSession); + + assertThat(equals, is(false)); + } + + @Test + public void equals_Should_returnTrue_When_sessionIdsAreEqual() { + Session session = new EasyRandom().nextObject(Session.class); + session.setId(1L); + Session otherSession = new EasyRandom().nextObject(Session.class); + otherSession.setId(1L); + + boolean equals = session.equals(otherSession); + + assertThat(equals, is(true)); + } + +} diff --git a/src/test/java/de/caritas/cob/userservice/api/repository/sessiondata/SessionDataTest.java b/src/test/java/de/caritas/cob/userservice/api/repository/sessiondata/SessionDataTest.java new file mode 100644 index 000000000..f33a06012 --- /dev/null +++ b/src/test/java/de/caritas/cob/userservice/api/repository/sessiondata/SessionDataTest.java @@ -0,0 +1,51 @@ +package de.caritas.cob.userservice.api.repository.sessiondata; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.is; + +import org.jeasy.random.EasyRandom; +import org.junit.Test; + +public class SessionDataTest { + + @Test + public void equals_Should_returnTrue_When_objectIsSameReference() { + SessionData sessionData = new EasyRandom().nextObject(SessionData.class); + + assertThat(sessionData, is(sessionData)); + } + + @Test + public void equals_Should_returnFalse_When_objectIsNoSessionDataInstance() { + SessionData sessionData = new EasyRandom().nextObject(SessionData.class); + + boolean equals = sessionData.equals(new Object()); + + assertThat(equals, is(false)); + } + + @Test + public void equals_Should_returnFalse_When_sessionIdsAreDifferent() { + SessionData sessionData = new EasyRandom().nextObject(SessionData.class); + sessionData.setId(1L); + SessionData otherSessionData = new EasyRandom().nextObject(SessionData.class); + otherSessionData.setId(2L); + + boolean equals = sessionData.equals(otherSessionData); + + assertThat(equals, is(false)); + } + + @Test + public void equals_Should_returnTrue_When_sessionIdsAreEqual() { + SessionData sessionData = new EasyRandom().nextObject(SessionData.class); + sessionData.setId(1L); + SessionData otherSessionData = new EasyRandom().nextObject(SessionData.class); + otherSessionData.setId(1L); + + boolean equals = sessionData.equals(otherSessionData); + + assertThat(equals, is(true)); + } + +} diff --git a/src/test/java/de/caritas/cob/userservice/api/repository/user/UserTest.java b/src/test/java/de/caritas/cob/userservice/api/repository/user/UserTest.java new file mode 100644 index 000000000..c56b7efba --- /dev/null +++ b/src/test/java/de/caritas/cob/userservice/api/repository/user/UserTest.java @@ -0,0 +1,51 @@ +package de.caritas.cob.userservice.api.repository.user; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.is; + +import org.jeasy.random.EasyRandom; +import org.junit.Test; + +public class UserTest { + + @Test + public void equals_Should_returnTrue_When_objectIsSameReference() { + User user = new EasyRandom().nextObject(User.class); + + assertThat(user, is(user)); + } + + @Test + public void equals_Should_returnFalse_When_objectIsNoUserInstance() { + User user = new EasyRandom().nextObject(User.class); + + boolean equals = user.equals(new Object()); + + assertThat(equals, is(false)); + } + + @Test + public void equals_Should_returnFalse_When_userIdsAreDifferent() { + User user = new EasyRandom().nextObject(User.class); + user.setUserId("1"); + User otherUser = new EasyRandom().nextObject(User.class); + otherUser.setUserId("2"); + + boolean equals = user.equals(otherUser); + + assertThat(equals, is(false)); + } + + @Test + public void equals_Should_returnTrue_When_userIdsAreEqual() { + User user = new EasyRandom().nextObject(User.class); + user.setUserId("1"); + User otherUser = new EasyRandom().nextObject(User.class); + otherUser.setUserId("1"); + + boolean equals = user.equals(otherUser); + + assertThat(equals, is(true)); + } + +} diff --git a/src/test/java/de/caritas/cob/userservice/api/repository/useragency/UserAgencyTest.java b/src/test/java/de/caritas/cob/userservice/api/repository/useragency/UserAgencyTest.java new file mode 100644 index 000000000..c3454a5d6 --- /dev/null +++ b/src/test/java/de/caritas/cob/userservice/api/repository/useragency/UserAgencyTest.java @@ -0,0 +1,51 @@ +package de.caritas.cob.userservice.api.repository.useragency; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.is; + +import org.jeasy.random.EasyRandom; +import org.junit.Test; + +public class UserAgencyTest { + + @Test + public void equals_Should_returnTrue_When_objectIsSameReference() { + UserAgency userAgency = new EasyRandom().nextObject(UserAgency.class); + + assertThat(userAgency, is(userAgency)); + } + + @Test + public void equals_Should_returnFalse_When_objectIsNoUserAgencyInstance() { + UserAgency userAgency = new EasyRandom().nextObject(UserAgency.class); + + boolean equals = userAgency.equals(new Object()); + + assertThat(equals, is(false)); + } + + @Test + public void equals_Should_returnFalse_When_userIdsAreDifferent() { + UserAgency userAgency = new EasyRandom().nextObject(UserAgency.class); + userAgency.setId(1L); + UserAgency otherUserAgency = new EasyRandom().nextObject(UserAgency.class); + otherUserAgency.setId(2L); + + boolean equals = userAgency.equals(otherUserAgency); + + assertThat(equals, is(false)); + } + + @Test + public void equals_Should_returnTrue_When_userIdsAreEqual() { + UserAgency userAgency = new EasyRandom().nextObject(UserAgency.class); + userAgency.setId(1L); + UserAgency otherUserAgency = new EasyRandom().nextObject(UserAgency.class); + otherUserAgency.setId(1L); + + boolean equals = userAgency.equals(otherUserAgency); + + assertThat(equals, is(true)); + } + +} diff --git a/src/test/java/de/caritas/cob/userservice/api/service/ChatServiceTest.java b/src/test/java/de/caritas/cob/userservice/api/service/ChatServiceTest.java index 9cad72ca7..642c6c8cd 100644 --- a/src/test/java/de/caritas/cob/userservice/api/service/ChatServiceTest.java +++ b/src/test/java/de/caritas/cob/userservice/api/service/ChatServiceTest.java @@ -13,14 +13,12 @@ import static de.caritas.cob.userservice.testHelper.TestConstants.RC_GROUP_ID; import static de.caritas.cob.userservice.testHelper.TestConstants.USER_ID; import static org.hamcrest.CoreMatchers.instanceOf; +import static org.hamcrest.MatcherAssert.assertThat; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; -import static org.mockito.ArgumentMatchers.anyString; -import static org.mockito.Mockito.atLeastOnce; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; @@ -39,7 +37,7 @@ import de.caritas.cob.userservice.api.model.UserSessionResponseDTO; import de.caritas.cob.userservice.api.repository.chat.Chat; import de.caritas.cob.userservice.api.repository.chat.ChatRepository; -import de.caritas.cob.userservice.api.repository.chatAgency.ChatAgencyRepository; +import de.caritas.cob.userservice.api.repository.chatagency.ChatAgencyRepository; import de.caritas.cob.userservice.api.repository.consultant.Consultant; import java.time.LocalDate; import java.time.LocalTime; diff --git a/src/test/java/de/caritas/cob/userservice/api/service/ConsultantAgencyServiceTest.java b/src/test/java/de/caritas/cob/userservice/api/service/ConsultantAgencyServiceTest.java index 92523835a..ba4aac8c3 100644 --- a/src/test/java/de/caritas/cob/userservice/api/service/ConsultantAgencyServiceTest.java +++ b/src/test/java/de/caritas/cob/userservice/api/service/ConsultantAgencyServiceTest.java @@ -1,9 +1,10 @@ package de.caritas.cob.userservice.api.service; +import static de.caritas.cob.userservice.localdatetime.CustomLocalDateTime.nowInUtc; import static org.hamcrest.CoreMatchers.everyItem; import static org.hamcrest.CoreMatchers.instanceOf; +import static org.hamcrest.MatcherAssert.assertThat; import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import static org.mockito.Mockito.times; @@ -14,8 +15,8 @@ import de.caritas.cob.userservice.api.exception.httpresponses.InternalServerErrorException; import de.caritas.cob.userservice.api.model.ConsultantResponseDTO; import de.caritas.cob.userservice.api.repository.consultant.Consultant; -import de.caritas.cob.userservice.api.repository.consultantAgency.ConsultantAgency; -import de.caritas.cob.userservice.api.repository.consultantAgency.ConsultantAgencyRepository; +import de.caritas.cob.userservice.api.repository.consultantagency.ConsultantAgency; +import de.caritas.cob.userservice.api.repository.consultantagency.ConsultantAgencyRepository; import java.time.LocalDateTime; import java.util.Arrays; import java.util.List; @@ -37,15 +38,16 @@ public class ConsultantAgencyServiceTest { private final Long AGENCY_ID = 1L; private final Consultant CONSULTANT = new Consultant(CONSULTANT_ID, CONSULTANT_ROCKETCHAT_ID, "consultant", "first name", - "last name", "consultant@cob.de", false, false, null, false, null, null, null, null, null, null); + "last name", "consultant@cob.de", false, false, null, false, null, null, null, null, null, + null); private final ConsultantAgency CONSULTANT_AGENCY = - new ConsultantAgency(AGENCY_ID, CONSULTANT, 1L, LocalDateTime.now(), LocalDateTime.now()); + new ConsultantAgency(AGENCY_ID, CONSULTANT, 1L, nowInUtc(), nowInUtc(), nowInUtc()); private final List CONSULTANT_AGENY_LIST = Arrays.asList(CONSULTANT_AGENCY); private final ConsultantAgency NULL_CONSULTANT_AGENCY = null; private final List CONSULTANT_AGENCY_NULL_LIST = Arrays.asList(NULL_CONSULTANT_AGENCY); private final ConsultantAgency CONSULTANT_NULL_AGENCY = new ConsultantAgency(AGENCY_ID, null, 1L, - LocalDateTime.now(), LocalDateTime.now()); + nowInUtc(), nowInUtc(), nowInUtc()); private final List CONSULTANT_NULL_AGENCY_LIST = Arrays.asList(CONSULTANT_NULL_AGENCY); private final String ERROR = "error"; diff --git a/src/test/java/de/caritas/cob/userservice/api/service/MonitoringServiceTest.java b/src/test/java/de/caritas/cob/userservice/api/service/MonitoringServiceTest.java index 3b913683c..2b071508a 100644 --- a/src/test/java/de/caritas/cob/userservice/api/service/MonitoringServiceTest.java +++ b/src/test/java/de/caritas/cob/userservice/api/service/MonitoringServiceTest.java @@ -1,6 +1,9 @@ package de.caritas.cob.userservice.api.service; +import static de.caritas.cob.userservice.api.repository.session.ConsultingType.SUCHT; +import static de.caritas.cob.userservice.api.repository.session.SessionStatus.IN_PROGRESS; import static de.caritas.cob.userservice.testHelper.TestConstants.CONSULTING_TYPE_SETTINGS_WIT_MONITORING; +import static de.caritas.cob.userservice.testHelper.TestConstants.POSTCODE; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import static org.mockito.Mockito.doReturn; @@ -44,7 +47,8 @@ public class MonitoringServiceTest { private final String ERROR = "error"; private final Long SESSION_ID = 123L; private final Session SESSION = - new Session(SESSION_ID, null, null, null, null, null, null, null, null); + new Session(SESSION_ID, null, null, SUCHT, POSTCODE, null, IN_PROGRESS, null, null, null, + null, false, false, null, null); private final MonitoringDTO MONITORING_DTO = new MonitoringDTO(); @Before @@ -58,9 +62,7 @@ public void setUp() { } /** - * * Method: updateMonitoring Role: consultant - * */ @Test @@ -68,7 +70,8 @@ public void updateMonitoring_Should_ThrowInternalServerErrorException_OnDatabase throws Exception { @SuppressWarnings("serial") - DataAccessException ex = new DataAccessException(ERROR) {}; + DataAccessException ex = new DataAccessException(ERROR) { + }; when(monitoringRepository.saveAll(Mockito.any())).thenThrow(ex); @@ -90,9 +93,7 @@ public void updateMonitoring_Should_SaveMonitoringData() { } /** - * * Method: deleteMonitoring Role: consultant - * */ @Test @@ -100,7 +101,8 @@ public void deleteMonitoring_Should_ThrowInternalServerErrorException_OnDatabase throws Exception { @SuppressWarnings("serial") - DataAccessException ex = new DataAccessException(ERROR) {}; + DataAccessException ex = new DataAccessException(ERROR) { + }; doThrow(ex).when(monitoringRepository).deleteAll(Mockito.any()); @@ -122,10 +124,7 @@ public void deleteMonitoring_Should_DeleteMonitoringData() { } /** - * * Method: crateMonitoring - * - * @throws CreateMonitoringException */ @Test @@ -134,7 +133,8 @@ public void createMonitoring_Should_UpdateMonitoring_WithInitialMonitoringListOf doReturn(MONITORING_DTO).when(monitoringHelper).getMonitoringInitalList(Mockito.any()); - monitoringService.createMonitoringIfConfigured(SESSION, CONSULTING_TYPE_SETTINGS_WIT_MONITORING); + monitoringService + .createMonitoringIfConfigured(SESSION, CONSULTING_TYPE_SETTINGS_WIT_MONITORING); verify(monitoringService, times(1)).updateMonitoring(SESSION_ID, MONITORING_DTO); verify(monitoringHelper, times(1)).getMonitoringInitalList(SESSION.getConsultingType()); @@ -142,7 +142,6 @@ public void createMonitoring_Should_UpdateMonitoring_WithInitialMonitoringListOf } /** - * * Method: deleteInitialMonitoring */ diff --git a/src/test/java/de/caritas/cob/userservice/api/service/RocketChatServiceTest.java b/src/test/java/de/caritas/cob/userservice/api/service/RocketChatServiceTest.java index 303d18514..f88e8e98f 100644 --- a/src/test/java/de/caritas/cob/userservice/api/service/RocketChatServiceTest.java +++ b/src/test/java/de/caritas/cob/userservice/api/service/RocketChatServiceTest.java @@ -1,5 +1,6 @@ package de.caritas.cob.userservice.api.service; +import static de.caritas.cob.userservice.localdatetime.CustomLocalDateTime.nowInUtc; import static de.caritas.cob.userservice.testHelper.ExceptionConstants.HTTP_STATUS_CODE_INTERNAL_SERVER_ERROR_EXCEPTION; import static de.caritas.cob.userservice.testHelper.ExceptionConstants.HTTP_STATUS_CODE_UNAUTHORIZED_EXCEPTION; import static de.caritas.cob.userservice.testHelper.FieldConstants.FIELD_NAME_ROCKET_CHAT_API_CLEAN_ROOM_HISTORY; @@ -39,9 +40,9 @@ import static de.caritas.cob.userservice.testHelper.TestConstants.USER_INFO_RESPONSE_DTO_FAILED; import static org.hamcrest.CoreMatchers.everyItem; import static org.hamcrest.CoreMatchers.instanceOf; +import static org.hamcrest.MatcherAssert.assertThat; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import static org.mockito.ArgumentMatchers.any; @@ -77,7 +78,8 @@ import de.caritas.cob.userservice.api.model.rocketchat.subscriptions.SubscriptionsGetDTO; import de.caritas.cob.userservice.api.model.rocketchat.subscriptions.SubscriptionsUpdateDTO; import de.caritas.cob.userservice.api.model.rocketchat.user.UserInfoResponseDTO; -import de.caritas.cob.userservice.api.service.helper.RocketChatCredentialsHelper; +import de.caritas.cob.userservice.api.service.rocketchat.RocketChatCredentialsProvider; +import de.caritas.cob.userservice.api.service.rocketchat.RocketChatService; import java.time.LocalDateTime; import java.util.ArrayList; import java.util.List; @@ -160,8 +162,8 @@ public class RocketChatServiceTest { new GroupDTO(GROUP_ID, GROUP_NAME, null, null, 0, 0, null, null, false, false, null); private final GroupResponseDTO GROUP_RESPONSE_DTO = new GroupResponseDTO(GROUP_DTO, true, null, null); - private final LocalDateTime DATETIME_OLDEST = LocalDateTime.now(); - private final LocalDateTime DATETIME_LATEST = LocalDateTime.now(); + private final LocalDateTime DATETIME_OLDEST = nowInUtc(); + private final LocalDateTime DATETIME_LATEST = nowInUtc(); private final String PASSWORD = "password"; MultiValueMap MULTI_VALUE_MAP_WITH_TECH_USER_CREDENTIALS = new LinkedMultiValueMap() { @@ -184,7 +186,7 @@ public class RocketChatServiceTest { @Mock Logger logger; @Mock - RocketChatCredentialsHelper rcCredentialsHelper; + RocketChatCredentialsProvider rcCredentialsHelper; private HttpHeaders HTTP_HEADERS = new HttpHeaders() { private static final long serialVersionUID = 1L; @@ -552,9 +554,8 @@ public void removeSystemMessages_Should_NotThrowException_WhenApiCallIsSuccessfu @Test public void getUserId_Should_LoginUser() throws RocketChatLoginException { - when(restTemplate.postForEntity(ArgumentMatchers.eq(RC_URL_CHAT_USER_LOGIN), - any(), ArgumentMatchers.>any())).thenReturn( - new ResponseEntity(LOGIN_RESPONSE_DTO_TECH_USER, HttpStatus.OK)); + when(rcCredentialsHelper.loginUser(any(), any())).thenReturn( + new ResponseEntity<>(LOGIN_RESPONSE_DTO_TECH_USER, HttpStatus.OK)); when(restTemplate.postForEntity(ArgumentMatchers.eq(RC_URL_CHAT_USER_LOGOUT), any(), ArgumentMatchers.>any())).thenReturn( @@ -562,17 +563,15 @@ public void getUserId_Should_LoginUser() throws RocketChatLoginException { rocketChatService.getUserID(USERNAME, PASSWORD, false); - verify(restTemplate, times(1)).postForEntity(Mockito.eq(RC_URL_CHAT_USER_LOGIN), - any(), Mockito.eq(LoginResponseDTO.class)); - + verify(this.rcCredentialsHelper, times(1)).loginUser(Mockito.eq(USERNAME), + Mockito.eq(PASSWORD)); } @Test public void getUserId_Should_LogoutUser() throws RocketChatLoginException { - when(restTemplate.postForEntity(ArgumentMatchers.eq(RC_URL_CHAT_USER_LOGIN), - any(), ArgumentMatchers.>any())).thenReturn( - new ResponseEntity(LOGIN_RESPONSE_DTO_TECH_USER, HttpStatus.OK)); + when(rcCredentialsHelper.loginUser(any(), any())).thenReturn( + new ResponseEntity<>(LOGIN_RESPONSE_DTO_TECH_USER, HttpStatus.OK)); when(restTemplate.postForEntity(ArgumentMatchers.eq(RC_URL_CHAT_USER_LOGOUT), any(), ArgumentMatchers.>any())).thenReturn( @@ -580,17 +579,16 @@ public void getUserId_Should_LogoutUser() throws RocketChatLoginException { rocketChatService.getUserID(USERNAME, PASSWORD, false); - verify(restTemplate, times(1)).postForEntity(Mockito.eq(RC_URL_CHAT_USER_LOGOUT), - any(), Mockito.eq(LogoutResponseDTO.class)); + verify(this.rcCredentialsHelper, times(1)).loginUser(Mockito.eq(USERNAME), + Mockito.eq(PASSWORD)); } @Test public void getUserId_Should_ReturnCorrectUserId() throws RocketChatLoginException { - when(restTemplate.postForEntity(ArgumentMatchers.eq(RC_URL_CHAT_USER_LOGIN), - any(), ArgumentMatchers.>any())).thenReturn( - new ResponseEntity(LOGIN_RESPONSE_DTO_TECH_USER, HttpStatus.OK)); + when(rcCredentialsHelper.loginUser(any(), any())).thenReturn( + new ResponseEntity<>(LOGIN_RESPONSE_DTO_TECH_USER, HttpStatus.OK)); when(restTemplate.postForEntity(ArgumentMatchers.eq(RC_URL_CHAT_USER_LOGOUT), any(), ArgumentMatchers.>any())).thenReturn( diff --git a/src/test/java/de/caritas/cob/userservice/api/service/SessionDataServiceTest.java b/src/test/java/de/caritas/cob/userservice/api/service/SessionDataServiceTest.java index 7f3e4122b..59695e7b3 100644 --- a/src/test/java/de/caritas/cob/userservice/api/service/SessionDataServiceTest.java +++ b/src/test/java/de/caritas/cob/userservice/api/service/SessionDataServiceTest.java @@ -14,17 +14,15 @@ import de.caritas.cob.userservice.api.repository.session.ConsultingType; import de.caritas.cob.userservice.api.repository.session.Session; import de.caritas.cob.userservice.api.repository.session.SessionStatus; -import de.caritas.cob.userservice.api.repository.sessionData.SessionDataRepository; +import de.caritas.cob.userservice.api.repository.sessiondata.SessionDataRepository; import de.caritas.cob.userservice.api.repository.user.User; import java.util.ArrayList; -import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.junit.MockitoJUnitRunner; -import org.slf4j.Logger; import org.springframework.dao.DataAccessException; @RunWith(MockitoJUnitRunner.class) @@ -32,7 +30,7 @@ public class SessionDataServiceTest { private final String USERNAME = "username"; private final String USER_ID = "9b71cc46-650d-42bb-8299-f8e3f6d7249f"; - private final User USER = new User(USER_ID, USERNAME, "name@domain.de", null); + private final User USER = new User(USER_ID, null, USERNAME, "name@domain.de", false); private final String CONSULTANT_ID = "1b71cc46-650d-42bb-8299-f8e3f6d7249a"; private final String CONSULTANT_ROCKETCHAT_ID = "xN3Mobksn3xdp7gEk"; private final Consultant CONSULTANT = @@ -40,7 +38,7 @@ public class SessionDataServiceTest { "last name", "consultant@cob.de", false, false, null, false, null, null, null, null, null, null); private final Session INITALIZED_SESSION = new Session(1L, USER, CONSULTANT, ConsultingType.SUCHT, - "99999", 0L, SessionStatus.INITIAL, null, null); + "99999", 0L, SessionStatus.INITIAL, null, null, null, null, false, false, null, null); private final UserDTO USER_DTO = new UserDTO(USERNAME, "99999", 99L, "xyz", "x@y.de", null, null, null, null, null, "true", "0", true); diff --git a/src/test/java/de/caritas/cob/userservice/api/service/SessionServiceTest.java b/src/test/java/de/caritas/cob/userservice/api/service/SessionServiceTest.java index d28a1369f..44952b1c2 100644 --- a/src/test/java/de/caritas/cob/userservice/api/service/SessionServiceTest.java +++ b/src/test/java/de/caritas/cob/userservice/api/service/SessionServiceTest.java @@ -1,5 +1,6 @@ package de.caritas.cob.userservice.api.service; +import static de.caritas.cob.userservice.localdatetime.CustomLocalDateTime.nowInUtc; import static de.caritas.cob.userservice.testHelper.TestConstants.AGENCY_DTO_LIST; import static de.caritas.cob.userservice.testHelper.TestConstants.AGENCY_ID; import static de.caritas.cob.userservice.testHelper.TestConstants.CONSULTANT_ID; @@ -51,7 +52,7 @@ import de.caritas.cob.userservice.api.model.UserSessionResponseDTO; import de.caritas.cob.userservice.api.model.registration.UserDTO; import de.caritas.cob.userservice.api.repository.consultant.Consultant; -import de.caritas.cob.userservice.api.repository.consultantAgency.ConsultantAgency; +import de.caritas.cob.userservice.api.repository.consultantagency.ConsultantAgency; import de.caritas.cob.userservice.api.repository.session.ConsultingType; import de.caritas.cob.userservice.api.repository.session.Session; import de.caritas.cob.userservice.api.repository.session.SessionRepository; @@ -86,18 +87,21 @@ public class SessionServiceTest { private final Consultant CONSULTANT = new Consultant(CONSULTANT_ID, ROCKETCHAT_ID, "consultant", "first name", "last name", "consultant@cob.de", false, false, null, false, null, null, null, null, null, null); - private final User USER = new User(USER_ID, "username", "name@domain.de", null); + private final User USER = new User(USER_ID, null, "username", "name@domain.de", false); private final Session SESSION = new Session(ENQUIRY_ID, null, null, ConsultingType.SUCHT, "99999", - 1L, SessionStatus.NEW, new Date(), null); + 1L, SessionStatus.NEW, new Date(), null, null, null, + false, false, null, null); private final Session SESSION_2 = new Session(ENQUIRY_ID_2, null, null, ConsultingType.SUCHT, - "99999", 1L, SessionStatus.NEW, new Date(), null); + "99999", 1L, SessionStatus.NEW, new Date(), null, null, null, + false, false, null, null); private final Session SESSION_WITH_CONSULTANT = new Session(ENQUIRY_ID, null, CONSULTANT, - ConsultingType.SUCHT, "99999", 1L, SessionStatus.NEW, new Date(), null); + ConsultingType.SUCHT, "99999", 1L, SessionStatus.NEW, new Date(), null, null, null, + false, false, null, null); private final Session ACCEPTED_SESSION = new Session(ENQUIRY_ID, null, CONSULTANT, - ConsultingType.SUCHT, "99999", 1L, SessionStatus.NEW, new Date(), null); + ConsultingType.SUCHT, "99999", 1L, SessionStatus.NEW, new Date(), null, null, null, + false, false, null, null); private final ConsultantAgency CONSULTANT_AGENCY_1 = new ConsultantAgency(1L, CONSULTANT, 1L, - LocalDateTime - .now(), LocalDateTime.now()); + nowInUtc(), nowInUtc(), nowInUtc()); private final Set CONSULTANT_AGENCY_SET = new HashSet<>(); private final List SESSION_LIST = Arrays.asList(SESSION, SESSION_2); private final List SESSION_LIST_SINGLE = Collections.singletonList(SESSION); diff --git a/src/test/java/de/caritas/cob/userservice/api/service/UserAgencyServiceTest.java b/src/test/java/de/caritas/cob/userservice/api/service/UserAgencyServiceTest.java index 5ab3aa7b4..2c0e641d2 100644 --- a/src/test/java/de/caritas/cob/userservice/api/service/UserAgencyServiceTest.java +++ b/src/test/java/de/caritas/cob/userservice/api/service/UserAgencyServiceTest.java @@ -6,9 +6,9 @@ import static de.caritas.cob.userservice.testHelper.TestConstants.USER_AGENCY_LIST; import static org.hamcrest.CoreMatchers.everyItem; import static org.hamcrest.CoreMatchers.instanceOf; +import static org.hamcrest.MatcherAssert.assertThat; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import static org.mockito.Mockito.doThrow; @@ -25,8 +25,8 @@ import org.mockito.Mockito; import org.springframework.dao.DataAccessException; import org.springframework.test.context.junit4.SpringRunner; -import de.caritas.cob.userservice.api.repository.userAgency.UserAgency; -import de.caritas.cob.userservice.api.repository.userAgency.UserAgencyRepository; +import de.caritas.cob.userservice.api.repository.useragency.UserAgency; +import de.caritas.cob.userservice.api.repository.useragency.UserAgencyRepository; @RunWith(SpringRunner.class) public class UserAgencyServiceTest { diff --git a/src/test/java/de/caritas/cob/userservice/api/service/emailsupplier/NewEnquiryEmailSupplierTest.java b/src/test/java/de/caritas/cob/userservice/api/service/emailsupplier/NewEnquiryEmailSupplierTest.java index 7d5153f6b..68a402224 100644 --- a/src/test/java/de/caritas/cob/userservice/api/service/emailsupplier/NewEnquiryEmailSupplierTest.java +++ b/src/test/java/de/caritas/cob/userservice/api/service/emailsupplier/NewEnquiryEmailSupplierTest.java @@ -1,6 +1,7 @@ package de.caritas.cob.userservice.api.service.emailsupplier; import static de.caritas.cob.userservice.api.helper.EmailNotificationHelper.TEMPLATE_NEW_ENQUIRY_NOTIFICATION; +import static de.caritas.cob.userservice.localdatetime.CustomLocalDateTime.nowInUtc; import static de.caritas.cob.userservice.testHelper.TestConstants.AGENCY_DTO_U25; import static de.caritas.cob.userservice.testHelper.TestConstants.MAIN_CONSULTANT; import static java.util.Arrays.asList; @@ -15,8 +16,8 @@ import de.caritas.cob.userservice.api.model.mailservice.MailDTO; import de.caritas.cob.userservice.api.model.mailservice.TemplateDataDTO; import de.caritas.cob.userservice.api.repository.consultant.Consultant; -import de.caritas.cob.userservice.api.repository.consultantAgency.ConsultantAgency; -import de.caritas.cob.userservice.api.repository.consultantAgency.ConsultantAgencyRepository; +import de.caritas.cob.userservice.api.repository.consultantagency.ConsultantAgency; +import de.caritas.cob.userservice.api.repository.consultantagency.ConsultantAgencyRepository; import de.caritas.cob.userservice.api.repository.session.Session; import de.caritas.cob.userservice.api.service.helper.AgencyServiceHelper; import java.time.LocalDateTime; @@ -63,8 +64,10 @@ public void generateEmails_Should_ReturnEmptyList_When_NoValidConsultantWasFound absentConsultant.setEmail("email"); when(consultantAgencyRepository.findByAgencyId(anyLong())).thenReturn(asList( null, - new ConsultantAgency(0L, new Consultant(), 0L, LocalDateTime.now(), LocalDateTime.now()), - new ConsultantAgency(1L, absentConsultant, 1L, LocalDateTime.now(), LocalDateTime.now()))); + new ConsultantAgency(0L, new Consultant(), 0L, nowInUtc(), nowInUtc(), + nowInUtc()), + new ConsultantAgency(1L, absentConsultant, 1L, nowInUtc(), nowInUtc(), + nowInUtc()))); List generatedMails = newEnquiryEmailSupplier.generateEmails(); @@ -75,8 +78,10 @@ public void generateEmails_Should_ReturnEmptyList_When_NoValidConsultantWasFound public void generateEmails_Should_ReturnExpectedMailDTO_When_PresentConsultantsWereFound() throws AgencyServiceHelperException { when(consultantAgencyRepository.findByAgencyId(anyLong())).thenReturn(asList( - new ConsultantAgency(0L, MAIN_CONSULTANT, 0L, LocalDateTime.now(), LocalDateTime.now()), - new ConsultantAgency(1L, MAIN_CONSULTANT, 1L, LocalDateTime.now(), LocalDateTime.now()))); + new ConsultantAgency(0L, MAIN_CONSULTANT, 0L, nowInUtc(), nowInUtc(), + nowInUtc()), + new ConsultantAgency(1L, MAIN_CONSULTANT, 1L, nowInUtc(), nowInUtc(), + nowInUtc()))); when(agencyServiceHelper.getAgency(any())).thenReturn(AGENCY_DTO_U25); when(session.getPostcode()).thenReturn("12345"); diff --git a/src/test/java/de/caritas/cob/userservice/api/service/emailsupplier/NewFeedbackEmailSupplierTest.java b/src/test/java/de/caritas/cob/userservice/api/service/emailsupplier/NewFeedbackEmailSupplierTest.java index b3ba8d940..e0ddcd872 100644 --- a/src/test/java/de/caritas/cob/userservice/api/service/emailsupplier/NewFeedbackEmailSupplierTest.java +++ b/src/test/java/de/caritas/cob/userservice/api/service/emailsupplier/NewFeedbackEmailSupplierTest.java @@ -24,7 +24,7 @@ import de.caritas.cob.userservice.api.repository.session.Session; import de.caritas.cob.userservice.api.service.ConsultantService; import de.caritas.cob.userservice.api.service.LogService; -import de.caritas.cob.userservice.api.service.RocketChatService; +import de.caritas.cob.userservice.api.service.rocketchat.RocketChatService; import java.util.List; import java.util.Optional; import org.junit.Before; diff --git a/src/test/java/de/caritas/cob/userservice/api/service/helper/AgencyServiceHelperTest.java b/src/test/java/de/caritas/cob/userservice/api/service/helper/AgencyServiceHelperTest.java index 83d42e8ff..2899b0379 100644 --- a/src/test/java/de/caritas/cob/userservice/api/service/helper/AgencyServiceHelperTest.java +++ b/src/test/java/de/caritas/cob/userservice/api/service/helper/AgencyServiceHelperTest.java @@ -4,12 +4,14 @@ import static de.caritas.cob.userservice.testHelper.TestConstants.AGENCY_ID; import static de.caritas.cob.userservice.testHelper.TestConstants.AGENCY_ID_LIST; import static org.hamcrest.CoreMatchers.instanceOf; +import static org.hamcrest.MatcherAssert.assertThat; import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import static org.mockito.Mockito.when; +import de.caritas.cob.userservice.api.exception.AgencyServiceHelperException; +import de.caritas.cob.userservice.api.model.AgencyDTO; import java.lang.reflect.Method; import java.util.List; import org.junit.Before; @@ -26,8 +28,6 @@ import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.client.RestTemplate; -import de.caritas.cob.userservice.api.exception.AgencyServiceHelperException; -import de.caritas.cob.userservice.api.model.AgencyDTO; @RunWith(MockitoJUnitRunner.class) public class AgencyServiceHelperTest { diff --git a/src/test/java/de/caritas/cob/userservice/api/service/helper/MailServiceHelperTest.java b/src/test/java/de/caritas/cob/userservice/api/service/helper/MailServiceHelperTest.java index 1b5c20da2..8bc4f574f 100644 --- a/src/test/java/de/caritas/cob/userservice/api/service/helper/MailServiceHelperTest.java +++ b/src/test/java/de/caritas/cob/userservice/api/service/helper/MailServiceHelperTest.java @@ -105,7 +105,7 @@ public void sendEmailNotification_ShouldLogException_WhenExceptionOccursWhileCal private HttpHeaders getCsrfHttpHeaders() { String csrfToken = UUID.randomUUID().toString(); HttpHeaders httpHeaders = new HttpHeaders(); - httpHeaders.setContentType(MediaType.APPLICATION_JSON_UTF8); + httpHeaders.setContentType(MediaType.APPLICATION_JSON); httpHeaders.add("Cookie", "X-CSRF-TOKEN=" + csrfToken); httpHeaders.add("CSRF-TOKEN", csrfToken); diff --git a/src/test/java/de/caritas/cob/userservice/api/service/helper/MessageServiceHelperTest.java b/src/test/java/de/caritas/cob/userservice/api/service/helper/MessageServiceHelperTest.java index f475d2d1c..5270c41a3 100644 --- a/src/test/java/de/caritas/cob/userservice/api/service/helper/MessageServiceHelperTest.java +++ b/src/test/java/de/caritas/cob/userservice/api/service/helper/MessageServiceHelperTest.java @@ -13,6 +13,8 @@ import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; + +import de.caritas.cob.userservice.api.service.rocketchat.RocketChatCredentialsProvider; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -48,7 +50,7 @@ public class MessageServiceHelperTest { @Mock private ServiceHelper serviceHelper; @Mock - private RocketChatCredentialsHelper rcCredentialHelper; + private RocketChatCredentialsProvider rcCredentialHelper; @Mock private UserHelper userHelper; @Mock diff --git a/src/test/java/de/caritas/cob/userservice/api/service/helper/RocketChatCredentialsHelperTest.java b/src/test/java/de/caritas/cob/userservice/api/service/helper/RocketChatCredentialsProviderTest.java similarity index 79% rename from src/test/java/de/caritas/cob/userservice/api/service/helper/RocketChatCredentialsHelperTest.java rename to src/test/java/de/caritas/cob/userservice/api/service/helper/RocketChatCredentialsProviderTest.java index e0fa402b9..7caa48c4f 100644 --- a/src/test/java/de/caritas/cob/userservice/api/service/helper/RocketChatCredentialsHelperTest.java +++ b/src/test/java/de/caritas/cob/userservice/api/service/helper/RocketChatCredentialsProviderTest.java @@ -1,5 +1,6 @@ package de.caritas.cob.userservice.api.service.helper; +import static de.caritas.cob.userservice.localdatetime.CustomLocalDateTime.nowInUtc; import static de.caritas.cob.userservice.testHelper.TestConstants.RC_CREDENTIALS_SYSTEM_A; import static de.caritas.cob.userservice.testHelper.TestConstants.RC_CREDENTIALS_SYSTEM_B; import static de.caritas.cob.userservice.testHelper.TestConstants.RC_CREDENTIALS_SYSTEM_C; @@ -25,13 +26,16 @@ import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; +import static org.springframework.test.util.ReflectionTestUtils.setField; import de.caritas.cob.userservice.api.container.RocketChatCredentials; import de.caritas.cob.userservice.api.exception.rocketchat.RocketChatUserNotInitializedException; import de.caritas.cob.userservice.api.model.rocketchat.login.DataDTO; import de.caritas.cob.userservice.api.model.rocketchat.login.LoginResponseDTO; import de.caritas.cob.userservice.api.model.rocketchat.logout.LogoutResponseDTO; +import de.caritas.cob.userservice.api.service.rocketchat.RocketChatCredentialsProvider; import java.time.LocalDateTime; +import java.util.concurrent.atomic.AtomicReference; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -50,18 +54,18 @@ import org.springframework.web.client.RestTemplate; @RunWith(MockitoJUnitRunner.class) -public class RocketChatCredentialsHelperTest { +public class RocketChatCredentialsProviderTest { /** * FIELD Names */ - private final static String FIELD_NAME_TECHNICAL_USER_A = "techUser_A"; - private final static String FIELD_NAME_TECHNICAL_USER_B = "techUser_B"; - private final static String FIELD_NAME_TECHNICAL_USER_C = "techUser_B"; + private final static String FIELD_NAME_TECHNICAL_USER_A = "techUserA"; + private final static String FIELD_NAME_TECHNICAL_USER_B = "techUserB"; + private final static String FIELD_NAME_TECHNICAL_USER_C = "techUserB"; - private final static String FIELD_NAME_SYSTEM_USER_A = "systemUser_A"; - private final static String FIELD_NAME_SYSTEM_USER_B = "systemUser_B"; + private final static String FIELD_NAME_SYSTEM_USER_A = "systemUserA"; + private final static String FIELD_NAME_SYSTEM_USER_B = "systemUserB"; private final static String FIELD_NAME_TECHNICAL_USERNAME = "technicalUsername"; private final static String FIELD_NAME_TECHNICAL_PASSWORD = "technicalPassword"; @@ -88,6 +92,7 @@ public class RocketChatCredentialsHelperTest { MultiValueMap MULTI_VALUE_MAP_WITH_TECHNICAL_USER_CREDENTIALS = new LinkedMultiValueMap() { private static final long serialVersionUID = 1L; + { add("username", TECHNICAL_USER_USERNAME); add("password", TECHNICAL_USER_PW); @@ -97,6 +102,7 @@ public class RocketChatCredentialsHelperTest { MultiValueMap MULTI_VALUE_MAP_WITH_SYSTEM_USER_CREDENTIALS = new LinkedMultiValueMap() { private static final long serialVersionUID = 1L; + { add("username", SYSTEM_USER_USERNAME); add("password", SYSTEM_USER_PW); @@ -122,7 +128,7 @@ public class RocketChatCredentialsHelperTest { LogoutResponseDTO LOGOUT_RESPONSE_DTO_TECHNICAL_USER_A = new LogoutResponseDTO("status", TECHNICAL_USER_USERNAME, new de.caritas.cob.userservice.api.model.rocketchat.logout.DataDTO( - TECHNICAL_USER_A_USERNAME)); + TECHNICAL_USER_A_USERNAME)); private final static String TECHNICAL_USER_USERNAME = "techUserName"; private final static String TECHNICAL_USER_PW = "techUserPW"; @@ -131,7 +137,7 @@ public class RocketChatCredentialsHelperTest { private final static String SYSTEM_USER_PW = "sysUserPW"; @InjectMocks - private RocketChatCredentialsHelper rcCredentialHelper; + private RocketChatCredentialsProvider rcCredentialHelper; @Mock private RestTemplate restTemplate; @@ -164,9 +170,7 @@ public void setup() throws NoSuchFieldException { } /** - * * Method: updateCredentials - * **/ @Test @@ -183,8 +187,8 @@ public void updateCredentials_Should_LoginAUsers_WhenNoUsersAreLoggedIn() when(restTemplate.postForEntity(ArgumentMatchers.eq(RC_URL_CHAT_USER_LOGIN), ArgumentMatchers.eq(requestTechnical), ArgumentMatchers.>any())) - .thenReturn(new ResponseEntity(LOGIN_RESPONSE_DTO_TECHNICAL_USER_A, - HttpStatus.OK)); + .thenReturn(new ResponseEntity(LOGIN_RESPONSE_DTO_TECHNICAL_USER_A, + HttpStatus.OK)); // Prepare intercept login system user HttpEntity> requestSys = @@ -193,8 +197,8 @@ public void updateCredentials_Should_LoginAUsers_WhenNoUsersAreLoggedIn() when(restTemplate.postForEntity(ArgumentMatchers.eq(RC_URL_CHAT_USER_LOGIN), ArgumentMatchers.eq(requestSys), ArgumentMatchers.>any())) - .thenReturn(new ResponseEntity(LOGIN_RESPONSE_DTO_SYSTEM_USER_A, - HttpStatus.OK)); + .thenReturn(new ResponseEntity(LOGIN_RESPONSE_DTO_SYSTEM_USER_A, + HttpStatus.OK)); // Execute test rcCredentialHelper.updateCredentials(); @@ -221,13 +225,13 @@ public void updateCredentials_Should_LoginBUsers_WhenAUsersAreLoggedIn() // Prepare intercept login technical user HttpEntity> requestTechnical = - new HttpEntity>( + new HttpEntity<>( MULTI_VALUE_MAP_WITH_TECHNICAL_USER_CREDENTIALS, headers); when(restTemplate.postForEntity(ArgumentMatchers.eq(RC_URL_CHAT_USER_LOGIN), ArgumentMatchers.eq(requestTechnical), ArgumentMatchers.>any())) - .thenReturn(new ResponseEntity(LOGIN_RESPONSE_DTO_TECHNICAL_USER_B, - HttpStatus.OK)); + .thenReturn(new ResponseEntity<>(LOGIN_RESPONSE_DTO_TECHNICAL_USER_B, + HttpStatus.OK)); // Prepare intercept login system user HttpEntity> requestSys = @@ -236,22 +240,22 @@ public void updateCredentials_Should_LoginBUsers_WhenAUsersAreLoggedIn() when(restTemplate.postForEntity(ArgumentMatchers.eq(RC_URL_CHAT_USER_LOGIN), ArgumentMatchers.eq(requestSys), ArgumentMatchers.>any())) - .thenReturn(new ResponseEntity(LOGIN_RESPONSE_DTO_SYSTEM_USER_B, - HttpStatus.OK)); + .thenReturn(new ResponseEntity<>(LOGIN_RESPONSE_DTO_SYSTEM_USER_B, + HttpStatus.OK)); RocketChatCredentials systemA = RocketChatCredentials.builder().rocketChatToken(SYSTEM_USER_A_TOKEN) .rocketChatUserId(SYSTEM_USER_A_ID).rocketChatUsername(SYSTEM_USER_A_USERNAME) - .timeStampCreated(LocalDateTime.now().minusMinutes(5)).build(); - FieldSetter.setField(rcCredentialHelper, - rcCredentialHelper.getClass().getDeclaredField(FIELD_NAME_SYSTEM_USER_A), systemA); + .timeStampCreated(nowInUtc().minusMinutes(5)).build(); + setField(rcCredentialHelper, FIELD_NAME_SYSTEM_USER_A, + new AtomicReference<>(systemA)); RocketChatCredentials technicalA = RocketChatCredentials.builder().rocketChatToken(TECHNICAL_USER_A_TOKEN) .rocketChatUserId(TECHNICAL_USER_A_ID).rocketChatUsername(TECHNICAL_USER_A_USERNAME) - .timeStampCreated(LocalDateTime.now().minusMinutes(5)).build(); - FieldSetter.setField(rcCredentialHelper, - rcCredentialHelper.getClass().getDeclaredField(FIELD_NAME_TECHNICAL_USER_A), technicalA); + .timeStampCreated(nowInUtc().minusMinutes(5)).build(); + setField(rcCredentialHelper, FIELD_NAME_TECHNICAL_USER_A, + new AtomicReference<>(technicalA)); // Get and check system user - pre test needs to be User A RocketChatCredentials systemUser = rcCredentialHelper.getSystemUser(); @@ -292,76 +296,71 @@ public void updateCredentials_Should_LogoutAndReLoginBUsers_WhenAllUsersArePrese RocketChatCredentials technicalA = RocketChatCredentials.builder().rocketChatToken(TECHNICAL_USER_A_TOKEN) .rocketChatUserId(TECHNICAL_USER_A_ID).rocketChatUsername(TECHNICAL_USER_A_USERNAME) - .timeStampCreated(LocalDateTime.now().minusMinutes(5)).build(); - FieldSetter.setField(rcCredentialHelper, - rcCredentialHelper.getClass().getDeclaredField(FIELD_NAME_TECHNICAL_USER_A), technicalA); + .timeStampCreated(nowInUtc().minusMinutes(5)).build(); + setField(rcCredentialHelper, FIELD_NAME_TECHNICAL_USER_A, + new AtomicReference<>(technicalA)); // create and set technical B user RocketChatCredentials technicalB = RocketChatCredentials.builder().rocketChatToken(TECHNICAL_USER_B_TOKEN) .rocketChatUserId(TECHNICAL_USER_B_ID).rocketChatUsername(TECHNICAL_USER_B_USERNAME) - .timeStampCreated(LocalDateTime.now().minusMinutes(1)).build(); - FieldSetter.setField(rcCredentialHelper, - rcCredentialHelper.getClass().getDeclaredField(FIELD_NAME_TECHNICAL_USER_B), technicalB); + .timeStampCreated(nowInUtc().minusMinutes(1)).build(); + setField(rcCredentialHelper, FIELD_NAME_TECHNICAL_USER_B, + new AtomicReference<>(technicalB)); // create and set system A user RocketChatCredentials systemA = RocketChatCredentials.builder().rocketChatToken(SYSTEM_USER_A_TOKEN) .rocketChatUserId(SYSTEM_USER_A_ID).rocketChatUsername(SYSTEM_USER_A_USERNAME) - .timeStampCreated(LocalDateTime.now().minusMinutes(5)).build(); - FieldSetter.setField(rcCredentialHelper, - rcCredentialHelper.getClass().getDeclaredField(FIELD_NAME_SYSTEM_USER_A), systemA); + .timeStampCreated(nowInUtc().minusMinutes(5)).build(); + setField(rcCredentialHelper, FIELD_NAME_SYSTEM_USER_A, + new AtomicReference<>(systemA)); // create and set system B user RocketChatCredentials systemB = RocketChatCredentials.builder().rocketChatToken(SYSTEM_USER_B_TOKEN) .rocketChatUserId(SYSTEM_USER_B_ID).rocketChatUsername(SYSTEM_USER_A_USERNAME) - .timeStampCreated(LocalDateTime.now().minusMinutes(1)).build(); - - FieldSetter.setField(rcCredentialHelper, - rcCredentialHelper.getClass().getDeclaredField(FIELD_NAME_SYSTEM_USER_B), systemB); + .timeStampCreated(nowInUtc().minusMinutes(1)).build(); + setField(rcCredentialHelper, FIELD_NAME_SYSTEM_USER_B, + new AtomicReference<>(systemB)); // prepare logout intercept for system user HttpHeaders headersLogoutSys = new HttpHeaders(); - headersLogoutSys.setContentType(MediaType.APPLICATION_JSON_UTF8); + headersLogoutSys.setContentType(MediaType.APPLICATION_JSON); headersLogoutSys.add(FIELD_VALUE_ROCKET_CHAT_HEADER_AUTH_TOKEN, SYSTEM_USER_A_TOKEN); headersLogoutSys.add(FIELD_VALUE_ROCKET_CHAT_HEADER_USER_ID, SYSTEM_USER_A_ID); - HttpEntity requestSysLogout = new HttpEntity(headersLogoutSys); + HttpEntity requestSysLogout = new HttpEntity<>(headersLogoutSys); when(restTemplate.postForEntity(ArgumentMatchers.eq(RC_URL_CHAT_USER_LOGOUT), ArgumentMatchers.eq(requestSysLogout), ArgumentMatchers.>any())) - .thenReturn(new ResponseEntity(LOGOUT_RESPONSE_DTO_SYSTEM_USER_A, - HttpStatus.OK)); + .thenReturn(new ResponseEntity<>(LOGOUT_RESPONSE_DTO_SYSTEM_USER_A, + HttpStatus.OK)); // prepare logout intercept for technical user HttpHeaders headersLogoutTec = new HttpHeaders(); - headersLogoutTec.setContentType(MediaType.APPLICATION_JSON_UTF8); + headersLogoutTec.setContentType(MediaType.APPLICATION_JSON); headersLogoutTec.add(FIELD_VALUE_ROCKET_CHAT_HEADER_AUTH_TOKEN, TECHNICAL_USER_A_TOKEN); headersLogoutTec.add(FIELD_VALUE_ROCKET_CHAT_HEADER_USER_ID, TECHNICAL_USER_A_ID); - HttpEntity requestTechnicalLogout = new HttpEntity(headersLogoutTec); + HttpEntity requestTechnicalLogout = new HttpEntity<>(headersLogoutTec); when(restTemplate.postForEntity(ArgumentMatchers.eq(RC_URL_CHAT_USER_LOGOUT), ArgumentMatchers.eq(requestTechnicalLogout), ArgumentMatchers.>any())) - .thenReturn(new ResponseEntity(LOGOUT_RESPONSE_DTO_TECHNICAL_USER_A, - HttpStatus.OK)); + .thenReturn(new ResponseEntity<>(LOGOUT_RESPONSE_DTO_TECHNICAL_USER_A, HttpStatus.OK)); // prepare login intercept for system user HttpEntity> requestSysLogin = - new HttpEntity>(MULTI_VALUE_MAP_WITH_SYSTEM_USER_CREDENTIALS, - headers); + new HttpEntity<>(MULTI_VALUE_MAP_WITH_SYSTEM_USER_CREDENTIALS, headers); when(restTemplate.postForEntity(ArgumentMatchers.eq(RC_URL_CHAT_USER_LOGIN), ArgumentMatchers.eq(requestSysLogin), ArgumentMatchers.>any())) - .thenReturn(new ResponseEntity(LOGIN_RESPONSE_DTO_SYSTEM_USER_B, - HttpStatus.OK)); + .thenReturn(new ResponseEntity<>(LOGIN_RESPONSE_DTO_SYSTEM_USER_B, HttpStatus.OK)); // prepare login intercept for technical user HttpEntity> requestTechnicalLogin = - new HttpEntity>( - MULTI_VALUE_MAP_WITH_TECHNICAL_USER_CREDENTIALS, headers); + new HttpEntity<>(MULTI_VALUE_MAP_WITH_TECHNICAL_USER_CREDENTIALS, headers); when(restTemplate.postForEntity(ArgumentMatchers.eq(RC_URL_CHAT_USER_LOGIN), ArgumentMatchers.eq(requestTechnicalLogin), ArgumentMatchers.>any())) - .thenReturn(new ResponseEntity(LOGIN_RESPONSE_DTO_TECHNICAL_USER_B, - HttpStatus.OK)); + .thenReturn(new ResponseEntity<>(LOGIN_RESPONSE_DTO_TECHNICAL_USER_B, + HttpStatus.OK)); // Execute test rcCredentialHelper.updateCredentials(); @@ -390,9 +389,7 @@ public void updateCredentials_Should_LogoutAndReLoginBUsers_WhenAllUsersArePrese } /** - * * Method: createPrivateGroup - * **/ @Test @@ -408,10 +405,8 @@ public void getTechnicalUser_Should_ThrowRocketChatUserNotInitializedException_W @Test public void getTechnicalUser_Should_ReturnUserA_WhenOnlyUserAIsInitialized() throws Exception { - - FieldSetter.setField(rcCredentialHelper, - rcCredentialHelper.getClass().getDeclaredField(FIELD_NAME_TECHNICAL_USER_A), - RC_CREDENTIALS_TECHNICAL_A); + setField(rcCredentialHelper, FIELD_NAME_TECHNICAL_USER_A, + new AtomicReference<>(RC_CREDENTIALS_TECHNICAL_A)); RocketChatCredentials technicalUser = rcCredentialHelper.getTechnicalUser(); @@ -421,10 +416,8 @@ public void getTechnicalUser_Should_ReturnUserA_WhenOnlyUserAIsInitialized() @Test public void getTechnicalUser_Should_ReturnUserB_WhenOnlyUserBIsInitialized() throws Exception { - - FieldSetter.setField(rcCredentialHelper, - rcCredentialHelper.getClass().getDeclaredField(FIELD_NAME_TECHNICAL_USER_B), - RC_CREDENTIALS_TECHNICAL_B); + setField(rcCredentialHelper, FIELD_NAME_TECHNICAL_USER_B, + new AtomicReference<>(RC_CREDENTIALS_TECHNICAL_B)); RocketChatCredentials technicalUser = rcCredentialHelper.getTechnicalUser(); @@ -433,13 +426,10 @@ public void getTechnicalUser_Should_ReturnUserB_WhenOnlyUserBIsInitialized() @Test public void getTechnicalUser_Should_ReturnUserA_WhenUserAIsNewer() throws Exception { - FieldSetter.setField(rcCredentialHelper, - rcCredentialHelper.getClass().getDeclaredField(FIELD_NAME_TECHNICAL_USER_A), - RC_CREDENTIALS_TECHNICAL_A); - - FieldSetter.setField(rcCredentialHelper, - rcCredentialHelper.getClass().getDeclaredField(FIELD_NAME_TECHNICAL_USER_C), - RC_CREDENTIALS_TECHNICAL_C); + setField(rcCredentialHelper, FIELD_NAME_TECHNICAL_USER_A, + new AtomicReference<>(RC_CREDENTIALS_TECHNICAL_A)); + setField(rcCredentialHelper, FIELD_NAME_TECHNICAL_USER_C, + new AtomicReference<>(RC_CREDENTIALS_TECHNICAL_C)); // Get User from Class (actual test) RocketChatCredentials technicalUser = rcCredentialHelper.getTechnicalUser(); @@ -450,13 +440,10 @@ public void getTechnicalUser_Should_ReturnUserA_WhenUserAIsNewer() throws Except @Test public void getTechnicalUser_Should_ReturnUserB_WhenUserBIsNewer() throws Exception { - FieldSetter.setField(rcCredentialHelper, - rcCredentialHelper.getClass().getDeclaredField(FIELD_NAME_TECHNICAL_USER_A), - RC_CREDENTIALS_TECHNICAL_A); - - FieldSetter.setField(rcCredentialHelper, - rcCredentialHelper.getClass().getDeclaredField(FIELD_NAME_TECHNICAL_USER_B), - RC_CREDENTIALS_TECHNICAL_B); + setField(rcCredentialHelper, FIELD_NAME_TECHNICAL_USER_A, + new AtomicReference<>(RC_CREDENTIALS_TECHNICAL_A)); + setField(rcCredentialHelper, FIELD_NAME_TECHNICAL_USER_B, + new AtomicReference<>(RC_CREDENTIALS_TECHNICAL_B)); // Get User from Class (actual test) RocketChatCredentials technicalUser = rcCredentialHelper.getTechnicalUser(); @@ -466,9 +453,7 @@ public void getTechnicalUser_Should_ReturnUserB_WhenUserBIsNewer() throws Except } /** - * * Method: getSystemUser - * **/ @Test @@ -484,10 +469,8 @@ public void getSystemUser_Should_ThrowRocketChatUserNotInitializedException_When @Test public void getSystemUser_Should_ReturnUserA_WhenOnlyUserAIsInitialized() throws Exception { - - FieldSetter.setField(rcCredentialHelper, - rcCredentialHelper.getClass().getDeclaredField(FIELD_NAME_SYSTEM_USER_A), - RC_CREDENTIALS_SYSTEM_A); + setField(rcCredentialHelper, FIELD_NAME_SYSTEM_USER_A, + new AtomicReference<>(RC_CREDENTIALS_SYSTEM_A)); RocketChatCredentials systemUser = rcCredentialHelper.getSystemUser(); @@ -497,10 +480,8 @@ public void getSystemUser_Should_ReturnUserA_WhenOnlyUserAIsInitialized() @Test public void getSystemUser_Should_ReturnUserB_WhenOnlyUserBIsInitialized() throws Exception { - - FieldSetter.setField(rcCredentialHelper, - rcCredentialHelper.getClass().getDeclaredField(FIELD_NAME_SYSTEM_USER_B), - RC_CREDENTIALS_SYSTEM_B); + setField(rcCredentialHelper, FIELD_NAME_SYSTEM_USER_B, + new AtomicReference<>(RC_CREDENTIALS_SYSTEM_B)); RocketChatCredentials systemUser = rcCredentialHelper.getSystemUser(); @@ -509,13 +490,10 @@ public void getSystemUser_Should_ReturnUserB_WhenOnlyUserBIsInitialized() @Test public void getSystemUser_Should_ReturnUserA_WhenUserAIsNewer() throws Exception { - FieldSetter.setField(rcCredentialHelper, - rcCredentialHelper.getClass().getDeclaredField(FIELD_NAME_SYSTEM_USER_A), - RC_CREDENTIALS_SYSTEM_A); - - FieldSetter.setField(rcCredentialHelper, - rcCredentialHelper.getClass().getDeclaredField(FIELD_NAME_SYSTEM_USER_B), - RC_CREDENTIALS_SYSTEM_C); + setField(rcCredentialHelper, FIELD_NAME_SYSTEM_USER_A, + new AtomicReference<>(RC_CREDENTIALS_SYSTEM_A)); + setField(rcCredentialHelper, FIELD_NAME_SYSTEM_USER_B, + new AtomicReference<>(RC_CREDENTIALS_SYSTEM_C)); // Get User from Class (actual test) RocketChatCredentials systemUser = rcCredentialHelper.getSystemUser(); @@ -526,13 +504,10 @@ public void getSystemUser_Should_ReturnUserA_WhenUserAIsNewer() throws Exception @Test public void getSystemUser_Should_ReturnUserB_WhenUserBIsNewer() throws Exception { - FieldSetter.setField(rcCredentialHelper, - rcCredentialHelper.getClass().getDeclaredField(FIELD_NAME_SYSTEM_USER_A), - RC_CREDENTIALS_SYSTEM_A); - - FieldSetter.setField(rcCredentialHelper, - rcCredentialHelper.getClass().getDeclaredField(FIELD_NAME_SYSTEM_USER_B), - RC_CREDENTIALS_SYSTEM_B); + setField(rcCredentialHelper, FIELD_NAME_SYSTEM_USER_A, + new AtomicReference<>(RC_CREDENTIALS_SYSTEM_A)); + setField(rcCredentialHelper, FIELD_NAME_SYSTEM_USER_B, + new AtomicReference<>(RC_CREDENTIALS_SYSTEM_B)); // Get User from Class (actual test) RocketChatCredentials systemUser = rcCredentialHelper.getSystemUser(); diff --git a/src/test/java/de/caritas/cob/userservice/api/service/helper/RocketChatRollbackHelperTest.java b/src/test/java/de/caritas/cob/userservice/api/service/helper/RocketChatRollbackServiceTest.java similarity index 86% rename from src/test/java/de/caritas/cob/userservice/api/service/helper/RocketChatRollbackHelperTest.java rename to src/test/java/de/caritas/cob/userservice/api/service/helper/RocketChatRollbackServiceTest.java index 6b05e6e65..d615f2730 100644 --- a/src/test/java/de/caritas/cob/userservice/api/service/helper/RocketChatRollbackHelperTest.java +++ b/src/test/java/de/caritas/cob/userservice/api/service/helper/RocketChatRollbackServiceTest.java @@ -12,7 +12,9 @@ import de.caritas.cob.userservice.api.exception.rocketchat.RocketChatRemoveUserFromGroupException; import de.caritas.cob.userservice.api.model.rocketchat.group.GroupMemberDTO; import de.caritas.cob.userservice.api.service.LogService; -import de.caritas.cob.userservice.api.service.RocketChatService; +import de.caritas.cob.userservice.api.service.rocketchat.RocketChatCredentialsProvider; +import de.caritas.cob.userservice.api.service.rocketchat.RocketChatRollbackService; +import de.caritas.cob.userservice.api.service.rocketchat.RocketChatService; import java.util.Arrays; import java.util.List; import org.junit.Before; @@ -25,7 +27,7 @@ import org.slf4j.Logger; @RunWith(MockitoJUnitRunner.class) -public class RocketChatRollbackHelperTest { +public class RocketChatRollbackServiceTest { private final String MEMBER_ID = "asdkds9"; private final String STATUS = "offline"; @@ -45,13 +47,13 @@ public class RocketChatRollbackHelperTest { new RocketChatAddUserToGroupException(EXCEPTION); @InjectMocks - private RocketChatRollbackHelper rocketChatRollbackHelper; + private RocketChatRollbackService rocketChatRollbackService; @Mock private RocketChatService rocketChatService; @Mock Logger logger; @Mock - private RocketChatCredentialsHelper rcCredentialHelper; + private RocketChatCredentialsProvider rcCredentialHelper; @Before public void setup() { @@ -73,7 +75,7 @@ public void rollbackRemoveUsersFromRocketChatGroup_Should_LogInternalServerError when(rcCredentialHelper.getTechnicalUser()).thenReturn(RC_CREDENTIALS_TECHNICAL_A); - rocketChatRollbackHelper.rollbackRemoveUsersFromRocketChatGroup(GROUP_ID, + rocketChatRollbackService.rollbackRemoveUsersFromRocketChatGroup(GROUP_ID, GROUP_MEMBER_DTO_LIST); verify(logger, atLeastOnce()).error(anyString(), anyString(), anyString()); @@ -90,7 +92,7 @@ public void rollbackRemoveUsersFromRocketChatGroup_Should_LogInternalServerError when(rcCredentialHelper.getTechnicalUser()).thenReturn(RC_CREDENTIALS_TECHNICAL_A); - rocketChatRollbackHelper.rollbackRemoveUsersFromRocketChatGroup(GROUP_ID, + rocketChatRollbackService.rollbackRemoveUsersFromRocketChatGroup(GROUP_ID, GROUP_MEMBER_DTO_LIST); verify(logger, atLeastOnce()).error(anyString(), anyString(), anyString()); @@ -107,7 +109,7 @@ public void rollbackRemoveUsersFromRocketChatGroup_Should_LogInternalServerError when(rcCredentialHelper.getTechnicalUser()).thenReturn(RC_CREDENTIALS_TECHNICAL_A); - rocketChatRollbackHelper.rollbackRemoveUsersFromRocketChatGroup(GROUP_ID, + rocketChatRollbackService.rollbackRemoveUsersFromRocketChatGroup(GROUP_ID, GROUP_MEMBER_DTO_LIST); verify(logger, atLeastOnce()).error(anyString(), anyString(), anyString()); @@ -124,7 +126,7 @@ public void rollbackRemoveUsersFromRocketChatGroup_Should_AddMissingUserToGroup_ when(rcCredentialHelper.getTechnicalUser()).thenReturn(RC_CREDENTIALS_TECHNICAL_A); - rocketChatRollbackHelper.rollbackRemoveUsersFromRocketChatGroup(GROUP_ID, + rocketChatRollbackService.rollbackRemoveUsersFromRocketChatGroup(GROUP_ID, GROUP_MEMBER_DTO_LIST); verify(logger, atLeastOnce()).error(anyString(), anyString(), anyString()); diff --git a/src/test/java/de/caritas/cob/userservice/api/service/liveevents/RelevantUserAccountIdsByChatProviderTest.java b/src/test/java/de/caritas/cob/userservice/api/service/liveevents/RelevantUserAccountIdsByChatProviderTest.java index abfac79a2..a01b58449 100644 --- a/src/test/java/de/caritas/cob/userservice/api/service/liveevents/RelevantUserAccountIdsByChatProviderTest.java +++ b/src/test/java/de/caritas/cob/userservice/api/service/liveevents/RelevantUserAccountIdsByChatProviderTest.java @@ -9,12 +9,11 @@ import static org.hamcrest.Matchers.is; import de.caritas.cob.userservice.api.exception.rocketchat.RocketChatGetGroupMembersException; -import de.caritas.cob.userservice.api.helper.AuthenticatedUser; import de.caritas.cob.userservice.api.model.rocketchat.group.GroupMemberDTO; import de.caritas.cob.userservice.api.repository.consultant.Consultant; import de.caritas.cob.userservice.api.repository.user.User; import de.caritas.cob.userservice.api.service.ConsultantService; -import de.caritas.cob.userservice.api.service.RocketChatService; +import de.caritas.cob.userservice.api.service.rocketchat.RocketChatService; import de.caritas.cob.userservice.api.service.UserService; import java.util.List; import java.util.Optional; @@ -84,7 +83,7 @@ private Consultant consultantWithId(String consultantId) { } private User userWithId(String userId) { - return new User(userId, null, null, null); + return new User(userId, null, null, null, false); } @Test diff --git a/src/test/java/de/caritas/cob/userservice/api/service/liveevents/RelevantUserAccountIdsBySessionProviderTest.java b/src/test/java/de/caritas/cob/userservice/api/service/liveevents/RelevantUserAccountIdsBySessionProviderTest.java index f6ce75139..9522cabf7 100644 --- a/src/test/java/de/caritas/cob/userservice/api/service/liveevents/RelevantUserAccountIdsBySessionProviderTest.java +++ b/src/test/java/de/caritas/cob/userservice/api/service/liveevents/RelevantUserAccountIdsBySessionProviderTest.java @@ -51,7 +51,7 @@ private Optional buildSessionWithUserAndConsultant() { Consultant consultant = new Consultant(); consultant.setId("consultant"); session.setConsultant(consultant); - User user = new User("user", null, null, null); + User user = new User("user", null, null, null, false); session.setUser(user); return Optional.of(session); } diff --git a/src/test/java/de/caritas/cob/userservice/testHelper/TestConstants.java b/src/test/java/de/caritas/cob/userservice/testHelper/TestConstants.java index 94cef2ee1..dd8a63d1e 100644 --- a/src/test/java/de/caritas/cob/userservice/testHelper/TestConstants.java +++ b/src/test/java/de/caritas/cob/userservice/testHelper/TestConstants.java @@ -1,5 +1,10 @@ package de.caritas.cob.userservice.testHelper; +import static de.caritas.cob.userservice.api.repository.session.ConsultingType.SUCHT; +import static de.caritas.cob.userservice.api.repository.session.ConsultingType.U25; +import static de.caritas.cob.userservice.api.repository.session.SessionStatus.IN_PROGRESS; +import static de.caritas.cob.userservice.localdatetime.CustomLocalDateTime.nowInUtc; + import de.caritas.cob.userservice.api.container.RocketChatCredentials; import de.caritas.cob.userservice.api.helper.AuthenticatedUser; import de.caritas.cob.userservice.api.helper.Helper; @@ -30,14 +35,14 @@ import de.caritas.cob.userservice.api.model.user.SessionConsultantForUserDTO; import de.caritas.cob.userservice.api.repository.chat.Chat; import de.caritas.cob.userservice.api.repository.chat.ChatInterval; -import de.caritas.cob.userservice.api.repository.chatAgency.ChatAgency; +import de.caritas.cob.userservice.api.repository.chatagency.ChatAgency; import de.caritas.cob.userservice.api.repository.consultant.Consultant; -import de.caritas.cob.userservice.api.repository.consultantAgency.ConsultantAgency; +import de.caritas.cob.userservice.api.repository.consultantagency.ConsultantAgency; import de.caritas.cob.userservice.api.repository.session.ConsultingType; import de.caritas.cob.userservice.api.repository.session.Session; import de.caritas.cob.userservice.api.repository.session.SessionStatus; import de.caritas.cob.userservice.api.repository.user.User; -import de.caritas.cob.userservice.api.repository.userAgency.UserAgency; +import de.caritas.cob.userservice.api.repository.useragency.UserAgency; import java.time.LocalDate; import java.time.LocalDateTime; import java.time.LocalTime; @@ -85,9 +90,9 @@ public class TestConstants { /** * ConsultingTypes */ - public static final String CONSULTING_TYPE_SUCHT_URL_NAME = ConsultingType.SUCHT.getUrlName(); - public static final ConsultingType CONSULTING_TYPE_SUCHT = ConsultingType.SUCHT; - public static final ConsultingType CONSULTING_TYPE_U25 = ConsultingType.U25; + public static final String CONSULTING_TYPE_SUCHT_URL_NAME = SUCHT.getUrlName(); + public static final ConsultingType CONSULTING_TYPE_SUCHT = SUCHT; + public static final ConsultingType CONSULTING_TYPE_U25 = U25; public static final ConsultingType CONSULTING_TYPE_PREGNANCY = ConsultingType.PREGNANCY; public static final ConsultingType CONSULTING_TYPE_AIDS = ConsultingType.AIDS; public static final ConsultingType CONSULTING_TYPE_CHILDREN = ConsultingType.CHILDREN; @@ -212,43 +217,42 @@ public class TestConstants { public static final RocketChatCredentials RC_CREDENTIALS = RocketChatCredentials.builder().rocketChatToken(RC_TOKEN).rocketChatUserId(RC_USER_ID) - .rocketChatUsername(RC_USERNAME).timeStampCreated(LocalDateTime.now()).build(); + .rocketChatUsername(RC_USERNAME).timeStampCreated(nowInUtc()).build(); public static final RocketChatCredentials RC_CREDENTIALS_WITH_EMPTY_USER_VALUES = RocketChatCredentials.builder() .rocketChatToken(RC_TOKEN) - .timeStampCreated(LocalDateTime.now()).build(); + .timeStampCreated(nowInUtc()).build(); public static final RocketChatCredentials RC_CREDENTIALS_TECHNICAL_A = RocketChatCredentials.builder().rocketChatToken(TECHNICAL_USER_A_TOKEN) .rocketChatUserId(TECHNICAL_USER_A_ID).rocketChatUsername(TECHNICAL_USER_A_USERNAME) - .timeStampCreated(LocalDateTime.now().minusMinutes(5)).build(); + .timeStampCreated(nowInUtc().minusMinutes(5)).build(); public static final RocketChatCredentials RC_CREDENTIALS_TECHNICAL_B = RocketChatCredentials.builder().rocketChatToken(TECHNICAL_USER_B_TOKEN) .rocketChatUserId(TECHNICAL_USER_B_ID).rocketChatUsername(TECHNICAL_USER_B_USERNAME) - .timeStampCreated(LocalDateTime.now().minusMinutes(1)).build(); + .timeStampCreated(nowInUtc().minusMinutes(1)).build(); public static final RocketChatCredentials RC_CREDENTIALS_TECHNICAL_C = RocketChatCredentials.builder().rocketChatToken(TECHNICAL_USER_C_TOKEN) .rocketChatUserId(TECHNICAL_USER_C_ID).rocketChatUsername(TECHNICAL_USER_C_USERNAME) - .timeStampCreated(LocalDateTime.now().minusMinutes(10)).build(); + .timeStampCreated(nowInUtc().minusMinutes(10)).build(); public static final RocketChatCredentials RC_CREDENTIALS_SYSTEM_A = RocketChatCredentials.builder().rocketChatToken(SYSTEM_USER_A_TOKEN) .rocketChatUserId(SYSTEM_USER_A_ID).rocketChatUsername(SYSTEM_USER_A_USERNAME) - .timeStampCreated(LocalDateTime.now().minusMinutes(5)).build(); + .timeStampCreated(nowInUtc().minusMinutes(5)).build(); public static final RocketChatCredentials RC_CREDENTIALS_SYSTEM_B = RocketChatCredentials.builder().rocketChatToken(SYSTEM_USER_B_TOKEN) .rocketChatUserId(SYSTEM_USER_B_ID).rocketChatUsername(SYSTEM_USER_A_USERNAME) - .timeStampCreated(LocalDateTime.now().minusMinutes(1)).build(); + .timeStampCreated(nowInUtc().minusMinutes(1)).build(); public static final RocketChatCredentials RC_CREDENTIALS_SYSTEM_C = RocketChatCredentials.builder().rocketChatToken(SYSTEM_USER_C_TOKEN) .rocketChatUserId(SYSTEM_USER_C_ID).rocketChatUsername(SYSTEM_USER_C_USERNAME) - .timeStampCreated(LocalDateTime.now().minusMinutes(10)).build(); - + .timeStampCreated(nowInUtc().minusMinutes(10)).build(); /* * Agencies @@ -331,7 +335,8 @@ public class TestConstants { USERNAME, "first name", "last name", EMAIL, false, false, null, false, null, null, null, null, null, null); public static final Consultant CONSULTANT_NO_RC_USER_ID = new Consultant(CONSULTANT_ID, "", - USERNAME, "first name", "last name", EMAIL, false, false, null, false, null, null, null, null, null, null); + USERNAME, "first name", "last name", EMAIL, false, false, null, false, null, null, null, null, + null, null); public static final Consultant MAIN_CONSULTANT = new Consultant(MAIN_CONSULTANT_ID, RC_USER_ID_MAIN_CONSULTANT, USERNAME, "first name", "last name", EMAIL, false, false, null, false, null, null, null, null, null, null); @@ -423,15 +428,16 @@ public class TestConstants { * ConsultantAgency */ public static final ConsultantAgency[] CONSULTANT_AGENCY = new ConsultantAgency[]{ - new ConsultantAgency(1L, CONSULTANT, AGENCY_ID, LocalDateTime.now(), LocalDateTime.now())}; + new ConsultantAgency(1L, CONSULTANT, AGENCY_ID, nowInUtc(), nowInUtc(), nowInUtc())}; public static final ConsultantAgency CONSULTANT_AGENCY_2 = - new ConsultantAgency(2L, CONSULTANT, AGENCY_ID_2, LocalDateTime.now(), LocalDateTime.now()); + new ConsultantAgency(2L, CONSULTANT, AGENCY_ID_2, nowInUtc(), nowInUtc(), nowInUtc()); public static final ConsultantAgency CONSULTANT_AGENCY_3 = - new ConsultantAgency(3L, CONSULTANT, AGENCY_ID_3, LocalDateTime.now(), LocalDateTime.now()); + new ConsultantAgency(3L, CONSULTANT, AGENCY_ID_3, nowInUtc(), nowInUtc(), nowInUtc()); public static final Set CONSULTANT_AGENCY_SET = new HashSet<>(Arrays.asList(CONSULTANT_AGENCY)); public static final Consultant CONSULTANT_WITH_AGENCY = new Consultant(CONSULTANT_ID, - ROCKETCHAT_ID, USERNAME, "first name", "last name", EMAIL, false, false, "absent", false, null, + ROCKETCHAT_ID, USERNAME, "first name", "last name", EMAIL, false, false, "absent", false, + null, null, new HashSet<>(Arrays.asList(CONSULTANT_AGENCY)), null, null, null); public static final Consultant CONSULTANT_WITH_AGENCY_2 = new Consultant(CONSULTANT_ID_2, ROCKETCHAT_ID, USERNAME, "first name", "last name", EMAIL, false, false, null, false, null, @@ -457,32 +463,34 @@ public class TestConstants { public static final Long ENQUIRY_ID = 1L; public static final Long ENQUIRY_ID_2 = 2L; public static final Session SESSION = - new Session(SESSION_ID, null, null, null, null, null, null, null, null); + new Session(SESSION_ID, null, null, SUCHT, POSTCODE, null, IN_PROGRESS, null, null, null, null, false, + false, null, null); public static final Session SESSION_WITH_CONSULTANT = - new Session(SESSION_ID, null, CONSULTANT_2, ConsultingType.SUCHT, POSTCODE, AGENCY_ID, - SessionStatus.IN_PROGRESS, new Date(), RC_GROUP_ID); + new Session(SESSION_ID, null, CONSULTANT_2, SUCHT, POSTCODE, AGENCY_ID, + IN_PROGRESS, new Date(), RC_GROUP_ID, null, null, false, false, null, null); public static final Session ENQUIRY_SESSION_WITH_CONSULTANT = - new Session(SESSION_ID, null, CONSULTANT_2, ConsultingType.SUCHT, POSTCODE, AGENCY_ID, - SessionStatus.NEW, new Date(), RC_GROUP_ID); + new Session(SESSION_ID, null, CONSULTANT_2, SUCHT, POSTCODE, AGENCY_ID, + SessionStatus.NEW, new Date(), RC_GROUP_ID, null, null, false, false, null, null); public static final Session SESSION_WITHOUT_CONSULTANT = new Session(SESSION_ID, USER_WITH_RC_ID, - null, ConsultingType.U25, POSTCODE, AGENCY_ID, SessionStatus.NEW, null, RC_GROUP_ID, null, + null, U25, POSTCODE, AGENCY_ID, SessionStatus.NEW, null, RC_GROUP_ID, null, null, IS_TEAM_SESSION, IS_MONITORING, null, null); public static final Session FEEDBACKSESSION_WITHOUT_CONSULTANT = new Session(SESSION_ID, - USER_WITH_RC_ID, null, ConsultingType.U25, POSTCODE, AGENCY_ID, SessionStatus.NEW, new Date(), + USER_WITH_RC_ID, null, U25, POSTCODE, AGENCY_ID, SessionStatus.NEW, new Date(), RC_GROUP_ID, RC_FEEDBACK_GROUP_ID, null, IS_TEAM_SESSION, IS_MONITORING, null, null); public static final Session FEEDBACKSESSION_WITH_CONSULTANT = - new Session(SESSION_ID, USER_WITH_RC_ID, CONSULTANT_2, ConsultingType.U25, POSTCODE, - AGENCY_ID, SessionStatus.IN_PROGRESS, new Date(), RC_GROUP_ID, RC_FEEDBACK_GROUP_ID, null, + new Session(SESSION_ID, USER_WITH_RC_ID, CONSULTANT_2, U25, POSTCODE, + AGENCY_ID, IN_PROGRESS, new Date(), RC_GROUP_ID, RC_FEEDBACK_GROUP_ID, null, IS_TEAM_SESSION, IS_MONITORING, null, null); public static final Session SESSION_WITHOUT_CONSULTANT_NO_RC_USER_ID = - new Session(SESSION_ID, USER_NO_RC_USER_ID_2, null, ConsultingType.SUCHT, POSTCODE, AGENCY_ID, - SessionStatus.NEW, new Date(), RC_GROUP_ID, null, IS_NO_TEAM_SESSION, IS_MONITORING); + new Session(TEAM_SESSION_ID, USER_NO_RC_USER_ID_2, null, SUCHT, POSTCODE, + AGENCY_ID, SessionStatus.NEW, new Date(), RC_GROUP_ID, null, null, IS_NO_TEAM_SESSION, + IS_MONITORING, null, null); public static final Session U25_SESSION_WITH_CONSULTANT = new Session(SESSION_ID, USER_WITH_RC_ID, - CONSULTANT_2, ConsultingType.U25, POSTCODE, AGENCY_ID, SessionStatus.IN_PROGRESS, new Date(), + CONSULTANT_2, U25, POSTCODE, AGENCY_ID, IN_PROGRESS, new Date(), RC_GROUP_ID, RC_FEEDBACK_GROUP_ID, null, IS_TEAM_SESSION, IS_MONITORING, null, null); public static final Session U25_SESSION_WITHOUT_CONSULTANT = new Session(SESSION_ID, - USER_WITH_RC_ID, null, ConsultingType.U25, POSTCODE, AGENCY_ID, SessionStatus.NEW, new Date(), + USER_WITH_RC_ID, null, U25, POSTCODE, AGENCY_ID, SessionStatus.NEW, new Date(), RC_GROUP_ID, RC_FEEDBACK_GROUP_ID, null, IS_TEAM_SESSION, IS_MONITORING, null, null); public static final List SESSION_LIST = Collections.singletonList(SESSION); public static final Set SESSION_SET = new HashSet<>( @@ -632,15 +640,15 @@ USER_WITH_RC_ID, null, ConsultingType.U25, POSTCODE, AGENCY_ID, SessionStatus.NE public static final UserChatDTO USER_CHAT_DTO_1 = new UserChatDTO(CHAT_ID, CHAT_TOPIC, null, null, CHAT_DURATION_30, IS_REPETITIVE, IS_ACTIVE, ConsultingType.PREGNANCY.getValue(), null, Helper.getUnixTimestampFromDate(new Date(NOW.getTime() + 86300000)), MESSAGES_NOT_READ, - RC_GROUP_ID_4, null, false, null, LocalDateTime.now()); + RC_GROUP_ID_4, null, false, null, nowInUtc()); public static final UserChatDTO USER_CHAT_DTO_2 = new UserChatDTO(CHAT_ID_2, CHAT_TOPIC_2, null, null, CHAT_DURATION_60, IS_REPETITIVE, IS_NOT_ACTIVE, ConsultingType.DEBT.getValue(), null, Helper.getUnixTimestampFromDate(new Date(NOW.getTime() + 86200000)), MESSAGES_NOT_READ, - RC_GROUP_ID_5, null, false, null, LocalDateTime.now()); + RC_GROUP_ID_5, null, false, null, nowInUtc()); public static final UserChatDTO USER_CHAT_DTO_3 = new UserChatDTO(CHAT_ID_3, CHAT_TOPIC_3, null, null, CHAT_DURATION_90, IS_NOT_REPETITIVE, IS_NOT_ACTIVE, ConsultingType.CHILDREN.getValue(), null, Helper.getUnixTimestampFromDate(new Date(NOW.getTime() + 86410000)), MESSAGES_NOT_READ, - RC_GROUP_ID_6, null, false, null, LocalDateTime.now()); + RC_GROUP_ID_6, null, false, null, nowInUtc()); public static final UserSessionResponseDTO USER_CHAT_RESPONSE_DTO = new UserSessionResponseDTO() .chat(USER_CHAT_DTO_1) .agency(EMPTY_AGENCY_DTO) @@ -788,8 +796,9 @@ USER_WITH_RC_ID, null, ConsultingType.U25, POSTCODE, AGENCY_ID, SessionStatus.NE NOW_MINUS_1_DAY, MESSAGE, FILE_DTO, org.assertj.core.util.Arrays.array(ATTACHMENT_DTO), null); public static final List ROOMS_UPDATE_DTO_LIST_WITH_ATTACHMENT = - Collections.singletonList(new RoomsUpdateDTO(RC_GROUP_ID, "name1", "fname1", "P", USER_DTO_1, true, false, - new Date(), ROOMS_LAST_MESSAGE_DTO_WITH_ATTACHMENT)); + Collections.singletonList( + new RoomsUpdateDTO(RC_GROUP_ID, "name1", "fname1", "P", USER_DTO_1, true, false, + new Date(), ROOMS_LAST_MESSAGE_DTO_WITH_ATTACHMENT)); public static final List ROOMS_UPDATE_DTO_LIST_WITH_ATTACHMENT_FOR_CHAT = Arrays.asList( new RoomsUpdateDTO(RC_GROUP_ID_4, "name1", "fname1", "P", USER_DTO_1, true, false, @@ -915,7 +924,8 @@ USER_WITH_RC_ID, null, ConsultingType.U25, POSTCODE, AGENCY_ID, SessionStatus.NE public static final String USER_ROLE = "user"; public static final Set USER_ROLES = new HashSet<>(Collections.singletonList(USER_ROLE)); public static final String CONSULTANT_ROLE = "consultant"; - public static final Set CONSULTANT_ROLES = new HashSet<>(Collections.singletonList(CONSULTANT_ROLE)); + public static final Set CONSULTANT_ROLES = new HashSet<>( + Collections.singletonList(CONSULTANT_ROLE)); /** * Registration values */ @@ -933,7 +943,7 @@ USER_WITH_RC_ID, null, ConsultingType.U25, POSTCODE, AGENCY_ID, SessionStatus.NE */ public static final ConsultingTypeSettings CONSULTING_TYPE_SETTINGS_WITH_FORMAL_LANGUAGE = - new ConsultingTypeSettings(ConsultingType.SUCHT, false, null, null, true, null, false, null, + new ConsultingTypeSettings(SUCHT, false, null, null, true, null, false, null, true, null, null); public static final ConsultingTypeSettings CONSULTING_TYPE_SETTINGS_KREUZBUND = new ConsultingTypeSettings(ConsultingType.KREUZBUND, false, null, null, true, null, false, @@ -1049,10 +1059,10 @@ USER_WITH_RC_ID, null, ConsultingType.U25, POSTCODE, AGENCY_ID, SessionStatus.NE new ConsultingTypeSettings(CONSULTING_TYPE_U25, false, null, null, true, null, false, null, false, null, null); public static final ConsultingTypeSettings CONSULTING_TYPE_SETTINGS_WITH_MONITORING = - new ConsultingTypeSettings(ConsultingType.SUCHT, false, null, null, IS_MONITORING, null, + new ConsultingTypeSettings(SUCHT, false, null, null, IS_MONITORING, null, false, null, false, null, null); public static final ConsultingTypeSettings CONSULTING_TYPE_SETTINGS_WITHOUT_MONITORING = - new ConsultingTypeSettings(ConsultingType.SUCHT, false, null, null, IS_NOT_MONITORING, null, + new ConsultingTypeSettings(SUCHT, false, null, null, IS_NOT_MONITORING, null, false, null, false, null, null); public static List AGENCY_ID_LIST = Arrays.asList(1L, 2L); public static AbsenceDTO ABSENCE_DTO_WITH_HTML_AND_JS = new AbsenceDTO() @@ -1069,7 +1079,7 @@ USER_WITH_RC_ID, null, ConsultingType.U25, POSTCODE, AGENCY_ID, SessionStatus.NE CHAT_TOPIC_3, null, null, CHAT_DURATION_90, IS_NOT_REPETITIVE, IS_NOT_ACTIVE, ConsultingType.CHILDREN.getValue(), ENCRYPTED_MESSAGE, Helper.getUnixTimestampFromDate(new Date(NOW.getTime() + 86410000)), MESSAGES_NOT_READ, - RC_GROUP_ID_6, null, false, null, LocalDateTime.now()); + RC_GROUP_ID_6, null, false, null, nowInUtc()); public static final ConsultantSessionResponseDTO CONSULTANT_SESSION_RESPONSE_DTO_WITH_ENCRYPTED_CHAT_MESSAGE = new ConsultantSessionResponseDTO() .chat(USER_CHAT_DTO_WITH_ENCRYPTED_MESSAGE) diff --git a/src/test/resources/database/UserServiceDatabase.sql b/src/test/resources/database/UserServiceDatabase.sql index a1b48dcc1..f0ee31ada 100644 --- a/src/test/resources/database/UserServiceDatabase.sql +++ b/src/test/resources/database/UserServiceDatabase.sql @@ -42,6 +42,7 @@ CREATE TABLE CONSULTANT_AGENCY AGENCY_ID bigint(21) NOT NULL, CREATE_DATE datetime, UPDATE_DATE datetime, + DELETE_DATE datetime, PRIMARY KEY (ID), FOREIGN KEY (CONSULTANT_ID) REFERENCES CONSULTANT (CONSULTANT_ID) );