Skip to content
This repository has been archived by the owner on Dec 17, 2024. It is now read-only.

Commit

Permalink
fix: formatted
Browse files Browse the repository at this point in the history
  • Loading branch information
Schweizer-Philipp committed May 10, 2021
1 parent bc568bd commit b2b2068
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 29 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package de.caritas.cob.agencyservice.api.manager.consultingtype;

import de.caritas.cob.agencyservice.api.exception.MissingConsultingTypeException;
import de.caritas.cob.agencyservice.api.service.ConsultingTypeService;
import de.caritas.cob.agencyservice.consultingtypeservice.generated.web.model.ExtendedConsultingTypeResponseDTO;
import de.caritas.cob.agencyservice.api.exception.MissingConsultingTypeException;
import lombok.Getter;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
Expand All @@ -24,11 +24,11 @@ public class ConsultingTypeManager {
* @throws MissingConsultingTypeException when no settings for provided consulting type where
* found
*/
public ExtendedConsultingTypeResponseDTO getConsultingTypeSettings(int consultingTypeId) throws MissingConsultingTypeException{
public ExtendedConsultingTypeResponseDTO getConsultingTypeSettings(int consultingTypeId)
throws MissingConsultingTypeException {
try {
return consultingTypeService.getExtendedConsultingTypeResponseDTO(consultingTypeId);
}
catch(RestClientException ex) {
} catch (RestClientException ex) {
throw new MissingConsultingTypeException(
String.format("No settings for consulting type %s found.", consultingTypeId));
}
Expand All @@ -42,9 +42,9 @@ public ExtendedConsultingTypeResponseDTO getConsultingTypeSettings(String consul
public boolean isConsultantBoundedToAgency(int consultingTypeId)
throws MissingConsultingTypeException {
try {
return consultingTypeService.getExtendedConsultingTypeResponseDTO(consultingTypeId).getConsultantBoundedToConsultingType();
}
catch(RestClientException ex) {
return consultingTypeService.getExtendedConsultingTypeResponseDTO(consultingTypeId)
.getConsultantBoundedToConsultingType();
} catch (RestClientException ex) {
throw new MissingConsultingTypeException(
String.format("No settings for consulting type %s found.", consultingTypeId));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
package de.caritas.cob.agencyservice.api.service;

import de.caritas.cob.agencyservice.api.exception.MissingConsultingTypeException;
import de.caritas.cob.agencyservice.api.service.securityheader.SecurityHeaderSupplier;
import de.caritas.cob.agencyservice.config.ConsultingTypeCachingConfig;
import de.caritas.cob.agencyservice.consultingtypeservice.generated.ApiClient;
import de.caritas.cob.agencyservice.consultingtypeservice.generated.web.model.ExtendedConsultingTypeResponseDTO;
import de.caritas.cob.agencyservice.api.service.securityheader.SecurityHeaderSupplier;
import de.caritas.cob.agencyservice.consultingtypeservice.generated.web.ConsultingTypeControllerApi;
import de.caritas.cob.agencyservice.consultingtypeservice.generated.web.model.ExtendedConsultingTypeResponseDTO;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.http.HttpHeaders;
import org.springframework.stereotype.Component;
import org.springframework.web.client.HttpClientErrorException;
import org.springframework.web.client.RestClientException;

/**
Expand All @@ -25,24 +23,24 @@ public class ConsultingTypeService {
private final @NonNull SecurityHeaderSupplier securityHeaderSupplier;

/**
* Returns the {@link ExtendedConsultingTypeResponseDTO} for the provided consulting type ID. the ExtendedConsultingTypeResponseDTO will be cached for further
* requests.
* Returns the {@link ExtendedConsultingTypeResponseDTO} for the provided consulting type ID. the
* ExtendedConsultingTypeResponseDTO will be cached for further requests.
*
* @param consultingTypeId the consulting type ID for the extended consulting type response DTO
* @return ExtendedConsultingTypeResponseDTO {@link ExtendedConsultingTypeResponseDTO}
* @throws RestClientException if http response code is not 2xx
*/
@Cacheable(value = ConsultingTypeCachingConfig.CONSULTING_TYPE_CACHE, key = "#consultingTypeId")
public ExtendedConsultingTypeResponseDTO getExtendedConsultingTypeResponseDTO(int consultingTypeId) throws RestClientException {
public ExtendedConsultingTypeResponseDTO getExtendedConsultingTypeResponseDTO(
int consultingTypeId) throws RestClientException {
addDefaultHeaders(this.consultingTypeControllerApi.getApiClient());
try {
return this.consultingTypeControllerApi.getExtendedConsultingTypeById(consultingTypeId);
} catch(RestClientException ex) {
} catch (RestClientException ex) {
throw ex;
}
}


private void addDefaultHeaders(ApiClient apiClient) {
HttpHeaders headers = this.securityHeaderSupplier.getCsrfHttpHeaders();
headers.forEach((key, value) -> apiClient.addDefaultHeader(key, value.iterator().next()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.Mockito.when;

import de.caritas.cob.agencyservice.consultingtypeservice.generated.web.model.ExtendedConsultingTypeResponseDTO;
import de.caritas.cob.agencyservice.AgencyServiceApplication;
import de.caritas.cob.agencyservice.api.exception.MissingConsultingTypeException;
import de.caritas.cob.agencyservice.api.service.ConsultingTypeService;
import de.caritas.cob.agencyservice.consultingtypeservice.generated.web.model.ExtendedConsultingTypeResponseDTO;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -35,8 +35,9 @@ public class ConsultingTypeManagerIT {
private ConsultingTypeService consultingTypeService;

@Test
public void getConsultantTypeSettings_Should_Throw_MissingConsultingTypeException_When_RestClientException(){
when(consultingTypeService.getExtendedConsultingTypeResponseDTO(anyInt())).thenThrow(new RestClientException(""));
public void getConsultantTypeSettings_Should_Throw_MissingConsultingTypeException_When_RestClientException() {
when(consultingTypeService.getExtendedConsultingTypeResponseDTO(anyInt()))
.thenThrow(new RestClientException(""));

assertThrows(MissingConsultingTypeException.class,
() -> consultingTypeManager.getConsultingTypeSettings(anyInt()));
Expand All @@ -46,9 +47,11 @@ public void getConsultantTypeSettings_Should_Throw_MissingConsultingTypeExceptio
public void getConsultantTypeSettings_Should_Return_ExtendedConsultingTypeResponseDTO()
throws MissingConsultingTypeException {
ExtendedConsultingTypeResponseDTO extendedConsultingTypeResponseDTO = new ExtendedConsultingTypeResponseDTO();
when(consultingTypeService.getExtendedConsultingTypeResponseDTO(anyInt())).thenReturn(extendedConsultingTypeResponseDTO);
when(consultingTypeService.getExtendedConsultingTypeResponseDTO(anyInt()))
.thenReturn(extendedConsultingTypeResponseDTO);

assertTrue(extendedConsultingTypeResponseDTO.equals(consultingTypeManager.getConsultingTypeSettings(anyInt())));
assertTrue(extendedConsultingTypeResponseDTO
.equals(consultingTypeManager.getConsultingTypeSettings(anyInt())));

}

Expand All @@ -57,7 +60,8 @@ public void isConsultantBoundedToAgency_Should_Return_True()
throws MissingConsultingTypeException {
ExtendedConsultingTypeResponseDTO extendedConsultingTypeResponseDTO = new ExtendedConsultingTypeResponseDTO();
extendedConsultingTypeResponseDTO.setConsultantBoundedToConsultingType(true);
when(consultingTypeService.getExtendedConsultingTypeResponseDTO(anyInt())).thenReturn(extendedConsultingTypeResponseDTO);
when(consultingTypeService.getExtendedConsultingTypeResponseDTO(anyInt()))
.thenReturn(extendedConsultingTypeResponseDTO);

assertTrue(consultingTypeManager.isConsultantBoundedToAgency(anyInt()));
}
Expand All @@ -67,7 +71,8 @@ public void isConsultantBoundedToAgency_Should_Return_False()
throws MissingConsultingTypeException {
ExtendedConsultingTypeResponseDTO extendedConsultingTypeResponseDTO = new ExtendedConsultingTypeResponseDTO();
extendedConsultingTypeResponseDTO.setConsultantBoundedToConsultingType(false);
when(consultingTypeService.getExtendedConsultingTypeResponseDTO(anyInt())).thenReturn(extendedConsultingTypeResponseDTO);
when(consultingTypeService.getExtendedConsultingTypeResponseDTO(anyInt()))
.thenReturn(extendedConsultingTypeResponseDTO);

assertFalse(consultingTypeManager.isConsultantBoundedToAgency(anyInt()));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,29 @@
package de.caritas.cob.agencyservice.testHelper;

import de.caritas.cob.agencyservice.consultingtypeservice.generated.web.model.RegistrationDTO;
import de.caritas.cob.agencyservice.consultingtypeservice.generated.web.model.WhiteSpotDTO;
import de.caritas.cob.agencyservice.api.manager.consultingtype.registration.Registration;
import de.caritas.cob.agencyservice.api.manager.consultingtype.whiteSpot.WhiteSpot;
import de.caritas.cob.agencyservice.consultingtypeservice.generated.web.model.ExtendedConsultingTypeResponseDTO;
import de.caritas.cob.agencyservice.consultingtypeservice.generated.web.model.RegistrationDTO;
import de.caritas.cob.agencyservice.consultingtypeservice.generated.web.model.WhiteSpotDTO;

public class ExtendedConsultingTypeResponseDTOHelper {

public static ExtendedConsultingTypeResponseDTO createExtendedConsultingTypeResponseDTO(int id, WhiteSpot whiteSpot, Registration registration, Boolean isLockedAgencies) {
public static ExtendedConsultingTypeResponseDTO createExtendedConsultingTypeResponseDTO(int id,
WhiteSpot whiteSpot, Registration registration, Boolean isLockedAgencies) {

var extendedConsultingTypeResponseDTO = new ExtendedConsultingTypeResponseDTO();

WhiteSpotDTO whiteSpotDTO = null;
if(whiteSpot != null) {
if (whiteSpot != null) {
whiteSpotDTO = new WhiteSpotDTO();
if(whiteSpot.getWhiteSpotAgencyId() != null)
if (whiteSpot.getWhiteSpotAgencyId() != null) {
whiteSpotDTO.setWhiteSpotAgencyId(whiteSpot.getWhiteSpotAgencyId().intValue());
}
whiteSpotDTO.setWhiteSpotAgencyAssigned(whiteSpot.isWhiteSpotAgencyAssigned());
}

RegistrationDTO registrationDTO = null;
if(registration != null){
if (registration != null) {
registrationDTO = new RegistrationDTO();
registrationDTO.setMinPostcodeSize(registration.getMinPostcodeSize());
}
Expand Down

0 comments on commit b2b2068

Please sign in to comment.