Skip to content

Commit

Permalink
feat: merge
Browse files Browse the repository at this point in the history
  • Loading branch information
tkuzynow committed Feb 20, 2024
2 parents c15bffa + 94690c1 commit 5dd43eb
Show file tree
Hide file tree
Showing 42 changed files with 1,153 additions and 140 deletions.
15 changes: 15 additions & 0 deletions api/agencyadminservice.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,9 @@ components:
dataProtection:
type: object
$ref: '#/components/schemas/DataProtectionDTO'
agencyLogo:
type: string
example: "base64 encoded image"

DataProtectionDTO:
type: object
Expand Down Expand Up @@ -630,6 +633,12 @@ components:
items:
type: string
enum: [ RELATIVE_COUNSELLING, SELF_COUNSELLING, PARENTAL_COUNSELLING]
dataProtection:
type: object
$ref: '#/components/schemas/DataProtectionDTO'
agencyLogo:
type: string
example: "base64 encoded image"

AgencyAdminFullResponseDTO:
type: object
Expand Down Expand Up @@ -690,6 +699,12 @@ components:
items:
type: string
enum: [ RELATIVE_COUNSELLING, SELF_COUNSELLING, PARENTAL_COUNSELLING ]
dataProtection:
type: object
$ref: '#/components/schemas/DataProtectionDTO'
agencyLogo:
type: string
example: "base64 encoded image"

DemographicsDTO:
type: object
Expand Down
7 changes: 7 additions & 0 deletions api/agencyservice.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,13 @@ components:
agencySpecificPrivacy:
type: string
example: "specific for agency privacy text"
topicIds:
type: array
items:
type: long
agencyLogo:
type: string
example: "base64 encoded image"

