forked from Onlineberatung/onlineBeratung-agencyService
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #132 from virtualidentityag/release-2024-03-20
release 2024-03-20
- Loading branch information
Showing
42 changed files
with
805 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
.../agencyservice/api/admin/validation/validators/AgencyDataProtectionValidationService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package de.caritas.cob.agencyservice.api.admin.validation.validators; | ||
|
||
import static de.caritas.cob.agencyservice.api.model.DataProtectionDTO.DataProtectionResponsibleEntityEnum.AGENCY_RESPONSIBLE; | ||
import static de.caritas.cob.agencyservice.api.model.DataProtectionDTO.DataProtectionResponsibleEntityEnum.ALTERNATIVE_REPRESENTATIVE; | ||
import static de.caritas.cob.agencyservice.api.model.DataProtectionDTO.DataProtectionResponsibleEntityEnum.DATA_PROTECTION_OFFICER; | ||
import static org.apache.commons.lang3.StringUtils.isBlank; | ||
|
||
import de.caritas.cob.agencyservice.api.admin.validation.validators.model.ValidateAgencyDTO; | ||
import de.caritas.cob.agencyservice.api.exception.httpresponses.HttpStatusExceptionReason; | ||
import de.caritas.cob.agencyservice.api.exception.httpresponses.InvalidOfflineStatusException; | ||
import de.caritas.cob.agencyservice.api.model.DataProtectionContactDTO; | ||
import de.caritas.cob.agencyservice.api.repository.agency.DataProtectionPlaceHolderType; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
@Slf4j | ||
public class AgencyDataProtectionValidationService { | ||
|
||
public void validate(ValidateAgencyDTO validateAgencyDto) { | ||
validateThatDataProtectionDtoExists(validateAgencyDto); | ||
validateIfDataProtectionOfficer(validateAgencyDto); | ||
validateIfAgencyResponsible(validateAgencyDto); | ||
validateIfAlternativeRepresentative(validateAgencyDto); | ||
} | ||
|
||
private void validateThatDataProtectionDtoExists(ValidateAgencyDTO validateAgencyDto) { | ||
if (validateAgencyDto.getDataProtectionDTO() == null) { | ||
log.warn( | ||
"Could not save agency with id {} status. Required fields for data protection officer is empty.", | ||
validateAgencyDto.getId()); | ||
throw new InvalidOfflineStatusException( | ||
HttpStatusExceptionReason.DATA_PROTECTION_DTO_IS_NULL); | ||
} | ||
} | ||
|
||
private void validateIfDataProtectionOfficer(ValidateAgencyDTO validateAgencyDto) { | ||
if (DATA_PROTECTION_OFFICER.equals( | ||
validateAgencyDto.getDataProtectionDTO().getDataProtectionResponsibleEntity()) | ||
&& areFieldsEmpty( | ||
validateAgencyDto.getDataProtectionDTO().getDataProtectionOfficerContact())) { | ||
log.warn( | ||
"Could not save agency with id {}. Required fields for data protection officer is empty.", | ||
validateAgencyDto.getId()); | ||
throw new InvalidOfflineStatusException( | ||
HttpStatusExceptionReason.DATA_PROTECTION_OFFICER_IS_EMPTY); | ||
} | ||
} | ||
|
||
private void validateIfAgencyResponsible(ValidateAgencyDTO validateAgencyDto) { | ||
if (AGENCY_RESPONSIBLE.equals( | ||
validateAgencyDto.getDataProtectionDTO().getDataProtectionResponsibleEntity()) | ||
&& areFieldsEmpty( | ||
validateAgencyDto.getDataProtectionDTO().getAgencyDataProtectionResponsibleContact())) { | ||
log.warn( | ||
"Could not save agency with id {} status. Required fields for agency responsible is empty.", | ||
validateAgencyDto.getId()); | ||
throw new InvalidOfflineStatusException( | ||
HttpStatusExceptionReason.DATA_PROTECTION_RESPONSIBLE_IS_EMPTY); | ||
} | ||
} | ||
|
||
private void validateIfAlternativeRepresentative(ValidateAgencyDTO validateAgencyDto) { | ||
if (ALTERNATIVE_REPRESENTATIVE.equals( | ||
validateAgencyDto.getDataProtectionDTO().getDataProtectionResponsibleEntity()) | ||
&& areFieldsEmpty(validateAgencyDto.getDataProtectionDTO() | ||
.getAlternativeDataProtectionRepresentativeContact())) { | ||
log.warn( | ||
"Could not save agency with id {} status. Required fields for alternative responsible is empty.", | ||
validateAgencyDto.getId()); | ||
throw new InvalidOfflineStatusException( | ||
HttpStatusExceptionReason.DATA_PROTECTION_ALTERNATIVE_RESPONSIBLE_IS_EMPTY); | ||
} | ||
} | ||
|
||
private boolean areFieldsEmpty(DataProtectionContactDTO dataProtectionOfficerContact) { | ||
return dataProtectionOfficerContact == null | ||
|| isBlank(dataProtectionOfficerContact.getNameAndLegalForm()) | ||
|| isBlank(dataProtectionOfficerContact.getCity()) | ||
|| isBlank(dataProtectionOfficerContact.getPostcode()) | ||
|| isBlank(dataProtectionOfficerContact.getEmail()); | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
...itas/cob/agencyservice/api/admin/validation/validators/AgencyDataProtectionValidator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package de.caritas.cob.agencyservice.api.admin.validation.validators; | ||
|
||
import de.caritas.cob.agencyservice.api.admin.validation.validators.annotation.UpdateAgencyValidator; | ||
import de.caritas.cob.agencyservice.api.admin.validation.validators.model.ValidateAgencyDTO; | ||
import de.caritas.cob.agencyservice.api.service.ApplicationSettingsService; | ||
import de.caritas.cob.agencyservice.api.service.TenantService; | ||
import lombok.NonNull; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
@UpdateAgencyValidator | ||
@Slf4j | ||
public class AgencyDataProtectionValidator implements ConcreteAgencyValidator { | ||
|
||
private final @NonNull TenantService tenantService; | ||
|
||
private final @NonNull ApplicationSettingsService applicationSettingsService; | ||
|
||
private final @NonNull AgencyDataProtectionValidationService agencyDataProtectionValidationService; | ||
|
||
@Value("${feature.multitenancy.with.single.domain.enabled}") | ||
private boolean multitenancyWithSingleDomain; | ||
|
||
@Override | ||
public void validate(ValidateAgencyDTO validateAgencyDto) { | ||
|
||
var tenant = tenantService.getRestrictedTenantDataByTenantId(validateAgencyDto.getTenantId()); | ||
|
||
if (Boolean.TRUE.equals(tenant.getSettings().getFeatureCentralDataProtectionTemplateEnabled())) { | ||
log.info("Validating agency data protection for agency with id {}.", validateAgencyDto.getId()); | ||
agencyDataProtectionValidationService.validate(validateAgencyDto); | ||
} | ||
|
||
if (multitenancyWithSingleDomain) { | ||
var mainTenantSubdomainForSingleDomainMultitenancy = applicationSettingsService.getApplicationSettings() | ||
.getMainTenantSubdomainForSingleDomainMultitenancy(); | ||
de.caritas.cob.agencyservice.tenantservice.generated.web.model.RestrictedTenantDTO mainTenant = tenantService.getRestrictedTenantDataBySubdomain( | ||
mainTenantSubdomainForSingleDomainMultitenancy.getValue()); | ||
if (Boolean.TRUE.equals(mainTenant.getSettings().getFeatureCentralDataProtectionTemplateEnabled())) { | ||
agencyDataProtectionValidationService.validate(validateAgencyDto); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.