Skip to content

Commit

Permalink
Merge pull request #115 from Onlineberatung/develop
Browse files Browse the repository at this point in the history
[pull] develop from Onlineberatung:develop
  • Loading branch information
tkuzynow authored Dec 7, 2023
2 parents fb5e360 + ac8f570 commit 14d4865
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import de.caritas.cob.agencyservice.api.repository.TenantAware;
import de.caritas.cob.agencyservice.api.repository.agencypostcoderange.AgencyPostcodeRange;
import de.caritas.cob.agencyservice.api.repository.agencytopic.AgencyTopic;
import jakarta.persistence.EnumType;
import jakarta.persistence.Enumerated;
import java.time.LocalDateTime;
import java.util.List;
Expand Down Expand Up @@ -120,7 +121,7 @@ private Integer getPostCodeInteger() {
private LocalDateTime updateDate;

@Column(name = "data_protection_responsible_entity", nullable = false)
@Enumerated
@Enumerated(EnumType.STRING)
private DataProtectionResponsibleEntity dataProtectionResponsibleEntity;


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,18 @@ public class CentralDataProtectionTemplateService {
public String renderPrivacyTemplateWithRenderedPlaceholderValues(Agency agency) {
RestrictedTenantDTO restrictedTenantDataByTenantId = tenantService.getRestrictedTenantDataByTenantId(
agency.getTenantId());
if (restrictedTenantDataByTenantId != null && restrictedTenantDataByTenantId.getContent() != null) {
return renderPrivacyTemplateWithRenderedPlaceholderValues(agency, restrictedTenantDataByTenantId);
if (restrictedTenantDataByTenantId != null
&& restrictedTenantDataByTenantId.getContent() != null) {
return renderPrivacyTemplateWithRenderedPlaceholderValues(agency,
restrictedTenantDataByTenantId);
}
log.debug("No privacy content set for tenant with id: {}", agency.getTenantId());
return null;
}

@Nullable
private String renderPrivacyTemplateWithRenderedPlaceholderValues(Agency agency, RestrictedTenantDTO restrictedTenantDataByTenantId) {
private String renderPrivacyTemplateWithRenderedPlaceholderValues(Agency agency,
RestrictedTenantDTO restrictedTenantDataByTenantId) {
var renderedPlaceholdersMap = renderDataProtectionPlaceholdersFromTemplates(agency);
Map<String, Object> dataModel = renderedPlaceholdersMap.entrySet().stream()
.collect(Collectors.toMap(entry -> entry.getKey().getPlaceholderVariable(),
Expand All @@ -62,12 +65,17 @@ protected Map<DataProtectionPlaceHolderType, String> renderDataProtectionPlaceho
&& restrictedTenantDataByTenantId.getContent().getDataProtectionContactTemplate() != null) {
var renderedDataProtectionOfficerContact = renderDataProtectionOfficerContactFromTemplate(
agency, restrictedTenantDataByTenantId.getContent().getDataProtectionContactTemplate());
result.put(DataProtectionPlaceHolderType.DATA_PROTECTION_OFFICER,
renderedDataProtectionOfficerContact);

if (renderedDataProtectionOfficerContact != null) {
result.put(DataProtectionPlaceHolderType.DATA_PROTECTION_OFFICER,
renderedDataProtectionOfficerContact);
}
var renderedDataProtectionResponsible = renderDataProtectionResponsibleFromTemplate(
agency, restrictedTenantDataByTenantId.getContent().getDataProtectionContactTemplate());
result.put(DataProtectionPlaceHolderType.DATA_PROTECTION_RESPONSIBLE,
renderedDataProtectionResponsible);
if (renderedDataProtectionResponsible != null) {
result.put(DataProtectionPlaceHolderType.DATA_PROTECTION_RESPONSIBLE,
renderedDataProtectionResponsible);
}
}
return result;
}
Expand All @@ -76,7 +84,8 @@ protected Map<DataProtectionPlaceHolderType, String> renderDataProtectionPlaceho
private String renderDataProtectionResponsibleFromTemplate(Agency agency,
DataProtectionContactTemplateDTO dataProtectionContactTemplateDTO) {
if (isDataProtectionResponsibleTemplateAvailable(dataProtectionContactTemplateDTO)) {
return renderDataProtectionResponsibleFromTemplateIfAvailable(agency, dataProtectionContactTemplateDTO);
return renderDataProtectionResponsibleFromTemplateIfAvailable(agency,
dataProtectionContactTemplateDTO);
} else {
log.warn("No data protection responsible template set for tenant with id: {}",
agency.getTenantId());
Expand All @@ -96,7 +105,8 @@ private String renderDataProtectionResponsibleFromTemplateIfAvailable(Agency age
private String renderDataProtectionOfficerContactFromTemplate(Agency agency,
DataProtectionContactTemplateDTO dataProtectionContactTemplateDTO) {
if (isDataProtectionOfficerTemplateAvailable(dataProtectionContactTemplateDTO)) {
return renderDataProtectionOfficerContactFromTemplateIfAvailable(agency, dataProtectionContactTemplateDTO);
return renderDataProtectionOfficerContactFromTemplateIfAvailable(agency,
dataProtectionContactTemplateDTO);
} else {
log.warn("No data protection officer template set for tenant with id: {}",
agency.getTenantId());
Expand All @@ -109,6 +119,14 @@ private String renderDataProtectionOfficerContactFromTemplateIfAvailable(Agency
DataProtectionContactTemplateDTO dataProtectionContactTemplateDTO) {
final DataProtectionOfficerDTO dataProtectionOfficerDTO = dataProtectionContactTemplateDTO.getAgencyContext()
.getDataProtectionOfficer();

if (agency.getDataProtectionResponsibleEntity() == null) {
log.warn("No data protection responsible entity set for agency with id: {}",
agency.getId());
log.warn("Returning null for data protection officer contact template");
return null;
}

switch (agency.getDataProtectionResponsibleEntity()) {
case DATA_PROTECTION_OFFICER -> {
var contactDataDTO = JsonConverter.convertFromJsonNullSafe(
Expand All @@ -129,11 +147,8 @@ private String renderDataProtectionOfficerContactFromTemplateIfAvailable(Agency
return renderDataProtectionContactTemplate(
dataProtectionOfficerDTO.getAgencyResponsibleContact(), agencyContact);
}
default -> {
log.error("No data protection responsible entity set for agency with id: {}",
agency.getId());
return null;
}
default -> throw new IllegalArgumentException("Unknown data protection responsible entity: "
+ agency.getDataProtectionResponsibleEntity());
}
}

Expand All @@ -149,7 +164,8 @@ private boolean isDataProtectionOfficerTemplateAvailable(
&& dataProtectionContactTemplateDTO.getAgencyContext().getDataProtectionOfficer() != null;
}

private boolean isDataProtectionAgencyContextAvailable(DataProtectionContactTemplateDTO dataProtectionContactTemplateDTO) {
private boolean isDataProtectionAgencyContextAvailable(
DataProtectionContactTemplateDTO dataProtectionContactTemplateDTO) {
return dataProtectionContactTemplateDTO != null
&& dataProtectionContactTemplateDTO.getAgencyContext() != null;
}
Expand Down

0 comments on commit 14d4865

Please sign in to comment.