FullAgencyResponseDTO:
type: object
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.google.common.base.Joiner;
import de.caritas.cob.agencyservice.api.admin.service.agency.AgencyAdminFullResponseDTOBuilder;
import de.caritas.cob.agencyservice.api.admin.service.agency.AgencyTopicEnrichmentService;
import de.caritas.cob.agencyservice.api.admin.service.agency.DataProtectionConverter;
import de.caritas.cob.agencyservice.api.admin.service.agency.DemographicsConverter;
import de.caritas.cob.agencyservice.api.admin.validation.DeleteAgencyValidator;
import de.caritas.cob.agencyservice.api.exception.httpresponses.ConflictException;
Expand All @@ -26,7 +27,6 @@
import java.time.ZoneOffset;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -49,12 +49,14 @@ public class AgencyAdminService {
private final @NonNull AgencyTopicMergeService agencyTopicMergeService;
private final @NonNull AppointmentService appointmentService;

private final @NonNull DataProtectionConverter dataProtectionConverter;
@Autowired(required = false)
private AgencyTopicEnrichmentService agencyTopicEnrichmentService;

@Autowired(required = false)
private DemographicsConverter demographicsConverter;


@Value("${feature.topics.enabled}")
private boolean featureTopicsEnabled;

Expand Down Expand Up @@ -138,13 +140,15 @@ private Agency fromAgencyDTO(AgencyDTO agencyDTO) {
.url(agencyDTO.getUrl())
.isExternal(agencyDTO.getExternal())
.counsellingRelations(Joiner.on(",").join(agencyDTO.getCounsellingRelations()))
.agencyLogo(agencyDTO.getAgencyLogo())
.createDate(LocalDateTime.now(ZoneOffset.UTC))
.updateDate(LocalDateTime.now(ZoneOffset.UTC));


if (featureDemographicsEnabled && agencyDTO.getDemographics() != null) {
demographicsConverter.convertToEntity(agencyDTO.getDemographics(), agencyBuilder);
}

dataProtectionConverter.convertToEntity(agencyDTO.getDataProtection(), agencyBuilder);
var agencyToCreate = agencyBuilder.build();

if (featureTopicsEnabled) {
Expand Down Expand Up @@ -205,7 +209,10 @@ private Agency mergeAgencies(Agency agency, UpdateAgencyDTO updateAgencyDTO) {
.createDate(agency.getCreateDate())
.updateDate(LocalDateTime.now(ZoneOffset.UTC))
.counsellingRelations(agency.getCounsellingRelations())
.deleteDate(agency.getDeleteDate());
.deleteDate(agency.getDeleteDate())
.agencyLogo(updateAgencyDTO.getAgencyLogo());

dataProtectionConverter.convertToEntity(updateAgencyDTO.getDataProtection(), agencyBuilder);

if (nonNull(updateAgencyDTO.getConsultingType())) {
agencyBuilder.consultingTypeId(updateAgencyDTO.getConsultingType());
Expand Down Expand Up @@ -235,6 +242,8 @@ private Agency mergeAgencies(Agency agency, UpdateAgencyDTO updateAgencyDTO) {
}




/**
* Changes the type of the agency.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ private AgencyAdminResponseDTO createAgency() {
.createDate(String.valueOf(this.agency.getCreateDate()))
.updateDate(String.valueOf(this.agency.getUpdateDate()))
.deleteDate(String.valueOf(this.agency.getDeleteDate()))
.dataProtection(new DataProtectionDTOBuilder(this.agency).fromAgency());
.dataProtection(new DataProtectionDTOBuilder(this.agency).fromAgency())
.agencyLogo(this.agency.getAgencyLogo());

responseDTO.demographics(getDemographics(this.agency));
return responseDTO;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package de.caritas.cob.agencyservice.api.admin.service.agency;

import de.caritas.cob.agencyservice.api.model.DataProtectionDTO;
import de.caritas.cob.agencyservice.api.repository.agency.Agency.AgencyBuilder;
import de.caritas.cob.agencyservice.api.repository.agency.DataProtectionResponsibleEntity;
import de.caritas.cob.agencyservice.api.util.JsonConverter;
import org.springframework.stereotype.Component;

@Component
public class DataProtectionConverter {

public void convertToEntity(DataProtectionDTO dataProtectionDTO, AgencyBuilder agencyBuilder) {
if (dataProtectionDTO != null) {
agencyBuilder.dataProtectionResponsibleEntity(convertEnums(dataProtectionDTO));
agencyBuilder.dataProtectionOfficerContactData(
JsonConverter.convertToJson(dataProtectionDTO.getDataProtectionOfficerContact()));
agencyBuilder.dataProtectionAgencyResponsibleContactData(JsonConverter.convertToJson(
dataProtectionDTO.getAgencyDataProtectionResponsibleContact()));
agencyBuilder.dataProtectionAlternativeContactData(JsonConverter.convertToJson(
dataProtectionDTO.getAlternativeDataProtectionRepresentativeContact()));
} else {
nullifyDataProtectionAttributes(agencyBuilder);
}
}

private static void nullifyDataProtectionAttributes(AgencyBuilder agencyBuilder) {
agencyBuilder.dataProtectionResponsibleEntity(null);
agencyBuilder.dataProtectionOfficerContactData(null);
agencyBuilder.dataProtectionAgencyResponsibleContactData(null);
agencyBuilder.dataProtectionAlternativeContactData(null);
}

private static DataProtectionResponsibleEntity convertEnums(
DataProtectionDTO dataProtectionDTO) {
var dataProtectionEntity = dataProtectionDTO.getDataProtectionResponsibleEntity();
if (dataProtectionEntity == null) {
return null;
}
switch (dataProtectionEntity) {
case AGENCY_RESPONSIBLE:
return DataProtectionResponsibleEntity.AGENCY_RESPONSIBLE;
case DATA_PROTECTION_OFFICER:
return DataProtectionResponsibleEntity.DATA_PROTECTION_OFFICER;
case ALTERNATIVE_REPRESENTATIVE:
return DataProtectionResponsibleEntity.ALTERNATIVE_REPRESENTATIVE;
default:
throw new IllegalArgumentException(
"DataProtectionResponsibleEntity not supported: " + dataProtectionEntity);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
import de.caritas.cob.agencyservice.api.model.DataProtectionDTO;
import de.caritas.cob.agencyservice.api.model.DataProtectionDTO.DataProtectionResponsibleEntityEnum;
import de.caritas.cob.agencyservice.api.repository.agency.Agency;
import de.caritas.cob.agencyservice.api.repository.agency.DataProtectionResponsibleEntity;
import de.caritas.cob.agencyservice.api.util.JsonConverter;
import java.util.function.Supplier;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;

Expand All @@ -13,60 +15,45 @@ public class DataProtectionDTOBuilder {

private final @NonNull Agency agency;


public DataProtectionDTO fromAgency() {
if (agency.getDataProtectionResponsibleEntity() == null) {
return null;
}

switch (this.agency.getDataProtectionResponsibleEntity()) {
case AGENCY_RESPONSIBLE:
return getAgencyResponsibleDataProtectionDTO();
case ALTERNATIVE_REPRESENTATIVE:
return getAlternativeRepresentative();
case DATA_PROTECTION_OFFICER:
return getDataProtectionOfficerDTO();
default:
return null;
}
return new DataProtectionDTO()
.dataProtectionResponsibleEntity(convertEnums(agency.getDataProtectionResponsibleEntity()))
.agencyDataProtectionResponsibleContact(
convertNullSafe(agency::getDataProtectionAgencyResponsibleContactData))
.alternativeDataProtectionRepresentativeContact(
convertNullSafe(agency::getDataProtectionAlternativeContactData))
.dataProtectionOfficerContact(
convertNullSafe(agency::getDataProtectionOfficerContactData));
}

private DataProtectionDTO getDataProtectionOfficerDTO() {
String dataProtectionOfficerContactData = this.agency.getDataProtectionOfficerContactData();
if (dataProtectionOfficerContactData == null) {
private DataProtectionContactDTO convertNullSafe(Supplier<String> dataProtectionDataSupplier) {
if (dataProtectionDataSupplier.get() == null) {
return null;
} else {
return JsonConverter.convertFromJson(dataProtectionDataSupplier.get());
}
DataProtectionContactDTO dataProtectionContactDTO = JsonConverter.convertFromJson(
dataProtectionOfficerContactData);
return new DataProtectionDTO()
.dataProtectionResponsibleEntity(
DataProtectionResponsibleEntityEnum.DATA_PROTECTION_OFFICER)
.dataProtectionOfficerContact(dataProtectionContactDTO);
}

private DataProtectionDTO getAlternativeRepresentative() {
String dataProtectionAlternativeContactData = this.agency.getDataProtectionAlternativeContactData();
if (dataProtectionAlternativeContactData == null) {
return null;
}
DataProtectionContactDTO dataProtectionContactDTO = JsonConverter.convertFromJson(
dataProtectionAlternativeContactData);

return new DataProtectionDTO()
.dataProtectionResponsibleEntity(
DataProtectionResponsibleEntityEnum.ALTERNATIVE_REPRESENTATIVE)
.alternativeDataProtectionRepresentativeContact(dataProtectionContactDTO);
}
private static DataProtectionResponsibleEntityEnum convertEnums(
DataProtectionResponsibleEntity dataProtectionEntity) {

private DataProtectionDTO getAgencyResponsibleDataProtectionDTO() {
String dataProtectionAgencyResponsibleContactData = this.agency.getDataProtectionAgencyResponsibleContactData();
if (dataProtectionAgencyResponsibleContactData == null) {
return null;
switch (dataProtectionEntity) {
case AGENCY_RESPONSIBLE:
return DataProtectionDTO.DataProtectionResponsibleEntityEnum.AGENCY_RESPONSIBLE;
case DATA_PROTECTION_OFFICER:
return DataProtectionDTO.DataProtectionResponsibleEntityEnum.DATA_PROTECTION_OFFICER;
case ALTERNATIVE_REPRESENTATIVE:
return DataProtectionDTO.DataProtectionResponsibleEntityEnum.ALTERNATIVE_REPRESENTATIVE;
default:
throw new IllegalArgumentException(
"DataProtectionResponsibleEntity not supported: " + dataProtectionEntity);
}
DataProtectionContactDTO dataProtectionContactDTO = JsonConverter.convertFromJson(
dataProtectionAgencyResponsibleContactData);
return new DataProtectionDTO()
.dataProtectionResponsibleEntity(DataProtectionResponsibleEntityEnum.AGENCY_RESPONSIBLE)
.agencyDataProtectionResponsibleContact(dataProtectionContactDTO);
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
import de.caritas.cob.agencyservice.api.admin.validation.validators.annotation.CreateAgencyValidator;
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.exception.httpresponses.BadRequestException;
import de.caritas.cob.agencyservice.api.model.AgencyDTO;
import de.caritas.cob.agencyservice.api.model.UpdateAgencyDTO;
import de.caritas.cob.agencyservice.api.repository.agency.AgencyRepository;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import org.springframework.context.ApplicationContext;
Expand All @@ -20,6 +22,8 @@ public class AgencyValidator {

private final @NonNull ApplicationContext applicationContext;

private final @NonNull AgencyRepository agencyRepository;

/**
* Validates an {@link AgencyDTO}.
*
Expand Down Expand Up @@ -53,15 +57,19 @@ private ValidateAgencyDTO fromAgencyDto(AgencyDTO agencyDto) {
.postcode(agencyDto.getPostcode())
.consultingType(agencyDto.getConsultingType())
.demographicsDTO(agencyDto.getDemographics())
.tenantId(agencyDto.getTenantId())
.build();
}

private ValidateAgencyDTO fromUpdateAgencyDto(Long agencyId, UpdateAgencyDTO updateAgencyDTO) {
var existingAgency = agencyRepository.findById(agencyId).orElseThrow(() -> new BadRequestException("Agency with id " + agencyId + "not found!"));
return ValidateAgencyDTO.builder()
.id(agencyId)
.postcode(updateAgencyDTO.getPostcode())
.offline(updateAgencyDTO.getOffline())
.tenantId(existingAgency.getTenantId())
.demographicsDTO(updateAgencyDTO.getDemographics())
.dataProtectionDTO(updateAgencyDTO.getDataProtection())
.build();
}
}
Loading

0 comments on commit 5dd43eb

Please sign in to comment.