Skip to content

Commit

Permalink
feat: add tenantId to RegistrationStatisticsEvent and change topic ma…
Browse files Browse the repository at this point in the history
…p headers.
  • Loading branch information
PhilippFr committed Sep 9, 2022
1 parent a81a73e commit 9090061
Show file tree
Hide file tree
Showing 3 changed files with 118 additions and 8 deletions.
116 changes: 109 additions & 7 deletions services/statisticsservice.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,28 @@ paths:
- statistics-controller
summary: 'Returns statistical data for a consultant. [Authorization: consultant]'
operationId: getConsultantStatistics
parameters:
- name: startDate
in: query
description: start of the period (inclusive)
schema:
type: string
format: date
example: 2019-10-23
- name: endDate
in: query
description: end of the period (inclusive)
schema:
type: string
format: date
example: 2019-10-23
responses:
200:
description: OK - successfull operation
content:
'application/json':
schema:
$ref: '#/components/schemas/ConsultantStatisticsResponseDTO'
400:
description: BAD REQUEST - invalid/incomplete request or body object
403:
Expand All @@ -21,19 +40,25 @@ paths:
description: INTERNAL SERVER ERROR - server encountered unexpected condition
security:
- Bearer: [ ]
/statistics/consultant/csv:
/statistics/registration:
get:
tags:
- statistics-controller
summary: 'Returns statistical data for a consultant as csv file. [Authorization: consultant]'
operationId: getConsultantStatisticsCsv
summary: 'Returns a list of user registration data per tenant'
operationId: getRegistrationStatistics
responses:
200:
description: OK - successfull operation
400:
description: BAD REQUEST - invalid/incomplete request or body object
description: successful operation
content:
'application/json':
schema:
$ref: '#/components/schemas/RegistrationStatisticsListResponseDTO'
204:
description: successful operation, but no content
401:
description: UNAUTHORIZED - no/invalid Keycloak token
403:
description: FORBIDDEN - no/invalid CSRF token
description: FORBIDDEN - no/invalid role/authorization or CSRF token
500:
description: INTERNAL SERVER ERROR - server encountered unexpected condition
security:
Expand All @@ -42,6 +67,38 @@ paths:
components:
schemas:

ConsultantStatisticsResponseDTO:
type: object
properties:
startDate:
type: string
format: date
example: 2019-10-23
endDate:
type: string
format: date
example: 2019-10-23
numberOfAssignedSessions:
type: integer
format: int64
description: The number of assigned sessions in the given period of time
example: 15
numberOfSessionsWhereConsultantWasActive:
type: integer
format: int64
description: The number of sessions in which the consultant was active in the given period of time
example: 5
numberOfSentMessages:
type: integer
format: int64
description: Number of messages sent by the consultant in the given period of time
example: 5
videoCallDuration:
type: integer
format: int64
description: The duration of all video calls of the consultant in the given period of time in seconds
example: 3560

EventType:
type: string
enum:
Expand Down Expand Up @@ -158,6 +215,51 @@ components:
format: int64
description: The id of the session
example: 12345
tenantId:
type: integer
format: int64
description: The id of the tenant
example: 1
registrationDate:
type: string
example: '2022-08-15T21:11:29'
age:
type: integer
example: '25'
gender:
type: string
example: 'FEMALE'
counsellingRelation:
type: string
example: 'SELF_COUNSELLING'
topicsInternalAttributes:
type: array
items:
type: string
example: [ 'angeho01','angeho13' ]
mainTopicInternalAttribute:
type: string
example: 'angeho01'
postalCode:
type: string
example: '99999'

RegistrationStatisticsListResponseDTO:
type: object
properties:
registrationStatistics:
type: array
items:
$ref: '#/components/schemas/RegistrationStatisticsResponseDTO'

RegistrationStatisticsResponseDTO:
type: object
required:
- userId
- registrationDate
properties:
userId:
type: string
registrationDate:
type: string
example: '2022-08-15T21:11:29'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.http.HttpHeaders;
import org.springframework.stereotype.Service;

@Service
Expand All @@ -35,7 +36,7 @@ public List<TopicDTO> getAllTopics() {

public List<TopicDTO> getAllActiveTopics() {
log.info("Calling topic service to get all active topics");
addDefaultHeaders(this.topicControllerApi.getApiClient());
addTenantHeaders(this.topicControllerApi.getApiClient());
return topicControllerApi.getAllActiveTopics();
}

Expand All @@ -45,6 +46,12 @@ private void addDefaultHeaders(ApiClient apiClient) {
headers.forEach((key, value) -> apiClient.addDefaultHeader(key, value.iterator().next()));
}

private void addTenantHeaders(ApiClient apiClient) {
var httpHeaders = new HttpHeaders();
tenantHeaderSupplier.addTenantHeader(httpHeaders);
httpHeaders.forEach((key, value) -> apiClient.addDefaultHeader(key, value.iterator().next()));
}

@Cacheable(cacheNames = CacheManagerConfig.TOPICS_CACHE)
public Map<Long, TopicDTO> getAllTopicsMap() {
var allTopics = this.getAllTopics();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public Optional<String> getPayload() {
new RegistrationStatisticsEventMessage()
.eventType(EVENT_TYPE)
.sessionId(sessionId)
.tenantId(createdUser.getTenantId())
.userId(createdUser.getUserId())
.userRole(UserRole.ASKER)
.registrationDate(toIsoTime(createdUser.getCreateDate()))
Expand Down

0 comments on commit 9090061

Please sign in to comment.