From 86cd926a6eacb6744aa4da7a5242781cacfdf46d Mon Sep 17 00:00:00 2001 From: aalicic Date: Fri, 24 Jun 2022 14:44:39 +0200 Subject: [PATCH 1/7] feat/VIC-786_Advice_seeker_books_a_meeting --- api/messageservice.yaml | 40 +++++++++++++++++++ .../api/controller/MessageController.java | 18 +++++++++ .../api/facade/PostGroupMessageFacade.java | 15 +++++++ .../api/service/RocketChatService.java | 2 +- 4 files changed, 74 insertions(+), 1 deletion(-) diff --git a/api/messageservice.yaml b/api/messageservice.yaml index 4e0591b..b1c68bb 100644 --- a/api/messageservice.yaml +++ b/api/messageservice.yaml @@ -358,6 +358,43 @@ paths: description: INTERNAL SERVER ERROR - server encountered unexpected condition security: - Bearer: [ ] + /messages/aliasWithContent/new: + post: + tags: + - message-controller + summary: 'Saves a new system message containing the provided message type in the alias and + some content. + [Authorization: Role: user, consultant, technical]' + operationId: saveAliasMessageWithContent + parameters: + - name: rcGroupId + in: header + required: true + schema: + type: string + requestBody: + required: true + content: + 'application/json': + schema: + $ref: '#/components/schemas/AliasMessageDTO' + responses: + 201: + description: CREATED - message was successfully created + content: + 'application/json': + schema: + $ref: '#/components/schemas/MessageResponseDTO' + 400: + description: BAD REQUEST - invalid/incomplete request or body object + 401: + description: UNAUTHORIZED - no/invalid Keycloak token + 403: + description: FORBIDDEN - no/invalid role/authorization + 500: + description: INTERNAL SERVER ERROR - server encountered unexpected condition + security: + - Bearer: [ ] components: schemas: @@ -491,6 +528,8 @@ components: $ref: '#/components/schemas/VideoCallMessageDTO' messageType: $ref: '#/components/schemas/MessageType' + content: + type: string ForwardMessageDTO: type: object @@ -560,6 +599,7 @@ components: - "USER_MUTED" - "USER_UNMUTED" - "E2EE_ACTIVATED" + - "APPOINTMENT_SET" UserDTO: type: object diff --git a/src/main/java/de/caritas/cob/messageservice/api/controller/MessageController.java b/src/main/java/de/caritas/cob/messageservice/api/controller/MessageController.java index 8abd483..9297f96 100644 --- a/src/main/java/de/caritas/cob/messageservice/api/controller/MessageController.java +++ b/src/main/java/de/caritas/cob/messageservice/api/controller/MessageController.java @@ -57,6 +57,8 @@ public class MessageController implements MessagesApi { public ResponseEntity getMessageStream(@RequestHeader String rcToken, @RequestHeader String rcUserId, @RequestParam String rcGroupId) { + //get all messages based on rcgroupid + MessageStreamDTO message = rocketChatService.getGroupMessages(rcToken, rcUserId, rcGroupId); return (message != null) ? new ResponseEntity<>(message, HttpStatus.OK) @@ -230,4 +232,20 @@ public ResponseEntity saveAliasOnlyMessage(@RequestHeader St return new ResponseEntity<>(response, HttpStatus.CREATED); } + + /** + * Posts an empty message which only contains an alias with the provided {@link MessageType} in + * the specified Rocket.Chat group. + * + * @param rcGroupId (required) Rocket.Chat group ID + * @param aliasOnlyMessageDTO {@link AliasOnlyMessageDTO} + * @return {@link ResponseEntity} with the {@link HttpStatus} + */ + @Override + public ResponseEntity saveAliasMessageWithContent(@RequestHeader String rcGroupId, + @Valid AliasMessageDTO aliasOnlyMessageDTO) { + var type = aliasOnlyMessageDTO.getMessageType(); + var response = postGroupMessageFacade.postAliasMessage(rcGroupId, type, aliasOnlyMessageDTO.getContent()); + return new ResponseEntity<>(response, HttpStatus.CREATED); + } } diff --git a/src/main/java/de/caritas/cob/messageservice/api/facade/PostGroupMessageFacade.java b/src/main/java/de/caritas/cob/messageservice/api/facade/PostGroupMessageFacade.java index 2c7af21..aaa2e3d 100644 --- a/src/main/java/de/caritas/cob/messageservice/api/facade/PostGroupMessageFacade.java +++ b/src/main/java/de/caritas/cob/messageservice/api/facade/PostGroupMessageFacade.java @@ -167,4 +167,19 @@ public MessageResponseDTO postAliasOnlyMessage(String rcGroupId, MessageType mes aliasMessageDTO); return mapper.messageResponseOf(response); } + + /** + * Posts an empty message which only contains an alias with the provided {@link MessageType} in + * the specified Rocket.Chat group. + * + * @param rcGroupId Rocket.Chat group ID + * @param messageType {@link MessageType} + * @return {@link MessageResponseDTO} + */ + public MessageResponseDTO postAliasMessage(String rcGroupId, MessageType messageType, String content) { + AliasMessageDTO aliasMessageDTO = new AliasMessageDTO().messageType(messageType).content(content); + var response = this.rocketChatService.postAliasOnlyMessageAsSystemUser(rcGroupId, + aliasMessageDTO); + return mapper.messageResponseOf(response); + } } diff --git a/src/main/java/de/caritas/cob/messageservice/api/service/RocketChatService.java b/src/main/java/de/caritas/cob/messageservice/api/service/RocketChatService.java index d5a8818..5ccbb85 100644 --- a/src/main/java/de/caritas/cob/messageservice/api/service/RocketChatService.java +++ b/src/main/java/de/caritas/cob/messageservice/api/service/RocketChatService.java @@ -168,7 +168,7 @@ private void setMessageType(MessagesDTO msg) { if (nonNull(msg.getAlias().getForwardMessageDTO())) { msg.getAlias().setMessageType(MessageType.FORWARD); - } else { + } else if (nonNull(msg.getAlias().getVideoCallMessageDTO())) { msg.getAlias().setMessageType(MessageType.VIDEOCALL); } } From 3c5d48c4b67718852e0bb8a2300fd41ca84cb52d Mon Sep 17 00:00:00 2001 From: aalicic Date: Fri, 24 Jun 2022 15:27:17 +0200 Subject: [PATCH 2/7] feat/VIC-364: Clean subdomain tenantid resolving in microservices --- .../api/controller/MessageControllerAuthorizationTestIT.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/test/java/de/caritas/cob/messageservice/api/controller/MessageControllerAuthorizationTestIT.java b/src/test/java/de/caritas/cob/messageservice/api/controller/MessageControllerAuthorizationTestIT.java index e1b7f3c..b7703be 100644 --- a/src/test/java/de/caritas/cob/messageservice/api/controller/MessageControllerAuthorizationTestIT.java +++ b/src/test/java/de/caritas/cob/messageservice/api/controller/MessageControllerAuthorizationTestIT.java @@ -22,6 +22,7 @@ import javax.servlet.http.Cookie; import org.jeasy.random.EasyRandom; import org.junit.Before; +import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; @@ -38,6 +39,7 @@ @TestPropertySource(properties = "spring.profiles.active=testing") @SpringBootTest @AutoConfigureMockMvc +@Ignore public class MessageControllerAuthorizationTestIT { protected final static String PATH_GET_MESSAGE_STREAM = "/messages"; From 3e8c903b9ed3236776bb5522099e77b64a326b76 Mon Sep 17 00:00:00 2001 From: aalicic Date: Fri, 24 Jun 2022 15:46:30 +0200 Subject: [PATCH 3/7] feat/VIC-364: Clean subdomain tenantid resolving in microservices --- .../de/caritas/cob/messageservice/config/SecurityConfig.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/de/caritas/cob/messageservice/config/SecurityConfig.java b/src/main/java/de/caritas/cob/messageservice/config/SecurityConfig.java index c74a498..646a92f 100644 --- a/src/main/java/de/caritas/cob/messageservice/config/SecurityConfig.java +++ b/src/main/java/de/caritas/cob/messageservice/config/SecurityConfig.java @@ -78,6 +78,8 @@ protected void configure(HttpSecurity http) throws Exception { .hasAuthority(USE_FEEDBACK) .antMatchers("/messages/aliasonly/new") .hasAnyAuthority(USER_DEFAULT, CONSULTANT_DEFAULT, TECHNICAL_DEFAULT) + .antMatchers("/messages/aliasWithContent/new") + .hasAnyAuthority(USER_DEFAULT, CONSULTANT_DEFAULT, TECHNICAL_DEFAULT) .anyRequest() .denyAll(); } From 6e5b8444e2677646a309049b690d539cdcbe212e Mon Sep 17 00:00:00 2001 From: aalicic Date: Wed, 29 Jun 2022 23:59:39 +0200 Subject: [PATCH 4/7] feat/VIC-786_Advice_seeker_books_a_meeting --- .../cob/messageservice/api/controller/MessageController.java | 4 +--- .../cob/messageservice/api/facade/PostGroupMessageFacade.java | 2 +- .../api/controller/MessageControllerAuthorizationTestIT.java | 2 -- 3 files changed, 2 insertions(+), 6 deletions(-) diff --git a/src/main/java/de/caritas/cob/messageservice/api/controller/MessageController.java b/src/main/java/de/caritas/cob/messageservice/api/controller/MessageController.java index 9297f96..fb783b2 100644 --- a/src/main/java/de/caritas/cob/messageservice/api/controller/MessageController.java +++ b/src/main/java/de/caritas/cob/messageservice/api/controller/MessageController.java @@ -57,8 +57,6 @@ public class MessageController implements MessagesApi { public ResponseEntity getMessageStream(@RequestHeader String rcToken, @RequestHeader String rcUserId, @RequestParam String rcGroupId) { - //get all messages based on rcgroupid - MessageStreamDTO message = rocketChatService.getGroupMessages(rcToken, rcUserId, rcGroupId); return (message != null) ? new ResponseEntity<>(message, HttpStatus.OK) @@ -234,7 +232,7 @@ public ResponseEntity saveAliasOnlyMessage(@RequestHeader St } /** - * Posts an empty message which only contains an alias with the provided {@link MessageType} in + * Posts a message which contains an alias with the provided {@link MessageType} in * the specified Rocket.Chat group. * * @param rcGroupId (required) Rocket.Chat group ID diff --git a/src/main/java/de/caritas/cob/messageservice/api/facade/PostGroupMessageFacade.java b/src/main/java/de/caritas/cob/messageservice/api/facade/PostGroupMessageFacade.java index aaa2e3d..5162250 100644 --- a/src/main/java/de/caritas/cob/messageservice/api/facade/PostGroupMessageFacade.java +++ b/src/main/java/de/caritas/cob/messageservice/api/facade/PostGroupMessageFacade.java @@ -169,7 +169,7 @@ public MessageResponseDTO postAliasOnlyMessage(String rcGroupId, MessageType mes } /** - * Posts an empty message which only contains an alias with the provided {@link MessageType} in + * Posts a message which contains an alias with the provided {@link MessageType} in * the specified Rocket.Chat group. * * @param rcGroupId Rocket.Chat group ID diff --git a/src/test/java/de/caritas/cob/messageservice/api/controller/MessageControllerAuthorizationTestIT.java b/src/test/java/de/caritas/cob/messageservice/api/controller/MessageControllerAuthorizationTestIT.java index b7703be..e1b7f3c 100644 --- a/src/test/java/de/caritas/cob/messageservice/api/controller/MessageControllerAuthorizationTestIT.java +++ b/src/test/java/de/caritas/cob/messageservice/api/controller/MessageControllerAuthorizationTestIT.java @@ -22,7 +22,6 @@ import javax.servlet.http.Cookie; import org.jeasy.random.EasyRandom; import org.junit.Before; -import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; @@ -39,7 +38,6 @@ @TestPropertySource(properties = "spring.profiles.active=testing") @SpringBootTest @AutoConfigureMockMvc -@Ignore public class MessageControllerAuthorizationTestIT { protected final static String PATH_GET_MESSAGE_STREAM = "/messages"; From c4467aee9aa3895126626c78cc9299d92c86583f Mon Sep 17 00:00:00 2001 From: aalicic Date: Thu, 30 Jun 2022 00:24:15 +0200 Subject: [PATCH 5/7] feat/VIC-786_Advice_seeker_books_a_meeting --- api/messageservice.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/messageservice.yaml b/api/messageservice.yaml index b1c68bb..72b1b8b 100644 --- a/api/messageservice.yaml +++ b/api/messageservice.yaml @@ -591,6 +591,7 @@ components: MessageType: type: string enum: + - "APPOINTMENT_SET" - "FINISHED_CONVERSATION" - "FORWARD" - "FURTHER_STEPS" @@ -599,7 +600,6 @@ components: - "USER_MUTED" - "USER_UNMUTED" - "E2EE_ACTIVATED" - - "APPOINTMENT_SET" UserDTO: type: object From 8993bb70719c096f6c02ea09dca69e0e3a459297 Mon Sep 17 00:00:00 2001 From: aalicic Date: Fri, 15 Jul 2022 11:31:03 +0200 Subject: [PATCH 6/7] feat/VIC-786_Advice_seeker_books_a_meeting --- api/messageservice.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/api/messageservice.yaml b/api/messageservice.yaml index 4b22144..0fd6012 100644 --- a/api/messageservice.yaml +++ b/api/messageservice.yaml @@ -641,6 +641,8 @@ components: type: string enum: - "APPOINTMENT_SET" + - "APPOINTMENT_CANCELLED" + - "APPOINTMENT_RESCHEDULED" - "FINISHED_CONVERSATION" - "FORWARD" - "FURTHER_STEPS" From de047e62571a7be8a3c9e0aac934beb1e81e8810 Mon Sep 17 00:00:00 2001 From: aalicic Date: Thu, 21 Jul 2022 11:24:39 +0200 Subject: [PATCH 7/7] chore: fix after merging --- .../de/caritas/cob/messageservice/Messenger.java | 2 +- .../api/controller/MessageController.java | 15 +++++++++------ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/main/java/de/caritas/cob/messageservice/Messenger.java b/src/main/java/de/caritas/cob/messageservice/Messenger.java index 0fb63e7..526d79c 100644 --- a/src/main/java/de/caritas/cob/messageservice/Messenger.java +++ b/src/main/java/de/caritas/cob/messageservice/Messenger.java @@ -1,4 +1,4 @@ -package de.caritas.cob.messageservice.api.facade; +package de.caritas.cob.messageservice; import static de.caritas.cob.messageservice.api.model.MessageType.MASTER_KEY_LOST; import static java.util.Objects.isNull; diff --git a/src/main/java/de/caritas/cob/messageservice/api/controller/MessageController.java b/src/main/java/de/caritas/cob/messageservice/api/controller/MessageController.java index a79162a..53e5952 100644 --- a/src/main/java/de/caritas/cob/messageservice/api/controller/MessageController.java +++ b/src/main/java/de/caritas/cob/messageservice/api/controller/MessageController.java @@ -271,22 +271,25 @@ public ResponseEntity patchMessage(String rcToken, String rcUserId, String ? ResponseEntity.noContent().build() : ResponseEntity.notFound().build(); } -} - /** - * Posts a message which contains an alias with the provided {@link MessageType} in - * the specified Rocket.Chat group. + * Posts a message which contains an alias with the provided {@link MessageType} in the specified + * Rocket.Chat group. * * @param rcGroupId (required) Rocket.Chat group ID * @param aliasOnlyMessageDTO {@link AliasOnlyMessageDTO} * @return {@link ResponseEntity} with the {@link HttpStatus} */ @Override - public ResponseEntity saveAliasMessageWithContent(@RequestHeader String rcGroupId, + public ResponseEntity saveAliasMessageWithContent( + @RequestHeader String rcGroupId, @Valid AliasMessageDTO aliasOnlyMessageDTO) { var type = aliasOnlyMessageDTO.getMessageType(); - var response = postGroupMessageFacade.postAliasMessage(rcGroupId, type, aliasOnlyMessageDTO.getContent()); + var response = messenger + .postAliasMessage(rcGroupId, type, aliasOnlyMessageDTO.getContent()); return new ResponseEntity<>(response, HttpStatus.CREATED); } +} + +