Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop' into feat/OBI-1160_reas…
Browse files Browse the repository at this point in the history
…signment_feedback_chat
  • Loading branch information
PhilippFr committed Nov 14, 2022
2 parents 76cc9bf + 85b3998 commit faf78fd
Show file tree
Hide file tree
Showing 37 changed files with 770 additions and 39 deletions.
53 changes: 51 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@
<liquibase-maven-plugin.version>4.8.0</liquibase-maven-plugin.version>
<javax.ws.rs-api.version>2.1.1</javax.ws.rs-api.version>
<spring-boot-starter-web.version>2.6.6</spring-boot-starter-web.version>
<spring-security-core.version>5.7.1</spring-security-core.version>
<spring-security-core.version>5.7.5</spring-security-core.version>
<spring-beans.version>5.2.20.RELEASE</spring-beans.version>
<spring-webmvc.version>5.2.20.RELEASE</spring-webmvc.version>
<spring-core.version>5.2.20.RELEASE</spring-core.version>
<json-smart.version>2.4.7</json-smart.version>
<springfox-swagger-ui.version>2.10.0</springfox-swagger-ui.version>
<spring-context-support.version>5.3.23</spring-context-support.version>
Expand Down Expand Up @@ -89,6 +92,21 @@
<artifactId>spring-security-core</artifactId>
<version>${spring-security-core.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>${spring-beans.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${spring-webmvc.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${spring-core.version}</version>
</dependency>

<dependency>
<groupId>org.hibernate.validator</groupId>
Expand Down Expand Up @@ -198,6 +216,12 @@
<artifactId>liquibase-maven-plugin</artifactId>
<version>${liquibase-maven-plugin.version}</version>
</dependency>
<dependency>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-core</artifactId>
<version>4.8.0</version>
</dependency>


<!-- https://mvnrepository.com/artifact/org.mariadb.jdbc/mariadb-java-client -->
<dependency>
Expand Down Expand Up @@ -490,6 +514,31 @@
</importMappings>
</configuration>
</execution>
<execution>
<id>application-settings-service-client-model</id>
<phase>generate-sources</phase>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<configOptions>
<sourceFolder>/</sourceFolder>
<library>resttemplate</library>
<dateLibrary>java8</dateLibrary>
</configOptions>
<inputSpec>${project.basedir}/services/applicationsettingsservice.yaml</inputSpec>
<generatorName>java</generatorName>
<generateApis>true</generateApis>
<generateApiTests>false</generateApiTests>
<generateModelTests>false</generateModelTests>
<apiPackage>
${project.groupId}.${project.artifactId}.applicationsettingsservice.generated.web
</apiPackage>
<modelPackage>
${project.groupId}.${project.artifactId}.applicationsettingsservice.generated.web.model
</modelPackage>
</configuration>
</execution>
<execution>
<id>user-admin-service</id>
<goals>
Expand Down Expand Up @@ -883,7 +932,7 @@
<plugin>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-maven-plugin</artifactId>
<version>4.1.1</version>
<version>${liquibase-maven-plugin.version}</version>
<configuration>
<propertyFile>src/main/resources/liquibase.properties</propertyFile>
</configuration>
Expand Down
89 changes: 89 additions & 0 deletions services/applicationsettingsservice.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
openapi: 3.0.1

info:
title: Definition for Application Settings API
description: This information will be replaced by the SpringFox config information
version: 0.0.1

paths:
/settings:
get:
tags:
- applicationsettings-controller
summary: 'Get all application settings'
operationId: getApplicationSettings
responses:
200:
description: OK - successful operation

content:
application/json:
schema:
$ref: '#/components/schemas/ApplicationSettingsDTO'
204:
description: NO CONTENT - no content found
400:
description: BAD REQUEST - invalid/incomplete request or body object
401:
description: UNAUTHORIZED - no/invalid Keycloak token
500:
description: INTERNAL SERVER ERROR - server encountered unexpected condition

components:
schemas:
ApplicationSettingsDTO:
type: object
required:
- multitenancyWithSingleDomainEnabled
- multitenancyEnabled
properties:
multitenancyWithSingleDomainEnabled:
allOf:
- $ref: '#/components/schemas/FeatureToggleDTO'
multitenancyEnabled:
allOf:
- $ref: '#/components/schemas/FeatureToggleDTO'
useTenantService:
allOf:
- $ref: '#/components/schemas/FeatureToggleDTO'
enableWalkthrough:
allOf:
- $ref: '#/components/schemas/FeatureToggleDTO'
disableVideoAppointments:
allOf:
- $ref: '#/components/schemas/FeatureToggleDTO'
mainTenantSubdomainForSingleDomainMultitenancy:
allOf:
- $ref: '#/components/schemas/SettingDTO'
budibaseSSO:
allOf:
- $ref: '#/components/schemas/FeatureToggleDTO'
useOverviewPage:
allOf:
- $ref: '#/components/schemas/FeatureToggleDTO'


FeatureToggleDTO:
type: object
required:
- value
- readOnly
properties:
value:
type: boolean
example: true
readOnly:
type: boolean
example: false
SettingDTO:
type: object
required:
- value
- readOnly
properties:
value:
type: string
example: true
readOnly:
type: boolean
example: false
13 changes: 13 additions & 0 deletions src/main/java/de/caritas/cob/userservice/api/Messenger.java
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,19 @@ public boolean isInChat(String chatId, String chatUserId) {
return chatUserIds.contains(chatUserId);
}

@Override
public boolean markAsDirectConsultant(Long sessionId) {
return sessionRepository
.findById(sessionId)
.map(
session -> {
session.setIsConsultantDirectlySet(true);
var updatedSession = sessionRepository.save(session);
return updatedSession.getIsConsultantDirectlySet();
})
.orElse(false);
}

@Override
public Optional<Map<String, String>> findSession(Long sessionId) {
var session = sessionRepository.findById(sessionId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,16 @@ public class UserController implements UsersApi {
@Override
public ResponseEntity<Void> registerUser(@Valid @RequestBody UserDTO user) {
user.setNewUserAccount(true);
createUserFacade.createUserAccountWithInitializedConsultingType(user);
var sessionId = createUserFacade.createUserAccountWithInitializedConsultingType(user);

return new ResponseEntity<>(HttpStatus.CREATED);
HttpStatus status;
if (user.isConsultantSet() && !messenger.markAsDirectConsultant(sessionId)) {
status = HttpStatus.INTERNAL_SERVER_ERROR;
} else {
status = HttpStatus.CREATED;
}

return ResponseEntity.status(status).build();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
import static de.caritas.cob.userservice.api.helper.UserHelper.STATE_REGEXP;
import static de.caritas.cob.userservice.api.helper.UserHelper.TERMS_ACCEPTED_REGEXP;
import static de.caritas.cob.userservice.api.helper.UserHelper.VALID_POSTCODE_REGEX;
import static org.apache.commons.lang3.StringUtils.isNotBlank;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.annotation.JsonProperty;
Expand Down Expand Up @@ -157,6 +159,11 @@ public UserDTO(String age, String state, String consultingType) {
this.consultingType = consultingType;
}

@JsonIgnore
public boolean isConsultantSet() {
return isNotBlank(consultantId);
}

@Override
public String toString() {
return "UserDTO{"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ public class CacheManagerConfig {

public static final String AGENCY_CACHE = "agencyCache";
public static final String CONSULTING_TYPE_CACHE = "consultingTypeCache";

public static final String APPLICATION_SETTINGS_CACHE = "applicationSettingsCache";
public static final String TENANT_CACHE = "tenantCache";
public static final String TENANT_ADMIN_CACHE = "tenantAdminCache";
public static final String TOPICS_CACHE = "topicsCache";
Expand Down Expand Up @@ -66,6 +68,18 @@ public class CacheManagerConfig {
@Value("${cache.topic.configuration.timeToLiveSeconds}")
private long topicTimeToLiveSeconds;

@Value("${cache.appsettings.configuration.maxEntriesLocalHeap}")
private long appSettingsMaxEntriesLocalHeap;

@Value("${cache.appsettings.configuration.eternal}")
private boolean appSettingsEternal;

@Value("${cache.appsettings.configuration.timeToIdleSeconds}")
private long appSettingsTimeToIdleSeconds;

@Value("${cache.appsettings.configuration.timeToLiveSeconds}")
private long appSettingsTimeToLiveSeconds;

@Bean
public CacheManager cacheManager() {
return new EhCacheCacheManager(ehCacheManager());
Expand All @@ -79,7 +93,7 @@ public net.sf.ehcache.CacheManager ehCacheManager() {
config.addCache(buildTenantCacheConfiguration());
config.addCache(buildTenantAdminCacheConfiguration());
config.addCache(buildTopicCacheConfiguration());

config.addCache(buildApplicationSettingsCacheConfiguration());
return net.sf.ehcache.CacheManager.newInstance(config);
}

Expand Down Expand Up @@ -132,4 +146,14 @@ private CacheConfiguration buildTopicCacheConfiguration() {
topicCacheConfiguration.setTimeToLiveSeconds(topicTimeToLiveSeconds);
return topicCacheConfiguration;
}

private CacheConfiguration buildApplicationSettingsCacheConfiguration() {
var appSettingsCacheConfiguration = new CacheConfiguration();
appSettingsCacheConfiguration.setName(APPLICATION_SETTINGS_CACHE);
appSettingsCacheConfiguration.setMaxEntriesLocalHeap(appSettingsMaxEntriesLocalHeap);
appSettingsCacheConfiguration.setEternal(appSettingsEternal);
appSettingsCacheConfiguration.setTimeToIdleSeconds(appSettingsTimeToIdleSeconds);
appSettingsCacheConfiguration.setTimeToLiveSeconds(appSettingsTimeToLiveSeconds);
return appSettingsCacheConfiguration;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
package de.caritas.cob.userservice.api.config.apiclient;

import static java.util.Objects.isNull;
import static java.util.Objects.nonNull;
import static org.apache.commons.lang3.StringUtils.isEmpty;

import de.caritas.cob.userservice.api.exception.httpresponses.InternalServerErrorException;
import java.beans.IntrospectionException;
import java.beans.Introspector;
import java.beans.PropertyDescriptor;
import java.util.Arrays;
import java.util.Collection;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.RestTemplate;

/** Extension of the generated UserService API client to adapt the handling of parameter values. */
public class ApplicationSettingsApiClient
extends de.caritas.cob.userservice.applicationsettingsservice.generated.ApiClient {

private static final String FILTER_NAME = "filter";

public ApplicationSettingsApiClient(RestTemplate restTemplate) {
super(restTemplate);
}

/**
* Changes the behavior of mapping multiple parameter values to exclude null values for objects
* which are not {@link Collection} for filter query params.
*
* @param collectionFormat The format to convert to
* @param name The name of the parameter
* @param value The parameter's value
* @return a Map containing non-null String value(s) of the input parameter
*/
@Override
public MultiValueMap<String, String> parameterToMultiValueMap(
CollectionFormat collectionFormat, String name, Object value) {

if (noValidFilterParams(name, value)) {
return super.parameterToMultiValueMap(collectionFormat, name, value);
}

return obtainQueryParameters(value);
}

private boolean noValidFilterParams(String queryName, Object queryValue) {
return isEmpty(queryName) || !queryName.equals(FILTER_NAME) || isNull(queryValue);
}

private MultiValueMap<String, String> obtainQueryParameters(Object queryValue) {
MultiValueMap<String, String> paramMap = new LinkedMultiValueMap<>();

try {
Arrays.asList(
Introspector.getBeanInfo(queryValue.getClass(), Object.class)
.getPropertyDescriptors())
.stream()
.filter(descriptor -> nonNull(descriptor.getReadMethod()))
.forEach(descriptor -> setMethodKeyValuePairs(queryValue, paramMap, descriptor));
return paramMap;

} catch (IntrospectionException exception) {
throw new InternalServerErrorException(
String.format("Could not obtain method properties of %s", queryValue.toString()),
exception);
}
}

private void setMethodKeyValuePairs(
Object queryValue, MultiValueMap<String, String> map, PropertyDescriptor descriptor) {
try {
Object value = descriptor.getReadMethod().invoke(queryValue);
if (nonNull(value)) {
map.add(descriptor.getName(), value.toString());
}
} catch (Exception exception) {
throw new InternalServerErrorException(
String.format("Could not obtain method key value pairs of %s", queryValue.toString()),
exception);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package de.caritas.cob.userservice.api.config.apiclient;

import de.caritas.cob.userservice.applicationsettingsservice.generated.web.ApplicationsettingsControllerApi;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;

@Component
public class ApplicationSettingsApiControllerFactory {

@Value("${consulting.type.service.api.url}")
private String applicationsettingsServiceApiUrl;

@Autowired private RestTemplate restTemplate;

public ApplicationsettingsControllerApi createControllerApi() {
var apiClient =
new ApplicationSettingsApiClient(restTemplate)
.setBasePath(this.applicationsettingsServiceApiUrl);
return new ApplicationsettingsControllerApi(apiClient);
}
}
Loading

0 comments on commit faf78fd

Please sign in to comment.