Skip to content

Commit

Permalink
Merge pull request #52 from Onlineberatung/develop
Browse files Browse the repository at this point in the history
[pull] develop from Onlineberatung:develop
  • Loading branch information
tkuzynow authored Oct 12, 2022
2 parents 93ffbe4 + 7aca959 commit f275a8f
Show file tree
Hide file tree
Showing 23 changed files with 197 additions and 244 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import de.caritas.cob.agencyservice.api.service.TenantHeaderSupplier;
import de.caritas.cob.agencyservice.api.service.securityheader.SecurityHeaderSupplier;
import de.caritas.cob.agencyservice.config.apiclient.UserAdminServiceApiControllerFactory;
import de.caritas.cob.agencyservice.useradminservice.generated.ApiClient;
import de.caritas.cob.agencyservice.useradminservice.generated.web.AdminUserControllerApi;
import de.caritas.cob.agencyservice.useradminservice.generated.web.model.AgencyTypeDTO;
Expand All @@ -21,7 +22,7 @@
@RequiredArgsConstructor
public class UserAdminService {

private final @NonNull AdminUserControllerApi adminUserControllerApi;
private final @NonNull UserAdminServiceApiControllerFactory userAdminServiceApiControllerFactory;
private final @NonNull SecurityHeaderSupplier securityHeaderSupplier;
private final @NonNull TenantHeaderSupplier tenantHeaderSupplier;

Expand All @@ -34,8 +35,9 @@ public class UserAdminService {
* tagged as team consultants
*/
public void adaptRelatedConsultantsForChange(Long agencyId, String agencyType) {
addDefaultHeaders(this.adminUserControllerApi.getApiClient());
this.adminUserControllerApi
AdminUserControllerApi controllerApi = userAdminServiceApiControllerFactory.createControllerApi();
addDefaultHeaders(controllerApi.getApiClient());
controllerApi
.changeAgencyType(agencyId,
new AgencyTypeDTO()
.agencyType(AgencyTypeEnum.fromValue(agencyType)));
Expand All @@ -57,14 +59,15 @@ protected void addDefaultHeaders(ApiClient apiClient) {
*/
public List<ConsultantAdminResponseDTO> getConsultantsOfAgency(Long agencyId, int currentPage,
int perPage) {
addDefaultHeaders(this.adminUserControllerApi.getApiClient());
var controllerApi = userAdminServiceApiControllerFactory.createControllerApi();
addDefaultHeaders(controllerApi.getApiClient());
ConsultantFilter consultantFilter = new ConsultantFilter().agencyId(agencyId);

Sort sortBy = new Sort();
sortBy.setField(FieldEnum.LASTNAME);
sortBy.setOrder(OrderEnum.ASC);

return this.adminUserControllerApi
return controllerApi
.getConsultants(currentPage, perPage, consultantFilter, sortBy)
.getEmbedded();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import de.caritas.cob.agencyservice.applicationsettingsservice.generated.web.model.ApplicationSettingsDTO;
import de.caritas.cob.agencyservice.config.CacheManagerConfig;

import de.caritas.cob.agencyservice.config.apiclient.ApplicationSettingsApiControllerFactory;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import org.springframework.cache.annotation.Cacheable;
Expand All @@ -18,15 +19,16 @@
@RequiredArgsConstructor
public class ApplicationSettingsService {

private final @NonNull ApplicationsettingsControllerApi applicationsettingsControllerApi;
private final @NonNull ApplicationSettingsApiControllerFactory applicationSettingsApiControllerFactory;
private final @NonNull SecurityHeaderSupplier securityHeaderSupplier;
private final @NonNull TenantHeaderSupplier tenantHeaderSupplier;


@Cacheable(value = CacheManagerConfig.APPLICATION_SETTINGS_CACHE)
public ApplicationSettingsDTO getApplicationSettings() {
addDefaultHeaders(this.applicationsettingsControllerApi.getApiClient());
return this.applicationsettingsControllerApi.getApplicationSettings();
ApplicationsettingsControllerApi controllerApi = applicationSettingsApiControllerFactory.createControllerApi();
addDefaultHeaders(controllerApi.getApiClient());
return controllerApi.getApplicationSettings();
}

private void addDefaultHeaders(ApiClient apiClient) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import de.caritas.cob.agencyservice.appointmentservice.generated.ApiClient;
import de.caritas.cob.agencyservice.appointmentservice.generated.web.AgencyApi;
import de.caritas.cob.agencyservice.appointmentservice.generated.web.model.AgencyMasterDataSyncRequestDTO;
import de.caritas.cob.agencyservice.config.apiclient.AppointmentServiceAgencyApiControllerFactory;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Value;
Expand All @@ -15,7 +16,7 @@
@RequiredArgsConstructor
public class AppointmentService {

private final @NonNull AgencyApi appointmentAgencyApi;
private final @NonNull AppointmentServiceAgencyApiControllerFactory appointmentServiceAgencyApiControllerFactory;
private final @NonNull SecurityHeaderSupplier securityHeaderSupplier;
private final @NonNull TenantHeaderSupplier tenantHeaderSupplier;

Expand All @@ -29,16 +30,18 @@ public void syncAgencyDataToAppointmentService(Agency agency) {
AgencyMasterDataSyncRequestDTO request = new AgencyMasterDataSyncRequestDTO();
request.setId(agency.getId());
request.setName(agency.getName());
addDefaultHeaders(appointmentAgencyApi.getApiClient());
appointmentAgencyApi.agencyMasterDataSync(request);
AgencyApi controllerApi = appointmentServiceAgencyApiControllerFactory.createControllerApi();
addDefaultHeaders(controllerApi.getApiClient());
controllerApi.agencyMasterDataSync(request);
}

public void deleteAgency(Agency agency) {
if (!appointmentFeatureEnabled) {
return;
}
addDefaultHeaders(appointmentAgencyApi.getApiClient());
appointmentAgencyApi.deleteAgency(agency.getId());
AgencyApi controllerApi = appointmentServiceAgencyApiControllerFactory.createControllerApi();
addDefaultHeaders(controllerApi.getApiClient());
controllerApi.deleteAgency(agency.getId());
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import de.caritas.cob.agencyservice.api.service.securityheader.SecurityHeaderSupplier;
import de.caritas.cob.agencyservice.config.CacheManagerConfig;
import de.caritas.cob.agencyservice.config.apiclient.ConsultingTypeServiceApiControllerFactory;
import de.caritas.cob.agencyservice.consultingtypeservice.generated.ApiClient;
import de.caritas.cob.agencyservice.consultingtypeservice.generated.web.ConsultingTypeControllerApi;
import de.caritas.cob.agencyservice.consultingtypeservice.generated.web.model.ExtendedConsultingTypeResponseDTO;
Expand All @@ -17,7 +18,7 @@
@RequiredArgsConstructor
public class ConsultingTypeService {

private final @NonNull ConsultingTypeControllerApi consultingTypeControllerApi;
private final @NonNull ConsultingTypeServiceApiControllerFactory consultingTypeServiceApiControllerFactory;
private final @NonNull SecurityHeaderSupplier securityHeaderSupplier;
private final @NonNull TenantHeaderSupplier tenantHeaderSupplier;

Expand All @@ -31,8 +32,9 @@ public class ConsultingTypeService {
@Cacheable(value = CacheManagerConfig.CONSULTING_TYPE_CACHE, key = "#consultingTypeId")
public ExtendedConsultingTypeResponseDTO getExtendedConsultingTypeResponseDTO(
int consultingTypeId) {
addDefaultHeaders(this.consultingTypeControllerApi.getApiClient());
return this.consultingTypeControllerApi.getExtendedConsultingTypeById(consultingTypeId);
ConsultingTypeControllerApi controllerApi = consultingTypeServiceApiControllerFactory.createControllerApi();
addDefaultHeaders(controllerApi.getApiClient());
return controllerApi.getExtendedConsultingTypeById(consultingTypeId);
}

private void addDefaultHeaders(ApiClient apiClient) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package de.caritas.cob.agencyservice.api.service;

import de.caritas.cob.agencyservice.config.CacheManagerConfig;
import de.caritas.cob.agencyservice.config.apiclient.TenantServiceApiControllerFactory;
import de.caritas.cob.agencyservice.tenantservice.generated.web.TenantControllerApi;
import de.caritas.cob.agencyservice.tenantservice.generated.web.model.RestrictedTenantDTO;
import lombok.NonNull;
Expand All @@ -13,21 +14,24 @@
@RequiredArgsConstructor
public class TenantService {

private final @NonNull TenantControllerApi tenantControllerApi;
private final @NonNull TenantServiceApiControllerFactory tenantServiceApiControllerFactory;

@Value("${multitenancy.enabled}")
private boolean multitenancy;

@Cacheable(cacheNames = CacheManagerConfig.TENANT_CACHE, key = "#subdomain")
public RestrictedTenantDTO getRestrictedTenantDataBySubdomain(String subdomain) {
return tenantControllerApi.getRestrictedTenantDataBySubdomainWithHttpInfo(subdomain).getBody();
TenantControllerApi controllerApi = tenantServiceApiControllerFactory.createControllerApi();
return controllerApi.getRestrictedTenantDataBySubdomainWithHttpInfo(subdomain).getBody();
}

public RestrictedTenantDTO getRestrictedTenantDataByTenantId(Long tenantId) {
return tenantControllerApi.getRestrictedTenantDataByTenantId(tenantId);
TenantControllerApi controllerApi = tenantServiceApiControllerFactory.createControllerApi();
return controllerApi.getRestrictedTenantDataByTenantId(tenantId);
}

public RestrictedTenantDTO getRestrictedTenantDataForSingleTenant() {
return tenantControllerApi.getRestrictedSingleTenantData();
TenantControllerApi controllerApi = tenantServiceApiControllerFactory.createControllerApi();
return controllerApi.getRestrictedSingleTenantData();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import de.caritas.cob.agencyservice.api.service.securityheader.SecurityHeaderSupplier;
import de.caritas.cob.agencyservice.config.CacheManagerConfig;
import de.caritas.cob.agencyservice.config.apiclient.TopicServiceApiControllerFactory;
import de.caritas.cob.agencyservice.topicservice.generated.web.TopicControllerApi;
import java.util.List;
import lombok.NonNull;
Expand All @@ -15,14 +16,15 @@
@RequiredArgsConstructor
public class TopicService {

private final @NonNull TopicControllerApi topicControllerApi;
private final @NonNull TopicServiceApiControllerFactory topicServiceApiControllerFactory;
private final @NonNull SecurityHeaderSupplier securityHeaderSupplier;
private final @NonNull TenantHeaderSupplier tenantHeaderSupplier;

@Cacheable(cacheNames = CacheManagerConfig.TOPICS_CACHE)
public List<TopicDTO> getAllTopics() {
addDefaultHeaders(this.topicControllerApi.getApiClient());
return topicControllerApi.getAllTopics();
TopicControllerApi controllerApi = topicServiceApiControllerFactory.createControllerApi();
addDefaultHeaders(controllerApi.getApiClient());
return controllerApi.getAllTopics();
}

private void addDefaultHeaders(ApiClient apiClient) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import de.caritas.cob.agencyservice.applicationsettingsservice.generated.web.model.ApplicationSettingsDTO;
import de.caritas.cob.agencyservice.applicationsettingsservice.generated.web.model.SettingDTO;
import de.caritas.cob.agencyservice.config.apiclient.ApplicationSettingsApiControllerFactory;
import de.caritas.cob.agencyservice.config.apiclient.TenantServiceApiControllerFactory;
import de.caritas.cob.agencyservice.tenantservice.generated.web.model.RestrictedTenantDTO;
import java.util.Optional;
import javax.servlet.http.HttpServletRequest;
Expand All @@ -25,11 +27,10 @@ public class MultitenancyWithSingleDomainTenantResolver implements TenantResolve
private boolean multitenancyWithSingleDomain;

@Autowired
@Qualifier("applicationsettingsControllerApiPrimary")
private ApplicationsettingsControllerApi applicationsettingsControllerApi;
private ApplicationSettingsApiControllerFactory applicationSettingsApiControllerFactory;

@Autowired
private TenantControllerApi tenantControllerApi;
private TenantServiceApiControllerFactory tenantServiceApiControllerFactory;

@Override
public Optional<Long> resolve(HttpServletRequest request) {
Expand All @@ -52,13 +53,14 @@ private Optional<Long> resolveForMultitenancyWithSingleDomain() {
}

private Optional<Long> resolveFromTenantServiceBasedOnMainTenantSubdomain(String rootTenantSubdomain) {
var tenantControllerApi = tenantServiceApiControllerFactory.createControllerApi();
RestrictedTenantDTO rootTenantData = tenantControllerApi.getRestrictedTenantDataBySubdomain(
rootTenantSubdomain);
return Optional.of(rootTenantData.getId());
}

private Optional<String> getMainTenantSubdomainFromApplicationSettings() {
ApplicationSettingsDTO applicationSettings = applicationsettingsControllerApi.getApplicationSettings();
ApplicationSettingsDTO applicationSettings = applicationSettingsApiControllerFactory.createControllerApi().getApplicationSettings();
SettingDTO mainTenantSubdomainForSingleDomainMultitenancy = applicationSettings.getMainTenantSubdomainForSingleDomainMultitenancy();
if (mainTenantSubdomainForSingleDomainMultitenancy == null) {
return Optional.empty();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package de.caritas.cob.agencyservice.config.apiclient;

import de.caritas.cob.agencyservice.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);
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package de.caritas.cob.agencyservice.config.apiclient;

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;
import de.caritas.cob.agencyservice.appointmentservice.generated.ApiClient;
import de.caritas.cob.agencyservice.appointmentservice.generated.web.AgencyApi;

@Component
public class AppointmentServiceAgencyApiControllerFactory {

@Value("${appointment.service.api.url}")
private String appointmentServiceApiUrl;

@Autowired
private RestTemplate restTemplate;

public AgencyApi createControllerApi() {
var apiClient = new ApiClient(restTemplate).setBasePath(this.appointmentServiceApiUrl);
return new de.caritas.cob.agencyservice.appointmentservice.generated.web.AgencyApi(apiClient);
}
}

This file was deleted.

Loading

0 comments on commit f275a8f

Please sign in to comment.